Completed
Push — master ( 05618b...519300 )
by cam
01:10
created
ecrire/public/aiguiller.php 1 patch
Indentation   +289 added lines, -289 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,172 +178,172 @@  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 ? $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 ? $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 = $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 = $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
-				$retour .= inclure_balise_dynamique(balise_formulaire__dyn($form, ...$args), false);
335
-				// on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
336
-				// sans cela le formulaire n'est pas actif apres le hit ajax
337
-				// la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
338
-				$retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
339
-				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
+                $retour .= inclure_balise_dynamique(balise_formulaire__dyn($form, ...$args), false);
335
+                // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
336
+                // sans cela le formulaire n'est pas actif apres le hit ajax
337
+                // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
338
+                $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
339
+                ajax_retour($retour, false);
340 340
 
341
-				return true; // on a fini le hit
342
-			}
343
-		}
344
-		// restaurer la lang en cours
345
-		changer_langue($old_lang);
346
-	}
341
+                return true; // on a fini le hit
342
+            }
343
+        }
344
+        // restaurer la lang en cours
345
+        changer_langue($old_lang);
346
+    }
347 347
 
348
-	return false; // le hit peut continuer normalement
348
+    return false; // le hit peut continuer normalement
349 349
 }
Please login to merge, or discard this patch.
ecrire/public/fonctions.php 1 patch
Indentation   +299 added lines, -299 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 
@@ -52,75 +52,75 @@  discard block
 block discarded – undo
52 52
  *     Introduction calculée
53 53
  **/
54 54
 function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) {
55
-	// Si un descriptif est envoye, on l'utilise directement
56
-	if (strlen($descriptif)) {
57
-		return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect);
58
-	}
59
-
60
-	// De preference ce qui est marque <intro>...</intro>
61
-	$intro = '';
62
-	$texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules
63
-	while ($fin = strpos($texte, '</intro>')) {
64
-		$zone = substr($texte, 0, $fin);
65
-		$texte = substr($texte, $fin + strlen('</intro>'));
66
-		if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') {
67
-			$zone = substr($zone, $deb + 7);
68
-		}
69
-		$intro .= $zone;
70
-	}
71
-
72
-	// [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
-	// qui inclus raccourcis et modeles
74
-	// un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
-	// par ailleurs le nettoyage des raccourcis ne tient pas compte
76
-	// des surcharges et enrichissement de propre
77
-	// couper doit se faire apres propre
78
-	//$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
-
80
-	// Cependant pour des questions de perfs on coupe quand meme, en prenant
81
-	// large et en se mefiant des tableaux #1323
82
-
83
-	if (strlen($intro)) {
84
-		$texte = $intro;
85
-	} else {
86
-		if (
87
-			strpos("\n" . $texte, "\n|") === false
88
-			and strlen($texte) > 2.5 * $longueur
89
-		) {
90
-			if (strpos($texte, '<multi') !== false) {
91
-				$texte = extraire_multi($texte);
92
-			}
93
-			$texte = couper($texte, 2 * $longueur);
94
-		}
95
-	}
96
-
97
-	// ne pas tenir compte des notes
98
-	if ($notes = charger_fonction('notes', 'inc', true)) {
99
-		$notes('', 'empiler');
100
-	}
101
-	// Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
102
-	// dans l'introduction.
103
-	$texte = supprime_img($texte, '');
104
-	$texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect);
105
-
106
-	if ($notes) {
107
-		$notes('', 'depiler');
108
-	}
109
-
110
-	if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
111
-		$suite = _INTRODUCTION_SUITE;
112
-	}
113
-	$texte = couper($texte, $longueur, $suite);
114
-	// comme on a coupe il faut repasser la typo (on a perdu les insecables)
115
-	$texte = typo($texte, true, $connect, []);
116
-
117
-	// et reparagrapher si necessaire (coherence avec le cas descriptif)
118
-	// une introduction a tojours un <p>
119
-	if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes
120
-	$texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
-	}
122
-
123
-	return $texte;
55
+    // Si un descriptif est envoye, on l'utilise directement
56
+    if (strlen($descriptif)) {
57
+        return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect);
58
+    }
59
+
60
+    // De preference ce qui est marque <intro>...</intro>
61
+    $intro = '';
62
+    $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules
63
+    while ($fin = strpos($texte, '</intro>')) {
64
+        $zone = substr($texte, 0, $fin);
65
+        $texte = substr($texte, $fin + strlen('</intro>'));
66
+        if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') {
67
+            $zone = substr($zone, $deb + 7);
68
+        }
69
+        $intro .= $zone;
70
+    }
71
+
72
+    // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
+    // qui inclus raccourcis et modeles
74
+    // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
+    // par ailleurs le nettoyage des raccourcis ne tient pas compte
76
+    // des surcharges et enrichissement de propre
77
+    // couper doit se faire apres propre
78
+    //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
+
80
+    // Cependant pour des questions de perfs on coupe quand meme, en prenant
81
+    // large et en se mefiant des tableaux #1323
82
+
83
+    if (strlen($intro)) {
84
+        $texte = $intro;
85
+    } else {
86
+        if (
87
+            strpos("\n" . $texte, "\n|") === false
88
+            and strlen($texte) > 2.5 * $longueur
89
+        ) {
90
+            if (strpos($texte, '<multi') !== false) {
91
+                $texte = extraire_multi($texte);
92
+            }
93
+            $texte = couper($texte, 2 * $longueur);
94
+        }
95
+    }
96
+
97
+    // ne pas tenir compte des notes
98
+    if ($notes = charger_fonction('notes', 'inc', true)) {
99
+        $notes('', 'empiler');
100
+    }
101
+    // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
102
+    // dans l'introduction.
103
+    $texte = supprime_img($texte, '');
104
+    $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect);
105
+
106
+    if ($notes) {
107
+        $notes('', 'depiler');
108
+    }
109
+
110
+    if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
111
+        $suite = _INTRODUCTION_SUITE;
112
+    }
113
+    $texte = couper($texte, $longueur, $suite);
114
+    // comme on a coupe il faut repasser la typo (on a perdu les insecables)
115
+    $texte = typo($texte, true, $connect, []);
116
+
117
+    // et reparagrapher si necessaire (coherence avec le cas descriptif)
118
+    // une introduction a tojours un <p>
119
+    if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes
120
+    $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
+    }
122
+
123
+    return $texte;
124 124
 }
125 125
 
126 126
 
@@ -155,73 +155,73 @@  discard block
 block discarded – undo
155 155
  *     Code HTML de la pagination
156 156
  **/
157 157
 function filtre_pagination_dist(
158
-	$total,
159
-	$nom,
160
-	$position,
161
-	$pas,
162
-	$liste = true,
163
-	$modele = '',
164
-	string $connect = '',
165
-	$env = []
158
+    $total,
159
+    $nom,
160
+    $position,
161
+    $pas,
162
+    $liste = true,
163
+    $modele = '',
164
+    string $connect = '',
165
+    $env = []
166 166
 ) {
167
-	static $ancres = [];
168
-	if ($pas < 1) {
169
-		return '';
170
-	}
171
-	$ancre = 'pagination' . $nom; // #pagination_articles
172
-	$debut = 'debut' . $nom; // 'debut_articles'
173
-
174
-	// n'afficher l'ancre qu'une fois
175
-	if (!isset($ancres[$ancre])) {
176
-		$bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
-	} else {
178
-		$bloc_ancre = '';
179
-	}
180
-	// liste = false : on ne veut que l'ancre
181
-	if (!$liste) {
182
-		return $ancres[$ancre];
183
-	}
184
-
185
-	$self = (empty($env['self']) ? self() : $env['self']);
186
-	$pagination = [
187
-		'debut' => $debut,
188
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
-		'total' => $total,
190
-		'position' => intval($position),
191
-		'pas' => $pas,
192
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
-		'page_courante' => floor(intval($position) / $pas) + 1,
194
-		'ancre' => $ancre,
195
-		'bloc_ancre' => $bloc_ancre
196
-	];
197
-	if (is_array($env)) {
198
-		$pagination = array_merge($env, $pagination);
199
-	}
200
-
201
-	// Pas de pagination
202
-	if ($pagination['nombre_pages'] <= 1) {
203
-		return '';
204
-	}
205
-
206
-	if ($modele) {
207
-		$pagination['type_pagination'] = $modele;
208
-		if (trouver_fond('pagination_' . $modele, 'modeles')) {
209
-			$modele = '_' . $modele;
210
-		}
211
-		else {
212
-			$modele = '';
213
-		}
214
-	}
215
-
216
-	if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) {
217
-		define('_PAGINATION_NOMBRE_LIENS_MAX', 10);
218
-	}
219
-	if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) {
220
-		define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5);
221
-	}
222
-
223
-
224
-	return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect);
167
+    static $ancres = [];
168
+    if ($pas < 1) {
169
+        return '';
170
+    }
171
+    $ancre = 'pagination' . $nom; // #pagination_articles
172
+    $debut = 'debut' . $nom; // 'debut_articles'
173
+
174
+    // n'afficher l'ancre qu'une fois
175
+    if (!isset($ancres[$ancre])) {
176
+        $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
+    } else {
178
+        $bloc_ancre = '';
179
+    }
180
+    // liste = false : on ne veut que l'ancre
181
+    if (!$liste) {
182
+        return $ancres[$ancre];
183
+    }
184
+
185
+    $self = (empty($env['self']) ? self() : $env['self']);
186
+    $pagination = [
187
+        'debut' => $debut,
188
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
+        'total' => $total,
190
+        'position' => intval($position),
191
+        'pas' => $pas,
192
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
+        'page_courante' => floor(intval($position) / $pas) + 1,
194
+        'ancre' => $ancre,
195
+        'bloc_ancre' => $bloc_ancre
196
+    ];
197
+    if (is_array($env)) {
198
+        $pagination = array_merge($env, $pagination);
199
+    }
200
+
201
+    // Pas de pagination
202
+    if ($pagination['nombre_pages'] <= 1) {
203
+        return '';
204
+    }
205
+
206
+    if ($modele) {
207
+        $pagination['type_pagination'] = $modele;
208
+        if (trouver_fond('pagination_' . $modele, 'modeles')) {
209
+            $modele = '_' . $modele;
210
+        }
211
+        else {
212
+            $modele = '';
213
+        }
214
+    }
215
+
216
+    if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) {
217
+        define('_PAGINATION_NOMBRE_LIENS_MAX', 10);
218
+    }
219
+    if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) {
220
+        define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5);
221
+    }
222
+
223
+
224
+    return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect);
225 225
 }
226 226
 
227 227
 
@@ -240,44 +240,44 @@  discard block
 block discarded – undo
240 240
  *     Liste (première page, dernière page).
241 241
  **/
242 242
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
243
-	if ($max <= 0 or $max >= $nombre) {
244
-		return [1, $nombre];
245
-	}
246
-	if ($max <= 1) {
247
-		return [$courante, $courante];
248
-	}
249
-
250
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
251
-	$derniere = min($nombre, $premiere + $max - 2);
252
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
253
-
254
-	return [$premiere, $derniere];
243
+    if ($max <= 0 or $max >= $nombre) {
244
+        return [1, $nombre];
245
+    }
246
+    if ($max <= 1) {
247
+        return [$courante, $courante];
248
+    }
249
+
250
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
251
+    $derniere = min($nombre, $premiere + $max - 2);
252
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
253
+
254
+    return [$premiere, $derniere];
255 255
 }
256 256
 
257 257
 function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) {
258
-	if ($numero_page === 'tous') {
259
-		return '&#8734;';
260
-	}
261
-	if ($numero_page === 'prev') {
262
-		return '&lt;';
263
-	}
264
-	if ($numero_page === 'next') {
265
-		return '&gt;';
266
-	}
267
-
268
-	switch ($type_pagination) {
269
-		case 'resultats':
270
-			return $rang_item + 1; // 1 11 21 31...
271
-		case 'naturel':
272
-			return $rang_item ?: 1; // 1 10 20 30...
273
-		case 'rang':
274
-			return $rang_item; // 0 10 20 30...
275
-
276
-		case 'page':
277
-		case 'prive':
278
-		default:
279
-			return $numero_page; // 1 2 3 4 5...
280
-	}
258
+    if ($numero_page === 'tous') {
259
+        return '&#8734;';
260
+    }
261
+    if ($numero_page === 'prev') {
262
+        return '&lt;';
263
+    }
264
+    if ($numero_page === 'next') {
265
+        return '&gt;';
266
+    }
267
+
268
+    switch ($type_pagination) {
269
+        case 'resultats':
270
+            return $rang_item + 1; // 1 11 21 31...
271
+        case 'naturel':
272
+            return $rang_item ?: 1; // 1 10 20 30...
273
+        case 'rang':
274
+            return $rang_item; // 0 10 20 30...
275
+
276
+        case 'page':
277
+        case 'prive':
278
+        default:
279
+            return $numero_page; // 1 2 3 4 5...
280
+    }
281 281
 }
282 282
 
283 283
 /**
@@ -290,15 +290,15 @@  discard block
 block discarded – undo
290 290
  **/
291 291
 function lister_objets_avec_logos($type) {
292 292
 
293
-	$objet = objet_type($type);
294
-	$ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet));
295
-	if ($ids) {
296
-		$ids = array_column($ids, 'id_objet');
297
-		return implode(',', $ids);
298
-	}
299
-	else {
300
-		return '0';
301
-	}
293
+    $objet = objet_type($type);
294
+    $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet));
295
+    if ($ids) {
296
+        $ids = array_column($ids, 'id_objet');
297
+        return implode(',', $ids);
298
+    }
299
+    else {
300
+        return '0';
301
+    }
302 302
 }
303 303
 
304 304
 
@@ -314,14 +314,14 @@  discard block
 block discarded – undo
314 314
  *     Code HTML des notes
315 315
  **/
316 316
 function calculer_notes() {
317
-	$r = '';
318
-	if ($notes = charger_fonction('notes', 'inc', true)) {
319
-		$r = $notes([]);
320
-		$notes('', 'depiler');
321
-		$notes('', 'empiler');
322
-	}
323
-
324
-	return $r;
317
+    $r = '';
318
+    if ($notes = charger_fonction('notes', 'inc', true)) {
319
+        $r = $notes([]);
320
+        $notes('', 'depiler');
321
+        $notes('', 'empiler');
322
+    }
323
+
324
+    return $r;
325 325
 }
326 326
 
327 327
 
@@ -338,10 +338,10 @@  discard block
 block discarded – undo
338 338
  * @return string
339 339
  */
340 340
 function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) {
341
-	$res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
342
-	$res = array_column($res, 'rang_lien', $objet_source);
341
+    $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
342
+    $res = array_column($res, 'rang_lien', $objet_source);
343 343
 
344
-	return ($res[$ids] ?? '');
344
+    return ($res[$ids] ?? '');
345 345
 }
346 346
 
347 347
 
@@ -358,19 +358,19 @@  discard block
 block discarded – undo
358 358
  * @private
359 359
  */
360 360
 function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) {
361
-	static $liens = [];
362
-	if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
363
-		include_spip('action/editer_liens');
364
-		// quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
365
-		if ($objet_lien == $objet and $objet_lien !== $objet_source) {
366
-			$res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']);
367
-		} else {
368
-			$res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]);
369
-		}
370
-
371
-		$liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
372
-	}
373
-	return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
361
+    static $liens = [];
362
+    if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
363
+        include_spip('action/editer_liens');
364
+        // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
365
+        if ($objet_lien == $objet and $objet_lien !== $objet_source) {
366
+            $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']);
367
+        } else {
368
+            $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]);
369
+        }
370
+
371
+        $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
372
+    }
373
+    return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
374 374
 }
375 375
 
376 376
 /**
@@ -384,24 +384,24 @@  discard block
 block discarded – undo
384 384
  * @return int|string
385 385
  */
386 386
 function calculer_rang_smart($titre, $objet_source, $id, $env) {
387
-	// Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
388
-	// permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
389
-	if (
390
-		isset($env['form']) and $env['form']
391
-		and isset($env['_objet_lien']) and $env['_objet_lien']
392
-		and (function_exists('lien_triables') or include_spip('action/editer_liens'))
393
-		and $r = objet_associable($env['_objet_lien'])
394
-		and [$p, $table_lien] = $r
395
-		and lien_triables($table_lien)
396
-		and isset($env['objet']) and $env['objet']
397
-		and isset($env['id_objet']) and $env['id_objet']
398
-		and $objet_source
399
-		and $id = intval($id)
400
-	) {
401
-		$rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
402
-		return ($rang ?: '');
403
-	}
404
-	return recuperer_numero($titre);
387
+    // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
388
+    // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
389
+    if (
390
+        isset($env['form']) and $env['form']
391
+        and isset($env['_objet_lien']) and $env['_objet_lien']
392
+        and (function_exists('lien_triables') or include_spip('action/editer_liens'))
393
+        and $r = objet_associable($env['_objet_lien'])
394
+        and [$p, $table_lien] = $r
395
+        and lien_triables($table_lien)
396
+        and isset($env['objet']) and $env['objet']
397
+        and isset($env['id_objet']) and $env['id_objet']
398
+        and $objet_source
399
+        and $id = intval($id)
400
+    ) {
401
+        $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
402
+        return ($rang ?: '');
403
+    }
404
+    return recuperer_numero($titre);
405 405
 }
406 406
 
407 407
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
  * @return string
418 418
  */
419 419
 function tri_protege_champ($t) {
420
-	return preg_replace(',[^\s\w.+\[\]],', '', $t);
420
+    return preg_replace(',[^\s\w.+\[\]],', '', $t);
421 421
 }
422 422
 
423 423
 /**
@@ -430,43 +430,43 @@  discard block
 block discarded – undo
430 430
  * @return string
431 431
  */
432 432
 function tri_champ_order($t, $from = null, $senstri = '') {
433
-	if (strncmp($t, 'multi ', 6) == 0) {
434
-		return 'multi';
435
-	}
436
-
437
-	$champ = $t;
438
-
439
-	$prefixe = '';
440
-	foreach (['num ', 'sinum '] as $p) {
441
-		if (strpos($t, $p) === 0) {
442
-			$champ = substr($t, strlen($p));
443
-			$prefixe = $p;
444
-		}
445
-	}
446
-
447
-	// enlever les autres espaces non evacues par tri_protege_champ
448
-	$champ = preg_replace(',\s,', '', $champ);
449
-
450
-	if (is_array($from)) {
451
-		$trouver_table = charger_fonction('trouver_table', 'base');
452
-		foreach ($from as $idt => $table_sql) {
453
-			if (
454
-				$desc = $trouver_table($table_sql)
455
-				and isset($desc['field'][$champ])
456
-			) {
457
-				$champ = "$idt.$champ";
458
-				break;
459
-			}
460
-		}
461
-	}
462
-	switch ($prefixe) {
463
-		case 'num ':
464
-			return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}";
465
-		case 'sinum ':
466
-			return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}";
467
-		default:
468
-			return $champ . $senstri;
469
-	}
433
+    if (strncmp($t, 'multi ', 6) == 0) {
434
+        return 'multi';
435
+    }
436
+
437
+    $champ = $t;
438
+
439
+    $prefixe = '';
440
+    foreach (['num ', 'sinum '] as $p) {
441
+        if (strpos($t, $p) === 0) {
442
+            $champ = substr($t, strlen($p));
443
+            $prefixe = $p;
444
+        }
445
+    }
446
+
447
+    // enlever les autres espaces non evacues par tri_protege_champ
448
+    $champ = preg_replace(',\s,', '', $champ);
449
+
450
+    if (is_array($from)) {
451
+        $trouver_table = charger_fonction('trouver_table', 'base');
452
+        foreach ($from as $idt => $table_sql) {
453
+            if (
454
+                $desc = $trouver_table($table_sql)
455
+                and isset($desc['field'][$champ])
456
+            ) {
457
+                $champ = "$idt.$champ";
458
+                break;
459
+            }
460
+        }
461
+    }
462
+    switch ($prefixe) {
463
+        case 'num ':
464
+            return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}";
465
+        case 'sinum ':
466
+            return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}";
467
+        default:
468
+            return $champ . $senstri;
469
+    }
470 470
 }
471 471
 
472 472
 /**
@@ -480,18 +480,18 @@  discard block
 block discarded – undo
480 480
  * @return string
481 481
  */
482 482
 function tri_champ_select($t) {
483
-	if (strncmp($t, 'multi ', 6) == 0) {
484
-		$t = substr($t, 6);
485
-		$t = preg_replace(',\s,', '', $t);
486
-		$t = sql_multi($t, $GLOBALS['spip_lang']);
487
-
488
-		return $t;
489
-	}
490
-	if (trim($t) == 'hasard') {
491
-		return 'rand() AS hasard';
492
-	}
493
-
494
-	return "''";
483
+    if (strncmp($t, 'multi ', 6) == 0) {
484
+        $t = substr($t, 6);
485
+        $t = preg_replace(',\s,', '', $t);
486
+        $t = sql_multi($t, $GLOBALS['spip_lang']);
487
+
488
+        return $t;
489
+    }
490
+    if (trim($t) == 'hasard') {
491
+        return 'rand() AS hasard';
492
+    }
493
+
494
+    return "''";
495 495
 }
496 496
 
497 497
 /**
@@ -503,16 +503,16 @@  discard block
 block discarded – undo
503 503
  * @return string
504 504
  */
505 505
 function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') {
506
-	if (!is_array($valeurs)) {
507
-		return '';
508
-	}
509
-	$f = sql_serveur('quote', $serveur, true);
510
-	if (!is_string($f) or !$f) {
511
-		return '';
512
-	}
513
-	$valeurs = implode(',', array_map($f, array_unique($valeurs)));
514
-
515
-	return $valeurs;
506
+    if (!is_array($valeurs)) {
507
+        return '';
508
+    }
509
+    $f = sql_serveur('quote', $serveur, true);
510
+    if (!is_string($f) or !$f) {
511
+        return '';
512
+    }
513
+    $valeurs = implode(',', array_map($f, array_unique($valeurs)));
514
+
515
+    return $valeurs;
516 516
 }
517 517
 
518 518
 /**
@@ -535,21 +535,21 @@  discard block
 block discarded – undo
535 535
  *     Valeur $defaut sinon.
536 536
  **/
537 537
 function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') {
538
-	// Si c'est un filtre d'image, on utilise image_filtrer()
539
-	// Attention : les 2 premiers arguments sont inversés dans ce cas
540
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
541
-		include_spip('inc/filtres_images_lib_mini');
542
-		$args[1] = $args[0];
543
-		$args[0] = $filtre;
544
-		return image_graver(image_filtrer($args));
545
-	}
546
-
547
-	$f = chercher_filtre($filtre);
548
-	if (!$f) {
549
-		return $defaut;
550
-	}
551
-	array_shift($args); // enlever $arg
552
-	array_shift($args); // enlever $filtre
553
-	array_unshift($args, $arg); // remettre $arg
554
-	return $f(...$args);
538
+    // Si c'est un filtre d'image, on utilise image_filtrer()
539
+    // Attention : les 2 premiers arguments sont inversés dans ce cas
540
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
541
+        include_spip('inc/filtres_images_lib_mini');
542
+        $args[1] = $args[0];
543
+        $args[0] = $filtre;
544
+        return image_graver(image_filtrer($args));
545
+    }
546
+
547
+    $f = chercher_filtre($filtre);
548
+    if (!$f) {
549
+        return $defaut;
550
+    }
551
+    array_shift($args); // enlever $arg
552
+    array_shift($args); // enlever $filtre
553
+    array_unshift($args, $arg); // remettre $arg
554
+    return $f(...$args);
555 555
 }
Please login to merge, or discard this patch.
ecrire/inc/queue.php 1 patch
Indentation   +524 added lines, -524 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Queue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 define('_JQ_SCHEDULED', 1);
@@ -50,103 +50,103 @@  discard block
 block discarded – undo
50 50
  *  id of job
51 51
  */
52 52
 function queue_add_job(
53
-	$function,
54
-	$description,
55
-	$arguments = [],
56
-	$file = '',
57
-	$no_duplicate = false,
58
-	$time = 0,
59
-	$priority = 0
53
+    $function,
54
+    $description,
55
+    $arguments = [],
56
+    $file = '',
57
+    $no_duplicate = false,
58
+    $time = 0,
59
+    $priority = 0
60 60
 ) {
61
-	include_spip('base/abstract_sql');
62
-
63
-	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
-	if (defined('_GENIE_SYNDIC_NOW')) {
65
-		$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
-	}
67
-
68
-	// serialiser les arguments
69
-	$arguments = serialize($arguments);
70
-	$md5args = md5($arguments);
71
-
72
-	// si pas de date programee, des que possible
73
-	$duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
-	if (!$time) {
75
-		$time = time();
76
-		$duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
-	}
78
-	$date = date('Y-m-d H:i:s', $time);
79
-
80
-	$set_job = [
81
-		'fonction' => $function,
82
-		'descriptif' => $description,
83
-		'args' => $arguments,
84
-		'md5args' => $md5args,
85
-		'inclure' => $file,
86
-		'priorite' => max(-10, min(10, intval($priority))),
87
-		'date' => $date,
88
-		'status' => _JQ_SCHEDULED,
89
-	];
90
-	// si option ne pas dupliquer, regarder si la fonction existe deja
91
-	// avec les memes args et file
92
-	if (
93
-		$no_duplicate
94
-		and
95
-		$id_job = sql_getfetsel(
96
-			'id_job',
97
-			'spip_jobs',
98
-			$duplicate_where =
99
-				$duplicate_where . 'fonction=' . sql_quote($function)
100
-				. (($no_duplicate === 'function_only') ? '' :
101
-			' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
-		)
103
-	) {
104
-		return $id_job;
105
-	}
106
-
107
-	$id_job = sql_insertq('spip_jobs', $set_job);
108
-	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
-	// avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
-	// doit s'effacer
111
-	if (
112
-		$no_duplicate
113
-		and
114
-		$id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
-	) {
116
-		sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
-
118
-		return $id_prev;
119
-	}
120
-
121
-	// verifier la non duplication qui peut etre problematique en cas de concurence
122
-	// il faut dans ce cas que seul le dernier ajoute se supprime !
123
-
124
-	// une option de debug pour verifier que les arguments en base sont bons
125
-	// ie cas d'un char non acceptables sur certains type de champs
126
-	// qui coupe la valeur
127
-	if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
-		if ($args !== $arguments) {
130
-			spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
-				$arguments,
132
-				true
133
-			), 'queue');
134
-		}
135
-	}
136
-
137
-	if ($id_job) {
138
-		queue_update_next_job_time($time);
139
-	}
140
-	// si la mise en file d'attente du job echoue,
141
-	// il ne faut pas perdre l'execution de la fonction
142
-	// on la lance immediatement, c'est un fallback
143
-	// sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
-	elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
-		$set_job['id_job'] = 0;
146
-		queue_start_job($set_job);
147
-	}
148
-
149
-	return $id_job;
61
+    include_spip('base/abstract_sql');
62
+
63
+    // cas pourri de ecrire/action/editer_site avec l'option reload=oui
64
+    if (defined('_GENIE_SYNDIC_NOW')) {
65
+        $arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
66
+    }
67
+
68
+    // serialiser les arguments
69
+    $arguments = serialize($arguments);
70
+    $md5args = md5($arguments);
71
+
72
+    // si pas de date programee, des que possible
73
+    $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND ';
74
+    if (!$time) {
75
+        $time = time();
76
+        $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution
77
+    }
78
+    $date = date('Y-m-d H:i:s', $time);
79
+
80
+    $set_job = [
81
+        'fonction' => $function,
82
+        'descriptif' => $description,
83
+        'args' => $arguments,
84
+        'md5args' => $md5args,
85
+        'inclure' => $file,
86
+        'priorite' => max(-10, min(10, intval($priority))),
87
+        'date' => $date,
88
+        'status' => _JQ_SCHEDULED,
89
+    ];
90
+    // si option ne pas dupliquer, regarder si la fonction existe deja
91
+    // avec les memes args et file
92
+    if (
93
+        $no_duplicate
94
+        and
95
+        $id_job = sql_getfetsel(
96
+            'id_job',
97
+            'spip_jobs',
98
+            $duplicate_where =
99
+                $duplicate_where . 'fonction=' . sql_quote($function)
100
+                . (($no_duplicate === 'function_only') ? '' :
101
+            ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file))
102
+        )
103
+    ) {
104
+        return $id_job;
105
+    }
106
+
107
+    $id_job = sql_insertq('spip_jobs', $set_job);
108
+    // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
109
+    // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
110
+    // doit s'effacer
111
+    if (
112
+        $no_duplicate
113
+        and
114
+        $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where")
115
+    ) {
116
+        sql_delete('spip_jobs', 'id_job=' . intval($id_job));
117
+
118
+        return $id_prev;
119
+    }
120
+
121
+    // verifier la non duplication qui peut etre problematique en cas de concurence
122
+    // il faut dans ce cas que seul le dernier ajoute se supprime !
123
+
124
+    // une option de debug pour verifier que les arguments en base sont bons
125
+    // ie cas d'un char non acceptables sur certains type de champs
126
+    // qui coupe la valeur
127
+    if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) {
128
+        $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job));
129
+        if ($args !== $arguments) {
130
+            spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export(
131
+                $arguments,
132
+                true
133
+            ), 'queue');
134
+        }
135
+    }
136
+
137
+    if ($id_job) {
138
+        queue_update_next_job_time($time);
139
+    }
140
+    // si la mise en file d'attente du job echoue,
141
+    // il ne faut pas perdre l'execution de la fonction
142
+    // on la lance immediatement, c'est un fallback
143
+    // sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
144
+    elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
145
+        $set_job['id_job'] = 0;
146
+        queue_start_job($set_job);
147
+    }
148
+
149
+    return $id_job;
150 150
 }
151 151
 
152 152
 /**
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
  * @return void
156 156
  */
157 157
 function queue_purger() {
158
-	include_spip('base/abstract_sql');
159
-	sql_delete('spip_jobs');
160
-	sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
-	include_spip('inc/genie');
162
-	genie_queue_watch_dist();
158
+    include_spip('base/abstract_sql');
159
+    sql_delete('spip_jobs');
160
+    sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')');
161
+    include_spip('inc/genie');
162
+    genie_queue_watch_dist();
163 163
 }
164 164
 
165 165
 /**
@@ -170,25 +170,25 @@  discard block
 block discarded – undo
170 170
  * @return int|bool
171 171
  */
172 172
 function queue_remove_job($id_job) {
173
-	include_spip('base/abstract_sql');
174
-
175
-	if (
176
-		$row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
-		and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
-	) {
179
-		queue_unlink_job($id_job);
180
-		// est-ce une tache cron qu'il faut relancer ?
181
-		if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
-			// relancer avec les nouveaux arguments de temps
183
-			include_spip('inc/genie');
184
-			// relancer avec la periode prevue
185
-			queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
-		}
187
-		queue_update_next_job_time();
188
-		return $res;
189
-	}
190
-
191
-	return false;
173
+    include_spip('base/abstract_sql');
174
+
175
+    if (
176
+        $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job))
177
+        and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job))
178
+    ) {
179
+        queue_unlink_job($id_job);
180
+        // est-ce une tache cron qu'il faut relancer ?
181
+        if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
182
+            // relancer avec les nouveaux arguments de temps
183
+            include_spip('inc/genie');
184
+            // relancer avec la periode prevue
185
+            queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
186
+        }
187
+        queue_update_next_job_time();
188
+        return $res;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 /**
@@ -201,18 +201,18 @@  discard block
 block discarded – undo
201 201
  *  ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois
202 202
  */
203 203
 function queue_link_job($id_job, $objets) {
204
-	include_spip('base/abstract_sql');
205
-
206
-	if (is_array($objets) and count($objets)) {
207
-		if (is_array(reset($objets))) {
208
-			foreach ($objets as $k => $o) {
209
-				$objets[$k]['id_job'] = $id_job;
210
-			}
211
-			sql_insertq_multi('spip_jobs_liens', $objets);
212
-		} else {
213
-			sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
214
-		}
215
-	}
204
+    include_spip('base/abstract_sql');
205
+
206
+    if (is_array($objets) and count($objets)) {
207
+        if (is_array(reset($objets))) {
208
+            foreach ($objets as $k => $o) {
209
+                $objets[$k]['id_job'] = $id_job;
210
+            }
211
+            sql_insertq_multi('spip_jobs_liens', $objets);
212
+        } else {
213
+            sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets));
214
+        }
215
+    }
216 216
 }
217 217
 
218 218
 /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
  *  resultat du sql_delete
225 225
  */
226 226
 function queue_unlink_job($id_job) {
227
-	return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
227
+    return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job));
228 228
 }
229 229
 
230 230
 /**
@@ -237,84 +237,84 @@  discard block
 block discarded – undo
237 237
  */
238 238
 function queue_start_job($row) {
239 239
 
240
-	// deserialiser les arguments
241
-	$args = unserialize($row['args']);
242
-	if ($args === false) {
243
-		spip_log('arguments job errones ' . var_export($row, true), 'queue');
244
-		$args = [];
245
-	}
246
-
247
-	$fonction = $row['fonction'];
248
-	if (strlen($inclure = trim($row['inclure']))) {
249
-		if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
250
-			$f = charger_fonction($fonction, rtrim($inclure, '/'), false);
251
-			if ($f) {
252
-				$fonction = $f;
253
-			}
254
-		} else {
255
-			include_spip($inclure);
256
-		}
257
-	}
258
-
259
-	if (!function_exists($fonction)) {
260
-		spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
261
-
262
-		return false;
263
-	}
264
-
265
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
266
-	switch (is_countable($args) ? count($args) : 0) {
267
-		case 0:
268
-			$res = $fonction();
269
-			break;
270
-		case 1:
271
-			$res = $fonction($args[0]);
272
-			break;
273
-		case 2:
274
-			$res = $fonction($args[0], $args[1]);
275
-			break;
276
-		case 3:
277
-			$res = $fonction($args[0], $args[1], $args[2]);
278
-			break;
279
-		case 4:
280
-			$res = $fonction($args[0], $args[1], $args[2], $args[3]);
281
-			break;
282
-		case 5:
283
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]);
284
-			break;
285
-		case 6:
286
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
287
-			break;
288
-		case 7:
289
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
290
-			break;
291
-		case 8:
292
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
293
-			break;
294
-		case 9:
295
-			$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
296
-			break;
297
-		case 10:
298
-			$res = $fonction(
299
-				$args[0],
300
-				$args[1],
301
-				$args[2],
302
-				$args[3],
303
-				$args[4],
304
-				$args[5],
305
-				$args[6],
306
-				$args[7],
307
-				$args[8],
308
-				$args[9]
309
-			);
310
-			break;
311
-		default:
312
-			# plus lent mais completement generique
313
-			$res = $fonction(...$args);
314
-	}
315
-	spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
316
-
317
-	return $res;
240
+    // deserialiser les arguments
241
+    $args = unserialize($row['args']);
242
+    if ($args === false) {
243
+        spip_log('arguments job errones ' . var_export($row, true), 'queue');
244
+        $args = [];
245
+    }
246
+
247
+    $fonction = $row['fonction'];
248
+    if (strlen($inclure = trim($row['inclure']))) {
249
+        if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
250
+            $f = charger_fonction($fonction, rtrim($inclure, '/'), false);
251
+            if ($f) {
252
+                $fonction = $f;
253
+            }
254
+        } else {
255
+            include_spip($inclure);
256
+        }
257
+    }
258
+
259
+    if (!function_exists($fonction)) {
260
+        spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue');
261
+
262
+        return false;
263
+    }
264
+
265
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue');
266
+    switch (is_countable($args) ? count($args) : 0) {
267
+        case 0:
268
+            $res = $fonction();
269
+            break;
270
+        case 1:
271
+            $res = $fonction($args[0]);
272
+            break;
273
+        case 2:
274
+            $res = $fonction($args[0], $args[1]);
275
+            break;
276
+        case 3:
277
+            $res = $fonction($args[0], $args[1], $args[2]);
278
+            break;
279
+        case 4:
280
+            $res = $fonction($args[0], $args[1], $args[2], $args[3]);
281
+            break;
282
+        case 5:
283
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]);
284
+            break;
285
+        case 6:
286
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
287
+            break;
288
+        case 7:
289
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]);
290
+            break;
291
+        case 8:
292
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]);
293
+            break;
294
+        case 9:
295
+            $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]);
296
+            break;
297
+        case 10:
298
+            $res = $fonction(
299
+                $args[0],
300
+                $args[1],
301
+                $args[2],
302
+                $args[3],
303
+                $args[4],
304
+                $args[5],
305
+                $args[6],
306
+                $args[7],
307
+                $args[8],
308
+                $args[9]
309
+            );
310
+            break;
311
+        default:
312
+            # plus lent mais completement generique
313
+            $res = $fonction(...$args);
314
+    }
315
+    spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue');
316
+
317
+    return $res;
318 318
 }
319 319
 
320 320
 /**
@@ -341,89 +341,89 @@  discard block
 block discarded – undo
341 341
  *     - true : une planification a été faite.
342 342
  */
343 343
 function queue_schedule($force_jobs = null) {
344
-	$time = time();
345
-	if (defined('_DEBUG_BLOCK_QUEUE')) {
346
-		spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
347
-
348
-		return;
349
-	}
350
-
351
-	// rien a faire si le prochain job est encore dans le futur
352
-	if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
353
-		spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
354
-
355
-		return;
356
-	}
357
-
358
-	include_spip('base/abstract_sql');
359
-	// on ne peut rien faire si pas de connexion SQL
360
-	if (!spip_connect()) {
361
-		return false;
362
-	}
363
-
364
-	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
365
-		$max_time = ini_get('max_execution_time') / 2;
366
-		// valeur conservatrice si on a pas reussi a lire le max_execution_time
367
-		if (!$max_time) {
368
-			$max_time = 5;
369
-		}
370
-		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
371
-	}
372
-	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
373
-
374
-	spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
375
-
376
-	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
377
-		define('_JQ_MAX_JOBS_EXECUTE', 200);
378
-	}
379
-	$nbj = 0;
380
-	// attraper les jobs
381
-	// dont la date est passee (echus en attente),
382
-	// par ordre :
383
-	//	- de priorite
384
-	//	- de date
385
-	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
386
-	// pour qu'il ne bloque pas les autres jobs en attente
387
-	if (is_array($force_jobs) and count($force_jobs)) {
388
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
389
-	} else {
390
-		$now = date('Y-m-d H:i:s', $time);
391
-		$cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
392
-	}
393
-
394
-	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
395
-	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
396
-	do {
397
-		if ($row = array_shift($res)) {
398
-			$nbj++;
399
-			// il faut un verrou, a base de sql_delete
400
-			if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
401
-				#spip_log("JQ schedule job ".$nbj." OK",'jq');
402
-				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
403
-				$row['status'] = _JQ_PENDING;
404
-				$row['date'] = date('Y-m-d H:i:s', $time);
405
-				sql_insertq('spip_jobs', $row);
406
-
407
-				// on a la main sur le job :
408
-				// l'executer
409
-				$result = queue_start_job($row);
410
-
411
-				$time = time();
412
-				queue_close_job($row, $time, $result);
413
-			}
414
-		}
415
-		spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
416
-	} while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
417
-	spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
418
-
419
-	if ($row = array_shift($res)) {
420
-		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
421
-		spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
422
-	} else {
423
-		queue_update_next_job_time();
424
-	}
425
-
426
-	return true;
344
+    $time = time();
345
+    if (defined('_DEBUG_BLOCK_QUEUE')) {
346
+        spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG);
347
+
348
+        return;
349
+    }
350
+
351
+    // rien a faire si le prochain job est encore dans le futur
352
+    if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) {
353
+        spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG);
354
+
355
+        return;
356
+    }
357
+
358
+    include_spip('base/abstract_sql');
359
+    // on ne peut rien faire si pas de connexion SQL
360
+    if (!spip_connect()) {
361
+        return false;
362
+    }
363
+
364
+    if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
365
+        $max_time = ini_get('max_execution_time') / 2;
366
+        // valeur conservatrice si on a pas reussi a lire le max_execution_time
367
+        if (!$max_time) {
368
+            $max_time = 5;
369
+        }
370
+        define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
371
+    }
372
+    $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
373
+
374
+    spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG);
375
+
376
+    if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
377
+        define('_JQ_MAX_JOBS_EXECUTE', 200);
378
+    }
379
+    $nbj = 0;
380
+    // attraper les jobs
381
+    // dont la date est passee (echus en attente),
382
+    // par ordre :
383
+    //	- de priorite
384
+    //	- de date
385
+    // lorsqu'un job cron n'a pas fini, sa priorite est descendue
386
+    // pour qu'il ne bloque pas les autres jobs en attente
387
+    if (is_array($force_jobs) and count($force_jobs)) {
388
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs);
389
+    } else {
390
+        $now = date('Y-m-d H:i:s', $time);
391
+        $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now);
392
+    }
393
+
394
+    register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
395
+    $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1));
396
+    do {
397
+        if ($row = array_shift($res)) {
398
+            $nbj++;
399
+            // il faut un verrou, a base de sql_delete
400
+            if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) {
401
+                #spip_log("JQ schedule job ".$nbj." OK",'jq');
402
+                // on reinsert dans la base aussitot avec un status=_JQ_PENDING
403
+                $row['status'] = _JQ_PENDING;
404
+                $row['date'] = date('Y-m-d H:i:s', $time);
405
+                sql_insertq('spip_jobs', $row);
406
+
407
+                // on a la main sur le job :
408
+                // l'executer
409
+                $result = queue_start_job($row);
410
+
411
+                $time = time();
412
+                queue_close_job($row, $time, $result);
413
+            }
414
+        }
415
+        spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG);
416
+    } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time);
417
+    spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG);
418
+
419
+    if ($row = array_shift($res)) {
420
+        queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
421
+        spip_log('JQ encore !', 'jq' . _LOG_DEBUG);
422
+    } else {
423
+        queue_update_next_job_time();
424
+    }
425
+
426
+    return true;
427 427
 }
428 428
 
429 429
 /**
@@ -441,21 +441,21 @@  discard block
 block discarded – undo
441 441
  * @param int $result
442 442
  */
443 443
 function queue_close_job(&$row, $time, $result = 0) {
444
-	// est-ce une tache cron qu'il faut relancer ?
445
-	if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
446
-		// relancer avec les nouveaux arguments de temps
447
-		include_spip('inc/genie');
448
-		if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
449
-		queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
450
-		} else // relancer avec la periode prevue
451
-		{
452
-			queue_genie_replan_job($row['fonction'], $periode, $time);
453
-		}
454
-	}
455
-	// purger ses liens eventuels avec des objets
456
-	sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
457
-	// supprimer le job fini
458
-	sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
444
+    // est-ce une tache cron qu'il faut relancer ?
445
+    if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
446
+        // relancer avec les nouveaux arguments de temps
447
+        include_spip('inc/genie');
448
+        if ($result < 0) { // relancer tout de suite, mais en baissant la priorite
449
+        queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
450
+        } else // relancer avec la periode prevue
451
+        {
452
+            queue_genie_replan_job($row['fonction'], $periode, $time);
453
+        }
454
+    }
455
+    // purger ses liens eventuels avec des objets
456
+    sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job']));
457
+    // supprimer le job fini
458
+    sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']));
459 459
 }
460 460
 
461 461
 /**
@@ -465,10 +465,10 @@  discard block
 block discarded – undo
465 465
  * @uses queue_update_next_job_time()
466 466
  */
467 467
 function queue_error_handler() {
468
-	// se remettre dans le bon dossier, car Apache le change parfois (toujours?)
469
-	chdir(_ROOT_CWD);
468
+    // se remettre dans le bon dossier, car Apache le change parfois (toujours?)
469
+    chdir(_ROOT_CWD);
470 470
 
471
-	queue_update_next_job_time();
471
+    queue_update_next_job_time();
472 472
 }
473 473
 
474 474
 
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
  *     Périodicité de la tâche en secondes, si tâche périodique, sinon false.
486 486
  */
487 487
 function queue_is_cron_job($function, $inclure) {
488
-	static $taches = null;
489
-	if (strncmp($inclure, 'genie/', 6) == 0) {
490
-		if (is_null($taches)) {
491
-			include_spip('inc/genie');
492
-			$taches = taches_generales();
493
-		}
494
-		if (isset($taches[$function])) {
495
-			return $taches[$function];
496
-		}
497
-	}
498
-
499
-	return false;
488
+    static $taches = null;
489
+    if (strncmp($inclure, 'genie/', 6) == 0) {
490
+        if (is_null($taches)) {
491
+            include_spip('inc/genie');
492
+            $taches = taches_generales();
493
+        }
494
+        if (isset($taches[$function])) {
495
+            return $taches[$function];
496
+        }
497
+    }
498
+
499
+    return false;
500 500
 }
501 501
 
502 502
 /**
@@ -510,62 +510,62 @@  discard block
 block discarded – undo
510 510
  *  temps de la tache ajoutee ou 0 pour ASAP
511 511
  */
512 512
 function queue_update_next_job_time($next_time = null) {
513
-	static $nb_jobs_scheduled = null;
514
-	static $deja_la = false;
515
-	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
516
-	static $next = null;
517
-	// queue_close_job peut etre reentrant ici
518
-	if ($deja_la) {
519
-		return;
520
-	}
521
-	$deja_la = true;
522
-
523
-	include_spip('base/abstract_sql');
524
-	$time = time();
525
-
526
-	// traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
527
-	// pour cause de timeout ou autre erreur fatale
528
-	$res = sql_allfetsel(
529
-		'*',
530
-		'spip_jobs',
531
-		'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
532
-	);
533
-	if (is_array($res)) {
534
-		foreach ($res as $row) {
535
-			queue_close_job($row, $time);
536
-			spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
537
-		}
538
-	}
539
-
540
-	// chercher la date du prochain job si pas connu
541
-	if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
542
-		$date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
543
-		$next = strtotime($date);
544
-	}
545
-	if (!is_null($next_time)) {
546
-		if (is_null($next) or $next > $next_time) {
547
-			$next = $next_time;
548
-		}
549
-	}
550
-
551
-	if ($next) {
552
-		if (is_null($nb_jobs_scheduled)) {
553
-			$nb_jobs_scheduled = sql_countsel(
554
-				'spip_jobs',
555
-				'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
556
-			);
557
-		} elseif ($next <= $time) {
558
-			$nb_jobs_scheduled++;
559
-		}
560
-		// si trop de jobs en attente, on force la purge en fin de hit
561
-		// pour assurer le coup
562
-		if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
563
-			define('_DIRECT_CRON_FORCE', true);
564
-		}
565
-	}
566
-
567
-	queue_set_next_job_time($next);
568
-	$deja_la = false;
513
+    static $nb_jobs_scheduled = null;
514
+    static $deja_la = false;
515
+    // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
516
+    static $next = null;
517
+    // queue_close_job peut etre reentrant ici
518
+    if ($deja_la) {
519
+        return;
520
+    }
521
+    $deja_la = true;
522
+
523
+    include_spip('base/abstract_sql');
524
+    $time = time();
525
+
526
+    // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
527
+    // pour cause de timeout ou autre erreur fatale
528
+    $res = sql_allfetsel(
529
+        '*',
530
+        'spip_jobs',
531
+        'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180))
532
+    );
533
+    if (is_array($res)) {
534
+        foreach ($res as $row) {
535
+            queue_close_job($row, $time);
536
+            spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR);
537
+        }
538
+    }
539
+
540
+    // chercher la date du prochain job si pas connu
541
+    if (is_null($next) or is_null(queue_sleep_time_to_next_job())) {
542
+        $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1');
543
+        $next = strtotime($date);
544
+    }
545
+    if (!is_null($next_time)) {
546
+        if (is_null($next) or $next > $next_time) {
547
+            $next = $next_time;
548
+        }
549
+    }
550
+
551
+    if ($next) {
552
+        if (is_null($nb_jobs_scheduled)) {
553
+            $nb_jobs_scheduled = sql_countsel(
554
+                'spip_jobs',
555
+                'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time))
556
+            );
557
+        } elseif ($next <= $time) {
558
+            $nb_jobs_scheduled++;
559
+        }
560
+        // si trop de jobs en attente, on force la purge en fin de hit
561
+        // pour assurer le coup
562
+        if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) {
563
+            define('_DIRECT_CRON_FORCE', true);
564
+        }
565
+    }
566
+
567
+    queue_set_next_job_time($next);
568
+    $deja_la = false;
569 569
 }
570 570
 
571 571
 
@@ -576,26 +576,26 @@  discard block
 block discarded – undo
576 576
  */
577 577
 function queue_set_next_job_time($next) {
578 578
 
579
-	// utiliser le temps courant reel plutot que temps de la requete ici
580
-	$time = time();
581
-
582
-	// toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
583
-	// et ne mettre a jour que si il y a un interet a le faire
584
-	// permet ausis d'initialiser le nom de fichier a coup sur
585
-	$curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
586
-	if (
587
-		($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
588
-		or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
589
-	) {
590
-		if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
591
-			cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
592
-		} else {
593
-			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
594
-		}
595
-		queue_sleep_time_to_next_job($next);
596
-	}
597
-
598
-	return queue_sleep_time_to_next_job();
579
+    // utiliser le temps courant reel plutot que temps de la requete ici
580
+    $time = time();
581
+
582
+    // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
583
+    // et ne mettre a jour que si il y a un interet a le faire
584
+    // permet ausis d'initialiser le nom de fichier a coup sur
585
+    $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
586
+    if (
587
+        ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
588
+        or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
589
+    ) {
590
+        if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
591
+            cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
592
+        } else {
593
+            ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
594
+        }
595
+        queue_sleep_time_to_next_job($next);
596
+    }
597
+
598
+    return queue_sleep_time_to_next_job();
599 599
 }
600 600
 
601 601
 /**
@@ -612,60 +612,60 @@  discard block
 block discarded – undo
612 612
  * @return string
613 613
  */
614 614
 function queue_affichage_cron() {
615
-	$texte = '';
616
-
617
-	$time_to_next = queue_sleep_time_to_next_job();
618
-	// rien a faire si le prochain job est encore dans le futur
619
-	if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
620
-		return $texte;
621
-	}
622
-
623
-	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
624
-	if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
625
-		return $texte;
626
-	}
627
-
628
-	@touch($lock);
629
-
630
-	// il y a des taches en attentes
631
-	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
632
-	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
633
-	$urgent = false;
634
-	if ($time_to_next < -300) {
635
-		$urgent = true;
636
-	}
637
-
638
-	$url_cron = generer_url_action('cron', '', false, true);
639
-
640
-	if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
641
-		if (queue_lancer_url_http_async($url_cron) and !$urgent) {
642
-			return $texte;
643
-		}
644
-	}
645
-
646
-	// si deja force, on retourne sans rien
647
-	if (defined('_DIRECT_CRON_FORCE')) {
648
-		return $texte;
649
-	}
650
-
651
-	// si c'est un bot
652
-	// inutile de faire un appel par image background,
653
-	// on force un appel direct en fin de hit
654
-	if ((defined('_IS_BOT') and _IS_BOT)) {
655
-		define('_DIRECT_CRON_FORCE', true);
656
-
657
-		return $texte;
658
-	}
659
-
660
-	if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
661
-		// en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
662
-		$url_cron = generer_url_action('cron');
663
-		$texte = '<!-- SPIP-CRON -->'
664
-		  . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
665
-		  . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
666
-	}
667
-
668
-	return $texte;
615
+    $texte = '';
616
+
617
+    $time_to_next = queue_sleep_time_to_next_job();
618
+    // rien a faire si le prochain job est encore dans le futur
619
+    if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) {
620
+        return $texte;
621
+    }
622
+
623
+    // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
624
+    if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) {
625
+        return $texte;
626
+    }
627
+
628
+    @touch($lock);
629
+
630
+    // il y a des taches en attentes
631
+    // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
632
+    // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
633
+    $urgent = false;
634
+    if ($time_to_next < -300) {
635
+        $urgent = true;
636
+    }
637
+
638
+    $url_cron = generer_url_action('cron', '', false, true);
639
+
640
+    if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) {
641
+        if (queue_lancer_url_http_async($url_cron) and !$urgent) {
642
+            return $texte;
643
+        }
644
+    }
645
+
646
+    // si deja force, on retourne sans rien
647
+    if (defined('_DIRECT_CRON_FORCE')) {
648
+        return $texte;
649
+    }
650
+
651
+    // si c'est un bot
652
+    // inutile de faire un appel par image background,
653
+    // on force un appel direct en fin de hit
654
+    if ((defined('_IS_BOT') and _IS_BOT)) {
655
+        define('_DIRECT_CRON_FORCE', true);
656
+
657
+        return $texte;
658
+    }
659
+
660
+    if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) {
661
+        // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS
662
+        $url_cron = generer_url_action('cron');
663
+        $texte = '<!-- SPIP-CRON -->'
664
+            . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>"
665
+            . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>";
666
+    }
667
+
668
+    return $texte;
669 669
 }
670 670
 
671 671
 /**
@@ -674,73 +674,73 @@  discard block
 block discarded – undo
674 674
  * @return bool : true si l'url a pu être appelée en asynchrone, false sinon
675 675
  */
676 676
 function queue_lancer_url_http_async($url_cron) {
677
-	// methode la plus rapide :
678
-	// Si fsockopen est possible, on lance le cron via un socket en asynchrone
679
-	// si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
680
-	// car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
681
-	// mais on renvoie false direct
682
-	if (function_exists('fsockopen')) {
683
-		$parts = parse_url($url_cron);
684
-
685
-		switch ($parts['scheme']) {
686
-			case 'https':
687
-				$scheme = 'ssl://';
688
-				$port = 443;
689
-				break;
690
-			case 'http':
691
-			default:
692
-				$scheme = '';
693
-				$port = 80;
694
-		}
695
-		$fp = @fsockopen(
696
-			$scheme . $parts['host'],
697
-			$parts['port'] ?? $port,
698
-			$errno,
699
-			$errstr,
700
-			1
701
-		);
702
-
703
-		if ($fp) {
704
-			$host_sent = $parts['host'];
705
-			if (isset($parts['port']) and $parts['port'] !== $port) {
706
-				$host_sent .= ':' . $parts['port'];
707
-			}
708
-			$timeout = 200; // ms
709
-			stream_set_timeout($fp, 0, $timeout * 1000);
710
-			$query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
711
-			$out = 'GET ' . $query . " HTTP/1.1\r\n";
712
-			$out .= 'Host: ' . $host_sent . "\r\n";
713
-			$out .= "Connection: Close\r\n\r\n";
714
-			fwrite($fp, $out);
715
-			spip_timer('read');
716
-			$t = 0;
717
-			// on lit la reponse si possible pour fermer proprement la connexion
718
-			// avec un timeout total de 200ms pour ne pas se bloquer
719
-			while (!feof($fp) and $t < $timeout) {
720
-				@fgets($fp, 1024);
721
-				$t += spip_timer('read', true);
722
-				spip_timer('read');
723
-			}
724
-			fclose($fp);
725
-			return true;
726
-		}
727
-	}
728
-	// si fsockopen n'est pas dispo on essaye cURL :
729
-	// lancer le cron par un cURL asynchrone si cURL est present
730
-	elseif (function_exists('curl_init')) {
731
-		//setting the curl parameters.
732
-		$ch = curl_init($url_cron);
733
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
734
-		// cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
735
-		curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
736
-		// valeur mini pour que la requete soit lancee
737
-		curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
738
-		// lancer
739
-		curl_exec($ch);
740
-		// fermer
741
-		curl_close($ch);
742
-		return true;
743
-	}
744
-
745
-	return false;
677
+    // methode la plus rapide :
678
+    // Si fsockopen est possible, on lance le cron via un socket en asynchrone
679
+    // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
680
+    // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
681
+    // mais on renvoie false direct
682
+    if (function_exists('fsockopen')) {
683
+        $parts = parse_url($url_cron);
684
+
685
+        switch ($parts['scheme']) {
686
+            case 'https':
687
+                $scheme = 'ssl://';
688
+                $port = 443;
689
+                break;
690
+            case 'http':
691
+            default:
692
+                $scheme = '';
693
+                $port = 80;
694
+        }
695
+        $fp = @fsockopen(
696
+            $scheme . $parts['host'],
697
+            $parts['port'] ?? $port,
698
+            $errno,
699
+            $errstr,
700
+            1
701
+        );
702
+
703
+        if ($fp) {
704
+            $host_sent = $parts['host'];
705
+            if (isset($parts['port']) and $parts['port'] !== $port) {
706
+                $host_sent .= ':' . $parts['port'];
707
+            }
708
+            $timeout = 200; // ms
709
+            stream_set_timeout($fp, 0, $timeout * 1000);
710
+            $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : '');
711
+            $out = 'GET ' . $query . " HTTP/1.1\r\n";
712
+            $out .= 'Host: ' . $host_sent . "\r\n";
713
+            $out .= "Connection: Close\r\n\r\n";
714
+            fwrite($fp, $out);
715
+            spip_timer('read');
716
+            $t = 0;
717
+            // on lit la reponse si possible pour fermer proprement la connexion
718
+            // avec un timeout total de 200ms pour ne pas se bloquer
719
+            while (!feof($fp) and $t < $timeout) {
720
+                @fgets($fp, 1024);
721
+                $t += spip_timer('read', true);
722
+                spip_timer('read');
723
+            }
724
+            fclose($fp);
725
+            return true;
726
+        }
727
+    }
728
+    // si fsockopen n'est pas dispo on essaye cURL :
729
+    // lancer le cron par un cURL asynchrone si cURL est present
730
+    elseif (function_exists('curl_init')) {
731
+        //setting the curl parameters.
732
+        $ch = curl_init($url_cron);
733
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
734
+        // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
735
+        curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
736
+        // valeur mini pour que la requete soit lancee
737
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
738
+        // lancer
739
+        curl_exec($ch);
740
+        // fermer
741
+        curl_close($ch);
742
+        return true;
743
+    }
744
+
745
+    return false;
746 746
 }
Please login to merge, or discard this patch.
ecrire/inc/cvt_configurer.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  */
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 include_spip('inc/config');
@@ -32,31 +32,31 @@  discard block
 block discarded – undo
32 32
  * @return array|false
33 33
  */
34 34
 function cvtconf_formulaire_charger($flux) {
35
-	if (
36
-		$form = $flux['args']['form']
37
-		and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX
38
-	) {
39
-		// Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
40
-		include_spip('inc/autoriser');
41
-		if (!autoriser('configurer', '_' . substr($form, 11))) {
42
-			return false;
43
-		}
35
+    if (
36
+        $form = $flux['args']['form']
37
+        and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX
38
+    ) {
39
+        // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
40
+        include_spip('inc/autoriser');
41
+        if (!autoriser('configurer', '_' . substr($form, 11))) {
42
+            return false;
43
+        }
44 44
 
45
-		// S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
46
-		if (!charger_fonction('charger', "formulaires/$form/", true)) {
47
-			$flux['data'] = cvtconf_formulaires_configurer_recense($form);
48
-			$flux['data']['editable'] = true;
49
-			if (_request('var_mode') == 'configurer' and autoriser('webmestre')) {
50
-				if (!_AJAX) {
51
-					var_dump($flux['data']);
52
-				}
53
-				// reinjecter pour la trace au traitement
54
-				$flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
55
-			}
56
-		}
57
-	}
45
+        // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
46
+        if (!charger_fonction('charger', "formulaires/$form/", true)) {
47
+            $flux['data'] = cvtconf_formulaires_configurer_recense($form);
48
+            $flux['data']['editable'] = true;
49
+            if (_request('var_mode') == 'configurer' and autoriser('webmestre')) {
50
+                if (!_AJAX) {
51
+                    var_dump($flux['data']);
52
+                }
53
+                // reinjecter pour la trace au traitement
54
+                $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
55
+            }
56
+        }
57
+    }
58 58
 
59
-	return $flux;
59
+    return $flux;
60 60
 }
61 61
 
62 62
 /**
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
  * @return array
67 67
  */
68 68
 function cvtconf_formulaire_traiter($flux) {
69
-	if (
70
-		$form = $flux['args']['form']
71
-		and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX
72
-		and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
73
-	) {
74
-		$trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
75
-		$flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
76
-	}
69
+    if (
70
+        $form = $flux['args']['form']
71
+        and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX
72
+        and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
73
+    ) {
74
+        $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
75
+        $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
76
+    }
77 77
 
78
-	return $flux;
78
+    return $flux;
79 79
 }
80 80
 
81 81
 /**
@@ -91,32 +91,32 @@  discard block
 block discarded – undo
91 91
  * @return string
92 92
  */
93 93
 function cvtconf_formulaires_configurer_enregistre($form, $args) {
94
-	$valeurs = [];
95
-	// charger les valeurs
96
-	// ce qui permet de prendre en charge une fonction charger() existante
97
-	// qui prend alors la main sur l'auto detection
98
-	if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
99
-		$valeurs = $charger_valeurs(...$args);
100
-	}
101
-	$valeurs = pipeline(
102
-		'formulaire_charger',
103
-		[
104
-			'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
105
-			'data' => $valeurs
106
-		]
107
-	);
108
-	// ne pas stocker editable !
109
-	unset($valeurs['editable']);
94
+    $valeurs = [];
95
+    // charger les valeurs
96
+    // ce qui permet de prendre en charge une fonction charger() existante
97
+    // qui prend alors la main sur l'auto detection
98
+    if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
99
+        $valeurs = $charger_valeurs(...$args);
100
+    }
101
+    $valeurs = pipeline(
102
+        'formulaire_charger',
103
+        [
104
+            'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
105
+            'data' => $valeurs
106
+        ]
107
+    );
108
+    // ne pas stocker editable !
109
+    unset($valeurs['editable']);
110 110
 
111
-	// recuperer les valeurs postees
112
-	$store = [];
113
-	foreach ($valeurs as $k => $v) {
114
-		if (substr($k, 0, 1) !== '_') {
115
-			$store[$k] = _request($k);
116
-		}
117
-	}
111
+    // recuperer les valeurs postees
112
+    $store = [];
113
+    foreach ($valeurs as $k => $v) {
114
+        if (substr($k, 0, 1) !== '_') {
115
+            $store[$k] = _request($k);
116
+        }
117
+    }
118 118
 
119
-	return cvtconf_configurer_stocker($form, $valeurs, $store);
119
+    return cvtconf_configurer_stocker($form, $valeurs, $store);
120 120
 }
121 121
 
122 122
 /**
@@ -132,31 +132,31 @@  discard block
 block discarded – undo
132 132
  * @return array
133 133
  */
134 134
 function cvtconf_definir_configurer_conteneur($form, $valeurs) {
135
-	// stocker en base
136
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
137
-	$casier = substr($form, 11);
138
-	$table = 'meta';
139
-	$prefixe = '';
140
-	$stockage = '';
135
+    // stocker en base
136
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
137
+    $casier = substr($form, 11);
138
+    $table = 'meta';
139
+    $prefixe = '';
140
+    $stockage = '';
141 141
 
142
-	if (isset($valeurs['_meta_casier'])) {
143
-		$casier = $valeurs['_meta_casier'];
144
-	}
145
-	if (isset($valeurs['_meta_prefixe'])) {
146
-		$prefixe = $valeurs['_meta_prefixe'];
147
-	}
148
-	if (isset($valeurs['_meta_stockage'])) {
149
-		$stockage = $valeurs['_meta_stockage'] . '::';
150
-	}
142
+    if (isset($valeurs['_meta_casier'])) {
143
+        $casier = $valeurs['_meta_casier'];
144
+    }
145
+    if (isset($valeurs['_meta_prefixe'])) {
146
+        $prefixe = $valeurs['_meta_prefixe'];
147
+    }
148
+    if (isset($valeurs['_meta_stockage'])) {
149
+        $stockage = $valeurs['_meta_stockage'] . '::';
150
+    }
151 151
 
152
-	// si on indique juste une table, il faut vider les autres proprietes
153
-	// car par defaut on utilise ni casier ni prefixe dans ce cas
154
-	if (isset($valeurs['_meta_table'])) {
155
-		$table = $valeurs['_meta_table'];
156
-		$casier = ($valeurs['_meta_casier'] ?? '');
157
-	}
152
+    // si on indique juste une table, il faut vider les autres proprietes
153
+    // car par defaut on utilise ni casier ni prefixe dans ce cas
154
+    if (isset($valeurs['_meta_table'])) {
155
+        $table = $valeurs['_meta_table'];
156
+        $casier = ($valeurs['_meta_casier'] ?? '');
157
+    }
158 158
 
159
-	return [$table, $casier, $prefixe, $stockage];
159
+    return [$table, $casier, $prefixe, $stockage];
160 160
 }
161 161
 
162 162
 /**
@@ -167,48 +167,48 @@  discard block
 block discarded – undo
167 167
  * @return array
168 168
  */
169 169
 function cvtconf_formulaires_configurer_recense($form) {
170
-	$valeurs = ['editable' => ' '];
170
+    $valeurs = ['editable' => ' '];
171 171
 
172
-	// sinon cas analyse du squelette
173
-	if (
174
-		$f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')
175
-		and lire_fichier($f, $contenu)
176
-	) {
177
-		for ($i = 0; $i < 2; $i++) {
178
-			// a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
-			// permet de trouver aussi les name="#GET{truc}"
180
-			if ($i == 1) {
181
-				$contenu = recuperer_fond("formulaires/$form", $valeurs);
182
-			}
172
+    // sinon cas analyse du squelette
173
+    if (
174
+        $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')
175
+        and lire_fichier($f, $contenu)
176
+    ) {
177
+        for ($i = 0; $i < 2; $i++) {
178
+            // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
+            // permet de trouver aussi les name="#GET{truc}"
180
+            if ($i == 1) {
181
+                $contenu = recuperer_fond("formulaires/$form", $valeurs);
182
+            }
183 183
 
184
-			$balises = array_merge(
185
-				extraire_balises($contenu, 'input'),
186
-				extraire_balises($contenu, 'textarea'),
187
-				extraire_balises($contenu, 'select')
188
-			);
184
+            $balises = array_merge(
185
+                extraire_balises($contenu, 'input'),
186
+                extraire_balises($contenu, 'textarea'),
187
+                extraire_balises($contenu, 'select')
188
+            );
189 189
 
190
-			foreach ($balises as $b) {
191
-				if (
192
-					$n = extraire_attribut($b, 'name')
193
-					and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r)
194
-					and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
-					and extraire_attribut($b, 'type') !== 'submit'
196
-				) {
197
-					$valeurs[$r[1]] = '';
198
-					// recuperer les valeurs _meta_xx qui peuvent etre fournies
199
-					// en input hidden dans le squelette
200
-					if (strncmp($r[1], '_meta_', 6) == 0) {
201
-						$valeurs[$r[1]] = extraire_attribut($b, 'value');
202
-					}
203
-				}
204
-			}
205
-		}
206
-	}
190
+            foreach ($balises as $b) {
191
+                if (
192
+                    $n = extraire_attribut($b, 'name')
193
+                    and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r)
194
+                    and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
+                    and extraire_attribut($b, 'type') !== 'submit'
196
+                ) {
197
+                    $valeurs[$r[1]] = '';
198
+                    // recuperer les valeurs _meta_xx qui peuvent etre fournies
199
+                    // en input hidden dans le squelette
200
+                    if (strncmp($r[1], '_meta_', 6) == 0) {
201
+                        $valeurs[$r[1]] = extraire_attribut($b, 'value');
202
+                    }
203
+                }
204
+            }
205
+        }
206
+    }
207 207
 
208 208
 
209
-	cvtconf_configurer_lire_meta($form, $valeurs);
209
+    cvtconf_configurer_lire_meta($form, $valeurs);
210 210
 
211
-	return $valeurs;
211
+    return $valeurs;
212 212
 }
213 213
 
214 214
 /**
@@ -220,26 +220,26 @@  discard block
 block discarded – undo
220 220
  * @return string
221 221
  */
222 222
 function cvtconf_configurer_stocker($form, $valeurs, $store) {
223
-	$trace = '';
224
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
-	// stocker en base
226
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
-	if (!isset($GLOBALS[$table])) {
228
-		lire_metas($table);
229
-	}
223
+    $trace = '';
224
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
+    // stocker en base
226
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
+    if (!isset($GLOBALS[$table])) {
228
+        lire_metas($table);
229
+    }
230 230
 
231
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
232
-	$table = ($table) ? "/$table/" : '';
233
-	$casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien
231
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
232
+    $table = ($table) ? "/$table/" : '';
233
+    $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien
234 234
 
235
-	foreach ($store as $k => $v) {
236
-		ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
-		if (_request('var_mode') == 'configurer' and autoriser('webmestre')) {
238
-			$trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
-		}
240
-	}
235
+    foreach ($store as $k => $v) {
236
+        ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
+        if (_request('var_mode') == 'configurer' and autoriser('webmestre')) {
238
+            $trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
+        }
240
+    }
241 241
 
242
-	return $trace;
242
+    return $trace;
243 243
 }
244 244
 
245 245
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  * @param array $valeurs
250 250
  */
251 251
 function cvtconf_configurer_lire_meta($form, &$valeurs) {
252
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
252
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
253 253
 
254
-	$table = ($table) ? "/$table/" : '';
255
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
256
-	if ($casier) {
257
-		$meta = lire_config("$stockage$table$prefixe$casier");
258
-		$prefixe = '';
259
-	} else {
260
-		$table = rtrim($table, '/');
261
-		$meta = lire_config("$stockage$table");
262
-	}
254
+    $table = ($table) ? "/$table/" : '';
255
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
256
+    if ($casier) {
257
+        $meta = lire_config("$stockage$table$prefixe$casier");
258
+        $prefixe = '';
259
+    } else {
260
+        $table = rtrim($table, '/');
261
+        $meta = lire_config("$stockage$table");
262
+    }
263 263
 
264
-	foreach ($valeurs as $k => $v) {
265
-		if (substr($k, 0, 1) !== '_') {
266
-			$valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
-		}
268
-	}
264
+    foreach ($valeurs as $k => $v) {
265
+        if (substr($k, 0, 1) !== '_') {
266
+            $valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
+        }
268
+    }
269 269
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2252 added lines, -2253 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,71 +48,71 @@  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
-		$inc ?
108
-			_T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($f).'</code>'])
109
-			.'<br />'
110
-			._T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($g).'</code>'])
111
-			:
112
-			_T('fichier_introuvable', ['fichier' => '<code>'. spip_htmlentities($d).'</code>']),
113
-			['all_inline' => true,'status' => 404]
114
-	);
115
-	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
+        $inc ?
108
+            _T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($f).'</code>'])
109
+            .'<br />'
110
+            ._T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($g).'</code>'])
111
+            :
112
+            _T('fichier_introuvable', ['fichier' => '<code>'. spip_htmlentities($d).'</code>']),
113
+            ['all_inline' => true,'status' => 404]
114
+    );
115
+    exit;
116 116
 }
117 117
 
118 118
 /**
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
  * @return bool
123 123
  */
124 124
 function include_once_check($file) {
125
-	if (file_exists($file)) {
126
-		include_once $file;
125
+    if (file_exists($file)) {
126
+        include_once $file;
127 127
 
128
-		return true;
129
-	}
130
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
-	$crash = ($crash ?: []);
132
-	$crash[$file] = true;
133
-	ecrire_meta('message_crash_plugins', serialize($crash));
128
+        return true;
129
+    }
130
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
+    $crash = ($crash ?: []);
132
+    $crash[$file] = true;
133
+    ecrire_meta('message_crash_plugins', serialize($crash));
134 134
 
135
-	return false;
135
+    return false;
136 136
 }
137 137
 
138 138
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  *     - string : chemin du fichier trouvé
157 157
  **/
158 158
 function include_spip($f, $include = true) {
159
-	return find_in_path($f . '.php', '', $include);
159
+    return find_in_path($f . '.php', '', $include);
160 160
 }
161 161
 
162 162
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
  *     - string : chemin du fichier trouvé
177 177
  **/
178 178
 function require_spip($f) {
179
-	return find_in_path($f . '.php', '', 'required');
179
+    return find_in_path($f . '.php', '', 'required');
180 180
 }
181 181
 
182 182
 
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
186 186
  */
187 187
 function include_fichiers_fonctions() {
188
-	static $done = false;
189
-	if (!$done) {
190
-		include_spip('inc/lang');
191
-
192
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
-		// donc il faut l'inclure "en globals"
194
-		if ($f = find_in_path('mes_fonctions.php')) {
195
-			global $dossier_squelettes;
196
-			include_once(_ROOT_CWD . $f);
197
-		}
198
-
199
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
-			// chargement optimise precompile
201
-			include_once(_CACHE_PLUGINS_FCT);
202
-		}
203
-		if (test_espace_prive()) {
204
-			include_spip('inc/filtres_ecrire');
205
-		}
206
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
-		$done = true;
208
-	}
188
+    static $done = false;
189
+    if (!$done) {
190
+        include_spip('inc/lang');
191
+
192
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
+        // donc il faut l'inclure "en globals"
194
+        if ($f = find_in_path('mes_fonctions.php')) {
195
+            global $dossier_squelettes;
196
+            include_once(_ROOT_CWD . $f);
197
+        }
198
+
199
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
+            // chargement optimise precompile
201
+            include_once(_CACHE_PLUGINS_FCT);
202
+        }
203
+        if (test_espace_prive()) {
204
+            include_spip('inc/filtres_ecrire');
205
+        }
206
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
+        $done = true;
208
+    }
209 209
 }
210 210
 
211 211
 /**
@@ -231,23 +231,23 @@  discard block
 block discarded – undo
231 231
  *     Les paramètres du pipeline modifiés
232 232
  **/
233 233
 function minipipe($fonc, &$val) {
234
-	// fonction
235
-	if (function_exists($fonc)) {
236
-		$val = $fonc($val);
237
-	} // Class::Methode
238
-	else {
239
-		if (
240
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
-			and $methode = [$regs[1], $regs[2]]
242
-			and is_callable($methode)
243
-		) {
244
-			$val = $methode($val);
245
-		} else {
246
-			spip_log("Erreur - '$fonc' non definie !");
247
-		}
248
-	}
249
-
250
-	return $val;
234
+    // fonction
235
+    if (function_exists($fonc)) {
236
+        $val = $fonc($val);
237
+    } // Class::Methode
238
+    else {
239
+        if (
240
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
+            and $methode = [$regs[1], $regs[2]]
242
+            and is_callable($methode)
243
+        ) {
244
+            $val = $methode($val);
245
+        } else {
246
+            spip_log("Erreur - '$fonc' non definie !");
247
+        }
248
+    }
249
+
250
+    return $val;
251 251
 }
252 252
 
253 253
 /**
@@ -278,46 +278,46 @@  discard block
 block discarded – undo
278 278
  *     Résultat
279 279
  */
280 280
 function pipeline($action, $val = null) {
281
-	static $charger;
282
-
283
-	// chargement initial des fonctions mises en cache, ou generation du cache
284
-	if (!$charger) {
285
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
-			include_spip('inc/plugin');
287
-			// generer les fichiers php precompiles
288
-			// de chargement des plugins et des pipelines
289
-			actualise_plugins_actifs();
290
-			if (!($ok = @is_readable($charger))) {
291
-				spip_log("fichier $charger pas cree");
292
-			}
293
-		}
294
-
295
-		if ($ok) {
296
-			include_once $charger;
297
-		}
298
-	}
299
-
300
-	// appliquer notre fonction si elle existe
301
-	$fonc = 'execute_pipeline_' . strtolower($action);
302
-	if (function_exists($fonc)) {
303
-		$val = $fonc($val);
304
-	} // plantage ?
305
-	else {
306
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
-	}
308
-
309
-	// si le flux est une table avec 2 cle args&data
310
-	// on ne ressort du pipe que les donnees dans 'data'
311
-	// array_key_exists pour php 4.1.0
312
-	if (
313
-		is_array($val)
314
-		and count($val) == 2
315
-		and (array_key_exists('data', $val))
316
-	) {
317
-		$val = $val['data'];
318
-	}
319
-
320
-	return $val;
281
+    static $charger;
282
+
283
+    // chargement initial des fonctions mises en cache, ou generation du cache
284
+    if (!$charger) {
285
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
+            include_spip('inc/plugin');
287
+            // generer les fichiers php precompiles
288
+            // de chargement des plugins et des pipelines
289
+            actualise_plugins_actifs();
290
+            if (!($ok = @is_readable($charger))) {
291
+                spip_log("fichier $charger pas cree");
292
+            }
293
+        }
294
+
295
+        if ($ok) {
296
+            include_once $charger;
297
+        }
298
+    }
299
+
300
+    // appliquer notre fonction si elle existe
301
+    $fonc = 'execute_pipeline_' . strtolower($action);
302
+    if (function_exists($fonc)) {
303
+        $val = $fonc($val);
304
+    } // plantage ?
305
+    else {
306
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
+    }
308
+
309
+    // si le flux est une table avec 2 cle args&data
310
+    // on ne ressort du pipe que les donnees dans 'data'
311
+    // array_key_exists pour php 4.1.0
312
+    if (
313
+        is_array($val)
314
+        and count($val) == 2
315
+        and (array_key_exists('data', $val))
316
+    ) {
317
+        $val = $val['data'];
318
+    }
319
+
320
+    return $val;
321 321
 }
322 322
 
323 323
 /**
@@ -361,38 +361,38 @@  discard block
 block discarded – undo
361 361
  *     paramètre est planté pour cause de compatibilité ascendante.
362 362
  */
363 363
 function spip_log($message = null, $name = null) {
364
-	static $pre = [];
365
-	static $log;
366
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
368
-		$logname = null;
369
-	}
370
-	if (!isset($regs[2])) {
371
-		$niveau = _LOG_INFO;
372
-	}
373
-	else {
374
-		$niveau = intval($regs[2]);
375
-	}
376
-
377
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
-		if (!$pre) {
379
-			$pre = [
380
-				_LOG_HS => 'HS:',
381
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
382
-				_LOG_CRITIQUE => 'CRITIQUE:',
383
-				_LOG_ERREUR => 'ERREUR:',
384
-				_LOG_AVERTISSEMENT => 'WARNING:',
385
-				_LOG_INFO_IMPORTANTE => '!INFO:',
386
-				_LOG_INFO => 'info:',
387
-				_LOG_DEBUG => 'debug:'
388
-			];
389
-			$log = charger_fonction('log', 'inc');
390
-		}
391
-		if (!is_string($message)) {
392
-			$message = print_r($message, true);
393
-		}
394
-		$log($pre[$niveau] . ' ' . $message, $logname);
395
-	}
364
+    static $pre = [];
365
+    static $log;
366
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
368
+        $logname = null;
369
+    }
370
+    if (!isset($regs[2])) {
371
+        $niveau = _LOG_INFO;
372
+    }
373
+    else {
374
+        $niveau = intval($regs[2]);
375
+    }
376
+
377
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
+        if (!$pre) {
379
+            $pre = [
380
+                _LOG_HS => 'HS:',
381
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
382
+                _LOG_CRITIQUE => 'CRITIQUE:',
383
+                _LOG_ERREUR => 'ERREUR:',
384
+                _LOG_AVERTISSEMENT => 'WARNING:',
385
+                _LOG_INFO_IMPORTANTE => '!INFO:',
386
+                _LOG_INFO => 'info:',
387
+                _LOG_DEBUG => 'debug:'
388
+            ];
389
+            $log = charger_fonction('log', 'inc');
390
+        }
391
+        if (!is_string($message)) {
392
+            $message = print_r($message, true);
393
+        }
394
+        $log($pre[$niveau] . ' ' . $message, $logname);
395
+    }
396 396
 }
397 397
 
398 398
 /**
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @param array $opt Tableau d'options
404 404
  **/
405 405
 function journal($phrase, $opt = []) {
406
-	$journal = charger_fonction('journal', 'inc');
407
-	$journal($phrase, $opt);
406
+    $journal = charger_fonction('journal', 'inc');
407
+    $journal($phrase, $opt);
408 408
 }
409 409
 
410 410
 
@@ -423,37 +423,37 @@  discard block
 block discarded – undo
423 423
  **/
424 424
 function _request($var, $c = false) {
425 425
 
426
-	if (is_array($c)) {
427
-		return $c[$var] ?? null;
428
-	}
429
-
430
-	if (isset($_GET[$var])) {
431
-		$a = $_GET[$var];
432
-	} elseif (isset($_POST[$var])) {
433
-		$a = $_POST[$var];
434
-	} else {
435
-		return null;
436
-	}
437
-
438
-	// Si on est en ajax et en POST tout a ete encode
439
-	// via encodeURIComponent, il faut donc repasser
440
-	// dans le charset local...
441
-	if (
442
-		defined('_AJAX')
443
-		and _AJAX
444
-		and isset($GLOBALS['meta']['charset'])
445
-		and $GLOBALS['meta']['charset'] != 'utf-8'
446
-		and is_string($a)
447
-		// check rapide mais pas fiable
448
-		and preg_match(',[\x80-\xFF],', $a)
449
-		// check fiable
450
-		and include_spip('inc/charsets')
451
-		and is_utf8($a)
452
-	) {
453
-		return importer_charset($a, 'utf-8');
454
-	}
455
-
456
-	return $a;
426
+    if (is_array($c)) {
427
+        return $c[$var] ?? null;
428
+    }
429
+
430
+    if (isset($_GET[$var])) {
431
+        $a = $_GET[$var];
432
+    } elseif (isset($_POST[$var])) {
433
+        $a = $_POST[$var];
434
+    } else {
435
+        return null;
436
+    }
437
+
438
+    // Si on est en ajax et en POST tout a ete encode
439
+    // via encodeURIComponent, il faut donc repasser
440
+    // dans le charset local...
441
+    if (
442
+        defined('_AJAX')
443
+        and _AJAX
444
+        and isset($GLOBALS['meta']['charset'])
445
+        and $GLOBALS['meta']['charset'] != 'utf-8'
446
+        and is_string($a)
447
+        // check rapide mais pas fiable
448
+        and preg_match(',[\x80-\xFF],', $a)
449
+        // check fiable
450
+        and include_spip('inc/charsets')
451
+        and is_utf8($a)
452
+    ) {
453
+        return importer_charset($a, 'utf-8');
454
+    }
455
+
456
+    return $a;
457 457
 }
458 458
 
459 459
 
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
  *     - false sinon
472 472
  **/
473 473
 function set_request($var, $val = null, $c = false) {
474
-	if (is_array($c)) {
475
-		unset($c[$var]);
476
-		if ($val !== null) {
477
-			$c[$var] = $val;
478
-		}
474
+    if (is_array($c)) {
475
+        unset($c[$var]);
476
+        if ($val !== null) {
477
+            $c[$var] = $val;
478
+        }
479 479
 
480
-		return $c;
481
-	}
480
+        return $c;
481
+    }
482 482
 
483
-	unset($_GET[$var]);
484
-	unset($_POST[$var]);
485
-	if ($val !== null) {
486
-		$_GET[$var] = $val;
487
-	}
483
+    unset($_GET[$var]);
484
+    unset($_POST[$var]);
485
+    if ($val !== null) {
486
+        $_GET[$var] = $val;
487
+    }
488 488
 
489
-	return false; # n'affecte pas $c
489
+    return false; # n'affecte pas $c
490 490
 }
491 491
 
492 492
 /**
@@ -506,25 +506,25 @@  discard block
 block discarded – undo
506 506
  * @return array|mixed|string
507 507
  */
508 508
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
509
-	if (is_array($value)) {
510
-		if ($key == '*') {
511
-			$key = array_keys($value);
512
-		}
513
-		if (!is_array($key)) {
514
-			$key = [$key];
515
-		}
516
-		foreach ($key as $k) {
517
-			if (!empty($value[$k])) {
518
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
-			}
520
-		}
521
-		return $value;
522
-	}
523
-	// si la valeur vient des GET ou POST on la sanitize
524
-	if (!empty($value) and $value == _request($key)) {
525
-		$value = $sanitize_function($value);
526
-	}
527
-	return $value;
509
+    if (is_array($value)) {
510
+        if ($key == '*') {
511
+            $key = array_keys($value);
512
+        }
513
+        if (!is_array($key)) {
514
+            $key = [$key];
515
+        }
516
+        foreach ($key as $k) {
517
+            if (!empty($value[$k])) {
518
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
+            }
520
+        }
521
+        return $value;
522
+    }
523
+    // si la valeur vient des GET ou POST on la sanitize
524
+    if (!empty($value) and $value == _request($key)) {
525
+        $value = $sanitize_function($value);
526
+    }
527
+    return $value;
528 528
 }
529 529
 
530 530
 /**
@@ -532,23 +532,22 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * On est sur le web, on exclut certains protocoles,
534 534
  * notamment 'file://', 'php://' et d'autres…
535
-
536 535
  * @param string $url
537 536
  * @return bool
538 537
  */
539 538
 function tester_url_absolue($url) {
540
-	$url = trim($url ?? '');
541
-	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
542
-		if (
543
-			isset($m[1])
544
-			and $p = strtolower(rtrim($m[1], ':'))
545
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
546
-		) {
547
-			return false;
548
-		}
549
-		return true;
550
-	}
551
-	return false;
539
+    $url = trim($url ?? '');
540
+    if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
541
+        if (
542
+            isset($m[1])
543
+            and $p = strtolower(rtrim($m[1], ':'))
544
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
545
+        ) {
546
+            return false;
547
+        }
548
+        return true;
549
+    }
550
+    return false;
552 551
 }
553 552
 
554 553
 /**
@@ -570,95 +569,95 @@  discard block
 block discarded – undo
570 569
  * @return string URL
571 570
  */
572 571
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
573
-	// requete erronnee : plusieurs variable dans $c et aucun $v
574
-	if (strpos($c, '|') !== false and is_null($v)) {
575
-		return null;
576
-	}
577
-
578
-	// lever l'#ancre
579
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
580
-		$url = $r[1];
581
-		$ancre = $r[2];
582
-	} else {
583
-		$ancre = '';
584
-	}
585
-
586
-	// eclater
587
-	$url = preg_split(',[?]|&amp;|&,', $url);
588
-
589
-	// recuperer la base
590
-	$a = array_shift($url);
591
-	if (!$a) {
592
-		$a = './';
593
-	}
594
-
595
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
596
-	$ajouts = array_flip(explode('|', $c));
597
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
598
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
599
-	$v_read = null;
600
-	// lire les variables et agir
601
-	foreach ($url as $n => $val) {
602
-		if (preg_match($regexp, urldecode($val), $r)) {
603
-			$r = array_pad($r, 3, null);
604
-			if ($v === null) {
605
-				// c'est un tableau, on memorise les valeurs
606
-				if (substr($r[1], -2) == '[]') {
607
-					if (!$v_read) {
608
-						$v_read = [];
609
-					}
610
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
611
-				} // c'est un scalaire, on retourne direct
612
-				else {
613
-					return $r[2] ? substr($r[2], 1) : '';
614
-				}
615
-			} // suppression
616
-			elseif (!$testv) {
617
-				unset($url[$n]);
618
-			}
619
-			// Ajout. Pour une variable, remplacer au meme endroit,
620
-			// pour un tableau ce sera fait dans la prochaine boucle
621
-			elseif (substr($r[1], -2) != '[]') {
622
-				$url[$n] = $r[1] . '=' . $u;
623
-				unset($ajouts[$r[1]]);
624
-			}
625
-			// Pour les tableaux on laisse tomber les valeurs de
626
-			// départ, on remplira à l'étape suivante
627
-			else {
628
-				unset($url[$n]);
629
-			}
630
-		}
631
-	}
632
-
633
-	// traiter les parametres pas encore trouves
634
-	if (
635
-		$v === null
636
-		and $args = func_get_args()
637
-		and count($args) == 2
638
-	) {
639
-		return $v_read; // rien trouve ou un tableau
640
-	} elseif ($testv) {
641
-		foreach ($ajouts as $k => $n) {
642
-			if (!is_array($v)) {
643
-				$url[] = $k . '=' . $u;
644
-			} else {
645
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
646
-				foreach ($v as $w) {
647
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
648
-				}
649
-			}
650
-		}
651
-	}
652
-
653
-	// eliminer les vides
654
-	$url = array_filter($url);
655
-
656
-	// recomposer l'adresse
657
-	if ($url) {
658
-		$a .= '?' . join($sep, $url);
659
-	}
660
-
661
-	return $a . $ancre;
572
+    // requete erronnee : plusieurs variable dans $c et aucun $v
573
+    if (strpos($c, '|') !== false and is_null($v)) {
574
+        return null;
575
+    }
576
+
577
+    // lever l'#ancre
578
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
579
+        $url = $r[1];
580
+        $ancre = $r[2];
581
+    } else {
582
+        $ancre = '';
583
+    }
584
+
585
+    // eclater
586
+    $url = preg_split(',[?]|&amp;|&,', $url);
587
+
588
+    // recuperer la base
589
+    $a = array_shift($url);
590
+    if (!$a) {
591
+        $a = './';
592
+    }
593
+
594
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
595
+    $ajouts = array_flip(explode('|', $c));
596
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
597
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
598
+    $v_read = null;
599
+    // lire les variables et agir
600
+    foreach ($url as $n => $val) {
601
+        if (preg_match($regexp, urldecode($val), $r)) {
602
+            $r = array_pad($r, 3, null);
603
+            if ($v === null) {
604
+                // c'est un tableau, on memorise les valeurs
605
+                if (substr($r[1], -2) == '[]') {
606
+                    if (!$v_read) {
607
+                        $v_read = [];
608
+                    }
609
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
610
+                } // c'est un scalaire, on retourne direct
611
+                else {
612
+                    return $r[2] ? substr($r[2], 1) : '';
613
+                }
614
+            } // suppression
615
+            elseif (!$testv) {
616
+                unset($url[$n]);
617
+            }
618
+            // Ajout. Pour une variable, remplacer au meme endroit,
619
+            // pour un tableau ce sera fait dans la prochaine boucle
620
+            elseif (substr($r[1], -2) != '[]') {
621
+                $url[$n] = $r[1] . '=' . $u;
622
+                unset($ajouts[$r[1]]);
623
+            }
624
+            // Pour les tableaux on laisse tomber les valeurs de
625
+            // départ, on remplira à l'étape suivante
626
+            else {
627
+                unset($url[$n]);
628
+            }
629
+        }
630
+    }
631
+
632
+    // traiter les parametres pas encore trouves
633
+    if (
634
+        $v === null
635
+        and $args = func_get_args()
636
+        and count($args) == 2
637
+    ) {
638
+        return $v_read; // rien trouve ou un tableau
639
+    } elseif ($testv) {
640
+        foreach ($ajouts as $k => $n) {
641
+            if (!is_array($v)) {
642
+                $url[] = $k . '=' . $u;
643
+            } else {
644
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
645
+                foreach ($v as $w) {
646
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
647
+                }
648
+            }
649
+        }
650
+    }
651
+
652
+    // eliminer les vides
653
+    $url = array_filter($url);
654
+
655
+    // recomposer l'adresse
656
+    if ($url) {
657
+        $a .= '?' . join($sep, $url);
658
+    }
659
+
660
+    return $a . $ancre;
662 661
 }
663 662
 
664 663
 /**
@@ -676,21 +675,21 @@  discard block
 block discarded – undo
676 675
  * @return string
677 676
  */
678 677
 function ancre_url($url, $ancre) {
679
-	// lever l'#ancre
680
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
681
-		$url = $r[1];
682
-	}
683
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
684
-		if (!function_exists('translitteration')) {
685
-			include_spip('inc/charsets');
686
-		}
687
-		$ancre = preg_replace(
688
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
689
-			['', '-'],
690
-			translitteration($ancre)
691
-		);
692
-	}
693
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
678
+    // lever l'#ancre
679
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
680
+        $url = $r[1];
681
+    }
682
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
683
+        if (!function_exists('translitteration')) {
684
+            include_spip('inc/charsets');
685
+        }
686
+        $ancre = preg_replace(
687
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
688
+            ['', '-'],
689
+            translitteration($ancre)
690
+        );
691
+    }
692
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
694 693
 }
695 694
 
696 695
 /**
@@ -700,16 +699,16 @@  discard block
 block discarded – undo
700 699
  * @return string
701 700
  */
702 701
 function nettoyer_uri($reset = null) {
703
-	static $done = false;
704
-	static $propre = '';
705
-	if (!is_null($reset)) {
706
-		return $propre = $reset;
707
-	}
708
-	if ($done) {
709
-		return $propre;
710
-	}
711
-	$done = true;
712
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
702
+    static $done = false;
703
+    static $propre = '';
704
+    if (!is_null($reset)) {
705
+        return $propre = $reset;
706
+    }
707
+    if ($done) {
708
+        return $propre;
709
+    }
710
+    $done = true;
711
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
713 712
 }
714 713
 
715 714
 /**
@@ -721,16 +720,16 @@  discard block
 block discarded – undo
721 720
  * @return string
722 721
  */
723 722
 function nettoyer_uri_var($request_uri) {
724
-	$uri1 = $request_uri;
725
-	do {
726
-		$uri = $uri1;
727
-		$uri1 = preg_replace(
728
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
729
-			'\1',
730
-			$uri
731
-		);
732
-	} while ($uri <> $uri1);
733
-	return preg_replace(',[?&]$,', '', $uri1);
723
+    $uri1 = $request_uri;
724
+    do {
725
+        $uri = $uri1;
726
+        $uri1 = preg_replace(
727
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
728
+            '\1',
729
+            $uri
730
+        );
731
+    } while ($uri <> $uri1);
732
+    return preg_replace(',[?&]$,', '', $uri1);
734 733
 }
735 734
 
736 735
 
@@ -744,48 +743,48 @@  discard block
 block discarded – undo
744 743
  *    URL vers soi-même
745 744
  **/
746 745
 function self($amp = '&amp;', $root = false) {
747
-	$url = nettoyer_uri();
748
-	if (
749
-		!$root
750
-		and (
751
-			// si pas de profondeur on peut tronquer
752
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
753
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
754
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
755
-	) {
756
-		$url = preg_replace(',^[^?]*/,', '', $url);
757
-	}
758
-	// ajouter le cas echeant les variables _POST['id_...']
759
-	foreach ($_POST as $v => $c) {
760
-		if (substr($v, 0, 3) == 'id_') {
761
-			$url = parametre_url($url, $v, $c, '&');
762
-		}
763
-	}
764
-
765
-	// supprimer les variables sans interet
766
-	if (test_espace_prive()) {
767
-		$url = preg_replace(',([?&])('
768
-			. 'lang|show_docs|'
769
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
770
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
771
-		$url = preg_replace(',[&]$,', '\1', $url);
772
-	}
773
-
774
-	// eviter les hacks
775
-	include_spip('inc/filtres_mini');
776
-	$url = spip_htmlspecialchars($url);
777
-
778
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
779
-
780
-	// &amp; ?
781
-	if ($amp != '&amp;') {
782
-		$url = str_replace('&amp;', $amp, $url);
783
-	}
784
-
785
-	// Si ca demarre par ? ou vide, donner './'
786
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
787
-
788
-	return $url;
746
+    $url = nettoyer_uri();
747
+    if (
748
+        !$root
749
+        and (
750
+            // si pas de profondeur on peut tronquer
751
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
752
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
753
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
754
+    ) {
755
+        $url = preg_replace(',^[^?]*/,', '', $url);
756
+    }
757
+    // ajouter le cas echeant les variables _POST['id_...']
758
+    foreach ($_POST as $v => $c) {
759
+        if (substr($v, 0, 3) == 'id_') {
760
+            $url = parametre_url($url, $v, $c, '&');
761
+        }
762
+    }
763
+
764
+    // supprimer les variables sans interet
765
+    if (test_espace_prive()) {
766
+        $url = preg_replace(',([?&])('
767
+            . 'lang|show_docs|'
768
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
769
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
770
+        $url = preg_replace(',[&]$,', '\1', $url);
771
+    }
772
+
773
+    // eviter les hacks
774
+    include_spip('inc/filtres_mini');
775
+    $url = spip_htmlspecialchars($url);
776
+
777
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
778
+
779
+    // &amp; ?
780
+    if ($amp != '&amp;') {
781
+        $url = str_replace('&amp;', $amp, $url);
782
+    }
783
+
784
+    // Si ca demarre par ? ou vide, donner './'
785
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
786
+
787
+    return $url;
789 788
 }
790 789
 
791 790
 
@@ -796,7 +795,7 @@  discard block
 block discarded – undo
796 795
  *     true si c'est le cas, false sinon.
797 796
  */
798 797
 function test_espace_prive() {
799
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
798
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
800 799
 }
801 800
 
802 801
 /**
@@ -806,7 +805,7 @@  discard block
 block discarded – undo
806 805
  * @return bool
807 806
  */
808 807
 function test_plugin_actif($plugin) {
809
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
808
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
810 809
 }
811 810
 
812 811
 /**
@@ -837,52 +836,52 @@  discard block
 block discarded – undo
837 836
  *     Texte
838 837
  */
839 838
 function _T($texte, $args = [], $options = []) {
840
-	static $traduire = false;
841
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
842
-	if ($options) {
843
-		// support de l'ancien argument $class
844
-		if (is_string($options)) {
845
-			$options = ['class' => $options];
846
-		}
847
-		$o = array_merge($o, $options);
848
-	}
849
-
850
-	if (!$traduire) {
851
-		$traduire = charger_fonction('traduire', 'inc');
852
-		include_spip('inc/lang');
853
-	}
854
-
855
-	// On peut passer explicitement la langue dans le tableau
856
-	// On utilise le même nom de variable que la globale
857
-	if (isset($args['spip_lang'])) {
858
-		$lang = $args['spip_lang'];
859
-		// On l'enleve pour ne pas le passer au remplacement
860
-		unset($args['spip_lang']);
861
-	} // Sinon on prend la langue du contexte
862
-	else {
863
-		$lang = $GLOBALS['spip_lang'];
864
-	}
865
-	$text = $traduire($texte, $lang);
866
-
867
-	if ($text === null || !strlen($text)) {
868
-		if (!$o['force']) {
869
-			return '';
870
-		}
871
-
872
-		$text = $texte;
873
-
874
-		// pour les chaines non traduites, assurer un service minimum
875
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
876
-			$n = strpos($text, ':');
877
-			if ($n !== false) {
878
-				$text = substr($text, $n + 1);
879
-			}
880
-			$text = str_replace('_', ' ', $text);
881
-		}
882
-		$o['class'] = null;
883
-	}
884
-
885
-	return _L($text, $args, $o);
839
+    static $traduire = false;
840
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
841
+    if ($options) {
842
+        // support de l'ancien argument $class
843
+        if (is_string($options)) {
844
+            $options = ['class' => $options];
845
+        }
846
+        $o = array_merge($o, $options);
847
+    }
848
+
849
+    if (!$traduire) {
850
+        $traduire = charger_fonction('traduire', 'inc');
851
+        include_spip('inc/lang');
852
+    }
853
+
854
+    // On peut passer explicitement la langue dans le tableau
855
+    // On utilise le même nom de variable que la globale
856
+    if (isset($args['spip_lang'])) {
857
+        $lang = $args['spip_lang'];
858
+        // On l'enleve pour ne pas le passer au remplacement
859
+        unset($args['spip_lang']);
860
+    } // Sinon on prend la langue du contexte
861
+    else {
862
+        $lang = $GLOBALS['spip_lang'];
863
+    }
864
+    $text = $traduire($texte, $lang);
865
+
866
+    if ($text === null || !strlen($text)) {
867
+        if (!$o['force']) {
868
+            return '';
869
+        }
870
+
871
+        $text = $texte;
872
+
873
+        // pour les chaines non traduites, assurer un service minimum
874
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
875
+            $n = strpos($text, ':');
876
+            if ($n !== false) {
877
+                $text = substr($text, $n + 1);
878
+            }
879
+            $text = str_replace('_', ' ', $text);
880
+        }
881
+        $o['class'] = null;
882
+    }
883
+
884
+    return _L($text, $args, $o);
886 885
 }
887 886
 
888 887
 
@@ -909,53 +908,53 @@  discard block
 block discarded – undo
909 908
  *     Texte
910 909
  */
911 910
 function _L($text, $args = [], $options = []) {
912
-	$f = $text;
913
-	$defaut_options = [
914
-		'class' => null,
915
-		'sanitize' => true,
916
-	];
917
-	// support de l'ancien argument $class
918
-	if ($options and is_string($options)) {
919
-		$options = ['class' => $options];
920
-	}
921
-	if (is_array($options)) {
922
-		$options += $defaut_options;
923
-	} else {
924
-		$options = $defaut_options;
925
-	}
926
-
927
-	if (is_array($args) and count($args)) {
928
-		if (!function_exists('interdire_scripts')) {
929
-			include_spip('inc/texte');
930
-		}
931
-		if (!function_exists('echapper_html_suspect')) {
932
-			include_spip('inc/texte_mini');
933
-		}
934
-		foreach ($args as $name => $value) {
935
-			if (strpos($text, (string) "@$name@") !== false) {
936
-				if ($options['sanitize']) {
937
-					$value = echapper_html_suspect($value);
938
-					$value = interdire_scripts($value, -1);
939
-				}
940
-				if (!empty($options['class'])) {
941
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
942
-				}
943
-				$text = str_replace("@$name@", $value, $text);
944
-				unset($args[$name]);
945
-			}
946
-		}
947
-		// Si des variables n'ont pas ete inserees, le signaler
948
-		// (chaines de langues pas a jour)
949
-		if ($args) {
950
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
951
-		}
952
-	}
953
-
954
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
955
-		return "<span class='debug-traduction-erreur'>$text</span>";
956
-	} else {
957
-		return $text;
958
-	}
911
+    $f = $text;
912
+    $defaut_options = [
913
+        'class' => null,
914
+        'sanitize' => true,
915
+    ];
916
+    // support de l'ancien argument $class
917
+    if ($options and is_string($options)) {
918
+        $options = ['class' => $options];
919
+    }
920
+    if (is_array($options)) {
921
+        $options += $defaut_options;
922
+    } else {
923
+        $options = $defaut_options;
924
+    }
925
+
926
+    if (is_array($args) and count($args)) {
927
+        if (!function_exists('interdire_scripts')) {
928
+            include_spip('inc/texte');
929
+        }
930
+        if (!function_exists('echapper_html_suspect')) {
931
+            include_spip('inc/texte_mini');
932
+        }
933
+        foreach ($args as $name => $value) {
934
+            if (strpos($text, (string) "@$name@") !== false) {
935
+                if ($options['sanitize']) {
936
+                    $value = echapper_html_suspect($value);
937
+                    $value = interdire_scripts($value, -1);
938
+                }
939
+                if (!empty($options['class'])) {
940
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
941
+                }
942
+                $text = str_replace("@$name@", $value, $text);
943
+                unset($args[$name]);
944
+            }
945
+        }
946
+        // Si des variables n'ont pas ete inserees, le signaler
947
+        // (chaines de langues pas a jour)
948
+        if ($args) {
949
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
950
+        }
951
+    }
952
+
953
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
954
+        return "<span class='debug-traduction-erreur'>$text</span>";
955
+    } else {
956
+        return $text;
957
+    }
959 958
 }
960 959
 
961 960
 
@@ -969,13 +968,13 @@  discard block
 block discarded – undo
969 968
  * @return string
970 969
  */
971 970
 function joli_repertoire($rep) {
972
-	$a = substr($rep, 0, 1);
973
-	if ($a <> '.' and $a <> '/') {
974
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
975
-	}
976
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
971
+    $a = substr($rep, 0, 1);
972
+    if ($a <> '.' and $a <> '/') {
973
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
974
+    }
975
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
977 976
 
978
-	return $rep;
977
+    return $rep;
979 978
 }
980 979
 
981 980
 
@@ -1000,54 +999,54 @@  discard block
 block discarded – undo
1000 999
  * @return float|int|string|void
1001 1000
  */
1002 1001
 function spip_timer($t = 'rien', $raw = false) {
1003
-	static $time;
1004
-	$a = time();
1005
-	$b = microtime();
1006
-	// microtime peut contenir les microsecondes et le temps
1007
-	$b = explode(' ', $b);
1008
-	if (count($b) == 2) {
1009
-		$a = end($b);
1010
-	} // plus precis !
1011
-	$b = reset($b);
1012
-	if (!isset($time[$t])) {
1013
-		$time[$t] = $a + $b;
1014
-	} else {
1015
-		$p = ($a + $b - $time[$t]) * 1000;
1016
-		unset($time[$t]);
1002
+    static $time;
1003
+    $a = time();
1004
+    $b = microtime();
1005
+    // microtime peut contenir les microsecondes et le temps
1006
+    $b = explode(' ', $b);
1007
+    if (count($b) == 2) {
1008
+        $a = end($b);
1009
+    } // plus precis !
1010
+    $b = reset($b);
1011
+    if (!isset($time[$t])) {
1012
+        $time[$t] = $a + $b;
1013
+    } else {
1014
+        $p = ($a + $b - $time[$t]) * 1000;
1015
+        unset($time[$t]);
1017 1016
 #			echo "'$p'";exit;
1018
-		if ($raw) {
1019
-			return $p;
1020
-		}
1021
-		if ($p < 1000) {
1022
-			$s = '';
1023
-		} else {
1024
-			$s = sprintf('%d ', $x = floor($p / 1000));
1025
-			$p -= ($x * 1000);
1026
-		}
1017
+        if ($raw) {
1018
+            return $p;
1019
+        }
1020
+        if ($p < 1000) {
1021
+            $s = '';
1022
+        } else {
1023
+            $s = sprintf('%d ', $x = floor($p / 1000));
1024
+            $p -= ($x * 1000);
1025
+        }
1027 1026
 
1028
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1029
-	}
1027
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1028
+    }
1030 1029
 }
1031 1030
 
1032 1031
 
1033 1032
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1034 1033
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1035 1034
 function spip_touch($fichier, $duree = 0, $touch = true) {
1036
-	if ($duree) {
1037
-		clearstatcache();
1038
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1039
-			return false;
1040
-		}
1041
-	}
1042
-	if ($touch !== false) {
1043
-		if (!@touch($fichier)) {
1044
-			spip_unlink($fichier);
1045
-			@touch($fichier);
1046
-		};
1047
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1048
-	}
1035
+    if ($duree) {
1036
+        clearstatcache();
1037
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1038
+            return false;
1039
+        }
1040
+    }
1041
+    if ($touch !== false) {
1042
+        if (!@touch($fichier)) {
1043
+            spip_unlink($fichier);
1044
+            @touch($fichier);
1045
+        };
1046
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1047
+    }
1049 1048
 
1050
-	return true;
1049
+    return true;
1051 1050
 }
1052 1051
 
1053 1052
 
@@ -1058,11 +1057,11 @@  discard block
 block discarded – undo
1058 1057
  * @uses cron()
1059 1058
  **/
1060 1059
 function action_cron() {
1061
-	include_spip('inc/headers');
1062
-	http_response_code(204); // No Content
1063
-	header('Connection: close');
1064
-	define('_DIRECT_CRON_FORCE', true);
1065
-	cron();
1060
+    include_spip('inc/headers');
1061
+    http_response_code(204); // No Content
1062
+    header('Connection: close');
1063
+    define('_DIRECT_CRON_FORCE', true);
1064
+    cron();
1066 1065
 }
1067 1066
 
1068 1067
 /**
@@ -1078,26 +1077,26 @@  discard block
 block discarded – undo
1078 1077
  *     True si la tache a pu être effectuée
1079 1078
  */
1080 1079
 function cron($taches = [], $taches_old = []) {
1081
-	// si pas en mode cron force, laisser tomber.
1082
-	if (!defined('_DIRECT_CRON_FORCE')) {
1083
-		return false;
1084
-	}
1085
-	if (!is_array($taches)) {
1086
-		$taches = $taches_old;
1087
-	} // compat anciens appels
1088
-	// si taches a inserer en base et base inaccessible, laisser tomber
1089
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1090
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1091
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1092
-	if ($taches and count($taches) and !spip_connect()) {
1093
-		return false;
1094
-	}
1095
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1096
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1097
-		return $genie($taches);
1098
-	}
1099
-
1100
-	return false;
1080
+    // si pas en mode cron force, laisser tomber.
1081
+    if (!defined('_DIRECT_CRON_FORCE')) {
1082
+        return false;
1083
+    }
1084
+    if (!is_array($taches)) {
1085
+        $taches = $taches_old;
1086
+    } // compat anciens appels
1087
+    // si taches a inserer en base et base inaccessible, laisser tomber
1088
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1089
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1090
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1091
+    if ($taches and count($taches) and !spip_connect()) {
1092
+        return false;
1093
+    }
1094
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1095
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1096
+        return $genie($taches);
1097
+    }
1098
+
1099
+    return false;
1101 1100
 }
1102 1101
 
1103 1102
 /**
@@ -1129,17 +1128,17 @@  discard block
 block discarded – undo
1129 1128
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1130 1129
  */
1131 1130
 function job_queue_add(
1132
-	$function,
1133
-	$description,
1134
-	$arguments = [],
1135
-	$file = '',
1136
-	$no_duplicate = false,
1137
-	$time = 0,
1138
-	$priority = 0
1131
+    $function,
1132
+    $description,
1133
+    $arguments = [],
1134
+    $file = '',
1135
+    $no_duplicate = false,
1136
+    $time = 0,
1137
+    $priority = 0
1139 1138
 ) {
1140
-	include_spip('inc/queue');
1139
+    include_spip('inc/queue');
1141 1140
 
1142
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1141
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1143 1142
 }
1144 1143
 
1145 1144
 /**
@@ -1150,9 +1149,9 @@  discard block
 block discarded – undo
1150 1149
  * @return bool
1151 1150
  */
1152 1151
 function job_queue_remove($id_job) {
1153
-	include_spip('inc/queue');
1152
+    include_spip('inc/queue');
1154 1153
 
1155
-	return queue_remove_job($id_job);
1154
+    return queue_remove_job($id_job);
1156 1155
 }
1157 1156
 
1158 1157
 /**
@@ -1165,9 +1164,9 @@  discard block
 block discarded – undo
1165 1164
  *     or an array of simple array to link multiples objet in one time
1166 1165
  */
1167 1166
 function job_queue_link($id_job, $objets) {
1168
-	include_spip('inc/queue');
1167
+    include_spip('inc/queue');
1169 1168
 
1170
-	return queue_link_job($id_job, $objets);
1169
+    return queue_link_job($id_job, $objets);
1171 1170
 }
1172 1171
 
1173 1172
 
@@ -1187,36 +1186,36 @@  discard block
 block discarded – undo
1187 1186
  *  - `null` si la queue n'est pas encore initialisée
1188 1187
  */
1189 1188
 function queue_sleep_time_to_next_job($force = null) {
1190
-	static $queue_next_job_time = -1;
1191
-	if ($force === true) {
1192
-		$queue_next_job_time = -1;
1193
-	} elseif ($force) {
1194
-		$queue_next_job_time = $force;
1195
-	}
1196
-
1197
-	if ($queue_next_job_time == -1) {
1198
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1199
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1200
-		}
1201
-		// utiliser un cache memoire si dispo
1202
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1203
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1204
-		} else {
1205
-			$queue_next_job_time = null;
1206
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1207
-				$queue_next_job_time = intval($contenu);
1208
-			}
1209
-		}
1210
-	}
1211
-
1212
-	if (is_null($queue_next_job_time)) {
1213
-		return null;
1214
-	}
1215
-	if (!$_SERVER['REQUEST_TIME']) {
1216
-		$_SERVER['REQUEST_TIME'] = time();
1217
-	}
1218
-
1219
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1189
+    static $queue_next_job_time = -1;
1190
+    if ($force === true) {
1191
+        $queue_next_job_time = -1;
1192
+    } elseif ($force) {
1193
+        $queue_next_job_time = $force;
1194
+    }
1195
+
1196
+    if ($queue_next_job_time == -1) {
1197
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1198
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1199
+        }
1200
+        // utiliser un cache memoire si dispo
1201
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1202
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1203
+        } else {
1204
+            $queue_next_job_time = null;
1205
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1206
+                $queue_next_job_time = intval($contenu);
1207
+            }
1208
+        }
1209
+    }
1210
+
1211
+    if (is_null($queue_next_job_time)) {
1212
+        return null;
1213
+    }
1214
+    if (!$_SERVER['REQUEST_TIME']) {
1215
+        $_SERVER['REQUEST_TIME'] = time();
1216
+    }
1217
+
1218
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1220 1219
 }
1221 1220
 
1222 1221
 
@@ -1228,11 +1227,11 @@  discard block
 block discarded – undo
1228 1227
  * @return string
1229 1228
  */
1230 1229
 function quote_amp($u) {
1231
-	return preg_replace(
1232
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1233
-		'&amp;',
1234
-		$u
1235
-	);
1230
+    return preg_replace(
1231
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1232
+        '&amp;',
1233
+        $u
1234
+    );
1236 1235
 }
1237 1236
 
1238 1237
 
@@ -1255,27 +1254,27 @@  discard block
 block discarded – undo
1255 1254
  *     Balise HTML `<script>` et son contenu
1256 1255
  **/
1257 1256
 function http_script($script, $src = '', $noscript = '') {
1258
-	static $done = [];
1257
+    static $done = [];
1259 1258
 
1260
-	if ($src && !isset($done[$src])) {
1261
-		$done[$src] = true;
1262
-		$src = find_in_path($src, _JAVASCRIPT);
1263
-		$src = " src='$src'";
1264
-	} else {
1265
-		$src = '';
1266
-	}
1267
-	if ($script) {
1268
-		$script = ("/*<![CDATA[*/\n" .
1269
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1270
-			'/*]]>*/');
1271
-	}
1272
-	if ($noscript) {
1273
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1274
-	}
1259
+    if ($src && !isset($done[$src])) {
1260
+        $done[$src] = true;
1261
+        $src = find_in_path($src, _JAVASCRIPT);
1262
+        $src = " src='$src'";
1263
+    } else {
1264
+        $src = '';
1265
+    }
1266
+    if ($script) {
1267
+        $script = ("/*<![CDATA[*/\n" .
1268
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1269
+            '/*]]>*/');
1270
+    }
1271
+    if ($noscript) {
1272
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1273
+    }
1275 1274
 
1276
-	return ($src or $script or $noscript)
1277
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1278
-		: '';
1275
+    return ($src or $script or $noscript)
1276
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1277
+        : '';
1279 1278
 }
1280 1279
 
1281 1280
 
@@ -1310,7 +1309,7 @@  discard block
 block discarded – undo
1310 1309
  *     Texte échappé
1311 1310
  **/
1312 1311
 function texte_script(string $texte): string {
1313
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1312
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1314 1313
 }
1315 1314
 
1316 1315
 
@@ -1347,68 +1346,68 @@  discard block
 block discarded – undo
1347 1346
  *     Liste des chemins, par ordre de priorité.
1348 1347
  **/
1349 1348
 function _chemin($dir_path = null) {
1350
-	static $path_base = null;
1351
-	static $path_full = null;
1352
-	if ($path_base == null) {
1353
-		// Chemin standard depuis l'espace public
1354
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1355
-			_DIR_RACINE . ':' .
1356
-			_DIR_RACINE . 'squelettes-dist/:' .
1357
-			_DIR_RACINE . 'prive/:' .
1358
-			_DIR_RESTREINT;
1359
-		// Ajouter squelettes/
1360
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1361
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1362
-		}
1363
-		foreach (explode(':', $path) as $dir) {
1364
-			if (strlen($dir) and substr($dir, -1) != '/') {
1365
-				$dir .= '/';
1366
-			}
1367
-			$path_base[] = $dir;
1368
-		}
1369
-		$path_full = $path_base;
1370
-		// Et le(s) dossier(s) des squelettes nommes
1371
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1372
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1373
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1374
-			}
1375
-		}
1376
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1377
-	}
1378
-	if ($dir_path === null) {
1379
-		return $path_full;
1380
-	}
1381
-
1382
-	if (is_array($dir_path) or strlen($dir_path)) {
1383
-		$tete = '';
1384
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1385
-			$tete = array_shift($path_base);
1386
-		}
1387
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1388
-		$dirs = array_reverse($dirs);
1389
-		foreach ($dirs as $dir_path) {
1390
-			if (substr($dir_path, -1) != '/') {
1391
-				$dir_path .= '/';
1392
-			}
1393
-			if (!in_array($dir_path, $path_base)) {
1394
-				array_unshift($path_base, $dir_path);
1395
-			}
1396
-		}
1397
-		if (strlen($tete)) {
1398
-			array_unshift($path_base, $tete);
1399
-		}
1400
-	}
1401
-	$path_full = $path_base;
1402
-	// Et le(s) dossier(s) des squelettes nommes
1403
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1404
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1405
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1406
-		}
1407
-	}
1408
-
1409
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1410
-
1411
-	return $path_full;
1349
+    static $path_base = null;
1350
+    static $path_full = null;
1351
+    if ($path_base == null) {
1352
+        // Chemin standard depuis l'espace public
1353
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1354
+            _DIR_RACINE . ':' .
1355
+            _DIR_RACINE . 'squelettes-dist/:' .
1356
+            _DIR_RACINE . 'prive/:' .
1357
+            _DIR_RESTREINT;
1358
+        // Ajouter squelettes/
1359
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1360
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1361
+        }
1362
+        foreach (explode(':', $path) as $dir) {
1363
+            if (strlen($dir) and substr($dir, -1) != '/') {
1364
+                $dir .= '/';
1365
+            }
1366
+            $path_base[] = $dir;
1367
+        }
1368
+        $path_full = $path_base;
1369
+        // Et le(s) dossier(s) des squelettes nommes
1370
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1371
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1372
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1373
+            }
1374
+        }
1375
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1376
+    }
1377
+    if ($dir_path === null) {
1378
+        return $path_full;
1379
+    }
1380
+
1381
+    if (is_array($dir_path) or strlen($dir_path)) {
1382
+        $tete = '';
1383
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1384
+            $tete = array_shift($path_base);
1385
+        }
1386
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1387
+        $dirs = array_reverse($dirs);
1388
+        foreach ($dirs as $dir_path) {
1389
+            if (substr($dir_path, -1) != '/') {
1390
+                $dir_path .= '/';
1391
+            }
1392
+            if (!in_array($dir_path, $path_base)) {
1393
+                array_unshift($path_base, $dir_path);
1394
+            }
1395
+        }
1396
+        if (strlen($tete)) {
1397
+            array_unshift($path_base, $tete);
1398
+        }
1399
+    }
1400
+    $path_full = $path_base;
1401
+    // Et le(s) dossier(s) des squelettes nommes
1402
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1403
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1404
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1405
+        }
1406
+    }
1407
+
1408
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1409
+
1410
+    return $path_full;
1412 1411
 }
1413 1412
 
1414 1413
 /**
@@ -1421,78 +1420,78 @@  discard block
 block discarded – undo
1421 1420
  * @return array Liste de chemins
1422 1421
  **/
1423 1422
 function creer_chemin() {
1424
-	$path_a = _chemin();
1425
-	static $c = '';
1423
+    $path_a = _chemin();
1424
+    static $c = '';
1426 1425
 
1427
-	// on calcule le chemin si le dossier skel a change
1428
-	if ($c != $GLOBALS['dossier_squelettes']) {
1429
-		// assurer le non plantage lors de la montee de version :
1430
-		$c = $GLOBALS['dossier_squelettes'];
1431
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1432
-	}
1426
+    // on calcule le chemin si le dossier skel a change
1427
+    if ($c != $GLOBALS['dossier_squelettes']) {
1428
+        // assurer le non plantage lors de la montee de version :
1429
+        $c = $GLOBALS['dossier_squelettes'];
1430
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1431
+    }
1433 1432
 
1434
-	return $path_a;
1433
+    return $path_a;
1435 1434
 }
1436 1435
 
1437 1436
 
1438 1437
 function lister_themes_prives() {
1439
-	static $themes = null;
1440
-	if (is_null($themes)) {
1441
-		// si pas encore definie
1442
-		if (!defined('_SPIP_THEME_PRIVE')) {
1443
-			define('_SPIP_THEME_PRIVE', 'spip');
1444
-		}
1445
-		$themes = [_SPIP_THEME_PRIVE];
1446
-		// lors d'une installation neuve, prefs n'est pas definie.
1447
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1448
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1449
-		} else {
1450
-			$prefs = [];
1451
-		}
1452
-		if (is_string($prefs)) {
1453
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1454
-		}
1455
-		if (
1456
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1457
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1458
-			and $theme != _SPIP_THEME_PRIVE
1459
-		) {
1460
-			array_unshift($themes, $theme);
1461
-		} // placer le theme choisi en tete
1462
-	}
1463
-
1464
-	return $themes;
1438
+    static $themes = null;
1439
+    if (is_null($themes)) {
1440
+        // si pas encore definie
1441
+        if (!defined('_SPIP_THEME_PRIVE')) {
1442
+            define('_SPIP_THEME_PRIVE', 'spip');
1443
+        }
1444
+        $themes = [_SPIP_THEME_PRIVE];
1445
+        // lors d'une installation neuve, prefs n'est pas definie.
1446
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1447
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1448
+        } else {
1449
+            $prefs = [];
1450
+        }
1451
+        if (is_string($prefs)) {
1452
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1453
+        }
1454
+        if (
1455
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1456
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1457
+            and $theme != _SPIP_THEME_PRIVE
1458
+        ) {
1459
+            array_unshift($themes, $theme);
1460
+        } // placer le theme choisi en tete
1461
+    }
1462
+
1463
+    return $themes;
1465 1464
 }
1466 1465
 
1467 1466
 function find_in_theme($file, $subdir = '', $include = false) {
1468
-	static $themefiles = [];
1469
-	if (isset($themefiles["$subdir$file"])) {
1470
-		return $themefiles["$subdir$file"];
1471
-	}
1472
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1473
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1474
-	if (
1475
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1476
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1477
-		and $f = find_in_theme("$file_svg_generique")
1478
-	) {
1479
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1480
-			return $themefiles["$subdir$file"] = $fsize;
1481
-		}
1482
-		else {
1483
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1484
-		}
1485
-	}
1486
-
1487
-	$themes = lister_themes_prives();
1488
-	foreach ($themes as $theme) {
1489
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1490
-			return $themefiles["$subdir$file"] = $f;
1491
-		}
1492
-	}
1493
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1494
-
1495
-	return $themefiles["$subdir$file"] = '';
1467
+    static $themefiles = [];
1468
+    if (isset($themefiles["$subdir$file"])) {
1469
+        return $themefiles["$subdir$file"];
1470
+    }
1471
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1472
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1473
+    if (
1474
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1475
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1476
+        and $f = find_in_theme("$file_svg_generique")
1477
+    ) {
1478
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1479
+            return $themefiles["$subdir$file"] = $fsize;
1480
+        }
1481
+        else {
1482
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1483
+        }
1484
+    }
1485
+
1486
+    $themes = lister_themes_prives();
1487
+    foreach ($themes as $theme) {
1488
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1489
+            return $themefiles["$subdir$file"] = $f;
1490
+        }
1491
+    }
1492
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1493
+
1494
+    return $themefiles["$subdir$file"] = '';
1496 1495
 }
1497 1496
 
1498 1497
 
@@ -1516,31 +1515,31 @@  discard block
 block discarded – undo
1516 1515
  *     sinon chaîne vide.
1517 1516
  **/
1518 1517
 function chemin_image($icone) {
1519
-	static $icone_renommer;
1520
-	if ($p = strpos($icone, '?')) {
1521
-		$icone = substr($icone, 0, $p);
1522
-	}
1523
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1524
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1525
-		return $icone;
1526
-	}
1527
-
1528
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1529
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1530
-		return $f;
1531
-	}
1532
-	// sinon passer par le module de renommage
1533
-	if (is_null($icone_renommer)) {
1534
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1535
-	}
1536
-	if ($icone_renommer) {
1537
-		[$icone, $fonction] = $icone_renommer($icone, '');
1538
-		if (file_exists($icone)) {
1539
-			return $icone;
1540
-		}
1541
-	}
1542
-
1543
-	return find_in_path($icone, _NOM_IMG_PACK);
1518
+    static $icone_renommer;
1519
+    if ($p = strpos($icone, '?')) {
1520
+        $icone = substr($icone, 0, $p);
1521
+    }
1522
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1523
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1524
+        return $icone;
1525
+    }
1526
+
1527
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1528
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1529
+        return $f;
1530
+    }
1531
+    // sinon passer par le module de renommage
1532
+    if (is_null($icone_renommer)) {
1533
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1534
+    }
1535
+    if ($icone_renommer) {
1536
+        [$icone, $fonction] = $icone_renommer($icone, '');
1537
+        if (file_exists($icone)) {
1538
+            return $icone;
1539
+        }
1540
+    }
1541
+
1542
+    return find_in_path($icone, _NOM_IMG_PACK);
1544 1543
 }
1545 1544
 
1546 1545
 //
@@ -1578,128 +1577,128 @@  discard block
 block discarded – undo
1578 1577
  *     - false : fichier introuvable
1579 1578
  **/
1580 1579
 function find_in_path($file, $dirname = '', $include = false) {
1581
-	static $dirs = [];
1582
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1583
-	static $c = '';
1584
-
1585
-	if (!$file and !strlen($file)) {
1586
-		return false;
1587
-	}
1588
-
1589
-	// on calcule le chemin si le dossier skel a change
1590
-	if ($c != $GLOBALS['dossier_squelettes']) {
1591
-		// assurer le non plantage lors de la montee de version :
1592
-		$c = $GLOBALS['dossier_squelettes'];
1593
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1594
-	}
1595
-
1596
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1597
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1598
-			return false;
1599
-		}
1600
-		if ($include and !isset($inc[$dirname][$file])) {
1601
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1602
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1603
-		}
1604
-
1605
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1606
-	}
1607
-
1608
-	$a = strrpos($file, '/');
1609
-	if ($a !== false) {
1610
-		$dirname .= substr($file, 0, ++$a);
1611
-		$file = substr($file, $a);
1612
-	}
1613
-
1614
-	foreach (creer_chemin() as $dir) {
1615
-		if (!isset($dirs[$a = $dir . $dirname])) {
1616
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1617
-		}
1618
-		if ($dirs[$a]) {
1619
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1620
-				if ($include and !isset($inc[$dirname][$file])) {
1621
-					include_once _ROOT_CWD . $a;
1622
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1623
-				}
1624
-				if (!defined('_SAUVER_CHEMIN')) {
1625
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1626
-					if (is_null($GLOBALS['path_files'])) {
1627
-						return $a;
1628
-					}
1629
-					define('_SAUVER_CHEMIN', true);
1630
-				}
1631
-
1632
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1633
-			}
1634
-		}
1635
-	}
1636
-
1637
-	if ($include) {
1638
-		spip_log("include_spip $dirname$file non trouve");
1639
-		if ($include === 'required') {
1640
-			echo '<pre>',
1641
-			'<strong>Erreur Fatale</strong><br />';
1642
-			if (function_exists('debug_print_backtrace')) {
1643
-				echo debug_print_backtrace();
1644
-			}
1645
-			echo '</pre>';
1646
-			die("Erreur interne: ne peut inclure $dirname$file");
1647
-		}
1648
-	}
1649
-
1650
-	if (!defined('_SAUVER_CHEMIN')) {
1651
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1652
-		if (is_null($GLOBALS['path_files'])) {
1653
-			return false;
1654
-		}
1655
-		define('_SAUVER_CHEMIN', true);
1656
-	}
1657
-
1658
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1580
+    static $dirs = [];
1581
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1582
+    static $c = '';
1583
+
1584
+    if (!$file and !strlen($file)) {
1585
+        return false;
1586
+    }
1587
+
1588
+    // on calcule le chemin si le dossier skel a change
1589
+    if ($c != $GLOBALS['dossier_squelettes']) {
1590
+        // assurer le non plantage lors de la montee de version :
1591
+        $c = $GLOBALS['dossier_squelettes'];
1592
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1593
+    }
1594
+
1595
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1596
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1597
+            return false;
1598
+        }
1599
+        if ($include and !isset($inc[$dirname][$file])) {
1600
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1601
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1602
+        }
1603
+
1604
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1605
+    }
1606
+
1607
+    $a = strrpos($file, '/');
1608
+    if ($a !== false) {
1609
+        $dirname .= substr($file, 0, ++$a);
1610
+        $file = substr($file, $a);
1611
+    }
1612
+
1613
+    foreach (creer_chemin() as $dir) {
1614
+        if (!isset($dirs[$a = $dir . $dirname])) {
1615
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1616
+        }
1617
+        if ($dirs[$a]) {
1618
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1619
+                if ($include and !isset($inc[$dirname][$file])) {
1620
+                    include_once _ROOT_CWD . $a;
1621
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1622
+                }
1623
+                if (!defined('_SAUVER_CHEMIN')) {
1624
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1625
+                    if (is_null($GLOBALS['path_files'])) {
1626
+                        return $a;
1627
+                    }
1628
+                    define('_SAUVER_CHEMIN', true);
1629
+                }
1630
+
1631
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1632
+            }
1633
+        }
1634
+    }
1635
+
1636
+    if ($include) {
1637
+        spip_log("include_spip $dirname$file non trouve");
1638
+        if ($include === 'required') {
1639
+            echo '<pre>',
1640
+            '<strong>Erreur Fatale</strong><br />';
1641
+            if (function_exists('debug_print_backtrace')) {
1642
+                echo debug_print_backtrace();
1643
+            }
1644
+            echo '</pre>';
1645
+            die("Erreur interne: ne peut inclure $dirname$file");
1646
+        }
1647
+    }
1648
+
1649
+    if (!defined('_SAUVER_CHEMIN')) {
1650
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1651
+        if (is_null($GLOBALS['path_files'])) {
1652
+            return false;
1653
+        }
1654
+        define('_SAUVER_CHEMIN', true);
1655
+    }
1656
+
1657
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1659 1658
 }
1660 1659
 
1661 1660
 function clear_path_cache() {
1662
-	$GLOBALS['path_files'] = [];
1663
-	spip_unlink(_CACHE_CHEMIN);
1661
+    $GLOBALS['path_files'] = [];
1662
+    spip_unlink(_CACHE_CHEMIN);
1664 1663
 }
1665 1664
 
1666 1665
 function load_path_cache() {
1667
-	// charger le path des plugins
1668
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1669
-		include_once(_CACHE_PLUGINS_PATH);
1670
-	}
1671
-	$GLOBALS['path_files'] = [];
1672
-	// si le visiteur est admin,
1673
-	// on ne recharge pas le cache pour forcer sa mise a jour
1674
-	if (
1675
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1676
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1677
-		// utiliser le cookie est un pis aller qui marche 'en general'
1678
-		// on blinde par un second test au moment de la lecture de la session
1679
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1680
-		// et en ignorant ce cache en cas de recalcul explicite
1681
-		!_request('var_mode')
1682
-	) {
1683
-		// on essaye de lire directement sans verrou pour aller plus vite
1684
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1685
-			// mais si semble corrompu on relit avec un verrou
1686
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1687
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1688
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1689
-					$GLOBALS['path_files'] = [];
1690
-				}
1691
-			}
1692
-		}
1693
-	}
1666
+    // charger le path des plugins
1667
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1668
+        include_once(_CACHE_PLUGINS_PATH);
1669
+    }
1670
+    $GLOBALS['path_files'] = [];
1671
+    // si le visiteur est admin,
1672
+    // on ne recharge pas le cache pour forcer sa mise a jour
1673
+    if (
1674
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1675
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1676
+        // utiliser le cookie est un pis aller qui marche 'en general'
1677
+        // on blinde par un second test au moment de la lecture de la session
1678
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1679
+        // et en ignorant ce cache en cas de recalcul explicite
1680
+        !_request('var_mode')
1681
+    ) {
1682
+        // on essaye de lire directement sans verrou pour aller plus vite
1683
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1684
+            // mais si semble corrompu on relit avec un verrou
1685
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1686
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1687
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1688
+                    $GLOBALS['path_files'] = [];
1689
+                }
1690
+            }
1691
+        }
1692
+    }
1694 1693
 }
1695 1694
 
1696 1695
 function save_path_cache() {
1697
-	if (
1698
-		defined('_SAUVER_CHEMIN')
1699
-		and _SAUVER_CHEMIN
1700
-	) {
1701
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1702
-	}
1696
+    if (
1697
+        defined('_SAUVER_CHEMIN')
1698
+        and _SAUVER_CHEMIN
1699
+    ) {
1700
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1701
+    }
1703 1702
 }
1704 1703
 
1705 1704
 
@@ -1719,33 +1718,33 @@  discard block
 block discarded – undo
1719 1718
  * @return array
1720 1719
  */
1721 1720
 function find_all_in_path($dir, $pattern, $recurs = false) {
1722
-	$liste_fichiers = [];
1723
-	$maxfiles = 10000;
1724
-
1725
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1726
-	// on a pas encore inclus flock.php
1727
-	if (!function_exists('preg_files')) {
1728
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1729
-	}
1730
-
1731
-	// Parcourir le chemin
1732
-	foreach (creer_chemin() as $d) {
1733
-		$f = $d . $dir;
1734
-		if (@is_dir($f)) {
1735
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1736
-			foreach ($liste as $chemin) {
1737
-				$nom = basename($chemin);
1738
-				// ne prendre que les fichiers pas deja trouves
1739
-				// car find_in_path prend le premier qu'il trouve,
1740
-				// les autres sont donc masques
1741
-				if (!isset($liste_fichiers[$nom])) {
1742
-					$liste_fichiers[$nom] = $chemin;
1743
-				}
1744
-			}
1745
-		}
1746
-	}
1747
-
1748
-	return $liste_fichiers;
1721
+    $liste_fichiers = [];
1722
+    $maxfiles = 10000;
1723
+
1724
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1725
+    // on a pas encore inclus flock.php
1726
+    if (!function_exists('preg_files')) {
1727
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1728
+    }
1729
+
1730
+    // Parcourir le chemin
1731
+    foreach (creer_chemin() as $d) {
1732
+        $f = $d . $dir;
1733
+        if (@is_dir($f)) {
1734
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1735
+            foreach ($liste as $chemin) {
1736
+                $nom = basename($chemin);
1737
+                // ne prendre que les fichiers pas deja trouves
1738
+                // car find_in_path prend le premier qu'il trouve,
1739
+                // les autres sont donc masques
1740
+                if (!isset($liste_fichiers[$nom])) {
1741
+                    $liste_fichiers[$nom] = $chemin;
1742
+                }
1743
+            }
1744
+        }
1745
+    }
1746
+
1747
+    return $liste_fichiers;
1749 1748
 }
1750 1749
 
1751 1750
 /**
@@ -1757,17 +1756,17 @@  discard block
 block discarded – undo
1757 1756
  * @return bool
1758 1757
  */
1759 1758
 function autoriser_sans_cookie($nom, $strict = false) {
1760
-	static $autsanscookie = ['install', 'base_repair'];
1759
+    static $autsanscookie = ['install', 'base_repair'];
1761 1760
 
1762
-	if (in_array($nom, $autsanscookie)) {
1763
-		if (test_espace_prive()) {
1764
-			include_spip('base/connect_sql');
1765
-			if (!$strict or !spip_connect()) {
1766
-				return true;
1767
-			}
1768
-		}
1769
-	}
1770
-	return false;
1761
+    if (in_array($nom, $autsanscookie)) {
1762
+        if (test_espace_prive()) {
1763
+            include_spip('base/connect_sql');
1764
+            if (!$strict or !spip_connect()) {
1765
+                return true;
1766
+            }
1767
+        }
1768
+    }
1769
+    return false;
1771 1770
 }
1772 1771
 
1773 1772
 /**
@@ -1777,56 +1776,56 @@  discard block
 block discarded – undo
1777 1776
  * @return string
1778 1777
  */
1779 1778
 function charger_fonction_url(string $quoi, string $type = '') {
1780
-	if ($type === 'defaut') {
1781
-		$objet = objet_type($quoi);
1782
-		if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1783
-			// deprecated
1784
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1785
-		) {
1786
-			return $f;
1787
-		}
1788
-		return '';
1789
-	}
1790
-
1791
-	if (!$type) {
1792
-		$type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1793
-	}
1794
-
1795
-	// inclure le module d'url
1796
-	include_spip('urls/'.$type);
1797
-
1798
-	switch ($quoi) {
1799
-		case 'page':
1800
-			if (
1801
-				 function_exists($f = "urls_{$type}_generer_url_page")
1802
-			  or function_exists($f .= "_dist")
1803
-			  // ou une fonction custom utilisateur independante du type d'url
1804
-			  or function_exists($f = "generer_url_page")
1805
-			  or function_exists($f .= "_dist")
1806
-			) {
1807
-				return $f;
1808
-			}
1809
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1810
-			return '';
1811
-		case 'objet':
1812
-		case 'decoder':
1813
-		default:
1814
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1815
-			if (function_exists($f = "urls_{$type}_{$fquoi}")
1816
-			  or function_exists($f .= "_dist")) {
1817
-				return $f;
1818
-			}
1819
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1820
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1821
-			if ($f = charger_fonction($type, 'urls', true)) {
1822
-				return $f;
1823
-			}
1824
-			// sinon on se rabat sur les urls page
1825
-			if ($type !== 'page') {
1826
-				return charger_fonction_url($quoi, 'page');
1827
-			}
1828
-			return '';
1829
-	}
1779
+    if ($type === 'defaut') {
1780
+        $objet = objet_type($quoi);
1781
+        if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1782
+            // deprecated
1783
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1784
+        ) {
1785
+            return $f;
1786
+        }
1787
+        return '';
1788
+    }
1789
+
1790
+    if (!$type) {
1791
+        $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1792
+    }
1793
+
1794
+    // inclure le module d'url
1795
+    include_spip('urls/'.$type);
1796
+
1797
+    switch ($quoi) {
1798
+        case 'page':
1799
+            if (
1800
+                    function_exists($f = "urls_{$type}_generer_url_page")
1801
+              or function_exists($f .= "_dist")
1802
+                // ou une fonction custom utilisateur independante du type d'url
1803
+              or function_exists($f = "generer_url_page")
1804
+              or function_exists($f .= "_dist")
1805
+            ) {
1806
+                return $f;
1807
+            }
1808
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1809
+            return '';
1810
+        case 'objet':
1811
+        case 'decoder':
1812
+        default:
1813
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1814
+            if (function_exists($f = "urls_{$type}_{$fquoi}")
1815
+              or function_exists($f .= "_dist")) {
1816
+                return $f;
1817
+            }
1818
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1819
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1820
+            if ($f = charger_fonction($type, 'urls', true)) {
1821
+                return $f;
1822
+            }
1823
+            // sinon on se rabat sur les urls page
1824
+            if ($type !== 'page') {
1825
+                return charger_fonction_url($quoi, 'page');
1826
+            }
1827
+            return '';
1828
+    }
1830 1829
 }
1831 1830
 
1832 1831
 
@@ -1855,47 +1854,47 @@  discard block
 block discarded – undo
1855 1854
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire)
1856 1855
  */
1857 1856
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1858
-	if ($public === null) {
1859
-		$public = !test_espace_prive();
1860
-	}
1861
-	$id = intval($id);
1862
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1863
-
1864
-	if (!$public) {
1865
-		if (!$entite) {
1866
-			return '';
1867
-		}
1868
-		if (!function_exists('generer_objet_url_ecrire')) {
1869
-			include_spip('inc/urls');
1870
-		}
1871
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1872
-	} else {
1873
-		$f = charger_fonction_url('objet', $type ?? '');
1874
-
1875
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1876
-		// @see charger_fonction_url
1877
-		if (!$entite) {
1878
-			return $f;
1879
-		}
1880
-
1881
-		// mais d'abord il faut tester le cas des urls sur une
1882
-		// base distante
1883
-		if ($connect
1884
-			and $g = charger_fonction('connect', 'urls', true)
1885
-		) {
1886
-			$f = $g;
1887
-		}
1888
-
1889
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1890
-	}
1891
-	if ($res) {
1892
-		return $res;
1893
-	}
1894
-
1895
-	// On a ete gentil mais la ....
1896
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1897
-
1898
-	return '';
1857
+    if ($public === null) {
1858
+        $public = !test_espace_prive();
1859
+    }
1860
+    $id = intval($id);
1861
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1862
+
1863
+    if (!$public) {
1864
+        if (!$entite) {
1865
+            return '';
1866
+        }
1867
+        if (!function_exists('generer_objet_url_ecrire')) {
1868
+            include_spip('inc/urls');
1869
+        }
1870
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1871
+    } else {
1872
+        $f = charger_fonction_url('objet', $type ?? '');
1873
+
1874
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1875
+        // @see charger_fonction_url
1876
+        if (!$entite) {
1877
+            return $f;
1878
+        }
1879
+
1880
+        // mais d'abord il faut tester le cas des urls sur une
1881
+        // base distante
1882
+        if ($connect
1883
+            and $g = charger_fonction('connect', 'urls', true)
1884
+        ) {
1885
+            $f = $g;
1886
+        }
1887
+
1888
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1889
+    }
1890
+    if ($res) {
1891
+        return $res;
1892
+    }
1893
+
1894
+    // On a ete gentil mais la ....
1895
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1896
+
1897
+    return '';
1899 1898
 }
1900 1899
 
1901 1900
 /**
@@ -1903,10 +1902,10 @@  discard block
 block discarded – undo
1903 1902
  * @see generer_objet_url
1904 1903
  */
1905 1904
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null){
1906
-	if ($public and is_string($public)) {
1907
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1908
-	}
1909
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1905
+    if ($public and is_string($public)) {
1906
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1907
+    }
1908
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1910 1909
 }
1911 1910
 
1912 1911
 /**
@@ -1918,19 +1917,19 @@  discard block
 block discarded – undo
1918 1917
  * @return string
1919 1918
  */
1920 1919
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1921
-	$id = intval($id);
1922
-	$exec = objet_info($entite, 'url_edit');
1923
-	$url = generer_url_ecrire($exec, $args);
1924
-	if (intval($id)) {
1925
-		$url = parametre_url($url, id_table_objet($entite), $id);
1926
-	} else {
1927
-		$url = parametre_url($url, 'new', 'oui');
1928
-	}
1929
-	if ($ancre) {
1930
-		$url = ancre_url($url, $ancre);
1931
-	}
1920
+    $id = intval($id);
1921
+    $exec = objet_info($entite, 'url_edit');
1922
+    $url = generer_url_ecrire($exec, $args);
1923
+    if (intval($id)) {
1924
+        $url = parametre_url($url, id_table_objet($entite), $id);
1925
+    } else {
1926
+        $url = parametre_url($url, 'new', 'oui');
1927
+    }
1928
+    if ($ancre) {
1929
+        $url = ancre_url($url, $ancre);
1930
+    }
1932 1931
 
1933
-	return $url;
1932
+    return $url;
1934 1933
 }
1935 1934
 
1936 1935
 /**
@@ -1938,18 +1937,18 @@  discard block
 block discarded – undo
1938 1937
  * @see generer_objet_url_ecrire_edit
1939 1938
  */
1940 1939
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = ''){
1941
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1940
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1942 1941
 }
1943 1942
 
1944 1943
 
1945 1944
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1946
-	include_spip('base/connect_sql');
1947
-	$id_type = id_table_objet($entite, $public);
1945
+    include_spip('base/connect_sql');
1946
+    $id_type = id_table_objet($entite, $public);
1948 1947
 
1949
-	return _DIR_RACINE . get_spip_script('./')
1950
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1951
-	. (!$args ? '' : "&$args")
1952
-	. (!$ancre ? '' : "#$ancre");
1948
+    return _DIR_RACINE . get_spip_script('./')
1949
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1950
+    . (!$args ? '' : "&$args")
1951
+    . (!$ancre ? '' : "#$ancre");
1953 1952
 }
1954 1953
 
1955 1954
 
@@ -1960,18 +1959,18 @@  discard block
 block discarded – undo
1960 1959
  * @return string
1961 1960
  */
1962 1961
 function urlencode_1738($url) {
1963
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1964
-		$uri = '';
1965
-		for ($i = 0; $i < strlen($url); $i++) {
1966
-			if (ord($a = $url[$i]) > 127) {
1967
-				$a = rawurlencode($a);
1968
-			}
1969
-			$uri .= $a;
1970
-		}
1971
-		$url = $uri;
1972
-	}
1962
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1963
+        $uri = '';
1964
+        for ($i = 0; $i < strlen($url); $i++) {
1965
+            if (ord($a = $url[$i]) > 127) {
1966
+                $a = rawurlencode($a);
1967
+            }
1968
+            $uri .= $a;
1969
+        }
1970
+        $url = $uri;
1971
+    }
1973 1972
 
1974
-	return quote_amp($url);
1973
+    return quote_amp($url);
1975 1974
 }
1976 1975
 
1977 1976
 /**
@@ -1987,14 +1986,14 @@  discard block
 block discarded – undo
1987 1986
  * @return string
1988 1987
  */
1989 1988
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1990
-	$id = intval($id);
1991
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1992
-	if (!preg_match(',^\w+:,', $h)) {
1993
-		include_spip('inc/filtres_mini');
1994
-		$h = url_absolue($h);
1995
-	}
1989
+    $id = intval($id);
1990
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1991
+    if (!preg_match(',^\w+:,', $h)) {
1992
+        include_spip('inc/filtres_mini');
1993
+        $h = url_absolue($h);
1994
+    }
1996 1995
 
1997
-	return $h;
1996
+    return $h;
1998 1997
 }
1999 1998
 
2000 1999
 /**
@@ -2002,7 +2001,7 @@  discard block
 block discarded – undo
2002 2001
  * @see  generer_objet_url_absolue
2003 2002
  */
2004 2003
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null){
2005
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
2004
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
2006 2005
 }
2007 2006
 
2008 2007
 
@@ -2018,11 +2017,11 @@  discard block
 block discarded – undo
2018 2017
  *     true si la valeur est considérée active ; false sinon.
2019 2018
  **/
2020 2019
 function test_valeur_serveur($truc) {
2021
-	if (!$truc) {
2022
-		return false;
2023
-	}
2020
+    if (!$truc) {
2021
+        return false;
2022
+    }
2024 2023
 
2025
-	return (strtolower($truc) !== 'off');
2024
+    return (strtolower($truc) !== 'off');
2026 2025
 }
2027 2026
 
2028 2027
 //
@@ -2050,82 +2049,82 @@  discard block
 block discarded – undo
2050 2049
  */
2051 2050
 function url_de_base($profondeur = null) {
2052 2051
 
2053
-	static $url = [];
2054
-	if (is_array($profondeur)) {
2055
-		return $url = $profondeur;
2056
-	}
2057
-	if ($profondeur === false) {
2058
-		return $url;
2059
-	}
2060
-
2061
-	if (is_null($profondeur)) {
2062
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2063
-	}
2064
-
2065
-	if (isset($url[$profondeur])) {
2066
-		return $url[$profondeur];
2067
-	}
2068
-
2069
-	$http = 'http';
2070
-
2071
-	if (
2072
-		isset($_SERVER['SCRIPT_URI'])
2073
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2074
-	) {
2075
-		$http = 'https';
2076
-	} elseif (
2077
-		isset($_SERVER['HTTPS'])
2078
-		and test_valeur_serveur($_SERVER['HTTPS'])
2079
-	) {
2080
-		$http = 'https';
2081
-	}
2082
-
2083
-	// note : HTTP_HOST contient le :port si necessaire
2084
-	$host = $_SERVER['HTTP_HOST'] ?? null;
2085
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2086
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2087
-		$host = $GLOBALS['meta']['adresse_site'];
2088
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2089
-			$http = $scheme;
2090
-			$host = str_replace("{$scheme}://", '', $host);
2091
-		}
2092
-	}
2093
-	if (
2094
-		isset($_SERVER['SERVER_PORT'])
2095
-		and $port = $_SERVER['SERVER_PORT']
2096
-		and strpos($host, ':') == false
2097
-	) {
2098
-		if (!defined('_PORT_HTTP_STANDARD')) {
2099
-			define('_PORT_HTTP_STANDARD', '80');
2100
-		}
2101
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2102
-			define('_PORT_HTTPS_STANDARD', '443');
2103
-		}
2104
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2105
-			$host .= ":$port";
2106
-		}
2107
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2108
-			$host .= ":$port";
2109
-		}
2110
-	}
2111
-
2112
-	if (!$GLOBALS['REQUEST_URI']) {
2113
-		if (isset($_SERVER['REQUEST_URI'])) {
2114
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2115
-		} else {
2116
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2117
-			if (
2118
-				!empty($_SERVER['QUERY_STRING'])
2119
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2120
-			) {
2121
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2122
-			}
2123
-		}
2124
-	}
2125
-
2126
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2127
-
2128
-	return $url[$profondeur];
2052
+    static $url = [];
2053
+    if (is_array($profondeur)) {
2054
+        return $url = $profondeur;
2055
+    }
2056
+    if ($profondeur === false) {
2057
+        return $url;
2058
+    }
2059
+
2060
+    if (is_null($profondeur)) {
2061
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2062
+    }
2063
+
2064
+    if (isset($url[$profondeur])) {
2065
+        return $url[$profondeur];
2066
+    }
2067
+
2068
+    $http = 'http';
2069
+
2070
+    if (
2071
+        isset($_SERVER['SCRIPT_URI'])
2072
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2073
+    ) {
2074
+        $http = 'https';
2075
+    } elseif (
2076
+        isset($_SERVER['HTTPS'])
2077
+        and test_valeur_serveur($_SERVER['HTTPS'])
2078
+    ) {
2079
+        $http = 'https';
2080
+    }
2081
+
2082
+    // note : HTTP_HOST contient le :port si necessaire
2083
+    $host = $_SERVER['HTTP_HOST'] ?? null;
2084
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2085
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2086
+        $host = $GLOBALS['meta']['adresse_site'];
2087
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2088
+            $http = $scheme;
2089
+            $host = str_replace("{$scheme}://", '', $host);
2090
+        }
2091
+    }
2092
+    if (
2093
+        isset($_SERVER['SERVER_PORT'])
2094
+        and $port = $_SERVER['SERVER_PORT']
2095
+        and strpos($host, ':') == false
2096
+    ) {
2097
+        if (!defined('_PORT_HTTP_STANDARD')) {
2098
+            define('_PORT_HTTP_STANDARD', '80');
2099
+        }
2100
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2101
+            define('_PORT_HTTPS_STANDARD', '443');
2102
+        }
2103
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2104
+            $host .= ":$port";
2105
+        }
2106
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2107
+            $host .= ":$port";
2108
+        }
2109
+    }
2110
+
2111
+    if (!$GLOBALS['REQUEST_URI']) {
2112
+        if (isset($_SERVER['REQUEST_URI'])) {
2113
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2114
+        } else {
2115
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2116
+            if (
2117
+                !empty($_SERVER['QUERY_STRING'])
2118
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2119
+            ) {
2120
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2121
+            }
2122
+        }
2123
+    }
2124
+
2125
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2126
+
2127
+    return $url[$profondeur];
2129 2128
 }
2130 2129
 
2131 2130
 /**
@@ -2138,26 +2137,26 @@  discard block
 block discarded – undo
2138 2137
  * @return string
2139 2138
  */
2140 2139
 function url_de_($http, $host, $request, $prof = 0) {
2141
-	$prof = max($prof, 0);
2140
+    $prof = max($prof, 0);
2142 2141
 
2143
-	$myself = ltrim($request, '/');
2144
-	# supprimer la chaine de GET
2145
-	[$myself] = explode('?', $myself);
2146
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2147
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2148
-	if (strpos($myself, '://') !== false) {
2149
-		$myself = explode('://', $myself);
2150
-		array_shift($myself);
2151
-		$myself = implode('://', $myself);
2152
-		$myself = explode('/', $myself);
2153
-		array_shift($myself);
2154
-		$myself = implode('/', $myself);
2155
-	}
2156
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2142
+    $myself = ltrim($request, '/');
2143
+    # supprimer la chaine de GET
2144
+    [$myself] = explode('?', $myself);
2145
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2146
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2147
+    if (strpos($myself, '://') !== false) {
2148
+        $myself = explode('://', $myself);
2149
+        array_shift($myself);
2150
+        $myself = implode('://', $myself);
2151
+        $myself = explode('/', $myself);
2152
+        array_shift($myself);
2153
+        $myself = implode('/', $myself);
2154
+    }
2155
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2157 2156
 
2158
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2157
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2159 2158
 
2160
-	return $url;
2159
+    return $url;
2161 2160
 }
2162 2161
 
2163 2162
 
@@ -2192,25 +2191,25 @@  discard block
 block discarded – undo
2192 2191
  * @return string URL
2193 2192
  **/
2194 2193
 function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) {
2195
-	if (!$rel) {
2196
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2197
-	} else {
2198
-		if (!is_string($rel)) {
2199
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2200
-		}
2201
-	}
2202
-
2203
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2204
-	if ($script and ($script <> 'accueil' or $rel)) {
2205
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2206
-	} elseif ($args) {
2207
-		$args = "?$args";
2208
-	}
2209
-	if ($ancre) {
2210
-		$args .= "#$ancre";
2211
-	}
2212
-
2213
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2194
+    if (!$rel) {
2195
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2196
+    } else {
2197
+        if (!is_string($rel)) {
2198
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2199
+        }
2200
+    }
2201
+
2202
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2203
+    if ($script and ($script <> 'accueil' or $rel)) {
2204
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2205
+    } elseif ($args) {
2206
+        $args = "?$args";
2207
+    }
2208
+    if ($ancre) {
2209
+        $args .= "#$ancre";
2210
+    }
2211
+
2212
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2214 2213
 }
2215 2214
 
2216 2215
 //
@@ -2232,15 +2231,15 @@  discard block
 block discarded – undo
2232 2231
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2233 2232
  **/
2234 2233
 function get_spip_script($default = '') {
2235
-	if (!defined('_SPIP_SCRIPT')) {
2236
-		return 'spip.php';
2237
-	}
2238
-	# cas define('_SPIP_SCRIPT', '');
2239
-	if (_SPIP_SCRIPT) {
2240
-		return _SPIP_SCRIPT;
2241
-	} else {
2242
-		return $default;
2243
-	}
2234
+    if (!defined('_SPIP_SCRIPT')) {
2235
+        return 'spip.php';
2236
+    }
2237
+    # cas define('_SPIP_SCRIPT', '');
2238
+    if (_SPIP_SCRIPT) {
2239
+        return _SPIP_SCRIPT;
2240
+    } else {
2241
+        return $default;
2242
+    }
2244 2243
 }
2245 2244
 
2246 2245
 /**
@@ -2269,45 +2268,45 @@  discard block
 block discarded – undo
2269 2268
  * @return string URL
2270 2269
  **/
2271 2270
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2272
-	// si le script est une action (spip_pass, spip_inscription),
2273
-	// standardiser vers la nouvelle API
2274
-
2275
-	if (is_array($args)) {
2276
-		$args = http_build_query($args);
2277
-	}
2278
-
2279
-	$url = '';
2280
-	if ($f = charger_fonction_url('page')) {
2281
-		$url = $f($script, $args);
2282
-		if ($url and !$rel) {
2283
-			include_spip('inc/filtres_mini');
2284
-			$url = url_absolue($url);
2285
-		}
2286
-	}
2287
-	if (!$url) {
2288
-		if (!$action) {
2289
-			$action = get_spip_script();
2290
-		}
2291
-		if ($script) {
2292
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2293
-		}
2294
-		if ($args) {
2295
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2296
-		}
2297
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2298
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2299
-	}
2300
-
2301
-	if (!$no_entities) {
2302
-		$url = quote_amp($url);
2303
-	}
2304
-
2305
-	return $url;
2271
+    // si le script est une action (spip_pass, spip_inscription),
2272
+    // standardiser vers la nouvelle API
2273
+
2274
+    if (is_array($args)) {
2275
+        $args = http_build_query($args);
2276
+    }
2277
+
2278
+    $url = '';
2279
+    if ($f = charger_fonction_url('page')) {
2280
+        $url = $f($script, $args);
2281
+        if ($url and !$rel) {
2282
+            include_spip('inc/filtres_mini');
2283
+            $url = url_absolue($url);
2284
+        }
2285
+    }
2286
+    if (!$url) {
2287
+        if (!$action) {
2288
+            $action = get_spip_script();
2289
+        }
2290
+        if ($script) {
2291
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2292
+        }
2293
+        if ($args) {
2294
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2295
+        }
2296
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2297
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2298
+    }
2299
+
2300
+    if (!$no_entities) {
2301
+        $url = quote_amp($url);
2302
+    }
2303
+
2304
+    return $url;
2306 2305
 }
2307 2306
 
2308 2307
 function generer_url_prive($script, $args = '', $no_entities = false) {
2309 2308
 
2310
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2309
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2311 2310
 }
2312 2311
 
2313 2312
 // Pour les formulaires en methode POST,
@@ -2332,19 +2331,19 @@  discard block
 block discarded – undo
2332 2331
  **/
2333 2332
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2334 2333
 
2335
-	$script1 = explode('&', $script);
2336
-	$script1 = reset($script1);
2334
+    $script1 = explode('&', $script);
2335
+    $script1 = reset($script1);
2337 2336
 
2338
-	return "<form action='"
2339
-	. ($script ? generer_url_ecrire($script) : '')
2340
-	. "' "
2341
-	. ($atts ?: " method='post'")
2342
-	. "><div>\n"
2343
-	. "<input type='hidden' name='exec' value='$script1' />"
2344
-	. $corps
2345
-	. (!$submit ? '' :
2346
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2347
-	. "</div></form>\n";
2337
+    return "<form action='"
2338
+    . ($script ? generer_url_ecrire($script) : '')
2339
+    . "' "
2340
+    . ($atts ?: " method='post'")
2341
+    . "><div>\n"
2342
+    . "<input type='hidden' name='exec' value='$script1' />"
2343
+    . $corps
2344
+    . (!$submit ? '' :
2345
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2346
+    . "</div></form>\n";
2348 2347
 }
2349 2348
 
2350 2349
 /**
@@ -2361,22 +2360,22 @@  discard block
 block discarded – undo
2361 2360
  * @return string
2362 2361
  */
2363 2362
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2364
-	// si l'on est dans l'espace prive, on garde dans l'url
2365
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2366
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2367
-	$h = (_DIR_RACINE and !$public)
2368
-		? generer_url_ecrire(_request('exec'))
2369
-		: generer_url_public();
2363
+    // si l'on est dans l'espace prive, on garde dans l'url
2364
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2365
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2366
+    $h = (_DIR_RACINE and !$public)
2367
+        ? generer_url_ecrire(_request('exec'))
2368
+        : generer_url_public();
2370 2369
 
2371
-	return "\n<form action='" .
2372
-	$h .
2373
-	"'" .
2374
-	$atts .
2375
-	">\n" .
2376
-	'<div>' .
2377
-	"\n<input type='hidden' name='action' value='$script' />" .
2378
-	$corps .
2379
-	'</div></form>';
2370
+    return "\n<form action='" .
2371
+    $h .
2372
+    "'" .
2373
+    $atts .
2374
+    ">\n" .
2375
+    '<div>' .
2376
+    "\n<input type='hidden' name='action' value='$script' />" .
2377
+    $corps .
2378
+    '</div></form>';
2380 2379
 }
2381 2380
 
2382 2381
 /**
@@ -2395,22 +2394,22 @@  discard block
 block discarded – undo
2395 2394
  *     URL
2396 2395
  */
2397 2396
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2398
-	// si l'on est dans l'espace prive, on garde dans l'url
2399
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2400
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2401
-	$url = (_DIR_RACINE and !$public)
2402
-		? generer_url_ecrire(_request('exec'))
2403
-		: generer_url_public('', '', false, false);
2404
-	$url = parametre_url($url, 'action', $script);
2405
-	if ($args) {
2406
-		$url .= quote_amp('&' . $args);
2407
-	}
2397
+    // si l'on est dans l'espace prive, on garde dans l'url
2398
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2399
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2400
+    $url = (_DIR_RACINE and !$public)
2401
+        ? generer_url_ecrire(_request('exec'))
2402
+        : generer_url_public('', '', false, false);
2403
+    $url = parametre_url($url, 'action', $script);
2404
+    if ($args) {
2405
+        $url .= quote_amp('&' . $args);
2406
+    }
2408 2407
 
2409
-	if ($no_entities) {
2410
-		$url = str_replace('&amp;', '&', $url);
2411
-	}
2408
+    if ($no_entities) {
2409
+        $url = str_replace('&amp;', '&', $url);
2410
+    }
2412 2411
 
2413
-	return $url;
2412
+    return $url;
2414 2413
 }
2415 2414
 
2416 2415
 
@@ -2429,23 +2428,23 @@  discard block
 block discarded – undo
2429 2428
  *     URL
2430 2429
  */
2431 2430
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2432
-	if (is_null($public)) {
2433
-		$public = (_DIR_RACINE ? false : '');
2434
-	}
2435
-	if (substr($script, -4) !== '.api') {
2436
-		$script .= '.api';
2437
-	}
2438
-	$url =
2439
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2440
-	. $script . '/'
2441
-	. ($path ? trim($path, '/') : '')
2442
-	. ($args ? "?" . quote_amp($args) : '');
2431
+    if (is_null($public)) {
2432
+        $public = (_DIR_RACINE ? false : '');
2433
+    }
2434
+    if (substr($script, -4) !== '.api') {
2435
+        $script .= '.api';
2436
+    }
2437
+    $url =
2438
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2439
+    . $script . '/'
2440
+    . ($path ? trim($path, '/') : '')
2441
+    . ($args ? "?" . quote_amp($args) : '');
2443 2442
 
2444
-	if ($no_entities) {
2445
-		$url = str_replace('&amp;', '&', $url);
2446
-	}
2443
+    if ($no_entities) {
2444
+        $url = str_replace('&amp;', '&', $url);
2445
+    }
2447 2446
 
2448
-	return $url;
2447
+    return $url;
2449 2448
 }
2450 2449
 
2451 2450
 
@@ -2458,8 +2457,8 @@  discard block
 block discarded – undo
2458 2457
  * @param string $ta Répertoire temporaire accessible
2459 2458
  */
2460 2459
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2461
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2462
-	spip_initialisation_suite();
2460
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2461
+    spip_initialisation_suite();
2463 2462
 }
2464 2463
 
2465 2464
 /**
@@ -2479,322 +2478,322 @@  discard block
 block discarded – undo
2479 2478
  * @param string $ta Répertoire temporaire accessible
2480 2479
  */
2481 2480
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2482
-	static $too_late = 0;
2483
-	if ($too_late++) {
2484
-		return;
2485
-	}
2486
-
2487
-	// Declaration des repertoires
2488
-
2489
-	// le nom du repertoire plugins/ activables/desactivables
2490
-	if (!defined('_DIR_PLUGINS')) {
2491
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2492
-	}
2493
-
2494
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2495
-	if (!defined('_DIR_PLUGINS_DIST')) {
2496
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2497
-	}
2498
-
2499
-	// le nom du repertoire des librairies
2500
-	if (!defined('_DIR_LIB')) {
2501
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2502
-	}
2503
-
2504
-	if (!defined('_DIR_IMG')) {
2505
-		define('_DIR_IMG', $pa);
2506
-	}
2507
-	if (!defined('_DIR_LOGOS')) {
2508
-		define('_DIR_LOGOS', $pa);
2509
-	}
2510
-	if (!defined('_DIR_IMG_ICONES')) {
2511
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2512
-	}
2513
-
2514
-	if (!defined('_DIR_DUMP')) {
2515
-		define('_DIR_DUMP', $ti . 'dump/');
2516
-	}
2517
-	if (!defined('_DIR_SESSIONS')) {
2518
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2519
-	}
2520
-	if (!defined('_DIR_TRANSFERT')) {
2521
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2522
-	}
2523
-	if (!defined('_DIR_CACHE')) {
2524
-		define('_DIR_CACHE', $ti . 'cache/');
2525
-	}
2526
-	if (!defined('_DIR_CACHE_XML')) {
2527
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2528
-	}
2529
-	if (!defined('_DIR_SKELS')) {
2530
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2531
-	}
2532
-	if (!defined('_DIR_AIDE')) {
2533
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2534
-	}
2535
-	if (!defined('_DIR_TMP')) {
2536
-		define('_DIR_TMP', $ti);
2537
-	}
2538
-
2539
-	if (!defined('_DIR_VAR')) {
2540
-		define('_DIR_VAR', $ta);
2541
-	}
2542
-
2543
-	if (!defined('_DIR_ETC')) {
2544
-		define('_DIR_ETC', $pi);
2545
-	}
2546
-	if (!defined('_DIR_CONNECT')) {
2547
-		define('_DIR_CONNECT', $pi);
2548
-	}
2549
-	if (!defined('_DIR_CHMOD')) {
2550
-		define('_DIR_CHMOD', $pi);
2551
-	}
2552
-
2553
-	if (!isset($GLOBALS['test_dirs'])) {
2554
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2555
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2556
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2557
-	}
2558
-
2559
-	// Declaration des fichiers
2560
-
2561
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2562
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2563
-	}
2564
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2565
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2566
-	}
2567
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2568
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2569
-	}
2570
-	if (!defined('_CACHE_PIPELINES')) {
2571
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2572
-	}
2573
-	if (!defined('_CACHE_CHEMIN')) {
2574
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2575
-	}
2576
-
2577
-	# attention .php obligatoire pour ecrire_fichier_securise
2578
-	if (!defined('_FILE_META')) {
2579
-		define('_FILE_META', $ti . 'meta_cache.php');
2580
-	}
2581
-	if (!defined('_DIR_LOG')) {
2582
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2583
-	}
2584
-	if (!defined('_FILE_LOG')) {
2585
-		define('_FILE_LOG', 'spip');
2586
-	}
2587
-	if (!defined('_FILE_LOG_SUFFIX')) {
2588
-		define('_FILE_LOG_SUFFIX', '.log');
2589
-	}
2590
-
2591
-	// Le fichier de connexion a la base de donnees
2592
-	// tient compte des anciennes versions (inc_connect...)
2593
-	if (!defined('_FILE_CONNECT_INS')) {
2594
-		define('_FILE_CONNECT_INS', 'connect');
2595
-	}
2596
-	if (!defined('_FILE_CONNECT')) {
2597
-		define(
2598
-			'_FILE_CONNECT',
2599
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2600
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2601
-			: false))
2602
-		);
2603
-	}
2604
-
2605
-	// Le fichier de reglages des droits
2606
-	if (!defined('_FILE_CHMOD_INS')) {
2607
-		define('_FILE_CHMOD_INS', 'chmod');
2608
-	}
2609
-	if (!defined('_FILE_CHMOD')) {
2610
-		define(
2611
-			'_FILE_CHMOD',
2612
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2613
-			: false)
2614
-		);
2615
-	}
2616
-
2617
-	if (!defined('_FILE_LDAP')) {
2618
-		define('_FILE_LDAP', 'ldap.php');
2619
-	}
2620
-
2621
-	if (!defined('_FILE_TMP_SUFFIX')) {
2622
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2623
-	}
2624
-	if (!defined('_FILE_CONNECT_TMP')) {
2625
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2626
-	}
2627
-	if (!defined('_FILE_CHMOD_TMP')) {
2628
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2629
-	}
2630
-
2631
-	// Definition des droits d'acces en ecriture
2632
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2633
-		include_once _FILE_CHMOD;
2634
-	}
2635
-
2636
-	// Se mefier des fichiers mal remplis!
2637
-	if (!defined('_SPIP_CHMOD')) {
2638
-		define('_SPIP_CHMOD', 0777);
2639
-	}
2640
-
2641
-	if (!defined('_DEFAULT_CHARSET')) {
2642
-		/** Le charset par défaut lors de l'installation */
2643
-		define('_DEFAULT_CHARSET', 'utf-8');
2644
-	}
2645
-	if (!defined('_ROOT_PLUGINS')) {
2646
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2647
-	}
2648
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2649
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2650
-	}
2651
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2652
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2653
-	}
2654
-
2655
-	// La taille des Log
2656
-	if (!defined('_MAX_LOG')) {
2657
-		define('_MAX_LOG', 100);
2658
-	}
2659
-
2660
-	// Sommes-nous dans l'empire du Mal ?
2661
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2662
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2663
-		if (!defined('_OS_SERVEUR')) {
2664
-			define('_OS_SERVEUR', 'windows');
2665
-		}
2666
-		if (!defined('_SPIP_LOCK_MODE')) {
2667
-			define('_SPIP_LOCK_MODE', 1);
2668
-		} // utiliser le flock php
2669
-	} else {
2670
-		if (!defined('_OS_SERVEUR')) {
2671
-			define('_OS_SERVEUR', '');
2672
-		}
2673
-		if (!defined('_SPIP_LOCK_MODE')) {
2674
-			define('_SPIP_LOCK_MODE', 1);
2675
-		} // utiliser le flock php
2676
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2677
-	}
2678
-
2679
-	// Langue par defaut
2680
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2681
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2682
-	}
2683
-
2684
-	//
2685
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2686
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2687
-	// pour le rendre surchargeable, on va provoquer un reecriture
2688
-	// systematique du noyau ou une baisse de perfs => a etudier)
2689
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2690
-
2691
-	// charger tout de suite le path et son cache
2692
-	load_path_cache();
2693
-
2694
-	// *********** traiter les variables ************
2695
-
2696
-	//
2697
-	// Securite
2698
-	//
2699
-
2700
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2701
-	if (isset($_REQUEST['GLOBALS'])) {
2702
-		die();
2703
-	}
2704
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2705
-	spip_desinfecte($_GET);
2706
-	spip_desinfecte($_POST);
2707
-	spip_desinfecte($_COOKIE);
2708
-	spip_desinfecte($_REQUEST);
2709
-
2710
-	// appliquer le cookie_prefix
2711
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2712
-		include_spip('inc/cookie');
2713
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2714
-	}
2715
-
2716
-	//
2717
-	// Capacites php (en fonction de la version)
2718
-	//
2719
-	$GLOBALS['flag_ob'] = (function_exists('ob_start')
2720
-		&& function_exists('ini_get')
2721
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2722
-	$GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2723
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2724
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2725
-		(get_cfg_var('upload_max_filesize') > 0));
2726
-
2727
-
2728
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2729
-	if (isset($_SERVER['REQUEST_URI'])) {
2730
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2731
-	} else {
2732
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2733
-		if (
2734
-			!empty($_SERVER['QUERY_STRING'])
2735
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2736
-		) {
2737
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2738
-		}
2739
-	}
2740
-
2741
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2742
-	if (!defined('_RENOUVELLE_ALEA')) {
2743
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2744
-	}
2745
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2746
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2747
-	}
2748
-
2749
-	// charger les meta si possible et renouveller l'alea au besoin
2750
-	// charge aussi effacer_meta et ecrire_meta
2751
-	$inc_meta = charger_fonction('meta', 'inc');
2752
-	$inc_meta();
2753
-
2754
-	// nombre de repertoires depuis la racine
2755
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2756
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2757
-	// le calcul est faux)
2758
-	if (!_DIR_RESTREINT) {
2759
-		$GLOBALS['profondeur_url'] = 1;
2760
-	} else {
2761
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2762
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2763
-		if (
2764
-			!$uri_ref
2765
-			// si on est appele avec un autre ti, on est sans doute en mutu
2766
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2767
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2768
-			// s'en remettre a l'adresse du site. alea jacta est.
2769
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2770
-		) {
2771
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2772
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2773
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2774
-			} else {
2775
-				$uri_ref = '';
2776
-			}
2777
-		}
2778
-		if (!$uri or !$uri_ref) {
2779
-			$GLOBALS['profondeur_url'] = 0;
2780
-		} else {
2781
-			$GLOBALS['profondeur_url'] = max(
2782
-				0,
2783
-				substr_count($uri[0], '/')
2784
-				- substr_count($uri_ref, '/')
2785
-			);
2786
-		}
2787
-	}
2788
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2789
-	if (_FILE_CONNECT) {
2790
-		if (
2791
-			verifier_visiteur() == '0minirezo'
2792
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2793
-			and !isset($_COOKIE['spip_admin'])
2794
-		) {
2795
-			clear_path_cache();
2796
-		}
2797
-	}
2481
+    static $too_late = 0;
2482
+    if ($too_late++) {
2483
+        return;
2484
+    }
2485
+
2486
+    // Declaration des repertoires
2487
+
2488
+    // le nom du repertoire plugins/ activables/desactivables
2489
+    if (!defined('_DIR_PLUGINS')) {
2490
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2491
+    }
2492
+
2493
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2494
+    if (!defined('_DIR_PLUGINS_DIST')) {
2495
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2496
+    }
2497
+
2498
+    // le nom du repertoire des librairies
2499
+    if (!defined('_DIR_LIB')) {
2500
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2501
+    }
2502
+
2503
+    if (!defined('_DIR_IMG')) {
2504
+        define('_DIR_IMG', $pa);
2505
+    }
2506
+    if (!defined('_DIR_LOGOS')) {
2507
+        define('_DIR_LOGOS', $pa);
2508
+    }
2509
+    if (!defined('_DIR_IMG_ICONES')) {
2510
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2511
+    }
2512
+
2513
+    if (!defined('_DIR_DUMP')) {
2514
+        define('_DIR_DUMP', $ti . 'dump/');
2515
+    }
2516
+    if (!defined('_DIR_SESSIONS')) {
2517
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2518
+    }
2519
+    if (!defined('_DIR_TRANSFERT')) {
2520
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2521
+    }
2522
+    if (!defined('_DIR_CACHE')) {
2523
+        define('_DIR_CACHE', $ti . 'cache/');
2524
+    }
2525
+    if (!defined('_DIR_CACHE_XML')) {
2526
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2527
+    }
2528
+    if (!defined('_DIR_SKELS')) {
2529
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2530
+    }
2531
+    if (!defined('_DIR_AIDE')) {
2532
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2533
+    }
2534
+    if (!defined('_DIR_TMP')) {
2535
+        define('_DIR_TMP', $ti);
2536
+    }
2537
+
2538
+    if (!defined('_DIR_VAR')) {
2539
+        define('_DIR_VAR', $ta);
2540
+    }
2541
+
2542
+    if (!defined('_DIR_ETC')) {
2543
+        define('_DIR_ETC', $pi);
2544
+    }
2545
+    if (!defined('_DIR_CONNECT')) {
2546
+        define('_DIR_CONNECT', $pi);
2547
+    }
2548
+    if (!defined('_DIR_CHMOD')) {
2549
+        define('_DIR_CHMOD', $pi);
2550
+    }
2551
+
2552
+    if (!isset($GLOBALS['test_dirs'])) {
2553
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2554
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2555
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2556
+    }
2557
+
2558
+    // Declaration des fichiers
2559
+
2560
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2561
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2562
+    }
2563
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2564
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2565
+    }
2566
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2567
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2568
+    }
2569
+    if (!defined('_CACHE_PIPELINES')) {
2570
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2571
+    }
2572
+    if (!defined('_CACHE_CHEMIN')) {
2573
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2574
+    }
2575
+
2576
+    # attention .php obligatoire pour ecrire_fichier_securise
2577
+    if (!defined('_FILE_META')) {
2578
+        define('_FILE_META', $ti . 'meta_cache.php');
2579
+    }
2580
+    if (!defined('_DIR_LOG')) {
2581
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2582
+    }
2583
+    if (!defined('_FILE_LOG')) {
2584
+        define('_FILE_LOG', 'spip');
2585
+    }
2586
+    if (!defined('_FILE_LOG_SUFFIX')) {
2587
+        define('_FILE_LOG_SUFFIX', '.log');
2588
+    }
2589
+
2590
+    // Le fichier de connexion a la base de donnees
2591
+    // tient compte des anciennes versions (inc_connect...)
2592
+    if (!defined('_FILE_CONNECT_INS')) {
2593
+        define('_FILE_CONNECT_INS', 'connect');
2594
+    }
2595
+    if (!defined('_FILE_CONNECT')) {
2596
+        define(
2597
+            '_FILE_CONNECT',
2598
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2599
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2600
+            : false))
2601
+        );
2602
+    }
2603
+
2604
+    // Le fichier de reglages des droits
2605
+    if (!defined('_FILE_CHMOD_INS')) {
2606
+        define('_FILE_CHMOD_INS', 'chmod');
2607
+    }
2608
+    if (!defined('_FILE_CHMOD')) {
2609
+        define(
2610
+            '_FILE_CHMOD',
2611
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2612
+            : false)
2613
+        );
2614
+    }
2615
+
2616
+    if (!defined('_FILE_LDAP')) {
2617
+        define('_FILE_LDAP', 'ldap.php');
2618
+    }
2619
+
2620
+    if (!defined('_FILE_TMP_SUFFIX')) {
2621
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2622
+    }
2623
+    if (!defined('_FILE_CONNECT_TMP')) {
2624
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2625
+    }
2626
+    if (!defined('_FILE_CHMOD_TMP')) {
2627
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2628
+    }
2629
+
2630
+    // Definition des droits d'acces en ecriture
2631
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2632
+        include_once _FILE_CHMOD;
2633
+    }
2634
+
2635
+    // Se mefier des fichiers mal remplis!
2636
+    if (!defined('_SPIP_CHMOD')) {
2637
+        define('_SPIP_CHMOD', 0777);
2638
+    }
2639
+
2640
+    if (!defined('_DEFAULT_CHARSET')) {
2641
+        /** Le charset par défaut lors de l'installation */
2642
+        define('_DEFAULT_CHARSET', 'utf-8');
2643
+    }
2644
+    if (!defined('_ROOT_PLUGINS')) {
2645
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2646
+    }
2647
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2648
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2649
+    }
2650
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2651
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2652
+    }
2653
+
2654
+    // La taille des Log
2655
+    if (!defined('_MAX_LOG')) {
2656
+        define('_MAX_LOG', 100);
2657
+    }
2658
+
2659
+    // Sommes-nous dans l'empire du Mal ?
2660
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2661
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2662
+        if (!defined('_OS_SERVEUR')) {
2663
+            define('_OS_SERVEUR', 'windows');
2664
+        }
2665
+        if (!defined('_SPIP_LOCK_MODE')) {
2666
+            define('_SPIP_LOCK_MODE', 1);
2667
+        } // utiliser le flock php
2668
+    } else {
2669
+        if (!defined('_OS_SERVEUR')) {
2670
+            define('_OS_SERVEUR', '');
2671
+        }
2672
+        if (!defined('_SPIP_LOCK_MODE')) {
2673
+            define('_SPIP_LOCK_MODE', 1);
2674
+        } // utiliser le flock php
2675
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2676
+    }
2677
+
2678
+    // Langue par defaut
2679
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2680
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2681
+    }
2682
+
2683
+    //
2684
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2685
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2686
+    // pour le rendre surchargeable, on va provoquer un reecriture
2687
+    // systematique du noyau ou une baisse de perfs => a etudier)
2688
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2689
+
2690
+    // charger tout de suite le path et son cache
2691
+    load_path_cache();
2692
+
2693
+    // *********** traiter les variables ************
2694
+
2695
+    //
2696
+    // Securite
2697
+    //
2698
+
2699
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2700
+    if (isset($_REQUEST['GLOBALS'])) {
2701
+        die();
2702
+    }
2703
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2704
+    spip_desinfecte($_GET);
2705
+    spip_desinfecte($_POST);
2706
+    spip_desinfecte($_COOKIE);
2707
+    spip_desinfecte($_REQUEST);
2708
+
2709
+    // appliquer le cookie_prefix
2710
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2711
+        include_spip('inc/cookie');
2712
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2713
+    }
2714
+
2715
+    //
2716
+    // Capacites php (en fonction de la version)
2717
+    //
2718
+    $GLOBALS['flag_ob'] = (function_exists('ob_start')
2719
+        && function_exists('ini_get')
2720
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2721
+    $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2722
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2723
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2724
+        (get_cfg_var('upload_max_filesize') > 0));
2725
+
2726
+
2727
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2728
+    if (isset($_SERVER['REQUEST_URI'])) {
2729
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2730
+    } else {
2731
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2732
+        if (
2733
+            !empty($_SERVER['QUERY_STRING'])
2734
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2735
+        ) {
2736
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2737
+        }
2738
+    }
2739
+
2740
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2741
+    if (!defined('_RENOUVELLE_ALEA')) {
2742
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2743
+    }
2744
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2745
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2746
+    }
2747
+
2748
+    // charger les meta si possible et renouveller l'alea au besoin
2749
+    // charge aussi effacer_meta et ecrire_meta
2750
+    $inc_meta = charger_fonction('meta', 'inc');
2751
+    $inc_meta();
2752
+
2753
+    // nombre de repertoires depuis la racine
2754
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2755
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2756
+    // le calcul est faux)
2757
+    if (!_DIR_RESTREINT) {
2758
+        $GLOBALS['profondeur_url'] = 1;
2759
+    } else {
2760
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2761
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2762
+        if (
2763
+            !$uri_ref
2764
+            // si on est appele avec un autre ti, on est sans doute en mutu
2765
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2766
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2767
+            // s'en remettre a l'adresse du site. alea jacta est.
2768
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2769
+        ) {
2770
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2771
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2772
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2773
+            } else {
2774
+                $uri_ref = '';
2775
+            }
2776
+        }
2777
+        if (!$uri or !$uri_ref) {
2778
+            $GLOBALS['profondeur_url'] = 0;
2779
+        } else {
2780
+            $GLOBALS['profondeur_url'] = max(
2781
+                0,
2782
+                substr_count($uri[0], '/')
2783
+                - substr_count($uri_ref, '/')
2784
+            );
2785
+        }
2786
+    }
2787
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2788
+    if (_FILE_CONNECT) {
2789
+        if (
2790
+            verifier_visiteur() == '0minirezo'
2791
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2792
+            and !isset($_COOKIE['spip_admin'])
2793
+        ) {
2794
+            clear_path_cache();
2795
+        }
2796
+    }
2798 2797
 }
2799 2798
 
2800 2799
 /**
@@ -2803,157 +2802,157 @@  discard block
 block discarded – undo
2803 2802
  *
2804 2803
  */
2805 2804
 function spip_initialisation_suite() {
2806
-	static $too_late = 0;
2807
-	if ($too_late++) {
2808
-		return;
2809
-	}
2810
-
2811
-	// taille mini des login
2812
-	if (!defined('_LOGIN_TROP_COURT')) {
2813
-		define('_LOGIN_TROP_COURT', 4);
2814
-	}
2815
-
2816
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2817
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2818
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2819
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2820
-
2821
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2822
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2823
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2824
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2825
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2826
-
2827
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2828
-		define('_PASS_LONGUEUR_MINI', 6);
2829
-	}
2830
-
2831
-	// largeur maximale des images dans l'administration
2832
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2833
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2834
-	}
2835
-
2836
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2837
-	if (!defined('_IMG_QUALITE')) {
2838
-		define('_IMG_QUALITE', 85);
2839
-	} # valeur par defaut
2840
-	if (!defined('_IMG_GD_QUALITE')) {
2841
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2842
-	} # surcharge pour la lib GD
2843
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2844
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2845
-	} # surcharge pour imagick en ligne de commande
2846
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2847
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2848
-		define('_IMG_IMAGICK_QUALITE', 75);
2849
-	} # surcharge pour imagick en PHP
2850
-
2851
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2852
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2853
-	} // poids en octet
2854
-
2855
-	// qq chaines standard
2856
-	if (!defined('_ACCESS_FILE_NAME')) {
2857
-		define('_ACCESS_FILE_NAME', '.htaccess');
2858
-	}
2859
-	if (!defined('_AUTH_USER_FILE')) {
2860
-		define('_AUTH_USER_FILE', '.htpasswd');
2861
-	}
2862
-	if (!defined('_SPIP_DUMP')) {
2863
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2864
-	}
2865
-	if (!defined('_CACHE_RUBRIQUES')) {
2866
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2867
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2868
-	}
2869
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2870
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2871
-		define('_CACHE_RUBRIQUES_MAX', 500);
2872
-	}
2873
-
2874
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2875
-		/**
2876
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2877
-		 * @var int Nombre de caractères */
2878
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2879
-	}
2880
-
2881
-	if (!defined('_EXTENSION_SQUELETTES')) {
2882
-		define('_EXTENSION_SQUELETTES', 'html');
2883
-	}
2884
-
2885
-	if (!defined('_DOCTYPE_ECRIRE')) {
2886
-		/** Définit le doctype de l’espace privé */
2887
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2888
-	}
2889
-	if (!defined('_DOCTYPE_AIDE')) {
2890
-		/** Définit le doctype de l’aide en ligne */
2891
-		define(
2892
-			'_DOCTYPE_AIDE',
2893
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2894
-		);
2895
-	}
2896
-
2897
-	if (!defined('_SPIP_SCRIPT')) {
2898
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2899
-		 * le script de l'espace public, alias index.php */
2900
-		define('_SPIP_SCRIPT', 'spip.php');
2901
-	}
2902
-	if (!defined('_SPIP_PAGE')) {
2903
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2904
-		define('_SPIP_PAGE', 'page');
2905
-	}
2906
-
2907
-	// le script de l'espace prive
2908
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2909
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2910
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2911
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2912
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2913
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2914
-		} else {
2915
-			define('_SPIP_ECRIRE_SCRIPT', '');
2916
-		}
2917
-	}
2918
-
2919
-
2920
-	if (!defined('_SPIP_AJAX')) {
2921
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2922
-			? 1
2923
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2924
-	}
2925
-
2926
-	// La requete est-elle en ajax ?
2927
-	if (!defined('_AJAX')) {
2928
-		define(
2929
-			'_AJAX',
2930
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2931
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2932
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2933
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2934
-			)
2935
-			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
2936
-		);
2937
-	}
2938
-
2939
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2940
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2941
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2942
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2943
-		define(
2944
-			'_IMG_GD_MAX_PIXELS',
2945
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2946
-			? $GLOBALS['meta']['max_taille_vignettes']
2947
-			: 0
2948
-		);
2949
-	}
2950
-
2951
-	// Protocoles a normaliser dans les chaines de langues
2952
-	if (!defined('_PROTOCOLES_STD')) {
2953
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2954
-	}
2955
-
2956
-	init_var_mode();
2805
+    static $too_late = 0;
2806
+    if ($too_late++) {
2807
+        return;
2808
+    }
2809
+
2810
+    // taille mini des login
2811
+    if (!defined('_LOGIN_TROP_COURT')) {
2812
+        define('_LOGIN_TROP_COURT', 4);
2813
+    }
2814
+
2815
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2816
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2817
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2818
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2819
+
2820
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2821
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2822
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2823
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2824
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2825
+
2826
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2827
+        define('_PASS_LONGUEUR_MINI', 6);
2828
+    }
2829
+
2830
+    // largeur maximale des images dans l'administration
2831
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2832
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2833
+    }
2834
+
2835
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2836
+    if (!defined('_IMG_QUALITE')) {
2837
+        define('_IMG_QUALITE', 85);
2838
+    } # valeur par defaut
2839
+    if (!defined('_IMG_GD_QUALITE')) {
2840
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2841
+    } # surcharge pour la lib GD
2842
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2843
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2844
+    } # surcharge pour imagick en ligne de commande
2845
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2846
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2847
+        define('_IMG_IMAGICK_QUALITE', 75);
2848
+    } # surcharge pour imagick en PHP
2849
+
2850
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2851
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2852
+    } // poids en octet
2853
+
2854
+    // qq chaines standard
2855
+    if (!defined('_ACCESS_FILE_NAME')) {
2856
+        define('_ACCESS_FILE_NAME', '.htaccess');
2857
+    }
2858
+    if (!defined('_AUTH_USER_FILE')) {
2859
+        define('_AUTH_USER_FILE', '.htpasswd');
2860
+    }
2861
+    if (!defined('_SPIP_DUMP')) {
2862
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2863
+    }
2864
+    if (!defined('_CACHE_RUBRIQUES')) {
2865
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2866
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2867
+    }
2868
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2869
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2870
+        define('_CACHE_RUBRIQUES_MAX', 500);
2871
+    }
2872
+
2873
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2874
+        /**
2875
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2876
+         * @var int Nombre de caractères */
2877
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2878
+    }
2879
+
2880
+    if (!defined('_EXTENSION_SQUELETTES')) {
2881
+        define('_EXTENSION_SQUELETTES', 'html');
2882
+    }
2883
+
2884
+    if (!defined('_DOCTYPE_ECRIRE')) {
2885
+        /** Définit le doctype de l’espace privé */
2886
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2887
+    }
2888
+    if (!defined('_DOCTYPE_AIDE')) {
2889
+        /** Définit le doctype de l’aide en ligne */
2890
+        define(
2891
+            '_DOCTYPE_AIDE',
2892
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2893
+        );
2894
+    }
2895
+
2896
+    if (!defined('_SPIP_SCRIPT')) {
2897
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2898
+         * le script de l'espace public, alias index.php */
2899
+        define('_SPIP_SCRIPT', 'spip.php');
2900
+    }
2901
+    if (!defined('_SPIP_PAGE')) {
2902
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2903
+        define('_SPIP_PAGE', 'page');
2904
+    }
2905
+
2906
+    // le script de l'espace prive
2907
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2908
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2909
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2910
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2911
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2912
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2913
+        } else {
2914
+            define('_SPIP_ECRIRE_SCRIPT', '');
2915
+        }
2916
+    }
2917
+
2918
+
2919
+    if (!defined('_SPIP_AJAX')) {
2920
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2921
+            ? 1
2922
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2923
+    }
2924
+
2925
+    // La requete est-elle en ajax ?
2926
+    if (!defined('_AJAX')) {
2927
+        define(
2928
+            '_AJAX',
2929
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2930
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2931
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2932
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2933
+            )
2934
+            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
2935
+        );
2936
+    }
2937
+
2938
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2939
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2940
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2941
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2942
+        define(
2943
+            '_IMG_GD_MAX_PIXELS',
2944
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2945
+            ? $GLOBALS['meta']['max_taille_vignettes']
2946
+            : 0
2947
+        );
2948
+    }
2949
+
2950
+    // Protocoles a normaliser dans les chaines de langues
2951
+    if (!defined('_PROTOCOLES_STD')) {
2952
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2953
+    }
2954
+
2955
+    init_var_mode();
2957 2956
 }
2958 2957
 
2959 2958
 /**
@@ -2987,219 +2986,219 @@  discard block
 block discarded – undo
2987 2986
  * `   var_mode` (calcul ou recalcul).
2988 2987
  */
2989 2988
 function init_var_mode() {
2990
-	static $done = false;
2991
-	if (!$done) {
2992
-		if (isset($_GET['var_mode'])) {
2993
-			$var_mode = explode(',', $_GET['var_mode']);
2994
-			// tout le monde peut calcul/recalcul
2995
-			if (!defined('_VAR_MODE')) {
2996
-				if (in_array('recalcul', $var_mode)) {
2997
-					define('_VAR_MODE', 'recalcul');
2998
-				} elseif (in_array('calcul', $var_mode)) {
2999
-					define('_VAR_MODE', 'calcul');
3000
-				}
3001
-			}
3002
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3003
-			if ($var_mode) {
3004
-				include_spip('inc/autoriser');
3005
-				// autoriser preview si preview seulement, et sinon autoriser debug
3006
-				if (
3007
-					autoriser(
3008
-						($_GET['var_mode'] == 'preview')
3009
-						? 'previsualiser'
3010
-						: 'debug'
3011
-					)
3012
-				) {
3013
-					if (in_array('traduction', $var_mode)) {
3014
-						// forcer le calcul pour passer dans traduire
3015
-						if (!defined('_VAR_MODE')) {
3016
-							define('_VAR_MODE', 'calcul');
3017
-						}
3018
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3019
-						if (!defined('_VAR_NOCACHE')) {
3020
-							define('_VAR_NOCACHE', true);
3021
-						}
3022
-						$var_mode = array_diff($var_mode, ['traduction']);
3023
-					}
3024
-					if (in_array('preview', $var_mode)) {
3025
-						// basculer sur les criteres de preview dans les boucles
3026
-						if (!defined('_VAR_PREVIEW')) {
3027
-							define('_VAR_PREVIEW', true);
3028
-						}
3029
-						// forcer le calcul
3030
-						if (!defined('_VAR_MODE')) {
3031
-							define('_VAR_MODE', 'calcul');
3032
-						}
3033
-						// et ne pas enregistrer de cache
3034
-						if (!defined('_VAR_NOCACHE')) {
3035
-							define('_VAR_NOCACHE', true);
3036
-						}
3037
-						$var_mode = array_diff($var_mode, ['preview']);
3038
-					}
3039
-					if (in_array('inclure', $var_mode)) {
3040
-						// forcer le compilo et ignorer les caches existants
3041
-						if (!defined('_VAR_MODE')) {
3042
-							define('_VAR_MODE', 'calcul');
3043
-						}
3044
-						if (!defined('_VAR_INCLURE')) {
3045
-							define('_VAR_INCLURE', true);
3046
-						}
3047
-						// et ne pas enregistrer de cache
3048
-						if (!defined('_VAR_NOCACHE')) {
3049
-							define('_VAR_NOCACHE', true);
3050
-						}
3051
-						$var_mode = array_diff($var_mode, ['inclure']);
3052
-					}
3053
-					if (in_array('urls', $var_mode)) {
3054
-						// forcer le compilo et ignorer les caches existants
3055
-						if (!defined('_VAR_MODE')) {
3056
-							define('_VAR_MODE', 'calcul');
3057
-						}
3058
-						if (!defined('_VAR_URLS')) {
3059
-							define('_VAR_URLS', true);
3060
-						}
3061
-						$var_mode = array_diff($var_mode, ['urls']);
3062
-					}
3063
-					if (in_array('images', $var_mode)) {
3064
-						// forcer le compilo et ignorer les caches existants
3065
-						if (!defined('_VAR_MODE')) {
3066
-							define('_VAR_MODE', 'calcul');
3067
-						}
3068
-						// indiquer qu'on doit recalculer les images
3069
-						if (!defined('_VAR_IMAGES')) {
3070
-							define('_VAR_IMAGES', true);
3071
-						}
3072
-						$var_mode = array_diff($var_mode, ['images']);
3073
-					}
3074
-					if (in_array('debug', $var_mode)) {
3075
-						if (!defined('_VAR_MODE')) {
3076
-							define('_VAR_MODE', 'debug');
3077
-						}
3078
-						// et ne pas enregistrer de cache
3079
-						if (!defined('_VAR_NOCACHE')) {
3080
-							define('_VAR_NOCACHE', true);
3081
-						}
3082
-						$var_mode = array_diff($var_mode, ['debug']);
3083
-					}
3084
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3085
-						define('_VAR_MODE', reset($var_mode));
3086
-					}
3087
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3088
-						spip_log($GLOBALS['visiteur_session']['nom']
3089
-							. ' ' . _VAR_MODE);
3090
-					}
3091
-				} // pas autorise ?
3092
-				else {
3093
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3094
-					if (
3095
-						!$GLOBALS['visiteur_session']
3096
-						and !empty($_SERVER['HTTP_HOST'])
3097
-						and !empty($_SERVER['REQUEST_METHOD'])
3098
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3099
-					) {
3100
-						$self = self('&', true);
3101
-						if (strpos($self, 'page=login') === false) {
3102
-							include_spip('inc/headers');
3103
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3104
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3105
-						}
3106
-					}
3107
-					// sinon tant pis
3108
-				}
3109
-			}
3110
-		}
3111
-		if (!defined('_VAR_MODE')) {
3112
-			/**
3113
-			 * Indique le mode de calcul ou d'affichage de la page.
3114
-			 * @see init_var_mode()
3115
-			 */
3116
-			define('_VAR_MODE', false);
3117
-		}
3118
-		$done = true;
3119
-	}
2989
+    static $done = false;
2990
+    if (!$done) {
2991
+        if (isset($_GET['var_mode'])) {
2992
+            $var_mode = explode(',', $_GET['var_mode']);
2993
+            // tout le monde peut calcul/recalcul
2994
+            if (!defined('_VAR_MODE')) {
2995
+                if (in_array('recalcul', $var_mode)) {
2996
+                    define('_VAR_MODE', 'recalcul');
2997
+                } elseif (in_array('calcul', $var_mode)) {
2998
+                    define('_VAR_MODE', 'calcul');
2999
+                }
3000
+            }
3001
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3002
+            if ($var_mode) {
3003
+                include_spip('inc/autoriser');
3004
+                // autoriser preview si preview seulement, et sinon autoriser debug
3005
+                if (
3006
+                    autoriser(
3007
+                        ($_GET['var_mode'] == 'preview')
3008
+                        ? 'previsualiser'
3009
+                        : 'debug'
3010
+                    )
3011
+                ) {
3012
+                    if (in_array('traduction', $var_mode)) {
3013
+                        // forcer le calcul pour passer dans traduire
3014
+                        if (!defined('_VAR_MODE')) {
3015
+                            define('_VAR_MODE', 'calcul');
3016
+                        }
3017
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3018
+                        if (!defined('_VAR_NOCACHE')) {
3019
+                            define('_VAR_NOCACHE', true);
3020
+                        }
3021
+                        $var_mode = array_diff($var_mode, ['traduction']);
3022
+                    }
3023
+                    if (in_array('preview', $var_mode)) {
3024
+                        // basculer sur les criteres de preview dans les boucles
3025
+                        if (!defined('_VAR_PREVIEW')) {
3026
+                            define('_VAR_PREVIEW', true);
3027
+                        }
3028
+                        // forcer le calcul
3029
+                        if (!defined('_VAR_MODE')) {
3030
+                            define('_VAR_MODE', 'calcul');
3031
+                        }
3032
+                        // et ne pas enregistrer de cache
3033
+                        if (!defined('_VAR_NOCACHE')) {
3034
+                            define('_VAR_NOCACHE', true);
3035
+                        }
3036
+                        $var_mode = array_diff($var_mode, ['preview']);
3037
+                    }
3038
+                    if (in_array('inclure', $var_mode)) {
3039
+                        // forcer le compilo et ignorer les caches existants
3040
+                        if (!defined('_VAR_MODE')) {
3041
+                            define('_VAR_MODE', 'calcul');
3042
+                        }
3043
+                        if (!defined('_VAR_INCLURE')) {
3044
+                            define('_VAR_INCLURE', true);
3045
+                        }
3046
+                        // et ne pas enregistrer de cache
3047
+                        if (!defined('_VAR_NOCACHE')) {
3048
+                            define('_VAR_NOCACHE', true);
3049
+                        }
3050
+                        $var_mode = array_diff($var_mode, ['inclure']);
3051
+                    }
3052
+                    if (in_array('urls', $var_mode)) {
3053
+                        // forcer le compilo et ignorer les caches existants
3054
+                        if (!defined('_VAR_MODE')) {
3055
+                            define('_VAR_MODE', 'calcul');
3056
+                        }
3057
+                        if (!defined('_VAR_URLS')) {
3058
+                            define('_VAR_URLS', true);
3059
+                        }
3060
+                        $var_mode = array_diff($var_mode, ['urls']);
3061
+                    }
3062
+                    if (in_array('images', $var_mode)) {
3063
+                        // forcer le compilo et ignorer les caches existants
3064
+                        if (!defined('_VAR_MODE')) {
3065
+                            define('_VAR_MODE', 'calcul');
3066
+                        }
3067
+                        // indiquer qu'on doit recalculer les images
3068
+                        if (!defined('_VAR_IMAGES')) {
3069
+                            define('_VAR_IMAGES', true);
3070
+                        }
3071
+                        $var_mode = array_diff($var_mode, ['images']);
3072
+                    }
3073
+                    if (in_array('debug', $var_mode)) {
3074
+                        if (!defined('_VAR_MODE')) {
3075
+                            define('_VAR_MODE', 'debug');
3076
+                        }
3077
+                        // et ne pas enregistrer de cache
3078
+                        if (!defined('_VAR_NOCACHE')) {
3079
+                            define('_VAR_NOCACHE', true);
3080
+                        }
3081
+                        $var_mode = array_diff($var_mode, ['debug']);
3082
+                    }
3083
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3084
+                        define('_VAR_MODE', reset($var_mode));
3085
+                    }
3086
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3087
+                        spip_log($GLOBALS['visiteur_session']['nom']
3088
+                            . ' ' . _VAR_MODE);
3089
+                    }
3090
+                } // pas autorise ?
3091
+                else {
3092
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3093
+                    if (
3094
+                        !$GLOBALS['visiteur_session']
3095
+                        and !empty($_SERVER['HTTP_HOST'])
3096
+                        and !empty($_SERVER['REQUEST_METHOD'])
3097
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3098
+                    ) {
3099
+                        $self = self('&', true);
3100
+                        if (strpos($self, 'page=login') === false) {
3101
+                            include_spip('inc/headers');
3102
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3103
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3104
+                        }
3105
+                    }
3106
+                    // sinon tant pis
3107
+                }
3108
+            }
3109
+        }
3110
+        if (!defined('_VAR_MODE')) {
3111
+            /**
3112
+             * Indique le mode de calcul ou d'affichage de la page.
3113
+             * @see init_var_mode()
3114
+             */
3115
+            define('_VAR_MODE', false);
3116
+        }
3117
+        $done = true;
3118
+    }
3120 3119
 }
3121 3120
 
3122 3121
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
3123 3122
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
3124 3123
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
3125 3124
 function spip_desinfecte(&$t, $deep = true) {
3126
-	foreach ($t as $key => $val) {
3127
-		if (is_string($t[$key])) {
3128
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3129
-		} // traiter aussi les "texte_plus" de article_edit
3130
-		else {
3131
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3132
-				spip_desinfecte($t[$key], $deep);
3133
-			}
3134
-		}
3135
-	}
3125
+    foreach ($t as $key => $val) {
3126
+        if (is_string($t[$key])) {
3127
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3128
+        } // traiter aussi les "texte_plus" de article_edit
3129
+        else {
3130
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3131
+                spip_desinfecte($t[$key], $deep);
3132
+            }
3133
+        }
3134
+    }
3136 3135
 }
3137 3136
 
3138 3137
 //  retourne le statut du visiteur s'il s'annonce
3139 3138
 
3140 3139
 function verifier_visiteur() {
3141
-	// Rq: pour que cette fonction marche depuis mes_options
3142
-	// il faut forcer l'init si ce n'est fait
3143
-	// mais on risque de perturber des plugins en initialisant trop tot
3144
-	// certaines constantes
3145
-	@spip_initialisation_core(
3146
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3147
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3148
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3149
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3150
-	);
3151
-
3152
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3153
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3154
-	// Attention on separe bien session_nom et nom, pour eviter
3155
-	// les melanges entre donnees SQL et variables plus aleatoires
3156
-	$variables_session = ['session_nom', 'session_email'];
3157
-	foreach ($variables_session as $var) {
3158
-		if (_request($var) !== null) {
3159
-			$init = true;
3160
-			break;
3161
-		}
3162
-	}
3163
-	if (isset($init)) {
3164
-		#@spip_initialisation_suite();
3165
-		$session = charger_fonction('session', 'inc');
3166
-		$session();
3167
-		include_spip('inc/texte');
3168
-		foreach ($variables_session as $var) {
3169
-			if (($a = _request($var)) !== null) {
3170
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3171
-			}
3172
-		}
3173
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3174
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3175
-		}
3176
-		$session($GLOBALS['visiteur_session']);
3177
-
3178
-		return 0;
3179
-	}
3180
-
3181
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3182
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3183
-		$session = charger_fonction('session', 'inc');
3184
-		if ($session()) {
3185
-			return $GLOBALS['visiteur_session']['statut'];
3186
-		}
3187
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3188
-			include_spip('inc/auth');
3189
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3190
-		}
3191
-		if ($h) {
3192
-			$GLOBALS['visiteur_session'] = $h;
3193
-
3194
-			return $GLOBALS['visiteur_session']['statut'];
3195
-		}
3196
-	}
3197
-
3198
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3199
-	include_spip('inc/lang');
3200
-	utiliser_langue_visiteur();
3201
-
3202
-	return false;
3140
+    // Rq: pour que cette fonction marche depuis mes_options
3141
+    // il faut forcer l'init si ce n'est fait
3142
+    // mais on risque de perturber des plugins en initialisant trop tot
3143
+    // certaines constantes
3144
+    @spip_initialisation_core(
3145
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3146
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3147
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3148
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3149
+    );
3150
+
3151
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3152
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3153
+    // Attention on separe bien session_nom et nom, pour eviter
3154
+    // les melanges entre donnees SQL et variables plus aleatoires
3155
+    $variables_session = ['session_nom', 'session_email'];
3156
+    foreach ($variables_session as $var) {
3157
+        if (_request($var) !== null) {
3158
+            $init = true;
3159
+            break;
3160
+        }
3161
+    }
3162
+    if (isset($init)) {
3163
+        #@spip_initialisation_suite();
3164
+        $session = charger_fonction('session', 'inc');
3165
+        $session();
3166
+        include_spip('inc/texte');
3167
+        foreach ($variables_session as $var) {
3168
+            if (($a = _request($var)) !== null) {
3169
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3170
+            }
3171
+        }
3172
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3173
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3174
+        }
3175
+        $session($GLOBALS['visiteur_session']);
3176
+
3177
+        return 0;
3178
+    }
3179
+
3180
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3181
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3182
+        $session = charger_fonction('session', 'inc');
3183
+        if ($session()) {
3184
+            return $GLOBALS['visiteur_session']['statut'];
3185
+        }
3186
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3187
+            include_spip('inc/auth');
3188
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3189
+        }
3190
+        if ($h) {
3191
+            $GLOBALS['visiteur_session'] = $h;
3192
+
3193
+            return $GLOBALS['visiteur_session']['statut'];
3194
+        }
3195
+    }
3196
+
3197
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3198
+    include_spip('inc/lang');
3199
+    utiliser_langue_visiteur();
3200
+
3201
+    return false;
3203 3202
 }
3204 3203
 
3205 3204
 
@@ -3222,21 +3221,21 @@  discard block
 block discarded – undo
3222 3221
  *     - string Langue utilisée.
3223 3222
  **/
3224 3223
 function lang_select($lang = null) {
3225
-	static $pile_langues = [];
3226
-	if (!function_exists('changer_langue')) {
3227
-		include_spip('inc/lang');
3228
-	}
3229
-	if ($lang === null) {
3230
-		$lang = array_pop($pile_langues);
3231
-	} else {
3232
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3233
-	}
3234
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3235
-		return $lang;
3236
-	}
3237
-	changer_langue($lang);
3224
+    static $pile_langues = [];
3225
+    if (!function_exists('changer_langue')) {
3226
+        include_spip('inc/lang');
3227
+    }
3228
+    if ($lang === null) {
3229
+        $lang = array_pop($pile_langues);
3230
+    } else {
3231
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3232
+    }
3233
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3234
+        return $lang;
3235
+    }
3236
+    changer_langue($lang);
3238 3237
 
3239
-	return $lang;
3238
+    return $lang;
3240 3239
 }
3241 3240
 
3242 3241
 /**
@@ -3253,20 +3252,20 @@  discard block
 block discarded – undo
3253 3252
  *     Identifiant de la session
3254 3253
  **/
3255 3254
 function spip_session($force = false) {
3256
-	static $session;
3257
-	if ($force or !isset($session)) {
3258
-		$s = pipeline(
3259
-			'definir_session',
3260
-			$GLOBALS['visiteur_session']
3261
-				? serialize($GLOBALS['visiteur_session'])
3262
-				. '_' . @$_COOKIE['spip_session']
3263
-				: ''
3264
-		);
3265
-		$session = $s ? substr(md5($s), 0, 8) : '';
3266
-	}
3255
+    static $session;
3256
+    if ($force or !isset($session)) {
3257
+        $s = pipeline(
3258
+            'definir_session',
3259
+            $GLOBALS['visiteur_session']
3260
+                ? serialize($GLOBALS['visiteur_session'])
3261
+                . '_' . @$_COOKIE['spip_session']
3262
+                : ''
3263
+        );
3264
+        $session = $s ? substr(md5($s), 0, 8) : '';
3265
+    }
3267 3266
 
3268
-	#spip_log('session: '.$session);
3269
-	return $session;
3267
+    #spip_log('session: '.$session);
3268
+    return $session;
3270 3269
 }
3271 3270
 
3272 3271
 
@@ -3285,9 +3284,9 @@  discard block
 block discarded – undo
3285 3284
  *    Lien sur une icone d'aide
3286 3285
  **/
3287 3286
 function aider($aide = '', $distante = false) {
3288
-	$aider = charger_fonction('aide', 'inc', true);
3287
+    $aider = charger_fonction('aide', 'inc', true);
3289 3288
 
3290
-	return $aider ? $aider($aide, '', [], $distante) : '';
3289
+    return $aider ? $aider($aide, '', [], $distante) : '';
3291 3290
 }
3292 3291
 
3293 3292
 /**
@@ -3297,24 +3296,24 @@  discard block
 block discarded – undo
3297 3296
  */
3298 3297
 function exec_info_dist() {
3299 3298
 
3300
-	include_spip('inc/autoriser');
3301
-	if (autoriser('phpinfos')) {
3302
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3303
-		$cookies_backup = [];
3304
-		foreach ($cookies_masques as $k) {
3305
-			if (!empty($_COOKIE[$k])) {
3306
-				$cookies_backup[$k] = $_COOKIE[$k];
3307
-				$_COOKIE[$k] = '******************************';
3308
-			}
3309
-		}
3310
-		phpinfo();
3311
-		foreach ($cookies_backup as $k => $v) {
3312
-			$_COOKIE[$k] = $v;
3313
-		}
3314
-	} else {
3315
-		include_spip('inc/filtres');
3316
-		sinon_interdire_acces();
3317
-	}
3299
+    include_spip('inc/autoriser');
3300
+    if (autoriser('phpinfos')) {
3301
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3302
+        $cookies_backup = [];
3303
+        foreach ($cookies_masques as $k) {
3304
+            if (!empty($_COOKIE[$k])) {
3305
+                $cookies_backup[$k] = $_COOKIE[$k];
3306
+                $_COOKIE[$k] = '******************************';
3307
+            }
3308
+        }
3309
+        phpinfo();
3310
+        foreach ($cookies_backup as $k => $v) {
3311
+            $_COOKIE[$k] = $v;
3312
+        }
3313
+    } else {
3314
+        include_spip('inc/filtres');
3315
+        sinon_interdire_acces();
3316
+    }
3318 3317
 }
3319 3318
 
3320 3319
 /**
@@ -3334,13 +3333,13 @@  discard block
 block discarded – undo
3334 3333
  *     - string si $message à false.
3335 3334
  **/
3336 3335
 function erreur_squelette($message = '', $lieu = '') {
3337
-	$debusquer = charger_fonction('debusquer', 'public');
3338
-	if (is_array($lieu)) {
3339
-		include_spip('public/compiler');
3340
-		$lieu = reconstruire_contexte_compil($lieu);
3341
-	}
3336
+    $debusquer = charger_fonction('debusquer', 'public');
3337
+    if (is_array($lieu)) {
3338
+        include_spip('public/compiler');
3339
+        $lieu = reconstruire_contexte_compil($lieu);
3340
+    }
3342 3341
 
3343
-	return $debusquer($message, $lieu);
3342
+    return $debusquer($message, $lieu);
3344 3343
 }
3345 3344
 
3346 3345
 /**
@@ -3377,108 +3376,108 @@  discard block
 block discarded – undo
3377 3376
  *     - ou tableau d'information sur le squelette.
3378 3377
  */
3379 3378
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3380
-	if (!function_exists('evaluer_fond')) {
3381
-		include_spip('public/assembler');
3382
-	}
3383
-	// assurer la compat avec l'ancienne syntaxe
3384
-	// (trim etait le 3eme argument, par defaut a true)
3385
-	if (!is_array($options)) {
3386
-		$options = ['trim' => $options];
3387
-	}
3388
-	if (!isset($options['trim'])) {
3389
-		$options['trim'] = true;
3390
-	}
3391
-
3392
-	if (isset($contexte['connect'])) {
3393
-		$connect = $contexte['connect'];
3394
-		unset($contexte['connect']);
3395
-	}
3396
-
3397
-	$texte = '';
3398
-	$pages = [];
3399
-	$lang_select = '';
3400
-	if (!isset($options['etoile']) or !$options['etoile']) {
3401
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3402
-		if (!isset($contexte['lang'])) {
3403
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3404
-		}
3405
-
3406
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3407
-			$lang_select = lang_select($contexte['lang']);
3408
-		}
3409
-	}
3410
-
3411
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3412
-		$GLOBALS['_INC_PUBLIC'] = 0;
3413
-	}
3414
-
3415
-	$GLOBALS['_INC_PUBLIC']++;
3416
-
3417
-	// fix #4235
3418
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3419
-
3420
-
3421
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3422
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3423
-
3424
-		$page = evaluer_fond($f, $contexte, $connect);
3425
-		if ($page === '') {
3426
-			$c = $options['compil'] ?? '';
3427
-			$a = ['fichier' => $f];
3428
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3429
-			erreur_squelette($erreur, $c);
3430
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3431
-			$page = ['texte' => '', 'erreur' => $erreur];
3432
-		}
3433
-
3434
-		$page = pipeline('recuperer_fond', [
3435
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3436
-			'data' => $page
3437
-		]);
3438
-		if (isset($options['ajax']) and $options['ajax']) {
3439
-			if (!function_exists('encoder_contexte_ajax')) {
3440
-				include_spip('inc/filtres');
3441
-			}
3442
-			$page['texte'] = encoder_contexte_ajax(
3443
-				array_merge(
3444
-					$contexte,
3445
-					['fond' => $f],
3446
-					($connect ? ['connect' => $connect] : [])
3447
-				),
3448
-				'',
3449
-				$page['texte'],
3450
-				$options['ajax']
3451
-			);
3452
-		}
3453
-
3454
-		if (isset($options['raw']) and $options['raw']) {
3455
-			$pages[] = $page;
3456
-		} else {
3457
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3458
-		}
3459
-
3460
-		// contamination de la session appelante, pour les inclusions statiques
3461
-		if (isset($page['invalideurs']['session'])) {
3462
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3463
-		}
3464
-	}
3465
-
3466
-	// restaurer le sessionnement du contexte appelant,
3467
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3468
-	if (isset($cache_utilise_session_appelant)) {
3469
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3470
-	}
3471
-
3472
-	$GLOBALS['_INC_PUBLIC']--;
3473
-
3474
-	if ($lang_select) {
3475
-		lang_select();
3476
-	}
3477
-	if (isset($options['raw']) and $options['raw']) {
3478
-		return is_array($fond) ? $pages : reset($pages);
3479
-	} else {
3480
-		return $options['trim'] ? ltrim($texte) : $texte;
3481
-	}
3379
+    if (!function_exists('evaluer_fond')) {
3380
+        include_spip('public/assembler');
3381
+    }
3382
+    // assurer la compat avec l'ancienne syntaxe
3383
+    // (trim etait le 3eme argument, par defaut a true)
3384
+    if (!is_array($options)) {
3385
+        $options = ['trim' => $options];
3386
+    }
3387
+    if (!isset($options['trim'])) {
3388
+        $options['trim'] = true;
3389
+    }
3390
+
3391
+    if (isset($contexte['connect'])) {
3392
+        $connect = $contexte['connect'];
3393
+        unset($contexte['connect']);
3394
+    }
3395
+
3396
+    $texte = '';
3397
+    $pages = [];
3398
+    $lang_select = '';
3399
+    if (!isset($options['etoile']) or !$options['etoile']) {
3400
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3401
+        if (!isset($contexte['lang'])) {
3402
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3403
+        }
3404
+
3405
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3406
+            $lang_select = lang_select($contexte['lang']);
3407
+        }
3408
+    }
3409
+
3410
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3411
+        $GLOBALS['_INC_PUBLIC'] = 0;
3412
+    }
3413
+
3414
+    $GLOBALS['_INC_PUBLIC']++;
3415
+
3416
+    // fix #4235
3417
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3418
+
3419
+
3420
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3421
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3422
+
3423
+        $page = evaluer_fond($f, $contexte, $connect);
3424
+        if ($page === '') {
3425
+            $c = $options['compil'] ?? '';
3426
+            $a = ['fichier' => $f];
3427
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3428
+            erreur_squelette($erreur, $c);
3429
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3430
+            $page = ['texte' => '', 'erreur' => $erreur];
3431
+        }
3432
+
3433
+        $page = pipeline('recuperer_fond', [
3434
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3435
+            'data' => $page
3436
+        ]);
3437
+        if (isset($options['ajax']) and $options['ajax']) {
3438
+            if (!function_exists('encoder_contexte_ajax')) {
3439
+                include_spip('inc/filtres');
3440
+            }
3441
+            $page['texte'] = encoder_contexte_ajax(
3442
+                array_merge(
3443
+                    $contexte,
3444
+                    ['fond' => $f],
3445
+                    ($connect ? ['connect' => $connect] : [])
3446
+                ),
3447
+                '',
3448
+                $page['texte'],
3449
+                $options['ajax']
3450
+            );
3451
+        }
3452
+
3453
+        if (isset($options['raw']) and $options['raw']) {
3454
+            $pages[] = $page;
3455
+        } else {
3456
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3457
+        }
3458
+
3459
+        // contamination de la session appelante, pour les inclusions statiques
3460
+        if (isset($page['invalideurs']['session'])) {
3461
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3462
+        }
3463
+    }
3464
+
3465
+    // restaurer le sessionnement du contexte appelant,
3466
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3467
+    if (isset($cache_utilise_session_appelant)) {
3468
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3469
+    }
3470
+
3471
+    $GLOBALS['_INC_PUBLIC']--;
3472
+
3473
+    if ($lang_select) {
3474
+        lang_select();
3475
+    }
3476
+    if (isset($options['raw']) and $options['raw']) {
3477
+        return is_array($fond) ? $pages : reset($pages);
3478
+    } else {
3479
+        return $options['trim'] ? ltrim($texte) : $texte;
3480
+    }
3482 3481
 }
3483 3482
 
3484 3483
 /**
@@ -3488,7 +3487,7 @@  discard block
 block discarded – undo
3488 3487
  * @return string
3489 3488
  */
3490 3489
 function trouve_modele($nom) {
3491
-	return trouver_fond($nom, 'modeles/');
3490
+    return trouver_fond($nom, 'modeles/');
3492 3491
 }
3493 3492
 
3494 3493
 /**
@@ -3504,21 +3503,21 @@  discard block
 block discarded – undo
3504 3503
  * @return array|string
3505 3504
  */
3506 3505
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3507
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3508
-	if (!$pathinfo) {
3509
-		return $f;
3510
-	}
3511
-	// renvoyer un tableau detaille si $pathinfo==true
3512
-	$p = pathinfo($f);
3513
-	if (!isset($p['extension']) or !$p['extension']) {
3514
-		$p['extension'] = _EXTENSION_SQUELETTES;
3515
-	}
3516
-	if (!isset($p['extension']) or !$p['filename']) {
3517
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3518
-	}
3519
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3506
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3507
+    if (!$pathinfo) {
3508
+        return $f;
3509
+    }
3510
+    // renvoyer un tableau detaille si $pathinfo==true
3511
+    $p = pathinfo($f);
3512
+    if (!isset($p['extension']) or !$p['extension']) {
3513
+        $p['extension'] = _EXTENSION_SQUELETTES;
3514
+    }
3515
+    if (!isset($p['extension']) or !$p['filename']) {
3516
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3517
+    }
3518
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3520 3519
 
3521
-	return $p;
3520
+    return $p;
3522 3521
 }
3523 3522
 
3524 3523
 /**
@@ -3538,21 +3537,21 @@  discard block
 block discarded – undo
3538 3537
  *     Nom de l'exec, sinon chaîne vide.
3539 3538
  **/
3540 3539
 function tester_url_ecrire($nom) {
3541
-	static $exec = [];
3542
-	if (isset($exec[$nom])) {
3543
-		return $exec[$nom];
3544
-	}
3545
-	// tester si c'est une page en squelette
3546
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3547
-		return $exec[$nom] = 'fond';
3548
-	} // echafaudage d'un fond !
3549
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3550
-		return $exec[$nom] = 'fond';
3551
-	}
3552
-	// attention, il ne faut pas inclure l'exec ici
3553
-	// car sinon #URL_ECRIRE provoque des inclusions
3554
-	// et des define intrusifs potentiels
3555
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3540
+    static $exec = [];
3541
+    if (isset($exec[$nom])) {
3542
+        return $exec[$nom];
3543
+    }
3544
+    // tester si c'est une page en squelette
3545
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3546
+        return $exec[$nom] = 'fond';
3547
+    } // echafaudage d'un fond !
3548
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3549
+        return $exec[$nom] = 'fond';
3550
+    }
3551
+    // attention, il ne faut pas inclure l'exec ici
3552
+    // car sinon #URL_ECRIRE provoque des inclusions
3553
+    // et des define intrusifs potentiels
3554
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3556 3555
 }
3557 3556
 
3558 3557
 /**
@@ -3562,8 +3561,8 @@  discard block
 block discarded – undo
3562 3561
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3563 3562
  **/
3564 3563
 function html5_permis() {
3565
-	return (!defined('_VERSION_HTML')
3566
-		or _VERSION_HTML !== 'html4');
3564
+    return (!defined('_VERSION_HTML')
3565
+        or _VERSION_HTML !== 'html4');
3567 3566
 }
3568 3567
 
3569 3568
 /**
@@ -3573,30 +3572,30 @@  discard block
 block discarded – undo
3573 3572
  * @return array
3574 3573
  */
3575 3574
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3576
-	$formats = null;
3577
-	if (!is_null($gd)) {
3578
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3579
-		if (isset($GLOBALS['meta'][$config])) {
3580
-			$formats = $GLOBALS['meta'][$config];
3581
-			$formats = explode(',', $formats);
3582
-			$formats = array_filter($formats);
3583
-			$formats = array_map('trim', $formats);
3584
-		}
3585
-	}
3586
-	if (is_null($formats)) {
3587
-		include_spip('inc/filtres_images_lib_mini');
3588
-		$formats = _image_extensions_acceptees_en_entree();
3589
-	}
3590
-
3591
-	if ($svg_allowed) {
3592
-		if (!in_array('svg', $formats)) {
3593
-			$formats[] = 'svg';
3594
-		}
3595
-	}
3596
-	else {
3597
-		$formats = array_diff($formats, ['svg']);
3598
-	}
3599
-	return $formats;
3575
+    $formats = null;
3576
+    if (!is_null($gd)) {
3577
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3578
+        if (isset($GLOBALS['meta'][$config])) {
3579
+            $formats = $GLOBALS['meta'][$config];
3580
+            $formats = explode(',', $formats);
3581
+            $formats = array_filter($formats);
3582
+            $formats = array_map('trim', $formats);
3583
+        }
3584
+    }
3585
+    if (is_null($formats)) {
3586
+        include_spip('inc/filtres_images_lib_mini');
3587
+        $formats = _image_extensions_acceptees_en_entree();
3588
+    }
3589
+
3590
+    if ($svg_allowed) {
3591
+        if (!in_array('svg', $formats)) {
3592
+            $formats[] = 'svg';
3593
+        }
3594
+    }
3595
+    else {
3596
+        $formats = array_diff($formats, ['svg']);
3597
+    }
3598
+    return $formats;
3600 3599
 }
3601 3600
 
3602 3601
 /**
@@ -3605,20 +3604,20 @@  discard block
 block discarded – undo
3605 3604
  * @return array|bool
3606 3605
  */
3607 3606
 function spip_getimagesize($fichier) {
3608
-	if (!$imagesize = @getimagesize($fichier)) {
3609
-		include_spip('inc/svg');
3610
-		if ($attrs = svg_lire_attributs($fichier)) {
3611
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3612
-			$imagesize = [
3613
-				$width,
3614
-				$height,
3615
-				IMAGETYPE_SVG,
3616
-				"width=\"{$width}\" height=\"{$height}\"",
3617
-				'mime' => 'image/svg+xml'
3618
-			];
3619
-		}
3620
-	}
3621
-	return $imagesize;
3607
+    if (!$imagesize = @getimagesize($fichier)) {
3608
+        include_spip('inc/svg');
3609
+        if ($attrs = svg_lire_attributs($fichier)) {
3610
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3611
+            $imagesize = [
3612
+                $width,
3613
+                $height,
3614
+                IMAGETYPE_SVG,
3615
+                "width=\"{$width}\" height=\"{$height}\"",
3616
+                'mime' => 'image/svg+xml'
3617
+            ];
3618
+        }
3619
+    }
3620
+    return $imagesize;
3622 3621
 }
3623 3622
 
3624 3623
 /**
@@ -3632,19 +3631,19 @@  discard block
 block discarded – undo
3632 3631
  * @param string $statut
3633 3632
  */
3634 3633
 function avertir_auteurs($nom, $message, $statut = '') {
3635
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3636
-	if (
3637
-		!$alertes
3638
-		or !is_array($alertes = unserialize($alertes))
3639
-	) {
3640
-		$alertes = [];
3641
-	}
3634
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3635
+    if (
3636
+        !$alertes
3637
+        or !is_array($alertes = unserialize($alertes))
3638
+    ) {
3639
+        $alertes = [];
3640
+    }
3642 3641
 
3643
-	if (!isset($alertes[$statut])) {
3644
-		$alertes[$statut] = [];
3645
-	}
3646
-	$alertes[$statut][$nom] = $message;
3647
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3642
+    if (!isset($alertes[$statut])) {
3643
+        $alertes[$statut] = [];
3644
+    }
3645
+    $alertes[$statut][$nom] = $message;
3646
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3648 3647
 }
3649 3648
 
3650 3649
 /**
@@ -3658,10 +3657,10 @@  discard block
 block discarded – undo
3658 3657
  * @return string|string[]
3659 3658
  */
3660 3659
 function spip_sanitize_classname($classes) {
3661
-	if (is_array($classes)) {
3662
-		return array_map('spip_sanitize_classname', $classes);
3663
-	}
3664
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3660
+    if (is_array($classes)) {
3661
+        return array_map('spip_sanitize_classname', $classes);
3662
+    }
3663
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3665 3664
 }
3666 3665
 
3667 3666
 
@@ -3686,32 +3685,32 @@  discard block
 block discarded – undo
3686 3685
  *    Avec operateur : bool.
3687 3686
  **/
3688 3687
 function spip_version_compare($v1, $v2, $op = null) {
3689
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3690
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3691
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3692
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3693
-
3694
-	$v1 = explode('.', $v1);
3695
-	$v2 = explode('.', $v2);
3696
-	// $v1 est toujours une version, donc sans etoile
3697
-	while (count($v1) < count($v2)) {
3698
-		$v1[] = '0';
3699
-	}
3700
-
3701
-	// $v2 peut etre une borne, donc accepte l'etoile
3702
-	$etoile = false;
3703
-	foreach ($v1 as $k => $v) {
3704
-		if (!isset($v2[$k])) {
3705
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3706
-		} else {
3707
-			if ($v2[$k] == '*') {
3708
-				$etoile = true;
3709
-				$v2[$k] = $v;
3710
-			}
3711
-		}
3712
-	}
3713
-	$v1 = implode('.', $v1);
3714
-	$v2 = implode('.', $v2);
3715
-
3716
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3688
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3689
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3690
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3691
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3692
+
3693
+    $v1 = explode('.', $v1);
3694
+    $v2 = explode('.', $v2);
3695
+    // $v1 est toujours une version, donc sans etoile
3696
+    while (count($v1) < count($v2)) {
3697
+        $v1[] = '0';
3698
+    }
3699
+
3700
+    // $v2 peut etre une borne, donc accepte l'etoile
3701
+    $etoile = false;
3702
+    foreach ($v1 as $k => $v) {
3703
+        if (!isset($v2[$k])) {
3704
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3705
+        } else {
3706
+            if ($v2[$k] == '*') {
3707
+                $etoile = true;
3708
+                $v2[$k] = $v;
3709
+            }
3710
+        }
3711
+    }
3712
+    $v1 = implode('.', $v1);
3713
+    $v2 = implode('.', $v2);
3714
+
3715
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3717 3716
 }
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 1 patch
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Autorisations
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('base/abstract_sql');
@@ -38,89 +38,89 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 if (!function_exists('autoriser')) {
41
-	/**
42
-	 * Autoriser une action
43
-	 *
44
-	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
-	 * une certaine action. Cette fonction est le point d'entrée de toutes
46
-	 * les autorisations.
47
-	 *
48
-	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
-	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
-	 * dans cet ordre :
51
-	 *
52
-	 * - autoriser_{type}_{faire}, sinon avec _dist
53
-	 * - autoriser_{type}, sinon avec _dist
54
-	 * - autoriser_{faire}, sinon avec _dist
55
-	 * - autoriser_{defaut}, sinon avec _dist
56
-	 *
57
-	 * Seul le premier argument est obligatoire.
58
-	 *
59
-	 * @note
60
-	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
-	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
-	 *     cette valeur.
63
-	 *
64
-	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
-	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
-	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
-	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
-	 *
69
-	 * @note
70
-	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
-	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
-	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
-	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
-	 *     quel serait le type, quel serait l'action ?
75
-	 *
76
-	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
-	 *     la fonction d'autorisation correspondante ne l'aura pas.
78
-	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
-	 *
80
-	 * @api
81
-	 * @see autoriser_dist()
82
-	 * @see objet_type()
83
-	 *
84
-	 * @param string $faire
85
-	 *   une action ('modifier', 'publier'...)
86
-	 * @param string|null $type
87
-	 *   Type d’objet ou élément sur lequel appliquer l’action.
88
-	 *   - null: indifférent à tout type d’élément ou objet éditorial
89
-	 *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
90
-	 *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
91
-	 *   Les soulignés seront retirés (cf. la note).
92
-	 * @param string|int|null $id
93
-	 *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
94
-	 *   - null: non utile pour l’autorisation
95
-	 *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
96
-	 *   - string: identifiant textuel
97
-	 * @param null|int|array $qui
98
-	 *   - si null on prend alors visiteur_session
99
-	 *   - un id_auteur (on regarde dans la base)
100
-	 *   - un tableau auteur complet, y compris [restreint]
101
-	 * @param array $opt
102
-	 *   options sous forme de tableau associatif
103
-	 * @return bool
104
-	 *   true si la personne peut effectuer l'action
105
-	 */
106
-	function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
107
-		// Charger les fonctions d'autorisation supplementaires
108
-		static $pipe;
109
-		if (!isset($pipe)) {
110
-			$pipe = 1;
111
-			pipeline('autoriser');
112
-		}
113
-
114
-		return autoriser_dist($faire, $type, $id, $qui, $opt);
115
-	}
41
+    /**
42
+     * Autoriser une action
43
+     *
44
+     * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
+     * une certaine action. Cette fonction est le point d'entrée de toutes
46
+     * les autorisations.
47
+     *
48
+     * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
+     * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
+     * dans cet ordre :
51
+     *
52
+     * - autoriser_{type}_{faire}, sinon avec _dist
53
+     * - autoriser_{type}, sinon avec _dist
54
+     * - autoriser_{faire}, sinon avec _dist
55
+     * - autoriser_{defaut}, sinon avec _dist
56
+     *
57
+     * Seul le premier argument est obligatoire.
58
+     *
59
+     * @note
60
+     *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
+     *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
+     *     cette valeur.
63
+     *
64
+     *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
+     *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
+     *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
+     *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
+     *
69
+     * @note
70
+     *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
+     *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
+     *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
+     *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
+     *     quel serait le type, quel serait l'action ?
75
+     *
76
+     *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
+     *     la fonction d'autorisation correspondante ne l'aura pas.
78
+     *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
+     *
80
+     * @api
81
+     * @see autoriser_dist()
82
+     * @see objet_type()
83
+     *
84
+     * @param string $faire
85
+     *   une action ('modifier', 'publier'...)
86
+     * @param string|null $type
87
+     *   Type d’objet ou élément sur lequel appliquer l’action.
88
+     *   - null: indifférent à tout type d’élément ou objet éditorial
89
+     *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
90
+     *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
91
+     *   Les soulignés seront retirés (cf. la note).
92
+     * @param string|int|null $id
93
+     *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
94
+     *   - null: non utile pour l’autorisation
95
+     *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
96
+     *   - string: identifiant textuel
97
+     * @param null|int|array $qui
98
+     *   - si null on prend alors visiteur_session
99
+     *   - un id_auteur (on regarde dans la base)
100
+     *   - un tableau auteur complet, y compris [restreint]
101
+     * @param array $opt
102
+     *   options sous forme de tableau associatif
103
+     * @return bool
104
+     *   true si la personne peut effectuer l'action
105
+     */
106
+    function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
107
+        // Charger les fonctions d'autorisation supplementaires
108
+        static $pipe;
109
+        if (!isset($pipe)) {
110
+            $pipe = 1;
111
+            pipeline('autoriser');
112
+        }
113
+
114
+        return autoriser_dist($faire, $type, $id, $qui, $opt);
115
+    }
116 116
 }
117 117
 
118 118
 
119 119
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
120 120
 // mais apres la fonction autoriser()
121 121
 if ($f = find_in_path('mes_fonctions.php')) {
122
-	global $dossier_squelettes;
123
-	include_once(_ROOT_CWD . $f);
122
+    global $dossier_squelettes;
123
+    include_once(_ROOT_CWD . $f);
124 124
 }
125 125
 
126 126
 
@@ -151,82 +151,82 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
153 153
 
154
-	$a = null;
155
-	if ($type === null) {
156
-		$type = '';
157
-	}
158
-
159
-	// Qui ? visiteur_session ?
160
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
161
-	if ($qui === null or $qui === '') {
162
-		$qui = $GLOBALS['visiteur_session'] ?: [];
163
-		$qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
164
-	} elseif (is_numeric($qui)) {
165
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
166
-	}
167
-
168
-	// Admins restreints, on construit ici (pas generique mais...)
169
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
170
-	if (_ADMINS_RESTREINTS and is_array($qui)) {
171
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
172
-	}
173
-
174
-	spip_log(
175
-		"autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
176
-		'autoriser' . _LOG_DEBUG
177
-	);
178
-
179
-	// passer par objet_type pour avoir les alias
180
-	// sauf si _ est le premier caractère.
181
-	if ($type and $type[0] !== '_') {
182
-		$type = objet_type($type, false);
183
-	}
184
-	// et supprimer les _
185
-	$type = str_replace('_', '', (string) $type);
186
-
187
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
188
-	if (
189
-		(isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
190
-		or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
191
-	) {
192
-		spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
193
-		return true;
194
-	}
195
-
196
-	// Chercher une fonction d'autorisation
197
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
198
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
199
-	$fonctions = $type
200
-		? [
201
-			'autoriser_' . $type . '_' . $faire,
202
-			'autoriser_' . $type . '_' . $faire . '_dist',
203
-			'autoriser_' . $type,
204
-			'autoriser_' . $type . '_dist',
205
-			'autoriser_' . $faire,
206
-			'autoriser_' . $faire . '_dist',
207
-			'autoriser_defaut',
208
-			'autoriser_defaut_dist'
209
-		]
210
-		: [
211
-			'autoriser_' . $faire,
212
-			'autoriser_' . $faire . '_dist',
213
-			'autoriser_defaut',
214
-			'autoriser_defaut_dist'
215
-		];
216
-
217
-	foreach ($fonctions as $f) {
218
-		if (function_exists($f)) {
219
-			$a = $f($faire, $type, $id, $qui, $opt);
220
-			break;
221
-		}
222
-	}
223
-
224
-	spip_log(
225
-		"$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
226
-		'autoriser' . _LOG_DEBUG
227
-	);
228
-
229
-	return $a;
154
+    $a = null;
155
+    if ($type === null) {
156
+        $type = '';
157
+    }
158
+
159
+    // Qui ? visiteur_session ?
160
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
161
+    if ($qui === null or $qui === '') {
162
+        $qui = $GLOBALS['visiteur_session'] ?: [];
163
+        $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
164
+    } elseif (is_numeric($qui)) {
165
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
166
+    }
167
+
168
+    // Admins restreints, on construit ici (pas generique mais...)
169
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
170
+    if (_ADMINS_RESTREINTS and is_array($qui)) {
171
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
172
+    }
173
+
174
+    spip_log(
175
+        "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
176
+        'autoriser' . _LOG_DEBUG
177
+    );
178
+
179
+    // passer par objet_type pour avoir les alias
180
+    // sauf si _ est le premier caractère.
181
+    if ($type and $type[0] !== '_') {
182
+        $type = objet_type($type, false);
183
+    }
184
+    // et supprimer les _
185
+    $type = str_replace('_', '', (string) $type);
186
+
187
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
188
+    if (
189
+        (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
190
+        or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
191
+    ) {
192
+        spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
193
+        return true;
194
+    }
195
+
196
+    // Chercher une fonction d'autorisation
197
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
198
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
199
+    $fonctions = $type
200
+        ? [
201
+            'autoriser_' . $type . '_' . $faire,
202
+            'autoriser_' . $type . '_' . $faire . '_dist',
203
+            'autoriser_' . $type,
204
+            'autoriser_' . $type . '_dist',
205
+            'autoriser_' . $faire,
206
+            'autoriser_' . $faire . '_dist',
207
+            'autoriser_defaut',
208
+            'autoriser_defaut_dist'
209
+        ]
210
+        : [
211
+            'autoriser_' . $faire,
212
+            'autoriser_' . $faire . '_dist',
213
+            'autoriser_defaut',
214
+            'autoriser_defaut_dist'
215
+        ];
216
+
217
+    foreach ($fonctions as $f) {
218
+        if (function_exists($f)) {
219
+            $a = $f($faire, $type, $id, $qui, $opt);
220
+            break;
221
+        }
222
+    }
223
+
224
+    spip_log(
225
+        "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
226
+        'autoriser' . _LOG_DEBUG
227
+    );
228
+
229
+    return $a;
230 230
 }
231 231
 
232 232
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -246,33 +246,33 @@  discard block
 block discarded – undo
246 246
  * @return bool
247 247
  */
248 248
 function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool {
249
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
250
-	static $autorisation;
251
-	// Tolérance avec certains appels
252
-	if ($type === null) {
253
-		$type = '';
254
-	}
255
-	if ($id === null) {
256
-		$id = 0;
257
-	}
258
-	if ($autoriser === 'verifier') {
259
-		return isset($autorisation[$faire][$type][$id]);
260
-	}
261
-	if ($autoriser === true) {
262
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
263
-	}
264
-	if ($autoriser === false) {
265
-		if ($id === '*') {
266
-			unset($GLOBALS['autoriser_exception'][$faire][$type]);
267
-			unset($autorisation[$faire][$type]);
268
-		}
269
-		else {
270
-			unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
271
-			unset($autorisation[$faire][$type][$id]);
272
-		}
273
-	}
274
-
275
-	return false;
249
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
250
+    static $autorisation;
251
+    // Tolérance avec certains appels
252
+    if ($type === null) {
253
+        $type = '';
254
+    }
255
+    if ($id === null) {
256
+        $id = 0;
257
+    }
258
+    if ($autoriser === 'verifier') {
259
+        return isset($autorisation[$faire][$type][$id]);
260
+    }
261
+    if ($autoriser === true) {
262
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
263
+    }
264
+    if ($autoriser === false) {
265
+        if ($id === '*') {
266
+            unset($GLOBALS['autoriser_exception'][$faire][$type]);
267
+            unset($autorisation[$faire][$type]);
268
+        }
269
+        else {
270
+            unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
271
+            unset($autorisation[$faire][$type][$id]);
272
+        }
273
+    }
274
+
275
+    return false;
276 276
 }
277 277
 
278 278
 
@@ -291,9 +291,9 @@  discard block
 block discarded – undo
291 291
  * @return bool true s'il a le droit, false sinon
292 292
  **/
293 293
 function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
294
-	return
295
-		$qui['statut'] === '0minirezo'
296
-		and !$qui['restreint'];
294
+    return
295
+        $qui['statut'] === '0minirezo'
296
+        and !$qui['restreint'];
297 297
 }
298 298
 
299 299
 /**
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
  * @return bool true s'il a le droit, false sinon
314 314
  */
315 315
 function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
316
-	if ($qui['statut'] === '5poubelle') {
317
-		return false;
318
-	}
319
-	return true;
316
+    if ($qui['statut'] === '5poubelle') {
317
+        return false;
318
+    }
319
+    return true;
320 320
 }
321 321
 
322 322
 /**
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
  * @return bool true s'il a le droit, false sinon
333 333
  **/
334 334
 function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
335
-	return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']);
335
+    return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']);
336 336
 }
337 337
 
338 338
 /**
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
  * @return bool true s'il a le droit, false sinon
352 352
  **/
353 353
 function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
354
-	return in_array($qui['statut'], ['0minirezo', '1comite']);
354
+    return in_array($qui['statut'], ['0minirezo', '1comite']);
355 355
 }
356 356
 
357 357
 /**
@@ -371,18 +371,18 @@  discard block
 block discarded – undo
371 371
  **/
372 372
 function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
373 373
 
374
-	// Le visiteur a-t-il un statut prevu par la config ?
375
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
376
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
377
-	}
374
+    // Le visiteur a-t-il un statut prevu par la config ?
375
+    if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
376
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
377
+    }
378 378
 
379
-	// A-t-on un token de prévisualisation valable ?
380
-	include_spip('inc/securiser_action');
381
-	if (decrire_token_previsu()) {
382
-		return true;
383
-	}
379
+    // A-t-on un token de prévisualisation valable ?
380
+    include_spip('inc/securiser_action');
381
+    if (decrire_token_previsu()) {
382
+        return true;
383
+    }
384 384
 
385
-	return false;
385
+    return false;
386 386
 }
387 387
 
388 388
 /**
@@ -411,58 +411,58 @@  discard block
 block discarded – undo
411 411
  */
412 412
 function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool {
413 413
 
414
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
415
-	if (!$type) {
416
-		return true;
417
-	}
418
-
419
-	include_spip('base/objets');
420
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
421
-	if (isset($infos['statut'])) {
422
-		foreach ($infos['statut'] as $c) {
423
-			if (isset($c['publie'])) {
424
-				if (!isset($c['previsu'])) {
425
-					return false;
426
-				} // pas de previsu definie => NIET
427
-				$champ = $c['champ'];
428
-				if (!isset($opt[$champ])) {
429
-					return false;
430
-				} // pas de champ passe a la demande => NIET
431
-				$previsu = explode(',', $c['previsu']);
432
-				// regarder si ce statut est autorise pour l'auteur
433
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
434
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
435
-					// sinon l’auteur en session
436
-					include_spip('inc/securiser_action');
437
-					if ($desc = decrire_token_previsu()) {
438
-						$id_auteur = $desc['id_auteur'];
439
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
440
-						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
441
-					} else {
442
-						$id_auteur = null;
443
-					}
444
-
445
-					if (!$id_auteur) {
446
-						return false;
447
-					} elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
448
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
449
-					} elseif (
450
-						!sql_countsel(
451
-							'spip_auteurs_liens',
452
-							'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
453
-						)
454
-					) {
455
-						return false;
456
-					} // pas auteur de cet objet => NIET
457
-				} elseif (!in_array($opt[$champ], $previsu)) {
458
-					// le statut n'est pas dans ceux definis par la previsu => NIET
459
-					return false;
460
-				}
461
-			}
462
-		}
463
-	}
464
-
465
-	return true;
414
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
415
+    if (!$type) {
416
+        return true;
417
+    }
418
+
419
+    include_spip('base/objets');
420
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
421
+    if (isset($infos['statut'])) {
422
+        foreach ($infos['statut'] as $c) {
423
+            if (isset($c['publie'])) {
424
+                if (!isset($c['previsu'])) {
425
+                    return false;
426
+                } // pas de previsu definie => NIET
427
+                $champ = $c['champ'];
428
+                if (!isset($opt[$champ])) {
429
+                    return false;
430
+                } // pas de champ passe a la demande => NIET
431
+                $previsu = explode(',', $c['previsu']);
432
+                // regarder si ce statut est autorise pour l'auteur
433
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
434
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
435
+                    // sinon l’auteur en session
436
+                    include_spip('inc/securiser_action');
437
+                    if ($desc = decrire_token_previsu()) {
438
+                        $id_auteur = $desc['id_auteur'];
439
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
440
+                        $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
441
+                    } else {
442
+                        $id_auteur = null;
443
+                    }
444
+
445
+                    if (!$id_auteur) {
446
+                        return false;
447
+                    } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
448
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
449
+                    } elseif (
450
+                        !sql_countsel(
451
+                            'spip_auteurs_liens',
452
+                            'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
453
+                        )
454
+                    ) {
455
+                        return false;
456
+                    } // pas auteur de cet objet => NIET
457
+                } elseif (!in_array($opt[$champ], $previsu)) {
458
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
459
+                    return false;
460
+                }
461
+            }
462
+        }
463
+    }
464
+
465
+    return true;
466 466
 }
467 467
 
468 468
 /**
@@ -478,51 +478,51 @@  discard block
 block discarded – undo
478 478
  * @return bool true s'il a le droit, false sinon
479 479
  **/
480 480
 function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
481
-	$multi_objets = explode(',', lire_config('multi_objets'));
482
-	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
483
-	$table = table_objet_sql($type);
484
-	if (
485
-		in_array($table, $multi_objets)
486
-		or in_array($table, $gerer_trad_objets)
487
-	) { // affichage du formulaire si la configuration l'accepte
488
-		$multi_secteurs = lire_config('multi_secteurs');
489
-		$champs = objet_info($type, 'field');
490
-		if (
491
-			$multi_secteurs === 'oui'
492
-			and array_key_exists('id_rubrique', $champs)
493
-		) {
494
-			// multilinguisme par secteur et objet rattaché à une rubrique
495
-			$primary = id_table_objet($type);
496
-			if ($table != 'spip_rubriques') {
497
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
498
-			} else {
499
-				$id_rubrique = $id;
500
-			}
501
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
502
-			if (!$id_secteur > 0) {
503
-				$id_secteur = $id_rubrique;
504
-			}
505
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
506
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
507
-			if ($langue_secteur != $langue_objet) {
508
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
509
-				return true;
510
-			}
511
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
512
-				return false;
513
-			} else {
514
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
515
-				if ($id_parent != 0) {
516
-					// sous-rubriques : pas de choix de langue
517
-					return false;
518
-				}
519
-			}
520
-		}
521
-	} else {
522
-		return false;
523
-	}
524
-
525
-	return autoriser('modifier', $type, $id, $qui, $opt);
481
+    $multi_objets = explode(',', lire_config('multi_objets'));
482
+    $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
483
+    $table = table_objet_sql($type);
484
+    if (
485
+        in_array($table, $multi_objets)
486
+        or in_array($table, $gerer_trad_objets)
487
+    ) { // affichage du formulaire si la configuration l'accepte
488
+        $multi_secteurs = lire_config('multi_secteurs');
489
+        $champs = objet_info($type, 'field');
490
+        if (
491
+            $multi_secteurs === 'oui'
492
+            and array_key_exists('id_rubrique', $champs)
493
+        ) {
494
+            // multilinguisme par secteur et objet rattaché à une rubrique
495
+            $primary = id_table_objet($type);
496
+            if ($table != 'spip_rubriques') {
497
+                $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
498
+            } else {
499
+                $id_rubrique = $id;
500
+            }
501
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
502
+            if (!$id_secteur > 0) {
503
+                $id_secteur = $id_rubrique;
504
+            }
505
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
506
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
507
+            if ($langue_secteur != $langue_objet) {
508
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
509
+                return true;
510
+            }
511
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
512
+                return false;
513
+            } else {
514
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
515
+                if ($id_parent != 0) {
516
+                    // sous-rubriques : pas de choix de langue
517
+                    return false;
518
+                }
519
+            }
520
+        }
521
+    } else {
522
+        return false;
523
+    }
524
+
525
+    return autoriser('modifier', $type, $id, $qui, $opt);
526 526
 }
527 527
 
528 528
 /**
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
  * @return bool true s'il a le droit, false sinon
539 539
  **/
540 540
 function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
541
-	return autoriser('modifier', $type, $id, $qui, $opt);
541
+    return autoriser('modifier', $type, $id, $qui, $opt);
542 542
 }
543 543
 
544 544
 /**
@@ -554,41 +554,41 @@  discard block
 block discarded – undo
554 554
  * @return bool true s'il a le droit, false sinon
555 555
  **/
556 556
 function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
557
-	$table = table_objet($type);
558
-	$trouver_table = charger_fonction('trouver_table', 'base');
559
-	$desc = $trouver_table($table);
560
-	if (!$desc) {
561
-		return false;
562
-	}
563
-
564
-	if (!isset($opt['statut'])) {
565
-		if (isset($desc['field']['statut'])) {
566
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
567
-		} else {
568
-			$statut = 'publie';
569
-		} // pas de statut => publie
570
-	} else {
571
-		$statut = $opt['statut'];
572
-	}
573
-
574
-	// Liste des statuts publiés pour cet objet
575
-	if (isset($desc['statut'][0]['publie'])) {
576
-		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
577
-	}
578
-	// Sinon en dur le statut "publie"
579
-	else {
580
-		$statuts_publies = ['publie'];
581
-	}
582
-
583
-	if (
584
-		in_array($statut, $statuts_publies)
585
-		// Ou cas particulier géré en dur ici pour les articles
586
-		or ($statut === 'prop' and $type === 'article' and $GLOBALS['meta']['post_dates'] === 'non')
587
-	) {
588
-		return autoriser('modifier', $type, $id);
589
-	}
590
-
591
-	return false;
557
+    $table = table_objet($type);
558
+    $trouver_table = charger_fonction('trouver_table', 'base');
559
+    $desc = $trouver_table($table);
560
+    if (!$desc) {
561
+        return false;
562
+    }
563
+
564
+    if (!isset($opt['statut'])) {
565
+        if (isset($desc['field']['statut'])) {
566
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
567
+        } else {
568
+            $statut = 'publie';
569
+        } // pas de statut => publie
570
+    } else {
571
+        $statut = $opt['statut'];
572
+    }
573
+
574
+    // Liste des statuts publiés pour cet objet
575
+    if (isset($desc['statut'][0]['publie'])) {
576
+        $statuts_publies = explode(',', $desc['statut'][0]['publie']);
577
+    }
578
+    // Sinon en dur le statut "publie"
579
+    else {
580
+        $statuts_publies = ['publie'];
581
+    }
582
+
583
+    if (
584
+        in_array($statut, $statuts_publies)
585
+        // Ou cas particulier géré en dur ici pour les articles
586
+        or ($statut === 'prop' and $type === 'article' and $GLOBALS['meta']['post_dates'] === 'non')
587
+    ) {
588
+        return autoriser('modifier', $type, $id);
589
+    }
590
+
591
+    return false;
592 592
 }
593 593
 
594 594
 /**
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
  * @return bool true s'il a le droit, false sinon
608 608
  **/
609 609
 function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
610
-	return autoriser('modifier', $type, $id, $qui, $opt);
610
+    return autoriser('modifier', $type, $id, $qui, $opt);
611 611
 }
612 612
 
613 613
 /**
@@ -625,12 +625,12 @@  discard block
 block discarded – undo
625 625
  * @return bool true s'il a le droit, false sinon
626 626
  **/
627 627
 function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
628
-	return
629
-		($qui['statut'] === '0minirezo')
630
-		and (
631
-			!$qui['restreint'] or !$id
632
-			or in_array($id, $qui['restreint'])
633
-		);
628
+    return
629
+        ($qui['statut'] === '0minirezo')
630
+        and (
631
+            !$qui['restreint'] or !$id
632
+            or in_array($id, $qui['restreint'])
633
+        );
634 634
 }
635 635
 
636 636
 /**
@@ -648,12 +648,12 @@  discard block
 block discarded – undo
648 648
  * @return bool true s'il a le droit, false sinon
649 649
  **/
650 650
 function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
651
-	if (!empty($opt['id_parent'])) {
652
-		return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
653
-	}
654
-	else {
655
-		return autoriser('defaut', null, 0, $qui, $opt);
656
-	}
651
+    if (!empty($opt['id_parent'])) {
652
+        return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
653
+    }
654
+    else {
655
+        return autoriser('defaut', null, 0, $qui, $opt);
656
+    }
657 657
 }
658 658
 
659 659
 /**
@@ -671,10 +671,10 @@  discard block
 block discarded – undo
671 671
  * @return bool true s'il a le droit, false sinon
672 672
  **/
673 673
 function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
674
-	return
675
-		($id or ($qui['statut'] === '0minirezo' and !$qui['restreint']))
676
-		and autoriser('voir', 'rubrique', $id)
677
-		and autoriser('publierdans', 'rubrique', $id);
674
+    return
675
+        ($id or ($qui['statut'] === '0minirezo' and !$qui['restreint']))
676
+        and autoriser('voir', 'rubrique', $id)
677
+        and autoriser('publierdans', 'rubrique', $id);
678 678
 }
679 679
 
680 680
 /**
@@ -692,10 +692,10 @@  discard block
 block discarded – undo
692 692
  * @return bool true s'il a le droit, false sinon
693 693
  **/
694 694
 function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
695
-	return
696
-		$id
697
-		and autoriser('voir', 'rubrique', $id)
698
-		and autoriser('creer', 'article');
695
+    return
696
+        $id
697
+        and autoriser('voir', 'rubrique', $id)
698
+        and autoriser('creer', 'article');
699 699
 }
700 700
 
701 701
 
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
  * @return bool true s'il a le droit, false sinon
715 715
  **/
716 716
 function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
717
-	return
718
-		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
717
+    return
718
+        autoriser('publierdans', 'rubrique', $id, $qui, $opt);
719 719
 }
720 720
 
721 721
 /**
@@ -733,29 +733,29 @@  discard block
 block discarded – undo
733 733
  * @return bool true s'il a le droit, false sinon
734 734
  **/
735 735
 function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
736
-	if (!$id = intval($id)) {
737
-		return false;
738
-	}
736
+    if (!$id = intval($id)) {
737
+        return false;
738
+    }
739 739
 
740
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
741
-		return false;
742
-	}
740
+    if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
741
+        return false;
742
+    }
743 743
 
744
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
745
-		return false;
746
-	}
744
+    if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
745
+        return false;
746
+    }
747 747
 
748
-	$compte = pipeline(
749
-		'objet_compte_enfants',
750
-		['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
751
-	);
752
-	foreach ($compte as $objet => $n) {
753
-		if ($n) {
754
-			return false;
755
-		}
756
-	}
748
+    $compte = pipeline(
749
+        'objet_compte_enfants',
750
+        ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
751
+    );
752
+    foreach ($compte as $objet => $n) {
753
+        if ($n) {
754
+            return false;
755
+        }
756
+    }
757 757
 
758
-	return autoriser('modifier', 'rubrique', $id);
758
+    return autoriser('modifier', 'rubrique', $id);
759 759
 }
760 760
 
761 761
 
@@ -775,23 +775,23 @@  discard block
 block discarded – undo
775 775
  * @return bool true s'il a le droit, false sinon
776 776
  **/
777 777
 function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
778
-	if (!$id) {
779
-		return false;
780
-	}
781
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
782
-
783
-	return
784
-		$r
785
-		and
786
-		(
787
-			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
788
-			or (
789
-				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
790
-				and in_array($qui['statut'], ['0minirezo', '1comite'])
791
-				and in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
792
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
793
-			)
794
-		);
778
+    if (!$id) {
779
+        return false;
780
+    }
781
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
782
+
783
+    return
784
+        $r
785
+        and
786
+        (
787
+            autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
788
+            or (
789
+                (!isset($opt['statut']) or $opt['statut'] !== 'publie')
790
+                and in_array($qui['statut'], ['0minirezo', '1comite'])
791
+                and in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
792
+                and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
793
+            )
794
+        );
795 795
 }
796 796
 
797 797
 /**
@@ -809,13 +809,13 @@  discard block
 block discarded – undo
809 809
  * @return bool true s'il a le droit, false sinon
810 810
  **/
811 811
 function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
812
-	if (!empty($opt['id_parent'])) {
813
-		// creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
814
-		return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
815
-	}
816
-	else {
817
-		return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite']));
818
-	}
812
+    if (!empty($opt['id_parent'])) {
813
+        // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
814
+        return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
815
+    }
816
+    else {
817
+        return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite']));
818
+    }
819 819
 }
820 820
 
821 821
 /**
@@ -837,28 +837,28 @@  discard block
 block discarded – undo
837 837
  * @return bool true s'il a le droit, false sinon
838 838
  */
839 839
 function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
840
-	if ($qui['statut'] === '0minirezo') {
841
-		return true;
842
-	}
843
-	// cas des articles : depend du statut de l'article et de l'auteur
844
-	if (isset($opt['statut'])) {
845
-		$statut = $opt['statut'];
846
-	} else {
847
-		if (!$id) {
848
-			return false;
849
-		}
850
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
851
-	}
852
-
853
-	return
854
-		// si on est pas auteur de l'article,
855
-		// seuls les propose et publies sont visibles
856
-		in_array($statut, ['prop', 'publie'])
857
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
858
-		or
859
-		($id
860
-			and $qui['id_auteur']
861
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
840
+    if ($qui['statut'] === '0minirezo') {
841
+        return true;
842
+    }
843
+    // cas des articles : depend du statut de l'article et de l'auteur
844
+    if (isset($opt['statut'])) {
845
+        $statut = $opt['statut'];
846
+    } else {
847
+        if (!$id) {
848
+            return false;
849
+        }
850
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
851
+    }
852
+
853
+    return
854
+        // si on est pas auteur de l'article,
855
+        // seuls les propose et publies sont visibles
856
+        in_array($statut, ['prop', 'publie'])
857
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
858
+        or
859
+        ($id
860
+            and $qui['id_auteur']
861
+            and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
862 862
 }
863 863
 
864 864
 
@@ -877,24 +877,24 @@  discard block
 block discarded – undo
877 877
  * @return bool true s'il a le droit, false sinon
878 878
  **/
879 879
 function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
880
-	# securite, mais on aurait pas du arriver ici !
881
-	if (
882
-		function_exists($f = 'autoriser_' . $type . '_voir')
883
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')
884
-	) {
885
-		return $f($faire, $type, $id, $qui, $opt);
886
-	}
880
+    # securite, mais on aurait pas du arriver ici !
881
+    if (
882
+        function_exists($f = 'autoriser_' . $type . '_voir')
883
+        or function_exists($f = 'autoriser_' . $type . '_voir_dist')
884
+    ) {
885
+        return $f($faire, $type, $id, $qui, $opt);
886
+    }
887 887
 
888
-	if ($qui['statut'] === '0minirezo') {
889
-		return true;
890
-	}
891
-	// admins et redacteurs peuvent voir un auteur
892
-	if ($type === 'auteur') {
893
-		return in_array($qui['statut'], ['0minirezo', '1comite']);
894
-	}
895
-	// sinon par defaut tout est visible
896
-	// sauf cas particuliers traites separemment (ie article)
897
-	return true;
888
+    if ($qui['statut'] === '0minirezo') {
889
+        return true;
890
+    }
891
+    // admins et redacteurs peuvent voir un auteur
892
+    if ($type === 'auteur') {
893
+        return in_array($qui['statut'], ['0minirezo', '1comite']);
894
+    }
895
+    // sinon par defaut tout est visible
896
+    // sauf cas particuliers traites separemment (ie article)
897
+    return true;
898 898
 }
899 899
 
900 900
 
@@ -917,12 +917,12 @@  discard block
 block discarded – undo
917 917
  * @return bool true s'il a le droit, false sinon
918 918
  **/
919 919
 function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
920
-	return
921
-		(defined('_ID_WEBMESTRES') ?
922
-			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
923
-			: $qui['webmestre'] === 'oui')
924
-		and $qui['statut'] === '0minirezo'
925
-		and !$qui['restreint'];
920
+    return
921
+        (defined('_ID_WEBMESTRES') ?
922
+            in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
923
+            : $qui['webmestre'] === 'oui')
924
+        and $qui['statut'] === '0minirezo'
925
+        and !$qui['restreint'];
926 926
 }
927 927
 
928 928
 /**
@@ -940,9 +940,9 @@  discard block
 block discarded – undo
940 940
  * @return bool true s'il a le droit, false sinon
941 941
  **/
942 942
 function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
943
-	return
944
-		$qui['statut'] === '0minirezo'
945
-		and !$qui['restreint'];
943
+    return
944
+        $qui['statut'] === '0minirezo'
945
+        and !$qui['restreint'];
946 946
 }
947 947
 
948 948
 /**
@@ -960,8 +960,8 @@  discard block
 block discarded – undo
960 960
  * @return bool true s'il a le droit, false sinon
961 961
  **/
962 962
 function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
963
-	return
964
-		$qui['statut'] === '0minirezo';
963
+    return
964
+        $qui['statut'] === '0minirezo';
965 965
 }
966 966
 
967 967
 /**
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
  * @return bool true s'il a le droit, false sinon
980 980
  **/
981 981
 function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
982
-	return autoriser('webmestre', null, 0, $qui, $opt);
982
+    return autoriser('webmestre', null, 0, $qui, $opt);
983 983
 }
984 984
 
985 985
 /**
@@ -998,23 +998,23 @@  discard block
 block discarded – undo
998 998
  * @return bool true s'il a le droit, false sinon
999 999
  **/
1000 1000
 function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1001
-	// les admins peuvent "previsualiser" une page auteur
1002
-	if (
1003
-		$qui['statut'] === '0minirezo'
1004
-		and !$qui['restreint']
1005
-	) {
1006
-		return true;
1007
-	} elseif ($id === 0) {
1008
-		return false;
1009
-	}
1010
-	// "Voir en ligne" si l'auteur a un article publie
1011
-	$n = sql_fetsel(
1012
-		'A.id_article',
1013
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
1014
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
1015
-	);
1001
+    // les admins peuvent "previsualiser" une page auteur
1002
+    if (
1003
+        $qui['statut'] === '0minirezo'
1004
+        and !$qui['restreint']
1005
+    ) {
1006
+        return true;
1007
+    } elseif ($id === 0) {
1008
+        return false;
1009
+    }
1010
+    // "Voir en ligne" si l'auteur a un article publie
1011
+    $n = sql_fetsel(
1012
+        'A.id_article',
1013
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
1014
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
1015
+    );
1016 1016
 
1017
-	return $n ? true : false;
1017
+    return $n ? true : false;
1018 1018
 }
1019 1019
 
1020 1020
 
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
  * @return bool true s'il a le droit, false sinon
1044 1044
  **/
1045 1045
 function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1046
-	return ($qui['statut'] === '0minirezo');
1046
+    return ($qui['statut'] === '0minirezo');
1047 1047
 }
1048 1048
 
1049 1049
 
@@ -1064,75 +1064,75 @@  discard block
 block discarded – undo
1064 1064
  * @return bool true s'il a le droit, false sinon
1065 1065
  **/
1066 1066
 function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1067
-	$id = intval($id);
1068
-
1069
-	// Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1070
-	// la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1071
-	if (!in_array($qui['statut'], ['0minirezo'])) {
1072
-		if (
1073
-			$id == $qui['id_auteur']
1074
-			&& empty($opt['statut'])
1075
-			&& empty($opt['webmestre'])
1076
-			&& empty($opt['restreintes'])
1077
-			&& empty($opt['login'])
1078
-		) {
1079
-			return true;
1080
-		}
1081
-		return false;
1082
-	}
1083
-
1084
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
1085
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1086
-	if ($qui['restreint']) {
1087
-		if (isset($opt['webmestre']) and $opt['webmestre']) {
1088
-			return false;
1089
-		} elseif (
1090
-			(isset($opt['statut']) and ($opt['statut'] === '0minirezo'))
1091
-			or (isset($opt['restreintes']) and $opt['restreintes'])
1092
-		) {
1093
-			return false;
1094
-		} else {
1095
-			if ($id == $qui['id_auteur']) {
1096
-				if (isset($opt['statut']) and $opt['statut']) {
1097
-					return false;
1098
-				} else {
1099
-					return true;
1100
-				}
1101
-			} else {
1102
-				if ($id_auteur = intval($id)) {
1103
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1104
-					if ($t and $t['statut'] != '0minirezo') {
1105
-						return true;
1106
-					} else {
1107
-						return false;
1108
-					}
1109
-				} // id = 0 => creation
1110
-				else {
1111
-					return true;
1112
-				}
1113
-			}
1114
-		}
1115
-	}
1116
-
1117
-	// Un admin complet fait ce qu'il veut
1118
-	// sauf se degrader
1119
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1120
-		return false;
1121
-	} elseif (
1122
-		isset($opt['webmestre'])
1123
-				and $opt['webmestre']
1124
-				and (defined('_ID_WEBMESTRES')
1125
-				or !autoriser('webmestre'))
1126
-	) {
1127
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1128
-		// ou si les webmestres sont fixes par constante (securite)
1129
-		return false;
1130
-	} // et modifier un webmestre si il ne l'est pas lui meme
1131
-	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1132
-		return false;
1133
-	} else {
1134
-		return true;
1135
-	}
1067
+    $id = intval($id);
1068
+
1069
+    // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1070
+    // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1071
+    if (!in_array($qui['statut'], ['0minirezo'])) {
1072
+        if (
1073
+            $id == $qui['id_auteur']
1074
+            && empty($opt['statut'])
1075
+            && empty($opt['webmestre'])
1076
+            && empty($opt['restreintes'])
1077
+            && empty($opt['login'])
1078
+        ) {
1079
+            return true;
1080
+        }
1081
+        return false;
1082
+    }
1083
+
1084
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
1085
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1086
+    if ($qui['restreint']) {
1087
+        if (isset($opt['webmestre']) and $opt['webmestre']) {
1088
+            return false;
1089
+        } elseif (
1090
+            (isset($opt['statut']) and ($opt['statut'] === '0minirezo'))
1091
+            or (isset($opt['restreintes']) and $opt['restreintes'])
1092
+        ) {
1093
+            return false;
1094
+        } else {
1095
+            if ($id == $qui['id_auteur']) {
1096
+                if (isset($opt['statut']) and $opt['statut']) {
1097
+                    return false;
1098
+                } else {
1099
+                    return true;
1100
+                }
1101
+            } else {
1102
+                if ($id_auteur = intval($id)) {
1103
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1104
+                    if ($t and $t['statut'] != '0minirezo') {
1105
+                        return true;
1106
+                    } else {
1107
+                        return false;
1108
+                    }
1109
+                } // id = 0 => creation
1110
+                else {
1111
+                    return true;
1112
+                }
1113
+            }
1114
+        }
1115
+    }
1116
+
1117
+    // Un admin complet fait ce qu'il veut
1118
+    // sauf se degrader
1119
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1120
+        return false;
1121
+    } elseif (
1122
+        isset($opt['webmestre'])
1123
+                and $opt['webmestre']
1124
+                and (defined('_ID_WEBMESTRES')
1125
+                or !autoriser('webmestre'))
1126
+    ) {
1127
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1128
+        // ou si les webmestres sont fixes par constante (securite)
1129
+        return false;
1130
+    } // et modifier un webmestre si il ne l'est pas lui meme
1131
+    elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1132
+        return false;
1133
+    } else {
1134
+        return true;
1135
+    }
1136 1136
 }
1137 1137
 
1138 1138
 
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
  * @return bool true s'il a le droit, false sinon
1152 1152
  **/
1153 1153
 function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1154
-	return autoriser('modifier', $type, $id, $qui, $opt);
1154
+    return autoriser('modifier', $type, $id, $qui, $opt);
1155 1155
 }
1156 1156
 
1157 1157
 
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
  * @return bool true s'il a le droit, false sinon
1171 1171
  **/
1172 1172
 function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1173
-	return $qui['statut'] === '0minirezo';
1173
+    return $qui['statut'] === '0minirezo';
1174 1174
 }
1175 1175
 
1176 1176
 /**
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
  * @return bool true s'il a le droit, false sinon
1189 1189
  **/
1190 1190
 function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1191
-	return $qui['statut'] === '0minirezo';
1191
+    return $qui['statut'] === '0minirezo';
1192 1192
 }
1193 1193
 
1194 1194
 /**
@@ -1205,54 +1205,54 @@  discard block
 block discarded – undo
1205 1205
  * @return array          Liste des rubriques
1206 1206
  **/
1207 1207
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1208
-	static $restreint = [];
1209
-
1210
-	if (!$id_auteur = intval($id_auteur)) {
1211
-		return [];
1212
-	}
1213
-	if ($raz) {
1214
-		unset($restreint[$id_auteur]);
1215
-	} elseif (isset($restreint[$id_auteur])) {
1216
-		return $restreint[$id_auteur];
1217
-	}
1218
-
1219
-	$rubriques = [];
1220
-	if (
1221
-		(!isset($GLOBALS['meta']['version_installee'])
1222
-		or $GLOBALS['meta']['version_installee'] > 16428)
1223
-		and $r = sql_allfetsel(
1224
-			'id_objet',
1225
-			'spip_auteurs_liens',
1226
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1227
-		)
1228
-		and is_countable($r) ? count($r) : 0
1229
-	) {
1230
-		$r = array_column($r, 'id_objet');
1231
-
1232
-		// recuperer toute la branche, au format chaine enumeration
1233
-		include_spip('inc/rubriques');
1234
-		$r = calcul_branche_in($r);
1235
-		$r = explode(',', $r);
1236
-
1237
-		// passer les rubriques en index, elimine les doublons
1238
-		$r = array_flip($r);
1239
-		// recuperer les index seuls
1240
-		$r = array_keys($r);
1241
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1242
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1243
-		$rubriques = array_combine($r, $r);
1244
-	}
1245
-
1246
-	// Affecter l'auteur session le cas echeant
1247
-	if (
1248
-		isset($GLOBALS['visiteur_session']['id_auteur'])
1249
-		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1250
-	) {
1251
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1252
-	}
1253
-
1254
-
1255
-	return $restreint[$id_auteur] = $rubriques;
1208
+    static $restreint = [];
1209
+
1210
+    if (!$id_auteur = intval($id_auteur)) {
1211
+        return [];
1212
+    }
1213
+    if ($raz) {
1214
+        unset($restreint[$id_auteur]);
1215
+    } elseif (isset($restreint[$id_auteur])) {
1216
+        return $restreint[$id_auteur];
1217
+    }
1218
+
1219
+    $rubriques = [];
1220
+    if (
1221
+        (!isset($GLOBALS['meta']['version_installee'])
1222
+        or $GLOBALS['meta']['version_installee'] > 16428)
1223
+        and $r = sql_allfetsel(
1224
+            'id_objet',
1225
+            'spip_auteurs_liens',
1226
+            'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1227
+        )
1228
+        and is_countable($r) ? count($r) : 0
1229
+    ) {
1230
+        $r = array_column($r, 'id_objet');
1231
+
1232
+        // recuperer toute la branche, au format chaine enumeration
1233
+        include_spip('inc/rubriques');
1234
+        $r = calcul_branche_in($r);
1235
+        $r = explode(',', $r);
1236
+
1237
+        // passer les rubriques en index, elimine les doublons
1238
+        $r = array_flip($r);
1239
+        // recuperer les index seuls
1240
+        $r = array_keys($r);
1241
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1242
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1243
+        $rubriques = array_combine($r, $r);
1244
+    }
1245
+
1246
+    // Affecter l'auteur session le cas echeant
1247
+    if (
1248
+        isset($GLOBALS['visiteur_session']['id_auteur'])
1249
+        and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1250
+    ) {
1251
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1252
+    }
1253
+
1254
+
1255
+    return $restreint[$id_auteur] = $rubriques;
1256 1256
 }
1257 1257
 
1258 1258
 /**
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
  * @return bool true s'il a le droit, false sinon
1271 1271
  **/
1272 1272
 function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1273
-	return autoriser('previsualiser');
1273
+    return autoriser('previsualiser');
1274 1274
 }
1275 1275
 
1276 1276
 /**
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
  * @return bool true s'il a le droit, false sinon
1289 1289
  **/
1290 1290
 function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1291
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1291
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1292 1292
 }
1293 1293
 
1294 1294
 /**
@@ -1306,9 +1306,9 @@  discard block
 block discarded – undo
1306 1306
  * @return bool true s'il a le droit, false sinon
1307 1307
  **/
1308 1308
 function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1309
-	$id = intval($id);
1310
-	return (($id == $qui['id_auteur']) or
1311
-		(($qui['statut'] === '0minirezo') and !$qui['restreint']));
1309
+    $id = intval($id);
1310
+    return (($id == $qui['id_auteur']) or
1311
+        (($qui['statut'] === '0minirezo') and !$qui['restreint']));
1312 1312
 }
1313 1313
 
1314 1314
 /**
@@ -1326,8 +1326,8 @@  discard block
 block discarded – undo
1326 1326
  * @return bool true s'il a le droit, false sinon
1327 1327
  **/
1328 1328
 function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1329
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1330
-	return autoriser('modifier', $type, $id, $qui, $opt);
1329
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1330
+    return autoriser('modifier', $type, $id, $qui, $opt);
1331 1331
 }
1332 1332
 
1333 1333
 
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
  * @return true
1348 1348
  **/
1349 1349
 function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1350
-	return true;
1350
+    return true;
1351 1351
 }
1352 1352
 
1353 1353
 /**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
  * @return false
1367 1367
  **/
1368 1368
 function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1369
-	return false;
1369
+    return false;
1370 1370
 }
1371 1371
 
1372 1372
 /**
@@ -1384,11 +1384,11 @@  discard block
 block discarded – undo
1384 1384
  * @return bool true s'il a le droit, false sinon
1385 1385
  **/
1386 1386
 function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1387
-	if (!autoriser('detruire') or _request('reinstall')) {
1388
-		return false;
1389
-	}
1387
+    if (!autoriser('detruire') or _request('reinstall')) {
1388
+        return false;
1389
+    }
1390 1390
 
1391
-	return true;
1391
+    return true;
1392 1392
 }
1393 1393
 
1394 1394
 /**
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
  * @return true
1407 1407
  **/
1408 1408
 function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1409
-	return true;
1409
+    return true;
1410 1410
 }
1411 1411
 
1412 1412
 /**
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
  * @return true
1425 1425
  **/
1426 1426
 function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1427
-	return true;
1427
+    return true;
1428 1428
 }
1429 1429
 
1430 1430
 /**
@@ -1442,7 +1442,7 @@  discard block
 block discarded – undo
1442 1442
  * @return bool true s'il a le droit, false sinon
1443 1443
  **/
1444 1444
 function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1445
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1445
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1446 1446
 }
1447 1447
 
1448 1448
 /**
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
  * @return true
1461 1461
  **/
1462 1462
 function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1463
-	return true;
1463
+    return true;
1464 1464
 }
1465 1465
 
1466 1466
 /**
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
  * @return bool true s'il a le droit, false sinon
1479 1479
  **/
1480 1480
 function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1481
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1481
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1482 1482
 }
1483 1483
 
1484 1484
 /**
@@ -1496,8 +1496,8 @@  discard block
 block discarded – undo
1496 1496
  * @return bool true s'il a le droit, false sinon
1497 1497
  **/
1498 1498
 function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1499
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1500
-		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1499
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1500
+        and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1501 1501
 }
1502 1502
 
1503 1503
 /**
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
  * @return true
1517 1517
  **/
1518 1518
 function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1519
-	return true;
1519
+    return true;
1520 1520
 }
1521 1521
 
1522 1522
 /**
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
  * @return true
1535 1535
  **/
1536 1536
 function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1537
-	return true;
1537
+    return true;
1538 1538
 }
1539 1539
 
1540 1540
 /**
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
  * @return bool true s'il a le droit, false sinon
1553 1553
  **/
1554 1554
 function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1555
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1555
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1556 1556
 }
1557 1557
 
1558 1558
 /**
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
  * @return true
1571 1571
  **/
1572 1572
 function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1573
-	return true;
1573
+    return true;
1574 1574
 }
1575 1575
 
1576 1576
 /**
@@ -1588,7 +1588,7 @@  discard block
 block discarded – undo
1588 1588
  * @return bool true s'il a le droit, false sinon
1589 1589
  **/
1590 1590
 function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1591
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1591
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1592 1592
 }
1593 1593
 
1594 1594
 /**
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
  * @return true
1607 1607
  **/
1608 1608
 function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1609
-	return true;
1609
+    return true;
1610 1610
 }
1611 1611
 
1612 1612
 /**
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
  * @return bool true s'il a le droit, false sinon
1625 1625
  **/
1626 1626
 function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1627
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1627
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1628 1628
 }
1629 1629
 
1630 1630
 /**
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
  * @return bool true s'il a le droit, false sinon
1643 1643
  **/
1644 1644
 function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1645
-	return verifier_table_non_vide();
1645
+    return verifier_table_non_vide();
1646 1646
 }
1647 1647
 
1648 1648
 
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
  * @return bool true s'il a le droit, false sinon
1664 1664
  **/
1665 1665
 function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1666
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1666
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1681,13 +1681,13 @@  discard block
 block discarded – undo
1681 1681
  * @return bool true s'il a le droit, false sinon
1682 1682
  **/
1683 1683
 function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1684
-	include_spip('base/abstract_sql');
1685
-	return
1686
-		$qui['statut'] === '0minirezo' and !$qui['restreint']
1687
-		and (
1688
-			$GLOBALS['meta']['accepter_visiteurs'] != 'non'
1689
-			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1690
-		);
1684
+    include_spip('base/abstract_sql');
1685
+    return
1686
+        $qui['statut'] === '0minirezo' and !$qui['restreint']
1687
+        and (
1688
+            $GLOBALS['meta']['accepter_visiteurs'] != 'non'
1689
+            or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1690
+        );
1691 1691
 }
1692 1692
 
1693 1693
 /**
@@ -1705,7 +1705,7 @@  discard block
 block discarded – undo
1705 1705
  * @return bool true s'il a le droit, false sinon
1706 1706
  **/
1707 1707
 function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1708
-	return $qui['statut'] === '0minirezo';
1708
+    return $qui['statut'] === '0minirezo';
1709 1709
 }
1710 1710
 
1711 1711
 /**
@@ -1723,7 +1723,7 @@  discard block
 block discarded – undo
1723 1723
  * @return bool true s'il a le droit, false sinon
1724 1724
  **/
1725 1725
 function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1726
-	return $qui['statut'] === '0minirezo';
1726
+    return $qui['statut'] === '0minirezo';
1727 1727
 }
1728 1728
 
1729 1729
 /**
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
  * @return bool true s'il a le droit, false sinon
1742 1742
  **/
1743 1743
 function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1744
-	return autoriser('configurer', '_interactions', $id, $qui, $opt);
1744
+    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1745 1745
 }
1746 1746
 
1747 1747
 /**
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
  * @return bool true s'il a le droit, false sinon
1760 1760
  **/
1761 1761
 function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1762
-	return autoriser('configurer', '_langue', $id, $qui, $opt);
1762
+    return autoriser('configurer', '_langue', $id, $qui, $opt);
1763 1763
 }
1764 1764
 
1765 1765
 /**
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
  * @return bool true s'il a le droit, false sinon
1778 1778
  **/
1779 1779
 function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1780
-	return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1780
+    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1781 1781
 }
1782 1782
 
1783 1783
 /**
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
  * @return bool true s'il a le droit, false sinon
1796 1796
  **/
1797 1797
 function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1798
-	return autoriser('configurer', '_contenu', $id, $qui, $opt);
1798
+    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1799 1799
 }
1800 1800
 
1801 1801
 /**
@@ -1813,7 +1813,7 @@  discard block
 block discarded – undo
1813 1813
  * @return bool true s'il a le droit, false sinon
1814 1814
  **/
1815 1815
 function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1816
-	return autoriser('configurer', '_avancees', $id, $qui, $opt);
1816
+    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1817 1817
 }
1818 1818
 
1819 1819
 /**
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
  * @return bool true s'il a le droit, false sinon
1832 1832
  **/
1833 1833
 function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1834
-	return autoriser('configurer', '_plugins', $id, $qui, $opt);
1834
+    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1835 1835
 }
1836 1836
 
1837 1837
 /**
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
  * @return bool true s'il a le droit, false sinon
1850 1850
  **/
1851 1851
 function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1852
-	return autoriser('detruire', $type, $id, $qui, $opt);
1852
+    return autoriser('detruire', $type, $id, $qui, $opt);
1853 1853
 }
1854 1854
 
1855 1855
 /**
@@ -1867,7 +1867,7 @@  discard block
 block discarded – undo
1867 1867
  * @return bool true s'il a le droit, false sinon
1868 1868
  **/
1869 1869
 function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1870
-	return autoriser('webmestre');
1870
+    return autoriser('webmestre');
1871 1871
 }
1872 1872
 
1873 1873
 
@@ -1887,11 +1887,11 @@  discard block
 block discarded – undo
1887 1887
  * @return bool true s'il a le droit, false sinon
1888 1888
  **/
1889 1889
 function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1890
-	if (test_espace_prive()) {
1891
-		return intval($qui['id_auteur']) ? true : false;
1892
-	} else {
1893
-		return autoriser('webmestre', '', $id, $qui, $opt);
1894
-	}
1890
+    if (test_espace_prive()) {
1891
+        return intval($qui['id_auteur']) ? true : false;
1892
+    } else {
1893
+        return autoriser('webmestre', '', $id, $qui, $opt);
1894
+    }
1895 1895
 }
1896 1896
 
1897 1897
 
@@ -1906,27 +1906,27 @@  discard block
 block discarded – undo
1906 1906
  *     Identifiants d'auteurs
1907 1907
  */
1908 1908
 function auteurs_objet($objet, $id_objet, $cond = '') {
1909
-	$objet = objet_type($objet);
1910
-	$where = [
1911
-		'objet=' . sql_quote($objet),
1912
-		'id_objet=' . intval($id_objet)
1913
-	];
1914
-	if (!empty($cond)) {
1915
-		if (is_array($cond)) {
1916
-			$where = array_merge($where, $cond);
1917
-		} else {
1918
-			$where[] = $cond;
1919
-		}
1920
-	}
1921
-	$auteurs = sql_allfetsel(
1922
-		'id_auteur',
1923
-		'spip_auteurs_liens',
1924
-		$where
1925
-	);
1926
-	if (is_array($auteurs)) {
1927
-		return array_column($auteurs, 'id_auteur');
1928
-	}
1929
-	return [];
1909
+    $objet = objet_type($objet);
1910
+    $where = [
1911
+        'objet=' . sql_quote($objet),
1912
+        'id_objet=' . intval($id_objet)
1913
+    ];
1914
+    if (!empty($cond)) {
1915
+        if (is_array($cond)) {
1916
+            $where = array_merge($where, $cond);
1917
+        } else {
1918
+            $where[] = $cond;
1919
+        }
1920
+    }
1921
+    $auteurs = sql_allfetsel(
1922
+        'id_auteur',
1923
+        'spip_auteurs_liens',
1924
+        $where
1925
+    );
1926
+    if (is_array($auteurs)) {
1927
+        return array_column($auteurs, 'id_auteur');
1928
+    }
1929
+    return [];
1930 1930
 }
1931 1931
 
1932 1932
 /**
@@ -1941,11 +1941,11 @@  discard block
 block discarded – undo
1941 1941
  *     - false : serveur SQL indisponible
1942 1942
  */
1943 1943
 function auteurs_article($id_article, $cond = '') {
1944
-	return sql_allfetsel(
1945
-		'id_auteur',
1946
-		'spip_auteurs_liens',
1947
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1948
-	);
1944
+    return sql_allfetsel(
1945
+        'id_auteur',
1946
+        'spip_auteurs_liens',
1947
+        "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1948
+    );
1949 1949
 }
1950 1950
 
1951 1951
 
@@ -1959,7 +1959,7 @@  discard block
 block discarded – undo
1959 1959
  */
1960 1960
 function acces_restreint_rubrique($id_rubrique) {
1961 1961
 
1962
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1962
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1963 1963
 }
1964 1964
 
1965 1965
 
@@ -1972,12 +1972,12 @@  discard block
 block discarded – undo
1972 1972
  * @return bool             true si un parent existe
1973 1973
  */
1974 1974
 function verifier_table_non_vide($table = 'spip_rubriques') {
1975
-	static $done = [];
1976
-	if (!isset($done[$table])) {
1977
-		$done[$table] = sql_countsel($table) > 0;
1978
-	}
1975
+    static $done = [];
1976
+    if (!isset($done[$table])) {
1977
+        $done[$table] = sql_countsel($table) > 0;
1978
+    }
1979 1979
 
1980
-	return $done[$table];
1980
+    return $done[$table];
1981 1981
 }
1982 1982
 
1983 1983
 /**
@@ -2004,15 +2004,15 @@  discard block
 block discarded – undo
2004 2004
  */
2005 2005
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
2006 2006
 
2007
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
2008
-	switch ($s) {
2009
-		case 'info_redacteurs':
2010
-			return ($GLOBALS['meta']['accepter_inscriptions'] === 'oui');
2011
-		case 'info_visiteurs':
2012
-			return ($GLOBALS['meta']['accepter_visiteurs'] === 'oui' or $GLOBALS['meta']['forums_publics'] === 'abo');
2013
-	}
2007
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
2008
+    switch ($s) {
2009
+        case 'info_redacteurs':
2010
+            return ($GLOBALS['meta']['accepter_inscriptions'] === 'oui');
2011
+        case 'info_visiteurs':
2012
+            return ($GLOBALS['meta']['accepter_visiteurs'] === 'oui' or $GLOBALS['meta']['forums_publics'] === 'abo');
2013
+    }
2014 2014
 
2015
-	return false;
2015
+    return false;
2016 2016
 }
2017 2017
 
2018 2018
 /**
@@ -2030,7 +2030,7 @@  discard block
 block discarded – undo
2030 2030
  * @return bool true s'il a le droit, false sinon
2031 2031
  **/
2032 2032
 function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
2033
-	return $qui['statut'] === '0minirezo' and !$qui['restreint'];
2033
+    return $qui['statut'] === '0minirezo' and !$qui['restreint'];
2034 2034
 }
2035 2035
 
2036 2036
 /**
@@ -2048,5 +2048,5 @@  discard block
 block discarded – undo
2048 2048
  * @return bool true s'il a le droit, false sinon
2049 2049
  **/
2050 2050
 function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
2051
-	return autoriser('webmestre');
2051
+    return autoriser('webmestre');
2052 2052
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 1 patch
Indentation   +1351 added lines, -1351 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,59 +120,59 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$H = null;
124
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
-	$var_G = ($G / 255);
126
-	$var_B = ($B / 255);
127
-
128
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
131
-
132
-	$L = ($var_Max + $var_Min) / 2;
133
-
134
-	if ($del_Max == 0) {
135
-		//This is a gray, no chroma...
136
-		$H = 0; //HSL results = 0 ÷ 1
137
-		$S = 0;
138
-	} else {
139
-		// Chromatic data...
140
-		if ($L < 0.5) {
141
-			$S = $del_Max / ($var_Max + $var_Min);
142
-		} else {
143
-			$S = $del_Max / (2 - $var_Max - $var_Min);
144
-		}
145
-
146
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
-
150
-		if ($var_R == $var_Max) {
151
-			$H = $del_B - $del_G;
152
-		} else {
153
-			if ($var_G == $var_Max) {
154
-				$H = (1 / 3) + $del_R - $del_B;
155
-			} else {
156
-				if ($var_B == $var_Max) {
157
-					$H = (2 / 3) + $del_G - $del_R;
158
-				}
159
-			}
160
-		}
161
-
162
-		if ($H < 0) {
163
-			$H += 1;
164
-		}
165
-		if ($H > 1) {
166
-			$H -= 1;
167
-		}
168
-	}
169
-
170
-	$ret = [];
171
-	$ret['h'] = $H;
172
-	$ret['s'] = $S;
173
-	$ret['l'] = $L;
174
-
175
-	return $ret;
123
+    $H = null;
124
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
125
+    $var_G = ($G / 255);
126
+    $var_B = ($B / 255);
127
+
128
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
129
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
130
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
131
+
132
+    $L = ($var_Max + $var_Min) / 2;
133
+
134
+    if ($del_Max == 0) {
135
+        //This is a gray, no chroma...
136
+        $H = 0; //HSL results = 0 ÷ 1
137
+        $S = 0;
138
+    } else {
139
+        // Chromatic data...
140
+        if ($L < 0.5) {
141
+            $S = $del_Max / ($var_Max + $var_Min);
142
+        } else {
143
+            $S = $del_Max / (2 - $var_Max - $var_Min);
144
+        }
145
+
146
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
147
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
149
+
150
+        if ($var_R == $var_Max) {
151
+            $H = $del_B - $del_G;
152
+        } else {
153
+            if ($var_G == $var_Max) {
154
+                $H = (1 / 3) + $del_R - $del_B;
155
+            } else {
156
+                if ($var_B == $var_Max) {
157
+                    $H = (2 / 3) + $del_G - $del_R;
158
+                }
159
+            }
160
+        }
161
+
162
+        if ($H < 0) {
163
+            $H += 1;
164
+        }
165
+        if ($H > 1) {
166
+            $H -= 1;
167
+        }
168
+    }
169
+
170
+    $ret = [];
171
+    $ret['h'] = $H;
172
+    $ret['s'] = $S;
173
+    $ret['l'] = $L;
174
+
175
+    return $ret;
176 176
 }
177 177
 
178 178
 
@@ -188,52 +188,52 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function _couleur_hsl_to_rgb($H, $S, $L) {
191
-	// helper
192
-	$hue_2_rgb = function ($v1, $v2, $vH) {
193
-		if ($vH < 0) {
194
-			$vH += 1;
195
-		}
196
-		if ($vH > 1) {
197
-			$vH -= 1;
198
-		}
199
-		if ((6 * $vH) < 1) {
200
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
201
-		}
202
-		if ((2 * $vH) < 1) {
203
-			return ($v2);
204
-		}
205
-		if ((3 * $vH) < 2) {
206
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
-		}
208
-
209
-		return ($v1);
210
-	};
211
-
212
-	if ($S == 0) {
213
-		// HSV values = 0 -> 1
214
-		$R = $L * 255;
215
-		$G = $L * 255;
216
-		$B = $L * 255;
217
-	} else {
218
-		if ($L < 0.5) {
219
-			$var_2 = $L * (1 + $S);
220
-		} else {
221
-			$var_2 = ($L + $S) - ($S * $L);
222
-		}
223
-
224
-		$var_1 = 2 * $L - $var_2;
225
-
226
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
-	}
230
-
231
-	$ret = [];
232
-	$ret['r'] = floor($R);
233
-	$ret['g'] = floor($G);
234
-	$ret['b'] = floor($B);
235
-
236
-	return $ret;
191
+    // helper
192
+    $hue_2_rgb = function ($v1, $v2, $vH) {
193
+        if ($vH < 0) {
194
+            $vH += 1;
195
+        }
196
+        if ($vH > 1) {
197
+            $vH -= 1;
198
+        }
199
+        if ((6 * $vH) < 1) {
200
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
201
+        }
202
+        if ((2 * $vH) < 1) {
203
+            return ($v2);
204
+        }
205
+        if ((3 * $vH) < 2) {
206
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
207
+        }
208
+
209
+        return ($v1);
210
+    };
211
+
212
+    if ($S == 0) {
213
+        // HSV values = 0 -> 1
214
+        $R = $L * 255;
215
+        $G = $L * 255;
216
+        $B = $L * 255;
217
+    } else {
218
+        if ($L < 0.5) {
219
+            $var_2 = $L * (1 + $S);
220
+        } else {
221
+            $var_2 = ($L + $S) - ($S * $L);
222
+        }
223
+
224
+        $var_1 = 2 * $L - $var_2;
225
+
226
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
227
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
228
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
229
+    }
230
+
231
+    $ret = [];
232
+    $ret['r'] = floor($R);
233
+    $ret['g'] = floor($G);
234
+    $ret['b'] = floor($B);
235
+
236
+    return $ret;
237 237
 }
238 238
 
239 239
 /**
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
  *     true si il faut supprimer le fichier temporaire ; false sinon.
251 251
  */
252 252
 function statut_effacer_images_temporaires($stat) {
253
-	static $statut = false; // par defaut on grave toute les images
254
-	if ($stat === 'get') {
255
-		return $statut;
256
-	}
257
-	$statut = $stat ? true : false;
253
+    static $statut = false; // par defaut on grave toute les images
254
+    if ($stat === 'get') {
255
+        return $statut;
256
+    }
257
+    $statut = $stat ? true : false;
258 258
 }
259 259
 
260 260
 
@@ -307,243 +307,243 @@  discard block
 block discarded – undo
307 307
  *     - array : tableau décrivant de l'image
308 308
  */
309 309
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
310
-	$ret = [];
311
-	$f = null;
312
-	static $images_recalcul = [];
313
-	if (strlen($img) == 0) {
314
-		return false;
315
-	}
316
-
317
-	$source = trim(extraire_attribut($img, 'src') ?? '');
318
-	if (strlen($source) < 1) {
319
-		$source = $img;
320
-		$img = "<img src='$source' />";
321
-	} elseif (
322
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
323
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
-		and in_array($extension, _image_extensions_acceptees_en_entree())
325
-	) {
326
-		# gerer img src="data:....base64"
327
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
-		if (!file_exists($local)) {
329
-			ecrire_fichier($local, base64_decode($regs[2]));
330
-		}
331
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
332
-			$sanitizer($local);
333
-		}
334
-		$source = $local;
335
-		$img = inserer_attribut($img, 'src', $source);
336
-		# eviter les mauvaises surprises lors de conversions de format
337
-		$img = inserer_attribut($img, 'width', '');
338
-		$img = inserer_attribut($img, 'height', '');
339
-	}
340
-
341
-	// les protocoles web prennent au moins 3 lettres
342
-	if (tester_url_absolue($source)) {
343
-		include_spip('inc/distant');
344
-		$fichier = _DIR_RACINE . copie_locale($source);
345
-		if (!$fichier) {
346
-			return '';
347
-		}
348
-		if (
349
-			$extension = _image_trouver_extension($fichier)
350
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
351
-		) {
352
-			$sanitizer($fichier);
353
-		}
354
-	} else {
355
-		// enlever le timestamp eventuel
356
-		if (strpos($source, '?') !== false) {
357
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
358
-		}
359
-		if (
360
-			strpos($source, '?') !== false
361
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
362
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
363
-		) {
364
-			$source = $f;
365
-		}
366
-		$fichier = $source;
367
-	}
368
-
369
-	$terminaison_dest = '';
370
-	if ($terminaison = _image_trouver_extension($fichier)) {
371
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
372
-	}
373
-
374
-	if (
375
-		$forcer_format !== false
376
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
377
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
378
-	) {
379
-		$terminaison_dest = $forcer_format;
380
-	}
381
-
382
-	if (!$terminaison_dest) {
383
-		return false;
384
-	}
385
-
386
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
387
-	$fichier_dest = $nom_fichier;
388
-	if (
389
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
390
-		or @file_exists($f = $fichier)
391
-	) {
392
-		// on passe la balise img a taille image qui exraira les attributs si possible
393
-		// au lieu de faire un acces disque sur le fichier
394
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
395
-		$date_src = @filemtime($f);
396
-	} elseif (
397
-		@file_exists($f = "$fichier.src")
398
-		and lire_fichier($f, $valeurs)
399
-		and $valeurs = unserialize($valeurs)
400
-		and isset($valeurs['hauteur_dest'])
401
-		and isset($valeurs['largeur_dest'])
402
-	) {
403
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
404
-		$ret['largeur'] = $valeurs['largeur_dest'];
405
-		$date_src = $valeurs['date'];
406
-	} // pas de fichier source par la
407
-	else {
408
-		return false;
409
-	}
410
-
411
-	// pas de taille mesurable
412
-	if (!($ret['hauteur'] or $ret['largeur'])) {
413
-		return false;
414
-	}
415
-
416
-	// les images calculees dependent du chemin du fichier source
417
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
418
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
419
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
420
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
421
-	// alors que ca concerne peu de site au final
422
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
423
-	$identifiant = $fichier;
424
-
425
-	// cas general :
426
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
427
-	// cas particulier de reduire :
428
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
429
-	$cache = 'cache-gd2';
430
-	if (substr($effet, 0, 7) == 'reduire') {
431
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
432
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
433
-		$ret['largeur_dest'] = $destWidth;
434
-		$ret['hauteur_dest'] = $destHeight;
435
-		$effet = "L{$destWidth}xH$destHeight";
436
-		$cache = 'cache-vignettes';
437
-		$fichier_dest = basename($fichier_dest);
438
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
439
-			// on garde la terminaison initiale car image simplement copiee
440
-			// et on postfixe son nom avec un md5 du path
441
-			$terminaison_dest = $terminaison;
442
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
-		} else {
444
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
-		}
446
-		$cache = sous_repertoire(_DIR_VAR, $cache);
447
-		$cache = sous_repertoire($cache, $effet);
448
-	} else {
449
-		$fichier_dest = md5("$identifiant-$effet");
450
-		$cache = sous_repertoire(_DIR_VAR, $cache);
451
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
452
-		$fichier_dest = substr($fichier_dest, 2);
453
-	}
454
-
455
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
-
457
-	$GLOBALS['images_calculees'][] = $fichier_dest;
458
-
459
-	$creer = true;
460
-	// si recalcul des images demande, recalculer chaque image une fois
461
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
462
-		$images_recalcul[$fichier_dest] = true;
463
-	} else {
464
-		if (@file_exists($f = $fichier_dest)) {
465
-			if (filemtime($f) >= $date_src) {
466
-				$creer = false;
467
-			}
468
-		} else {
469
-			if (
470
-				@file_exists($f = "$fichier_dest.src")
471
-				and lire_fichier($f, $valeurs)
472
-				and $valeurs = unserialize($valeurs)
473
-				and $valeurs['date'] >= $date_src
474
-			) {
475
-				$creer = false;
476
-			}
477
-		}
478
-	}
479
-	if ($creer) {
480
-		if (!@file_exists($fichier)) {
481
-			if (!@file_exists("$fichier.src")) {
482
-				spip_log("Image absente : $fichier");
483
-
484
-				return false;
485
-			}
486
-			# on reconstruit l'image source absente a partir de la chaine des .src
487
-			reconstruire_image_intermediaire($fichier);
488
-		}
489
-	}
490
-
491
-	if ($creer) {
492
-		spip_log(
493
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
-			'images' . _LOG_DEBUG
495
-		);
496
-	}
497
-
498
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
499
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
-	$ret['fichier'] = $fichier;
501
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
-	$ret['fichier_dest'] = $fichier_dest;
503
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
504
-	$ret['format_dest'] = $terminaison_dest;
505
-	$ret['date_src'] = $date_src;
506
-	$ret['creer'] = $creer;
507
-	$ret['class'] = extraire_attribut($img, 'class');
508
-	$ret['alt'] = extraire_attribut($img, 'alt');
509
-	$ret['style'] = extraire_attribut($img, 'style');
510
-	$ret['tag'] = $img;
511
-	if ($fonction_creation) {
512
-		$ret['reconstruction'] = $fonction_creation;
513
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
-		# cas de image_reduire qui finalement ne reduit pas l'image source
515
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
-	}
518
-
519
-	$ret = pipeline('image_preparer_filtre', [
520
-			'args' => [
521
-				'img' => $img,
522
-				'effet' => $effet,
523
-				'forcer_format' => $forcer_format,
524
-				'fonction_creation' => $fonction_creation,
525
-				'find_in_path' => $find_in_path,
526
-			],
527
-			'data' => $ret
528
-		]);
529
-
530
-	// une globale pour le debug en cas de crash memoire
531
-	$GLOBALS['derniere_image_calculee'] = $ret;
532
-
533
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
-	if ($term_fonction === 'svg') {
535
-		if ($creer and !$support_svg) {
536
-			process_image_svg_identite($ret);
537
-			$ret['creer'] = false;
538
-		}
539
-	}
540
-	else {
541
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
-			return false;
543
-		}
544
-	}
545
-
546
-	return $ret;
310
+    $ret = [];
311
+    $f = null;
312
+    static $images_recalcul = [];
313
+    if (strlen($img) == 0) {
314
+        return false;
315
+    }
316
+
317
+    $source = trim(extraire_attribut($img, 'src') ?? '');
318
+    if (strlen($source) < 1) {
319
+        $source = $img;
320
+        $img = "<img src='$source' />";
321
+    } elseif (
322
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
323
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
324
+        and in_array($extension, _image_extensions_acceptees_en_entree())
325
+    ) {
326
+        # gerer img src="data:....base64"
327
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
328
+        if (!file_exists($local)) {
329
+            ecrire_fichier($local, base64_decode($regs[2]));
330
+        }
331
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
332
+            $sanitizer($local);
333
+        }
334
+        $source = $local;
335
+        $img = inserer_attribut($img, 'src', $source);
336
+        # eviter les mauvaises surprises lors de conversions de format
337
+        $img = inserer_attribut($img, 'width', '');
338
+        $img = inserer_attribut($img, 'height', '');
339
+    }
340
+
341
+    // les protocoles web prennent au moins 3 lettres
342
+    if (tester_url_absolue($source)) {
343
+        include_spip('inc/distant');
344
+        $fichier = _DIR_RACINE . copie_locale($source);
345
+        if (!$fichier) {
346
+            return '';
347
+        }
348
+        if (
349
+            $extension = _image_trouver_extension($fichier)
350
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
351
+        ) {
352
+            $sanitizer($fichier);
353
+        }
354
+    } else {
355
+        // enlever le timestamp eventuel
356
+        if (strpos($source, '?') !== false) {
357
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
358
+        }
359
+        if (
360
+            strpos($source, '?') !== false
361
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
362
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
363
+        ) {
364
+            $source = $f;
365
+        }
366
+        $fichier = $source;
367
+    }
368
+
369
+    $terminaison_dest = '';
370
+    if ($terminaison = _image_trouver_extension($fichier)) {
371
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
372
+    }
373
+
374
+    if (
375
+        $forcer_format !== false
376
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
377
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
378
+    ) {
379
+        $terminaison_dest = $forcer_format;
380
+    }
381
+
382
+    if (!$terminaison_dest) {
383
+        return false;
384
+    }
385
+
386
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
387
+    $fichier_dest = $nom_fichier;
388
+    if (
389
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
390
+        or @file_exists($f = $fichier)
391
+    ) {
392
+        // on passe la balise img a taille image qui exraira les attributs si possible
393
+        // au lieu de faire un acces disque sur le fichier
394
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
395
+        $date_src = @filemtime($f);
396
+    } elseif (
397
+        @file_exists($f = "$fichier.src")
398
+        and lire_fichier($f, $valeurs)
399
+        and $valeurs = unserialize($valeurs)
400
+        and isset($valeurs['hauteur_dest'])
401
+        and isset($valeurs['largeur_dest'])
402
+    ) {
403
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
404
+        $ret['largeur'] = $valeurs['largeur_dest'];
405
+        $date_src = $valeurs['date'];
406
+    } // pas de fichier source par la
407
+    else {
408
+        return false;
409
+    }
410
+
411
+    // pas de taille mesurable
412
+    if (!($ret['hauteur'] or $ret['largeur'])) {
413
+        return false;
414
+    }
415
+
416
+    // les images calculees dependent du chemin du fichier source
417
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
418
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
419
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
420
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
421
+    // alors que ca concerne peu de site au final
422
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
423
+    $identifiant = $fichier;
424
+
425
+    // cas general :
426
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
427
+    // cas particulier de reduire :
428
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
429
+    $cache = 'cache-gd2';
430
+    if (substr($effet, 0, 7) == 'reduire') {
431
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
432
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
433
+        $ret['largeur_dest'] = $destWidth;
434
+        $ret['hauteur_dest'] = $destHeight;
435
+        $effet = "L{$destWidth}xH$destHeight";
436
+        $cache = 'cache-vignettes';
437
+        $fichier_dest = basename($fichier_dest);
438
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
439
+            // on garde la terminaison initiale car image simplement copiee
440
+            // et on postfixe son nom avec un md5 du path
441
+            $terminaison_dest = $terminaison;
442
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
443
+        } else {
444
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
445
+        }
446
+        $cache = sous_repertoire(_DIR_VAR, $cache);
447
+        $cache = sous_repertoire($cache, $effet);
448
+    } else {
449
+        $fichier_dest = md5("$identifiant-$effet");
450
+        $cache = sous_repertoire(_DIR_VAR, $cache);
451
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
452
+        $fichier_dest = substr($fichier_dest, 2);
453
+    }
454
+
455
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
456
+
457
+    $GLOBALS['images_calculees'][] = $fichier_dest;
458
+
459
+    $creer = true;
460
+    // si recalcul des images demande, recalculer chaque image une fois
461
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
462
+        $images_recalcul[$fichier_dest] = true;
463
+    } else {
464
+        if (@file_exists($f = $fichier_dest)) {
465
+            if (filemtime($f) >= $date_src) {
466
+                $creer = false;
467
+            }
468
+        } else {
469
+            if (
470
+                @file_exists($f = "$fichier_dest.src")
471
+                and lire_fichier($f, $valeurs)
472
+                and $valeurs = unserialize($valeurs)
473
+                and $valeurs['date'] >= $date_src
474
+            ) {
475
+                $creer = false;
476
+            }
477
+        }
478
+    }
479
+    if ($creer) {
480
+        if (!@file_exists($fichier)) {
481
+            if (!@file_exists("$fichier.src")) {
482
+                spip_log("Image absente : $fichier");
483
+
484
+                return false;
485
+            }
486
+            # on reconstruit l'image source absente a partir de la chaine des .src
487
+            reconstruire_image_intermediaire($fichier);
488
+        }
489
+    }
490
+
491
+    if ($creer) {
492
+        spip_log(
493
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
494
+            'images' . _LOG_DEBUG
495
+        );
496
+    }
497
+
498
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
499
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
500
+    $ret['fichier'] = $fichier;
501
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
502
+    $ret['fichier_dest'] = $fichier_dest;
503
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
504
+    $ret['format_dest'] = $terminaison_dest;
505
+    $ret['date_src'] = $date_src;
506
+    $ret['creer'] = $creer;
507
+    $ret['class'] = extraire_attribut($img, 'class');
508
+    $ret['alt'] = extraire_attribut($img, 'alt');
509
+    $ret['style'] = extraire_attribut($img, 'style');
510
+    $ret['tag'] = $img;
511
+    if ($fonction_creation) {
512
+        $ret['reconstruction'] = $fonction_creation;
513
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
514
+        # cas de image_reduire qui finalement ne reduit pas l'image source
515
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
516
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
517
+    }
518
+
519
+    $ret = pipeline('image_preparer_filtre', [
520
+            'args' => [
521
+                'img' => $img,
522
+                'effet' => $effet,
523
+                'forcer_format' => $forcer_format,
524
+                'fonction_creation' => $fonction_creation,
525
+                'find_in_path' => $find_in_path,
526
+            ],
527
+            'data' => $ret
528
+        ]);
529
+
530
+    // une globale pour le debug en cas de crash memoire
531
+    $GLOBALS['derniere_image_calculee'] = $ret;
532
+
533
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
534
+    if ($term_fonction === 'svg') {
535
+        if ($creer and !$support_svg) {
536
+            process_image_svg_identite($ret);
537
+            $ret['creer'] = false;
538
+        }
539
+    }
540
+    else {
541
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
542
+            return false;
543
+        }
544
+    }
545
+
546
+    return $ret;
547 547
 }
548 548
 
549 549
 
@@ -552,53 +552,53 @@  discard block
 block discarded – undo
552 552
  * @return array
553 553
  */
554 554
 function _image_extensions_acceptees_en_entree() {
555
-	static $extensions = null;
556
-	if (empty($extensions)) {
557
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
559
-			// action=tester renseigne gd_formats et detecte le support de webp
560
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
561
-			$extensions = array_map('trim', $extensions);
562
-			$extensions = array_filter($extensions);
563
-			$extensions = array_unique($extensions);
564
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
565
-			}
566
-		}
567
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
-	}
569
-
570
-	return $extensions;
555
+    static $extensions = null;
556
+    if (empty($extensions)) {
557
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
558
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
559
+            // action=tester renseigne gd_formats et detecte le support de webp
560
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
561
+            $extensions = array_map('trim', $extensions);
562
+            $extensions = array_filter($extensions);
563
+            $extensions = array_unique($extensions);
564
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
565
+            }
566
+        }
567
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
568
+    }
569
+
570
+    return $extensions;
571 571
 }
572 572
 
573 573
 /**
574 574
  * @return array|string[]|null
575 575
  */
576 576
 function _image_extensions_acceptees_en_sortie() {
577
-	static $extensions = null;
578
-	if (empty($extensions)) {
579
-		$extensions = _image_extensions_acceptees_en_entree();
580
-		$extensions = array_diff($extensions, ['jpeg']);
581
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
582
-			$extensions = array_diff($extensions, ['gif']);
583
-		}
584
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
585
-			$extensions = array_diff($extensions, ['webp']);
586
-		}
587
-	}
588
-
589
-	return $extensions;
577
+    static $extensions = null;
578
+    if (empty($extensions)) {
579
+        $extensions = _image_extensions_acceptees_en_entree();
580
+        $extensions = array_diff($extensions, ['jpeg']);
581
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
582
+            $extensions = array_diff($extensions, ['gif']);
583
+        }
584
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
585
+            $extensions = array_diff($extensions, ['webp']);
586
+        }
587
+    }
588
+
589
+    return $extensions;
590 590
 }
591 591
 
592 592
 function _image_extension_normalisee($extension) {
593
-	$extension = strtolower($extension);
594
-	if ($extension === 'jpeg') {
595
-		$extension = 'jpg';
596
-	}
597
-	return $extension;
593
+    $extension = strtolower($extension);
594
+    if ($extension === 'jpeg') {
595
+        $extension = 'jpg';
596
+    }
597
+    return $extension;
598 598
 }
599 599
 
600 600
 function _image_extensions_conservent_transparence() {
601
-	return ['png', 'webp'];
601
+    return ['png', 'webp'];
602 602
 }
603 603
 
604 604
 
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
  * @return string
609 609
  */
610 610
 function _image_trouver_extension($path) {
611
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
-		$terminaison = strtolower($regs[1]);
614
-		return $terminaison;
615
-	}
616
-	return '';
611
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
612
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
613
+        $terminaison = strtolower($regs[1]);
614
+        return $terminaison;
615
+    }
616
+    return '';
617 617
 }
618 618
 
619 619
 /**
@@ -624,33 +624,33 @@  discard block
 block discarded – undo
624 624
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
625 625
  */
626 626
 function _image_trouver_extension_pertinente($path) {
627
-	$path = supprimer_timestamp($path);
628
-	$terminaison = _image_trouver_extension($path);
629
-	if ($terminaison == 'jpg') {
630
-		$terminaison = 'jpeg';
631
-	}
632
-
633
-	if (!file_exists($path)) {
634
-		return $terminaison;
635
-	}
636
-
637
-	if (!$info = @spip_getimagesize($path)) {
638
-		return $terminaison;
639
-	}
640
-
641
-	if (isset($info['mime'])) {
642
-		$mime = $info['mime'];
643
-	}
644
-	else {
645
-		$mime = image_type_to_mime_type($info[2]);
646
-	}
647
-
648
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
649
-	if ($_terminaison and $_terminaison !== $terminaison) {
650
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
651
-		$terminaison = $_terminaison;
652
-	}
653
-	return $terminaison;
627
+    $path = supprimer_timestamp($path);
628
+    $terminaison = _image_trouver_extension($path);
629
+    if ($terminaison == 'jpg') {
630
+        $terminaison = 'jpeg';
631
+    }
632
+
633
+    if (!file_exists($path)) {
634
+        return $terminaison;
635
+    }
636
+
637
+    if (!$info = @spip_getimagesize($path)) {
638
+        return $terminaison;
639
+    }
640
+
641
+    if (isset($info['mime'])) {
642
+        $mime = $info['mime'];
643
+    }
644
+    else {
645
+        $mime = image_type_to_mime_type($info[2]);
646
+    }
647
+
648
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
649
+    if ($_terminaison and $_terminaison !== $terminaison) {
650
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
651
+        $terminaison = $_terminaison;
652
+    }
653
+    return $terminaison;
654 654
 }
655 655
 
656 656
 /**
@@ -658,36 +658,36 @@  discard block
 block discarded – undo
658 658
  * @return string
659 659
  */
660 660
 function _image_trouver_extension_depuis_mime($mime) {
661
-	switch (strtolower($mime)) {
662
-		case 'image/png':
663
-		case 'image/x-png':
664
-			$terminaison = 'png';
665
-			break;
666
-
667
-		case 'image/jpg':
668
-		case 'image/jpeg':
669
-		case 'image/pjpeg':
670
-			$terminaison = 'jpeg';
671
-			break;
672
-
673
-		case 'image/gif':
674
-			$terminaison = 'gif';
675
-			break;
676
-
677
-		case 'image/webp':
678
-		case 'image/x-webp':
679
-			$terminaison = 'webp';
680
-			break;
681
-
682
-		case 'image/svg+xml':
683
-			$terminaison = 'svg';
684
-			break;
685
-
686
-		default:
687
-			$terminaison = '';
688
-	}
689
-
690
-	return $terminaison;
661
+    switch (strtolower($mime)) {
662
+        case 'image/png':
663
+        case 'image/x-png':
664
+            $terminaison = 'png';
665
+            break;
666
+
667
+        case 'image/jpg':
668
+        case 'image/jpeg':
669
+        case 'image/pjpeg':
670
+            $terminaison = 'jpeg';
671
+            break;
672
+
673
+        case 'image/gif':
674
+            $terminaison = 'gif';
675
+            break;
676
+
677
+        case 'image/webp':
678
+        case 'image/x-webp':
679
+            $terminaison = 'webp';
680
+            break;
681
+
682
+        case 'image/svg+xml':
683
+            $terminaison = 'svg';
684
+            break;
685
+
686
+        default:
687
+            $terminaison = '';
688
+    }
689
+
690
+    return $terminaison;
691 691
 }
692 692
 
693 693
 
@@ -707,18 +707,18 @@  discard block
 block discarded – undo
707 707
  *     Une ressource de type Image GD.
708 708
  */
709 709
 function _imagecreatefrom_func(string $func, string $filename) {
710
-	if (!function_exists($func)) {
711
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
712
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
713
-		return null;
714
-	}
715
-	$img = @$func($filename);
716
-	if (!$img) {
717
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
718
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
719
-		$img = imagecreate(10, 10);
720
-	}
721
-	return $img;
710
+    if (!function_exists($func)) {
711
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
712
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
713
+        return null;
714
+    }
715
+    $img = @$func($filename);
716
+    if (!$img) {
717
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
718
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
719
+        $img = imagecreate(10, 10);
720
+    }
721
+    return $img;
722 722
 }
723 723
 
724 724
 /**
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
  *     Une ressource de type Image GD.
735 735
  */
736 736
 function _imagecreatefromjpeg($filename) {
737
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
737
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
738 738
 }
739 739
 
740 740
 /**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
  *     Une ressource de type Image GD.
751 751
  */
752 752
 function _imagecreatefrompng($filename) {
753
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
753
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
754 754
 }
755 755
 
756 756
 /**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
  *     Une ressource de type Image GD.
767 767
  */
768 768
 function _imagecreatefromgif($filename) {
769
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
769
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
770 770
 }
771 771
 
772 772
 
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
  *     Une ressource de type Image GD.
784 784
  */
785 785
 function _imagecreatefromwebp($filename) {
786
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
786
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
787 787
 }
788 788
 
789 789
 /**
@@ -801,24 +801,24 @@  discard block
 block discarded – undo
801 801
  *     - true si une image est bien retournée.
802 802
  */
803 803
 function _image_imagepng($img, $fichier) {
804
-	if (!function_exists('imagepng')) {
805
-		return false;
806
-	}
807
-	$tmp = $fichier . '.tmp';
808
-	$ret = imagepng($img, $tmp);
809
-	if (file_exists($tmp)) {
810
-		$taille_test = getimagesize($tmp);
811
-		if ($taille_test[0] < 1) {
812
-			return false;
813
-		}
814
-
815
-		spip_unlink($fichier); // le fichier peut deja exister
816
-		@rename($tmp, $fichier);
817
-
818
-		return $ret;
819
-	}
820
-
821
-	return false;
804
+    if (!function_exists('imagepng')) {
805
+        return false;
806
+    }
807
+    $tmp = $fichier . '.tmp';
808
+    $ret = imagepng($img, $tmp);
809
+    if (file_exists($tmp)) {
810
+        $taille_test = getimagesize($tmp);
811
+        if ($taille_test[0] < 1) {
812
+            return false;
813
+        }
814
+
815
+        spip_unlink($fichier); // le fichier peut deja exister
816
+        @rename($tmp, $fichier);
817
+
818
+        return $ret;
819
+    }
820
+
821
+    return false;
822 822
 }
823 823
 
824 824
 /**
@@ -836,24 +836,24 @@  discard block
 block discarded – undo
836 836
  *     - true si une image est bien retournée.
837 837
  */
838 838
 function _image_imagegif($img, $fichier) {
839
-	if (!function_exists('imagegif')) {
840
-		return false;
841
-	}
842
-	$tmp = $fichier . '.tmp';
843
-	$ret = imagegif($img, $tmp);
844
-	if (file_exists($tmp)) {
845
-		$taille_test = getimagesize($tmp);
846
-		if ($taille_test[0] < 1) {
847
-			return false;
848
-		}
849
-
850
-		spip_unlink($fichier); // le fichier peut deja exister
851
-		@rename($tmp, $fichier);
852
-
853
-		return $ret;
854
-	}
855
-
856
-	return false;
839
+    if (!function_exists('imagegif')) {
840
+        return false;
841
+    }
842
+    $tmp = $fichier . '.tmp';
843
+    $ret = imagegif($img, $tmp);
844
+    if (file_exists($tmp)) {
845
+        $taille_test = getimagesize($tmp);
846
+        if ($taille_test[0] < 1) {
847
+            return false;
848
+        }
849
+
850
+        spip_unlink($fichier); // le fichier peut deja exister
851
+        @rename($tmp, $fichier);
852
+
853
+        return $ret;
854
+    }
855
+
856
+    return false;
857 857
 }
858 858
 
859 859
 /**
@@ -876,29 +876,29 @@  discard block
 block discarded – undo
876 876
  *     - true si une image est bien retournée.
877 877
  */
878 878
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
879
-	if (!function_exists('imagejpeg')) {
880
-		return false;
881
-	}
882
-	$tmp = $fichier . '.tmp';
879
+    if (!function_exists('imagejpeg')) {
880
+        return false;
881
+    }
882
+    $tmp = $fichier . '.tmp';
883 883
 
884
-	// Enable interlancing
885
-	imageinterlace($img, true);
884
+    // Enable interlancing
885
+    imageinterlace($img, true);
886 886
 
887
-	$ret = imagejpeg($img, $tmp, $qualite);
887
+    $ret = imagejpeg($img, $tmp, $qualite);
888 888
 
889
-	if (file_exists($tmp)) {
890
-		$taille_test = getimagesize($tmp);
891
-		if ($taille_test[0] < 1) {
892
-			return false;
893
-		}
889
+    if (file_exists($tmp)) {
890
+        $taille_test = getimagesize($tmp);
891
+        if ($taille_test[0] < 1) {
892
+            return false;
893
+        }
894 894
 
895
-		spip_unlink($fichier); // le fichier peut deja exister
896
-		@rename($tmp, $fichier);
895
+        spip_unlink($fichier); // le fichier peut deja exister
896
+        @rename($tmp, $fichier);
897 897
 
898
-		return $ret;
899
-	}
898
+        return $ret;
899
+    }
900 900
 
901
-	return false;
901
+    return false;
902 902
 }
903 903
 
904 904
 /**
@@ -916,9 +916,9 @@  discard block
 block discarded – undo
916 916
  *     true si le fichier a bien été créé ; false sinon.
917 917
  */
918 918
 function _image_imageico($img, $fichier) {
919
-	$gd_image_array = [$img];
919
+    $gd_image_array = [$img];
920 920
 
921
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
921
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
922 922
 }
923 923
 
924 924
 
@@ -937,24 +937,24 @@  discard block
 block discarded – undo
937 937
  *     - true si une image est bien retournée.
938 938
  */
939 939
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
940
-	if (!function_exists('imagewebp')) {
941
-		return false;
942
-	}
943
-	$tmp = $fichier . '.tmp';
944
-	$ret = imagewebp($img, $tmp, $qualite);
945
-	if (file_exists($tmp)) {
946
-		$taille_test = getimagesize($tmp);
947
-		if ($taille_test[0] < 1) {
948
-			return false;
949
-		}
950
-
951
-		spip_unlink($fichier); // le fichier peut deja exister
952
-		@rename($tmp, $fichier);
953
-
954
-		return $ret;
955
-	}
956
-
957
-	return false;
940
+    if (!function_exists('imagewebp')) {
941
+        return false;
942
+    }
943
+    $tmp = $fichier . '.tmp';
944
+    $ret = imagewebp($img, $tmp, $qualite);
945
+    if (file_exists($tmp)) {
946
+        $taille_test = getimagesize($tmp);
947
+        if ($taille_test[0] < 1) {
948
+            return false;
949
+        }
950
+
951
+        spip_unlink($fichier); // le fichier peut deja exister
952
+        @rename($tmp, $fichier);
953
+
954
+        return $ret;
955
+    }
956
+
957
+    return false;
958 958
 }
959 959
 
960 960
 /**
@@ -974,35 +974,35 @@  discard block
 block discarded – undo
974 974
  */
975 975
 function _image_imagesvg($img, $fichier) {
976 976
 
977
-	$tmp = $fichier . '.tmp';
978
-	if (strpos($img, '<') === false) {
979
-		$img = supprimer_timestamp($img);
980
-		if (!file_exists($img)) {
981
-			return false;
982
-		}
983
-		@copy($img, $tmp);
984
-		if (filesize($tmp) == filesize($img)) {
985
-			spip_unlink($fichier); // le fichier peut deja exister
986
-			@rename($tmp, $fichier);
987
-			return true;
988
-		}
989
-		return false;
990
-	}
991
-
992
-	file_put_contents($tmp, $img);
993
-	if (file_exists($tmp)) {
994
-		$taille_test = spip_getimagesize($tmp);
995
-		if ($taille_test[0] < 1) {
996
-			return false;
997
-		}
998
-
999
-		spip_unlink($fichier); // le fichier peut deja exister
1000
-		@rename($tmp, $fichier);
1001
-
1002
-		return true;
1003
-	}
1004
-
1005
-	return false;
977
+    $tmp = $fichier . '.tmp';
978
+    if (strpos($img, '<') === false) {
979
+        $img = supprimer_timestamp($img);
980
+        if (!file_exists($img)) {
981
+            return false;
982
+        }
983
+        @copy($img, $tmp);
984
+        if (filesize($tmp) == filesize($img)) {
985
+            spip_unlink($fichier); // le fichier peut deja exister
986
+            @rename($tmp, $fichier);
987
+            return true;
988
+        }
989
+        return false;
990
+    }
991
+
992
+    file_put_contents($tmp, $img);
993
+    if (file_exists($tmp)) {
994
+        $taille_test = spip_getimagesize($tmp);
995
+        if ($taille_test[0] < 1) {
996
+            return false;
997
+        }
998
+
999
+        spip_unlink($fichier); // le fichier peut deja exister
1000
+        @rename($tmp, $fichier);
1001
+
1002
+        return true;
1003
+    }
1004
+
1005
+    return false;
1006 1006
 }
1007 1007
 
1008 1008
 
@@ -1030,29 +1030,29 @@  discard block
 block discarded – undo
1030 1030
  *     - false sinon.
1031 1031
  */
1032 1032
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1033
-	if (is_null($fonction)) {
1034
-		$fonction = '_image_image' . $valeurs['format_dest'];
1035
-	}
1036
-	$ret = false;
1037
-	#un flag pour reperer les images gravees
1038
-	$lock =
1039
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1040
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1041
-	if (
1042
-		function_exists($fonction)
1043
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1044
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1045
-		&& !$lock
1046
-	) {
1047
-		if (@file_exists($valeurs['fichier_dest'])) {
1048
-			// dans tous les cas mettre a jour la taille de l'image finale
1049
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1050
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1051
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1052
-		}
1053
-	}
1054
-
1055
-	return $ret;
1033
+    if (is_null($fonction)) {
1034
+        $fonction = '_image_image' . $valeurs['format_dest'];
1035
+    }
1036
+    $ret = false;
1037
+    #un flag pour reperer les images gravees
1038
+    $lock =
1039
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1040
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1041
+    if (
1042
+        function_exists($fonction)
1043
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1044
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1045
+        && !$lock
1046
+    ) {
1047
+        if (@file_exists($valeurs['fichier_dest'])) {
1048
+            // dans tous les cas mettre a jour la taille de l'image finale
1049
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1050
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1051
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1052
+        }
1053
+    }
1054
+
1055
+    return $ret;
1056 1056
 }
1057 1057
 
1058 1058
 /**
@@ -1065,27 +1065,27 @@  discard block
 block discarded – undo
1065 1065
  *     Chemin vers le fichier manquant
1066 1066
  **/
1067 1067
 function reconstruire_image_intermediaire($fichier_manquant) {
1068
-	$reconstruire = [];
1069
-	$fichier = $fichier_manquant;
1070
-	while (
1071
-		strpos($fichier, '://') === false
1072
-		and !@file_exists($fichier)
1073
-		and lire_fichier($src = "$fichier.src", $source)
1074
-		and $valeurs = unserialize($source)
1075
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1076
-	) {
1077
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1078
-		$reconstruire[] = $valeurs['reconstruction'];
1079
-	}
1080
-	while (count($reconstruire)) {
1081
-		$r = array_pop($reconstruire);
1082
-		$fonction = $r[0];
1083
-		$args = $r[1];
1084
-		$fonction(...$args);
1085
-	}
1086
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1087
-	// mais l'on peut nettoyer les miettes de sa creation
1088
-	ramasse_miettes($fichier_manquant);
1068
+    $reconstruire = [];
1069
+    $fichier = $fichier_manquant;
1070
+    while (
1071
+        strpos($fichier, '://') === false
1072
+        and !@file_exists($fichier)
1073
+        and lire_fichier($src = "$fichier.src", $source)
1074
+        and $valeurs = unserialize($source)
1075
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1076
+    ) {
1077
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1078
+        $reconstruire[] = $valeurs['reconstruction'];
1079
+    }
1080
+    while (count($reconstruire)) {
1081
+        $r = array_pop($reconstruire);
1082
+        $fonction = $r[0];
1083
+        $args = $r[1];
1084
+        $fonction(...$args);
1085
+    }
1086
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1087
+    // mais l'on peut nettoyer les miettes de sa creation
1088
+    ramasse_miettes($fichier_manquant);
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1105,28 +1105,28 @@  discard block
 block discarded – undo
1105 1105
  *     Chemin du fichier d'image calculé
1106 1106
  **/
1107 1107
 function ramasse_miettes($fichier) {
1108
-	if (
1109
-		strpos($fichier, '://') !== false
1110
-		or !lire_fichier($src = "$fichier.src", $source)
1111
-		or !$valeurs = unserialize($source)
1112
-	) {
1113
-		return;
1114
-	}
1115
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1116
-	while (
1117
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1118
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1119
-		and (lire_fichier(
1120
-			$src = "$fichier.src",
1121
-			$source
1122
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1123
-		and ($valeurs = unserialize($source))  # et valide
1124
-	) {
1125
-		# on efface le fichier
1126
-		spip_unlink($fichier);
1127
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1128
-		#spip_unlink($src);
1129
-	}
1108
+    if (
1109
+        strpos($fichier, '://') !== false
1110
+        or !lire_fichier($src = "$fichier.src", $source)
1111
+        or !$valeurs = unserialize($source)
1112
+    ) {
1113
+        return;
1114
+    }
1115
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1116
+    while (
1117
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1118
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1119
+        and (lire_fichier(
1120
+            $src = "$fichier.src",
1121
+            $source
1122
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1123
+        and ($valeurs = unserialize($source))  # et valide
1124
+    ) {
1125
+        # on efface le fichier
1126
+        spip_unlink($fichier);
1127
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1128
+        #spip_unlink($src);
1129
+    }
1130 1130
 }
1131 1131
 
1132 1132
 
@@ -1151,71 +1151,71 @@  discard block
 block discarded – undo
1151 1151
  *     Code HTML de l'image
1152 1152
  **/
1153 1153
 function image_graver($img) {
1154
-	// appeler le filtre post_image_filtrer qui permet de faire
1155
-	// des traitements auto a la fin d'une serie de filtres
1156
-	$img = pipeline('post_image_filtrer', $img);
1157
-
1158
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1159
-	if (($p = strpos($fichier, '?')) !== false) {
1160
-		$fichier = substr($fichier, 0, $p);
1161
-	}
1162
-	if (strlen($fichier) < 1) {
1163
-		$fichier = $img;
1164
-	}
1165
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1166
-	# et qu'il ne s'agit pas d'une URL
1167
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1168
-		reconstruire_image_intermediaire($fichier);
1169
-	}
1170
-	ramasse_miettes($fichier);
1171
-
1172
-	// ajouter le timestamp si besoin
1173
-	if (strpos($fichier_ori, '?') === false) {
1174
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1175
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1176
-	}
1177
-
1178
-	return $img;
1154
+    // appeler le filtre post_image_filtrer qui permet de faire
1155
+    // des traitements auto a la fin d'une serie de filtres
1156
+    $img = pipeline('post_image_filtrer', $img);
1157
+
1158
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1159
+    if (($p = strpos($fichier, '?')) !== false) {
1160
+        $fichier = substr($fichier, 0, $p);
1161
+    }
1162
+    if (strlen($fichier) < 1) {
1163
+        $fichier = $img;
1164
+    }
1165
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1166
+    # et qu'il ne s'agit pas d'une URL
1167
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1168
+        reconstruire_image_intermediaire($fichier);
1169
+    }
1170
+    ramasse_miettes($fichier);
1171
+
1172
+    // ajouter le timestamp si besoin
1173
+    if (strpos($fichier_ori, '?') === false) {
1174
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1175
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1176
+    }
1177
+
1178
+    return $img;
1179 1179
 }
1180 1180
 
1181 1181
 
1182 1182
 if (!function_exists('imagepalettetotruecolor')) {
1183
-	/**
1184
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1185
-	 *
1186
-	 * @note Pour compatibilité avec PHP < 5.5
1187
-	 *
1188
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1189
-	 *
1190
-	 * @param ressource $img
1191
-	 * @return bool
1192
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1193
-	 *     - false si la transformation ne peut être faite.
1194
-	 **/
1195
-	function imagepalettetotruecolor(&$img) {
1196
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1197
-			return false;
1198
-		} elseif (!imageistruecolor($img)) {
1199
-			$w = imagesx($img);
1200
-			$h = imagesy($img);
1201
-			$img1 = imagecreatetruecolor($w, $h);
1202
-			//Conserver la transparence si possible
1203
-			if (function_exists('ImageCopyResampled')) {
1204
-				if (function_exists('imageAntiAlias')) {
1205
-					imageAntiAlias($img1, true);
1206
-				}
1207
-				@imagealphablending($img1, false);
1208
-				@imagesavealpha($img1, true);
1209
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1210
-			} else {
1211
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1212
-			}
1213
-
1214
-			$img = $img1;
1215
-		}
1216
-
1217
-		return true;
1218
-	}
1183
+    /**
1184
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1185
+     *
1186
+     * @note Pour compatibilité avec PHP < 5.5
1187
+     *
1188
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1189
+     *
1190
+     * @param ressource $img
1191
+     * @return bool
1192
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1193
+     *     - false si la transformation ne peut être faite.
1194
+     **/
1195
+    function imagepalettetotruecolor(&$img) {
1196
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1197
+            return false;
1198
+        } elseif (!imageistruecolor($img)) {
1199
+            $w = imagesx($img);
1200
+            $h = imagesy($img);
1201
+            $img1 = imagecreatetruecolor($w, $h);
1202
+            //Conserver la transparence si possible
1203
+            if (function_exists('ImageCopyResampled')) {
1204
+                if (function_exists('imageAntiAlias')) {
1205
+                    imageAntiAlias($img1, true);
1206
+                }
1207
+                @imagealphablending($img1, false);
1208
+                @imagesavealpha($img1, true);
1209
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1210
+            } else {
1211
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1212
+            }
1213
+
1214
+            $img = $img1;
1215
+        }
1216
+
1217
+        return true;
1218
+    }
1219 1219
 }
1220 1220
 
1221 1221
 /**
@@ -1242,34 +1242,34 @@  discard block
 block discarded – undo
1242 1242
  *     Code html modifié de la balise.
1243 1243
  **/
1244 1244
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1245
-	if ($style === false) {
1246
-		$style = extraire_attribut($tag, 'style');
1247
-	}
1248
-
1249
-	// enlever le width et height du style
1250
-	if ($style) {
1251
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1252
-	}
1253
-	if ($style and $style[0] === ';') {
1254
-		$style = substr($style, 1);
1255
-	}
1256
-
1257
-	// mettre des attributs de width et height sur les images,
1258
-	// ca accelere le rendu du navigateur
1259
-	// ca permet aux navigateurs de reserver la bonne taille
1260
-	// quand on a desactive l'affichage des images.
1261
-	$tag = inserer_attribut($tag, 'width', round($width));
1262
-	$tag = inserer_attribut($tag, 'height', round($height));
1263
-
1264
-	// attributs deprecies. Transformer en CSS
1265
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1266
-		$style = "margin:${espace}px;" . $style;
1267
-		$tag = inserer_attribut($tag, 'hspace', '');
1268
-	}
1269
-
1270
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1271
-
1272
-	return $tag;
1245
+    if ($style === false) {
1246
+        $style = extraire_attribut($tag, 'style');
1247
+    }
1248
+
1249
+    // enlever le width et height du style
1250
+    if ($style) {
1251
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1252
+    }
1253
+    if ($style and $style[0] === ';') {
1254
+        $style = substr($style, 1);
1255
+    }
1256
+
1257
+    // mettre des attributs de width et height sur les images,
1258
+    // ca accelere le rendu du navigateur
1259
+    // ca permet aux navigateurs de reserver la bonne taille
1260
+    // quand on a desactive l'affichage des images.
1261
+    $tag = inserer_attribut($tag, 'width', round($width));
1262
+    $tag = inserer_attribut($tag, 'height', round($height));
1263
+
1264
+    // attributs deprecies. Transformer en CSS
1265
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1266
+        $style = "margin:${espace}px;" . $style;
1267
+        $tag = inserer_attribut($tag, 'hspace', '');
1268
+    }
1269
+
1270
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1271
+
1272
+    return $tag;
1273 1273
 }
1274 1274
 
1275 1275
 
@@ -1295,72 +1295,72 @@  discard block
 block discarded – undo
1295 1295
  *     Retourne le code HTML de l'image
1296 1296
  **/
1297 1297
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1298
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1299
-
1300
-	// fermer les tags img pas bien fermes;
1301
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1302
-
1303
-	// le style
1304
-	$style = $valeurs['style'];
1305
-	if (isset($surcharge['style'])) {
1306
-		$style = $surcharge['style'];
1307
-		unset($surcharge['style']);
1308
-	}
1309
-
1310
-	// traiter specifiquement la largeur et la hauteur
1311
-	$width = $valeurs['largeur'];
1312
-	if (isset($surcharge['width'])) {
1313
-		$width = $surcharge['width'];
1314
-		unset($surcharge['width']);
1315
-	}
1316
-	$height = $valeurs['hauteur'];
1317
-	if (isset($surcharge['height'])) {
1318
-		$height = $surcharge['height'];
1319
-		unset($surcharge['height']);
1320
-	}
1321
-
1322
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1323
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1324
-	// on remplace toute les ref a src dans le tag
1325
-	$src = extraire_attribut($tag, 'src');
1326
-	if (isset($surcharge['src'])) {
1327
-		$tag = str_replace($src, $surcharge['src'], $tag);
1328
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1329
-		// pas garanti comme methode, mais mieux que rien
1330
-		if (strpos($src, '&') !== false) {
1331
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1332
-		}
1333
-		$src = $surcharge['src'];
1334
-		unset($surcharge['src']);
1335
-	}
1336
-
1337
-	$class = $valeurs['class'];
1338
-	if (isset($surcharge['class'])) {
1339
-		$class = $surcharge['class'];
1340
-		unset($surcharge['class']);
1341
-	}
1342
-	if (is_scalar($class) && strlen($class)) {
1343
-		$tag = inserer_attribut($tag, 'class', $class);
1344
-	}
1345
-
1346
-	if (count($surcharge)) {
1347
-		foreach ($surcharge as $attribut => $valeur) {
1348
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1349
-		}
1350
-	}
1351
-
1352
-	$tag = pipeline(
1353
-		'image_ecrire_tag_finir',
1354
-		[
1355
-			'args' => [
1356
-				'valeurs' => $valeurs,
1357
-				'surcharge' => $surcharge,
1358
-			],
1359
-			'data' => $tag
1360
-		]
1361
-	);
1362
-
1363
-	return $tag;
1298
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1299
+
1300
+    // fermer les tags img pas bien fermes;
1301
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1302
+
1303
+    // le style
1304
+    $style = $valeurs['style'];
1305
+    if (isset($surcharge['style'])) {
1306
+        $style = $surcharge['style'];
1307
+        unset($surcharge['style']);
1308
+    }
1309
+
1310
+    // traiter specifiquement la largeur et la hauteur
1311
+    $width = $valeurs['largeur'];
1312
+    if (isset($surcharge['width'])) {
1313
+        $width = $surcharge['width'];
1314
+        unset($surcharge['width']);
1315
+    }
1316
+    $height = $valeurs['hauteur'];
1317
+    if (isset($surcharge['height'])) {
1318
+        $height = $surcharge['height'];
1319
+        unset($surcharge['height']);
1320
+    }
1321
+
1322
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1323
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1324
+    // on remplace toute les ref a src dans le tag
1325
+    $src = extraire_attribut($tag, 'src');
1326
+    if (isset($surcharge['src'])) {
1327
+        $tag = str_replace($src, $surcharge['src'], $tag);
1328
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1329
+        // pas garanti comme methode, mais mieux que rien
1330
+        if (strpos($src, '&') !== false) {
1331
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1332
+        }
1333
+        $src = $surcharge['src'];
1334
+        unset($surcharge['src']);
1335
+    }
1336
+
1337
+    $class = $valeurs['class'];
1338
+    if (isset($surcharge['class'])) {
1339
+        $class = $surcharge['class'];
1340
+        unset($surcharge['class']);
1341
+    }
1342
+    if (is_scalar($class) && strlen($class)) {
1343
+        $tag = inserer_attribut($tag, 'class', $class);
1344
+    }
1345
+
1346
+    if (count($surcharge)) {
1347
+        foreach ($surcharge as $attribut => $valeur) {
1348
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1349
+        }
1350
+    }
1351
+
1352
+    $tag = pipeline(
1353
+        'image_ecrire_tag_finir',
1354
+        [
1355
+            'args' => [
1356
+                'valeurs' => $valeurs,
1357
+                'surcharge' => $surcharge,
1358
+            ],
1359
+            'data' => $tag
1360
+        ]
1361
+    );
1362
+
1363
+    return $tag;
1364 1364
 }
1365 1365
 
1366 1366
 /**
@@ -1383,259 +1383,259 @@  discard block
 block discarded – undo
1383 1383
  *     Description de l'image, sinon null.
1384 1384
  **/
1385 1385
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1386
-	$srcHeight = null;
1387
-	$retour = [];
1388
-	// ordre de preference des formats graphiques pour creer les vignettes
1389
-	// le premier format disponible, selon la methode demandee, est utilise
1390
-	$image = $valeurs['fichier'];
1391
-	$format = $valeurs['format_source'];
1392
-	$destdir = dirname($valeurs['fichier_dest']);
1393
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1394
-
1395
-	$format_sortie = $valeurs['format_dest'];
1396
-
1397
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1398
-		$process = $GLOBALS['meta']['image_process'];
1399
-	}
1400
-
1401
-	// si le doc n'est pas une image dans un format accetpable, refuser
1402
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1403
-		return;
1404
-	}
1405
-	$destination = "$destdir/$destfile";
1406
-
1407
-	// calculer la taille
1408
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1409
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1410
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1411
-		}
1412
-	} elseif ($process == 'convert' or $process == 'imagick') {
1413
-		$destWidth = $maxWidth;
1414
-		$destHeight = $maxHeight;
1415
-	} else {
1416
-		spip_log("echec $process sur $image");
1417
-
1418
-		return;
1419
-	}
1420
-
1421
-	$vignette = '';
1422
-
1423
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1424
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1425
-		$vignette = $destination . '.' . $format;
1426
-		@copy($image, $vignette);
1427
-	}
1428
-
1429
-	elseif ($valeurs['format_source'] === 'svg') {
1430
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1431
-			$format_sortie = 'svg';
1432
-			$vignette = $destination . '.' . $format_sortie;
1433
-			$valeurs['fichier_dest'] = $vignette;
1434
-			_image_gd_output($svg, $valeurs);
1435
-		}
1436
-	}
1437
-
1438
-	// imagemagick en ligne de commande
1439
-	elseif ($process == 'convert') {
1440
-		if (!defined('_CONVERT_COMMAND')) {
1441
-			define('_CONVERT_COMMAND', 'convert');
1442
-		} // Securite : mes_options.php peut preciser le chemin absolu
1443
-		if (!defined('_RESIZE_COMMAND')) {
1444
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1445
-		}
1446
-		$vignette = $destination . '.' . $format_sortie;
1447
-		$commande = str_replace(
1448
-			['%x', '%y', '%src', '%dest'],
1449
-			[
1450
-				$destWidth,
1451
-				$destHeight,
1452
-				escapeshellcmd($image),
1453
-				escapeshellcmd($vignette)
1454
-			],
1455
-			_RESIZE_COMMAND
1456
-		);
1457
-		spip_log($commande);
1458
-		exec($commande);
1459
-		if (!@file_exists($vignette)) {
1460
-			spip_log("echec convert sur $vignette");
1461
-
1462
-			return;  // echec commande
1463
-		}
1464
-	}
1465
-
1466
-	// php5 imagemagick
1467
-	elseif ($process == 'imagick') {
1468
-		$vignette = "$destination." . $format_sortie;
1469
-
1470
-		if (!class_exists(\Imagick::class)) {
1471
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1472
-
1473
-			return;
1474
-		}
1475
-		$imagick = new Imagick();
1476
-		$imagick->readImage($image);
1477
-		$imagick->resizeImage(
1478
-			$destWidth,
1479
-			$destHeight,
1480
-			Imagick::FILTER_LANCZOS,
1481
-			1
1482
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1483
-		$imagick->writeImage($vignette);
1484
-
1485
-		if (!@file_exists($vignette)) {
1486
-			spip_log("echec imagick sur $vignette");
1487
-
1488
-			return;
1489
-		}
1490
-	}
1491
-
1492
-	// netpbm
1493
-	elseif ($process == 'netpbm') {
1494
-		if (!defined('_PNMSCALE_COMMAND')) {
1495
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1496
-		} // Securite : mes_options.php peut preciser le chemin absolu
1497
-		if (_PNMSCALE_COMMAND == '') {
1498
-			return;
1499
-		}
1500
-		$vignette = $destination . '.' . $format_sortie;
1501
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1502
-		if ($format == 'jpg') {
1503
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1504
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
-			if (!($s = @filesize($vignette))) {
1506
-				spip_unlink($vignette);
1507
-			}
1508
-			if (!@file_exists($vignette)) {
1509
-				spip_log("echec netpbm-jpg sur $vignette");
1510
-
1511
-				return;
1512
-			}
1513
-		} else {
1514
-			if ($format == 'gif') {
1515
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1516
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1517
-				if (!($s = @filesize($vignette))) {
1518
-					spip_unlink($vignette);
1519
-				}
1520
-				if (!@file_exists($vignette)) {
1521
-					spip_log("echec netpbm-gif sur $vignette");
1522
-
1523
-					return;
1524
-				}
1525
-			} else {
1526
-				if ($format == 'png') {
1527
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1528
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1529
-					if (!($s = @filesize($vignette))) {
1530
-						spip_unlink($vignette);
1531
-					}
1532
-					if (!@file_exists($vignette)) {
1533
-						spip_log("echec netpbm-png sur $vignette");
1534
-
1535
-						return;
1536
-					}
1537
-				}
1538
-			}
1539
-		}
1540
-	}
1541
-
1542
-	// gd ou gd2
1543
-	elseif ($process == 'gd1' or $process == 'gd2') {
1544
-		if (!function_exists('gd_info')) {
1545
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1546
-
1547
-			return;
1548
-		}
1549
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1550
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1551
-
1552
-			return;
1553
-		}
1554
-		$destFormat = $format_sortie;
1555
-		if (!$destFormat) {
1556
-			spip_log("pas de format pour $image");
1557
-
1558
-			return;
1559
-		}
1560
-
1561
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1562
-		if (!function_exists($fonction_imagecreatefrom)) {
1563
-			return '';
1564
-		}
1565
-		$srcImage = @$fonction_imagecreatefrom($image);
1566
-		if (!$srcImage) {
1567
-			spip_log('echec gd1/gd2');
1568
-
1569
-			return;
1570
-		}
1571
-
1572
-		// Initialisation de l'image destination
1573
-		$destImage = null;
1574
-		if ($process == 'gd2' and $destFormat != 'gif') {
1575
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1576
-		}
1577
-		if (!$destImage) {
1578
-			$destImage = ImageCreate($destWidth, $destHeight);
1579
-		}
1580
-
1581
-		// Recopie de l'image d'origine avec adaptation de la taille
1582
-		$ok = false;
1583
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1584
-			if ($format == 'gif') {
1585
-				// Si un GIF est transparent,
1586
-				// fabriquer un PNG transparent
1587
-				$transp = imagecolortransparent($srcImage);
1588
-				if ($transp > 0) {
1589
-					$destFormat = 'png';
1590
-				}
1591
-			}
1592
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1593
-				// Conserver la transparence
1594
-				if (function_exists('imageAntiAlias')) {
1595
-					imageAntiAlias($destImage, true);
1596
-				}
1597
-				@imagealphablending($destImage, false);
1598
-				@imagesavealpha($destImage, true);
1599
-			}
1600
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1601
-		}
1602
-		if (!$ok) {
1603
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1604
-		}
1605
-
1606
-		// Sauvegarde de l'image destination
1607
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1608
-		$valeurs['format_dest'] = $format = $destFormat;
1609
-		_image_gd_output($destImage, $valeurs);
1610
-
1611
-		if ($srcImage) {
1612
-			ImageDestroy($srcImage);
1613
-		}
1614
-		ImageDestroy($destImage);
1615
-	}
1616
-
1617
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1618
-		$size = [$destWidth, $destHeight];
1619
-	}
1620
-
1621
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1622
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1623
-	if ($size[0] < 1) {
1624
-		$size[0] = $destWidth;
1625
-	}
1626
-	if ($size[1] < 1) {
1627
-		$size[1] = $destHeight;
1628
-	}
1629
-
1630
-	$retour['width'] = $largeur = $size[0];
1631
-	$retour['height'] = $hauteur = $size[1];
1632
-
1633
-	$retour['fichier'] = $vignette;
1634
-	$retour['format'] = $format;
1635
-	$retour['date'] = @filemtime($vignette);
1636
-
1637
-	// renvoyer l'image
1638
-	return $retour;
1386
+    $srcHeight = null;
1387
+    $retour = [];
1388
+    // ordre de preference des formats graphiques pour creer les vignettes
1389
+    // le premier format disponible, selon la methode demandee, est utilise
1390
+    $image = $valeurs['fichier'];
1391
+    $format = $valeurs['format_source'];
1392
+    $destdir = dirname($valeurs['fichier_dest']);
1393
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1394
+
1395
+    $format_sortie = $valeurs['format_dest'];
1396
+
1397
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1398
+        $process = $GLOBALS['meta']['image_process'];
1399
+    }
1400
+
1401
+    // si le doc n'est pas une image dans un format accetpable, refuser
1402
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1403
+        return;
1404
+    }
1405
+    $destination = "$destdir/$destfile";
1406
+
1407
+    // calculer la taille
1408
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1409
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1410
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1411
+        }
1412
+    } elseif ($process == 'convert' or $process == 'imagick') {
1413
+        $destWidth = $maxWidth;
1414
+        $destHeight = $maxHeight;
1415
+    } else {
1416
+        spip_log("echec $process sur $image");
1417
+
1418
+        return;
1419
+    }
1420
+
1421
+    $vignette = '';
1422
+
1423
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1424
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1425
+        $vignette = $destination . '.' . $format;
1426
+        @copy($image, $vignette);
1427
+    }
1428
+
1429
+    elseif ($valeurs['format_source'] === 'svg') {
1430
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1431
+            $format_sortie = 'svg';
1432
+            $vignette = $destination . '.' . $format_sortie;
1433
+            $valeurs['fichier_dest'] = $vignette;
1434
+            _image_gd_output($svg, $valeurs);
1435
+        }
1436
+    }
1437
+
1438
+    // imagemagick en ligne de commande
1439
+    elseif ($process == 'convert') {
1440
+        if (!defined('_CONVERT_COMMAND')) {
1441
+            define('_CONVERT_COMMAND', 'convert');
1442
+        } // Securite : mes_options.php peut preciser le chemin absolu
1443
+        if (!defined('_RESIZE_COMMAND')) {
1444
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1445
+        }
1446
+        $vignette = $destination . '.' . $format_sortie;
1447
+        $commande = str_replace(
1448
+            ['%x', '%y', '%src', '%dest'],
1449
+            [
1450
+                $destWidth,
1451
+                $destHeight,
1452
+                escapeshellcmd($image),
1453
+                escapeshellcmd($vignette)
1454
+            ],
1455
+            _RESIZE_COMMAND
1456
+        );
1457
+        spip_log($commande);
1458
+        exec($commande);
1459
+        if (!@file_exists($vignette)) {
1460
+            spip_log("echec convert sur $vignette");
1461
+
1462
+            return;  // echec commande
1463
+        }
1464
+    }
1465
+
1466
+    // php5 imagemagick
1467
+    elseif ($process == 'imagick') {
1468
+        $vignette = "$destination." . $format_sortie;
1469
+
1470
+        if (!class_exists(\Imagick::class)) {
1471
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1472
+
1473
+            return;
1474
+        }
1475
+        $imagick = new Imagick();
1476
+        $imagick->readImage($image);
1477
+        $imagick->resizeImage(
1478
+            $destWidth,
1479
+            $destHeight,
1480
+            Imagick::FILTER_LANCZOS,
1481
+            1
1482
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1483
+        $imagick->writeImage($vignette);
1484
+
1485
+        if (!@file_exists($vignette)) {
1486
+            spip_log("echec imagick sur $vignette");
1487
+
1488
+            return;
1489
+        }
1490
+    }
1491
+
1492
+    // netpbm
1493
+    elseif ($process == 'netpbm') {
1494
+        if (!defined('_PNMSCALE_COMMAND')) {
1495
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1496
+        } // Securite : mes_options.php peut preciser le chemin absolu
1497
+        if (_PNMSCALE_COMMAND == '') {
1498
+            return;
1499
+        }
1500
+        $vignette = $destination . '.' . $format_sortie;
1501
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1502
+        if ($format == 'jpg') {
1503
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1504
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
+            if (!($s = @filesize($vignette))) {
1506
+                spip_unlink($vignette);
1507
+            }
1508
+            if (!@file_exists($vignette)) {
1509
+                spip_log("echec netpbm-jpg sur $vignette");
1510
+
1511
+                return;
1512
+            }
1513
+        } else {
1514
+            if ($format == 'gif') {
1515
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1516
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1517
+                if (!($s = @filesize($vignette))) {
1518
+                    spip_unlink($vignette);
1519
+                }
1520
+                if (!@file_exists($vignette)) {
1521
+                    spip_log("echec netpbm-gif sur $vignette");
1522
+
1523
+                    return;
1524
+                }
1525
+            } else {
1526
+                if ($format == 'png') {
1527
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1528
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1529
+                    if (!($s = @filesize($vignette))) {
1530
+                        spip_unlink($vignette);
1531
+                    }
1532
+                    if (!@file_exists($vignette)) {
1533
+                        spip_log("echec netpbm-png sur $vignette");
1534
+
1535
+                        return;
1536
+                    }
1537
+                }
1538
+            }
1539
+        }
1540
+    }
1541
+
1542
+    // gd ou gd2
1543
+    elseif ($process == 'gd1' or $process == 'gd2') {
1544
+        if (!function_exists('gd_info')) {
1545
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1546
+
1547
+            return;
1548
+        }
1549
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1550
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1551
+
1552
+            return;
1553
+        }
1554
+        $destFormat = $format_sortie;
1555
+        if (!$destFormat) {
1556
+            spip_log("pas de format pour $image");
1557
+
1558
+            return;
1559
+        }
1560
+
1561
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1562
+        if (!function_exists($fonction_imagecreatefrom)) {
1563
+            return '';
1564
+        }
1565
+        $srcImage = @$fonction_imagecreatefrom($image);
1566
+        if (!$srcImage) {
1567
+            spip_log('echec gd1/gd2');
1568
+
1569
+            return;
1570
+        }
1571
+
1572
+        // Initialisation de l'image destination
1573
+        $destImage = null;
1574
+        if ($process == 'gd2' and $destFormat != 'gif') {
1575
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1576
+        }
1577
+        if (!$destImage) {
1578
+            $destImage = ImageCreate($destWidth, $destHeight);
1579
+        }
1580
+
1581
+        // Recopie de l'image d'origine avec adaptation de la taille
1582
+        $ok = false;
1583
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1584
+            if ($format == 'gif') {
1585
+                // Si un GIF est transparent,
1586
+                // fabriquer un PNG transparent
1587
+                $transp = imagecolortransparent($srcImage);
1588
+                if ($transp > 0) {
1589
+                    $destFormat = 'png';
1590
+                }
1591
+            }
1592
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1593
+                // Conserver la transparence
1594
+                if (function_exists('imageAntiAlias')) {
1595
+                    imageAntiAlias($destImage, true);
1596
+                }
1597
+                @imagealphablending($destImage, false);
1598
+                @imagesavealpha($destImage, true);
1599
+            }
1600
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1601
+        }
1602
+        if (!$ok) {
1603
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1604
+        }
1605
+
1606
+        // Sauvegarde de l'image destination
1607
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1608
+        $valeurs['format_dest'] = $format = $destFormat;
1609
+        _image_gd_output($destImage, $valeurs);
1610
+
1611
+        if ($srcImage) {
1612
+            ImageDestroy($srcImage);
1613
+        }
1614
+        ImageDestroy($destImage);
1615
+    }
1616
+
1617
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1618
+        $size = [$destWidth, $destHeight];
1619
+    }
1620
+
1621
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1622
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1623
+    if ($size[0] < 1) {
1624
+        $size[0] = $destWidth;
1625
+    }
1626
+    if ($size[1] < 1) {
1627
+        $size[1] = $destHeight;
1628
+    }
1629
+
1630
+    $retour['width'] = $largeur = $size[0];
1631
+    $retour['height'] = $hauteur = $size[1];
1632
+
1633
+    $retour['fichier'] = $vignette;
1634
+    $retour['format'] = $format;
1635
+    $retour['date'] = @filemtime($vignette);
1636
+
1637
+    // renvoyer l'image
1638
+    return $retour;
1639 1639
 }
1640 1640
 
1641 1641
 /**
@@ -1655,25 +1655,25 @@  discard block
 block discarded – undo
1655 1655
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1656 1656
  **/
1657 1657
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1658
-	$ratioWidth = $srcWidth / $maxWidth;
1659
-	$ratioHeight = $srcHeight / $maxHeight;
1660
-
1661
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1662
-		$destWidth = $srcWidth;
1663
-		$destHeight = $srcHeight;
1664
-	} elseif ($ratioWidth < $ratioHeight) {
1665
-		$destWidth = $srcWidth / $ratioHeight;
1666
-		$destHeight = $maxHeight;
1667
-	} else {
1668
-		$destWidth = $maxWidth;
1669
-		$destHeight = $srcHeight / $ratioWidth;
1670
-	}
1671
-
1672
-	return [
1673
-		intval(round($destWidth)),
1674
-		intval(round($destHeight)),
1675
-		max($ratioWidth, $ratioHeight)
1676
-	];
1658
+    $ratioWidth = $srcWidth / $maxWidth;
1659
+    $ratioHeight = $srcHeight / $maxHeight;
1660
+
1661
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1662
+        $destWidth = $srcWidth;
1663
+        $destHeight = $srcHeight;
1664
+    } elseif ($ratioWidth < $ratioHeight) {
1665
+        $destWidth = $srcWidth / $ratioHeight;
1666
+        $destHeight = $maxHeight;
1667
+    } else {
1668
+        $destWidth = $maxWidth;
1669
+        $destHeight = $srcHeight / $ratioWidth;
1670
+    }
1671
+
1672
+    return [
1673
+        intval(round($destWidth)),
1674
+        intval(round($destHeight)),
1675
+        max($ratioWidth, $ratioHeight)
1676
+    ];
1677 1677
 }
1678 1678
 
1679 1679
 /**
@@ -1693,25 +1693,25 @@  discard block
 block discarded – undo
1693 1693
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1694 1694
  **/
1695 1695
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1696
-	$ratioWidth = $srcWidth / $maxWidth;
1697
-	$ratioHeight = $srcHeight / $maxHeight;
1698
-
1699
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1700
-		$destWidth = $srcWidth;
1701
-		$destHeight = $srcHeight;
1702
-	} elseif ($ratioWidth > $ratioHeight) {
1703
-		$destWidth = $srcWidth / $ratioHeight;
1704
-		$destHeight = $maxHeight;
1705
-	} else {
1706
-		$destWidth = $maxWidth;
1707
-		$destHeight = $srcHeight / $ratioWidth;
1708
-	}
1709
-
1710
-	return [
1711
-		intval(round($destWidth)),
1712
-		intval(round($destHeight)),
1713
-		min($ratioWidth, $ratioHeight)
1714
-	];
1696
+    $ratioWidth = $srcWidth / $maxWidth;
1697
+    $ratioHeight = $srcHeight / $maxHeight;
1698
+
1699
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1700
+        $destWidth = $srcWidth;
1701
+        $destHeight = $srcHeight;
1702
+    } elseif ($ratioWidth > $ratioHeight) {
1703
+        $destWidth = $srcWidth / $ratioHeight;
1704
+        $destHeight = $maxHeight;
1705
+    } else {
1706
+        $destWidth = $maxWidth;
1707
+        $destHeight = $srcHeight / $ratioWidth;
1708
+    }
1709
+
1710
+    return [
1711
+        intval(round($destWidth)),
1712
+        intval(round($destHeight)),
1713
+        min($ratioWidth, $ratioHeight)
1714
+    ];
1715 1715
 }
1716 1716
 
1717 1717
 
@@ -1724,12 +1724,12 @@  discard block
 block discarded – undo
1724 1724
  * @return string
1725 1725
  */
1726 1726
 function process_image_svg_identite($image) {
1727
-	if ($image['creer']) {
1728
-		$source = $image['fichier'];
1729
-		_image_gd_output($source, $image);
1730
-	}
1727
+    if ($image['creer']) {
1728
+        $source = $image['fichier'];
1729
+        _image_gd_output($source, $image);
1730
+    }
1731 1731
 
1732
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1732
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1733 1733
 }
1734 1734
 
1735 1735
 
@@ -1762,111 +1762,111 @@  discard block
 block discarded – undo
1762 1762
  *     Code HTML de la balise img produite
1763 1763
  **/
1764 1764
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1765
-	$image = false;
1766
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1767
-		$process = $GLOBALS['meta']['image_process'];
1768
-	}
1769
-	# determiner le format de sortie
1770
-	$format_sortie = false; // le choix par defaut sera bon
1771
-	if ($process == 'netpbm') {
1772
-		$format_sortie = 'jpg';
1773
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1774
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1775
-		// on verifie que l'extension choisie est bonne (en principe oui)
1776
-		$gd_formats = formats_image_acceptables(true);
1777
-		if (
1778
-			is_array($image)
1779
-			and (!in_array($image['format_dest'], $gd_formats)
1780
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1781
-			)
1782
-		) {
1783
-			if ($image['format_source'] == 'jpg') {
1784
-				$formats_sortie = ['jpg', 'png', 'gif'];
1785
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1786
-			{
1787
-				$formats_sortie = ['png', 'jpg', 'gif'];
1788
-			}
1789
-			// Choisir le format destination
1790
-			// - on sauve de preference en JPEG (meilleure compression)
1791
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1792
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1793
-			# pas *ecrire*
1794
-			$format_sortie = '';
1795
-			foreach ($formats_sortie as $fmt) {
1796
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1797
-					$format_sortie = $fmt;
1798
-					break;
1799
-				}
1800
-			}
1801
-			$image = false;
1802
-		}
1803
-	}
1804
-
1805
-	if (!is_array($image)) {
1806
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1807
-	}
1808
-
1809
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1810
-		spip_log("image_reduire_src:pas de version locale de $img");
1811
-		// on peut resizer en mode html si on dispose des elements
1812
-		if (
1813
-			$srcw = extraire_attribut($img, 'width')
1814
-			and $srch = extraire_attribut($img, 'height')
1815
-		) {
1816
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1817
-
1818
-			return _image_tag_changer_taille($img, $w, $h);
1819
-		}
1820
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1821
-		// sous la forme style='max-width: NNpx;'
1822
-		return inserer_attribut(
1823
-			$img,
1824
-			'style',
1825
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1826
-		);
1827
-	}
1828
-
1829
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1830
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1831
-		if ($image['creer']) {
1832
-			@copy($image['fichier'], $image['fichier_dest']);
1833
-		}
1834
-
1835
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1836
-	}
1837
-
1838
-	if ($image['creer'] == false && !$force) {
1839
-		return _image_ecrire_tag(
1840
-			$image,
1841
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1842
-		);
1843
-	}
1844
-
1845
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1846
-		$destWidth = $image['largeur_dest'];
1847
-		$destHeight = $image['hauteur_dest'];
1848
-		$logo = $image['fichier'];
1849
-		$date = $image['date_src'];
1850
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1851
-
1852
-		if ($preview && $preview['fichier']) {
1853
-			$logo = $preview['fichier'];
1854
-			$destWidth = $preview['width'];
1855
-			$destHeight = $preview['height'];
1856
-			$date = $preview['date'];
1857
-		}
1858
-		// dans l'espace prive mettre un timestamp sur l'adresse
1859
-		// de l'image, de facon a tromper le cache du navigateur
1860
-		// quand on fait supprimer/reuploader un logo
1861
-		// (pas de filemtime si SAFE MODE)
1862
-		$date = test_espace_prive() ? ('?' . $date) : '';
1863
-
1864
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1865
-	}
1866
-	else {
1867
-		# BMP, tiff ... les redacteurs osent tout!
1868
-		return $img;
1869
-	}
1765
+    $image = false;
1766
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1767
+        $process = $GLOBALS['meta']['image_process'];
1768
+    }
1769
+    # determiner le format de sortie
1770
+    $format_sortie = false; // le choix par defaut sera bon
1771
+    if ($process == 'netpbm') {
1772
+        $format_sortie = 'jpg';
1773
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1774
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1775
+        // on verifie que l'extension choisie est bonne (en principe oui)
1776
+        $gd_formats = formats_image_acceptables(true);
1777
+        if (
1778
+            is_array($image)
1779
+            and (!in_array($image['format_dest'], $gd_formats)
1780
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1781
+            )
1782
+        ) {
1783
+            if ($image['format_source'] == 'jpg') {
1784
+                $formats_sortie = ['jpg', 'png', 'gif'];
1785
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1786
+            {
1787
+                $formats_sortie = ['png', 'jpg', 'gif'];
1788
+            }
1789
+            // Choisir le format destination
1790
+            // - on sauve de preference en JPEG (meilleure compression)
1791
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1792
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1793
+            # pas *ecrire*
1794
+            $format_sortie = '';
1795
+            foreach ($formats_sortie as $fmt) {
1796
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1797
+                    $format_sortie = $fmt;
1798
+                    break;
1799
+                }
1800
+            }
1801
+            $image = false;
1802
+        }
1803
+    }
1804
+
1805
+    if (!is_array($image)) {
1806
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1807
+    }
1808
+
1809
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1810
+        spip_log("image_reduire_src:pas de version locale de $img");
1811
+        // on peut resizer en mode html si on dispose des elements
1812
+        if (
1813
+            $srcw = extraire_attribut($img, 'width')
1814
+            and $srch = extraire_attribut($img, 'height')
1815
+        ) {
1816
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1817
+
1818
+            return _image_tag_changer_taille($img, $w, $h);
1819
+        }
1820
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1821
+        // sous la forme style='max-width: NNpx;'
1822
+        return inserer_attribut(
1823
+            $img,
1824
+            'style',
1825
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1826
+        );
1827
+    }
1828
+
1829
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1830
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1831
+        if ($image['creer']) {
1832
+            @copy($image['fichier'], $image['fichier_dest']);
1833
+        }
1834
+
1835
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1836
+    }
1837
+
1838
+    if ($image['creer'] == false && !$force) {
1839
+        return _image_ecrire_tag(
1840
+            $image,
1841
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1842
+        );
1843
+    }
1844
+
1845
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1846
+        $destWidth = $image['largeur_dest'];
1847
+        $destHeight = $image['hauteur_dest'];
1848
+        $logo = $image['fichier'];
1849
+        $date = $image['date_src'];
1850
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1851
+
1852
+        if ($preview && $preview['fichier']) {
1853
+            $logo = $preview['fichier'];
1854
+            $destWidth = $preview['width'];
1855
+            $destHeight = $preview['height'];
1856
+            $date = $preview['date'];
1857
+        }
1858
+        // dans l'espace prive mettre un timestamp sur l'adresse
1859
+        // de l'image, de facon a tromper le cache du navigateur
1860
+        // quand on fait supprimer/reuploader un logo
1861
+        // (pas de filemtime si SAFE MODE)
1862
+        $date = test_espace_prive() ? ('?' . $date) : '';
1863
+
1864
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1865
+    }
1866
+    else {
1867
+        # BMP, tiff ... les redacteurs osent tout!
1868
+        return $img;
1869
+    }
1870 1870
 }
1871 1871
 
1872 1872
 /**
@@ -1881,145 +1881,145 @@  discard block
 block discarded – undo
1881 1881
  */
1882 1882
 class phpthumb_functions {
1883 1883
 
1884
-	/**
1885
-	 * Retourne la couleur d'un pixel dans une image
1886
-	 *
1887
-	 * @param resource|GdImage $img
1888
-	 * @param int $x
1889
-	 * @param int $y
1890
-	 * @return array|bool
1891
-	 */
1892
-	public static function GetPixelColor(&$img, $x, $y) {
1893
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1894
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1895
-		}
1896
-		return false;
1897
-	}
1898
-
1899
-	/**
1900
-	 * Retourne un nombre dans une représentation en Little Endian
1901
-	 *
1902
-	 * @param int $number
1903
-	 * @param int $minbytes
1904
-	 * @return string
1905
-	 */
1906
-	public static function LittleEndian2String($number, $minbytes = 1) {
1907
-		$intstring = '';
1908
-		while ($number > 0) {
1909
-			$intstring = $intstring . chr($number & 255);
1910
-			$number >>= 8;
1911
-		}
1912
-
1913
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1914
-	}
1915
-
1916
-	/**
1917
-	 * Transforme une ressource GD en image au format ICO
1918
-	 *
1919
-	 * @param array $gd_image_array
1920
-	 *     Tableau de ressources d'images GD
1921
-	 * @return string
1922
-	 *     Image au format ICO
1923
-	 */
1924
-	public static function GD2ICOstring(&$gd_image_array) {
1925
-		foreach ($gd_image_array as $key => $gd_image) {
1926
-			$ImageWidths[$key] = ImageSX($gd_image);
1927
-			$ImageHeights[$key] = ImageSY($gd_image);
1928
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1929
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1930
-
1931
-			$icXOR[$key] = '';
1932
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1933
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1934
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1935
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1936
-					$r = $argb['red'];
1937
-					$g = $argb['green'];
1938
-					$b = $argb['blue'];
1939
-
1940
-					if ($bpp[$key] == 32) {
1941
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1942
-					} elseif ($bpp[$key] == 24) {
1943
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1944
-					}
1945
-
1946
-					if ($a < 128) {
1947
-						@$icANDmask[$key][$y] .= '1';
1948
-					} else {
1949
-						@$icANDmask[$key][$y] .= '0';
1950
-					}
1951
-				}
1952
-				// mask bits are 32-bit aligned per scanline
1953
-				while (strlen($icANDmask[$key][$y]) % 32) {
1954
-					$icANDmask[$key][$y] .= '0';
1955
-				}
1956
-			}
1957
-			$icAND[$key] = '';
1958
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1959
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1960
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1961
-				}
1962
-			}
1963
-		}
1964
-
1965
-		foreach ($gd_image_array as $key => $gd_image) {
1966
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1967
-
1968
-			// BITMAPINFOHEADER - 40 bytes
1969
-			$BitmapInfoHeader[$key] = '';
1970
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1971
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1972
-			// The biHeight member specifies the combined
1973
-			// height of the XOR and AND masks.
1974
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1975
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1976
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1977
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1978
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1979
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1980
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1981
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1982
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1983
-		}
1984
-
1985
-
1986
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1987
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1988
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1989
-
1990
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1991
-		foreach ($gd_image_array as $key => $gd_image) {
1992
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1993
-
1994
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1995
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1996
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1998
-
1999
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
2000
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
2001
-
2002
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
2003
-			$icondata .= phpthumb_functions::LittleEndian2String(
2004
-				$dwBytesInRes,
2005
-				4
2006
-			);     // dwBytesInRes;	// How many bytes in this resource?
2007
-
2008
-			$icondata .= phpthumb_functions::LittleEndian2String(
2009
-				$dwImageOffset,
2010
-				4
2011
-			);    // dwImageOffset;   // Where in the file is this image?
2012
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2013
-			$dwImageOffset += strlen($icXOR[$key]);
2014
-			$dwImageOffset += strlen($icAND[$key]);
2015
-		}
2016
-
2017
-		foreach ($gd_image_array as $key => $gd_image) {
2018
-			$icondata .= $BitmapInfoHeader[$key];
2019
-			$icondata .= $icXOR[$key];
2020
-			$icondata .= $icAND[$key];
2021
-		}
2022
-
2023
-		return $icondata;
2024
-	}
1884
+    /**
1885
+     * Retourne la couleur d'un pixel dans une image
1886
+     *
1887
+     * @param resource|GdImage $img
1888
+     * @param int $x
1889
+     * @param int $y
1890
+     * @return array|bool
1891
+     */
1892
+    public static function GetPixelColor(&$img, $x, $y) {
1893
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1894
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1895
+        }
1896
+        return false;
1897
+    }
1898
+
1899
+    /**
1900
+     * Retourne un nombre dans une représentation en Little Endian
1901
+     *
1902
+     * @param int $number
1903
+     * @param int $minbytes
1904
+     * @return string
1905
+     */
1906
+    public static function LittleEndian2String($number, $minbytes = 1) {
1907
+        $intstring = '';
1908
+        while ($number > 0) {
1909
+            $intstring = $intstring . chr($number & 255);
1910
+            $number >>= 8;
1911
+        }
1912
+
1913
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1914
+    }
1915
+
1916
+    /**
1917
+     * Transforme une ressource GD en image au format ICO
1918
+     *
1919
+     * @param array $gd_image_array
1920
+     *     Tableau de ressources d'images GD
1921
+     * @return string
1922
+     *     Image au format ICO
1923
+     */
1924
+    public static function GD2ICOstring(&$gd_image_array) {
1925
+        foreach ($gd_image_array as $key => $gd_image) {
1926
+            $ImageWidths[$key] = ImageSX($gd_image);
1927
+            $ImageHeights[$key] = ImageSY($gd_image);
1928
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1929
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1930
+
1931
+            $icXOR[$key] = '';
1932
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1933
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1934
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1935
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1936
+                    $r = $argb['red'];
1937
+                    $g = $argb['green'];
1938
+                    $b = $argb['blue'];
1939
+
1940
+                    if ($bpp[$key] == 32) {
1941
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1942
+                    } elseif ($bpp[$key] == 24) {
1943
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1944
+                    }
1945
+
1946
+                    if ($a < 128) {
1947
+                        @$icANDmask[$key][$y] .= '1';
1948
+                    } else {
1949
+                        @$icANDmask[$key][$y] .= '0';
1950
+                    }
1951
+                }
1952
+                // mask bits are 32-bit aligned per scanline
1953
+                while (strlen($icANDmask[$key][$y]) % 32) {
1954
+                    $icANDmask[$key][$y] .= '0';
1955
+                }
1956
+            }
1957
+            $icAND[$key] = '';
1958
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1959
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1960
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1961
+                }
1962
+            }
1963
+        }
1964
+
1965
+        foreach ($gd_image_array as $key => $gd_image) {
1966
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1967
+
1968
+            // BITMAPINFOHEADER - 40 bytes
1969
+            $BitmapInfoHeader[$key] = '';
1970
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1971
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1972
+            // The biHeight member specifies the combined
1973
+            // height of the XOR and AND masks.
1974
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1975
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1976
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1977
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1978
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1979
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1980
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1981
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1982
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1983
+        }
1984
+
1985
+
1986
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1987
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1988
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1989
+
1990
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1991
+        foreach ($gd_image_array as $key => $gd_image) {
1992
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1993
+
1994
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1995
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1996
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1997
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1998
+
1999
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
2000
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
2001
+
2002
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
2003
+            $icondata .= phpthumb_functions::LittleEndian2String(
2004
+                $dwBytesInRes,
2005
+                4
2006
+            );     // dwBytesInRes;	// How many bytes in this resource?
2007
+
2008
+            $icondata .= phpthumb_functions::LittleEndian2String(
2009
+                $dwImageOffset,
2010
+                4
2011
+            );    // dwImageOffset;   // Where in the file is this image?
2012
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
2013
+            $dwImageOffset += strlen($icXOR[$key]);
2014
+            $dwImageOffset += strlen($icAND[$key]);
2015
+        }
2016
+
2017
+        foreach ($gd_image_array as $key => $gd_image) {
2018
+            $icondata .= $BitmapInfoHeader[$key];
2019
+            $icondata .= $icXOR[$key];
2020
+            $icondata .= $icAND[$key];
2021
+        }
2022
+
2023
+        return $icondata;
2024
+    }
2025 2025
 }
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/charsets');
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function exporter_csv_champ($champ) {
35
-	#$champ = str_replace("\r", "\n", $champ);
36
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
-	#$champ = str_replace("\n", ", ", $champ);
38
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
-	$champ = str_replace('"', '""', $champ);
35
+    #$champ = str_replace("\r", "\n", $champ);
36
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
+    #$champ = str_replace("\n", ", ", $champ);
38
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
+    $champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+    return '"' . $champ . '"';
42 42
 }
43 43
 
44 44
 /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
  * @return string
56 56
  */
57 57
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) {
58
-	if ($callback) {
59
-		$ligne = $callback($nb, $ligne, $delim, $importer_charset);
60
-	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
-	if ($importer_charset) {
63
-		$output = str_replace('’', '\'', $output);
64
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
-	}
66
-	return $output;
58
+    if ($callback) {
59
+        $ligne = $callback($nb, $ligne, $delim, $importer_charset);
60
+    }
61
+    $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
+    if ($importer_charset) {
63
+        $output = str_replace('’', '\'', $output);
64
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
+    }
66
+    return $output;
67 67
 }
68 68
 
69 69
 /**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
  * @return string
76 76
  */
77 77
 function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
78
-	return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
78
+    return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
79 79
 }
80 80
 
81 81
 /**
@@ -101,101 +101,101 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
103 103
 
104
-	// support ancienne syntaxe
105
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
-	if (is_string($options)) {
107
-		$args = func_get_args();
108
-		$options = [];
109
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
-			if (!empty($args[$k])) {
111
-				$options[$option] = $args[$k];
112
-			}
113
-		}
114
-	}
115
-
116
-	$default_options = [
117
-		'delim' => ', ',
118
-		'entetes' => null,
119
-		'envoyer' => true,
120
-		'charset' => null,
121
-		'callback' => null,
122
-	];
123
-	$options = array_merge($default_options, $options);
124
-
125
-	$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
-
127
-	if ($options['delim'] == 'TAB') {
128
-		$options['delim'] = "\t";
129
-	}
130
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
131
-		$options['delim'] = ',';
132
-	}
133
-
134
-	$charset = $GLOBALS['meta']['charset'];
135
-	$importer_charset = null;
136
-	if ($options['delim'] == ',') {
137
-		$extension = 'csv';
138
-	} else {
139
-		$extension = 'xls';
140
-		# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
-		$charset = 'iso-8859-1';
142
-	}
143
-	// mais si une option charset est explicite, elle a la priorite
144
-	if (!empty($options['charset'])) {
145
-		$charset = $options['charset'];
146
-	}
147
-
148
-	$importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
-
150
-	$filename = "$filename.$extension";
151
-
152
-	$output = '';
153
-	$nb = 0;
154
-	if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
-	}
157
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
-	$nb++;
159
-
160
-	if ($options['envoyer']) {
161
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
-		header("Content-Type: text/comma-separated-values; charset=$charset");
163
-		header("Content-Disposition: $disposition; filename=$filename");
164
-
165
-		// Vider tous les tampons
166
-		$level = @ob_get_level();
167
-		while ($level--) {
168
-			@ob_end_flush();
169
-		}
170
-	}
171
-
172
-	// si envoyer=='attachment' on passe par un fichier temporaire
173
-	// sinon on ecrit directement sur stdout
174
-	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
-		$fichier = 'php://output';
176
-	}
177
-	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
-	}
180
-
181
-	$fp = fopen($fichier, 'w');
182
-	$length = fwrite($fp, $output);
183
-
184
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
-		$length += fwrite($fp, $output);
187
-		$nb++;
188
-	}
189
-	fclose($fp);
190
-
191
-	if ($options['envoyer']) {
192
-		if ($options['envoyer'] === 'attachment') {
193
-			header("Content-Length: $length");
194
-			readfile($fichier);
195
-		}
196
-		// si on a envoye inline, c'est deja tout bon
197
-		exit;
198
-	}
199
-
200
-	return $fichier;
104
+    // support ancienne syntaxe
105
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
+    if (is_string($options)) {
107
+        $args = func_get_args();
108
+        $options = [];
109
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
+            if (!empty($args[$k])) {
111
+                $options[$option] = $args[$k];
112
+            }
113
+        }
114
+    }
115
+
116
+    $default_options = [
117
+        'delim' => ', ',
118
+        'entetes' => null,
119
+        'envoyer' => true,
120
+        'charset' => null,
121
+        'callback' => null,
122
+    ];
123
+    $options = array_merge($default_options, $options);
124
+
125
+    $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
+
127
+    if ($options['delim'] == 'TAB') {
128
+        $options['delim'] = "\t";
129
+    }
130
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
131
+        $options['delim'] = ',';
132
+    }
133
+
134
+    $charset = $GLOBALS['meta']['charset'];
135
+    $importer_charset = null;
136
+    if ($options['delim'] == ',') {
137
+        $extension = 'csv';
138
+    } else {
139
+        $extension = 'xls';
140
+        # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
+        $charset = 'iso-8859-1';
142
+    }
143
+    // mais si une option charset est explicite, elle a la priorite
144
+    if (!empty($options['charset'])) {
145
+        $charset = $options['charset'];
146
+    }
147
+
148
+    $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
+
150
+    $filename = "$filename.$extension";
151
+
152
+    $output = '';
153
+    $nb = 0;
154
+    if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
+    }
157
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
+    $nb++;
159
+
160
+    if ($options['envoyer']) {
161
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
+        header("Content-Type: text/comma-separated-values; charset=$charset");
163
+        header("Content-Disposition: $disposition; filename=$filename");
164
+
165
+        // Vider tous les tampons
166
+        $level = @ob_get_level();
167
+        while ($level--) {
168
+            @ob_end_flush();
169
+        }
170
+    }
171
+
172
+    // si envoyer=='attachment' on passe par un fichier temporaire
173
+    // sinon on ecrit directement sur stdout
174
+    if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
+        $fichier = 'php://output';
176
+    }
177
+    else {
178
+    $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
+    }
180
+
181
+    $fp = fopen($fichier, 'w');
182
+    $length = fwrite($fp, $output);
183
+
184
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
+        $length += fwrite($fp, $output);
187
+        $nb++;
188
+    }
189
+    fclose($fp);
190
+
191
+    if ($options['envoyer']) {
192
+        if ($options['envoyer'] === 'attachment') {
193
+            header("Content-Length: $length");
194
+            readfile($fichier);
195
+        }
196
+        // si on a envoye inline, c'est deja tout bon
197
+        exit;
198
+    }
199
+
200
+    return $fichier;
201 201
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2473 added lines, -2473 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 $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 $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 = $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 = $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 = $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 = $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 = $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 = $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,20 +1991,20 @@  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
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1999
-		$args = array_values($args[0]);
2000
-		$num = count($args);
2001
-	}
1997
+    if ($num === 1 && is_array($args[0])) {
1998
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1999
+        $args = array_values($args[0]);
2000
+        $num = count($args);
2001
+    }
2002 2002
 
2003
-	// un index compris entre 0 et num exclus
2004
-	$i = ((intval($i) -1) % $num); // dans ]-$num;$num[
2005
-	$i = ($i + $num) % $num; // dans [0;$num[
2006
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
2007
-	return $args[$i];
2003
+    // un index compris entre 0 et num exclus
2004
+    $i = ((intval($i) -1) % $num); // dans ]-$num;$num[
2005
+    $i = ($i + $num) % $num; // dans [0;$num[
2006
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
2007
+    return $args[$i];
2008 2008
 }
2009 2009
 
2010 2010
 
@@ -2030,51 +2030,51 @@  discard block
 block discarded – undo
2030 2030
  *     - null lorsque l’attribut n’existe pas.
2031 2031
  **/
2032 2032
 function extraire_attribut($balise, $attribut, $complet = false) {
2033
-	if (is_array($balise)) {
2034
-		array_walk(
2035
-			$balise,
2036
-			function (&$a, $key, $t) {
2037
-				$a = extraire_attribut($a, $t);
2038
-			},
2039
-			$attribut
2040
-		);
2041
-
2042
-		return $balise;
2043
-	}
2044
-	if (
2045
-		$balise
2046
-		&& preg_match(
2047
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2048
-			. $attribut
2049
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2050
-			$balise,
2051
-			$r
2052
-		)
2053
-	) {
2054
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2055
-			$r[4] = substr($r[3], 1, -1);
2056
-			$r[3] = $r[3][0];
2057
-		} elseif ($r[3] !== '') {
2058
-			$r[4] = $r[3];
2059
-			$r[3] = '';
2060
-		} else {
2061
-			$r[4] = trim($r[2]);
2062
-		}
2063
-		$att = $r[4];
2064
-		if (strpos($att, '&#') !== false) {
2065
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2066
-		}
2067
-		$att = filtrer_entites($att);
2068
-	} else {
2069
-		$att = null;
2070
-		$r = [];
2071
-	}
2072
-
2073
-	if ($complet) {
2074
-		return [$att, $r];
2075
-	} else {
2076
-		return $att;
2077
-	}
2033
+    if (is_array($balise)) {
2034
+        array_walk(
2035
+            $balise,
2036
+            function (&$a, $key, $t) {
2037
+                $a = extraire_attribut($a, $t);
2038
+            },
2039
+            $attribut
2040
+        );
2041
+
2042
+        return $balise;
2043
+    }
2044
+    if (
2045
+        $balise
2046
+        && preg_match(
2047
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2048
+            . $attribut
2049
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2050
+            $balise,
2051
+            $r
2052
+        )
2053
+    ) {
2054
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2055
+            $r[4] = substr($r[3], 1, -1);
2056
+            $r[3] = $r[3][0];
2057
+        } elseif ($r[3] !== '') {
2058
+            $r[4] = $r[3];
2059
+            $r[3] = '';
2060
+        } else {
2061
+            $r[4] = trim($r[2]);
2062
+        }
2063
+        $att = $r[4];
2064
+        if (strpos($att, '&#') !== false) {
2065
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2066
+        }
2067
+        $att = filtrer_entites($att);
2068
+    } else {
2069
+        $att = null;
2070
+        $r = [];
2071
+    }
2072
+
2073
+    if ($complet) {
2074
+        return [$att, $r];
2075
+    } else {
2076
+        return $att;
2077
+    }
2078 2078
 }
2079 2079
 
2080 2080
 /**
@@ -2107,41 +2107,41 @@  discard block
 block discarded – undo
2107 2107
  **/
2108 2108
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2109 2109
 
2110
-	if ($balise === null or $balise === '') {
2111
-		return '';
2112
-	}
2110
+    if ($balise === null or $balise === '') {
2111
+        return '';
2112
+    }
2113 2113
 
2114
-	// preparer l'attribut
2115
-	// supprimer les &nbsp; etc mais pas les balises html
2116
-	// qui ont un sens dans un attribut value d'un input
2117
-	if ($proteger) {
2118
-		$val = attribut_html($val, false);
2119
-	}
2114
+    // preparer l'attribut
2115
+    // supprimer les &nbsp; etc mais pas les balises html
2116
+    // qui ont un sens dans un attribut value d'un input
2117
+    if ($proteger) {
2118
+        $val = attribut_html($val, false);
2119
+    }
2120 2120
 
2121
-	// echapper les ' pour eviter tout bug
2122
-	$val = str_replace("'", '&#039;', $val);
2123
-	if ($vider and strlen($val) === 0) {
2124
-		$insert = '';
2125
-	} else {
2126
-		$insert = " $attribut='$val'";
2127
-	}
2121
+    // echapper les ' pour eviter tout bug
2122
+    $val = str_replace("'", '&#039;', $val);
2123
+    if ($vider and strlen($val) === 0) {
2124
+        $insert = '';
2125
+    } else {
2126
+        $insert = " $attribut='$val'";
2127
+    }
2128 2128
 
2129
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2129
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2130 2130
 
2131
-	if ($old !== null) {
2132
-		// Remplacer l'ancien attribut du meme nom
2133
-		$balise = $r[1] . $insert . $r[5];
2134
-	} else {
2135
-		// preferer une balise " />" (comme <img />)
2136
-		if (preg_match(',/>,', $balise)) {
2137
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2138
-		} // sinon une balise <a ...> ... </a>
2139
-		else {
2140
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2141
-		}
2142
-	}
2131
+    if ($old !== null) {
2132
+        // Remplacer l'ancien attribut du meme nom
2133
+        $balise = $r[1] . $insert . $r[5];
2134
+    } else {
2135
+        // preferer une balise " />" (comme <img />)
2136
+        if (preg_match(',/>,', $balise)) {
2137
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2138
+        } // sinon une balise <a ...> ... </a>
2139
+        else {
2140
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2141
+        }
2142
+    }
2143 2143
 
2144
-	return $balise;
2144
+    return $balise;
2145 2145
 }
2146 2146
 
2147 2147
 /**
@@ -2159,7 +2159,7 @@  discard block
 block discarded – undo
2159 2159
  * @return string Code HTML sans l'attribut
2160 2160
  **/
2161 2161
 function vider_attribut(?string $balise, string $attribut): string {
2162
-	return inserer_attribut($balise, $attribut, '', false, true);
2162
+    return inserer_attribut($balise, $attribut, '', false, true);
2163 2163
 }
2164 2164
 
2165 2165
 /**
@@ -2171,53 +2171,53 @@  discard block
 block discarded – undo
2171 2171
  * @return string
2172 2172
  */
2173 2173
 function modifier_class($balise, $class, $operation = 'ajouter') {
2174
-	if (is_string($class)) {
2175
-		$class = explode(' ', trim($class));
2176
-	}
2177
-	$class = array_filter($class);
2178
-	$class = array_unique($class);
2179
-	if (!$class) {
2180
-		return $balise;
2181
-	}
2182
-
2183
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2184
-	if (preg_match(',[^\w-],', implode('', $class))) {
2185
-		return $balise;
2186
-	}
2187
-
2188
-	$class_courante = extraire_attribut($balise, 'class');
2189
-	$class_new = $class_courante;
2190
-	foreach ($class as $c) {
2191
-		$is_class_presente = false;
2192
-		if (
2193
-			$class_courante
2194
-			and strpos($class_courante, (string) $c) !== false
2195
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2196
-		) {
2197
-			$is_class_presente = true;
2198
-		}
2199
-		if (
2200
-			in_array($operation, ['ajouter', 'commuter'])
2201
-			and !$is_class_presente
2202
-		) {
2203
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2204
-		} elseif (
2205
-			in_array($operation, ['supprimer', 'commuter'])
2206
-			and $is_class_presente
2207
-		) {
2208
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2209
-		}
2210
-	}
2211
-
2212
-	if ($class_new !== $class_courante) {
2213
-		if (strlen($class_new)) {
2214
-			$balise = inserer_attribut($balise, 'class', $class_new);
2215
-		} elseif ($class_courante) {
2216
-			$balise = vider_attribut($balise, 'class');
2217
-		}
2218
-	}
2219
-
2220
-	return $balise;
2174
+    if (is_string($class)) {
2175
+        $class = explode(' ', trim($class));
2176
+    }
2177
+    $class = array_filter($class);
2178
+    $class = array_unique($class);
2179
+    if (!$class) {
2180
+        return $balise;
2181
+    }
2182
+
2183
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2184
+    if (preg_match(',[^\w-],', implode('', $class))) {
2185
+        return $balise;
2186
+    }
2187
+
2188
+    $class_courante = extraire_attribut($balise, 'class');
2189
+    $class_new = $class_courante;
2190
+    foreach ($class as $c) {
2191
+        $is_class_presente = false;
2192
+        if (
2193
+            $class_courante
2194
+            and strpos($class_courante, (string) $c) !== false
2195
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2196
+        ) {
2197
+            $is_class_presente = true;
2198
+        }
2199
+        if (
2200
+            in_array($operation, ['ajouter', 'commuter'])
2201
+            and !$is_class_presente
2202
+        ) {
2203
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2204
+        } elseif (
2205
+            in_array($operation, ['supprimer', 'commuter'])
2206
+            and $is_class_presente
2207
+        ) {
2208
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2209
+        }
2210
+    }
2211
+
2212
+    if ($class_new !== $class_courante) {
2213
+        if (strlen($class_new)) {
2214
+            $balise = inserer_attribut($balise, 'class', $class_new);
2215
+        } elseif ($class_courante) {
2216
+            $balise = vider_attribut($balise, 'class');
2217
+        }
2218
+    }
2219
+
2220
+    return $balise;
2221 2221
 }
2222 2222
 
2223 2223
 /**
@@ -2227,7 +2227,7 @@  discard block
 block discarded – undo
2227 2227
  * @return string
2228 2228
  */
2229 2229
 function ajouter_class($balise, $class) {
2230
-	return modifier_class($balise, $class, 'ajouter');
2230
+    return modifier_class($balise, $class, 'ajouter');
2231 2231
 }
2232 2232
 
2233 2233
 /**
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
  * @return string
2238 2238
  */
2239 2239
 function supprimer_class($balise, $class) {
2240
-	return modifier_class($balise, $class, 'supprimer');
2240
+    return modifier_class($balise, $class, 'supprimer');
2241 2241
 }
2242 2242
 
2243 2243
 /**
@@ -2248,7 +2248,7 @@  discard block
 block discarded – undo
2248 2248
  * @return string
2249 2249
  */
2250 2250
 function commuter_class($balise, $class) {
2251
-	return modifier_class($balise, $class, 'commuter');
2251
+    return modifier_class($balise, $class, 'commuter');
2252 2252
 }
2253 2253
 
2254 2254
 /**
@@ -2259,19 +2259,19 @@  discard block
 block discarded – undo
2259 2259
  * @return string
2260 2260
  */
2261 2261
 function tester_config($id, $mode = '') {
2262
-	include_spip('action/inscrire_auteur');
2262
+    include_spip('action/inscrire_auteur');
2263 2263
 
2264
-	return tester_statut_inscription($mode, $id);
2264
+    return tester_statut_inscription($mode, $id);
2265 2265
 }
2266 2266
 
2267 2267
 //
2268 2268
 // Quelques fonctions de calcul arithmetique
2269 2269
 //
2270 2270
 function floatstr($a) {
2271
- return str_replace(',', '.', (string)floatval($a));
2271
+    return str_replace(',', '.', (string)floatval($a));
2272 2272
 }
2273 2273
 function strize($f, $a, $b) {
2274
- return floatstr($f(floatstr($a), floatstr($b)));
2274
+    return floatstr($f(floatstr($a), floatstr($b)));
2275 2275
 }
2276 2276
 
2277 2277
 /**
@@ -2290,7 +2290,7 @@  discard block
 block discarded – undo
2290 2290
  * @return int $a+$b
2291 2291
  **/
2292 2292
 function plus($a, $b) {
2293
-	return $a + $b;
2293
+    return $a + $b;
2294 2294
 }
2295 2295
 function strplus($a, $b) {
2296 2296
 return strize('plus', $a, $b);
@@ -2311,7 +2311,7 @@  discard block
 block discarded – undo
2311 2311
  * @return int $a-$b
2312 2312
  **/
2313 2313
 function moins($a, $b) {
2314
-	return $a - $b;
2314
+    return $a - $b;
2315 2315
 }
2316 2316
 function strmoins($a, $b) {
2317 2317
 return strize('moins', $a, $b);
@@ -2334,7 +2334,7 @@  discard block
 block discarded – undo
2334 2334
  * @return int $a*$b
2335 2335
  **/
2336 2336
 function mult($a, $b) {
2337
-	return $a * $b;
2337
+    return $a * $b;
2338 2338
 }
2339 2339
 function strmult($a, $b) {
2340 2340
 return strize('mult', $a, $b);
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
  * @return int $a/$b (ou 0 si $b est nul)
2358 2358
  **/
2359 2359
 function div($a, $b) {
2360
-	return $b ? $a / $b : 0;
2360
+    return $b ? $a / $b : 0;
2361 2361
 }
2362 2362
 function strdiv($a, $b) {
2363 2363
 return strize('div', $a, $b);
@@ -2381,7 +2381,7 @@  discard block
 block discarded – undo
2381 2381
  * @return int ($nb % $mod) + $add
2382 2382
  **/
2383 2383
 function modulo($nb, $mod, $add = 0) {
2384
-	return ($mod ? $nb % $mod : 0) + $add;
2384
+    return ($mod ? $nb % $mod : 0) + $add;
2385 2385
 }
2386 2386
 
2387 2387
 
@@ -2396,26 +2396,26 @@  discard block
 block discarded – undo
2396 2396
  *      - true sinon
2397 2397
  **/
2398 2398
 function nom_acceptable($nom) {
2399
-	$remp2 = [];
2400
-	$remp1 = [];
2401
-	if (!is_string($nom)) {
2402
-		return false;
2403
-	}
2404
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2405
-		define('_TAGS_NOM_AUTEUR', '');
2406
-	}
2407
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2408
-	foreach ($tags_acceptes as $tag) {
2409
-		if (strlen($tag)) {
2410
-			$remp1[] = '<' . trim($tag) . '>';
2411
-			$remp1[] = '</' . trim($tag) . '>';
2412
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2413
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2414
-		}
2415
-	}
2416
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2417
-
2418
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2399
+    $remp2 = [];
2400
+    $remp1 = [];
2401
+    if (!is_string($nom)) {
2402
+        return false;
2403
+    }
2404
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2405
+        define('_TAGS_NOM_AUTEUR', '');
2406
+    }
2407
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2408
+    foreach ($tags_acceptes as $tag) {
2409
+        if (strlen($tag)) {
2410
+            $remp1[] = '<' . trim($tag) . '>';
2411
+            $remp1[] = '</' . trim($tag) . '>';
2412
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2413
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2414
+        }
2415
+    }
2416
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2417
+
2418
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2419 2419
 }
2420 2420
 
2421 2421
 
@@ -2431,14 +2431,14 @@  discard block
 block discarded – undo
2431 2431
  *      - renvoie un tableau si l'entree est un tableau
2432 2432
  **/
2433 2433
 function email_valide($adresses) {
2434
-	if (is_array($adresses)) {
2435
-		$adresses = array_map('email_valide', $adresses);
2436
-		$adresses = array_filter($adresses);
2437
-		return $adresses;
2438
-	}
2434
+    if (is_array($adresses)) {
2435
+        $adresses = array_map('email_valide', $adresses);
2436
+        $adresses = array_filter($adresses);
2437
+        return $adresses;
2438
+    }
2439 2439
 
2440
-	$email_valide = charger_fonction('email_valide', 'inc');
2441
-	return $email_valide($adresses);
2440
+    $email_valide = charger_fonction('email_valide', 'inc');
2441
+    return $email_valide($adresses);
2442 2442
 }
2443 2443
 
2444 2444
 /**
@@ -2452,27 +2452,27 @@  discard block
 block discarded – undo
2452 2452
  * @return string Texte
2453 2453
  **/
2454 2454
 function afficher_enclosures($tags) {
2455
-	$s = [];
2456
-	foreach (extraire_balises($tags, 'a') as $tag) {
2457
-		if (
2458
-			extraire_attribut($tag, 'rel') == 'enclosure'
2459
-			and $t = extraire_attribut($tag, 'href')
2460
-		) {
2461
-			$s[] = preg_replace(
2462
-				',>[^<]+</a>,S',
2463
-				'>'
2464
-				. http_img_pack(
2465
-					'attachment-16.png',
2466
-					$t,
2467
-					'title="' . attribut_html($t) . '"'
2468
-				)
2469
-				. '</a>',
2470
-				$tag
2471
-			);
2472
-		}
2473
-	}
2474
-
2475
-	return join('&nbsp;', $s);
2455
+    $s = [];
2456
+    foreach (extraire_balises($tags, 'a') as $tag) {
2457
+        if (
2458
+            extraire_attribut($tag, 'rel') == 'enclosure'
2459
+            and $t = extraire_attribut($tag, 'href')
2460
+        ) {
2461
+            $s[] = preg_replace(
2462
+                ',>[^<]+</a>,S',
2463
+                '>'
2464
+                . http_img_pack(
2465
+                    'attachment-16.png',
2466
+                    $t,
2467
+                    'title="' . attribut_html($t) . '"'
2468
+                )
2469
+                . '</a>',
2470
+                $tag
2471
+            );
2472
+        }
2473
+    }
2474
+
2475
+    return join('&nbsp;', $s);
2476 2476
 }
2477 2477
 
2478 2478
 /**
@@ -2487,15 +2487,15 @@  discard block
 block discarded – undo
2487 2487
  * @return string Liens trouvés
2488 2488
  **/
2489 2489
 function afficher_tags($tags, $rels = 'tag,directory') {
2490
-	$s = [];
2491
-	foreach (extraire_balises($tags, 'a') as $tag) {
2492
-		$rel = extraire_attribut($tag, 'rel');
2493
-		if (strstr(",$rels,", (string) ",$rel,")) {
2494
-			$s[] = $tag;
2495
-		}
2496
-	}
2490
+    $s = [];
2491
+    foreach (extraire_balises($tags, 'a') as $tag) {
2492
+        $rel = extraire_attribut($tag, 'rel');
2493
+        if (strstr(",$rels,", (string) ",$rel,")) {
2494
+            $s[] = $tag;
2495
+        }
2496
+    }
2497 2497
 
2498
-	return join(', ', $s);
2498
+    return join(', ', $s);
2499 2499
 }
2500 2500
 
2501 2501
 
@@ -2517,21 +2517,21 @@  discard block
 block discarded – undo
2517 2517
  * @return string Tag HTML `<a>` avec microformat.
2518 2518
  **/
2519 2519
 function enclosure2microformat($e) {
2520
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2521
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2522
-	}
2523
-	$type = extraire_attribut($e, 'type');
2524
-	if (!$length = extraire_attribut($e, 'length')) {
2525
-		# <media:content : longeur dans fileSize. On tente.
2526
-		$length = extraire_attribut($e, 'fileSize');
2527
-	}
2528
-	$fichier = basename($url);
2520
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2521
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2522
+    }
2523
+    $type = extraire_attribut($e, 'type');
2524
+    if (!$length = extraire_attribut($e, 'length')) {
2525
+        # <media:content : longeur dans fileSize. On tente.
2526
+        $length = extraire_attribut($e, 'fileSize');
2527
+    }
2528
+    $fichier = basename($url);
2529 2529
 
2530
-	return '<a rel="enclosure"'
2531
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2532
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2533
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2534
-	. '>' . $fichier . '</a>';
2530
+    return '<a rel="enclosure"'
2531
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2532
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2533
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2534
+    . '>' . $fichier . '</a>';
2535 2535
 }
2536 2536
 
2537 2537
 /**
@@ -2549,24 +2549,24 @@  discard block
 block discarded – undo
2549 2549
  * @return string Tags RSS `<enclosure>`.
2550 2550
  **/
2551 2551
 function microformat2enclosure($tags) {
2552
-	$enclosures = [];
2553
-	foreach (extraire_balises($tags, 'a') as $e) {
2554
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2555
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2556
-			$type = extraire_attribut($e, 'type');
2557
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2558
-				$length = intval(extraire_attribut($e, 'length'));
2559
-			} # vieux data
2560
-			$fichier = basename($url);
2561
-			$enclosures[] = '<enclosure'
2562
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2563
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2564
-				. ($length ? ' length="' . $length . '"' : '')
2565
-				. ' />';
2566
-		}
2567
-	}
2552
+    $enclosures = [];
2553
+    foreach (extraire_balises($tags, 'a') as $e) {
2554
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2555
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2556
+            $type = extraire_attribut($e, 'type');
2557
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2558
+                $length = intval(extraire_attribut($e, 'length'));
2559
+            } # vieux data
2560
+            $fichier = basename($url);
2561
+            $enclosures[] = '<enclosure'
2562
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2563
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2564
+                . ($length ? ' length="' . $length . '"' : '')
2565
+                . ' />';
2566
+        }
2567
+    }
2568 2568
 
2569
-	return join("\n", $enclosures);
2569
+    return join("\n", $enclosures);
2570 2570
 }
2571 2571
 
2572 2572
 
@@ -2582,16 +2582,16 @@  discard block
 block discarded – undo
2582 2582
  * @return string Tags RSS Atom `<dc:subject>`.
2583 2583
  **/
2584 2584
 function tags2dcsubject($tags) {
2585
-	$subjects = '';
2586
-	foreach (extraire_balises($tags, 'a') as $e) {
2587
-		if (extraire_attribut($e, 'rel') == 'tag') {
2588
-			$subjects .= '<dc:subject>'
2589
-				. texte_backend(textebrut($e))
2590
-				. '</dc:subject>' . "\n";
2591
-		}
2592
-	}
2585
+    $subjects = '';
2586
+    foreach (extraire_balises($tags, 'a') as $e) {
2587
+        if (extraire_attribut($e, 'rel') == 'tag') {
2588
+            $subjects .= '<dc:subject>'
2589
+                . texte_backend(textebrut($e))
2590
+                . '</dc:subject>' . "\n";
2591
+        }
2592
+    }
2593 2593
 
2594
-	return $subjects;
2594
+    return $subjects;
2595 2595
 }
2596 2596
 
2597 2597
 /**
@@ -2620,27 +2620,27 @@  discard block
 block discarded – undo
2620 2620
  *     - Tableau de résultats, si tableau en entrée.
2621 2621
  **/
2622 2622
 function extraire_balise($texte, $tag = 'a') {
2623
-	if (is_array($texte)) {
2624
-		array_walk(
2625
-			$texte,
2626
-			function (&$a, $key, $t) {
2627
-				$a = extraire_balise($a, $t);
2628
-			},
2629
-			$tag
2630
-		);
2631
-
2632
-		return $texte;
2633
-	}
2634
-
2635
-	if (
2636
-		preg_match(
2637
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2638
-			$texte,
2639
-			$regs
2640
-		)
2641
-	) {
2642
-		return $regs[0];
2643
-	}
2623
+    if (is_array($texte)) {
2624
+        array_walk(
2625
+            $texte,
2626
+            function (&$a, $key, $t) {
2627
+                $a = extraire_balise($a, $t);
2628
+            },
2629
+            $tag
2630
+        );
2631
+
2632
+        return $texte;
2633
+    }
2634
+
2635
+    if (
2636
+        preg_match(
2637
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2638
+            $texte,
2639
+            $regs
2640
+        )
2641
+    ) {
2642
+        return $regs[0];
2643
+    }
2644 2644
 }
2645 2645
 
2646 2646
 /**
@@ -2668,30 +2668,30 @@  discard block
 block discarded – undo
2668 2668
  *     - Tableau de résultats, si tableau en entrée.
2669 2669
  **/
2670 2670
 function extraire_balises($texte, $tag = 'a') {
2671
-	if (is_array($texte)) {
2672
-		array_walk(
2673
-			$texte,
2674
-			function (&$a, $key, $t) {
2675
-				$a = extraire_balises($a, $t);
2676
-			},
2677
-			$tag
2678
-		);
2679
-
2680
-		return $texte;
2681
-	}
2682
-
2683
-	if (
2684
-		preg_match_all(
2685
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2686
-			$texte,
2687
-			$regs,
2688
-			PREG_PATTERN_ORDER
2689
-		)
2690
-	) {
2691
-		return $regs[0];
2692
-	} else {
2693
-		return [];
2694
-	}
2671
+    if (is_array($texte)) {
2672
+        array_walk(
2673
+            $texte,
2674
+            function (&$a, $key, $t) {
2675
+                $a = extraire_balises($a, $t);
2676
+            },
2677
+            $tag
2678
+        );
2679
+
2680
+        return $texte;
2681
+    }
2682
+
2683
+    if (
2684
+        preg_match_all(
2685
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2686
+            $texte,
2687
+            $regs,
2688
+            PREG_PATTERN_ORDER
2689
+        )
2690
+    ) {
2691
+        return $regs[0];
2692
+    } else {
2693
+        return [];
2694
+    }
2695 2695
 }
2696 2696
 
2697 2697
 /**
@@ -2720,11 +2720,11 @@  discard block
 block discarded – undo
2720 2720
  *     - `$def` si on n'a pas transmis de tableau
2721 2721
  **/
2722 2722
 function in_any($val, $vals, $def = '') {
2723
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2724
-		$vals = $v;
2725
-	}
2723
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2724
+        $vals = $v;
2725
+    }
2726 2726
 
2727
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2727
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2728 2728
 }
2729 2729
 
2730 2730
 
@@ -2745,12 +2745,12 @@  discard block
 block discarded – undo
2745 2745
  *     Résultat du calcul
2746 2746
  **/
2747 2747
 function valeur_numerique($expr) {
2748
-	$a = 0;
2749
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2750
-		eval("\$a = $expr;");
2751
-	}
2748
+    $a = 0;
2749
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2750
+        eval("\$a = $expr;");
2751
+    }
2752 2752
 
2753
-	return intval($a);
2753
+    return intval($a);
2754 2754
 }
2755 2755
 
2756 2756
 /**
@@ -2769,7 +2769,7 @@  discard block
 block discarded – undo
2769 2769
  *      Retourne `$a*$b/$c`
2770 2770
  **/
2771 2771
 function regledetrois($a, $b, $c) {
2772
-	return round($a * $b / $c);
2772
+    return round($a * $b / $c);
2773 2773
 }
2774 2774
 
2775 2775
 
@@ -2792,79 +2792,79 @@  discard block
 block discarded – undo
2792 2792
  * @return string Suite de champs input hidden
2793 2793
  **/
2794 2794
 function form_hidden(?string $action = ''): string {
2795
-	$action ??= '';
2796
-
2797
-	$contexte = [];
2798
-	include_spip('inc/urls');
2799
-	if (
2800
-		$p = urls_decoder_url($action, '')
2801
-		and reset($p)
2802
-	) {
2803
-		$fond = array_shift($p);
2804
-		if ($fond != '404') {
2805
-			$contexte = array_shift($p);
2806
-			$contexte['page'] = $fond;
2807
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2808
-		}
2809
-	}
2810
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2811
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2812
-		unset($contexte['type']);
2813
-	}
2814
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2815
-		unset($contexte['type-page']);
2816
-	}
2817
-
2818
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2819
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2820
-	$values = [];
2821
-
2822
-	// d'abord avec celles de l'url
2823
-	if (false !== ($p = strpos($action, '?'))) {
2824
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2825
-			$c = explode('=', $c, 2);
2826
-			$var = array_shift($c);
2827
-			$val = array_shift($c) ?? '';
2828
-			if ($var) {
2829
-				$val = rawurldecode($val);
2830
-				$var = rawurldecode($var); // decoder les [] eventuels
2831
-				if (preg_match(',\[\]$,S', $var)) {
2832
-					$values[] = [$var, $val];
2833
-				} else {
2834
-					if (!isset($values[$var])) {
2835
-						$values[$var] = [$var, $val];
2836
-					}
2837
-				}
2838
-			}
2839
-		}
2840
-	}
2841
-
2842
-	// ensuite avec celles du contexte, sans doublonner !
2843
-	foreach ($contexte as $var => $val) {
2844
-		if (preg_match(',\[\]$,S', $var)) {
2845
-			$values[] = [$var, $val];
2846
-		} else {
2847
-			if (!isset($values[$var])) {
2848
-				$values[$var] = [$var, $val];
2849
-			}
2850
-		}
2851
-	}
2852
-
2853
-	// puis on rassemble le tout
2854
-	$hidden = [];
2855
-	foreach ($values as $value) {
2856
-		[$var, $val] = $value;
2857
-		$hidden[] = '<input name="'
2858
-			. entites_html($var)
2859
-			. '"'
2860
-			. (is_null($val)
2861
-				? ''
2862
-				: ' value="' . entites_html($val) . '"'
2863
-			)
2864
-			. ' type="hidden"' . "\n/>";
2865
-	}
2866
-
2867
-	return join('', $hidden);
2795
+    $action ??= '';
2796
+
2797
+    $contexte = [];
2798
+    include_spip('inc/urls');
2799
+    if (
2800
+        $p = urls_decoder_url($action, '')
2801
+        and reset($p)
2802
+    ) {
2803
+        $fond = array_shift($p);
2804
+        if ($fond != '404') {
2805
+            $contexte = array_shift($p);
2806
+            $contexte['page'] = $fond;
2807
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2808
+        }
2809
+    }
2810
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2811
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2812
+        unset($contexte['type']);
2813
+    }
2814
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2815
+        unset($contexte['type-page']);
2816
+    }
2817
+
2818
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2819
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2820
+    $values = [];
2821
+
2822
+    // d'abord avec celles de l'url
2823
+    if (false !== ($p = strpos($action, '?'))) {
2824
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2825
+            $c = explode('=', $c, 2);
2826
+            $var = array_shift($c);
2827
+            $val = array_shift($c) ?? '';
2828
+            if ($var) {
2829
+                $val = rawurldecode($val);
2830
+                $var = rawurldecode($var); // decoder les [] eventuels
2831
+                if (preg_match(',\[\]$,S', $var)) {
2832
+                    $values[] = [$var, $val];
2833
+                } else {
2834
+                    if (!isset($values[$var])) {
2835
+                        $values[$var] = [$var, $val];
2836
+                    }
2837
+                }
2838
+            }
2839
+        }
2840
+    }
2841
+
2842
+    // ensuite avec celles du contexte, sans doublonner !
2843
+    foreach ($contexte as $var => $val) {
2844
+        if (preg_match(',\[\]$,S', $var)) {
2845
+            $values[] = [$var, $val];
2846
+        } else {
2847
+            if (!isset($values[$var])) {
2848
+                $values[$var] = [$var, $val];
2849
+            }
2850
+        }
2851
+    }
2852
+
2853
+    // puis on rassemble le tout
2854
+    $hidden = [];
2855
+    foreach ($values as $value) {
2856
+        [$var, $val] = $value;
2857
+        $hidden[] = '<input name="'
2858
+            . entites_html($var)
2859
+            . '"'
2860
+            . (is_null($val)
2861
+                ? ''
2862
+                : ' value="' . entites_html($val) . '"'
2863
+            )
2864
+            . ' type="hidden"' . "\n/>";
2865
+    }
2866
+
2867
+    return join('', $hidden);
2868 2868
 }
2869 2869
 
2870 2870
 
@@ -2886,7 +2886,7 @@  discard block
 block discarded – undo
2886 2886
  *    - la première valeur du tableau sinon.
2887 2887
  **/
2888 2888
 function filtre_reset($array) {
2889
-	return !is_array($array) ? null : reset($array);
2889
+    return !is_array($array) ? null : reset($array);
2890 2890
 }
2891 2891
 
2892 2892
 /**
@@ -2907,7 +2907,7 @@  discard block
 block discarded – undo
2907 2907
  *    - la dernière valeur du tableau sinon.
2908 2908
  **/
2909 2909
 function filtre_end($array) {
2910
-	return !is_array($array) ? null : end($array);
2910
+    return !is_array($array) ? null : end($array);
2911 2911
 }
2912 2912
 
2913 2913
 /**
@@ -2927,11 +2927,11 @@  discard block
 block discarded – undo
2927 2927
  *
2928 2928
  **/
2929 2929
 function filtre_push($array, $val) {
2930
-	if (!is_array($array) or !array_push($array, $val)) {
2931
-		return '';
2932
-	}
2930
+    if (!is_array($array) or !array_push($array, $val)) {
2931
+        return '';
2932
+    }
2933 2933
 
2934
-	return $array;
2934
+    return $array;
2935 2935
 }
2936 2936
 
2937 2937
 /**
@@ -2950,7 +2950,7 @@  discard block
 block discarded – undo
2950 2950
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2951 2951
  **/
2952 2952
 function filtre_find($array, $val) {
2953
-	return (is_array($array) and in_array($val, $array));
2953
+    return (is_array($array) and in_array($val, $array));
2954 2954
 }
2955 2955
 
2956 2956
 
@@ -2967,13 +2967,13 @@  discard block
 block discarded – undo
2967 2967
  *     Contenu avec urls en absolus
2968 2968
  **/
2969 2969
 function urls_absolues_css($contenu, $source) {
2970
-	$path = suivre_lien(url_absolue($source), './');
2970
+    $path = suivre_lien(url_absolue($source), './');
2971 2971
 
2972
-	return preg_replace_callback(
2973
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2974
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2975
-		$contenu
2976
-	);
2972
+    return preg_replace_callback(
2973
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2974
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2975
+        $contenu
2976
+    );
2977 2977
 }
2978 2978
 
2979 2979
 
@@ -3002,119 +3002,119 @@  discard block
 block discarded – undo
3002 3002
  *     Chemin du fichier CSS inversé
3003 3003
  **/
3004 3004
 function direction_css($css, $voulue = '') {
3005
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3006
-		return $css;
3007
-	}
3008
-	include_spip('inc/lang');
3009
-	// si on a precise le sens voulu en argument, le prendre en compte
3010
-	if ($voulue = strtolower($voulue)) {
3011
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
3012
-			$voulue = lang_dir($voulue);
3013
-		}
3014
-	} else {
3015
-		$voulue = lang_dir();
3016
-	}
3017
-
3018
-	$r = count($r) > 1;
3019
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3020
-	$dir = $r ? 'rtl' : 'ltr';
3021
-	$ndir = $r ? 'ltr' : 'rtl';
3022
-
3023
-	if ($voulue == $dir) {
3024
-		return $css;
3025
-	}
3026
-
3027
-	if (
3028
-		// url absolue
3029
-		preg_match(',^https?:,i', $css)
3030
-		// ou qui contient un ?
3031
-		or (($p = strpos($css, '?')) !== false)
3032
-	) {
3033
-		$distant = true;
3034
-		$cssf = parse_url($css);
3035
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3036
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
3037
-	} else {
3038
-		$distant = false;
3039
-		$cssf = $css;
3040
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3041
-		//propose (rien a faire dans ce cas)
3042
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3043
-		if (@file_exists($f)) {
3044
-			return $f;
3045
-		}
3046
-	}
3047
-
3048
-	// 2.
3049
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3050
-	$f = $dir_var
3051
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3052
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3053
-
3054
-	// la css peut etre distante (url absolue !)
3055
-	if ($distant) {
3056
-		include_spip('inc/distant');
3057
-		$res = recuperer_url($css);
3058
-		if (!$res or !$contenu = $res['page']) {
3059
-			return $css;
3060
-		}
3061
-	} else {
3062
-		if (
3063
-			(@filemtime($f) > @filemtime($css))
3064
-			and (_VAR_MODE != 'recalcul')
3065
-		) {
3066
-			return $f;
3067
-		}
3068
-		if (!lire_fichier($css, $contenu)) {
3069
-			return $css;
3070
-		}
3071
-	}
3072
-
3073
-
3074
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3075
-	include_spip('lib/csstidy/class.csstidy');
3076
-	$parser = new csstidy();
3077
-	$parser->set_cfg('optimise_shorthands', 0);
3078
-	$parser->set_cfg('reverse_left_and_right', true);
3079
-	$parser->parse($contenu);
3080
-
3081
-	$contenu = $parser->print->plain();
3082
-
3083
-
3084
-	// reperer les @import auxquels il faut propager le direction_css
3085
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3086
-	$src = [];
3087
-	$src_direction_css = [];
3088
-	$src_faux_abs = [];
3089
-	$d = dirname($css);
3090
-	foreach ($regs[1] as $k => $import_css) {
3091
-		$css_direction = direction_css("$d/$import_css", $voulue);
3092
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3093
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3094
-			$css_direction = substr($css_direction, strlen($d) + 1);
3095
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3096
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3097
-			$css_direction = substr($css_direction, strlen($dir_var));
3098
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3099
-			$css_direction = '/@@@@@@/' . $css_direction;
3100
-		}
3101
-		$src[] = $regs[0][$k];
3102
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3103
-	}
3104
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3105
-
3106
-	$contenu = urls_absolues_css($contenu, $css);
3107
-
3108
-	// virer les fausses url absolues que l'on a mis dans les import
3109
-	if (count($src_faux_abs)) {
3110
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3111
-	}
3112
-
3113
-	if (!ecrire_fichier($f, $contenu)) {
3114
-		return $css;
3115
-	}
3116
-
3117
-	return $f;
3005
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3006
+        return $css;
3007
+    }
3008
+    include_spip('inc/lang');
3009
+    // si on a precise le sens voulu en argument, le prendre en compte
3010
+    if ($voulue = strtolower($voulue)) {
3011
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
3012
+            $voulue = lang_dir($voulue);
3013
+        }
3014
+    } else {
3015
+        $voulue = lang_dir();
3016
+    }
3017
+
3018
+    $r = count($r) > 1;
3019
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3020
+    $dir = $r ? 'rtl' : 'ltr';
3021
+    $ndir = $r ? 'ltr' : 'rtl';
3022
+
3023
+    if ($voulue == $dir) {
3024
+        return $css;
3025
+    }
3026
+
3027
+    if (
3028
+        // url absolue
3029
+        preg_match(',^https?:,i', $css)
3030
+        // ou qui contient un ?
3031
+        or (($p = strpos($css, '?')) !== false)
3032
+    ) {
3033
+        $distant = true;
3034
+        $cssf = parse_url($css);
3035
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3036
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
3037
+    } else {
3038
+        $distant = false;
3039
+        $cssf = $css;
3040
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3041
+        //propose (rien a faire dans ce cas)
3042
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3043
+        if (@file_exists($f)) {
3044
+            return $f;
3045
+        }
3046
+    }
3047
+
3048
+    // 2.
3049
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3050
+    $f = $dir_var
3051
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3052
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3053
+
3054
+    // la css peut etre distante (url absolue !)
3055
+    if ($distant) {
3056
+        include_spip('inc/distant');
3057
+        $res = recuperer_url($css);
3058
+        if (!$res or !$contenu = $res['page']) {
3059
+            return $css;
3060
+        }
3061
+    } else {
3062
+        if (
3063
+            (@filemtime($f) > @filemtime($css))
3064
+            and (_VAR_MODE != 'recalcul')
3065
+        ) {
3066
+            return $f;
3067
+        }
3068
+        if (!lire_fichier($css, $contenu)) {
3069
+            return $css;
3070
+        }
3071
+    }
3072
+
3073
+
3074
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3075
+    include_spip('lib/csstidy/class.csstidy');
3076
+    $parser = new csstidy();
3077
+    $parser->set_cfg('optimise_shorthands', 0);
3078
+    $parser->set_cfg('reverse_left_and_right', true);
3079
+    $parser->parse($contenu);
3080
+
3081
+    $contenu = $parser->print->plain();
3082
+
3083
+
3084
+    // reperer les @import auxquels il faut propager le direction_css
3085
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3086
+    $src = [];
3087
+    $src_direction_css = [];
3088
+    $src_faux_abs = [];
3089
+    $d = dirname($css);
3090
+    foreach ($regs[1] as $k => $import_css) {
3091
+        $css_direction = direction_css("$d/$import_css", $voulue);
3092
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3093
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3094
+            $css_direction = substr($css_direction, strlen($d) + 1);
3095
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3096
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3097
+            $css_direction = substr($css_direction, strlen($dir_var));
3098
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3099
+            $css_direction = '/@@@@@@/' . $css_direction;
3100
+        }
3101
+        $src[] = $regs[0][$k];
3102
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3103
+    }
3104
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3105
+
3106
+    $contenu = urls_absolues_css($contenu, $css);
3107
+
3108
+    // virer les fausses url absolues que l'on a mis dans les import
3109
+    if (count($src_faux_abs)) {
3110
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3111
+    }
3112
+
3113
+    if (!ecrire_fichier($f, $contenu)) {
3114
+        return $css;
3115
+    }
3116
+
3117
+    return $f;
3118 3118
 }
3119 3119
 
3120 3120
 
@@ -3137,46 +3137,46 @@  discard block
 block discarded – undo
3137 3137
  *     - Chemin ou URL du fichier CSS source sinon.
3138 3138
  **/
3139 3139
 function url_absolue_css($css) {
3140
-	if (!preg_match(',\.css$,i', $css, $r)) {
3141
-		return $css;
3142
-	}
3140
+    if (!preg_match(',\.css$,i', $css, $r)) {
3141
+        return $css;
3142
+    }
3143 3143
 
3144
-	$url_absolue_css = url_absolue($css);
3144
+    $url_absolue_css = url_absolue($css);
3145 3145
 
3146
-	$f = basename($css, '.css');
3147
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3148
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3149
-		. '.css';
3146
+    $f = basename($css, '.css');
3147
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3148
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3149
+        . '.css';
3150 3150
 
3151
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3152
-		return $f;
3153
-	}
3151
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3152
+        return $f;
3153
+    }
3154 3154
 
3155
-	if ($url_absolue_css == $css) {
3156
-		if (
3157
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3158
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3159
-		) {
3160
-			include_spip('inc/distant');
3161
-			$contenu = recuperer_url($css);
3162
-			$contenu = $contenu['page'] ?? '';
3163
-			if (!$contenu) {
3164
-				return $css;
3165
-			}
3166
-		}
3167
-	} elseif (!lire_fichier($css, $contenu)) {
3168
-		return $css;
3169
-	}
3155
+    if ($url_absolue_css == $css) {
3156
+        if (
3157
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3158
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3159
+        ) {
3160
+            include_spip('inc/distant');
3161
+            $contenu = recuperer_url($css);
3162
+            $contenu = $contenu['page'] ?? '';
3163
+            if (!$contenu) {
3164
+                return $css;
3165
+            }
3166
+        }
3167
+    } elseif (!lire_fichier($css, $contenu)) {
3168
+        return $css;
3169
+    }
3170 3170
 
3171
-	// passer les url relatives a la css d'origine en url absolues
3172
-	$contenu = urls_absolues_css($contenu, $css);
3171
+    // passer les url relatives a la css d'origine en url absolues
3172
+    $contenu = urls_absolues_css($contenu, $css);
3173 3173
 
3174
-	// ecrire la css
3175
-	if (!ecrire_fichier($f, $contenu)) {
3176
-		return $css;
3177
-	}
3174
+    // ecrire la css
3175
+    if (!ecrire_fichier($f, $contenu)) {
3176
+        return $css;
3177
+    }
3178 3178
 
3179
-	return $f;
3179
+    return $f;
3180 3180
 }
3181 3181
 
3182 3182
 
@@ -3210,24 +3210,24 @@  discard block
 block discarded – undo
3210 3210
  *     Valeur trouvée ou valeur par défaut.
3211 3211
  **/
3212 3212
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3213
-	foreach (explode('/', $cle) as $k) {
3214
-		$table = (is_string($table) ? @unserialize($table) : $table);
3213
+    foreach (explode('/', $cle) as $k) {
3214
+        $table = (is_string($table) ? @unserialize($table) : $table);
3215 3215
 
3216
-		if (is_object($table)) {
3217
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3218
-		} elseif (is_array($table)) {
3219
-			if ($conserver_null) {
3220
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3221
-			} else {
3222
-				$table = ($table[$k] ?? $defaut);
3223
-			}
3224
-		} else {
3225
-			$table = $defaut;
3226
-			break;
3227
-		}
3228
-	}
3216
+        if (is_object($table)) {
3217
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3218
+        } elseif (is_array($table)) {
3219
+            if ($conserver_null) {
3220
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3221
+            } else {
3222
+                $table = ($table[$k] ?? $defaut);
3223
+            }
3224
+        } else {
3225
+            $table = $defaut;
3226
+            break;
3227
+        }
3228
+    }
3229 3229
 
3230
-	return $table;
3230
+    return $table;
3231 3231
 }
3232 3232
 
3233 3233
 /**
@@ -3260,22 +3260,22 @@  discard block
 block discarded – undo
3260 3260
  *     - string : expression trouvée.
3261 3261
  **/
3262 3262
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3263
-	if (intval($modif) and $capte == 0) {
3264
-		$capte = $modif;
3265
-		$modif = 'UimsS';
3266
-	}
3267
-	$expression = str_replace('\/', '/', $expression);
3268
-	$expression = str_replace('/', '\/', $expression);
3263
+    if (intval($modif) and $capte == 0) {
3264
+        $capte = $modif;
3265
+        $modif = 'UimsS';
3266
+    }
3267
+    $expression = str_replace('\/', '/', $expression);
3268
+    $expression = str_replace('/', '\/', $expression);
3269 3269
 
3270
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3271
-		if (isset($r[$capte])) {
3272
-			return $r[$capte];
3273
-		} else {
3274
-			return true;
3275
-		}
3276
-	}
3270
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3271
+        if (isset($r[$capte])) {
3272
+            return $r[$capte];
3273
+        } else {
3274
+            return true;
3275
+        }
3276
+    }
3277 3277
 
3278
-	return false;
3278
+    return false;
3279 3279
 }
3280 3280
 
3281 3281
 
@@ -3302,10 +3302,10 @@  discard block
 block discarded – undo
3302 3302
  *     Texte
3303 3303
  **/
3304 3304
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3305
-	$expression = str_replace('\/', '/', $expression);
3306
-	$expression = str_replace('/', '\/', $expression);
3305
+    $expression = str_replace('\/', '/', $expression);
3306
+    $expression = str_replace('/', '\/', $expression);
3307 3307
 
3308
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3308
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3309 3309
 }
3310 3310
 
3311 3311
 
@@ -3323,25 +3323,25 @@  discard block
 block discarded – undo
3323 3323
  **/
3324 3324
 function traiter_doublons_documents(&$doublons, $letexte) {
3325 3325
 
3326
-	// Verifier dans le texte & les notes (pas beau, helas)
3327
-	$t = $letexte . $GLOBALS['les_notes'];
3326
+    // Verifier dans le texte & les notes (pas beau, helas)
3327
+    $t = $letexte . $GLOBALS['les_notes'];
3328 3328
 
3329
-	if (
3330
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3331
-		and preg_match_all(
3332
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3333
-			$t,
3334
-			$matches,
3335
-			PREG_PATTERN_ORDER
3336
-		)
3337
-	) {
3338
-		if (!isset($doublons['documents'])) {
3339
-			$doublons['documents'] = '';
3340
-		}
3341
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3342
-	}
3329
+    if (
3330
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3331
+        and preg_match_all(
3332
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3333
+            $t,
3334
+            $matches,
3335
+            PREG_PATTERN_ORDER
3336
+        )
3337
+    ) {
3338
+        if (!isset($doublons['documents'])) {
3339
+            $doublons['documents'] = '';
3340
+        }
3341
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3342
+    }
3343 3343
 
3344
-	return $letexte;
3344
+    return $letexte;
3345 3345
 }
3346 3346
 
3347 3347
 /**
@@ -3355,7 +3355,7 @@  discard block
 block discarded – undo
3355 3355
  * @return string Chaîne vide
3356 3356
  **/
3357 3357
 function vide($texte) {
3358
-	return '';
3358
+    return '';
3359 3359
 }
3360 3360
 
3361 3361
 //
@@ -3384,23 +3384,23 @@  discard block
 block discarded – undo
3384 3384
  *      Code HTML résultant
3385 3385
  **/
3386 3386
 function env_to_params($env, $ignore_params = []) {
3387
-	$ignore_params = array_merge(
3388
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3389
-		$ignore_params
3390
-	);
3391
-	if (!is_array($env)) {
3392
-		$env = unserialize($env);
3393
-	}
3394
-	$texte = '';
3395
-	if ($env) {
3396
-		foreach ($env as $i => $j) {
3397
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3398
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3399
-			}
3400
-		}
3401
-	}
3402
-
3403
-	return $texte;
3387
+    $ignore_params = array_merge(
3388
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3389
+        $ignore_params
3390
+    );
3391
+    if (!is_array($env)) {
3392
+        $env = unserialize($env);
3393
+    }
3394
+    $texte = '';
3395
+    if ($env) {
3396
+        foreach ($env as $i => $j) {
3397
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3398
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3399
+            }
3400
+        }
3401
+    }
3402
+
3403
+    return $texte;
3404 3404
 }
3405 3405
 
3406 3406
 /**
@@ -3423,23 +3423,23 @@  discard block
 block discarded – undo
3423 3423
  *      Code HTML résultant
3424 3424
  **/
3425 3425
 function env_to_attributs($env, $ignore_params = []) {
3426
-	$ignore_params = array_merge(
3427
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3428
-		$ignore_params
3429
-	);
3430
-	if (!is_array($env)) {
3431
-		$env = unserialize($env);
3432
-	}
3433
-	$texte = '';
3434
-	if ($env) {
3435
-		foreach ($env as $i => $j) {
3436
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3437
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3438
-			}
3439
-		}
3440
-	}
3426
+    $ignore_params = array_merge(
3427
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3428
+        $ignore_params
3429
+    );
3430
+    if (!is_array($env)) {
3431
+        $env = unserialize($env);
3432
+    }
3433
+    $texte = '';
3434
+    if ($env) {
3435
+        foreach ($env as $i => $j) {
3436
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3437
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3438
+            }
3439
+        }
3440
+    }
3441 3441
 
3442
-	return $texte;
3442
+    return $texte;
3443 3443
 }
3444 3444
 
3445 3445
 
@@ -3457,7 +3457,7 @@  discard block
 block discarded – undo
3457 3457
  * @return string Chaînes concaténés
3458 3458
  **/
3459 3459
 function concat(...$args): string {
3460
-	return join('', $args);
3460
+    return join('', $args);
3461 3461
 }
3462 3462
 
3463 3463
 
@@ -3477,23 +3477,23 @@  discard block
 block discarded – undo
3477 3477
  *     Contenu du ou des fichiers, concaténé
3478 3478
  **/
3479 3479
 function charge_scripts($files, $script = true) {
3480
-	$flux = '';
3481
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3482
-		if (!is_string($file)) {
3483
-			continue;
3484
-		}
3485
-		if ($script) {
3486
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3487
-		}
3488
-		if ($file) {
3489
-			$path = find_in_path($file);
3490
-			if ($path) {
3491
-				$flux .= spip_file_get_contents($path);
3492
-			}
3493
-		}
3494
-	}
3495
-
3496
-	return $flux;
3480
+    $flux = '';
3481
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3482
+        if (!is_string($file)) {
3483
+            continue;
3484
+        }
3485
+        if ($script) {
3486
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3487
+        }
3488
+        if ($file) {
3489
+            $path = find_in_path($file);
3490
+            if ($path) {
3491
+                $flux .= spip_file_get_contents($path);
3492
+            }
3493
+        }
3494
+    }
3495
+
3496
+    return $flux;
3497 3497
 }
3498 3498
 
3499 3499
 /**
@@ -3504,22 +3504,22 @@  discard block
 block discarded – undo
3504 3504
  * @return string
3505 3505
  */
3506 3506
 function http_img_variante_svg_si_possible($img_file) {
3507
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3508
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3509
-	if (
3510
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3511
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3512
-		and file_exists($variante_svg_generique)
3513
-	) {
3514
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3515
-			$img_file = $variante_svg_size;
3516
-		}
3517
-		else {
3518
-			$img_file = $variante_svg_generique;
3519
-		}
3520
-	}
3507
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3508
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3509
+    if (
3510
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3511
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3512
+        and file_exists($variante_svg_generique)
3513
+    ) {
3514
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3515
+            $img_file = $variante_svg_size;
3516
+        }
3517
+        else {
3518
+            $img_file = $variante_svg_generique;
3519
+        }
3520
+    }
3521 3521
 
3522
-	return $img_file;
3522
+    return $img_file;
3523 3523
 }
3524 3524
 
3525 3525
 /**
@@ -3540,54 +3540,54 @@  discard block
 block discarded – undo
3540 3540
  */
3541 3541
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3542 3542
 
3543
-	$img_file = $img;
3544
-	if ($p = strpos($img_file, '?')) {
3545
-		$img_file = substr($img_file, 0, $p);
3546
-	}
3547
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3548
-		$img_file = chemin_image($img);
3549
-	}
3550
-	else {
3551
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3552
-			$img_file = http_img_variante_svg_si_possible($img_file);
3553
-		}
3554
-	}
3555
-	if (stripos($atts, 'width') === false) {
3556
-		// utiliser directement l'info de taille presente dans le nom
3557
-		if (
3558
-			(!isset($options['utiliser_suffixe_size'])
3559
-				or $options['utiliser_suffixe_size'] == true
3560
-			  or strpos($img_file, '-xx.svg') !== false)
3561
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3562
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3563
-		) {
3564
-			$largeur = $hauteur = intval($regs[1]);
3565
-		} else {
3566
-			$taille = taille_image($img_file);
3567
-			[$hauteur, $largeur] = $taille;
3568
-			if (!$hauteur or !$largeur) {
3569
-				return '';
3570
-			}
3571
-		}
3572
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3573
-	}
3574
-
3575
-	if (file_exists($img_file)) {
3576
-		$img_file = timestamp($img_file);
3577
-	}
3578
-	if ($alt === false) {
3579
-		$alt = '';
3580
-	}
3581
-	elseif ($alt or $alt === '') {
3582
-		$alt = " alt='" . attribut_html($alt) . "'";
3583
-	}
3584
-	else {
3585
-		$alt = " alt='" . attribut_html($title) . "'";
3586
-	}
3587
-	return "<img src='$img_file'$alt"
3588
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3589
-	. ' ' . ltrim($atts)
3590
-	. ' />';
3543
+    $img_file = $img;
3544
+    if ($p = strpos($img_file, '?')) {
3545
+        $img_file = substr($img_file, 0, $p);
3546
+    }
3547
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3548
+        $img_file = chemin_image($img);
3549
+    }
3550
+    else {
3551
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3552
+            $img_file = http_img_variante_svg_si_possible($img_file);
3553
+        }
3554
+    }
3555
+    if (stripos($atts, 'width') === false) {
3556
+        // utiliser directement l'info de taille presente dans le nom
3557
+        if (
3558
+            (!isset($options['utiliser_suffixe_size'])
3559
+                or $options['utiliser_suffixe_size'] == true
3560
+              or strpos($img_file, '-xx.svg') !== false)
3561
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3562
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3563
+        ) {
3564
+            $largeur = $hauteur = intval($regs[1]);
3565
+        } else {
3566
+            $taille = taille_image($img_file);
3567
+            [$hauteur, $largeur] = $taille;
3568
+            if (!$hauteur or !$largeur) {
3569
+                return '';
3570
+            }
3571
+        }
3572
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3573
+    }
3574
+
3575
+    if (file_exists($img_file)) {
3576
+        $img_file = timestamp($img_file);
3577
+    }
3578
+    if ($alt === false) {
3579
+        $alt = '';
3580
+    }
3581
+    elseif ($alt or $alt === '') {
3582
+        $alt = " alt='" . attribut_html($alt) . "'";
3583
+    }
3584
+    else {
3585
+        $alt = " alt='" . attribut_html($title) . "'";
3586
+    }
3587
+    return "<img src='$img_file'$alt"
3588
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3589
+    . ' ' . ltrim($atts)
3590
+    . ' />';
3591 3591
 }
3592 3592
 
3593 3593
 /**
@@ -3599,70 +3599,70 @@  discard block
 block discarded – undo
3599 3599
  * @return string
3600 3600
  */
3601 3601
 function http_style_background($img, $att = '', $size = null) {
3602
-	if ($size and is_numeric($size)) {
3603
-		$size = trim($size) . 'px';
3604
-	}
3605
-	return " style='background" .
3606
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3607
-		. ($size ? "background-size:{$size};" : '')
3608
-		. "'";
3602
+    if ($size and is_numeric($size)) {
3603
+        $size = trim($size) . 'px';
3604
+    }
3605
+    return " style='background" .
3606
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3607
+        . ($size ? "background-size:{$size};" : '')
3608
+        . "'";
3609 3609
 }
3610 3610
 
3611 3611
 
3612 3612
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3613
-	$args = [$alt_or_size, $class_or_size, $size];
3614
-	while (is_null(end($args)) and count($args)) {
3615
-		array_pop($args);
3616
-	}
3617
-	if (!count($args)) {
3618
-		return [null, null, null];
3619
-	}
3620
-	if (count($args) < 3) {
3621
-		$maybe_size = array_pop($args);
3622
-		// @2x
3623
-		// @1.5x
3624
-		// 512
3625
-		// 512x*
3626
-		// 512x300
3627
-		if (
3628
-			!strlen($maybe_size)
3629
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3630
-		) {
3631
-			$args[] = $maybe_size;
3632
-			$maybe_size = null;
3633
-		}
3634
-		while (count($args) < 2) {
3635
-			$args[] = null; // default alt or class
3636
-		}
3637
-		$args[] = $maybe_size;
3638
-	}
3639
-	return $args;
3613
+    $args = [$alt_or_size, $class_or_size, $size];
3614
+    while (is_null(end($args)) and count($args)) {
3615
+        array_pop($args);
3616
+    }
3617
+    if (!count($args)) {
3618
+        return [null, null, null];
3619
+    }
3620
+    if (count($args) < 3) {
3621
+        $maybe_size = array_pop($args);
3622
+        // @2x
3623
+        // @1.5x
3624
+        // 512
3625
+        // 512x*
3626
+        // 512x300
3627
+        if (
3628
+            !strlen($maybe_size)
3629
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3630
+        ) {
3631
+            $args[] = $maybe_size;
3632
+            $maybe_size = null;
3633
+        }
3634
+        while (count($args) < 2) {
3635
+            $args[] = null; // default alt or class
3636
+        }
3637
+        $args[] = $maybe_size;
3638
+    }
3639
+    return $args;
3640 3640
 }
3641 3641
 
3642 3642
 function helper_filtre_balise_img_svg_size($img, $size) {
3643
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3644
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3645
-		$coef = floatval(substr($size, 1, -1));
3646
-		[$h, $w] = taille_image($img);
3647
-		$height = intval(round($h / $coef));
3648
-		$width = intval(round($w / $coef));
3649
-	}
3650
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3651
-	else {
3652
-		$size = explode('x', $size, 2);
3653
-		$size = array_map('trim', $size);
3654
-		$height = $width = intval(array_shift($size));
3655
-
3656
-		if (count($size) and reset($size)) {
3657
-			$height = array_shift($size);
3658
-			if ($height === '*') {
3659
-				[$h, $w] = taille_image($img);
3660
-				$height = intval(round($h * $width / $w));
3661
-			}
3662
-		}
3663
-	}
3664
-
3665
-	return [$width, $height];
3643
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3644
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3645
+        $coef = floatval(substr($size, 1, -1));
3646
+        [$h, $w] = taille_image($img);
3647
+        $height = intval(round($h / $coef));
3648
+        $width = intval(round($w / $coef));
3649
+    }
3650
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3651
+    else {
3652
+        $size = explode('x', $size, 2);
3653
+        $size = array_map('trim', $size);
3654
+        $height = $width = intval(array_shift($size));
3655
+
3656
+        if (count($size) and reset($size)) {
3657
+            $height = array_shift($size);
3658
+            if ($height === '*') {
3659
+                [$h, $w] = taille_image($img);
3660
+                $height = intval(round($h * $width / $w));
3661
+            }
3662
+        }
3663
+    }
3664
+
3665
+    return [$width, $height];
3666 3666
 }
3667 3667
 
3668 3668
 /**
@@ -3698,43 +3698,43 @@  discard block
 block discarded – undo
3698 3698
  */
3699 3699
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3700 3700
 
3701
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3702
-
3703
-	$img = trim((string) $img);
3704
-	if (strpos($img, '<img') === 0) {
3705
-		if (!is_null($alt)) {
3706
-			$img = inserer_attribut($img, 'alt', $alt);
3707
-		}
3708
-		if (!is_null($class)) {
3709
-			if (strlen($class)) {
3710
-				$img = inserer_attribut($img, 'class', $class);
3711
-			}
3712
-			else {
3713
-				$img = vider_attribut($img, 'class');
3714
-			}
3715
-		}
3716
-	}
3717
-	else {
3718
-		$img = http_img_pack(
3719
-			$img,
3720
-			$alt,
3721
-			$class ? " class='" . attribut_html($class) . "'" : '',
3722
-			'',
3723
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3724
-		);
3725
-		if (is_null($alt)) {
3726
-			$img = vider_attribut($img, 'alt');
3727
-		}
3728
-	}
3729
-
3730
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3731
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3732
-
3733
-		$img = inserer_attribut($img, 'width', $width);
3734
-		$img = inserer_attribut($img, 'height', $height);
3735
-	}
3736
-
3737
-	return $img;
3701
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3702
+
3703
+    $img = trim((string) $img);
3704
+    if (strpos($img, '<img') === 0) {
3705
+        if (!is_null($alt)) {
3706
+            $img = inserer_attribut($img, 'alt', $alt);
3707
+        }
3708
+        if (!is_null($class)) {
3709
+            if (strlen($class)) {
3710
+                $img = inserer_attribut($img, 'class', $class);
3711
+            }
3712
+            else {
3713
+                $img = vider_attribut($img, 'class');
3714
+            }
3715
+        }
3716
+    }
3717
+    else {
3718
+        $img = http_img_pack(
3719
+            $img,
3720
+            $alt,
3721
+            $class ? " class='" . attribut_html($class) . "'" : '',
3722
+            '',
3723
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3724
+        );
3725
+        if (is_null($alt)) {
3726
+            $img = vider_attribut($img, 'alt');
3727
+        }
3728
+    }
3729
+
3730
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3731
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3732
+
3733
+        $img = inserer_attribut($img, 'width', $width);
3734
+        $img = inserer_attribut($img, 'height', $height);
3735
+    }
3736
+
3737
+    return $img;
3738 3738
 }
3739 3739
 
3740 3740
 
@@ -3768,80 +3768,80 @@  discard block
 block discarded – undo
3768 3768
  */
3769 3769
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3770 3770
 
3771
-	$svg = null;
3772
-	$img = trim($img);
3773
-	$img_file = $img;
3774
-	if (strpos($img, '<svg') === false) {
3775
-		if ($p = strpos($img_file, '?')) {
3776
-			$img_file = substr($img_file, 0, $p);
3777
-		}
3778
-
3779
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3780
-		// la copie locale a toutes les chances d'etre la ou de resservir
3781
-		if (tester_url_absolue($img_file)) {
3782
-			include_spip('inc/distant');
3783
-			$fichier = copie_locale($img_file);
3784
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3785
-		}
3786
-
3787
-		if (
3788
-			!$img_file
3789
-			or !file_exists($img_file)
3790
-			or !$svg = file_get_contents($img_file)
3791
-		) {
3792
-			return '';
3793
-		}
3794
-	}
3795
-
3796
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3797
-		return '';
3798
-	}
3799
-
3800
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3801
-
3802
-	$balise_svg = $match[0];
3803
-	$balise_svg_source = $balise_svg;
3804
-
3805
-	// entete XML à supprimer
3806
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3807
-
3808
-	// IE est toujours mon ami
3809
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3810
-
3811
-	// regler la classe
3812
-	if (!is_null($class)) {
3813
-		if (strlen($class)) {
3814
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3815
-		}
3816
-		else {
3817
-			$balise_svg = vider_attribut($balise_svg, 'class');
3818
-		}
3819
-	}
3820
-
3821
-	// regler le alt
3822
-	if ($alt) {
3823
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3824
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3825
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3826
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3827
-		$balise_svg .= $title;
3828
-	}
3829
-	else {
3830
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3831
-	}
3832
-
3833
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3834
-
3835
-	if (!is_null($size) and strlen($size = trim($size))) {
3836
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3837
-
3838
-		if (!function_exists('svg_redimensionner')) {
3839
-			include_spip('inc/svg');
3840
-		}
3841
-		$svg = svg_redimensionner($svg, $width, $height);
3842
-	}
3843
-
3844
-	return $svg;
3771
+    $svg = null;
3772
+    $img = trim($img);
3773
+    $img_file = $img;
3774
+    if (strpos($img, '<svg') === false) {
3775
+        if ($p = strpos($img_file, '?')) {
3776
+            $img_file = substr($img_file, 0, $p);
3777
+        }
3778
+
3779
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3780
+        // la copie locale a toutes les chances d'etre la ou de resservir
3781
+        if (tester_url_absolue($img_file)) {
3782
+            include_spip('inc/distant');
3783
+            $fichier = copie_locale($img_file);
3784
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3785
+        }
3786
+
3787
+        if (
3788
+            !$img_file
3789
+            or !file_exists($img_file)
3790
+            or !$svg = file_get_contents($img_file)
3791
+        ) {
3792
+            return '';
3793
+        }
3794
+    }
3795
+
3796
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3797
+        return '';
3798
+    }
3799
+
3800
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3801
+
3802
+    $balise_svg = $match[0];
3803
+    $balise_svg_source = $balise_svg;
3804
+
3805
+    // entete XML à supprimer
3806
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3807
+
3808
+    // IE est toujours mon ami
3809
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3810
+
3811
+    // regler la classe
3812
+    if (!is_null($class)) {
3813
+        if (strlen($class)) {
3814
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3815
+        }
3816
+        else {
3817
+            $balise_svg = vider_attribut($balise_svg, 'class');
3818
+        }
3819
+    }
3820
+
3821
+    // regler le alt
3822
+    if ($alt) {
3823
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3824
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3825
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3826
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3827
+        $balise_svg .= $title;
3828
+    }
3829
+    else {
3830
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3831
+    }
3832
+
3833
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3834
+
3835
+    if (!is_null($size) and strlen($size = trim($size))) {
3836
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3837
+
3838
+        if (!function_exists('svg_redimensionner')) {
3839
+            include_spip('inc/svg');
3840
+        }
3841
+        $svg = svg_redimensionner($svg, $width, $height);
3842
+    }
3843
+
3844
+    return $svg;
3845 3845
 }
3846 3846
 
3847 3847
 
@@ -3867,18 +3867,18 @@  discard block
 block discarded – undo
3867 3867
  *     Code HTML résultant
3868 3868
  **/
3869 3869
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3870
-	$texte = '';
3871
-	if (is_array($tableau)) {
3872
-		foreach ($tableau as $k => $v) {
3873
-			$res = recuperer_fond(
3874
-				'modeles/' . $modele,
3875
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3876
-			);
3877
-			$texte .= $res;
3878
-		}
3879
-	}
3870
+    $texte = '';
3871
+    if (is_array($tableau)) {
3872
+        foreach ($tableau as $k => $v) {
3873
+            $res = recuperer_fond(
3874
+                'modeles/' . $modele,
3875
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3876
+            );
3877
+            $texte .= $res;
3878
+        }
3879
+    }
3880 3880
 
3881
-	return $texte;
3881
+    return $texte;
3882 3882
 }
3883 3883
 
3884 3884
 
@@ -3903,37 +3903,37 @@  discard block
 block discarded – undo
3903 3903
  *         - tout : retourne toutes les informations du plugin actif
3904 3904
  **/
3905 3905
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3906
-	include_spip('inc/plugin');
3907
-	$plugin = strtoupper($plugin);
3908
-	$plugins_actifs = liste_plugin_actifs();
3909
-
3910
-	if (!$plugin) {
3911
-		return serialize(array_keys($plugins_actifs));
3912
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3913
-		return '';
3914
-	} elseif (($type_info == 'est_actif') and !$reload) {
3915
-		return $plugins_actifs[$plugin] ? 1 : 0;
3916
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3917
-		return $plugins_actifs[$plugin][$type_info];
3918
-	} else {
3919
-		$get_infos = charger_fonction('get_infos', 'plugins');
3920
-		// On prend en compte les extensions
3921
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3922
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3923
-		} else {
3924
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3925
-		}
3926
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3927
-			return '';
3928
-		}
3929
-		if ($type_info == 'tout') {
3930
-			return $infos;
3931
-		} elseif ($type_info == 'est_actif') {
3932
-			return $infos ? 1 : 0;
3933
-		} else {
3934
-			return strval($infos[$type_info]);
3935
-		}
3936
-	}
3906
+    include_spip('inc/plugin');
3907
+    $plugin = strtoupper($plugin);
3908
+    $plugins_actifs = liste_plugin_actifs();
3909
+
3910
+    if (!$plugin) {
3911
+        return serialize(array_keys($plugins_actifs));
3912
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3913
+        return '';
3914
+    } elseif (($type_info == 'est_actif') and !$reload) {
3915
+        return $plugins_actifs[$plugin] ? 1 : 0;
3916
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3917
+        return $plugins_actifs[$plugin][$type_info];
3918
+    } else {
3919
+        $get_infos = charger_fonction('get_infos', 'plugins');
3920
+        // On prend en compte les extensions
3921
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3922
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3923
+        } else {
3924
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3925
+        }
3926
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3927
+            return '';
3928
+        }
3929
+        if ($type_info == 'tout') {
3930
+            return $infos;
3931
+        } elseif ($type_info == 'est_actif') {
3932
+            return $infos ? 1 : 0;
3933
+        } else {
3934
+            return strval($infos[$type_info]);
3935
+        }
3936
+    }
3937 3937
 }
3938 3938
 
3939 3939
 
@@ -3960,9 +3960,9 @@  discard block
 block discarded – undo
3960 3960
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3961 3961
  */
3962 3962
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3963
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3963
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3964 3964
 
3965
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3965
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3966 3966
 }
3967 3967
 
3968 3968
 
@@ -3992,19 +3992,19 @@  discard block
 block discarded – undo
3992 3992
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3993 3993
  */
3994 3994
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3995
-	static $puce_statut = null;
3996
-	if (!$puce_statut) {
3997
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3998
-	}
3995
+    static $puce_statut = null;
3996
+    if (!$puce_statut) {
3997
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3998
+    }
3999 3999
 
4000
-	return $puce_statut(
4001
-		$id_objet,
4002
-		$statut,
4003
-		$id_parent,
4004
-		$objet,
4005
-		false,
4006
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4007
-	);
4000
+    return $puce_statut(
4001
+        $id_objet,
4002
+        $statut,
4003
+        $id_parent,
4004
+        $objet,
4005
+        false,
4006
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4007
+    );
4008 4008
 }
4009 4009
 
4010 4010
 
@@ -4031,98 +4031,98 @@  discard block
 block discarded – undo
4031 4031
  *   hash du contexte
4032 4032
  */
4033 4033
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
4034
-	$env = null;
4035
-	if (
4036
-		is_string($c)
4037
-		and @unserialize($c) !== false
4038
-	) {
4039
-		$c = unserialize($c);
4040
-	}
4041
-
4042
-	// supprimer les parametres debut_x
4043
-	// pour que la pagination ajax ne soit pas plantee
4044
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4045
-	// le debut_x=0 n'existe pas, et on resterait sur 1
4046
-	if (is_array($c)) {
4047
-		foreach ($c as $k => $v) {
4048
-			if (strpos($k, 'debut_') === 0) {
4049
-				unset($c[$k]);
4050
-			}
4051
-		}
4052
-	}
4053
-
4054
-	if (!function_exists('calculer_cle_action')) {
4055
-		include_spip('inc/securiser_action');
4056
-	}
4057
-
4058
-	$c = serialize($c);
4059
-	$cle = calculer_cle_action($form . $c);
4060
-	$c = "$cle:$c";
4061
-
4062
-	// on ne stocke pas les contextes dans des fichiers en cache
4063
-	// par defaut, sauf si cette configuration a été forcée
4064
-	// OU que la longueur de l’argument géneré est plus long
4065
-	// que ce qui est toléré.
4066
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4067
-	if (!$cache_contextes_ajax) {
4068
-		$env = $c;
4069
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4070
-			$env = gzdeflate($env);
4071
-		}
4072
-		$env = _xor($env);
4073
-		$env = base64_encode($env);
4074
-		$len = strlen($env);
4075
-		// Si l’url est trop longue pour le navigateur
4076
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4077
-		if ($len > $max_len) {
4078
-			$cache_contextes_ajax = true;
4079
-			spip_log(
4080
-				'Contextes AJAX forces en fichiers !'
4081
-				. ' Cela arrive lorsque la valeur du contexte'
4082
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4083
-				_LOG_AVERTISSEMENT
4084
-			);
4085
-		}
4086
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4087
-		elseif (
4088
-			$max_len = @ini_get('suhosin.get.max_value_length')
4089
-			and $max_len < $len
4090
-		) {
4091
-			$cache_contextes_ajax = true;
4092
-			spip_log('Contextes AJAX forces en fichiers !'
4093
-				. ' Cela arrive lorsque la valeur du contexte'
4094
-				. ' depasse la longueur maximale autorisee par Suhosin'
4095
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4096
-				. ' Vous devriez modifier les parametres de Suhosin'
4097
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4098
-		}
4099
-	}
4100
-
4101
-	if ($cache_contextes_ajax) {
4102
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4103
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4104
-		$md5 = md5($c);
4105
-		ecrire_fichier("$dir/c$md5", $c);
4106
-		$env = $md5;
4107
-	}
4108
-
4109
-	if ($emboite === null) {
4110
-		return $env;
4111
-	}
4112
-	if (!trim($emboite)) {
4113
-		return '';
4114
-	}
4115
-	// toujours encoder l'url source dans le bloc ajax
4116
-	$r = self();
4117
-	$r = ' data-origin="' . $r . '"';
4118
-	$class = 'ajaxbloc';
4119
-	if ($ajaxid and is_string($ajaxid)) {
4120
-		// ajaxid est normalement conforme a un nom de classe css
4121
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4122
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4123
-	}
4124
-
4125
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4034
+    $env = null;
4035
+    if (
4036
+        is_string($c)
4037
+        and @unserialize($c) !== false
4038
+    ) {
4039
+        $c = unserialize($c);
4040
+    }
4041
+
4042
+    // supprimer les parametres debut_x
4043
+    // pour que la pagination ajax ne soit pas plantee
4044
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4045
+    // le debut_x=0 n'existe pas, et on resterait sur 1
4046
+    if (is_array($c)) {
4047
+        foreach ($c as $k => $v) {
4048
+            if (strpos($k, 'debut_') === 0) {
4049
+                unset($c[$k]);
4050
+            }
4051
+        }
4052
+    }
4053
+
4054
+    if (!function_exists('calculer_cle_action')) {
4055
+        include_spip('inc/securiser_action');
4056
+    }
4057
+
4058
+    $c = serialize($c);
4059
+    $cle = calculer_cle_action($form . $c);
4060
+    $c = "$cle:$c";
4061
+
4062
+    // on ne stocke pas les contextes dans des fichiers en cache
4063
+    // par defaut, sauf si cette configuration a été forcée
4064
+    // OU que la longueur de l’argument géneré est plus long
4065
+    // que ce qui est toléré.
4066
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4067
+    if (!$cache_contextes_ajax) {
4068
+        $env = $c;
4069
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4070
+            $env = gzdeflate($env);
4071
+        }
4072
+        $env = _xor($env);
4073
+        $env = base64_encode($env);
4074
+        $len = strlen($env);
4075
+        // Si l’url est trop longue pour le navigateur
4076
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4077
+        if ($len > $max_len) {
4078
+            $cache_contextes_ajax = true;
4079
+            spip_log(
4080
+                'Contextes AJAX forces en fichiers !'
4081
+                . ' Cela arrive lorsque la valeur du contexte'
4082
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4083
+                _LOG_AVERTISSEMENT
4084
+            );
4085
+        }
4086
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4087
+        elseif (
4088
+            $max_len = @ini_get('suhosin.get.max_value_length')
4089
+            and $max_len < $len
4090
+        ) {
4091
+            $cache_contextes_ajax = true;
4092
+            spip_log('Contextes AJAX forces en fichiers !'
4093
+                . ' Cela arrive lorsque la valeur du contexte'
4094
+                . ' depasse la longueur maximale autorisee par Suhosin'
4095
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4096
+                . ' Vous devriez modifier les parametres de Suhosin'
4097
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4098
+        }
4099
+    }
4100
+
4101
+    if ($cache_contextes_ajax) {
4102
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4103
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4104
+        $md5 = md5($c);
4105
+        ecrire_fichier("$dir/c$md5", $c);
4106
+        $env = $md5;
4107
+    }
4108
+
4109
+    if ($emboite === null) {
4110
+        return $env;
4111
+    }
4112
+    if (!trim($emboite)) {
4113
+        return '';
4114
+    }
4115
+    // toujours encoder l'url source dans le bloc ajax
4116
+    $r = self();
4117
+    $r = ' data-origin="' . $r . '"';
4118
+    $class = 'ajaxbloc';
4119
+    if ($ajaxid and is_string($ajaxid)) {
4120
+        // ajaxid est normalement conforme a un nom de classe css
4121
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4122
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4123
+    }
4124
+
4125
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4126 4126
 }
4127 4127
 
4128 4128
 /**
@@ -4142,37 +4142,37 @@  discard block
 block discarded – undo
4142 4142
  *   - false : erreur de décodage
4143 4143
  */
4144 4144
 function decoder_contexte_ajax($c, $form = '') {
4145
-	if (!function_exists('calculer_cle_action')) {
4146
-		include_spip('inc/securiser_action');
4147
-	}
4148
-	if (
4149
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4150
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4151
-		and lire_fichier("$dir/c$c", $contexte)
4152
-	) {
4153
-		$c = $contexte;
4154
-	} else {
4155
-		$c = @base64_decode($c);
4156
-		$c = _xor($c);
4157
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4158
-			$c = @gzinflate($c);
4159
-		}
4160
-	}
4161
-
4162
-	// extraire la signature en debut de contexte
4163
-	// et la verifier avant de deserializer
4164
-	// format : signature:donneesserializees
4165
-	if ($p = strpos($c, ':')) {
4166
-		$cle = substr($c, 0, $p);
4167
-		$c = substr($c, $p + 1);
4168
-
4169
-		if ($cle == calculer_cle_action($form . $c)) {
4170
-			$env = @unserialize($c);
4171
-			return $env;
4172
-		}
4173
-	}
4174
-
4175
-	return false;
4145
+    if (!function_exists('calculer_cle_action')) {
4146
+        include_spip('inc/securiser_action');
4147
+    }
4148
+    if (
4149
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4150
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4151
+        and lire_fichier("$dir/c$c", $contexte)
4152
+    ) {
4153
+        $c = $contexte;
4154
+    } else {
4155
+        $c = @base64_decode($c);
4156
+        $c = _xor($c);
4157
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4158
+            $c = @gzinflate($c);
4159
+        }
4160
+    }
4161
+
4162
+    // extraire la signature en debut de contexte
4163
+    // et la verifier avant de deserializer
4164
+    // format : signature:donneesserializees
4165
+    if ($p = strpos($c, ':')) {
4166
+        $cle = substr($c, 0, $p);
4167
+        $c = substr($c, $p + 1);
4168
+
4169
+        if ($cle == calculer_cle_action($form . $c)) {
4170
+            $env = @unserialize($c);
4171
+            return $env;
4172
+        }
4173
+    }
4174
+
4175
+    return false;
4176 4176
 }
4177 4177
 
4178 4178
 
@@ -4190,20 +4190,20 @@  discard block
 block discarded – undo
4190 4190
  *    Message décrypté ou encrypté
4191 4191
  **/
4192 4192
 function _xor($message, $key = null) {
4193
-	if (is_null($key)) {
4194
-		if (!function_exists('calculer_cle_action')) {
4195
-			include_spip('inc/securiser_action');
4196
-		}
4197
-		$key = pack('H*', calculer_cle_action('_xor'));
4198
-	}
4193
+    if (is_null($key)) {
4194
+        if (!function_exists('calculer_cle_action')) {
4195
+            include_spip('inc/securiser_action');
4196
+        }
4197
+        $key = pack('H*', calculer_cle_action('_xor'));
4198
+    }
4199 4199
 
4200
-	$keylen = strlen($key);
4201
-	$messagelen = strlen($message);
4202
-	for ($i = 0; $i < $messagelen; $i++) {
4203
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4204
-	}
4200
+    $keylen = strlen($key);
4201
+    $messagelen = strlen($message);
4202
+    for ($i = 0; $i < $messagelen; $i++) {
4203
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4204
+    }
4205 4205
 
4206
-	return $message;
4206
+    return $message;
4207 4207
 }
4208 4208
 
4209 4209
 /**
@@ -4217,7 +4217,7 @@  discard block
 block discarded – undo
4217 4217
  * @return string
4218 4218
  */
4219 4219
 function url_reponse_forum($texte) {
4220
- return $texte;
4220
+    return $texte;
4221 4221
 }
4222 4222
 
4223 4223
 /**
@@ -4231,7 +4231,7 @@  discard block
 block discarded – undo
4231 4231
  * @return string
4232 4232
  */
4233 4233
 function url_rss_forum($texte) {
4234
- return $texte;
4234
+    return $texte;
4235 4235
 }
4236 4236
 
4237 4237
 
@@ -4270,37 +4270,37 @@  discard block
 block discarded – undo
4270 4270
  *   Code HTML
4271 4271
  */
4272 4272
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4273
-	if ($on) {
4274
-		$bal = 'strong';
4275
-		$class = '';
4276
-		$att = '';
4277
-		// si $on passe la balise et optionnelement une ou ++classe
4278
-		// a.active span.selected.active etc....
4279
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4280
-			$on = explode('.', $on);
4281
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4282
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4283
-				$bal = array_shift($on);
4284
-				$class = implode(' ', $on);
4285
-				if ($bal == 'a') {
4286
-					$att = 'href="#" ';
4287
-				}
4288
-			}
4289
-		}
4290
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4291
-	} else {
4292
-		$bal = 'a';
4293
-		$att = "href='$url'"
4294
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4295
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4296
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4297
-			. $evt;
4298
-	}
4299
-	if ($libelle === null) {
4300
-		$libelle = $url;
4301
-	}
4302
-
4303
-	return "<$bal $att>$libelle</$bal>";
4273
+    if ($on) {
4274
+        $bal = 'strong';
4275
+        $class = '';
4276
+        $att = '';
4277
+        // si $on passe la balise et optionnelement une ou ++classe
4278
+        // a.active span.selected.active etc....
4279
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4280
+            $on = explode('.', $on);
4281
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4282
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4283
+                $bal = array_shift($on);
4284
+                $class = implode(' ', $on);
4285
+                if ($bal == 'a') {
4286
+                    $att = 'href="#" ';
4287
+                }
4288
+            }
4289
+        }
4290
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4291
+    } else {
4292
+        $bal = 'a';
4293
+        $att = "href='$url'"
4294
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4295
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4296
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4297
+            . $evt;
4298
+    }
4299
+    if ($libelle === null) {
4300
+        $libelle = $url;
4301
+    }
4302
+
4303
+    return "<$bal $att>$libelle</$bal>";
4304 4304
 }
4305 4305
 
4306 4306
 
@@ -4317,39 +4317,39 @@  discard block
 block discarded – undo
4317 4317
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4318 4318
  */
4319 4319
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4320
-	static $local_singulier_ou_pluriel = [];
4321
-
4322
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4323
-	if (!is_numeric($nb) or $nb == 0) {
4324
-		return '';
4325
-	}
4326
-	if (!is_array($vars)) {
4327
-		return '';
4328
-	}
4329
-
4330
-	$langue = $GLOBALS['spip_lang'];
4331
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4332
-		$local_singulier_ou_pluriel[$langue] = false;
4333
-		if (
4334
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4335
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4336
-		) {
4337
-			$local_singulier_ou_pluriel[$langue] = $f;
4338
-		}
4339
-	}
4340
-
4341
-	// si on a une surcharge on l'utilise
4342
-	if ($local_singulier_ou_pluriel[$langue]) {
4343
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4344
-	}
4345
-
4346
-	// sinon traitement par defaut
4347
-	$vars[$var] = $nb;
4348
-	if ($nb >= 2) {
4349
-		return _T($chaine_plusieurs, $vars);
4350
-	} else {
4351
-		return _T($chaine_un, $vars);
4352
-	}
4320
+    static $local_singulier_ou_pluriel = [];
4321
+
4322
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4323
+    if (!is_numeric($nb) or $nb == 0) {
4324
+        return '';
4325
+    }
4326
+    if (!is_array($vars)) {
4327
+        return '';
4328
+    }
4329
+
4330
+    $langue = $GLOBALS['spip_lang'];
4331
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4332
+        $local_singulier_ou_pluriel[$langue] = false;
4333
+        if (
4334
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4335
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4336
+        ) {
4337
+            $local_singulier_ou_pluriel[$langue] = $f;
4338
+        }
4339
+    }
4340
+
4341
+    // si on a une surcharge on l'utilise
4342
+    if ($local_singulier_ou_pluriel[$langue]) {
4343
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4344
+    }
4345
+
4346
+    // sinon traitement par defaut
4347
+    $vars[$var] = $nb;
4348
+    if ($nb >= 2) {
4349
+        return _T($chaine_plusieurs, $vars);
4350
+    } else {
4351
+        return _T($chaine_un, $vars);
4352
+    }
4353 4353
 }
4354 4354
 
4355 4355
 
@@ -4377,73 +4377,73 @@  discard block
 block discarded – undo
4377 4377
  */
4378 4378
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4379 4379
 
4380
-	$class_lien = $class_bouton = $class;
4381
-
4382
-	// Normaliser la fonction et compléter la classe en fonction
4383
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4384
-		$class_lien .= ' danger';
4385
-		$class_bouton .= ' btn_danger';
4386
-	} elseif ($fonction == 'rien.gif') {
4387
-		$fonction = '';
4388
-	} elseif ($fonction == 'delsafe') {
4389
-		$fonction = 'del';
4390
-	}
4391
-
4392
-	$fond_origine = $fond;
4393
-	// Remappage des icone : article-24.png+new => article-new-24.png
4394
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4395
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4396
-	}
4397
-
4398
-	// Ajouter le type d'objet dans la classe
4399
-	$objet_type = substr(basename($fond), 0, -4);
4400
-	$class_lien .= " $objet_type";
4401
-	$class_bouton .= " $objet_type";
4402
-
4403
-	// Texte
4404
-	$alt = attribut_html($texte);
4405
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4406
-
4407
-	// Liens : préparer les classes ajax
4408
-	$ajax = '';
4409
-	if ($type === 'lien') {
4410
-		if (strpos($class_lien, 'ajax') !== false) {
4411
-			$ajax = 'ajax';
4412
-			if (strpos($class_lien, 'preload') !== false) {
4413
-				$ajax .= ' preload';
4414
-			}
4415
-			if (strpos($class_lien, 'nocache') !== false) {
4416
-				$ajax .= ' nocache';
4417
-			}
4418
-			$ajax = " class='$ajax'";
4419
-		}
4420
-	}
4421
-
4422
-	// Repérer la taille et l'ajouter dans la classe
4423
-	$size = 24;
4424
-	if (
4425
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4426
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4427
-	) {
4428
-		$size = $match[1];
4429
-	}
4430
-	$class_lien .= " s$size";
4431
-	$class_bouton .= " s$size";
4432
-
4433
-	// Icône
4434
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4435
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4436
-
4437
-	// Markup final
4438
-	if ($type == 'lien') {
4439
-		return "<span class='icone $class_lien'>"
4440
-		. "<a href='$lien'$title$ajax$javascript>"
4441
-		. $icone
4442
-		. "<b>$texte</b>"
4443
-		. "</a></span>\n";
4444
-	} else {
4445
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4446
-	}
4380
+    $class_lien = $class_bouton = $class;
4381
+
4382
+    // Normaliser la fonction et compléter la classe en fonction
4383
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4384
+        $class_lien .= ' danger';
4385
+        $class_bouton .= ' btn_danger';
4386
+    } elseif ($fonction == 'rien.gif') {
4387
+        $fonction = '';
4388
+    } elseif ($fonction == 'delsafe') {
4389
+        $fonction = 'del';
4390
+    }
4391
+
4392
+    $fond_origine = $fond;
4393
+    // Remappage des icone : article-24.png+new => article-new-24.png
4394
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4395
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4396
+    }
4397
+
4398
+    // Ajouter le type d'objet dans la classe
4399
+    $objet_type = substr(basename($fond), 0, -4);
4400
+    $class_lien .= " $objet_type";
4401
+    $class_bouton .= " $objet_type";
4402
+
4403
+    // Texte
4404
+    $alt = attribut_html($texte);
4405
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4406
+
4407
+    // Liens : préparer les classes ajax
4408
+    $ajax = '';
4409
+    if ($type === 'lien') {
4410
+        if (strpos($class_lien, 'ajax') !== false) {
4411
+            $ajax = 'ajax';
4412
+            if (strpos($class_lien, 'preload') !== false) {
4413
+                $ajax .= ' preload';
4414
+            }
4415
+            if (strpos($class_lien, 'nocache') !== false) {
4416
+                $ajax .= ' nocache';
4417
+            }
4418
+            $ajax = " class='$ajax'";
4419
+        }
4420
+    }
4421
+
4422
+    // Repérer la taille et l'ajouter dans la classe
4423
+    $size = 24;
4424
+    if (
4425
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4426
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4427
+    ) {
4428
+        $size = $match[1];
4429
+    }
4430
+    $class_lien .= " s$size";
4431
+    $class_bouton .= " s$size";
4432
+
4433
+    // Icône
4434
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4435
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4436
+
4437
+    // Markup final
4438
+    if ($type == 'lien') {
4439
+        return "<span class='icone $class_lien'>"
4440
+        . "<a href='$lien'$title$ajax$javascript>"
4441
+        . $icone
4442
+        . "<b>$texte</b>"
4443
+        . "</a></span>\n";
4444
+    } else {
4445
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4446
+    }
4447 4447
 }
4448 4448
 
4449 4449
 /**
@@ -4467,7 +4467,7 @@  discard block
 block discarded – undo
4467 4467
  *     Code HTML du lien
4468 4468
  **/
4469 4469
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4470
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4470
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4471 4471
 }
4472 4472
 
4473 4473
 /**
@@ -4502,7 +4502,7 @@  discard block
 block discarded – undo
4502 4502
  *     Code HTML du lien
4503 4503
  **/
4504 4504
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4505
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4505
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4506 4506
 }
4507 4507
 
4508 4508
 /**
@@ -4547,7 +4547,7 @@  discard block
 block discarded – undo
4547 4547
  *     Code HTML du lien
4548 4548
  **/
4549 4549
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4550
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4550
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4551 4551
 }
4552 4552
 
4553 4553
 /**
@@ -4578,7 +4578,7 @@  discard block
 block discarded – undo
4578 4578
  *     Code HTML du lien
4579 4579
  **/
4580 4580
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4581
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4581
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4582 4582
 }
4583 4583
 
4584 4584
 /**
@@ -4609,7 +4609,7 @@  discard block
 block discarded – undo
4609 4609
  *     Code HTML du lien
4610 4610
  */
4611 4611
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4612
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4612
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4613 4613
 }
4614 4614
 
4615 4615
 
@@ -4631,7 +4631,7 @@  discard block
 block discarded – undo
4631 4631
  * @return array Liste des éléments
4632 4632
  */
4633 4633
 function filtre_explode_dist($a, $b) {
4634
-	return explode($b, (string) $a);
4634
+    return explode($b, (string) $a);
4635 4635
 }
4636 4636
 
4637 4637
 /**
@@ -4652,7 +4652,7 @@  discard block
 block discarded – undo
4652 4652
  * @return string Texte
4653 4653
  */
4654 4654
 function filtre_implode_dist($a, $b) {
4655
-	return is_array($a) ? implode($b, $a) : $a;
4655
+    return is_array($a) ? implode($b, $a) : $a;
4656 4656
 }
4657 4657
 
4658 4658
 /**
@@ -4661,24 +4661,24 @@  discard block
 block discarded – undo
4661 4661
  * @return string Code CSS
4662 4662
  */
4663 4663
 function bando_images_background() {
4664
-	include_spip('inc/bandeau');
4665
-	// recuperer tous les boutons et leurs images
4666
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4664
+    include_spip('inc/bandeau');
4665
+    // recuperer tous les boutons et leurs images
4666
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4667 4667
 
4668
-	$res = '';
4669
-	foreach ($boutons as $page => $detail) {
4670
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4671
-		if (is_array($detail->sousmenu)) {
4672
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4673
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4674
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4675
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4676
-				}
4677
-			}
4678
-		}
4679
-	}
4668
+    $res = '';
4669
+    foreach ($boutons as $page => $detail) {
4670
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4671
+        if (is_array($detail->sousmenu)) {
4672
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4673
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4674
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4675
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4676
+                }
4677
+            }
4678
+        }
4679
+    }
4680 4680
 
4681
-	return $res;
4681
+    return $res;
4682 4682
 }
4683 4683
 
4684 4684
 /**
@@ -4703,27 +4703,27 @@  discard block
 block discarded – undo
4703 4703
  */
4704 4704
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4705 4705
 
4706
-	// Classes : dispatcher `ajax` sur le formulaire
4707
-	$class_form = '';
4708
-	if (strpos($class, 'ajax') !== false) {
4709
-		$class_form = 'ajax';
4710
-		$class = str_replace('ajax', '', $class);
4711
-	}
4712
-	$class_btn = 'submit ' . trim($class);
4706
+    // Classes : dispatcher `ajax` sur le formulaire
4707
+    $class_form = '';
4708
+    if (strpos($class, 'ajax') !== false) {
4709
+        $class_form = 'ajax';
4710
+        $class = str_replace('ajax', '', $class);
4711
+    }
4712
+    $class_btn = 'submit ' . trim($class);
4713 4713
 
4714
-	if ($confirm) {
4715
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4716
-		if ($callback) {
4717
-			$callback = "$confirm?($callback):false";
4718
-		} else {
4719
-			$callback = $confirm;
4720
-		}
4721
-	}
4722
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4723
-	$title = $title ? " title='$title'" : '';
4714
+    if ($confirm) {
4715
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4716
+        if ($callback) {
4717
+            $callback = "$confirm?($callback):false";
4718
+        } else {
4719
+            $callback = $confirm;
4720
+        }
4721
+    }
4722
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4723
+    $title = $title ? " title='$title'" : '';
4724 4724
 
4725
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4726
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4725
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4726
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4727 4727
 }
4728 4728
 
4729 4729
 /**
@@ -4746,101 +4746,101 @@  discard block
 block discarded – undo
4746 4746
  * @return string
4747 4747
  */
4748 4748
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4749
-	static $trouver_table = null;
4750
-	static $objets;
4751
-
4752
-	// On verifie qu'on a tout ce qu'il faut
4753
-	$id_objet = intval($id_objet);
4754
-	if (!($id_objet and $type_objet and $info)) {
4755
-		return '';
4756
-	}
4757
-
4758
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4759
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4760
-		return '';
4761
-	}
4762
-
4763
-	// Si on demande l'url, on retourne direct la fonction
4764
-	if ($info == 'url') {
4765
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4766
-	}
4767
-
4768
-	// Sinon on va tout chercher dans la table et on garde en memoire
4769
-	$demande_titre = ($info === 'titre');
4770
-	$demande_introduction = ($info === 'introduction');
4771
-
4772
-	// 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
4773
-	if (
4774
-		!isset($objets[$type_objet][$id_objet])
4775
-		or
4776
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4777
-	) {
4778
-		if (!$trouver_table) {
4779
-			$trouver_table = charger_fonction('trouver_table', 'base');
4780
-		}
4781
-		$desc = $trouver_table(table_objet_sql($type_objet));
4782
-		if (!$desc) {
4783
-			return $objets[$type_objet] = false;
4784
-		}
4785
-
4786
-		// Si on demande le titre, on le gere en interne
4787
-		$champ_titre = '';
4788
-		if ($demande_titre) {
4789
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4790
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4791
-		}
4792
-		include_spip('base/abstract_sql');
4793
-		include_spip('base/connect_sql');
4794
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4795
-			'*' . $champ_titre,
4796
-			$desc['table_sql'],
4797
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4798
-		);
4799
-
4800
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4801
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4802
-	}
4803
-
4804
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4805
-	// ajouter la longueur au début des params supplémentaires
4806
-	if ($demande_introduction) {
4807
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4808
-		array_unshift($params, $introduction_longueur);
4809
-	}
4810
-
4811
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4812
-	if (
4813
-		$generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4814
-		// @deprecated 4.1 generer_TRUC_TYPE
4815
-		or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4816
-	) {
4817
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4818
-	}
4819
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4820
-	elseif (
4821
-		$generer = charger_fonction("generer_objet_${info}", '', true)
4822
-		// @deprecated 4.1 generer_TRUC_entite
4823
-		or $generer = charger_fonction("generer_${info}_entite", '', true)
4824
-	) {
4825
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4826
-	} // Sinon on prend directement le champ SQL tel quel
4827
-	else {
4828
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4829
-	}
4830
-
4831
-	// On va ensuite appliquer les traitements automatiques si besoin
4832
-	if (!$etoile) {
4833
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4834
-		// mais ce fonctionnement est a ameliorer !
4835
-		$info_generee = appliquer_traitement_champ(
4836
-			$info_generee,
4837
-			$info,
4838
-			table_objet($type_objet),
4839
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4840
-		);
4841
-	}
4842
-
4843
-	return $info_generee;
4749
+    static $trouver_table = null;
4750
+    static $objets;
4751
+
4752
+    // On verifie qu'on a tout ce qu'il faut
4753
+    $id_objet = intval($id_objet);
4754
+    if (!($id_objet and $type_objet and $info)) {
4755
+        return '';
4756
+    }
4757
+
4758
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4759
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4760
+        return '';
4761
+    }
4762
+
4763
+    // Si on demande l'url, on retourne direct la fonction
4764
+    if ($info == 'url') {
4765
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4766
+    }
4767
+
4768
+    // Sinon on va tout chercher dans la table et on garde en memoire
4769
+    $demande_titre = ($info === 'titre');
4770
+    $demande_introduction = ($info === 'introduction');
4771
+
4772
+    // 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
4773
+    if (
4774
+        !isset($objets[$type_objet][$id_objet])
4775
+        or
4776
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4777
+    ) {
4778
+        if (!$trouver_table) {
4779
+            $trouver_table = charger_fonction('trouver_table', 'base');
4780
+        }
4781
+        $desc = $trouver_table(table_objet_sql($type_objet));
4782
+        if (!$desc) {
4783
+            return $objets[$type_objet] = false;
4784
+        }
4785
+
4786
+        // Si on demande le titre, on le gere en interne
4787
+        $champ_titre = '';
4788
+        if ($demande_titre) {
4789
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4790
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4791
+        }
4792
+        include_spip('base/abstract_sql');
4793
+        include_spip('base/connect_sql');
4794
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4795
+            '*' . $champ_titre,
4796
+            $desc['table_sql'],
4797
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4798
+        );
4799
+
4800
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4801
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4802
+    }
4803
+
4804
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4805
+    // ajouter la longueur au début des params supplémentaires
4806
+    if ($demande_introduction) {
4807
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4808
+        array_unshift($params, $introduction_longueur);
4809
+    }
4810
+
4811
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4812
+    if (
4813
+        $generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4814
+        // @deprecated 4.1 generer_TRUC_TYPE
4815
+        or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4816
+    ) {
4817
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4818
+    }
4819
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4820
+    elseif (
4821
+        $generer = charger_fonction("generer_objet_${info}", '', true)
4822
+        // @deprecated 4.1 generer_TRUC_entite
4823
+        or $generer = charger_fonction("generer_${info}_entite", '', true)
4824
+    ) {
4825
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4826
+    } // Sinon on prend directement le champ SQL tel quel
4827
+    else {
4828
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4829
+    }
4830
+
4831
+    // On va ensuite appliquer les traitements automatiques si besoin
4832
+    if (!$etoile) {
4833
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4834
+        // mais ce fonctionnement est a ameliorer !
4835
+        $info_generee = appliquer_traitement_champ(
4836
+            $info_generee,
4837
+            $info,
4838
+            table_objet($type_objet),
4839
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4840
+        );
4841
+    }
4842
+
4843
+    return $info_generee;
4844 4844
 }
4845 4845
 
4846 4846
 /**
@@ -4848,7 +4848,7 @@  discard block
 block discarded – undo
4848 4848
  * @see generer_objet_info
4849 4849
  */
4850 4850
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4851
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4851
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4852 4852
 }
4853 4853
 
4854 4854
 /**
@@ -4881,36 +4881,36 @@  discard block
 block discarded – undo
4881 4881
  */
4882 4882
 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 {
4883 4883
 
4884
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4885
-	$texte = $ligne_sql['texte'] ?? '';
4886
-	// En absence de descriptif, on se rabat sur chapo + texte
4887
-	if (isset($ligne_sql['chapo'])) {
4888
-		$chapo = $ligne_sql['chapo'];
4889
-		$texte = strlen($descriptif) ?
4890
-			'' :
4891
-			"$chapo \n\n $texte";
4892
-	}
4884
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4885
+    $texte = $ligne_sql['texte'] ?? '';
4886
+    // En absence de descriptif, on se rabat sur chapo + texte
4887
+    if (isset($ligne_sql['chapo'])) {
4888
+        $chapo = $ligne_sql['chapo'];
4889
+        $texte = strlen($descriptif) ?
4890
+            '' :
4891
+            "$chapo \n\n $texte";
4892
+    }
4893 4893
 
4894
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4895
-	if (!intval($longueur_ou_suite)) {
4896
-		$longueur = intval($introduction_longueur ?: 600);
4897
-	} else {
4898
-		$longueur = intval($longueur_ou_suite);
4899
-	}
4894
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4895
+    if (!intval($longueur_ou_suite)) {
4896
+        $longueur = intval($introduction_longueur ?: 600);
4897
+    } else {
4898
+        $longueur = intval($longueur_ou_suite);
4899
+    }
4900 4900
 
4901
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4902
-	// Ex : #INTRODUCTION{...}
4903
-	if (
4904
-		is_null($suite)
4905
-		and !intval($longueur_ou_suite)
4906
-	) {
4907
-		$suite = $longueur_ou_suite;
4908
-	}
4901
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4902
+    // Ex : #INTRODUCTION{...}
4903
+    if (
4904
+        is_null($suite)
4905
+        and !intval($longueur_ou_suite)
4906
+    ) {
4907
+        $suite = $longueur_ou_suite;
4908
+    }
4909 4909
 
4910
-	$f = chercher_filtre('introduction');
4911
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4910
+    $f = chercher_filtre('introduction');
4911
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4912 4912
 
4913
-	return $introduction;
4913
+    return $introduction;
4914 4914
 }
4915 4915
 
4916 4916
 /**
@@ -4918,7 +4918,7 @@  discard block
 block discarded – undo
4918 4918
  * @see generer_objet_introduction
4919 4919
  */
4920 4920
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4921
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4921
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4922 4922
 }
4923 4923
 
4924 4924
 /**
@@ -4932,44 +4932,44 @@  discard block
 block discarded – undo
4932 4932
  * @return string
4933 4933
  */
4934 4934
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4935
-	if (!$champ) {
4936
-		return $texte;
4937
-	}
4935
+    if (!$champ) {
4936
+        return $texte;
4937
+    }
4938 4938
 
4939
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4940
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4941
-	include_fichiers_fonctions();
4939
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4940
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4941
+    include_fichiers_fonctions();
4942 4942
 
4943
-	$champ = strtoupper($champ);
4944
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4945
-	if (!$traitements or !is_array($traitements)) {
4946
-		return $texte;
4947
-	}
4943
+    $champ = strtoupper($champ);
4944
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4945
+    if (!$traitements or !is_array($traitements)) {
4946
+        return $texte;
4947
+    }
4948 4948
 
4949
-	$traitement = '';
4950
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4951
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4952
-		$table_objet = table_objet($table_objet);
4953
-		if (isset($traitements[$table_objet])) {
4954
-			$traitement = $traitements[$table_objet];
4955
-		}
4956
-	}
4957
-	if (!$traitement and isset($traitements[0])) {
4958
-		$traitement = $traitements[0];
4959
-	}
4960
-	// (sinon prendre le premier de la liste par defaut ?)
4949
+    $traitement = '';
4950
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4951
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4952
+        $table_objet = table_objet($table_objet);
4953
+        if (isset($traitements[$table_objet])) {
4954
+            $traitement = $traitements[$table_objet];
4955
+        }
4956
+    }
4957
+    if (!$traitement and isset($traitements[0])) {
4958
+        $traitement = $traitements[0];
4959
+    }
4960
+    // (sinon prendre le premier de la liste par defaut ?)
4961 4961
 
4962
-	if (!$traitement) {
4963
-		return $texte;
4964
-	}
4962
+    if (!$traitement) {
4963
+        return $texte;
4964
+    }
4965 4965
 
4966
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4966
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4967 4967
 
4968
-	// Fournir $connect et $Pile[0] au traitement si besoin
4969
-	$Pile = [0 => $env];
4970
-	eval("\$texte = $traitement;");
4968
+    // Fournir $connect et $Pile[0] au traitement si besoin
4969
+    $Pile = [0 => $env];
4970
+    eval("\$texte = $traitement;");
4971 4971
 
4972
-	return $texte;
4972
+    return $texte;
4973 4973
 }
4974 4974
 
4975 4975
 
@@ -4983,21 +4983,21 @@  discard block
 block discarded – undo
4983 4983
  * @return string
4984 4984
  */
4985 4985
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4986
-	include_spip('inc/liens');
4987
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4988
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4989
-	// le raccourcis n'est plus valide
4990
-	$titre = typo($titre['titre']) ?? '';
4991
-	// on essaye avec generer_info_entite ?
4992
-	if (!strlen($titre) and !$connect) {
4993
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4994
-	}
4995
-	if (!strlen($titre)) {
4996
-		$titre = _T('info_sans_titre');
4997
-	}
4998
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4986
+    include_spip('inc/liens');
4987
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4988
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4989
+    // le raccourcis n'est plus valide
4990
+    $titre = typo($titre['titre']) ?? '';
4991
+    // on essaye avec generer_info_entite ?
4992
+    if (!strlen($titre) and !$connect) {
4993
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4994
+    }
4995
+    if (!strlen($titre)) {
4996
+        $titre = _T('info_sans_titre');
4997
+    }
4998
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4999 4999
 
5000
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
5000
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
5001 5001
 }
5002 5002
 
5003 5003
 /**
@@ -5005,7 +5005,7 @@  discard block
 block discarded – undo
5005 5005
  * @see generer_objet_lien
5006 5006
  */
5007 5007
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
5008
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5008
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5009 5009
 }
5010 5010
 
5011 5011
 /**
@@ -5021,15 +5021,15 @@  discard block
 block discarded – undo
5021 5021
  * @return string
5022 5022
  */
5023 5023
 function wrap($texte, $wrap) {
5024
-	$balises = extraire_balises($wrap);
5025
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5026
-		$texte = $wrap . $texte;
5027
-		$regs = array_reverse($regs[1]);
5028
-		$wrap = '</' . implode('></', $regs) . '>';
5029
-		$texte = $texte . $wrap;
5030
-	}
5024
+    $balises = extraire_balises($wrap);
5025
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5026
+        $texte = $wrap . $texte;
5027
+        $regs = array_reverse($regs[1]);
5028
+        $wrap = '</' . implode('></', $regs) . '>';
5029
+        $texte = $texte . $wrap;
5030
+    }
5031 5031
 
5032
-	return $texte;
5032
+    return $texte;
5033 5033
 }
5034 5034
 
5035 5035
 
@@ -5049,44 +5049,44 @@  discard block
 block discarded – undo
5049 5049
  * @return array|mixed|string
5050 5050
  */
5051 5051
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
5052
-	if (is_string($u)) {
5053
-		$u = typo($u);
5052
+    if (is_string($u)) {
5053
+        $u = typo($u);
5054 5054
 
5055
-		return $u;
5056
-	}
5055
+        return $u;
5056
+    }
5057 5057
 
5058
-	// caster $u en array si besoin
5059
-	if (is_object($u)) {
5060
-		$u = (array)$u;
5061
-	}
5058
+    // caster $u en array si besoin
5059
+    if (is_object($u)) {
5060
+        $u = (array)$u;
5061
+    }
5062 5062
 
5063
-	if (is_array($u)) {
5064
-		$out = '';
5065
-		// toutes les cles sont numeriques ?
5066
-		// et aucun enfant n'est un tableau
5067
-		// liste simple separee par des virgules
5068
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5069
-		$array_values = array_map('is_array', $u);
5070
-		$object_values = array_map('is_object', $u);
5071
-		if (
5072
-			array_sum($numeric_keys) == count($numeric_keys)
5073
-			and !array_sum($array_values)
5074
-			and !array_sum($object_values)
5075
-		) {
5076
-			return join(', ', array_map('filtre_print_dist', $u));
5077
-		}
5063
+    if (is_array($u)) {
5064
+        $out = '';
5065
+        // toutes les cles sont numeriques ?
5066
+        // et aucun enfant n'est un tableau
5067
+        // liste simple separee par des virgules
5068
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5069
+        $array_values = array_map('is_array', $u);
5070
+        $object_values = array_map('is_object', $u);
5071
+        if (
5072
+            array_sum($numeric_keys) == count($numeric_keys)
5073
+            and !array_sum($array_values)
5074
+            and !array_sum($object_values)
5075
+        ) {
5076
+            return join(', ', array_map('filtre_print_dist', $u));
5077
+        }
5078 5078
 
5079
-		// sinon on passe a la ligne et on indente
5080
-		$i_str = str_pad('', $indent, ' ');
5081
-		foreach ($u as $k => $v) {
5082
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5083
-		}
5079
+        // sinon on passe a la ligne et on indente
5080
+        $i_str = str_pad('', $indent, ' ');
5081
+        foreach ($u as $k => $v) {
5082
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5083
+        }
5084 5084
 
5085
-		return $out;
5086
-	}
5085
+        return $out;
5086
+    }
5087 5087
 
5088
-	// on sait pas quoi faire...
5089
-	return $u;
5088
+    // on sait pas quoi faire...
5089
+    return $u;
5090 5090
 }
5091 5091
 
5092 5092
 
@@ -5099,10 +5099,10 @@  discard block
 block discarded – undo
5099 5099
  * @return string|array
5100 5100
  */
5101 5101
 function objet_info($objet, $info) {
5102
-	$table = table_objet_sql($objet);
5103
-	$infos = lister_tables_objets_sql($table);
5102
+    $table = table_objet_sql($objet);
5103
+    $infos = lister_tables_objets_sql($table);
5104 5104
 
5105
-	return ($infos[$info] ?? '');
5105
+    return ($infos[$info] ?? '');
5106 5106
 }
5107 5107
 
5108 5108
 /**
@@ -5117,11 +5117,11 @@  discard block
 block discarded – undo
5117 5117
  *     Texte traduit du comptage, tel que '3 articles'
5118 5118
  */
5119 5119
 function objet_afficher_nb($nb, $objet) {
5120
-	if (!$nb) {
5121
-		return _T(objet_info($objet, 'info_aucun_objet'));
5122
-	} else {
5123
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5124
-	}
5120
+    if (!$nb) {
5121
+        return _T(objet_info($objet, 'info_aucun_objet'));
5122
+    } else {
5123
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5124
+    }
5125 5125
 }
5126 5126
 
5127 5127
 /**
@@ -5133,11 +5133,11 @@  discard block
 block discarded – undo
5133 5133
  * @return string
5134 5134
  */
5135 5135
 function objet_icone($objet, $taille = 24, $class = '') {
5136
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5137
-	$icone = chemin_image($icone);
5138
-	$balise_img = charger_filtre('balise_img');
5136
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5137
+    $icone = chemin_image($icone);
5138
+    $balise_img = charger_filtre('balise_img');
5139 5139
 
5140
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5140
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5141 5141
 }
5142 5142
 
5143 5143
 /**
@@ -5158,12 +5158,12 @@  discard block
 block discarded – undo
5158 5158
  * @return string
5159 5159
  */
5160 5160
 function objet_T($objet, $chaine, $args = [], $options = []) {
5161
-	$chaine = explode(':', $chaine);
5162
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5163
-		return $t;
5164
-	}
5165
-	$chaine = implode(':', $chaine);
5166
-	return _T($chaine, $args, $options);
5161
+    $chaine = explode(':', $chaine);
5162
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5163
+        return $t;
5164
+    }
5165
+    $chaine = implode(':', $chaine);
5166
+    return _T($chaine, $args, $options);
5167 5167
 }
5168 5168
 
5169 5169
 /**
@@ -5177,18 +5177,18 @@  discard block
 block discarded – undo
5177 5177
  * @return string      Code HTML
5178 5178
  */
5179 5179
 function insert_head_css_conditionnel($flux) {
5180
-	if (
5181
-		strpos($flux, '<!-- insert_head_css -->') === false
5182
-		and $p = strpos($flux, '<!-- insert_head -->')
5183
-	) {
5184
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5185
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5186
-			$p = $p1;
5187
-		}
5188
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5189
-	}
5180
+    if (
5181
+        strpos($flux, '<!-- insert_head_css -->') === false
5182
+        and $p = strpos($flux, '<!-- insert_head -->')
5183
+    ) {
5184
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5185
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5186
+            $p = $p1;
5187
+        }
5188
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5189
+    }
5190 5190
 
5191
-	return $flux;
5191
+    return $flux;
5192 5192
 }
5193 5193
 
5194 5194
 /**
@@ -5211,72 +5211,72 @@  discard block
 block discarded – undo
5211 5211
  * @return string
5212 5212
  */
5213 5213
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5214
-	if (isset($contexte['format'])) {
5215
-		$extension = $contexte['format'];
5216
-		unset($contexte['format']);
5217
-	} else {
5218
-		$extension = 'html';
5219
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5220
-			$extension = $m[1];
5221
-		}
5222
-	}
5223
-	// recuperer le contenu produit par le squelette
5224
-	$options['raw'] = true;
5225
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5226
-
5227
-	// calculer le nom de la css
5228
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5229
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5230
-	$contexte_implicite = calculer_contexte_implicite();
5231
-
5232
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5233
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5234
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5235
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5236
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5237
-	}
5238
-	else {
5239
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5240
-		ksort($contexte);
5241
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5242
-	}
5243
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5244
-
5245
-	// mettre a jour le fichier si il n'existe pas
5246
-	// ou trop ancien
5247
-	// le dernier fichier produit est toujours suffixe par .last
5248
-	// et recopie sur le fichier cible uniquement si il change
5249
-	if (
5250
-		!file_exists($filename)
5251
-		or !file_exists($filename . '.last')
5252
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5253
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5254
-	) {
5255
-		$contenu = $cache['texte'];
5256
-		// passer les urls en absolu si c'est une css
5257
-		if ($extension == 'css') {
5258
-			$contenu = urls_absolues_css(
5259
-				$contenu,
5260
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5261
-			);
5262
-		}
5263
-
5264
-		$comment = '';
5265
-		// ne pas insérer de commentaire sur certains formats
5266
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5267
-			$comment = "/* #PRODUIRE{fond=$fond";
5268
-			foreach ($contexte as $k => $v) {
5269
-				$comment .= ",$k=$v";
5270
-			}
5271
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5272
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5273
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5274
-		}
5275
-		// et ecrire le fichier si il change
5276
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5277
-	}
5278
-
5279
-	return timestamp($filename);
5214
+    if (isset($contexte['format'])) {
5215
+        $extension = $contexte['format'];
5216
+        unset($contexte['format']);
5217
+    } else {
5218
+        $extension = 'html';
5219
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5220
+            $extension = $m[1];
5221
+        }
5222
+    }
5223
+    // recuperer le contenu produit par le squelette
5224
+    $options['raw'] = true;
5225
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5226
+
5227
+    // calculer le nom de la css
5228
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5229
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5230
+    $contexte_implicite = calculer_contexte_implicite();
5231
+
5232
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5233
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5234
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5235
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5236
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5237
+    }
5238
+    else {
5239
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5240
+        ksort($contexte);
5241
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5242
+    }
5243
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5244
+
5245
+    // mettre a jour le fichier si il n'existe pas
5246
+    // ou trop ancien
5247
+    // le dernier fichier produit est toujours suffixe par .last
5248
+    // et recopie sur le fichier cible uniquement si il change
5249
+    if (
5250
+        !file_exists($filename)
5251
+        or !file_exists($filename . '.last')
5252
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5253
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5254
+    ) {
5255
+        $contenu = $cache['texte'];
5256
+        // passer les urls en absolu si c'est une css
5257
+        if ($extension == 'css') {
5258
+            $contenu = urls_absolues_css(
5259
+                $contenu,
5260
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5261
+            );
5262
+        }
5263
+
5264
+        $comment = '';
5265
+        // ne pas insérer de commentaire sur certains formats
5266
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5267
+            $comment = "/* #PRODUIRE{fond=$fond";
5268
+            foreach ($contexte as $k => $v) {
5269
+                $comment .= ",$k=$v";
5270
+            }
5271
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5272
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5273
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5274
+        }
5275
+        // et ecrire le fichier si il change
5276
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5277
+    }
5278
+
5279
+    return timestamp($filename);
5280 5280
 }
5281 5281
 
5282 5282
 /**
@@ -5289,15 +5289,15 @@  discard block
 block discarded – undo
5289 5289
  *    $fichier auquel on a ajouté le timestamp
5290 5290
  */
5291 5291
 function timestamp($fichier) {
5292
-	if (
5293
-		!$fichier
5294
-		or !file_exists($fichier)
5295
-		or !$m = filemtime($fichier)
5296
-	) {
5297
-		return $fichier;
5298
-	}
5292
+    if (
5293
+        !$fichier
5294
+        or !file_exists($fichier)
5295
+        or !$m = filemtime($fichier)
5296
+    ) {
5297
+        return $fichier;
5298
+    }
5299 5299
 
5300
-	return "$fichier?$m";
5300
+    return "$fichier?$m";
5301 5301
 }
5302 5302
 
5303 5303
 /**
@@ -5307,11 +5307,11 @@  discard block
 block discarded – undo
5307 5307
  * @return string
5308 5308
  */
5309 5309
 function supprimer_timestamp($url) {
5310
-	if (strpos($url, '?') === false) {
5311
-		return $url;
5312
-	}
5310
+    if (strpos($url, '?') === false) {
5311
+        return $url;
5312
+    }
5313 5313
 
5314
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5314
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5315 5315
 }
5316 5316
 
5317 5317
 /**
@@ -5326,9 +5326,9 @@  discard block
 block discarded – undo
5326 5326
  * @return string
5327 5327
  */
5328 5328
 function filtre_nettoyer_titre_email_dist($titre) {
5329
-	include_spip('inc/envoyer_mail');
5329
+    include_spip('inc/envoyer_mail');
5330 5330
 
5331
-	return nettoyer_titre_email($titre);
5331
+    return nettoyer_titre_email($titre);
5332 5332
 }
5333 5333
 
5334 5334
 /**
@@ -5350,27 +5350,27 @@  discard block
 block discarded – undo
5350 5350
  * @return string
5351 5351
  */
5352 5352
 function filtre_chercher_rubrique_dist(
5353
-	$titre,
5354
-	$id_objet,
5355
-	$id_parent,
5356
-	$objet,
5357
-	$id_secteur,
5358
-	$restreint,
5359
-	$actionable = false,
5360
-	$retour_sans_cadre = false
5353
+    $titre,
5354
+    $id_objet,
5355
+    $id_parent,
5356
+    $objet,
5357
+    $id_secteur,
5358
+    $restreint,
5359
+    $actionable = false,
5360
+    $retour_sans_cadre = false
5361 5361
 ) {
5362
-	include_spip('inc/filtres_ecrire');
5362
+    include_spip('inc/filtres_ecrire');
5363 5363
 
5364
-	return chercher_rubrique(
5365
-		$titre,
5366
-		$id_objet,
5367
-		$id_parent,
5368
-		$objet,
5369
-		$id_secteur,
5370
-		$restreint,
5371
-		$actionable,
5372
-		$retour_sans_cadre
5373
-	);
5364
+    return chercher_rubrique(
5365
+        $titre,
5366
+        $id_objet,
5367
+        $id_parent,
5368
+        $objet,
5369
+        $id_secteur,
5370
+        $restreint,
5371
+        $actionable,
5372
+        $retour_sans_cadre
5373
+    );
5374 5374
 }
5375 5375
 
5376 5376
 /**
@@ -5399,56 +5399,56 @@  discard block
 block discarded – undo
5399 5399
  *     Chaîne vide si l'accès est autorisé
5400 5400
  */
5401 5401
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5402
-	if ($ok) {
5403
-		return '';
5404
-	}
5405
-
5406
-	// Vider tous les tampons
5407
-	$level = @ob_get_level();
5408
-	while ($level--) {
5409
-		@ob_end_clean();
5410
-	}
5411
-
5412
-	include_spip('inc/headers');
5413
-
5414
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5415
-	if ($url) {
5416
-		redirige_par_entete($url, '', $statut);
5417
-	}
5418
-
5419
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5420
-	if (!is_numeric($statut) and is_null($message)) {
5421
-		$message = $statut;
5422
-		$statut = 0;
5423
-	}
5424
-	if (!$message) {
5425
-		$message = '';
5426
-	}
5427
-	$statut = intval($statut);
5428
-
5429
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5430
-	if (test_espace_prive()) {
5431
-		if (!$statut or !in_array($statut, [404, 403])) {
5432
-			$statut = 403;
5433
-		}
5434
-		http_response_code(403);
5435
-		$echec = charger_fonction('403', 'exec');
5436
-		$echec($message);
5437
-	} else {
5438
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5439
-		if (!$statut) {
5440
-			$statut = 404;
5441
-		}
5442
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5443
-		http_response_code($statut);
5444
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5445
-		if ($statut >= 400) {
5446
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5447
-		}
5448
-	}
5449
-
5450
-
5451
-	exit;
5402
+    if ($ok) {
5403
+        return '';
5404
+    }
5405
+
5406
+    // Vider tous les tampons
5407
+    $level = @ob_get_level();
5408
+    while ($level--) {
5409
+        @ob_end_clean();
5410
+    }
5411
+
5412
+    include_spip('inc/headers');
5413
+
5414
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5415
+    if ($url) {
5416
+        redirige_par_entete($url, '', $statut);
5417
+    }
5418
+
5419
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5420
+    if (!is_numeric($statut) and is_null($message)) {
5421
+        $message = $statut;
5422
+        $statut = 0;
5423
+    }
5424
+    if (!$message) {
5425
+        $message = '';
5426
+    }
5427
+    $statut = intval($statut);
5428
+
5429
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5430
+    if (test_espace_prive()) {
5431
+        if (!$statut or !in_array($statut, [404, 403])) {
5432
+            $statut = 403;
5433
+        }
5434
+        http_response_code(403);
5435
+        $echec = charger_fonction('403', 'exec');
5436
+        $echec($message);
5437
+    } else {
5438
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5439
+        if (!$statut) {
5440
+            $statut = 404;
5441
+        }
5442
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5443
+        http_response_code($statut);
5444
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5445
+        if ($statut >= 400) {
5446
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5447
+        }
5448
+    }
5449
+
5450
+
5451
+    exit;
5452 5452
 }
5453 5453
 
5454 5454
 /**
@@ -5459,11 +5459,11 @@  discard block
 block discarded – undo
5459 5459
  * @return string
5460 5460
  */
5461 5461
 function filtre_compacte_dist($source, $format = null) {
5462
-	if (function_exists('minifier')) {
5463
-		return minifier($source, $format);
5464
-	}
5462
+    if (function_exists('minifier')) {
5463
+        return minifier($source, $format);
5464
+    }
5465 5465
 
5466
-	return $source;
5466
+    return $source;
5467 5467
 }
5468 5468
 
5469 5469
 
@@ -5475,31 +5475,31 @@  discard block
 block discarded – undo
5475 5475
  * @return string
5476 5476
  */
5477 5477
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5478
-	$l = strlen($passe);
5479
-
5480
-	if ($l <= 8 or !$afficher_partiellement) {
5481
-		if (!$l) {
5482
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5483
-		}
5484
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5485
-	}
5486
-
5487
-	if (is_null($portion_pourcent)) {
5488
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5489
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5490
-		}
5491
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5492
-	}
5493
-	if ($portion_pourcent >= 100) {
5494
-		return $passe;
5495
-	}
5496
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5497
-	$e = max($e, 0);
5498
-	$mid = str_pad('', $l - 2 * $e, '*');
5499
-	if ($e > 0 and strlen($mid) > 8) {
5500
-		$mid = '***...***';
5501
-	}
5502
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5478
+    $l = strlen($passe);
5479
+
5480
+    if ($l <= 8 or !$afficher_partiellement) {
5481
+        if (!$l) {
5482
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5483
+        }
5484
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5485
+    }
5486
+
5487
+    if (is_null($portion_pourcent)) {
5488
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5489
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5490
+        }
5491
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5492
+    }
5493
+    if ($portion_pourcent >= 100) {
5494
+        return $passe;
5495
+    }
5496
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5497
+    $e = max($e, 0);
5498
+    $mid = str_pad('', $l - 2 * $e, '*');
5499
+    if ($e > 0 and strlen($mid) > 8) {
5500
+        $mid = '***...***';
5501
+    }
5502
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5503 5503
 }
5504 5504
 
5505 5505
 
@@ -5520,64 +5520,64 @@  discard block
 block discarded – undo
5520 5520
  */
5521 5521
 function identifiant_slug($texte, $type = '', $options = []) {
5522 5522
 
5523
-	$original = $texte;
5524
-	$separateur = ($options['separateur'] ?? '_');
5525
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5526
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5523
+    $original = $texte;
5524
+    $separateur = ($options['separateur'] ?? '_');
5525
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5526
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5527 5527
 
5528
-	if (!function_exists('translitteration')) {
5529
-		include_spip('inc/charsets');
5530
-	}
5528
+    if (!function_exists('translitteration')) {
5529
+        include_spip('inc/charsets');
5530
+    }
5531 5531
 
5532
-	// pas de balise html
5533
-	if (strpos($texte, '<') !== false) {
5534
-		$texte = strip_tags($texte);
5535
-	}
5536
-	if (strpos($texte, '&') !== false) {
5537
-		$texte = unicode2charset($texte);
5538
-	}
5539
-	// On enlève les espaces indésirables
5540
-	$texte = trim($texte);
5532
+    // pas de balise html
5533
+    if (strpos($texte, '<') !== false) {
5534
+        $texte = strip_tags($texte);
5535
+    }
5536
+    if (strpos($texte, '&') !== false) {
5537
+        $texte = unicode2charset($texte);
5538
+    }
5539
+    // On enlève les espaces indésirables
5540
+    $texte = trim($texte);
5541 5541
 
5542
-	// On enlève les accents et cie
5543
-	$texte = translitteration($texte);
5542
+    // On enlève les accents et cie
5543
+    $texte = translitteration($texte);
5544 5544
 
5545
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5546
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5545
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5546
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5547 5547
 
5548
-	// nettoyer les doubles occurences du separateur si besoin
5549
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5550
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5551
-	}
5548
+    // nettoyer les doubles occurences du separateur si besoin
5549
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5550
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5551
+    }
5552 5552
 
5553
-	// pas de separateur au debut ni a la fin
5554
-	$texte = trim($texte, $separateur);
5553
+    // pas de separateur au debut ni a la fin
5554
+    $texte = trim($texte, $separateur);
5555 5555
 
5556
-	// en minuscules
5557
-	$texte = strtolower($texte);
5556
+    // en minuscules
5557
+    $texte = strtolower($texte);
5558 5558
 
5559
-	switch ($type) {
5560
-		case 'class':
5561
-		case 'id':
5562
-		case 'anchor':
5563
-			if (preg_match(',^\d,', $texte)) {
5564
-				$texte = substr($type, 0, 1) . $texte;
5565
-			}
5566
-	}
5559
+    switch ($type) {
5560
+        case 'class':
5561
+        case 'id':
5562
+        case 'anchor':
5563
+            if (preg_match(',^\d,', $texte)) {
5564
+                $texte = substr($type, 0, 1) . $texte;
5565
+            }
5566
+    }
5567 5567
 
5568
-	if (strlen($texte) > $longueur_maxi) {
5569
-		$texte = substr($texte, 0, $longueur_maxi);
5570
-	}
5568
+    if (strlen($texte) > $longueur_maxi) {
5569
+        $texte = substr($texte, 0, $longueur_maxi);
5570
+    }
5571 5571
 
5572
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5573
-		if (preg_match(',^\d,', $texte)) {
5574
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5575
-		}
5576
-		$texte .= $separateur . md5($original);
5577
-		$texte = substr($texte, 0, $longueur_mini);
5578
-	}
5572
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5573
+        if (preg_match(',^\d,', $texte)) {
5574
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5575
+        }
5576
+        $texte .= $separateur . md5($original);
5577
+        $texte = substr($texte, 0, $longueur_mini);
5578
+    }
5579 5579
 
5580
-	return $texte;
5580
+    return $texte;
5581 5581
 }
5582 5582
 
5583 5583
 
@@ -5598,11 +5598,11 @@  discard block
 block discarded – undo
5598 5598
  * @exemple `<:info_maximum|label_nettoyer:>`
5599 5599
  */
5600 5600
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5601
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5602
-	if ($ucfirst) {
5603
-		$label = spip_ucfirst($label);
5604
-	}
5605
-	return $label;
5601
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5602
+    if ($ucfirst) {
5603
+        $label = spip_ucfirst($label);
5604
+    }
5605
+    return $label;
5606 5606
 }
5607 5607
 
5608 5608
 /**
@@ -5615,8 +5615,8 @@  discard block
 block discarded – undo
5615 5615
  * @exemple `<:info_maximum|label_ponctuer:>`
5616 5616
  */
5617 5617
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5618
-	$label = label_nettoyer($text, $ucfirst);
5619
-	return _T('label_ponctuer', ['label' => $label]);
5618
+    $label = label_nettoyer($text, $ucfirst);
5619
+    return _T('label_ponctuer', ['label' => $label]);
5620 5620
 }
5621 5621
 
5622 5622
 
@@ -5629,19 +5629,19 @@  discard block
 block discarded – undo
5629 5629
  * @return array
5630 5630
  */
5631 5631
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5632
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5633
-		return [];
5634
-	}
5632
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5633
+        return [];
5634
+    }
5635 5635
 
5636
-	// compatibilite signature inversee
5637
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5638
-		[$objet, $id_objet] = [$id_objet, $objet];
5639
-	}
5636
+    // compatibilite signature inversee
5637
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5638
+        [$objet, $id_objet] = [$id_objet, $objet];
5639
+    }
5640 5640
 
5641
-	if (!function_exists($fonction)) {
5642
-		include_spip('base/objets');
5643
-	}
5644
-	return $fonction($objet, $id_objet);
5641
+    if (!function_exists($fonction)) {
5642
+        include_spip('base/objets');
5643
+    }
5644
+    return $fonction($objet, $id_objet);
5645 5645
 }
5646 5646
 
5647 5647
 
@@ -5656,7 +5656,7 @@  discard block
 block discarded – undo
5656 5656
  * @return array
5657 5657
  */
5658 5658
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5659
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5659
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5660 5660
 }
5661 5661
 
5662 5662
 /**
@@ -5670,7 +5670,7 @@  discard block
 block discarded – undo
5670 5670
  * @return array
5671 5671
  */
5672 5672
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5673
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5673
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5674 5674
 }
5675 5675
 
5676 5676
 /**
@@ -5684,7 +5684,7 @@  discard block
 block discarded – undo
5684 5684
  * @return array
5685 5685
  */
5686 5686
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5687
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5687
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5688 5688
 }
5689 5689
 
5690 5690
 /**
@@ -5698,5 +5698,5 @@  discard block
 block discarded – undo
5698 5698
  * @return array
5699 5699
  */
5700 5700
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5701
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5701
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5702 5702
 }
Please login to merge, or discard this patch.