Completed
Push — master ( e7e916...24fa88 )
by cam
01:10
created
ecrire/inc/urls.php 2 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('base/objets');
23 23
 
@@ -57,106 +57,106 @@  discard block
 block discarded – undo
57 57
  *
58 58
  */
59 59
 function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) {
60
-	static $current_base = null;
60
+    static $current_base = null;
61 61
 
62
-	// les anciennes fonctions modifient directement les globales
63
-	// on les sauve avant l'appel, et on les retablit apres !
64
-	$save = [
65
-		$GLOBALS['fond'] ?? null,
66
-		$GLOBALS['contexte'] ?? null,
67
-		$_SERVER['REDIRECT_url_propre'] ?? null,
68
-		$_ENV['url_propre'] ?? null,
69
-		$GLOBALS['profondeur_url']
70
-	];
62
+    // les anciennes fonctions modifient directement les globales
63
+    // on les sauve avant l'appel, et on les retablit apres !
64
+    $save = [
65
+        $GLOBALS['fond'] ?? null,
66
+        $GLOBALS['contexte'] ?? null,
67
+        $_SERVER['REDIRECT_url_propre'] ?? null,
68
+        $_ENV['url_propre'] ?? null,
69
+        $GLOBALS['profondeur_url']
70
+    ];
71 71
 
72
-	if (is_null($current_base)) {
73
-		include_spip('inc/filtres_mini');
74
-		// le decodage des urls se fait toujours par rapport au site public
75
-		$current_base = url_absolue(_DIR_RACINE ?: './');
76
-	}
77
-	if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
-		$url = substr($url, strlen($current_base));
79
-	}
72
+    if (is_null($current_base)) {
73
+        include_spip('inc/filtres_mini');
74
+        // le decodage des urls se fait toujours par rapport au site public
75
+        $current_base = url_absolue(_DIR_RACINE ?: './');
76
+    }
77
+    if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
+        $url = substr($url, strlen($current_base));
79
+    }
80 80
 
81
-	// si on est en train d'assembler la page principale,
82
-	// recuperer l'url depuis les globales url propres si fournies
83
-	// sinon extraire la bonne portion d'url
84
-	if ($assembler) {
85
-		if (isset($_SERVER['REDIRECT_url_propre'])) {
86
-			$url = $_SERVER['REDIRECT_url_propre'];
87
-		} elseif (isset($_ENV['url_propre'])) {
88
-			$url = $_ENV['url_propre'];
89
-		} else {
90
-			$qs = explode('?', $url);
91
-			// ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
-			$url = ltrim($qs[0], '/');
93
-			$url = explode('/', $url);
94
-			while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
-				array_shift($url);
96
-			}
97
-			$qs[0] = implode('/', $url);
98
-			$url = implode('?', $qs);
99
-		}
100
-	}
81
+    // si on est en train d'assembler la page principale,
82
+    // recuperer l'url depuis les globales url propres si fournies
83
+    // sinon extraire la bonne portion d'url
84
+    if ($assembler) {
85
+        if (isset($_SERVER['REDIRECT_url_propre'])) {
86
+            $url = $_SERVER['REDIRECT_url_propre'];
87
+        } elseif (isset($_ENV['url_propre'])) {
88
+            $url = $_ENV['url_propre'];
89
+        } else {
90
+            $qs = explode('?', $url);
91
+            // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
+            $url = ltrim($qs[0], '/');
93
+            $url = explode('/', $url);
94
+            while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
+                array_shift($url);
96
+            }
97
+            $qs[0] = implode('/', $url);
98
+            $url = implode('?', $qs);
99
+        }
100
+    }
101 101
 
102
-	unset($_SERVER['REDIRECT_url_propre']);
103
-	unset($_ENV['url_propre']);
104
-	include_spip('inc/filtres_mini');
105
-	if (strpos($url, '://') === false) {
106
-		$GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
-	} else {
108
-		$GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
-	}
102
+    unset($_SERVER['REDIRECT_url_propre']);
103
+    unset($_ENV['url_propre']);
104
+    include_spip('inc/filtres_mini');
105
+    if (strpos($url, '://') === false) {
106
+        $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
+    } else {
108
+        $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
+    }
110 110
 
111
-	$url_redirect = '';
112
-	$decoder = charger_fonction_url('decoder');
113
-	if ($decoder) {
114
-		$a = $decoder($url, $fond, $contexte);
115
-		if (is_array($a)) {
116
-			[$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
117
-			$url_redirect ??= '';
118
-			if ($url_redirect === $url) {
119
-				$url_redirect = '';
120
-			} // securite pour eviter une redirection infinie
121
-			if ($assembler and strlen($url_redirect)) {
122
-				spip_log("Redirige $url vers $url_redirect");
123
-				include_spip('inc/headers');
124
-				redirige_par_entete($url_redirect, '', 301);
125
-			}
126
-			if (isset($nfond)) {
127
-				$fond = $nfond;
128
-			} else {
129
-				if (
130
-					$fond == ''
131
-					or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
132
-				) {
133
-					$fond = $type;
134
-				}
135
-			}
136
-			if (isset($ncontexte)) {
137
-				$contexte = $ncontexte;
138
-			}
139
-			if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
140
-				$contexte['type'] = $type;
141
-			}
142
-			if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
143
-				$contexte['type-page'] = $type;
144
-			}
145
-		}
146
-	}
111
+    $url_redirect = '';
112
+    $decoder = charger_fonction_url('decoder');
113
+    if ($decoder) {
114
+        $a = $decoder($url, $fond, $contexte);
115
+        if (is_array($a)) {
116
+            [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
117
+            $url_redirect ??= '';
118
+            if ($url_redirect === $url) {
119
+                $url_redirect = '';
120
+            } // securite pour eviter une redirection infinie
121
+            if ($assembler and strlen($url_redirect)) {
122
+                spip_log("Redirige $url vers $url_redirect");
123
+                include_spip('inc/headers');
124
+                redirige_par_entete($url_redirect, '', 301);
125
+            }
126
+            if (isset($nfond)) {
127
+                $fond = $nfond;
128
+            } else {
129
+                if (
130
+                    $fond == ''
131
+                    or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
132
+                ) {
133
+                    $fond = $type;
134
+                }
135
+            }
136
+            if (isset($ncontexte)) {
137
+                $contexte = $ncontexte;
138
+            }
139
+            if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
140
+                $contexte['type'] = $type;
141
+            }
142
+            if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
143
+                $contexte['type-page'] = $type;
144
+            }
145
+        }
146
+    }
147 147
 
148
-	// retablir les globales
149
-	[$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
148
+    // retablir les globales
149
+    [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
150 150
 
151
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
152
-	// d'inversion url => objet
153
-	// maintenir pour compat ?
154
-	#if ($assembler) {
155
-	#	unset($_SERVER['REDIRECT_url_propre']);
156
-	#	unset($_ENV['url_propre']);
157
-	#}
151
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
152
+    // d'inversion url => objet
153
+    // maintenir pour compat ?
154
+    #if ($assembler) {
155
+    #	unset($_SERVER['REDIRECT_url_propre']);
156
+    #	unset($_ENV['url_propre']);
157
+    #}
158 158
 
159
-	return [$fond, $contexte, $url_redirect];
159
+    return [$fond, $contexte, $url_redirect];
160 160
 }
161 161
 
162 162
 /**
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
  * @return array|false|string
170 170
  */
171 171
 function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array {
172
-	if ($url_propre) {
173
-		if ($GLOBALS['profondeur_url'] <= 0) {
174
-			$urls_anciennes = charger_fonction_url('decoder', 'propres');
175
-		} else {
176
-			$urls_anciennes = charger_fonction_url('decoder', 'arbo');
177
-		}
172
+    if ($url_propre) {
173
+        if ($GLOBALS['profondeur_url'] <= 0) {
174
+            $urls_anciennes = charger_fonction_url('decoder', 'propres');
175
+        } else {
176
+            $urls_anciennes = charger_fonction_url('decoder', 'arbo');
177
+        }
178 178
 
179
-		if ($urls_anciennes) {
180
-			$urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
181
-		}
182
-		return $urls_anciennes ?: [];
183
-	}
179
+        if ($urls_anciennes) {
180
+            $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
181
+        }
182
+        return $urls_anciennes ?: [];
183
+    }
184 184
 
185
-	return [];
185
+    return [];
186 186
 }
187 187
 
188 188
 /**
@@ -195,41 +195,41 @@  discard block
 block discarded – undo
195 195
  * @return array|false|string
196 196
  */
197 197
 function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array {
198
-	// Migration depuis anciennes URLs ?
199
-	// traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
200
-	if (
201
-		$url
202
-		and $GLOBALS['profondeur_url'] <= 0
203
-	) {
204
-		$r = nettoyer_url_page($url, $contexte);
205
-		if ($r) {
206
-			[$contexte, $type, , , $suite] = $r;
207
-			$_id = id_table_objet($type);
208
-			$id_objet = $contexte[$_id];
209
-			$url_propre = generer_objet_url($id_objet, $type);
210
-			if (
211
-				strlen($url_propre)
212
-				and !strstr($url, (string) $url_propre)
213
-				and (
214
-					objet_test_si_publie($type, $id_objet)
215
-					or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
216
-				)
217
-			) {
218
-				[, $hash] = array_pad(explode('#', $url_propre), 2, null);
219
-				$args = [];
220
-				foreach (array_filter(explode('&', $suite)) as $fragment) {
221
-					if ($fragment != "$_id=$id_objet") {
222
-						$args[] = $fragment;
223
-					}
224
-				}
225
-				$url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
198
+    // Migration depuis anciennes URLs ?
199
+    // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
200
+    if (
201
+        $url
202
+        and $GLOBALS['profondeur_url'] <= 0
203
+    ) {
204
+        $r = nettoyer_url_page($url, $contexte);
205
+        if ($r) {
206
+            [$contexte, $type, , , $suite] = $r;
207
+            $_id = id_table_objet($type);
208
+            $id_objet = $contexte[$_id];
209
+            $url_propre = generer_objet_url($id_objet, $type);
210
+            if (
211
+                strlen($url_propre)
212
+                and !strstr($url, (string) $url_propre)
213
+                and (
214
+                    objet_test_si_publie($type, $id_objet)
215
+                    or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
216
+                )
217
+            ) {
218
+                [, $hash] = array_pad(explode('#', $url_propre), 2, null);
219
+                $args = [];
220
+                foreach (array_filter(explode('&', $suite)) as $fragment) {
221
+                    if ($fragment != "$_id=$id_objet") {
222
+                        $args[] = $fragment;
223
+                    }
224
+                }
225
+                $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
226 226
 
227
-				return [$contexte, $type, $url_redirect, $type];
228
-			}
229
-		}
230
-	}
231
-	/* Fin compatibilite anciennes urls */
232
-	return [];
227
+                return [$contexte, $type, $url_redirect, $type];
228
+            }
229
+        }
230
+    }
231
+    /* Fin compatibilite anciennes urls */
232
+    return [];
233 233
 }
234 234
 
235 235
 /**
@@ -242,24 +242,24 @@  discard block
 block discarded – undo
242 242
  * @return string|array
243 243
  */
244 244
 function urls_liste_objets($preg = true) {
245
-	static $url_objets = null;
246
-	if (is_null($url_objets)) {
247
-		$url_objets = [];
248
-		// recuperer les tables_objets_sql declarees
249
-		$tables_objets = lister_tables_objets_sql();
250
-		foreach ($tables_objets as $t => $infos) {
251
-			if ($infos['page']) {
252
-				$url_objets[] = $infos['type'];
253
-				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
254
-			}
255
-		}
256
-		$url_objets = pipeline('declarer_url_objets', $url_objets);
257
-	}
258
-	if (!$preg) {
259
-		return $url_objets;
260
-	}
245
+    static $url_objets = null;
246
+    if (is_null($url_objets)) {
247
+        $url_objets = [];
248
+        // recuperer les tables_objets_sql declarees
249
+        $tables_objets = lister_tables_objets_sql();
250
+        foreach ($tables_objets as $t => $infos) {
251
+            if ($infos['page']) {
252
+                $url_objets[] = $infos['type'];
253
+                $url_objets = array_merge($url_objets, $infos['type_surnoms']);
254
+            }
255
+        }
256
+        $url_objets = pipeline('declarer_url_objets', $url_objets);
257
+    }
258
+    if (!$preg) {
259
+        return $url_objets;
260
+    }
261 261
 
262
-	return implode('|', array_map('preg_quote', $url_objets));
262
+    return implode('|', array_map('preg_quote', $url_objets));
263 263
 }
264 264
 
265 265
 /**
@@ -273,26 +273,26 @@  discard block
 block discarded – undo
273 273
  * @return array
274 274
  */
275 275
 function nettoyer_url_page($url, $contexte = []) {
276
-	$url_objets = urls_liste_objets();
277
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
278
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
276
+    $url_objets = urls_liste_objets();
277
+    $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
278
+    $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
280 280
 
281
-	if (
282
-		preg_match($raccourci_url_page_html, $url, $regs)
283
-		or preg_match($raccourci_url_page_id, $url, $regs)
284
-		or preg_match($raccourci_url_page_spip, $url, $regs)
285
-	) {
286
-		$regs = array_pad($regs, 4, null);
287
-		$type = objet_type($regs[1]);
288
-		$_id = id_table_objet($type);
289
-		$contexte[$_id] = $regs[2];
290
-		$suite = $regs[3];
281
+    if (
282
+        preg_match($raccourci_url_page_html, $url, $regs)
283
+        or preg_match($raccourci_url_page_id, $url, $regs)
284
+        or preg_match($raccourci_url_page_spip, $url, $regs)
285
+    ) {
286
+        $regs = array_pad($regs, 4, null);
287
+        $type = objet_type($regs[1]);
288
+        $_id = id_table_objet($type);
289
+        $contexte[$_id] = $regs[2];
290
+        $suite = $regs[3];
291 291
 
292
-		return [$contexte, $type, null, $type, $suite];
293
-	}
292
+        return [$contexte, $type, null, $type, $suite];
293
+    }
294 294
 
295
-	return [];
295
+    return [];
296 296
 }
297 297
 
298 298
 /**
@@ -310,38 +310,38 @@  discard block
 block discarded – undo
310 310
  * @return string
311 311
  */
312 312
 function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string {
313
-	static $furls = [];
314
-	$id = intval($id);
315
-	if (!isset($furls[$objet])) {
316
-		if (
317
-			function_exists($f = 'generer_' . $objet . '_url_ecrire')
318
-			// ou definie par un plugin
319
-			or $f = charger_fonction($f, 'urls', true)
320
-			// deprecated
321
-			or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
322
-		) {
323
-			$furls[$objet] = $f;
324
-		} else {
325
-			$furls[$objet] = '';
326
-		}
327
-	}
328
-	if ($furls[$objet]) {
329
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
330
-	}
331
-	// si pas de flag public fourni
332
-	// le calculer en fonction de la declaration de statut
333
-	if (is_null($public) and !$connect) {
334
-		$public = objet_test_si_publie($objet, $id, $connect);
335
-	}
336
-	if ($public or $connect) {
337
-		return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
338
-	}
339
-	$a = id_table_objet($objet) . '=' . intval($id);
340
-	if (!function_exists('objet_info')) {
341
-		include_spip('inc/filtres');
342
-	}
313
+    static $furls = [];
314
+    $id = intval($id);
315
+    if (!isset($furls[$objet])) {
316
+        if (
317
+            function_exists($f = 'generer_' . $objet . '_url_ecrire')
318
+            // ou definie par un plugin
319
+            or $f = charger_fonction($f, 'urls', true)
320
+            // deprecated
321
+            or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
322
+        ) {
323
+            $furls[$objet] = $f;
324
+        } else {
325
+            $furls[$objet] = '';
326
+        }
327
+    }
328
+    if ($furls[$objet]) {
329
+        return $furls[$objet]($id, $args, $ancre, $public, $connect);
330
+    }
331
+    // si pas de flag public fourni
332
+    // le calculer en fonction de la declaration de statut
333
+    if (is_null($public) and !$connect) {
334
+        $public = objet_test_si_publie($objet, $id, $connect);
335
+    }
336
+    if ($public or $connect) {
337
+        return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
338
+    }
339
+    $a = id_table_objet($objet) . '=' . intval($id);
340
+    if (!function_exists('objet_info')) {
341
+        include_spip('inc/filtres');
342
+    }
343 343
 
344
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
344
+    return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
345 345
 }
346 346
 
347 347
 /**
@@ -349,5 +349,5 @@  discard block
 block discarded – undo
349 349
  * @see generer_objet_url_ecrire
350 350
  */
351 351
 function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, string $connect = '') {
352
-	return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect);
352
+    return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect);
353 353
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	) {
204 204
 		$r = nettoyer_url_page($url, $contexte);
205 205
 		if ($r) {
206
-			[$contexte, $type, , , $suite] = $r;
206
+			[$contexte, $type,,, $suite] = $r;
207 207
 			$_id = id_table_objet($type);
208 208
 			$id_objet = $contexte[$_id];
209 209
 			$url_propre = generer_objet_url($id_objet, $type);
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
  */
275 275
 function nettoyer_url_page($url, $contexte = []) {
276 276
 	$url_objets = urls_liste_objets();
277
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
278
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
277
+	$raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,';
278
+	$raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
+	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,';
280 280
 
281 281
 	if (
282 282
 		preg_match($raccourci_url_page_html, $url, $regs)
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 	$id = intval($id);
315 315
 	if (!isset($furls[$objet])) {
316 316
 		if (
317
-			function_exists($f = 'generer_' . $objet . '_url_ecrire')
317
+			function_exists($f = 'generer_'.$objet.'_url_ecrire')
318 318
 			// ou definie par un plugin
319 319
 			or $f = charger_fonction($f, 'urls', true)
320 320
 			// deprecated
321
-			or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
321
+			or function_exists($f = 'generer_url_ecrire_'.$objet) or $f = charger_fonction($f, 'urls', true)
322 322
 		) {
323 323
 			$furls[$objet] = $f;
324 324
 		} else {
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	if ($public or $connect) {
337 337
 		return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
338 338
 	}
339
-	$a = id_table_objet($objet) . '=' . intval($id);
339
+	$a = id_table_objet($objet).'='.intval($id);
340 340
 	if (!function_exists('objet_info')) {
341 341
 		include_spip('inc/filtres');
342 342
 	}
343 343
 
344
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
344
+	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : '');
345 345
 }
346 346
 
347 347
 /**
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2265 added lines, -2266 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,66 +48,66 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = [];
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
83
-		// si le fichier truc/machin/nom.php n'existe pas,
84
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
-	) {
87
-		include_spip(substr($dossier, 0, -1));
88
-	}
89
-	if (function_exists($f)) {
90
-		return $f;
91
-	}
92
-	if (function_exists($g)) {
93
-		return $g;
94
-	}
95
-
96
-	if ($continue) {
97
-		return $echecs[$f] = false;
98
-	}
99
-
100
-	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
102
-		($inc ? '' : " (fichier $d absent de $dossier)"));
103
-
104
-	include_spip('inc/minipres');
105
-	echo minipres(
106
-		_T('forum_titre_erreur'),
107
-		_T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
-		['all_inline' => true,'status' => 404]
109
-	);
110
-	exit;
51
+    static $echecs = [];
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (
82
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
83
+        // si le fichier truc/machin/nom.php n'existe pas,
84
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
+    ) {
87
+        include_spip(substr($dossier, 0, -1));
88
+    }
89
+    if (function_exists($f)) {
90
+        return $f;
91
+    }
92
+    if (function_exists($g)) {
93
+        return $g;
94
+    }
95
+
96
+    if ($continue) {
97
+        return $echecs[$f] = false;
98
+    }
99
+
100
+    // Echec : message d'erreur
101
+    spip_log("fonction $nom ($f ou $g) indisponible" .
102
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
103
+
104
+    include_spip('inc/minipres');
105
+    echo minipres(
106
+        _T('forum_titre_erreur'),
107
+        _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
+        ['all_inline' => true,'status' => 404]
109
+    );
110
+    exit;
111 111
 }
112 112
 
113 113
 /**
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
  * @return bool
118 118
  */
119 119
 function include_once_check($file) {
120
-	if (file_exists($file)) {
121
-		include_once $file;
120
+    if (file_exists($file)) {
121
+        include_once $file;
122 122
 
123
-		return true;
124
-	}
125
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
-	$crash = ($crash ?: []);
127
-	$crash[$file] = true;
128
-	ecrire_meta('message_crash_plugins', serialize($crash));
123
+        return true;
124
+    }
125
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
+    $crash = ($crash ?: []);
127
+    $crash[$file] = true;
128
+    ecrire_meta('message_crash_plugins', serialize($crash));
129 129
 
130
-	return false;
130
+    return false;
131 131
 }
132 132
 
133 133
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
  *     - string : chemin du fichier trouvé
152 152
  **/
153 153
 function include_spip($f, $include = true) {
154
-	return find_in_path($f . '.php', '', $include);
154
+    return find_in_path($f . '.php', '', $include);
155 155
 }
156 156
 
157 157
 /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
  *     - string : chemin du fichier trouvé
172 172
  **/
173 173
 function require_spip($f) {
174
-	return find_in_path($f . '.php', '', 'required');
174
+    return find_in_path($f . '.php', '', 'required');
175 175
 }
176 176
 
177 177
 
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
181 181
  */
182 182
 function include_fichiers_fonctions() {
183
-	static $done = false;
184
-	if (!$done) {
185
-		include_spip('inc/lang');
186
-
187
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
-		// donc il faut l'inclure "en globals"
189
-		if ($f = find_in_path('mes_fonctions.php')) {
190
-			global $dossier_squelettes;
191
-			include_once(_ROOT_CWD . $f);
192
-		}
193
-
194
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
-			// chargement optimise precompile
196
-			include_once(_CACHE_PLUGINS_FCT);
197
-		}
198
-		if (test_espace_prive()) {
199
-			include_spip('inc/filtres_ecrire');
200
-		}
201
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
-		$done = true;
203
-	}
183
+    static $done = false;
184
+    if (!$done) {
185
+        include_spip('inc/lang');
186
+
187
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
+        // donc il faut l'inclure "en globals"
189
+        if ($f = find_in_path('mes_fonctions.php')) {
190
+            global $dossier_squelettes;
191
+            include_once(_ROOT_CWD . $f);
192
+        }
193
+
194
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
+            // chargement optimise precompile
196
+            include_once(_CACHE_PLUGINS_FCT);
197
+        }
198
+        if (test_espace_prive()) {
199
+            include_spip('inc/filtres_ecrire');
200
+        }
201
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
+        $done = true;
203
+    }
204 204
 }
205 205
 
206 206
 /**
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
  *     Les paramètres du pipeline modifiés
227 227
  **/
228 228
 function minipipe($fonc, &$val) {
229
-	// fonction
230
-	if (function_exists($fonc)) {
231
-		$val = call_user_func($fonc, $val);
232
-	} // Class::Methode
233
-	else {
234
-		if (
235
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
-			and $methode = [$regs[1], $regs[2]]
237
-			and is_callable($methode)
238
-		) {
239
-			$val = call_user_func($methode, $val);
240
-		} else {
241
-			spip_log("Erreur - '$fonc' non definie !");
242
-		}
243
-	}
244
-
245
-	return $val;
229
+    // fonction
230
+    if (function_exists($fonc)) {
231
+        $val = call_user_func($fonc, $val);
232
+    } // Class::Methode
233
+    else {
234
+        if (
235
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
+            and $methode = [$regs[1], $regs[2]]
237
+            and is_callable($methode)
238
+        ) {
239
+            $val = call_user_func($methode, $val);
240
+        } else {
241
+            spip_log("Erreur - '$fonc' non definie !");
242
+        }
243
+    }
244
+
245
+    return $val;
246 246
 }
247 247
 
248 248
 /**
@@ -273,46 +273,46 @@  discard block
 block discarded – undo
273 273
  *     Résultat
274 274
  */
275 275
 function pipeline($action, $val = null) {
276
-	static $charger;
277
-
278
-	// chargement initial des fonctions mises en cache, ou generation du cache
279
-	if (!$charger) {
280
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
-			include_spip('inc/plugin');
282
-			// generer les fichiers php precompiles
283
-			// de chargement des plugins et des pipelines
284
-			actualise_plugins_actifs();
285
-			if (!($ok = @is_readable($charger))) {
286
-				spip_log("fichier $charger pas cree");
287
-			}
288
-		}
289
-
290
-		if ($ok) {
291
-			include_once $charger;
292
-		}
293
-	}
294
-
295
-	// appliquer notre fonction si elle existe
296
-	$fonc = 'execute_pipeline_' . strtolower($action);
297
-	if (function_exists($fonc)) {
298
-		$val = $fonc($val);
299
-	} // plantage ?
300
-	else {
301
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
-	}
303
-
304
-	// si le flux est une table avec 2 cle args&data
305
-	// on ne ressort du pipe que les donnees dans 'data'
306
-	// array_key_exists pour php 4.1.0
307
-	if (
308
-		is_array($val)
309
-		and count($val) == 2
310
-		and (array_key_exists('data', $val))
311
-	) {
312
-		$val = $val['data'];
313
-	}
314
-
315
-	return $val;
276
+    static $charger;
277
+
278
+    // chargement initial des fonctions mises en cache, ou generation du cache
279
+    if (!$charger) {
280
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
+            include_spip('inc/plugin');
282
+            // generer les fichiers php precompiles
283
+            // de chargement des plugins et des pipelines
284
+            actualise_plugins_actifs();
285
+            if (!($ok = @is_readable($charger))) {
286
+                spip_log("fichier $charger pas cree");
287
+            }
288
+        }
289
+
290
+        if ($ok) {
291
+            include_once $charger;
292
+        }
293
+    }
294
+
295
+    // appliquer notre fonction si elle existe
296
+    $fonc = 'execute_pipeline_' . strtolower($action);
297
+    if (function_exists($fonc)) {
298
+        $val = $fonc($val);
299
+    } // plantage ?
300
+    else {
301
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
+    }
303
+
304
+    // si le flux est une table avec 2 cle args&data
305
+    // on ne ressort du pipe que les donnees dans 'data'
306
+    // array_key_exists pour php 4.1.0
307
+    if (
308
+        is_array($val)
309
+        and count($val) == 2
310
+        and (array_key_exists('data', $val))
311
+    ) {
312
+        $val = $val['data'];
313
+    }
314
+
315
+    return $val;
316 316
 }
317 317
 
318 318
 /**
@@ -356,38 +356,38 @@  discard block
 block discarded – undo
356 356
  *     paramètre est planté pour cause de compatibilité ascendante.
357 357
  */
358 358
 function spip_log($message = null, $name = null) {
359
-	static $pre = [];
360
-	static $log;
361
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
363
-		$logname = null;
364
-	}
365
-	if (!isset($regs[2])) {
366
-		$niveau = _LOG_INFO;
367
-	}
368
-	else {
369
-		$niveau = intval($regs[2]);
370
-	}
371
-
372
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
-		if (!$pre) {
374
-			$pre = [
375
-				_LOG_HS => 'HS:',
376
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
377
-				_LOG_CRITIQUE => 'CRITIQUE:',
378
-				_LOG_ERREUR => 'ERREUR:',
379
-				_LOG_AVERTISSEMENT => 'WARNING:',
380
-				_LOG_INFO_IMPORTANTE => '!INFO:',
381
-				_LOG_INFO => 'info:',
382
-				_LOG_DEBUG => 'debug:'
383
-			];
384
-			$log = charger_fonction('log', 'inc');
385
-		}
386
-		if (!is_string($message)) {
387
-			$message = print_r($message, true);
388
-		}
389
-		$log($pre[$niveau] . ' ' . $message, $logname);
390
-	}
359
+    static $pre = [];
360
+    static $log;
361
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
363
+        $logname = null;
364
+    }
365
+    if (!isset($regs[2])) {
366
+        $niveau = _LOG_INFO;
367
+    }
368
+    else {
369
+        $niveau = intval($regs[2]);
370
+    }
371
+
372
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
+        if (!$pre) {
374
+            $pre = [
375
+                _LOG_HS => 'HS:',
376
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
377
+                _LOG_CRITIQUE => 'CRITIQUE:',
378
+                _LOG_ERREUR => 'ERREUR:',
379
+                _LOG_AVERTISSEMENT => 'WARNING:',
380
+                _LOG_INFO_IMPORTANTE => '!INFO:',
381
+                _LOG_INFO => 'info:',
382
+                _LOG_DEBUG => 'debug:'
383
+            ];
384
+            $log = charger_fonction('log', 'inc');
385
+        }
386
+        if (!is_string($message)) {
387
+            $message = print_r($message, true);
388
+        }
389
+        $log($pre[$niveau] . ' ' . $message, $logname);
390
+    }
391 391
 }
392 392
 
393 393
 /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
  * @param array $opt Tableau d'options
399 399
  **/
400 400
 function journal($phrase, $opt = []) {
401
-	$journal = charger_fonction('journal', 'inc');
402
-	$journal($phrase, $opt);
401
+    $journal = charger_fonction('journal', 'inc');
402
+    $journal($phrase, $opt);
403 403
 }
404 404
 
405 405
 
@@ -418,37 +418,37 @@  discard block
 block discarded – undo
418 418
  **/
419 419
 function _request($var, $c = false) {
420 420
 
421
-	if (is_array($c)) {
422
-		return $c[$var] ?? null;
423
-	}
424
-
425
-	if (isset($_GET[$var])) {
426
-		$a = $_GET[$var];
427
-	} elseif (isset($_POST[$var])) {
428
-		$a = $_POST[$var];
429
-	} else {
430
-		return null;
431
-	}
432
-
433
-	// Si on est en ajax et en POST tout a ete encode
434
-	// via encodeURIComponent, il faut donc repasser
435
-	// dans le charset local...
436
-	if (
437
-		defined('_AJAX')
438
-		and _AJAX
439
-		and isset($GLOBALS['meta']['charset'])
440
-		and $GLOBALS['meta']['charset'] != 'utf-8'
441
-		and is_string($a)
442
-		// check rapide mais pas fiable
443
-		and preg_match(',[\x80-\xFF],', $a)
444
-		// check fiable
445
-		and include_spip('inc/charsets')
446
-		and is_utf8($a)
447
-	) {
448
-		return importer_charset($a, 'utf-8');
449
-	}
450
-
451
-	return $a;
421
+    if (is_array($c)) {
422
+        return $c[$var] ?? null;
423
+    }
424
+
425
+    if (isset($_GET[$var])) {
426
+        $a = $_GET[$var];
427
+    } elseif (isset($_POST[$var])) {
428
+        $a = $_POST[$var];
429
+    } else {
430
+        return null;
431
+    }
432
+
433
+    // Si on est en ajax et en POST tout a ete encode
434
+    // via encodeURIComponent, il faut donc repasser
435
+    // dans le charset local...
436
+    if (
437
+        defined('_AJAX')
438
+        and _AJAX
439
+        and isset($GLOBALS['meta']['charset'])
440
+        and $GLOBALS['meta']['charset'] != 'utf-8'
441
+        and is_string($a)
442
+        // check rapide mais pas fiable
443
+        and preg_match(',[\x80-\xFF],', $a)
444
+        // check fiable
445
+        and include_spip('inc/charsets')
446
+        and is_utf8($a)
447
+    ) {
448
+        return importer_charset($a, 'utf-8');
449
+    }
450
+
451
+    return $a;
452 452
 }
453 453
 
454 454
 
@@ -466,22 +466,22 @@  discard block
 block discarded – undo
466 466
  *     - false sinon
467 467
  **/
468 468
 function set_request($var, $val = null, $c = false) {
469
-	if (is_array($c)) {
470
-		unset($c[$var]);
471
-		if ($val !== null) {
472
-			$c[$var] = $val;
473
-		}
469
+    if (is_array($c)) {
470
+        unset($c[$var]);
471
+        if ($val !== null) {
472
+            $c[$var] = $val;
473
+        }
474 474
 
475
-		return $c;
476
-	}
475
+        return $c;
476
+    }
477 477
 
478
-	unset($_GET[$var]);
479
-	unset($_POST[$var]);
480
-	if ($val !== null) {
481
-		$_GET[$var] = $val;
482
-	}
478
+    unset($_GET[$var]);
479
+    unset($_POST[$var]);
480
+    if ($val !== null) {
481
+        $_GET[$var] = $val;
482
+    }
483 483
 
484
-	return false; # n'affecte pas $c
484
+    return false; # n'affecte pas $c
485 485
 }
486 486
 
487 487
 /**
@@ -501,25 +501,25 @@  discard block
 block discarded – undo
501 501
  * @return array|mixed|string
502 502
  */
503 503
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
504
-	if (is_array($value)) {
505
-		if ($key == '*') {
506
-			$key = array_keys($value);
507
-		}
508
-		if (!is_array($key)) {
509
-			$key = [$key];
510
-		}
511
-		foreach ($key as $k) {
512
-			if (!empty($value[$k])) {
513
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
-			}
515
-		}
516
-		return $value;
517
-	}
518
-	// si la valeur vient des GET ou POST on la sanitize
519
-	if (!empty($value) and $value == _request($key)) {
520
-		$value = $sanitize_function($value);
521
-	}
522
-	return $value;
504
+    if (is_array($value)) {
505
+        if ($key == '*') {
506
+            $key = array_keys($value);
507
+        }
508
+        if (!is_array($key)) {
509
+            $key = [$key];
510
+        }
511
+        foreach ($key as $k) {
512
+            if (!empty($value[$k])) {
513
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
+            }
515
+        }
516
+        return $value;
517
+    }
518
+    // si la valeur vient des GET ou POST on la sanitize
519
+    if (!empty($value) and $value == _request($key)) {
520
+        $value = $sanitize_function($value);
521
+    }
522
+    return $value;
523 523
 }
524 524
 
525 525
 /**
@@ -527,23 +527,22 @@  discard block
 block discarded – undo
527 527
  *
528 528
  * On est sur le web, on exclut certains protocoles,
529 529
  * notamment 'file://', 'php://' et d'autres…
530
-
531 530
  * @param string $url
532 531
  * @return bool
533 532
  */
534 533
 function tester_url_absolue($url) {
535
-	$url = trim($url);
536
-	if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
537
-		if (
538
-			isset($m[1])
539
-			and $p = strtolower(rtrim($m[1], ':'))
540
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
541
-		) {
542
-			return false;
543
-		}
544
-		return true;
545
-	}
546
-	return false;
534
+    $url = trim($url);
535
+    if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
536
+        if (
537
+            isset($m[1])
538
+            and $p = strtolower(rtrim($m[1], ':'))
539
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
540
+        ) {
541
+            return false;
542
+        }
543
+        return true;
544
+    }
545
+    return false;
547 546
 }
548 547
 
549 548
 /**
@@ -565,95 +564,95 @@  discard block
 block discarded – undo
565 564
  * @return string URL
566 565
  */
567 566
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
568
-	// requete erronnee : plusieurs variable dans $c et aucun $v
569
-	if (strpos($c, '|') !== false and is_null($v)) {
570
-		return null;
571
-	}
572
-
573
-	// lever l'#ancre
574
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
575
-		$url = $r[1];
576
-		$ancre = $r[2];
577
-	} else {
578
-		$ancre = '';
579
-	}
580
-
581
-	// eclater
582
-	$url = preg_split(',[?]|&amp;|&,', $url);
583
-
584
-	// recuperer la base
585
-	$a = array_shift($url);
586
-	if (!$a) {
587
-		$a = './';
588
-	}
589
-
590
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
591
-	$ajouts = array_flip(explode('|', $c));
592
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
593
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
594
-	$v_read = null;
595
-	// lire les variables et agir
596
-	foreach ($url as $n => $val) {
597
-		if (preg_match($regexp, urldecode($val), $r)) {
598
-			$r = array_pad($r, 3, null);
599
-			if ($v === null) {
600
-				// c'est un tableau, on memorise les valeurs
601
-				if (substr($r[1], -2) == '[]') {
602
-					if (!$v_read) {
603
-						$v_read = [];
604
-					}
605
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
606
-				} // c'est un scalaire, on retourne direct
607
-				else {
608
-					return $r[2] ? substr($r[2], 1) : '';
609
-				}
610
-			} // suppression
611
-			elseif (!$testv) {
612
-				unset($url[$n]);
613
-			}
614
-			// Ajout. Pour une variable, remplacer au meme endroit,
615
-			// pour un tableau ce sera fait dans la prochaine boucle
616
-			elseif (substr($r[1], -2) != '[]') {
617
-				$url[$n] = $r[1] . '=' . $u;
618
-				unset($ajouts[$r[1]]);
619
-			}
620
-			// Pour les tableaux on laisse tomber les valeurs de
621
-			// départ, on remplira à l'étape suivante
622
-			else {
623
-				unset($url[$n]);
624
-			}
625
-		}
626
-	}
627
-
628
-	// traiter les parametres pas encore trouves
629
-	if (
630
-		$v === null
631
-		and $args = func_get_args()
632
-		and count($args) == 2
633
-	) {
634
-		return $v_read; // rien trouve ou un tableau
635
-	} elseif ($testv) {
636
-		foreach ($ajouts as $k => $n) {
637
-			if (!is_array($v)) {
638
-				$url[] = $k . '=' . $u;
639
-			} else {
640
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
641
-				foreach ($v as $w) {
642
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
643
-				}
644
-			}
645
-		}
646
-	}
647
-
648
-	// eliminer les vides
649
-	$url = array_filter($url);
650
-
651
-	// recomposer l'adresse
652
-	if ($url) {
653
-		$a .= '?' . join($sep, $url);
654
-	}
655
-
656
-	return $a . $ancre;
567
+    // requete erronnee : plusieurs variable dans $c et aucun $v
568
+    if (strpos($c, '|') !== false and is_null($v)) {
569
+        return null;
570
+    }
571
+
572
+    // lever l'#ancre
573
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
574
+        $url = $r[1];
575
+        $ancre = $r[2];
576
+    } else {
577
+        $ancre = '';
578
+    }
579
+
580
+    // eclater
581
+    $url = preg_split(',[?]|&amp;|&,', $url);
582
+
583
+    // recuperer la base
584
+    $a = array_shift($url);
585
+    if (!$a) {
586
+        $a = './';
587
+    }
588
+
589
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
590
+    $ajouts = array_flip(explode('|', $c));
591
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
592
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
593
+    $v_read = null;
594
+    // lire les variables et agir
595
+    foreach ($url as $n => $val) {
596
+        if (preg_match($regexp, urldecode($val), $r)) {
597
+            $r = array_pad($r, 3, null);
598
+            if ($v === null) {
599
+                // c'est un tableau, on memorise les valeurs
600
+                if (substr($r[1], -2) == '[]') {
601
+                    if (!$v_read) {
602
+                        $v_read = [];
603
+                    }
604
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
605
+                } // c'est un scalaire, on retourne direct
606
+                else {
607
+                    return $r[2] ? substr($r[2], 1) : '';
608
+                }
609
+            } // suppression
610
+            elseif (!$testv) {
611
+                unset($url[$n]);
612
+            }
613
+            // Ajout. Pour une variable, remplacer au meme endroit,
614
+            // pour un tableau ce sera fait dans la prochaine boucle
615
+            elseif (substr($r[1], -2) != '[]') {
616
+                $url[$n] = $r[1] . '=' . $u;
617
+                unset($ajouts[$r[1]]);
618
+            }
619
+            // Pour les tableaux on laisse tomber les valeurs de
620
+            // départ, on remplira à l'étape suivante
621
+            else {
622
+                unset($url[$n]);
623
+            }
624
+        }
625
+    }
626
+
627
+    // traiter les parametres pas encore trouves
628
+    if (
629
+        $v === null
630
+        and $args = func_get_args()
631
+        and count($args) == 2
632
+    ) {
633
+        return $v_read; // rien trouve ou un tableau
634
+    } elseif ($testv) {
635
+        foreach ($ajouts as $k => $n) {
636
+            if (!is_array($v)) {
637
+                $url[] = $k . '=' . $u;
638
+            } else {
639
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
640
+                foreach ($v as $w) {
641
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
642
+                }
643
+            }
644
+        }
645
+    }
646
+
647
+    // eliminer les vides
648
+    $url = array_filter($url);
649
+
650
+    // recomposer l'adresse
651
+    if ($url) {
652
+        $a .= '?' . join($sep, $url);
653
+    }
654
+
655
+    return $a . $ancre;
657 656
 }
658 657
 
659 658
 /**
@@ -671,21 +670,21 @@  discard block
 block discarded – undo
671 670
  * @return string
672 671
  */
673 672
 function ancre_url($url, $ancre) {
674
-	// lever l'#ancre
675
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
676
-		$url = $r[1];
677
-	}
678
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
679
-		if (!function_exists('translitteration')) {
680
-			include_spip('inc/charsets');
681
-		}
682
-		$ancre = preg_replace(
683
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
684
-			['', '-'],
685
-			translitteration($ancre)
686
-		);
687
-	}
688
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
673
+    // lever l'#ancre
674
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
675
+        $url = $r[1];
676
+    }
677
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
678
+        if (!function_exists('translitteration')) {
679
+            include_spip('inc/charsets');
680
+        }
681
+        $ancre = preg_replace(
682
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
683
+            ['', '-'],
684
+            translitteration($ancre)
685
+        );
686
+    }
687
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
689 688
 }
690 689
 
691 690
 /**
@@ -695,16 +694,16 @@  discard block
 block discarded – undo
695 694
  * @return string
696 695
  */
697 696
 function nettoyer_uri($reset = null) {
698
-	static $done = false;
699
-	static $propre = '';
700
-	if (!is_null($reset)) {
701
-		return $propre = $reset;
702
-	}
703
-	if ($done) {
704
-		return $propre;
705
-	}
706
-	$done = true;
707
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
697
+    static $done = false;
698
+    static $propre = '';
699
+    if (!is_null($reset)) {
700
+        return $propre = $reset;
701
+    }
702
+    if ($done) {
703
+        return $propre;
704
+    }
705
+    $done = true;
706
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
708 707
 }
709 708
 
710 709
 /**
@@ -716,16 +715,16 @@  discard block
 block discarded – undo
716 715
  * @return string
717 716
  */
718 717
 function nettoyer_uri_var($request_uri) {
719
-	$uri1 = $request_uri;
720
-	do {
721
-		$uri = $uri1;
722
-		$uri1 = preg_replace(
723
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
724
-			'\1',
725
-			$uri
726
-		);
727
-	} while ($uri <> $uri1);
728
-	return preg_replace(',[?&]$,', '', $uri1);
718
+    $uri1 = $request_uri;
719
+    do {
720
+        $uri = $uri1;
721
+        $uri1 = preg_replace(
722
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
723
+            '\1',
724
+            $uri
725
+        );
726
+    } while ($uri <> $uri1);
727
+    return preg_replace(',[?&]$,', '', $uri1);
729 728
 }
730 729
 
731 730
 
@@ -739,48 +738,48 @@  discard block
 block discarded – undo
739 738
  *    URL vers soi-même
740 739
  **/
741 740
 function self($amp = '&amp;', $root = false) {
742
-	$url = nettoyer_uri();
743
-	if (
744
-		!$root
745
-		and (
746
-			// si pas de profondeur on peut tronquer
747
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
748
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
749
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
750
-	) {
751
-		$url = preg_replace(',^[^?]*/,', '', $url);
752
-	}
753
-	// ajouter le cas echeant les variables _POST['id_...']
754
-	foreach ($_POST as $v => $c) {
755
-		if (substr($v, 0, 3) == 'id_') {
756
-			$url = parametre_url($url, $v, $c, '&');
757
-		}
758
-	}
759
-
760
-	// supprimer les variables sans interet
761
-	if (test_espace_prive()) {
762
-		$url = preg_replace(',([?&])('
763
-			. 'lang|show_docs|'
764
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
765
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
766
-		$url = preg_replace(',[&]$,', '\1', $url);
767
-	}
768
-
769
-	// eviter les hacks
770
-	include_spip('inc/filtres_mini');
771
-	$url = spip_htmlspecialchars($url);
772
-
773
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
774
-
775
-	// &amp; ?
776
-	if ($amp != '&amp;') {
777
-		$url = str_replace('&amp;', $amp, $url);
778
-	}
779
-
780
-	// Si ca demarre par ? ou vide, donner './'
781
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
782
-
783
-	return $url;
741
+    $url = nettoyer_uri();
742
+    if (
743
+        !$root
744
+        and (
745
+            // si pas de profondeur on peut tronquer
746
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
747
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
748
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
749
+    ) {
750
+        $url = preg_replace(',^[^?]*/,', '', $url);
751
+    }
752
+    // ajouter le cas echeant les variables _POST['id_...']
753
+    foreach ($_POST as $v => $c) {
754
+        if (substr($v, 0, 3) == 'id_') {
755
+            $url = parametre_url($url, $v, $c, '&');
756
+        }
757
+    }
758
+
759
+    // supprimer les variables sans interet
760
+    if (test_espace_prive()) {
761
+        $url = preg_replace(',([?&])('
762
+            . 'lang|show_docs|'
763
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
764
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
765
+        $url = preg_replace(',[&]$,', '\1', $url);
766
+    }
767
+
768
+    // eviter les hacks
769
+    include_spip('inc/filtres_mini');
770
+    $url = spip_htmlspecialchars($url);
771
+
772
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
773
+
774
+    // &amp; ?
775
+    if ($amp != '&amp;') {
776
+        $url = str_replace('&amp;', $amp, $url);
777
+    }
778
+
779
+    // Si ca demarre par ? ou vide, donner './'
780
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
781
+
782
+    return $url;
784 783
 }
785 784
 
786 785
 
@@ -791,7 +790,7 @@  discard block
 block discarded – undo
791 790
  *     true si c'est le cas, false sinon.
792 791
  */
793 792
 function test_espace_prive() {
794
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
793
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
795 794
 }
796 795
 
797 796
 /**
@@ -801,7 +800,7 @@  discard block
 block discarded – undo
801 800
  * @return bool
802 801
  */
803 802
 function test_plugin_actif($plugin) {
804
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
803
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
805 804
 }
806 805
 
807 806
 /**
@@ -832,52 +831,52 @@  discard block
 block discarded – undo
832 831
  *     Texte
833 832
  */
834 833
 function _T($texte, $args = [], $options = []) {
835
-	static $traduire = false;
836
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
837
-	if ($options) {
838
-		// support de l'ancien argument $class
839
-		if (is_string($options)) {
840
-			$options = ['class' => $options];
841
-		}
842
-		$o = array_merge($o, $options);
843
-	}
844
-
845
-	if (!$traduire) {
846
-		$traduire = charger_fonction('traduire', 'inc');
847
-		include_spip('inc/lang');
848
-	}
849
-
850
-	// On peut passer explicitement la langue dans le tableau
851
-	// On utilise le même nom de variable que la globale
852
-	if (isset($args['spip_lang'])) {
853
-		$lang = $args['spip_lang'];
854
-		// On l'enleve pour ne pas le passer au remplacement
855
-		unset($args['spip_lang']);
856
-	} // Sinon on prend la langue du contexte
857
-	else {
858
-		$lang = $GLOBALS['spip_lang'];
859
-	}
860
-	$text = $traduire($texte, $lang);
861
-
862
-	if ($text === null || !strlen($text)) {
863
-		if (!$o['force']) {
864
-			return '';
865
-		}
866
-
867
-		$text = $texte;
868
-
869
-		// pour les chaines non traduites, assurer un service minimum
870
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
871
-			$n = strpos($text, ':');
872
-			if ($n !== false) {
873
-				$text = substr($text, $n + 1);
874
-			}
875
-			$text = str_replace('_', ' ', $text);
876
-		}
877
-		$o['class'] = null;
878
-	}
879
-
880
-	return _L($text, $args, $o);
834
+    static $traduire = false;
835
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
836
+    if ($options) {
837
+        // support de l'ancien argument $class
838
+        if (is_string($options)) {
839
+            $options = ['class' => $options];
840
+        }
841
+        $o = array_merge($o, $options);
842
+    }
843
+
844
+    if (!$traduire) {
845
+        $traduire = charger_fonction('traduire', 'inc');
846
+        include_spip('inc/lang');
847
+    }
848
+
849
+    // On peut passer explicitement la langue dans le tableau
850
+    // On utilise le même nom de variable que la globale
851
+    if (isset($args['spip_lang'])) {
852
+        $lang = $args['spip_lang'];
853
+        // On l'enleve pour ne pas le passer au remplacement
854
+        unset($args['spip_lang']);
855
+    } // Sinon on prend la langue du contexte
856
+    else {
857
+        $lang = $GLOBALS['spip_lang'];
858
+    }
859
+    $text = $traduire($texte, $lang);
860
+
861
+    if ($text === null || !strlen($text)) {
862
+        if (!$o['force']) {
863
+            return '';
864
+        }
865
+
866
+        $text = $texte;
867
+
868
+        // pour les chaines non traduites, assurer un service minimum
869
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
870
+            $n = strpos($text, ':');
871
+            if ($n !== false) {
872
+                $text = substr($text, $n + 1);
873
+            }
874
+            $text = str_replace('_', ' ', $text);
875
+        }
876
+        $o['class'] = null;
877
+    }
878
+
879
+    return _L($text, $args, $o);
881 880
 }
882 881
 
883 882
 
@@ -904,53 +903,53 @@  discard block
 block discarded – undo
904 903
  *     Texte
905 904
  */
906 905
 function _L($text, $args = [], $options = []) {
907
-	$f = $text;
908
-	$defaut_options = [
909
-		'class' => null,
910
-		'sanitize' => true,
911
-	];
912
-	// support de l'ancien argument $class
913
-	if ($options and is_string($options)) {
914
-		$options = ['class' => $options];
915
-	}
916
-	if (is_array($options)) {
917
-		$options += $defaut_options;
918
-	} else {
919
-		$options = $defaut_options;
920
-	}
921
-
922
-	if (is_array($args) and count($args)) {
923
-		if (!function_exists('interdire_scripts')) {
924
-			include_spip('inc/texte');
925
-		}
926
-		if (!function_exists('echapper_html_suspect')) {
927
-			include_spip('inc/texte_mini');
928
-		}
929
-		foreach ($args as $name => $value) {
930
-			if (strpos($text, (string) "@$name@") !== false) {
931
-				if ($options['sanitize']) {
932
-					$value = echapper_html_suspect($value);
933
-					$value = interdire_scripts($value, -1);
934
-				}
935
-				if (!empty($options['class'])) {
936
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
937
-				}
938
-				$text = str_replace("@$name@", $value, $text);
939
-				unset($args[$name]);
940
-			}
941
-		}
942
-		// Si des variables n'ont pas ete inserees, le signaler
943
-		// (chaines de langues pas a jour)
944
-		if ($args) {
945
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
946
-		}
947
-	}
948
-
949
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
950
-		return "<span class='debug-traduction-erreur'>$text</span>";
951
-	} else {
952
-		return $text;
953
-	}
906
+    $f = $text;
907
+    $defaut_options = [
908
+        'class' => null,
909
+        'sanitize' => true,
910
+    ];
911
+    // support de l'ancien argument $class
912
+    if ($options and is_string($options)) {
913
+        $options = ['class' => $options];
914
+    }
915
+    if (is_array($options)) {
916
+        $options += $defaut_options;
917
+    } else {
918
+        $options = $defaut_options;
919
+    }
920
+
921
+    if (is_array($args) and count($args)) {
922
+        if (!function_exists('interdire_scripts')) {
923
+            include_spip('inc/texte');
924
+        }
925
+        if (!function_exists('echapper_html_suspect')) {
926
+            include_spip('inc/texte_mini');
927
+        }
928
+        foreach ($args as $name => $value) {
929
+            if (strpos($text, (string) "@$name@") !== false) {
930
+                if ($options['sanitize']) {
931
+                    $value = echapper_html_suspect($value);
932
+                    $value = interdire_scripts($value, -1);
933
+                }
934
+                if (!empty($options['class'])) {
935
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
936
+                }
937
+                $text = str_replace("@$name@", $value, $text);
938
+                unset($args[$name]);
939
+            }
940
+        }
941
+        // Si des variables n'ont pas ete inserees, le signaler
942
+        // (chaines de langues pas a jour)
943
+        if ($args) {
944
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
945
+        }
946
+    }
947
+
948
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
949
+        return "<span class='debug-traduction-erreur'>$text</span>";
950
+    } else {
951
+        return $text;
952
+    }
954 953
 }
955 954
 
956 955
 
@@ -964,13 +963,13 @@  discard block
 block discarded – undo
964 963
  * @return string
965 964
  */
966 965
 function joli_repertoire($rep) {
967
-	$a = substr($rep, 0, 1);
968
-	if ($a <> '.' and $a <> '/') {
969
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
970
-	}
971
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
966
+    $a = substr($rep, 0, 1);
967
+    if ($a <> '.' and $a <> '/') {
968
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
969
+    }
970
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
972 971
 
973
-	return $rep;
972
+    return $rep;
974 973
 }
975 974
 
976 975
 
@@ -995,54 +994,54 @@  discard block
 block discarded – undo
995 994
  * @return float|int|string|void
996 995
  */
997 996
 function spip_timer($t = 'rien', $raw = false) {
998
-	static $time;
999
-	$a = time();
1000
-	$b = microtime();
1001
-	// microtime peut contenir les microsecondes et le temps
1002
-	$b = explode(' ', $b);
1003
-	if (count($b) == 2) {
1004
-		$a = end($b);
1005
-	} // plus precis !
1006
-	$b = reset($b);
1007
-	if (!isset($time[$t])) {
1008
-		$time[$t] = $a + $b;
1009
-	} else {
1010
-		$p = ($a + $b - $time[$t]) * 1000;
1011
-		unset($time[$t]);
997
+    static $time;
998
+    $a = time();
999
+    $b = microtime();
1000
+    // microtime peut contenir les microsecondes et le temps
1001
+    $b = explode(' ', $b);
1002
+    if (count($b) == 2) {
1003
+        $a = end($b);
1004
+    } // plus precis !
1005
+    $b = reset($b);
1006
+    if (!isset($time[$t])) {
1007
+        $time[$t] = $a + $b;
1008
+    } else {
1009
+        $p = ($a + $b - $time[$t]) * 1000;
1010
+        unset($time[$t]);
1012 1011
 #			echo "'$p'";exit;
1013
-		if ($raw) {
1014
-			return $p;
1015
-		}
1016
-		if ($p < 1000) {
1017
-			$s = '';
1018
-		} else {
1019
-			$s = sprintf('%d ', $x = floor($p / 1000));
1020
-			$p -= ($x * 1000);
1021
-		}
1012
+        if ($raw) {
1013
+            return $p;
1014
+        }
1015
+        if ($p < 1000) {
1016
+            $s = '';
1017
+        } else {
1018
+            $s = sprintf('%d ', $x = floor($p / 1000));
1019
+            $p -= ($x * 1000);
1020
+        }
1022 1021
 
1023
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1024
-	}
1022
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1023
+    }
1025 1024
 }
1026 1025
 
1027 1026
 
1028 1027
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1029 1028
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1030 1029
 function spip_touch($fichier, $duree = 0, $touch = true) {
1031
-	if ($duree) {
1032
-		clearstatcache();
1033
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1034
-			return false;
1035
-		}
1036
-	}
1037
-	if ($touch !== false) {
1038
-		if (!@touch($fichier)) {
1039
-			spip_unlink($fichier);
1040
-			@touch($fichier);
1041
-		};
1042
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1043
-	}
1030
+    if ($duree) {
1031
+        clearstatcache();
1032
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1033
+            return false;
1034
+        }
1035
+    }
1036
+    if ($touch !== false) {
1037
+        if (!@touch($fichier)) {
1038
+            spip_unlink($fichier);
1039
+            @touch($fichier);
1040
+        };
1041
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1042
+    }
1044 1043
 
1045
-	return true;
1044
+    return true;
1046 1045
 }
1047 1046
 
1048 1047
 
@@ -1053,11 +1052,11 @@  discard block
 block discarded – undo
1053 1052
  * @uses cron()
1054 1053
  **/
1055 1054
 function action_cron() {
1056
-	include_spip('inc/headers');
1057
-	http_response_code(204); // No Content
1058
-	header('Connection: close');
1059
-	define('_DIRECT_CRON_FORCE', true);
1060
-	cron();
1055
+    include_spip('inc/headers');
1056
+    http_response_code(204); // No Content
1057
+    header('Connection: close');
1058
+    define('_DIRECT_CRON_FORCE', true);
1059
+    cron();
1061 1060
 }
1062 1061
 
1063 1062
 /**
@@ -1073,26 +1072,26 @@  discard block
 block discarded – undo
1073 1072
  *     True si la tache a pu être effectuée
1074 1073
  */
1075 1074
 function cron($taches = [], $taches_old = []) {
1076
-	// si pas en mode cron force, laisser tomber.
1077
-	if (!defined('_DIRECT_CRON_FORCE')) {
1078
-		return false;
1079
-	}
1080
-	if (!is_array($taches)) {
1081
-		$taches = $taches_old;
1082
-	} // compat anciens appels
1083
-	// si taches a inserer en base et base inaccessible, laisser tomber
1084
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1085
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1086
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1087
-	if ($taches and count($taches) and !spip_connect()) {
1088
-		return false;
1089
-	}
1090
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1091
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1092
-		return $genie($taches);
1093
-	}
1094
-
1095
-	return false;
1075
+    // si pas en mode cron force, laisser tomber.
1076
+    if (!defined('_DIRECT_CRON_FORCE')) {
1077
+        return false;
1078
+    }
1079
+    if (!is_array($taches)) {
1080
+        $taches = $taches_old;
1081
+    } // compat anciens appels
1082
+    // si taches a inserer en base et base inaccessible, laisser tomber
1083
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1084
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1085
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1086
+    if ($taches and count($taches) and !spip_connect()) {
1087
+        return false;
1088
+    }
1089
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1090
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1091
+        return $genie($taches);
1092
+    }
1093
+
1094
+    return false;
1096 1095
 }
1097 1096
 
1098 1097
 /**
@@ -1124,17 +1123,17 @@  discard block
 block discarded – undo
1124 1123
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1125 1124
  */
1126 1125
 function job_queue_add(
1127
-	$function,
1128
-	$description,
1129
-	$arguments = [],
1130
-	$file = '',
1131
-	$no_duplicate = false,
1132
-	$time = 0,
1133
-	$priority = 0
1126
+    $function,
1127
+    $description,
1128
+    $arguments = [],
1129
+    $file = '',
1130
+    $no_duplicate = false,
1131
+    $time = 0,
1132
+    $priority = 0
1134 1133
 ) {
1135
-	include_spip('inc/queue');
1134
+    include_spip('inc/queue');
1136 1135
 
1137
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1136
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1138 1137
 }
1139 1138
 
1140 1139
 /**
@@ -1145,9 +1144,9 @@  discard block
 block discarded – undo
1145 1144
  * @return bool
1146 1145
  */
1147 1146
 function job_queue_remove($id_job) {
1148
-	include_spip('inc/queue');
1147
+    include_spip('inc/queue');
1149 1148
 
1150
-	return queue_remove_job($id_job);
1149
+    return queue_remove_job($id_job);
1151 1150
 }
1152 1151
 
1153 1152
 /**
@@ -1160,9 +1159,9 @@  discard block
 block discarded – undo
1160 1159
  *     or an array of simple array to link multiples objet in one time
1161 1160
  */
1162 1161
 function job_queue_link($id_job, $objets) {
1163
-	include_spip('inc/queue');
1162
+    include_spip('inc/queue');
1164 1163
 
1165
-	return queue_link_job($id_job, $objets);
1164
+    return queue_link_job($id_job, $objets);
1166 1165
 }
1167 1166
 
1168 1167
 
@@ -1182,36 +1181,36 @@  discard block
 block discarded – undo
1182 1181
  *  - `null` si la queue n'est pas encore initialisée
1183 1182
  */
1184 1183
 function queue_sleep_time_to_next_job($force = null) {
1185
-	static $queue_next_job_time = -1;
1186
-	if ($force === true) {
1187
-		$queue_next_job_time = -1;
1188
-	} elseif ($force) {
1189
-		$queue_next_job_time = $force;
1190
-	}
1191
-
1192
-	if ($queue_next_job_time == -1) {
1193
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1194
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1195
-		}
1196
-		// utiliser un cache memoire si dispo
1197
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1198
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1199
-		} else {
1200
-			$queue_next_job_time = null;
1201
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1202
-				$queue_next_job_time = intval($contenu);
1203
-			}
1204
-		}
1205
-	}
1206
-
1207
-	if (is_null($queue_next_job_time)) {
1208
-		return null;
1209
-	}
1210
-	if (!$_SERVER['REQUEST_TIME']) {
1211
-		$_SERVER['REQUEST_TIME'] = time();
1212
-	}
1213
-
1214
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1184
+    static $queue_next_job_time = -1;
1185
+    if ($force === true) {
1186
+        $queue_next_job_time = -1;
1187
+    } elseif ($force) {
1188
+        $queue_next_job_time = $force;
1189
+    }
1190
+
1191
+    if ($queue_next_job_time == -1) {
1192
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1193
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1194
+        }
1195
+        // utiliser un cache memoire si dispo
1196
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1197
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1198
+        } else {
1199
+            $queue_next_job_time = null;
1200
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1201
+                $queue_next_job_time = intval($contenu);
1202
+            }
1203
+        }
1204
+    }
1205
+
1206
+    if (is_null($queue_next_job_time)) {
1207
+        return null;
1208
+    }
1209
+    if (!$_SERVER['REQUEST_TIME']) {
1210
+        $_SERVER['REQUEST_TIME'] = time();
1211
+    }
1212
+
1213
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1215 1214
 }
1216 1215
 
1217 1216
 
@@ -1223,11 +1222,11 @@  discard block
 block discarded – undo
1223 1222
  * @return string
1224 1223
  */
1225 1224
 function quote_amp($u) {
1226
-	return preg_replace(
1227
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1228
-		'&amp;',
1229
-		$u
1230
-	);
1225
+    return preg_replace(
1226
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1227
+        '&amp;',
1228
+        $u
1229
+    );
1231 1230
 }
1232 1231
 
1233 1232
 
@@ -1250,27 +1249,27 @@  discard block
 block discarded – undo
1250 1249
  *     Balise HTML `<script>` et son contenu
1251 1250
  **/
1252 1251
 function http_script($script, $src = '', $noscript = '') {
1253
-	static $done = [];
1252
+    static $done = [];
1254 1253
 
1255
-	if ($src && !isset($done[$src])) {
1256
-		$done[$src] = true;
1257
-		$src = find_in_path($src, _JAVASCRIPT);
1258
-		$src = " src='$src'";
1259
-	} else {
1260
-		$src = '';
1261
-	}
1262
-	if ($script) {
1263
-		$script = ("/*<![CDATA[*/\n" .
1264
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1265
-			'/*]]>*/');
1266
-	}
1267
-	if ($noscript) {
1268
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1269
-	}
1254
+    if ($src && !isset($done[$src])) {
1255
+        $done[$src] = true;
1256
+        $src = find_in_path($src, _JAVASCRIPT);
1257
+        $src = " src='$src'";
1258
+    } else {
1259
+        $src = '';
1260
+    }
1261
+    if ($script) {
1262
+        $script = ("/*<![CDATA[*/\n" .
1263
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1264
+            '/*]]>*/');
1265
+    }
1266
+    if ($noscript) {
1267
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1268
+    }
1270 1269
 
1271
-	return ($src or $script or $noscript)
1272
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1273
-		: '';
1270
+    return ($src or $script or $noscript)
1271
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1272
+        : '';
1274 1273
 }
1275 1274
 
1276 1275
 
@@ -1305,7 +1304,7 @@  discard block
 block discarded – undo
1305 1304
  *     Texte échappé
1306 1305
  **/
1307 1306
 function texte_script(string $texte): string {
1308
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1307
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1309 1308
 }
1310 1309
 
1311 1310
 
@@ -1342,68 +1341,68 @@  discard block
 block discarded – undo
1342 1341
  *     Liste des chemins, par ordre de priorité.
1343 1342
  **/
1344 1343
 function _chemin($dir_path = null) {
1345
-	static $path_base = null;
1346
-	static $path_full = null;
1347
-	if ($path_base == null) {
1348
-		// Chemin standard depuis l'espace public
1349
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1350
-			_DIR_RACINE . ':' .
1351
-			_DIR_RACINE . 'squelettes-dist/:' .
1352
-			_DIR_RACINE . 'prive/:' .
1353
-			_DIR_RESTREINT;
1354
-		// Ajouter squelettes/
1355
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1356
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1357
-		}
1358
-		foreach (explode(':', $path) as $dir) {
1359
-			if (strlen($dir) and substr($dir, -1) != '/') {
1360
-				$dir .= '/';
1361
-			}
1362
-			$path_base[] = $dir;
1363
-		}
1364
-		$path_full = $path_base;
1365
-		// Et le(s) dossier(s) des squelettes nommes
1366
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1367
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1368
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1369
-			}
1370
-		}
1371
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1372
-	}
1373
-	if ($dir_path === null) {
1374
-		return $path_full;
1375
-	}
1376
-
1377
-	if (is_array($dir_path) or strlen($dir_path)) {
1378
-		$tete = '';
1379
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1380
-			$tete = array_shift($path_base);
1381
-		}
1382
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1383
-		$dirs = array_reverse($dirs);
1384
-		foreach ($dirs as $dir_path) {
1385
-			if (substr($dir_path, -1) != '/') {
1386
-				$dir_path .= '/';
1387
-			}
1388
-			if (!in_array($dir_path, $path_base)) {
1389
-				array_unshift($path_base, $dir_path);
1390
-			}
1391
-		}
1392
-		if (strlen($tete)) {
1393
-			array_unshift($path_base, $tete);
1394
-		}
1395
-	}
1396
-	$path_full = $path_base;
1397
-	// Et le(s) dossier(s) des squelettes nommes
1398
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1399
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1400
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1401
-		}
1402
-	}
1403
-
1404
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1405
-
1406
-	return $path_full;
1344
+    static $path_base = null;
1345
+    static $path_full = null;
1346
+    if ($path_base == null) {
1347
+        // Chemin standard depuis l'espace public
1348
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1349
+            _DIR_RACINE . ':' .
1350
+            _DIR_RACINE . 'squelettes-dist/:' .
1351
+            _DIR_RACINE . 'prive/:' .
1352
+            _DIR_RESTREINT;
1353
+        // Ajouter squelettes/
1354
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1355
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1356
+        }
1357
+        foreach (explode(':', $path) as $dir) {
1358
+            if (strlen($dir) and substr($dir, -1) != '/') {
1359
+                $dir .= '/';
1360
+            }
1361
+            $path_base[] = $dir;
1362
+        }
1363
+        $path_full = $path_base;
1364
+        // Et le(s) dossier(s) des squelettes nommes
1365
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1366
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1367
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1368
+            }
1369
+        }
1370
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1371
+    }
1372
+    if ($dir_path === null) {
1373
+        return $path_full;
1374
+    }
1375
+
1376
+    if (is_array($dir_path) or strlen($dir_path)) {
1377
+        $tete = '';
1378
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1379
+            $tete = array_shift($path_base);
1380
+        }
1381
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1382
+        $dirs = array_reverse($dirs);
1383
+        foreach ($dirs as $dir_path) {
1384
+            if (substr($dir_path, -1) != '/') {
1385
+                $dir_path .= '/';
1386
+            }
1387
+            if (!in_array($dir_path, $path_base)) {
1388
+                array_unshift($path_base, $dir_path);
1389
+            }
1390
+        }
1391
+        if (strlen($tete)) {
1392
+            array_unshift($path_base, $tete);
1393
+        }
1394
+    }
1395
+    $path_full = $path_base;
1396
+    // Et le(s) dossier(s) des squelettes nommes
1397
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1398
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1399
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1400
+        }
1401
+    }
1402
+
1403
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1404
+
1405
+    return $path_full;
1407 1406
 }
1408 1407
 
1409 1408
 /**
@@ -1416,78 +1415,78 @@  discard block
 block discarded – undo
1416 1415
  * @return array Liste de chemins
1417 1416
  **/
1418 1417
 function creer_chemin() {
1419
-	$path_a = _chemin();
1420
-	static $c = '';
1418
+    $path_a = _chemin();
1419
+    static $c = '';
1421 1420
 
1422
-	// on calcule le chemin si le dossier skel a change
1423
-	if ($c != $GLOBALS['dossier_squelettes']) {
1424
-		// assurer le non plantage lors de la montee de version :
1425
-		$c = $GLOBALS['dossier_squelettes'];
1426
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1427
-	}
1421
+    // on calcule le chemin si le dossier skel a change
1422
+    if ($c != $GLOBALS['dossier_squelettes']) {
1423
+        // assurer le non plantage lors de la montee de version :
1424
+        $c = $GLOBALS['dossier_squelettes'];
1425
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1426
+    }
1428 1427
 
1429
-	return $path_a;
1428
+    return $path_a;
1430 1429
 }
1431 1430
 
1432 1431
 
1433 1432
 function lister_themes_prives() {
1434
-	static $themes = null;
1435
-	if (is_null($themes)) {
1436
-		// si pas encore definie
1437
-		if (!defined('_SPIP_THEME_PRIVE')) {
1438
-			define('_SPIP_THEME_PRIVE', 'spip');
1439
-		}
1440
-		$themes = [_SPIP_THEME_PRIVE];
1441
-		// lors d'une installation neuve, prefs n'est pas definie.
1442
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1443
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1444
-		} else {
1445
-			$prefs = [];
1446
-		}
1447
-		if (is_string($prefs)) {
1448
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1449
-		}
1450
-		if (
1451
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1452
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1453
-			and $theme != _SPIP_THEME_PRIVE
1454
-		) {
1455
-			array_unshift($themes, $theme);
1456
-		} // placer le theme choisi en tete
1457
-	}
1458
-
1459
-	return $themes;
1433
+    static $themes = null;
1434
+    if (is_null($themes)) {
1435
+        // si pas encore definie
1436
+        if (!defined('_SPIP_THEME_PRIVE')) {
1437
+            define('_SPIP_THEME_PRIVE', 'spip');
1438
+        }
1439
+        $themes = [_SPIP_THEME_PRIVE];
1440
+        // lors d'une installation neuve, prefs n'est pas definie.
1441
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1442
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1443
+        } else {
1444
+            $prefs = [];
1445
+        }
1446
+        if (is_string($prefs)) {
1447
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1448
+        }
1449
+        if (
1450
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1451
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1452
+            and $theme != _SPIP_THEME_PRIVE
1453
+        ) {
1454
+            array_unshift($themes, $theme);
1455
+        } // placer le theme choisi en tete
1456
+    }
1457
+
1458
+    return $themes;
1460 1459
 }
1461 1460
 
1462 1461
 function find_in_theme($file, $subdir = '', $include = false) {
1463
-	static $themefiles = [];
1464
-	if (isset($themefiles["$subdir$file"])) {
1465
-		return $themefiles["$subdir$file"];
1466
-	}
1467
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1468
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1469
-	if (
1470
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1471
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1472
-		and $f = find_in_theme("$file_svg_generique")
1473
-	) {
1474
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1475
-			return $themefiles["$subdir$file"] = $fsize;
1476
-		}
1477
-		else {
1478
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1479
-		}
1480
-	}
1481
-
1482
-	$themes = lister_themes_prives();
1483
-	foreach ($themes as $theme) {
1484
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1485
-			return $themefiles["$subdir$file"] = $f;
1486
-		}
1487
-	}
1488
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1489
-
1490
-	return $themefiles["$subdir$file"] = '';
1462
+    static $themefiles = [];
1463
+    if (isset($themefiles["$subdir$file"])) {
1464
+        return $themefiles["$subdir$file"];
1465
+    }
1466
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1467
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1468
+    if (
1469
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1470
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1471
+        and $f = find_in_theme("$file_svg_generique")
1472
+    ) {
1473
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1474
+            return $themefiles["$subdir$file"] = $fsize;
1475
+        }
1476
+        else {
1477
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1478
+        }
1479
+    }
1480
+
1481
+    $themes = lister_themes_prives();
1482
+    foreach ($themes as $theme) {
1483
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1484
+            return $themefiles["$subdir$file"] = $f;
1485
+        }
1486
+    }
1487
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1488
+
1489
+    return $themefiles["$subdir$file"] = '';
1491 1490
 }
1492 1491
 
1493 1492
 
@@ -1511,31 +1510,31 @@  discard block
 block discarded – undo
1511 1510
  *     sinon chaîne vide.
1512 1511
  **/
1513 1512
 function chemin_image($icone) {
1514
-	static $icone_renommer;
1515
-	if ($p = strpos($icone, '?')) {
1516
-		$icone = substr($icone, 0, $p);
1517
-	}
1518
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1519
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1520
-		return $icone;
1521
-	}
1522
-
1523
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1524
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1525
-		return $f;
1526
-	}
1527
-	// sinon passer par le module de renommage
1528
-	if (is_null($icone_renommer)) {
1529
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1530
-	}
1531
-	if ($icone_renommer) {
1532
-		[$icone, $fonction] = $icone_renommer($icone, '');
1533
-		if (file_exists($icone)) {
1534
-			return $icone;
1535
-		}
1536
-	}
1537
-
1538
-	return find_in_path($icone, _NOM_IMG_PACK);
1513
+    static $icone_renommer;
1514
+    if ($p = strpos($icone, '?')) {
1515
+        $icone = substr($icone, 0, $p);
1516
+    }
1517
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1518
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1519
+        return $icone;
1520
+    }
1521
+
1522
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1523
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1524
+        return $f;
1525
+    }
1526
+    // sinon passer par le module de renommage
1527
+    if (is_null($icone_renommer)) {
1528
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1529
+    }
1530
+    if ($icone_renommer) {
1531
+        [$icone, $fonction] = $icone_renommer($icone, '');
1532
+        if (file_exists($icone)) {
1533
+            return $icone;
1534
+        }
1535
+    }
1536
+
1537
+    return find_in_path($icone, _NOM_IMG_PACK);
1539 1538
 }
1540 1539
 
1541 1540
 //
@@ -1573,128 +1572,128 @@  discard block
 block discarded – undo
1573 1572
  *     - false : fichier introuvable
1574 1573
  **/
1575 1574
 function find_in_path($file, $dirname = '', $include = false) {
1576
-	static $dirs = [];
1577
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1578
-	static $c = '';
1579
-
1580
-	if (!$file and !strlen($file)) {
1581
-		return false;
1582
-	}
1583
-
1584
-	// on calcule le chemin si le dossier skel a change
1585
-	if ($c != $GLOBALS['dossier_squelettes']) {
1586
-		// assurer le non plantage lors de la montee de version :
1587
-		$c = $GLOBALS['dossier_squelettes'];
1588
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1589
-	}
1590
-
1591
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1592
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1593
-			return false;
1594
-		}
1595
-		if ($include and !isset($inc[$dirname][$file])) {
1596
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1597
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1598
-		}
1599
-
1600
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1601
-	}
1602
-
1603
-	$a = strrpos($file, '/');
1604
-	if ($a !== false) {
1605
-		$dirname .= substr($file, 0, ++$a);
1606
-		$file = substr($file, $a);
1607
-	}
1608
-
1609
-	foreach (creer_chemin() as $dir) {
1610
-		if (!isset($dirs[$a = $dir . $dirname])) {
1611
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1612
-		}
1613
-		if ($dirs[$a]) {
1614
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1615
-				if ($include and !isset($inc[$dirname][$file])) {
1616
-					include_once _ROOT_CWD . $a;
1617
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1618
-				}
1619
-				if (!defined('_SAUVER_CHEMIN')) {
1620
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1621
-					if (is_null($GLOBALS['path_files'])) {
1622
-						return $a;
1623
-					}
1624
-					define('_SAUVER_CHEMIN', true);
1625
-				}
1626
-
1627
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1628
-			}
1629
-		}
1630
-	}
1631
-
1632
-	if ($include) {
1633
-		spip_log("include_spip $dirname$file non trouve");
1634
-		if ($include === 'required') {
1635
-			echo '<pre>',
1636
-			'<strong>Erreur Fatale</strong><br />';
1637
-			if (function_exists('debug_print_backtrace')) {
1638
-				echo debug_print_backtrace();
1639
-			}
1640
-			echo '</pre>';
1641
-			die("Erreur interne: ne peut inclure $dirname$file");
1642
-		}
1643
-	}
1644
-
1645
-	if (!defined('_SAUVER_CHEMIN')) {
1646
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1647
-		if (is_null($GLOBALS['path_files'])) {
1648
-			return false;
1649
-		}
1650
-		define('_SAUVER_CHEMIN', true);
1651
-	}
1652
-
1653
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1575
+    static $dirs = [];
1576
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1577
+    static $c = '';
1578
+
1579
+    if (!$file and !strlen($file)) {
1580
+        return false;
1581
+    }
1582
+
1583
+    // on calcule le chemin si le dossier skel a change
1584
+    if ($c != $GLOBALS['dossier_squelettes']) {
1585
+        // assurer le non plantage lors de la montee de version :
1586
+        $c = $GLOBALS['dossier_squelettes'];
1587
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1588
+    }
1589
+
1590
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1591
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1592
+            return false;
1593
+        }
1594
+        if ($include and !isset($inc[$dirname][$file])) {
1595
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1596
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1597
+        }
1598
+
1599
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1600
+    }
1601
+
1602
+    $a = strrpos($file, '/');
1603
+    if ($a !== false) {
1604
+        $dirname .= substr($file, 0, ++$a);
1605
+        $file = substr($file, $a);
1606
+    }
1607
+
1608
+    foreach (creer_chemin() as $dir) {
1609
+        if (!isset($dirs[$a = $dir . $dirname])) {
1610
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1611
+        }
1612
+        if ($dirs[$a]) {
1613
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1614
+                if ($include and !isset($inc[$dirname][$file])) {
1615
+                    include_once _ROOT_CWD . $a;
1616
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1617
+                }
1618
+                if (!defined('_SAUVER_CHEMIN')) {
1619
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1620
+                    if (is_null($GLOBALS['path_files'])) {
1621
+                        return $a;
1622
+                    }
1623
+                    define('_SAUVER_CHEMIN', true);
1624
+                }
1625
+
1626
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1627
+            }
1628
+        }
1629
+    }
1630
+
1631
+    if ($include) {
1632
+        spip_log("include_spip $dirname$file non trouve");
1633
+        if ($include === 'required') {
1634
+            echo '<pre>',
1635
+            '<strong>Erreur Fatale</strong><br />';
1636
+            if (function_exists('debug_print_backtrace')) {
1637
+                echo debug_print_backtrace();
1638
+            }
1639
+            echo '</pre>';
1640
+            die("Erreur interne: ne peut inclure $dirname$file");
1641
+        }
1642
+    }
1643
+
1644
+    if (!defined('_SAUVER_CHEMIN')) {
1645
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1646
+        if (is_null($GLOBALS['path_files'])) {
1647
+            return false;
1648
+        }
1649
+        define('_SAUVER_CHEMIN', true);
1650
+    }
1651
+
1652
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1654 1653
 }
1655 1654
 
1656 1655
 function clear_path_cache() {
1657
-	$GLOBALS['path_files'] = [];
1658
-	spip_unlink(_CACHE_CHEMIN);
1656
+    $GLOBALS['path_files'] = [];
1657
+    spip_unlink(_CACHE_CHEMIN);
1659 1658
 }
1660 1659
 
1661 1660
 function load_path_cache() {
1662
-	// charger le path des plugins
1663
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1664
-		include_once(_CACHE_PLUGINS_PATH);
1665
-	}
1666
-	$GLOBALS['path_files'] = [];
1667
-	// si le visiteur est admin,
1668
-	// on ne recharge pas le cache pour forcer sa mise a jour
1669
-	if (
1670
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1671
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1672
-		// utiliser le cookie est un pis aller qui marche 'en general'
1673
-		// on blinde par un second test au moment de la lecture de la session
1674
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1675
-		// et en ignorant ce cache en cas de recalcul explicite
1676
-		!_request('var_mode')
1677
-	) {
1678
-		// on essaye de lire directement sans verrou pour aller plus vite
1679
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1680
-			// mais si semble corrompu on relit avec un verrou
1681
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1682
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1683
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1684
-					$GLOBALS['path_files'] = [];
1685
-				}
1686
-			}
1687
-		}
1688
-	}
1661
+    // charger le path des plugins
1662
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1663
+        include_once(_CACHE_PLUGINS_PATH);
1664
+    }
1665
+    $GLOBALS['path_files'] = [];
1666
+    // si le visiteur est admin,
1667
+    // on ne recharge pas le cache pour forcer sa mise a jour
1668
+    if (
1669
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1670
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1671
+        // utiliser le cookie est un pis aller qui marche 'en general'
1672
+        // on blinde par un second test au moment de la lecture de la session
1673
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1674
+        // et en ignorant ce cache en cas de recalcul explicite
1675
+        !_request('var_mode')
1676
+    ) {
1677
+        // on essaye de lire directement sans verrou pour aller plus vite
1678
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1679
+            // mais si semble corrompu on relit avec un verrou
1680
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1681
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1682
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1683
+                    $GLOBALS['path_files'] = [];
1684
+                }
1685
+            }
1686
+        }
1687
+    }
1689 1688
 }
1690 1689
 
1691 1690
 function save_path_cache() {
1692
-	if (
1693
-		defined('_SAUVER_CHEMIN')
1694
-		and _SAUVER_CHEMIN
1695
-	) {
1696
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1697
-	}
1691
+    if (
1692
+        defined('_SAUVER_CHEMIN')
1693
+        and _SAUVER_CHEMIN
1694
+    ) {
1695
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1696
+    }
1698 1697
 }
1699 1698
 
1700 1699
 
@@ -1714,33 +1713,33 @@  discard block
 block discarded – undo
1714 1713
  * @return array
1715 1714
  */
1716 1715
 function find_all_in_path($dir, $pattern, $recurs = false) {
1717
-	$liste_fichiers = [];
1718
-	$maxfiles = 10000;
1719
-
1720
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1721
-	// on a pas encore inclus flock.php
1722
-	if (!function_exists('preg_files')) {
1723
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1724
-	}
1725
-
1726
-	// Parcourir le chemin
1727
-	foreach (creer_chemin() as $d) {
1728
-		$f = $d . $dir;
1729
-		if (@is_dir($f)) {
1730
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1731
-			foreach ($liste as $chemin) {
1732
-				$nom = basename($chemin);
1733
-				// ne prendre que les fichiers pas deja trouves
1734
-				// car find_in_path prend le premier qu'il trouve,
1735
-				// les autres sont donc masques
1736
-				if (!isset($liste_fichiers[$nom])) {
1737
-					$liste_fichiers[$nom] = $chemin;
1738
-				}
1739
-			}
1740
-		}
1741
-	}
1742
-
1743
-	return $liste_fichiers;
1716
+    $liste_fichiers = [];
1717
+    $maxfiles = 10000;
1718
+
1719
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1720
+    // on a pas encore inclus flock.php
1721
+    if (!function_exists('preg_files')) {
1722
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1723
+    }
1724
+
1725
+    // Parcourir le chemin
1726
+    foreach (creer_chemin() as $d) {
1727
+        $f = $d . $dir;
1728
+        if (@is_dir($f)) {
1729
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1730
+            foreach ($liste as $chemin) {
1731
+                $nom = basename($chemin);
1732
+                // ne prendre que les fichiers pas deja trouves
1733
+                // car find_in_path prend le premier qu'il trouve,
1734
+                // les autres sont donc masques
1735
+                if (!isset($liste_fichiers[$nom])) {
1736
+                    $liste_fichiers[$nom] = $chemin;
1737
+                }
1738
+            }
1739
+        }
1740
+    }
1741
+
1742
+    return $liste_fichiers;
1744 1743
 }
1745 1744
 
1746 1745
 /**
@@ -1752,17 +1751,17 @@  discard block
 block discarded – undo
1752 1751
  * @return bool
1753 1752
  */
1754 1753
 function autoriser_sans_cookie($nom, $strict = false) {
1755
-	static $autsanscookie = ['install', 'base_repair'];
1754
+    static $autsanscookie = ['install', 'base_repair'];
1756 1755
 
1757
-	if (in_array($nom, $autsanscookie)) {
1758
-		if (test_espace_prive()) {
1759
-			include_spip('base/connect_sql');
1760
-			if (!$strict or !spip_connect()) {
1761
-				return true;
1762
-			}
1763
-		}
1764
-	}
1765
-	return false;
1756
+    if (in_array($nom, $autsanscookie)) {
1757
+        if (test_espace_prive()) {
1758
+            include_spip('base/connect_sql');
1759
+            if (!$strict or !spip_connect()) {
1760
+                return true;
1761
+            }
1762
+        }
1763
+    }
1764
+    return false;
1766 1765
 }
1767 1766
 
1768 1767
 /**
@@ -1772,56 +1771,56 @@  discard block
 block discarded – undo
1772 1771
  * @return string
1773 1772
  */
1774 1773
 function charger_fonction_url(string $quoi, string $type = '') {
1775
-	if ($type === 'defaut') {
1776
-		$objet = objet_type($quoi);
1777
-		if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1778
-			// deprecated
1779
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1780
-		) {
1781
-			return $f;
1782
-		}
1783
-		return '';
1784
-	}
1785
-
1786
-	if (!$type) {
1787
-		$type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1788
-	}
1789
-
1790
-	// inclure le module d'url
1791
-	include_spip('urls/'.$type);
1792
-
1793
-	switch ($quoi) {
1794
-		case 'page':
1795
-			if (
1796
-				 function_exists($f = "urls_{$type}_generer_url_page")
1797
-			  or function_exists($f .= "_dist")
1798
-			  // ou une fonction custom utilisateur independante du type d'url
1799
-			  or function_exists($f = "generer_url_page")
1800
-			  or function_exists($f .= "_dist")
1801
-			) {
1802
-				return $f;
1803
-			}
1804
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1805
-			return '';
1806
-		case 'objet':
1807
-		case 'decoder':
1808
-		default:
1809
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1810
-			if (function_exists($f = "urls_{$type}_{$fquoi}")
1811
-			  or function_exists($f .= "_dist")) {
1812
-				return $f;
1813
-			}
1814
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1815
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1816
-			if ($f = charger_fonction($type, 'urls', true)) {
1817
-				return $f;
1818
-			}
1819
-			// sinon on se rabat sur les urls page
1820
-			if ($type !== 'page') {
1821
-				return charger_fonction_url($quoi, 'page');
1822
-			}
1823
-			return '';
1824
-	}
1774
+    if ($type === 'defaut') {
1775
+        $objet = objet_type($quoi);
1776
+        if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1777
+            // deprecated
1778
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1779
+        ) {
1780
+            return $f;
1781
+        }
1782
+        return '';
1783
+    }
1784
+
1785
+    if (!$type) {
1786
+        $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1787
+    }
1788
+
1789
+    // inclure le module d'url
1790
+    include_spip('urls/'.$type);
1791
+
1792
+    switch ($quoi) {
1793
+        case 'page':
1794
+            if (
1795
+                    function_exists($f = "urls_{$type}_generer_url_page")
1796
+              or function_exists($f .= "_dist")
1797
+                // ou une fonction custom utilisateur independante du type d'url
1798
+              or function_exists($f = "generer_url_page")
1799
+              or function_exists($f .= "_dist")
1800
+            ) {
1801
+                return $f;
1802
+            }
1803
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1804
+            return '';
1805
+        case 'objet':
1806
+        case 'decoder':
1807
+        default:
1808
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1809
+            if (function_exists($f = "urls_{$type}_{$fquoi}")
1810
+              or function_exists($f .= "_dist")) {
1811
+                return $f;
1812
+            }
1813
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1814
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1815
+            if ($f = charger_fonction($type, 'urls', true)) {
1816
+                return $f;
1817
+            }
1818
+            // sinon on se rabat sur les urls page
1819
+            if ($type !== 'page') {
1820
+                return charger_fonction_url($quoi, 'page');
1821
+            }
1822
+            return '';
1823
+    }
1825 1824
 }
1826 1825
 
1827 1826
 
@@ -1850,47 +1849,47 @@  discard block
 block discarded – undo
1850 1849
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire)
1851 1850
  */
1852 1851
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1853
-	if ($public === null) {
1854
-		$public = !test_espace_prive();
1855
-	}
1856
-	$id = intval($id);
1857
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1858
-
1859
-	if (!$public) {
1860
-		if (!$entite) {
1861
-			return '';
1862
-		}
1863
-		if (!function_exists('generer_objet_url_ecrire')) {
1864
-			include_spip('inc/urls');
1865
-		}
1866
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1867
-	} else {
1868
-		$f = charger_fonction_url('objet', $type ?? '');
1869
-
1870
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1871
-		// @see charger_fonction_url
1872
-		if (!$entite) {
1873
-			return $f;
1874
-		}
1875
-
1876
-		// mais d'abord il faut tester le cas des urls sur une
1877
-		// base distante
1878
-		if ($connect
1879
-			and $g = charger_fonction('connect', 'urls', true)
1880
-		) {
1881
-			$f = $g;
1882
-		}
1883
-
1884
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1885
-	}
1886
-	if ($res) {
1887
-		return $res;
1888
-	}
1889
-
1890
-	// On a ete gentil mais la ....
1891
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1892
-
1893
-	return '';
1852
+    if ($public === null) {
1853
+        $public = !test_espace_prive();
1854
+    }
1855
+    $id = intval($id);
1856
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1857
+
1858
+    if (!$public) {
1859
+        if (!$entite) {
1860
+            return '';
1861
+        }
1862
+        if (!function_exists('generer_objet_url_ecrire')) {
1863
+            include_spip('inc/urls');
1864
+        }
1865
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1866
+    } else {
1867
+        $f = charger_fonction_url('objet', $type ?? '');
1868
+
1869
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1870
+        // @see charger_fonction_url
1871
+        if (!$entite) {
1872
+            return $f;
1873
+        }
1874
+
1875
+        // mais d'abord il faut tester le cas des urls sur une
1876
+        // base distante
1877
+        if ($connect
1878
+            and $g = charger_fonction('connect', 'urls', true)
1879
+        ) {
1880
+            $f = $g;
1881
+        }
1882
+
1883
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1884
+    }
1885
+    if ($res) {
1886
+        return $res;
1887
+    }
1888
+
1889
+    // On a ete gentil mais la ....
1890
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1891
+
1892
+    return '';
1894 1893
 }
1895 1894
 
1896 1895
 /**
@@ -1898,10 +1897,10 @@  discard block
 block discarded – undo
1898 1897
  * @see generer_objet_url
1899 1898
  */
1900 1899
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null){
1901
-	if ($public and is_string($public)) {
1902
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1903
-	}
1904
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1900
+    if ($public and is_string($public)) {
1901
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1902
+    }
1903
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1905 1904
 }
1906 1905
 
1907 1906
 /**
@@ -1913,19 +1912,19 @@  discard block
 block discarded – undo
1913 1912
  * @return string
1914 1913
  */
1915 1914
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1916
-	$id = intval($id);
1917
-	$exec = objet_info($entite, 'url_edit');
1918
-	$url = generer_url_ecrire($exec, $args);
1919
-	if (intval($id)) {
1920
-		$url = parametre_url($url, id_table_objet($entite), $id);
1921
-	} else {
1922
-		$url = parametre_url($url, 'new', 'oui');
1923
-	}
1924
-	if ($ancre) {
1925
-		$url = ancre_url($url, $ancre);
1926
-	}
1915
+    $id = intval($id);
1916
+    $exec = objet_info($entite, 'url_edit');
1917
+    $url = generer_url_ecrire($exec, $args);
1918
+    if (intval($id)) {
1919
+        $url = parametre_url($url, id_table_objet($entite), $id);
1920
+    } else {
1921
+        $url = parametre_url($url, 'new', 'oui');
1922
+    }
1923
+    if ($ancre) {
1924
+        $url = ancre_url($url, $ancre);
1925
+    }
1927 1926
 
1928
-	return $url;
1927
+    return $url;
1929 1928
 }
1930 1929
 
1931 1930
 /**
@@ -1933,18 +1932,18 @@  discard block
 block discarded – undo
1933 1932
  * @see generer_objet_url_ecrire_edit
1934 1933
  */
1935 1934
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = ''){
1936
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1935
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1937 1936
 }
1938 1937
 
1939 1938
 
1940 1939
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1941
-	include_spip('base/connect_sql');
1942
-	$id_type = id_table_objet($entite, $public);
1940
+    include_spip('base/connect_sql');
1941
+    $id_type = id_table_objet($entite, $public);
1943 1942
 
1944
-	return _DIR_RACINE . get_spip_script('./')
1945
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1946
-	. (!$args ? '' : "&$args")
1947
-	. (!$ancre ? '' : "#$ancre");
1943
+    return _DIR_RACINE . get_spip_script('./')
1944
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1945
+    . (!$args ? '' : "&$args")
1946
+    . (!$ancre ? '' : "#$ancre");
1948 1947
 }
1949 1948
 
1950 1949
 
@@ -1955,18 +1954,18 @@  discard block
 block discarded – undo
1955 1954
  * @return string
1956 1955
  */
1957 1956
 function urlencode_1738($url) {
1958
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1959
-		$uri = '';
1960
-		for ($i = 0; $i < strlen($url); $i++) {
1961
-			if (ord($a = $url[$i]) > 127) {
1962
-				$a = rawurlencode($a);
1963
-			}
1964
-			$uri .= $a;
1965
-		}
1966
-		$url = $uri;
1967
-	}
1957
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1958
+        $uri = '';
1959
+        for ($i = 0; $i < strlen($url); $i++) {
1960
+            if (ord($a = $url[$i]) > 127) {
1961
+                $a = rawurlencode($a);
1962
+            }
1963
+            $uri .= $a;
1964
+        }
1965
+        $url = $uri;
1966
+    }
1968 1967
 
1969
-	return quote_amp($url);
1968
+    return quote_amp($url);
1970 1969
 }
1971 1970
 
1972 1971
 /**
@@ -1982,14 +1981,14 @@  discard block
 block discarded – undo
1982 1981
  * @return string
1983 1982
  */
1984 1983
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1985
-	$id = intval($id);
1986
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1987
-	if (!preg_match(',^\w+:,', $h)) {
1988
-		include_spip('inc/filtres_mini');
1989
-		$h = url_absolue($h);
1990
-	}
1984
+    $id = intval($id);
1985
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1986
+    if (!preg_match(',^\w+:,', $h)) {
1987
+        include_spip('inc/filtres_mini');
1988
+        $h = url_absolue($h);
1989
+    }
1991 1990
 
1992
-	return $h;
1991
+    return $h;
1993 1992
 }
1994 1993
 
1995 1994
 /**
@@ -1997,7 +1996,7 @@  discard block
 block discarded – undo
1997 1996
  * @see  generer_objet_url_absolue
1998 1997
  */
1999 1998
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null){
2000
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
1999
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
2001 2000
 }
2002 2001
 
2003 2002
 
@@ -2013,11 +2012,11 @@  discard block
 block discarded – undo
2013 2012
  *     true si la valeur est considérée active ; false sinon.
2014 2013
  **/
2015 2014
 function test_valeur_serveur($truc) {
2016
-	if (!$truc) {
2017
-		return false;
2018
-	}
2015
+    if (!$truc) {
2016
+        return false;
2017
+    }
2019 2018
 
2020
-	return (strtolower($truc) !== 'off');
2019
+    return (strtolower($truc) !== 'off');
2021 2020
 }
2022 2021
 
2023 2022
 //
@@ -2045,82 +2044,82 @@  discard block
 block discarded – undo
2045 2044
  */
2046 2045
 function url_de_base($profondeur = null) {
2047 2046
 
2048
-	static $url = [];
2049
-	if (is_array($profondeur)) {
2050
-		return $url = $profondeur;
2051
-	}
2052
-	if ($profondeur === false) {
2053
-		return $url;
2054
-	}
2055
-
2056
-	if (is_null($profondeur)) {
2057
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2058
-	}
2059
-
2060
-	if (isset($url[$profondeur])) {
2061
-		return $url[$profondeur];
2062
-	}
2063
-
2064
-	$http = 'http';
2065
-
2066
-	if (
2067
-		isset($_SERVER['SCRIPT_URI'])
2068
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2069
-	) {
2070
-		$http = 'https';
2071
-	} elseif (
2072
-		isset($_SERVER['HTTPS'])
2073
-		and test_valeur_serveur($_SERVER['HTTPS'])
2074
-	) {
2075
-		$http = 'https';
2076
-	}
2077
-
2078
-	// note : HTTP_HOST contient le :port si necessaire
2079
-	$host = $_SERVER['HTTP_HOST'] ?? null;
2080
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2081
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2082
-		$host = $GLOBALS['meta']['adresse_site'];
2083
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2084
-			$http = $scheme;
2085
-			$host = str_replace("{$scheme}://", '', $host);
2086
-		}
2087
-	}
2088
-	if (
2089
-		isset($_SERVER['SERVER_PORT'])
2090
-		and $port = $_SERVER['SERVER_PORT']
2091
-		and strpos($host, ':') == false
2092
-	) {
2093
-		if (!defined('_PORT_HTTP_STANDARD')) {
2094
-			define('_PORT_HTTP_STANDARD', '80');
2095
-		}
2096
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2097
-			define('_PORT_HTTPS_STANDARD', '443');
2098
-		}
2099
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2100
-			$host .= ":$port";
2101
-		}
2102
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2103
-			$host .= ":$port";
2104
-		}
2105
-	}
2106
-
2107
-	if (!$GLOBALS['REQUEST_URI']) {
2108
-		if (isset($_SERVER['REQUEST_URI'])) {
2109
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2110
-		} else {
2111
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2112
-			if (
2113
-				!empty($_SERVER['QUERY_STRING'])
2114
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2115
-			) {
2116
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2117
-			}
2118
-		}
2119
-	}
2120
-
2121
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2122
-
2123
-	return $url[$profondeur];
2047
+    static $url = [];
2048
+    if (is_array($profondeur)) {
2049
+        return $url = $profondeur;
2050
+    }
2051
+    if ($profondeur === false) {
2052
+        return $url;
2053
+    }
2054
+
2055
+    if (is_null($profondeur)) {
2056
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2057
+    }
2058
+
2059
+    if (isset($url[$profondeur])) {
2060
+        return $url[$profondeur];
2061
+    }
2062
+
2063
+    $http = 'http';
2064
+
2065
+    if (
2066
+        isset($_SERVER['SCRIPT_URI'])
2067
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2068
+    ) {
2069
+        $http = 'https';
2070
+    } elseif (
2071
+        isset($_SERVER['HTTPS'])
2072
+        and test_valeur_serveur($_SERVER['HTTPS'])
2073
+    ) {
2074
+        $http = 'https';
2075
+    }
2076
+
2077
+    // note : HTTP_HOST contient le :port si necessaire
2078
+    $host = $_SERVER['HTTP_HOST'] ?? null;
2079
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2080
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2081
+        $host = $GLOBALS['meta']['adresse_site'];
2082
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2083
+            $http = $scheme;
2084
+            $host = str_replace("{$scheme}://", '', $host);
2085
+        }
2086
+    }
2087
+    if (
2088
+        isset($_SERVER['SERVER_PORT'])
2089
+        and $port = $_SERVER['SERVER_PORT']
2090
+        and strpos($host, ':') == false
2091
+    ) {
2092
+        if (!defined('_PORT_HTTP_STANDARD')) {
2093
+            define('_PORT_HTTP_STANDARD', '80');
2094
+        }
2095
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2096
+            define('_PORT_HTTPS_STANDARD', '443');
2097
+        }
2098
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2099
+            $host .= ":$port";
2100
+        }
2101
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2102
+            $host .= ":$port";
2103
+        }
2104
+    }
2105
+
2106
+    if (!$GLOBALS['REQUEST_URI']) {
2107
+        if (isset($_SERVER['REQUEST_URI'])) {
2108
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2109
+        } else {
2110
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2111
+            if (
2112
+                !empty($_SERVER['QUERY_STRING'])
2113
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2114
+            ) {
2115
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2116
+            }
2117
+        }
2118
+    }
2119
+
2120
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2121
+
2122
+    return $url[$profondeur];
2124 2123
 }
2125 2124
 
2126 2125
 /**
@@ -2133,26 +2132,26 @@  discard block
 block discarded – undo
2133 2132
  * @return string
2134 2133
  */
2135 2134
 function url_de_($http, $host, $request, $prof = 0) {
2136
-	$prof = max($prof, 0);
2135
+    $prof = max($prof, 0);
2137 2136
 
2138
-	$myself = ltrim($request, '/');
2139
-	# supprimer la chaine de GET
2140
-	[$myself] = explode('?', $myself);
2141
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2142
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2143
-	if (strpos($myself, '://') !== false) {
2144
-		$myself = explode('://', $myself);
2145
-		array_shift($myself);
2146
-		$myself = implode('://', $myself);
2147
-		$myself = explode('/', $myself);
2148
-		array_shift($myself);
2149
-		$myself = implode('/', $myself);
2150
-	}
2151
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2137
+    $myself = ltrim($request, '/');
2138
+    # supprimer la chaine de GET
2139
+    [$myself] = explode('?', $myself);
2140
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2141
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2142
+    if (strpos($myself, '://') !== false) {
2143
+        $myself = explode('://', $myself);
2144
+        array_shift($myself);
2145
+        $myself = implode('://', $myself);
2146
+        $myself = explode('/', $myself);
2147
+        array_shift($myself);
2148
+        $myself = implode('/', $myself);
2149
+    }
2150
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2152 2151
 
2153
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2152
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2154 2153
 
2155
-	return $url;
2154
+    return $url;
2156 2155
 }
2157 2156
 
2158 2157
 
@@ -2187,25 +2186,25 @@  discard block
 block discarded – undo
2187 2186
  * @return string URL
2188 2187
  **/
2189 2188
 function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) {
2190
-	if (!$rel) {
2191
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2192
-	} else {
2193
-		if (!is_string($rel)) {
2194
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2195
-		}
2196
-	}
2197
-
2198
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2199
-	if ($script and ($script <> 'accueil' or $rel)) {
2200
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2201
-	} elseif ($args) {
2202
-		$args = "?$args";
2203
-	}
2204
-	if ($ancre) {
2205
-		$args .= "#$ancre";
2206
-	}
2207
-
2208
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2189
+    if (!$rel) {
2190
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2191
+    } else {
2192
+        if (!is_string($rel)) {
2193
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2194
+        }
2195
+    }
2196
+
2197
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2198
+    if ($script and ($script <> 'accueil' or $rel)) {
2199
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2200
+    } elseif ($args) {
2201
+        $args = "?$args";
2202
+    }
2203
+    if ($ancre) {
2204
+        $args .= "#$ancre";
2205
+    }
2206
+
2207
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2209 2208
 }
2210 2209
 
2211 2210
 //
@@ -2227,15 +2226,15 @@  discard block
 block discarded – undo
2227 2226
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2228 2227
  **/
2229 2228
 function get_spip_script($default = '') {
2230
-	if (!defined('_SPIP_SCRIPT')) {
2231
-		return 'spip.php';
2232
-	}
2233
-	# cas define('_SPIP_SCRIPT', '');
2234
-	if (_SPIP_SCRIPT) {
2235
-		return _SPIP_SCRIPT;
2236
-	} else {
2237
-		return $default;
2238
-	}
2229
+    if (!defined('_SPIP_SCRIPT')) {
2230
+        return 'spip.php';
2231
+    }
2232
+    # cas define('_SPIP_SCRIPT', '');
2233
+    if (_SPIP_SCRIPT) {
2234
+        return _SPIP_SCRIPT;
2235
+    } else {
2236
+        return $default;
2237
+    }
2239 2238
 }
2240 2239
 
2241 2240
 /**
@@ -2264,45 +2263,45 @@  discard block
 block discarded – undo
2264 2263
  * @return string URL
2265 2264
  **/
2266 2265
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2267
-	// si le script est une action (spip_pass, spip_inscription),
2268
-	// standardiser vers la nouvelle API
2269
-
2270
-	if (is_array($args)) {
2271
-		$args = http_build_query($args);
2272
-	}
2273
-
2274
-	$url = '';
2275
-	if ($f = charger_fonction_url('page')) {
2276
-		$url = $f($script, $args);
2277
-		if ($url and !$rel) {
2278
-			include_spip('inc/filtres_mini');
2279
-			$url = url_absolue($url);
2280
-		}
2281
-	}
2282
-	if (!$url) {
2283
-		if (!$action) {
2284
-			$action = get_spip_script();
2285
-		}
2286
-		if ($script) {
2287
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2288
-		}
2289
-		if ($args) {
2290
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2291
-		}
2292
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2293
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2294
-	}
2295
-
2296
-	if (!$no_entities) {
2297
-		$url = quote_amp($url);
2298
-	}
2299
-
2300
-	return $url;
2266
+    // si le script est une action (spip_pass, spip_inscription),
2267
+    // standardiser vers la nouvelle API
2268
+
2269
+    if (is_array($args)) {
2270
+        $args = http_build_query($args);
2271
+    }
2272
+
2273
+    $url = '';
2274
+    if ($f = charger_fonction_url('page')) {
2275
+        $url = $f($script, $args);
2276
+        if ($url and !$rel) {
2277
+            include_spip('inc/filtres_mini');
2278
+            $url = url_absolue($url);
2279
+        }
2280
+    }
2281
+    if (!$url) {
2282
+        if (!$action) {
2283
+            $action = get_spip_script();
2284
+        }
2285
+        if ($script) {
2286
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2287
+        }
2288
+        if ($args) {
2289
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2290
+        }
2291
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2292
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2293
+    }
2294
+
2295
+    if (!$no_entities) {
2296
+        $url = quote_amp($url);
2297
+    }
2298
+
2299
+    return $url;
2301 2300
 }
2302 2301
 
2303 2302
 function generer_url_prive($script, $args = '', $no_entities = false) {
2304 2303
 
2305
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2304
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2306 2305
 }
2307 2306
 
2308 2307
 // Pour les formulaires en methode POST,
@@ -2327,19 +2326,19 @@  discard block
 block discarded – undo
2327 2326
  **/
2328 2327
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2329 2328
 
2330
-	$script1 = explode('&', $script);
2331
-	$script1 = reset($script1);
2329
+    $script1 = explode('&', $script);
2330
+    $script1 = reset($script1);
2332 2331
 
2333
-	return "<form action='"
2334
-	. ($script ? generer_url_ecrire($script) : '')
2335
-	. "' "
2336
-	. ($atts ?: " method='post'")
2337
-	. "><div>\n"
2338
-	. "<input type='hidden' name='exec' value='$script1' />"
2339
-	. $corps
2340
-	. (!$submit ? '' :
2341
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2342
-	. "</div></form>\n";
2332
+    return "<form action='"
2333
+    . ($script ? generer_url_ecrire($script) : '')
2334
+    . "' "
2335
+    . ($atts ?: " method='post'")
2336
+    . "><div>\n"
2337
+    . "<input type='hidden' name='exec' value='$script1' />"
2338
+    . $corps
2339
+    . (!$submit ? '' :
2340
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2341
+    . "</div></form>\n";
2343 2342
 }
2344 2343
 
2345 2344
 /**
@@ -2356,22 +2355,22 @@  discard block
 block discarded – undo
2356 2355
  * @return string
2357 2356
  */
2358 2357
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2359
-	// si l'on est dans l'espace prive, on garde dans l'url
2360
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2361
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2362
-	$h = (_DIR_RACINE and !$public)
2363
-		? generer_url_ecrire(_request('exec'))
2364
-		: generer_url_public();
2358
+    // si l'on est dans l'espace prive, on garde dans l'url
2359
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2360
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2361
+    $h = (_DIR_RACINE and !$public)
2362
+        ? generer_url_ecrire(_request('exec'))
2363
+        : generer_url_public();
2365 2364
 
2366
-	return "\n<form action='" .
2367
-	$h .
2368
-	"'" .
2369
-	$atts .
2370
-	">\n" .
2371
-	'<div>' .
2372
-	"\n<input type='hidden' name='action' value='$script' />" .
2373
-	$corps .
2374
-	'</div></form>';
2365
+    return "\n<form action='" .
2366
+    $h .
2367
+    "'" .
2368
+    $atts .
2369
+    ">\n" .
2370
+    '<div>' .
2371
+    "\n<input type='hidden' name='action' value='$script' />" .
2372
+    $corps .
2373
+    '</div></form>';
2375 2374
 }
2376 2375
 
2377 2376
 /**
@@ -2390,22 +2389,22 @@  discard block
 block discarded – undo
2390 2389
  *     URL
2391 2390
  */
2392 2391
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2393
-	// si l'on est dans l'espace prive, on garde dans l'url
2394
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2395
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2396
-	$url = (_DIR_RACINE and !$public)
2397
-		? generer_url_ecrire(_request('exec'))
2398
-		: generer_url_public('', '', false, false);
2399
-	$url = parametre_url($url, 'action', $script);
2400
-	if ($args) {
2401
-		$url .= quote_amp('&' . $args);
2402
-	}
2392
+    // si l'on est dans l'espace prive, on garde dans l'url
2393
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2394
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2395
+    $url = (_DIR_RACINE and !$public)
2396
+        ? generer_url_ecrire(_request('exec'))
2397
+        : generer_url_public('', '', false, false);
2398
+    $url = parametre_url($url, 'action', $script);
2399
+    if ($args) {
2400
+        $url .= quote_amp('&' . $args);
2401
+    }
2403 2402
 
2404
-	if ($no_entities) {
2405
-		$url = str_replace('&amp;', '&', $url);
2406
-	}
2403
+    if ($no_entities) {
2404
+        $url = str_replace('&amp;', '&', $url);
2405
+    }
2407 2406
 
2408
-	return $url;
2407
+    return $url;
2409 2408
 }
2410 2409
 
2411 2410
 
@@ -2418,8 +2417,8 @@  discard block
 block discarded – undo
2418 2417
  * @param string $ta Répertoire temporaire accessible
2419 2418
  */
2420 2419
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2421
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2422
-	spip_initialisation_suite();
2420
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2421
+    spip_initialisation_suite();
2423 2422
 }
2424 2423
 
2425 2424
 /**
@@ -2439,322 +2438,322 @@  discard block
 block discarded – undo
2439 2438
  * @param string $ta Répertoire temporaire accessible
2440 2439
  */
2441 2440
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2442
-	static $too_late = 0;
2443
-	if ($too_late++) {
2444
-		return;
2445
-	}
2446
-
2447
-	// Declaration des repertoires
2448
-
2449
-	// le nom du repertoire plugins/ activables/desactivables
2450
-	if (!defined('_DIR_PLUGINS')) {
2451
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2452
-	}
2453
-
2454
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2455
-	if (!defined('_DIR_PLUGINS_DIST')) {
2456
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2457
-	}
2458
-
2459
-	// le nom du repertoire des librairies
2460
-	if (!defined('_DIR_LIB')) {
2461
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2462
-	}
2463
-
2464
-	if (!defined('_DIR_IMG')) {
2465
-		define('_DIR_IMG', $pa);
2466
-	}
2467
-	if (!defined('_DIR_LOGOS')) {
2468
-		define('_DIR_LOGOS', $pa);
2469
-	}
2470
-	if (!defined('_DIR_IMG_ICONES')) {
2471
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2472
-	}
2473
-
2474
-	if (!defined('_DIR_DUMP')) {
2475
-		define('_DIR_DUMP', $ti . 'dump/');
2476
-	}
2477
-	if (!defined('_DIR_SESSIONS')) {
2478
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2479
-	}
2480
-	if (!defined('_DIR_TRANSFERT')) {
2481
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2482
-	}
2483
-	if (!defined('_DIR_CACHE')) {
2484
-		define('_DIR_CACHE', $ti . 'cache/');
2485
-	}
2486
-	if (!defined('_DIR_CACHE_XML')) {
2487
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2488
-	}
2489
-	if (!defined('_DIR_SKELS')) {
2490
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2491
-	}
2492
-	if (!defined('_DIR_AIDE')) {
2493
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2494
-	}
2495
-	if (!defined('_DIR_TMP')) {
2496
-		define('_DIR_TMP', $ti);
2497
-	}
2498
-
2499
-	if (!defined('_DIR_VAR')) {
2500
-		define('_DIR_VAR', $ta);
2501
-	}
2502
-
2503
-	if (!defined('_DIR_ETC')) {
2504
-		define('_DIR_ETC', $pi);
2505
-	}
2506
-	if (!defined('_DIR_CONNECT')) {
2507
-		define('_DIR_CONNECT', $pi);
2508
-	}
2509
-	if (!defined('_DIR_CHMOD')) {
2510
-		define('_DIR_CHMOD', $pi);
2511
-	}
2512
-
2513
-	if (!isset($GLOBALS['test_dirs'])) {
2514
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2515
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2516
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2517
-	}
2518
-
2519
-	// Declaration des fichiers
2520
-
2521
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2522
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2523
-	}
2524
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2525
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2526
-	}
2527
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2528
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2529
-	}
2530
-	if (!defined('_CACHE_PIPELINES')) {
2531
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2532
-	}
2533
-	if (!defined('_CACHE_CHEMIN')) {
2534
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2535
-	}
2536
-
2537
-	# attention .php obligatoire pour ecrire_fichier_securise
2538
-	if (!defined('_FILE_META')) {
2539
-		define('_FILE_META', $ti . 'meta_cache.php');
2540
-	}
2541
-	if (!defined('_DIR_LOG')) {
2542
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2543
-	}
2544
-	if (!defined('_FILE_LOG')) {
2545
-		define('_FILE_LOG', 'spip');
2546
-	}
2547
-	if (!defined('_FILE_LOG_SUFFIX')) {
2548
-		define('_FILE_LOG_SUFFIX', '.log');
2549
-	}
2550
-
2551
-	// Le fichier de connexion a la base de donnees
2552
-	// tient compte des anciennes versions (inc_connect...)
2553
-	if (!defined('_FILE_CONNECT_INS')) {
2554
-		define('_FILE_CONNECT_INS', 'connect');
2555
-	}
2556
-	if (!defined('_FILE_CONNECT')) {
2557
-		define(
2558
-			'_FILE_CONNECT',
2559
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2560
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2561
-			: false))
2562
-		);
2563
-	}
2564
-
2565
-	// Le fichier de reglages des droits
2566
-	if (!defined('_FILE_CHMOD_INS')) {
2567
-		define('_FILE_CHMOD_INS', 'chmod');
2568
-	}
2569
-	if (!defined('_FILE_CHMOD')) {
2570
-		define(
2571
-			'_FILE_CHMOD',
2572
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2573
-			: false)
2574
-		);
2575
-	}
2576
-
2577
-	if (!defined('_FILE_LDAP')) {
2578
-		define('_FILE_LDAP', 'ldap.php');
2579
-	}
2580
-
2581
-	if (!defined('_FILE_TMP_SUFFIX')) {
2582
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2583
-	}
2584
-	if (!defined('_FILE_CONNECT_TMP')) {
2585
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2586
-	}
2587
-	if (!defined('_FILE_CHMOD_TMP')) {
2588
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2589
-	}
2590
-
2591
-	// Definition des droits d'acces en ecriture
2592
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2593
-		include_once _FILE_CHMOD;
2594
-	}
2595
-
2596
-	// Se mefier des fichiers mal remplis!
2597
-	if (!defined('_SPIP_CHMOD')) {
2598
-		define('_SPIP_CHMOD', 0777);
2599
-	}
2600
-
2601
-	if (!defined('_DEFAULT_CHARSET')) {
2602
-		/** Le charset par défaut lors de l'installation */
2603
-		define('_DEFAULT_CHARSET', 'utf-8');
2604
-	}
2605
-	if (!defined('_ROOT_PLUGINS')) {
2606
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2607
-	}
2608
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2609
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2610
-	}
2611
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2612
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2613
-	}
2614
-
2615
-	// La taille des Log
2616
-	if (!defined('_MAX_LOG')) {
2617
-		define('_MAX_LOG', 100);
2618
-	}
2619
-
2620
-	// Sommes-nous dans l'empire du Mal ?
2621
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2622
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2623
-		if (!defined('_OS_SERVEUR')) {
2624
-			define('_OS_SERVEUR', 'windows');
2625
-		}
2626
-		if (!defined('_SPIP_LOCK_MODE')) {
2627
-			define('_SPIP_LOCK_MODE', 1);
2628
-		} // utiliser le flock php
2629
-	} else {
2630
-		if (!defined('_OS_SERVEUR')) {
2631
-			define('_OS_SERVEUR', '');
2632
-		}
2633
-		if (!defined('_SPIP_LOCK_MODE')) {
2634
-			define('_SPIP_LOCK_MODE', 1);
2635
-		} // utiliser le flock php
2636
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2637
-	}
2638
-
2639
-	// Langue par defaut
2640
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2641
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2642
-	}
2643
-
2644
-	//
2645
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2646
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2647
-	// pour le rendre surchargeable, on va provoquer un reecriture
2648
-	// systematique du noyau ou une baisse de perfs => a etudier)
2649
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2650
-
2651
-	// charger tout de suite le path et son cache
2652
-	load_path_cache();
2653
-
2654
-	// *********** traiter les variables ************
2655
-
2656
-	//
2657
-	// Securite
2658
-	//
2659
-
2660
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2661
-	if (isset($_REQUEST['GLOBALS'])) {
2662
-		die();
2663
-	}
2664
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2665
-	spip_desinfecte($_GET);
2666
-	spip_desinfecte($_POST);
2667
-	spip_desinfecte($_COOKIE);
2668
-	spip_desinfecte($_REQUEST);
2669
-
2670
-	// appliquer le cookie_prefix
2671
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2672
-		include_spip('inc/cookie');
2673
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2674
-	}
2675
-
2676
-	//
2677
-	// Capacites php (en fonction de la version)
2678
-	//
2679
-	$GLOBALS['flag_ob'] = (function_exists('ob_start')
2680
-		&& function_exists('ini_get')
2681
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2682
-	$GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2683
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2684
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2685
-		(get_cfg_var('upload_max_filesize') > 0));
2686
-
2687
-
2688
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2689
-	if (isset($_SERVER['REQUEST_URI'])) {
2690
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2691
-	} else {
2692
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2693
-		if (
2694
-			!empty($_SERVER['QUERY_STRING'])
2695
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2696
-		) {
2697
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2698
-		}
2699
-	}
2700
-
2701
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2702
-	if (!defined('_RENOUVELLE_ALEA')) {
2703
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2704
-	}
2705
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2706
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2707
-	}
2708
-
2709
-	// charger les meta si possible et renouveller l'alea au besoin
2710
-	// charge aussi effacer_meta et ecrire_meta
2711
-	$inc_meta = charger_fonction('meta', 'inc');
2712
-	$inc_meta();
2713
-
2714
-	// nombre de repertoires depuis la racine
2715
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2716
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2717
-	// le calcul est faux)
2718
-	if (!_DIR_RESTREINT) {
2719
-		$GLOBALS['profondeur_url'] = 1;
2720
-	} else {
2721
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2722
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2723
-		if (
2724
-			!$uri_ref
2725
-			// si on est appele avec un autre ti, on est sans doute en mutu
2726
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2727
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2728
-			// s'en remettre a l'adresse du site. alea jacta est.
2729
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2730
-		) {
2731
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2732
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2733
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2734
-			} else {
2735
-				$uri_ref = '';
2736
-			}
2737
-		}
2738
-		if (!$uri or !$uri_ref) {
2739
-			$GLOBALS['profondeur_url'] = 0;
2740
-		} else {
2741
-			$GLOBALS['profondeur_url'] = max(
2742
-				0,
2743
-				substr_count($uri[0], '/')
2744
-				- substr_count($uri_ref, '/')
2745
-			);
2746
-		}
2747
-	}
2748
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2749
-	if (_FILE_CONNECT) {
2750
-		if (
2751
-			verifier_visiteur() == '0minirezo'
2752
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2753
-			and !isset($_COOKIE['spip_admin'])
2754
-		) {
2755
-			clear_path_cache();
2756
-		}
2757
-	}
2441
+    static $too_late = 0;
2442
+    if ($too_late++) {
2443
+        return;
2444
+    }
2445
+
2446
+    // Declaration des repertoires
2447
+
2448
+    // le nom du repertoire plugins/ activables/desactivables
2449
+    if (!defined('_DIR_PLUGINS')) {
2450
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2451
+    }
2452
+
2453
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2454
+    if (!defined('_DIR_PLUGINS_DIST')) {
2455
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2456
+    }
2457
+
2458
+    // le nom du repertoire des librairies
2459
+    if (!defined('_DIR_LIB')) {
2460
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2461
+    }
2462
+
2463
+    if (!defined('_DIR_IMG')) {
2464
+        define('_DIR_IMG', $pa);
2465
+    }
2466
+    if (!defined('_DIR_LOGOS')) {
2467
+        define('_DIR_LOGOS', $pa);
2468
+    }
2469
+    if (!defined('_DIR_IMG_ICONES')) {
2470
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2471
+    }
2472
+
2473
+    if (!defined('_DIR_DUMP')) {
2474
+        define('_DIR_DUMP', $ti . 'dump/');
2475
+    }
2476
+    if (!defined('_DIR_SESSIONS')) {
2477
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2478
+    }
2479
+    if (!defined('_DIR_TRANSFERT')) {
2480
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2481
+    }
2482
+    if (!defined('_DIR_CACHE')) {
2483
+        define('_DIR_CACHE', $ti . 'cache/');
2484
+    }
2485
+    if (!defined('_DIR_CACHE_XML')) {
2486
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2487
+    }
2488
+    if (!defined('_DIR_SKELS')) {
2489
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2490
+    }
2491
+    if (!defined('_DIR_AIDE')) {
2492
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2493
+    }
2494
+    if (!defined('_DIR_TMP')) {
2495
+        define('_DIR_TMP', $ti);
2496
+    }
2497
+
2498
+    if (!defined('_DIR_VAR')) {
2499
+        define('_DIR_VAR', $ta);
2500
+    }
2501
+
2502
+    if (!defined('_DIR_ETC')) {
2503
+        define('_DIR_ETC', $pi);
2504
+    }
2505
+    if (!defined('_DIR_CONNECT')) {
2506
+        define('_DIR_CONNECT', $pi);
2507
+    }
2508
+    if (!defined('_DIR_CHMOD')) {
2509
+        define('_DIR_CHMOD', $pi);
2510
+    }
2511
+
2512
+    if (!isset($GLOBALS['test_dirs'])) {
2513
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2514
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2515
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2516
+    }
2517
+
2518
+    // Declaration des fichiers
2519
+
2520
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2521
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2522
+    }
2523
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2524
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2525
+    }
2526
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2527
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2528
+    }
2529
+    if (!defined('_CACHE_PIPELINES')) {
2530
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2531
+    }
2532
+    if (!defined('_CACHE_CHEMIN')) {
2533
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2534
+    }
2535
+
2536
+    # attention .php obligatoire pour ecrire_fichier_securise
2537
+    if (!defined('_FILE_META')) {
2538
+        define('_FILE_META', $ti . 'meta_cache.php');
2539
+    }
2540
+    if (!defined('_DIR_LOG')) {
2541
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2542
+    }
2543
+    if (!defined('_FILE_LOG')) {
2544
+        define('_FILE_LOG', 'spip');
2545
+    }
2546
+    if (!defined('_FILE_LOG_SUFFIX')) {
2547
+        define('_FILE_LOG_SUFFIX', '.log');
2548
+    }
2549
+
2550
+    // Le fichier de connexion a la base de donnees
2551
+    // tient compte des anciennes versions (inc_connect...)
2552
+    if (!defined('_FILE_CONNECT_INS')) {
2553
+        define('_FILE_CONNECT_INS', 'connect');
2554
+    }
2555
+    if (!defined('_FILE_CONNECT')) {
2556
+        define(
2557
+            '_FILE_CONNECT',
2558
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2559
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2560
+            : false))
2561
+        );
2562
+    }
2563
+
2564
+    // Le fichier de reglages des droits
2565
+    if (!defined('_FILE_CHMOD_INS')) {
2566
+        define('_FILE_CHMOD_INS', 'chmod');
2567
+    }
2568
+    if (!defined('_FILE_CHMOD')) {
2569
+        define(
2570
+            '_FILE_CHMOD',
2571
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2572
+            : false)
2573
+        );
2574
+    }
2575
+
2576
+    if (!defined('_FILE_LDAP')) {
2577
+        define('_FILE_LDAP', 'ldap.php');
2578
+    }
2579
+
2580
+    if (!defined('_FILE_TMP_SUFFIX')) {
2581
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2582
+    }
2583
+    if (!defined('_FILE_CONNECT_TMP')) {
2584
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2585
+    }
2586
+    if (!defined('_FILE_CHMOD_TMP')) {
2587
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2588
+    }
2589
+
2590
+    // Definition des droits d'acces en ecriture
2591
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2592
+        include_once _FILE_CHMOD;
2593
+    }
2594
+
2595
+    // Se mefier des fichiers mal remplis!
2596
+    if (!defined('_SPIP_CHMOD')) {
2597
+        define('_SPIP_CHMOD', 0777);
2598
+    }
2599
+
2600
+    if (!defined('_DEFAULT_CHARSET')) {
2601
+        /** Le charset par défaut lors de l'installation */
2602
+        define('_DEFAULT_CHARSET', 'utf-8');
2603
+    }
2604
+    if (!defined('_ROOT_PLUGINS')) {
2605
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2606
+    }
2607
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2608
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2609
+    }
2610
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2611
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2612
+    }
2613
+
2614
+    // La taille des Log
2615
+    if (!defined('_MAX_LOG')) {
2616
+        define('_MAX_LOG', 100);
2617
+    }
2618
+
2619
+    // Sommes-nous dans l'empire du Mal ?
2620
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2621
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2622
+        if (!defined('_OS_SERVEUR')) {
2623
+            define('_OS_SERVEUR', 'windows');
2624
+        }
2625
+        if (!defined('_SPIP_LOCK_MODE')) {
2626
+            define('_SPIP_LOCK_MODE', 1);
2627
+        } // utiliser le flock php
2628
+    } else {
2629
+        if (!defined('_OS_SERVEUR')) {
2630
+            define('_OS_SERVEUR', '');
2631
+        }
2632
+        if (!defined('_SPIP_LOCK_MODE')) {
2633
+            define('_SPIP_LOCK_MODE', 1);
2634
+        } // utiliser le flock php
2635
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2636
+    }
2637
+
2638
+    // Langue par defaut
2639
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2640
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2641
+    }
2642
+
2643
+    //
2644
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2645
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2646
+    // pour le rendre surchargeable, on va provoquer un reecriture
2647
+    // systematique du noyau ou une baisse de perfs => a etudier)
2648
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2649
+
2650
+    // charger tout de suite le path et son cache
2651
+    load_path_cache();
2652
+
2653
+    // *********** traiter les variables ************
2654
+
2655
+    //
2656
+    // Securite
2657
+    //
2658
+
2659
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2660
+    if (isset($_REQUEST['GLOBALS'])) {
2661
+        die();
2662
+    }
2663
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2664
+    spip_desinfecte($_GET);
2665
+    spip_desinfecte($_POST);
2666
+    spip_desinfecte($_COOKIE);
2667
+    spip_desinfecte($_REQUEST);
2668
+
2669
+    // appliquer le cookie_prefix
2670
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2671
+        include_spip('inc/cookie');
2672
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2673
+    }
2674
+
2675
+    //
2676
+    // Capacites php (en fonction de la version)
2677
+    //
2678
+    $GLOBALS['flag_ob'] = (function_exists('ob_start')
2679
+        && function_exists('ini_get')
2680
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2681
+    $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2682
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2683
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2684
+        (get_cfg_var('upload_max_filesize') > 0));
2685
+
2686
+
2687
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2688
+    if (isset($_SERVER['REQUEST_URI'])) {
2689
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2690
+    } else {
2691
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2692
+        if (
2693
+            !empty($_SERVER['QUERY_STRING'])
2694
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2695
+        ) {
2696
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2697
+        }
2698
+    }
2699
+
2700
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2701
+    if (!defined('_RENOUVELLE_ALEA')) {
2702
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2703
+    }
2704
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2705
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2706
+    }
2707
+
2708
+    // charger les meta si possible et renouveller l'alea au besoin
2709
+    // charge aussi effacer_meta et ecrire_meta
2710
+    $inc_meta = charger_fonction('meta', 'inc');
2711
+    $inc_meta();
2712
+
2713
+    // nombre de repertoires depuis la racine
2714
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2715
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2716
+    // le calcul est faux)
2717
+    if (!_DIR_RESTREINT) {
2718
+        $GLOBALS['profondeur_url'] = 1;
2719
+    } else {
2720
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2721
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2722
+        if (
2723
+            !$uri_ref
2724
+            // si on est appele avec un autre ti, on est sans doute en mutu
2725
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2726
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2727
+            // s'en remettre a l'adresse du site. alea jacta est.
2728
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2729
+        ) {
2730
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2731
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2732
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2733
+            } else {
2734
+                $uri_ref = '';
2735
+            }
2736
+        }
2737
+        if (!$uri or !$uri_ref) {
2738
+            $GLOBALS['profondeur_url'] = 0;
2739
+        } else {
2740
+            $GLOBALS['profondeur_url'] = max(
2741
+                0,
2742
+                substr_count($uri[0], '/')
2743
+                - substr_count($uri_ref, '/')
2744
+            );
2745
+        }
2746
+    }
2747
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2748
+    if (_FILE_CONNECT) {
2749
+        if (
2750
+            verifier_visiteur() == '0minirezo'
2751
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2752
+            and !isset($_COOKIE['spip_admin'])
2753
+        ) {
2754
+            clear_path_cache();
2755
+        }
2756
+    }
2758 2757
 }
2759 2758
 
2760 2759
 /**
@@ -2763,190 +2762,190 @@  discard block
 block discarded – undo
2763 2762
  *
2764 2763
  */
2765 2764
 function spip_initialisation_suite() {
2766
-	static $too_late = 0;
2767
-	if ($too_late++) {
2768
-		return;
2769
-	}
2770
-
2771
-	// taille mini des login
2772
-	if (!defined('_LOGIN_TROP_COURT')) {
2773
-		define('_LOGIN_TROP_COURT', 4);
2774
-	}
2775
-
2776
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2777
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2778
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2779
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2780
-
2781
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2782
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2783
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2784
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2785
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2786
-
2787
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2788
-		define('_PASS_LONGUEUR_MINI', 6);
2789
-	}
2790
-
2791
-	// largeur maximale des images dans l'administration
2792
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2793
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2794
-	}
2795
-
2796
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2797
-	if (!defined('_IMG_QUALITE')) {
2798
-		define('_IMG_QUALITE', 85);
2799
-	} # valeur par defaut
2800
-	if (!defined('_IMG_GD_QUALITE')) {
2801
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2802
-	} # surcharge pour la lib GD
2803
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2804
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2805
-	} # surcharge pour imagick en ligne de commande
2806
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2807
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2808
-		define('_IMG_IMAGICK_QUALITE', 75);
2809
-	} # surcharge pour imagick en PHP
2810
-
2811
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2812
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2813
-	} // poids en octet
2814
-
2815
-	// qq chaines standard
2816
-	if (!defined('_ACCESS_FILE_NAME')) {
2817
-		define('_ACCESS_FILE_NAME', '.htaccess');
2818
-	}
2819
-	if (!defined('_AUTH_USER_FILE')) {
2820
-		define('_AUTH_USER_FILE', '.htpasswd');
2821
-	}
2822
-	if (!defined('_SPIP_DUMP')) {
2823
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2824
-	}
2825
-	if (!defined('_CACHE_RUBRIQUES')) {
2826
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2827
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2828
-	}
2829
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2830
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2831
-		define('_CACHE_RUBRIQUES_MAX', 500);
2832
-	}
2833
-
2834
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2835
-		/**
2836
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2837
-		 * @var int Nombre de caractères */
2838
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2839
-	}
2840
-
2841
-	if (!defined('_EXTENSION_SQUELETTES')) {
2842
-		define('_EXTENSION_SQUELETTES', 'html');
2843
-	}
2844
-
2845
-	if (!defined('_DOCTYPE_ECRIRE')) {
2846
-		/** Définit le doctype de l’espace privé */
2847
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2848
-	}
2849
-	if (!defined('_DOCTYPE_AIDE')) {
2850
-		/** Définit le doctype de l’aide en ligne */
2851
-		define(
2852
-			'_DOCTYPE_AIDE',
2853
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2854
-		);
2855
-	}
2856
-
2857
-	if (!defined('_SPIP_SCRIPT')) {
2858
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2859
-		 * le script de l'espace public, alias index.php */
2860
-		define('_SPIP_SCRIPT', 'spip.php');
2861
-	}
2862
-	if (!defined('_SPIP_PAGE')) {
2863
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2864
-		define('_SPIP_PAGE', 'page');
2865
-	}
2866
-
2867
-	// le script de l'espace prive
2868
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2869
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2870
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2871
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2872
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2873
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2874
-		} else {
2875
-			define('_SPIP_ECRIRE_SCRIPT', '');
2876
-		}
2877
-	}
2878
-
2879
-
2880
-	if (!defined('_SPIP_AJAX')) {
2881
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2882
-			? 1
2883
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2884
-	}
2885
-
2886
-	// La requete est-elle en ajax ?
2887
-	if (!defined('_AJAX')) {
2888
-		define(
2889
-			'_AJAX',
2890
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2891
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2892
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2893
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2894
-			)
2895
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2896
-		);
2897
-	}
2898
-
2899
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2900
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2901
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2902
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2903
-		define(
2904
-			'_IMG_GD_MAX_PIXELS',
2905
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2906
-			? $GLOBALS['meta']['max_taille_vignettes']
2907
-			: 0
2908
-		);
2909
-	}
2910
-
2911
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2912
-		define('_MEMORY_LIMIT_MIN', 16);
2913
-	} // en Mo
2914
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2915
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2916
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2917
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2918
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2919
-			$unit = strtolower(substr($memory, -1));
2920
-			$memory = substr($memory, 0, -1);
2921
-			switch ($unit) {
2922
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2923
-				case 'g':
2924
-					$memory *= 1024;
2925
-				case 'm':
2926
-					$memory *= 1024;
2927
-				case 'k':
2928
-					$memory *= 1024;
2929
-			}
2930
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2931
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2932
-				if (trim(ini_get('memory_limit')) != $m) {
2933
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2934
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2935
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2936
-				}
2937
-			}
2938
-		} else {
2939
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2940
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2941
-			}
2942
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2943
-	}
2944
-	// Protocoles a normaliser dans les chaines de langues
2945
-	if (!defined('_PROTOCOLES_STD')) {
2946
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2947
-	}
2948
-
2949
-	init_var_mode();
2765
+    static $too_late = 0;
2766
+    if ($too_late++) {
2767
+        return;
2768
+    }
2769
+
2770
+    // taille mini des login
2771
+    if (!defined('_LOGIN_TROP_COURT')) {
2772
+        define('_LOGIN_TROP_COURT', 4);
2773
+    }
2774
+
2775
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2776
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2777
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2778
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2779
+
2780
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2781
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2782
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2783
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2784
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2785
+
2786
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2787
+        define('_PASS_LONGUEUR_MINI', 6);
2788
+    }
2789
+
2790
+    // largeur maximale des images dans l'administration
2791
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2792
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2793
+    }
2794
+
2795
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2796
+    if (!defined('_IMG_QUALITE')) {
2797
+        define('_IMG_QUALITE', 85);
2798
+    } # valeur par defaut
2799
+    if (!defined('_IMG_GD_QUALITE')) {
2800
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2801
+    } # surcharge pour la lib GD
2802
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2803
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2804
+    } # surcharge pour imagick en ligne de commande
2805
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2806
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2807
+        define('_IMG_IMAGICK_QUALITE', 75);
2808
+    } # surcharge pour imagick en PHP
2809
+
2810
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2811
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2812
+    } // poids en octet
2813
+
2814
+    // qq chaines standard
2815
+    if (!defined('_ACCESS_FILE_NAME')) {
2816
+        define('_ACCESS_FILE_NAME', '.htaccess');
2817
+    }
2818
+    if (!defined('_AUTH_USER_FILE')) {
2819
+        define('_AUTH_USER_FILE', '.htpasswd');
2820
+    }
2821
+    if (!defined('_SPIP_DUMP')) {
2822
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2823
+    }
2824
+    if (!defined('_CACHE_RUBRIQUES')) {
2825
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2826
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2827
+    }
2828
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2829
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2830
+        define('_CACHE_RUBRIQUES_MAX', 500);
2831
+    }
2832
+
2833
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2834
+        /**
2835
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2836
+         * @var int Nombre de caractères */
2837
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2838
+    }
2839
+
2840
+    if (!defined('_EXTENSION_SQUELETTES')) {
2841
+        define('_EXTENSION_SQUELETTES', 'html');
2842
+    }
2843
+
2844
+    if (!defined('_DOCTYPE_ECRIRE')) {
2845
+        /** Définit le doctype de l’espace privé */
2846
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2847
+    }
2848
+    if (!defined('_DOCTYPE_AIDE')) {
2849
+        /** Définit le doctype de l’aide en ligne */
2850
+        define(
2851
+            '_DOCTYPE_AIDE',
2852
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2853
+        );
2854
+    }
2855
+
2856
+    if (!defined('_SPIP_SCRIPT')) {
2857
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2858
+         * le script de l'espace public, alias index.php */
2859
+        define('_SPIP_SCRIPT', 'spip.php');
2860
+    }
2861
+    if (!defined('_SPIP_PAGE')) {
2862
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2863
+        define('_SPIP_PAGE', 'page');
2864
+    }
2865
+
2866
+    // le script de l'espace prive
2867
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2868
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2869
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2870
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2871
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2872
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2873
+        } else {
2874
+            define('_SPIP_ECRIRE_SCRIPT', '');
2875
+        }
2876
+    }
2877
+
2878
+
2879
+    if (!defined('_SPIP_AJAX')) {
2880
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2881
+            ? 1
2882
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2883
+    }
2884
+
2885
+    // La requete est-elle en ajax ?
2886
+    if (!defined('_AJAX')) {
2887
+        define(
2888
+            '_AJAX',
2889
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2890
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2891
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2892
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2893
+            )
2894
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2895
+        );
2896
+    }
2897
+
2898
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2899
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2900
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2901
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2902
+        define(
2903
+            '_IMG_GD_MAX_PIXELS',
2904
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2905
+            ? $GLOBALS['meta']['max_taille_vignettes']
2906
+            : 0
2907
+        );
2908
+    }
2909
+
2910
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2911
+        define('_MEMORY_LIMIT_MIN', 16);
2912
+    } // en Mo
2913
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2914
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2915
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2916
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2917
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2918
+            $unit = strtolower(substr($memory, -1));
2919
+            $memory = substr($memory, 0, -1);
2920
+            switch ($unit) {
2921
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2922
+                case 'g':
2923
+                    $memory *= 1024;
2924
+                case 'm':
2925
+                    $memory *= 1024;
2926
+                case 'k':
2927
+                    $memory *= 1024;
2928
+            }
2929
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2930
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2931
+                if (trim(ini_get('memory_limit')) != $m) {
2932
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2933
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2934
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2935
+                }
2936
+            }
2937
+        } else {
2938
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2939
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2940
+            }
2941
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2942
+    }
2943
+    // Protocoles a normaliser dans les chaines de langues
2944
+    if (!defined('_PROTOCOLES_STD')) {
2945
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2946
+    }
2947
+
2948
+    init_var_mode();
2950 2949
 }
2951 2950
 
2952 2951
 /**
@@ -2980,219 +2979,219 @@  discard block
 block discarded – undo
2980 2979
  * `   var_mode` (calcul ou recalcul).
2981 2980
  */
2982 2981
 function init_var_mode() {
2983
-	static $done = false;
2984
-	if (!$done) {
2985
-		if (isset($_GET['var_mode'])) {
2986
-			$var_mode = explode(',', $_GET['var_mode']);
2987
-			// tout le monde peut calcul/recalcul
2988
-			if (!defined('_VAR_MODE')) {
2989
-				if (in_array('recalcul', $var_mode)) {
2990
-					define('_VAR_MODE', 'recalcul');
2991
-				} elseif (in_array('calcul', $var_mode)) {
2992
-					define('_VAR_MODE', 'calcul');
2993
-				}
2994
-			}
2995
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2996
-			if ($var_mode) {
2997
-				include_spip('inc/autoriser');
2998
-				// autoriser preview si preview seulement, et sinon autoriser debug
2999
-				if (
3000
-					autoriser(
3001
-						($_GET['var_mode'] == 'preview')
3002
-						? 'previsualiser'
3003
-						: 'debug'
3004
-					)
3005
-				) {
3006
-					if (in_array('traduction', $var_mode)) {
3007
-						// forcer le calcul pour passer dans traduire
3008
-						if (!defined('_VAR_MODE')) {
3009
-							define('_VAR_MODE', 'calcul');
3010
-						}
3011
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3012
-						if (!defined('_VAR_NOCACHE')) {
3013
-							define('_VAR_NOCACHE', true);
3014
-						}
3015
-						$var_mode = array_diff($var_mode, ['traduction']);
3016
-					}
3017
-					if (in_array('preview', $var_mode)) {
3018
-						// basculer sur les criteres de preview dans les boucles
3019
-						if (!defined('_VAR_PREVIEW')) {
3020
-							define('_VAR_PREVIEW', true);
3021
-						}
3022
-						// forcer le calcul
3023
-						if (!defined('_VAR_MODE')) {
3024
-							define('_VAR_MODE', 'calcul');
3025
-						}
3026
-						// et ne pas enregistrer de cache
3027
-						if (!defined('_VAR_NOCACHE')) {
3028
-							define('_VAR_NOCACHE', true);
3029
-						}
3030
-						$var_mode = array_diff($var_mode, ['preview']);
3031
-					}
3032
-					if (in_array('inclure', $var_mode)) {
3033
-						// forcer le compilo et ignorer les caches existants
3034
-						if (!defined('_VAR_MODE')) {
3035
-							define('_VAR_MODE', 'calcul');
3036
-						}
3037
-						if (!defined('_VAR_INCLURE')) {
3038
-							define('_VAR_INCLURE', true);
3039
-						}
3040
-						// et ne pas enregistrer de cache
3041
-						if (!defined('_VAR_NOCACHE')) {
3042
-							define('_VAR_NOCACHE', true);
3043
-						}
3044
-						$var_mode = array_diff($var_mode, ['inclure']);
3045
-					}
3046
-					if (in_array('urls', $var_mode)) {
3047
-						// forcer le compilo et ignorer les caches existants
3048
-						if (!defined('_VAR_MODE')) {
3049
-							define('_VAR_MODE', 'calcul');
3050
-						}
3051
-						if (!defined('_VAR_URLS')) {
3052
-							define('_VAR_URLS', true);
3053
-						}
3054
-						$var_mode = array_diff($var_mode, ['urls']);
3055
-					}
3056
-					if (in_array('images', $var_mode)) {
3057
-						// forcer le compilo et ignorer les caches existants
3058
-						if (!defined('_VAR_MODE')) {
3059
-							define('_VAR_MODE', 'calcul');
3060
-						}
3061
-						// indiquer qu'on doit recalculer les images
3062
-						if (!defined('_VAR_IMAGES')) {
3063
-							define('_VAR_IMAGES', true);
3064
-						}
3065
-						$var_mode = array_diff($var_mode, ['images']);
3066
-					}
3067
-					if (in_array('debug', $var_mode)) {
3068
-						if (!defined('_VAR_MODE')) {
3069
-							define('_VAR_MODE', 'debug');
3070
-						}
3071
-						// et ne pas enregistrer de cache
3072
-						if (!defined('_VAR_NOCACHE')) {
3073
-							define('_VAR_NOCACHE', true);
3074
-						}
3075
-						$var_mode = array_diff($var_mode, ['debug']);
3076
-					}
3077
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3078
-						define('_VAR_MODE', reset($var_mode));
3079
-					}
3080
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3081
-						spip_log($GLOBALS['visiteur_session']['nom']
3082
-							. ' ' . _VAR_MODE);
3083
-					}
3084
-				} // pas autorise ?
3085
-				else {
3086
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3087
-					if (
3088
-						!$GLOBALS['visiteur_session']
3089
-						and !empty($_SERVER['HTTP_HOST'])
3090
-						and !empty($_SERVER['REQUEST_METHOD'])
3091
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3092
-					) {
3093
-						$self = self('&', true);
3094
-						if (strpos($self, 'page=login') === false) {
3095
-							include_spip('inc/headers');
3096
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3097
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3098
-						}
3099
-					}
3100
-					// sinon tant pis
3101
-				}
3102
-			}
3103
-		}
3104
-		if (!defined('_VAR_MODE')) {
3105
-			/**
3106
-			 * Indique le mode de calcul ou d'affichage de la page.
3107
-			 * @see init_var_mode()
3108
-			 */
3109
-			define('_VAR_MODE', false);
3110
-		}
3111
-		$done = true;
3112
-	}
2982
+    static $done = false;
2983
+    if (!$done) {
2984
+        if (isset($_GET['var_mode'])) {
2985
+            $var_mode = explode(',', $_GET['var_mode']);
2986
+            // tout le monde peut calcul/recalcul
2987
+            if (!defined('_VAR_MODE')) {
2988
+                if (in_array('recalcul', $var_mode)) {
2989
+                    define('_VAR_MODE', 'recalcul');
2990
+                } elseif (in_array('calcul', $var_mode)) {
2991
+                    define('_VAR_MODE', 'calcul');
2992
+                }
2993
+            }
2994
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2995
+            if ($var_mode) {
2996
+                include_spip('inc/autoriser');
2997
+                // autoriser preview si preview seulement, et sinon autoriser debug
2998
+                if (
2999
+                    autoriser(
3000
+                        ($_GET['var_mode'] == 'preview')
3001
+                        ? 'previsualiser'
3002
+                        : 'debug'
3003
+                    )
3004
+                ) {
3005
+                    if (in_array('traduction', $var_mode)) {
3006
+                        // forcer le calcul pour passer dans traduire
3007
+                        if (!defined('_VAR_MODE')) {
3008
+                            define('_VAR_MODE', 'calcul');
3009
+                        }
3010
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3011
+                        if (!defined('_VAR_NOCACHE')) {
3012
+                            define('_VAR_NOCACHE', true);
3013
+                        }
3014
+                        $var_mode = array_diff($var_mode, ['traduction']);
3015
+                    }
3016
+                    if (in_array('preview', $var_mode)) {
3017
+                        // basculer sur les criteres de preview dans les boucles
3018
+                        if (!defined('_VAR_PREVIEW')) {
3019
+                            define('_VAR_PREVIEW', true);
3020
+                        }
3021
+                        // forcer le calcul
3022
+                        if (!defined('_VAR_MODE')) {
3023
+                            define('_VAR_MODE', 'calcul');
3024
+                        }
3025
+                        // et ne pas enregistrer de cache
3026
+                        if (!defined('_VAR_NOCACHE')) {
3027
+                            define('_VAR_NOCACHE', true);
3028
+                        }
3029
+                        $var_mode = array_diff($var_mode, ['preview']);
3030
+                    }
3031
+                    if (in_array('inclure', $var_mode)) {
3032
+                        // forcer le compilo et ignorer les caches existants
3033
+                        if (!defined('_VAR_MODE')) {
3034
+                            define('_VAR_MODE', 'calcul');
3035
+                        }
3036
+                        if (!defined('_VAR_INCLURE')) {
3037
+                            define('_VAR_INCLURE', true);
3038
+                        }
3039
+                        // et ne pas enregistrer de cache
3040
+                        if (!defined('_VAR_NOCACHE')) {
3041
+                            define('_VAR_NOCACHE', true);
3042
+                        }
3043
+                        $var_mode = array_diff($var_mode, ['inclure']);
3044
+                    }
3045
+                    if (in_array('urls', $var_mode)) {
3046
+                        // forcer le compilo et ignorer les caches existants
3047
+                        if (!defined('_VAR_MODE')) {
3048
+                            define('_VAR_MODE', 'calcul');
3049
+                        }
3050
+                        if (!defined('_VAR_URLS')) {
3051
+                            define('_VAR_URLS', true);
3052
+                        }
3053
+                        $var_mode = array_diff($var_mode, ['urls']);
3054
+                    }
3055
+                    if (in_array('images', $var_mode)) {
3056
+                        // forcer le compilo et ignorer les caches existants
3057
+                        if (!defined('_VAR_MODE')) {
3058
+                            define('_VAR_MODE', 'calcul');
3059
+                        }
3060
+                        // indiquer qu'on doit recalculer les images
3061
+                        if (!defined('_VAR_IMAGES')) {
3062
+                            define('_VAR_IMAGES', true);
3063
+                        }
3064
+                        $var_mode = array_diff($var_mode, ['images']);
3065
+                    }
3066
+                    if (in_array('debug', $var_mode)) {
3067
+                        if (!defined('_VAR_MODE')) {
3068
+                            define('_VAR_MODE', 'debug');
3069
+                        }
3070
+                        // et ne pas enregistrer de cache
3071
+                        if (!defined('_VAR_NOCACHE')) {
3072
+                            define('_VAR_NOCACHE', true);
3073
+                        }
3074
+                        $var_mode = array_diff($var_mode, ['debug']);
3075
+                    }
3076
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3077
+                        define('_VAR_MODE', reset($var_mode));
3078
+                    }
3079
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3080
+                        spip_log($GLOBALS['visiteur_session']['nom']
3081
+                            . ' ' . _VAR_MODE);
3082
+                    }
3083
+                } // pas autorise ?
3084
+                else {
3085
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3086
+                    if (
3087
+                        !$GLOBALS['visiteur_session']
3088
+                        and !empty($_SERVER['HTTP_HOST'])
3089
+                        and !empty($_SERVER['REQUEST_METHOD'])
3090
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3091
+                    ) {
3092
+                        $self = self('&', true);
3093
+                        if (strpos($self, 'page=login') === false) {
3094
+                            include_spip('inc/headers');
3095
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3096
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3097
+                        }
3098
+                    }
3099
+                    // sinon tant pis
3100
+                }
3101
+            }
3102
+        }
3103
+        if (!defined('_VAR_MODE')) {
3104
+            /**
3105
+             * Indique le mode de calcul ou d'affichage de la page.
3106
+             * @see init_var_mode()
3107
+             */
3108
+            define('_VAR_MODE', false);
3109
+        }
3110
+        $done = true;
3111
+    }
3113 3112
 }
3114 3113
 
3115 3114
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
3116 3115
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
3117 3116
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
3118 3117
 function spip_desinfecte(&$t, $deep = true) {
3119
-	foreach ($t as $key => $val) {
3120
-		if (is_string($t[$key])) {
3121
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3122
-		} // traiter aussi les "texte_plus" de article_edit
3123
-		else {
3124
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3125
-				spip_desinfecte($t[$key], $deep);
3126
-			}
3127
-		}
3128
-	}
3118
+    foreach ($t as $key => $val) {
3119
+        if (is_string($t[$key])) {
3120
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3121
+        } // traiter aussi les "texte_plus" de article_edit
3122
+        else {
3123
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3124
+                spip_desinfecte($t[$key], $deep);
3125
+            }
3126
+        }
3127
+    }
3129 3128
 }
3130 3129
 
3131 3130
 //  retourne le statut du visiteur s'il s'annonce
3132 3131
 
3133 3132
 function verifier_visiteur() {
3134
-	// Rq: pour que cette fonction marche depuis mes_options
3135
-	// il faut forcer l'init si ce n'est fait
3136
-	// mais on risque de perturber des plugins en initialisant trop tot
3137
-	// certaines constantes
3138
-	@spip_initialisation_core(
3139
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3140
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3141
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3142
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3143
-	);
3144
-
3145
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3146
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3147
-	// Attention on separe bien session_nom et nom, pour eviter
3148
-	// les melanges entre donnees SQL et variables plus aleatoires
3149
-	$variables_session = ['session_nom', 'session_email'];
3150
-	foreach ($variables_session as $var) {
3151
-		if (_request($var) !== null) {
3152
-			$init = true;
3153
-			break;
3154
-		}
3155
-	}
3156
-	if (isset($init)) {
3157
-		#@spip_initialisation_suite();
3158
-		$session = charger_fonction('session', 'inc');
3159
-		$session();
3160
-		include_spip('inc/texte');
3161
-		foreach ($variables_session as $var) {
3162
-			if (($a = _request($var)) !== null) {
3163
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3164
-			}
3165
-		}
3166
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3167
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3168
-		}
3169
-		$session($GLOBALS['visiteur_session']);
3170
-
3171
-		return 0;
3172
-	}
3173
-
3174
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3175
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3176
-		$session = charger_fonction('session', 'inc');
3177
-		if ($session()) {
3178
-			return $GLOBALS['visiteur_session']['statut'];
3179
-		}
3180
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3181
-			include_spip('inc/auth');
3182
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3183
-		}
3184
-		if ($h) {
3185
-			$GLOBALS['visiteur_session'] = $h;
3186
-
3187
-			return $GLOBALS['visiteur_session']['statut'];
3188
-		}
3189
-	}
3190
-
3191
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3192
-	include_spip('inc/lang');
3193
-	utiliser_langue_visiteur();
3194
-
3195
-	return false;
3133
+    // Rq: pour que cette fonction marche depuis mes_options
3134
+    // il faut forcer l'init si ce n'est fait
3135
+    // mais on risque de perturber des plugins en initialisant trop tot
3136
+    // certaines constantes
3137
+    @spip_initialisation_core(
3138
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3139
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3140
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3141
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3142
+    );
3143
+
3144
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3145
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3146
+    // Attention on separe bien session_nom et nom, pour eviter
3147
+    // les melanges entre donnees SQL et variables plus aleatoires
3148
+    $variables_session = ['session_nom', 'session_email'];
3149
+    foreach ($variables_session as $var) {
3150
+        if (_request($var) !== null) {
3151
+            $init = true;
3152
+            break;
3153
+        }
3154
+    }
3155
+    if (isset($init)) {
3156
+        #@spip_initialisation_suite();
3157
+        $session = charger_fonction('session', 'inc');
3158
+        $session();
3159
+        include_spip('inc/texte');
3160
+        foreach ($variables_session as $var) {
3161
+            if (($a = _request($var)) !== null) {
3162
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3163
+            }
3164
+        }
3165
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3166
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3167
+        }
3168
+        $session($GLOBALS['visiteur_session']);
3169
+
3170
+        return 0;
3171
+    }
3172
+
3173
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3174
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3175
+        $session = charger_fonction('session', 'inc');
3176
+        if ($session()) {
3177
+            return $GLOBALS['visiteur_session']['statut'];
3178
+        }
3179
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3180
+            include_spip('inc/auth');
3181
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3182
+        }
3183
+        if ($h) {
3184
+            $GLOBALS['visiteur_session'] = $h;
3185
+
3186
+            return $GLOBALS['visiteur_session']['statut'];
3187
+        }
3188
+    }
3189
+
3190
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3191
+    include_spip('inc/lang');
3192
+    utiliser_langue_visiteur();
3193
+
3194
+    return false;
3196 3195
 }
3197 3196
 
3198 3197
 
@@ -3215,21 +3214,21 @@  discard block
 block discarded – undo
3215 3214
  *     - string Langue utilisée.
3216 3215
  **/
3217 3216
 function lang_select($lang = null) {
3218
-	static $pile_langues = [];
3219
-	if (!function_exists('changer_langue')) {
3220
-		include_spip('inc/lang');
3221
-	}
3222
-	if ($lang === null) {
3223
-		$lang = array_pop($pile_langues);
3224
-	} else {
3225
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3226
-	}
3227
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3228
-		return $lang;
3229
-	}
3230
-	changer_langue($lang);
3217
+    static $pile_langues = [];
3218
+    if (!function_exists('changer_langue')) {
3219
+        include_spip('inc/lang');
3220
+    }
3221
+    if ($lang === null) {
3222
+        $lang = array_pop($pile_langues);
3223
+    } else {
3224
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3225
+    }
3226
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3227
+        return $lang;
3228
+    }
3229
+    changer_langue($lang);
3231 3230
 
3232
-	return $lang;
3231
+    return $lang;
3233 3232
 }
3234 3233
 
3235 3234
 /**
@@ -3246,20 +3245,20 @@  discard block
 block discarded – undo
3246 3245
  *     Identifiant de la session
3247 3246
  **/
3248 3247
 function spip_session($force = false) {
3249
-	static $session;
3250
-	if ($force or !isset($session)) {
3251
-		$s = pipeline(
3252
-			'definir_session',
3253
-			$GLOBALS['visiteur_session']
3254
-				? serialize($GLOBALS['visiteur_session'])
3255
-				. '_' . @$_COOKIE['spip_session']
3256
-				: ''
3257
-		);
3258
-		$session = $s ? substr(md5($s), 0, 8) : '';
3259
-	}
3248
+    static $session;
3249
+    if ($force or !isset($session)) {
3250
+        $s = pipeline(
3251
+            'definir_session',
3252
+            $GLOBALS['visiteur_session']
3253
+                ? serialize($GLOBALS['visiteur_session'])
3254
+                . '_' . @$_COOKIE['spip_session']
3255
+                : ''
3256
+        );
3257
+        $session = $s ? substr(md5($s), 0, 8) : '';
3258
+    }
3260 3259
 
3261
-	#spip_log('session: '.$session);
3262
-	return $session;
3260
+    #spip_log('session: '.$session);
3261
+    return $session;
3263 3262
 }
3264 3263
 
3265 3264
 
@@ -3278,9 +3277,9 @@  discard block
 block discarded – undo
3278 3277
  *    Lien sur une icone d'aide
3279 3278
  **/
3280 3279
 function aider($aide = '', $distante = false) {
3281
-	$aider = charger_fonction('aide', 'inc', true);
3280
+    $aider = charger_fonction('aide', 'inc', true);
3282 3281
 
3283
-	return $aider ? $aider($aide, '', [], $distante) : '';
3282
+    return $aider ? $aider($aide, '', [], $distante) : '';
3284 3283
 }
3285 3284
 
3286 3285
 /**
@@ -3290,24 +3289,24 @@  discard block
 block discarded – undo
3290 3289
  */
3291 3290
 function exec_info_dist() {
3292 3291
 
3293
-	include_spip('inc/autoriser');
3294
-	if (autoriser('phpinfos')) {
3295
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3296
-		$cookies_backup = [];
3297
-		foreach ($cookies_masques as $k) {
3298
-			if (!empty($_COOKIE[$k])) {
3299
-				$cookies_backup[$k] = $_COOKIE[$k];
3300
-				$_COOKIE[$k] = '******************************';
3301
-			}
3302
-		}
3303
-		phpinfo();
3304
-		foreach ($cookies_backup as $k => $v) {
3305
-			$_COOKIE[$k] = $v;
3306
-		}
3307
-	} else {
3308
-		include_spip('inc/filtres');
3309
-		sinon_interdire_acces();
3310
-	}
3292
+    include_spip('inc/autoriser');
3293
+    if (autoriser('phpinfos')) {
3294
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3295
+        $cookies_backup = [];
3296
+        foreach ($cookies_masques as $k) {
3297
+            if (!empty($_COOKIE[$k])) {
3298
+                $cookies_backup[$k] = $_COOKIE[$k];
3299
+                $_COOKIE[$k] = '******************************';
3300
+            }
3301
+        }
3302
+        phpinfo();
3303
+        foreach ($cookies_backup as $k => $v) {
3304
+            $_COOKIE[$k] = $v;
3305
+        }
3306
+    } else {
3307
+        include_spip('inc/filtres');
3308
+        sinon_interdire_acces();
3309
+    }
3311 3310
 }
3312 3311
 
3313 3312
 /**
@@ -3327,13 +3326,13 @@  discard block
 block discarded – undo
3327 3326
  *     - string si $message à false.
3328 3327
  **/
3329 3328
 function erreur_squelette($message = '', $lieu = '') {
3330
-	$debusquer = charger_fonction('debusquer', 'public');
3331
-	if (is_array($lieu)) {
3332
-		include_spip('public/compiler');
3333
-		$lieu = reconstruire_contexte_compil($lieu);
3334
-	}
3329
+    $debusquer = charger_fonction('debusquer', 'public');
3330
+    if (is_array($lieu)) {
3331
+        include_spip('public/compiler');
3332
+        $lieu = reconstruire_contexte_compil($lieu);
3333
+    }
3335 3334
 
3336
-	return $debusquer($message, $lieu);
3335
+    return $debusquer($message, $lieu);
3337 3336
 }
3338 3337
 
3339 3338
 /**
@@ -3370,108 +3369,108 @@  discard block
 block discarded – undo
3370 3369
  *     - ou tableau d'information sur le squelette.
3371 3370
  */
3372 3371
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3373
-	if (!function_exists('evaluer_fond')) {
3374
-		include_spip('public/assembler');
3375
-	}
3376
-	// assurer la compat avec l'ancienne syntaxe
3377
-	// (trim etait le 3eme argument, par defaut a true)
3378
-	if (!is_array($options)) {
3379
-		$options = ['trim' => $options];
3380
-	}
3381
-	if (!isset($options['trim'])) {
3382
-		$options['trim'] = true;
3383
-	}
3384
-
3385
-	if (isset($contexte['connect'])) {
3386
-		$connect = $contexte['connect'];
3387
-		unset($contexte['connect']);
3388
-	}
3389
-
3390
-	$texte = '';
3391
-	$pages = [];
3392
-	$lang_select = '';
3393
-	if (!isset($options['etoile']) or !$options['etoile']) {
3394
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3395
-		if (!isset($contexte['lang'])) {
3396
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3397
-		}
3398
-
3399
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3400
-			$lang_select = lang_select($contexte['lang']);
3401
-		}
3402
-	}
3403
-
3404
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3405
-		$GLOBALS['_INC_PUBLIC'] = 0;
3406
-	}
3407
-
3408
-	$GLOBALS['_INC_PUBLIC']++;
3409
-
3410
-	// fix #4235
3411
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3412
-
3413
-
3414
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3415
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3416
-
3417
-		$page = evaluer_fond($f, $contexte, $connect);
3418
-		if ($page === '') {
3419
-			$c = $options['compil'] ?? '';
3420
-			$a = ['fichier' => $f];
3421
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3422
-			erreur_squelette($erreur, $c);
3423
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3424
-			$page = ['texte' => '', 'erreur' => $erreur];
3425
-		}
3426
-
3427
-		$page = pipeline('recuperer_fond', [
3428
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3429
-			'data' => $page
3430
-		]);
3431
-		if (isset($options['ajax']) and $options['ajax']) {
3432
-			if (!function_exists('encoder_contexte_ajax')) {
3433
-				include_spip('inc/filtres');
3434
-			}
3435
-			$page['texte'] = encoder_contexte_ajax(
3436
-				array_merge(
3437
-					$contexte,
3438
-					['fond' => $f],
3439
-					($connect ? ['connect' => $connect] : [])
3440
-				),
3441
-				'',
3442
-				$page['texte'],
3443
-				$options['ajax']
3444
-			);
3445
-		}
3446
-
3447
-		if (isset($options['raw']) and $options['raw']) {
3448
-			$pages[] = $page;
3449
-		} else {
3450
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3451
-		}
3452
-
3453
-		// contamination de la session appelante, pour les inclusions statiques
3454
-		if (isset($page['invalideurs']['session'])) {
3455
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3456
-		}
3457
-	}
3458
-
3459
-	// restaurer le sessionnement du contexte appelant,
3460
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3461
-	if (isset($cache_utilise_session_appelant)) {
3462
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3463
-	}
3464
-
3465
-	$GLOBALS['_INC_PUBLIC']--;
3466
-
3467
-	if ($lang_select) {
3468
-		lang_select();
3469
-	}
3470
-	if (isset($options['raw']) and $options['raw']) {
3471
-		return is_array($fond) ? $pages : reset($pages);
3472
-	} else {
3473
-		return $options['trim'] ? ltrim($texte) : $texte;
3474
-	}
3372
+    if (!function_exists('evaluer_fond')) {
3373
+        include_spip('public/assembler');
3374
+    }
3375
+    // assurer la compat avec l'ancienne syntaxe
3376
+    // (trim etait le 3eme argument, par defaut a true)
3377
+    if (!is_array($options)) {
3378
+        $options = ['trim' => $options];
3379
+    }
3380
+    if (!isset($options['trim'])) {
3381
+        $options['trim'] = true;
3382
+    }
3383
+
3384
+    if (isset($contexte['connect'])) {
3385
+        $connect = $contexte['connect'];
3386
+        unset($contexte['connect']);
3387
+    }
3388
+
3389
+    $texte = '';
3390
+    $pages = [];
3391
+    $lang_select = '';
3392
+    if (!isset($options['etoile']) or !$options['etoile']) {
3393
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3394
+        if (!isset($contexte['lang'])) {
3395
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3396
+        }
3397
+
3398
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3399
+            $lang_select = lang_select($contexte['lang']);
3400
+        }
3401
+    }
3402
+
3403
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3404
+        $GLOBALS['_INC_PUBLIC'] = 0;
3405
+    }
3406
+
3407
+    $GLOBALS['_INC_PUBLIC']++;
3408
+
3409
+    // fix #4235
3410
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3411
+
3412
+
3413
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3414
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3415
+
3416
+        $page = evaluer_fond($f, $contexte, $connect);
3417
+        if ($page === '') {
3418
+            $c = $options['compil'] ?? '';
3419
+            $a = ['fichier' => $f];
3420
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3421
+            erreur_squelette($erreur, $c);
3422
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3423
+            $page = ['texte' => '', 'erreur' => $erreur];
3424
+        }
3425
+
3426
+        $page = pipeline('recuperer_fond', [
3427
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3428
+            'data' => $page
3429
+        ]);
3430
+        if (isset($options['ajax']) and $options['ajax']) {
3431
+            if (!function_exists('encoder_contexte_ajax')) {
3432
+                include_spip('inc/filtres');
3433
+            }
3434
+            $page['texte'] = encoder_contexte_ajax(
3435
+                array_merge(
3436
+                    $contexte,
3437
+                    ['fond' => $f],
3438
+                    ($connect ? ['connect' => $connect] : [])
3439
+                ),
3440
+                '',
3441
+                $page['texte'],
3442
+                $options['ajax']
3443
+            );
3444
+        }
3445
+
3446
+        if (isset($options['raw']) and $options['raw']) {
3447
+            $pages[] = $page;
3448
+        } else {
3449
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3450
+        }
3451
+
3452
+        // contamination de la session appelante, pour les inclusions statiques
3453
+        if (isset($page['invalideurs']['session'])) {
3454
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3455
+        }
3456
+    }
3457
+
3458
+    // restaurer le sessionnement du contexte appelant,
3459
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3460
+    if (isset($cache_utilise_session_appelant)) {
3461
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3462
+    }
3463
+
3464
+    $GLOBALS['_INC_PUBLIC']--;
3465
+
3466
+    if ($lang_select) {
3467
+        lang_select();
3468
+    }
3469
+    if (isset($options['raw']) and $options['raw']) {
3470
+        return is_array($fond) ? $pages : reset($pages);
3471
+    } else {
3472
+        return $options['trim'] ? ltrim($texte) : $texte;
3473
+    }
3475 3474
 }
3476 3475
 
3477 3476
 /**
@@ -3481,7 +3480,7 @@  discard block
 block discarded – undo
3481 3480
  * @return string
3482 3481
  */
3483 3482
 function trouve_modele($nom) {
3484
-	return trouver_fond($nom, 'modeles/');
3483
+    return trouver_fond($nom, 'modeles/');
3485 3484
 }
3486 3485
 
3487 3486
 /**
@@ -3497,21 +3496,21 @@  discard block
 block discarded – undo
3497 3496
  * @return array|string
3498 3497
  */
3499 3498
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3500
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3501
-	if (!$pathinfo) {
3502
-		return $f;
3503
-	}
3504
-	// renvoyer un tableau detaille si $pathinfo==true
3505
-	$p = pathinfo($f);
3506
-	if (!isset($p['extension']) or !$p['extension']) {
3507
-		$p['extension'] = _EXTENSION_SQUELETTES;
3508
-	}
3509
-	if (!isset($p['extension']) or !$p['filename']) {
3510
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3511
-	}
3512
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3499
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3500
+    if (!$pathinfo) {
3501
+        return $f;
3502
+    }
3503
+    // renvoyer un tableau detaille si $pathinfo==true
3504
+    $p = pathinfo($f);
3505
+    if (!isset($p['extension']) or !$p['extension']) {
3506
+        $p['extension'] = _EXTENSION_SQUELETTES;
3507
+    }
3508
+    if (!isset($p['extension']) or !$p['filename']) {
3509
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3510
+    }
3511
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3513 3512
 
3514
-	return $p;
3513
+    return $p;
3515 3514
 }
3516 3515
 
3517 3516
 /**
@@ -3531,21 +3530,21 @@  discard block
 block discarded – undo
3531 3530
  *     Nom de l'exec, sinon chaîne vide.
3532 3531
  **/
3533 3532
 function tester_url_ecrire($nom) {
3534
-	static $exec = [];
3535
-	if (isset($exec[$nom])) {
3536
-		return $exec[$nom];
3537
-	}
3538
-	// tester si c'est une page en squelette
3539
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3540
-		return $exec[$nom] = 'fond';
3541
-	} // echafaudage d'un fond !
3542
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3543
-		return $exec[$nom] = 'fond';
3544
-	}
3545
-	// attention, il ne faut pas inclure l'exec ici
3546
-	// car sinon #URL_ECRIRE provoque des inclusions
3547
-	// et des define intrusifs potentiels
3548
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3533
+    static $exec = [];
3534
+    if (isset($exec[$nom])) {
3535
+        return $exec[$nom];
3536
+    }
3537
+    // tester si c'est une page en squelette
3538
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3539
+        return $exec[$nom] = 'fond';
3540
+    } // echafaudage d'un fond !
3541
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3542
+        return $exec[$nom] = 'fond';
3543
+    }
3544
+    // attention, il ne faut pas inclure l'exec ici
3545
+    // car sinon #URL_ECRIRE provoque des inclusions
3546
+    // et des define intrusifs potentiels
3547
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3549 3548
 }
3550 3549
 
3551 3550
 /**
@@ -3555,8 +3554,8 @@  discard block
 block discarded – undo
3555 3554
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3556 3555
  **/
3557 3556
 function html5_permis() {
3558
-	return (!defined('_VERSION_HTML')
3559
-		or _VERSION_HTML !== 'html4');
3557
+    return (!defined('_VERSION_HTML')
3558
+        or _VERSION_HTML !== 'html4');
3560 3559
 }
3561 3560
 
3562 3561
 /**
@@ -3566,30 +3565,30 @@  discard block
 block discarded – undo
3566 3565
  * @return array
3567 3566
  */
3568 3567
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3569
-	$formats = null;
3570
-	if (!is_null($gd)) {
3571
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3572
-		if (isset($GLOBALS['meta'][$config])) {
3573
-			$formats = $GLOBALS['meta'][$config];
3574
-			$formats = explode(',', $formats);
3575
-			$formats = array_filter($formats);
3576
-			$formats = array_map('trim', $formats);
3577
-		}
3578
-	}
3579
-	if (is_null($formats)) {
3580
-		include_spip('inc/filtres_images_lib_mini');
3581
-		$formats = _image_extensions_acceptees_en_entree();
3582
-	}
3583
-
3584
-	if ($svg_allowed) {
3585
-		if (!in_array('svg', $formats)) {
3586
-			$formats[] = 'svg';
3587
-		}
3588
-	}
3589
-	else {
3590
-		$formats = array_diff($formats, ['svg']);
3591
-	}
3592
-	return $formats;
3568
+    $formats = null;
3569
+    if (!is_null($gd)) {
3570
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3571
+        if (isset($GLOBALS['meta'][$config])) {
3572
+            $formats = $GLOBALS['meta'][$config];
3573
+            $formats = explode(',', $formats);
3574
+            $formats = array_filter($formats);
3575
+            $formats = array_map('trim', $formats);
3576
+        }
3577
+    }
3578
+    if (is_null($formats)) {
3579
+        include_spip('inc/filtres_images_lib_mini');
3580
+        $formats = _image_extensions_acceptees_en_entree();
3581
+    }
3582
+
3583
+    if ($svg_allowed) {
3584
+        if (!in_array('svg', $formats)) {
3585
+            $formats[] = 'svg';
3586
+        }
3587
+    }
3588
+    else {
3589
+        $formats = array_diff($formats, ['svg']);
3590
+    }
3591
+    return $formats;
3593 3592
 }
3594 3593
 
3595 3594
 /**
@@ -3598,20 +3597,20 @@  discard block
 block discarded – undo
3598 3597
  * @return array|bool
3599 3598
  */
3600 3599
 function spip_getimagesize($fichier) {
3601
-	if (!$imagesize = @getimagesize($fichier)) {
3602
-		include_spip('inc/svg');
3603
-		if ($attrs = svg_lire_attributs($fichier)) {
3604
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3605
-			$imagesize = [
3606
-				$width,
3607
-				$height,
3608
-				IMAGETYPE_SVG,
3609
-				"width=\"{$width}\" height=\"{$height}\"",
3610
-				'mime' => 'image/svg+xml'
3611
-			];
3612
-		}
3613
-	}
3614
-	return $imagesize;
3600
+    if (!$imagesize = @getimagesize($fichier)) {
3601
+        include_spip('inc/svg');
3602
+        if ($attrs = svg_lire_attributs($fichier)) {
3603
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3604
+            $imagesize = [
3605
+                $width,
3606
+                $height,
3607
+                IMAGETYPE_SVG,
3608
+                "width=\"{$width}\" height=\"{$height}\"",
3609
+                'mime' => 'image/svg+xml'
3610
+            ];
3611
+        }
3612
+    }
3613
+    return $imagesize;
3615 3614
 }
3616 3615
 
3617 3616
 /**
@@ -3625,19 +3624,19 @@  discard block
 block discarded – undo
3625 3624
  * @param string $statut
3626 3625
  */
3627 3626
 function avertir_auteurs($nom, $message, $statut = '') {
3628
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3629
-	if (
3630
-		!$alertes
3631
-		or !is_array($alertes = unserialize($alertes))
3632
-	) {
3633
-		$alertes = [];
3634
-	}
3627
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3628
+    if (
3629
+        !$alertes
3630
+        or !is_array($alertes = unserialize($alertes))
3631
+    ) {
3632
+        $alertes = [];
3633
+    }
3635 3634
 
3636
-	if (!isset($alertes[$statut])) {
3637
-		$alertes[$statut] = [];
3638
-	}
3639
-	$alertes[$statut][$nom] = $message;
3640
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3635
+    if (!isset($alertes[$statut])) {
3636
+        $alertes[$statut] = [];
3637
+    }
3638
+    $alertes[$statut][$nom] = $message;
3639
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3641 3640
 }
3642 3641
 
3643 3642
 /**
@@ -3651,10 +3650,10 @@  discard block
 block discarded – undo
3651 3650
  * @return string|string[]
3652 3651
  */
3653 3652
 function spip_sanitize_classname($classes) {
3654
-	if (is_array($classes)) {
3655
-		return array_map('spip_sanitize_classname', $classes);
3656
-	}
3657
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3653
+    if (is_array($classes)) {
3654
+        return array_map('spip_sanitize_classname', $classes);
3655
+    }
3656
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3658 3657
 }
3659 3658
 
3660 3659
 
@@ -3679,32 +3678,32 @@  discard block
 block discarded – undo
3679 3678
  *    Avec operateur : bool.
3680 3679
  **/
3681 3680
 function spip_version_compare($v1, $v2, $op = null) {
3682
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3683
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3684
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3685
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3686
-
3687
-	$v1 = explode('.', $v1);
3688
-	$v2 = explode('.', $v2);
3689
-	// $v1 est toujours une version, donc sans etoile
3690
-	while (count($v1) < count($v2)) {
3691
-		$v1[] = '0';
3692
-	}
3693
-
3694
-	// $v2 peut etre une borne, donc accepte l'etoile
3695
-	$etoile = false;
3696
-	foreach ($v1 as $k => $v) {
3697
-		if (!isset($v2[$k])) {
3698
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3699
-		} else {
3700
-			if ($v2[$k] == '*') {
3701
-				$etoile = true;
3702
-				$v2[$k] = $v;
3703
-			}
3704
-		}
3705
-	}
3706
-	$v1 = implode('.', $v1);
3707
-	$v2 = implode('.', $v2);
3708
-
3709
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3681
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3682
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3683
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3684
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3685
+
3686
+    $v1 = explode('.', $v1);
3687
+    $v2 = explode('.', $v2);
3688
+    // $v1 est toujours une version, donc sans etoile
3689
+    while (count($v1) < count($v2)) {
3690
+        $v1[] = '0';
3691
+    }
3692
+
3693
+    // $v2 peut etre une borne, donc accepte l'etoile
3694
+    $etoile = false;
3695
+    foreach ($v1 as $k => $v) {
3696
+        if (!isset($v2[$k])) {
3697
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3698
+        } else {
3699
+            if ($v2[$k] == '*') {
3700
+                $etoile = true;
3701
+                $v2[$k] = $v;
3702
+            }
3703
+        }
3704
+    }
3705
+    $v1 = implode('.', $v1);
3706
+    $v2 = implode('.', $v2);
3707
+
3708
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3710 3709
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2451 added lines, -2451 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,38 +77,38 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = $desc['commit_short'] ?? $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = $desc['commit_short'] ?? $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if ($texte === null || !strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if ($texte === null || !strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	[$h, $l] = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    [$h, $l] = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	[$h, $l] = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    [$h, $l] = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
-	static $to = null;
870
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -910,44 +910,44 @@  discard block
 block discarded – undo
910 910
  *     Texte encodé pour XML
911 911
  */
912 912
 function texte_backend(string $texte): string {
913
-	if ($texte === '') {
914
-		return '';
915
-	}
913
+    if ($texte === '') {
914
+        return '';
915
+    }
916 916
 
917
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
917
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
918 918
 
919
-	// si on a des liens ou des images, les passer en absolu
920
-	$texte = liens_absolus($texte);
919
+    // si on a des liens ou des images, les passer en absolu
920
+    $texte = liens_absolus($texte);
921 921
 
922
-	// echapper les tags &gt; &lt;
923
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
922
+    // echapper les tags &gt; &lt;
923
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
924 924
 
925
-	// importer les &eacute;
926
-	$texte = filtrer_entites($texte);
925
+    // importer les &eacute;
926
+    $texte = filtrer_entites($texte);
927 927
 
928
-	// " -> &quot; et tout ce genre de choses
929
-	$u = $GLOBALS['meta']['pcre_u'];
930
-	$texte = str_replace('&nbsp;', ' ', $texte);
931
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
-	$texte = entites_html($texte, false, false);
934
-	// mais bien echapper les double quotes !
935
-	$texte = str_replace('"', '&#034;', $texte);
928
+    // " -> &quot; et tout ce genre de choses
929
+    $u = $GLOBALS['meta']['pcre_u'];
930
+    $texte = str_replace('&nbsp;', ' ', $texte);
931
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
+    $texte = entites_html($texte, false, false);
934
+    // mais bien echapper les double quotes !
935
+    $texte = str_replace('"', '&#034;', $texte);
936 936
 
937
-	// verifier le charset
938
-	$texte = charset2unicode($texte);
937
+    // verifier le charset
938
+    $texte = charset2unicode($texte);
939 939
 
940
-	// Caracteres problematiques en iso-latin 1
941
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
-		$texte = str_replace(chr(156), '&#156;', $texte);
943
-		$texte = str_replace(chr(140), '&#140;', $texte);
944
-		$texte = str_replace(chr(159), '&#159;', $texte);
945
-	}
940
+    // Caracteres problematiques en iso-latin 1
941
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
+        $texte = str_replace(chr(156), '&#156;', $texte);
943
+        $texte = str_replace(chr(140), '&#140;', $texte);
944
+        $texte = str_replace(chr(159), '&#159;', $texte);
945
+    }
946 946
 
947
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
948
-	// et le caractere apostrophe alourdit les squelettes avec PHP
949
-	// ==> on les remplace par l'entite HTML
950
-	return str_replace($apostrophe, "'", $texte);
947
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
948
+    // et le caractere apostrophe alourdit les squelettes avec PHP
949
+    // ==> on les remplace par l'entite HTML
950
+    return str_replace($apostrophe, "'", $texte);
951 951
 }
952 952
 
953 953
 /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
  *     Texte encodé et quote pour XML
965 965
  */
966 966
 function texte_backendq(string $texte): string {
967
-	return addslashes(texte_backend($texte));
967
+    return addslashes(texte_backend($texte));
968 968
 }
969 969
 
970 970
 
@@ -987,11 +987,11 @@  discard block
 block discarded – undo
987 987
  *     Numéro de titre, sinon chaîne vide
988 988
  **/
989 989
 function supprimer_numero($texte) {
990
-	return preg_replace(
991
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
-		'',
993
-		$texte
994
-	);
990
+    return preg_replace(
991
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
+        '',
993
+        $texte
994
+    );
995 995
 }
996 996
 
997 997
 /**
@@ -1014,17 +1014,17 @@  discard block
 block discarded – undo
1014 1014
  *     Numéro de titre, sinon chaîne vide
1015 1015
  **/
1016 1016
 function recuperer_numero($texte) {
1017
-	if (
1018
-		preg_match(
1019
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
-			$texte,
1021
-			$regs
1022
-		)
1023
-	) {
1024
-		return strval($regs[1]);
1025
-	} else {
1026
-		return '';
1027
-	}
1017
+    if (
1018
+        preg_match(
1019
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
+            $texte,
1021
+            $regs
1022
+        )
1023
+    ) {
1024
+        return strval($regs[1]);
1025
+    } else {
1026
+        return '';
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1051,16 +1051,16 @@  discard block
 block discarded – undo
1051 1051
  *     Texte converti
1052 1052
  **/
1053 1053
 function supprimer_tags(?string $texte, $rempl = ''): string {
1054
-	if ($texte === null || !strlen($texte)) {
1055
-		return '';
1056
-	}
1057
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
-	// ne pas oublier un < final non ferme car coupe
1059
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
-	// mais qui peut aussi etre un simple signe plus petit que
1061
-	$texte = str_replace('<', '&lt;', $texte);
1054
+    if ($texte === null || !strlen($texte)) {
1055
+        return '';
1056
+    }
1057
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
+    // ne pas oublier un < final non ferme car coupe
1059
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
+    // mais qui peut aussi etre un simple signe plus petit que
1061
+    $texte = str_replace('<', '&lt;', $texte);
1062 1062
 
1063
-	return $texte;
1063
+    return $texte;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1083,9 +1083,9 @@  discard block
 block discarded – undo
1083 1083
  *     Texte converti
1084 1084
  **/
1085 1085
 function echapper_tags($texte, $rempl = '') {
1086
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1086
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1087 1087
 
1088
-	return $texte;
1088
+    return $texte;
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1106,18 +1106,18 @@  discard block
 block discarded – undo
1106 1106
  *     Texte converti
1107 1107
  **/
1108 1108
 function textebrut($texte) {
1109
-	$u = $GLOBALS['meta']['pcre_u'];
1110
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
-	$texte = preg_replace("/^\n+/", '', $texte);
1113
-	$texte = preg_replace("/\n+$/", '', $texte);
1114
-	$texte = preg_replace("/\n +/", "\n", $texte);
1115
-	$texte = supprimer_tags($texte);
1116
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
-	$texte = str_replace('&#8217;', "'", $texte);
1109
+    $u = $GLOBALS['meta']['pcre_u'];
1110
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
+    $texte = preg_replace("/^\n+/", '', $texte);
1113
+    $texte = preg_replace("/\n+$/", '', $texte);
1114
+    $texte = preg_replace("/\n +/", "\n", $texte);
1115
+    $texte = supprimer_tags($texte);
1116
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
+    $texte = str_replace('&#8217;', "'", $texte);
1119 1119
 
1120
-	return $texte;
1120
+    return $texte;
1121 1121
 }
1122 1122
 
1123 1123
 
@@ -1133,23 +1133,23 @@  discard block
 block discarded – undo
1133 1133
  *     Texte avec liens ouvrants
1134 1134
  **/
1135 1135
 function liens_ouvrants($texte) {
1136
-	if (
1137
-		preg_match_all(
1138
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
-			$texte,
1140
-			$liens,
1141
-			PREG_PATTERN_ORDER
1142
-		)
1143
-	) {
1144
-		foreach ($liens[0] as $a) {
1145
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
-			$ablank = inserer_attribut($a, 'rel', $rel);
1147
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1148
-			$texte = str_replace($a, $ablank, $texte);
1149
-		}
1150
-	}
1151
-
1152
-	return $texte;
1136
+    if (
1137
+        preg_match_all(
1138
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
+            $texte,
1140
+            $liens,
1141
+            PREG_PATTERN_ORDER
1142
+        )
1143
+    ) {
1144
+        foreach ($liens[0] as $a) {
1145
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
+            $ablank = inserer_attribut($a, 'rel', $rel);
1147
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1148
+            $texte = str_replace($a, $ablank, $texte);
1149
+        }
1150
+    }
1151
+
1152
+    return $texte;
1153 1153
 }
1154 1154
 
1155 1155
 /**
@@ -1159,22 +1159,22 @@  discard block
 block discarded – undo
1159 1159
  * @return string
1160 1160
  */
1161 1161
 function liens_nofollow($texte) {
1162
-	if (stripos($texte, '<a') === false) {
1163
-		return $texte;
1164
-	}
1162
+    if (stripos($texte, '<a') === false) {
1163
+        return $texte;
1164
+    }
1165 1165
 
1166
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
-		foreach ($regs[0] as $a) {
1168
-			$rel = extraire_attribut($a, 'rel');
1169
-			if (strpos($rel, 'nofollow') === false) {
1170
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1171
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1172
-				$texte = str_replace($a, $anofollow, $texte);
1173
-			}
1174
-		}
1175
-	}
1166
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
+        foreach ($regs[0] as $a) {
1168
+            $rel = extraire_attribut($a, 'rel');
1169
+            if (strpos($rel, 'nofollow') === false) {
1170
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1171
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1172
+                $texte = str_replace($a, $anofollow, $texte);
1173
+            }
1174
+        }
1175
+    }
1176 1176
 
1177
-	return $texte;
1177
+    return $texte;
1178 1178
 }
1179 1179
 
1180 1180
 /**
@@ -1193,12 +1193,12 @@  discard block
 block discarded – undo
1193 1193
  *     Texte sans paraghaphes
1194 1194
  **/
1195 1195
 function PtoBR($texte) {
1196
-	$u = $GLOBALS['meta']['pcre_u'];
1197
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1198
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1196
+    $u = $GLOBALS['meta']['pcre_u'];
1197
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1198
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1200 1200
 
1201
-	return $texte;
1201
+    return $texte;
1202 1202
 }
1203 1203
 
1204 1204
 
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
  * @return string Texte encadré du style CSS
1224 1224
  */
1225 1225
 function lignes_longues($texte) {
1226
-	if (!strlen(trim($texte))) {
1227
-		return $texte;
1228
-	}
1229
-	include_spip('inc/texte');
1230
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
-		'div' : 'span';
1226
+    if (!strlen(trim($texte))) {
1227
+        return $texte;
1228
+    }
1229
+    include_spip('inc/texte');
1230
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
+        'div' : 'span';
1232 1232
 
1233
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1233
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1234 1234
 }
1235 1235
 
1236 1236
 /**
@@ -1249,30 +1249,30 @@  discard block
 block discarded – undo
1249 1249
  * @return string Texte en majuscule
1250 1250
  */
1251 1251
 function majuscules($texte) {
1252
-	if (!strlen($texte)) {
1253
-		return '';
1254
-	}
1252
+    if (!strlen($texte)) {
1253
+        return '';
1254
+    }
1255 1255
 
1256
-	// Cas du turc
1257
-	if ($GLOBALS['spip_lang'] == 'tr') {
1258
-		# remplacer hors des tags et des entites
1259
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
-			foreach ($regs as $n => $match) {
1261
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
-			}
1263
-		}
1256
+    // Cas du turc
1257
+    if ($GLOBALS['spip_lang'] == 'tr') {
1258
+        # remplacer hors des tags et des entites
1259
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
+            foreach ($regs as $n => $match) {
1261
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
+            }
1263
+        }
1264 1264
 
1265
-		$texte = str_replace('i', '&#304;', $texte);
1265
+        $texte = str_replace('i', '&#304;', $texte);
1266 1266
 
1267
-		if ($regs) {
1268
-			foreach ($regs as $n => $match) {
1269
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
-			}
1271
-		}
1272
-	}
1267
+        if ($regs) {
1268
+            foreach ($regs as $n => $match) {
1269
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
+            }
1271
+        }
1272
+    }
1273 1273
 
1274
-	// Cas general
1275
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1274
+    // Cas general
1275
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1276 1276
 }
1277 1277
 
1278 1278
 /**
@@ -1290,29 +1290,29 @@  discard block
 block discarded – undo
1290 1290
  * @return string
1291 1291
  **/
1292 1292
 function taille_en_octets($taille) {
1293
-	if (!defined('_KILOBYTE')) {
1294
-		/**
1295
-		 * Définit le nombre d'octets dans un Kilobyte
1296
-		 *
1297
-		 * @var int
1298
-		 **/
1299
-		define('_KILOBYTE', 1024);
1300
-	}
1293
+    if (!defined('_KILOBYTE')) {
1294
+        /**
1295
+         * Définit le nombre d'octets dans un Kilobyte
1296
+         *
1297
+         * @var int
1298
+         **/
1299
+        define('_KILOBYTE', 1024);
1300
+    }
1301 1301
 
1302
-	if ($taille < 1) {
1303
-		return '';
1304
-	}
1305
-	if ($taille < _KILOBYTE) {
1306
-		$taille = _T('taille_octets', ['taille' => $taille]);
1307
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
-	} else {
1312
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
-	}
1302
+    if ($taille < 1) {
1303
+        return '';
1304
+    }
1305
+    if ($taille < _KILOBYTE) {
1306
+        $taille = _T('taille_octets', ['taille' => $taille]);
1307
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
+    } else {
1312
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
+    }
1314 1314
 
1315
-	return $taille;
1315
+    return $taille;
1316 1316
 }
1317 1317
 
1318 1318
 
@@ -1334,21 +1334,21 @@  discard block
 block discarded – undo
1334 1334
  *     Texte prêt pour être utilisé en attribut HTML
1335 1335
  **/
1336 1336
 function attribut_html(?string $texte, $textebrut = true): string {
1337
-	if ($texte === null) {
1338
-		return '';
1339
-	}
1340
-	$u = $GLOBALS['meta']['pcre_u'];
1341
-	if ($textebrut) {
1342
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
-	}
1344
-	$texte = texte_backend($texte);
1345
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337
+    if ($texte === null) {
1338
+        return '';
1339
+    }
1340
+    $u = $GLOBALS['meta']['pcre_u'];
1341
+    if ($textebrut) {
1342
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
+    }
1344
+    $texte = texte_backend($texte);
1345
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346 1346
 
1347
-	return preg_replace(
1348
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
-		['&', '&#38;'],
1350
-		$texte
1351
-	);
1347
+    return preg_replace(
1348
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
+        ['&', '&#38;'],
1350
+        $texte
1351
+    );
1352 1352
 }
1353 1353
 
1354 1354
 
@@ -1368,15 +1368,15 @@  discard block
 block discarded – undo
1368 1368
  *     URL ou chaîne vide
1369 1369
  **/
1370 1370
 function vider_url(?string $url, $entites = true): string {
1371
-	if ($url === null) {
1372
-		return '';
1373
-	}
1374
-	# un message pour abs_url
1375
-	$GLOBALS['mode_abs_url'] = 'url';
1376
-	$url = trim($url);
1377
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1371
+    if ($url === null) {
1372
+        return '';
1373
+    }
1374
+    # un message pour abs_url
1375
+    $GLOBALS['mode_abs_url'] = 'url';
1376
+    $url = trim($url);
1377
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1378 1378
 
1379
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1379
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1380 1380
 }
1381 1381
 
1382 1382
 
@@ -1391,10 +1391,10 @@  discard block
 block discarded – undo
1391 1391
  * @return string Adresse email maquillée
1392 1392
  **/
1393 1393
 function antispam($texte) {
1394
-	include_spip('inc/acces');
1395
-	$masque = creer_pass_aleatoire(3);
1394
+    include_spip('inc/acces');
1395
+    $masque = creer_pass_aleatoire(3);
1396 1396
 
1397
-	return preg_replace('/@/', " $masque ", $texte);
1397
+    return preg_replace('/@/', " $masque ", $texte);
1398 1398
 }
1399 1399
 
1400 1400
 /**
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
  *     True si on a le droit d'accès, false sinon.
1427 1427
  **/
1428 1428
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1429
-	include_spip('inc/acces');
1430
-	if ($op) {
1431
-		$dir .= " $op $args";
1432
-	}
1429
+    include_spip('inc/acces');
1430
+    if ($op) {
1431
+        $dir .= " $op $args";
1432
+    }
1433 1433
 
1434
-	return verifier_low_sec($id_auteur, $cle, $dir);
1434
+    return verifier_low_sec($id_auteur, $cle, $dir);
1435 1435
 }
1436 1436
 
1437 1437
 /**
@@ -1456,13 +1456,13 @@  discard block
 block discarded – undo
1456 1456
  *     Retourne $texte, sinon $sinon.
1457 1457
  **/
1458 1458
 function sinon($texte, $sinon = '') {
1459
-	if ($texte) {
1460
-		return $texte;
1461
-	} elseif (is_scalar($texte) and strlen($texte)) {
1462
-		return $texte;
1463
-	} else {
1464
-		return $sinon;
1465
-	}
1459
+    if ($texte) {
1460
+        return $texte;
1461
+    } elseif (is_scalar($texte) and strlen($texte)) {
1462
+        return $texte;
1463
+    } else {
1464
+        return $sinon;
1465
+    }
1466 1466
 }
1467 1467
 
1468 1468
 /**
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
  * @return mixed
1487 1487
  **/
1488 1488
 function choixsivide($a, $vide, $pasvide) {
1489
-	return $a ? $pasvide : $vide;
1489
+    return $a ? $pasvide : $vide;
1490 1490
 }
1491 1491
 
1492 1492
 /**
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
  * @return mixed
1511 1511
  **/
1512 1512
 function choixsiegal($a1, $a2, $v, $f) {
1513
-	return ($a1 == $a2) ? $v : $f;
1513
+    return ($a1 == $a2) ? $v : $f;
1514 1514
 }
1515 1515
 
1516 1516
 //
@@ -1529,13 +1529,13 @@  discard block
 block discarded – undo
1529 1529
  * @return string
1530 1530
  **/
1531 1531
 function filtrer_ical($texte) {
1532
-	#include_spip('inc/charsets');
1533
-	$texte = html2unicode($texte);
1534
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
-	$texte = preg_replace('/,/', '\,', $texte);
1532
+    #include_spip('inc/charsets');
1533
+    $texte = html2unicode($texte);
1534
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
+    $texte = preg_replace("/\n/", ' ', $texte);
1536
+    $texte = preg_replace('/,/', '\,', $texte);
1537 1537
 
1538
-	return $texte;
1538
+    return $texte;
1539 1539
 }
1540 1540
 
1541 1541
 
@@ -1560,54 +1560,54 @@  discard block
 block discarded – undo
1560 1560
  * @return string
1561 1561
  **/
1562 1562
 function post_autobr($texte, $delim = "\n_ ") {
1563
-	if (!function_exists('echappe_html')) {
1564
-		include_spip('inc/texte_mini');
1565
-	}
1566
-	$texte = str_replace("\r\n", "\r", $texte);
1567
-	$texte = str_replace("\r", "\n", $texte);
1568
-
1569
-	if (preg_match(",\n+$,", $texte, $fin)) {
1570
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
-	} else {
1572
-		$fin = '';
1573
-	}
1574
-
1575
-	$texte = echappe_html($texte, '', true);
1576
-
1577
-	// echapper les modeles
1578
-	if (strpos($texte, '<') !== false) {
1579
-		include_spip('inc/lien');
1580
-		if (defined('_PREG_MODELE')) {
1581
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1583
-		}
1584
-	}
1585
-
1586
-	$debut = '';
1587
-	$suite = $texte;
1588
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1589
-		$debut .= substr($suite, 0, $t - 1);
1590
-		$suite = substr($suite, $t);
1591
-		$car = substr($suite, 0, 1);
1592
-		if (
1593
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
-		) {
1597
-			$debut .= $delim;
1598
-		} else {
1599
-			$debut .= "\n";
1600
-		}
1601
-		if (preg_match(",^\n+,", $suite, $regs)) {
1602
-			$debut .= $regs[0];
1603
-			$suite = substr($suite, strlen($regs[0]));
1604
-		}
1605
-	}
1606
-	$texte = $debut . $suite;
1607
-
1608
-	$texte = echappe_retour($texte);
1609
-
1610
-	return $texte . $fin;
1563
+    if (!function_exists('echappe_html')) {
1564
+        include_spip('inc/texte_mini');
1565
+    }
1566
+    $texte = str_replace("\r\n", "\r", $texte);
1567
+    $texte = str_replace("\r", "\n", $texte);
1568
+
1569
+    if (preg_match(",\n+$,", $texte, $fin)) {
1570
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
+    } else {
1572
+        $fin = '';
1573
+    }
1574
+
1575
+    $texte = echappe_html($texte, '', true);
1576
+
1577
+    // echapper les modeles
1578
+    if (strpos($texte, '<') !== false) {
1579
+        include_spip('inc/lien');
1580
+        if (defined('_PREG_MODELE')) {
1581
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1583
+        }
1584
+    }
1585
+
1586
+    $debut = '';
1587
+    $suite = $texte;
1588
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1589
+        $debut .= substr($suite, 0, $t - 1);
1590
+        $suite = substr($suite, $t);
1591
+        $car = substr($suite, 0, 1);
1592
+        if (
1593
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
+        ) {
1597
+            $debut .= $delim;
1598
+        } else {
1599
+            $debut .= "\n";
1600
+        }
1601
+        if (preg_match(",^\n+,", $suite, $regs)) {
1602
+            $debut .= $regs[0];
1603
+            $suite = substr($suite, strlen($regs[0]));
1604
+        }
1605
+    }
1606
+    $texte = $debut . $suite;
1607
+
1608
+    $texte = echappe_retour($texte);
1609
+
1610
+    return $texte . $fin;
1611 1611
 }
1612 1612
 
1613 1613
 
@@ -1648,47 +1648,47 @@  discard block
 block discarded – undo
1648 1648
  * @return string
1649 1649
  **/
1650 1650
 function extraire_idiome($letexte, $lang = null, $options = []) {
1651
-	static $traduire = false;
1652
-	if (
1653
-		$letexte
1654
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
-	) {
1656
-		if (!$traduire) {
1657
-			$traduire = charger_fonction('traduire', 'inc');
1658
-			include_spip('inc/lang');
1659
-		}
1660
-		if (!$lang) {
1661
-			$lang = $GLOBALS['spip_lang'];
1662
-		}
1663
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
-		if (is_bool($options)) {
1665
-			$options = ['echappe_span' => $options];
1666
-		}
1667
-		if (!isset($options['echappe_span'])) {
1668
-			$options = array_merge($options, ['echappe_span' => false]);
1669
-		}
1670
-
1671
-		foreach ($regs as $reg) {
1672
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
-			$desc = $traduire($cle, $lang, true);
1674
-			$l = $desc->langue;
1675
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
-			if (strlen($desc->texte)) {
1677
-				$trad = code_echappement($desc->texte, 'idiome', false);
1678
-				if ($l !== $lang) {
1679
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
-				}
1681
-				if (lang_dir($l) !== lang_dir($lang)) {
1682
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
-				}
1684
-				if (!$options['echappe_span']) {
1685
-					$trad = echappe_retour($trad, 'idiome');
1686
-				}
1687
-				$letexte = str_replace($reg[0], $trad, $letexte);
1688
-			}
1689
-		}
1690
-	}
1691
-	return $letexte;
1651
+    static $traduire = false;
1652
+    if (
1653
+        $letexte
1654
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
+    ) {
1656
+        if (!$traduire) {
1657
+            $traduire = charger_fonction('traduire', 'inc');
1658
+            include_spip('inc/lang');
1659
+        }
1660
+        if (!$lang) {
1661
+            $lang = $GLOBALS['spip_lang'];
1662
+        }
1663
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
+        if (is_bool($options)) {
1665
+            $options = ['echappe_span' => $options];
1666
+        }
1667
+        if (!isset($options['echappe_span'])) {
1668
+            $options = array_merge($options, ['echappe_span' => false]);
1669
+        }
1670
+
1671
+        foreach ($regs as $reg) {
1672
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
+            $desc = $traduire($cle, $lang, true);
1674
+            $l = $desc->langue;
1675
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
+            if (strlen($desc->texte)) {
1677
+                $trad = code_echappement($desc->texte, 'idiome', false);
1678
+                if ($l !== $lang) {
1679
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
+                }
1681
+                if (lang_dir($l) !== lang_dir($lang)) {
1682
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
+                }
1684
+                if (!$options['echappe_span']) {
1685
+                    $trad = echappe_retour($trad, 'idiome');
1686
+                }
1687
+                $letexte = str_replace($reg[0], $trad, $letexte);
1688
+            }
1689
+        }
1690
+    }
1691
+    return $letexte;
1692 1692
 }
1693 1693
 
1694 1694
 /**
@@ -1740,68 +1740,68 @@  discard block
 block discarded – undo
1740 1740
  **/
1741 1741
 function extraire_multi($letexte, $lang = null, $options = []) {
1742 1742
 
1743
-	if (
1744
-		$letexte
1745
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
-	) {
1747
-		if (!$lang) {
1748
-			$lang = $GLOBALS['spip_lang'];
1749
-		}
1750
-
1751
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
-		if (is_bool($options)) {
1753
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
-		}
1755
-		if (!isset($options['echappe_span'])) {
1756
-			$options = array_merge($options, ['echappe_span' => false]);
1757
-		}
1758
-		if (!isset($options['lang_defaut'])) {
1759
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
-		}
1761
-
1762
-		include_spip('inc/lang');
1763
-		foreach ($regs as $reg) {
1764
-			// chercher la version de la langue courante
1765
-			$trads = extraire_trads($reg[1]);
1766
-			if ($l = approcher_langue($trads, $lang)) {
1767
-				$trad = $trads[$l];
1768
-			} else {
1769
-				if ($options['lang_defaut'] == 'aucune') {
1770
-					$trad = '';
1771
-				} else {
1772
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
-					// ou la premiere dispo
1774
-					// mais typographier le texte selon les regles de celle-ci
1775
-					// Attention aux blocs multi sur plusieurs lignes
1776
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
-						$l = key($trads);
1778
-					}
1779
-					$trad = $trads[$l];
1780
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1781
-					$trad = $typographie($trad);
1782
-					// Tester si on echappe en span ou en div
1783
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1784
-					include_spip('inc/texte');
1785
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
-					if ($mode === 'div') {
1788
-						$trad = rtrim($trad) . "\n\n";
1789
-					}
1790
-					$trad = code_echappement($trad, 'multi', false, $mode);
1791
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
-					if (lang_dir($l) !== lang_dir($lang)) {
1793
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
-					}
1795
-					if (!$options['echappe_span']) {
1796
-						$trad = echappe_retour($trad, 'multi');
1797
-					}
1798
-				}
1799
-			}
1800
-			$letexte = str_replace($reg[0], $trad, $letexte);
1801
-		}
1802
-	}
1803
-
1804
-	return $letexte;
1743
+    if (
1744
+        $letexte
1745
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
+    ) {
1747
+        if (!$lang) {
1748
+            $lang = $GLOBALS['spip_lang'];
1749
+        }
1750
+
1751
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
+        if (is_bool($options)) {
1753
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
+        }
1755
+        if (!isset($options['echappe_span'])) {
1756
+            $options = array_merge($options, ['echappe_span' => false]);
1757
+        }
1758
+        if (!isset($options['lang_defaut'])) {
1759
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
+        }
1761
+
1762
+        include_spip('inc/lang');
1763
+        foreach ($regs as $reg) {
1764
+            // chercher la version de la langue courante
1765
+            $trads = extraire_trads($reg[1]);
1766
+            if ($l = approcher_langue($trads, $lang)) {
1767
+                $trad = $trads[$l];
1768
+            } else {
1769
+                if ($options['lang_defaut'] == 'aucune') {
1770
+                    $trad = '';
1771
+                } else {
1772
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
+                    // ou la premiere dispo
1774
+                    // mais typographier le texte selon les regles de celle-ci
1775
+                    // Attention aux blocs multi sur plusieurs lignes
1776
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
+                        $l = key($trads);
1778
+                    }
1779
+                    $trad = $trads[$l];
1780
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1781
+                    $trad = $typographie($trad);
1782
+                    // Tester si on echappe en span ou en div
1783
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1784
+                    include_spip('inc/texte');
1785
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
+                    if ($mode === 'div') {
1788
+                        $trad = rtrim($trad) . "\n\n";
1789
+                    }
1790
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1791
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
+                    if (lang_dir($l) !== lang_dir($lang)) {
1793
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
+                    }
1795
+                    if (!$options['echappe_span']) {
1796
+                        $trad = echappe_retour($trad, 'multi');
1797
+                    }
1798
+                }
1799
+            }
1800
+            $letexte = str_replace($reg[0], $trad, $letexte);
1801
+        }
1802
+    }
1803
+
1804
+    return $letexte;
1805 1805
 }
1806 1806
 
1807 1807
 /**
@@ -1817,21 +1817,21 @@  discard block
 block discarded – undo
1817 1817
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1818 1818
  **/
1819 1819
 function extraire_trads($bloc) {
1820
-	$trads = [];
1821
-	$lang = '';
1820
+    $trads = [];
1821
+    $lang = '';
1822 1822
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1823 1823
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1824
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
-		$texte = trim($regs[1]);
1826
-		if ($texte or $lang) {
1827
-			$trads[$lang] = $texte;
1828
-		}
1829
-		$bloc = substr($bloc, strlen($regs[0]));
1830
-		$lang = $regs[2];
1831
-	}
1832
-	$trads[$lang] = $bloc;
1824
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
+        $texte = trim($regs[1]);
1826
+        if ($texte or $lang) {
1827
+            $trads[$lang] = $texte;
1828
+        }
1829
+        $bloc = substr($bloc, strlen($regs[0]));
1830
+        $lang = $regs[2];
1831
+    }
1832
+    $trads[$lang] = $bloc;
1833 1833
 
1834
-	return $trads;
1834
+    return $trads;
1835 1835
 }
1836 1836
 
1837 1837
 
@@ -1842,7 +1842,7 @@  discard block
 block discarded – undo
1842 1842
  * @return string L'initiale en majuscule
1843 1843
  */
1844 1844
 function filtre_initiale($nom) {
1845
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1845
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1846 1846
 }
1847 1847
 
1848 1848
 
@@ -1887,33 +1887,33 @@  discard block
 block discarded – undo
1887 1887
  *      - null (interne) : si on empile
1888 1888
  **/
1889 1889
 function unique($donnee, $famille = '', $cpt = false) {
1890
-	static $mem = [];
1891
-	// permettre de vider la pile et de la restaurer
1892
-	// pour le calcul de introduction...
1893
-	if ($famille == '_spip_raz_') {
1894
-		$tmp = $mem;
1895
-		$mem = [];
1896
-
1897
-		return $tmp;
1898
-	} elseif ($famille == '_spip_set_') {
1899
-		$mem = $donnee;
1900
-
1901
-		return;
1902
-	}
1903
-	// eviter une notice
1904
-	if (!isset($mem[$famille])) {
1905
-		$mem[$famille] = [];
1906
-	}
1907
-	if ($cpt) {
1908
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
-	}
1910
-	// eviter une notice
1911
-	if (!isset($mem[$famille][$donnee])) {
1912
-		$mem[$famille][$donnee] = 0;
1913
-	}
1914
-	if (!($mem[$famille][$donnee]++)) {
1915
-		return $donnee;
1916
-	}
1890
+    static $mem = [];
1891
+    // permettre de vider la pile et de la restaurer
1892
+    // pour le calcul de introduction...
1893
+    if ($famille == '_spip_raz_') {
1894
+        $tmp = $mem;
1895
+        $mem = [];
1896
+
1897
+        return $tmp;
1898
+    } elseif ($famille == '_spip_set_') {
1899
+        $mem = $donnee;
1900
+
1901
+        return;
1902
+    }
1903
+    // eviter une notice
1904
+    if (!isset($mem[$famille])) {
1905
+        $mem[$famille] = [];
1906
+    }
1907
+    if ($cpt) {
1908
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
+    }
1910
+    // eviter une notice
1911
+    if (!isset($mem[$famille][$donnee])) {
1912
+        $mem[$famille][$donnee] = 0;
1913
+    }
1914
+    if (!($mem[$famille][$donnee]++)) {
1915
+        return $donnee;
1916
+    }
1917 1917
 }
1918 1918
 
1919 1919
 
@@ -1943,16 +1943,16 @@  discard block
 block discarded – undo
1943 1943
  *     Une des valeurs en fonction du compteur.
1944 1944
  **/
1945 1945
 function alterner($i, ...$args) {
1946
-	// recuperer les arguments (attention fonctions un peu space)
1947
-	$num = count($args);
1946
+    // recuperer les arguments (attention fonctions un peu space)
1947
+    $num = count($args);
1948 1948
 
1949
-	if ($num === 1 && is_array($args[0])) {
1950
-		$args = $args[0];
1951
-		$num = count($args);
1952
-	}
1949
+    if ($num === 1 && is_array($args[0])) {
1950
+        $args = $args[0];
1951
+        $num = count($args);
1952
+    }
1953 1953
 
1954
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
-	return $args[(intval($i) - 1) % $num];
1954
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
+    return $args[(intval($i) - 1) % $num];
1956 1956
 }
1957 1957
 
1958 1958
 
@@ -1978,51 +1978,51 @@  discard block
 block discarded – undo
1978 1978
  *     - null lorsque l’attribut n’existe pas.
1979 1979
  **/
1980 1980
 function extraire_attribut($balise, $attribut, $complet = false) {
1981
-	if (is_array($balise)) {
1982
-		array_walk(
1983
-			$balise,
1984
-			function (&$a, $key, $t) {
1985
-				$a = extraire_attribut($a, $t);
1986
-			},
1987
-			$attribut
1988
-		);
1989
-
1990
-		return $balise;
1991
-	}
1992
-	if (
1993
-		$balise
1994
-		&& preg_match(
1995
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
-			. $attribut
1997
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
-			$balise,
1999
-			$r
2000
-		)
2001
-	) {
2002
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
-			$r[4] = substr($r[3], 1, -1);
2004
-			$r[3] = $r[3][0];
2005
-		} elseif ($r[3] !== '') {
2006
-			$r[4] = $r[3];
2007
-			$r[3] = '';
2008
-		} else {
2009
-			$r[4] = trim($r[2]);
2010
-		}
2011
-		$att = $r[4];
2012
-		if (strpos($att, '&#') !== false) {
2013
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
-		}
2015
-		$att = filtrer_entites($att);
2016
-	} else {
2017
-		$att = null;
2018
-		$r = [];
2019
-	}
2020
-
2021
-	if ($complet) {
2022
-		return [$att, $r];
2023
-	} else {
2024
-		return $att;
2025
-	}
1981
+    if (is_array($balise)) {
1982
+        array_walk(
1983
+            $balise,
1984
+            function (&$a, $key, $t) {
1985
+                $a = extraire_attribut($a, $t);
1986
+            },
1987
+            $attribut
1988
+        );
1989
+
1990
+        return $balise;
1991
+    }
1992
+    if (
1993
+        $balise
1994
+        && preg_match(
1995
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
+            . $attribut
1997
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
+            $balise,
1999
+            $r
2000
+        )
2001
+    ) {
2002
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
+            $r[4] = substr($r[3], 1, -1);
2004
+            $r[3] = $r[3][0];
2005
+        } elseif ($r[3] !== '') {
2006
+            $r[4] = $r[3];
2007
+            $r[3] = '';
2008
+        } else {
2009
+            $r[4] = trim($r[2]);
2010
+        }
2011
+        $att = $r[4];
2012
+        if (strpos($att, '&#') !== false) {
2013
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
+        }
2015
+        $att = filtrer_entites($att);
2016
+    } else {
2017
+        $att = null;
2018
+        $r = [];
2019
+    }
2020
+
2021
+    if ($complet) {
2022
+        return [$att, $r];
2023
+    } else {
2024
+        return $att;
2025
+    }
2026 2026
 }
2027 2027
 
2028 2028
 /**
@@ -2055,41 +2055,41 @@  discard block
 block discarded – undo
2055 2055
  **/
2056 2056
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2057 2057
 
2058
-	if ($balise === null or $balise === '') {
2059
-		return '';
2060
-	}
2058
+    if ($balise === null or $balise === '') {
2059
+        return '';
2060
+    }
2061 2061
 
2062
-	// preparer l'attribut
2063
-	// supprimer les &nbsp; etc mais pas les balises html
2064
-	// qui ont un sens dans un attribut value d'un input
2065
-	if ($proteger) {
2066
-		$val = attribut_html($val, false);
2067
-	}
2062
+    // preparer l'attribut
2063
+    // supprimer les &nbsp; etc mais pas les balises html
2064
+    // qui ont un sens dans un attribut value d'un input
2065
+    if ($proteger) {
2066
+        $val = attribut_html($val, false);
2067
+    }
2068 2068
 
2069
-	// echapper les ' pour eviter tout bug
2070
-	$val = str_replace("'", '&#039;', $val);
2071
-	if ($vider and strlen($val) === 0) {
2072
-		$insert = '';
2073
-	} else {
2074
-		$insert = " $attribut='$val'";
2075
-	}
2069
+    // echapper les ' pour eviter tout bug
2070
+    $val = str_replace("'", '&#039;', $val);
2071
+    if ($vider and strlen($val) === 0) {
2072
+        $insert = '';
2073
+    } else {
2074
+        $insert = " $attribut='$val'";
2075
+    }
2076 2076
 
2077
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2077
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2078 2078
 
2079
-	if ($old !== null) {
2080
-		// Remplacer l'ancien attribut du meme nom
2081
-		$balise = $r[1] . $insert . $r[5];
2082
-	} else {
2083
-		// preferer une balise " />" (comme <img />)
2084
-		if (preg_match(',/>,', $balise)) {
2085
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
-		} // sinon une balise <a ...> ... </a>
2087
-		else {
2088
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
-		}
2090
-	}
2079
+    if ($old !== null) {
2080
+        // Remplacer l'ancien attribut du meme nom
2081
+        $balise = $r[1] . $insert . $r[5];
2082
+    } else {
2083
+        // preferer une balise " />" (comme <img />)
2084
+        if (preg_match(',/>,', $balise)) {
2085
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
+        } // sinon une balise <a ...> ... </a>
2087
+        else {
2088
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
+        }
2090
+    }
2091 2091
 
2092
-	return $balise;
2092
+    return $balise;
2093 2093
 }
2094 2094
 
2095 2095
 /**
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
  * @return string Code HTML sans l'attribut
2108 2108
  **/
2109 2109
 function vider_attribut(?string $balise, string $attribut): string {
2110
-	return inserer_attribut($balise, $attribut, '', false, true);
2110
+    return inserer_attribut($balise, $attribut, '', false, true);
2111 2111
 }
2112 2112
 
2113 2113
 /**
@@ -2119,53 +2119,53 @@  discard block
 block discarded – undo
2119 2119
  * @return string
2120 2120
  */
2121 2121
 function modifier_class($balise, $class, $operation = 'ajouter') {
2122
-	if (is_string($class)) {
2123
-		$class = explode(' ', trim($class));
2124
-	}
2125
-	$class = array_filter($class);
2126
-	$class = array_unique($class);
2127
-	if (!$class) {
2128
-		return $balise;
2129
-	}
2130
-
2131
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2132
-	if (preg_match(',[^\w-],', implode('', $class))) {
2133
-		return $balise;
2134
-	}
2135
-
2136
-	$class_courante = extraire_attribut($balise, 'class');
2137
-	$class_new = $class_courante;
2138
-	foreach ($class as $c) {
2139
-		$is_class_presente = false;
2140
-		if (
2141
-			$class_courante
2142
-			and strpos($class_courante, (string) $c) !== false
2143
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
-		) {
2145
-			$is_class_presente = true;
2146
-		}
2147
-		if (
2148
-			in_array($operation, ['ajouter', 'commuter'])
2149
-			and !$is_class_presente
2150
-		) {
2151
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
-		} elseif (
2153
-			in_array($operation, ['supprimer', 'commuter'])
2154
-			and $is_class_presente
2155
-		) {
2156
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
-		}
2158
-	}
2159
-
2160
-	if ($class_new !== $class_courante) {
2161
-		if (strlen($class_new)) {
2162
-			$balise = inserer_attribut($balise, 'class', $class_new);
2163
-		} elseif ($class_courante) {
2164
-			$balise = vider_attribut($balise, 'class');
2165
-		}
2166
-	}
2167
-
2168
-	return $balise;
2122
+    if (is_string($class)) {
2123
+        $class = explode(' ', trim($class));
2124
+    }
2125
+    $class = array_filter($class);
2126
+    $class = array_unique($class);
2127
+    if (!$class) {
2128
+        return $balise;
2129
+    }
2130
+
2131
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2132
+    if (preg_match(',[^\w-],', implode('', $class))) {
2133
+        return $balise;
2134
+    }
2135
+
2136
+    $class_courante = extraire_attribut($balise, 'class');
2137
+    $class_new = $class_courante;
2138
+    foreach ($class as $c) {
2139
+        $is_class_presente = false;
2140
+        if (
2141
+            $class_courante
2142
+            and strpos($class_courante, (string) $c) !== false
2143
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
+        ) {
2145
+            $is_class_presente = true;
2146
+        }
2147
+        if (
2148
+            in_array($operation, ['ajouter', 'commuter'])
2149
+            and !$is_class_presente
2150
+        ) {
2151
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
+        } elseif (
2153
+            in_array($operation, ['supprimer', 'commuter'])
2154
+            and $is_class_presente
2155
+        ) {
2156
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
+        }
2158
+    }
2159
+
2160
+    if ($class_new !== $class_courante) {
2161
+        if (strlen($class_new)) {
2162
+            $balise = inserer_attribut($balise, 'class', $class_new);
2163
+        } elseif ($class_courante) {
2164
+            $balise = vider_attribut($balise, 'class');
2165
+        }
2166
+    }
2167
+
2168
+    return $balise;
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
  * @return string
2176 2176
  */
2177 2177
 function ajouter_class($balise, $class) {
2178
-	return modifier_class($balise, $class, 'ajouter');
2178
+    return modifier_class($balise, $class, 'ajouter');
2179 2179
 }
2180 2180
 
2181 2181
 /**
@@ -2185,7 +2185,7 @@  discard block
 block discarded – undo
2185 2185
  * @return string
2186 2186
  */
2187 2187
 function supprimer_class($balise, $class) {
2188
-	return modifier_class($balise, $class, 'supprimer');
2188
+    return modifier_class($balise, $class, 'supprimer');
2189 2189
 }
2190 2190
 
2191 2191
 /**
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
  * @return string
2197 2197
  */
2198 2198
 function commuter_class($balise, $class) {
2199
-	return modifier_class($balise, $class, 'commuter');
2199
+    return modifier_class($balise, $class, 'commuter');
2200 2200
 }
2201 2201
 
2202 2202
 /**
@@ -2207,19 +2207,19 @@  discard block
 block discarded – undo
2207 2207
  * @return string
2208 2208
  */
2209 2209
 function tester_config($id, $mode = '') {
2210
-	include_spip('action/inscrire_auteur');
2210
+    include_spip('action/inscrire_auteur');
2211 2211
 
2212
-	return tester_statut_inscription($mode, $id);
2212
+    return tester_statut_inscription($mode, $id);
2213 2213
 }
2214 2214
 
2215 2215
 //
2216 2216
 // Quelques fonctions de calcul arithmetique
2217 2217
 //
2218 2218
 function floatstr($a) {
2219
- return str_replace(',', '.', (string)floatval($a));
2219
+    return str_replace(',', '.', (string)floatval($a));
2220 2220
 }
2221 2221
 function strize($f, $a, $b) {
2222
- return floatstr($f(floatstr($a), floatstr($b)));
2222
+    return floatstr($f(floatstr($a), floatstr($b)));
2223 2223
 }
2224 2224
 
2225 2225
 /**
@@ -2238,7 +2238,7 @@  discard block
 block discarded – undo
2238 2238
  * @return int $a+$b
2239 2239
  **/
2240 2240
 function plus($a, $b) {
2241
-	return $a + $b;
2241
+    return $a + $b;
2242 2242
 }
2243 2243
 function strplus($a, $b) {
2244 2244
 return strize('plus', $a, $b);
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
  * @return int $a-$b
2260 2260
  **/
2261 2261
 function moins($a, $b) {
2262
-	return $a - $b;
2262
+    return $a - $b;
2263 2263
 }
2264 2264
 function strmoins($a, $b) {
2265 2265
 return strize('moins', $a, $b);
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
  * @return int $a*$b
2283 2283
  **/
2284 2284
 function mult($a, $b) {
2285
-	return $a * $b;
2285
+    return $a * $b;
2286 2286
 }
2287 2287
 function strmult($a, $b) {
2288 2288
 return strize('mult', $a, $b);
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
  * @return int $a/$b (ou 0 si $b est nul)
2306 2306
  **/
2307 2307
 function div($a, $b) {
2308
-	return $b ? $a / $b : 0;
2308
+    return $b ? $a / $b : 0;
2309 2309
 }
2310 2310
 function strdiv($a, $b) {
2311 2311
 return strize('div', $a, $b);
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
  * @return int ($nb % $mod) + $add
2330 2330
  **/
2331 2331
 function modulo($nb, $mod, $add = 0) {
2332
-	return ($mod ? $nb % $mod : 0) + $add;
2332
+    return ($mod ? $nb % $mod : 0) + $add;
2333 2333
 }
2334 2334
 
2335 2335
 
@@ -2344,26 +2344,26 @@  discard block
 block discarded – undo
2344 2344
  *      - true sinon
2345 2345
  **/
2346 2346
 function nom_acceptable($nom) {
2347
-	$remp2 = [];
2348
-	$remp1 = [];
2349
-	if (!is_string($nom)) {
2350
-		return false;
2351
-	}
2352
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2353
-		define('_TAGS_NOM_AUTEUR', '');
2354
-	}
2355
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
-	foreach ($tags_acceptes as $tag) {
2357
-		if (strlen($tag)) {
2358
-			$remp1[] = '<' . trim($tag) . '>';
2359
-			$remp1[] = '</' . trim($tag) . '>';
2360
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2361
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2362
-		}
2363
-	}
2364
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
-
2366
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2347
+    $remp2 = [];
2348
+    $remp1 = [];
2349
+    if (!is_string($nom)) {
2350
+        return false;
2351
+    }
2352
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2353
+        define('_TAGS_NOM_AUTEUR', '');
2354
+    }
2355
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
+    foreach ($tags_acceptes as $tag) {
2357
+        if (strlen($tag)) {
2358
+            $remp1[] = '<' . trim($tag) . '>';
2359
+            $remp1[] = '</' . trim($tag) . '>';
2360
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2361
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2362
+        }
2363
+    }
2364
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
+
2366
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2367 2367
 }
2368 2368
 
2369 2369
 
@@ -2379,14 +2379,14 @@  discard block
 block discarded – undo
2379 2379
  *      - renvoie un tableau si l'entree est un tableau
2380 2380
  **/
2381 2381
 function email_valide($adresses) {
2382
-	if (is_array($adresses)) {
2383
-		$adresses = array_map('email_valide', $adresses);
2384
-		$adresses = array_filter($adresses);
2385
-		return $adresses;
2386
-	}
2382
+    if (is_array($adresses)) {
2383
+        $adresses = array_map('email_valide', $adresses);
2384
+        $adresses = array_filter($adresses);
2385
+        return $adresses;
2386
+    }
2387 2387
 
2388
-	$email_valide = charger_fonction('email_valide', 'inc');
2389
-	return $email_valide($adresses);
2388
+    $email_valide = charger_fonction('email_valide', 'inc');
2389
+    return $email_valide($adresses);
2390 2390
 }
2391 2391
 
2392 2392
 /**
@@ -2400,27 +2400,27 @@  discard block
 block discarded – undo
2400 2400
  * @return string Texte
2401 2401
  **/
2402 2402
 function afficher_enclosures($tags) {
2403
-	$s = [];
2404
-	foreach (extraire_balises($tags, 'a') as $tag) {
2405
-		if (
2406
-			extraire_attribut($tag, 'rel') == 'enclosure'
2407
-			and $t = extraire_attribut($tag, 'href')
2408
-		) {
2409
-			$s[] = preg_replace(
2410
-				',>[^<]+</a>,S',
2411
-				'>'
2412
-				. http_img_pack(
2413
-					'attachment-16.png',
2414
-					$t,
2415
-					'title="' . attribut_html($t) . '"'
2416
-				)
2417
-				. '</a>',
2418
-				$tag
2419
-			);
2420
-		}
2421
-	}
2422
-
2423
-	return join('&nbsp;', $s);
2403
+    $s = [];
2404
+    foreach (extraire_balises($tags, 'a') as $tag) {
2405
+        if (
2406
+            extraire_attribut($tag, 'rel') == 'enclosure'
2407
+            and $t = extraire_attribut($tag, 'href')
2408
+        ) {
2409
+            $s[] = preg_replace(
2410
+                ',>[^<]+</a>,S',
2411
+                '>'
2412
+                . http_img_pack(
2413
+                    'attachment-16.png',
2414
+                    $t,
2415
+                    'title="' . attribut_html($t) . '"'
2416
+                )
2417
+                . '</a>',
2418
+                $tag
2419
+            );
2420
+        }
2421
+    }
2422
+
2423
+    return join('&nbsp;', $s);
2424 2424
 }
2425 2425
 
2426 2426
 /**
@@ -2435,15 +2435,15 @@  discard block
 block discarded – undo
2435 2435
  * @return string Liens trouvés
2436 2436
  **/
2437 2437
 function afficher_tags($tags, $rels = 'tag,directory') {
2438
-	$s = [];
2439
-	foreach (extraire_balises($tags, 'a') as $tag) {
2440
-		$rel = extraire_attribut($tag, 'rel');
2441
-		if (strstr(",$rels,", (string) ",$rel,")) {
2442
-			$s[] = $tag;
2443
-		}
2444
-	}
2438
+    $s = [];
2439
+    foreach (extraire_balises($tags, 'a') as $tag) {
2440
+        $rel = extraire_attribut($tag, 'rel');
2441
+        if (strstr(",$rels,", (string) ",$rel,")) {
2442
+            $s[] = $tag;
2443
+        }
2444
+    }
2445 2445
 
2446
-	return join(', ', $s);
2446
+    return join(', ', $s);
2447 2447
 }
2448 2448
 
2449 2449
 
@@ -2465,21 +2465,21 @@  discard block
 block discarded – undo
2465 2465
  * @return string Tag HTML `<a>` avec microformat.
2466 2466
  **/
2467 2467
 function enclosure2microformat($e) {
2468
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2470
-	}
2471
-	$type = extraire_attribut($e, 'type');
2472
-	if (!$length = extraire_attribut($e, 'length')) {
2473
-		# <media:content : longeur dans fileSize. On tente.
2474
-		$length = extraire_attribut($e, 'fileSize');
2475
-	}
2476
-	$fichier = basename($url);
2468
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2470
+    }
2471
+    $type = extraire_attribut($e, 'type');
2472
+    if (!$length = extraire_attribut($e, 'length')) {
2473
+        # <media:content : longeur dans fileSize. On tente.
2474
+        $length = extraire_attribut($e, 'fileSize');
2475
+    }
2476
+    $fichier = basename($url);
2477 2477
 
2478
-	return '<a rel="enclosure"'
2479
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
-	. '>' . $fichier . '</a>';
2478
+    return '<a rel="enclosure"'
2479
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
+    . '>' . $fichier . '</a>';
2483 2483
 }
2484 2484
 
2485 2485
 /**
@@ -2497,24 +2497,24 @@  discard block
 block discarded – undo
2497 2497
  * @return string Tags RSS `<enclosure>`.
2498 2498
  **/
2499 2499
 function microformat2enclosure($tags) {
2500
-	$enclosures = [];
2501
-	foreach (extraire_balises($tags, 'a') as $e) {
2502
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2504
-			$type = extraire_attribut($e, 'type');
2505
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
-				$length = intval(extraire_attribut($e, 'length'));
2507
-			} # vieux data
2508
-			$fichier = basename($url);
2509
-			$enclosures[] = '<enclosure'
2510
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
-				. ($length ? ' length="' . $length . '"' : '')
2513
-				. ' />';
2514
-		}
2515
-	}
2500
+    $enclosures = [];
2501
+    foreach (extraire_balises($tags, 'a') as $e) {
2502
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2504
+            $type = extraire_attribut($e, 'type');
2505
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
+                $length = intval(extraire_attribut($e, 'length'));
2507
+            } # vieux data
2508
+            $fichier = basename($url);
2509
+            $enclosures[] = '<enclosure'
2510
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
+                . ($length ? ' length="' . $length . '"' : '')
2513
+                . ' />';
2514
+        }
2515
+    }
2516 2516
 
2517
-	return join("\n", $enclosures);
2517
+    return join("\n", $enclosures);
2518 2518
 }
2519 2519
 
2520 2520
 
@@ -2530,16 +2530,16 @@  discard block
 block discarded – undo
2530 2530
  * @return string Tags RSS Atom `<dc:subject>`.
2531 2531
  **/
2532 2532
 function tags2dcsubject($tags) {
2533
-	$subjects = '';
2534
-	foreach (extraire_balises($tags, 'a') as $e) {
2535
-		if (extraire_attribut($e, 'rel') == 'tag') {
2536
-			$subjects .= '<dc:subject>'
2537
-				. texte_backend(textebrut($e))
2538
-				. '</dc:subject>' . "\n";
2539
-		}
2540
-	}
2533
+    $subjects = '';
2534
+    foreach (extraire_balises($tags, 'a') as $e) {
2535
+        if (extraire_attribut($e, 'rel') == 'tag') {
2536
+            $subjects .= '<dc:subject>'
2537
+                . texte_backend(textebrut($e))
2538
+                . '</dc:subject>' . "\n";
2539
+        }
2540
+    }
2541 2541
 
2542
-	return $subjects;
2542
+    return $subjects;
2543 2543
 }
2544 2544
 
2545 2545
 /**
@@ -2568,27 +2568,27 @@  discard block
 block discarded – undo
2568 2568
  *     - Tableau de résultats, si tableau en entrée.
2569 2569
  **/
2570 2570
 function extraire_balise($texte, $tag = 'a') {
2571
-	if (is_array($texte)) {
2572
-		array_walk(
2573
-			$texte,
2574
-			function (&$a, $key, $t) {
2575
-				$a = extraire_balise($a, $t);
2576
-			},
2577
-			$tag
2578
-		);
2579
-
2580
-		return $texte;
2581
-	}
2582
-
2583
-	if (
2584
-		preg_match(
2585
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
-			$texte,
2587
-			$regs
2588
-		)
2589
-	) {
2590
-		return $regs[0];
2591
-	}
2571
+    if (is_array($texte)) {
2572
+        array_walk(
2573
+            $texte,
2574
+            function (&$a, $key, $t) {
2575
+                $a = extraire_balise($a, $t);
2576
+            },
2577
+            $tag
2578
+        );
2579
+
2580
+        return $texte;
2581
+    }
2582
+
2583
+    if (
2584
+        preg_match(
2585
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
+            $texte,
2587
+            $regs
2588
+        )
2589
+    ) {
2590
+        return $regs[0];
2591
+    }
2592 2592
 }
2593 2593
 
2594 2594
 /**
@@ -2616,30 +2616,30 @@  discard block
 block discarded – undo
2616 2616
  *     - Tableau de résultats, si tableau en entrée.
2617 2617
  **/
2618 2618
 function extraire_balises($texte, $tag = 'a') {
2619
-	if (is_array($texte)) {
2620
-		array_walk(
2621
-			$texte,
2622
-			function (&$a, $key, $t) {
2623
-				$a = extraire_balises($a, $t);
2624
-			},
2625
-			$tag
2626
-		);
2627
-
2628
-		return $texte;
2629
-	}
2630
-
2631
-	if (
2632
-		preg_match_all(
2633
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
-			$texte,
2635
-			$regs,
2636
-			PREG_PATTERN_ORDER
2637
-		)
2638
-	) {
2639
-		return $regs[0];
2640
-	} else {
2641
-		return [];
2642
-	}
2619
+    if (is_array($texte)) {
2620
+        array_walk(
2621
+            $texte,
2622
+            function (&$a, $key, $t) {
2623
+                $a = extraire_balises($a, $t);
2624
+            },
2625
+            $tag
2626
+        );
2627
+
2628
+        return $texte;
2629
+    }
2630
+
2631
+    if (
2632
+        preg_match_all(
2633
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
+            $texte,
2635
+            $regs,
2636
+            PREG_PATTERN_ORDER
2637
+        )
2638
+    ) {
2639
+        return $regs[0];
2640
+    } else {
2641
+        return [];
2642
+    }
2643 2643
 }
2644 2644
 
2645 2645
 /**
@@ -2668,11 +2668,11 @@  discard block
 block discarded – undo
2668 2668
  *     - `$def` si on n'a pas transmis de tableau
2669 2669
  **/
2670 2670
 function in_any($val, $vals, $def = '') {
2671
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
-		$vals = $v;
2673
-	}
2671
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
+        $vals = $v;
2673
+    }
2674 2674
 
2675
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2675
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2676 2676
 }
2677 2677
 
2678 2678
 
@@ -2693,12 +2693,12 @@  discard block
 block discarded – undo
2693 2693
  *     Résultat du calcul
2694 2694
  **/
2695 2695
 function valeur_numerique($expr) {
2696
-	$a = 0;
2697
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
-		eval("\$a = $expr;");
2699
-	}
2696
+    $a = 0;
2697
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
+        eval("\$a = $expr;");
2699
+    }
2700 2700
 
2701
-	return intval($a);
2701
+    return intval($a);
2702 2702
 }
2703 2703
 
2704 2704
 /**
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *      Retourne `$a*$b/$c`
2718 2718
  **/
2719 2719
 function regledetrois($a, $b, $c) {
2720
-	return round($a * $b / $c);
2720
+    return round($a * $b / $c);
2721 2721
 }
2722 2722
 
2723 2723
 
@@ -2740,79 +2740,79 @@  discard block
 block discarded – undo
2740 2740
  * @return string Suite de champs input hidden
2741 2741
  **/
2742 2742
 function form_hidden(?string $action = ''): string {
2743
-	$action ??= '';
2744
-
2745
-	$contexte = [];
2746
-	include_spip('inc/urls');
2747
-	if (
2748
-		$p = urls_decoder_url($action, '')
2749
-		and reset($p)
2750
-	) {
2751
-		$fond = array_shift($p);
2752
-		if ($fond != '404') {
2753
-			$contexte = array_shift($p);
2754
-			$contexte['page'] = $fond;
2755
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2756
-		}
2757
-	}
2758
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2759
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2760
-		unset($contexte['type']);
2761
-	}
2762
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2763
-		unset($contexte['type-page']);
2764
-	}
2765
-
2766
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2767
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2768
-	$values = [];
2769
-
2770
-	// d'abord avec celles de l'url
2771
-	if (false !== ($p = strpos($action, '?'))) {
2772
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2773
-			$c = explode('=', $c, 2);
2774
-			$var = array_shift($c);
2775
-			$val = array_shift($c);
2776
-			if ($var) {
2777
-				$val = rawurldecode($val);
2778
-				$var = rawurldecode($var); // decoder les [] eventuels
2779
-				if (preg_match(',\[\]$,S', $var)) {
2780
-					$values[] = [$var, $val];
2781
-				} else {
2782
-					if (!isset($values[$var])) {
2783
-						$values[$var] = [$var, $val];
2784
-					}
2785
-				}
2786
-			}
2787
-		}
2788
-	}
2789
-
2790
-	// ensuite avec celles du contexte, sans doublonner !
2791
-	foreach ($contexte as $var => $val) {
2792
-		if (preg_match(',\[\]$,S', $var)) {
2793
-			$values[] = [$var, $val];
2794
-		} else {
2795
-			if (!isset($values[$var])) {
2796
-				$values[$var] = [$var, $val];
2797
-			}
2798
-		}
2799
-	}
2800
-
2801
-	// puis on rassemble le tout
2802
-	$hidden = [];
2803
-	foreach ($values as $value) {
2804
-		[$var, $val] = $value;
2805
-		$hidden[] = '<input name="'
2806
-			. entites_html($var)
2807
-			. '"'
2808
-			. (is_null($val)
2809
-				? ''
2810
-				: ' value="' . entites_html($val) . '"'
2811
-			)
2812
-			. ' type="hidden"' . "\n/>";
2813
-	}
2814
-
2815
-	return join('', $hidden);
2743
+    $action ??= '';
2744
+
2745
+    $contexte = [];
2746
+    include_spip('inc/urls');
2747
+    if (
2748
+        $p = urls_decoder_url($action, '')
2749
+        and reset($p)
2750
+    ) {
2751
+        $fond = array_shift($p);
2752
+        if ($fond != '404') {
2753
+            $contexte = array_shift($p);
2754
+            $contexte['page'] = $fond;
2755
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2756
+        }
2757
+    }
2758
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2759
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2760
+        unset($contexte['type']);
2761
+    }
2762
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2763
+        unset($contexte['type-page']);
2764
+    }
2765
+
2766
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2767
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2768
+    $values = [];
2769
+
2770
+    // d'abord avec celles de l'url
2771
+    if (false !== ($p = strpos($action, '?'))) {
2772
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2773
+            $c = explode('=', $c, 2);
2774
+            $var = array_shift($c);
2775
+            $val = array_shift($c);
2776
+            if ($var) {
2777
+                $val = rawurldecode($val);
2778
+                $var = rawurldecode($var); // decoder les [] eventuels
2779
+                if (preg_match(',\[\]$,S', $var)) {
2780
+                    $values[] = [$var, $val];
2781
+                } else {
2782
+                    if (!isset($values[$var])) {
2783
+                        $values[$var] = [$var, $val];
2784
+                    }
2785
+                }
2786
+            }
2787
+        }
2788
+    }
2789
+
2790
+    // ensuite avec celles du contexte, sans doublonner !
2791
+    foreach ($contexte as $var => $val) {
2792
+        if (preg_match(',\[\]$,S', $var)) {
2793
+            $values[] = [$var, $val];
2794
+        } else {
2795
+            if (!isset($values[$var])) {
2796
+                $values[$var] = [$var, $val];
2797
+            }
2798
+        }
2799
+    }
2800
+
2801
+    // puis on rassemble le tout
2802
+    $hidden = [];
2803
+    foreach ($values as $value) {
2804
+        [$var, $val] = $value;
2805
+        $hidden[] = '<input name="'
2806
+            . entites_html($var)
2807
+            . '"'
2808
+            . (is_null($val)
2809
+                ? ''
2810
+                : ' value="' . entites_html($val) . '"'
2811
+            )
2812
+            . ' type="hidden"' . "\n/>";
2813
+    }
2814
+
2815
+    return join('', $hidden);
2816 2816
 }
2817 2817
 
2818 2818
 
@@ -2834,7 +2834,7 @@  discard block
 block discarded – undo
2834 2834
  *    - la première valeur du tableau sinon.
2835 2835
  **/
2836 2836
 function filtre_reset($array) {
2837
-	return !is_array($array) ? null : reset($array);
2837
+    return !is_array($array) ? null : reset($array);
2838 2838
 }
2839 2839
 
2840 2840
 /**
@@ -2855,7 +2855,7 @@  discard block
 block discarded – undo
2855 2855
  *    - la dernière valeur du tableau sinon.
2856 2856
  **/
2857 2857
 function filtre_end($array) {
2858
-	return !is_array($array) ? null : end($array);
2858
+    return !is_array($array) ? null : end($array);
2859 2859
 }
2860 2860
 
2861 2861
 /**
@@ -2875,11 +2875,11 @@  discard block
 block discarded – undo
2875 2875
  *
2876 2876
  **/
2877 2877
 function filtre_push($array, $val) {
2878
-	if (!is_array($array) or !array_push($array, $val)) {
2879
-		return '';
2880
-	}
2878
+    if (!is_array($array) or !array_push($array, $val)) {
2879
+        return '';
2880
+    }
2881 2881
 
2882
-	return $array;
2882
+    return $array;
2883 2883
 }
2884 2884
 
2885 2885
 /**
@@ -2898,7 +2898,7 @@  discard block
 block discarded – undo
2898 2898
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2899 2899
  **/
2900 2900
 function filtre_find($array, $val) {
2901
-	return (is_array($array) and in_array($val, $array));
2901
+    return (is_array($array) and in_array($val, $array));
2902 2902
 }
2903 2903
 
2904 2904
 
@@ -2915,13 +2915,13 @@  discard block
 block discarded – undo
2915 2915
  *     Contenu avec urls en absolus
2916 2916
  **/
2917 2917
 function urls_absolues_css($contenu, $source) {
2918
-	$path = suivre_lien(url_absolue($source), './');
2918
+    $path = suivre_lien(url_absolue($source), './');
2919 2919
 
2920
-	return preg_replace_callback(
2921
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2922
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2923
-		$contenu
2924
-	);
2920
+    return preg_replace_callback(
2921
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2922
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2923
+        $contenu
2924
+    );
2925 2925
 }
2926 2926
 
2927 2927
 
@@ -2950,119 +2950,119 @@  discard block
 block discarded – undo
2950 2950
  *     Chemin du fichier CSS inversé
2951 2951
  **/
2952 2952
 function direction_css($css, $voulue = '') {
2953
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2954
-		return $css;
2955
-	}
2956
-	include_spip('inc/lang');
2957
-	// si on a precise le sens voulu en argument, le prendre en compte
2958
-	if ($voulue = strtolower($voulue)) {
2959
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2960
-			$voulue = lang_dir($voulue);
2961
-		}
2962
-	} else {
2963
-		$voulue = lang_dir();
2964
-	}
2965
-
2966
-	$r = count($r) > 1;
2967
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2968
-	$dir = $r ? 'rtl' : 'ltr';
2969
-	$ndir = $r ? 'ltr' : 'rtl';
2970
-
2971
-	if ($voulue == $dir) {
2972
-		return $css;
2973
-	}
2974
-
2975
-	if (
2976
-		// url absolue
2977
-		preg_match(',^https?:,i', $css)
2978
-		// ou qui contient un ?
2979
-		or (($p = strpos($css, '?')) !== false)
2980
-	) {
2981
-		$distant = true;
2982
-		$cssf = parse_url($css);
2983
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2984
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2985
-	} else {
2986
-		$distant = false;
2987
-		$cssf = $css;
2988
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2989
-		//propose (rien a faire dans ce cas)
2990
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2991
-		if (@file_exists($f)) {
2992
-			return $f;
2993
-		}
2994
-	}
2995
-
2996
-	// 2.
2997
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2998
-	$f = $dir_var
2999
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3000
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3001
-
3002
-	// la css peut etre distante (url absolue !)
3003
-	if ($distant) {
3004
-		include_spip('inc/distant');
3005
-		$res = recuperer_url($css);
3006
-		if (!$res or !$contenu = $res['page']) {
3007
-			return $css;
3008
-		}
3009
-	} else {
3010
-		if (
3011
-			(@filemtime($f) > @filemtime($css))
3012
-			and (_VAR_MODE != 'recalcul')
3013
-		) {
3014
-			return $f;
3015
-		}
3016
-		if (!lire_fichier($css, $contenu)) {
3017
-			return $css;
3018
-		}
3019
-	}
3020
-
3021
-
3022
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3023
-	include_spip('lib/csstidy/class.csstidy');
3024
-	$parser = new csstidy();
3025
-	$parser->set_cfg('optimise_shorthands', 0);
3026
-	$parser->set_cfg('reverse_left_and_right', true);
3027
-	$parser->parse($contenu);
3028
-
3029
-	$contenu = $parser->print->plain();
3030
-
3031
-
3032
-	// reperer les @import auxquels il faut propager le direction_css
3033
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3034
-	$src = [];
3035
-	$src_direction_css = [];
3036
-	$src_faux_abs = [];
3037
-	$d = dirname($css);
3038
-	foreach ($regs[1] as $k => $import_css) {
3039
-		$css_direction = direction_css("$d/$import_css", $voulue);
3040
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3041
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3042
-			$css_direction = substr($css_direction, strlen($d) + 1);
3043
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3044
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3045
-			$css_direction = substr($css_direction, strlen($dir_var));
3046
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3047
-			$css_direction = '/@@@@@@/' . $css_direction;
3048
-		}
3049
-		$src[] = $regs[0][$k];
3050
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3051
-	}
3052
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3053
-
3054
-	$contenu = urls_absolues_css($contenu, $css);
3055
-
3056
-	// virer les fausses url absolues que l'on a mis dans les import
3057
-	if (count($src_faux_abs)) {
3058
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3059
-	}
3060
-
3061
-	if (!ecrire_fichier($f, $contenu)) {
3062
-		return $css;
3063
-	}
3064
-
3065
-	return $f;
2953
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2954
+        return $css;
2955
+    }
2956
+    include_spip('inc/lang');
2957
+    // si on a precise le sens voulu en argument, le prendre en compte
2958
+    if ($voulue = strtolower($voulue)) {
2959
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2960
+            $voulue = lang_dir($voulue);
2961
+        }
2962
+    } else {
2963
+        $voulue = lang_dir();
2964
+    }
2965
+
2966
+    $r = count($r) > 1;
2967
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2968
+    $dir = $r ? 'rtl' : 'ltr';
2969
+    $ndir = $r ? 'ltr' : 'rtl';
2970
+
2971
+    if ($voulue == $dir) {
2972
+        return $css;
2973
+    }
2974
+
2975
+    if (
2976
+        // url absolue
2977
+        preg_match(',^https?:,i', $css)
2978
+        // ou qui contient un ?
2979
+        or (($p = strpos($css, '?')) !== false)
2980
+    ) {
2981
+        $distant = true;
2982
+        $cssf = parse_url($css);
2983
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2984
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2985
+    } else {
2986
+        $distant = false;
2987
+        $cssf = $css;
2988
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2989
+        //propose (rien a faire dans ce cas)
2990
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2991
+        if (@file_exists($f)) {
2992
+            return $f;
2993
+        }
2994
+    }
2995
+
2996
+    // 2.
2997
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2998
+    $f = $dir_var
2999
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3000
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3001
+
3002
+    // la css peut etre distante (url absolue !)
3003
+    if ($distant) {
3004
+        include_spip('inc/distant');
3005
+        $res = recuperer_url($css);
3006
+        if (!$res or !$contenu = $res['page']) {
3007
+            return $css;
3008
+        }
3009
+    } else {
3010
+        if (
3011
+            (@filemtime($f) > @filemtime($css))
3012
+            and (_VAR_MODE != 'recalcul')
3013
+        ) {
3014
+            return $f;
3015
+        }
3016
+        if (!lire_fichier($css, $contenu)) {
3017
+            return $css;
3018
+        }
3019
+    }
3020
+
3021
+
3022
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3023
+    include_spip('lib/csstidy/class.csstidy');
3024
+    $parser = new csstidy();
3025
+    $parser->set_cfg('optimise_shorthands', 0);
3026
+    $parser->set_cfg('reverse_left_and_right', true);
3027
+    $parser->parse($contenu);
3028
+
3029
+    $contenu = $parser->print->plain();
3030
+
3031
+
3032
+    // reperer les @import auxquels il faut propager le direction_css
3033
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3034
+    $src = [];
3035
+    $src_direction_css = [];
3036
+    $src_faux_abs = [];
3037
+    $d = dirname($css);
3038
+    foreach ($regs[1] as $k => $import_css) {
3039
+        $css_direction = direction_css("$d/$import_css", $voulue);
3040
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3041
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3042
+            $css_direction = substr($css_direction, strlen($d) + 1);
3043
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3044
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3045
+            $css_direction = substr($css_direction, strlen($dir_var));
3046
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3047
+            $css_direction = '/@@@@@@/' . $css_direction;
3048
+        }
3049
+        $src[] = $regs[0][$k];
3050
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3051
+    }
3052
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3053
+
3054
+    $contenu = urls_absolues_css($contenu, $css);
3055
+
3056
+    // virer les fausses url absolues que l'on a mis dans les import
3057
+    if (count($src_faux_abs)) {
3058
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3059
+    }
3060
+
3061
+    if (!ecrire_fichier($f, $contenu)) {
3062
+        return $css;
3063
+    }
3064
+
3065
+    return $f;
3066 3066
 }
3067 3067
 
3068 3068
 
@@ -3085,46 +3085,46 @@  discard block
 block discarded – undo
3085 3085
  *     - Chemin ou URL du fichier CSS source sinon.
3086 3086
  **/
3087 3087
 function url_absolue_css($css) {
3088
-	if (!preg_match(',\.css$,i', $css, $r)) {
3089
-		return $css;
3090
-	}
3088
+    if (!preg_match(',\.css$,i', $css, $r)) {
3089
+        return $css;
3090
+    }
3091 3091
 
3092
-	$url_absolue_css = url_absolue($css);
3092
+    $url_absolue_css = url_absolue($css);
3093 3093
 
3094
-	$f = basename($css, '.css');
3095
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3096
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3097
-		. '.css';
3094
+    $f = basename($css, '.css');
3095
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3096
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3097
+        . '.css';
3098 3098
 
3099
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3100
-		return $f;
3101
-	}
3099
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3100
+        return $f;
3101
+    }
3102 3102
 
3103
-	if ($url_absolue_css == $css) {
3104
-		if (
3105
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3106
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3107
-		) {
3108
-			include_spip('inc/distant');
3109
-			$contenu = recuperer_url($css);
3110
-			$contenu = $contenu['page'] ?? '';
3111
-			if (!$contenu) {
3112
-				return $css;
3113
-			}
3114
-		}
3115
-	} elseif (!lire_fichier($css, $contenu)) {
3116
-		return $css;
3117
-	}
3103
+    if ($url_absolue_css == $css) {
3104
+        if (
3105
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3106
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3107
+        ) {
3108
+            include_spip('inc/distant');
3109
+            $contenu = recuperer_url($css);
3110
+            $contenu = $contenu['page'] ?? '';
3111
+            if (!$contenu) {
3112
+                return $css;
3113
+            }
3114
+        }
3115
+    } elseif (!lire_fichier($css, $contenu)) {
3116
+        return $css;
3117
+    }
3118 3118
 
3119
-	// passer les url relatives a la css d'origine en url absolues
3120
-	$contenu = urls_absolues_css($contenu, $css);
3119
+    // passer les url relatives a la css d'origine en url absolues
3120
+    $contenu = urls_absolues_css($contenu, $css);
3121 3121
 
3122
-	// ecrire la css
3123
-	if (!ecrire_fichier($f, $contenu)) {
3124
-		return $css;
3125
-	}
3122
+    // ecrire la css
3123
+    if (!ecrire_fichier($f, $contenu)) {
3124
+        return $css;
3125
+    }
3126 3126
 
3127
-	return $f;
3127
+    return $f;
3128 3128
 }
3129 3129
 
3130 3130
 
@@ -3158,24 +3158,24 @@  discard block
 block discarded – undo
3158 3158
  *     Valeur trouvée ou valeur par défaut.
3159 3159
  **/
3160 3160
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3161
-	foreach (explode('/', $cle) as $k) {
3162
-		$table = (is_string($table) ? @unserialize($table) : $table);
3161
+    foreach (explode('/', $cle) as $k) {
3162
+        $table = (is_string($table) ? @unserialize($table) : $table);
3163 3163
 
3164
-		if (is_object($table)) {
3165
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3166
-		} elseif (is_array($table)) {
3167
-			if ($conserver_null) {
3168
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3169
-			} else {
3170
-				$table = ($table[$k] ?? $defaut);
3171
-			}
3172
-		} else {
3173
-			$table = $defaut;
3174
-			break;
3175
-		}
3176
-	}
3164
+        if (is_object($table)) {
3165
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3166
+        } elseif (is_array($table)) {
3167
+            if ($conserver_null) {
3168
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3169
+            } else {
3170
+                $table = ($table[$k] ?? $defaut);
3171
+            }
3172
+        } else {
3173
+            $table = $defaut;
3174
+            break;
3175
+        }
3176
+    }
3177 3177
 
3178
-	return $table;
3178
+    return $table;
3179 3179
 }
3180 3180
 
3181 3181
 /**
@@ -3208,22 +3208,22 @@  discard block
 block discarded – undo
3208 3208
  *     - string : expression trouvée.
3209 3209
  **/
3210 3210
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3211
-	if (intval($modif) and $capte == 0) {
3212
-		$capte = $modif;
3213
-		$modif = 'UimsS';
3214
-	}
3215
-	$expression = str_replace('\/', '/', $expression);
3216
-	$expression = str_replace('/', '\/', $expression);
3211
+    if (intval($modif) and $capte == 0) {
3212
+        $capte = $modif;
3213
+        $modif = 'UimsS';
3214
+    }
3215
+    $expression = str_replace('\/', '/', $expression);
3216
+    $expression = str_replace('/', '\/', $expression);
3217 3217
 
3218
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3219
-		if (isset($r[$capte])) {
3220
-			return $r[$capte];
3221
-		} else {
3222
-			return true;
3223
-		}
3224
-	}
3218
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3219
+        if (isset($r[$capte])) {
3220
+            return $r[$capte];
3221
+        } else {
3222
+            return true;
3223
+        }
3224
+    }
3225 3225
 
3226
-	return false;
3226
+    return false;
3227 3227
 }
3228 3228
 
3229 3229
 
@@ -3250,10 +3250,10 @@  discard block
 block discarded – undo
3250 3250
  *     Texte
3251 3251
  **/
3252 3252
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3253
-	$expression = str_replace('\/', '/', $expression);
3254
-	$expression = str_replace('/', '\/', $expression);
3253
+    $expression = str_replace('\/', '/', $expression);
3254
+    $expression = str_replace('/', '\/', $expression);
3255 3255
 
3256
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3256
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3257 3257
 }
3258 3258
 
3259 3259
 
@@ -3271,25 +3271,25 @@  discard block
 block discarded – undo
3271 3271
  **/
3272 3272
 function traiter_doublons_documents(&$doublons, $letexte) {
3273 3273
 
3274
-	// Verifier dans le texte & les notes (pas beau, helas)
3275
-	$t = $letexte . $GLOBALS['les_notes'];
3274
+    // Verifier dans le texte & les notes (pas beau, helas)
3275
+    $t = $letexte . $GLOBALS['les_notes'];
3276 3276
 
3277
-	if (
3278
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3279
-		and preg_match_all(
3280
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3281
-			$t,
3282
-			$matches,
3283
-			PREG_PATTERN_ORDER
3284
-		)
3285
-	) {
3286
-		if (!isset($doublons['documents'])) {
3287
-			$doublons['documents'] = '';
3288
-		}
3289
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3290
-	}
3277
+    if (
3278
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3279
+        and preg_match_all(
3280
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3281
+            $t,
3282
+            $matches,
3283
+            PREG_PATTERN_ORDER
3284
+        )
3285
+    ) {
3286
+        if (!isset($doublons['documents'])) {
3287
+            $doublons['documents'] = '';
3288
+        }
3289
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3290
+    }
3291 3291
 
3292
-	return $letexte;
3292
+    return $letexte;
3293 3293
 }
3294 3294
 
3295 3295
 /**
@@ -3303,7 +3303,7 @@  discard block
 block discarded – undo
3303 3303
  * @return string Chaîne vide
3304 3304
  **/
3305 3305
 function vide($texte) {
3306
-	return '';
3306
+    return '';
3307 3307
 }
3308 3308
 
3309 3309
 //
@@ -3332,23 +3332,23 @@  discard block
 block discarded – undo
3332 3332
  *      Code HTML résultant
3333 3333
  **/
3334 3334
 function env_to_params($env, $ignore_params = []) {
3335
-	$ignore_params = array_merge(
3336
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3337
-		$ignore_params
3338
-	);
3339
-	if (!is_array($env)) {
3340
-		$env = unserialize($env);
3341
-	}
3342
-	$texte = '';
3343
-	if ($env) {
3344
-		foreach ($env as $i => $j) {
3345
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3346
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3347
-			}
3348
-		}
3349
-	}
3350
-
3351
-	return $texte;
3335
+    $ignore_params = array_merge(
3336
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3337
+        $ignore_params
3338
+    );
3339
+    if (!is_array($env)) {
3340
+        $env = unserialize($env);
3341
+    }
3342
+    $texte = '';
3343
+    if ($env) {
3344
+        foreach ($env as $i => $j) {
3345
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3346
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3347
+            }
3348
+        }
3349
+    }
3350
+
3351
+    return $texte;
3352 3352
 }
3353 3353
 
3354 3354
 /**
@@ -3371,23 +3371,23 @@  discard block
 block discarded – undo
3371 3371
  *      Code HTML résultant
3372 3372
  **/
3373 3373
 function env_to_attributs($env, $ignore_params = []) {
3374
-	$ignore_params = array_merge(
3375
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3376
-		$ignore_params
3377
-	);
3378
-	if (!is_array($env)) {
3379
-		$env = unserialize($env);
3380
-	}
3381
-	$texte = '';
3382
-	if ($env) {
3383
-		foreach ($env as $i => $j) {
3384
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3385
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3386
-			}
3387
-		}
3388
-	}
3374
+    $ignore_params = array_merge(
3375
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3376
+        $ignore_params
3377
+    );
3378
+    if (!is_array($env)) {
3379
+        $env = unserialize($env);
3380
+    }
3381
+    $texte = '';
3382
+    if ($env) {
3383
+        foreach ($env as $i => $j) {
3384
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3385
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3386
+            }
3387
+        }
3388
+    }
3389 3389
 
3390
-	return $texte;
3390
+    return $texte;
3391 3391
 }
3392 3392
 
3393 3393
 
@@ -3405,7 +3405,7 @@  discard block
 block discarded – undo
3405 3405
  * @return string Chaînes concaténés
3406 3406
  **/
3407 3407
 function concat(...$args): string {
3408
-	return join('', $args);
3408
+    return join('', $args);
3409 3409
 }
3410 3410
 
3411 3411
 
@@ -3425,23 +3425,23 @@  discard block
 block discarded – undo
3425 3425
  *     Contenu du ou des fichiers, concaténé
3426 3426
  **/
3427 3427
 function charge_scripts($files, $script = true) {
3428
-	$flux = '';
3429
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3430
-		if (!is_string($file)) {
3431
-			continue;
3432
-		}
3433
-		if ($script) {
3434
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3435
-		}
3436
-		if ($file) {
3437
-			$path = find_in_path($file);
3438
-			if ($path) {
3439
-				$flux .= spip_file_get_contents($path);
3440
-			}
3441
-		}
3442
-	}
3443
-
3444
-	return $flux;
3428
+    $flux = '';
3429
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3430
+        if (!is_string($file)) {
3431
+            continue;
3432
+        }
3433
+        if ($script) {
3434
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3435
+        }
3436
+        if ($file) {
3437
+            $path = find_in_path($file);
3438
+            if ($path) {
3439
+                $flux .= spip_file_get_contents($path);
3440
+            }
3441
+        }
3442
+    }
3443
+
3444
+    return $flux;
3445 3445
 }
3446 3446
 
3447 3447
 /**
@@ -3452,22 +3452,22 @@  discard block
 block discarded – undo
3452 3452
  * @return string
3453 3453
  */
3454 3454
 function http_img_variante_svg_si_possible($img_file) {
3455
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3456
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3457
-	if (
3458
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3459
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3460
-		and file_exists($variante_svg_generique)
3461
-	) {
3462
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3463
-			$img_file = $variante_svg_size;
3464
-		}
3465
-		else {
3466
-			$img_file = $variante_svg_generique;
3467
-		}
3468
-	}
3455
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3456
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3457
+    if (
3458
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3459
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3460
+        and file_exists($variante_svg_generique)
3461
+    ) {
3462
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3463
+            $img_file = $variante_svg_size;
3464
+        }
3465
+        else {
3466
+            $img_file = $variante_svg_generique;
3467
+        }
3468
+    }
3469 3469
 
3470
-	return $img_file;
3470
+    return $img_file;
3471 3471
 }
3472 3472
 
3473 3473
 /**
@@ -3488,54 +3488,54 @@  discard block
 block discarded – undo
3488 3488
  */
3489 3489
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3490 3490
 
3491
-	$img_file = $img;
3492
-	if ($p = strpos($img_file, '?')) {
3493
-		$img_file = substr($img_file, 0, $p);
3494
-	}
3495
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3496
-		$img_file = chemin_image($img);
3497
-	}
3498
-	else {
3499
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3500
-			$img_file = http_img_variante_svg_si_possible($img_file);
3501
-		}
3502
-	}
3503
-	if (stripos($atts, 'width') === false) {
3504
-		// utiliser directement l'info de taille presente dans le nom
3505
-		if (
3506
-			(!isset($options['utiliser_suffixe_size'])
3507
-				or $options['utiliser_suffixe_size'] == true
3508
-			  or strpos($img_file, '-xx.svg') !== false)
3509
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3510
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3511
-		) {
3512
-			$largeur = $hauteur = intval($regs[1]);
3513
-		} else {
3514
-			$taille = taille_image($img_file);
3515
-			[$hauteur, $largeur] = $taille;
3516
-			if (!$hauteur or !$largeur) {
3517
-				return '';
3518
-			}
3519
-		}
3520
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3521
-	}
3522
-
3523
-	if (file_exists($img_file)) {
3524
-		$img_file = timestamp($img_file);
3525
-	}
3526
-	if ($alt === false) {
3527
-		$alt = '';
3528
-	}
3529
-	elseif ($alt or $alt === '') {
3530
-		$alt = " alt='" . attribut_html($alt) . "'";
3531
-	}
3532
-	else {
3533
-		$alt = " alt='" . attribut_html($title) . "'";
3534
-	}
3535
-	return "<img src='$img_file'$alt"
3536
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3537
-	. ' ' . ltrim($atts)
3538
-	. ' />';
3491
+    $img_file = $img;
3492
+    if ($p = strpos($img_file, '?')) {
3493
+        $img_file = substr($img_file, 0, $p);
3494
+    }
3495
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3496
+        $img_file = chemin_image($img);
3497
+    }
3498
+    else {
3499
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3500
+            $img_file = http_img_variante_svg_si_possible($img_file);
3501
+        }
3502
+    }
3503
+    if (stripos($atts, 'width') === false) {
3504
+        // utiliser directement l'info de taille presente dans le nom
3505
+        if (
3506
+            (!isset($options['utiliser_suffixe_size'])
3507
+                or $options['utiliser_suffixe_size'] == true
3508
+              or strpos($img_file, '-xx.svg') !== false)
3509
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3510
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3511
+        ) {
3512
+            $largeur = $hauteur = intval($regs[1]);
3513
+        } else {
3514
+            $taille = taille_image($img_file);
3515
+            [$hauteur, $largeur] = $taille;
3516
+            if (!$hauteur or !$largeur) {
3517
+                return '';
3518
+            }
3519
+        }
3520
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3521
+    }
3522
+
3523
+    if (file_exists($img_file)) {
3524
+        $img_file = timestamp($img_file);
3525
+    }
3526
+    if ($alt === false) {
3527
+        $alt = '';
3528
+    }
3529
+    elseif ($alt or $alt === '') {
3530
+        $alt = " alt='" . attribut_html($alt) . "'";
3531
+    }
3532
+    else {
3533
+        $alt = " alt='" . attribut_html($title) . "'";
3534
+    }
3535
+    return "<img src='$img_file'$alt"
3536
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3537
+    . ' ' . ltrim($atts)
3538
+    . ' />';
3539 3539
 }
3540 3540
 
3541 3541
 /**
@@ -3547,70 +3547,70 @@  discard block
 block discarded – undo
3547 3547
  * @return string
3548 3548
  */
3549 3549
 function http_style_background($img, $att = '', $size = null) {
3550
-	if ($size and is_numeric($size)) {
3551
-		$size = trim($size) . 'px';
3552
-	}
3553
-	return " style='background" .
3554
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3555
-		. ($size ? "background-size:{$size};" : '')
3556
-		. "'";
3550
+    if ($size and is_numeric($size)) {
3551
+        $size = trim($size) . 'px';
3552
+    }
3553
+    return " style='background" .
3554
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3555
+        . ($size ? "background-size:{$size};" : '')
3556
+        . "'";
3557 3557
 }
3558 3558
 
3559 3559
 
3560 3560
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3561
-	$args = [$alt_or_size, $class_or_size, $size];
3562
-	while (is_null(end($args)) and count($args)) {
3563
-		array_pop($args);
3564
-	}
3565
-	if (!count($args)) {
3566
-		return [null, null, null];
3567
-	}
3568
-	if (count($args) < 3) {
3569
-		$maybe_size = array_pop($args);
3570
-		// @2x
3571
-		// @1.5x
3572
-		// 512
3573
-		// 512x*
3574
-		// 512x300
3575
-		if (
3576
-			!strlen($maybe_size)
3577
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3578
-		) {
3579
-			$args[] = $maybe_size;
3580
-			$maybe_size = null;
3581
-		}
3582
-		while (count($args) < 2) {
3583
-			$args[] = null; // default alt or class
3584
-		}
3585
-		$args[] = $maybe_size;
3586
-	}
3587
-	return $args;
3561
+    $args = [$alt_or_size, $class_or_size, $size];
3562
+    while (is_null(end($args)) and count($args)) {
3563
+        array_pop($args);
3564
+    }
3565
+    if (!count($args)) {
3566
+        return [null, null, null];
3567
+    }
3568
+    if (count($args) < 3) {
3569
+        $maybe_size = array_pop($args);
3570
+        // @2x
3571
+        // @1.5x
3572
+        // 512
3573
+        // 512x*
3574
+        // 512x300
3575
+        if (
3576
+            !strlen($maybe_size)
3577
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3578
+        ) {
3579
+            $args[] = $maybe_size;
3580
+            $maybe_size = null;
3581
+        }
3582
+        while (count($args) < 2) {
3583
+            $args[] = null; // default alt or class
3584
+        }
3585
+        $args[] = $maybe_size;
3586
+    }
3587
+    return $args;
3588 3588
 }
3589 3589
 
3590 3590
 function helper_filtre_balise_img_svg_size($img, $size) {
3591
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3592
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3593
-		$coef = floatval(substr($size, 1, -1));
3594
-		[$h, $w] = taille_image($img);
3595
-		$height = intval(round($h / $coef));
3596
-		$width = intval(round($w / $coef));
3597
-	}
3598
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3599
-	else {
3600
-		$size = explode('x', $size, 2);
3601
-		$size = array_map('trim', $size);
3602
-		$height = $width = intval(array_shift($size));
3603
-
3604
-		if (count($size) and reset($size)) {
3605
-			$height = array_shift($size);
3606
-			if ($height === '*') {
3607
-				[$h, $w] = taille_image($img);
3608
-				$height = intval(round($h * $width / $w));
3609
-			}
3610
-		}
3611
-	}
3612
-
3613
-	return [$width, $height];
3591
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3592
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3593
+        $coef = floatval(substr($size, 1, -1));
3594
+        [$h, $w] = taille_image($img);
3595
+        $height = intval(round($h / $coef));
3596
+        $width = intval(round($w / $coef));
3597
+    }
3598
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3599
+    else {
3600
+        $size = explode('x', $size, 2);
3601
+        $size = array_map('trim', $size);
3602
+        $height = $width = intval(array_shift($size));
3603
+
3604
+        if (count($size) and reset($size)) {
3605
+            $height = array_shift($size);
3606
+            if ($height === '*') {
3607
+                [$h, $w] = taille_image($img);
3608
+                $height = intval(round($h * $width / $w));
3609
+            }
3610
+        }
3611
+    }
3612
+
3613
+    return [$width, $height];
3614 3614
 }
3615 3615
 
3616 3616
 /**
@@ -3646,43 +3646,43 @@  discard block
 block discarded – undo
3646 3646
  */
3647 3647
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3648 3648
 
3649
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3650
-
3651
-	$img = trim($img);
3652
-	if (strpos($img, '<img') === 0) {
3653
-		if (!is_null($alt)) {
3654
-			$img = inserer_attribut($img, 'alt', $alt);
3655
-		}
3656
-		if (!is_null($class)) {
3657
-			if (strlen($class)) {
3658
-				$img = inserer_attribut($img, 'class', $class);
3659
-			}
3660
-			else {
3661
-				$img = vider_attribut($img, 'class');
3662
-			}
3663
-		}
3664
-	}
3665
-	else {
3666
-		$img = http_img_pack(
3667
-			$img,
3668
-			$alt,
3669
-			$class ? " class='" . attribut_html($class) . "'" : '',
3670
-			'',
3671
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3672
-		);
3673
-		if (is_null($alt)) {
3674
-			$img = vider_attribut($img, 'alt');
3675
-		}
3676
-	}
3677
-
3678
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3679
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3680
-
3681
-		$img = inserer_attribut($img, 'width', $width);
3682
-		$img = inserer_attribut($img, 'height', $height);
3683
-	}
3684
-
3685
-	return $img;
3649
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3650
+
3651
+    $img = trim($img);
3652
+    if (strpos($img, '<img') === 0) {
3653
+        if (!is_null($alt)) {
3654
+            $img = inserer_attribut($img, 'alt', $alt);
3655
+        }
3656
+        if (!is_null($class)) {
3657
+            if (strlen($class)) {
3658
+                $img = inserer_attribut($img, 'class', $class);
3659
+            }
3660
+            else {
3661
+                $img = vider_attribut($img, 'class');
3662
+            }
3663
+        }
3664
+    }
3665
+    else {
3666
+        $img = http_img_pack(
3667
+            $img,
3668
+            $alt,
3669
+            $class ? " class='" . attribut_html($class) . "'" : '',
3670
+            '',
3671
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3672
+        );
3673
+        if (is_null($alt)) {
3674
+            $img = vider_attribut($img, 'alt');
3675
+        }
3676
+    }
3677
+
3678
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3679
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3680
+
3681
+        $img = inserer_attribut($img, 'width', $width);
3682
+        $img = inserer_attribut($img, 'height', $height);
3683
+    }
3684
+
3685
+    return $img;
3686 3686
 }
3687 3687
 
3688 3688
 
@@ -3716,80 +3716,80 @@  discard block
 block discarded – undo
3716 3716
  */
3717 3717
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3718 3718
 
3719
-	$svg = null;
3720
-	$img = trim($img);
3721
-	$img_file = $img;
3722
-	if (strpos($img, '<svg') === false) {
3723
-		if ($p = strpos($img_file, '?')) {
3724
-			$img_file = substr($img_file, 0, $p);
3725
-		}
3726
-
3727
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3728
-		// la copie locale a toutes les chances d'etre la ou de resservir
3729
-		if (tester_url_absolue($img_file)) {
3730
-			include_spip('inc/distant');
3731
-			$fichier = copie_locale($img_file);
3732
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3733
-		}
3734
-
3735
-		if (
3736
-			!$img_file
3737
-			or !file_exists($img_file)
3738
-			or !$svg = file_get_contents($img_file)
3739
-		) {
3740
-			return '';
3741
-		}
3742
-	}
3743
-
3744
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3745
-		return '';
3746
-	}
3747
-
3748
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3749
-
3750
-	$balise_svg = $match[0];
3751
-	$balise_svg_source = $balise_svg;
3752
-
3753
-	// entete XML à supprimer
3754
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3755
-
3756
-	// IE est toujours mon ami
3757
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3758
-
3759
-	// regler la classe
3760
-	if (!is_null($class)) {
3761
-		if (strlen($class)) {
3762
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3763
-		}
3764
-		else {
3765
-			$balise_svg = vider_attribut($balise_svg, 'class');
3766
-		}
3767
-	}
3768
-
3769
-	// regler le alt
3770
-	if ($alt) {
3771
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3772
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3773
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3774
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3775
-		$balise_svg .= $title;
3776
-	}
3777
-	else {
3778
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3779
-	}
3780
-
3781
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3782
-
3783
-	if (!is_null($size) and strlen($size = trim($size))) {
3784
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3785
-
3786
-		if (!function_exists('svg_redimensionner')) {
3787
-			include_spip('inc/svg');
3788
-		}
3789
-		$svg = svg_redimensionner($svg, $width, $height);
3790
-	}
3791
-
3792
-	return $svg;
3719
+    $svg = null;
3720
+    $img = trim($img);
3721
+    $img_file = $img;
3722
+    if (strpos($img, '<svg') === false) {
3723
+        if ($p = strpos($img_file, '?')) {
3724
+            $img_file = substr($img_file, 0, $p);
3725
+        }
3726
+
3727
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3728
+        // la copie locale a toutes les chances d'etre la ou de resservir
3729
+        if (tester_url_absolue($img_file)) {
3730
+            include_spip('inc/distant');
3731
+            $fichier = copie_locale($img_file);
3732
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3733
+        }
3734
+
3735
+        if (
3736
+            !$img_file
3737
+            or !file_exists($img_file)
3738
+            or !$svg = file_get_contents($img_file)
3739
+        ) {
3740
+            return '';
3741
+        }
3742
+    }
3743
+
3744
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3745
+        return '';
3746
+    }
3747
+
3748
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3749
+
3750
+    $balise_svg = $match[0];
3751
+    $balise_svg_source = $balise_svg;
3752
+
3753
+    // entete XML à supprimer
3754
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3755
+
3756
+    // IE est toujours mon ami
3757
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3758
+
3759
+    // regler la classe
3760
+    if (!is_null($class)) {
3761
+        if (strlen($class)) {
3762
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3763
+        }
3764
+        else {
3765
+            $balise_svg = vider_attribut($balise_svg, 'class');
3766
+        }
3767
+    }
3768
+
3769
+    // regler le alt
3770
+    if ($alt) {
3771
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3772
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3773
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3774
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3775
+        $balise_svg .= $title;
3776
+    }
3777
+    else {
3778
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3779
+    }
3780
+
3781
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3782
+
3783
+    if (!is_null($size) and strlen($size = trim($size))) {
3784
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3785
+
3786
+        if (!function_exists('svg_redimensionner')) {
3787
+            include_spip('inc/svg');
3788
+        }
3789
+        $svg = svg_redimensionner($svg, $width, $height);
3790
+    }
3791
+
3792
+    return $svg;
3793 3793
 }
3794 3794
 
3795 3795
 
@@ -3815,18 +3815,18 @@  discard block
 block discarded – undo
3815 3815
  *     Code HTML résultant
3816 3816
  **/
3817 3817
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3818
-	$texte = '';
3819
-	if (is_array($tableau)) {
3820
-		foreach ($tableau as $k => $v) {
3821
-			$res = recuperer_fond(
3822
-				'modeles/' . $modele,
3823
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3824
-			);
3825
-			$texte .= $res;
3826
-		}
3827
-	}
3818
+    $texte = '';
3819
+    if (is_array($tableau)) {
3820
+        foreach ($tableau as $k => $v) {
3821
+            $res = recuperer_fond(
3822
+                'modeles/' . $modele,
3823
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3824
+            );
3825
+            $texte .= $res;
3826
+        }
3827
+    }
3828 3828
 
3829
-	return $texte;
3829
+    return $texte;
3830 3830
 }
3831 3831
 
3832 3832
 
@@ -3851,37 +3851,37 @@  discard block
 block discarded – undo
3851 3851
  *         - tout : retourne toutes les informations du plugin actif
3852 3852
  **/
3853 3853
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3854
-	include_spip('inc/plugin');
3855
-	$plugin = strtoupper($plugin);
3856
-	$plugins_actifs = liste_plugin_actifs();
3857
-
3858
-	if (!$plugin) {
3859
-		return serialize(array_keys($plugins_actifs));
3860
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3861
-		return '';
3862
-	} elseif (($type_info == 'est_actif') and !$reload) {
3863
-		return $plugins_actifs[$plugin] ? 1 : 0;
3864
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3865
-		return $plugins_actifs[$plugin][$type_info];
3866
-	} else {
3867
-		$get_infos = charger_fonction('get_infos', 'plugins');
3868
-		// On prend en compte les extensions
3869
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3870
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3871
-		} else {
3872
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3873
-		}
3874
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3875
-			return '';
3876
-		}
3877
-		if ($type_info == 'tout') {
3878
-			return $infos;
3879
-		} elseif ($type_info == 'est_actif') {
3880
-			return $infos ? 1 : 0;
3881
-		} else {
3882
-			return strval($infos[$type_info]);
3883
-		}
3884
-	}
3854
+    include_spip('inc/plugin');
3855
+    $plugin = strtoupper($plugin);
3856
+    $plugins_actifs = liste_plugin_actifs();
3857
+
3858
+    if (!$plugin) {
3859
+        return serialize(array_keys($plugins_actifs));
3860
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3861
+        return '';
3862
+    } elseif (($type_info == 'est_actif') and !$reload) {
3863
+        return $plugins_actifs[$plugin] ? 1 : 0;
3864
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3865
+        return $plugins_actifs[$plugin][$type_info];
3866
+    } else {
3867
+        $get_infos = charger_fonction('get_infos', 'plugins');
3868
+        // On prend en compte les extensions
3869
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3870
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3871
+        } else {
3872
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3873
+        }
3874
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3875
+            return '';
3876
+        }
3877
+        if ($type_info == 'tout') {
3878
+            return $infos;
3879
+        } elseif ($type_info == 'est_actif') {
3880
+            return $infos ? 1 : 0;
3881
+        } else {
3882
+            return strval($infos[$type_info]);
3883
+        }
3884
+    }
3885 3885
 }
3886 3886
 
3887 3887
 
@@ -3908,9 +3908,9 @@  discard block
 block discarded – undo
3908 3908
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3909 3909
  */
3910 3910
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3911
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3911
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3912 3912
 
3913
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3913
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3914 3914
 }
3915 3915
 
3916 3916
 
@@ -3940,19 +3940,19 @@  discard block
 block discarded – undo
3940 3940
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3941 3941
  */
3942 3942
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3943
-	static $puce_statut = null;
3944
-	if (!$puce_statut) {
3945
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3946
-	}
3943
+    static $puce_statut = null;
3944
+    if (!$puce_statut) {
3945
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3946
+    }
3947 3947
 
3948
-	return $puce_statut(
3949
-		$id_objet,
3950
-		$statut,
3951
-		$id_parent,
3952
-		$objet,
3953
-		false,
3954
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3955
-	);
3948
+    return $puce_statut(
3949
+        $id_objet,
3950
+        $statut,
3951
+        $id_parent,
3952
+        $objet,
3953
+        false,
3954
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3955
+    );
3956 3956
 }
3957 3957
 
3958 3958
 
@@ -3979,98 +3979,98 @@  discard block
 block discarded – undo
3979 3979
  *   hash du contexte
3980 3980
  */
3981 3981
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3982
-	$env = null;
3983
-	if (
3984
-		is_string($c)
3985
-		and @unserialize($c) !== false
3986
-	) {
3987
-		$c = unserialize($c);
3988
-	}
3989
-
3990
-	// supprimer les parametres debut_x
3991
-	// pour que la pagination ajax ne soit pas plantee
3992
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3993
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3994
-	if (is_array($c)) {
3995
-		foreach ($c as $k => $v) {
3996
-			if (strpos($k, 'debut_') === 0) {
3997
-				unset($c[$k]);
3998
-			}
3999
-		}
4000
-	}
4001
-
4002
-	if (!function_exists('calculer_cle_action')) {
4003
-		include_spip('inc/securiser_action');
4004
-	}
4005
-
4006
-	$c = serialize($c);
4007
-	$cle = calculer_cle_action($form . $c);
4008
-	$c = "$cle:$c";
4009
-
4010
-	// on ne stocke pas les contextes dans des fichiers en cache
4011
-	// par defaut, sauf si cette configuration a été forcée
4012
-	// OU que la longueur de l’argument géneré est plus long
4013
-	// que ce qui est toléré.
4014
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4015
-	if (!$cache_contextes_ajax) {
4016
-		$env = $c;
4017
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4018
-			$env = gzdeflate($env);
4019
-		}
4020
-		$env = _xor($env);
4021
-		$env = base64_encode($env);
4022
-		$len = strlen($env);
4023
-		// Si l’url est trop longue pour le navigateur
4024
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4025
-		if ($len > $max_len) {
4026
-			$cache_contextes_ajax = true;
4027
-			spip_log(
4028
-				'Contextes AJAX forces en fichiers !'
4029
-				. ' Cela arrive lorsque la valeur du contexte'
4030
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4031
-				_LOG_AVERTISSEMENT
4032
-			);
4033
-		}
4034
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4035
-		elseif (
4036
-			$max_len = @ini_get('suhosin.get.max_value_length')
4037
-			and $max_len < $len
4038
-		) {
4039
-			$cache_contextes_ajax = true;
4040
-			spip_log('Contextes AJAX forces en fichiers !'
4041
-				. ' Cela arrive lorsque la valeur du contexte'
4042
-				. ' depasse la longueur maximale autorisee par Suhosin'
4043
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4044
-				. ' Vous devriez modifier les parametres de Suhosin'
4045
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4046
-		}
4047
-	}
4048
-
4049
-	if ($cache_contextes_ajax) {
4050
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4051
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4052
-		$md5 = md5($c);
4053
-		ecrire_fichier("$dir/c$md5", $c);
4054
-		$env = $md5;
4055
-	}
4056
-
4057
-	if ($emboite === null) {
4058
-		return $env;
4059
-	}
4060
-	if (!trim($emboite)) {
4061
-		return '';
4062
-	}
4063
-	// toujours encoder l'url source dans le bloc ajax
4064
-	$r = self();
4065
-	$r = ' data-origin="' . $r . '"';
4066
-	$class = 'ajaxbloc';
4067
-	if ($ajaxid and is_string($ajaxid)) {
4068
-		// ajaxid est normalement conforme a un nom de classe css
4069
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4070
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4071
-	}
4072
-
4073
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3982
+    $env = null;
3983
+    if (
3984
+        is_string($c)
3985
+        and @unserialize($c) !== false
3986
+    ) {
3987
+        $c = unserialize($c);
3988
+    }
3989
+
3990
+    // supprimer les parametres debut_x
3991
+    // pour que la pagination ajax ne soit pas plantee
3992
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3993
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3994
+    if (is_array($c)) {
3995
+        foreach ($c as $k => $v) {
3996
+            if (strpos($k, 'debut_') === 0) {
3997
+                unset($c[$k]);
3998
+            }
3999
+        }
4000
+    }
4001
+
4002
+    if (!function_exists('calculer_cle_action')) {
4003
+        include_spip('inc/securiser_action');
4004
+    }
4005
+
4006
+    $c = serialize($c);
4007
+    $cle = calculer_cle_action($form . $c);
4008
+    $c = "$cle:$c";
4009
+
4010
+    // on ne stocke pas les contextes dans des fichiers en cache
4011
+    // par defaut, sauf si cette configuration a été forcée
4012
+    // OU que la longueur de l’argument géneré est plus long
4013
+    // que ce qui est toléré.
4014
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4015
+    if (!$cache_contextes_ajax) {
4016
+        $env = $c;
4017
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4018
+            $env = gzdeflate($env);
4019
+        }
4020
+        $env = _xor($env);
4021
+        $env = base64_encode($env);
4022
+        $len = strlen($env);
4023
+        // Si l’url est trop longue pour le navigateur
4024
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4025
+        if ($len > $max_len) {
4026
+            $cache_contextes_ajax = true;
4027
+            spip_log(
4028
+                'Contextes AJAX forces en fichiers !'
4029
+                . ' Cela arrive lorsque la valeur du contexte'
4030
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4031
+                _LOG_AVERTISSEMENT
4032
+            );
4033
+        }
4034
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4035
+        elseif (
4036
+            $max_len = @ini_get('suhosin.get.max_value_length')
4037
+            and $max_len < $len
4038
+        ) {
4039
+            $cache_contextes_ajax = true;
4040
+            spip_log('Contextes AJAX forces en fichiers !'
4041
+                . ' Cela arrive lorsque la valeur du contexte'
4042
+                . ' depasse la longueur maximale autorisee par Suhosin'
4043
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4044
+                . ' Vous devriez modifier les parametres de Suhosin'
4045
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4046
+        }
4047
+    }
4048
+
4049
+    if ($cache_contextes_ajax) {
4050
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4051
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4052
+        $md5 = md5($c);
4053
+        ecrire_fichier("$dir/c$md5", $c);
4054
+        $env = $md5;
4055
+    }
4056
+
4057
+    if ($emboite === null) {
4058
+        return $env;
4059
+    }
4060
+    if (!trim($emboite)) {
4061
+        return '';
4062
+    }
4063
+    // toujours encoder l'url source dans le bloc ajax
4064
+    $r = self();
4065
+    $r = ' data-origin="' . $r . '"';
4066
+    $class = 'ajaxbloc';
4067
+    if ($ajaxid and is_string($ajaxid)) {
4068
+        // ajaxid est normalement conforme a un nom de classe css
4069
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4070
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4071
+    }
4072
+
4073
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4074 4074
 }
4075 4075
 
4076 4076
 /**
@@ -4090,37 +4090,37 @@  discard block
 block discarded – undo
4090 4090
  *   - false : erreur de décodage
4091 4091
  */
4092 4092
 function decoder_contexte_ajax($c, $form = '') {
4093
-	if (!function_exists('calculer_cle_action')) {
4094
-		include_spip('inc/securiser_action');
4095
-	}
4096
-	if (
4097
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4098
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4099
-		and lire_fichier("$dir/c$c", $contexte)
4100
-	) {
4101
-		$c = $contexte;
4102
-	} else {
4103
-		$c = @base64_decode($c);
4104
-		$c = _xor($c);
4105
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4106
-			$c = @gzinflate($c);
4107
-		}
4108
-	}
4109
-
4110
-	// extraire la signature en debut de contexte
4111
-	// et la verifier avant de deserializer
4112
-	// format : signature:donneesserializees
4113
-	if ($p = strpos($c, ':')) {
4114
-		$cle = substr($c, 0, $p);
4115
-		$c = substr($c, $p + 1);
4116
-
4117
-		if ($cle == calculer_cle_action($form . $c)) {
4118
-			$env = @unserialize($c);
4119
-			return $env;
4120
-		}
4121
-	}
4122
-
4123
-	return false;
4093
+    if (!function_exists('calculer_cle_action')) {
4094
+        include_spip('inc/securiser_action');
4095
+    }
4096
+    if (
4097
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4098
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4099
+        and lire_fichier("$dir/c$c", $contexte)
4100
+    ) {
4101
+        $c = $contexte;
4102
+    } else {
4103
+        $c = @base64_decode($c);
4104
+        $c = _xor($c);
4105
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4106
+            $c = @gzinflate($c);
4107
+        }
4108
+    }
4109
+
4110
+    // extraire la signature en debut de contexte
4111
+    // et la verifier avant de deserializer
4112
+    // format : signature:donneesserializees
4113
+    if ($p = strpos($c, ':')) {
4114
+        $cle = substr($c, 0, $p);
4115
+        $c = substr($c, $p + 1);
4116
+
4117
+        if ($cle == calculer_cle_action($form . $c)) {
4118
+            $env = @unserialize($c);
4119
+            return $env;
4120
+        }
4121
+    }
4122
+
4123
+    return false;
4124 4124
 }
4125 4125
 
4126 4126
 
@@ -4138,20 +4138,20 @@  discard block
 block discarded – undo
4138 4138
  *    Message décrypté ou encrypté
4139 4139
  **/
4140 4140
 function _xor($message, $key = null) {
4141
-	if (is_null($key)) {
4142
-		if (!function_exists('calculer_cle_action')) {
4143
-			include_spip('inc/securiser_action');
4144
-		}
4145
-		$key = pack('H*', calculer_cle_action('_xor'));
4146
-	}
4141
+    if (is_null($key)) {
4142
+        if (!function_exists('calculer_cle_action')) {
4143
+            include_spip('inc/securiser_action');
4144
+        }
4145
+        $key = pack('H*', calculer_cle_action('_xor'));
4146
+    }
4147 4147
 
4148
-	$keylen = strlen($key);
4149
-	$messagelen = strlen($message);
4150
-	for ($i = 0; $i < $messagelen; $i++) {
4151
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4152
-	}
4148
+    $keylen = strlen($key);
4149
+    $messagelen = strlen($message);
4150
+    for ($i = 0; $i < $messagelen; $i++) {
4151
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4152
+    }
4153 4153
 
4154
-	return $message;
4154
+    return $message;
4155 4155
 }
4156 4156
 
4157 4157
 /**
@@ -4165,7 +4165,7 @@  discard block
 block discarded – undo
4165 4165
  * @return string
4166 4166
  */
4167 4167
 function url_reponse_forum($texte) {
4168
- return $texte;
4168
+    return $texte;
4169 4169
 }
4170 4170
 
4171 4171
 /**
@@ -4179,7 +4179,7 @@  discard block
 block discarded – undo
4179 4179
  * @return string
4180 4180
  */
4181 4181
 function url_rss_forum($texte) {
4182
- return $texte;
4182
+    return $texte;
4183 4183
 }
4184 4184
 
4185 4185
 
@@ -4218,37 +4218,37 @@  discard block
 block discarded – undo
4218 4218
  *   Code HTML
4219 4219
  */
4220 4220
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4221
-	if ($on) {
4222
-		$bal = 'strong';
4223
-		$class = '';
4224
-		$att = '';
4225
-		// si $on passe la balise et optionnelement une ou ++classe
4226
-		// a.active span.selected.active etc....
4227
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4228
-			$on = explode('.', $on);
4229
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4230
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4231
-				$bal = array_shift($on);
4232
-				$class = implode(' ', $on);
4233
-				if ($bal == 'a') {
4234
-					$att = 'href="#" ';
4235
-				}
4236
-			}
4237
-		}
4238
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4239
-	} else {
4240
-		$bal = 'a';
4241
-		$att = "href='$url'"
4242
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4243
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4244
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4245
-			. $evt;
4246
-	}
4247
-	if ($libelle === null) {
4248
-		$libelle = $url;
4249
-	}
4250
-
4251
-	return "<$bal $att>$libelle</$bal>";
4221
+    if ($on) {
4222
+        $bal = 'strong';
4223
+        $class = '';
4224
+        $att = '';
4225
+        // si $on passe la balise et optionnelement une ou ++classe
4226
+        // a.active span.selected.active etc....
4227
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4228
+            $on = explode('.', $on);
4229
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4230
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4231
+                $bal = array_shift($on);
4232
+                $class = implode(' ', $on);
4233
+                if ($bal == 'a') {
4234
+                    $att = 'href="#" ';
4235
+                }
4236
+            }
4237
+        }
4238
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4239
+    } else {
4240
+        $bal = 'a';
4241
+        $att = "href='$url'"
4242
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4243
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4244
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4245
+            . $evt;
4246
+    }
4247
+    if ($libelle === null) {
4248
+        $libelle = $url;
4249
+    }
4250
+
4251
+    return "<$bal $att>$libelle</$bal>";
4252 4252
 }
4253 4253
 
4254 4254
 
@@ -4265,39 +4265,39 @@  discard block
 block discarded – undo
4265 4265
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4266 4266
  */
4267 4267
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4268
-	static $local_singulier_ou_pluriel = [];
4269
-
4270
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4271
-	if (!is_numeric($nb) or $nb == 0) {
4272
-		return '';
4273
-	}
4274
-	if (!is_array($vars)) {
4275
-		return '';
4276
-	}
4277
-
4278
-	$langue = $GLOBALS['spip_lang'];
4279
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4280
-		$local_singulier_ou_pluriel[$langue] = false;
4281
-		if (
4282
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4283
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4284
-		) {
4285
-			$local_singulier_ou_pluriel[$langue] = $f;
4286
-		}
4287
-	}
4288
-
4289
-	// si on a une surcharge on l'utilise
4290
-	if ($local_singulier_ou_pluriel[$langue]) {
4291
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4292
-	}
4293
-
4294
-	// sinon traitement par defaut
4295
-	$vars[$var] = $nb;
4296
-	if ($nb >= 2) {
4297
-		return _T($chaine_plusieurs, $vars);
4298
-	} else {
4299
-		return _T($chaine_un, $vars);
4300
-	}
4268
+    static $local_singulier_ou_pluriel = [];
4269
+
4270
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4271
+    if (!is_numeric($nb) or $nb == 0) {
4272
+        return '';
4273
+    }
4274
+    if (!is_array($vars)) {
4275
+        return '';
4276
+    }
4277
+
4278
+    $langue = $GLOBALS['spip_lang'];
4279
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4280
+        $local_singulier_ou_pluriel[$langue] = false;
4281
+        if (
4282
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4283
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4284
+        ) {
4285
+            $local_singulier_ou_pluriel[$langue] = $f;
4286
+        }
4287
+    }
4288
+
4289
+    // si on a une surcharge on l'utilise
4290
+    if ($local_singulier_ou_pluriel[$langue]) {
4291
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4292
+    }
4293
+
4294
+    // sinon traitement par defaut
4295
+    $vars[$var] = $nb;
4296
+    if ($nb >= 2) {
4297
+        return _T($chaine_plusieurs, $vars);
4298
+    } else {
4299
+        return _T($chaine_un, $vars);
4300
+    }
4301 4301
 }
4302 4302
 
4303 4303
 
@@ -4325,73 +4325,73 @@  discard block
 block discarded – undo
4325 4325
  */
4326 4326
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4327 4327
 
4328
-	$class_lien = $class_bouton = $class;
4329
-
4330
-	// Normaliser la fonction et compléter la classe en fonction
4331
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4332
-		$class_lien .= ' danger';
4333
-		$class_bouton .= ' btn_danger';
4334
-	} elseif ($fonction == 'rien.gif') {
4335
-		$fonction = '';
4336
-	} elseif ($fonction == 'delsafe') {
4337
-		$fonction = 'del';
4338
-	}
4339
-
4340
-	$fond_origine = $fond;
4341
-	// Remappage des icone : article-24.png+new => article-new-24.png
4342
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4343
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4344
-	}
4345
-
4346
-	// Ajouter le type d'objet dans la classe
4347
-	$objet_type = substr(basename($fond), 0, -4);
4348
-	$class_lien .= " $objet_type";
4349
-	$class_bouton .= " $objet_type";
4350
-
4351
-	// Texte
4352
-	$alt = attribut_html($texte);
4353
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4354
-
4355
-	// Liens : préparer les classes ajax
4356
-	$ajax = '';
4357
-	if ($type === 'lien') {
4358
-		if (strpos($class_lien, 'ajax') !== false) {
4359
-			$ajax = 'ajax';
4360
-			if (strpos($class_lien, 'preload') !== false) {
4361
-				$ajax .= ' preload';
4362
-			}
4363
-			if (strpos($class_lien, 'nocache') !== false) {
4364
-				$ajax .= ' nocache';
4365
-			}
4366
-			$ajax = " class='$ajax'";
4367
-		}
4368
-	}
4369
-
4370
-	// Repérer la taille et l'ajouter dans la classe
4371
-	$size = 24;
4372
-	if (
4373
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4374
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4375
-	) {
4376
-		$size = $match[1];
4377
-	}
4378
-	$class_lien .= " s$size";
4379
-	$class_bouton .= " s$size";
4380
-
4381
-	// Icône
4382
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4383
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4384
-
4385
-	// Markup final
4386
-	if ($type == 'lien') {
4387
-		return "<span class='icone $class_lien'>"
4388
-		. "<a href='$lien'$title$ajax$javascript>"
4389
-		. $icone
4390
-		. "<b>$texte</b>"
4391
-		. "</a></span>\n";
4392
-	} else {
4393
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4394
-	}
4328
+    $class_lien = $class_bouton = $class;
4329
+
4330
+    // Normaliser la fonction et compléter la classe en fonction
4331
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4332
+        $class_lien .= ' danger';
4333
+        $class_bouton .= ' btn_danger';
4334
+    } elseif ($fonction == 'rien.gif') {
4335
+        $fonction = '';
4336
+    } elseif ($fonction == 'delsafe') {
4337
+        $fonction = 'del';
4338
+    }
4339
+
4340
+    $fond_origine = $fond;
4341
+    // Remappage des icone : article-24.png+new => article-new-24.png
4342
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4343
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4344
+    }
4345
+
4346
+    // Ajouter le type d'objet dans la classe
4347
+    $objet_type = substr(basename($fond), 0, -4);
4348
+    $class_lien .= " $objet_type";
4349
+    $class_bouton .= " $objet_type";
4350
+
4351
+    // Texte
4352
+    $alt = attribut_html($texte);
4353
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4354
+
4355
+    // Liens : préparer les classes ajax
4356
+    $ajax = '';
4357
+    if ($type === 'lien') {
4358
+        if (strpos($class_lien, 'ajax') !== false) {
4359
+            $ajax = 'ajax';
4360
+            if (strpos($class_lien, 'preload') !== false) {
4361
+                $ajax .= ' preload';
4362
+            }
4363
+            if (strpos($class_lien, 'nocache') !== false) {
4364
+                $ajax .= ' nocache';
4365
+            }
4366
+            $ajax = " class='$ajax'";
4367
+        }
4368
+    }
4369
+
4370
+    // Repérer la taille et l'ajouter dans la classe
4371
+    $size = 24;
4372
+    if (
4373
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4374
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4375
+    ) {
4376
+        $size = $match[1];
4377
+    }
4378
+    $class_lien .= " s$size";
4379
+    $class_bouton .= " s$size";
4380
+
4381
+    // Icône
4382
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4383
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4384
+
4385
+    // Markup final
4386
+    if ($type == 'lien') {
4387
+        return "<span class='icone $class_lien'>"
4388
+        . "<a href='$lien'$title$ajax$javascript>"
4389
+        . $icone
4390
+        . "<b>$texte</b>"
4391
+        . "</a></span>\n";
4392
+    } else {
4393
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4394
+    }
4395 4395
 }
4396 4396
 
4397 4397
 /**
@@ -4415,7 +4415,7 @@  discard block
 block discarded – undo
4415 4415
  *     Code HTML du lien
4416 4416
  **/
4417 4417
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4418
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4418
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4419 4419
 }
4420 4420
 
4421 4421
 /**
@@ -4450,7 +4450,7 @@  discard block
 block discarded – undo
4450 4450
  *     Code HTML du lien
4451 4451
  **/
4452 4452
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4453
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4453
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4454 4454
 }
4455 4455
 
4456 4456
 /**
@@ -4495,7 +4495,7 @@  discard block
 block discarded – undo
4495 4495
  *     Code HTML du lien
4496 4496
  **/
4497 4497
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4498
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4498
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4499 4499
 }
4500 4500
 
4501 4501
 /**
@@ -4526,7 +4526,7 @@  discard block
 block discarded – undo
4526 4526
  *     Code HTML du lien
4527 4527
  **/
4528 4528
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4529
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4529
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4530 4530
 }
4531 4531
 
4532 4532
 /**
@@ -4557,7 +4557,7 @@  discard block
 block discarded – undo
4557 4557
  *     Code HTML du lien
4558 4558
  */
4559 4559
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4560
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4560
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4561 4561
 }
4562 4562
 
4563 4563
 
@@ -4579,7 +4579,7 @@  discard block
 block discarded – undo
4579 4579
  * @return array Liste des éléments
4580 4580
  */
4581 4581
 function filtre_explode_dist($a, $b) {
4582
- return explode($b, $a);
4582
+    return explode($b, $a);
4583 4583
 }
4584 4584
 
4585 4585
 /**
@@ -4600,7 +4600,7 @@  discard block
 block discarded – undo
4600 4600
  * @return string Texte
4601 4601
  */
4602 4602
 function filtre_implode_dist($a, $b) {
4603
- return is_array($a) ? implode($b, $a) : $a;
4603
+    return is_array($a) ? implode($b, $a) : $a;
4604 4604
 }
4605 4605
 
4606 4606
 /**
@@ -4609,24 +4609,24 @@  discard block
 block discarded – undo
4609 4609
  * @return string Code CSS
4610 4610
  */
4611 4611
 function bando_images_background() {
4612
-	include_spip('inc/bandeau');
4613
-	// recuperer tous les boutons et leurs images
4614
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4612
+    include_spip('inc/bandeau');
4613
+    // recuperer tous les boutons et leurs images
4614
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4615 4615
 
4616
-	$res = '';
4617
-	foreach ($boutons as $page => $detail) {
4618
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4619
-		if (is_array($detail->sousmenu)) {
4620
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4621
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4622
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4623
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4624
-				}
4625
-			}
4626
-		}
4627
-	}
4616
+    $res = '';
4617
+    foreach ($boutons as $page => $detail) {
4618
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4619
+        if (is_array($detail->sousmenu)) {
4620
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4621
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4622
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4623
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4624
+                }
4625
+            }
4626
+        }
4627
+    }
4628 4628
 
4629
-	return $res;
4629
+    return $res;
4630 4630
 }
4631 4631
 
4632 4632
 /**
@@ -4651,27 +4651,27 @@  discard block
 block discarded – undo
4651 4651
  */
4652 4652
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4653 4653
 
4654
-	// Classes : dispatcher `ajax` sur le formulaire
4655
-	$class_form = '';
4656
-	if (strpos($class, 'ajax') !== false) {
4657
-		$class_form = 'ajax';
4658
-		$class = str_replace('ajax', '', $class);
4659
-	}
4660
-	$class_btn = 'submit ' . trim($class);
4654
+    // Classes : dispatcher `ajax` sur le formulaire
4655
+    $class_form = '';
4656
+    if (strpos($class, 'ajax') !== false) {
4657
+        $class_form = 'ajax';
4658
+        $class = str_replace('ajax', '', $class);
4659
+    }
4660
+    $class_btn = 'submit ' . trim($class);
4661 4661
 
4662
-	if ($confirm) {
4663
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4664
-		if ($callback) {
4665
-			$callback = "$confirm?($callback):false";
4666
-		} else {
4667
-			$callback = $confirm;
4668
-		}
4669
-	}
4670
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4671
-	$title = $title ? " title='$title'" : '';
4662
+    if ($confirm) {
4663
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4664
+        if ($callback) {
4665
+            $callback = "$confirm?($callback):false";
4666
+        } else {
4667
+            $callback = $confirm;
4668
+        }
4669
+    }
4670
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4671
+    $title = $title ? " title='$title'" : '';
4672 4672
 
4673
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4674
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4673
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4674
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4675 4675
 }
4676 4676
 
4677 4677
 /**
@@ -4694,101 +4694,101 @@  discard block
 block discarded – undo
4694 4694
  * @return string
4695 4695
  */
4696 4696
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4697
-	static $trouver_table = null;
4698
-	static $objets;
4699
-
4700
-	// On verifie qu'on a tout ce qu'il faut
4701
-	$id_objet = intval($id_objet);
4702
-	if (!($id_objet and $type_objet and $info)) {
4703
-		return '';
4704
-	}
4705
-
4706
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4707
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4708
-		return '';
4709
-	}
4710
-
4711
-	// Si on demande l'url, on retourne direct la fonction
4712
-	if ($info == 'url') {
4713
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4714
-	}
4715
-
4716
-	// Sinon on va tout chercher dans la table et on garde en memoire
4717
-	$demande_titre = ($info === 'titre');
4718
-	$demande_introduction = ($info === 'introduction');
4719
-
4720
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4721
-	if (
4722
-		!isset($objets[$type_objet][$id_objet])
4723
-		or
4724
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4725
-	) {
4726
-		if (!$trouver_table) {
4727
-			$trouver_table = charger_fonction('trouver_table', 'base');
4728
-		}
4729
-		$desc = $trouver_table(table_objet_sql($type_objet));
4730
-		if (!$desc) {
4731
-			return $objets[$type_objet] = false;
4732
-		}
4733
-
4734
-		// Si on demande le titre, on le gere en interne
4735
-		$champ_titre = '';
4736
-		if ($demande_titre) {
4737
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4738
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4739
-		}
4740
-		include_spip('base/abstract_sql');
4741
-		include_spip('base/connect_sql');
4742
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4743
-			'*' . $champ_titre,
4744
-			$desc['table_sql'],
4745
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4746
-		);
4747
-
4748
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4749
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4750
-	}
4751
-
4752
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4753
-	// ajouter la longueur au début des params supplémentaires
4754
-	if ($demande_introduction) {
4755
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4756
-		array_unshift($params, $introduction_longueur);
4757
-	}
4758
-
4759
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4760
-	if (
4761
-		$generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4762
-		// @deprecated 4.1 generer_TRUC_TYPE
4763
-		or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4764
-	) {
4765
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4766
-	}
4767
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4768
-	elseif (
4769
-		$generer = charger_fonction("generer_objet_${info}", '', true)
4770
-		// @deprecated 4.1 generer_TRUC_entite
4771
-		or $generer = charger_fonction("generer_${info}_entite", '', true)
4772
-	) {
4773
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4774
-	} // Sinon on prend directement le champ SQL tel quel
4775
-	else {
4776
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4777
-	}
4778
-
4779
-	// On va ensuite appliquer les traitements automatiques si besoin
4780
-	if (!$etoile) {
4781
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4782
-		// mais ce fonctionnement est a ameliorer !
4783
-		$info_generee = appliquer_traitement_champ(
4784
-			$info_generee,
4785
-			$info,
4786
-			table_objet($type_objet),
4787
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4788
-		);
4789
-	}
4790
-
4791
-	return $info_generee;
4697
+    static $trouver_table = null;
4698
+    static $objets;
4699
+
4700
+    // On verifie qu'on a tout ce qu'il faut
4701
+    $id_objet = intval($id_objet);
4702
+    if (!($id_objet and $type_objet and $info)) {
4703
+        return '';
4704
+    }
4705
+
4706
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4707
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4708
+        return '';
4709
+    }
4710
+
4711
+    // Si on demande l'url, on retourne direct la fonction
4712
+    if ($info == 'url') {
4713
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4714
+    }
4715
+
4716
+    // Sinon on va tout chercher dans la table et on garde en memoire
4717
+    $demande_titre = ($info === 'titre');
4718
+    $demande_introduction = ($info === 'introduction');
4719
+
4720
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4721
+    if (
4722
+        !isset($objets[$type_objet][$id_objet])
4723
+        or
4724
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4725
+    ) {
4726
+        if (!$trouver_table) {
4727
+            $trouver_table = charger_fonction('trouver_table', 'base');
4728
+        }
4729
+        $desc = $trouver_table(table_objet_sql($type_objet));
4730
+        if (!$desc) {
4731
+            return $objets[$type_objet] = false;
4732
+        }
4733
+
4734
+        // Si on demande le titre, on le gere en interne
4735
+        $champ_titre = '';
4736
+        if ($demande_titre) {
4737
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4738
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4739
+        }
4740
+        include_spip('base/abstract_sql');
4741
+        include_spip('base/connect_sql');
4742
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4743
+            '*' . $champ_titre,
4744
+            $desc['table_sql'],
4745
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4746
+        );
4747
+
4748
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4749
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4750
+    }
4751
+
4752
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4753
+    // ajouter la longueur au début des params supplémentaires
4754
+    if ($demande_introduction) {
4755
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4756
+        array_unshift($params, $introduction_longueur);
4757
+    }
4758
+
4759
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4760
+    if (
4761
+        $generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4762
+        // @deprecated 4.1 generer_TRUC_TYPE
4763
+        or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4764
+    ) {
4765
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4766
+    }
4767
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4768
+    elseif (
4769
+        $generer = charger_fonction("generer_objet_${info}", '', true)
4770
+        // @deprecated 4.1 generer_TRUC_entite
4771
+        or $generer = charger_fonction("generer_${info}_entite", '', true)
4772
+    ) {
4773
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4774
+    } // Sinon on prend directement le champ SQL tel quel
4775
+    else {
4776
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4777
+    }
4778
+
4779
+    // On va ensuite appliquer les traitements automatiques si besoin
4780
+    if (!$etoile) {
4781
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4782
+        // mais ce fonctionnement est a ameliorer !
4783
+        $info_generee = appliquer_traitement_champ(
4784
+            $info_generee,
4785
+            $info,
4786
+            table_objet($type_objet),
4787
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4788
+        );
4789
+    }
4790
+
4791
+    return $info_generee;
4792 4792
 }
4793 4793
 
4794 4794
 /**
@@ -4796,7 +4796,7 @@  discard block
 block discarded – undo
4796 4796
  * @see generer_objet_info
4797 4797
  */
4798 4798
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4799
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4799
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4800 4800
 }
4801 4801
 
4802 4802
 /**
@@ -4829,36 +4829,36 @@  discard block
 block discarded – undo
4829 4829
  */
4830 4830
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4831 4831
 
4832
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4833
-	$texte = $ligne_sql['texte'] ?? '';
4834
-	// En absence de descriptif, on se rabat sur chapo + texte
4835
-	if (isset($ligne_sql['chapo'])) {
4836
-		$chapo = $ligne_sql['chapo'];
4837
-		$texte = strlen($descriptif) ?
4838
-			'' :
4839
-			"$chapo \n\n $texte";
4840
-	}
4832
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4833
+    $texte = $ligne_sql['texte'] ?? '';
4834
+    // En absence de descriptif, on se rabat sur chapo + texte
4835
+    if (isset($ligne_sql['chapo'])) {
4836
+        $chapo = $ligne_sql['chapo'];
4837
+        $texte = strlen($descriptif) ?
4838
+            '' :
4839
+            "$chapo \n\n $texte";
4840
+    }
4841 4841
 
4842
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4843
-	if (!intval($longueur_ou_suite)) {
4844
-		$longueur = intval($introduction_longueur ?: 600);
4845
-	} else {
4846
-		$longueur = intval($longueur_ou_suite);
4847
-	}
4842
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4843
+    if (!intval($longueur_ou_suite)) {
4844
+        $longueur = intval($introduction_longueur ?: 600);
4845
+    } else {
4846
+        $longueur = intval($longueur_ou_suite);
4847
+    }
4848 4848
 
4849
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4850
-	// Ex : #INTRODUCTION{...}
4851
-	if (
4852
-		is_null($suite)
4853
-		and !intval($longueur_ou_suite)
4854
-	) {
4855
-		$suite = $longueur_ou_suite;
4856
-	}
4849
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4850
+    // Ex : #INTRODUCTION{...}
4851
+    if (
4852
+        is_null($suite)
4853
+        and !intval($longueur_ou_suite)
4854
+    ) {
4855
+        $suite = $longueur_ou_suite;
4856
+    }
4857 4857
 
4858
-	$f = chercher_filtre('introduction');
4859
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4858
+    $f = chercher_filtre('introduction');
4859
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4860 4860
 
4861
-	return $introduction;
4861
+    return $introduction;
4862 4862
 }
4863 4863
 
4864 4864
 /**
@@ -4866,7 +4866,7 @@  discard block
 block discarded – undo
4866 4866
  * @see generer_objet_introduction
4867 4867
  */
4868 4868
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4869
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4869
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4870 4870
 }
4871 4871
 
4872 4872
 /**
@@ -4880,44 +4880,44 @@  discard block
 block discarded – undo
4880 4880
  * @return string
4881 4881
  */
4882 4882
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4883
-	if (!$champ) {
4884
-		return $texte;
4885
-	}
4883
+    if (!$champ) {
4884
+        return $texte;
4885
+    }
4886 4886
 
4887
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4888
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4889
-	include_fichiers_fonctions();
4887
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4888
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4889
+    include_fichiers_fonctions();
4890 4890
 
4891
-	$champ = strtoupper($champ);
4892
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4893
-	if (!$traitements or !is_array($traitements)) {
4894
-		return $texte;
4895
-	}
4891
+    $champ = strtoupper($champ);
4892
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4893
+    if (!$traitements or !is_array($traitements)) {
4894
+        return $texte;
4895
+    }
4896 4896
 
4897
-	$traitement = '';
4898
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4899
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4900
-		$table_objet = table_objet($table_objet);
4901
-		if (isset($traitements[$table_objet])) {
4902
-			$traitement = $traitements[$table_objet];
4903
-		}
4904
-	}
4905
-	if (!$traitement and isset($traitements[0])) {
4906
-		$traitement = $traitements[0];
4907
-	}
4908
-	// (sinon prendre le premier de la liste par defaut ?)
4897
+    $traitement = '';
4898
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4899
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4900
+        $table_objet = table_objet($table_objet);
4901
+        if (isset($traitements[$table_objet])) {
4902
+            $traitement = $traitements[$table_objet];
4903
+        }
4904
+    }
4905
+    if (!$traitement and isset($traitements[0])) {
4906
+        $traitement = $traitements[0];
4907
+    }
4908
+    // (sinon prendre le premier de la liste par defaut ?)
4909 4909
 
4910
-	if (!$traitement) {
4911
-		return $texte;
4912
-	}
4910
+    if (!$traitement) {
4911
+        return $texte;
4912
+    }
4913 4913
 
4914
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4914
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4915 4915
 
4916
-	// Fournir $connect et $Pile[0] au traitement si besoin
4917
-	$Pile = [0 => $env];
4918
-	eval("\$texte = $traitement;");
4916
+    // Fournir $connect et $Pile[0] au traitement si besoin
4917
+    $Pile = [0 => $env];
4918
+    eval("\$texte = $traitement;");
4919 4919
 
4920
-	return $texte;
4920
+    return $texte;
4921 4921
 }
4922 4922
 
4923 4923
 
@@ -4931,21 +4931,21 @@  discard block
 block discarded – undo
4931 4931
  * @return string
4932 4932
  */
4933 4933
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4934
-	include_spip('inc/liens');
4935
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4936
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4937
-	// le raccourcis n'est plus valide
4938
-	$titre = typo($titre['titre']) ?? '';
4939
-	// on essaye avec generer_info_entite ?
4940
-	if (!strlen($titre) and !$connect) {
4941
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4942
-	}
4943
-	if (!strlen($titre)) {
4944
-		$titre = _T('info_sans_titre');
4945
-	}
4946
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4934
+    include_spip('inc/liens');
4935
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4936
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4937
+    // le raccourcis n'est plus valide
4938
+    $titre = typo($titre['titre']) ?? '';
4939
+    // on essaye avec generer_info_entite ?
4940
+    if (!strlen($titre) and !$connect) {
4941
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4942
+    }
4943
+    if (!strlen($titre)) {
4944
+        $titre = _T('info_sans_titre');
4945
+    }
4946
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4947 4947
 
4948
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4948
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4949 4949
 }
4950 4950
 
4951 4951
 /**
@@ -4953,7 +4953,7 @@  discard block
 block discarded – undo
4953 4953
  * @see generer_objet_lien
4954 4954
  */
4955 4955
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4956
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4956
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4957 4957
 }
4958 4958
 
4959 4959
 /**
@@ -4969,15 +4969,15 @@  discard block
 block discarded – undo
4969 4969
  * @return string
4970 4970
  */
4971 4971
 function wrap($texte, $wrap) {
4972
-	$balises = extraire_balises($wrap);
4973
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4974
-		$texte = $wrap . $texte;
4975
-		$regs = array_reverse($regs[1]);
4976
-		$wrap = '</' . implode('></', $regs) . '>';
4977
-		$texte = $texte . $wrap;
4978
-	}
4972
+    $balises = extraire_balises($wrap);
4973
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4974
+        $texte = $wrap . $texte;
4975
+        $regs = array_reverse($regs[1]);
4976
+        $wrap = '</' . implode('></', $regs) . '>';
4977
+        $texte = $texte . $wrap;
4978
+    }
4979 4979
 
4980
-	return $texte;
4980
+    return $texte;
4981 4981
 }
4982 4982
 
4983 4983
 
@@ -4997,44 +4997,44 @@  discard block
 block discarded – undo
4997 4997
  * @return array|mixed|string
4998 4998
  */
4999 4999
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
5000
-	if (is_string($u)) {
5001
-		$u = typo($u);
5000
+    if (is_string($u)) {
5001
+        $u = typo($u);
5002 5002
 
5003
-		return $u;
5004
-	}
5003
+        return $u;
5004
+    }
5005 5005
 
5006
-	// caster $u en array si besoin
5007
-	if (is_object($u)) {
5008
-		$u = (array)$u;
5009
-	}
5006
+    // caster $u en array si besoin
5007
+    if (is_object($u)) {
5008
+        $u = (array)$u;
5009
+    }
5010 5010
 
5011
-	if (is_array($u)) {
5012
-		$out = '';
5013
-		// toutes les cles sont numeriques ?
5014
-		// et aucun enfant n'est un tableau
5015
-		// liste simple separee par des virgules
5016
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5017
-		$array_values = array_map('is_array', $u);
5018
-		$object_values = array_map('is_object', $u);
5019
-		if (
5020
-			array_sum($numeric_keys) == count($numeric_keys)
5021
-			and !array_sum($array_values)
5022
-			and !array_sum($object_values)
5023
-		) {
5024
-			return join(', ', array_map('filtre_print_dist', $u));
5025
-		}
5011
+    if (is_array($u)) {
5012
+        $out = '';
5013
+        // toutes les cles sont numeriques ?
5014
+        // et aucun enfant n'est un tableau
5015
+        // liste simple separee par des virgules
5016
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5017
+        $array_values = array_map('is_array', $u);
5018
+        $object_values = array_map('is_object', $u);
5019
+        if (
5020
+            array_sum($numeric_keys) == count($numeric_keys)
5021
+            and !array_sum($array_values)
5022
+            and !array_sum($object_values)
5023
+        ) {
5024
+            return join(', ', array_map('filtre_print_dist', $u));
5025
+        }
5026 5026
 
5027
-		// sinon on passe a la ligne et on indente
5028
-		$i_str = str_pad('', $indent, ' ');
5029
-		foreach ($u as $k => $v) {
5030
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5031
-		}
5027
+        // sinon on passe a la ligne et on indente
5028
+        $i_str = str_pad('', $indent, ' ');
5029
+        foreach ($u as $k => $v) {
5030
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5031
+        }
5032 5032
 
5033
-		return $out;
5034
-	}
5033
+        return $out;
5034
+    }
5035 5035
 
5036
-	// on sait pas quoi faire...
5037
-	return $u;
5036
+    // on sait pas quoi faire...
5037
+    return $u;
5038 5038
 }
5039 5039
 
5040 5040
 
@@ -5047,10 +5047,10 @@  discard block
 block discarded – undo
5047 5047
  * @return string|array
5048 5048
  */
5049 5049
 function objet_info($objet, $info) {
5050
-	$table = table_objet_sql($objet);
5051
-	$infos = lister_tables_objets_sql($table);
5050
+    $table = table_objet_sql($objet);
5051
+    $infos = lister_tables_objets_sql($table);
5052 5052
 
5053
-	return ($infos[$info] ?? '');
5053
+    return ($infos[$info] ?? '');
5054 5054
 }
5055 5055
 
5056 5056
 /**
@@ -5065,11 +5065,11 @@  discard block
 block discarded – undo
5065 5065
  *     Texte traduit du comptage, tel que '3 articles'
5066 5066
  */
5067 5067
 function objet_afficher_nb($nb, $objet) {
5068
-	if (!$nb) {
5069
-		return _T(objet_info($objet, 'info_aucun_objet'));
5070
-	} else {
5071
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5072
-	}
5068
+    if (!$nb) {
5069
+        return _T(objet_info($objet, 'info_aucun_objet'));
5070
+    } else {
5071
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5072
+    }
5073 5073
 }
5074 5074
 
5075 5075
 /**
@@ -5081,11 +5081,11 @@  discard block
 block discarded – undo
5081 5081
  * @return string
5082 5082
  */
5083 5083
 function objet_icone($objet, $taille = 24, $class = '') {
5084
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5085
-	$icone = chemin_image($icone);
5086
-	$balise_img = charger_filtre('balise_img');
5084
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5085
+    $icone = chemin_image($icone);
5086
+    $balise_img = charger_filtre('balise_img');
5087 5087
 
5088
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5088
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5089 5089
 }
5090 5090
 
5091 5091
 /**
@@ -5106,12 +5106,12 @@  discard block
 block discarded – undo
5106 5106
  * @return string
5107 5107
  */
5108 5108
 function objet_T($objet, $chaine, $args = [], $options = []) {
5109
-	$chaine = explode(':', $chaine);
5110
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5111
-		return $t;
5112
-	}
5113
-	$chaine = implode(':', $chaine);
5114
-	return _T($chaine, $args, $options);
5109
+    $chaine = explode(':', $chaine);
5110
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5111
+        return $t;
5112
+    }
5113
+    $chaine = implode(':', $chaine);
5114
+    return _T($chaine, $args, $options);
5115 5115
 }
5116 5116
 
5117 5117
 /**
@@ -5125,18 +5125,18 @@  discard block
 block discarded – undo
5125 5125
  * @return string      Code HTML
5126 5126
  */
5127 5127
 function insert_head_css_conditionnel($flux) {
5128
-	if (
5129
-		strpos($flux, '<!-- insert_head_css -->') === false
5130
-		and $p = strpos($flux, '<!-- insert_head -->')
5131
-	) {
5132
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5133
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5134
-			$p = $p1;
5135
-		}
5136
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5137
-	}
5128
+    if (
5129
+        strpos($flux, '<!-- insert_head_css -->') === false
5130
+        and $p = strpos($flux, '<!-- insert_head -->')
5131
+    ) {
5132
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5133
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5134
+            $p = $p1;
5135
+        }
5136
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5137
+    }
5138 5138
 
5139
-	return $flux;
5139
+    return $flux;
5140 5140
 }
5141 5141
 
5142 5142
 /**
@@ -5159,72 +5159,72 @@  discard block
 block discarded – undo
5159 5159
  * @return string
5160 5160
  */
5161 5161
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5162
-	if (isset($contexte['format'])) {
5163
-		$extension = $contexte['format'];
5164
-		unset($contexte['format']);
5165
-	} else {
5166
-		$extension = 'html';
5167
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5168
-			$extension = $m[1];
5169
-		}
5170
-	}
5171
-	// recuperer le contenu produit par le squelette
5172
-	$options['raw'] = true;
5173
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5174
-
5175
-	// calculer le nom de la css
5176
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5177
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5178
-	$contexte_implicite = calculer_contexte_implicite();
5179
-
5180
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5181
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5182
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5183
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5184
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5185
-	}
5186
-	else {
5187
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5188
-		ksort($contexte);
5189
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5190
-	}
5191
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5192
-
5193
-	// mettre a jour le fichier si il n'existe pas
5194
-	// ou trop ancien
5195
-	// le dernier fichier produit est toujours suffixe par .last
5196
-	// et recopie sur le fichier cible uniquement si il change
5197
-	if (
5198
-		!file_exists($filename)
5199
-		or !file_exists($filename . '.last')
5200
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5201
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5202
-	) {
5203
-		$contenu = $cache['texte'];
5204
-		// passer les urls en absolu si c'est une css
5205
-		if ($extension == 'css') {
5206
-			$contenu = urls_absolues_css(
5207
-				$contenu,
5208
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5209
-			);
5210
-		}
5211
-
5212
-		$comment = '';
5213
-		// ne pas insérer de commentaire sur certains formats
5214
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5215
-			$comment = "/* #PRODUIRE{fond=$fond";
5216
-			foreach ($contexte as $k => $v) {
5217
-				$comment .= ",$k=$v";
5218
-			}
5219
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5220
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5221
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5222
-		}
5223
-		// et ecrire le fichier si il change
5224
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5225
-	}
5226
-
5227
-	return timestamp($filename);
5162
+    if (isset($contexte['format'])) {
5163
+        $extension = $contexte['format'];
5164
+        unset($contexte['format']);
5165
+    } else {
5166
+        $extension = 'html';
5167
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5168
+            $extension = $m[1];
5169
+        }
5170
+    }
5171
+    // recuperer le contenu produit par le squelette
5172
+    $options['raw'] = true;
5173
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5174
+
5175
+    // calculer le nom de la css
5176
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5177
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5178
+    $contexte_implicite = calculer_contexte_implicite();
5179
+
5180
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5181
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5182
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5183
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5184
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5185
+    }
5186
+    else {
5187
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5188
+        ksort($contexte);
5189
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5190
+    }
5191
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5192
+
5193
+    // mettre a jour le fichier si il n'existe pas
5194
+    // ou trop ancien
5195
+    // le dernier fichier produit est toujours suffixe par .last
5196
+    // et recopie sur le fichier cible uniquement si il change
5197
+    if (
5198
+        !file_exists($filename)
5199
+        or !file_exists($filename . '.last')
5200
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5201
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5202
+    ) {
5203
+        $contenu = $cache['texte'];
5204
+        // passer les urls en absolu si c'est une css
5205
+        if ($extension == 'css') {
5206
+            $contenu = urls_absolues_css(
5207
+                $contenu,
5208
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5209
+            );
5210
+        }
5211
+
5212
+        $comment = '';
5213
+        // ne pas insérer de commentaire sur certains formats
5214
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5215
+            $comment = "/* #PRODUIRE{fond=$fond";
5216
+            foreach ($contexte as $k => $v) {
5217
+                $comment .= ",$k=$v";
5218
+            }
5219
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5220
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5221
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5222
+        }
5223
+        // et ecrire le fichier si il change
5224
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5225
+    }
5226
+
5227
+    return timestamp($filename);
5228 5228
 }
5229 5229
 
5230 5230
 /**
@@ -5237,15 +5237,15 @@  discard block
 block discarded – undo
5237 5237
  *    $fichier auquel on a ajouté le timestamp
5238 5238
  */
5239 5239
 function timestamp($fichier) {
5240
-	if (
5241
-		!$fichier
5242
-		or !file_exists($fichier)
5243
-		or !$m = filemtime($fichier)
5244
-	) {
5245
-		return $fichier;
5246
-	}
5240
+    if (
5241
+        !$fichier
5242
+        or !file_exists($fichier)
5243
+        or !$m = filemtime($fichier)
5244
+    ) {
5245
+        return $fichier;
5246
+    }
5247 5247
 
5248
-	return "$fichier?$m";
5248
+    return "$fichier?$m";
5249 5249
 }
5250 5250
 
5251 5251
 /**
@@ -5255,11 +5255,11 @@  discard block
 block discarded – undo
5255 5255
  * @return string
5256 5256
  */
5257 5257
 function supprimer_timestamp($url) {
5258
-	if (strpos($url, '?') === false) {
5259
-		return $url;
5260
-	}
5258
+    if (strpos($url, '?') === false) {
5259
+        return $url;
5260
+    }
5261 5261
 
5262
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5262
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5263 5263
 }
5264 5264
 
5265 5265
 /**
@@ -5274,9 +5274,9 @@  discard block
 block discarded – undo
5274 5274
  * @return string
5275 5275
  */
5276 5276
 function filtre_nettoyer_titre_email_dist($titre) {
5277
-	include_spip('inc/envoyer_mail');
5277
+    include_spip('inc/envoyer_mail');
5278 5278
 
5279
-	return nettoyer_titre_email($titre);
5279
+    return nettoyer_titre_email($titre);
5280 5280
 }
5281 5281
 
5282 5282
 /**
@@ -5298,27 +5298,27 @@  discard block
 block discarded – undo
5298 5298
  * @return string
5299 5299
  */
5300 5300
 function filtre_chercher_rubrique_dist(
5301
-	$titre,
5302
-	$id_objet,
5303
-	$id_parent,
5304
-	$objet,
5305
-	$id_secteur,
5306
-	$restreint,
5307
-	$actionable = false,
5308
-	$retour_sans_cadre = false
5301
+    $titre,
5302
+    $id_objet,
5303
+    $id_parent,
5304
+    $objet,
5305
+    $id_secteur,
5306
+    $restreint,
5307
+    $actionable = false,
5308
+    $retour_sans_cadre = false
5309 5309
 ) {
5310
-	include_spip('inc/filtres_ecrire');
5310
+    include_spip('inc/filtres_ecrire');
5311 5311
 
5312
-	return chercher_rubrique(
5313
-		$titre,
5314
-		$id_objet,
5315
-		$id_parent,
5316
-		$objet,
5317
-		$id_secteur,
5318
-		$restreint,
5319
-		$actionable,
5320
-		$retour_sans_cadre
5321
-	);
5312
+    return chercher_rubrique(
5313
+        $titre,
5314
+        $id_objet,
5315
+        $id_parent,
5316
+        $objet,
5317
+        $id_secteur,
5318
+        $restreint,
5319
+        $actionable,
5320
+        $retour_sans_cadre
5321
+    );
5322 5322
 }
5323 5323
 
5324 5324
 /**
@@ -5347,56 +5347,56 @@  discard block
 block discarded – undo
5347 5347
  *     Chaîne vide si l'accès est autorisé
5348 5348
  */
5349 5349
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5350
-	if ($ok) {
5351
-		return '';
5352
-	}
5353
-
5354
-	// Vider tous les tampons
5355
-	$level = @ob_get_level();
5356
-	while ($level--) {
5357
-		@ob_end_clean();
5358
-	}
5359
-
5360
-	include_spip('inc/headers');
5361
-
5362
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5363
-	if ($url) {
5364
-		redirige_par_entete($url, '', $statut);
5365
-	}
5366
-
5367
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5368
-	if (!is_numeric($statut) and is_null($message)) {
5369
-		$message = $statut;
5370
-		$statut = 0;
5371
-	}
5372
-	if (!$message) {
5373
-		$message = '';
5374
-	}
5375
-	$statut = intval($statut);
5376
-
5377
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5378
-	if (test_espace_prive()) {
5379
-		if (!$statut or !in_array($statut, [404, 403])) {
5380
-			$statut = 403;
5381
-		}
5382
-		http_response_code(403);
5383
-		$echec = charger_fonction('403', 'exec');
5384
-		$echec($message);
5385
-	} else {
5386
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5387
-		if (!$statut) {
5388
-			$statut = 404;
5389
-		}
5390
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5391
-		http_response_code($statut);
5392
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5393
-		if ($statut >= 400) {
5394
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5395
-		}
5396
-	}
5397
-
5398
-
5399
-	exit;
5350
+    if ($ok) {
5351
+        return '';
5352
+    }
5353
+
5354
+    // Vider tous les tampons
5355
+    $level = @ob_get_level();
5356
+    while ($level--) {
5357
+        @ob_end_clean();
5358
+    }
5359
+
5360
+    include_spip('inc/headers');
5361
+
5362
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5363
+    if ($url) {
5364
+        redirige_par_entete($url, '', $statut);
5365
+    }
5366
+
5367
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5368
+    if (!is_numeric($statut) and is_null($message)) {
5369
+        $message = $statut;
5370
+        $statut = 0;
5371
+    }
5372
+    if (!$message) {
5373
+        $message = '';
5374
+    }
5375
+    $statut = intval($statut);
5376
+
5377
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5378
+    if (test_espace_prive()) {
5379
+        if (!$statut or !in_array($statut, [404, 403])) {
5380
+            $statut = 403;
5381
+        }
5382
+        http_response_code(403);
5383
+        $echec = charger_fonction('403', 'exec');
5384
+        $echec($message);
5385
+    } else {
5386
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5387
+        if (!$statut) {
5388
+            $statut = 404;
5389
+        }
5390
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5391
+        http_response_code($statut);
5392
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5393
+        if ($statut >= 400) {
5394
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5395
+        }
5396
+    }
5397
+
5398
+
5399
+    exit;
5400 5400
 }
5401 5401
 
5402 5402
 /**
@@ -5407,11 +5407,11 @@  discard block
 block discarded – undo
5407 5407
  * @return string
5408 5408
  */
5409 5409
 function filtre_compacte_dist($source, $format = null) {
5410
-	if (function_exists('compacte')) {
5411
-		return compacte($source, $format);
5412
-	}
5410
+    if (function_exists('compacte')) {
5411
+        return compacte($source, $format);
5412
+    }
5413 5413
 
5414
-	return $source;
5414
+    return $source;
5415 5415
 }
5416 5416
 
5417 5417
 
@@ -5423,31 +5423,31 @@  discard block
 block discarded – undo
5423 5423
  * @return string
5424 5424
  */
5425 5425
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5426
-	$l = strlen($passe);
5427
-
5428
-	if ($l <= 8 or !$afficher_partiellement) {
5429
-		if (!$l) {
5430
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5431
-		}
5432
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5433
-	}
5434
-
5435
-	if (is_null($portion_pourcent)) {
5436
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5437
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5438
-		}
5439
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5440
-	}
5441
-	if ($portion_pourcent >= 100) {
5442
-		return $passe;
5443
-	}
5444
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5445
-	$e = max($e, 0);
5446
-	$mid = str_pad('', $l - 2 * $e, '*');
5447
-	if ($e > 0 and strlen($mid) > 8) {
5448
-		$mid = '***...***';
5449
-	}
5450
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5426
+    $l = strlen($passe);
5427
+
5428
+    if ($l <= 8 or !$afficher_partiellement) {
5429
+        if (!$l) {
5430
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5431
+        }
5432
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5433
+    }
5434
+
5435
+    if (is_null($portion_pourcent)) {
5436
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5437
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5438
+        }
5439
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5440
+    }
5441
+    if ($portion_pourcent >= 100) {
5442
+        return $passe;
5443
+    }
5444
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5445
+    $e = max($e, 0);
5446
+    $mid = str_pad('', $l - 2 * $e, '*');
5447
+    if ($e > 0 and strlen($mid) > 8) {
5448
+        $mid = '***...***';
5449
+    }
5450
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5451 5451
 }
5452 5452
 
5453 5453
 
@@ -5468,64 +5468,64 @@  discard block
 block discarded – undo
5468 5468
  */
5469 5469
 function identifiant_slug($texte, $type = '', $options = []) {
5470 5470
 
5471
-	$original = $texte;
5472
-	$separateur = ($options['separateur'] ?? '_');
5473
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5474
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5471
+    $original = $texte;
5472
+    $separateur = ($options['separateur'] ?? '_');
5473
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5474
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5475 5475
 
5476
-	if (!function_exists('translitteration')) {
5477
-		include_spip('inc/charsets');
5478
-	}
5476
+    if (!function_exists('translitteration')) {
5477
+        include_spip('inc/charsets');
5478
+    }
5479 5479
 
5480
-	// pas de balise html
5481
-	if (strpos($texte, '<') !== false) {
5482
-		$texte = strip_tags($texte);
5483
-	}
5484
-	if (strpos($texte, '&') !== false) {
5485
-		$texte = unicode2charset($texte);
5486
-	}
5487
-	// On enlève les espaces indésirables
5488
-	$texte = trim($texte);
5480
+    // pas de balise html
5481
+    if (strpos($texte, '<') !== false) {
5482
+        $texte = strip_tags($texte);
5483
+    }
5484
+    if (strpos($texte, '&') !== false) {
5485
+        $texte = unicode2charset($texte);
5486
+    }
5487
+    // On enlève les espaces indésirables
5488
+    $texte = trim($texte);
5489 5489
 
5490
-	// On enlève les accents et cie
5491
-	$texte = translitteration($texte);
5490
+    // On enlève les accents et cie
5491
+    $texte = translitteration($texte);
5492 5492
 
5493
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5494
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5493
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5494
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5495 5495
 
5496
-	// nettoyer les doubles occurences du separateur si besoin
5497
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5498
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5499
-	}
5496
+    // nettoyer les doubles occurences du separateur si besoin
5497
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5498
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5499
+    }
5500 5500
 
5501
-	// pas de separateur au debut ni a la fin
5502
-	$texte = trim($texte, $separateur);
5501
+    // pas de separateur au debut ni a la fin
5502
+    $texte = trim($texte, $separateur);
5503 5503
 
5504
-	// en minuscules
5505
-	$texte = strtolower($texte);
5504
+    // en minuscules
5505
+    $texte = strtolower($texte);
5506 5506
 
5507
-	switch ($type) {
5508
-		case 'class':
5509
-		case 'id':
5510
-		case 'anchor':
5511
-			if (preg_match(',^\d,', $texte)) {
5512
-				$texte = substr($type, 0, 1) . $texte;
5513
-			}
5514
-	}
5507
+    switch ($type) {
5508
+        case 'class':
5509
+        case 'id':
5510
+        case 'anchor':
5511
+            if (preg_match(',^\d,', $texte)) {
5512
+                $texte = substr($type, 0, 1) . $texte;
5513
+            }
5514
+    }
5515 5515
 
5516
-	if (strlen($texte) > $longueur_maxi) {
5517
-		$texte = substr($texte, 0, $longueur_maxi);
5518
-	}
5516
+    if (strlen($texte) > $longueur_maxi) {
5517
+        $texte = substr($texte, 0, $longueur_maxi);
5518
+    }
5519 5519
 
5520
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5521
-		if (preg_match(',^\d,', $texte)) {
5522
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5523
-		}
5524
-		$texte .= $separateur . md5($original);
5525
-		$texte = substr($texte, 0, $longueur_mini);
5526
-	}
5520
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5521
+        if (preg_match(',^\d,', $texte)) {
5522
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5523
+        }
5524
+        $texte .= $separateur . md5($original);
5525
+        $texte = substr($texte, 0, $longueur_mini);
5526
+    }
5527 5527
 
5528
-	return $texte;
5528
+    return $texte;
5529 5529
 }
5530 5530
 
5531 5531
 
@@ -5546,11 +5546,11 @@  discard block
 block discarded – undo
5546 5546
  * @exemple `<:info_maximum|label_nettoyer:>`
5547 5547
  */
5548 5548
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5549
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5550
-	if ($ucfirst) {
5551
-		$label = spip_ucfirst($label);
5552
-	}
5553
-	return $label;
5549
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5550
+    if ($ucfirst) {
5551
+        $label = spip_ucfirst($label);
5552
+    }
5553
+    return $label;
5554 5554
 }
5555 5555
 
5556 5556
 /**
@@ -5563,8 +5563,8 @@  discard block
 block discarded – undo
5563 5563
  * @exemple `<:info_maximum|label_ponctuer:>`
5564 5564
  */
5565 5565
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5566
-	$label = label_nettoyer($text, $ucfirst);
5567
-	return _T('label_ponctuer', ['label' => $label]);
5566
+    $label = label_nettoyer($text, $ucfirst);
5567
+    return _T('label_ponctuer', ['label' => $label]);
5568 5568
 }
5569 5569
 
5570 5570
 
@@ -5577,19 +5577,19 @@  discard block
 block discarded – undo
5577 5577
  * @return array
5578 5578
  */
5579 5579
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5580
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5581
-		return [];
5582
-	}
5580
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5581
+        return [];
5582
+    }
5583 5583
 
5584
-	// compatibilite signature inversee
5585
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5586
-		[$objet, $id_objet] = [$id_objet, $objet];
5587
-	}
5584
+    // compatibilite signature inversee
5585
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5586
+        [$objet, $id_objet] = [$id_objet, $objet];
5587
+    }
5588 5588
 
5589
-	if (!function_exists($fonction)) {
5590
-		include_spip('base/objets');
5591
-	}
5592
-	return $fonction($objet, $id_objet);
5589
+    if (!function_exists($fonction)) {
5590
+        include_spip('base/objets');
5591
+    }
5592
+    return $fonction($objet, $id_objet);
5593 5593
 }
5594 5594
 
5595 5595
 
@@ -5604,7 +5604,7 @@  discard block
 block discarded – undo
5604 5604
  * @return array
5605 5605
  */
5606 5606
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5607
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5607
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5608 5608
 }
5609 5609
 
5610 5610
 /**
@@ -5618,7 +5618,7 @@  discard block
 block discarded – undo
5618 5618
  * @return array
5619 5619
  */
5620 5620
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5621
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5621
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5622 5622
 }
5623 5623
 
5624 5624
 /**
@@ -5632,7 +5632,7 @@  discard block
 block discarded – undo
5632 5632
  * @return array
5633 5633
  */
5634 5634
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5635
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5635
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5636 5636
 }
5637 5637
 
5638 5638
 /**
@@ -5646,5 +5646,5 @@  discard block
 block discarded – undo
5646 5646
  * @return array
5647 5647
  */
5648 5648
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5649
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5649
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5650 5650
 }
Please login to merge, or discard this patch.