Completed
Push — master ( 3a1501...2ae253 )
by cam
01:52
created
ecrire/public/aiguiller.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -19,158 +19,158 @@  discard block
 block discarded – undo
19 19
  * @return string
20 20
  */
21 21
 function securiser_redirect_action($redirect) {
22
-	$redirect ??= '';
23
-	// cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect
24
-	if (strpos($redirect, '%') !== false) {
25
-		$r2 = urldecode($redirect);
26
-		if (($r3 = securiser_redirect_action($r2)) !== $r2) {
27
-			return $r3;
28
-		}
29
-	}
30
-	if (
31
-		(tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect)))
32
-		and !defined('_AUTORISER_ACTION_ABS_REDIRECT')
33
-	) {
34
-		// si l'url est une url du site, on la laisse passer sans rien faire
35
-		// c'est encore le plus simple
36
-		$base = $GLOBALS['meta']['adresse_site'] . '/';
37
-		if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
38
-			return $redirect;
39
-		}
40
-		$base = url_de_base();
41
-		if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
42
-			return $redirect;
43
-		}
22
+    $redirect ??= '';
23
+    // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect
24
+    if (strpos($redirect, '%') !== false) {
25
+        $r2 = urldecode($redirect);
26
+        if (($r3 = securiser_redirect_action($r2)) !== $r2) {
27
+            return $r3;
28
+        }
29
+    }
30
+    if (
31
+        (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect)))
32
+        and !defined('_AUTORISER_ACTION_ABS_REDIRECT')
33
+    ) {
34
+        // si l'url est une url du site, on la laisse passer sans rien faire
35
+        // c'est encore le plus simple
36
+        $base = $GLOBALS['meta']['adresse_site'] . '/';
37
+        if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
38
+            return $redirect;
39
+        }
40
+        $base = url_de_base();
41
+        if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
42
+            return $redirect;
43
+        }
44 44
 
45
-		return '';
46
-	}
45
+        return '';
46
+    }
47 47
 
48
-	return $redirect;
48
+    return $redirect;
49 49
 }
50 50
 
51 51
 function traiter_appels_actions() {
52
-	// cas de l'appel qui renvoie une redirection (302) ou rien (204)
53
-	if ($action = _request('action')) {
54
-		include_spip('base/abstract_sql'); // chargement systematique pour les actions
55
-		include_spip('inc/autoriser');
56
-		include_spip('inc/headers');
57
-		include_spip('inc/actions');
58
-		// des actions peuvent appeler _T
59
-		if (!isset($GLOBALS['spip_lang'])) {
60
-			include_spip('inc/lang');
61
-			utiliser_langue_visiteur();
62
-		}
63
-		// si l'action est provoque par un hit {ajax}
64
-		// il faut transmettre l'env ajax au redirect
65
-		// on le met avant dans la query string au cas ou l'action fait elle meme sa redirection
66
-		if (
67
-			($v = _request('var_ajax'))
68
-			and ($v !== 'form')
69
-			and ($args = _request('var_ajax_env'))
70
-			and ($url = _request('redirect'))
71
-		) {
72
-			$url = parametre_url($url, 'var_ajax', $v, '&');
73
-			$url = parametre_url($url, 'var_ajax_env', $args, '&');
74
-			set_request('redirect', $url);
75
-		} else {
76
-			if (_request('redirect')) {
77
-				set_request('redirect', securiser_redirect_action(_request('redirect')));
78
-			}
79
-		}
80
-		$var_f = charger_fonction($action, 'action');
81
-		$var_f();
82
-		if (!isset($GLOBALS['redirect'])) {
83
-			$GLOBALS['redirect'] = _request('redirect') ?? '';
84
-			if ($_SERVER['REQUEST_METHOD'] === 'POST') {
85
-				$GLOBALS['redirect'] = urldecode($GLOBALS['redirect']);
86
-			}
87
-			$GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']);
88
-		}
89
-		if ($url = $GLOBALS['redirect']) {
90
-			// si l'action est provoque par un hit {ajax}
91
-			// il faut transmettre l'env ajax au redirect
92
-			// qui a pu etre defini par l'action
93
-			if (
94
-				($v = _request('var_ajax'))
95
-				and ($v !== 'form')
96
-				and ($args = _request('var_ajax_env'))
97
-			) {
98
-				$url = parametre_url($url, 'var_ajax', $v, '&');
99
-				$url = parametre_url($url, 'var_ajax_env', $args, '&');
100
-				// passer l'ancre en variable pour pouvoir la gerer cote serveur
101
-				$url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url);
102
-			}
103
-			$url = str_replace('&', '&', $url); // les redirections se font en &, pas en en &
104
-			redirige_par_entete($url);
105
-		}
52
+    // cas de l'appel qui renvoie une redirection (302) ou rien (204)
53
+    if ($action = _request('action')) {
54
+        include_spip('base/abstract_sql'); // chargement systematique pour les actions
55
+        include_spip('inc/autoriser');
56
+        include_spip('inc/headers');
57
+        include_spip('inc/actions');
58
+        // des actions peuvent appeler _T
59
+        if (!isset($GLOBALS['spip_lang'])) {
60
+            include_spip('inc/lang');
61
+            utiliser_langue_visiteur();
62
+        }
63
+        // si l'action est provoque par un hit {ajax}
64
+        // il faut transmettre l'env ajax au redirect
65
+        // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection
66
+        if (
67
+            ($v = _request('var_ajax'))
68
+            and ($v !== 'form')
69
+            and ($args = _request('var_ajax_env'))
70
+            and ($url = _request('redirect'))
71
+        ) {
72
+            $url = parametre_url($url, 'var_ajax', $v, '&');
73
+            $url = parametre_url($url, 'var_ajax_env', $args, '&');
74
+            set_request('redirect', $url);
75
+        } else {
76
+            if (_request('redirect')) {
77
+                set_request('redirect', securiser_redirect_action(_request('redirect')));
78
+            }
79
+        }
80
+        $var_f = charger_fonction($action, 'action');
81
+        $var_f();
82
+        if (!isset($GLOBALS['redirect'])) {
83
+            $GLOBALS['redirect'] = _request('redirect') ?? '';
84
+            if ($_SERVER['REQUEST_METHOD'] === 'POST') {
85
+                $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']);
86
+            }
87
+            $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']);
88
+        }
89
+        if ($url = $GLOBALS['redirect']) {
90
+            // si l'action est provoque par un hit {ajax}
91
+            // il faut transmettre l'env ajax au redirect
92
+            // qui a pu etre defini par l'action
93
+            if (
94
+                ($v = _request('var_ajax'))
95
+                and ($v !== 'form')
96
+                and ($args = _request('var_ajax_env'))
97
+            ) {
98
+                $url = parametre_url($url, 'var_ajax', $v, '&');
99
+                $url = parametre_url($url, 'var_ajax_env', $args, '&');
100
+                // passer l'ancre en variable pour pouvoir la gerer cote serveur
101
+                $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url);
102
+            }
103
+            $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en &
104
+            redirige_par_entete($url);
105
+        }
106 106
 
107
-		// attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0
108
-		// et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment)
109
-		if (
110
-			!headers_sent()
111
-			and !ob_get_length()
112
-		) {
113
-			http_status(204);
114
-		} // No Content
115
-		return true;
116
-	}
107
+        // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0
108
+        // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment)
109
+        if (
110
+            !headers_sent()
111
+            and !ob_get_length()
112
+        ) {
113
+            http_status(204);
114
+        } // No Content
115
+        return true;
116
+    }
117 117
 
118
-	return false;
118
+    return false;
119 119
 }
120 120
 
121 121
 
122 122
 function refuser_traiter_formulaire_ajax() {
123
-	if (
124
-		$v = _request('var_ajax')
125
-		and $v == 'form'
126
-		and $form = _request('formulaire_action')
127
-		and $args = _request('formulaire_action_args')
128
-		and decoder_contexte_ajax($args, $form) !== false
129
-	) {
130
-		// on est bien dans le contexte de traitement d'un formulaire en ajax
131
-		// mais traiter ne veut pas
132
-		// on le dit a la page qui va resumbit
133
-		// sans ajax
134
-		include_spip('inc/actions');
135
-		ajax_retour('noajax', false);
136
-		exit;
137
-	}
123
+    if (
124
+        $v = _request('var_ajax')
125
+        and $v == 'form'
126
+        and $form = _request('formulaire_action')
127
+        and $args = _request('formulaire_action_args')
128
+        and decoder_contexte_ajax($args, $form) !== false
129
+    ) {
130
+        // on est bien dans le contexte de traitement d'un formulaire en ajax
131
+        // mais traiter ne veut pas
132
+        // on le dit a la page qui va resumbit
133
+        // sans ajax
134
+        include_spip('inc/actions');
135
+        ajax_retour('noajax', false);
136
+        exit;
137
+    }
138 138
 }
139 139
 
140 140
 function traiter_appels_inclusions_ajax() {
141
-	// traiter les appels de bloc ajax (ex: pagination)
142
-	if (
143
-		$v = _request('var_ajax')
144
-		and $v !== 'form'
145
-		and $args = _request('var_ajax_env')
146
-	) {
147
-		include_spip('inc/filtres');
148
-		include_spip('inc/actions');
149
-		if (
150
-			$args = decoder_contexte_ajax($args)
151
-			and $fond = $args['fond']
152
-		) {
153
-			include_spip('public/assembler');
154
-			$contexte = calculer_contexte();
155
-			$contexte = array_merge($args, $contexte);
156
-			$page = recuperer_fond($fond, $contexte, ['trim' => false]);
157
-			$texte = $page;
158
-			if ($ancre = _request('var_ajax_ancre')) {
159
-				// pas n'importe quoi quand meme dans la variable !
160
-				$ancre = str_replace(['<', '"', "'"], ['&lt;', '&quot;', ''], $ancre);
161
-				$texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte;
162
-			}
163
-		} else {
164
-			include_spip('inc/headers');
165
-			http_response_code(400);
166
-			$texte = _L('signature ajax bloc incorrecte');
167
-		}
168
-		ajax_retour($texte, false);
141
+    // traiter les appels de bloc ajax (ex: pagination)
142
+    if (
143
+        $v = _request('var_ajax')
144
+        and $v !== 'form'
145
+        and $args = _request('var_ajax_env')
146
+    ) {
147
+        include_spip('inc/filtres');
148
+        include_spip('inc/actions');
149
+        if (
150
+            $args = decoder_contexte_ajax($args)
151
+            and $fond = $args['fond']
152
+        ) {
153
+            include_spip('public/assembler');
154
+            $contexte = calculer_contexte();
155
+            $contexte = array_merge($args, $contexte);
156
+            $page = recuperer_fond($fond, $contexte, ['trim' => false]);
157
+            $texte = $page;
158
+            if ($ancre = _request('var_ajax_ancre')) {
159
+                // pas n'importe quoi quand meme dans la variable !
160
+                $ancre = str_replace(['<', '"', "'"], ['&lt;', '&quot;', ''], $ancre);
161
+                $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte;
162
+            }
163
+        } else {
164
+            include_spip('inc/headers');
165
+            http_response_code(400);
166
+            $texte = _L('signature ajax bloc incorrecte');
167
+        }
168
+        ajax_retour($texte, false);
169 169
 
170
-		return true; // on a fini le hit
171
-	}
170
+        return true; // on a fini le hit
171
+    }
172 172
 
173
-	return false;
173
+    return false;
174 174
 }
175 175
 
176 176
 // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter
@@ -178,173 +178,173 @@  discard block
 block discarded – undo
178 178
 // Le 1er renvoie True si il faut faire exit a la sortie
179 179
 
180 180
 function traiter_formulaires_dynamiques($get = false) {
181
-	static $post = [];
182
-	static $done = false;
181
+    static $post = [];
182
+    static $done = false;
183 183
 
184
-	if ($get) {
185
-		return $post;
186
-	}
187
-	if ($done) {
188
-		return false;
189
-	}
190
-	$done = true;
184
+    if ($get) {
185
+        return $post;
186
+    }
187
+    if ($done) {
188
+        return false;
189
+    }
190
+    $done = true;
191 191
 
192
-	if (
193
-		!($form = _request('formulaire_action')
194
-		and $args = _request('formulaire_action_args'))
195
-	) {
196
-		return false;
197
-	} // le hit peut continuer normalement
192
+    if (
193
+        !($form = _request('formulaire_action')
194
+        and $args = _request('formulaire_action_args'))
195
+    ) {
196
+        return false;
197
+    } // le hit peut continuer normalement
198 198
 
199
-	// verifier que le post est licite (du meme auteur ou d'une session anonyme)
200
-	$sign = _request('formulaire_action_sign');
201
-	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
202
-		if (empty($sign)) {
203
-			spip_log("signature ajax form incorrecte : $form (formulaire non signe mais on a une session)", 'formulaires' . _LOG_ERREUR);
204
-			return false;
205
-		}
206
-		$securiser_action = charger_fonction('securiser_action', 'inc');
207
-		$secu = $securiser_action($form, $args, '', -1);
208
-		if ($sign !== $secu['hash']) {
209
-			spip_log("signature ajax form incorrecte : $form (formulaire signe mais ne correspond pas a la session)", 'formulaires' . _LOG_ERREUR);
210
-			return false;
211
-		}
212
-	}
213
-	else {
214
-		if (!empty($sign)) {
215
-			spip_log("signature ajax form incorrecte : $form (formulaire signe mais pas de session)", 'formulaires' . _LOG_ERREUR);
216
-			return false;
217
-		}
218
-	}
199
+    // verifier que le post est licite (du meme auteur ou d'une session anonyme)
200
+    $sign = _request('formulaire_action_sign');
201
+    if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
202
+        if (empty($sign)) {
203
+            spip_log("signature ajax form incorrecte : $form (formulaire non signe mais on a une session)", 'formulaires' . _LOG_ERREUR);
204
+            return false;
205
+        }
206
+        $securiser_action = charger_fonction('securiser_action', 'inc');
207
+        $secu = $securiser_action($form, $args, '', -1);
208
+        if ($sign !== $secu['hash']) {
209
+            spip_log("signature ajax form incorrecte : $form (formulaire signe mais ne correspond pas a la session)", 'formulaires' . _LOG_ERREUR);
210
+            return false;
211
+        }
212
+    }
213
+    else {
214
+        if (!empty($sign)) {
215
+            spip_log("signature ajax form incorrecte : $form (formulaire signe mais pas de session)", 'formulaires' . _LOG_ERREUR);
216
+            return false;
217
+        }
218
+    }
219 219
 
220
-	include_spip('inc/filtres');
221
-	if (($args = decoder_contexte_ajax($args, $form)) === false) {
222
-		spip_log("signature ajax form incorrecte : $form (encodage corrompu)", 'formulaires' . _LOG_ERREUR);
220
+    include_spip('inc/filtres');
221
+    if (($args = decoder_contexte_ajax($args, $form)) === false) {
222
+        spip_log("signature ajax form incorrecte : $form (encodage corrompu)", 'formulaires' . _LOG_ERREUR);
223 223
 
224
-		return false; // continuons le hit comme si de rien etait
225
-	} else {
226
-		include_spip('inc/lang');
227
-		// sauvegarder la lang en cours
228
-		$old_lang = $GLOBALS['spip_lang'];
229
-		// changer la langue avec celle qui a cours dans le formulaire
230
-		// on la depile de $args car c'est un argument implicite masque
231
-		changer_langue(array_shift($args));
224
+        return false; // continuons le hit comme si de rien etait
225
+    } else {
226
+        include_spip('inc/lang');
227
+        // sauvegarder la lang en cours
228
+        $old_lang = $GLOBALS['spip_lang'];
229
+        // changer la langue avec celle qui a cours dans le formulaire
230
+        // on la depile de $args car c'est un argument implicite masque
231
+        changer_langue(array_shift($args));
232 232
 
233 233
 
234
-		// inclure mes_fonctions et autres filtres avant verifier/traiter
235
-		include_fichiers_fonctions();
236
-		// ainsi que l'API SQL bien utile dans verifier/traiter
237
-		include_spip('base/abstract_sql');
234
+        // inclure mes_fonctions et autres filtres avant verifier/traiter
235
+        include_fichiers_fonctions();
236
+        // ainsi que l'API SQL bien utile dans verifier/traiter
237
+        include_spip('base/abstract_sql');
238 238
 
239
-		/**
240
-		 * Pipeline exécuté lors de la soumission d'un formulaire,
241
-		 * mais avant l'appel de la fonction de vérification.
242
-		 */
243
-		pipeline(
244
-			'formulaire_receptionner',
245
-			[
246
-				'args' => ['form' => $form, 'args' => $args],
247
-				'data' => null,
248
-			]
249
-		);
239
+        /**
240
+         * Pipeline exécuté lors de la soumission d'un formulaire,
241
+         * mais avant l'appel de la fonction de vérification.
242
+         */
243
+        pipeline(
244
+            'formulaire_receptionner',
245
+            [
246
+                'args' => ['form' => $form, 'args' => $args],
247
+                'data' => null,
248
+            ]
249
+        );
250 250
 
251
-		$verifier = charger_fonction('verifier', "formulaires/$form/", true);
252
-		$post["erreurs_$form"] = pipeline(
253
-			'formulaire_verifier',
254
-			[
255
-				'args' => ['form' => $form, 'args' => $args],
256
-				'data' => $verifier ? call_user_func_array($verifier, $args) : []
257
-			]
258
-		);
259
-		// prise en charge CVT multi etape si besoin
260
-		if (_request('cvtm_prev_post')) {
261
-			include_spip('inc/cvt_multietapes');
262
-			$post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes(
263
-				['form' => $form, 'args' => $args],
264
-				$post["erreurs_$form"]
265
-			);
266
-		}
251
+        $verifier = charger_fonction('verifier', "formulaires/$form/", true);
252
+        $post["erreurs_$form"] = pipeline(
253
+            'formulaire_verifier',
254
+            [
255
+                'args' => ['form' => $form, 'args' => $args],
256
+                'data' => $verifier ? call_user_func_array($verifier, $args) : []
257
+            ]
258
+        );
259
+        // prise en charge CVT multi etape si besoin
260
+        if (_request('cvtm_prev_post')) {
261
+            include_spip('inc/cvt_multietapes');
262
+            $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes(
263
+                ['form' => $form, 'args' => $args],
264
+                $post["erreurs_$form"]
265
+            );
266
+        }
267 267
 
268
-		// accessibilite : si des erreurs mais pas de message general l'ajouter
269
-		if ((isset($post["erreurs_$form"]) and is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) and !isset($post["erreurs_$form"]['message_erreur'])) {
270
-			$post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(
271
-				is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0,
272
-				'avis_1_erreur_saisie',
273
-				'avis_nb_erreurs_saisie'
274
-			);
275
-		}
268
+        // accessibilite : si des erreurs mais pas de message general l'ajouter
269
+        if ((isset($post["erreurs_$form"]) and is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) and !isset($post["erreurs_$form"]['message_erreur'])) {
270
+            $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(
271
+                is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0,
272
+                'avis_1_erreur_saisie',
273
+                'avis_nb_erreurs_saisie'
274
+            );
275
+        }
276 276
 
277
-		// si on ne demandait qu'une verif json
278
-		if (_request('formulaire_action_verifier_json')) {
279
-			include_spip('inc/json');
280
-			include_spip('inc/actions');
281
-			ajax_retour(json_encode($post["erreurs_$form"], JSON_THROW_ON_ERROR), 'text/plain');
277
+        // si on ne demandait qu'une verif json
278
+        if (_request('formulaire_action_verifier_json')) {
279
+            include_spip('inc/json');
280
+            include_spip('inc/actions');
281
+            ajax_retour(json_encode($post["erreurs_$form"], JSON_THROW_ON_ERROR), 'text/plain');
282 282
 
283
-			return true; // on a fini le hit
284
-		}
285
-		$retour = '';
286
-		if (isset($post["erreurs_$form"]) and ((is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) == 0)) {
287
-			$rev = '';
288
-			if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) {
289
-				$rev = call_user_func_array($traiter, $args);
290
-			}
283
+            return true; // on a fini le hit
284
+        }
285
+        $retour = '';
286
+        if (isset($post["erreurs_$form"]) and ((is_countable($post["erreurs_$form"]) ? count($post["erreurs_$form"]) : 0) == 0)) {
287
+            $rev = '';
288
+            if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) {
289
+                $rev = call_user_func_array($traiter, $args);
290
+            }
291 291
 
292
-			$rev = pipeline(
293
-				'formulaire_traiter',
294
-				[
295
-					'args' => ['form' => $form, 'args' => $args],
296
-					'data' => $rev
297
-				]
298
-			);
299
-			// le retour de traiter est
300
-			// un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx)
301
-			// il permet le pipelinage, en particulier
302
-			// en y passant l'id de l'objet cree/modifie
303
-			// si message_erreur est present, on considere que le traitement a echoue
304
-			$post["message_ok_$form"] = '';
305
-			// on peut avoir message_ok et message_erreur
306
-			if (isset($rev['message_ok'])) {
307
-				$post["message_ok_$form"] = $rev['message_ok'];
308
-			}
292
+            $rev = pipeline(
293
+                'formulaire_traiter',
294
+                [
295
+                    'args' => ['form' => $form, 'args' => $args],
296
+                    'data' => $rev
297
+                ]
298
+            );
299
+            // le retour de traiter est
300
+            // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx)
301
+            // il permet le pipelinage, en particulier
302
+            // en y passant l'id de l'objet cree/modifie
303
+            // si message_erreur est present, on considere que le traitement a echoue
304
+            $post["message_ok_$form"] = '';
305
+            // on peut avoir message_ok et message_erreur
306
+            if (isset($rev['message_ok'])) {
307
+                $post["message_ok_$form"] = $rev['message_ok'];
308
+            }
309 309
 
310
-			// verifier si traiter n'a pas echoue avec une erreur :
311
-			if (isset($rev['message_erreur'])) {
312
-				$post["erreurs_$form"]['message_erreur'] = $rev['message_erreur'];
313
-				// si il y a une erreur on ne redirige pas
314
-			} else {
315
-				// sinon faire ce qu'il faut :
316
-				if (isset($rev['editable'])) {
317
-					$post["editable_$form"] = $rev['editable'];
318
-				}
319
-				// si une redirection est demandee, appeler redirigae_formulaire qui choisira
320
-				// le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue)
321
-				if (isset($rev['redirect']) and $rev['redirect']) {
322
-					include_spip('inc/headers');
323
-					[$masque, $message] = redirige_formulaire($rev['redirect'], '', 'ajaxform');
324
-					$post["message_ok_$form"] .= $message;
325
-					$retour .= $masque;
326
-				}
327
-			}
328
-		}
329
-		// si le formulaire a ete soumis en ajax, on le renvoie direct !
330
-		if (_request('var_ajax')) {
331
-			if (find_in_path('formulaire_.php', 'balise/', true)) {
332
-				include_spip('inc/actions');
333
-				include_spip('public/assembler');
334
-				array_unshift($args, $form);
335
-				$retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false);
336
-				// on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
337
-				// sans cela le formulaire n'est pas actif apres le hit ajax
338
-				// la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
339
-				$retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
340
-				ajax_retour($retour, false);
310
+            // verifier si traiter n'a pas echoue avec une erreur :
311
+            if (isset($rev['message_erreur'])) {
312
+                $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur'];
313
+                // si il y a une erreur on ne redirige pas
314
+            } else {
315
+                // sinon faire ce qu'il faut :
316
+                if (isset($rev['editable'])) {
317
+                    $post["editable_$form"] = $rev['editable'];
318
+                }
319
+                // si une redirection est demandee, appeler redirigae_formulaire qui choisira
320
+                // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue)
321
+                if (isset($rev['redirect']) and $rev['redirect']) {
322
+                    include_spip('inc/headers');
323
+                    [$masque, $message] = redirige_formulaire($rev['redirect'], '', 'ajaxform');
324
+                    $post["message_ok_$form"] .= $message;
325
+                    $retour .= $masque;
326
+                }
327
+            }
328
+        }
329
+        // si le formulaire a ete soumis en ajax, on le renvoie direct !
330
+        if (_request('var_ajax')) {
331
+            if (find_in_path('formulaire_.php', 'balise/', true)) {
332
+                include_spip('inc/actions');
333
+                include_spip('public/assembler');
334
+                array_unshift($args, $form);
335
+                $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false);
336
+                // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
337
+                // sans cela le formulaire n'est pas actif apres le hit ajax
338
+                // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
339
+                $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
340
+                ajax_retour($retour, false);
341 341
 
342
-				return true; // on a fini le hit
343
-			}
344
-		}
345
-		// restaurer la lang en cours
346
-		changer_langue($old_lang);
347
-	}
342
+                return true; // on a fini le hit
343
+            }
344
+        }
345
+        // restaurer la lang en cours
346
+        changer_langue($old_lang);
347
+    }
348 348
 
349
-	return false; // le hit peut continuer normalement
349
+    return false; // le hit peut continuer normalement
350 350
 }
Please login to merge, or discard this patch.
ecrire/inc/distant.php 2 patches
Indentation   +1053 added lines, -1053 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2_097_152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		($GLOBALS['meta']['adresse_site'] ?? '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        ($GLOBALS['meta']['adresse_site'] ?? '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,89 +68,89 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode === 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode === 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local === $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode === 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
119
-		}
120
-		else {
121
-			spip_log("copie_locale : recuperation $source sur $localrac OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
122
-		}
123
-		if (!$res or !$res['length']) {
124
-			// si $t c'est sans doute juste un not-modified-since
125
-			return $t ? $local : false;
126
-		}
127
-
128
-		// si on retrouve l'extension
129
-		if (
130
-			!empty($res['headers'])
131
-			and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
132
-		) {
133
-			if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
134
-				$sanitizer($localrac);
135
-			}
136
-		}
137
-
138
-		// pour une eventuelle indexation
139
-		pipeline(
140
-			'post_edition',
141
-			[
142
-				'args' => [
143
-					'operation' => 'copie_locale',
144
-					'source' => $source,
145
-					'fichier' => $local,
146
-					'http_res' => $res['length'],
147
-				],
148
-				'data' => null
149
-			]
150
-		);
151
-	}
152
-
153
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode === 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode === 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local === $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode === 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
119
+        }
120
+        else {
121
+            spip_log("copie_locale : recuperation $source sur $localrac OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
122
+        }
123
+        if (!$res or !$res['length']) {
124
+            // si $t c'est sans doute juste un not-modified-since
125
+            return $t ? $local : false;
126
+        }
127
+
128
+        // si on retrouve l'extension
129
+        if (
130
+            !empty($res['headers'])
131
+            and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])
132
+        ) {
133
+            if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
134
+                $sanitizer($localrac);
135
+            }
136
+        }
137
+
138
+        // pour une eventuelle indexation
139
+        pipeline(
140
+            'post_edition',
141
+            [
142
+                'args' => [
143
+                    'operation' => 'copie_locale',
144
+                    'source' => $source,
145
+                    'fichier' => $local,
146
+                    'http_res' => $res['length'],
147
+                ],
148
+                'data' => null
149
+            ]
150
+        );
151
+    }
152
+
153
+    return $local;
154 154
 }
155 155
 
156 156
 /**
@@ -165,99 +165,99 @@  discard block
 block discarded – undo
165 165
  *   url ou false en cas d'echec
166 166
  */
167 167
 function valider_url_distante($url, $known_hosts = []) {
168
-	if (!function_exists('protocole_verifier')) {
169
-		include_spip('inc/filtres_mini');
170
-	}
171
-
172
-	if (!protocole_verifier($url, ['http', 'https'])) {
173
-		return false;
174
-	}
175
-
176
-	$parsed_url = parse_url($url);
177
-	if (!$parsed_url or empty($parsed_url['host'])) {
178
-		return false;
179
-	}
180
-
181
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
182
-		return false;
183
-	}
184
-
185
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
186
-		return false;
187
-	}
188
-
189
-	if (!is_array($known_hosts)) {
190
-		$known_hosts = [$known_hosts];
191
-	}
192
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
193
-	$known_hosts[] = url_de_base();
194
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
195
-
196
-	$is_known_host = false;
197
-	foreach ($known_hosts as $known_host) {
198
-		$parse_known = parse_url($known_host);
199
-		if (
200
-			$parse_known
201
-			and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
202
-		) {
203
-			$is_known_host = true;
204
-			break;
205
-		}
206
-	}
207
-
208
-	if (!$is_known_host) {
209
-		$host = trim($parsed_url['host'], '.');
210
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
211
-			$ip = gethostbyname($host);
212
-			if ($ip === $host) {
213
-				// Error condition for gethostbyname()
214
-				$ip = false;
215
-			}
216
-			if ($records = dns_get_record($host)) {
217
-				foreach ($records as $record) {
218
-					// il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
219
-					// se fasse sur la meme IP
220
-					if ($record['ttl'] < 10) {
221
-						$ip = false;
222
-						break;
223
-					}
224
-				}
225
-			}
226
-			else {
227
-				$ip = false;
228
-			}
229
-		}
230
-		if ($ip) {
231
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
232
-				return false;
233
-			}
234
-		}
235
-	}
236
-
237
-	if (empty($parsed_url['port'])) {
238
-		return $url;
239
-	}
240
-
241
-	$port = $parsed_url['port'];
242
-	if ($port === 80  or $port === 443  or $port === 8080) {
243
-		return $url;
244
-	}
245
-
246
-	if ($is_known_host) {
247
-		foreach ($known_hosts as $known_host) {
248
-			$parse_known = parse_url($known_host);
249
-			if (
250
-				$parse_known
251
-				and !empty($parse_known['port'])
252
-				and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
253
-				and $parse_known['port'] == $port
254
-			) {
255
-				return $url;
256
-			}
257
-		}
258
-	}
259
-
260
-	return false;
168
+    if (!function_exists('protocole_verifier')) {
169
+        include_spip('inc/filtres_mini');
170
+    }
171
+
172
+    if (!protocole_verifier($url, ['http', 'https'])) {
173
+        return false;
174
+    }
175
+
176
+    $parsed_url = parse_url($url);
177
+    if (!$parsed_url or empty($parsed_url['host'])) {
178
+        return false;
179
+    }
180
+
181
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
182
+        return false;
183
+    }
184
+
185
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
186
+        return false;
187
+    }
188
+
189
+    if (!is_array($known_hosts)) {
190
+        $known_hosts = [$known_hosts];
191
+    }
192
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
193
+    $known_hosts[] = url_de_base();
194
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
195
+
196
+    $is_known_host = false;
197
+    foreach ($known_hosts as $known_host) {
198
+        $parse_known = parse_url($known_host);
199
+        if (
200
+            $parse_known
201
+            and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
202
+        ) {
203
+            $is_known_host = true;
204
+            break;
205
+        }
206
+    }
207
+
208
+    if (!$is_known_host) {
209
+        $host = trim($parsed_url['host'], '.');
210
+        if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
211
+            $ip = gethostbyname($host);
212
+            if ($ip === $host) {
213
+                // Error condition for gethostbyname()
214
+                $ip = false;
215
+            }
216
+            if ($records = dns_get_record($host)) {
217
+                foreach ($records as $record) {
218
+                    // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit
219
+                    // se fasse sur la meme IP
220
+                    if ($record['ttl'] < 10) {
221
+                        $ip = false;
222
+                        break;
223
+                    }
224
+                }
225
+            }
226
+            else {
227
+                $ip = false;
228
+            }
229
+        }
230
+        if ($ip) {
231
+            if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
232
+                return false;
233
+            }
234
+        }
235
+    }
236
+
237
+    if (empty($parsed_url['port'])) {
238
+        return $url;
239
+    }
240
+
241
+    $port = $parsed_url['port'];
242
+    if ($port === 80  or $port === 443  or $port === 8080) {
243
+        return $url;
244
+    }
245
+
246
+    if ($is_known_host) {
247
+        foreach ($known_hosts as $known_host) {
248
+            $parse_known = parse_url($known_host);
249
+            if (
250
+                $parse_known
251
+                and !empty($parse_known['port'])
252
+                and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
253
+                and $parse_known['port'] == $port
254
+            ) {
255
+                return $url;
256
+            }
257
+        }
258
+    }
259
+
260
+    return false;
261 261
 }
262 262
 
263 263
 /**
@@ -277,86 +277,86 @@  discard block
 block discarded – undo
277 277
  */
278 278
 function prepare_donnees_post($donnees, $boundary = '') {
279 279
 
280
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
281
-	// pour un appel soap par exemple
282
-	// l'entete est separe des donnees par un double retour a la ligne
283
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
284
-	if (is_string($donnees) && strlen($donnees)) {
285
-		$entete = '';
286
-		// on repasse tous les \r\n et \r en simples \n
287
-		$donnees = str_replace("\r\n", "\n", $donnees);
288
-		$donnees = str_replace("\r", "\n", $donnees);
289
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
290
-		$p = strpos($donnees, "\n\n");
291
-		if ($p !== false) {
292
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
293
-			$donnees = substr($donnees, $p + 2);
294
-		}
295
-		$chaine = str_replace("\n", "\r\n", $donnees);
296
-	} else {
297
-		/* boundary automatique */
298
-		// Si on a plus de 500 octects de donnees, on "boundarise"
299
-		if ($boundary === '') {
300
-			$taille = 0;
301
-			foreach ($donnees as $cle => $valeur) {
302
-				if (is_array($valeur)) {
303
-					foreach ($valeur as $val2) {
304
-						$taille += strlen($val2);
305
-					}
306
-				} else {
307
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
308
-					$taille += strlen($valeur);
309
-				}
310
-			}
311
-			if ($taille > 500) {
312
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
313
-			}
314
-		}
315
-
316
-		if (is_string($boundary) and strlen($boundary)) {
317
-			// fabrique une chaine HTTP pour un POST avec boundary
318
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
319
-			$chaine = '';
320
-			if (is_array($donnees)) {
321
-				foreach ($donnees as $cle => $valeur) {
322
-					if (is_array($valeur)) {
323
-						foreach ($valeur as $val2) {
324
-							$chaine .= "\r\n--$boundary\r\n";
325
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
326
-							$chaine .= "\r\n";
327
-							$chaine .= $val2;
328
-						}
329
-					} else {
330
-						$chaine .= "\r\n--$boundary\r\n";
331
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
332
-						$chaine .= "\r\n";
333
-						$chaine .= $valeur;
334
-					}
335
-				}
336
-				$chaine .= "\r\n--$boundary\r\n";
337
-			}
338
-		} else {
339
-			// fabrique une chaine HTTP simple pour un POST
340
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
341
-			$chaine = [];
342
-			if (is_array($donnees)) {
343
-				foreach ($donnees as $cle => $valeur) {
344
-					if (is_array($valeur)) {
345
-						foreach ($valeur as $val2) {
346
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
347
-						}
348
-					} else {
349
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
350
-					}
351
-				}
352
-				$chaine = implode('&', $chaine);
353
-			} else {
354
-				$chaine = $donnees;
355
-			}
356
-		}
357
-	}
358
-
359
-	return [$entete, $chaine];
280
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
281
+    // pour un appel soap par exemple
282
+    // l'entete est separe des donnees par un double retour a la ligne
283
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
284
+    if (is_string($donnees) && strlen($donnees)) {
285
+        $entete = '';
286
+        // on repasse tous les \r\n et \r en simples \n
287
+        $donnees = str_replace("\r\n", "\n", $donnees);
288
+        $donnees = str_replace("\r", "\n", $donnees);
289
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
290
+        $p = strpos($donnees, "\n\n");
291
+        if ($p !== false) {
292
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
293
+            $donnees = substr($donnees, $p + 2);
294
+        }
295
+        $chaine = str_replace("\n", "\r\n", $donnees);
296
+    } else {
297
+        /* boundary automatique */
298
+        // Si on a plus de 500 octects de donnees, on "boundarise"
299
+        if ($boundary === '') {
300
+            $taille = 0;
301
+            foreach ($donnees as $cle => $valeur) {
302
+                if (is_array($valeur)) {
303
+                    foreach ($valeur as $val2) {
304
+                        $taille += strlen($val2);
305
+                    }
306
+                } else {
307
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
308
+                    $taille += strlen($valeur);
309
+                }
310
+            }
311
+            if ($taille > 500) {
312
+                $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
313
+            }
314
+        }
315
+
316
+        if (is_string($boundary) and strlen($boundary)) {
317
+            // fabrique une chaine HTTP pour un POST avec boundary
318
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
319
+            $chaine = '';
320
+            if (is_array($donnees)) {
321
+                foreach ($donnees as $cle => $valeur) {
322
+                    if (is_array($valeur)) {
323
+                        foreach ($valeur as $val2) {
324
+                            $chaine .= "\r\n--$boundary\r\n";
325
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
326
+                            $chaine .= "\r\n";
327
+                            $chaine .= $val2;
328
+                        }
329
+                    } else {
330
+                        $chaine .= "\r\n--$boundary\r\n";
331
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
332
+                        $chaine .= "\r\n";
333
+                        $chaine .= $valeur;
334
+                    }
335
+                }
336
+                $chaine .= "\r\n--$boundary\r\n";
337
+            }
338
+        } else {
339
+            // fabrique une chaine HTTP simple pour un POST
340
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
341
+            $chaine = [];
342
+            if (is_array($donnees)) {
343
+                foreach ($donnees as $cle => $valeur) {
344
+                    if (is_array($valeur)) {
345
+                        foreach ($valeur as $val2) {
346
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
347
+                        }
348
+                    } else {
349
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
350
+                    }
351
+                }
352
+                $chaine = implode('&', $chaine);
353
+            } else {
354
+                $chaine = $donnees;
355
+            }
356
+        }
357
+    }
358
+
359
+    return [$entete, $chaine];
360 360
 }
361 361
 
362 362
 /**
@@ -370,20 +370,20 @@  discard block
 block discarded – undo
370 370
  */
371 371
 function url_to_ascii($url_idn) {
372 372
 
373
-	if ($parts = parse_url($url_idn)) {
374
-		$host = $parts['host'];
375
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
376
-			include_spip('inc/idna_convert.class');
377
-			$IDN = new idna_convert();
378
-			$host_ascii = $IDN->encode($host);
379
-			$url_idn = explode($host, $url_idn, 2);
380
-			$url_idn = implode($host_ascii, $url_idn);
381
-		}
382
-		// et on urlencode les char utf si besoin dans le path
383
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
384
-	}
385
-
386
-	return $url_idn;
373
+    if ($parts = parse_url($url_idn)) {
374
+        $host = $parts['host'];
375
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
376
+            include_spip('inc/idna_convert.class');
377
+            $IDN = new idna_convert();
378
+            $host_ascii = $IDN->encode($host);
379
+            $url_idn = explode($host, $url_idn, 2);
380
+            $url_idn = implode($host_ascii, $url_idn);
381
+        }
382
+        // et on urlencode les char utf si besoin dans le path
383
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn);
384
+    }
385
+
386
+    return $url_idn;
387 387
 }
388 388
 
389 389
 /**
@@ -424,209 +424,209 @@  discard block
 block discarded – undo
424 424
  *     string file : nom du fichier si enregistre dans un fichier
425 425
  */
426 426
 function recuperer_url($url, $options = []) {
427
-	// Conserve la mémoire de la méthode fournit éventuellement
428
-	$methode_demandee = $options['methode'] ?? '';
429
-	$default = [
430
-		'transcoder' => false,
431
-		'methode' => 'GET',
432
-		'taille_max' => null,
433
-		'headers' => [],
434
-		'datas' => '',
435
-		'boundary' => '',
436
-		'refuser_gz' => false,
437
-		'if_modified_since' => '',
438
-		'uri_referer' => '',
439
-		'file' => '',
440
-		'follow_location' => 10,
441
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
442
-	];
443
-	$options = array_merge($default, $options);
444
-	// copier directement dans un fichier ?
445
-	$copy = $options['file'];
446
-
447
-	if ($options['methode'] == 'HEAD') {
448
-		$options['taille_max'] = 0;
449
-	}
450
-	if (is_null($options['taille_max'])) {
451
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
452
-	}
453
-
454
-	spip_log("recuperer_url " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
455
-
456
-	// Ajout des en-têtes spécifiques si besoin
457
-	$formatted_data = '';
458
-	if (!empty($options['headers'])) {
459
-		foreach ($options['headers'] as $champ => $valeur) {
460
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
461
-		}
462
-	}
463
-
464
-	if (!empty($options['datas'])) {
465
-		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
466
-		$head .= $formatted_data;
467
-		if (stripos($head, 'Content-Length:') === false) {
468
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
469
-		}
470
-		$formatted_data = $head . "\r\n" . $postdata;
471
-		if (
472
-			strlen($postdata)
473
-			and !$methode_demandee
474
-		) {
475
-			$options['methode'] = 'POST';
476
-		}
477
-	} elseif ($formatted_data) {
478
-		$formatted_data .= "\r\n";
479
-	}
480
-
481
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
482
-	$url = preg_replace(',^feed://,i', 'http://', $url);
483
-	if (!tester_url_absolue($url)) {
484
-		$url = 'http://' . $url;
485
-	} elseif (strncmp($url, '//', 2) == 0) {
486
-		$url = 'http:' . $url;
487
-	}
488
-
489
-	$url = url_to_ascii($url);
490
-
491
-	$result = [
492
-		'status' => 0,
493
-		'headers' => '',
494
-		'page' => '',
495
-		'length' => 0,
496
-		'last_modified' => '',
497
-		'location' => '',
498
-		'url' => $url
499
-	];
500
-
501
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
502
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
503
-
504
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
505
-	[$handle, $fopen] = init_http(
506
-		$options['methode'],
507
-		$url,
508
-		$refuser_gz,
509
-		$options['uri_referer'],
510
-		$formatted_data,
511
-		$options['version_http'],
512
-		$options['if_modified_since']
513
-	);
514
-	if (!$handle) {
515
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
516
-
517
-		return false;
518
-	}
519
-
520
-	// Sauf en fopen, envoyer le flux d'entree
521
-	// et recuperer les en-tetes de reponses
522
-	if (!$fopen) {
523
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
524
-		if (!$res) {
525
-			fclose($handle);
526
-			$t = @parse_url($url);
527
-			$host = $t['host'];
528
-			// Chinoisierie inexplicable pour contrer
529
-			// les actions liberticides de l'empire du milieu
530
-			if (
531
-				!need_proxy($host)
532
-				and $res = @file_get_contents($url)
533
-			) {
534
-				$result['length'] = strlen($res);
535
-				if ($copy) {
536
-					ecrire_fichier($copy, $res);
537
-					$result['file'] = $copy;
538
-				} else {
539
-					$result['page'] = $res;
540
-				}
541
-				$res = [
542
-					'status' => 200,
543
-				];
544
-			} else {
545
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
546
-				return false;
547
-			}
548
-		} elseif ($res['location'] and $options['follow_location']) {
549
-			$options['follow_location']--;
550
-			fclose($handle);
551
-			include_spip('inc/filtres');
552
-			$url = suivre_lien($url, $res['location']);
553
-
554
-			// une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
555
-			if ($options['methode'] !== 'GET') {
556
-				if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
557
-					$options['methode'] = 'GET';
558
-					$options['datas'] = '';
559
-				}
560
-			}
561
-			spip_log("recuperer_url recommence " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
562
-
563
-			return recuperer_url($url, $options);
564
-		} elseif ($res['status'] !== 200) {
565
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
566
-		}
567
-		$result['status'] = $res['status'];
568
-		if (isset($res['headers'])) {
569
-			$result['headers'] = $res['headers'];
570
-		}
571
-		if (isset($res['last_modified'])) {
572
-			$result['last_modified'] = $res['last_modified'];
573
-		}
574
-		if (isset($res['location'])) {
575
-			$result['location'] = $res['location'];
576
-		}
577
-	}
578
-
579
-	// on ne veut que les entetes
580
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
581
-		spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
582
-		return $result;
583
-	}
584
-
585
-
586
-	// s'il faut deballer, le faire via un fichier temporaire
587
-	// sinon la memoire explose pour les gros flux
588
-
589
-	$gz = false;
590
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
591
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
592
-	}
593
-
594
-	// si on a pas deja recuperer le contenu par une methode detournee
595
-	if (!$result['length']) {
596
-		$res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
597
-		fclose($handle);
598
-		if ($copy) {
599
-			$result['length'] = $res;
600
-			$result['file'] = $copy;
601
-		} elseif ($res) {
602
-			$result['page'] = &$res;
603
-			$result['length'] = strlen($result['page']);
604
-		}
605
-		if (!$result['status']) {
606
-			$result['status'] = 200; // on a reussi, donc !
607
-		}
608
-	}
609
-	if (!$result['page']) {
610
-		return $result;
611
-	}
612
-
613
-	// Decompresser au besoin
614
-	if ($gz) {
615
-		$result['page'] = implode('', gzfile($gz));
616
-		supprimer_fichier($gz);
617
-	}
618
-
619
-	// Faut-il l'importer dans notre charset local ?
620
-	if ($options['transcoder']) {
621
-		include_spip('inc/charsets');
622
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
623
-	}
624
-
625
-	$trace = json_decode(json_encode($result), true);
626
-	$trace['page'] = '...';
627
-	spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
628
-
629
-	return $result;
427
+    // Conserve la mémoire de la méthode fournit éventuellement
428
+    $methode_demandee = $options['methode'] ?? '';
429
+    $default = [
430
+        'transcoder' => false,
431
+        'methode' => 'GET',
432
+        'taille_max' => null,
433
+        'headers' => [],
434
+        'datas' => '',
435
+        'boundary' => '',
436
+        'refuser_gz' => false,
437
+        'if_modified_since' => '',
438
+        'uri_referer' => '',
439
+        'file' => '',
440
+        'follow_location' => 10,
441
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
442
+    ];
443
+    $options = array_merge($default, $options);
444
+    // copier directement dans un fichier ?
445
+    $copy = $options['file'];
446
+
447
+    if ($options['methode'] == 'HEAD') {
448
+        $options['taille_max'] = 0;
449
+    }
450
+    if (is_null($options['taille_max'])) {
451
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
452
+    }
453
+
454
+    spip_log("recuperer_url " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
455
+
456
+    // Ajout des en-têtes spécifiques si besoin
457
+    $formatted_data = '';
458
+    if (!empty($options['headers'])) {
459
+        foreach ($options['headers'] as $champ => $valeur) {
460
+            $formatted_data .= $champ . ': ' . $valeur . "\r\n";
461
+        }
462
+    }
463
+
464
+    if (!empty($options['datas'])) {
465
+        [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
466
+        $head .= $formatted_data;
467
+        if (stripos($head, 'Content-Length:') === false) {
468
+            $head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
469
+        }
470
+        $formatted_data = $head . "\r\n" . $postdata;
471
+        if (
472
+            strlen($postdata)
473
+            and !$methode_demandee
474
+        ) {
475
+            $options['methode'] = 'POST';
476
+        }
477
+    } elseif ($formatted_data) {
478
+        $formatted_data .= "\r\n";
479
+    }
480
+
481
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
482
+    $url = preg_replace(',^feed://,i', 'http://', $url);
483
+    if (!tester_url_absolue($url)) {
484
+        $url = 'http://' . $url;
485
+    } elseif (strncmp($url, '//', 2) == 0) {
486
+        $url = 'http:' . $url;
487
+    }
488
+
489
+    $url = url_to_ascii($url);
490
+
491
+    $result = [
492
+        'status' => 0,
493
+        'headers' => '',
494
+        'page' => '',
495
+        'length' => 0,
496
+        'last_modified' => '',
497
+        'location' => '',
498
+        'url' => $url
499
+    ];
500
+
501
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
502
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
503
+
504
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
505
+    [$handle, $fopen] = init_http(
506
+        $options['methode'],
507
+        $url,
508
+        $refuser_gz,
509
+        $options['uri_referer'],
510
+        $formatted_data,
511
+        $options['version_http'],
512
+        $options['if_modified_since']
513
+    );
514
+    if (!$handle) {
515
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
516
+
517
+        return false;
518
+    }
519
+
520
+    // Sauf en fopen, envoyer le flux d'entree
521
+    // et recuperer les en-tetes de reponses
522
+    if (!$fopen) {
523
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
524
+        if (!$res) {
525
+            fclose($handle);
526
+            $t = @parse_url($url);
527
+            $host = $t['host'];
528
+            // Chinoisierie inexplicable pour contrer
529
+            // les actions liberticides de l'empire du milieu
530
+            if (
531
+                !need_proxy($host)
532
+                and $res = @file_get_contents($url)
533
+            ) {
534
+                $result['length'] = strlen($res);
535
+                if ($copy) {
536
+                    ecrire_fichier($copy, $res);
537
+                    $result['file'] = $copy;
538
+                } else {
539
+                    $result['page'] = $res;
540
+                }
541
+                $res = [
542
+                    'status' => 200,
543
+                ];
544
+            } else {
545
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
546
+                return false;
547
+            }
548
+        } elseif ($res['location'] and $options['follow_location']) {
549
+            $options['follow_location']--;
550
+            fclose($handle);
551
+            include_spip('inc/filtres');
552
+            $url = suivre_lien($url, $res['location']);
553
+
554
+            // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode
555
+            if ($options['methode'] !== 'GET') {
556
+                if (empty($res['status']) or !in_array($res['status'], [307, 308])) {
557
+                    $options['methode'] = 'GET';
558
+                    $options['datas'] = '';
559
+                }
560
+            }
561
+            spip_log("recuperer_url recommence " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
562
+
563
+            return recuperer_url($url, $options);
564
+        } elseif ($res['status'] !== 200) {
565
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
566
+        }
567
+        $result['status'] = $res['status'];
568
+        if (isset($res['headers'])) {
569
+            $result['headers'] = $res['headers'];
570
+        }
571
+        if (isset($res['last_modified'])) {
572
+            $result['last_modified'] = $res['last_modified'];
573
+        }
574
+        if (isset($res['location'])) {
575
+            $result['location'] = $res['location'];
576
+        }
577
+    }
578
+
579
+    // on ne veut que les entetes
580
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
581
+        spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
582
+        return $result;
583
+    }
584
+
585
+
586
+    // s'il faut deballer, le faire via un fichier temporaire
587
+    // sinon la memoire explose pour les gros flux
588
+
589
+    $gz = false;
590
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
591
+        $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
592
+    }
593
+
594
+    // si on a pas deja recuperer le contenu par une methode detournee
595
+    if (!$result['length']) {
596
+        $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy);
597
+        fclose($handle);
598
+        if ($copy) {
599
+            $result['length'] = $res;
600
+            $result['file'] = $copy;
601
+        } elseif ($res) {
602
+            $result['page'] = &$res;
603
+            $result['length'] = strlen($result['page']);
604
+        }
605
+        if (!$result['status']) {
606
+            $result['status'] = 200; // on a reussi, donc !
607
+        }
608
+    }
609
+    if (!$result['page']) {
610
+        return $result;
611
+    }
612
+
613
+    // Decompresser au besoin
614
+    if ($gz) {
615
+        $result['page'] = implode('', gzfile($gz));
616
+        supprimer_fichier($gz);
617
+    }
618
+
619
+    // Faut-il l'importer dans notre charset local ?
620
+    if ($options['transcoder']) {
621
+        include_spip('inc/charsets');
622
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
623
+    }
624
+
625
+    $trace = json_decode(json_encode($result), true);
626
+    $trace['page'] = '...';
627
+    spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
628
+
629
+    return $result;
630 630
 }
631 631
 
632 632
 /**
@@ -642,73 +642,73 @@  discard block
 block discarded – undo
642 642
  * @return array|bool|mixed
643 643
  */
644 644
 function recuperer_url_cache($url, $options = []) {
645
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
646
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
647
-	}
648
-	$default = [
649
-		'transcoder' => false,
650
-		'methode' => 'GET',
651
-		'taille_max' => null,
652
-		'datas' => '',
653
-		'boundary' => '',
654
-		'refuser_gz' => false,
655
-		'if_modified_since' => '',
656
-		'uri_referer' => '',
657
-		'file' => '',
658
-		'follow_location' => 10,
659
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
660
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
661
-	];
662
-	$options = array_merge($default, $options);
663
-
664
-	// cas ou il n'est pas possible de cacher
665
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
666
-		return recuperer_url($url, $options);
667
-	}
668
-
669
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
670
-	static $errors = [];
671
-	if (isset($errors[$url])) {
672
-		return $errors[$url];
673
-	}
674
-
675
-	$sig = $options;
676
-	unset($sig['if_modified_since']);
677
-	unset($sig['delai_cache']);
678
-	$sig['url'] = $url;
679
-
680
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
681
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
682
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
683
-	$cache = "$sub$cache";
684
-
685
-	$res = false;
686
-	$is_cached = file_exists($cache);
687
-	if (
688
-		$is_cached
689
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
690
-	) {
691
-		lire_fichier($cache, $res);
692
-		if ($res = unserialize($res)) {
693
-			// mettre le last_modified et le status=304 ?
694
-		}
695
-	}
696
-	if (!$res) {
697
-		$res = recuperer_url($url, $options);
698
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
699
-		if (!$res) {
700
-			if ($is_cached) {
701
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
702
-				lire_fichier($cache, $res);
703
-				$res = unserialize($res);
704
-			}
705
-
706
-			return $errors[$url] = $res;
707
-		}
708
-		ecrire_fichier($cache, serialize($res));
709
-	}
710
-
711
-	return $res;
645
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
646
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
647
+    }
648
+    $default = [
649
+        'transcoder' => false,
650
+        'methode' => 'GET',
651
+        'taille_max' => null,
652
+        'datas' => '',
653
+        'boundary' => '',
654
+        'refuser_gz' => false,
655
+        'if_modified_since' => '',
656
+        'uri_referer' => '',
657
+        'file' => '',
658
+        'follow_location' => 10,
659
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
660
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
661
+    ];
662
+    $options = array_merge($default, $options);
663
+
664
+    // cas ou il n'est pas possible de cacher
665
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
666
+        return recuperer_url($url, $options);
667
+    }
668
+
669
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
670
+    static $errors = [];
671
+    if (isset($errors[$url])) {
672
+        return $errors[$url];
673
+    }
674
+
675
+    $sig = $options;
676
+    unset($sig['if_modified_since']);
677
+    unset($sig['delai_cache']);
678
+    $sig['url'] = $url;
679
+
680
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
681
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
682
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
683
+    $cache = "$sub$cache";
684
+
685
+    $res = false;
686
+    $is_cached = file_exists($cache);
687
+    if (
688
+        $is_cached
689
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
690
+    ) {
691
+        lire_fichier($cache, $res);
692
+        if ($res = unserialize($res)) {
693
+            // mettre le last_modified et le status=304 ?
694
+        }
695
+    }
696
+    if (!$res) {
697
+        $res = recuperer_url($url, $options);
698
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
699
+        if (!$res) {
700
+            if ($is_cached) {
701
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
702
+                lire_fichier($cache, $res);
703
+                $res = unserialize($res);
704
+            }
705
+
706
+            return $errors[$url] = $res;
707
+        }
708
+        ecrire_fichier($cache, serialize($res));
709
+    }
710
+
711
+    return $res;
712 712
 }
713 713
 
714 714
 /**
@@ -726,42 +726,42 @@  discard block
 block discarded – undo
726 726
  *   string contenu de la resource
727 727
  */
728 728
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
729
-	$tmpfile = null;
730
-	$taille = 0;
731
-	$result = '';
732
-	$fp = false;
733
-	if ($fichier) {
734
-		include_spip('inc/acces');
735
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
736
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
737
-		if (!$fp and file_exists($fichier)) {
738
-			return filesize($fichier);
739
-		}
740
-		if (!$fp) {
741
-			return false;
742
-		}
743
-		$result = 0; // on renvoie la taille du fichier
744
-	}
745
-	while (!feof($handle) and $taille < $taille_max) {
746
-		$res = fread($handle, 16384);
747
-		$taille += strlen($res);
748
-		if ($fp) {
749
-			fwrite($fp, $res);
750
-			$result = $taille;
751
-		} else {
752
-			$result .= $res;
753
-		}
754
-	}
755
-	if ($fp) {
756
-		spip_fclose_unlock($fp);
757
-		spip_unlink($fichier);
758
-		@rename($tmpfile, $fichier);
759
-		if (!file_exists($fichier)) {
760
-			return false;
761
-		}
762
-	}
763
-
764
-	return $result;
729
+    $tmpfile = null;
730
+    $taille = 0;
731
+    $result = '';
732
+    $fp = false;
733
+    if ($fichier) {
734
+        include_spip('inc/acces');
735
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
736
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
737
+        if (!$fp and file_exists($fichier)) {
738
+            return filesize($fichier);
739
+        }
740
+        if (!$fp) {
741
+            return false;
742
+        }
743
+        $result = 0; // on renvoie la taille du fichier
744
+    }
745
+    while (!feof($handle) and $taille < $taille_max) {
746
+        $res = fread($handle, 16384);
747
+        $taille += strlen($res);
748
+        if ($fp) {
749
+            fwrite($fp, $res);
750
+            $result = $taille;
751
+        } else {
752
+            $result .= $res;
753
+        }
754
+    }
755
+    if ($fp) {
756
+        spip_fclose_unlock($fp);
757
+        spip_unlink($fichier);
758
+        @rename($tmpfile, $fichier);
759
+        if (!file_exists($fichier)) {
760
+            return false;
761
+        }
762
+    }
763
+
764
+    return $result;
765 765
 }
766 766
 
767 767
 /**
@@ -783,35 +783,35 @@  discard block
 block discarded – undo
783 783
  *   string location
784 784
  */
785 785
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
786
-	$result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
787
-
788
-	$s = @trim(fgets($handle, 16384));
789
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
790
-		return false;
791
-	}
792
-	$result['status'] = intval($r[1]);
793
-	while ($s = trim(fgets($handle, 16384))) {
794
-		$result['headers'][] = $s . "\n";
795
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
796
-		[, $d, $v] = $r;
797
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
798
-			$result['location'] = $v;
799
-		} elseif ($d == 'Last-Modified') {
800
-			$result['last_modified'] = strtotime($v);
801
-		}
802
-	}
803
-	if (
804
-		$if_modified_since
805
-		and $result['last_modified']
806
-		and $if_modified_since > $result['last_modified']
807
-		and $result['status'] == 200
808
-	) {
809
-		$result['status'] = 304;
810
-	}
811
-
812
-	$result['headers'] = implode('', $result['headers']);
813
-
814
-	return $result;
786
+    $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
787
+
788
+    $s = @trim(fgets($handle, 16384));
789
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
790
+        return false;
791
+    }
792
+    $result['status'] = intval($r[1]);
793
+    while ($s = trim(fgets($handle, 16384))) {
794
+        $result['headers'][] = $s . "\n";
795
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
796
+        [, $d, $v] = $r;
797
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
798
+            $result['location'] = $v;
799
+        } elseif ($d == 'Last-Modified') {
800
+            $result['last_modified'] = strtotime($v);
801
+        }
802
+    }
803
+    if (
804
+        $if_modified_since
805
+        and $result['last_modified']
806
+        and $if_modified_since > $result['last_modified']
807
+        and $result['status'] == 200
808
+    ) {
809
+        $result['status'] = 304;
810
+    }
811
+
812
+    $result['headers'] = implode('', $result['headers']);
813
+
814
+    return $result;
815 815
 }
816 816
 
817 817
 /**
@@ -833,22 +833,22 @@  discard block
 block discarded – undo
833 833
  *     Nom du fichier pour copie locale
834 834
  **/
835 835
 function nom_fichier_copie_locale($source, $extension) {
836
-	include_spip('inc/documents');
836
+    include_spip('inc/documents');
837 837
 
838
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
839
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
838
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
839
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
840 840
 
841
-	// on se place tout le temps comme si on etait a la racine
842
-	if (_DIR_RACINE) {
843
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
844
-	}
841
+    // on se place tout le temps comme si on etait a la racine
842
+    if (_DIR_RACINE) {
843
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
844
+    }
845 845
 
846
-	$m = md5($source);
846
+    $m = md5($source);
847 847
 
848
-	return $d
849
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
850
-	. substr($m, 0, 4)
851
-	. ".$extension";
848
+    return $d
849
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
850
+    . substr($m, 0, 4)
851
+    . ".$extension";
852 852
 }
853 853
 
854 854
 /**
@@ -866,70 +866,70 @@  discard block
 block discarded – undo
866 866
  *      Nom du fichier calculé
867 867
  **/
868 868
 function fichier_copie_locale($source) {
869
-	// Si c'est deja local pas de souci
870
-	if (!tester_url_absolue($source)) {
871
-		if (_DIR_RACINE) {
872
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
873
-		}
874
-
875
-		return $source;
876
-	}
877
-
878
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
879
-	// a deja ete copie en local avec cette extension
880
-	// dans ce cas elle est fiable, pas la peine de requeter en base
881
-	$path_parts = pathinfo($source);
882
-	if (!isset($path_parts['extension'])) {
883
-		$path_parts['extension'] = '';
884
-	}
885
-	$ext = $path_parts ? $path_parts['extension'] : '';
886
-	if (
887
-		$ext
888
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
889
-		and $f = nom_fichier_copie_locale($source, $ext)
890
-		and file_exists(_DIR_RACINE . $f)
891
-	) {
892
-		return $f;
893
-	}
894
-
895
-
896
-	// Si c'est deja dans la table des documents,
897
-	// ramener le nom de sa copie potentielle
898
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
899
-
900
-	if ($ext) {
901
-		return nom_fichier_copie_locale($source, $ext);
902
-	}
903
-
904
-	// voir si l'extension indiquee dans le nom du fichier est ok
905
-	// et si il n'aurait pas deja ete rapatrie
906
-
907
-	$ext = $path_parts ? $path_parts['extension'] : '';
908
-
909
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
910
-		$f = nom_fichier_copie_locale($source, $ext);
911
-		if (file_exists(_DIR_RACINE . $f)) {
912
-			return $f;
913
-		}
914
-	}
915
-
916
-	// Ping  pour voir si son extension est connue et autorisee
917
-	// avec mise en cache du resultat du ping
918
-
919
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
920
-	if (
921
-		!@file_exists($cache)
922
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
923
-		or _request('var_mode') === 'recalcul'
924
-	) {
925
-		$path_parts = recuperer_infos_distantes($source, 0, false);
926
-		ecrire_fichier($cache, serialize($path_parts));
927
-	}
928
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
929
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
930
-		return nom_fichier_copie_locale($source, $ext);
931
-	}
932
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
869
+    // Si c'est deja local pas de souci
870
+    if (!tester_url_absolue($source)) {
871
+        if (_DIR_RACINE) {
872
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
873
+        }
874
+
875
+        return $source;
876
+    }
877
+
878
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
879
+    // a deja ete copie en local avec cette extension
880
+    // dans ce cas elle est fiable, pas la peine de requeter en base
881
+    $path_parts = pathinfo($source);
882
+    if (!isset($path_parts['extension'])) {
883
+        $path_parts['extension'] = '';
884
+    }
885
+    $ext = $path_parts ? $path_parts['extension'] : '';
886
+    if (
887
+        $ext
888
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
889
+        and $f = nom_fichier_copie_locale($source, $ext)
890
+        and file_exists(_DIR_RACINE . $f)
891
+    ) {
892
+        return $f;
893
+    }
894
+
895
+
896
+    // Si c'est deja dans la table des documents,
897
+    // ramener le nom de sa copie potentielle
898
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
899
+
900
+    if ($ext) {
901
+        return nom_fichier_copie_locale($source, $ext);
902
+    }
903
+
904
+    // voir si l'extension indiquee dans le nom du fichier est ok
905
+    // et si il n'aurait pas deja ete rapatrie
906
+
907
+    $ext = $path_parts ? $path_parts['extension'] : '';
908
+
909
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
910
+        $f = nom_fichier_copie_locale($source, $ext);
911
+        if (file_exists(_DIR_RACINE . $f)) {
912
+            return $f;
913
+        }
914
+    }
915
+
916
+    // Ping  pour voir si son extension est connue et autorisee
917
+    // avec mise en cache du resultat du ping
918
+
919
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
920
+    if (
921
+        !@file_exists($cache)
922
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
923
+        or _request('var_mode') === 'recalcul'
924
+    ) {
925
+        $path_parts = recuperer_infos_distantes($source, 0, false);
926
+        ecrire_fichier($cache, serialize($path_parts));
927
+    }
928
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
929
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
930
+        return nom_fichier_copie_locale($source, $ext);
931
+    }
932
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
933 933
 }
934 934
 
935 935
 
@@ -957,97 +957,97 @@  discard block
 block discarded – undo
957 957
  **/
958 958
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
959 959
 
960
-	// pas la peine de perdre son temps
961
-	if (!tester_url_absolue($source)) {
962
-		return false;
963
-	}
964
-
965
-	# charger les alias des types mime
966
-	include_spip('base/typedoc');
967
-
968
-	$a = [];
969
-	$mime_type = '';
970
-	// On va directement charger le debut des images et des fichiers html,
971
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
972
-	// ca echoue l'utilisateur devra les entrer...
973
-	$reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
974
-	$headers = $reponse['headers'] ?? '';
975
-	$a['body'] = $reponse['page'] ?? '';
976
-	if ($headers) {
977
-		if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
978
-			return false;
979
-		}
980
-
981
-		$a['extension'] = $extension;
982
-
983
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
984
-			$a['taille'] = intval($regs[1]);
985
-		}
986
-	}
987
-
988
-	// Echec avec HEAD, on tente avec GET
989
-	if (!$a and !$max) {
990
-		spip_log("tenter GET $source", 'distant');
991
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
992
-	}
993
-
994
-	// si on a rien trouve pas la peine d'insister
995
-	if (!$a) {
996
-		return false;
997
-	}
998
-
999
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1000
-	// recharger le document en GET et recuperer des donnees supplementaires...
1001
-	include_spip('inc/filtres_images_lib_mini');
1002
-	if (
1003
-		strpos($mime_type, 'image/') === 0
1004
-		and $extension = _image_trouver_extension_depuis_mime($mime_type)
1005
-	) {
1006
-		if (
1007
-			$max == 0
1008
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1009
-			and in_array($extension, formats_image_acceptables())
1010
-			and $charger_si_petite_image
1011
-		) {
1012
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1013
-		} else {
1014
-			if ($a['body']) {
1015
-				$a['extension'] = $extension;
1016
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1017
-				ecrire_fichier($a['fichier'], $a['body']);
1018
-				$size_image = @spip_getimagesize($a['fichier']);
1019
-				$a['largeur'] = intval($size_image[0]);
1020
-				$a['hauteur'] = intval($size_image[1]);
1021
-				$a['type_image'] = true;
1022
-			}
1023
-		}
1024
-	}
1025
-
1026
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1027
-	// ce sera mieux que 0x0
1028
-	// Flash is dead!
1029
-	if (
1030
-		$a and isset($a['extension']) and $a['extension'] == 'swf'
1031
-		and empty($a['largeur'])
1032
-	) {
1033
-		$a['largeur'] = 425;
1034
-		$a['hauteur'] = 350;
1035
-	}
1036
-
1037
-	if ($mime_type == 'text/html') {
1038
-		include_spip('inc/filtres');
1039
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1040
-		$page = $page['page'] ?? '';
1041
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1042
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1043
-		}
1044
-		if (!isset($a['taille']) or !$a['taille']) {
1045
-			$a['taille'] = strlen($page); # a peu pres
1046
-		}
1047
-	}
1048
-	$a['mime_type'] = $mime_type;
1049
-
1050
-	return $a;
960
+    // pas la peine de perdre son temps
961
+    if (!tester_url_absolue($source)) {
962
+        return false;
963
+    }
964
+
965
+    # charger les alias des types mime
966
+    include_spip('base/typedoc');
967
+
968
+    $a = [];
969
+    $mime_type = '';
970
+    // On va directement charger le debut des images et des fichiers html,
971
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
972
+    // ca echoue l'utilisateur devra les entrer...
973
+    $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
974
+    $headers = $reponse['headers'] ?? '';
975
+    $a['body'] = $reponse['page'] ?? '';
976
+    if ($headers) {
977
+        if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
978
+            return false;
979
+        }
980
+
981
+        $a['extension'] = $extension;
982
+
983
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
984
+            $a['taille'] = intval($regs[1]);
985
+        }
986
+    }
987
+
988
+    // Echec avec HEAD, on tente avec GET
989
+    if (!$a and !$max) {
990
+        spip_log("tenter GET $source", 'distant');
991
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
992
+    }
993
+
994
+    // si on a rien trouve pas la peine d'insister
995
+    if (!$a) {
996
+        return false;
997
+    }
998
+
999
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1000
+    // recharger le document en GET et recuperer des donnees supplementaires...
1001
+    include_spip('inc/filtres_images_lib_mini');
1002
+    if (
1003
+        strpos($mime_type, 'image/') === 0
1004
+        and $extension = _image_trouver_extension_depuis_mime($mime_type)
1005
+    ) {
1006
+        if (
1007
+            $max == 0
1008
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1009
+            and in_array($extension, formats_image_acceptables())
1010
+            and $charger_si_petite_image
1011
+        ) {
1012
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1013
+        } else {
1014
+            if ($a['body']) {
1015
+                $a['extension'] = $extension;
1016
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1017
+                ecrire_fichier($a['fichier'], $a['body']);
1018
+                $size_image = @spip_getimagesize($a['fichier']);
1019
+                $a['largeur'] = intval($size_image[0]);
1020
+                $a['hauteur'] = intval($size_image[1]);
1021
+                $a['type_image'] = true;
1022
+            }
1023
+        }
1024
+    }
1025
+
1026
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1027
+    // ce sera mieux que 0x0
1028
+    // Flash is dead!
1029
+    if (
1030
+        $a and isset($a['extension']) and $a['extension'] == 'swf'
1031
+        and empty($a['largeur'])
1032
+    ) {
1033
+        $a['largeur'] = 425;
1034
+        $a['hauteur'] = 350;
1035
+    }
1036
+
1037
+    if ($mime_type == 'text/html') {
1038
+        include_spip('inc/filtres');
1039
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1040
+        $page = $page['page'] ?? '';
1041
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1042
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1043
+        }
1044
+        if (!isset($a['taille']) or !$a['taille']) {
1045
+            $a['taille'] = strlen($page); # a peu pres
1046
+        }
1047
+    }
1048
+    $a['mime_type'] = $mime_type;
1049
+
1050
+    return $a;
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1056,70 +1056,70 @@  discard block
 block discarded – undo
1056 1056
  * @return false|mixed
1057 1057
  */
1058 1058
 function distant_trouver_extension_selon_headers($source, $headers) {
1059
-	if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1060
-		$mime_type = (trim($regs[1]));
1061
-	} else {
1062
-		$mime_type = '';
1063
-	} // inconnu
1064
-
1065
-	// Appliquer les alias
1066
-	while (isset($GLOBALS['mime_alias'][$mime_type])) {
1067
-		$mime_type = $GLOBALS['mime_alias'][$mime_type];
1068
-	}
1069
-
1070
-	// pour corriger_extension()
1071
-	include_spip('inc/documents');
1072
-
1073
-	// Si on a un mime-type insignifiant
1074
-	// text/plain,application/octet-stream ou vide
1075
-	// c'est peut-etre que le serveur ne sait pas
1076
-	// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1077
-	// ou le Content-Disposition: attachment; filename=...
1078
-	$t = null;
1079
-	if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1080
-		if (
1081
-			!$t
1082
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1083
-		) {
1084
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1085
-		}
1086
-		if (
1087
-			!$t
1088
-			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1089
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1090
-		) {
1091
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1092
-		}
1093
-	}
1094
-
1095
-	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1096
-	if (!$t) {
1097
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1098
-	}
1099
-
1100
-	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1101
-	// On essaie de nouveau avec l'extension
1102
-	if (
1103
-		!$t
1104
-		and $mime_type != 'text/plain'
1105
-		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1106
-	) {
1107
-		# eviter xxx.3 => 3gp (> SPIP 3)
1108
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1109
-	}
1110
-
1111
-	if ($t) {
1112
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1113
-		return $t['extension'];
1114
-	} else {
1115
-		# par defaut on retombe sur '.bin' si c'est autorise
1116
-		spip_log("mime-type $mime_type inconnu", 'distant');
1117
-		$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1118
-		if (!$t) {
1119
-			return false;
1120
-		}
1121
-		return $t['extension'];
1122
-	}
1059
+    if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1060
+        $mime_type = (trim($regs[1]));
1061
+    } else {
1062
+        $mime_type = '';
1063
+    } // inconnu
1064
+
1065
+    // Appliquer les alias
1066
+    while (isset($GLOBALS['mime_alias'][$mime_type])) {
1067
+        $mime_type = $GLOBALS['mime_alias'][$mime_type];
1068
+    }
1069
+
1070
+    // pour corriger_extension()
1071
+    include_spip('inc/documents');
1072
+
1073
+    // Si on a un mime-type insignifiant
1074
+    // text/plain,application/octet-stream ou vide
1075
+    // c'est peut-etre que le serveur ne sait pas
1076
+    // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1077
+    // ou le Content-Disposition: attachment; filename=...
1078
+    $t = null;
1079
+    if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1080
+        if (
1081
+            !$t
1082
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1083
+        ) {
1084
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1085
+        }
1086
+        if (
1087
+            !$t
1088
+            and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1089
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1090
+        ) {
1091
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1092
+        }
1093
+    }
1094
+
1095
+    // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1096
+    if (!$t) {
1097
+        $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1098
+    }
1099
+
1100
+    // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1101
+    // On essaie de nouveau avec l'extension
1102
+    if (
1103
+        !$t
1104
+        and $mime_type != 'text/plain'
1105
+        and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1106
+    ) {
1107
+        # eviter xxx.3 => 3gp (> SPIP 3)
1108
+        $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1109
+    }
1110
+
1111
+    if ($t) {
1112
+        spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1113
+        return $t['extension'];
1114
+    } else {
1115
+        # par defaut on retombe sur '.bin' si c'est autorise
1116
+        spip_log("mime-type $mime_type inconnu", 'distant');
1117
+        $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1118
+        if (!$t) {
1119
+            return false;
1120
+        }
1121
+        return $t['extension'];
1122
+    }
1123 1123
 }
1124 1124
 
1125 1125
 /**
@@ -1135,45 +1135,45 @@  discard block
 block discarded – undo
1135 1135
  */
1136 1136
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1137 1137
 
1138
-	$http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1138
+    $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null;
1139 1139
 	
1140
-	// rien a faire si pas de proxy :)
1141
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1142
-		return '';
1143
-	}
1144
-
1145
-	if (is_null($http_noproxy)) {
1146
-		$http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1147
-	}
1148
-	// si pas d'exception, on retourne le proxy
1149
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1150
-		return $http_proxy;
1151
-	}
1152
-
1153
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1154
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1155
-	$http_noproxy = str_replace("\n", ' ', $http_noproxy);
1156
-	$http_noproxy = str_replace("\r", ' ', $http_noproxy);
1157
-	$http_noproxy = " $http_noproxy ";
1158
-	$domain = $host;
1159
-	// si le domaine exact www.example.org est dans les exceptions
1160
-	if (strpos($http_noproxy, (string) " $domain ") !== false) {
1161
-		return '';
1162
-	}
1163
-
1164
-	while (strpos($domain, '.') !== false) {
1165
-		$domain = explode('.', $domain);
1166
-		array_shift($domain);
1167
-		$domain = implode('.', $domain);
1168
-
1169
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1170
-		if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1171
-			return '';
1172
-		}
1173
-	}
1174
-
1175
-	// ok c'est pas une exception
1176
-	return $http_proxy;
1140
+    // rien a faire si pas de proxy :)
1141
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1142
+        return '';
1143
+    }
1144
+
1145
+    if (is_null($http_noproxy)) {
1146
+        $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null;
1147
+    }
1148
+    // si pas d'exception, on retourne le proxy
1149
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1150
+        return $http_proxy;
1151
+    }
1152
+
1153
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1154
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1155
+    $http_noproxy = str_replace("\n", ' ', $http_noproxy);
1156
+    $http_noproxy = str_replace("\r", ' ', $http_noproxy);
1157
+    $http_noproxy = " $http_noproxy ";
1158
+    $domain = $host;
1159
+    // si le domaine exact www.example.org est dans les exceptions
1160
+    if (strpos($http_noproxy, (string) " $domain ") !== false) {
1161
+        return '';
1162
+    }
1163
+
1164
+    while (strpos($domain, '.') !== false) {
1165
+        $domain = explode('.', $domain);
1166
+        array_shift($domain);
1167
+        $domain = implode('.', $domain);
1168
+
1169
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1170
+        if (strpos($http_noproxy, (string) " .$domain ") !== false) {
1171
+            return '';
1172
+        }
1173
+    }
1174
+
1175
+    // ok c'est pas une exception
1176
+    return $http_proxy;
1177 1177
 }
1178 1178
 
1179 1179
 
@@ -1196,59 +1196,59 @@  discard block
 block discarded – undo
1196 1196
  * @return array
1197 1197
  */
1198 1198
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1199
-	$user = $via_proxy = $proxy_user = '';
1200
-	$fopen = false;
1201
-
1202
-	$t = @parse_url($url);
1203
-	$host = $t['host'];
1204
-	if ($t['scheme'] == 'http') {
1205
-		$scheme = 'http';
1206
-		$noproxy = '';
1207
-	} elseif ($t['scheme'] == 'https') {
1208
-		$scheme = 'ssl';
1209
-		$noproxy = 'ssl://';
1210
-		if (!isset($t['port']) || !($port = $t['port'])) {
1211
-			$t['port'] = 443;
1212
-		}
1213
-	} else {
1214
-		$scheme = $t['scheme'];
1215
-		$noproxy = $scheme . '://';
1216
-	}
1217
-	if (isset($t['user'])) {
1218
-		$user = [$t['user'], $t['pass']];
1219
-	}
1220
-
1221
-	if (!isset($t['port']) || !($port = $t['port'])) {
1222
-		$port = 80;
1223
-	}
1224
-	if (!isset($t['path']) || !($path = $t['path'])) {
1225
-		$path = '/';
1226
-	}
1227
-
1228
-	if (!empty($t['query'])) {
1229
-		$path .= '?' . $t['query'];
1230
-	}
1231
-
1232
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1233
-	if (!$f or !is_resource($f)) {
1234
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1235
-		// ce qui correspond a $f===110
1236
-		if (
1237
-			$f !== 110
1238
-			and !need_proxy($host)
1239
-			and !_request('tester_proxy')
1240
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1241
-		) {
1242
-			$f = @fopen($url, 'rb');
1243
-			spip_log("connexion vers $url par simple fopen", 'distant');
1244
-			$fopen = true;
1245
-		} else {
1246
-			// echec total
1247
-			$f = false;
1248
-		}
1249
-	}
1250
-
1251
-	return [$f, $fopen];
1199
+    $user = $via_proxy = $proxy_user = '';
1200
+    $fopen = false;
1201
+
1202
+    $t = @parse_url($url);
1203
+    $host = $t['host'];
1204
+    if ($t['scheme'] == 'http') {
1205
+        $scheme = 'http';
1206
+        $noproxy = '';
1207
+    } elseif ($t['scheme'] == 'https') {
1208
+        $scheme = 'ssl';
1209
+        $noproxy = 'ssl://';
1210
+        if (!isset($t['port']) || !($port = $t['port'])) {
1211
+            $t['port'] = 443;
1212
+        }
1213
+    } else {
1214
+        $scheme = $t['scheme'];
1215
+        $noproxy = $scheme . '://';
1216
+    }
1217
+    if (isset($t['user'])) {
1218
+        $user = [$t['user'], $t['pass']];
1219
+    }
1220
+
1221
+    if (!isset($t['port']) || !($port = $t['port'])) {
1222
+        $port = 80;
1223
+    }
1224
+    if (!isset($t['path']) || !($path = $t['path'])) {
1225
+        $path = '/';
1226
+    }
1227
+
1228
+    if (!empty($t['query'])) {
1229
+        $path .= '?' . $t['query'];
1230
+    }
1231
+
1232
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1233
+    if (!$f or !is_resource($f)) {
1234
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1235
+        // ce qui correspond a $f===110
1236
+        if (
1237
+            $f !== 110
1238
+            and !need_proxy($host)
1239
+            and !_request('tester_proxy')
1240
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1241
+        ) {
1242
+            $f = @fopen($url, 'rb');
1243
+            spip_log("connexion vers $url par simple fopen", 'distant');
1244
+            $fopen = true;
1245
+        } else {
1246
+            // echec total
1247
+            $f = false;
1248
+        }
1249
+    }
1250
+
1251
+    return [$f, $fopen];
1252 1252
 }
1253 1253
 
1254 1254
 /**
@@ -1283,123 +1283,123 @@  discard block
 block discarded – undo
1283 1283
  *   resource socket vers l'url demandee
1284 1284
  */
1285 1285
 function lance_requete(
1286
-	$method,
1287
-	$scheme,
1288
-	$user,
1289
-	$host,
1290
-	$path,
1291
-	$port,
1292
-	$noproxy,
1293
-	$refuse_gz = false,
1294
-	$referer = '',
1295
-	$datas = '',
1296
-	$vers = 'HTTP/1.0',
1297
-	$date = ''
1286
+    $method,
1287
+    $scheme,
1288
+    $user,
1289
+    $host,
1290
+    $path,
1291
+    $port,
1292
+    $noproxy,
1293
+    $refuse_gz = false,
1294
+    $referer = '',
1295
+    $datas = '',
1296
+    $vers = 'HTTP/1.0',
1297
+    $date = ''
1298 1298
 ) {
1299 1299
 
1300
-	$proxy_user = '';
1301
-	$http_proxy = need_proxy($host);
1302
-	if ($user) {
1303
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1304
-	}
1305
-
1306
-	$connect = '';
1307
-	if ($http_proxy) {
1308
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1309
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1310
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1311
-				. "Host: $path_host\r\n"
1312
-				. "Proxy-Connection: Keep-Alive\r\n";
1313
-		} else {
1314
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1315
-				. (!$user ? '' : "$user@")
1316
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1317
-		}
1318
-		$t2 = @parse_url($http_proxy);
1319
-		$first_host = $t2['host'];
1320
-		$port = ($t2['port'] ?? null) ?: 80;
1321
-		if ($t2['user'] ?? null) {
1322
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1323
-		}
1324
-	} else {
1325
-		$first_host = $noproxy . $host;
1326
-	}
1327
-
1328
-	if ($connect) {
1329
-		$streamContext = stream_context_create([
1330
-			'ssl' => [
1331
-				'verify_peer' => false,
1332
-				'allow_self_signed' => true,
1333
-				'SNI_enabled' => true,
1334
-				'peer_name' => $host,
1335
-			]
1336
-		]);
1337
-		$f = @stream_socket_client(
1338
-			"tcp://$first_host:$port",
1339
-			$errno,
1340
-			$errstr,
1341
-			_INC_DISTANT_CONNECT_TIMEOUT,
1342
-			STREAM_CLIENT_CONNECT,
1343
-			$streamContext
1344
-		);
1345
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1346
-		if (!$f) {
1347
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1348
-			return $errno;
1349
-		}
1350
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1351
-
1352
-		fputs($f, $connect);
1353
-		fputs($f, "\r\n");
1354
-		$res = fread($f, 1024);
1355
-		if (
1356
-			!$res
1357
-			or !count($res = explode(' ', $res))
1358
-			or $res[1] !== '200'
1359
-		) {
1360
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1361
-			fclose($f);
1362
-
1363
-			return false;
1364
-		}
1365
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1366
-		stream_set_blocking($f, true);
1367
-		// envoyer le handshake
1368
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1369
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1370
-	} else {
1371
-		$ntry = 3;
1372
-		do {
1373
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1374
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1375
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1376
-		if (!$f) {
1377
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1378
-
1379
-			return $errno;
1380
-		}
1381
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1382
-	}
1383
-
1384
-	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1385
-
1386
-	$host_port = $host;
1387
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1388
-		$host_port .= ":$port";
1389
-	}
1390
-	$req = "$method $path $vers\r\n"
1391
-		. "Host: $host_port\r\n"
1392
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1393
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1394
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1395
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1396
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1397
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1398
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1300
+    $proxy_user = '';
1301
+    $http_proxy = need_proxy($host);
1302
+    if ($user) {
1303
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1304
+    }
1305
+
1306
+    $connect = '';
1307
+    if ($http_proxy) {
1308
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1309
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1310
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1311
+                . "Host: $path_host\r\n"
1312
+                . "Proxy-Connection: Keep-Alive\r\n";
1313
+        } else {
1314
+            $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1315
+                . (!$user ? '' : "$user@")
1316
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1317
+        }
1318
+        $t2 = @parse_url($http_proxy);
1319
+        $first_host = $t2['host'];
1320
+        $port = ($t2['port'] ?? null) ?: 80;
1321
+        if ($t2['user'] ?? null) {
1322
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1323
+        }
1324
+    } else {
1325
+        $first_host = $noproxy . $host;
1326
+    }
1327
+
1328
+    if ($connect) {
1329
+        $streamContext = stream_context_create([
1330
+            'ssl' => [
1331
+                'verify_peer' => false,
1332
+                'allow_self_signed' => true,
1333
+                'SNI_enabled' => true,
1334
+                'peer_name' => $host,
1335
+            ]
1336
+        ]);
1337
+        $f = @stream_socket_client(
1338
+            "tcp://$first_host:$port",
1339
+            $errno,
1340
+            $errstr,
1341
+            _INC_DISTANT_CONNECT_TIMEOUT,
1342
+            STREAM_CLIENT_CONNECT,
1343
+            $streamContext
1344
+        );
1345
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1346
+        if (!$f) {
1347
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1348
+            return $errno;
1349
+        }
1350
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1351
+
1352
+        fputs($f, $connect);
1353
+        fputs($f, "\r\n");
1354
+        $res = fread($f, 1024);
1355
+        if (
1356
+            !$res
1357
+            or !count($res = explode(' ', $res))
1358
+            or $res[1] !== '200'
1359
+        ) {
1360
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1361
+            fclose($f);
1362
+
1363
+            return false;
1364
+        }
1365
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1366
+        stream_set_blocking($f, true);
1367
+        // envoyer le handshake
1368
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1369
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1370
+    } else {
1371
+        $ntry = 3;
1372
+        do {
1373
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1374
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1375
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1376
+        if (!$f) {
1377
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1378
+
1379
+            return $errno;
1380
+        }
1381
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1382
+    }
1383
+
1384
+    $site = $GLOBALS['meta']['adresse_site'] ?? '';
1385
+
1386
+    $host_port = $host;
1387
+    if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1388
+        $host_port .= ":$port";
1389
+    }
1390
+    $req = "$method $path $vers\r\n"
1391
+        . "Host: $host_port\r\n"
1392
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1393
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1394
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1395
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1396
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1397
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1398
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1399 1399
 
1400 1400
 #	spip_log("Requete\n$req", 'distant');
1401
-	fputs($f, $req);
1402
-	fputs($f, $datas ?: "\r\n");
1401
+    fputs($f, $req);
1402
+    fputs($f, $datas ?: "\r\n");
1403 1403
 
1404
-	return $f;
1404
+    return $f;
1405 1405
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32 32
 	define('_INC_DISTANT_MAX_SIZE', 2_097_152);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38
-define('_REGEXP_COPIE_LOCALE', ',' 	.
38
+define('_REGEXP_COPIE_LOCALE', ','.
39 39
 	preg_replace(
40 40
 		'@^https?:@',
41 41
 		'https?:',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// si c'est la protection de soi-meme, retourner le path
72 72
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
73
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
74 74
 
75 75
 		return @file_exists($source) ? $source : false;
76 76
 	}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		return false;
91 91
 	}
92 92
 
93
-	$localrac = _DIR_RACINE . $local;
93
+	$localrac = _DIR_RACINE.$local;
94 94
 	$t = ($mode === 'force') ? false : @file_exists($localrac);
95 95
 
96 96
 	// test d'existence du fichier
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
 			['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116 116
 		);
117 117
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE);
119 119
 		}
120 120
 		else {
121
-			spip_log("copie_locale : recuperation $source sur $localrac OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant');
121
+			spip_log("copie_locale : recuperation $source sur $localrac OK | taille ".$res['length'].' status '.$res['status'], 'distant');
122 122
 		}
123 123
 		if (!$res or !$res['length']) {
124 124
 			// si $t c'est sans doute juste un not-modified-since
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 
208 208
 	if (!$is_known_host) {
209 209
 		$host = trim($parsed_url['host'], '.');
210
-		if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) {
210
+		if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) {
211 211
 			$ip = gethostbyname($host);
212 212
 			if ($ip === $host) {
213 213
 				// Error condition for gethostbyname()
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 			}
229 229
 		}
230 230
 		if ($ip) {
231
-			if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
231
+			if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
232 232
 				return false;
233 233
 			}
234 234
 		}
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	}
240 240
 
241 241
 	$port = $parsed_url['port'];
242
-	if ($port === 80  or $port === 443  or $port === 8080) {
242
+	if ($port === 80 or $port === 443 or $port === 8080) {
243 243
 		return $url;
244 244
 	}
245 245
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 				}
310 310
 			}
311 311
 			if ($taille > 500) {
312
-				$boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8);
312
+				$boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8);
313 313
 			}
314 314
 		}
315 315
 
@@ -337,16 +337,16 @@  discard block
 block discarded – undo
337 337
 			}
338 338
 		} else {
339 339
 			// fabrique une chaine HTTP simple pour un POST
340
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
340
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
341 341
 			$chaine = [];
342 342
 			if (is_array($donnees)) {
343 343
 				foreach ($donnees as $cle => $valeur) {
344 344
 					if (is_array($valeur)) {
345 345
 						foreach ($valeur as $val2) {
346
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
346
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
347 347
 						}
348 348
 					} else {
349
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
349
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
350 350
 					}
351 351
 				}
352 352
 				$chaine = implode('&', $chaine);
@@ -451,13 +451,13 @@  discard block
 block discarded – undo
451 451
 		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
452 452
 	}
453 453
 
454
-	spip_log("recuperer_url " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
454
+	spip_log("recuperer_url ".$options['methode']." sur $url", 'distant'._LOG_DEBUG);
455 455
 
456 456
 	// Ajout des en-têtes spécifiques si besoin
457 457
 	$formatted_data = '';
458 458
 	if (!empty($options['headers'])) {
459 459
 		foreach ($options['headers'] as $champ => $valeur) {
460
-			$formatted_data .= $champ . ': ' . $valeur . "\r\n";
460
+			$formatted_data .= $champ.': '.$valeur."\r\n";
461 461
 		}
462 462
 	}
463 463
 
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 		[$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']);
466 466
 		$head .= $formatted_data;
467 467
 		if (stripos($head, 'Content-Length:') === false) {
468
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
468
+			$head .= 'Content-Length: '.strlen($postdata)."\r\n";
469 469
 		}
470
-		$formatted_data = $head . "\r\n" . $postdata;
470
+		$formatted_data = $head."\r\n".$postdata;
471 471
 		if (
472 472
 			strlen($postdata)
473 473
 			and !$methode_demandee
@@ -481,9 +481,9 @@  discard block
 block discarded – undo
481 481
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
482 482
 	$url = preg_replace(',^feed://,i', 'http://', $url);
483 483
 	if (!tester_url_absolue($url)) {
484
-		$url = 'http://' . $url;
484
+		$url = 'http://'.$url;
485 485
 	} elseif (strncmp($url, '//', 2) == 0) {
486
-		$url = 'http:' . $url;
486
+		$url = 'http:'.$url;
487 487
 	}
488 488
 
489 489
 	$url = url_to_ascii($url);
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 		$options['if_modified_since']
513 513
 	);
514 514
 	if (!$handle) {
515
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
515
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
516 516
 
517 517
 		return false;
518 518
 	}
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 					'status' => 200,
543 543
 				];
544 544
 			} else {
545
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
545
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
546 546
 				return false;
547 547
 			}
548 548
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -558,11 +558,11 @@  discard block
 block discarded – undo
558 558
 					$options['datas'] = '';
559 559
 				}
560 560
 			}
561
-			spip_log("recuperer_url recommence " . $options['methode']. " sur $url", 'distant' . _LOG_DEBUG);
561
+			spip_log("recuperer_url recommence ".$options['methode']." sur $url", 'distant'._LOG_DEBUG);
562 562
 
563 563
 			return recuperer_url($url, $options);
564 564
 		} elseif ($res['status'] !== 200) {
565
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
565
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
566 566
 		}
567 567
 		$result['status'] = $res['status'];
568 568
 		if (isset($res['headers'])) {
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 
579 579
 	// on ne veut que les entetes
580 580
 	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
581
-		spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG);
581
+		spip_log("RESULTAT recuperer_url ".$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG);
582 582
 		return $result;
583 583
 	}
584 584
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 
589 589
 	$gz = false;
590 590
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
591
-		$gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz');
591
+		$gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz');
592 592
 	}
593 593
 
594 594
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 
625 625
 	$trace = json_decode(json_encode($result), true);
626 626
 	$trace['page'] = '...';
627
-	spip_log("RESULTAT recuperer_url " . $options['methode']. " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG);
627
+	spip_log("RESULTAT recuperer_url ".$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG);
628 628
 
629 629
 	return $result;
630 630
 }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 	$sig['url'] = $url;
679 679
 
680 680
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
681
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
681
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
682 682
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
683 683
 	$cache = "$sub$cache";
684 684
 
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 	$fp = false;
733 733
 	if ($fichier) {
734 734
 		include_spip('inc/acces');
735
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
735
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
736 736
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
737 737
 		if (!$fp and file_exists($fichier)) {
738 738
 			return filesize($fichier);
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	}
792 792
 	$result['status'] = intval($r[1]);
793 793
 	while ($s = trim(fgets($handle, 16384))) {
794
-		$result['headers'][] = $s . "\n";
794
+		$result['headers'][] = $s."\n";
795 795
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
796 796
 		[, $d, $v] = $r;
797 797
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -840,13 +840,13 @@  discard block
 block discarded – undo
840 840
 
841 841
 	// on se place tout le temps comme si on etait a la racine
842 842
 	if (_DIR_RACINE) {
843
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
843
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
844 844
 	}
845 845
 
846 846
 	$m = md5($source);
847 847
 
848 848
 	return $d
849
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
849
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
850 850
 	. substr($m, 0, 4)
851 851
 	. ".$extension";
852 852
 }
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 	// Si c'est deja local pas de souci
870 870
 	if (!tester_url_absolue($source)) {
871 871
 		if (_DIR_RACINE) {
872
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
872
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
873 873
 		}
874 874
 
875 875
 		return $source;
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 		$ext
888 888
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
889 889
 		and $f = nom_fichier_copie_locale($source, $ext)
890
-		and file_exists(_DIR_RACINE . $f)
890
+		and file_exists(_DIR_RACINE.$f)
891 891
 	) {
892 892
 		return $f;
893 893
 	}
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 
896 896
 	// Si c'est deja dans la table des documents,
897 897
 	// ramener le nom de sa copie potentielle
898
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
898
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
899 899
 
900 900
 	if ($ext) {
901 901
 		return nom_fichier_copie_locale($source, $ext);
@@ -906,9 +906,9 @@  discard block
 block discarded – undo
906 906
 
907 907
 	$ext = $path_parts ? $path_parts['extension'] : '';
908 908
 
909
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
909
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
910 910
 		$f = nom_fichier_copie_locale($source, $ext);
911
-		if (file_exists(_DIR_RACINE . $f)) {
911
+		if (file_exists(_DIR_RACINE.$f)) {
912 912
 			return $f;
913 913
 		}
914 914
 	}
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
 	// Ping  pour voir si son extension est connue et autorisee
917 917
 	// avec mise en cache du resultat du ping
918 918
 
919
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
919
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
920 920
 	if (
921 921
 		!@file_exists($cache)
922 922
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
@@ -926,10 +926,10 @@  discard block
 block discarded – undo
926 926
 		ecrire_fichier($cache, serialize($path_parts));
927 927
 	}
928 928
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
929
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
929
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
930 930
 		return nom_fichier_copie_locale($source, $ext);
931 931
 	}
932
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
932
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
933 933
 }
934 934
 
935 935
 
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 		} else {
1014 1014
 			if ($a['body']) {
1015 1015
 				$a['extension'] = $extension;
1016
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1016
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1017 1017
 				ecrire_fichier($a['fichier'], $a['body']);
1018 1018
 				$size_image = @spip_getimagesize($a['fichier']);
1019 1019
 				$a['largeur'] = intval($size_image[0]);
@@ -1081,20 +1081,20 @@  discard block
 block discarded – undo
1081 1081
 			!$t
1082 1082
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1083 1083
 		) {
1084
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1084
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1085 1085
 		}
1086 1086
 		if (
1087 1087
 			!$t
1088 1088
 			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1089 1089
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1090 1090
 		) {
1091
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1091
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1092 1092
 		}
1093 1093
 	}
1094 1094
 
1095 1095
 	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1096 1096
 	if (!$t) {
1097
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1097
+		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1098 1098
 	}
1099 1099
 
1100 1100
 	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1105,11 +1105,11 @@  discard block
 block discarded – undo
1105 1105
 		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1106 1106
 	) {
1107 1107
 		# eviter xxx.3 => 3gp (> SPIP 3)
1108
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text'));
1108
+		$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text'));
1109 1109
 	}
1110 1110
 
1111 1111
 	if ($t) {
1112
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1112
+		spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1113 1113
 		return $t['extension'];
1114 1114
 	} else {
1115 1115
 		# par defaut on retombe sur '.bin' si c'est autorise
@@ -1212,7 +1212,7 @@  discard block
 block discarded – undo
1212 1212
 		}
1213 1213
 	} else {
1214 1214
 		$scheme = $t['scheme'];
1215
-		$noproxy = $scheme . '://';
1215
+		$noproxy = $scheme.'://';
1216 1216
 	}
1217 1217
 	if (isset($t['user'])) {
1218 1218
 		$user = [$t['user'], $t['pass']];
@@ -1226,7 +1226,7 @@  discard block
 block discarded – undo
1226 1226
 	}
1227 1227
 
1228 1228
 	if (!empty($t['query'])) {
1229
-		$path .= '?' . $t['query'];
1229
+		$path .= '?'.$t['query'];
1230 1230
 	}
1231 1231
 
1232 1232
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1300,29 +1300,29 @@  discard block
 block discarded – undo
1300 1300
 	$proxy_user = '';
1301 1301
 	$http_proxy = need_proxy($host);
1302 1302
 	if ($user) {
1303
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1303
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1304 1304
 	}
1305 1305
 
1306 1306
 	$connect = '';
1307 1307
 	if ($http_proxy) {
1308
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1309
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1310
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1308
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) {
1309
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1310
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1311 1311
 				. "Host: $path_host\r\n"
1312 1312
 				. "Proxy-Connection: Keep-Alive\r\n";
1313 1313
 		} else {
1314
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1314
+			$path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://")
1315 1315
 				. (!$user ? '' : "$user@")
1316
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1316
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1317 1317
 		}
1318 1318
 		$t2 = @parse_url($http_proxy);
1319 1319
 		$first_host = $t2['host'];
1320 1320
 		$port = ($t2['port'] ?? null) ?: 80;
1321 1321
 		if ($t2['user'] ?? null) {
1322
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1322
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1323 1323
 		}
1324 1324
 	} else {
1325
-		$first_host = $noproxy . $host;
1325
+		$first_host = $noproxy.$host;
1326 1326
 	}
1327 1327
 
1328 1328
 	if ($connect) {
@@ -1344,7 +1344,7 @@  discard block
 block discarded – undo
1344 1344
 		);
1345 1345
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1346 1346
 		if (!$f) {
1347
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1347
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1348 1348
 			return $errno;
1349 1349
 		}
1350 1350
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1357,7 +1357,7 @@  discard block
 block discarded – undo
1357 1357
 			or !count($res = explode(' ', $res))
1358 1358
 			or $res[1] !== '200'
1359 1359
 		) {
1360
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1360
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1361 1361
 			fclose($f);
1362 1362
 
1363 1363
 			return false;
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1375 1375
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1376 1376
 		if (!$f) {
1377
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1377
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1378 1378
 
1379 1379
 			return $errno;
1380 1380
 		}
@@ -1384,16 +1384,16 @@  discard block
 block discarded – undo
1384 1384
 	$site = $GLOBALS['meta']['adresse_site'] ?? '';
1385 1385
 
1386 1386
 	$host_port = $host;
1387
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1387
+	if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) {
1388 1388
 		$host_port .= ":$port";
1389 1389
 	}
1390 1390
 	$req = "$method $path $vers\r\n"
1391 1391
 		. "Host: $host_port\r\n"
1392
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1393
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1392
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1393
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1394 1394
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1395
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1396
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1395
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1396
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1397 1397
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1398 1398
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1399 1399
 
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2280 added lines, -2281 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 ($url && 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 ($url && 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
 
@@ -2424,23 +2423,23 @@  discard block
 block discarded – undo
2424 2423
  *     URL
2425 2424
  */
2426 2425
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2427
-	if (is_null($public)) {
2428
-		$public = (_DIR_RACINE ? false : '');
2429
-	}
2430
-	if (substr($script, -4) !== '.api') {
2431
-		$script .= '.api';
2432
-	}
2433
-	$url =
2434
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2435
-	. $script . '/'
2436
-	. ($path ? trim($path, '/') : '')
2437
-	. ($args ? "?" . quote_amp($args) : '');
2426
+    if (is_null($public)) {
2427
+        $public = (_DIR_RACINE ? false : '');
2428
+    }
2429
+    if (substr($script, -4) !== '.api') {
2430
+        $script .= '.api';
2431
+    }
2432
+    $url =
2433
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2434
+    . $script . '/'
2435
+    . ($path ? trim($path, '/') : '')
2436
+    . ($args ? "?" . quote_amp($args) : '');
2438 2437
 
2439
-	if ($no_entities) {
2440
-		$url = str_replace('&amp;', '&', $url);
2441
-	}
2438
+    if ($no_entities) {
2439
+        $url = str_replace('&amp;', '&', $url);
2440
+    }
2442 2441
 
2443
-	return $url;
2442
+    return $url;
2444 2443
 }
2445 2444
 
2446 2445
 
@@ -2453,8 +2452,8 @@  discard block
 block discarded – undo
2453 2452
  * @param string $ta Répertoire temporaire accessible
2454 2453
  */
2455 2454
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2456
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2457
-	spip_initialisation_suite();
2455
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2456
+    spip_initialisation_suite();
2458 2457
 }
2459 2458
 
2460 2459
 /**
@@ -2474,322 +2473,322 @@  discard block
 block discarded – undo
2474 2473
  * @param string $ta Répertoire temporaire accessible
2475 2474
  */
2476 2475
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2477
-	static $too_late = 0;
2478
-	if ($too_late++) {
2479
-		return;
2480
-	}
2481
-
2482
-	// Declaration des repertoires
2483
-
2484
-	// le nom du repertoire plugins/ activables/desactivables
2485
-	if (!defined('_DIR_PLUGINS')) {
2486
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2487
-	}
2488
-
2489
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2490
-	if (!defined('_DIR_PLUGINS_DIST')) {
2491
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2492
-	}
2493
-
2494
-	// le nom du repertoire des librairies
2495
-	if (!defined('_DIR_LIB')) {
2496
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2497
-	}
2498
-
2499
-	if (!defined('_DIR_IMG')) {
2500
-		define('_DIR_IMG', $pa);
2501
-	}
2502
-	if (!defined('_DIR_LOGOS')) {
2503
-		define('_DIR_LOGOS', $pa);
2504
-	}
2505
-	if (!defined('_DIR_IMG_ICONES')) {
2506
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2507
-	}
2508
-
2509
-	if (!defined('_DIR_DUMP')) {
2510
-		define('_DIR_DUMP', $ti . 'dump/');
2511
-	}
2512
-	if (!defined('_DIR_SESSIONS')) {
2513
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2514
-	}
2515
-	if (!defined('_DIR_TRANSFERT')) {
2516
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2517
-	}
2518
-	if (!defined('_DIR_CACHE')) {
2519
-		define('_DIR_CACHE', $ti . 'cache/');
2520
-	}
2521
-	if (!defined('_DIR_CACHE_XML')) {
2522
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2523
-	}
2524
-	if (!defined('_DIR_SKELS')) {
2525
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2526
-	}
2527
-	if (!defined('_DIR_AIDE')) {
2528
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2529
-	}
2530
-	if (!defined('_DIR_TMP')) {
2531
-		define('_DIR_TMP', $ti);
2532
-	}
2533
-
2534
-	if (!defined('_DIR_VAR')) {
2535
-		define('_DIR_VAR', $ta);
2536
-	}
2537
-
2538
-	if (!defined('_DIR_ETC')) {
2539
-		define('_DIR_ETC', $pi);
2540
-	}
2541
-	if (!defined('_DIR_CONNECT')) {
2542
-		define('_DIR_CONNECT', $pi);
2543
-	}
2544
-	if (!defined('_DIR_CHMOD')) {
2545
-		define('_DIR_CHMOD', $pi);
2546
-	}
2547
-
2548
-	if (!isset($GLOBALS['test_dirs'])) {
2549
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2550
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2551
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2552
-	}
2553
-
2554
-	// Declaration des fichiers
2555
-
2556
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2557
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2558
-	}
2559
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2560
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2561
-	}
2562
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2563
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2564
-	}
2565
-	if (!defined('_CACHE_PIPELINES')) {
2566
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2567
-	}
2568
-	if (!defined('_CACHE_CHEMIN')) {
2569
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2570
-	}
2571
-
2572
-	# attention .php obligatoire pour ecrire_fichier_securise
2573
-	if (!defined('_FILE_META')) {
2574
-		define('_FILE_META', $ti . 'meta_cache.php');
2575
-	}
2576
-	if (!defined('_DIR_LOG')) {
2577
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2578
-	}
2579
-	if (!defined('_FILE_LOG')) {
2580
-		define('_FILE_LOG', 'spip');
2581
-	}
2582
-	if (!defined('_FILE_LOG_SUFFIX')) {
2583
-		define('_FILE_LOG_SUFFIX', '.log');
2584
-	}
2585
-
2586
-	// Le fichier de connexion a la base de donnees
2587
-	// tient compte des anciennes versions (inc_connect...)
2588
-	if (!defined('_FILE_CONNECT_INS')) {
2589
-		define('_FILE_CONNECT_INS', 'connect');
2590
-	}
2591
-	if (!defined('_FILE_CONNECT')) {
2592
-		define(
2593
-			'_FILE_CONNECT',
2594
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2595
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2596
-			: false))
2597
-		);
2598
-	}
2599
-
2600
-	// Le fichier de reglages des droits
2601
-	if (!defined('_FILE_CHMOD_INS')) {
2602
-		define('_FILE_CHMOD_INS', 'chmod');
2603
-	}
2604
-	if (!defined('_FILE_CHMOD')) {
2605
-		define(
2606
-			'_FILE_CHMOD',
2607
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2608
-			: false)
2609
-		);
2610
-	}
2611
-
2612
-	if (!defined('_FILE_LDAP')) {
2613
-		define('_FILE_LDAP', 'ldap.php');
2614
-	}
2615
-
2616
-	if (!defined('_FILE_TMP_SUFFIX')) {
2617
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2618
-	}
2619
-	if (!defined('_FILE_CONNECT_TMP')) {
2620
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2621
-	}
2622
-	if (!defined('_FILE_CHMOD_TMP')) {
2623
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2624
-	}
2625
-
2626
-	// Definition des droits d'acces en ecriture
2627
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2628
-		include_once _FILE_CHMOD;
2629
-	}
2630
-
2631
-	// Se mefier des fichiers mal remplis!
2632
-	if (!defined('_SPIP_CHMOD')) {
2633
-		define('_SPIP_CHMOD', 0777);
2634
-	}
2635
-
2636
-	if (!defined('_DEFAULT_CHARSET')) {
2637
-		/** Le charset par défaut lors de l'installation */
2638
-		define('_DEFAULT_CHARSET', 'utf-8');
2639
-	}
2640
-	if (!defined('_ROOT_PLUGINS')) {
2641
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2642
-	}
2643
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2644
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2645
-	}
2646
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2647
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2648
-	}
2649
-
2650
-	// La taille des Log
2651
-	if (!defined('_MAX_LOG')) {
2652
-		define('_MAX_LOG', 100);
2653
-	}
2654
-
2655
-	// Sommes-nous dans l'empire du Mal ?
2656
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2657
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2658
-		if (!defined('_OS_SERVEUR')) {
2659
-			define('_OS_SERVEUR', 'windows');
2660
-		}
2661
-		if (!defined('_SPIP_LOCK_MODE')) {
2662
-			define('_SPIP_LOCK_MODE', 1);
2663
-		} // utiliser le flock php
2664
-	} else {
2665
-		if (!defined('_OS_SERVEUR')) {
2666
-			define('_OS_SERVEUR', '');
2667
-		}
2668
-		if (!defined('_SPIP_LOCK_MODE')) {
2669
-			define('_SPIP_LOCK_MODE', 1);
2670
-		} // utiliser le flock php
2671
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2672
-	}
2673
-
2674
-	// Langue par defaut
2675
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2676
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2677
-	}
2678
-
2679
-	//
2680
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2681
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2682
-	// pour le rendre surchargeable, on va provoquer un reecriture
2683
-	// systematique du noyau ou une baisse de perfs => a etudier)
2684
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2685
-
2686
-	// charger tout de suite le path et son cache
2687
-	load_path_cache();
2688
-
2689
-	// *********** traiter les variables ************
2690
-
2691
-	//
2692
-	// Securite
2693
-	//
2694
-
2695
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2696
-	if (isset($_REQUEST['GLOBALS'])) {
2697
-		die();
2698
-	}
2699
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2700
-	spip_desinfecte($_GET);
2701
-	spip_desinfecte($_POST);
2702
-	spip_desinfecte($_COOKIE);
2703
-	spip_desinfecte($_REQUEST);
2704
-
2705
-	// appliquer le cookie_prefix
2706
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2707
-		include_spip('inc/cookie');
2708
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2709
-	}
2710
-
2711
-	//
2712
-	// Capacites php (en fonction de la version)
2713
-	//
2714
-	$GLOBALS['flag_ob'] = (function_exists('ob_start')
2715
-		&& function_exists('ini_get')
2716
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2717
-	$GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2718
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2719
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2720
-		(get_cfg_var('upload_max_filesize') > 0));
2721
-
2722
-
2723
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2724
-	if (isset($_SERVER['REQUEST_URI'])) {
2725
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2726
-	} else {
2727
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2728
-		if (
2729
-			!empty($_SERVER['QUERY_STRING'])
2730
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2731
-		) {
2732
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2733
-		}
2734
-	}
2735
-
2736
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2737
-	if (!defined('_RENOUVELLE_ALEA')) {
2738
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2739
-	}
2740
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2741
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2742
-	}
2743
-
2744
-	// charger les meta si possible et renouveller l'alea au besoin
2745
-	// charge aussi effacer_meta et ecrire_meta
2746
-	$inc_meta = charger_fonction('meta', 'inc');
2747
-	$inc_meta();
2748
-
2749
-	// nombre de repertoires depuis la racine
2750
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2751
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2752
-	// le calcul est faux)
2753
-	if (!_DIR_RESTREINT) {
2754
-		$GLOBALS['profondeur_url'] = 1;
2755
-	} else {
2756
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2757
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2758
-		if (
2759
-			!$uri_ref
2760
-			// si on est appele avec un autre ti, on est sans doute en mutu
2761
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2762
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2763
-			// s'en remettre a l'adresse du site. alea jacta est.
2764
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2765
-		) {
2766
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2767
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2768
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2769
-			} else {
2770
-				$uri_ref = '';
2771
-			}
2772
-		}
2773
-		if (!$uri or !$uri_ref) {
2774
-			$GLOBALS['profondeur_url'] = 0;
2775
-		} else {
2776
-			$GLOBALS['profondeur_url'] = max(
2777
-				0,
2778
-				substr_count($uri[0], '/')
2779
-				- substr_count($uri_ref, '/')
2780
-			);
2781
-		}
2782
-	}
2783
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2784
-	if (_FILE_CONNECT) {
2785
-		if (
2786
-			verifier_visiteur() == '0minirezo'
2787
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2788
-			and !isset($_COOKIE['spip_admin'])
2789
-		) {
2790
-			clear_path_cache();
2791
-		}
2792
-	}
2476
+    static $too_late = 0;
2477
+    if ($too_late++) {
2478
+        return;
2479
+    }
2480
+
2481
+    // Declaration des repertoires
2482
+
2483
+    // le nom du repertoire plugins/ activables/desactivables
2484
+    if (!defined('_DIR_PLUGINS')) {
2485
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2486
+    }
2487
+
2488
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2489
+    if (!defined('_DIR_PLUGINS_DIST')) {
2490
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2491
+    }
2492
+
2493
+    // le nom du repertoire des librairies
2494
+    if (!defined('_DIR_LIB')) {
2495
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2496
+    }
2497
+
2498
+    if (!defined('_DIR_IMG')) {
2499
+        define('_DIR_IMG', $pa);
2500
+    }
2501
+    if (!defined('_DIR_LOGOS')) {
2502
+        define('_DIR_LOGOS', $pa);
2503
+    }
2504
+    if (!defined('_DIR_IMG_ICONES')) {
2505
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2506
+    }
2507
+
2508
+    if (!defined('_DIR_DUMP')) {
2509
+        define('_DIR_DUMP', $ti . 'dump/');
2510
+    }
2511
+    if (!defined('_DIR_SESSIONS')) {
2512
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2513
+    }
2514
+    if (!defined('_DIR_TRANSFERT')) {
2515
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2516
+    }
2517
+    if (!defined('_DIR_CACHE')) {
2518
+        define('_DIR_CACHE', $ti . 'cache/');
2519
+    }
2520
+    if (!defined('_DIR_CACHE_XML')) {
2521
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2522
+    }
2523
+    if (!defined('_DIR_SKELS')) {
2524
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2525
+    }
2526
+    if (!defined('_DIR_AIDE')) {
2527
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2528
+    }
2529
+    if (!defined('_DIR_TMP')) {
2530
+        define('_DIR_TMP', $ti);
2531
+    }
2532
+
2533
+    if (!defined('_DIR_VAR')) {
2534
+        define('_DIR_VAR', $ta);
2535
+    }
2536
+
2537
+    if (!defined('_DIR_ETC')) {
2538
+        define('_DIR_ETC', $pi);
2539
+    }
2540
+    if (!defined('_DIR_CONNECT')) {
2541
+        define('_DIR_CONNECT', $pi);
2542
+    }
2543
+    if (!defined('_DIR_CHMOD')) {
2544
+        define('_DIR_CHMOD', $pi);
2545
+    }
2546
+
2547
+    if (!isset($GLOBALS['test_dirs'])) {
2548
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2549
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2550
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2551
+    }
2552
+
2553
+    // Declaration des fichiers
2554
+
2555
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2556
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2557
+    }
2558
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2559
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2560
+    }
2561
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2562
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2563
+    }
2564
+    if (!defined('_CACHE_PIPELINES')) {
2565
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2566
+    }
2567
+    if (!defined('_CACHE_CHEMIN')) {
2568
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2569
+    }
2570
+
2571
+    # attention .php obligatoire pour ecrire_fichier_securise
2572
+    if (!defined('_FILE_META')) {
2573
+        define('_FILE_META', $ti . 'meta_cache.php');
2574
+    }
2575
+    if (!defined('_DIR_LOG')) {
2576
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2577
+    }
2578
+    if (!defined('_FILE_LOG')) {
2579
+        define('_FILE_LOG', 'spip');
2580
+    }
2581
+    if (!defined('_FILE_LOG_SUFFIX')) {
2582
+        define('_FILE_LOG_SUFFIX', '.log');
2583
+    }
2584
+
2585
+    // Le fichier de connexion a la base de donnees
2586
+    // tient compte des anciennes versions (inc_connect...)
2587
+    if (!defined('_FILE_CONNECT_INS')) {
2588
+        define('_FILE_CONNECT_INS', 'connect');
2589
+    }
2590
+    if (!defined('_FILE_CONNECT')) {
2591
+        define(
2592
+            '_FILE_CONNECT',
2593
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2594
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2595
+            : false))
2596
+        );
2597
+    }
2598
+
2599
+    // Le fichier de reglages des droits
2600
+    if (!defined('_FILE_CHMOD_INS')) {
2601
+        define('_FILE_CHMOD_INS', 'chmod');
2602
+    }
2603
+    if (!defined('_FILE_CHMOD')) {
2604
+        define(
2605
+            '_FILE_CHMOD',
2606
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2607
+            : false)
2608
+        );
2609
+    }
2610
+
2611
+    if (!defined('_FILE_LDAP')) {
2612
+        define('_FILE_LDAP', 'ldap.php');
2613
+    }
2614
+
2615
+    if (!defined('_FILE_TMP_SUFFIX')) {
2616
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2617
+    }
2618
+    if (!defined('_FILE_CONNECT_TMP')) {
2619
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2620
+    }
2621
+    if (!defined('_FILE_CHMOD_TMP')) {
2622
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2623
+    }
2624
+
2625
+    // Definition des droits d'acces en ecriture
2626
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2627
+        include_once _FILE_CHMOD;
2628
+    }
2629
+
2630
+    // Se mefier des fichiers mal remplis!
2631
+    if (!defined('_SPIP_CHMOD')) {
2632
+        define('_SPIP_CHMOD', 0777);
2633
+    }
2634
+
2635
+    if (!defined('_DEFAULT_CHARSET')) {
2636
+        /** Le charset par défaut lors de l'installation */
2637
+        define('_DEFAULT_CHARSET', 'utf-8');
2638
+    }
2639
+    if (!defined('_ROOT_PLUGINS')) {
2640
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2641
+    }
2642
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2643
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2644
+    }
2645
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2646
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2647
+    }
2648
+
2649
+    // La taille des Log
2650
+    if (!defined('_MAX_LOG')) {
2651
+        define('_MAX_LOG', 100);
2652
+    }
2653
+
2654
+    // Sommes-nous dans l'empire du Mal ?
2655
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2656
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2657
+        if (!defined('_OS_SERVEUR')) {
2658
+            define('_OS_SERVEUR', 'windows');
2659
+        }
2660
+        if (!defined('_SPIP_LOCK_MODE')) {
2661
+            define('_SPIP_LOCK_MODE', 1);
2662
+        } // utiliser le flock php
2663
+    } else {
2664
+        if (!defined('_OS_SERVEUR')) {
2665
+            define('_OS_SERVEUR', '');
2666
+        }
2667
+        if (!defined('_SPIP_LOCK_MODE')) {
2668
+            define('_SPIP_LOCK_MODE', 1);
2669
+        } // utiliser le flock php
2670
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2671
+    }
2672
+
2673
+    // Langue par defaut
2674
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2675
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2676
+    }
2677
+
2678
+    //
2679
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2680
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2681
+    // pour le rendre surchargeable, on va provoquer un reecriture
2682
+    // systematique du noyau ou une baisse de perfs => a etudier)
2683
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2684
+
2685
+    // charger tout de suite le path et son cache
2686
+    load_path_cache();
2687
+
2688
+    // *********** traiter les variables ************
2689
+
2690
+    //
2691
+    // Securite
2692
+    //
2693
+
2694
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2695
+    if (isset($_REQUEST['GLOBALS'])) {
2696
+        die();
2697
+    }
2698
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2699
+    spip_desinfecte($_GET);
2700
+    spip_desinfecte($_POST);
2701
+    spip_desinfecte($_COOKIE);
2702
+    spip_desinfecte($_REQUEST);
2703
+
2704
+    // appliquer le cookie_prefix
2705
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2706
+        include_spip('inc/cookie');
2707
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2708
+    }
2709
+
2710
+    //
2711
+    // Capacites php (en fonction de la version)
2712
+    //
2713
+    $GLOBALS['flag_ob'] = (function_exists('ob_start')
2714
+        && function_exists('ini_get')
2715
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2716
+    $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2717
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2718
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2719
+        (get_cfg_var('upload_max_filesize') > 0));
2720
+
2721
+
2722
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2723
+    if (isset($_SERVER['REQUEST_URI'])) {
2724
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2725
+    } else {
2726
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2727
+        if (
2728
+            !empty($_SERVER['QUERY_STRING'])
2729
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2730
+        ) {
2731
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2732
+        }
2733
+    }
2734
+
2735
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2736
+    if (!defined('_RENOUVELLE_ALEA')) {
2737
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2738
+    }
2739
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2740
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2741
+    }
2742
+
2743
+    // charger les meta si possible et renouveller l'alea au besoin
2744
+    // charge aussi effacer_meta et ecrire_meta
2745
+    $inc_meta = charger_fonction('meta', 'inc');
2746
+    $inc_meta();
2747
+
2748
+    // nombre de repertoires depuis la racine
2749
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2750
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2751
+    // le calcul est faux)
2752
+    if (!_DIR_RESTREINT) {
2753
+        $GLOBALS['profondeur_url'] = 1;
2754
+    } else {
2755
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2756
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2757
+        if (
2758
+            !$uri_ref
2759
+            // si on est appele avec un autre ti, on est sans doute en mutu
2760
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2761
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2762
+            // s'en remettre a l'adresse du site. alea jacta est.
2763
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2764
+        ) {
2765
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2766
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2767
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2768
+            } else {
2769
+                $uri_ref = '';
2770
+            }
2771
+        }
2772
+        if (!$uri or !$uri_ref) {
2773
+            $GLOBALS['profondeur_url'] = 0;
2774
+        } else {
2775
+            $GLOBALS['profondeur_url'] = max(
2776
+                0,
2777
+                substr_count($uri[0], '/')
2778
+                - substr_count($uri_ref, '/')
2779
+            );
2780
+        }
2781
+    }
2782
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2783
+    if (_FILE_CONNECT) {
2784
+        if (
2785
+            verifier_visiteur() == '0minirezo'
2786
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2787
+            and !isset($_COOKIE['spip_admin'])
2788
+        ) {
2789
+            clear_path_cache();
2790
+        }
2791
+    }
2793 2792
 }
2794 2793
 
2795 2794
 /**
@@ -2798,190 +2797,190 @@  discard block
 block discarded – undo
2798 2797
  *
2799 2798
  */
2800 2799
 function spip_initialisation_suite() {
2801
-	static $too_late = 0;
2802
-	if ($too_late++) {
2803
-		return;
2804
-	}
2805
-
2806
-	// taille mini des login
2807
-	if (!defined('_LOGIN_TROP_COURT')) {
2808
-		define('_LOGIN_TROP_COURT', 4);
2809
-	}
2810
-
2811
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2812
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2813
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2814
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2815
-
2816
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2817
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2818
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2819
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2820
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2821
-
2822
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2823
-		define('_PASS_LONGUEUR_MINI', 6);
2824
-	}
2825
-
2826
-	// largeur maximale des images dans l'administration
2827
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2828
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2829
-	}
2830
-
2831
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2832
-	if (!defined('_IMG_QUALITE')) {
2833
-		define('_IMG_QUALITE', 85);
2834
-	} # valeur par defaut
2835
-	if (!defined('_IMG_GD_QUALITE')) {
2836
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2837
-	} # surcharge pour la lib GD
2838
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2839
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2840
-	} # surcharge pour imagick en ligne de commande
2841
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2842
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2843
-		define('_IMG_IMAGICK_QUALITE', 75);
2844
-	} # surcharge pour imagick en PHP
2845
-
2846
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2847
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2848
-	} // poids en octet
2849
-
2850
-	// qq chaines standard
2851
-	if (!defined('_ACCESS_FILE_NAME')) {
2852
-		define('_ACCESS_FILE_NAME', '.htaccess');
2853
-	}
2854
-	if (!defined('_AUTH_USER_FILE')) {
2855
-		define('_AUTH_USER_FILE', '.htpasswd');
2856
-	}
2857
-	if (!defined('_SPIP_DUMP')) {
2858
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2859
-	}
2860
-	if (!defined('_CACHE_RUBRIQUES')) {
2861
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2862
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2863
-	}
2864
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2865
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2866
-		define('_CACHE_RUBRIQUES_MAX', 500);
2867
-	}
2868
-
2869
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2870
-		/**
2871
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2872
-		 * @var int Nombre de caractères */
2873
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2874
-	}
2875
-
2876
-	if (!defined('_EXTENSION_SQUELETTES')) {
2877
-		define('_EXTENSION_SQUELETTES', 'html');
2878
-	}
2879
-
2880
-	if (!defined('_DOCTYPE_ECRIRE')) {
2881
-		/** Définit le doctype de l’espace privé */
2882
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2883
-	}
2884
-	if (!defined('_DOCTYPE_AIDE')) {
2885
-		/** Définit le doctype de l’aide en ligne */
2886
-		define(
2887
-			'_DOCTYPE_AIDE',
2888
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2889
-		);
2890
-	}
2891
-
2892
-	if (!defined('_SPIP_SCRIPT')) {
2893
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2894
-		 * le script de l'espace public, alias index.php */
2895
-		define('_SPIP_SCRIPT', 'spip.php');
2896
-	}
2897
-	if (!defined('_SPIP_PAGE')) {
2898
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2899
-		define('_SPIP_PAGE', 'page');
2900
-	}
2901
-
2902
-	// le script de l'espace prive
2903
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2904
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2905
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2906
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2907
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2908
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2909
-		} else {
2910
-			define('_SPIP_ECRIRE_SCRIPT', '');
2911
-		}
2912
-	}
2913
-
2914
-
2915
-	if (!defined('_SPIP_AJAX')) {
2916
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2917
-			? 1
2918
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2919
-	}
2920
-
2921
-	// La requete est-elle en ajax ?
2922
-	if (!defined('_AJAX')) {
2923
-		define(
2924
-			'_AJAX',
2925
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2926
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2927
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2928
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2929
-			)
2930
-			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
2931
-		);
2932
-	}
2933
-
2934
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2935
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2936
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2937
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2938
-		define(
2939
-			'_IMG_GD_MAX_PIXELS',
2940
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2941
-			? $GLOBALS['meta']['max_taille_vignettes']
2942
-			: 0
2943
-		);
2944
-	}
2945
-
2946
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2947
-		define('_MEMORY_LIMIT_MIN', 16);
2948
-	} // en Mo
2949
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2950
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2951
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2952
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2953
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2954
-			$unit = strtolower(substr($memory, -1));
2955
-			$memory = substr($memory, 0, -1);
2956
-			switch ($unit) {
2957
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2958
-				case 'g':
2959
-					$memory *= 1024;
2960
-				case 'm':
2961
-					$memory *= 1024;
2962
-				case 'k':
2963
-					$memory *= 1024;
2964
-			}
2965
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2966
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2967
-				if (trim(ini_get('memory_limit')) != $m) {
2968
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2969
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2970
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2971
-				}
2972
-			}
2973
-		} else {
2974
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2975
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2976
-			}
2977
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2978
-	}
2979
-	// Protocoles a normaliser dans les chaines de langues
2980
-	if (!defined('_PROTOCOLES_STD')) {
2981
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2982
-	}
2983
-
2984
-	init_var_mode();
2800
+    static $too_late = 0;
2801
+    if ($too_late++) {
2802
+        return;
2803
+    }
2804
+
2805
+    // taille mini des login
2806
+    if (!defined('_LOGIN_TROP_COURT')) {
2807
+        define('_LOGIN_TROP_COURT', 4);
2808
+    }
2809
+
2810
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2811
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2812
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2813
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2814
+
2815
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2816
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2817
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2818
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2819
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2820
+
2821
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2822
+        define('_PASS_LONGUEUR_MINI', 6);
2823
+    }
2824
+
2825
+    // largeur maximale des images dans l'administration
2826
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2827
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2828
+    }
2829
+
2830
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2831
+    if (!defined('_IMG_QUALITE')) {
2832
+        define('_IMG_QUALITE', 85);
2833
+    } # valeur par defaut
2834
+    if (!defined('_IMG_GD_QUALITE')) {
2835
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2836
+    } # surcharge pour la lib GD
2837
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2838
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2839
+    } # surcharge pour imagick en ligne de commande
2840
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2841
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2842
+        define('_IMG_IMAGICK_QUALITE', 75);
2843
+    } # surcharge pour imagick en PHP
2844
+
2845
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2846
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2847
+    } // poids en octet
2848
+
2849
+    // qq chaines standard
2850
+    if (!defined('_ACCESS_FILE_NAME')) {
2851
+        define('_ACCESS_FILE_NAME', '.htaccess');
2852
+    }
2853
+    if (!defined('_AUTH_USER_FILE')) {
2854
+        define('_AUTH_USER_FILE', '.htpasswd');
2855
+    }
2856
+    if (!defined('_SPIP_DUMP')) {
2857
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2858
+    }
2859
+    if (!defined('_CACHE_RUBRIQUES')) {
2860
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2861
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2862
+    }
2863
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2864
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2865
+        define('_CACHE_RUBRIQUES_MAX', 500);
2866
+    }
2867
+
2868
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2869
+        /**
2870
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2871
+         * @var int Nombre de caractères */
2872
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2873
+    }
2874
+
2875
+    if (!defined('_EXTENSION_SQUELETTES')) {
2876
+        define('_EXTENSION_SQUELETTES', 'html');
2877
+    }
2878
+
2879
+    if (!defined('_DOCTYPE_ECRIRE')) {
2880
+        /** Définit le doctype de l’espace privé */
2881
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2882
+    }
2883
+    if (!defined('_DOCTYPE_AIDE')) {
2884
+        /** Définit le doctype de l’aide en ligne */
2885
+        define(
2886
+            '_DOCTYPE_AIDE',
2887
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2888
+        );
2889
+    }
2890
+
2891
+    if (!defined('_SPIP_SCRIPT')) {
2892
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2893
+         * le script de l'espace public, alias index.php */
2894
+        define('_SPIP_SCRIPT', 'spip.php');
2895
+    }
2896
+    if (!defined('_SPIP_PAGE')) {
2897
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2898
+        define('_SPIP_PAGE', 'page');
2899
+    }
2900
+
2901
+    // le script de l'espace prive
2902
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2903
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2904
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2905
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2906
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2907
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2908
+        } else {
2909
+            define('_SPIP_ECRIRE_SCRIPT', '');
2910
+        }
2911
+    }
2912
+
2913
+
2914
+    if (!defined('_SPIP_AJAX')) {
2915
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2916
+            ? 1
2917
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2918
+    }
2919
+
2920
+    // La requete est-elle en ajax ?
2921
+    if (!defined('_AJAX')) {
2922
+        define(
2923
+            '_AJAX',
2924
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2925
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2926
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2927
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2928
+            )
2929
+            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
2930
+        );
2931
+    }
2932
+
2933
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2934
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2935
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2936
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2937
+        define(
2938
+            '_IMG_GD_MAX_PIXELS',
2939
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2940
+            ? $GLOBALS['meta']['max_taille_vignettes']
2941
+            : 0
2942
+        );
2943
+    }
2944
+
2945
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2946
+        define('_MEMORY_LIMIT_MIN', 16);
2947
+    } // en Mo
2948
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2949
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2950
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2951
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2952
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2953
+            $unit = strtolower(substr($memory, -1));
2954
+            $memory = substr($memory, 0, -1);
2955
+            switch ($unit) {
2956
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2957
+                case 'g':
2958
+                    $memory *= 1024;
2959
+                case 'm':
2960
+                    $memory *= 1024;
2961
+                case 'k':
2962
+                    $memory *= 1024;
2963
+            }
2964
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2965
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2966
+                if (trim(ini_get('memory_limit')) != $m) {
2967
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2968
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2969
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2970
+                }
2971
+            }
2972
+        } else {
2973
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2974
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2975
+            }
2976
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2977
+    }
2978
+    // Protocoles a normaliser dans les chaines de langues
2979
+    if (!defined('_PROTOCOLES_STD')) {
2980
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2981
+    }
2982
+
2983
+    init_var_mode();
2985 2984
 }
2986 2985
 
2987 2986
 /**
@@ -3015,219 +3014,219 @@  discard block
 block discarded – undo
3015 3014
  * `   var_mode` (calcul ou recalcul).
3016 3015
  */
3017 3016
 function init_var_mode() {
3018
-	static $done = false;
3019
-	if (!$done) {
3020
-		if (isset($_GET['var_mode'])) {
3021
-			$var_mode = explode(',', $_GET['var_mode']);
3022
-			// tout le monde peut calcul/recalcul
3023
-			if (!defined('_VAR_MODE')) {
3024
-				if (in_array('recalcul', $var_mode)) {
3025
-					define('_VAR_MODE', 'recalcul');
3026
-				} elseif (in_array('calcul', $var_mode)) {
3027
-					define('_VAR_MODE', 'calcul');
3028
-				}
3029
-			}
3030
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3031
-			if ($var_mode) {
3032
-				include_spip('inc/autoriser');
3033
-				// autoriser preview si preview seulement, et sinon autoriser debug
3034
-				if (
3035
-					autoriser(
3036
-						($_GET['var_mode'] == 'preview')
3037
-						? 'previsualiser'
3038
-						: 'debug'
3039
-					)
3040
-				) {
3041
-					if (in_array('traduction', $var_mode)) {
3042
-						// forcer le calcul pour passer dans traduire
3043
-						if (!defined('_VAR_MODE')) {
3044
-							define('_VAR_MODE', 'calcul');
3045
-						}
3046
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3047
-						if (!defined('_VAR_NOCACHE')) {
3048
-							define('_VAR_NOCACHE', true);
3049
-						}
3050
-						$var_mode = array_diff($var_mode, ['traduction']);
3051
-					}
3052
-					if (in_array('preview', $var_mode)) {
3053
-						// basculer sur les criteres de preview dans les boucles
3054
-						if (!defined('_VAR_PREVIEW')) {
3055
-							define('_VAR_PREVIEW', true);
3056
-						}
3057
-						// forcer le calcul
3058
-						if (!defined('_VAR_MODE')) {
3059
-							define('_VAR_MODE', 'calcul');
3060
-						}
3061
-						// et ne pas enregistrer de cache
3062
-						if (!defined('_VAR_NOCACHE')) {
3063
-							define('_VAR_NOCACHE', true);
3064
-						}
3065
-						$var_mode = array_diff($var_mode, ['preview']);
3066
-					}
3067
-					if (in_array('inclure', $var_mode)) {
3068
-						// forcer le compilo et ignorer les caches existants
3069
-						if (!defined('_VAR_MODE')) {
3070
-							define('_VAR_MODE', 'calcul');
3071
-						}
3072
-						if (!defined('_VAR_INCLURE')) {
3073
-							define('_VAR_INCLURE', true);
3074
-						}
3075
-						// et ne pas enregistrer de cache
3076
-						if (!defined('_VAR_NOCACHE')) {
3077
-							define('_VAR_NOCACHE', true);
3078
-						}
3079
-						$var_mode = array_diff($var_mode, ['inclure']);
3080
-					}
3081
-					if (in_array('urls', $var_mode)) {
3082
-						// forcer le compilo et ignorer les caches existants
3083
-						if (!defined('_VAR_MODE')) {
3084
-							define('_VAR_MODE', 'calcul');
3085
-						}
3086
-						if (!defined('_VAR_URLS')) {
3087
-							define('_VAR_URLS', true);
3088
-						}
3089
-						$var_mode = array_diff($var_mode, ['urls']);
3090
-					}
3091
-					if (in_array('images', $var_mode)) {
3092
-						// forcer le compilo et ignorer les caches existants
3093
-						if (!defined('_VAR_MODE')) {
3094
-							define('_VAR_MODE', 'calcul');
3095
-						}
3096
-						// indiquer qu'on doit recalculer les images
3097
-						if (!defined('_VAR_IMAGES')) {
3098
-							define('_VAR_IMAGES', true);
3099
-						}
3100
-						$var_mode = array_diff($var_mode, ['images']);
3101
-					}
3102
-					if (in_array('debug', $var_mode)) {
3103
-						if (!defined('_VAR_MODE')) {
3104
-							define('_VAR_MODE', 'debug');
3105
-						}
3106
-						// et ne pas enregistrer de cache
3107
-						if (!defined('_VAR_NOCACHE')) {
3108
-							define('_VAR_NOCACHE', true);
3109
-						}
3110
-						$var_mode = array_diff($var_mode, ['debug']);
3111
-					}
3112
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3113
-						define('_VAR_MODE', reset($var_mode));
3114
-					}
3115
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3116
-						spip_log($GLOBALS['visiteur_session']['nom']
3117
-							. ' ' . _VAR_MODE);
3118
-					}
3119
-				} // pas autorise ?
3120
-				else {
3121
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3122
-					if (
3123
-						!$GLOBALS['visiteur_session']
3124
-						and !empty($_SERVER['HTTP_HOST'])
3125
-						and !empty($_SERVER['REQUEST_METHOD'])
3126
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3127
-					) {
3128
-						$self = self('&', true);
3129
-						if (strpos($self, 'page=login') === false) {
3130
-							include_spip('inc/headers');
3131
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3132
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3133
-						}
3134
-					}
3135
-					// sinon tant pis
3136
-				}
3137
-			}
3138
-		}
3139
-		if (!defined('_VAR_MODE')) {
3140
-			/**
3141
-			 * Indique le mode de calcul ou d'affichage de la page.
3142
-			 * @see init_var_mode()
3143
-			 */
3144
-			define('_VAR_MODE', false);
3145
-		}
3146
-		$done = true;
3147
-	}
3017
+    static $done = false;
3018
+    if (!$done) {
3019
+        if (isset($_GET['var_mode'])) {
3020
+            $var_mode = explode(',', $_GET['var_mode']);
3021
+            // tout le monde peut calcul/recalcul
3022
+            if (!defined('_VAR_MODE')) {
3023
+                if (in_array('recalcul', $var_mode)) {
3024
+                    define('_VAR_MODE', 'recalcul');
3025
+                } elseif (in_array('calcul', $var_mode)) {
3026
+                    define('_VAR_MODE', 'calcul');
3027
+                }
3028
+            }
3029
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3030
+            if ($var_mode) {
3031
+                include_spip('inc/autoriser');
3032
+                // autoriser preview si preview seulement, et sinon autoriser debug
3033
+                if (
3034
+                    autoriser(
3035
+                        ($_GET['var_mode'] == 'preview')
3036
+                        ? 'previsualiser'
3037
+                        : 'debug'
3038
+                    )
3039
+                ) {
3040
+                    if (in_array('traduction', $var_mode)) {
3041
+                        // forcer le calcul pour passer dans traduire
3042
+                        if (!defined('_VAR_MODE')) {
3043
+                            define('_VAR_MODE', 'calcul');
3044
+                        }
3045
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3046
+                        if (!defined('_VAR_NOCACHE')) {
3047
+                            define('_VAR_NOCACHE', true);
3048
+                        }
3049
+                        $var_mode = array_diff($var_mode, ['traduction']);
3050
+                    }
3051
+                    if (in_array('preview', $var_mode)) {
3052
+                        // basculer sur les criteres de preview dans les boucles
3053
+                        if (!defined('_VAR_PREVIEW')) {
3054
+                            define('_VAR_PREVIEW', true);
3055
+                        }
3056
+                        // forcer le calcul
3057
+                        if (!defined('_VAR_MODE')) {
3058
+                            define('_VAR_MODE', 'calcul');
3059
+                        }
3060
+                        // et ne pas enregistrer de cache
3061
+                        if (!defined('_VAR_NOCACHE')) {
3062
+                            define('_VAR_NOCACHE', true);
3063
+                        }
3064
+                        $var_mode = array_diff($var_mode, ['preview']);
3065
+                    }
3066
+                    if (in_array('inclure', $var_mode)) {
3067
+                        // forcer le compilo et ignorer les caches existants
3068
+                        if (!defined('_VAR_MODE')) {
3069
+                            define('_VAR_MODE', 'calcul');
3070
+                        }
3071
+                        if (!defined('_VAR_INCLURE')) {
3072
+                            define('_VAR_INCLURE', true);
3073
+                        }
3074
+                        // et ne pas enregistrer de cache
3075
+                        if (!defined('_VAR_NOCACHE')) {
3076
+                            define('_VAR_NOCACHE', true);
3077
+                        }
3078
+                        $var_mode = array_diff($var_mode, ['inclure']);
3079
+                    }
3080
+                    if (in_array('urls', $var_mode)) {
3081
+                        // forcer le compilo et ignorer les caches existants
3082
+                        if (!defined('_VAR_MODE')) {
3083
+                            define('_VAR_MODE', 'calcul');
3084
+                        }
3085
+                        if (!defined('_VAR_URLS')) {
3086
+                            define('_VAR_URLS', true);
3087
+                        }
3088
+                        $var_mode = array_diff($var_mode, ['urls']);
3089
+                    }
3090
+                    if (in_array('images', $var_mode)) {
3091
+                        // forcer le compilo et ignorer les caches existants
3092
+                        if (!defined('_VAR_MODE')) {
3093
+                            define('_VAR_MODE', 'calcul');
3094
+                        }
3095
+                        // indiquer qu'on doit recalculer les images
3096
+                        if (!defined('_VAR_IMAGES')) {
3097
+                            define('_VAR_IMAGES', true);
3098
+                        }
3099
+                        $var_mode = array_diff($var_mode, ['images']);
3100
+                    }
3101
+                    if (in_array('debug', $var_mode)) {
3102
+                        if (!defined('_VAR_MODE')) {
3103
+                            define('_VAR_MODE', 'debug');
3104
+                        }
3105
+                        // et ne pas enregistrer de cache
3106
+                        if (!defined('_VAR_NOCACHE')) {
3107
+                            define('_VAR_NOCACHE', true);
3108
+                        }
3109
+                        $var_mode = array_diff($var_mode, ['debug']);
3110
+                    }
3111
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3112
+                        define('_VAR_MODE', reset($var_mode));
3113
+                    }
3114
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3115
+                        spip_log($GLOBALS['visiteur_session']['nom']
3116
+                            . ' ' . _VAR_MODE);
3117
+                    }
3118
+                } // pas autorise ?
3119
+                else {
3120
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3121
+                    if (
3122
+                        !$GLOBALS['visiteur_session']
3123
+                        and !empty($_SERVER['HTTP_HOST'])
3124
+                        and !empty($_SERVER['REQUEST_METHOD'])
3125
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3126
+                    ) {
3127
+                        $self = self('&', true);
3128
+                        if (strpos($self, 'page=login') === false) {
3129
+                            include_spip('inc/headers');
3130
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3131
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3132
+                        }
3133
+                    }
3134
+                    // sinon tant pis
3135
+                }
3136
+            }
3137
+        }
3138
+        if (!defined('_VAR_MODE')) {
3139
+            /**
3140
+             * Indique le mode de calcul ou d'affichage de la page.
3141
+             * @see init_var_mode()
3142
+             */
3143
+            define('_VAR_MODE', false);
3144
+        }
3145
+        $done = true;
3146
+    }
3148 3147
 }
3149 3148
 
3150 3149
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
3151 3150
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
3152 3151
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
3153 3152
 function spip_desinfecte(&$t, $deep = true) {
3154
-	foreach ($t as $key => $val) {
3155
-		if (is_string($t[$key])) {
3156
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3157
-		} // traiter aussi les "texte_plus" de article_edit
3158
-		else {
3159
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3160
-				spip_desinfecte($t[$key], $deep);
3161
-			}
3162
-		}
3163
-	}
3153
+    foreach ($t as $key => $val) {
3154
+        if (is_string($t[$key])) {
3155
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3156
+        } // traiter aussi les "texte_plus" de article_edit
3157
+        else {
3158
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3159
+                spip_desinfecte($t[$key], $deep);
3160
+            }
3161
+        }
3162
+    }
3164 3163
 }
3165 3164
 
3166 3165
 //  retourne le statut du visiteur s'il s'annonce
3167 3166
 
3168 3167
 function verifier_visiteur() {
3169
-	// Rq: pour que cette fonction marche depuis mes_options
3170
-	// il faut forcer l'init si ce n'est fait
3171
-	// mais on risque de perturber des plugins en initialisant trop tot
3172
-	// certaines constantes
3173
-	@spip_initialisation_core(
3174
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3175
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3176
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3177
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3178
-	);
3179
-
3180
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3181
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3182
-	// Attention on separe bien session_nom et nom, pour eviter
3183
-	// les melanges entre donnees SQL et variables plus aleatoires
3184
-	$variables_session = ['session_nom', 'session_email'];
3185
-	foreach ($variables_session as $var) {
3186
-		if (_request($var) !== null) {
3187
-			$init = true;
3188
-			break;
3189
-		}
3190
-	}
3191
-	if (isset($init)) {
3192
-		#@spip_initialisation_suite();
3193
-		$session = charger_fonction('session', 'inc');
3194
-		$session();
3195
-		include_spip('inc/texte');
3196
-		foreach ($variables_session as $var) {
3197
-			if (($a = _request($var)) !== null) {
3198
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3199
-			}
3200
-		}
3201
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3202
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3203
-		}
3204
-		$session($GLOBALS['visiteur_session']);
3205
-
3206
-		return 0;
3207
-	}
3208
-
3209
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3210
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3211
-		$session = charger_fonction('session', 'inc');
3212
-		if ($session()) {
3213
-			return $GLOBALS['visiteur_session']['statut'];
3214
-		}
3215
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3216
-			include_spip('inc/auth');
3217
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3218
-		}
3219
-		if ($h) {
3220
-			$GLOBALS['visiteur_session'] = $h;
3221
-
3222
-			return $GLOBALS['visiteur_session']['statut'];
3223
-		}
3224
-	}
3225
-
3226
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3227
-	include_spip('inc/lang');
3228
-	utiliser_langue_visiteur();
3229
-
3230
-	return false;
3168
+    // Rq: pour que cette fonction marche depuis mes_options
3169
+    // il faut forcer l'init si ce n'est fait
3170
+    // mais on risque de perturber des plugins en initialisant trop tot
3171
+    // certaines constantes
3172
+    @spip_initialisation_core(
3173
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3174
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3175
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3176
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3177
+    );
3178
+
3179
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3180
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3181
+    // Attention on separe bien session_nom et nom, pour eviter
3182
+    // les melanges entre donnees SQL et variables plus aleatoires
3183
+    $variables_session = ['session_nom', 'session_email'];
3184
+    foreach ($variables_session as $var) {
3185
+        if (_request($var) !== null) {
3186
+            $init = true;
3187
+            break;
3188
+        }
3189
+    }
3190
+    if (isset($init)) {
3191
+        #@spip_initialisation_suite();
3192
+        $session = charger_fonction('session', 'inc');
3193
+        $session();
3194
+        include_spip('inc/texte');
3195
+        foreach ($variables_session as $var) {
3196
+            if (($a = _request($var)) !== null) {
3197
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3198
+            }
3199
+        }
3200
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3201
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3202
+        }
3203
+        $session($GLOBALS['visiteur_session']);
3204
+
3205
+        return 0;
3206
+    }
3207
+
3208
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3209
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3210
+        $session = charger_fonction('session', 'inc');
3211
+        if ($session()) {
3212
+            return $GLOBALS['visiteur_session']['statut'];
3213
+        }
3214
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3215
+            include_spip('inc/auth');
3216
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3217
+        }
3218
+        if ($h) {
3219
+            $GLOBALS['visiteur_session'] = $h;
3220
+
3221
+            return $GLOBALS['visiteur_session']['statut'];
3222
+        }
3223
+    }
3224
+
3225
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3226
+    include_spip('inc/lang');
3227
+    utiliser_langue_visiteur();
3228
+
3229
+    return false;
3231 3230
 }
3232 3231
 
3233 3232
 
@@ -3250,21 +3249,21 @@  discard block
 block discarded – undo
3250 3249
  *     - string Langue utilisée.
3251 3250
  **/
3252 3251
 function lang_select($lang = null) {
3253
-	static $pile_langues = [];
3254
-	if (!function_exists('changer_langue')) {
3255
-		include_spip('inc/lang');
3256
-	}
3257
-	if ($lang === null) {
3258
-		$lang = array_pop($pile_langues);
3259
-	} else {
3260
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3261
-	}
3262
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3263
-		return $lang;
3264
-	}
3265
-	changer_langue($lang);
3252
+    static $pile_langues = [];
3253
+    if (!function_exists('changer_langue')) {
3254
+        include_spip('inc/lang');
3255
+    }
3256
+    if ($lang === null) {
3257
+        $lang = array_pop($pile_langues);
3258
+    } else {
3259
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3260
+    }
3261
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3262
+        return $lang;
3263
+    }
3264
+    changer_langue($lang);
3266 3265
 
3267
-	return $lang;
3266
+    return $lang;
3268 3267
 }
3269 3268
 
3270 3269
 /**
@@ -3281,20 +3280,20 @@  discard block
 block discarded – undo
3281 3280
  *     Identifiant de la session
3282 3281
  **/
3283 3282
 function spip_session($force = false) {
3284
-	static $session;
3285
-	if ($force or !isset($session)) {
3286
-		$s = pipeline(
3287
-			'definir_session',
3288
-			$GLOBALS['visiteur_session']
3289
-				? serialize($GLOBALS['visiteur_session'])
3290
-				. '_' . @$_COOKIE['spip_session']
3291
-				: ''
3292
-		);
3293
-		$session = $s ? substr(md5($s), 0, 8) : '';
3294
-	}
3283
+    static $session;
3284
+    if ($force or !isset($session)) {
3285
+        $s = pipeline(
3286
+            'definir_session',
3287
+            $GLOBALS['visiteur_session']
3288
+                ? serialize($GLOBALS['visiteur_session'])
3289
+                . '_' . @$_COOKIE['spip_session']
3290
+                : ''
3291
+        );
3292
+        $session = $s ? substr(md5($s), 0, 8) : '';
3293
+    }
3295 3294
 
3296
-	#spip_log('session: '.$session);
3297
-	return $session;
3295
+    #spip_log('session: '.$session);
3296
+    return $session;
3298 3297
 }
3299 3298
 
3300 3299
 
@@ -3313,9 +3312,9 @@  discard block
 block discarded – undo
3313 3312
  *    Lien sur une icone d'aide
3314 3313
  **/
3315 3314
 function aider($aide = '', $distante = false) {
3316
-	$aider = charger_fonction('aide', 'inc', true);
3315
+    $aider = charger_fonction('aide', 'inc', true);
3317 3316
 
3318
-	return $aider ? $aider($aide, '', [], $distante) : '';
3317
+    return $aider ? $aider($aide, '', [], $distante) : '';
3319 3318
 }
3320 3319
 
3321 3320
 /**
@@ -3325,24 +3324,24 @@  discard block
 block discarded – undo
3325 3324
  */
3326 3325
 function exec_info_dist() {
3327 3326
 
3328
-	include_spip('inc/autoriser');
3329
-	if (autoriser('phpinfos')) {
3330
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3331
-		$cookies_backup = [];
3332
-		foreach ($cookies_masques as $k) {
3333
-			if (!empty($_COOKIE[$k])) {
3334
-				$cookies_backup[$k] = $_COOKIE[$k];
3335
-				$_COOKIE[$k] = '******************************';
3336
-			}
3337
-		}
3338
-		phpinfo();
3339
-		foreach ($cookies_backup as $k => $v) {
3340
-			$_COOKIE[$k] = $v;
3341
-		}
3342
-	} else {
3343
-		include_spip('inc/filtres');
3344
-		sinon_interdire_acces();
3345
-	}
3327
+    include_spip('inc/autoriser');
3328
+    if (autoriser('phpinfos')) {
3329
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3330
+        $cookies_backup = [];
3331
+        foreach ($cookies_masques as $k) {
3332
+            if (!empty($_COOKIE[$k])) {
3333
+                $cookies_backup[$k] = $_COOKIE[$k];
3334
+                $_COOKIE[$k] = '******************************';
3335
+            }
3336
+        }
3337
+        phpinfo();
3338
+        foreach ($cookies_backup as $k => $v) {
3339
+            $_COOKIE[$k] = $v;
3340
+        }
3341
+    } else {
3342
+        include_spip('inc/filtres');
3343
+        sinon_interdire_acces();
3344
+    }
3346 3345
 }
3347 3346
 
3348 3347
 /**
@@ -3362,13 +3361,13 @@  discard block
 block discarded – undo
3362 3361
  *     - string si $message à false.
3363 3362
  **/
3364 3363
 function erreur_squelette($message = '', $lieu = '') {
3365
-	$debusquer = charger_fonction('debusquer', 'public');
3366
-	if (is_array($lieu)) {
3367
-		include_spip('public/compiler');
3368
-		$lieu = reconstruire_contexte_compil($lieu);
3369
-	}
3364
+    $debusquer = charger_fonction('debusquer', 'public');
3365
+    if (is_array($lieu)) {
3366
+        include_spip('public/compiler');
3367
+        $lieu = reconstruire_contexte_compil($lieu);
3368
+    }
3370 3369
 
3371
-	return $debusquer($message, $lieu);
3370
+    return $debusquer($message, $lieu);
3372 3371
 }
3373 3372
 
3374 3373
 /**
@@ -3405,108 +3404,108 @@  discard block
 block discarded – undo
3405 3404
  *     - ou tableau d'information sur le squelette.
3406 3405
  */
3407 3406
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3408
-	if (!function_exists('evaluer_fond')) {
3409
-		include_spip('public/assembler');
3410
-	}
3411
-	// assurer la compat avec l'ancienne syntaxe
3412
-	// (trim etait le 3eme argument, par defaut a true)
3413
-	if (!is_array($options)) {
3414
-		$options = ['trim' => $options];
3415
-	}
3416
-	if (!isset($options['trim'])) {
3417
-		$options['trim'] = true;
3418
-	}
3419
-
3420
-	if (isset($contexte['connect'])) {
3421
-		$connect = $contexte['connect'];
3422
-		unset($contexte['connect']);
3423
-	}
3424
-
3425
-	$texte = '';
3426
-	$pages = [];
3427
-	$lang_select = '';
3428
-	if (!isset($options['etoile']) or !$options['etoile']) {
3429
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3430
-		if (!isset($contexte['lang'])) {
3431
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3432
-		}
3433
-
3434
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3435
-			$lang_select = lang_select($contexte['lang']);
3436
-		}
3437
-	}
3438
-
3439
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3440
-		$GLOBALS['_INC_PUBLIC'] = 0;
3441
-	}
3442
-
3443
-	$GLOBALS['_INC_PUBLIC']++;
3444
-
3445
-	// fix #4235
3446
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3447
-
3448
-
3449
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3450
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3451
-
3452
-		$page = evaluer_fond($f, $contexte, $connect);
3453
-		if ($page === '') {
3454
-			$c = $options['compil'] ?? '';
3455
-			$a = ['fichier' => $f];
3456
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3457
-			erreur_squelette($erreur, $c);
3458
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3459
-			$page = ['texte' => '', 'erreur' => $erreur];
3460
-		}
3461
-
3462
-		$page = pipeline('recuperer_fond', [
3463
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3464
-			'data' => $page
3465
-		]);
3466
-		if (isset($options['ajax']) and $options['ajax']) {
3467
-			if (!function_exists('encoder_contexte_ajax')) {
3468
-				include_spip('inc/filtres');
3469
-			}
3470
-			$page['texte'] = encoder_contexte_ajax(
3471
-				array_merge(
3472
-					$contexte,
3473
-					['fond' => $f],
3474
-					($connect ? ['connect' => $connect] : [])
3475
-				),
3476
-				'',
3477
-				$page['texte'],
3478
-				$options['ajax']
3479
-			);
3480
-		}
3481
-
3482
-		if (isset($options['raw']) and $options['raw']) {
3483
-			$pages[] = $page;
3484
-		} else {
3485
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3486
-		}
3487
-
3488
-		// contamination de la session appelante, pour les inclusions statiques
3489
-		if (isset($page['invalideurs']['session'])) {
3490
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3491
-		}
3492
-	}
3493
-
3494
-	// restaurer le sessionnement du contexte appelant,
3495
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3496
-	if (isset($cache_utilise_session_appelant)) {
3497
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3498
-	}
3499
-
3500
-	$GLOBALS['_INC_PUBLIC']--;
3501
-
3502
-	if ($lang_select) {
3503
-		lang_select();
3504
-	}
3505
-	if (isset($options['raw']) and $options['raw']) {
3506
-		return is_array($fond) ? $pages : reset($pages);
3507
-	} else {
3508
-		return $options['trim'] ? ltrim($texte) : $texte;
3509
-	}
3407
+    if (!function_exists('evaluer_fond')) {
3408
+        include_spip('public/assembler');
3409
+    }
3410
+    // assurer la compat avec l'ancienne syntaxe
3411
+    // (trim etait le 3eme argument, par defaut a true)
3412
+    if (!is_array($options)) {
3413
+        $options = ['trim' => $options];
3414
+    }
3415
+    if (!isset($options['trim'])) {
3416
+        $options['trim'] = true;
3417
+    }
3418
+
3419
+    if (isset($contexte['connect'])) {
3420
+        $connect = $contexte['connect'];
3421
+        unset($contexte['connect']);
3422
+    }
3423
+
3424
+    $texte = '';
3425
+    $pages = [];
3426
+    $lang_select = '';
3427
+    if (!isset($options['etoile']) or !$options['etoile']) {
3428
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3429
+        if (!isset($contexte['lang'])) {
3430
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3431
+        }
3432
+
3433
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3434
+            $lang_select = lang_select($contexte['lang']);
3435
+        }
3436
+    }
3437
+
3438
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3439
+        $GLOBALS['_INC_PUBLIC'] = 0;
3440
+    }
3441
+
3442
+    $GLOBALS['_INC_PUBLIC']++;
3443
+
3444
+    // fix #4235
3445
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3446
+
3447
+
3448
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3449
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3450
+
3451
+        $page = evaluer_fond($f, $contexte, $connect);
3452
+        if ($page === '') {
3453
+            $c = $options['compil'] ?? '';
3454
+            $a = ['fichier' => $f];
3455
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3456
+            erreur_squelette($erreur, $c);
3457
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3458
+            $page = ['texte' => '', 'erreur' => $erreur];
3459
+        }
3460
+
3461
+        $page = pipeline('recuperer_fond', [
3462
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3463
+            'data' => $page
3464
+        ]);
3465
+        if (isset($options['ajax']) and $options['ajax']) {
3466
+            if (!function_exists('encoder_contexte_ajax')) {
3467
+                include_spip('inc/filtres');
3468
+            }
3469
+            $page['texte'] = encoder_contexte_ajax(
3470
+                array_merge(
3471
+                    $contexte,
3472
+                    ['fond' => $f],
3473
+                    ($connect ? ['connect' => $connect] : [])
3474
+                ),
3475
+                '',
3476
+                $page['texte'],
3477
+                $options['ajax']
3478
+            );
3479
+        }
3480
+
3481
+        if (isset($options['raw']) and $options['raw']) {
3482
+            $pages[] = $page;
3483
+        } else {
3484
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3485
+        }
3486
+
3487
+        // contamination de la session appelante, pour les inclusions statiques
3488
+        if (isset($page['invalideurs']['session'])) {
3489
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3490
+        }
3491
+    }
3492
+
3493
+    // restaurer le sessionnement du contexte appelant,
3494
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3495
+    if (isset($cache_utilise_session_appelant)) {
3496
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3497
+    }
3498
+
3499
+    $GLOBALS['_INC_PUBLIC']--;
3500
+
3501
+    if ($lang_select) {
3502
+        lang_select();
3503
+    }
3504
+    if (isset($options['raw']) and $options['raw']) {
3505
+        return is_array($fond) ? $pages : reset($pages);
3506
+    } else {
3507
+        return $options['trim'] ? ltrim($texte) : $texte;
3508
+    }
3510 3509
 }
3511 3510
 
3512 3511
 /**
@@ -3516,7 +3515,7 @@  discard block
 block discarded – undo
3516 3515
  * @return string
3517 3516
  */
3518 3517
 function trouve_modele($nom) {
3519
-	return trouver_fond($nom, 'modeles/');
3518
+    return trouver_fond($nom, 'modeles/');
3520 3519
 }
3521 3520
 
3522 3521
 /**
@@ -3532,21 +3531,21 @@  discard block
 block discarded – undo
3532 3531
  * @return array|string
3533 3532
  */
3534 3533
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3535
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3536
-	if (!$pathinfo) {
3537
-		return $f;
3538
-	}
3539
-	// renvoyer un tableau detaille si $pathinfo==true
3540
-	$p = pathinfo($f);
3541
-	if (!isset($p['extension']) or !$p['extension']) {
3542
-		$p['extension'] = _EXTENSION_SQUELETTES;
3543
-	}
3544
-	if (!isset($p['extension']) or !$p['filename']) {
3545
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3546
-	}
3547
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3534
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3535
+    if (!$pathinfo) {
3536
+        return $f;
3537
+    }
3538
+    // renvoyer un tableau detaille si $pathinfo==true
3539
+    $p = pathinfo($f);
3540
+    if (!isset($p['extension']) or !$p['extension']) {
3541
+        $p['extension'] = _EXTENSION_SQUELETTES;
3542
+    }
3543
+    if (!isset($p['extension']) or !$p['filename']) {
3544
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3545
+    }
3546
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3548 3547
 
3549
-	return $p;
3548
+    return $p;
3550 3549
 }
3551 3550
 
3552 3551
 /**
@@ -3566,21 +3565,21 @@  discard block
 block discarded – undo
3566 3565
  *     Nom de l'exec, sinon chaîne vide.
3567 3566
  **/
3568 3567
 function tester_url_ecrire($nom) {
3569
-	static $exec = [];
3570
-	if (isset($exec[$nom])) {
3571
-		return $exec[$nom];
3572
-	}
3573
-	// tester si c'est une page en squelette
3574
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3575
-		return $exec[$nom] = 'fond';
3576
-	} // echafaudage d'un fond !
3577
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3578
-		return $exec[$nom] = 'fond';
3579
-	}
3580
-	// attention, il ne faut pas inclure l'exec ici
3581
-	// car sinon #URL_ECRIRE provoque des inclusions
3582
-	// et des define intrusifs potentiels
3583
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3568
+    static $exec = [];
3569
+    if (isset($exec[$nom])) {
3570
+        return $exec[$nom];
3571
+    }
3572
+    // tester si c'est une page en squelette
3573
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3574
+        return $exec[$nom] = 'fond';
3575
+    } // echafaudage d'un fond !
3576
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3577
+        return $exec[$nom] = 'fond';
3578
+    }
3579
+    // attention, il ne faut pas inclure l'exec ici
3580
+    // car sinon #URL_ECRIRE provoque des inclusions
3581
+    // et des define intrusifs potentiels
3582
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3584 3583
 }
3585 3584
 
3586 3585
 /**
@@ -3590,8 +3589,8 @@  discard block
 block discarded – undo
3590 3589
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3591 3590
  **/
3592 3591
 function html5_permis() {
3593
-	return (!defined('_VERSION_HTML')
3594
-		or _VERSION_HTML !== 'html4');
3592
+    return (!defined('_VERSION_HTML')
3593
+        or _VERSION_HTML !== 'html4');
3595 3594
 }
3596 3595
 
3597 3596
 /**
@@ -3601,30 +3600,30 @@  discard block
 block discarded – undo
3601 3600
  * @return array
3602 3601
  */
3603 3602
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3604
-	$formats = null;
3605
-	if (!is_null($gd)) {
3606
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3607
-		if (isset($GLOBALS['meta'][$config])) {
3608
-			$formats = $GLOBALS['meta'][$config];
3609
-			$formats = explode(',', $formats);
3610
-			$formats = array_filter($formats);
3611
-			$formats = array_map('trim', $formats);
3612
-		}
3613
-	}
3614
-	if (is_null($formats)) {
3615
-		include_spip('inc/filtres_images_lib_mini');
3616
-		$formats = _image_extensions_acceptees_en_entree();
3617
-	}
3618
-
3619
-	if ($svg_allowed) {
3620
-		if (!in_array('svg', $formats)) {
3621
-			$formats[] = 'svg';
3622
-		}
3623
-	}
3624
-	else {
3625
-		$formats = array_diff($formats, ['svg']);
3626
-	}
3627
-	return $formats;
3603
+    $formats = null;
3604
+    if (!is_null($gd)) {
3605
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3606
+        if (isset($GLOBALS['meta'][$config])) {
3607
+            $formats = $GLOBALS['meta'][$config];
3608
+            $formats = explode(',', $formats);
3609
+            $formats = array_filter($formats);
3610
+            $formats = array_map('trim', $formats);
3611
+        }
3612
+    }
3613
+    if (is_null($formats)) {
3614
+        include_spip('inc/filtres_images_lib_mini');
3615
+        $formats = _image_extensions_acceptees_en_entree();
3616
+    }
3617
+
3618
+    if ($svg_allowed) {
3619
+        if (!in_array('svg', $formats)) {
3620
+            $formats[] = 'svg';
3621
+        }
3622
+    }
3623
+    else {
3624
+        $formats = array_diff($formats, ['svg']);
3625
+    }
3626
+    return $formats;
3628 3627
 }
3629 3628
 
3630 3629
 /**
@@ -3633,20 +3632,20 @@  discard block
 block discarded – undo
3633 3632
  * @return array|bool
3634 3633
  */
3635 3634
 function spip_getimagesize($fichier) {
3636
-	if (!$imagesize = @getimagesize($fichier)) {
3637
-		include_spip('inc/svg');
3638
-		if ($attrs = svg_lire_attributs($fichier)) {
3639
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3640
-			$imagesize = [
3641
-				$width,
3642
-				$height,
3643
-				IMAGETYPE_SVG,
3644
-				"width=\"{$width}\" height=\"{$height}\"",
3645
-				'mime' => 'image/svg+xml'
3646
-			];
3647
-		}
3648
-	}
3649
-	return $imagesize;
3635
+    if (!$imagesize = @getimagesize($fichier)) {
3636
+        include_spip('inc/svg');
3637
+        if ($attrs = svg_lire_attributs($fichier)) {
3638
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3639
+            $imagesize = [
3640
+                $width,
3641
+                $height,
3642
+                IMAGETYPE_SVG,
3643
+                "width=\"{$width}\" height=\"{$height}\"",
3644
+                'mime' => 'image/svg+xml'
3645
+            ];
3646
+        }
3647
+    }
3648
+    return $imagesize;
3650 3649
 }
3651 3650
 
3652 3651
 /**
@@ -3660,19 +3659,19 @@  discard block
 block discarded – undo
3660 3659
  * @param string $statut
3661 3660
  */
3662 3661
 function avertir_auteurs($nom, $message, $statut = '') {
3663
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3664
-	if (
3665
-		!$alertes
3666
-		or !is_array($alertes = unserialize($alertes))
3667
-	) {
3668
-		$alertes = [];
3669
-	}
3662
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3663
+    if (
3664
+        !$alertes
3665
+        or !is_array($alertes = unserialize($alertes))
3666
+    ) {
3667
+        $alertes = [];
3668
+    }
3670 3669
 
3671
-	if (!isset($alertes[$statut])) {
3672
-		$alertes[$statut] = [];
3673
-	}
3674
-	$alertes[$statut][$nom] = $message;
3675
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3670
+    if (!isset($alertes[$statut])) {
3671
+        $alertes[$statut] = [];
3672
+    }
3673
+    $alertes[$statut][$nom] = $message;
3674
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3676 3675
 }
3677 3676
 
3678 3677
 /**
@@ -3686,10 +3685,10 @@  discard block
 block discarded – undo
3686 3685
  * @return string|string[]
3687 3686
  */
3688 3687
 function spip_sanitize_classname($classes) {
3689
-	if (is_array($classes)) {
3690
-		return array_map('spip_sanitize_classname', $classes);
3691
-	}
3692
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3688
+    if (is_array($classes)) {
3689
+        return array_map('spip_sanitize_classname', $classes);
3690
+    }
3691
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3693 3692
 }
3694 3693
 
3695 3694
 
@@ -3714,32 +3713,32 @@  discard block
 block discarded – undo
3714 3713
  *    Avec operateur : bool.
3715 3714
  **/
3716 3715
 function spip_version_compare($v1, $v2, $op = null) {
3717
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3718
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3719
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3720
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3721
-
3722
-	$v1 = explode('.', $v1);
3723
-	$v2 = explode('.', $v2);
3724
-	// $v1 est toujours une version, donc sans etoile
3725
-	while (count($v1) < count($v2)) {
3726
-		$v1[] = '0';
3727
-	}
3728
-
3729
-	// $v2 peut etre une borne, donc accepte l'etoile
3730
-	$etoile = false;
3731
-	foreach ($v1 as $k => $v) {
3732
-		if (!isset($v2[$k])) {
3733
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3734
-		} else {
3735
-			if ($v2[$k] == '*') {
3736
-				$etoile = true;
3737
-				$v2[$k] = $v;
3738
-			}
3739
-		}
3740
-	}
3741
-	$v1 = implode('.', $v1);
3742
-	$v2 = implode('.', $v2);
3743
-
3744
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3716
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3717
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3718
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3719
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3720
+
3721
+    $v1 = explode('.', $v1);
3722
+    $v2 = explode('.', $v2);
3723
+    // $v1 est toujours une version, donc sans etoile
3724
+    while (count($v1) < count($v2)) {
3725
+        $v1[] = '0';
3726
+    }
3727
+
3728
+    // $v2 peut etre une borne, donc accepte l'etoile
3729
+    $etoile = false;
3730
+    foreach ($v1 as $k => $v) {
3731
+        if (!isset($v2[$k])) {
3732
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3733
+        } else {
3734
+            if ($v2[$k] == '*') {
3735
+                $etoile = true;
3736
+                $v2[$k] = $v;
3737
+            }
3738
+        }
3739
+    }
3740
+    $v1 = implode('.', $v1);
3741
+    $v2 = implode('.', $v2);
3742
+
3743
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3745 3744
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 2 patches
Indentation   +2469 added lines, -2469 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
 /**
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
  * @return void
213 213
  */
214 214
 function header_silencieux($version) {
215
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
216
-		$version = '';
217
-	}
215
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
216
+        $version = '';
217
+    }
218 218
 
219
-	return $version;
219
+    return $version;
220 220
 }
221 221
 
222 222
 /**
@@ -229,19 +229,19 @@  discard block
 block discarded – undo
229 229
  *    - string|null si $raw = false
230 230
  */
231 231
 function version_vcs_courante($dir, $raw = false) {
232
-	$desc = decrire_version_git($dir);
233
-	if ($desc === null) {
234
-		$desc = decrire_version_svn($dir);
235
-	}
236
-	if ($desc === null or $raw) {
237
-		return $desc;
238
-	}
239
-	// affichage "GIT [master: abcdef]"
240
-	$commit = $desc['commit_short'] ?? $desc['commit'];
241
-	if ($desc['branch']) {
242
-		$commit = $desc['branch'] . ': ' . $commit;
243
-	}
244
-	return "{$desc['vcs']} [$commit]";
232
+    $desc = decrire_version_git($dir);
233
+    if ($desc === null) {
234
+        $desc = decrire_version_svn($dir);
235
+    }
236
+    if ($desc === null or $raw) {
237
+        return $desc;
238
+    }
239
+    // affichage "GIT [master: abcdef]"
240
+    $commit = $desc['commit_short'] ?? $desc['commit'];
241
+    if ($desc['branch']) {
242
+        $commit = $desc['branch'] . ': ' . $commit;
243
+    }
244
+    return "{$desc['vcs']} [$commit]";
245 245
 }
246 246
 
247 247
 /**
@@ -253,24 +253,24 @@  discard block
 block discarded – undo
253 253
  *      array ['branch' => xx, 'commit' => yy] sinon.
254 254
  **/
255 255
 function decrire_version_git($dir) {
256
-	if (!$dir) {
257
-		$dir = '.';
258
-	}
256
+    if (!$dir) {
257
+        $dir = '.';
258
+    }
259 259
 
260
-	// version installee par GIT
261
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
262
-		$currentHead = trim(substr($c, 4));
263
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
264
-			return [
265
-				'vcs' => 'GIT',
266
-				'branch' => basename($currentHead),
267
-				'commit' => trim($hash),
268
-				'commit_short' => substr(trim($hash), 0, 8),
269
-			];
270
-		}
271
-	}
260
+    // version installee par GIT
261
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
262
+        $currentHead = trim(substr($c, 4));
263
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
264
+            return [
265
+                'vcs' => 'GIT',
266
+                'branch' => basename($currentHead),
267
+                'commit' => trim($hash),
268
+                'commit_short' => substr(trim($hash), 0, 8),
269
+            ];
270
+        }
271
+    }
272 272
 
273
-	return null;
273
+    return null;
274 274
 }
275 275
 
276 276
 
@@ -283,25 +283,25 @@  discard block
 block discarded – undo
283 283
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
284 284
  **/
285 285
 function decrire_version_svn($dir) {
286
-	if (!$dir) {
287
-		$dir = '.';
288
-	}
289
-	// version installee par SVN
290
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
291
-		$db = new SQLite3($dir . '/.svn/wc.db');
292
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
293
-		if ($result) {
294
-			$row = $result->fetchArray();
295
-			if ($row['changed_revision'] != '') {
296
-				return [
297
-					'vcs' => 'SVN',
298
-					'branch' => '',
299
-					'commit' => $row['changed_revision'],
300
-				];
301
-			}
302
-		}
303
-	}
304
-	return null;
286
+    if (!$dir) {
287
+        $dir = '.';
288
+    }
289
+    // version installee par SVN
290
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
291
+        $db = new SQLite3($dir . '/.svn/wc.db');
292
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
293
+        if ($result) {
294
+            $row = $result->fetchArray();
295
+            if ($row['changed_revision'] != '') {
296
+                return [
297
+                    'vcs' => 'SVN',
298
+                    'branch' => '',
299
+                    'commit' => $row['changed_revision'],
300
+                ];
301
+            }
302
+        }
303
+    }
304
+    return null;
305 305
 }
306 306
 
307 307
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
  *     Code HTML retourné par le filtre
349 349
  **/
350 350
 function filtrer($filtre) {
351
-	$tous = func_get_args();
352
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
353
-		return image_filtrer($tous);
354
-	} elseif ($f = chercher_filtre($filtre)) {
355
-		array_shift($tous);
356
-		return call_user_func_array($f, $tous);
357
-	} else {
358
-		// le filtre n'existe pas, on provoque une erreur
359
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
360
-		erreur_squelette($msg);
361
-		return '';
362
-	}
351
+    $tous = func_get_args();
352
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
353
+        return image_filtrer($tous);
354
+    } elseif ($f = chercher_filtre($filtre)) {
355
+        array_shift($tous);
356
+        return call_user_func_array($f, $tous);
357
+    } else {
358
+        // le filtre n'existe pas, on provoque une erreur
359
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
360
+        erreur_squelette($msg);
361
+        return '';
362
+    }
363 363
 }
364 364
 
365 365
 /**
@@ -376,11 +376,11 @@  discard block
 block discarded – undo
376 376
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
377 377
  */
378 378
 function trouver_filtre_matrice($filtre) {
379
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
380
-		find_in_path($f, '', true);
381
-		$GLOBALS['spip_matrice'][$filtre] = true;
382
-	}
383
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
379
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
380
+        find_in_path($f, '', true);
381
+        $GLOBALS['spip_matrice'][$filtre] = true;
382
+    }
383
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
384 384
 }
385 385
 
386 386
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
  * @return mixed
409 409
  */
410 410
 function filtre_set(&$Pile, $val, $key, $continue = null) {
411
-	$Pile['vars'][$key] = $val;
412
-	return $continue ? $val : '';
411
+    $Pile['vars'][$key] = $val;
412
+    return $continue ? $val : '';
413 413
 }
414 414
 
415 415
 /**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
436 436
  */
437 437
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
438
-	$Pile[0][$key] = $val;
439
-	return $continue ? $val : '';
438
+    $Pile[0][$key] = $val;
439
+    return $continue ? $val : '';
440 440
 }
441 441
 
442 442
 /**
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
  * @return string
446 446
  */
447 447
 function filtre_sanitize_env(&$Pile, $keys) {
448
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
449
-	return '';
448
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
449
+    return '';
450 450
 }
451 451
 
452 452
 
@@ -469,18 +469,18 @@  discard block
 block discarded – undo
469 469
  * @return mixed Retourne la valeur (sans la modifier).
470 470
  */
471 471
 function filtre_debug($val, $key = null) {
472
-	$debug = (
473
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
474
-		) . var_export($val, true);
472
+    $debug = (
473
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
474
+        ) . var_export($val, true);
475 475
 
476
-	include_spip('inc/autoriser');
477
-	if (autoriser('webmestre')) {
478
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
479
-	}
476
+    include_spip('inc/autoriser');
477
+    if (autoriser('webmestre')) {
478
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
479
+    }
480 480
 
481
-	spip_log($debug, 'debug');
481
+    spip_log($debug, 'debug');
482 482
 
483
-	return $val;
483
+    return $val;
484 484
 }
485 485
 
486 486
 
@@ -508,89 +508,89 @@  discard block
 block discarded – undo
508 508
  *     Texte qui a reçu les filtres
509 509
  **/
510 510
 function image_filtrer($args) {
511
-	$filtre = array_shift($args); # enlever $filtre
512
-	$texte = array_shift($args);
513
-	if ($texte === null || !strlen($texte)) {
514
-		return;
515
-	}
516
-	find_in_path('filtres_images_mini.php', 'inc/', true);
517
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
518
-	// Cas du nom de fichier local
519
-	$is_file = trim($texte);
520
-	if (
521
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
522
-		  or strpbrk($is_file, "<>\n\r\t") !== false
523
-		  or strpos($is_file, '/') === 0
524
-	) {
525
-		$is_file = false;
526
-	}
527
-	if ($is_file) {
528
-		$is_local_file = function ($path) {
529
-			if (strpos($path, '?') !== false) {
530
-				$path = supprimer_timestamp($path);
531
-				// remove ?24px added by find_in_theme on .svg files
532
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
533
-			}
534
-			return file_exists($path);
535
-		};
536
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
537
-			array_unshift($args, "<img src='$is_file' />");
538
-			$res = call_user_func_array($filtre, $args);
539
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
540
-			return $res;
541
-		}
542
-	}
543
-
544
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
545
-	if (
546
-		preg_match_all(
547
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
548
-			$texte,
549
-			$tags,
550
-			PREG_SET_ORDER
551
-		)
552
-	) {
553
-		foreach ($tags as $tag) {
554
-			$class = extraire_attribut($tag[3], 'class');
555
-			if (
556
-				!$class or
557
-				(strpos($class, 'filtre_inactif') === false
558
-					// compat historique a virer en 3.2
559
-					and strpos($class, 'no_image_filtrer') === false)
560
-			) {
561
-				array_unshift($args, $tag[3]);
562
-				if ($reduit = call_user_func_array($filtre, $args)) {
563
-					// En cas de span spip_documents, modifier le style=...width:
564
-					if ($tag[1]) {
565
-						$w = extraire_attribut($reduit, 'width');
566
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
567
-							$w = $regs[1];
568
-						}
569
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
570
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
571
-							$replace = inserer_attribut($tag[1], 'style', $style);
572
-							$texte = str_replace($tag[1], $replace, $texte);
573
-						}
574
-					}
575
-					// traiter aussi un eventuel mouseover
576
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
577
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
578
-							$srcover = $match[1];
579
-							array_shift($args);
580
-							array_unshift($args, "<img src='" . $match[1] . "' />");
581
-							$srcover_filter = call_user_func_array($filtre, $args);
582
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
583
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
584
-						}
585
-					}
586
-					$texte = str_replace($tag[3], $reduit, $texte);
587
-				}
588
-				array_shift($args);
589
-			}
590
-		}
591
-	}
592
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
593
-	return $texte;
511
+    $filtre = array_shift($args); # enlever $filtre
512
+    $texte = array_shift($args);
513
+    if ($texte === null || !strlen($texte)) {
514
+        return;
515
+    }
516
+    find_in_path('filtres_images_mini.php', 'inc/', true);
517
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
518
+    // Cas du nom de fichier local
519
+    $is_file = trim($texte);
520
+    if (
521
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
522
+          or strpbrk($is_file, "<>\n\r\t") !== false
523
+          or strpos($is_file, '/') === 0
524
+    ) {
525
+        $is_file = false;
526
+    }
527
+    if ($is_file) {
528
+        $is_local_file = function ($path) {
529
+            if (strpos($path, '?') !== false) {
530
+                $path = supprimer_timestamp($path);
531
+                // remove ?24px added by find_in_theme on .svg files
532
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
533
+            }
534
+            return file_exists($path);
535
+        };
536
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
537
+            array_unshift($args, "<img src='$is_file' />");
538
+            $res = call_user_func_array($filtre, $args);
539
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
540
+            return $res;
541
+        }
542
+    }
543
+
544
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
545
+    if (
546
+        preg_match_all(
547
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
548
+            $texte,
549
+            $tags,
550
+            PREG_SET_ORDER
551
+        )
552
+    ) {
553
+        foreach ($tags as $tag) {
554
+            $class = extraire_attribut($tag[3], 'class');
555
+            if (
556
+                !$class or
557
+                (strpos($class, 'filtre_inactif') === false
558
+                    // compat historique a virer en 3.2
559
+                    and strpos($class, 'no_image_filtrer') === false)
560
+            ) {
561
+                array_unshift($args, $tag[3]);
562
+                if ($reduit = call_user_func_array($filtre, $args)) {
563
+                    // En cas de span spip_documents, modifier le style=...width:
564
+                    if ($tag[1]) {
565
+                        $w = extraire_attribut($reduit, 'width');
566
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
567
+                            $w = $regs[1];
568
+                        }
569
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
570
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
571
+                            $replace = inserer_attribut($tag[1], 'style', $style);
572
+                            $texte = str_replace($tag[1], $replace, $texte);
573
+                        }
574
+                    }
575
+                    // traiter aussi un eventuel mouseover
576
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
577
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
578
+                            $srcover = $match[1];
579
+                            array_shift($args);
580
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
581
+                            $srcover_filter = call_user_func_array($filtre, $args);
582
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
583
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
584
+                        }
585
+                    }
586
+                    $texte = str_replace($tag[3], $reduit, $texte);
587
+                }
588
+                array_shift($args);
589
+            }
590
+        }
591
+    }
592
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
593
+    return $texte;
594 594
 }
595 595
 
596 596
 /**
@@ -607,91 +607,91 @@  discard block
 block discarded – undo
607 607
  **/
608 608
 function infos_image($img, $force_refresh = false) {
609 609
 
610
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
611
-	$srcWidth = 0;
612
-	$srcHeight = 0;
613
-	$srcSize = null;
614
-
615
-	$src = extraire_attribut($img, 'src');
616
-
617
-	if (!$src) {
618
-		$src = $img;
619
-	} else {
620
-		$srcWidth = extraire_attribut($img, 'width');
621
-		$srcHeight = extraire_attribut($img, 'height');
622
-	}
623
-
624
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
625
-	// la copie locale a toutes les chances d'etre la ou de resservir
626
-	if (tester_url_absolue($src)) {
627
-		include_spip('inc/distant');
628
-		$fichier = copie_locale($src);
629
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
630
-	}
631
-	if (($p = strpos($src, '?')) !== false) {
632
-		$src = substr($src, 0, $p);
633
-	}
634
-
635
-	$imagesize = false;
636
-	if (isset($largeur_img[$src]) and !$force_refresh) {
637
-		$srcWidth = $largeur_img[$src];
638
-	}
639
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
640
-		$srcHeight = $hauteur_img[$src];
641
-	}
642
-	if (isset($poids_img[$src]) and !$force_refresh) {
643
-		$srcSize = $poids_img[$src];
644
-	}
645
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
646
-		if (
647
-			file_exists($src)
648
-			and $imagesize = spip_getimagesize($src)
649
-		) {
650
-			if (!$srcWidth) {
651
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
652
-			}
653
-			if (!$srcHeight) {
654
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
655
-			}
656
-			if (!$srcSize){
657
-				$poids_img[$src] = filesize($src);
658
-			}
659
-		}
660
-		elseif (strpos($src, '<svg') !== false) {
661
-			include_spip('inc/svg');
662
-			if ($attrs = svg_lire_attributs($src)) {
663
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
664
-				if (!$srcWidth) {
665
-					$largeur_img[$src] = $srcWidth = $width;
666
-				}
667
-				if (!$srcHeight) {
668
-					$hauteur_img[$src] = $srcHeight = $height;
669
-				}
670
-				if (!$srcSize){
671
-					$poids_img[$src] = $srcSize = strlen($src);
672
-				}
673
-			}
674
-		}
675
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
676
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
677
-		elseif (
678
-			@file_exists($f = "$src.src")
679
-			and lire_fichier($f, $valeurs)
680
-			and $valeurs = unserialize($valeurs)
681
-		) {
682
-			if (!$srcWidth) {
683
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
684
-			}
685
-			if (!$srcHeight) {
686
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
687
-			}
688
-			if (!$srcSize){
689
-				$poids_img[$src] = $srcSize = 0;
690
-			}
691
-		}
692
-	}
693
-
694
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
610
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
611
+    $srcWidth = 0;
612
+    $srcHeight = 0;
613
+    $srcSize = null;
614
+
615
+    $src = extraire_attribut($img, 'src');
616
+
617
+    if (!$src) {
618
+        $src = $img;
619
+    } else {
620
+        $srcWidth = extraire_attribut($img, 'width');
621
+        $srcHeight = extraire_attribut($img, 'height');
622
+    }
623
+
624
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
625
+    // la copie locale a toutes les chances d'etre la ou de resservir
626
+    if (tester_url_absolue($src)) {
627
+        include_spip('inc/distant');
628
+        $fichier = copie_locale($src);
629
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
630
+    }
631
+    if (($p = strpos($src, '?')) !== false) {
632
+        $src = substr($src, 0, $p);
633
+    }
634
+
635
+    $imagesize = false;
636
+    if (isset($largeur_img[$src]) and !$force_refresh) {
637
+        $srcWidth = $largeur_img[$src];
638
+    }
639
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
640
+        $srcHeight = $hauteur_img[$src];
641
+    }
642
+    if (isset($poids_img[$src]) and !$force_refresh) {
643
+        $srcSize = $poids_img[$src];
644
+    }
645
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
646
+        if (
647
+            file_exists($src)
648
+            and $imagesize = spip_getimagesize($src)
649
+        ) {
650
+            if (!$srcWidth) {
651
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
652
+            }
653
+            if (!$srcHeight) {
654
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
655
+            }
656
+            if (!$srcSize){
657
+                $poids_img[$src] = filesize($src);
658
+            }
659
+        }
660
+        elseif (strpos($src, '<svg') !== false) {
661
+            include_spip('inc/svg');
662
+            if ($attrs = svg_lire_attributs($src)) {
663
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
664
+                if (!$srcWidth) {
665
+                    $largeur_img[$src] = $srcWidth = $width;
666
+                }
667
+                if (!$srcHeight) {
668
+                    $hauteur_img[$src] = $srcHeight = $height;
669
+                }
670
+                if (!$srcSize){
671
+                    $poids_img[$src] = $srcSize = strlen($src);
672
+                }
673
+            }
674
+        }
675
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
676
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
677
+        elseif (
678
+            @file_exists($f = "$src.src")
679
+            and lire_fichier($f, $valeurs)
680
+            and $valeurs = unserialize($valeurs)
681
+        ) {
682
+            if (!$srcWidth) {
683
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
684
+            }
685
+            if (!$srcHeight) {
686
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
687
+            }
688
+            if (!$srcSize){
689
+                $poids_img[$src] = $srcSize = 0;
690
+            }
691
+        }
692
+    }
693
+
694
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
695 695
 }
696 696
 
697 697
 /**
@@ -707,13 +707,13 @@  discard block
 block discarded – undo
707 707
  *     poids
708 708
  **/
709 709
 function poids_image($img, $force_refresh = false) {
710
-	$infos = infos_image($img, $force_refresh);
711
-	return $infos['poids'];
710
+    $infos = infos_image($img, $force_refresh);
711
+    return $infos['poids'];
712 712
 }
713 713
 
714 714
 function taille_image($img, $force_refresh = false){
715
-	$infos = infos_image($img, $force_refresh);
716
-	return [$infos['hauteur'], $infos['largeur']];
715
+    $infos = infos_image($img, $force_refresh);
716
+    return [$infos['hauteur'], $infos['largeur']];
717 717
 }
718 718
 
719 719
 /**
@@ -730,12 +730,12 @@  discard block
 block discarded – undo
730 730
  *     Largeur en pixels, NULL ou 0 si aucune image.
731 731
  **/
732 732
 function largeur($img) {
733
-	if (!$img) {
734
-		return;
735
-	}
736
-	[$h, $l] = taille_image($img);
733
+    if (!$img) {
734
+        return;
735
+    }
736
+    [$h, $l] = taille_image($img);
737 737
 
738
-	return $l;
738
+    return $l;
739 739
 }
740 740
 
741 741
 /**
@@ -752,12 +752,12 @@  discard block
 block discarded – undo
752 752
  *     Hauteur en pixels, NULL ou 0 si aucune image.
753 753
  **/
754 754
 function hauteur($img) {
755
-	if (!$img) {
756
-		return;
757
-	}
758
-	[$h, $l] = taille_image($img);
755
+    if (!$img) {
756
+        return;
757
+    }
758
+    [$h, $l] = taille_image($img);
759 759
 
760
-	return $h;
760
+    return $h;
761 761
 }
762 762
 
763 763
 
@@ -777,11 +777,11 @@  discard block
 block discarded – undo
777 777
  * @return string
778 778
  **/
779 779
 function corriger_entites_html($texte) {
780
-	if (strpos($texte, '&amp;') === false) {
781
-		return $texte;
782
-	}
780
+    if (strpos($texte, '&amp;') === false) {
781
+        return $texte;
782
+    }
783 783
 
784
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
784
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
785 785
 }
786 786
 
787 787
 /**
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
  * @return string
797 797
  **/
798 798
 function corriger_toutes_entites_html($texte) {
799
-	if (strpos($texte, '&amp;') === false) {
800
-		return $texte;
801
-	}
799
+    if (strpos($texte, '&amp;') === false) {
800
+        return $texte;
801
+    }
802 802
 
803
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
803
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
804 804
 }
805 805
 
806 806
 /**
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
  * @return string
811 811
  **/
812 812
 function proteger_amp($texte) {
813
-	return str_replace('&', '&amp;', $texte);
813
+    return str_replace('&', '&amp;', $texte);
814 814
 }
815 815
 
816 816
 
@@ -841,21 +841,21 @@  discard block
 block discarded – undo
841 841
  * @return mixed|string
842 842
  */
843 843
 function entites_html($texte, $tout = false, $quote = true) {
844
-	if (
845
-		!is_string($texte) or !$texte
846
-		or strpbrk($texte, "&\"'<>") == false
847
-	) {
848
-		return $texte;
849
-	}
850
-	include_spip('inc/texte');
851
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
852
-	$flags |= ENT_HTML401;
853
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
854
-	if ($tout) {
855
-		return corriger_toutes_entites_html($texte);
856
-	} else {
857
-		return corriger_entites_html($texte);
858
-	}
844
+    if (
845
+        !is_string($texte) or !$texte
846
+        or strpbrk($texte, "&\"'<>") == false
847
+    ) {
848
+        return $texte;
849
+    }
850
+    include_spip('inc/texte');
851
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
852
+    $flags |= ENT_HTML401;
853
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
854
+    if ($tout) {
855
+        return corriger_toutes_entites_html($texte);
856
+    } else {
857
+        return corriger_entites_html($texte);
858
+    }
859 859
 }
860 860
 
861 861
 /**
@@ -874,37 +874,37 @@  discard block
 block discarded – undo
874 874
  *     Texte converti
875 875
  **/
876 876
 function filtrer_entites($texte) {
877
-	if (strpos($texte, '&') === false) {
878
-		return $texte;
879
-	}
880
-	// filtrer
881
-	$texte = html2unicode($texte);
882
-	// remettre le tout dans le charset cible
883
-	$texte = unicode2charset($texte);
884
-	// cas particulier des " et ' qu'il faut filtrer aussi
885
-	// (on le faisait deja avec un &quot;)
886
-	if (strpos($texte, '&#') !== false) {
887
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
888
-	}
877
+    if (strpos($texte, '&') === false) {
878
+        return $texte;
879
+    }
880
+    // filtrer
881
+    $texte = html2unicode($texte);
882
+    // remettre le tout dans le charset cible
883
+    $texte = unicode2charset($texte);
884
+    // cas particulier des " et ' qu'il faut filtrer aussi
885
+    // (on le faisait deja avec un &quot;)
886
+    if (strpos($texte, '&#') !== false) {
887
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
888
+    }
889 889
 
890
-	return $texte;
890
+    return $texte;
891 891
 }
892 892
 
893 893
 
894 894
 if (!function_exists('filtre_filtrer_entites_dist')) {
895
-	/**
896
-	 * Version sécurisée de filtrer_entites
897
-	 *
898
-	 * @uses interdire_scripts()
899
-	 * @uses filtrer_entites()
900
-	 *
901
-	 * @param string $t
902
-	 * @return string
903
-	 */
904
-	function filtre_filtrer_entites_dist($t) {
905
-		include_spip('inc/texte');
906
-		return interdire_scripts(filtrer_entites($t));
907
-	}
895
+    /**
896
+     * Version sécurisée de filtrer_entites
897
+     *
898
+     * @uses interdire_scripts()
899
+     * @uses filtrer_entites()
900
+     *
901
+     * @param string $t
902
+     * @return string
903
+     */
904
+    function filtre_filtrer_entites_dist($t) {
905
+        include_spip('inc/texte');
906
+        return interdire_scripts(filtrer_entites($t));
907
+    }
908 908
 }
909 909
 
910 910
 
@@ -919,18 +919,18 @@  discard block
 block discarded – undo
919 919
  * @return string|array
920 920
  **/
921 921
 function supprimer_caracteres_illegaux($texte) {
922
-	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";
923
-	static $to = null;
922
+    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";
923
+    static $to = null;
924 924
 
925
-	if (is_array($texte)) {
926
-		return array_map('supprimer_caracteres_illegaux', $texte);
927
-	}
925
+    if (is_array($texte)) {
926
+        return array_map('supprimer_caracteres_illegaux', $texte);
927
+    }
928 928
 
929
-	if (!$to) {
930
-		$to = str_repeat('-', strlen($from));
931
-	}
929
+    if (!$to) {
930
+        $to = str_repeat('-', strlen($from));
931
+    }
932 932
 
933
-	return strtr($texte, $from, $to);
933
+    return strtr($texte, $from, $to);
934 934
 }
935 935
 
936 936
 /**
@@ -942,10 +942,10 @@  discard block
 block discarded – undo
942 942
  * @return string|array
943 943
  **/
944 944
 function corriger_caracteres($texte) {
945
-	$texte = corriger_caracteres_windows($texte);
946
-	$texte = supprimer_caracteres_illegaux($texte);
945
+    $texte = corriger_caracteres_windows($texte);
946
+    $texte = supprimer_caracteres_illegaux($texte);
947 947
 
948
-	return $texte;
948
+    return $texte;
949 949
 }
950 950
 
951 951
 /**
@@ -962,44 +962,44 @@  discard block
 block discarded – undo
962 962
  *     Texte encodé pour XML
963 963
  */
964 964
 function texte_backend(string $texte): string {
965
-	if ($texte === '') {
966
-		return '';
967
-	}
965
+    if ($texte === '') {
966
+        return '';
967
+    }
968 968
 
969
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
969
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
970 970
 
971
-	// si on a des liens ou des images, les passer en absolu
972
-	$texte = liens_absolus($texte);
971
+    // si on a des liens ou des images, les passer en absolu
972
+    $texte = liens_absolus($texte);
973 973
 
974
-	// echapper les tags &gt; &lt;
975
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
974
+    // echapper les tags &gt; &lt;
975
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
976 976
 
977
-	// importer les &eacute;
978
-	$texte = filtrer_entites($texte);
977
+    // importer les &eacute;
978
+    $texte = filtrer_entites($texte);
979 979
 
980
-	// " -> &quot; et tout ce genre de choses
981
-	$u = $GLOBALS['meta']['pcre_u'];
982
-	$texte = str_replace('&nbsp;', ' ', $texte);
983
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
984
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
985
-	$texte = entites_html($texte, false, false);
986
-	// mais bien echapper les double quotes !
987
-	$texte = str_replace('"', '&#034;', $texte);
980
+    // " -> &quot; et tout ce genre de choses
981
+    $u = $GLOBALS['meta']['pcre_u'];
982
+    $texte = str_replace('&nbsp;', ' ', $texte);
983
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
984
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
985
+    $texte = entites_html($texte, false, false);
986
+    // mais bien echapper les double quotes !
987
+    $texte = str_replace('"', '&#034;', $texte);
988 988
 
989
-	// verifier le charset
990
-	$texte = charset2unicode($texte);
989
+    // verifier le charset
990
+    $texte = charset2unicode($texte);
991 991
 
992
-	// Caracteres problematiques en iso-latin 1
993
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
994
-		$texte = str_replace(chr(156), '&#156;', $texte);
995
-		$texte = str_replace(chr(140), '&#140;', $texte);
996
-		$texte = str_replace(chr(159), '&#159;', $texte);
997
-	}
992
+    // Caracteres problematiques en iso-latin 1
993
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
994
+        $texte = str_replace(chr(156), '&#156;', $texte);
995
+        $texte = str_replace(chr(140), '&#140;', $texte);
996
+        $texte = str_replace(chr(159), '&#159;', $texte);
997
+    }
998 998
 
999
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
1000
-	// et le caractere apostrophe alourdit les squelettes avec PHP
1001
-	// ==> on les remplace par l'entite HTML
1002
-	return str_replace($apostrophe, "'", $texte);
999
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
1000
+    // et le caractere apostrophe alourdit les squelettes avec PHP
1001
+    // ==> on les remplace par l'entite HTML
1002
+    return str_replace($apostrophe, "'", $texte);
1003 1003
 }
1004 1004
 
1005 1005
 /**
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
  *     Texte encodé et quote pour XML
1017 1017
  */
1018 1018
 function texte_backendq(string $texte): string {
1019
-	return addslashes(texte_backend($texte));
1019
+    return addslashes(texte_backend($texte));
1020 1020
 }
1021 1021
 
1022 1022
 
@@ -1039,11 +1039,11 @@  discard block
 block discarded – undo
1039 1039
  *     Numéro de titre, sinon chaîne vide
1040 1040
  **/
1041 1041
 function supprimer_numero($texte) {
1042
-	return preg_replace(
1043
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1044
-		'',
1045
-		$texte
1046
-	);
1042
+    return preg_replace(
1043
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1044
+        '',
1045
+        $texte
1046
+    );
1047 1047
 }
1048 1048
 
1049 1049
 /**
@@ -1066,17 +1066,17 @@  discard block
 block discarded – undo
1066 1066
  *     Numéro de titre, sinon chaîne vide
1067 1067
  **/
1068 1068
 function recuperer_numero($texte) {
1069
-	if (
1070
-		preg_match(
1071
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1072
-			$texte,
1073
-			$regs
1074
-		)
1075
-	) {
1076
-		return strval($regs[1]);
1077
-	} else {
1078
-		return '';
1079
-	}
1069
+    if (
1070
+        preg_match(
1071
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1072
+            $texte,
1073
+            $regs
1074
+        )
1075
+    ) {
1076
+        return strval($regs[1]);
1077
+    } else {
1078
+        return '';
1079
+    }
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1103,16 +1103,16 @@  discard block
 block discarded – undo
1103 1103
  *     Texte converti
1104 1104
  **/
1105 1105
 function supprimer_tags(?string $texte, $rempl = ''): string {
1106
-	if ($texte === null || !strlen($texte)) {
1107
-		return '';
1108
-	}
1109
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1110
-	// ne pas oublier un < final non ferme car coupe
1111
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1112
-	// mais qui peut aussi etre un simple signe plus petit que
1113
-	$texte = str_replace('<', '&lt;', $texte);
1106
+    if ($texte === null || !strlen($texte)) {
1107
+        return '';
1108
+    }
1109
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1110
+    // ne pas oublier un < final non ferme car coupe
1111
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1112
+    // mais qui peut aussi etre un simple signe plus petit que
1113
+    $texte = str_replace('<', '&lt;', $texte);
1114 1114
 
1115
-	return $texte;
1115
+    return $texte;
1116 1116
 }
1117 1117
 
1118 1118
 /**
@@ -1135,9 +1135,9 @@  discard block
 block discarded – undo
1135 1135
  *     Texte converti
1136 1136
  **/
1137 1137
 function echapper_tags($texte, $rempl = '') {
1138
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1138
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1139 1139
 
1140
-	return $texte;
1140
+    return $texte;
1141 1141
 }
1142 1142
 
1143 1143
 /**
@@ -1158,18 +1158,18 @@  discard block
 block discarded – undo
1158 1158
  *     Texte converti
1159 1159
  **/
1160 1160
 function textebrut($texte) {
1161
-	$u = $GLOBALS['meta']['pcre_u'];
1162
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1163
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1164
-	$texte = preg_replace("/^\n+/", '', $texte);
1165
-	$texte = preg_replace("/\n+$/", '', $texte);
1166
-	$texte = preg_replace("/\n +/", "\n", $texte);
1167
-	$texte = supprimer_tags($texte);
1168
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1169
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1170
-	$texte = str_replace('&#8217;', "'", $texte);
1161
+    $u = $GLOBALS['meta']['pcre_u'];
1162
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1163
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1164
+    $texte = preg_replace("/^\n+/", '', $texte);
1165
+    $texte = preg_replace("/\n+$/", '', $texte);
1166
+    $texte = preg_replace("/\n +/", "\n", $texte);
1167
+    $texte = supprimer_tags($texte);
1168
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1169
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1170
+    $texte = str_replace('&#8217;', "'", $texte);
1171 1171
 
1172
-	return $texte;
1172
+    return $texte;
1173 1173
 }
1174 1174
 
1175 1175
 
@@ -1185,23 +1185,23 @@  discard block
 block discarded – undo
1185 1185
  *     Texte avec liens ouvrants
1186 1186
  **/
1187 1187
 function liens_ouvrants($texte) {
1188
-	if (
1189
-		preg_match_all(
1190
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1191
-			$texte,
1192
-			$liens,
1193
-			PREG_PATTERN_ORDER
1194
-		)
1195
-	) {
1196
-		foreach ($liens[0] as $a) {
1197
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1198
-			$ablank = inserer_attribut($a, 'rel', $rel);
1199
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1200
-			$texte = str_replace($a, $ablank, $texte);
1201
-		}
1202
-	}
1203
-
1204
-	return $texte;
1188
+    if (
1189
+        preg_match_all(
1190
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1191
+            $texte,
1192
+            $liens,
1193
+            PREG_PATTERN_ORDER
1194
+        )
1195
+    ) {
1196
+        foreach ($liens[0] as $a) {
1197
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1198
+            $ablank = inserer_attribut($a, 'rel', $rel);
1199
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1200
+            $texte = str_replace($a, $ablank, $texte);
1201
+        }
1202
+    }
1203
+
1204
+    return $texte;
1205 1205
 }
1206 1206
 
1207 1207
 /**
@@ -1211,22 +1211,22 @@  discard block
 block discarded – undo
1211 1211
  * @return string
1212 1212
  */
1213 1213
 function liens_nofollow($texte) {
1214
-	if (stripos($texte, '<a') === false) {
1215
-		return $texte;
1216
-	}
1214
+    if (stripos($texte, '<a') === false) {
1215
+        return $texte;
1216
+    }
1217 1217
 
1218
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1219
-		foreach ($regs[0] as $a) {
1220
-			$rel = extraire_attribut($a, 'rel') ?? '';
1221
-			if (strpos($rel, 'nofollow') === false) {
1222
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1223
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1224
-				$texte = str_replace($a, $anofollow, $texte);
1225
-			}
1226
-		}
1227
-	}
1218
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1219
+        foreach ($regs[0] as $a) {
1220
+            $rel = extraire_attribut($a, 'rel') ?? '';
1221
+            if (strpos($rel, 'nofollow') === false) {
1222
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1223
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1224
+                $texte = str_replace($a, $anofollow, $texte);
1225
+            }
1226
+        }
1227
+    }
1228 1228
 
1229
-	return $texte;
1229
+    return $texte;
1230 1230
 }
1231 1231
 
1232 1232
 /**
@@ -1245,12 +1245,12 @@  discard block
 block discarded – undo
1245 1245
  *     Texte sans paraghaphes
1246 1246
  **/
1247 1247
 function PtoBR($texte) {
1248
-	$u = $GLOBALS['meta']['pcre_u'];
1249
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1250
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1251
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1248
+    $u = $GLOBALS['meta']['pcre_u'];
1249
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1250
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1251
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1252 1252
 
1253
-	return $texte;
1253
+    return $texte;
1254 1254
 }
1255 1255
 
1256 1256
 
@@ -1275,14 +1275,14 @@  discard block
 block discarded – undo
1275 1275
  * @return string Texte encadré du style CSS
1276 1276
  */
1277 1277
 function lignes_longues($texte) {
1278
-	if (!strlen(trim($texte))) {
1279
-		return $texte;
1280
-	}
1281
-	include_spip('inc/texte');
1282
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1283
-		'div' : 'span';
1278
+    if (!strlen(trim($texte))) {
1279
+        return $texte;
1280
+    }
1281
+    include_spip('inc/texte');
1282
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1283
+        'div' : 'span';
1284 1284
 
1285
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1285
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1301,30 +1301,30 @@  discard block
 block discarded – undo
1301 1301
  * @return string Texte en majuscule
1302 1302
  */
1303 1303
 function majuscules($texte) {
1304
-	if (!strlen($texte)) {
1305
-		return '';
1306
-	}
1304
+    if (!strlen($texte)) {
1305
+        return '';
1306
+    }
1307 1307
 
1308
-	// Cas du turc
1309
-	if ($GLOBALS['spip_lang'] == 'tr') {
1310
-		# remplacer hors des tags et des entites
1311
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1312
-			foreach ($regs as $n => $match) {
1313
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1314
-			}
1315
-		}
1308
+    // Cas du turc
1309
+    if ($GLOBALS['spip_lang'] == 'tr') {
1310
+        # remplacer hors des tags et des entites
1311
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1312
+            foreach ($regs as $n => $match) {
1313
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1314
+            }
1315
+        }
1316 1316
 
1317
-		$texte = str_replace('i', '&#304;', $texte);
1317
+        $texte = str_replace('i', '&#304;', $texte);
1318 1318
 
1319
-		if ($regs) {
1320
-			foreach ($regs as $n => $match) {
1321
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1322
-			}
1323
-		}
1324
-	}
1319
+        if ($regs) {
1320
+            foreach ($regs as $n => $match) {
1321
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1322
+            }
1323
+        }
1324
+    }
1325 1325
 
1326
-	// Cas general
1327
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1326
+    // Cas general
1327
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1328 1328
 }
1329 1329
 
1330 1330
 /**
@@ -1342,29 +1342,29 @@  discard block
 block discarded – undo
1342 1342
  * @return string
1343 1343
  **/
1344 1344
 function taille_en_octets($taille) {
1345
-	if (!defined('_KILOBYTE')) {
1346
-		/**
1347
-		 * Définit le nombre d'octets dans un Kilobyte
1348
-		 *
1349
-		 * @var int
1350
-		 **/
1351
-		define('_KILOBYTE', 1024);
1352
-	}
1345
+    if (!defined('_KILOBYTE')) {
1346
+        /**
1347
+         * Définit le nombre d'octets dans un Kilobyte
1348
+         *
1349
+         * @var int
1350
+         **/
1351
+        define('_KILOBYTE', 1024);
1352
+    }
1353 1353
 
1354
-	if ($taille < 1) {
1355
-		return '';
1356
-	}
1357
-	if ($taille < _KILOBYTE) {
1358
-		$taille = _T('taille_octets', ['taille' => $taille]);
1359
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1360
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1361
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1362
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1363
-	} else {
1364
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1365
-	}
1354
+    if ($taille < 1) {
1355
+        return '';
1356
+    }
1357
+    if ($taille < _KILOBYTE) {
1358
+        $taille = _T('taille_octets', ['taille' => $taille]);
1359
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1360
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1361
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1362
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1363
+    } else {
1364
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1365
+    }
1366 1366
 
1367
-	return $taille;
1367
+    return $taille;
1368 1368
 }
1369 1369
 
1370 1370
 
@@ -1386,21 +1386,21 @@  discard block
 block discarded – undo
1386 1386
  *     Texte prêt pour être utilisé en attribut HTML
1387 1387
  **/
1388 1388
 function attribut_html(?string $texte, $textebrut = true): string {
1389
-	if ($texte === null) {
1390
-		return '';
1391
-	}
1392
-	$u = $GLOBALS['meta']['pcre_u'];
1393
-	if ($textebrut) {
1394
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1395
-	}
1396
-	$texte = texte_backend($texte);
1397
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1389
+    if ($texte === null) {
1390
+        return '';
1391
+    }
1392
+    $u = $GLOBALS['meta']['pcre_u'];
1393
+    if ($textebrut) {
1394
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1395
+    }
1396
+    $texte = texte_backend($texte);
1397
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1398 1398
 
1399
-	return preg_replace(
1400
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1401
-		['&', '&#38;'],
1402
-		$texte
1403
-	);
1399
+    return preg_replace(
1400
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1401
+        ['&', '&#38;'],
1402
+        $texte
1403
+    );
1404 1404
 }
1405 1405
 
1406 1406
 
@@ -1420,15 +1420,15 @@  discard block
 block discarded – undo
1420 1420
  *     URL ou chaîne vide
1421 1421
  **/
1422 1422
 function vider_url(?string $url, $entites = true): string {
1423
-	if ($url === null) {
1424
-		return '';
1425
-	}
1426
-	# un message pour abs_url
1427
-	$GLOBALS['mode_abs_url'] = 'url';
1428
-	$url = trim($url);
1429
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1423
+    if ($url === null) {
1424
+        return '';
1425
+    }
1426
+    # un message pour abs_url
1427
+    $GLOBALS['mode_abs_url'] = 'url';
1428
+    $url = trim($url);
1429
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1430 1430
 
1431
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1431
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1432 1432
 }
1433 1433
 
1434 1434
 
@@ -1443,10 +1443,10 @@  discard block
 block discarded – undo
1443 1443
  * @return string Adresse email maquillée
1444 1444
  **/
1445 1445
 function antispam($texte) {
1446
-	include_spip('inc/acces');
1447
-	$masque = creer_pass_aleatoire(3);
1446
+    include_spip('inc/acces');
1447
+    $masque = creer_pass_aleatoire(3);
1448 1448
 
1449
-	return preg_replace('/@/', " $masque ", $texte);
1449
+    return preg_replace('/@/', " $masque ", $texte);
1450 1450
 }
1451 1451
 
1452 1452
 /**
@@ -1478,8 +1478,8 @@  discard block
 block discarded – undo
1478 1478
  *     True si on a le droit d'accès, false sinon.
1479 1479
  **/
1480 1480
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1481
-	include_spip('inc/acces');
1482
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1481
+    include_spip('inc/acces');
1482
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1483 1483
 }
1484 1484
 
1485 1485
 /**
@@ -1504,13 +1504,13 @@  discard block
 block discarded – undo
1504 1504
  *     Retourne $texte, sinon $sinon.
1505 1505
  **/
1506 1506
 function sinon($texte, $sinon = '') {
1507
-	if ($texte) {
1508
-		return $texte;
1509
-	} elseif (is_scalar($texte) and strlen($texte)) {
1510
-		return $texte;
1511
-	} else {
1512
-		return $sinon;
1513
-	}
1507
+    if ($texte) {
1508
+        return $texte;
1509
+    } elseif (is_scalar($texte) and strlen($texte)) {
1510
+        return $texte;
1511
+    } else {
1512
+        return $sinon;
1513
+    }
1514 1514
 }
1515 1515
 
1516 1516
 /**
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
  * @return mixed
1535 1535
  **/
1536 1536
 function choixsivide($a, $vide, $pasvide) {
1537
-	return $a ? $pasvide : $vide;
1537
+    return $a ? $pasvide : $vide;
1538 1538
 }
1539 1539
 
1540 1540
 /**
@@ -1558,7 +1558,7 @@  discard block
 block discarded – undo
1558 1558
  * @return mixed
1559 1559
  **/
1560 1560
 function choixsiegal($a1, $a2, $v, $f) {
1561
-	return ($a1 == $a2) ? $v : $f;
1561
+    return ($a1 == $a2) ? $v : $f;
1562 1562
 }
1563 1563
 
1564 1564
 //
@@ -1577,13 +1577,13 @@  discard block
 block discarded – undo
1577 1577
  * @return string
1578 1578
  **/
1579 1579
 function filtrer_ical($texte) {
1580
-	#include_spip('inc/charsets');
1581
-	$texte = html2unicode($texte);
1582
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1583
-	$texte = preg_replace("/\n/", ' ', $texte);
1584
-	$texte = preg_replace('/,/', '\,', $texte);
1580
+    #include_spip('inc/charsets');
1581
+    $texte = html2unicode($texte);
1582
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1583
+    $texte = preg_replace("/\n/", ' ', $texte);
1584
+    $texte = preg_replace('/,/', '\,', $texte);
1585 1585
 
1586
-	return $texte;
1586
+    return $texte;
1587 1587
 }
1588 1588
 
1589 1589
 
@@ -1608,54 +1608,54 @@  discard block
 block discarded – undo
1608 1608
  * @return string
1609 1609
  **/
1610 1610
 function post_autobr($texte, $delim = "\n_ ") {
1611
-	if (!function_exists('echappe_html')) {
1612
-		include_spip('inc/texte_mini');
1613
-	}
1614
-	$texte = str_replace("\r\n", "\r", $texte);
1615
-	$texte = str_replace("\r", "\n", $texte);
1616
-
1617
-	if (preg_match(",\n+$,", $texte, $fin)) {
1618
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1619
-	} else {
1620
-		$fin = '';
1621
-	}
1622
-
1623
-	$texte = echappe_html($texte, '', true);
1624
-
1625
-	// echapper les modeles
1626
-	if (strpos($texte, '<') !== false) {
1627
-		include_spip('inc/lien');
1628
-		if (defined('_PREG_MODELE')) {
1629
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1630
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1631
-		}
1632
-	}
1633
-
1634
-	$debut = '';
1635
-	$suite = $texte;
1636
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1637
-		$debut .= substr($suite, 0, $t - 1);
1638
-		$suite = substr($suite, $t);
1639
-		$car = substr($suite, 0, 1);
1640
-		if (
1641
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1642
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1643
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1644
-		) {
1645
-			$debut .= $delim;
1646
-		} else {
1647
-			$debut .= "\n";
1648
-		}
1649
-		if (preg_match(",^\n+,", $suite, $regs)) {
1650
-			$debut .= $regs[0];
1651
-			$suite = substr($suite, strlen($regs[0]));
1652
-		}
1653
-	}
1654
-	$texte = $debut . $suite;
1655
-
1656
-	$texte = echappe_retour($texte);
1657
-
1658
-	return $texte . $fin;
1611
+    if (!function_exists('echappe_html')) {
1612
+        include_spip('inc/texte_mini');
1613
+    }
1614
+    $texte = str_replace("\r\n", "\r", $texte);
1615
+    $texte = str_replace("\r", "\n", $texte);
1616
+
1617
+    if (preg_match(",\n+$,", $texte, $fin)) {
1618
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1619
+    } else {
1620
+        $fin = '';
1621
+    }
1622
+
1623
+    $texte = echappe_html($texte, '', true);
1624
+
1625
+    // echapper les modeles
1626
+    if (strpos($texte, '<') !== false) {
1627
+        include_spip('inc/lien');
1628
+        if (defined('_PREG_MODELE')) {
1629
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1630
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1631
+        }
1632
+    }
1633
+
1634
+    $debut = '';
1635
+    $suite = $texte;
1636
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1637
+        $debut .= substr($suite, 0, $t - 1);
1638
+        $suite = substr($suite, $t);
1639
+        $car = substr($suite, 0, 1);
1640
+        if (
1641
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1642
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1643
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1644
+        ) {
1645
+            $debut .= $delim;
1646
+        } else {
1647
+            $debut .= "\n";
1648
+        }
1649
+        if (preg_match(",^\n+,", $suite, $regs)) {
1650
+            $debut .= $regs[0];
1651
+            $suite = substr($suite, strlen($regs[0]));
1652
+        }
1653
+    }
1654
+    $texte = $debut . $suite;
1655
+
1656
+    $texte = echappe_retour($texte);
1657
+
1658
+    return $texte . $fin;
1659 1659
 }
1660 1660
 
1661 1661
 
@@ -1696,47 +1696,47 @@  discard block
 block discarded – undo
1696 1696
  * @return string
1697 1697
  **/
1698 1698
 function extraire_idiome($letexte, $lang = null, $options = []) {
1699
-	static $traduire = false;
1700
-	if (
1701
-		$letexte
1702
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1703
-	) {
1704
-		if (!$traduire) {
1705
-			$traduire = charger_fonction('traduire', 'inc');
1706
-			include_spip('inc/lang');
1707
-		}
1708
-		if (!$lang) {
1709
-			$lang = $GLOBALS['spip_lang'];
1710
-		}
1711
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1712
-		if (is_bool($options)) {
1713
-			$options = ['echappe_span' => $options];
1714
-		}
1715
-		if (!isset($options['echappe_span'])) {
1716
-			$options = array_merge($options, ['echappe_span' => false]);
1717
-		}
1718
-
1719
-		foreach ($regs as $reg) {
1720
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1721
-			$desc = $traduire($cle, $lang, true);
1722
-			$l = $desc->langue;
1723
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1724
-			if (strlen($desc->texte)) {
1725
-				$trad = code_echappement($desc->texte, 'idiome', false);
1726
-				if ($l !== $lang) {
1727
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1728
-				}
1729
-				if (lang_dir($l) !== lang_dir($lang)) {
1730
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1731
-				}
1732
-				if (!$options['echappe_span']) {
1733
-					$trad = echappe_retour($trad, 'idiome');
1734
-				}
1735
-				$letexte = str_replace($reg[0], $trad, $letexte);
1736
-			}
1737
-		}
1738
-	}
1739
-	return $letexte;
1699
+    static $traduire = false;
1700
+    if (
1701
+        $letexte
1702
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1703
+    ) {
1704
+        if (!$traduire) {
1705
+            $traduire = charger_fonction('traduire', 'inc');
1706
+            include_spip('inc/lang');
1707
+        }
1708
+        if (!$lang) {
1709
+            $lang = $GLOBALS['spip_lang'];
1710
+        }
1711
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1712
+        if (is_bool($options)) {
1713
+            $options = ['echappe_span' => $options];
1714
+        }
1715
+        if (!isset($options['echappe_span'])) {
1716
+            $options = array_merge($options, ['echappe_span' => false]);
1717
+        }
1718
+
1719
+        foreach ($regs as $reg) {
1720
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1721
+            $desc = $traduire($cle, $lang, true);
1722
+            $l = $desc->langue;
1723
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1724
+            if (strlen($desc->texte)) {
1725
+                $trad = code_echappement($desc->texte, 'idiome', false);
1726
+                if ($l !== $lang) {
1727
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1728
+                }
1729
+                if (lang_dir($l) !== lang_dir($lang)) {
1730
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1731
+                }
1732
+                if (!$options['echappe_span']) {
1733
+                    $trad = echappe_retour($trad, 'idiome');
1734
+                }
1735
+                $letexte = str_replace($reg[0], $trad, $letexte);
1736
+            }
1737
+        }
1738
+    }
1739
+    return $letexte;
1740 1740
 }
1741 1741
 
1742 1742
 /**
@@ -1788,68 +1788,68 @@  discard block
 block discarded – undo
1788 1788
  **/
1789 1789
 function extraire_multi($letexte, $lang = null, $options = []) {
1790 1790
 
1791
-	if (
1792
-		$letexte
1793
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1794
-	) {
1795
-		if (!$lang) {
1796
-			$lang = $GLOBALS['spip_lang'];
1797
-		}
1798
-
1799
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1800
-		if (is_bool($options)) {
1801
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1802
-		}
1803
-		if (!isset($options['echappe_span'])) {
1804
-			$options = array_merge($options, ['echappe_span' => false]);
1805
-		}
1806
-		if (!isset($options['lang_defaut'])) {
1807
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1808
-		}
1809
-
1810
-		include_spip('inc/lang');
1811
-		foreach ($regs as $reg) {
1812
-			// chercher la version de la langue courante
1813
-			$trads = extraire_trads($reg[1]);
1814
-			if ($l = approcher_langue($trads, $lang)) {
1815
-				$trad = $trads[$l];
1816
-			} else {
1817
-				if ($options['lang_defaut'] == 'aucune') {
1818
-					$trad = '';
1819
-				} else {
1820
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1821
-					// ou la premiere dispo
1822
-					// mais typographier le texte selon les regles de celle-ci
1823
-					// Attention aux blocs multi sur plusieurs lignes
1824
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1825
-						$l = key($trads);
1826
-					}
1827
-					$trad = $trads[$l];
1828
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1829
-					$trad = $typographie($trad);
1830
-					// Tester si on echappe en span ou en div
1831
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1832
-					include_spip('inc/texte');
1833
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1834
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1835
-					if ($mode === 'div') {
1836
-						$trad = rtrim($trad) . "\n\n";
1837
-					}
1838
-					$trad = code_echappement($trad, 'multi', false, $mode);
1839
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1840
-					if (lang_dir($l) !== lang_dir($lang)) {
1841
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1842
-					}
1843
-					if (!$options['echappe_span']) {
1844
-						$trad = echappe_retour($trad, 'multi');
1845
-					}
1846
-				}
1847
-			}
1848
-			$letexte = str_replace($reg[0], $trad, $letexte);
1849
-		}
1850
-	}
1851
-
1852
-	return $letexte;
1791
+    if (
1792
+        $letexte
1793
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1794
+    ) {
1795
+        if (!$lang) {
1796
+            $lang = $GLOBALS['spip_lang'];
1797
+        }
1798
+
1799
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1800
+        if (is_bool($options)) {
1801
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1802
+        }
1803
+        if (!isset($options['echappe_span'])) {
1804
+            $options = array_merge($options, ['echappe_span' => false]);
1805
+        }
1806
+        if (!isset($options['lang_defaut'])) {
1807
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1808
+        }
1809
+
1810
+        include_spip('inc/lang');
1811
+        foreach ($regs as $reg) {
1812
+            // chercher la version de la langue courante
1813
+            $trads = extraire_trads($reg[1]);
1814
+            if ($l = approcher_langue($trads, $lang)) {
1815
+                $trad = $trads[$l];
1816
+            } else {
1817
+                if ($options['lang_defaut'] == 'aucune') {
1818
+                    $trad = '';
1819
+                } else {
1820
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1821
+                    // ou la premiere dispo
1822
+                    // mais typographier le texte selon les regles de celle-ci
1823
+                    // Attention aux blocs multi sur plusieurs lignes
1824
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1825
+                        $l = key($trads);
1826
+                    }
1827
+                    $trad = $trads[$l];
1828
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1829
+                    $trad = $typographie($trad);
1830
+                    // Tester si on echappe en span ou en div
1831
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1832
+                    include_spip('inc/texte');
1833
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1834
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1835
+                    if ($mode === 'div') {
1836
+                        $trad = rtrim($trad) . "\n\n";
1837
+                    }
1838
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1839
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1840
+                    if (lang_dir($l) !== lang_dir($lang)) {
1841
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1842
+                    }
1843
+                    if (!$options['echappe_span']) {
1844
+                        $trad = echappe_retour($trad, 'multi');
1845
+                    }
1846
+                }
1847
+            }
1848
+            $letexte = str_replace($reg[0], $trad, $letexte);
1849
+        }
1850
+    }
1851
+
1852
+    return $letexte;
1853 1853
 }
1854 1854
 
1855 1855
 /**
@@ -1865,21 +1865,21 @@  discard block
 block discarded – undo
1865 1865
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1866 1866
  **/
1867 1867
 function extraire_trads($bloc) {
1868
-	$trads = [];
1869
-	$lang = '';
1868
+    $trads = [];
1869
+    $lang = '';
1870 1870
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1871 1871
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1872
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1873
-		$texte = trim($regs[1]);
1874
-		if ($texte or $lang) {
1875
-			$trads[$lang] = $texte;
1876
-		}
1877
-		$bloc = substr($bloc, strlen($regs[0]));
1878
-		$lang = $regs[2];
1879
-	}
1880
-	$trads[$lang] = $bloc;
1872
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1873
+        $texte = trim($regs[1]);
1874
+        if ($texte or $lang) {
1875
+            $trads[$lang] = $texte;
1876
+        }
1877
+        $bloc = substr($bloc, strlen($regs[0]));
1878
+        $lang = $regs[2];
1879
+    }
1880
+    $trads[$lang] = $bloc;
1881 1881
 
1882
-	return $trads;
1882
+    return $trads;
1883 1883
 }
1884 1884
 
1885 1885
 
@@ -1890,7 +1890,7 @@  discard block
 block discarded – undo
1890 1890
  * @return string L'initiale en majuscule
1891 1891
  */
1892 1892
 function filtre_initiale($nom) {
1893
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1893
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1894 1894
 }
1895 1895
 
1896 1896
 
@@ -1935,33 +1935,33 @@  discard block
 block discarded – undo
1935 1935
  *      - null (interne) : si on empile
1936 1936
  **/
1937 1937
 function unique($donnee, $famille = '', $cpt = false) {
1938
-	static $mem = [];
1939
-	// permettre de vider la pile et de la restaurer
1940
-	// pour le calcul de introduction...
1941
-	if ($famille == '_spip_raz_') {
1942
-		$tmp = $mem;
1943
-		$mem = [];
1944
-
1945
-		return $tmp;
1946
-	} elseif ($famille == '_spip_set_') {
1947
-		$mem = $donnee;
1948
-
1949
-		return;
1950
-	}
1951
-	// eviter une notice
1952
-	if (!isset($mem[$famille])) {
1953
-		$mem[$famille] = [];
1954
-	}
1955
-	if ($cpt) {
1956
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1957
-	}
1958
-	// eviter une notice
1959
-	if (!isset($mem[$famille][$donnee])) {
1960
-		$mem[$famille][$donnee] = 0;
1961
-	}
1962
-	if (!($mem[$famille][$donnee]++)) {
1963
-		return $donnee;
1964
-	}
1938
+    static $mem = [];
1939
+    // permettre de vider la pile et de la restaurer
1940
+    // pour le calcul de introduction...
1941
+    if ($famille == '_spip_raz_') {
1942
+        $tmp = $mem;
1943
+        $mem = [];
1944
+
1945
+        return $tmp;
1946
+    } elseif ($famille == '_spip_set_') {
1947
+        $mem = $donnee;
1948
+
1949
+        return;
1950
+    }
1951
+    // eviter une notice
1952
+    if (!isset($mem[$famille])) {
1953
+        $mem[$famille] = [];
1954
+    }
1955
+    if ($cpt) {
1956
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1957
+    }
1958
+    // eviter une notice
1959
+    if (!isset($mem[$famille][$donnee])) {
1960
+        $mem[$famille][$donnee] = 0;
1961
+    }
1962
+    if (!($mem[$famille][$donnee]++)) {
1963
+        return $donnee;
1964
+    }
1965 1965
 }
1966 1966
 
1967 1967
 
@@ -1991,16 +1991,16 @@  discard block
 block discarded – undo
1991 1991
  *     Une des valeurs en fonction du compteur.
1992 1992
  **/
1993 1993
 function alterner($i, ...$args) {
1994
-	// recuperer les arguments (attention fonctions un peu space)
1995
-	$num = count($args);
1994
+    // recuperer les arguments (attention fonctions un peu space)
1995
+    $num = count($args);
1996 1996
 
1997
-	if ($num === 1 && is_array($args[0])) {
1998
-		$args = $args[0];
1999
-		$num = count($args);
2000
-	}
1997
+    if ($num === 1 && is_array($args[0])) {
1998
+        $args = $args[0];
1999
+        $num = count($args);
2000
+    }
2001 2001
 
2002
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
2003
-	return $args[(intval($i) - 1) % $num];
2002
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
2003
+    return $args[(intval($i) - 1) % $num];
2004 2004
 }
2005 2005
 
2006 2006
 
@@ -2026,51 +2026,51 @@  discard block
 block discarded – undo
2026 2026
  *     - null lorsque l’attribut n’existe pas.
2027 2027
  **/
2028 2028
 function extraire_attribut($balise, $attribut, $complet = false) {
2029
-	if (is_array($balise)) {
2030
-		array_walk(
2031
-			$balise,
2032
-			function (&$a, $key, $t) {
2033
-				$a = extraire_attribut($a, $t);
2034
-			},
2035
-			$attribut
2036
-		);
2037
-
2038
-		return $balise;
2039
-	}
2040
-	if (
2041
-		$balise
2042
-		&& preg_match(
2043
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2044
-			. $attribut
2045
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2046
-			$balise,
2047
-			$r
2048
-		)
2049
-	) {
2050
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2051
-			$r[4] = substr($r[3], 1, -1);
2052
-			$r[3] = $r[3][0];
2053
-		} elseif ($r[3] !== '') {
2054
-			$r[4] = $r[3];
2055
-			$r[3] = '';
2056
-		} else {
2057
-			$r[4] = trim($r[2]);
2058
-		}
2059
-		$att = $r[4];
2060
-		if (strpos($att, '&#') !== false) {
2061
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2062
-		}
2063
-		$att = filtrer_entites($att);
2064
-	} else {
2065
-		$att = null;
2066
-		$r = [];
2067
-	}
2068
-
2069
-	if ($complet) {
2070
-		return [$att, $r];
2071
-	} else {
2072
-		return $att;
2073
-	}
2029
+    if (is_array($balise)) {
2030
+        array_walk(
2031
+            $balise,
2032
+            function (&$a, $key, $t) {
2033
+                $a = extraire_attribut($a, $t);
2034
+            },
2035
+            $attribut
2036
+        );
2037
+
2038
+        return $balise;
2039
+    }
2040
+    if (
2041
+        $balise
2042
+        && preg_match(
2043
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2044
+            . $attribut
2045
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2046
+            $balise,
2047
+            $r
2048
+        )
2049
+    ) {
2050
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2051
+            $r[4] = substr($r[3], 1, -1);
2052
+            $r[3] = $r[3][0];
2053
+        } elseif ($r[3] !== '') {
2054
+            $r[4] = $r[3];
2055
+            $r[3] = '';
2056
+        } else {
2057
+            $r[4] = trim($r[2]);
2058
+        }
2059
+        $att = $r[4];
2060
+        if (strpos($att, '&#') !== false) {
2061
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2062
+        }
2063
+        $att = filtrer_entites($att);
2064
+    } else {
2065
+        $att = null;
2066
+        $r = [];
2067
+    }
2068
+
2069
+    if ($complet) {
2070
+        return [$att, $r];
2071
+    } else {
2072
+        return $att;
2073
+    }
2074 2074
 }
2075 2075
 
2076 2076
 /**
@@ -2103,41 +2103,41 @@  discard block
 block discarded – undo
2103 2103
  **/
2104 2104
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2105 2105
 
2106
-	if ($balise === null or $balise === '') {
2107
-		return '';
2108
-	}
2106
+    if ($balise === null or $balise === '') {
2107
+        return '';
2108
+    }
2109 2109
 
2110
-	// preparer l'attribut
2111
-	// supprimer les &nbsp; etc mais pas les balises html
2112
-	// qui ont un sens dans un attribut value d'un input
2113
-	if ($proteger) {
2114
-		$val = attribut_html($val, false);
2115
-	}
2110
+    // preparer l'attribut
2111
+    // supprimer les &nbsp; etc mais pas les balises html
2112
+    // qui ont un sens dans un attribut value d'un input
2113
+    if ($proteger) {
2114
+        $val = attribut_html($val, false);
2115
+    }
2116 2116
 
2117
-	// echapper les ' pour eviter tout bug
2118
-	$val = str_replace("'", '&#039;', $val);
2119
-	if ($vider and strlen($val) === 0) {
2120
-		$insert = '';
2121
-	} else {
2122
-		$insert = " $attribut='$val'";
2123
-	}
2117
+    // echapper les ' pour eviter tout bug
2118
+    $val = str_replace("'", '&#039;', $val);
2119
+    if ($vider and strlen($val) === 0) {
2120
+        $insert = '';
2121
+    } else {
2122
+        $insert = " $attribut='$val'";
2123
+    }
2124 2124
 
2125
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2125
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2126 2126
 
2127
-	if ($old !== null) {
2128
-		// Remplacer l'ancien attribut du meme nom
2129
-		$balise = $r[1] . $insert . $r[5];
2130
-	} else {
2131
-		// preferer une balise " />" (comme <img />)
2132
-		if (preg_match(',/>,', $balise)) {
2133
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2134
-		} // sinon une balise <a ...> ... </a>
2135
-		else {
2136
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2137
-		}
2138
-	}
2127
+    if ($old !== null) {
2128
+        // Remplacer l'ancien attribut du meme nom
2129
+        $balise = $r[1] . $insert . $r[5];
2130
+    } else {
2131
+        // preferer une balise " />" (comme <img />)
2132
+        if (preg_match(',/>,', $balise)) {
2133
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2134
+        } // sinon une balise <a ...> ... </a>
2135
+        else {
2136
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2137
+        }
2138
+    }
2139 2139
 
2140
-	return $balise;
2140
+    return $balise;
2141 2141
 }
2142 2142
 
2143 2143
 /**
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
  * @return string Code HTML sans l'attribut
2156 2156
  **/
2157 2157
 function vider_attribut(?string $balise, string $attribut): string {
2158
-	return inserer_attribut($balise, $attribut, '', false, true);
2158
+    return inserer_attribut($balise, $attribut, '', false, true);
2159 2159
 }
2160 2160
 
2161 2161
 /**
@@ -2167,53 +2167,53 @@  discard block
 block discarded – undo
2167 2167
  * @return string
2168 2168
  */
2169 2169
 function modifier_class($balise, $class, $operation = 'ajouter') {
2170
-	if (is_string($class)) {
2171
-		$class = explode(' ', trim($class));
2172
-	}
2173
-	$class = array_filter($class);
2174
-	$class = array_unique($class);
2175
-	if (!$class) {
2176
-		return $balise;
2177
-	}
2178
-
2179
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2180
-	if (preg_match(',[^\w-],', implode('', $class))) {
2181
-		return $balise;
2182
-	}
2183
-
2184
-	$class_courante = extraire_attribut($balise, 'class');
2185
-	$class_new = $class_courante;
2186
-	foreach ($class as $c) {
2187
-		$is_class_presente = false;
2188
-		if (
2189
-			$class_courante
2190
-			and strpos($class_courante, (string) $c) !== false
2191
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2192
-		) {
2193
-			$is_class_presente = true;
2194
-		}
2195
-		if (
2196
-			in_array($operation, ['ajouter', 'commuter'])
2197
-			and !$is_class_presente
2198
-		) {
2199
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2200
-		} elseif (
2201
-			in_array($operation, ['supprimer', 'commuter'])
2202
-			and $is_class_presente
2203
-		) {
2204
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2205
-		}
2206
-	}
2207
-
2208
-	if ($class_new !== $class_courante) {
2209
-		if (strlen($class_new)) {
2210
-			$balise = inserer_attribut($balise, 'class', $class_new);
2211
-		} elseif ($class_courante) {
2212
-			$balise = vider_attribut($balise, 'class');
2213
-		}
2214
-	}
2215
-
2216
-	return $balise;
2170
+    if (is_string($class)) {
2171
+        $class = explode(' ', trim($class));
2172
+    }
2173
+    $class = array_filter($class);
2174
+    $class = array_unique($class);
2175
+    if (!$class) {
2176
+        return $balise;
2177
+    }
2178
+
2179
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2180
+    if (preg_match(',[^\w-],', implode('', $class))) {
2181
+        return $balise;
2182
+    }
2183
+
2184
+    $class_courante = extraire_attribut($balise, 'class');
2185
+    $class_new = $class_courante;
2186
+    foreach ($class as $c) {
2187
+        $is_class_presente = false;
2188
+        if (
2189
+            $class_courante
2190
+            and strpos($class_courante, (string) $c) !== false
2191
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2192
+        ) {
2193
+            $is_class_presente = true;
2194
+        }
2195
+        if (
2196
+            in_array($operation, ['ajouter', 'commuter'])
2197
+            and !$is_class_presente
2198
+        ) {
2199
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2200
+        } elseif (
2201
+            in_array($operation, ['supprimer', 'commuter'])
2202
+            and $is_class_presente
2203
+        ) {
2204
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2205
+        }
2206
+    }
2207
+
2208
+    if ($class_new !== $class_courante) {
2209
+        if (strlen($class_new)) {
2210
+            $balise = inserer_attribut($balise, 'class', $class_new);
2211
+        } elseif ($class_courante) {
2212
+            $balise = vider_attribut($balise, 'class');
2213
+        }
2214
+    }
2215
+
2216
+    return $balise;
2217 2217
 }
2218 2218
 
2219 2219
 /**
@@ -2223,7 +2223,7 @@  discard block
 block discarded – undo
2223 2223
  * @return string
2224 2224
  */
2225 2225
 function ajouter_class($balise, $class) {
2226
-	return modifier_class($balise, $class, 'ajouter');
2226
+    return modifier_class($balise, $class, 'ajouter');
2227 2227
 }
2228 2228
 
2229 2229
 /**
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
  * @return string
2234 2234
  */
2235 2235
 function supprimer_class($balise, $class) {
2236
-	return modifier_class($balise, $class, 'supprimer');
2236
+    return modifier_class($balise, $class, 'supprimer');
2237 2237
 }
2238 2238
 
2239 2239
 /**
@@ -2244,7 +2244,7 @@  discard block
 block discarded – undo
2244 2244
  * @return string
2245 2245
  */
2246 2246
 function commuter_class($balise, $class) {
2247
-	return modifier_class($balise, $class, 'commuter');
2247
+    return modifier_class($balise, $class, 'commuter');
2248 2248
 }
2249 2249
 
2250 2250
 /**
@@ -2255,19 +2255,19 @@  discard block
 block discarded – undo
2255 2255
  * @return string
2256 2256
  */
2257 2257
 function tester_config($id, $mode = '') {
2258
-	include_spip('action/inscrire_auteur');
2258
+    include_spip('action/inscrire_auteur');
2259 2259
 
2260
-	return tester_statut_inscription($mode, $id);
2260
+    return tester_statut_inscription($mode, $id);
2261 2261
 }
2262 2262
 
2263 2263
 //
2264 2264
 // Quelques fonctions de calcul arithmetique
2265 2265
 //
2266 2266
 function floatstr($a) {
2267
- return str_replace(',', '.', (string)floatval($a));
2267
+    return str_replace(',', '.', (string)floatval($a));
2268 2268
 }
2269 2269
 function strize($f, $a, $b) {
2270
- return floatstr($f(floatstr($a), floatstr($b)));
2270
+    return floatstr($f(floatstr($a), floatstr($b)));
2271 2271
 }
2272 2272
 
2273 2273
 /**
@@ -2286,7 +2286,7 @@  discard block
 block discarded – undo
2286 2286
  * @return int $a+$b
2287 2287
  **/
2288 2288
 function plus($a, $b) {
2289
-	return $a + $b;
2289
+    return $a + $b;
2290 2290
 }
2291 2291
 function strplus($a, $b) {
2292 2292
 return strize('plus', $a, $b);
@@ -2307,7 +2307,7 @@  discard block
 block discarded – undo
2307 2307
  * @return int $a-$b
2308 2308
  **/
2309 2309
 function moins($a, $b) {
2310
-	return $a - $b;
2310
+    return $a - $b;
2311 2311
 }
2312 2312
 function strmoins($a, $b) {
2313 2313
 return strize('moins', $a, $b);
@@ -2330,7 +2330,7 @@  discard block
 block discarded – undo
2330 2330
  * @return int $a*$b
2331 2331
  **/
2332 2332
 function mult($a, $b) {
2333
-	return $a * $b;
2333
+    return $a * $b;
2334 2334
 }
2335 2335
 function strmult($a, $b) {
2336 2336
 return strize('mult', $a, $b);
@@ -2353,7 +2353,7 @@  discard block
 block discarded – undo
2353 2353
  * @return int $a/$b (ou 0 si $b est nul)
2354 2354
  **/
2355 2355
 function div($a, $b) {
2356
-	return $b ? $a / $b : 0;
2356
+    return $b ? $a / $b : 0;
2357 2357
 }
2358 2358
 function strdiv($a, $b) {
2359 2359
 return strize('div', $a, $b);
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
  * @return int ($nb % $mod) + $add
2378 2378
  **/
2379 2379
 function modulo($nb, $mod, $add = 0) {
2380
-	return ($mod ? $nb % $mod : 0) + $add;
2380
+    return ($mod ? $nb % $mod : 0) + $add;
2381 2381
 }
2382 2382
 
2383 2383
 
@@ -2392,26 +2392,26 @@  discard block
 block discarded – undo
2392 2392
  *      - true sinon
2393 2393
  **/
2394 2394
 function nom_acceptable($nom) {
2395
-	$remp2 = [];
2396
-	$remp1 = [];
2397
-	if (!is_string($nom)) {
2398
-		return false;
2399
-	}
2400
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2401
-		define('_TAGS_NOM_AUTEUR', '');
2402
-	}
2403
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2404
-	foreach ($tags_acceptes as $tag) {
2405
-		if (strlen($tag)) {
2406
-			$remp1[] = '<' . trim($tag) . '>';
2407
-			$remp1[] = '</' . trim($tag) . '>';
2408
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2409
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2410
-		}
2411
-	}
2412
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2413
-
2414
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2395
+    $remp2 = [];
2396
+    $remp1 = [];
2397
+    if (!is_string($nom)) {
2398
+        return false;
2399
+    }
2400
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2401
+        define('_TAGS_NOM_AUTEUR', '');
2402
+    }
2403
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2404
+    foreach ($tags_acceptes as $tag) {
2405
+        if (strlen($tag)) {
2406
+            $remp1[] = '<' . trim($tag) . '>';
2407
+            $remp1[] = '</' . trim($tag) . '>';
2408
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2409
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2410
+        }
2411
+    }
2412
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2413
+
2414
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2415 2415
 }
2416 2416
 
2417 2417
 
@@ -2427,14 +2427,14 @@  discard block
 block discarded – undo
2427 2427
  *      - renvoie un tableau si l'entree est un tableau
2428 2428
  **/
2429 2429
 function email_valide($adresses) {
2430
-	if (is_array($adresses)) {
2431
-		$adresses = array_map('email_valide', $adresses);
2432
-		$adresses = array_filter($adresses);
2433
-		return $adresses;
2434
-	}
2430
+    if (is_array($adresses)) {
2431
+        $adresses = array_map('email_valide', $adresses);
2432
+        $adresses = array_filter($adresses);
2433
+        return $adresses;
2434
+    }
2435 2435
 
2436
-	$email_valide = charger_fonction('email_valide', 'inc');
2437
-	return $email_valide($adresses);
2436
+    $email_valide = charger_fonction('email_valide', 'inc');
2437
+    return $email_valide($adresses);
2438 2438
 }
2439 2439
 
2440 2440
 /**
@@ -2448,27 +2448,27 @@  discard block
 block discarded – undo
2448 2448
  * @return string Texte
2449 2449
  **/
2450 2450
 function afficher_enclosures($tags) {
2451
-	$s = [];
2452
-	foreach (extraire_balises($tags, 'a') as $tag) {
2453
-		if (
2454
-			extraire_attribut($tag, 'rel') == 'enclosure'
2455
-			and $t = extraire_attribut($tag, 'href')
2456
-		) {
2457
-			$s[] = preg_replace(
2458
-				',>[^<]+</a>,S',
2459
-				'>'
2460
-				. http_img_pack(
2461
-					'attachment-16.png',
2462
-					$t,
2463
-					'title="' . attribut_html($t) . '"'
2464
-				)
2465
-				. '</a>',
2466
-				$tag
2467
-			);
2468
-		}
2469
-	}
2470
-
2471
-	return join('&nbsp;', $s);
2451
+    $s = [];
2452
+    foreach (extraire_balises($tags, 'a') as $tag) {
2453
+        if (
2454
+            extraire_attribut($tag, 'rel') == 'enclosure'
2455
+            and $t = extraire_attribut($tag, 'href')
2456
+        ) {
2457
+            $s[] = preg_replace(
2458
+                ',>[^<]+</a>,S',
2459
+                '>'
2460
+                . http_img_pack(
2461
+                    'attachment-16.png',
2462
+                    $t,
2463
+                    'title="' . attribut_html($t) . '"'
2464
+                )
2465
+                . '</a>',
2466
+                $tag
2467
+            );
2468
+        }
2469
+    }
2470
+
2471
+    return join('&nbsp;', $s);
2472 2472
 }
2473 2473
 
2474 2474
 /**
@@ -2483,15 +2483,15 @@  discard block
 block discarded – undo
2483 2483
  * @return string Liens trouvés
2484 2484
  **/
2485 2485
 function afficher_tags($tags, $rels = 'tag,directory') {
2486
-	$s = [];
2487
-	foreach (extraire_balises($tags, 'a') as $tag) {
2488
-		$rel = extraire_attribut($tag, 'rel');
2489
-		if (strstr(",$rels,", (string) ",$rel,")) {
2490
-			$s[] = $tag;
2491
-		}
2492
-	}
2486
+    $s = [];
2487
+    foreach (extraire_balises($tags, 'a') as $tag) {
2488
+        $rel = extraire_attribut($tag, 'rel');
2489
+        if (strstr(",$rels,", (string) ",$rel,")) {
2490
+            $s[] = $tag;
2491
+        }
2492
+    }
2493 2493
 
2494
-	return join(', ', $s);
2494
+    return join(', ', $s);
2495 2495
 }
2496 2496
 
2497 2497
 
@@ -2513,21 +2513,21 @@  discard block
 block discarded – undo
2513 2513
  * @return string Tag HTML `<a>` avec microformat.
2514 2514
  **/
2515 2515
 function enclosure2microformat($e) {
2516
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2517
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2518
-	}
2519
-	$type = extraire_attribut($e, 'type');
2520
-	if (!$length = extraire_attribut($e, 'length')) {
2521
-		# <media:content : longeur dans fileSize. On tente.
2522
-		$length = extraire_attribut($e, 'fileSize');
2523
-	}
2524
-	$fichier = basename($url);
2516
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2517
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2518
+    }
2519
+    $type = extraire_attribut($e, 'type');
2520
+    if (!$length = extraire_attribut($e, 'length')) {
2521
+        # <media:content : longeur dans fileSize. On tente.
2522
+        $length = extraire_attribut($e, 'fileSize');
2523
+    }
2524
+    $fichier = basename($url);
2525 2525
 
2526
-	return '<a rel="enclosure"'
2527
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2528
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2529
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2530
-	. '>' . $fichier . '</a>';
2526
+    return '<a rel="enclosure"'
2527
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2528
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2529
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2530
+    . '>' . $fichier . '</a>';
2531 2531
 }
2532 2532
 
2533 2533
 /**
@@ -2545,24 +2545,24 @@  discard block
 block discarded – undo
2545 2545
  * @return string Tags RSS `<enclosure>`.
2546 2546
  **/
2547 2547
 function microformat2enclosure($tags) {
2548
-	$enclosures = [];
2549
-	foreach (extraire_balises($tags, 'a') as $e) {
2550
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2551
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2552
-			$type = extraire_attribut($e, 'type');
2553
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2554
-				$length = intval(extraire_attribut($e, 'length'));
2555
-			} # vieux data
2556
-			$fichier = basename($url);
2557
-			$enclosures[] = '<enclosure'
2558
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2559
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2560
-				. ($length ? ' length="' . $length . '"' : '')
2561
-				. ' />';
2562
-		}
2563
-	}
2548
+    $enclosures = [];
2549
+    foreach (extraire_balises($tags, 'a') as $e) {
2550
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2551
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2552
+            $type = extraire_attribut($e, 'type');
2553
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2554
+                $length = intval(extraire_attribut($e, 'length'));
2555
+            } # vieux data
2556
+            $fichier = basename($url);
2557
+            $enclosures[] = '<enclosure'
2558
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2559
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2560
+                . ($length ? ' length="' . $length . '"' : '')
2561
+                . ' />';
2562
+        }
2563
+    }
2564 2564
 
2565
-	return join("\n", $enclosures);
2565
+    return join("\n", $enclosures);
2566 2566
 }
2567 2567
 
2568 2568
 
@@ -2578,16 +2578,16 @@  discard block
 block discarded – undo
2578 2578
  * @return string Tags RSS Atom `<dc:subject>`.
2579 2579
  **/
2580 2580
 function tags2dcsubject($tags) {
2581
-	$subjects = '';
2582
-	foreach (extraire_balises($tags, 'a') as $e) {
2583
-		if (extraire_attribut($e, 'rel') == 'tag') {
2584
-			$subjects .= '<dc:subject>'
2585
-				. texte_backend(textebrut($e))
2586
-				. '</dc:subject>' . "\n";
2587
-		}
2588
-	}
2581
+    $subjects = '';
2582
+    foreach (extraire_balises($tags, 'a') as $e) {
2583
+        if (extraire_attribut($e, 'rel') == 'tag') {
2584
+            $subjects .= '<dc:subject>'
2585
+                . texte_backend(textebrut($e))
2586
+                . '</dc:subject>' . "\n";
2587
+        }
2588
+    }
2589 2589
 
2590
-	return $subjects;
2590
+    return $subjects;
2591 2591
 }
2592 2592
 
2593 2593
 /**
@@ -2616,27 +2616,27 @@  discard block
 block discarded – undo
2616 2616
  *     - Tableau de résultats, si tableau en entrée.
2617 2617
  **/
2618 2618
 function extraire_balise($texte, $tag = 'a') {
2619
-	if (is_array($texte)) {
2620
-		array_walk(
2621
-			$texte,
2622
-			function (&$a, $key, $t) {
2623
-				$a = extraire_balise($a, $t);
2624
-			},
2625
-			$tag
2626
-		);
2627
-
2628
-		return $texte;
2629
-	}
2630
-
2631
-	if (
2632
-		preg_match(
2633
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2634
-			$texte,
2635
-			$regs
2636
-		)
2637
-	) {
2638
-		return $regs[0];
2639
-	}
2619
+    if (is_array($texte)) {
2620
+        array_walk(
2621
+            $texte,
2622
+            function (&$a, $key, $t) {
2623
+                $a = extraire_balise($a, $t);
2624
+            },
2625
+            $tag
2626
+        );
2627
+
2628
+        return $texte;
2629
+    }
2630
+
2631
+    if (
2632
+        preg_match(
2633
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2634
+            $texte,
2635
+            $regs
2636
+        )
2637
+    ) {
2638
+        return $regs[0];
2639
+    }
2640 2640
 }
2641 2641
 
2642 2642
 /**
@@ -2664,30 +2664,30 @@  discard block
 block discarded – undo
2664 2664
  *     - Tableau de résultats, si tableau en entrée.
2665 2665
  **/
2666 2666
 function extraire_balises($texte, $tag = 'a') {
2667
-	if (is_array($texte)) {
2668
-		array_walk(
2669
-			$texte,
2670
-			function (&$a, $key, $t) {
2671
-				$a = extraire_balises($a, $t);
2672
-			},
2673
-			$tag
2674
-		);
2675
-
2676
-		return $texte;
2677
-	}
2678
-
2679
-	if (
2680
-		preg_match_all(
2681
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2682
-			$texte,
2683
-			$regs,
2684
-			PREG_PATTERN_ORDER
2685
-		)
2686
-	) {
2687
-		return $regs[0];
2688
-	} else {
2689
-		return [];
2690
-	}
2667
+    if (is_array($texte)) {
2668
+        array_walk(
2669
+            $texte,
2670
+            function (&$a, $key, $t) {
2671
+                $a = extraire_balises($a, $t);
2672
+            },
2673
+            $tag
2674
+        );
2675
+
2676
+        return $texte;
2677
+    }
2678
+
2679
+    if (
2680
+        preg_match_all(
2681
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2682
+            $texte,
2683
+            $regs,
2684
+            PREG_PATTERN_ORDER
2685
+        )
2686
+    ) {
2687
+        return $regs[0];
2688
+    } else {
2689
+        return [];
2690
+    }
2691 2691
 }
2692 2692
 
2693 2693
 /**
@@ -2716,11 +2716,11 @@  discard block
 block discarded – undo
2716 2716
  *     - `$def` si on n'a pas transmis de tableau
2717 2717
  **/
2718 2718
 function in_any($val, $vals, $def = '') {
2719
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2720
-		$vals = $v;
2721
-	}
2719
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2720
+        $vals = $v;
2721
+    }
2722 2722
 
2723
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2723
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2724 2724
 }
2725 2725
 
2726 2726
 
@@ -2741,12 +2741,12 @@  discard block
 block discarded – undo
2741 2741
  *     Résultat du calcul
2742 2742
  **/
2743 2743
 function valeur_numerique($expr) {
2744
-	$a = 0;
2745
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2746
-		eval("\$a = $expr;");
2747
-	}
2744
+    $a = 0;
2745
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2746
+        eval("\$a = $expr;");
2747
+    }
2748 2748
 
2749
-	return intval($a);
2749
+    return intval($a);
2750 2750
 }
2751 2751
 
2752 2752
 /**
@@ -2765,7 +2765,7 @@  discard block
 block discarded – undo
2765 2765
  *      Retourne `$a*$b/$c`
2766 2766
  **/
2767 2767
 function regledetrois($a, $b, $c) {
2768
-	return round($a * $b / $c);
2768
+    return round($a * $b / $c);
2769 2769
 }
2770 2770
 
2771 2771
 
@@ -2788,79 +2788,79 @@  discard block
 block discarded – undo
2788 2788
  * @return string Suite de champs input hidden
2789 2789
  **/
2790 2790
 function form_hidden(?string $action = ''): string {
2791
-	$action ??= '';
2792
-
2793
-	$contexte = [];
2794
-	include_spip('inc/urls');
2795
-	if (
2796
-		$p = urls_decoder_url($action, '')
2797
-		and reset($p)
2798
-	) {
2799
-		$fond = array_shift($p);
2800
-		if ($fond != '404') {
2801
-			$contexte = array_shift($p);
2802
-			$contexte['page'] = $fond;
2803
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2804
-		}
2805
-	}
2806
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2807
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2808
-		unset($contexte['type']);
2809
-	}
2810
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2811
-		unset($contexte['type-page']);
2812
-	}
2813
-
2814
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2815
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2816
-	$values = [];
2817
-
2818
-	// d'abord avec celles de l'url
2819
-	if (false !== ($p = strpos($action, '?'))) {
2820
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2821
-			$c = explode('=', $c, 2);
2822
-			$var = array_shift($c);
2823
-			$val = array_shift($c) ?? '';
2824
-			if ($var) {
2825
-				$val = rawurldecode($val);
2826
-				$var = rawurldecode($var); // decoder les [] eventuels
2827
-				if (preg_match(',\[\]$,S', $var)) {
2828
-					$values[] = [$var, $val];
2829
-				} else {
2830
-					if (!isset($values[$var])) {
2831
-						$values[$var] = [$var, $val];
2832
-					}
2833
-				}
2834
-			}
2835
-		}
2836
-	}
2837
-
2838
-	// ensuite avec celles du contexte, sans doublonner !
2839
-	foreach ($contexte as $var => $val) {
2840
-		if (preg_match(',\[\]$,S', $var)) {
2841
-			$values[] = [$var, $val];
2842
-		} else {
2843
-			if (!isset($values[$var])) {
2844
-				$values[$var] = [$var, $val];
2845
-			}
2846
-		}
2847
-	}
2848
-
2849
-	// puis on rassemble le tout
2850
-	$hidden = [];
2851
-	foreach ($values as $value) {
2852
-		[$var, $val] = $value;
2853
-		$hidden[] = '<input name="'
2854
-			. entites_html($var)
2855
-			. '"'
2856
-			. (is_null($val)
2857
-				? ''
2858
-				: ' value="' . entites_html($val) . '"'
2859
-			)
2860
-			. ' type="hidden"' . "\n/>";
2861
-	}
2862
-
2863
-	return join('', $hidden);
2791
+    $action ??= '';
2792
+
2793
+    $contexte = [];
2794
+    include_spip('inc/urls');
2795
+    if (
2796
+        $p = urls_decoder_url($action, '')
2797
+        and reset($p)
2798
+    ) {
2799
+        $fond = array_shift($p);
2800
+        if ($fond != '404') {
2801
+            $contexte = array_shift($p);
2802
+            $contexte['page'] = $fond;
2803
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2804
+        }
2805
+    }
2806
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2807
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2808
+        unset($contexte['type']);
2809
+    }
2810
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2811
+        unset($contexte['type-page']);
2812
+    }
2813
+
2814
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2815
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2816
+    $values = [];
2817
+
2818
+    // d'abord avec celles de l'url
2819
+    if (false !== ($p = strpos($action, '?'))) {
2820
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2821
+            $c = explode('=', $c, 2);
2822
+            $var = array_shift($c);
2823
+            $val = array_shift($c) ?? '';
2824
+            if ($var) {
2825
+                $val = rawurldecode($val);
2826
+                $var = rawurldecode($var); // decoder les [] eventuels
2827
+                if (preg_match(',\[\]$,S', $var)) {
2828
+                    $values[] = [$var, $val];
2829
+                } else {
2830
+                    if (!isset($values[$var])) {
2831
+                        $values[$var] = [$var, $val];
2832
+                    }
2833
+                }
2834
+            }
2835
+        }
2836
+    }
2837
+
2838
+    // ensuite avec celles du contexte, sans doublonner !
2839
+    foreach ($contexte as $var => $val) {
2840
+        if (preg_match(',\[\]$,S', $var)) {
2841
+            $values[] = [$var, $val];
2842
+        } else {
2843
+            if (!isset($values[$var])) {
2844
+                $values[$var] = [$var, $val];
2845
+            }
2846
+        }
2847
+    }
2848
+
2849
+    // puis on rassemble le tout
2850
+    $hidden = [];
2851
+    foreach ($values as $value) {
2852
+        [$var, $val] = $value;
2853
+        $hidden[] = '<input name="'
2854
+            . entites_html($var)
2855
+            . '"'
2856
+            . (is_null($val)
2857
+                ? ''
2858
+                : ' value="' . entites_html($val) . '"'
2859
+            )
2860
+            . ' type="hidden"' . "\n/>";
2861
+    }
2862
+
2863
+    return join('', $hidden);
2864 2864
 }
2865 2865
 
2866 2866
 
@@ -2882,7 +2882,7 @@  discard block
 block discarded – undo
2882 2882
  *    - la première valeur du tableau sinon.
2883 2883
  **/
2884 2884
 function filtre_reset($array) {
2885
-	return !is_array($array) ? null : reset($array);
2885
+    return !is_array($array) ? null : reset($array);
2886 2886
 }
2887 2887
 
2888 2888
 /**
@@ -2903,7 +2903,7 @@  discard block
 block discarded – undo
2903 2903
  *    - la dernière valeur du tableau sinon.
2904 2904
  **/
2905 2905
 function filtre_end($array) {
2906
-	return !is_array($array) ? null : end($array);
2906
+    return !is_array($array) ? null : end($array);
2907 2907
 }
2908 2908
 
2909 2909
 /**
@@ -2923,11 +2923,11 @@  discard block
 block discarded – undo
2923 2923
  *
2924 2924
  **/
2925 2925
 function filtre_push($array, $val) {
2926
-	if (!is_array($array) or !array_push($array, $val)) {
2927
-		return '';
2928
-	}
2926
+    if (!is_array($array) or !array_push($array, $val)) {
2927
+        return '';
2928
+    }
2929 2929
 
2930
-	return $array;
2930
+    return $array;
2931 2931
 }
2932 2932
 
2933 2933
 /**
@@ -2946,7 +2946,7 @@  discard block
 block discarded – undo
2946 2946
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2947 2947
  **/
2948 2948
 function filtre_find($array, $val) {
2949
-	return (is_array($array) and in_array($val, $array));
2949
+    return (is_array($array) and in_array($val, $array));
2950 2950
 }
2951 2951
 
2952 2952
 
@@ -2963,13 +2963,13 @@  discard block
 block discarded – undo
2963 2963
  *     Contenu avec urls en absolus
2964 2964
  **/
2965 2965
 function urls_absolues_css($contenu, $source) {
2966
-	$path = suivre_lien(url_absolue($source), './');
2966
+    $path = suivre_lien(url_absolue($source), './');
2967 2967
 
2968
-	return preg_replace_callback(
2969
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2970
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2971
-		$contenu
2972
-	);
2968
+    return preg_replace_callback(
2969
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2970
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2971
+        $contenu
2972
+    );
2973 2973
 }
2974 2974
 
2975 2975
 
@@ -2998,119 +2998,119 @@  discard block
 block discarded – undo
2998 2998
  *     Chemin du fichier CSS inversé
2999 2999
  **/
3000 3000
 function direction_css($css, $voulue = '') {
3001
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3002
-		return $css;
3003
-	}
3004
-	include_spip('inc/lang');
3005
-	// si on a precise le sens voulu en argument, le prendre en compte
3006
-	if ($voulue = strtolower($voulue)) {
3007
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
3008
-			$voulue = lang_dir($voulue);
3009
-		}
3010
-	} else {
3011
-		$voulue = lang_dir();
3012
-	}
3013
-
3014
-	$r = count($r) > 1;
3015
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3016
-	$dir = $r ? 'rtl' : 'ltr';
3017
-	$ndir = $r ? 'ltr' : 'rtl';
3018
-
3019
-	if ($voulue == $dir) {
3020
-		return $css;
3021
-	}
3022
-
3023
-	if (
3024
-		// url absolue
3025
-		preg_match(',^https?:,i', $css)
3026
-		// ou qui contient un ?
3027
-		or (($p = strpos($css, '?')) !== false)
3028
-	) {
3029
-		$distant = true;
3030
-		$cssf = parse_url($css);
3031
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3032
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
3033
-	} else {
3034
-		$distant = false;
3035
-		$cssf = $css;
3036
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3037
-		//propose (rien a faire dans ce cas)
3038
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3039
-		if (@file_exists($f)) {
3040
-			return $f;
3041
-		}
3042
-	}
3043
-
3044
-	// 2.
3045
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3046
-	$f = $dir_var
3047
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3048
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3049
-
3050
-	// la css peut etre distante (url absolue !)
3051
-	if ($distant) {
3052
-		include_spip('inc/distant');
3053
-		$res = recuperer_url($css);
3054
-		if (!$res or !$contenu = $res['page']) {
3055
-			return $css;
3056
-		}
3057
-	} else {
3058
-		if (
3059
-			(@filemtime($f) > @filemtime($css))
3060
-			and (_VAR_MODE != 'recalcul')
3061
-		) {
3062
-			return $f;
3063
-		}
3064
-		if (!lire_fichier($css, $contenu)) {
3065
-			return $css;
3066
-		}
3067
-	}
3068
-
3069
-
3070
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3071
-	include_spip('lib/csstidy/class.csstidy');
3072
-	$parser = new csstidy();
3073
-	$parser->set_cfg('optimise_shorthands', 0);
3074
-	$parser->set_cfg('reverse_left_and_right', true);
3075
-	$parser->parse($contenu);
3076
-
3077
-	$contenu = $parser->print->plain();
3078
-
3079
-
3080
-	// reperer les @import auxquels il faut propager le direction_css
3081
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3082
-	$src = [];
3083
-	$src_direction_css = [];
3084
-	$src_faux_abs = [];
3085
-	$d = dirname($css);
3086
-	foreach ($regs[1] as $k => $import_css) {
3087
-		$css_direction = direction_css("$d/$import_css", $voulue);
3088
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3089
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3090
-			$css_direction = substr($css_direction, strlen($d) + 1);
3091
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3092
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3093
-			$css_direction = substr($css_direction, strlen($dir_var));
3094
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3095
-			$css_direction = '/@@@@@@/' . $css_direction;
3096
-		}
3097
-		$src[] = $regs[0][$k];
3098
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3099
-	}
3100
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3101
-
3102
-	$contenu = urls_absolues_css($contenu, $css);
3103
-
3104
-	// virer les fausses url absolues que l'on a mis dans les import
3105
-	if (count($src_faux_abs)) {
3106
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3107
-	}
3108
-
3109
-	if (!ecrire_fichier($f, $contenu)) {
3110
-		return $css;
3111
-	}
3112
-
3113
-	return $f;
3001
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3002
+        return $css;
3003
+    }
3004
+    include_spip('inc/lang');
3005
+    // si on a precise le sens voulu en argument, le prendre en compte
3006
+    if ($voulue = strtolower($voulue)) {
3007
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
3008
+            $voulue = lang_dir($voulue);
3009
+        }
3010
+    } else {
3011
+        $voulue = lang_dir();
3012
+    }
3013
+
3014
+    $r = count($r) > 1;
3015
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3016
+    $dir = $r ? 'rtl' : 'ltr';
3017
+    $ndir = $r ? 'ltr' : 'rtl';
3018
+
3019
+    if ($voulue == $dir) {
3020
+        return $css;
3021
+    }
3022
+
3023
+    if (
3024
+        // url absolue
3025
+        preg_match(',^https?:,i', $css)
3026
+        // ou qui contient un ?
3027
+        or (($p = strpos($css, '?')) !== false)
3028
+    ) {
3029
+        $distant = true;
3030
+        $cssf = parse_url($css);
3031
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3032
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
3033
+    } else {
3034
+        $distant = false;
3035
+        $cssf = $css;
3036
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3037
+        //propose (rien a faire dans ce cas)
3038
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3039
+        if (@file_exists($f)) {
3040
+            return $f;
3041
+        }
3042
+    }
3043
+
3044
+    // 2.
3045
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3046
+    $f = $dir_var
3047
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3048
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3049
+
3050
+    // la css peut etre distante (url absolue !)
3051
+    if ($distant) {
3052
+        include_spip('inc/distant');
3053
+        $res = recuperer_url($css);
3054
+        if (!$res or !$contenu = $res['page']) {
3055
+            return $css;
3056
+        }
3057
+    } else {
3058
+        if (
3059
+            (@filemtime($f) > @filemtime($css))
3060
+            and (_VAR_MODE != 'recalcul')
3061
+        ) {
3062
+            return $f;
3063
+        }
3064
+        if (!lire_fichier($css, $contenu)) {
3065
+            return $css;
3066
+        }
3067
+    }
3068
+
3069
+
3070
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3071
+    include_spip('lib/csstidy/class.csstidy');
3072
+    $parser = new csstidy();
3073
+    $parser->set_cfg('optimise_shorthands', 0);
3074
+    $parser->set_cfg('reverse_left_and_right', true);
3075
+    $parser->parse($contenu);
3076
+
3077
+    $contenu = $parser->print->plain();
3078
+
3079
+
3080
+    // reperer les @import auxquels il faut propager le direction_css
3081
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3082
+    $src = [];
3083
+    $src_direction_css = [];
3084
+    $src_faux_abs = [];
3085
+    $d = dirname($css);
3086
+    foreach ($regs[1] as $k => $import_css) {
3087
+        $css_direction = direction_css("$d/$import_css", $voulue);
3088
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3089
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3090
+            $css_direction = substr($css_direction, strlen($d) + 1);
3091
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3092
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3093
+            $css_direction = substr($css_direction, strlen($dir_var));
3094
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3095
+            $css_direction = '/@@@@@@/' . $css_direction;
3096
+        }
3097
+        $src[] = $regs[0][$k];
3098
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3099
+    }
3100
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3101
+
3102
+    $contenu = urls_absolues_css($contenu, $css);
3103
+
3104
+    // virer les fausses url absolues que l'on a mis dans les import
3105
+    if (count($src_faux_abs)) {
3106
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3107
+    }
3108
+
3109
+    if (!ecrire_fichier($f, $contenu)) {
3110
+        return $css;
3111
+    }
3112
+
3113
+    return $f;
3114 3114
 }
3115 3115
 
3116 3116
 
@@ -3133,46 +3133,46 @@  discard block
 block discarded – undo
3133 3133
  *     - Chemin ou URL du fichier CSS source sinon.
3134 3134
  **/
3135 3135
 function url_absolue_css($css) {
3136
-	if (!preg_match(',\.css$,i', $css, $r)) {
3137
-		return $css;
3138
-	}
3136
+    if (!preg_match(',\.css$,i', $css, $r)) {
3137
+        return $css;
3138
+    }
3139 3139
 
3140
-	$url_absolue_css = url_absolue($css);
3140
+    $url_absolue_css = url_absolue($css);
3141 3141
 
3142
-	$f = basename($css, '.css');
3143
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3144
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3145
-		. '.css';
3142
+    $f = basename($css, '.css');
3143
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3144
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3145
+        . '.css';
3146 3146
 
3147
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3148
-		return $f;
3149
-	}
3147
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3148
+        return $f;
3149
+    }
3150 3150
 
3151
-	if ($url_absolue_css == $css) {
3152
-		if (
3153
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3154
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3155
-		) {
3156
-			include_spip('inc/distant');
3157
-			$contenu = recuperer_url($css);
3158
-			$contenu = $contenu['page'] ?? '';
3159
-			if (!$contenu) {
3160
-				return $css;
3161
-			}
3162
-		}
3163
-	} elseif (!lire_fichier($css, $contenu)) {
3164
-		return $css;
3165
-	}
3151
+    if ($url_absolue_css == $css) {
3152
+        if (
3153
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3154
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3155
+        ) {
3156
+            include_spip('inc/distant');
3157
+            $contenu = recuperer_url($css);
3158
+            $contenu = $contenu['page'] ?? '';
3159
+            if (!$contenu) {
3160
+                return $css;
3161
+            }
3162
+        }
3163
+    } elseif (!lire_fichier($css, $contenu)) {
3164
+        return $css;
3165
+    }
3166 3166
 
3167
-	// passer les url relatives a la css d'origine en url absolues
3168
-	$contenu = urls_absolues_css($contenu, $css);
3167
+    // passer les url relatives a la css d'origine en url absolues
3168
+    $contenu = urls_absolues_css($contenu, $css);
3169 3169
 
3170
-	// ecrire la css
3171
-	if (!ecrire_fichier($f, $contenu)) {
3172
-		return $css;
3173
-	}
3170
+    // ecrire la css
3171
+    if (!ecrire_fichier($f, $contenu)) {
3172
+        return $css;
3173
+    }
3174 3174
 
3175
-	return $f;
3175
+    return $f;
3176 3176
 }
3177 3177
 
3178 3178
 
@@ -3206,24 +3206,24 @@  discard block
 block discarded – undo
3206 3206
  *     Valeur trouvée ou valeur par défaut.
3207 3207
  **/
3208 3208
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3209
-	foreach (explode('/', $cle) as $k) {
3210
-		$table = (is_string($table) ? @unserialize($table) : $table);
3209
+    foreach (explode('/', $cle) as $k) {
3210
+        $table = (is_string($table) ? @unserialize($table) : $table);
3211 3211
 
3212
-		if (is_object($table)) {
3213
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3214
-		} elseif (is_array($table)) {
3215
-			if ($conserver_null) {
3216
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3217
-			} else {
3218
-				$table = ($table[$k] ?? $defaut);
3219
-			}
3220
-		} else {
3221
-			$table = $defaut;
3222
-			break;
3223
-		}
3224
-	}
3212
+        if (is_object($table)) {
3213
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3214
+        } elseif (is_array($table)) {
3215
+            if ($conserver_null) {
3216
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3217
+            } else {
3218
+                $table = ($table[$k] ?? $defaut);
3219
+            }
3220
+        } else {
3221
+            $table = $defaut;
3222
+            break;
3223
+        }
3224
+    }
3225 3225
 
3226
-	return $table;
3226
+    return $table;
3227 3227
 }
3228 3228
 
3229 3229
 /**
@@ -3256,22 +3256,22 @@  discard block
 block discarded – undo
3256 3256
  *     - string : expression trouvée.
3257 3257
  **/
3258 3258
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3259
-	if (intval($modif) and $capte == 0) {
3260
-		$capte = $modif;
3261
-		$modif = 'UimsS';
3262
-	}
3263
-	$expression = str_replace('\/', '/', $expression);
3264
-	$expression = str_replace('/', '\/', $expression);
3259
+    if (intval($modif) and $capte == 0) {
3260
+        $capte = $modif;
3261
+        $modif = 'UimsS';
3262
+    }
3263
+    $expression = str_replace('\/', '/', $expression);
3264
+    $expression = str_replace('/', '\/', $expression);
3265 3265
 
3266
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3267
-		if (isset($r[$capte])) {
3268
-			return $r[$capte];
3269
-		} else {
3270
-			return true;
3271
-		}
3272
-	}
3266
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3267
+        if (isset($r[$capte])) {
3268
+            return $r[$capte];
3269
+        } else {
3270
+            return true;
3271
+        }
3272
+    }
3273 3273
 
3274
-	return false;
3274
+    return false;
3275 3275
 }
3276 3276
 
3277 3277
 
@@ -3298,10 +3298,10 @@  discard block
 block discarded – undo
3298 3298
  *     Texte
3299 3299
  **/
3300 3300
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3301
-	$expression = str_replace('\/', '/', $expression);
3302
-	$expression = str_replace('/', '\/', $expression);
3301
+    $expression = str_replace('\/', '/', $expression);
3302
+    $expression = str_replace('/', '\/', $expression);
3303 3303
 
3304
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3304
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3305 3305
 }
3306 3306
 
3307 3307
 
@@ -3319,25 +3319,25 @@  discard block
 block discarded – undo
3319 3319
  **/
3320 3320
 function traiter_doublons_documents(&$doublons, $letexte) {
3321 3321
 
3322
-	// Verifier dans le texte & les notes (pas beau, helas)
3323
-	$t = $letexte . $GLOBALS['les_notes'];
3322
+    // Verifier dans le texte & les notes (pas beau, helas)
3323
+    $t = $letexte . $GLOBALS['les_notes'];
3324 3324
 
3325
-	if (
3326
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3327
-		and preg_match_all(
3328
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3329
-			$t,
3330
-			$matches,
3331
-			PREG_PATTERN_ORDER
3332
-		)
3333
-	) {
3334
-		if (!isset($doublons['documents'])) {
3335
-			$doublons['documents'] = '';
3336
-		}
3337
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3338
-	}
3325
+    if (
3326
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3327
+        and preg_match_all(
3328
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3329
+            $t,
3330
+            $matches,
3331
+            PREG_PATTERN_ORDER
3332
+        )
3333
+    ) {
3334
+        if (!isset($doublons['documents'])) {
3335
+            $doublons['documents'] = '';
3336
+        }
3337
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3338
+    }
3339 3339
 
3340
-	return $letexte;
3340
+    return $letexte;
3341 3341
 }
3342 3342
 
3343 3343
 /**
@@ -3351,7 +3351,7 @@  discard block
 block discarded – undo
3351 3351
  * @return string Chaîne vide
3352 3352
  **/
3353 3353
 function vide($texte) {
3354
-	return '';
3354
+    return '';
3355 3355
 }
3356 3356
 
3357 3357
 //
@@ -3380,23 +3380,23 @@  discard block
 block discarded – undo
3380 3380
  *      Code HTML résultant
3381 3381
  **/
3382 3382
 function env_to_params($env, $ignore_params = []) {
3383
-	$ignore_params = array_merge(
3384
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3385
-		$ignore_params
3386
-	);
3387
-	if (!is_array($env)) {
3388
-		$env = unserialize($env);
3389
-	}
3390
-	$texte = '';
3391
-	if ($env) {
3392
-		foreach ($env as $i => $j) {
3393
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3394
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3395
-			}
3396
-		}
3397
-	}
3398
-
3399
-	return $texte;
3383
+    $ignore_params = array_merge(
3384
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3385
+        $ignore_params
3386
+    );
3387
+    if (!is_array($env)) {
3388
+        $env = unserialize($env);
3389
+    }
3390
+    $texte = '';
3391
+    if ($env) {
3392
+        foreach ($env as $i => $j) {
3393
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3394
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3395
+            }
3396
+        }
3397
+    }
3398
+
3399
+    return $texte;
3400 3400
 }
3401 3401
 
3402 3402
 /**
@@ -3419,23 +3419,23 @@  discard block
 block discarded – undo
3419 3419
  *      Code HTML résultant
3420 3420
  **/
3421 3421
 function env_to_attributs($env, $ignore_params = []) {
3422
-	$ignore_params = array_merge(
3423
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3424
-		$ignore_params
3425
-	);
3426
-	if (!is_array($env)) {
3427
-		$env = unserialize($env);
3428
-	}
3429
-	$texte = '';
3430
-	if ($env) {
3431
-		foreach ($env as $i => $j) {
3432
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3433
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3434
-			}
3435
-		}
3436
-	}
3422
+    $ignore_params = array_merge(
3423
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3424
+        $ignore_params
3425
+    );
3426
+    if (!is_array($env)) {
3427
+        $env = unserialize($env);
3428
+    }
3429
+    $texte = '';
3430
+    if ($env) {
3431
+        foreach ($env as $i => $j) {
3432
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3433
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3434
+            }
3435
+        }
3436
+    }
3437 3437
 
3438
-	return $texte;
3438
+    return $texte;
3439 3439
 }
3440 3440
 
3441 3441
 
@@ -3453,7 +3453,7 @@  discard block
 block discarded – undo
3453 3453
  * @return string Chaînes concaténés
3454 3454
  **/
3455 3455
 function concat(...$args): string {
3456
-	return join('', $args);
3456
+    return join('', $args);
3457 3457
 }
3458 3458
 
3459 3459
 
@@ -3473,23 +3473,23 @@  discard block
 block discarded – undo
3473 3473
  *     Contenu du ou des fichiers, concaténé
3474 3474
  **/
3475 3475
 function charge_scripts($files, $script = true) {
3476
-	$flux = '';
3477
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3478
-		if (!is_string($file)) {
3479
-			continue;
3480
-		}
3481
-		if ($script) {
3482
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3483
-		}
3484
-		if ($file) {
3485
-			$path = find_in_path($file);
3486
-			if ($path) {
3487
-				$flux .= spip_file_get_contents($path);
3488
-			}
3489
-		}
3490
-	}
3491
-
3492
-	return $flux;
3476
+    $flux = '';
3477
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3478
+        if (!is_string($file)) {
3479
+            continue;
3480
+        }
3481
+        if ($script) {
3482
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3483
+        }
3484
+        if ($file) {
3485
+            $path = find_in_path($file);
3486
+            if ($path) {
3487
+                $flux .= spip_file_get_contents($path);
3488
+            }
3489
+        }
3490
+    }
3491
+
3492
+    return $flux;
3493 3493
 }
3494 3494
 
3495 3495
 /**
@@ -3500,22 +3500,22 @@  discard block
 block discarded – undo
3500 3500
  * @return string
3501 3501
  */
3502 3502
 function http_img_variante_svg_si_possible($img_file) {
3503
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3504
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3505
-	if (
3506
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3507
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3508
-		and file_exists($variante_svg_generique)
3509
-	) {
3510
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3511
-			$img_file = $variante_svg_size;
3512
-		}
3513
-		else {
3514
-			$img_file = $variante_svg_generique;
3515
-		}
3516
-	}
3503
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3504
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3505
+    if (
3506
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3507
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3508
+        and file_exists($variante_svg_generique)
3509
+    ) {
3510
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3511
+            $img_file = $variante_svg_size;
3512
+        }
3513
+        else {
3514
+            $img_file = $variante_svg_generique;
3515
+        }
3516
+    }
3517 3517
 
3518
-	return $img_file;
3518
+    return $img_file;
3519 3519
 }
3520 3520
 
3521 3521
 /**
@@ -3536,54 +3536,54 @@  discard block
 block discarded – undo
3536 3536
  */
3537 3537
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3538 3538
 
3539
-	$img_file = $img;
3540
-	if ($p = strpos($img_file, '?')) {
3541
-		$img_file = substr($img_file, 0, $p);
3542
-	}
3543
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3544
-		$img_file = chemin_image($img);
3545
-	}
3546
-	else {
3547
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3548
-			$img_file = http_img_variante_svg_si_possible($img_file);
3549
-		}
3550
-	}
3551
-	if (stripos($atts, 'width') === false) {
3552
-		// utiliser directement l'info de taille presente dans le nom
3553
-		if (
3554
-			(!isset($options['utiliser_suffixe_size'])
3555
-				or $options['utiliser_suffixe_size'] == true
3556
-			  or strpos($img_file, '-xx.svg') !== false)
3557
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3558
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3559
-		) {
3560
-			$largeur = $hauteur = intval($regs[1]);
3561
-		} else {
3562
-			$taille = taille_image($img_file);
3563
-			[$hauteur, $largeur] = $taille;
3564
-			if (!$hauteur or !$largeur) {
3565
-				return '';
3566
-			}
3567
-		}
3568
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3569
-	}
3570
-
3571
-	if (file_exists($img_file)) {
3572
-		$img_file = timestamp($img_file);
3573
-	}
3574
-	if ($alt === false) {
3575
-		$alt = '';
3576
-	}
3577
-	elseif ($alt or $alt === '') {
3578
-		$alt = " alt='" . attribut_html($alt) . "'";
3579
-	}
3580
-	else {
3581
-		$alt = " alt='" . attribut_html($title) . "'";
3582
-	}
3583
-	return "<img src='$img_file'$alt"
3584
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3585
-	. ' ' . ltrim($atts)
3586
-	. ' />';
3539
+    $img_file = $img;
3540
+    if ($p = strpos($img_file, '?')) {
3541
+        $img_file = substr($img_file, 0, $p);
3542
+    }
3543
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3544
+        $img_file = chemin_image($img);
3545
+    }
3546
+    else {
3547
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3548
+            $img_file = http_img_variante_svg_si_possible($img_file);
3549
+        }
3550
+    }
3551
+    if (stripos($atts, 'width') === false) {
3552
+        // utiliser directement l'info de taille presente dans le nom
3553
+        if (
3554
+            (!isset($options['utiliser_suffixe_size'])
3555
+                or $options['utiliser_suffixe_size'] == true
3556
+              or strpos($img_file, '-xx.svg') !== false)
3557
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3558
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3559
+        ) {
3560
+            $largeur = $hauteur = intval($regs[1]);
3561
+        } else {
3562
+            $taille = taille_image($img_file);
3563
+            [$hauteur, $largeur] = $taille;
3564
+            if (!$hauteur or !$largeur) {
3565
+                return '';
3566
+            }
3567
+        }
3568
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3569
+    }
3570
+
3571
+    if (file_exists($img_file)) {
3572
+        $img_file = timestamp($img_file);
3573
+    }
3574
+    if ($alt === false) {
3575
+        $alt = '';
3576
+    }
3577
+    elseif ($alt or $alt === '') {
3578
+        $alt = " alt='" . attribut_html($alt) . "'";
3579
+    }
3580
+    else {
3581
+        $alt = " alt='" . attribut_html($title) . "'";
3582
+    }
3583
+    return "<img src='$img_file'$alt"
3584
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3585
+    . ' ' . ltrim($atts)
3586
+    . ' />';
3587 3587
 }
3588 3588
 
3589 3589
 /**
@@ -3595,70 +3595,70 @@  discard block
 block discarded – undo
3595 3595
  * @return string
3596 3596
  */
3597 3597
 function http_style_background($img, $att = '', $size = null) {
3598
-	if ($size and is_numeric($size)) {
3599
-		$size = trim($size) . 'px';
3600
-	}
3601
-	return " style='background" .
3602
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3603
-		. ($size ? "background-size:{$size};" : '')
3604
-		. "'";
3598
+    if ($size and is_numeric($size)) {
3599
+        $size = trim($size) . 'px';
3600
+    }
3601
+    return " style='background" .
3602
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3603
+        . ($size ? "background-size:{$size};" : '')
3604
+        . "'";
3605 3605
 }
3606 3606
 
3607 3607
 
3608 3608
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3609
-	$args = [$alt_or_size, $class_or_size, $size];
3610
-	while (is_null(end($args)) and count($args)) {
3611
-		array_pop($args);
3612
-	}
3613
-	if (!count($args)) {
3614
-		return [null, null, null];
3615
-	}
3616
-	if (count($args) < 3) {
3617
-		$maybe_size = array_pop($args);
3618
-		// @2x
3619
-		// @1.5x
3620
-		// 512
3621
-		// 512x*
3622
-		// 512x300
3623
-		if (
3624
-			!strlen($maybe_size)
3625
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3626
-		) {
3627
-			$args[] = $maybe_size;
3628
-			$maybe_size = null;
3629
-		}
3630
-		while (count($args) < 2) {
3631
-			$args[] = null; // default alt or class
3632
-		}
3633
-		$args[] = $maybe_size;
3634
-	}
3635
-	return $args;
3609
+    $args = [$alt_or_size, $class_or_size, $size];
3610
+    while (is_null(end($args)) and count($args)) {
3611
+        array_pop($args);
3612
+    }
3613
+    if (!count($args)) {
3614
+        return [null, null, null];
3615
+    }
3616
+    if (count($args) < 3) {
3617
+        $maybe_size = array_pop($args);
3618
+        // @2x
3619
+        // @1.5x
3620
+        // 512
3621
+        // 512x*
3622
+        // 512x300
3623
+        if (
3624
+            !strlen($maybe_size)
3625
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3626
+        ) {
3627
+            $args[] = $maybe_size;
3628
+            $maybe_size = null;
3629
+        }
3630
+        while (count($args) < 2) {
3631
+            $args[] = null; // default alt or class
3632
+        }
3633
+        $args[] = $maybe_size;
3634
+    }
3635
+    return $args;
3636 3636
 }
3637 3637
 
3638 3638
 function helper_filtre_balise_img_svg_size($img, $size) {
3639
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3640
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3641
-		$coef = floatval(substr($size, 1, -1));
3642
-		[$h, $w] = taille_image($img);
3643
-		$height = intval(round($h / $coef));
3644
-		$width = intval(round($w / $coef));
3645
-	}
3646
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3647
-	else {
3648
-		$size = explode('x', $size, 2);
3649
-		$size = array_map('trim', $size);
3650
-		$height = $width = intval(array_shift($size));
3651
-
3652
-		if (count($size) and reset($size)) {
3653
-			$height = array_shift($size);
3654
-			if ($height === '*') {
3655
-				[$h, $w] = taille_image($img);
3656
-				$height = intval(round($h * $width / $w));
3657
-			}
3658
-		}
3659
-	}
3660
-
3661
-	return [$width, $height];
3639
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3640
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3641
+        $coef = floatval(substr($size, 1, -1));
3642
+        [$h, $w] = taille_image($img);
3643
+        $height = intval(round($h / $coef));
3644
+        $width = intval(round($w / $coef));
3645
+    }
3646
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3647
+    else {
3648
+        $size = explode('x', $size, 2);
3649
+        $size = array_map('trim', $size);
3650
+        $height = $width = intval(array_shift($size));
3651
+
3652
+        if (count($size) and reset($size)) {
3653
+            $height = array_shift($size);
3654
+            if ($height === '*') {
3655
+                [$h, $w] = taille_image($img);
3656
+                $height = intval(round($h * $width / $w));
3657
+            }
3658
+        }
3659
+    }
3660
+
3661
+    return [$width, $height];
3662 3662
 }
3663 3663
 
3664 3664
 /**
@@ -3694,43 +3694,43 @@  discard block
 block discarded – undo
3694 3694
  */
3695 3695
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3696 3696
 
3697
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3698
-
3699
-	$img = trim((string) $img);
3700
-	if (strpos($img, '<img') === 0) {
3701
-		if (!is_null($alt)) {
3702
-			$img = inserer_attribut($img, 'alt', $alt);
3703
-		}
3704
-		if (!is_null($class)) {
3705
-			if (strlen($class)) {
3706
-				$img = inserer_attribut($img, 'class', $class);
3707
-			}
3708
-			else {
3709
-				$img = vider_attribut($img, 'class');
3710
-			}
3711
-		}
3712
-	}
3713
-	else {
3714
-		$img = http_img_pack(
3715
-			$img,
3716
-			$alt,
3717
-			$class ? " class='" . attribut_html($class) . "'" : '',
3718
-			'',
3719
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3720
-		);
3721
-		if (is_null($alt)) {
3722
-			$img = vider_attribut($img, 'alt');
3723
-		}
3724
-	}
3725
-
3726
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3727
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3728
-
3729
-		$img = inserer_attribut($img, 'width', $width);
3730
-		$img = inserer_attribut($img, 'height', $height);
3731
-	}
3732
-
3733
-	return $img;
3697
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3698
+
3699
+    $img = trim((string) $img);
3700
+    if (strpos($img, '<img') === 0) {
3701
+        if (!is_null($alt)) {
3702
+            $img = inserer_attribut($img, 'alt', $alt);
3703
+        }
3704
+        if (!is_null($class)) {
3705
+            if (strlen($class)) {
3706
+                $img = inserer_attribut($img, 'class', $class);
3707
+            }
3708
+            else {
3709
+                $img = vider_attribut($img, 'class');
3710
+            }
3711
+        }
3712
+    }
3713
+    else {
3714
+        $img = http_img_pack(
3715
+            $img,
3716
+            $alt,
3717
+            $class ? " class='" . attribut_html($class) . "'" : '',
3718
+            '',
3719
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3720
+        );
3721
+        if (is_null($alt)) {
3722
+            $img = vider_attribut($img, 'alt');
3723
+        }
3724
+    }
3725
+
3726
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3727
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3728
+
3729
+        $img = inserer_attribut($img, 'width', $width);
3730
+        $img = inserer_attribut($img, 'height', $height);
3731
+    }
3732
+
3733
+    return $img;
3734 3734
 }
3735 3735
 
3736 3736
 
@@ -3764,80 +3764,80 @@  discard block
 block discarded – undo
3764 3764
  */
3765 3765
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3766 3766
 
3767
-	$svg = null;
3768
-	$img = trim($img);
3769
-	$img_file = $img;
3770
-	if (strpos($img, '<svg') === false) {
3771
-		if ($p = strpos($img_file, '?')) {
3772
-			$img_file = substr($img_file, 0, $p);
3773
-		}
3774
-
3775
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3776
-		// la copie locale a toutes les chances d'etre la ou de resservir
3777
-		if (tester_url_absolue($img_file)) {
3778
-			include_spip('inc/distant');
3779
-			$fichier = copie_locale($img_file);
3780
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3781
-		}
3782
-
3783
-		if (
3784
-			!$img_file
3785
-			or !file_exists($img_file)
3786
-			or !$svg = file_get_contents($img_file)
3787
-		) {
3788
-			return '';
3789
-		}
3790
-	}
3791
-
3792
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3793
-		return '';
3794
-	}
3795
-
3796
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3797
-
3798
-	$balise_svg = $match[0];
3799
-	$balise_svg_source = $balise_svg;
3800
-
3801
-	// entete XML à supprimer
3802
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3803
-
3804
-	// IE est toujours mon ami
3805
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3806
-
3807
-	// regler la classe
3808
-	if (!is_null($class)) {
3809
-		if (strlen($class)) {
3810
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3811
-		}
3812
-		else {
3813
-			$balise_svg = vider_attribut($balise_svg, 'class');
3814
-		}
3815
-	}
3816
-
3817
-	// regler le alt
3818
-	if ($alt) {
3819
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3820
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3821
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3822
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3823
-		$balise_svg .= $title;
3824
-	}
3825
-	else {
3826
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3827
-	}
3828
-
3829
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3830
-
3831
-	if (!is_null($size) and strlen($size = trim($size))) {
3832
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3833
-
3834
-		if (!function_exists('svg_redimensionner')) {
3835
-			include_spip('inc/svg');
3836
-		}
3837
-		$svg = svg_redimensionner($svg, $width, $height);
3838
-	}
3839
-
3840
-	return $svg;
3767
+    $svg = null;
3768
+    $img = trim($img);
3769
+    $img_file = $img;
3770
+    if (strpos($img, '<svg') === false) {
3771
+        if ($p = strpos($img_file, '?')) {
3772
+            $img_file = substr($img_file, 0, $p);
3773
+        }
3774
+
3775
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3776
+        // la copie locale a toutes les chances d'etre la ou de resservir
3777
+        if (tester_url_absolue($img_file)) {
3778
+            include_spip('inc/distant');
3779
+            $fichier = copie_locale($img_file);
3780
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3781
+        }
3782
+
3783
+        if (
3784
+            !$img_file
3785
+            or !file_exists($img_file)
3786
+            or !$svg = file_get_contents($img_file)
3787
+        ) {
3788
+            return '';
3789
+        }
3790
+    }
3791
+
3792
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3793
+        return '';
3794
+    }
3795
+
3796
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3797
+
3798
+    $balise_svg = $match[0];
3799
+    $balise_svg_source = $balise_svg;
3800
+
3801
+    // entete XML à supprimer
3802
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3803
+
3804
+    // IE est toujours mon ami
3805
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3806
+
3807
+    // regler la classe
3808
+    if (!is_null($class)) {
3809
+        if (strlen($class)) {
3810
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3811
+        }
3812
+        else {
3813
+            $balise_svg = vider_attribut($balise_svg, 'class');
3814
+        }
3815
+    }
3816
+
3817
+    // regler le alt
3818
+    if ($alt) {
3819
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3820
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3821
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3822
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3823
+        $balise_svg .= $title;
3824
+    }
3825
+    else {
3826
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3827
+    }
3828
+
3829
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3830
+
3831
+    if (!is_null($size) and strlen($size = trim($size))) {
3832
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3833
+
3834
+        if (!function_exists('svg_redimensionner')) {
3835
+            include_spip('inc/svg');
3836
+        }
3837
+        $svg = svg_redimensionner($svg, $width, $height);
3838
+    }
3839
+
3840
+    return $svg;
3841 3841
 }
3842 3842
 
3843 3843
 
@@ -3863,18 +3863,18 @@  discard block
 block discarded – undo
3863 3863
  *     Code HTML résultant
3864 3864
  **/
3865 3865
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3866
-	$texte = '';
3867
-	if (is_array($tableau)) {
3868
-		foreach ($tableau as $k => $v) {
3869
-			$res = recuperer_fond(
3870
-				'modeles/' . $modele,
3871
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3872
-			);
3873
-			$texte .= $res;
3874
-		}
3875
-	}
3866
+    $texte = '';
3867
+    if (is_array($tableau)) {
3868
+        foreach ($tableau as $k => $v) {
3869
+            $res = recuperer_fond(
3870
+                'modeles/' . $modele,
3871
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3872
+            );
3873
+            $texte .= $res;
3874
+        }
3875
+    }
3876 3876
 
3877
-	return $texte;
3877
+    return $texte;
3878 3878
 }
3879 3879
 
3880 3880
 
@@ -3899,37 +3899,37 @@  discard block
 block discarded – undo
3899 3899
  *         - tout : retourne toutes les informations du plugin actif
3900 3900
  **/
3901 3901
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3902
-	include_spip('inc/plugin');
3903
-	$plugin = strtoupper($plugin);
3904
-	$plugins_actifs = liste_plugin_actifs();
3905
-
3906
-	if (!$plugin) {
3907
-		return serialize(array_keys($plugins_actifs));
3908
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3909
-		return '';
3910
-	} elseif (($type_info == 'est_actif') and !$reload) {
3911
-		return $plugins_actifs[$plugin] ? 1 : 0;
3912
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3913
-		return $plugins_actifs[$plugin][$type_info];
3914
-	} else {
3915
-		$get_infos = charger_fonction('get_infos', 'plugins');
3916
-		// On prend en compte les extensions
3917
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3918
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3919
-		} else {
3920
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3921
-		}
3922
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3923
-			return '';
3924
-		}
3925
-		if ($type_info == 'tout') {
3926
-			return $infos;
3927
-		} elseif ($type_info == 'est_actif') {
3928
-			return $infos ? 1 : 0;
3929
-		} else {
3930
-			return strval($infos[$type_info]);
3931
-		}
3932
-	}
3902
+    include_spip('inc/plugin');
3903
+    $plugin = strtoupper($plugin);
3904
+    $plugins_actifs = liste_plugin_actifs();
3905
+
3906
+    if (!$plugin) {
3907
+        return serialize(array_keys($plugins_actifs));
3908
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3909
+        return '';
3910
+    } elseif (($type_info == 'est_actif') and !$reload) {
3911
+        return $plugins_actifs[$plugin] ? 1 : 0;
3912
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3913
+        return $plugins_actifs[$plugin][$type_info];
3914
+    } else {
3915
+        $get_infos = charger_fonction('get_infos', 'plugins');
3916
+        // On prend en compte les extensions
3917
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3918
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3919
+        } else {
3920
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3921
+        }
3922
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3923
+            return '';
3924
+        }
3925
+        if ($type_info == 'tout') {
3926
+            return $infos;
3927
+        } elseif ($type_info == 'est_actif') {
3928
+            return $infos ? 1 : 0;
3929
+        } else {
3930
+            return strval($infos[$type_info]);
3931
+        }
3932
+    }
3933 3933
 }
3934 3934
 
3935 3935
 
@@ -3956,9 +3956,9 @@  discard block
 block discarded – undo
3956 3956
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3957 3957
  */
3958 3958
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3959
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3959
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3960 3960
 
3961
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3961
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3962 3962
 }
3963 3963
 
3964 3964
 
@@ -3988,19 +3988,19 @@  discard block
 block discarded – undo
3988 3988
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3989 3989
  */
3990 3990
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3991
-	static $puce_statut = null;
3992
-	if (!$puce_statut) {
3993
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3994
-	}
3991
+    static $puce_statut = null;
3992
+    if (!$puce_statut) {
3993
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3994
+    }
3995 3995
 
3996
-	return $puce_statut(
3997
-		$id_objet,
3998
-		$statut,
3999
-		$id_parent,
4000
-		$objet,
4001
-		false,
4002
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4003
-	);
3996
+    return $puce_statut(
3997
+        $id_objet,
3998
+        $statut,
3999
+        $id_parent,
4000
+        $objet,
4001
+        false,
4002
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4003
+    );
4004 4004
 }
4005 4005
 
4006 4006
 
@@ -4027,98 +4027,98 @@  discard block
 block discarded – undo
4027 4027
  *   hash du contexte
4028 4028
  */
4029 4029
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
4030
-	$env = null;
4031
-	if (
4032
-		is_string($c)
4033
-		and @unserialize($c) !== false
4034
-	) {
4035
-		$c = unserialize($c);
4036
-	}
4037
-
4038
-	// supprimer les parametres debut_x
4039
-	// pour que la pagination ajax ne soit pas plantee
4040
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4041
-	// le debut_x=0 n'existe pas, et on resterait sur 1
4042
-	if (is_array($c)) {
4043
-		foreach ($c as $k => $v) {
4044
-			if (strpos($k, 'debut_') === 0) {
4045
-				unset($c[$k]);
4046
-			}
4047
-		}
4048
-	}
4049
-
4050
-	if (!function_exists('calculer_cle_action')) {
4051
-		include_spip('inc/securiser_action');
4052
-	}
4053
-
4054
-	$c = serialize($c);
4055
-	$cle = calculer_cle_action($form . $c);
4056
-	$c = "$cle:$c";
4057
-
4058
-	// on ne stocke pas les contextes dans des fichiers en cache
4059
-	// par defaut, sauf si cette configuration a été forcée
4060
-	// OU que la longueur de l’argument géneré est plus long
4061
-	// que ce qui est toléré.
4062
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4063
-	if (!$cache_contextes_ajax) {
4064
-		$env = $c;
4065
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4066
-			$env = gzdeflate($env);
4067
-		}
4068
-		$env = _xor($env);
4069
-		$env = base64_encode($env);
4070
-		$len = strlen($env);
4071
-		// Si l’url est trop longue pour le navigateur
4072
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4073
-		if ($len > $max_len) {
4074
-			$cache_contextes_ajax = true;
4075
-			spip_log(
4076
-				'Contextes AJAX forces en fichiers !'
4077
-				. ' Cela arrive lorsque la valeur du contexte'
4078
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4079
-				_LOG_AVERTISSEMENT
4080
-			);
4081
-		}
4082
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4083
-		elseif (
4084
-			$max_len = @ini_get('suhosin.get.max_value_length')
4085
-			and $max_len < $len
4086
-		) {
4087
-			$cache_contextes_ajax = true;
4088
-			spip_log('Contextes AJAX forces en fichiers !'
4089
-				. ' Cela arrive lorsque la valeur du contexte'
4090
-				. ' depasse la longueur maximale autorisee par Suhosin'
4091
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4092
-				. ' Vous devriez modifier les parametres de Suhosin'
4093
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4094
-		}
4095
-	}
4096
-
4097
-	if ($cache_contextes_ajax) {
4098
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4099
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4100
-		$md5 = md5($c);
4101
-		ecrire_fichier("$dir/c$md5", $c);
4102
-		$env = $md5;
4103
-	}
4104
-
4105
-	if ($emboite === null) {
4106
-		return $env;
4107
-	}
4108
-	if (!trim($emboite)) {
4109
-		return '';
4110
-	}
4111
-	// toujours encoder l'url source dans le bloc ajax
4112
-	$r = self();
4113
-	$r = ' data-origin="' . $r . '"';
4114
-	$class = 'ajaxbloc';
4115
-	if ($ajaxid and is_string($ajaxid)) {
4116
-		// ajaxid est normalement conforme a un nom de classe css
4117
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4118
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4119
-	}
4120
-
4121
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4030
+    $env = null;
4031
+    if (
4032
+        is_string($c)
4033
+        and @unserialize($c) !== false
4034
+    ) {
4035
+        $c = unserialize($c);
4036
+    }
4037
+
4038
+    // supprimer les parametres debut_x
4039
+    // pour que la pagination ajax ne soit pas plantee
4040
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4041
+    // le debut_x=0 n'existe pas, et on resterait sur 1
4042
+    if (is_array($c)) {
4043
+        foreach ($c as $k => $v) {
4044
+            if (strpos($k, 'debut_') === 0) {
4045
+                unset($c[$k]);
4046
+            }
4047
+        }
4048
+    }
4049
+
4050
+    if (!function_exists('calculer_cle_action')) {
4051
+        include_spip('inc/securiser_action');
4052
+    }
4053
+
4054
+    $c = serialize($c);
4055
+    $cle = calculer_cle_action($form . $c);
4056
+    $c = "$cle:$c";
4057
+
4058
+    // on ne stocke pas les contextes dans des fichiers en cache
4059
+    // par defaut, sauf si cette configuration a été forcée
4060
+    // OU que la longueur de l’argument géneré est plus long
4061
+    // que ce qui est toléré.
4062
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4063
+    if (!$cache_contextes_ajax) {
4064
+        $env = $c;
4065
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4066
+            $env = gzdeflate($env);
4067
+        }
4068
+        $env = _xor($env);
4069
+        $env = base64_encode($env);
4070
+        $len = strlen($env);
4071
+        // Si l’url est trop longue pour le navigateur
4072
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4073
+        if ($len > $max_len) {
4074
+            $cache_contextes_ajax = true;
4075
+            spip_log(
4076
+                'Contextes AJAX forces en fichiers !'
4077
+                . ' Cela arrive lorsque la valeur du contexte'
4078
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4079
+                _LOG_AVERTISSEMENT
4080
+            );
4081
+        }
4082
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4083
+        elseif (
4084
+            $max_len = @ini_get('suhosin.get.max_value_length')
4085
+            and $max_len < $len
4086
+        ) {
4087
+            $cache_contextes_ajax = true;
4088
+            spip_log('Contextes AJAX forces en fichiers !'
4089
+                . ' Cela arrive lorsque la valeur du contexte'
4090
+                . ' depasse la longueur maximale autorisee par Suhosin'
4091
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4092
+                . ' Vous devriez modifier les parametres de Suhosin'
4093
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4094
+        }
4095
+    }
4096
+
4097
+    if ($cache_contextes_ajax) {
4098
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4099
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4100
+        $md5 = md5($c);
4101
+        ecrire_fichier("$dir/c$md5", $c);
4102
+        $env = $md5;
4103
+    }
4104
+
4105
+    if ($emboite === null) {
4106
+        return $env;
4107
+    }
4108
+    if (!trim($emboite)) {
4109
+        return '';
4110
+    }
4111
+    // toujours encoder l'url source dans le bloc ajax
4112
+    $r = self();
4113
+    $r = ' data-origin="' . $r . '"';
4114
+    $class = 'ajaxbloc';
4115
+    if ($ajaxid and is_string($ajaxid)) {
4116
+        // ajaxid est normalement conforme a un nom de classe css
4117
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4118
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4119
+    }
4120
+
4121
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4122 4122
 }
4123 4123
 
4124 4124
 /**
@@ -4138,37 +4138,37 @@  discard block
 block discarded – undo
4138 4138
  *   - false : erreur de décodage
4139 4139
  */
4140 4140
 function decoder_contexte_ajax($c, $form = '') {
4141
-	if (!function_exists('calculer_cle_action')) {
4142
-		include_spip('inc/securiser_action');
4143
-	}
4144
-	if (
4145
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4146
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4147
-		and lire_fichier("$dir/c$c", $contexte)
4148
-	) {
4149
-		$c = $contexte;
4150
-	} else {
4151
-		$c = @base64_decode($c);
4152
-		$c = _xor($c);
4153
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4154
-			$c = @gzinflate($c);
4155
-		}
4156
-	}
4157
-
4158
-	// extraire la signature en debut de contexte
4159
-	// et la verifier avant de deserializer
4160
-	// format : signature:donneesserializees
4161
-	if ($p = strpos($c, ':')) {
4162
-		$cle = substr($c, 0, $p);
4163
-		$c = substr($c, $p + 1);
4164
-
4165
-		if ($cle == calculer_cle_action($form . $c)) {
4166
-			$env = @unserialize($c);
4167
-			return $env;
4168
-		}
4169
-	}
4170
-
4171
-	return false;
4141
+    if (!function_exists('calculer_cle_action')) {
4142
+        include_spip('inc/securiser_action');
4143
+    }
4144
+    if (
4145
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4146
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4147
+        and lire_fichier("$dir/c$c", $contexte)
4148
+    ) {
4149
+        $c = $contexte;
4150
+    } else {
4151
+        $c = @base64_decode($c);
4152
+        $c = _xor($c);
4153
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4154
+            $c = @gzinflate($c);
4155
+        }
4156
+    }
4157
+
4158
+    // extraire la signature en debut de contexte
4159
+    // et la verifier avant de deserializer
4160
+    // format : signature:donneesserializees
4161
+    if ($p = strpos($c, ':')) {
4162
+        $cle = substr($c, 0, $p);
4163
+        $c = substr($c, $p + 1);
4164
+
4165
+        if ($cle == calculer_cle_action($form . $c)) {
4166
+            $env = @unserialize($c);
4167
+            return $env;
4168
+        }
4169
+    }
4170
+
4171
+    return false;
4172 4172
 }
4173 4173
 
4174 4174
 
@@ -4186,20 +4186,20 @@  discard block
 block discarded – undo
4186 4186
  *    Message décrypté ou encrypté
4187 4187
  **/
4188 4188
 function _xor($message, $key = null) {
4189
-	if (is_null($key)) {
4190
-		if (!function_exists('calculer_cle_action')) {
4191
-			include_spip('inc/securiser_action');
4192
-		}
4193
-		$key = pack('H*', calculer_cle_action('_xor'));
4194
-	}
4189
+    if (is_null($key)) {
4190
+        if (!function_exists('calculer_cle_action')) {
4191
+            include_spip('inc/securiser_action');
4192
+        }
4193
+        $key = pack('H*', calculer_cle_action('_xor'));
4194
+    }
4195 4195
 
4196
-	$keylen = strlen($key);
4197
-	$messagelen = strlen($message);
4198
-	for ($i = 0; $i < $messagelen; $i++) {
4199
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4200
-	}
4196
+    $keylen = strlen($key);
4197
+    $messagelen = strlen($message);
4198
+    for ($i = 0; $i < $messagelen; $i++) {
4199
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4200
+    }
4201 4201
 
4202
-	return $message;
4202
+    return $message;
4203 4203
 }
4204 4204
 
4205 4205
 /**
@@ -4213,7 +4213,7 @@  discard block
 block discarded – undo
4213 4213
  * @return string
4214 4214
  */
4215 4215
 function url_reponse_forum($texte) {
4216
- return $texte;
4216
+    return $texte;
4217 4217
 }
4218 4218
 
4219 4219
 /**
@@ -4227,7 +4227,7 @@  discard block
 block discarded – undo
4227 4227
  * @return string
4228 4228
  */
4229 4229
 function url_rss_forum($texte) {
4230
- return $texte;
4230
+    return $texte;
4231 4231
 }
4232 4232
 
4233 4233
 
@@ -4266,37 +4266,37 @@  discard block
 block discarded – undo
4266 4266
  *   Code HTML
4267 4267
  */
4268 4268
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4269
-	if ($on) {
4270
-		$bal = 'strong';
4271
-		$class = '';
4272
-		$att = '';
4273
-		// si $on passe la balise et optionnelement une ou ++classe
4274
-		// a.active span.selected.active etc....
4275
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4276
-			$on = explode('.', $on);
4277
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4278
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4279
-				$bal = array_shift($on);
4280
-				$class = implode(' ', $on);
4281
-				if ($bal == 'a') {
4282
-					$att = 'href="#" ';
4283
-				}
4284
-			}
4285
-		}
4286
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4287
-	} else {
4288
-		$bal = 'a';
4289
-		$att = "href='$url'"
4290
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4291
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4292
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4293
-			. $evt;
4294
-	}
4295
-	if ($libelle === null) {
4296
-		$libelle = $url;
4297
-	}
4298
-
4299
-	return "<$bal $att>$libelle</$bal>";
4269
+    if ($on) {
4270
+        $bal = 'strong';
4271
+        $class = '';
4272
+        $att = '';
4273
+        // si $on passe la balise et optionnelement une ou ++classe
4274
+        // a.active span.selected.active etc....
4275
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4276
+            $on = explode('.', $on);
4277
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4278
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4279
+                $bal = array_shift($on);
4280
+                $class = implode(' ', $on);
4281
+                if ($bal == 'a') {
4282
+                    $att = 'href="#" ';
4283
+                }
4284
+            }
4285
+        }
4286
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4287
+    } else {
4288
+        $bal = 'a';
4289
+        $att = "href='$url'"
4290
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4291
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4292
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4293
+            . $evt;
4294
+    }
4295
+    if ($libelle === null) {
4296
+        $libelle = $url;
4297
+    }
4298
+
4299
+    return "<$bal $att>$libelle</$bal>";
4300 4300
 }
4301 4301
 
4302 4302
 
@@ -4313,39 +4313,39 @@  discard block
 block discarded – undo
4313 4313
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4314 4314
  */
4315 4315
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4316
-	static $local_singulier_ou_pluriel = [];
4317
-
4318
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4319
-	if (!is_numeric($nb) or $nb == 0) {
4320
-		return '';
4321
-	}
4322
-	if (!is_array($vars)) {
4323
-		return '';
4324
-	}
4325
-
4326
-	$langue = $GLOBALS['spip_lang'];
4327
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4328
-		$local_singulier_ou_pluriel[$langue] = false;
4329
-		if (
4330
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4331
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4332
-		) {
4333
-			$local_singulier_ou_pluriel[$langue] = $f;
4334
-		}
4335
-	}
4336
-
4337
-	// si on a une surcharge on l'utilise
4338
-	if ($local_singulier_ou_pluriel[$langue]) {
4339
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4340
-	}
4341
-
4342
-	// sinon traitement par defaut
4343
-	$vars[$var] = $nb;
4344
-	if ($nb >= 2) {
4345
-		return _T($chaine_plusieurs, $vars);
4346
-	} else {
4347
-		return _T($chaine_un, $vars);
4348
-	}
4316
+    static $local_singulier_ou_pluriel = [];
4317
+
4318
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4319
+    if (!is_numeric($nb) or $nb == 0) {
4320
+        return '';
4321
+    }
4322
+    if (!is_array($vars)) {
4323
+        return '';
4324
+    }
4325
+
4326
+    $langue = $GLOBALS['spip_lang'];
4327
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4328
+        $local_singulier_ou_pluriel[$langue] = false;
4329
+        if (
4330
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4331
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4332
+        ) {
4333
+            $local_singulier_ou_pluriel[$langue] = $f;
4334
+        }
4335
+    }
4336
+
4337
+    // si on a une surcharge on l'utilise
4338
+    if ($local_singulier_ou_pluriel[$langue]) {
4339
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4340
+    }
4341
+
4342
+    // sinon traitement par defaut
4343
+    $vars[$var] = $nb;
4344
+    if ($nb >= 2) {
4345
+        return _T($chaine_plusieurs, $vars);
4346
+    } else {
4347
+        return _T($chaine_un, $vars);
4348
+    }
4349 4349
 }
4350 4350
 
4351 4351
 
@@ -4373,73 +4373,73 @@  discard block
 block discarded – undo
4373 4373
  */
4374 4374
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4375 4375
 
4376
-	$class_lien = $class_bouton = $class;
4377
-
4378
-	// Normaliser la fonction et compléter la classe en fonction
4379
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4380
-		$class_lien .= ' danger';
4381
-		$class_bouton .= ' btn_danger';
4382
-	} elseif ($fonction == 'rien.gif') {
4383
-		$fonction = '';
4384
-	} elseif ($fonction == 'delsafe') {
4385
-		$fonction = 'del';
4386
-	}
4387
-
4388
-	$fond_origine = $fond;
4389
-	// Remappage des icone : article-24.png+new => article-new-24.png
4390
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4391
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4392
-	}
4393
-
4394
-	// Ajouter le type d'objet dans la classe
4395
-	$objet_type = substr(basename($fond), 0, -4);
4396
-	$class_lien .= " $objet_type";
4397
-	$class_bouton .= " $objet_type";
4398
-
4399
-	// Texte
4400
-	$alt = attribut_html($texte);
4401
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4402
-
4403
-	// Liens : préparer les classes ajax
4404
-	$ajax = '';
4405
-	if ($type === 'lien') {
4406
-		if (strpos($class_lien, 'ajax') !== false) {
4407
-			$ajax = 'ajax';
4408
-			if (strpos($class_lien, 'preload') !== false) {
4409
-				$ajax .= ' preload';
4410
-			}
4411
-			if (strpos($class_lien, 'nocache') !== false) {
4412
-				$ajax .= ' nocache';
4413
-			}
4414
-			$ajax = " class='$ajax'";
4415
-		}
4416
-	}
4417
-
4418
-	// Repérer la taille et l'ajouter dans la classe
4419
-	$size = 24;
4420
-	if (
4421
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4422
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4423
-	) {
4424
-		$size = $match[1];
4425
-	}
4426
-	$class_lien .= " s$size";
4427
-	$class_bouton .= " s$size";
4428
-
4429
-	// Icône
4430
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4431
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4432
-
4433
-	// Markup final
4434
-	if ($type == 'lien') {
4435
-		return "<span class='icone $class_lien'>"
4436
-		. "<a href='$lien'$title$ajax$javascript>"
4437
-		. $icone
4438
-		. "<b>$texte</b>"
4439
-		. "</a></span>\n";
4440
-	} else {
4441
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4442
-	}
4376
+    $class_lien = $class_bouton = $class;
4377
+
4378
+    // Normaliser la fonction et compléter la classe en fonction
4379
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4380
+        $class_lien .= ' danger';
4381
+        $class_bouton .= ' btn_danger';
4382
+    } elseif ($fonction == 'rien.gif') {
4383
+        $fonction = '';
4384
+    } elseif ($fonction == 'delsafe') {
4385
+        $fonction = 'del';
4386
+    }
4387
+
4388
+    $fond_origine = $fond;
4389
+    // Remappage des icone : article-24.png+new => article-new-24.png
4390
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4391
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4392
+    }
4393
+
4394
+    // Ajouter le type d'objet dans la classe
4395
+    $objet_type = substr(basename($fond), 0, -4);
4396
+    $class_lien .= " $objet_type";
4397
+    $class_bouton .= " $objet_type";
4398
+
4399
+    // Texte
4400
+    $alt = attribut_html($texte);
4401
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4402
+
4403
+    // Liens : préparer les classes ajax
4404
+    $ajax = '';
4405
+    if ($type === 'lien') {
4406
+        if (strpos($class_lien, 'ajax') !== false) {
4407
+            $ajax = 'ajax';
4408
+            if (strpos($class_lien, 'preload') !== false) {
4409
+                $ajax .= ' preload';
4410
+            }
4411
+            if (strpos($class_lien, 'nocache') !== false) {
4412
+                $ajax .= ' nocache';
4413
+            }
4414
+            $ajax = " class='$ajax'";
4415
+        }
4416
+    }
4417
+
4418
+    // Repérer la taille et l'ajouter dans la classe
4419
+    $size = 24;
4420
+    if (
4421
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4422
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4423
+    ) {
4424
+        $size = $match[1];
4425
+    }
4426
+    $class_lien .= " s$size";
4427
+    $class_bouton .= " s$size";
4428
+
4429
+    // Icône
4430
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4431
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4432
+
4433
+    // Markup final
4434
+    if ($type == 'lien') {
4435
+        return "<span class='icone $class_lien'>"
4436
+        . "<a href='$lien'$title$ajax$javascript>"
4437
+        . $icone
4438
+        . "<b>$texte</b>"
4439
+        . "</a></span>\n";
4440
+    } else {
4441
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4442
+    }
4443 4443
 }
4444 4444
 
4445 4445
 /**
@@ -4463,7 +4463,7 @@  discard block
 block discarded – undo
4463 4463
  *     Code HTML du lien
4464 4464
  **/
4465 4465
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4466
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4466
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4467 4467
 }
4468 4468
 
4469 4469
 /**
@@ -4498,7 +4498,7 @@  discard block
 block discarded – undo
4498 4498
  *     Code HTML du lien
4499 4499
  **/
4500 4500
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4501
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4501
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4502 4502
 }
4503 4503
 
4504 4504
 /**
@@ -4543,7 +4543,7 @@  discard block
 block discarded – undo
4543 4543
  *     Code HTML du lien
4544 4544
  **/
4545 4545
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4546
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4546
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4547 4547
 }
4548 4548
 
4549 4549
 /**
@@ -4574,7 +4574,7 @@  discard block
 block discarded – undo
4574 4574
  *     Code HTML du lien
4575 4575
  **/
4576 4576
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4577
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4577
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4578 4578
 }
4579 4579
 
4580 4580
 /**
@@ -4605,7 +4605,7 @@  discard block
 block discarded – undo
4605 4605
  *     Code HTML du lien
4606 4606
  */
4607 4607
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4608
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4608
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4609 4609
 }
4610 4610
 
4611 4611
 
@@ -4627,7 +4627,7 @@  discard block
 block discarded – undo
4627 4627
  * @return array Liste des éléments
4628 4628
  */
4629 4629
 function filtre_explode_dist($a, $b) {
4630
-	return explode($b, (string) $a);
4630
+    return explode($b, (string) $a);
4631 4631
 }
4632 4632
 
4633 4633
 /**
@@ -4648,7 +4648,7 @@  discard block
 block discarded – undo
4648 4648
  * @return string Texte
4649 4649
  */
4650 4650
 function filtre_implode_dist($a, $b) {
4651
-	return is_array($a) ? implode($b, $a) : $a;
4651
+    return is_array($a) ? implode($b, $a) : $a;
4652 4652
 }
4653 4653
 
4654 4654
 /**
@@ -4657,24 +4657,24 @@  discard block
 block discarded – undo
4657 4657
  * @return string Code CSS
4658 4658
  */
4659 4659
 function bando_images_background() {
4660
-	include_spip('inc/bandeau');
4661
-	// recuperer tous les boutons et leurs images
4662
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4660
+    include_spip('inc/bandeau');
4661
+    // recuperer tous les boutons et leurs images
4662
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4663 4663
 
4664
-	$res = '';
4665
-	foreach ($boutons as $page => $detail) {
4666
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4667
-		if (is_array($detail->sousmenu)) {
4668
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4669
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4670
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4671
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4672
-				}
4673
-			}
4674
-		}
4675
-	}
4664
+    $res = '';
4665
+    foreach ($boutons as $page => $detail) {
4666
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4667
+        if (is_array($detail->sousmenu)) {
4668
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4669
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4670
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4671
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4672
+                }
4673
+            }
4674
+        }
4675
+    }
4676 4676
 
4677
-	return $res;
4677
+    return $res;
4678 4678
 }
4679 4679
 
4680 4680
 /**
@@ -4699,27 +4699,27 @@  discard block
 block discarded – undo
4699 4699
  */
4700 4700
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4701 4701
 
4702
-	// Classes : dispatcher `ajax` sur le formulaire
4703
-	$class_form = '';
4704
-	if (strpos($class, 'ajax') !== false) {
4705
-		$class_form = 'ajax';
4706
-		$class = str_replace('ajax', '', $class);
4707
-	}
4708
-	$class_btn = 'submit ' . trim($class);
4702
+    // Classes : dispatcher `ajax` sur le formulaire
4703
+    $class_form = '';
4704
+    if (strpos($class, 'ajax') !== false) {
4705
+        $class_form = 'ajax';
4706
+        $class = str_replace('ajax', '', $class);
4707
+    }
4708
+    $class_btn = 'submit ' . trim($class);
4709 4709
 
4710
-	if ($confirm) {
4711
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4712
-		if ($callback) {
4713
-			$callback = "$confirm?($callback):false";
4714
-		} else {
4715
-			$callback = $confirm;
4716
-		}
4717
-	}
4718
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4719
-	$title = $title ? " title='$title'" : '';
4710
+    if ($confirm) {
4711
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4712
+        if ($callback) {
4713
+            $callback = "$confirm?($callback):false";
4714
+        } else {
4715
+            $callback = $confirm;
4716
+        }
4717
+    }
4718
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4719
+    $title = $title ? " title='$title'" : '';
4720 4720
 
4721
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4722
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4721
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4722
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4723 4723
 }
4724 4724
 
4725 4725
 /**
@@ -4742,101 +4742,101 @@  discard block
 block discarded – undo
4742 4742
  * @return string
4743 4743
  */
4744 4744
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4745
-	static $trouver_table = null;
4746
-	static $objets;
4747
-
4748
-	// On verifie qu'on a tout ce qu'il faut
4749
-	$id_objet = intval($id_objet);
4750
-	if (!($id_objet and $type_objet and $info)) {
4751
-		return '';
4752
-	}
4753
-
4754
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4755
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4756
-		return '';
4757
-	}
4758
-
4759
-	// Si on demande l'url, on retourne direct la fonction
4760
-	if ($info == 'url') {
4761
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4762
-	}
4763
-
4764
-	// Sinon on va tout chercher dans la table et on garde en memoire
4765
-	$demande_titre = ($info === 'titre');
4766
-	$demande_introduction = ($info === 'introduction');
4767
-
4768
-	// 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
4769
-	if (
4770
-		!isset($objets[$type_objet][$id_objet])
4771
-		or
4772
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4773
-	) {
4774
-		if (!$trouver_table) {
4775
-			$trouver_table = charger_fonction('trouver_table', 'base');
4776
-		}
4777
-		$desc = $trouver_table(table_objet_sql($type_objet));
4778
-		if (!$desc) {
4779
-			return $objets[$type_objet] = false;
4780
-		}
4781
-
4782
-		// Si on demande le titre, on le gere en interne
4783
-		$champ_titre = '';
4784
-		if ($demande_titre) {
4785
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4786
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4787
-		}
4788
-		include_spip('base/abstract_sql');
4789
-		include_spip('base/connect_sql');
4790
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4791
-			'*' . $champ_titre,
4792
-			$desc['table_sql'],
4793
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4794
-		);
4795
-
4796
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4797
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4798
-	}
4799
-
4800
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4801
-	// ajouter la longueur au début des params supplémentaires
4802
-	if ($demande_introduction) {
4803
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4804
-		array_unshift($params, $introduction_longueur);
4805
-	}
4806
-
4807
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4808
-	if (
4809
-		$generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4810
-		// @deprecated 4.1 generer_TRUC_TYPE
4811
-		or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4812
-	) {
4813
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4814
-	}
4815
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4816
-	elseif (
4817
-		$generer = charger_fonction("generer_objet_${info}", '', true)
4818
-		// @deprecated 4.1 generer_TRUC_entite
4819
-		or $generer = charger_fonction("generer_${info}_entite", '', true)
4820
-	) {
4821
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4822
-	} // Sinon on prend directement le champ SQL tel quel
4823
-	else {
4824
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4825
-	}
4826
-
4827
-	// On va ensuite appliquer les traitements automatiques si besoin
4828
-	if (!$etoile) {
4829
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4830
-		// mais ce fonctionnement est a ameliorer !
4831
-		$info_generee = appliquer_traitement_champ(
4832
-			$info_generee,
4833
-			$info,
4834
-			table_objet($type_objet),
4835
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4836
-		);
4837
-	}
4838
-
4839
-	return $info_generee;
4745
+    static $trouver_table = null;
4746
+    static $objets;
4747
+
4748
+    // On verifie qu'on a tout ce qu'il faut
4749
+    $id_objet = intval($id_objet);
4750
+    if (!($id_objet and $type_objet and $info)) {
4751
+        return '';
4752
+    }
4753
+
4754
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4755
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4756
+        return '';
4757
+    }
4758
+
4759
+    // Si on demande l'url, on retourne direct la fonction
4760
+    if ($info == 'url') {
4761
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4762
+    }
4763
+
4764
+    // Sinon on va tout chercher dans la table et on garde en memoire
4765
+    $demande_titre = ($info === 'titre');
4766
+    $demande_introduction = ($info === 'introduction');
4767
+
4768
+    // 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
4769
+    if (
4770
+        !isset($objets[$type_objet][$id_objet])
4771
+        or
4772
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4773
+    ) {
4774
+        if (!$trouver_table) {
4775
+            $trouver_table = charger_fonction('trouver_table', 'base');
4776
+        }
4777
+        $desc = $trouver_table(table_objet_sql($type_objet));
4778
+        if (!$desc) {
4779
+            return $objets[$type_objet] = false;
4780
+        }
4781
+
4782
+        // Si on demande le titre, on le gere en interne
4783
+        $champ_titre = '';
4784
+        if ($demande_titre) {
4785
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4786
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4787
+        }
4788
+        include_spip('base/abstract_sql');
4789
+        include_spip('base/connect_sql');
4790
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4791
+            '*' . $champ_titre,
4792
+            $desc['table_sql'],
4793
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4794
+        );
4795
+
4796
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4797
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4798
+    }
4799
+
4800
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4801
+    // ajouter la longueur au début des params supplémentaires
4802
+    if ($demande_introduction) {
4803
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4804
+        array_unshift($params, $introduction_longueur);
4805
+    }
4806
+
4807
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4808
+    if (
4809
+        $generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4810
+        // @deprecated 4.1 generer_TRUC_TYPE
4811
+        or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4812
+    ) {
4813
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4814
+    }
4815
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4816
+    elseif (
4817
+        $generer = charger_fonction("generer_objet_${info}", '', true)
4818
+        // @deprecated 4.1 generer_TRUC_entite
4819
+        or $generer = charger_fonction("generer_${info}_entite", '', true)
4820
+    ) {
4821
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4822
+    } // Sinon on prend directement le champ SQL tel quel
4823
+    else {
4824
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4825
+    }
4826
+
4827
+    // On va ensuite appliquer les traitements automatiques si besoin
4828
+    if (!$etoile) {
4829
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4830
+        // mais ce fonctionnement est a ameliorer !
4831
+        $info_generee = appliquer_traitement_champ(
4832
+            $info_generee,
4833
+            $info,
4834
+            table_objet($type_objet),
4835
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4836
+        );
4837
+    }
4838
+
4839
+    return $info_generee;
4840 4840
 }
4841 4841
 
4842 4842
 /**
@@ -4844,7 +4844,7 @@  discard block
 block discarded – undo
4844 4844
  * @see generer_objet_info
4845 4845
  */
4846 4846
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4847
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4847
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4848 4848
 }
4849 4849
 
4850 4850
 /**
@@ -4877,36 +4877,36 @@  discard block
 block discarded – undo
4877 4877
  */
4878 4878
 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 {
4879 4879
 
4880
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4881
-	$texte = $ligne_sql['texte'] ?? '';
4882
-	// En absence de descriptif, on se rabat sur chapo + texte
4883
-	if (isset($ligne_sql['chapo'])) {
4884
-		$chapo = $ligne_sql['chapo'];
4885
-		$texte = strlen($descriptif) ?
4886
-			'' :
4887
-			"$chapo \n\n $texte";
4888
-	}
4880
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4881
+    $texte = $ligne_sql['texte'] ?? '';
4882
+    // En absence de descriptif, on se rabat sur chapo + texte
4883
+    if (isset($ligne_sql['chapo'])) {
4884
+        $chapo = $ligne_sql['chapo'];
4885
+        $texte = strlen($descriptif) ?
4886
+            '' :
4887
+            "$chapo \n\n $texte";
4888
+    }
4889 4889
 
4890
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4891
-	if (!intval($longueur_ou_suite)) {
4892
-		$longueur = intval($introduction_longueur ?: 600);
4893
-	} else {
4894
-		$longueur = intval($longueur_ou_suite);
4895
-	}
4890
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4891
+    if (!intval($longueur_ou_suite)) {
4892
+        $longueur = intval($introduction_longueur ?: 600);
4893
+    } else {
4894
+        $longueur = intval($longueur_ou_suite);
4895
+    }
4896 4896
 
4897
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4898
-	// Ex : #INTRODUCTION{...}
4899
-	if (
4900
-		is_null($suite)
4901
-		and !intval($longueur_ou_suite)
4902
-	) {
4903
-		$suite = $longueur_ou_suite;
4904
-	}
4897
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4898
+    // Ex : #INTRODUCTION{...}
4899
+    if (
4900
+        is_null($suite)
4901
+        and !intval($longueur_ou_suite)
4902
+    ) {
4903
+        $suite = $longueur_ou_suite;
4904
+    }
4905 4905
 
4906
-	$f = chercher_filtre('introduction');
4907
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4906
+    $f = chercher_filtre('introduction');
4907
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4908 4908
 
4909
-	return $introduction;
4909
+    return $introduction;
4910 4910
 }
4911 4911
 
4912 4912
 /**
@@ -4914,7 +4914,7 @@  discard block
 block discarded – undo
4914 4914
  * @see generer_objet_introduction
4915 4915
  */
4916 4916
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4917
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4917
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4918 4918
 }
4919 4919
 
4920 4920
 /**
@@ -4928,44 +4928,44 @@  discard block
 block discarded – undo
4928 4928
  * @return string
4929 4929
  */
4930 4930
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4931
-	if (!$champ) {
4932
-		return $texte;
4933
-	}
4931
+    if (!$champ) {
4932
+        return $texte;
4933
+    }
4934 4934
 
4935
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4936
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4937
-	include_fichiers_fonctions();
4935
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4936
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4937
+    include_fichiers_fonctions();
4938 4938
 
4939
-	$champ = strtoupper($champ);
4940
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4941
-	if (!$traitements or !is_array($traitements)) {
4942
-		return $texte;
4943
-	}
4939
+    $champ = strtoupper($champ);
4940
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4941
+    if (!$traitements or !is_array($traitements)) {
4942
+        return $texte;
4943
+    }
4944 4944
 
4945
-	$traitement = '';
4946
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4947
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4948
-		$table_objet = table_objet($table_objet);
4949
-		if (isset($traitements[$table_objet])) {
4950
-			$traitement = $traitements[$table_objet];
4951
-		}
4952
-	}
4953
-	if (!$traitement and isset($traitements[0])) {
4954
-		$traitement = $traitements[0];
4955
-	}
4956
-	// (sinon prendre le premier de la liste par defaut ?)
4945
+    $traitement = '';
4946
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4947
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4948
+        $table_objet = table_objet($table_objet);
4949
+        if (isset($traitements[$table_objet])) {
4950
+            $traitement = $traitements[$table_objet];
4951
+        }
4952
+    }
4953
+    if (!$traitement and isset($traitements[0])) {
4954
+        $traitement = $traitements[0];
4955
+    }
4956
+    // (sinon prendre le premier de la liste par defaut ?)
4957 4957
 
4958
-	if (!$traitement) {
4959
-		return $texte;
4960
-	}
4958
+    if (!$traitement) {
4959
+        return $texte;
4960
+    }
4961 4961
 
4962
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4962
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4963 4963
 
4964
-	// Fournir $connect et $Pile[0] au traitement si besoin
4965
-	$Pile = [0 => $env];
4966
-	eval("\$texte = $traitement;");
4964
+    // Fournir $connect et $Pile[0] au traitement si besoin
4965
+    $Pile = [0 => $env];
4966
+    eval("\$texte = $traitement;");
4967 4967
 
4968
-	return $texte;
4968
+    return $texte;
4969 4969
 }
4970 4970
 
4971 4971
 
@@ -4979,21 +4979,21 @@  discard block
 block discarded – undo
4979 4979
  * @return string
4980 4980
  */
4981 4981
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4982
-	include_spip('inc/liens');
4983
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4984
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4985
-	// le raccourcis n'est plus valide
4986
-	$titre = typo($titre['titre']) ?? '';
4987
-	// on essaye avec generer_info_entite ?
4988
-	if (!strlen($titre) and !$connect) {
4989
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4990
-	}
4991
-	if (!strlen($titre)) {
4992
-		$titre = _T('info_sans_titre');
4993
-	}
4994
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4982
+    include_spip('inc/liens');
4983
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4984
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4985
+    // le raccourcis n'est plus valide
4986
+    $titre = typo($titre['titre']) ?? '';
4987
+    // on essaye avec generer_info_entite ?
4988
+    if (!strlen($titre) and !$connect) {
4989
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4990
+    }
4991
+    if (!strlen($titre)) {
4992
+        $titre = _T('info_sans_titre');
4993
+    }
4994
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4995 4995
 
4996
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4996
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4997 4997
 }
4998 4998
 
4999 4999
 /**
@@ -5001,7 +5001,7 @@  discard block
 block discarded – undo
5001 5001
  * @see generer_objet_lien
5002 5002
  */
5003 5003
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
5004
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5004
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5005 5005
 }
5006 5006
 
5007 5007
 /**
@@ -5017,15 +5017,15 @@  discard block
 block discarded – undo
5017 5017
  * @return string
5018 5018
  */
5019 5019
 function wrap($texte, $wrap) {
5020
-	$balises = extraire_balises($wrap);
5021
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5022
-		$texte = $wrap . $texte;
5023
-		$regs = array_reverse($regs[1]);
5024
-		$wrap = '</' . implode('></', $regs) . '>';
5025
-		$texte = $texte . $wrap;
5026
-	}
5020
+    $balises = extraire_balises($wrap);
5021
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5022
+        $texte = $wrap . $texte;
5023
+        $regs = array_reverse($regs[1]);
5024
+        $wrap = '</' . implode('></', $regs) . '>';
5025
+        $texte = $texte . $wrap;
5026
+    }
5027 5027
 
5028
-	return $texte;
5028
+    return $texte;
5029 5029
 }
5030 5030
 
5031 5031
 
@@ -5045,44 +5045,44 @@  discard block
 block discarded – undo
5045 5045
  * @return array|mixed|string
5046 5046
  */
5047 5047
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
5048
-	if (is_string($u)) {
5049
-		$u = typo($u);
5048
+    if (is_string($u)) {
5049
+        $u = typo($u);
5050 5050
 
5051
-		return $u;
5052
-	}
5051
+        return $u;
5052
+    }
5053 5053
 
5054
-	// caster $u en array si besoin
5055
-	if (is_object($u)) {
5056
-		$u = (array)$u;
5057
-	}
5054
+    // caster $u en array si besoin
5055
+    if (is_object($u)) {
5056
+        $u = (array)$u;
5057
+    }
5058 5058
 
5059
-	if (is_array($u)) {
5060
-		$out = '';
5061
-		// toutes les cles sont numeriques ?
5062
-		// et aucun enfant n'est un tableau
5063
-		// liste simple separee par des virgules
5064
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5065
-		$array_values = array_map('is_array', $u);
5066
-		$object_values = array_map('is_object', $u);
5067
-		if (
5068
-			array_sum($numeric_keys) == count($numeric_keys)
5069
-			and !array_sum($array_values)
5070
-			and !array_sum($object_values)
5071
-		) {
5072
-			return join(', ', array_map('filtre_print_dist', $u));
5073
-		}
5059
+    if (is_array($u)) {
5060
+        $out = '';
5061
+        // toutes les cles sont numeriques ?
5062
+        // et aucun enfant n'est un tableau
5063
+        // liste simple separee par des virgules
5064
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5065
+        $array_values = array_map('is_array', $u);
5066
+        $object_values = array_map('is_object', $u);
5067
+        if (
5068
+            array_sum($numeric_keys) == count($numeric_keys)
5069
+            and !array_sum($array_values)
5070
+            and !array_sum($object_values)
5071
+        ) {
5072
+            return join(', ', array_map('filtre_print_dist', $u));
5073
+        }
5074 5074
 
5075
-		// sinon on passe a la ligne et on indente
5076
-		$i_str = str_pad('', $indent, ' ');
5077
-		foreach ($u as $k => $v) {
5078
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5079
-		}
5075
+        // sinon on passe a la ligne et on indente
5076
+        $i_str = str_pad('', $indent, ' ');
5077
+        foreach ($u as $k => $v) {
5078
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5079
+        }
5080 5080
 
5081
-		return $out;
5082
-	}
5081
+        return $out;
5082
+    }
5083 5083
 
5084
-	// on sait pas quoi faire...
5085
-	return $u;
5084
+    // on sait pas quoi faire...
5085
+    return $u;
5086 5086
 }
5087 5087
 
5088 5088
 
@@ -5095,10 +5095,10 @@  discard block
 block discarded – undo
5095 5095
  * @return string|array
5096 5096
  */
5097 5097
 function objet_info($objet, $info) {
5098
-	$table = table_objet_sql($objet);
5099
-	$infos = lister_tables_objets_sql($table);
5098
+    $table = table_objet_sql($objet);
5099
+    $infos = lister_tables_objets_sql($table);
5100 5100
 
5101
-	return ($infos[$info] ?? '');
5101
+    return ($infos[$info] ?? '');
5102 5102
 }
5103 5103
 
5104 5104
 /**
@@ -5113,11 +5113,11 @@  discard block
 block discarded – undo
5113 5113
  *     Texte traduit du comptage, tel que '3 articles'
5114 5114
  */
5115 5115
 function objet_afficher_nb($nb, $objet) {
5116
-	if (!$nb) {
5117
-		return _T(objet_info($objet, 'info_aucun_objet'));
5118
-	} else {
5119
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5120
-	}
5116
+    if (!$nb) {
5117
+        return _T(objet_info($objet, 'info_aucun_objet'));
5118
+    } else {
5119
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5120
+    }
5121 5121
 }
5122 5122
 
5123 5123
 /**
@@ -5129,11 +5129,11 @@  discard block
 block discarded – undo
5129 5129
  * @return string
5130 5130
  */
5131 5131
 function objet_icone($objet, $taille = 24, $class = '') {
5132
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5133
-	$icone = chemin_image($icone);
5134
-	$balise_img = charger_filtre('balise_img');
5132
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5133
+    $icone = chemin_image($icone);
5134
+    $balise_img = charger_filtre('balise_img');
5135 5135
 
5136
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5136
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5137 5137
 }
5138 5138
 
5139 5139
 /**
@@ -5154,12 +5154,12 @@  discard block
 block discarded – undo
5154 5154
  * @return string
5155 5155
  */
5156 5156
 function objet_T($objet, $chaine, $args = [], $options = []) {
5157
-	$chaine = explode(':', $chaine);
5158
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5159
-		return $t;
5160
-	}
5161
-	$chaine = implode(':', $chaine);
5162
-	return _T($chaine, $args, $options);
5157
+    $chaine = explode(':', $chaine);
5158
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5159
+        return $t;
5160
+    }
5161
+    $chaine = implode(':', $chaine);
5162
+    return _T($chaine, $args, $options);
5163 5163
 }
5164 5164
 
5165 5165
 /**
@@ -5173,18 +5173,18 @@  discard block
 block discarded – undo
5173 5173
  * @return string      Code HTML
5174 5174
  */
5175 5175
 function insert_head_css_conditionnel($flux) {
5176
-	if (
5177
-		strpos($flux, '<!-- insert_head_css -->') === false
5178
-		and $p = strpos($flux, '<!-- insert_head -->')
5179
-	) {
5180
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5181
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5182
-			$p = $p1;
5183
-		}
5184
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5185
-	}
5176
+    if (
5177
+        strpos($flux, '<!-- insert_head_css -->') === false
5178
+        and $p = strpos($flux, '<!-- insert_head -->')
5179
+    ) {
5180
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5181
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5182
+            $p = $p1;
5183
+        }
5184
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5185
+    }
5186 5186
 
5187
-	return $flux;
5187
+    return $flux;
5188 5188
 }
5189 5189
 
5190 5190
 /**
@@ -5207,72 +5207,72 @@  discard block
 block discarded – undo
5207 5207
  * @return string
5208 5208
  */
5209 5209
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5210
-	if (isset($contexte['format'])) {
5211
-		$extension = $contexte['format'];
5212
-		unset($contexte['format']);
5213
-	} else {
5214
-		$extension = 'html';
5215
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5216
-			$extension = $m[1];
5217
-		}
5218
-	}
5219
-	// recuperer le contenu produit par le squelette
5220
-	$options['raw'] = true;
5221
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5222
-
5223
-	// calculer le nom de la css
5224
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5225
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5226
-	$contexte_implicite = calculer_contexte_implicite();
5227
-
5228
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5229
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5230
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5231
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5232
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5233
-	}
5234
-	else {
5235
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5236
-		ksort($contexte);
5237
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5238
-	}
5239
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5240
-
5241
-	// mettre a jour le fichier si il n'existe pas
5242
-	// ou trop ancien
5243
-	// le dernier fichier produit est toujours suffixe par .last
5244
-	// et recopie sur le fichier cible uniquement si il change
5245
-	if (
5246
-		!file_exists($filename)
5247
-		or !file_exists($filename . '.last')
5248
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5249
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5250
-	) {
5251
-		$contenu = $cache['texte'];
5252
-		// passer les urls en absolu si c'est une css
5253
-		if ($extension == 'css') {
5254
-			$contenu = urls_absolues_css(
5255
-				$contenu,
5256
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5257
-			);
5258
-		}
5259
-
5260
-		$comment = '';
5261
-		// ne pas insérer de commentaire sur certains formats
5262
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5263
-			$comment = "/* #PRODUIRE{fond=$fond";
5264
-			foreach ($contexte as $k => $v) {
5265
-				$comment .= ",$k=$v";
5266
-			}
5267
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5268
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5269
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5270
-		}
5271
-		// et ecrire le fichier si il change
5272
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5273
-	}
5274
-
5275
-	return timestamp($filename);
5210
+    if (isset($contexte['format'])) {
5211
+        $extension = $contexte['format'];
5212
+        unset($contexte['format']);
5213
+    } else {
5214
+        $extension = 'html';
5215
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5216
+            $extension = $m[1];
5217
+        }
5218
+    }
5219
+    // recuperer le contenu produit par le squelette
5220
+    $options['raw'] = true;
5221
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5222
+
5223
+    // calculer le nom de la css
5224
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5225
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5226
+    $contexte_implicite = calculer_contexte_implicite();
5227
+
5228
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5229
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5230
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5231
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5232
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5233
+    }
5234
+    else {
5235
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5236
+        ksort($contexte);
5237
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5238
+    }
5239
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5240
+
5241
+    // mettre a jour le fichier si il n'existe pas
5242
+    // ou trop ancien
5243
+    // le dernier fichier produit est toujours suffixe par .last
5244
+    // et recopie sur le fichier cible uniquement si il change
5245
+    if (
5246
+        !file_exists($filename)
5247
+        or !file_exists($filename . '.last')
5248
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5249
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5250
+    ) {
5251
+        $contenu = $cache['texte'];
5252
+        // passer les urls en absolu si c'est une css
5253
+        if ($extension == 'css') {
5254
+            $contenu = urls_absolues_css(
5255
+                $contenu,
5256
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5257
+            );
5258
+        }
5259
+
5260
+        $comment = '';
5261
+        // ne pas insérer de commentaire sur certains formats
5262
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5263
+            $comment = "/* #PRODUIRE{fond=$fond";
5264
+            foreach ($contexte as $k => $v) {
5265
+                $comment .= ",$k=$v";
5266
+            }
5267
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5268
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5269
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5270
+        }
5271
+        // et ecrire le fichier si il change
5272
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5273
+    }
5274
+
5275
+    return timestamp($filename);
5276 5276
 }
5277 5277
 
5278 5278
 /**
@@ -5285,15 +5285,15 @@  discard block
 block discarded – undo
5285 5285
  *    $fichier auquel on a ajouté le timestamp
5286 5286
  */
5287 5287
 function timestamp($fichier) {
5288
-	if (
5289
-		!$fichier
5290
-		or !file_exists($fichier)
5291
-		or !$m = filemtime($fichier)
5292
-	) {
5293
-		return $fichier;
5294
-	}
5288
+    if (
5289
+        !$fichier
5290
+        or !file_exists($fichier)
5291
+        or !$m = filemtime($fichier)
5292
+    ) {
5293
+        return $fichier;
5294
+    }
5295 5295
 
5296
-	return "$fichier?$m";
5296
+    return "$fichier?$m";
5297 5297
 }
5298 5298
 
5299 5299
 /**
@@ -5303,11 +5303,11 @@  discard block
 block discarded – undo
5303 5303
  * @return string
5304 5304
  */
5305 5305
 function supprimer_timestamp($url) {
5306
-	if (strpos($url, '?') === false) {
5307
-		return $url;
5308
-	}
5306
+    if (strpos($url, '?') === false) {
5307
+        return $url;
5308
+    }
5309 5309
 
5310
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5310
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5311 5311
 }
5312 5312
 
5313 5313
 /**
@@ -5322,9 +5322,9 @@  discard block
 block discarded – undo
5322 5322
  * @return string
5323 5323
  */
5324 5324
 function filtre_nettoyer_titre_email_dist($titre) {
5325
-	include_spip('inc/envoyer_mail');
5325
+    include_spip('inc/envoyer_mail');
5326 5326
 
5327
-	return nettoyer_titre_email($titre);
5327
+    return nettoyer_titre_email($titre);
5328 5328
 }
5329 5329
 
5330 5330
 /**
@@ -5346,27 +5346,27 @@  discard block
 block discarded – undo
5346 5346
  * @return string
5347 5347
  */
5348 5348
 function filtre_chercher_rubrique_dist(
5349
-	$titre,
5350
-	$id_objet,
5351
-	$id_parent,
5352
-	$objet,
5353
-	$id_secteur,
5354
-	$restreint,
5355
-	$actionable = false,
5356
-	$retour_sans_cadre = false
5349
+    $titre,
5350
+    $id_objet,
5351
+    $id_parent,
5352
+    $objet,
5353
+    $id_secteur,
5354
+    $restreint,
5355
+    $actionable = false,
5356
+    $retour_sans_cadre = false
5357 5357
 ) {
5358
-	include_spip('inc/filtres_ecrire');
5358
+    include_spip('inc/filtres_ecrire');
5359 5359
 
5360
-	return chercher_rubrique(
5361
-		$titre,
5362
-		$id_objet,
5363
-		$id_parent,
5364
-		$objet,
5365
-		$id_secteur,
5366
-		$restreint,
5367
-		$actionable,
5368
-		$retour_sans_cadre
5369
-	);
5360
+    return chercher_rubrique(
5361
+        $titre,
5362
+        $id_objet,
5363
+        $id_parent,
5364
+        $objet,
5365
+        $id_secteur,
5366
+        $restreint,
5367
+        $actionable,
5368
+        $retour_sans_cadre
5369
+    );
5370 5370
 }
5371 5371
 
5372 5372
 /**
@@ -5395,56 +5395,56 @@  discard block
 block discarded – undo
5395 5395
  *     Chaîne vide si l'accès est autorisé
5396 5396
  */
5397 5397
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5398
-	if ($ok) {
5399
-		return '';
5400
-	}
5401
-
5402
-	// Vider tous les tampons
5403
-	$level = @ob_get_level();
5404
-	while ($level--) {
5405
-		@ob_end_clean();
5406
-	}
5407
-
5408
-	include_spip('inc/headers');
5409
-
5410
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5411
-	if ($url) {
5412
-		redirige_par_entete($url, '', $statut);
5413
-	}
5414
-
5415
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5416
-	if (!is_numeric($statut) and is_null($message)) {
5417
-		$message = $statut;
5418
-		$statut = 0;
5419
-	}
5420
-	if (!$message) {
5421
-		$message = '';
5422
-	}
5423
-	$statut = intval($statut);
5424
-
5425
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5426
-	if (test_espace_prive()) {
5427
-		if (!$statut or !in_array($statut, [404, 403])) {
5428
-			$statut = 403;
5429
-		}
5430
-		http_response_code(403);
5431
-		$echec = charger_fonction('403', 'exec');
5432
-		$echec($message);
5433
-	} else {
5434
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5435
-		if (!$statut) {
5436
-			$statut = 404;
5437
-		}
5438
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5439
-		http_response_code($statut);
5440
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5441
-		if ($statut >= 400) {
5442
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5443
-		}
5444
-	}
5445
-
5446
-
5447
-	exit;
5398
+    if ($ok) {
5399
+        return '';
5400
+    }
5401
+
5402
+    // Vider tous les tampons
5403
+    $level = @ob_get_level();
5404
+    while ($level--) {
5405
+        @ob_end_clean();
5406
+    }
5407
+
5408
+    include_spip('inc/headers');
5409
+
5410
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5411
+    if ($url) {
5412
+        redirige_par_entete($url, '', $statut);
5413
+    }
5414
+
5415
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5416
+    if (!is_numeric($statut) and is_null($message)) {
5417
+        $message = $statut;
5418
+        $statut = 0;
5419
+    }
5420
+    if (!$message) {
5421
+        $message = '';
5422
+    }
5423
+    $statut = intval($statut);
5424
+
5425
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5426
+    if (test_espace_prive()) {
5427
+        if (!$statut or !in_array($statut, [404, 403])) {
5428
+            $statut = 403;
5429
+        }
5430
+        http_response_code(403);
5431
+        $echec = charger_fonction('403', 'exec');
5432
+        $echec($message);
5433
+    } else {
5434
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5435
+        if (!$statut) {
5436
+            $statut = 404;
5437
+        }
5438
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5439
+        http_response_code($statut);
5440
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5441
+        if ($statut >= 400) {
5442
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5443
+        }
5444
+    }
5445
+
5446
+
5447
+    exit;
5448 5448
 }
5449 5449
 
5450 5450
 /**
@@ -5455,11 +5455,11 @@  discard block
 block discarded – undo
5455 5455
  * @return string
5456 5456
  */
5457 5457
 function filtre_compacte_dist($source, $format = null) {
5458
-	if (function_exists('minifier')) {
5459
-		return minifier($source, $format);
5460
-	}
5458
+    if (function_exists('minifier')) {
5459
+        return minifier($source, $format);
5460
+    }
5461 5461
 
5462
-	return $source;
5462
+    return $source;
5463 5463
 }
5464 5464
 
5465 5465
 
@@ -5471,31 +5471,31 @@  discard block
 block discarded – undo
5471 5471
  * @return string
5472 5472
  */
5473 5473
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5474
-	$l = strlen($passe);
5475
-
5476
-	if ($l <= 8 or !$afficher_partiellement) {
5477
-		if (!$l) {
5478
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5479
-		}
5480
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5481
-	}
5482
-
5483
-	if (is_null($portion_pourcent)) {
5484
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5485
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5486
-		}
5487
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5488
-	}
5489
-	if ($portion_pourcent >= 100) {
5490
-		return $passe;
5491
-	}
5492
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5493
-	$e = max($e, 0);
5494
-	$mid = str_pad('', $l - 2 * $e, '*');
5495
-	if ($e > 0 and strlen($mid) > 8) {
5496
-		$mid = '***...***';
5497
-	}
5498
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5474
+    $l = strlen($passe);
5475
+
5476
+    if ($l <= 8 or !$afficher_partiellement) {
5477
+        if (!$l) {
5478
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5479
+        }
5480
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5481
+    }
5482
+
5483
+    if (is_null($portion_pourcent)) {
5484
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5485
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5486
+        }
5487
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5488
+    }
5489
+    if ($portion_pourcent >= 100) {
5490
+        return $passe;
5491
+    }
5492
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5493
+    $e = max($e, 0);
5494
+    $mid = str_pad('', $l - 2 * $e, '*');
5495
+    if ($e > 0 and strlen($mid) > 8) {
5496
+        $mid = '***...***';
5497
+    }
5498
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5499 5499
 }
5500 5500
 
5501 5501
 
@@ -5516,64 +5516,64 @@  discard block
 block discarded – undo
5516 5516
  */
5517 5517
 function identifiant_slug($texte, $type = '', $options = []) {
5518 5518
 
5519
-	$original = $texte;
5520
-	$separateur = ($options['separateur'] ?? '_');
5521
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5522
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5519
+    $original = $texte;
5520
+    $separateur = ($options['separateur'] ?? '_');
5521
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5522
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5523 5523
 
5524
-	if (!function_exists('translitteration')) {
5525
-		include_spip('inc/charsets');
5526
-	}
5524
+    if (!function_exists('translitteration')) {
5525
+        include_spip('inc/charsets');
5526
+    }
5527 5527
 
5528
-	// pas de balise html
5529
-	if (strpos($texte, '<') !== false) {
5530
-		$texte = strip_tags($texte);
5531
-	}
5532
-	if (strpos($texte, '&') !== false) {
5533
-		$texte = unicode2charset($texte);
5534
-	}
5535
-	// On enlève les espaces indésirables
5536
-	$texte = trim($texte);
5528
+    // pas de balise html
5529
+    if (strpos($texte, '<') !== false) {
5530
+        $texte = strip_tags($texte);
5531
+    }
5532
+    if (strpos($texte, '&') !== false) {
5533
+        $texte = unicode2charset($texte);
5534
+    }
5535
+    // On enlève les espaces indésirables
5536
+    $texte = trim($texte);
5537 5537
 
5538
-	// On enlève les accents et cie
5539
-	$texte = translitteration($texte);
5538
+    // On enlève les accents et cie
5539
+    $texte = translitteration($texte);
5540 5540
 
5541
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5542
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5541
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5542
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5543 5543
 
5544
-	// nettoyer les doubles occurences du separateur si besoin
5545
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5546
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5547
-	}
5544
+    // nettoyer les doubles occurences du separateur si besoin
5545
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5546
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5547
+    }
5548 5548
 
5549
-	// pas de separateur au debut ni a la fin
5550
-	$texte = trim($texte, $separateur);
5549
+    // pas de separateur au debut ni a la fin
5550
+    $texte = trim($texte, $separateur);
5551 5551
 
5552
-	// en minuscules
5553
-	$texte = strtolower($texte);
5552
+    // en minuscules
5553
+    $texte = strtolower($texte);
5554 5554
 
5555
-	switch ($type) {
5556
-		case 'class':
5557
-		case 'id':
5558
-		case 'anchor':
5559
-			if (preg_match(',^\d,', $texte)) {
5560
-				$texte = substr($type, 0, 1) . $texte;
5561
-			}
5562
-	}
5555
+    switch ($type) {
5556
+        case 'class':
5557
+        case 'id':
5558
+        case 'anchor':
5559
+            if (preg_match(',^\d,', $texte)) {
5560
+                $texte = substr($type, 0, 1) . $texte;
5561
+            }
5562
+    }
5563 5563
 
5564
-	if (strlen($texte) > $longueur_maxi) {
5565
-		$texte = substr($texte, 0, $longueur_maxi);
5566
-	}
5564
+    if (strlen($texte) > $longueur_maxi) {
5565
+        $texte = substr($texte, 0, $longueur_maxi);
5566
+    }
5567 5567
 
5568
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5569
-		if (preg_match(',^\d,', $texte)) {
5570
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5571
-		}
5572
-		$texte .= $separateur . md5($original);
5573
-		$texte = substr($texte, 0, $longueur_mini);
5574
-	}
5568
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5569
+        if (preg_match(',^\d,', $texte)) {
5570
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5571
+        }
5572
+        $texte .= $separateur . md5($original);
5573
+        $texte = substr($texte, 0, $longueur_mini);
5574
+    }
5575 5575
 
5576
-	return $texte;
5576
+    return $texte;
5577 5577
 }
5578 5578
 
5579 5579
 
@@ -5594,11 +5594,11 @@  discard block
 block discarded – undo
5594 5594
  * @exemple `<:info_maximum|label_nettoyer:>`
5595 5595
  */
5596 5596
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5597
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5598
-	if ($ucfirst) {
5599
-		$label = spip_ucfirst($label);
5600
-	}
5601
-	return $label;
5597
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5598
+    if ($ucfirst) {
5599
+        $label = spip_ucfirst($label);
5600
+    }
5601
+    return $label;
5602 5602
 }
5603 5603
 
5604 5604
 /**
@@ -5611,8 +5611,8 @@  discard block
 block discarded – undo
5611 5611
  * @exemple `<:info_maximum|label_ponctuer:>`
5612 5612
  */
5613 5613
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5614
-	$label = label_nettoyer($text, $ucfirst);
5615
-	return _T('label_ponctuer', ['label' => $label]);
5614
+    $label = label_nettoyer($text, $ucfirst);
5615
+    return _T('label_ponctuer', ['label' => $label]);
5616 5616
 }
5617 5617
 
5618 5618
 
@@ -5625,19 +5625,19 @@  discard block
 block discarded – undo
5625 5625
  * @return array
5626 5626
  */
5627 5627
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5628
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5629
-		return [];
5630
-	}
5628
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5629
+        return [];
5630
+    }
5631 5631
 
5632
-	// compatibilite signature inversee
5633
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5634
-		[$objet, $id_objet] = [$id_objet, $objet];
5635
-	}
5632
+    // compatibilite signature inversee
5633
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5634
+        [$objet, $id_objet] = [$id_objet, $objet];
5635
+    }
5636 5636
 
5637
-	if (!function_exists($fonction)) {
5638
-		include_spip('base/objets');
5639
-	}
5640
-	return $fonction($objet, $id_objet);
5637
+    if (!function_exists($fonction)) {
5638
+        include_spip('base/objets');
5639
+    }
5640
+    return $fonction($objet, $id_objet);
5641 5641
 }
5642 5642
 
5643 5643
 
@@ -5652,7 +5652,7 @@  discard block
 block discarded – undo
5652 5652
  * @return array
5653 5653
  */
5654 5654
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5655
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5655
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5656 5656
 }
5657 5657
 
5658 5658
 /**
@@ -5666,7 +5666,7 @@  discard block
 block discarded – undo
5666 5666
  * @return array
5667 5667
  */
5668 5668
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5669
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5669
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5670 5670
 }
5671 5671
 
5672 5672
 /**
@@ -5680,7 +5680,7 @@  discard block
 block discarded – undo
5680 5680
  * @return array
5681 5681
  */
5682 5682
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5683
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5683
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5684 5684
 }
5685 5685
 
5686 5686
 /**
@@ -5694,5 +5694,5 @@  discard block
 block discarded – undo
5694 5694
  * @return array
5695 5695
  */
5696 5696
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5697
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5697
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5698 5698
 }
Please login to merge, or discard this patch.
Spacing   +133 added lines, -134 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
+	foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) {
100 100
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101 101
 		// fonction ou name\space\fonction
102 102
 		if (is_callable($f)) {
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	// affichage "GIT [master: abcdef]"
240 240
 	$commit = $desc['commit_short'] ?? $desc['commit'];
241 241
 	if ($desc['branch']) {
242
-		$commit = $desc['branch'] . ': ' . $commit;
242
+		$commit = $desc['branch'].': '.$commit;
243 243
 	}
244 244
 	return "{$desc['vcs']} [$commit]";
245 245
 }
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	}
259 259
 
260 260
 	// version installee par GIT
261
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
261
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
262 262
 		$currentHead = trim(substr($c, 4));
263
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
263
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
264 264
 			return [
265 265
 				'vcs' => 'GIT',
266 266
 				'branch' => basename($currentHead),
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 		$dir = '.';
288 288
 	}
289 289
 	// version installee par SVN
290
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
291
-		$db = new SQLite3($dir . '/.svn/wc.db');
290
+	if (file_exists($dir.'/.svn/wc.db') && class_exists(\SQLite3::class)) {
291
+		$db = new SQLite3($dir.'/.svn/wc.db');
292 292
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
293 293
 		if ($result) {
294 294
 			$row = $result->fetchArray();
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 
307 307
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
308 308
 // et laisser passer les fonctions personnelles baptisees image_...
309
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
310
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
311
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
312
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
313
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
314
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
309
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
310
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
311
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
312
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
313
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
314
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
315 315
 
316 316
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
317 317
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -470,8 +470,8 @@  discard block
 block discarded – undo
470 470
  */
471 471
 function filtre_debug($val, $key = null) {
472 472
 	$debug = (
473
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
474
-		) . var_export($val, true);
473
+		is_null($key) ? '' : (var_export($key, true).' = ')
474
+		).var_export($val, true);
475 475
 
476 476
 	include_spip('inc/autoriser');
477 477
 	if (autoriser('webmestre')) {
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 		$is_file = false;
526 526
 	}
527 527
 	if ($is_file) {
528
-		$is_local_file = function ($path) {
528
+		$is_local_file = function($path) {
529 529
 			if (strpos($path, '?') !== false) {
530 530
 				$path = supprimer_timestamp($path);
531 531
 				// remove ?24px added by find_in_theme on .svg files
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
578 578
 							$srcover = $match[1];
579 579
 							array_shift($args);
580
-							array_unshift($args, "<img src='" . $match[1] . "' />");
580
+							array_unshift($args, "<img src='".$match[1]."' />");
581 581
 							$srcover_filter = call_user_func_array($filtre, $args);
582 582
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
583 583
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 			if (!$srcHeight) {
654 654
 				$hauteur_img[$src] = $srcHeight = $imagesize[1];
655 655
 			}
656
-			if (!$srcSize){
656
+			if (!$srcSize) {
657 657
 				$poids_img[$src] = filesize($src);
658 658
 			}
659 659
 		}
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 				if (!$srcHeight) {
668 668
 					$hauteur_img[$src] = $srcHeight = $height;
669 669
 				}
670
-				if (!$srcSize){
670
+				if (!$srcSize) {
671 671
 					$poids_img[$src] = $srcSize = strlen($src);
672 672
 				}
673 673
 			}
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 			if (!$srcHeight) {
686 686
 				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
687 687
 			}
688
-			if (!$srcSize){
688
+			if (!$srcSize) {
689 689
 				$poids_img[$src] = $srcSize = 0;
690 690
 			}
691 691
 		}
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	return $infos['poids'];
712 712
 }
713 713
 
714
-function taille_image($img, $force_refresh = false){
714
+function taille_image($img, $force_refresh = false) {
715 715
 	$infos = infos_image($img, $force_refresh);
716 716
 	return [$infos['hauteur'], $infos['largeur']];
717 717
 }
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 	// " -> &quot; et tout ce genre de choses
981 981
 	$u = $GLOBALS['meta']['pcre_u'];
982 982
 	$texte = str_replace('&nbsp;', ' ', $texte);
983
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
983
+	$texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte);
984 984
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
985 985
 	$texte = entites_html($texte, false, false);
986 986
 	// mais bien echapper les double quotes !
@@ -1040,7 +1040,7 @@  discard block
 block discarded – undo
1040 1040
  **/
1041 1041
 function supprimer_numero($texte) {
1042 1042
 	return preg_replace(
1043
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1043
+		',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1044 1044
 		'',
1045 1045
 		$texte
1046 1046
 	);
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 function recuperer_numero($texte) {
1069 1069
 	if (
1070 1070
 		preg_match(
1071
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1071
+			',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1072 1072
 			$texte,
1073 1073
 			$regs
1074 1074
 		)
@@ -1159,8 +1159,8 @@  discard block
 block discarded – undo
1159 1159
  **/
1160 1160
 function textebrut($texte) {
1161 1161
 	$u = $GLOBALS['meta']['pcre_u'];
1162
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1163
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1162
+	$texte = preg_replace('/\s+/S'.$u, ' ', $texte);
1163
+	$texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte);
1164 1164
 	$texte = preg_replace("/^\n+/", '', $texte);
1165 1165
 	$texte = preg_replace("/\n+$/", '', $texte);
1166 1166
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 		)
1195 1195
 	) {
1196 1196
 		foreach ($liens[0] as $a) {
1197
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1197
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1198 1198
 			$ablank = inserer_attribut($a, 'rel', $rel);
1199 1199
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1200 1200
 			$texte = str_replace($a, $ablank, $texte);
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		foreach ($regs[0] as $a) {
1220 1220
 			$rel = extraire_attribut($a, 'rel') ?? '';
1221 1221
 			if (strpos($rel, 'nofollow') === false) {
1222
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1222
+				$rel = 'nofollow'.($rel ? " $rel" : '');
1223 1223
 				$anofollow = inserer_attribut($a, 'rel', $rel);
1224 1224
 				$texte = str_replace($a, $anofollow, $texte);
1225 1225
 			}
@@ -1248,7 +1248,7 @@  discard block
 block discarded – undo
1248 1248
 	$u = $GLOBALS['meta']['pcre_u'];
1249 1249
 	$texte = preg_replace('@</p>@iS', "\n", $texte);
1250 1250
 	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1251
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1251
+	$texte = preg_replace('@^\s*<br />@S'.$u, '', $texte);
1252 1252
 
1253 1253
 	return $texte;
1254 1254
 }
@@ -1279,7 +1279,7 @@  discard block
 block discarded – undo
1279 1279
 		return $texte;
1280 1280
 	}
1281 1281
 	include_spip('inc/texte');
1282
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1282
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1283 1283
 		'div' : 'span';
1284 1284
 
1285 1285
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 	}
1392 1392
 	$u = $GLOBALS['meta']['pcre_u'];
1393 1393
 	if ($textebrut) {
1394
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1394
+		$texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte));
1395 1395
 	}
1396 1396
 	$texte = texte_backend($texte);
1397 1397
 	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
 	# un message pour abs_url
1427 1427
 	$GLOBALS['mode_abs_url'] = 'url';
1428 1428
 	$url = trim($url);
1429
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1429
+	$r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS';
1430 1430
 
1431 1431
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1432 1432
 }
@@ -1626,14 +1626,14 @@  discard block
 block discarded – undo
1626 1626
 	if (strpos($texte, '<') !== false) {
1627 1627
 		include_spip('inc/lien');
1628 1628
 		if (defined('_PREG_MODELE')) {
1629
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1629
+			$preg_modeles = '@'._PREG_MODELE.'@imsS';
1630 1630
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1631 1631
 		}
1632 1632
 	}
1633 1633
 
1634 1634
 	$debut = '';
1635 1635
 	$suite = $texte;
1636
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1636
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1637 1637
 		$debut .= substr($suite, 0, $t - 1);
1638 1638
 		$suite = substr($suite, $t);
1639 1639
 		$car = substr($suite, 0, 1);
@@ -1651,11 +1651,11 @@  discard block
 block discarded – undo
1651 1651
 			$suite = substr($suite, strlen($regs[0]));
1652 1652
 		}
1653 1653
 	}
1654
-	$texte = $debut . $suite;
1654
+	$texte = $debut.$suite;
1655 1655
 
1656 1656
 	$texte = echappe_retour($texte);
1657 1657
 
1658
-	return $texte . $fin;
1658
+	return $texte.$fin;
1659 1659
 }
1660 1660
 
1661 1661
 
@@ -1717,7 +1717,7 @@  discard block
 block discarded – undo
1717 1717
 		}
1718 1718
 
1719 1719
 		foreach ($regs as $reg) {
1720
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1720
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1721 1721
 			$desc = $traduire($cle, $lang, true);
1722 1722
 			$l = $desc->langue;
1723 1723
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1831,9 +1831,9 @@  discard block
 block discarded – undo
1831 1831
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1832 1832
 					include_spip('inc/texte');
1833 1833
 					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1834
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1834
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1835 1835
 					if ($mode === 'div') {
1836
-						$trad = rtrim($trad) . "\n\n";
1836
+						$trad = rtrim($trad)."\n\n";
1837 1837
 					}
1838 1838
 					$trad = code_echappement($trad, 'multi', false, $mode);
1839 1839
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
@@ -2029,7 +2029,7 @@  discard block
 block discarded – undo
2029 2029
 	if (is_array($balise)) {
2030 2030
 		array_walk(
2031 2031
 			$balise,
2032
-			function (&$a, $key, $t) {
2032
+			function(&$a, $key, $t) {
2033 2033
 				$a = extraire_attribut($a, $t);
2034 2034
 			},
2035 2035
 			$attribut
@@ -2126,14 +2126,14 @@  discard block
 block discarded – undo
2126 2126
 
2127 2127
 	if ($old !== null) {
2128 2128
 		// Remplacer l'ancien attribut du meme nom
2129
-		$balise = $r[1] . $insert . $r[5];
2129
+		$balise = $r[1].$insert.$r[5];
2130 2130
 	} else {
2131 2131
 		// preferer une balise " />" (comme <img />)
2132 2132
 		if (preg_match(',/>,', $balise)) {
2133
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2133
+			$balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1);
2134 2134
 		} // sinon une balise <a ...> ... </a>
2135 2135
 		else {
2136
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2136
+			$balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1);
2137 2137
 		}
2138 2138
 	}
2139 2139
 
@@ -2188,7 +2188,7 @@  discard block
 block discarded – undo
2188 2188
 		if (
2189 2189
 			$class_courante
2190 2190
 			and strpos($class_courante, (string) $c) !== false
2191
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2191
+			and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante)
2192 2192
 		) {
2193 2193
 			$is_class_presente = true;
2194 2194
 		}
@@ -2196,12 +2196,12 @@  discard block
 block discarded – undo
2196 2196
 			in_array($operation, ['ajouter', 'commuter'])
2197 2197
 			and !$is_class_presente
2198 2198
 		) {
2199
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2199
+			$class_new = ltrim(rtrim($class_new ?? '').' '.$c);
2200 2200
 		} elseif (
2201 2201
 			in_array($operation, ['supprimer', 'commuter'])
2202 2202
 			and $is_class_presente
2203 2203
 		) {
2204
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2204
+			$class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new));
2205 2205
 		}
2206 2206
 	}
2207 2207
 
@@ -2264,7 +2264,7 @@  discard block
 block discarded – undo
2264 2264
 // Quelques fonctions de calcul arithmetique
2265 2265
 //
2266 2266
 function floatstr($a) {
2267
- return str_replace(',', '.', (string)floatval($a));
2267
+ return str_replace(',', '.', (string) floatval($a));
2268 2268
 }
2269 2269
 function strize($f, $a, $b) {
2270 2270
  return floatstr($f(floatstr($a), floatstr($b)));
@@ -2400,13 +2400,13 @@  discard block
 block discarded – undo
2400 2400
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2401 2401
 		define('_TAGS_NOM_AUTEUR', '');
2402 2402
 	}
2403
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2403
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2404 2404
 	foreach ($tags_acceptes as $tag) {
2405 2405
 		if (strlen($tag)) {
2406
-			$remp1[] = '<' . trim($tag) . '>';
2407
-			$remp1[] = '</' . trim($tag) . '>';
2408
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2409
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2406
+			$remp1[] = '<'.trim($tag).'>';
2407
+			$remp1[] = '</'.trim($tag).'>';
2408
+			$remp2[] = '\x60'.trim($tag).'\x61';
2409
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2410 2410
 		}
2411 2411
 	}
2412 2412
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2460,7 +2460,7 @@  discard block
 block discarded – undo
2460 2460
 				. http_img_pack(
2461 2461
 					'attachment-16.png',
2462 2462
 					$t,
2463
-					'title="' . attribut_html($t) . '"'
2463
+					'title="'.attribut_html($t).'"'
2464 2464
 				)
2465 2465
 				. '</a>',
2466 2466
 				$tag
@@ -2524,10 +2524,10 @@  discard block
 block discarded – undo
2524 2524
 	$fichier = basename($url);
2525 2525
 
2526 2526
 	return '<a rel="enclosure"'
2527
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2528
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2529
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2530
-	. '>' . $fichier . '</a>';
2527
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2528
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2529
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2530
+	. '>'.$fichier.'</a>';
2531 2531
 }
2532 2532
 
2533 2533
 /**
@@ -2555,9 +2555,9 @@  discard block
 block discarded – undo
2555 2555
 			} # vieux data
2556 2556
 			$fichier = basename($url);
2557 2557
 			$enclosures[] = '<enclosure'
2558
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2559
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2560
-				. ($length ? ' length="' . $length . '"' : '')
2558
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2559
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2560
+				. ($length ? ' length="'.$length.'"' : '')
2561 2561
 				. ' />';
2562 2562
 		}
2563 2563
 	}
@@ -2583,7 +2583,7 @@  discard block
 block discarded – undo
2583 2583
 		if (extraire_attribut($e, 'rel') == 'tag') {
2584 2584
 			$subjects .= '<dc:subject>'
2585 2585
 				. texte_backend(textebrut($e))
2586
-				. '</dc:subject>' . "\n";
2586
+				. '</dc:subject>'."\n";
2587 2587
 		}
2588 2588
 	}
2589 2589
 
@@ -2619,7 +2619,7 @@  discard block
 block discarded – undo
2619 2619
 	if (is_array($texte)) {
2620 2620
 		array_walk(
2621 2621
 			$texte,
2622
-			function (&$a, $key, $t) {
2622
+			function(&$a, $key, $t) {
2623 2623
 				$a = extraire_balise($a, $t);
2624 2624
 			},
2625 2625
 			$tag
@@ -2667,7 +2667,7 @@  discard block
 block discarded – undo
2667 2667
 	if (is_array($texte)) {
2668 2668
 		array_walk(
2669 2669
 			$texte,
2670
-			function (&$a, $key, $t) {
2670
+			function(&$a, $key, $t) {
2671 2671
 				$a = extraire_balises($a, $t);
2672 2672
 			},
2673 2673
 			$tag
@@ -2800,7 +2800,7 @@  discard block
 block discarded – undo
2800 2800
 		if ($fond != '404') {
2801 2801
 			$contexte = array_shift($p);
2802 2802
 			$contexte['page'] = $fond;
2803
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2803
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2804 2804
 		}
2805 2805
 	}
2806 2806
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2855,9 +2855,9 @@  discard block
 block discarded – undo
2855 2855
 			. '"'
2856 2856
 			. (is_null($val)
2857 2857
 				? ''
2858
-				: ' value="' . entites_html($val) . '"'
2858
+				: ' value="'.entites_html($val).'"'
2859 2859
 			)
2860
-			. ' type="hidden"' . "\n/>";
2860
+			. ' type="hidden"'."\n/>";
2861 2861
 	}
2862 2862
 
2863 2863
 	return join('', $hidden);
@@ -2967,7 +2967,7 @@  discard block
 block discarded – undo
2967 2967
 
2968 2968
 	return preg_replace_callback(
2969 2969
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2970
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2970
+		fn($x) => "url('".suivre_lien($path, $x[1])."')",
2971 2971
 		$contenu
2972 2972
 	);
2973 2973
 }
@@ -3028,14 +3028,14 @@  discard block
 block discarded – undo
3028 3028
 	) {
3029 3029
 		$distant = true;
3030 3030
 		$cssf = parse_url($css);
3031
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3031
+		$cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : '');
3032 3032
 		$cssf = preg_replace(',[?:&=],', '_', $cssf);
3033 3033
 	} else {
3034 3034
 		$distant = false;
3035 3035
 		$cssf = $css;
3036 3036
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3037 3037
 		//propose (rien a faire dans ce cas)
3038
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3038
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
3039 3039
 		if (@file_exists($f)) {
3040 3040
 			return $f;
3041 3041
 		}
@@ -3045,7 +3045,7 @@  discard block
 block discarded – undo
3045 3045
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3046 3046
 	$f = $dir_var
3047 3047
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3048
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3048
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
3049 3049
 
3050 3050
 	// la css peut etre distante (url absolue !)
3051 3051
 	if ($distant) {
@@ -3091,8 +3091,8 @@  discard block
 block discarded – undo
3091 3091
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3092 3092
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3093 3093
 			$css_direction = substr($css_direction, strlen($dir_var));
3094
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3095
-			$css_direction = '/@@@@@@/' . $css_direction;
3094
+			$src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction;
3095
+			$css_direction = '/@@@@@@/'.$css_direction;
3096 3096
 		}
3097 3097
 		$src[] = $regs[0][$k];
3098 3098
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3141,7 +3141,7 @@  discard block
 block discarded – undo
3141 3141
 
3142 3142
 	$f = basename($css, '.css');
3143 3143
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3144
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3144
+		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3145 3145
 		. '.css';
3146 3146
 
3147 3147
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3151,7 +3151,7 @@  discard block
 block discarded – undo
3151 3151
 	if ($url_absolue_css == $css) {
3152 3152
 		if (
3153 3153
 			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3154
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3154
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3155 3155
 		) {
3156 3156
 			include_spip('inc/distant');
3157 3157
 			$contenu = recuperer_url($css);
@@ -3263,7 +3263,7 @@  discard block
 block discarded – undo
3263 3263
 	$expression = str_replace('\/', '/', $expression);
3264 3264
 	$expression = str_replace('/', '\/', $expression);
3265 3265
 
3266
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3266
+	if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) {
3267 3267
 		if (isset($r[$capte])) {
3268 3268
 			return $r[$capte];
3269 3269
 		} else {
@@ -3301,7 +3301,7 @@  discard block
 block discarded – undo
3301 3301
 	$expression = str_replace('\/', '/', $expression);
3302 3302
 	$expression = str_replace('/', '\/', $expression);
3303 3303
 
3304
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3304
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3305 3305
 }
3306 3306
 
3307 3307
 
@@ -3320,7 +3320,7 @@  discard block
 block discarded – undo
3320 3320
 function traiter_doublons_documents(&$doublons, $letexte) {
3321 3321
 
3322 3322
 	// Verifier dans le texte & les notes (pas beau, helas)
3323
-	$t = $letexte . $GLOBALS['les_notes'];
3323
+	$t = $letexte.$GLOBALS['les_notes'];
3324 3324
 
3325 3325
 	if (
3326 3326
 		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
@@ -3334,7 +3334,7 @@  discard block
 block discarded – undo
3334 3334
 		if (!isset($doublons['documents'])) {
3335 3335
 			$doublons['documents'] = '';
3336 3336
 		}
3337
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3337
+		$doublons['documents'] .= ','.join(',', $matches[1]);
3338 3338
 	}
3339 3339
 
3340 3340
 	return $letexte;
@@ -3391,7 +3391,7 @@  discard block
 block discarded – undo
3391 3391
 	if ($env) {
3392 3392
 		foreach ($env as $i => $j) {
3393 3393
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3394
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3394
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3395 3395
 			}
3396 3396
 		}
3397 3397
 	}
@@ -3430,7 +3430,7 @@  discard block
 block discarded – undo
3430 3430
 	if ($env) {
3431 3431
 		foreach ($env as $i => $j) {
3432 3432
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3433
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3433
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3434 3434
 			}
3435 3435
 		}
3436 3436
 	}
@@ -3504,10 +3504,10 @@  discard block
 block discarded – undo
3504 3504
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3505 3505
 	if (
3506 3506
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3507
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3507
+		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg'
3508 3508
 		and file_exists($variante_svg_generique)
3509 3509
 	) {
3510
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3510
+		if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) {
3511 3511
 			$img_file = $variante_svg_size;
3512 3512
 		}
3513 3513
 		else {
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
 				return '';
3566 3566
 			}
3567 3567
 		}
3568
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3568
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3569 3569
 	}
3570 3570
 
3571 3571
 	if (file_exists($img_file)) {
@@ -3575,14 +3575,14 @@  discard block
 block discarded – undo
3575 3575
 		$alt = '';
3576 3576
 	}
3577 3577
 	elseif ($alt or $alt === '') {
3578
-		$alt = " alt='" . attribut_html($alt) . "'";
3578
+		$alt = " alt='".attribut_html($alt)."'";
3579 3579
 	}
3580 3580
 	else {
3581
-		$alt = " alt='" . attribut_html($title) . "'";
3581
+		$alt = " alt='".attribut_html($title)."'";
3582 3582
 	}
3583 3583
 	return "<img src='$img_file'$alt"
3584
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3585
-	. ' ' . ltrim($atts)
3584
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3585
+	. ' '.ltrim($atts)
3586 3586
 	. ' />';
3587 3587
 }
3588 3588
 
@@ -3596,10 +3596,10 @@  discard block
 block discarded – undo
3596 3596
  */
3597 3597
 function http_style_background($img, $att = '', $size = null) {
3598 3598
 	if ($size and is_numeric($size)) {
3599
-		$size = trim($size) . 'px';
3599
+		$size = trim($size).'px';
3600 3600
 	}
3601
-	return " style='background" .
3602
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3601
+	return " style='background".
3602
+		($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';'
3603 3603
 		. ($size ? "background-size:{$size};" : '')
3604 3604
 		. "'";
3605 3605
 }
@@ -3714,7 +3714,7 @@  discard block
 block discarded – undo
3714 3714
 		$img = http_img_pack(
3715 3715
 			$img,
3716 3716
 			$alt,
3717
-			$class ? " class='" . attribut_html($class) . "'" : '',
3717
+			$class ? " class='".attribut_html($class)."'" : '',
3718 3718
 			'',
3719 3719
 			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3720 3720
 		);
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
 	$balise_svg_source = $balise_svg;
3800 3800
 
3801 3801
 	// entete XML à supprimer
3802
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3802
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3803 3803
 
3804 3804
 	// IE est toujours mon ami
3805 3805
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3817,9 +3817,9 @@  discard block
 block discarded – undo
3817 3817
 	// regler le alt
3818 3818
 	if ($alt) {
3819 3819
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3820
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3820
+		$id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4);
3821 3821
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3822
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3822
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3823 3823
 		$balise_svg .= $title;
3824 3824
 	}
3825 3825
 	else {
@@ -3867,7 +3867,7 @@  discard block
 block discarded – undo
3867 3867
 	if (is_array($tableau)) {
3868 3868
 		foreach ($tableau as $k => $v) {
3869 3869
 			$res = recuperer_fond(
3870
-				'modeles/' . $modele,
3870
+				'modeles/'.$modele,
3871 3871
 				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3872 3872
 			);
3873 3873
 			$texte .= $res;
@@ -4052,7 +4052,7 @@  discard block
 block discarded – undo
4052 4052
 	}
4053 4053
 
4054 4054
 	$c = serialize($c);
4055
-	$cle = calculer_cle_action($form . $c);
4055
+	$cle = calculer_cle_action($form.$c);
4056 4056
 	$c = "$cle:$c";
4057 4057
 
4058 4058
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -4110,15 +4110,15 @@  discard block
 block discarded – undo
4110 4110
 	}
4111 4111
 	// toujours encoder l'url source dans le bloc ajax
4112 4112
 	$r = self();
4113
-	$r = ' data-origin="' . $r . '"';
4113
+	$r = ' data-origin="'.$r.'"';
4114 4114
 	$class = 'ajaxbloc';
4115 4115
 	if ($ajaxid and is_string($ajaxid)) {
4116 4116
 		// ajaxid est normalement conforme a un nom de classe css
4117 4117
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4118
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4118
+		$class .= ' ajax-id-'.entites_html($ajaxid);
4119 4119
 	}
4120 4120
 
4121
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4121
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4122 4122
 }
4123 4123
 
4124 4124
 /**
@@ -4162,7 +4162,7 @@  discard block
 block discarded – undo
4162 4162
 		$cle = substr($c, 0, $p);
4163 4163
 		$c = substr($c, $p + 1);
4164 4164
 
4165
-		if ($cle == calculer_cle_action($form . $c)) {
4165
+		if ($cle == calculer_cle_action($form.$c)) {
4166 4166
 			$env = @unserialize($c);
4167 4167
 			return $env;
4168 4168
 		}
@@ -4283,13 +4283,13 @@  discard block
 block discarded – undo
4283 4283
 				}
4284 4284
 			}
4285 4285
 		}
4286
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4286
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4287 4287
 	} else {
4288 4288
 		$bal = 'a';
4289 4289
 		$att = "href='$url'"
4290
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4291
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4292
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4290
+			. ($title ? " title='".attribut_html($title)."'" : '')
4291
+			. ($class ? " class='".attribut_html($class)."'" : '')
4292
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4293 4293
 			. $evt;
4294 4294
 	}
4295 4295
 	if ($libelle === null) {
@@ -4428,7 +4428,7 @@  discard block
 block discarded – undo
4428 4428
 
4429 4429
 	// Icône
4430 4430
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4431
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4431
+	$icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>";
4432 4432
 
4433 4433
 	// Markup final
4434 4434
 	if ($type == 'lien') {
@@ -4705,20 +4705,20 @@  discard block
 block discarded – undo
4705 4705
 		$class_form = 'ajax';
4706 4706
 		$class = str_replace('ajax', '', $class);
4707 4707
 	}
4708
-	$class_btn = 'submit ' . trim($class);
4708
+	$class_btn = 'submit '.trim($class);
4709 4709
 
4710 4710
 	if ($confirm) {
4711
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4711
+		$confirm = 'confirm("'.attribut_html($confirm).'")';
4712 4712
 		if ($callback) {
4713 4713
 			$callback = "$confirm?($callback):false";
4714 4714
 		} else {
4715 4715
 			$callback = $confirm;
4716 4716
 		}
4717 4717
 	}
4718
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4718
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : '';
4719 4719
 	$title = $title ? " title='$title'" : '';
4720 4720
 
4721
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4721
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4722 4722
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4723 4723
 }
4724 4724
 
@@ -4783,14 +4783,14 @@  discard block
 block discarded – undo
4783 4783
 		$champ_titre = '';
4784 4784
 		if ($demande_titre) {
4785 4785
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4786
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4786
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4787 4787
 		}
4788 4788
 		include_spip('base/abstract_sql');
4789 4789
 		include_spip('base/connect_sql');
4790 4790
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4791
-			'*' . $champ_titre,
4791
+			'*'.$champ_titre,
4792 4792
 			$desc['table_sql'],
4793
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4793
+			id_table_objet($type_objet).' = '.intval($id_objet)
4794 4794
 		);
4795 4795
 
4796 4796
 		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
@@ -4883,8 +4883,7 @@  discard block
 block discarded – undo
4883 4883
 	if (isset($ligne_sql['chapo'])) {
4884 4884
 		$chapo = $ligne_sql['chapo'];
4885 4885
 		$texte = strlen($descriptif) ?
4886
-			'' :
4887
-			"$chapo \n\n $texte";
4886
+			'' : "$chapo \n\n $texte";
4888 4887
 	}
4889 4888
 
4890 4889
 	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
@@ -4959,7 +4958,7 @@  discard block
 block discarded – undo
4959 4958
 		return $texte;
4960 4959
 	}
4961 4960
 
4962
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4961
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4963 4962
 
4964 4963
 	// Fournir $connect et $Pile[0] au traitement si besoin
4965 4964
 	$Pile = [0 => $env];
@@ -4993,7 +4992,7 @@  discard block
 block discarded – undo
4993 4992
 	}
4994 4993
 	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4995 4994
 
4996
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4995
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>';
4997 4996
 }
4998 4997
 
4999 4998
 /**
@@ -5019,10 +5018,10 @@  discard block
 block discarded – undo
5019 5018
 function wrap($texte, $wrap) {
5020 5019
 	$balises = extraire_balises($wrap);
5021 5020
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5022
-		$texte = $wrap . $texte;
5021
+		$texte = $wrap.$texte;
5023 5022
 		$regs = array_reverse($regs[1]);
5024
-		$wrap = '</' . implode('></', $regs) . '>';
5025
-		$texte = $texte . $wrap;
5023
+		$wrap = '</'.implode('></', $regs).'>';
5024
+		$texte = $texte.$wrap;
5026 5025
 	}
5027 5026
 
5028 5027
 	return $texte;
@@ -5053,7 +5052,7 @@  discard block
 block discarded – undo
5053 5052
 
5054 5053
 	// caster $u en array si besoin
5055 5054
 	if (is_object($u)) {
5056
-		$u = (array)$u;
5055
+		$u = (array) $u;
5057 5056
 	}
5058 5057
 
5059 5058
 	if (is_array($u)) {
@@ -5075,7 +5074,7 @@  discard block
 block discarded – undo
5075 5074
 		// sinon on passe a la ligne et on indente
5076 5075
 		$i_str = str_pad('', $indent, ' ');
5077 5076
 		foreach ($u as $k => $v) {
5078
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5077
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
5079 5078
 		}
5080 5079
 
5081 5080
 		return $out;
@@ -5129,7 +5128,7 @@  discard block
 block discarded – undo
5129 5128
  * @return string
5130 5129
  */
5131 5130
 function objet_icone($objet, $taille = 24, $class = '') {
5132
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5131
+	$icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png';
5133 5132
 	$icone = chemin_image($icone);
5134 5133
 	$balise_img = charger_filtre('balise_img');
5135 5134
 
@@ -5155,7 +5154,7 @@  discard block
 block discarded – undo
5155 5154
  */
5156 5155
 function objet_T($objet, $chaine, $args = [], $options = []) {
5157 5156
 	$chaine = explode(':', $chaine);
5158
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5157
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) {
5159 5158
 		return $t;
5160 5159
 	}
5161 5160
 	$chaine = implode(':', $chaine);
@@ -5221,7 +5220,7 @@  discard block
 block discarded – undo
5221 5220
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5222 5221
 
5223 5222
 	// calculer le nom de la css
5224
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5223
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
5225 5224
 	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5226 5225
 	$contexte_implicite = calculer_contexte_implicite();
5227 5226
 
@@ -5229,14 +5228,14 @@  discard block
 block discarded – undo
5229 5228
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5230 5229
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5231 5230
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5232
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5231
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
5233 5232
 	}
5234 5233
 	else {
5235 5234
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5236 5235
 		ksort($contexte);
5237
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5236
+		$hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect);
5238 5237
 	}
5239
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5238
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
5240 5239
 
5241 5240
 	// mettre a jour le fichier si il n'existe pas
5242 5241
 	// ou trop ancien
@@ -5244,8 +5243,8 @@  discard block
 block discarded – undo
5244 5243
 	// et recopie sur le fichier cible uniquement si il change
5245 5244
 	if (
5246 5245
 		!file_exists($filename)
5247
-		or !file_exists($filename . '.last')
5248
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5246
+		or !file_exists($filename.'.last')
5247
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified'])
5249 5248
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5250 5249
 	) {
5251 5250
 		$contenu = $cache['texte'];
@@ -5266,10 +5265,10 @@  discard block
 block discarded – undo
5266 5265
 			}
5267 5266
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5268 5267
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5269
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5268
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
5270 5269
 		}
5271 5270
 		// et ecrire le fichier si il change
5272
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5271
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
5273 5272
 	}
5274 5273
 
5275 5274
 	return timestamp($filename);
@@ -5495,7 +5494,7 @@  discard block
 block discarded – undo
5495 5494
 	if ($e > 0 and strlen($mid) > 8) {
5496 5495
 		$mid = '***...***';
5497 5496
 	}
5498
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5497
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5499 5498
 }
5500 5499
 
5501 5500
 
@@ -5557,7 +5556,7 @@  discard block
 block discarded – undo
5557 5556
 		case 'id':
5558 5557
 		case 'anchor':
5559 5558
 			if (preg_match(',^\d,', $texte)) {
5560
-				$texte = substr($type, 0, 1) . $texte;
5559
+				$texte = substr($type, 0, 1).$texte;
5561 5560
 			}
5562 5561
 	}
5563 5562
 
@@ -5567,9 +5566,9 @@  discard block
 block discarded – undo
5567 5566
 
5568 5567
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5569 5568
 		if (preg_match(',^\d,', $texte)) {
5570
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5569
+			$texte = ($type ? substr($type, 0, 1) : 's').$texte;
5571 5570
 		}
5572
-		$texte .= $separateur . md5($original);
5571
+		$texte .= $separateur.md5($original);
5573 5572
 		$texte = substr($texte, 0, $longueur_mini);
5574 5573
 	}
5575 5574
 
Please login to merge, or discard this patch.