Completed
Push — master ( 30a191...ec6233 )
by cam
01:11
created
ecrire/public/debusquer.php 1 patch
Indentation   +682 added lines, -682 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
 include_spip('public/decompiler');
@@ -66,136 +66,136 @@  discard block
 block discarded – undo
66 66
  *     - string si $message à false.
67 67
  **/
68 68
 function public_debusquer_dist($message = '', $lieu = '', $opt = []) {
69
-	static $tableau_des_erreurs = [];
70
-
71
-	// Pour des tests unitaires, pouvoir récupérer les erreurs générées
72
-	if (isset($opt['erreurs'])) {
73
-		if ($opt['erreurs'] == 'get') {
74
-			return $tableau_des_erreurs;
75
-		}
76
-		if ($opt['erreurs'] == 'reset') {
77
-			$tableau_des_erreurs = [];
78
-
79
-			return true;
80
-		}
81
-	}
82
-
83
-	// Erreur ou appel final ?
84
-	if ($message) {
85
-		$message = debusquer_compose_message($message);
86
-		$tableau_des_erreurs[] = [$message, $lieu];
87
-		set_request('var_mode', 'debug');
88
-		$GLOBALS['bouton_admin_debug'] = true;
89
-		// Permettre a la compil de continuer
90
-		if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) {
91
-			$lieu->code = "''";
92
-		}
93
-		// forcer l'appel au debusqueur en cas de boucles infernales
94
-		$urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS);
95
-		if (!$urgence) {
96
-			return;
97
-		}
98
-	}
99
-	if (empty($GLOBALS['debug_objets']['principal'])) {
100
-		// espace public ?
101
-		if (isset($GLOBALS['fond'])) {
102
-			$GLOBALS['debug_objets']['principal'] = $GLOBALS['fond'];
103
-		}
104
-	}
105
-
106
-	include_spip('inc/autoriser');
107
-	if (!autoriser('debug')) {
108
-		return;
109
-	}
110
-	include_spip('inc/headers');
111
-	include_spip('inc/filtres');
112
-
113
-	// en cas de squelette inclus,  virer le code de l'incluant:
114
-	// - il contient souvent une Div restreignant la largeur a 3 fois rien
115
-	// - ca fait 2 headers !
116
-	// sauf si l'on se trouve deja dans un flux compresse (plugin compresseur
117
-	// actif par exemple)
118
-	if (
119
-		ob_get_length()
120
-		and
121
-		!in_array('ob_gzhandler', ob_get_status())
122
-	) {
123
-		ob_end_clean();
124
-	}
125
-
126
-	lang_select($GLOBALS['visiteur_session']['lang']);
127
-	$fonc = _request('var_mode_objet');
128
-	$mode = _request('var_mode_affiche');
129
-	$self = str_replace("\\'", ''', self());
130
-	$self = parametre_url($self, 'var_mode', 'debug');
131
-
132
-	$res = debusquer_bandeau($tableau_des_erreurs)
133
-		. '<br />'
134
-		. debusquer_squelette($fonc, $mode, $self);
135
-
136
-	if (!_DIR_RESTREINT or headers_sent()) {
137
-		return $res;
138
-	}
139
-	if ($tableau_des_erreurs) {
140
-		http_response_code(503);
141
-	}
142
-
143
-	http_no_cache();
144
-	if (isset($_GET['var_profile'])) {
145
-		$titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', '');
146
-		$titre = parametre_url($titre, 'var_mode', '');
147
-	} else {
148
-		if (!$fonc) {
149
-			$fonc = $GLOBALS['debug_objets']['principal'];
150
-		}
151
-		$titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : ''));
152
-	}
153
-	if ($message === false) {
154
-		lang_select();
155
-
156
-		return debusquer_entete($titre, $res);
157
-	} else {
158
-		echo debusquer_entete($titre, $res);
159
-	}
160
-	exit;
69
+    static $tableau_des_erreurs = [];
70
+
71
+    // Pour des tests unitaires, pouvoir récupérer les erreurs générées
72
+    if (isset($opt['erreurs'])) {
73
+        if ($opt['erreurs'] == 'get') {
74
+            return $tableau_des_erreurs;
75
+        }
76
+        if ($opt['erreurs'] == 'reset') {
77
+            $tableau_des_erreurs = [];
78
+
79
+            return true;
80
+        }
81
+    }
82
+
83
+    // Erreur ou appel final ?
84
+    if ($message) {
85
+        $message = debusquer_compose_message($message);
86
+        $tableau_des_erreurs[] = [$message, $lieu];
87
+        set_request('var_mode', 'debug');
88
+        $GLOBALS['bouton_admin_debug'] = true;
89
+        // Permettre a la compil de continuer
90
+        if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) {
91
+            $lieu->code = "''";
92
+        }
93
+        // forcer l'appel au debusqueur en cas de boucles infernales
94
+        $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS);
95
+        if (!$urgence) {
96
+            return;
97
+        }
98
+    }
99
+    if (empty($GLOBALS['debug_objets']['principal'])) {
100
+        // espace public ?
101
+        if (isset($GLOBALS['fond'])) {
102
+            $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond'];
103
+        }
104
+    }
105
+
106
+    include_spip('inc/autoriser');
107
+    if (!autoriser('debug')) {
108
+        return;
109
+    }
110
+    include_spip('inc/headers');
111
+    include_spip('inc/filtres');
112
+
113
+    // en cas de squelette inclus,  virer le code de l'incluant:
114
+    // - il contient souvent une Div restreignant la largeur a 3 fois rien
115
+    // - ca fait 2 headers !
116
+    // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur
117
+    // actif par exemple)
118
+    if (
119
+        ob_get_length()
120
+        and
121
+        !in_array('ob_gzhandler', ob_get_status())
122
+    ) {
123
+        ob_end_clean();
124
+    }
125
+
126
+    lang_select($GLOBALS['visiteur_session']['lang']);
127
+    $fonc = _request('var_mode_objet');
128
+    $mode = _request('var_mode_affiche');
129
+    $self = str_replace("\\'", '&#39;', self());
130
+    $self = parametre_url($self, 'var_mode', 'debug');
131
+
132
+    $res = debusquer_bandeau($tableau_des_erreurs)
133
+        . '<br />'
134
+        . debusquer_squelette($fonc, $mode, $self);
135
+
136
+    if (!_DIR_RESTREINT or headers_sent()) {
137
+        return $res;
138
+    }
139
+    if ($tableau_des_erreurs) {
140
+        http_response_code(503);
141
+    }
142
+
143
+    http_no_cache();
144
+    if (isset($_GET['var_profile'])) {
145
+        $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', '');
146
+        $titre = parametre_url($titre, 'var_mode', '');
147
+    } else {
148
+        if (!$fonc) {
149
+            $fonc = $GLOBALS['debug_objets']['principal'];
150
+        }
151
+        $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : ''));
152
+    }
153
+    if ($message === false) {
154
+        lang_select();
155
+
156
+        return debusquer_entete($titre, $res);
157
+    } else {
158
+        echo debusquer_entete($titre, $res);
159
+    }
160
+    exit;
161 161
 }
162 162
 
163 163
 function debusquer_compose_message($msg) {
164
-	if (is_array($msg)) {
165
-		// si c'est un texte, c'est une traduction a faire, mais
166
-		// sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments)
167
-		if (!is_numeric($msg[0]) and count($msg) == 2) {
168
-			// message avec argument: instancier
169
-			$msg = _T($msg[0], $msg[1], 'spip-debug-arg');
170
-		} else {
171
-			// message SQL: interpreter
172
-			$msg = debusquer_requete($msg);
173
-		}
174
-	}
175
-	// FIXME: le fond n'est pas la si on n'est pas dans un squelette
176
-	// cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur
177
-	$fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : '';
178
-	// une erreur critique sort $message en array
179
-	$debug = is_array($msg) ? $msg[1] : $msg;
180
-	spip_log('Debug: ' . $debug . ' (' . $fond . ')');
181
-
182
-	return $msg;
164
+    if (is_array($msg)) {
165
+        // si c'est un texte, c'est une traduction a faire, mais
166
+        // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments)
167
+        if (!is_numeric($msg[0]) and count($msg) == 2) {
168
+            // message avec argument: instancier
169
+            $msg = _T($msg[0], $msg[1], 'spip-debug-arg');
170
+        } else {
171
+            // message SQL: interpreter
172
+            $msg = debusquer_requete($msg);
173
+        }
174
+    }
175
+    // FIXME: le fond n'est pas la si on n'est pas dans un squelette
176
+    // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur
177
+    $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : '';
178
+    // une erreur critique sort $message en array
179
+    $debug = is_array($msg) ? $msg[1] : $msg;
180
+    spip_log('Debug: ' . $debug . ' (' . $fond . ')');
181
+
182
+    return $msg;
183 183
 }
184 184
 
185 185
 function debusquer_bandeau($erreurs) {
186 186
 
187
-	if (!empty($erreurs)) {
188
-		$n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')];
187
+    if (!empty($erreurs)) {
188
+        $n = [count($erreurs) . ' ' . _T('zbug_erreur_squelette')];
189 189
 
190
-		return debusquer_navigation($erreurs, $n);
191
-	} elseif (!empty($GLOBALS['tableau_des_temps'])) {
192
-		include_spip('public/tracer');
193
-		list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']);
190
+        return debusquer_navigation($erreurs, $n);
191
+    } elseif (!empty($GLOBALS['tableau_des_temps'])) {
192
+        include_spip('public/tracer');
193
+        list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']);
194 194
 
195
-		return debusquer_navigation($temps, $nav, 'debug-profile');
196
-	} else {
197
-		return '';
198
-	}
195
+        return debusquer_navigation($temps, $nav, 'debug-profile');
196
+    } else {
197
+        return '';
198
+    }
199 199
 }
200 200
 
201 201
 /**
@@ -205,42 +205,42 @@  discard block
 block discarded – undo
205 205
  * @return string Code HTML
206 206
  **/
207 207
 function debusquer_contexte($env) {
208
-	if (is_string($env) and is_array($env_tab = @unserialize($env))) {
209
-		$env = $env_tab;
210
-	}
211
-
212
-	if (!$env) {
213
-		return '';
214
-	}
215
-	$res = '';
216
-	foreach ($env as $nom => $valeur) {
217
-		if (is_array($valeur)) {
218
-			$valeur_simple = [];
219
-			foreach ($valeur as $v) {
220
-				if (is_array($v)) {
221
-					$valeur_simple[] = 'array:' . count($v);
222
-				} elseif (is_object($v)) {
223
-					$valeur_simple[] = get_class($v);
224
-				} elseif (is_string($v)) {
225
-					$valeur_simple[] = "'" . $v . "'";
226
-				} else {
227
-					$valeur_simple[] = $v;
228
-				}
229
-			}
230
-			$n = count($valeur);
231
-			$valeur = (($n > 3) ? 'array:' . $n . ' ' : '');
232
-			$valeur .= '[' . join(', ', $valeur_simple) . ']';
233
-		} elseif (is_object($valeur)) {
234
-			$valeur = get_class($valeur);
235
-		} elseif (is_string($valeur)) {
236
-			$valeur = "'" . $valeur . "'";
237
-		}
238
-		$res .= "\n<tr><td><strong>" . nl2br(entites_html($nom))
239
-			. '</strong></td><td>:&nbsp;' . nl2br(entites_html($valeur))
240
-			. "</td></tr>\n";
241
-	}
242
-
243
-	return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n";
208
+    if (is_string($env) and is_array($env_tab = @unserialize($env))) {
209
+        $env = $env_tab;
210
+    }
211
+
212
+    if (!$env) {
213
+        return '';
214
+    }
215
+    $res = '';
216
+    foreach ($env as $nom => $valeur) {
217
+        if (is_array($valeur)) {
218
+            $valeur_simple = [];
219
+            foreach ($valeur as $v) {
220
+                if (is_array($v)) {
221
+                    $valeur_simple[] = 'array:' . count($v);
222
+                } elseif (is_object($v)) {
223
+                    $valeur_simple[] = get_class($v);
224
+                } elseif (is_string($v)) {
225
+                    $valeur_simple[] = "'" . $v . "'";
226
+                } else {
227
+                    $valeur_simple[] = $v;
228
+                }
229
+            }
230
+            $n = count($valeur);
231
+            $valeur = (($n > 3) ? 'array:' . $n . ' ' : '');
232
+            $valeur .= '[' . join(', ', $valeur_simple) . ']';
233
+        } elseif (is_object($valeur)) {
234
+            $valeur = get_class($valeur);
235
+        } elseif (is_string($valeur)) {
236
+            $valeur = "'" . $valeur . "'";
237
+        }
238
+        $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom))
239
+            . '</strong></td><td>:&nbsp;' . nl2br(entites_html($valeur))
240
+            . "</td></tr>\n";
241
+    }
242
+
243
+    return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n";
244 244
 }
245 245
 
246 246
 // Affichage du tableau des erreurs ou des temps de calcul
@@ -248,66 +248,66 @@  discard block
 block discarded – undo
248 248
 
249 249
 function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') {
250 250
 
251
-	if (_request('exec') == 'valider_xml') {
252
-		return '';
253
-	}
254
-	$GLOBALS['bouton_admin_debug'] = true;
255
-	$res = '';
256
-	$href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug'));
257
-	foreach ($tableau as $i => $err) {
258
-		$boucle = $ligne = $skel = '';
259
-		list($msg, $lieu) = $err;
260
-		if (is_object($lieu)) {
261
-			$ligne = $lieu->ligne;
262
-			$boucle = $lieu->id_boucle ? $lieu->id_boucle : '';
263
-			if (isset($lieu->descr['nom'])) {
264
-				$nom_code = $lieu->descr['nom'];
265
-				$skel = $lieu->descr['sourcefile'];
266
-				$h2 = parametre_url($href, 'var_mode_objet', $nom_code);
267
-				$h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne;
268
-				$skel = "<a href='$h3'><b>$skel</b></a>";
269
-				if ($boucle) {
270
-					$h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle');
271
-					$boucle = "<a href='$h3'><b>$boucle</b></a>";
272
-				}
273
-			}
274
-		}
275
-
276
-		$j = ($i + 1);
277
-		$res .= "<tr id='req$j'><td style='text-align: right'>"
278
-			. $j
279
-			. "&nbsp;</td><td style='text-align: left'>"
280
-			. (is_array($msg) ? implode('', $msg) : $msg)
281
-			. "</td><td style='text-align: left'>"
282
-			. ($skel ? $skel : '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;')
283
-			. "</td><td class='spip-debug-arg' style='text-align: left'>"
284
-			. ($boucle ? $boucle : '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;')
285
-			. "</td><td style='text-align: right'>"
286
-			. $ligne
287
-			. "</td></tr>\n";
288
-	}
289
-
290
-	return "\n<table id='$id'>"
291
-	. "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">"
292
-	. $caption[0]
251
+    if (_request('exec') == 'valider_xml') {
252
+        return '';
253
+    }
254
+    $GLOBALS['bouton_admin_debug'] = true;
255
+    $res = '';
256
+    $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug'));
257
+    foreach ($tableau as $i => $err) {
258
+        $boucle = $ligne = $skel = '';
259
+        list($msg, $lieu) = $err;
260
+        if (is_object($lieu)) {
261
+            $ligne = $lieu->ligne;
262
+            $boucle = $lieu->id_boucle ? $lieu->id_boucle : '';
263
+            if (isset($lieu->descr['nom'])) {
264
+                $nom_code = $lieu->descr['nom'];
265
+                $skel = $lieu->descr['sourcefile'];
266
+                $h2 = parametre_url($href, 'var_mode_objet', $nom_code);
267
+                $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne;
268
+                $skel = "<a href='$h3'><b>$skel</b></a>";
269
+                if ($boucle) {
270
+                    $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle');
271
+                    $boucle = "<a href='$h3'><b>$boucle</b></a>";
272
+                }
273
+            }
274
+        }
275
+
276
+        $j = ($i + 1);
277
+        $res .= "<tr id='req$j'><td style='text-align: right'>"
278
+            . $j
279
+            . "&nbsp;</td><td style='text-align: left'>"
280
+            . (is_array($msg) ? implode('', $msg) : $msg)
281
+            . "</td><td style='text-align: left'>"
282
+            . ($skel ? $skel : '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;')
283
+            . "</td><td class='spip-debug-arg' style='text-align: left'>"
284
+            . ($boucle ? $boucle : '&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;')
285
+            . "</td><td style='text-align: right'>"
286
+            . $ligne
287
+            . "</td></tr>\n";
288
+    }
289
+
290
+    return "\n<table id='$id'>"
291
+    . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">"
292
+    . $caption[0]
293 293
 ## aide locale courte a ecrire, avec lien vers une grosse page de documentation
294 294
 #		aider('erreur_compilation'),
295
-	. '</caption>'
296
-	//  fausse caption du chrono (mais vraie nav)
297
-	. (!empty($caption[1]) ? $caption[1] : '')
298
-	. '<tr><th>'
299
-	. _T('numero')
300
-	. '</th><th>'
301
-	. _T('public:message')
302
-	. '</th><th>'
303
-	. _T('squelette')
304
-	. '</th><th>'
305
-	. _T('zbug_boucle')
306
-	. '</th><th>'
307
-	. _T('ligne')
308
-	. '</th></tr>'
309
-	. $res
310
-	. '</table>';
295
+    . '</caption>'
296
+    //  fausse caption du chrono (mais vraie nav)
297
+    . (!empty($caption[1]) ? $caption[1] : '')
298
+    . '<tr><th>'
299
+    . _T('numero')
300
+    . '</th><th>'
301
+    . _T('public:message')
302
+    . '</th><th>'
303
+    . _T('squelette')
304
+    . '</th><th>'
305
+    . _T('zbug_boucle')
306
+    . '</th><th>'
307
+    . _T('ligne')
308
+    . '</th></tr>'
309
+    . $res
310
+    . '</table>';
311 311
 }
312 312
 
313 313
 
@@ -327,124 +327,124 @@  discard block
 block discarded – undo
327 327
  *    ou un tableau si l'erreur est critique
328 328
  **/
329 329
 function debusquer_requete($message) {
330
-	list($errno, $msg, $query) = $message;
331
-
332
-	// FIXME: ces écritures mélangent divers syntaxe des moteurs SQL
333
-	// il serait plus prudent certainement d'avoir une fonction d'analyse par moteur
334
-	if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) {
335
-		$errno = $regs[2];
336
-	} elseif (
337
-		is_numeric($errno) and ($errno == 1030 or $errno <= 1026)
338
-		and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs)
339
-	) {
340
-		$errno = $regs[1];
341
-	}
342
-
343
-	// Erreur systeme
344
-	if (is_numeric($errno) and $errno > 0 and $errno < 200) {
345
-		$retour = '<tt><br /><br /><blink>'
346
-			. _T('info_erreur_systeme', ['errsys' => $errno])
347
-			. "</blink><br />\n<b>"
348
-			. _T(
349
-				'info_erreur_systeme2',
350
-				['script' => generer_url_ecrire('base_repair')]
351
-			)
352
-			. '</b><br />';
353
-		spip_log("Erreur systeme $errno");
354
-
355
-		return [$retour, ''];
356
-	}
357
-
358
-	// Requete erronee
359
-	$err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n"
360
-		. spip_htmlspecialchars($msg)
361
-		. "\n<br /><span style='color: red'><b>"
362
-		. spip_htmlspecialchars($query)
363
-		. '</b></span></tt><br />';
364
-
365
-	//. aider('erreur_mysql');
366
-
367
-	return $err;
330
+    list($errno, $msg, $query) = $message;
331
+
332
+    // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL
333
+    // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur
334
+    if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) {
335
+        $errno = $regs[2];
336
+    } elseif (
337
+        is_numeric($errno) and ($errno == 1030 or $errno <= 1026)
338
+        and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs)
339
+    ) {
340
+        $errno = $regs[1];
341
+    }
342
+
343
+    // Erreur systeme
344
+    if (is_numeric($errno) and $errno > 0 and $errno < 200) {
345
+        $retour = '<tt><br /><br /><blink>'
346
+            . _T('info_erreur_systeme', ['errsys' => $errno])
347
+            . "</blink><br />\n<b>"
348
+            . _T(
349
+                'info_erreur_systeme2',
350
+                ['script' => generer_url_ecrire('base_repair')]
351
+            )
352
+            . '</b><br />';
353
+        spip_log("Erreur systeme $errno");
354
+
355
+        return [$retour, ''];
356
+    }
357
+
358
+    // Requete erronee
359
+    $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n"
360
+        . spip_htmlspecialchars($msg)
361
+        . "\n<br /><span style='color: red'><b>"
362
+        . spip_htmlspecialchars($query)
363
+        . '</b></span></tt><br />';
364
+
365
+    //. aider('erreur_mysql');
366
+
367
+    return $err;
368 368
 }
369 369
 
370 370
 
371 371
 // https://code.spip.net/@trouve_boucle_debug
372 372
 function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') {
373 373
 
374
-	$id = $nom . $boucle;
375
-	if (is_array($GLOBALS['debug_objets']['sequence'][$id])) {
376
-		foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) {
377
-			if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) {
378
-				$y = substr_count($v[0], "\n");
379
-			} else {
380
-				if ($v[1][0] == '#') { // balise dynamique
381
-				$incl = $GLOBALS['debug_objets']['resultat'][$v[2]];
382
-				} else // inclusion
383
-				{
384
-					$incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])];
385
-				}
386
-				$y = substr_count($incl, "\n")
387
-					+ substr_count($r[1], "\n")
388
-					+ substr_count($r[3], "\n");
389
-			}
390
-			if ($n <= ($y + $debut)) {
391
-				if ($v[1][0] == '?') {
392
-					return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1));
393
-				} elseif ($v[1][0] == '!') {
394
-					if ($incl = trouve_squelette_inclus($v[1])) {
395
-						return trouve_boucle_debug($n, $incl, $debut);
396
-					}
397
-				}
398
-
399
-				return [$nom, $boucle, $v[2] - 1 + $n - $debut];
400
-			}
401
-			$debut += $y;
402
-		}
403
-	}
404
-
405
-	return [$nom, $boucle, $n - $debut];
374
+    $id = $nom . $boucle;
375
+    if (is_array($GLOBALS['debug_objets']['sequence'][$id])) {
376
+        foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) {
377
+            if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) {
378
+                $y = substr_count($v[0], "\n");
379
+            } else {
380
+                if ($v[1][0] == '#') { // balise dynamique
381
+                $incl = $GLOBALS['debug_objets']['resultat'][$v[2]];
382
+                } else // inclusion
383
+                {
384
+                    $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])];
385
+                }
386
+                $y = substr_count($incl, "\n")
387
+                    + substr_count($r[1], "\n")
388
+                    + substr_count($r[3], "\n");
389
+            }
390
+            if ($n <= ($y + $debut)) {
391
+                if ($v[1][0] == '?') {
392
+                    return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1));
393
+                } elseif ($v[1][0] == '!') {
394
+                    if ($incl = trouve_squelette_inclus($v[1])) {
395
+                        return trouve_boucle_debug($n, $incl, $debut);
396
+                    }
397
+                }
398
+
399
+                return [$nom, $boucle, $v[2] - 1 + $n - $debut];
400
+            }
401
+            $debut += $y;
402
+        }
403
+    }
404
+
405
+    return [$nom, $boucle, $n - $debut];
406 406
 }
407 407
 
408 408
 // https://code.spip.net/@trouve_squelette_inclus
409 409
 function trouve_squelette_inclus($script) {
410 410
 
411
-	preg_match('/include\(.(.*).php3?.\);/', $script, $reg);
412
-	// si le script X.php n'est pas ecrire/public.php
413
-	// on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux)
414
-	if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond'
415
-	if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page'
416
-		if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) {
417
-				$reg[1] = 'inconnu';
418
-		}
419
-	}
420
-	}
421
-	$incl = ',' . $reg[1] . '[.]\w$,';
422
-
423
-	foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) {
424
-		if (preg_match($incl, $v)) {
425
-			return $k;
426
-		}
427
-	}
428
-
429
-	return '';
411
+    preg_match('/include\(.(.*).php3?.\);/', $script, $reg);
412
+    // si le script X.php n'est pas ecrire/public.php
413
+    // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux)
414
+    if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond'
415
+    if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page'
416
+        if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) {
417
+                $reg[1] = 'inconnu';
418
+        }
419
+    }
420
+    }
421
+    $incl = ',' . $reg[1] . '[.]\w$,';
422
+
423
+    foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) {
424
+        if (preg_match($incl, $v)) {
425
+            return $k;
426
+        }
427
+    }
428
+
429
+    return '';
430 430
 }
431 431
 
432 432
 // https://code.spip.net/@reference_boucle_debug
433 433
 function reference_boucle_debug($n, $nom, $self) {
434
-	list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom);
435
-
436
-	if (!$boucle) {
437
-		return !$ligne ? '' :
438
-			(' (' .
439
-				(($nom != $skel) ? _T('squelette_inclus_ligne') :
440
-					_T('squelette_ligne')) .
441
-				" <a href='$self&amp;var_mode_objet=$skel&amp;var_mode_affiche=squelette&amp;var_mode_ligne=$ligne#L$ligne'>$ligne</a>)");
442
-	} else {
443
-		$self .= "&amp;var_mode_objet=$skel$boucle&amp;var_mode_affiche=boucle";
444
-
445
-		return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" :
446
-			" (boucle $boucle ligne\n<a href='$self&amp;var_mode_ligne=$ligne#L$ligne'>$ligne</a>)";
447
-	}
434
+    list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom);
435
+
436
+    if (!$boucle) {
437
+        return !$ligne ? '' :
438
+            (' (' .
439
+                (($nom != $skel) ? _T('squelette_inclus_ligne') :
440
+                    _T('squelette_ligne')) .
441
+                " <a href='$self&amp;var_mode_objet=$skel&amp;var_mode_affiche=squelette&amp;var_mode_ligne=$ligne#L$ligne'>$ligne</a>)");
442
+    } else {
443
+        $self .= "&amp;var_mode_objet=$skel$boucle&amp;var_mode_affiche=boucle";
444
+
445
+        return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" :
446
+            " (boucle $boucle ligne\n<a href='$self&amp;var_mode_ligne=$ligne#L$ligne'>$ligne</a>)";
447
+    }
448 448
 }
449 449
 
450 450
 // affiche un texte avec numero de ligne et ancre.
@@ -452,397 +452,397 @@  discard block
 block discarded – undo
452 452
 // https://code.spip.net/@ancre_texte
453 453
 function ancre_texte($texte, $fautifs = [], $nocpt = false) {
454 454
 
455
-	$var_mode_ligne = _request('var_mode_ligne');
456
-	if ($var_mode_ligne) {
457
-		$fautifs[] = [$var_mode_ligne];
458
-	}
459
-	$res = '';
460
-
461
-	$s = highlight_string($texte, true);
462
-	if (substr($s, 0, 6) == '<code>') {
463
-		$s = substr($s, 6);
464
-		$res = '<code>';
465
-	}
466
-
467
-	$s = preg_replace(
468
-		',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,',
469
-		'<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>',
470
-		$s
471
-	);
472
-
473
-
474
-	$tableau = explode('<br />', $s);
475
-
476
-	$format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n";
477
-
478
-	$format10 = str_replace('white', 'lightgrey', $format);
479
-	$formaterr = 'color: red;';
480
-	$i = 1;
481
-	$flignes = [];
482
-	$loc = [0, 0];
483
-	foreach ($fautifs as $lc) {
484
-		if (is_array($lc)) {
485
-			$l = array_shift($lc);
486
-			$flignes[$l] = $lc;
487
-		} else {
488
-			$flignes[$lc] = $loc;
489
-		}
490
-	}
491
-
492
-	$ancre = md5($texte);
493
-	foreach ($tableau as $ligne) {
494
-		if (isset($flignes[$i])) {
495
-			$ligne = str_replace('&nbsp;', ' ', $ligne);
496
-			$indexmesg = $flignes[$i][1];
497
-			$err = textebrut($flignes[$i][2]);
498
-			// tentative de pointer sur la colonne fautive;
499
-			// marche pas car highlight_string rajoute des entites. A revoir.
500
-			// $m = $flignes[$i][0];
501
-			// $ligne = substr($ligne, 0, $m-1) .
502
-			// sprintf($formaterr, substr($ligne,$m));
503
-			$bg = $formaterr;
504
-		} else {
505
-			$indexmesg = $ancre;
506
-			$err = $bg = '';
507
-		}
508
-		$res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne);
509
-		$i++;
510
-	}
511
-
512
-	return "<div id='T$ancre'>"
513
-	. '<div onclick="'
514
-	. "jQuery(this).parent().find('a').toggle();"
515
-	. '" title="'
516
-	. _T('masquer_colonne')
517
-	. '" style="cursor: pointer;">'
518
-	. ($nocpt ? '' : _T('info_numero_abbreviation'))
519
-	. '</div>
455
+    $var_mode_ligne = _request('var_mode_ligne');
456
+    if ($var_mode_ligne) {
457
+        $fautifs[] = [$var_mode_ligne];
458
+    }
459
+    $res = '';
460
+
461
+    $s = highlight_string($texte, true);
462
+    if (substr($s, 0, 6) == '<code>') {
463
+        $s = substr($s, 6);
464
+        $res = '<code>';
465
+    }
466
+
467
+    $s = preg_replace(
468
+        ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,',
469
+        '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>',
470
+        $s
471
+    );
472
+
473
+
474
+    $tableau = explode('<br />', $s);
475
+
476
+    $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n";
477
+
478
+    $format10 = str_replace('white', 'lightgrey', $format);
479
+    $formaterr = 'color: red;';
480
+    $i = 1;
481
+    $flignes = [];
482
+    $loc = [0, 0];
483
+    foreach ($fautifs as $lc) {
484
+        if (is_array($lc)) {
485
+            $l = array_shift($lc);
486
+            $flignes[$l] = $lc;
487
+        } else {
488
+            $flignes[$lc] = $loc;
489
+        }
490
+    }
491
+
492
+    $ancre = md5($texte);
493
+    foreach ($tableau as $ligne) {
494
+        if (isset($flignes[$i])) {
495
+            $ligne = str_replace('&nbsp;', ' ', $ligne);
496
+            $indexmesg = $flignes[$i][1];
497
+            $err = textebrut($flignes[$i][2]);
498
+            // tentative de pointer sur la colonne fautive;
499
+            // marche pas car highlight_string rajoute des entites. A revoir.
500
+            // $m = $flignes[$i][0];
501
+            // $ligne = substr($ligne, 0, $m-1) .
502
+            // sprintf($formaterr, substr($ligne,$m));
503
+            $bg = $formaterr;
504
+        } else {
505
+            $indexmesg = $ancre;
506
+            $err = $bg = '';
507
+        }
508
+        $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne);
509
+        $i++;
510
+    }
511
+
512
+    return "<div id='T$ancre'>"
513
+    . '<div onclick="'
514
+    . "jQuery(this).parent().find('a').toggle();"
515
+    . '" title="'
516
+    . _T('masquer_colonne')
517
+    . '" style="cursor: pointer;">'
518
+    . ($nocpt ? '' : _T('info_numero_abbreviation'))
519
+    . '</div>
520 520
 	' . $res . "</div>\n";
521 521
 }
522 522
 
523 523
 // l'environnement graphique du debuggueur
524 524
 
525 525
 function debusquer_squelette($fonc, $mode, $self) {
526
-	$texte = '';
527
-
528
-	if ($mode !== 'validation') {
529
-		if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) {
530
-			$res = "<div id='spip-boucles'>\n"
531
-				. debusquer_navigation_squelettes($self)
532
-				. '</div>';
533
-		} else {
534
-			$res = '';
535
-		}
536
-		if ($fonc) {
537
-			$id = " id='$fonc'";
538
-			if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) {
539
-				list($legend, $texte, $res2) = debusquer_source($fonc, $mode);
540
-				$texte .= $res2;
541
-			} elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) {
542
-				$legend = _T('zbug_' . $mode);
543
-				$texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout'];
544
-				$texte = ancre_texte($texte, ['', '']);
545
-			}
546
-		} else {
547
-			if (strlen(trim($res))) {
548
-				return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>";
549
-			} else {
550
-				// cas de l'appel sur erreur: montre la page
551
-				return isset($GLOBALS['debug_objets']['resultat']['tout'])
552
-					? $GLOBALS['debug_objets']['resultat']['tout']
553
-					: '';
554
-			}
555
-		}
556
-	} else {
557
-		$valider = charger_fonction('valider', 'xml');
558
-		$val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']);
559
-		// Si erreur, signaler leur nombre dans le formulaire admin
560
-		$GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : '';
561
-		list($texte, $err) = emboite_texte($val, $fonc, $self);
562
-		if ($err === false) {
563
-			$err = _T('impossible');
564
-		} elseif ($err === true) {
565
-			$err = _T('correcte');
566
-		} else {
567
-			$err = ": $err";
568
-		}
569
-		$legend = _T('validation') . ' ' . $err;
570
-		$res = $id = '';
571
-	}
572
-
573
-	return !trim($texte) ? '' : (
574
-		"<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res"
575
-		. "<div id='debug_boucle'><fieldset$id><legend>"
576
-		. "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> &#8593; "
577
-		. ($legend ? $legend : $mode)
578
-		. '</a></legend>'
579
-		. $texte
580
-		. '</fieldset></div>'
581
-		. '</div>');
526
+    $texte = '';
527
+
528
+    if ($mode !== 'validation') {
529
+        if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) {
530
+            $res = "<div id='spip-boucles'>\n"
531
+                . debusquer_navigation_squelettes($self)
532
+                . '</div>';
533
+        } else {
534
+            $res = '';
535
+        }
536
+        if ($fonc) {
537
+            $id = " id='$fonc'";
538
+            if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) {
539
+                list($legend, $texte, $res2) = debusquer_source($fonc, $mode);
540
+                $texte .= $res2;
541
+            } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) {
542
+                $legend = _T('zbug_' . $mode);
543
+                $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout'];
544
+                $texte = ancre_texte($texte, ['', '']);
545
+            }
546
+        } else {
547
+            if (strlen(trim($res))) {
548
+                return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>";
549
+            } else {
550
+                // cas de l'appel sur erreur: montre la page
551
+                return isset($GLOBALS['debug_objets']['resultat']['tout'])
552
+                    ? $GLOBALS['debug_objets']['resultat']['tout']
553
+                    : '';
554
+            }
555
+        }
556
+    } else {
557
+        $valider = charger_fonction('valider', 'xml');
558
+        $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']);
559
+        // Si erreur, signaler leur nombre dans le formulaire admin
560
+        $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : '';
561
+        list($texte, $err) = emboite_texte($val, $fonc, $self);
562
+        if ($err === false) {
563
+            $err = _T('impossible');
564
+        } elseif ($err === true) {
565
+            $err = _T('correcte');
566
+        } else {
567
+            $err = ": $err";
568
+        }
569
+        $legend = _T('validation') . ' ' . $err;
570
+        $res = $id = '';
571
+    }
572
+
573
+    return !trim($texte) ? '' : (
574
+        "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res"
575
+        . "<div id='debug_boucle'><fieldset$id><legend>"
576
+        . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> &#8593; "
577
+        . ($legend ? $legend : $mode)
578
+        . '</a></legend>'
579
+        . $texte
580
+        . '</fieldset></div>'
581
+        . '</div>');
582 582
 }
583 583
 
584 584
 
585 585
 // https://code.spip.net/@emboite_texte
586 586
 function emboite_texte($res, $fonc = '', $self = '') {
587
-	$errs = $res->err;
588
-	$texte = $res->entete . ($errs ? '' : $res->page);
589
-
590
-	if (!$texte and !$errs) {
591
-		return [ancre_texte('', ['', '']), false];
592
-	}
593
-	if (!$errs) {
594
-		return [ancre_texte($texte, ['', '']), true];
595
-	}
596
-
597
-	if (!isset($GLOBALS['debug_objets'])) {
598
-		$colors = ['#e0e0f0', '#f8f8ff'];
599
-		$encore = count_occ($errs);
600
-		$encore2 = [];
601
-		$fautifs = [];
602
-
603
-		$err = '<tr><th>'
604
-			. _T('numero')
605
-			. '</th><th>'
606
-			. _T('occurence')
607
-			. '</th><th>'
608
-			. _T('ligne')
609
-			. '</th><th>'
610
-			. _T('colonne')
611
-			. '</th><th>'
612
-			. _T('erreur')
613
-			. '</th></tr>';
614
-
615
-		$i = 0;
616
-		$style = "style='text-align: right; padding-right: 5px'";
617
-		foreach ($errs as $r) {
618
-			$i++;
619
-			list($msg, $ligne, $col) = $r;
620
-			#spip_log("$r = list($msg, $ligne, $col");
621
-			if (isset($encore2[$msg])) {
622
-				$ref = ++$encore2[$msg];
623
-			} else {
624
-				$encore2[$msg] = $ref = 1;
625
-			}
626
-			$err .= "<tr  style='background-color: "
627
-				. $colors[$i % 2]
628
-				. "'><td $style><a href='#debut_err'>"
629
-				. $i
630
-				. "</a></td><td $style>"
631
-				. "$ref/$encore[$msg]</td>"
632
-				. "<td $style><a href='#L"
633
-				. $ligne
634
-				. "' id='T$i'>"
635
-				. $ligne
636
-				. "</a></td><td $style>"
637
-				. $col
638
-				. "</td><td>$msg</td></tr>\n";
639
-			$fautifs[] = [$ligne, $col, $i, $msg];
640
-		}
641
-		$err = "<h2 style='text-align: center'>"
642
-			. $i
643
-			. "<a href='#fin_err'>"
644
-			. ' ' . _T('erreur_texte')
645
-			. "</a></h2><table id='debut_err' style='width: 100%'>"
646
-			. $err
647
-			. " </table><a id='fin_err'></a>";
648
-
649
-		return [ancre_texte($texte, $fautifs), $err];
650
-	} else {
651
-		list($msg, $fermant, $ouvrant) = $errs[0];
652
-		$rf = reference_boucle_debug($fermant, $fonc, $self);
653
-		$ro = reference_boucle_debug($ouvrant, $fonc, $self);
654
-		$err = $msg .
655
-			"<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" .
656
-			"<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro";
657
-
658
-		return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err];
659
-	}
587
+    $errs = $res->err;
588
+    $texte = $res->entete . ($errs ? '' : $res->page);
589
+
590
+    if (!$texte and !$errs) {
591
+        return [ancre_texte('', ['', '']), false];
592
+    }
593
+    if (!$errs) {
594
+        return [ancre_texte($texte, ['', '']), true];
595
+    }
596
+
597
+    if (!isset($GLOBALS['debug_objets'])) {
598
+        $colors = ['#e0e0f0', '#f8f8ff'];
599
+        $encore = count_occ($errs);
600
+        $encore2 = [];
601
+        $fautifs = [];
602
+
603
+        $err = '<tr><th>'
604
+            . _T('numero')
605
+            . '</th><th>'
606
+            . _T('occurence')
607
+            . '</th><th>'
608
+            . _T('ligne')
609
+            . '</th><th>'
610
+            . _T('colonne')
611
+            . '</th><th>'
612
+            . _T('erreur')
613
+            . '</th></tr>';
614
+
615
+        $i = 0;
616
+        $style = "style='text-align: right; padding-right: 5px'";
617
+        foreach ($errs as $r) {
618
+            $i++;
619
+            list($msg, $ligne, $col) = $r;
620
+            #spip_log("$r = list($msg, $ligne, $col");
621
+            if (isset($encore2[$msg])) {
622
+                $ref = ++$encore2[$msg];
623
+            } else {
624
+                $encore2[$msg] = $ref = 1;
625
+            }
626
+            $err .= "<tr  style='background-color: "
627
+                . $colors[$i % 2]
628
+                . "'><td $style><a href='#debut_err'>"
629
+                . $i
630
+                . "</a></td><td $style>"
631
+                . "$ref/$encore[$msg]</td>"
632
+                . "<td $style><a href='#L"
633
+                . $ligne
634
+                . "' id='T$i'>"
635
+                . $ligne
636
+                . "</a></td><td $style>"
637
+                . $col
638
+                . "</td><td>$msg</td></tr>\n";
639
+            $fautifs[] = [$ligne, $col, $i, $msg];
640
+        }
641
+        $err = "<h2 style='text-align: center'>"
642
+            . $i
643
+            . "<a href='#fin_err'>"
644
+            . ' ' . _T('erreur_texte')
645
+            . "</a></h2><table id='debut_err' style='width: 100%'>"
646
+            . $err
647
+            . " </table><a id='fin_err'></a>";
648
+
649
+        return [ancre_texte($texte, $fautifs), $err];
650
+    } else {
651
+        list($msg, $fermant, $ouvrant) = $errs[0];
652
+        $rf = reference_boucle_debug($fermant, $fonc, $self);
653
+        $ro = reference_boucle_debug($ouvrant, $fonc, $self);
654
+        $err = $msg .
655
+            "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" .
656
+            "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro";
657
+
658
+        return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err];
659
+    }
660 660
 }
661 661
 
662 662
 // https://code.spip.net/@count_occ
663 663
 function count_occ($regs) {
664
-	$encore = [];
665
-	foreach ($regs as $r) {
666
-		if (isset($encore[$r[0]])) {
667
-			$encore[$r[0]]++;
668
-		} else {
669
-			$encore[$r[0]] = 1;
670
-		}
671
-	}
672
-
673
-	return $encore;
664
+    $encore = [];
665
+    foreach ($regs as $r) {
666
+        if (isset($encore[$r[0]])) {
667
+            $encore[$r[0]]++;
668
+        } else {
669
+            $encore[$r[0]] = 1;
670
+        }
671
+    }
672
+
673
+    return $encore;
674 674
 }
675 675
 
676 676
 function debusquer_navigation_squelettes($self) {
677 677
 
678
-	$res = '';
679
-	$boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : '';
680
-	$contexte = $GLOBALS['debug_objets']['contexte'];
681
-	$t_skel = _T('squelette');
682
-	foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) {
683
-		$self2 = parametre_url($self, 'var_mode_objet', $nom);
684
-		$nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile);
685
-		$temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T(
686
-			'zbug_profile',
687
-			['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]]
688
-		);
689
-
690
-		$res .= "<fieldset id='f_" . $nom . "'><legend>"
691
-			. $t_skel
692
-			. ' '
693
-			. $sourcefile
694
-			. "&nbsp;:\n<a href='$self2&amp;var_mode_affiche=squelette#f_$nom'>"
695
-			. $t_skel
696
-			. "</a>\n<a href='$self2&amp;var_mode_affiche=resultat#f_$nom'>"
697
-			. _T('zbug_resultat')
698
-			. "</a>\n<a href='$self2&amp;var_mode_affiche=code#f_$nom'>"
699
-			. _T('zbug_code')
700
-			. "</a>\n<a href='"
701
-			. str_replace('var_mode=debug', 'var_profile=1&amp;var_mode=recalcul', $self)
702
-			. "'>"
703
-			. _T('zbug_calcul')
704
-			. '</a></legend>'
705
-			. (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />"))
706
-			. debusquer_contexte($contexte[$sourcefile])
707
-		. (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n"))
708
-		. "</fieldset>\n";
709
-	}
710
-
711
-	return $res;
678
+    $res = '';
679
+    $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : '';
680
+    $contexte = $GLOBALS['debug_objets']['contexte'];
681
+    $t_skel = _T('squelette');
682
+    foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) {
683
+        $self2 = parametre_url($self, 'var_mode_objet', $nom);
684
+        $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile);
685
+        $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T(
686
+            'zbug_profile',
687
+            ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]]
688
+        );
689
+
690
+        $res .= "<fieldset id='f_" . $nom . "'><legend>"
691
+            . $t_skel
692
+            . ' '
693
+            . $sourcefile
694
+            . "&nbsp;:\n<a href='$self2&amp;var_mode_affiche=squelette#f_$nom'>"
695
+            . $t_skel
696
+            . "</a>\n<a href='$self2&amp;var_mode_affiche=resultat#f_$nom'>"
697
+            . _T('zbug_resultat')
698
+            . "</a>\n<a href='$self2&amp;var_mode_affiche=code#f_$nom'>"
699
+            . _T('zbug_code')
700
+            . "</a>\n<a href='"
701
+            . str_replace('var_mode=debug', 'var_profile=1&amp;var_mode=recalcul', $self)
702
+            . "'>"
703
+            . _T('zbug_calcul')
704
+            . '</a></legend>'
705
+            . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />"))
706
+            . debusquer_contexte($contexte[$sourcefile])
707
+        . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n"))
708
+        . "</fieldset>\n";
709
+    }
710
+
711
+    return $res;
712 712
 }
713 713
 
714 714
 function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) {
715
-	$i = 0;
716
-	$res = '';
717
-	$var_mode_objet = _request('var_mode_objet');
718
-	$gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : '';
719
-
720
-	foreach ($boucles as $objet => $boucle) {
721
-		if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) {
722
-			$i++;
723
-			$nom = $boucle->id_boucle;
724
-			$req = $boucle->type_requete;
725
-			$crit = public_decompiler($boucle, $gram, 0, 'criteres');
726
-			$self2 = $self . '&amp;var_mode_objet=' . $objet;
727
-
728
-			$res .= "\n<tr style='background-color: " .
729
-				($i % 2 ? '#e0e0f0' : '#f8f8ff') .
730
-				"'><td  align='right'>$i</td><td>\n" .
731
-				"<a  class='debug_link_boucle' href='" .
732
-				$self2 .
733
-				"&amp;var_mode_affiche=boucle#f_$nom_skel'>" .
734
-				_T('zbug_boucle') .
735
-				"</a></td><td>\n<a class='debug_link_boucle' href='" .
736
-				$self2 .
737
-				"&amp;var_mode_affiche=resultat#f_$nom_skel'>" .
738
-				_T('zbug_resultat') .
739
-				"</a></td><td>\n<a class='debug_link_resultat' href='" .
740
-				$self2 .
741
-				"&amp;var_mode_affiche=code#f_$nom_skel'>" .
742
-				_T('zbug_code') .
743
-				"</a></td><td>\n<a class='debug_link_resultat' href='" .
744
-				str_replace('var_mode=', 'var_profile=', $self2) .
745
-				"'>" .
746
-				_T('zbug_calcul') .
747
-				"</a></td><td>\n" .
748
-				(($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) .
749
-				"</td><td>\n" .
750
-				$req .
751
-				"</td><td>\n" .
752
-				spip_htmlspecialchars($crit) .
753
-				'</td></tr>';
754
-		}
755
-	}
756
-
757
-	return $res;
715
+    $i = 0;
716
+    $res = '';
717
+    $var_mode_objet = _request('var_mode_objet');
718
+    $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : '';
719
+
720
+    foreach ($boucles as $objet => $boucle) {
721
+        if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) {
722
+            $i++;
723
+            $nom = $boucle->id_boucle;
724
+            $req = $boucle->type_requete;
725
+            $crit = public_decompiler($boucle, $gram, 0, 'criteres');
726
+            $self2 = $self . '&amp;var_mode_objet=' . $objet;
727
+
728
+            $res .= "\n<tr style='background-color: " .
729
+                ($i % 2 ? '#e0e0f0' : '#f8f8ff') .
730
+                "'><td  align='right'>$i</td><td>\n" .
731
+                "<a  class='debug_link_boucle' href='" .
732
+                $self2 .
733
+                "&amp;var_mode_affiche=boucle#f_$nom_skel'>" .
734
+                _T('zbug_boucle') .
735
+                "</a></td><td>\n<a class='debug_link_boucle' href='" .
736
+                $self2 .
737
+                "&amp;var_mode_affiche=resultat#f_$nom_skel'>" .
738
+                _T('zbug_resultat') .
739
+                "</a></td><td>\n<a class='debug_link_resultat' href='" .
740
+                $self2 .
741
+                "&amp;var_mode_affiche=code#f_$nom_skel'>" .
742
+                _T('zbug_code') .
743
+                "</a></td><td>\n<a class='debug_link_resultat' href='" .
744
+                str_replace('var_mode=', 'var_profile=', $self2) .
745
+                "'>" .
746
+                _T('zbug_calcul') .
747
+                "</a></td><td>\n" .
748
+                (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) .
749
+                "</td><td>\n" .
750
+                $req .
751
+                "</td><td>\n" .
752
+                spip_htmlspecialchars($crit) .
753
+                '</td></tr>';
754
+        }
755
+    }
756
+
757
+    return $res;
758 758
 }
759 759
 
760 760
 function debusquer_source($objet, $affiche) {
761
-	$quoi = $GLOBALS['debug_objets'][$affiche][$objet];
762
-	if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) {
763
-		$nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle;
764
-	} else {
765
-		$nom = $GLOBALS['debug_objets']['sourcefile'][$objet];
766
-	}
767
-	$res2 = '';
768
-
769
-	if ($affiche == 'resultat') {
770
-		$legend = $nom;
771
-		$req = $GLOBALS['debug_objets']['requete'][$objet];
772
-		if (function_exists('_mysql_traite_query')) {
773
-			$c = strtolower(_request('connect'));
774
-			$c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe'];
775
-			$req = _mysql_traite_query($req, '', $c);
776
-		}
777
-		//  permettre le copier/coller facile
778
-		// $res = ancre_texte($req, array(), true);
779
-		$res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n";
780
-		//  formatage et affichage des resultats bruts de la requete
781
-		$ress_req = spip_query($req);
782
-		$brut_sql = '';
783
-		$num = 1;
784
-		//  eviter l'affichage de milliers de lignes
785
-		//  personnalisation possible dans mes_options
786
-		$max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50;
787
-		while ($retours_sql = sql_fetch($ress_req)) {
788
-			if ($num <= $max_aff) {
789
-				$brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>';
790
-				$brut_sql .= '<p>';
791
-				foreach ($retours_sql as $key => $val) {
792
-					$brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n";
793
-				}
794
-				$brut_sql .= '</p>';
795
-			}
796
-			$num++;
797
-		}
798
-		$res2 = interdire_scripts($brut_sql);
799
-		foreach ($quoi as $view) {
800
-			//  ne pas afficher les $contexte_inclus
801
-			$view = preg_replace(',<\?php.+\?[>],Uims', '', $view);
802
-			if ($view) {
803
-				$res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>';
804
-			}
805
-		}
806
-	} elseif ($affiche == 'code') {
807
-		$legend = $nom;
808
-		$res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>');
809
-	} elseif ($affiche == 'boucle') {
810
-		$legend = _T('zbug_boucle') . ' ' . $nom;
811
-		// Le compilateur prefixe le nom des boucles par l'extension du fichier source.
812
-		$gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : '';
813
-		$res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle'));
814
-	} elseif ($affiche == 'squelette') {
815
-		$legend = $GLOBALS['debug_objets']['sourcefile'][$objet];
816
-		$res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]);
817
-	}
818
-
819
-	return [$legend, $res, $res2];
761
+    $quoi = $GLOBALS['debug_objets'][$affiche][$objet];
762
+    if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) {
763
+        $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle;
764
+    } else {
765
+        $nom = $GLOBALS['debug_objets']['sourcefile'][$objet];
766
+    }
767
+    $res2 = '';
768
+
769
+    if ($affiche == 'resultat') {
770
+        $legend = $nom;
771
+        $req = $GLOBALS['debug_objets']['requete'][$objet];
772
+        if (function_exists('_mysql_traite_query')) {
773
+            $c = strtolower(_request('connect'));
774
+            $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe'];
775
+            $req = _mysql_traite_query($req, '', $c);
776
+        }
777
+        //  permettre le copier/coller facile
778
+        // $res = ancre_texte($req, array(), true);
779
+        $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n";
780
+        //  formatage et affichage des resultats bruts de la requete
781
+        $ress_req = spip_query($req);
782
+        $brut_sql = '';
783
+        $num = 1;
784
+        //  eviter l'affichage de milliers de lignes
785
+        //  personnalisation possible dans mes_options
786
+        $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50;
787
+        while ($retours_sql = sql_fetch($ress_req)) {
788
+            if ($num <= $max_aff) {
789
+                $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>';
790
+                $brut_sql .= '<p>';
791
+                foreach ($retours_sql as $key => $val) {
792
+                    $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n";
793
+                }
794
+                $brut_sql .= '</p>';
795
+            }
796
+            $num++;
797
+        }
798
+        $res2 = interdire_scripts($brut_sql);
799
+        foreach ($quoi as $view) {
800
+            //  ne pas afficher les $contexte_inclus
801
+            $view = preg_replace(',<\?php.+\?[>],Uims', '', $view);
802
+            if ($view) {
803
+                $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>';
804
+            }
805
+        }
806
+    } elseif ($affiche == 'code') {
807
+        $legend = $nom;
808
+        $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>');
809
+    } elseif ($affiche == 'boucle') {
810
+        $legend = _T('zbug_boucle') . ' ' . $nom;
811
+        // Le compilateur prefixe le nom des boucles par l'extension du fichier source.
812
+        $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : '';
813
+        $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle'));
814
+    } elseif ($affiche == 'squelette') {
815
+        $legend = $GLOBALS['debug_objets']['sourcefile'][$objet];
816
+        $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]);
817
+    }
818
+
819
+    return [$legend, $res, $res2];
820 820
 }
821 821
 
822 822
 // https://code.spip.net/@debusquer_entete
823 823
 function debusquer_entete($titre, $corps) {
824 824
 
825
-	include_spip('balise/formulaire_admin');
826
-	include_spip('public/assembler'); // pour inclure_balise_dynamique
827
-	include_spip('inc/texte'); // pour corriger_typo
828
-
829
-	return _DOCTYPE_ECRIRE .
830
-	html_lang_attributes() .
831
-	"<head>\n<title>" .
832
-	('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' .
833
-		_T('admin_debug') . ' ' . $titre . ' (' .
834
-		supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) .
835
-	")</title>\n" .
836
-	"<meta http-equiv='Content-Type' content='text/html" .
837
-	(($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') .
838
-	"' />\n" .
839
-	http_script('', 'jquery.js')
840
-	. "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css'))
841
-	. "' type='text/css' />" .
842
-	"</head>\n" .
843
-	"<body style='margin:0 10px;'>\n" .
844
-	"<div id='spip-debug-header'>" .
845
-	$corps .
846
-	inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) .
847
-	'</div></body></html>';
825
+    include_spip('balise/formulaire_admin');
826
+    include_spip('public/assembler'); // pour inclure_balise_dynamique
827
+    include_spip('inc/texte'); // pour corriger_typo
828
+
829
+    return _DOCTYPE_ECRIRE .
830
+    html_lang_attributes() .
831
+    "<head>\n<title>" .
832
+    ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' .
833
+        _T('admin_debug') . ' ' . $titre . ' (' .
834
+        supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) .
835
+    ")</title>\n" .
836
+    "<meta http-equiv='Content-Type' content='text/html" .
837
+    (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') .
838
+    "' />\n" .
839
+    http_script('', 'jquery.js')
840
+    . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css'))
841
+    . "' type='text/css' />" .
842
+    "</head>\n" .
843
+    "<body style='margin:0 10px;'>\n" .
844
+    "<div id='spip-debug-header'>" .
845
+    $corps .
846
+    inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) .
847
+    '</div></body></html>';
848 848
 }
Please login to merge, or discard this patch.
ecrire/public/aiguiller.php 1 patch
Indentation   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -11,164 +11,164 @@  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
 function securiser_redirect_action($redirect) {
18
-	// cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect
19
-	if (strpos($redirect, '%') !== false) {
20
-		$r2 = urldecode($redirect);
21
-		if (($r3 = securiser_redirect_action($r2)) !== $r2) {
22
-			return $r3;
23
-		}
24
-	}
25
-	if (
26
-		(tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect)))
27
-		and !defined('_AUTORISER_ACTION_ABS_REDIRECT')
28
-	) {
29
-		// si l'url est une url du site, on la laisse passer sans rien faire
30
-		// c'est encore le plus simple
31
-		$base = $GLOBALS['meta']['adresse_site'] . '/';
32
-		if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
33
-			return $redirect;
34
-		}
35
-		$base = url_de_base();
36
-		if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
37
-			return $redirect;
38
-		}
18
+    // cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect
19
+    if (strpos($redirect, '%') !== false) {
20
+        $r2 = urldecode($redirect);
21
+        if (($r3 = securiser_redirect_action($r2)) !== $r2) {
22
+            return $r3;
23
+        }
24
+    }
25
+    if (
26
+        (tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect)))
27
+        and !defined('_AUTORISER_ACTION_ABS_REDIRECT')
28
+    ) {
29
+        // si l'url est une url du site, on la laisse passer sans rien faire
30
+        // c'est encore le plus simple
31
+        $base = $GLOBALS['meta']['adresse_site'] . '/';
32
+        if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
33
+            return $redirect;
34
+        }
35
+        $base = url_de_base();
36
+        if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) {
37
+            return $redirect;
38
+        }
39 39
 
40
-		return '';
41
-	}
40
+        return '';
41
+    }
42 42
 
43
-	return $redirect;
43
+    return $redirect;
44 44
 }
45 45
 
46 46
 // https://code.spip.net/@traiter_appels_actions
47 47
 function traiter_appels_actions() {
48
-	// cas de l'appel qui renvoie une redirection (302) ou rien (204)
49
-	if ($action = _request('action')) {
50
-		include_spip('base/abstract_sql'); // chargement systematique pour les actions
51
-		include_spip('inc/autoriser');
52
-		include_spip('inc/headers');
53
-		include_spip('inc/actions');
54
-		// des actions peuvent appeler _T
55
-		if (!isset($GLOBALS['spip_lang'])) {
56
-			include_spip('inc/lang');
57
-			utiliser_langue_visiteur();
58
-		}
59
-		// si l'action est provoque par un hit {ajax}
60
-		// il faut transmettre l'env ajax au redirect
61
-		// on le met avant dans la query string au cas ou l'action fait elle meme sa redirection
62
-		if (
63
-			($v = _request('var_ajax'))
64
-			and ($v !== 'form')
65
-			and ($args = _request('var_ajax_env'))
66
-			and ($url = _request('redirect'))
67
-		) {
68
-			$url = parametre_url($url, 'var_ajax', $v, '&');
69
-			$url = parametre_url($url, 'var_ajax_env', $args, '&');
70
-			set_request('redirect', $url);
71
-		} else {
72
-			if (_request('redirect')) {
73
-				set_request('redirect', securiser_redirect_action(_request('redirect')));
74
-			}
75
-		}
76
-		$var_f = charger_fonction($action, 'action');
77
-		$var_f();
78
-		if (!isset($GLOBALS['redirect'])) {
79
-			$GLOBALS['redirect'] = _request('redirect');
80
-			if ($_SERVER['REQUEST_METHOD'] == 'POST') {
81
-				$GLOBALS['redirect'] = urldecode($GLOBALS['redirect']);
82
-			}
83
-			$GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']);
84
-		}
85
-		if ($url = $GLOBALS['redirect']) {
86
-			// si l'action est provoque par un hit {ajax}
87
-			// il faut transmettre l'env ajax au redirect
88
-			// qui a pu etre defini par l'action
89
-			if (
90
-				($v = _request('var_ajax'))
91
-				and ($v !== 'form')
92
-				and ($args = _request('var_ajax_env'))
93
-			) {
94
-				$url = parametre_url($url, 'var_ajax', $v, '&');
95
-				$url = parametre_url($url, 'var_ajax_env', $args, '&');
96
-				// passer l'ancre en variable pour pouvoir la gerer cote serveur
97
-				$url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url);
98
-			}
99
-			$url = str_replace('&amp;', '&', $url); // les redirections se font en &, pas en en &amp;
100
-			redirige_par_entete($url);
101
-		}
48
+    // cas de l'appel qui renvoie une redirection (302) ou rien (204)
49
+    if ($action = _request('action')) {
50
+        include_spip('base/abstract_sql'); // chargement systematique pour les actions
51
+        include_spip('inc/autoriser');
52
+        include_spip('inc/headers');
53
+        include_spip('inc/actions');
54
+        // des actions peuvent appeler _T
55
+        if (!isset($GLOBALS['spip_lang'])) {
56
+            include_spip('inc/lang');
57
+            utiliser_langue_visiteur();
58
+        }
59
+        // si l'action est provoque par un hit {ajax}
60
+        // il faut transmettre l'env ajax au redirect
61
+        // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection
62
+        if (
63
+            ($v = _request('var_ajax'))
64
+            and ($v !== 'form')
65
+            and ($args = _request('var_ajax_env'))
66
+            and ($url = _request('redirect'))
67
+        ) {
68
+            $url = parametre_url($url, 'var_ajax', $v, '&');
69
+            $url = parametre_url($url, 'var_ajax_env', $args, '&');
70
+            set_request('redirect', $url);
71
+        } else {
72
+            if (_request('redirect')) {
73
+                set_request('redirect', securiser_redirect_action(_request('redirect')));
74
+            }
75
+        }
76
+        $var_f = charger_fonction($action, 'action');
77
+        $var_f();
78
+        if (!isset($GLOBALS['redirect'])) {
79
+            $GLOBALS['redirect'] = _request('redirect');
80
+            if ($_SERVER['REQUEST_METHOD'] == 'POST') {
81
+                $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']);
82
+            }
83
+            $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']);
84
+        }
85
+        if ($url = $GLOBALS['redirect']) {
86
+            // si l'action est provoque par un hit {ajax}
87
+            // il faut transmettre l'env ajax au redirect
88
+            // qui a pu etre defini par l'action
89
+            if (
90
+                ($v = _request('var_ajax'))
91
+                and ($v !== 'form')
92
+                and ($args = _request('var_ajax_env'))
93
+            ) {
94
+                $url = parametre_url($url, 'var_ajax', $v, '&');
95
+                $url = parametre_url($url, 'var_ajax_env', $args, '&');
96
+                // passer l'ancre en variable pour pouvoir la gerer cote serveur
97
+                $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url);
98
+            }
99
+            $url = str_replace('&amp;', '&', $url); // les redirections se font en &, pas en en &amp;
100
+            redirige_par_entete($url);
101
+        }
102 102
 
103
-		// attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0
104
-		// et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment)
105
-		if (
106
-			!headers_sent()
107
-			and !ob_get_length()
108
-		) {
109
-			http_status(204);
110
-		} // No Content
111
-		return true;
112
-	}
103
+        // attention : avec zlib.output_compression=1 on a vu des cas de ob_get_length() qui renvoi 0
104
+        // et du coup en renvoi un status 204 a tort (vu sur le menu rubriques notamment)
105
+        if (
106
+            !headers_sent()
107
+            and !ob_get_length()
108
+        ) {
109
+            http_status(204);
110
+        } // No Content
111
+        return true;
112
+    }
113 113
 
114
-	return false;
114
+    return false;
115 115
 }
116 116
 
117 117
 
118 118
 // https://code.spip.net/@refuser_traiter_formulaire_ajax
119 119
 function refuser_traiter_formulaire_ajax() {
120
-	if (
121
-		$v = _request('var_ajax')
122
-		and $v == 'form'
123
-		and $form = _request('formulaire_action')
124
-		and $args = _request('formulaire_action_args')
125
-		and decoder_contexte_ajax($args, $form) !== false
126
-	) {
127
-		// on est bien dans le contexte de traitement d'un formulaire en ajax
128
-		// mais traiter ne veut pas
129
-		// on le dit a la page qui va resumbit
130
-		// sans ajax
131
-		include_spip('inc/actions');
132
-		ajax_retour('noajax', false);
133
-		exit;
134
-	}
120
+    if (
121
+        $v = _request('var_ajax')
122
+        and $v == 'form'
123
+        and $form = _request('formulaire_action')
124
+        and $args = _request('formulaire_action_args')
125
+        and decoder_contexte_ajax($args, $form) !== false
126
+    ) {
127
+        // on est bien dans le contexte de traitement d'un formulaire en ajax
128
+        // mais traiter ne veut pas
129
+        // on le dit a la page qui va resumbit
130
+        // sans ajax
131
+        include_spip('inc/actions');
132
+        ajax_retour('noajax', false);
133
+        exit;
134
+    }
135 135
 }
136 136
 
137 137
 // https://code.spip.net/@traiter_appels_inclusions_ajax
138 138
 function traiter_appels_inclusions_ajax() {
139
-	// traiter les appels de bloc ajax (ex: pagination)
140
-	if (
141
-		$v = _request('var_ajax')
142
-		and $v !== 'form'
143
-		and $args = _request('var_ajax_env')
144
-	) {
145
-		include_spip('inc/filtres');
146
-		include_spip('inc/actions');
147
-		if (
148
-			$args = decoder_contexte_ajax($args)
149
-			and $fond = $args['fond']
150
-		) {
151
-			include_spip('public/assembler');
152
-			$contexte = calculer_contexte();
153
-			$contexte = array_merge($args, $contexte);
154
-			$page = recuperer_fond($fond, $contexte, ['trim' => false]);
155
-			$texte = $page;
156
-			if ($ancre = _request('var_ajax_ancre')) {
157
-				// pas n'importe quoi quand meme dans la variable !
158
-				$ancre = str_replace(['<', '"', "'"], ['&lt;', '&quot;', ''], $ancre);
159
-				$texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte;
160
-			}
161
-		} else {
162
-			include_spip('inc/headers');
163
-			http_response_code(400);
164
-			$texte = _L('signature ajax bloc incorrecte');
165
-		}
166
-		ajax_retour($texte, false);
139
+    // traiter les appels de bloc ajax (ex: pagination)
140
+    if (
141
+        $v = _request('var_ajax')
142
+        and $v !== 'form'
143
+        and $args = _request('var_ajax_env')
144
+    ) {
145
+        include_spip('inc/filtres');
146
+        include_spip('inc/actions');
147
+        if (
148
+            $args = decoder_contexte_ajax($args)
149
+            and $fond = $args['fond']
150
+        ) {
151
+            include_spip('public/assembler');
152
+            $contexte = calculer_contexte();
153
+            $contexte = array_merge($args, $contexte);
154
+            $page = recuperer_fond($fond, $contexte, ['trim' => false]);
155
+            $texte = $page;
156
+            if ($ancre = _request('var_ajax_ancre')) {
157
+                // pas n'importe quoi quand meme dans la variable !
158
+                $ancre = str_replace(['<', '"', "'"], ['&lt;', '&quot;', ''], $ancre);
159
+                $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte;
160
+            }
161
+        } else {
162
+            include_spip('inc/headers');
163
+            http_response_code(400);
164
+            $texte = _L('signature ajax bloc incorrecte');
165
+        }
166
+        ajax_retour($texte, false);
167 167
 
168
-		return true; // on a fini le hit
169
-	}
168
+        return true; // on a fini le hit
169
+    }
170 170
 
171
-	return false;
171
+    return false;
172 172
 }
173 173
 
174 174
 // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter
@@ -177,152 +177,152 @@  discard block
 block discarded – undo
177 177
 
178 178
 // https://code.spip.net/@traiter_formulaires_dynamiques
179 179
 function traiter_formulaires_dynamiques($get = false) {
180
-	static $post = [];
181
-	static $done = false;
180
+    static $post = [];
181
+    static $done = false;
182 182
 
183
-	if ($get) {
184
-		return $post;
185
-	}
186
-	if ($done) {
187
-		return false;
188
-	}
189
-	$done = true;
183
+    if ($get) {
184
+        return $post;
185
+    }
186
+    if ($done) {
187
+        return false;
188
+    }
189
+    $done = true;
190 190
 
191
-	if (
192
-		!($form = _request('formulaire_action')
193
-		and $args = _request('formulaire_action_args'))
194
-	) {
195
-		return false;
196
-	} // le hit peut continuer normalement
191
+    if (
192
+        !($form = _request('formulaire_action')
193
+        and $args = _request('formulaire_action_args'))
194
+    ) {
195
+        return false;
196
+    } // le hit peut continuer normalement
197 197
 
198
-	include_spip('inc/filtres');
199
-	if (($args = decoder_contexte_ajax($args, $form)) === false) {
200
-		spip_log("signature ajax form incorrecte : $form");
198
+    include_spip('inc/filtres');
199
+    if (($args = decoder_contexte_ajax($args, $form)) === false) {
200
+        spip_log("signature ajax form incorrecte : $form");
201 201
 
202
-		return false; // continuons le hit comme si de rien etait
203
-	} else {
204
-		include_spip('inc/lang');
205
-		// sauvegarder la lang en cours
206
-		$old_lang = $GLOBALS['spip_lang'];
207
-		// changer la langue avec celle qui a cours dans le formulaire
208
-		// on la depile de $args car c'est un argument implicite masque
209
-		changer_langue(array_shift($args));
202
+        return false; // continuons le hit comme si de rien etait
203
+    } else {
204
+        include_spip('inc/lang');
205
+        // sauvegarder la lang en cours
206
+        $old_lang = $GLOBALS['spip_lang'];
207
+        // changer la langue avec celle qui a cours dans le formulaire
208
+        // on la depile de $args car c'est un argument implicite masque
209
+        changer_langue(array_shift($args));
210 210
 
211 211
 
212
-		// inclure mes_fonctions et autres filtres avant verifier/traiter
213
-		include_fichiers_fonctions();
214
-		// ainsi que l'API SQL bien utile dans verifier/traiter
215
-		include_spip('base/abstract_sql');
212
+        // inclure mes_fonctions et autres filtres avant verifier/traiter
213
+        include_fichiers_fonctions();
214
+        // ainsi que l'API SQL bien utile dans verifier/traiter
215
+        include_spip('base/abstract_sql');
216 216
 
217
-		/**
218
-		 * Pipeline exécuté lors de la soumission d'un formulaire,
219
-		 * mais avant l'appel de la fonction de vérification.
220
-		 */
221
-		pipeline(
222
-			'formulaire_receptionner',
223
-			[
224
-				'args' => ['form' => $form, 'args' => $args],
225
-				'data' => null,
226
-			]
227
-		);
217
+        /**
218
+         * Pipeline exécuté lors de la soumission d'un formulaire,
219
+         * mais avant l'appel de la fonction de vérification.
220
+         */
221
+        pipeline(
222
+            'formulaire_receptionner',
223
+            [
224
+                'args' => ['form' => $form, 'args' => $args],
225
+                'data' => null,
226
+            ]
227
+        );
228 228
 
229
-		$verifier = charger_fonction('verifier', "formulaires/$form/", true);
230
-		$post["erreurs_$form"] = pipeline(
231
-			'formulaire_verifier',
232
-			[
233
-				'args' => ['form' => $form, 'args' => $args],
234
-				'data' => $verifier ? call_user_func_array($verifier, $args) : []
235
-			]
236
-		);
237
-		// prise en charge CVT multi etape si besoin
238
-		if (_request('cvtm_prev_post')) {
239
-			include_spip('inc/cvt_multietapes');
240
-			$post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes(
241
-				['form' => $form, 'args' => $args],
242
-				$post["erreurs_$form"]
243
-			);
244
-		}
229
+        $verifier = charger_fonction('verifier', "formulaires/$form/", true);
230
+        $post["erreurs_$form"] = pipeline(
231
+            'formulaire_verifier',
232
+            [
233
+                'args' => ['form' => $form, 'args' => $args],
234
+                'data' => $verifier ? call_user_func_array($verifier, $args) : []
235
+            ]
236
+        );
237
+        // prise en charge CVT multi etape si besoin
238
+        if (_request('cvtm_prev_post')) {
239
+            include_spip('inc/cvt_multietapes');
240
+            $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes(
241
+                ['form' => $form, 'args' => $args],
242
+                $post["erreurs_$form"]
243
+            );
244
+        }
245 245
 
246
-		// accessibilite : si des erreurs mais pas de message general l'ajouter
247
-		if ((isset($post["erreurs_$form"]) and count($post["erreurs_$form"])) and !isset($post["erreurs_$form"]['message_erreur'])) {
248
-			$post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(
249
-				count($post["erreurs_$form"]),
250
-				'avis_1_erreur_saisie',
251
-				'avis_nb_erreurs_saisie'
252
-			);
253
-		}
246
+        // accessibilite : si des erreurs mais pas de message general l'ajouter
247
+        if ((isset($post["erreurs_$form"]) and count($post["erreurs_$form"])) and !isset($post["erreurs_$form"]['message_erreur'])) {
248
+            $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(
249
+                count($post["erreurs_$form"]),
250
+                'avis_1_erreur_saisie',
251
+                'avis_nb_erreurs_saisie'
252
+            );
253
+        }
254 254
 
255
-		// si on ne demandait qu'une verif json
256
-		if (_request('formulaire_action_verifier_json')) {
257
-			include_spip('inc/json');
258
-			include_spip('inc/actions');
259
-			ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain');
255
+        // si on ne demandait qu'une verif json
256
+        if (_request('formulaire_action_verifier_json')) {
257
+            include_spip('inc/json');
258
+            include_spip('inc/actions');
259
+            ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain');
260 260
 
261
-			return true; // on a fini le hit
262
-		}
263
-		$retour = '';
264
-		if (isset($post["erreurs_$form"]) and (count($post["erreurs_$form"]) == 0)) {
265
-			$rev = '';
266
-			if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) {
267
-				$rev = call_user_func_array($traiter, $args);
268
-			}
261
+            return true; // on a fini le hit
262
+        }
263
+        $retour = '';
264
+        if (isset($post["erreurs_$form"]) and (count($post["erreurs_$form"]) == 0)) {
265
+            $rev = '';
266
+            if ($traiter = charger_fonction('traiter', "formulaires/$form/", true)) {
267
+                $rev = call_user_func_array($traiter, $args);
268
+            }
269 269
 
270
-			$rev = pipeline(
271
-				'formulaire_traiter',
272
-				[
273
-					'args' => ['form' => $form, 'args' => $args],
274
-					'data' => $rev
275
-				]
276
-			);
277
-			// le retour de traiter est
278
-			// un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx)
279
-			// il permet le pipelinage, en particulier
280
-			// en y passant l'id de l'objet cree/modifie
281
-			// si message_erreur est present, on considere que le traitement a echoue
282
-			$post["message_ok_$form"] = '';
283
-			// on peut avoir message_ok et message_erreur
284
-			if (isset($rev['message_ok'])) {
285
-				$post["message_ok_$form"] = $rev['message_ok'];
286
-			}
270
+            $rev = pipeline(
271
+                'formulaire_traiter',
272
+                [
273
+                    'args' => ['form' => $form, 'args' => $args],
274
+                    'data' => $rev
275
+                ]
276
+            );
277
+            // le retour de traiter est
278
+            // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx)
279
+            // il permet le pipelinage, en particulier
280
+            // en y passant l'id de l'objet cree/modifie
281
+            // si message_erreur est present, on considere que le traitement a echoue
282
+            $post["message_ok_$form"] = '';
283
+            // on peut avoir message_ok et message_erreur
284
+            if (isset($rev['message_ok'])) {
285
+                $post["message_ok_$form"] = $rev['message_ok'];
286
+            }
287 287
 
288
-			// verifier si traiter n'a pas echoue avec une erreur :
289
-			if (isset($rev['message_erreur'])) {
290
-				$post["erreurs_$form"]['message_erreur'] = $rev['message_erreur'];
291
-				// si il y a une erreur on ne redirige pas
292
-			} else {
293
-				// sinon faire ce qu'il faut :
294
-				if (isset($rev['editable'])) {
295
-					$post["editable_$form"] = $rev['editable'];
296
-				}
297
-				// si une redirection est demandee, appeler redirigae_formulaire qui choisira
298
-				// le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue)
299
-				if (isset($rev['redirect']) and $rev['redirect']) {
300
-					include_spip('inc/headers');
301
-					list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform');
302
-					$post["message_ok_$form"] .= $message;
303
-					$retour .= $masque;
304
-				}
305
-			}
306
-		}
307
-		// si le formulaire a ete soumis en ajax, on le renvoie direct !
308
-		if (_request('var_ajax')) {
309
-			if (find_in_path('formulaire_.php', 'balise/', true)) {
310
-				include_spip('inc/actions');
311
-				include_spip('public/assembler');
312
-				array_unshift($args, $form);
313
-				$retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false);
314
-				// on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
315
-				// sans cela le formulaire n'est pas actif apres le hit ajax
316
-				// la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
317
-				$retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
318
-				ajax_retour($retour, false);
288
+            // verifier si traiter n'a pas echoue avec une erreur :
289
+            if (isset($rev['message_erreur'])) {
290
+                $post["erreurs_$form"]['message_erreur'] = $rev['message_erreur'];
291
+                // si il y a une erreur on ne redirige pas
292
+            } else {
293
+                // sinon faire ce qu'il faut :
294
+                if (isset($rev['editable'])) {
295
+                    $post["editable_$form"] = $rev['editable'];
296
+                }
297
+                // si une redirection est demandee, appeler redirigae_formulaire qui choisira
298
+                // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue)
299
+                if (isset($rev['redirect']) and $rev['redirect']) {
300
+                    include_spip('inc/headers');
301
+                    list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform');
302
+                    $post["message_ok_$form"] .= $message;
303
+                    $retour .= $masque;
304
+                }
305
+            }
306
+        }
307
+        // si le formulaire a ete soumis en ajax, on le renvoie direct !
308
+        if (_request('var_ajax')) {
309
+            if (find_in_path('formulaire_.php', 'balise/', true)) {
310
+                include_spip('inc/actions');
311
+                include_spip('public/assembler');
312
+                array_unshift($args, $form);
313
+                $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false);
314
+                // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7
315
+                // sans cela le formulaire n'est pas actif apres le hit ajax
316
+                // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe
317
+                $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour;
318
+                ajax_retour($retour, false);
319 319
 
320
-				return true; // on a fini le hit
321
-			}
322
-		}
323
-		// restaurer la lang en cours
324
-		changer_langue($old_lang);
325
-	}
320
+                return true; // on a fini le hit
321
+            }
322
+        }
323
+        // restaurer la lang en cours
324
+        changer_langue($old_lang);
325
+    }
326 326
 
327
-	return false; // le hit peut continuer normalement
327
+    return false; // le hit peut continuer normalement
328 328
 }
Please login to merge, or discard this patch.
ecrire/action/menu_rubriques.php 2 patches
Indentation   +155 added lines, -155 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/autoriser');
@@ -35,42 +35,42 @@  discard block
 block discarded – undo
35 35
  **/
36 36
 function action_menu_rubriques_dist() {
37 37
 
38
-	// si pas acces a ecrire, pas acces au menu
39
-	// on renvoi un 401 qui fait echouer la requete ajax silencieusement
40
-	if (!autoriser('ecrire')) {
41
-		$retour =
42
-		'<ul class="deroulant__sous-menu" data-profondeur="1">' .
43
-			'<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' .
44
-				'<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' .
45
-					'<span class="libelle">' . _T('public:lien_connecter') . '</span>' .
46
-				'</a>' .
47
-			'</li>' .
48
-		'</ul>';
49
-		include_spip('inc/actions');
50
-		ajax_retour($retour);
51
-		exit;
52
-	}
53
-
54
-	if ($date = intval(_request('date'))) {
55
-		header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT');
56
-	}
57
-
58
-	$r = gen_liste_rubriques();
59
-	if (
60
-		!$r
61
-		and isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
62
-		and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')
63
-	) {
64
-		include_spip('inc/headers');
65
-		header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
66
-		http_response_code(304);
67
-		exit;
68
-	} else {
69
-		include_spip('inc/actions');
70
-		$ret = menu_rubriques();
71
-		ajax_retour($ret);
72
-		exit;
73
-	}
38
+    // si pas acces a ecrire, pas acces au menu
39
+    // on renvoi un 401 qui fait echouer la requete ajax silencieusement
40
+    if (!autoriser('ecrire')) {
41
+        $retour =
42
+        '<ul class="deroulant__sous-menu" data-profondeur="1">' .
43
+            '<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' .
44
+                '<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' .
45
+                    '<span class="libelle">' . _T('public:lien_connecter') . '</span>' .
46
+                '</a>' .
47
+            '</li>' .
48
+        '</ul>';
49
+        include_spip('inc/actions');
50
+        ajax_retour($retour);
51
+        exit;
52
+    }
53
+
54
+    if ($date = intval(_request('date'))) {
55
+        header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT');
56
+    }
57
+
58
+    $r = gen_liste_rubriques();
59
+    if (
60
+        !$r
61
+        and isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
62
+        and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')
63
+    ) {
64
+        include_spip('inc/headers');
65
+        header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
66
+        http_response_code(304);
67
+        exit;
68
+    } else {
69
+        include_spip('inc/actions');
70
+        $ret = menu_rubriques();
71
+        ajax_retour($ret);
72
+        exit;
73
+    }
74 74
 }
75 75
 
76 76
 /**
@@ -84,44 +84,44 @@  discard block
 block discarded – undo
84 84
  *     Code HTML présentant la liste des rubriques
85 85
  **/
86 86
 function menu_rubriques($complet = true) {
87
-	$ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">'
88
-		. '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">'
89
-		. '<span class="libelle">' . _T('info_tout_site') . '</span>'
90
-		. '</a>'
91
-		. '</li>';
92
-
93
-	if (!$complet) {
94
-		return "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n";
95
-	}
96
-
97
-	if (!isset($GLOBALS['db_art_cache'])) {
98
-		gen_liste_rubriques();
99
-	}
100
-	$arr_low = extraire_article(0, $GLOBALS['db_art_cache']);
101
-
102
-	$total_lignes = $i = sizeof($arr_low);
103
-
104
-	if ($i > 0) {
105
-		$nb_col = min(8, ceil($total_lignes / 30));
106
-		if ($nb_col <= 1) {
107
-			$nb_col = ceil($total_lignes / 10);
108
-		}
109
-		foreach ($arr_low as $id_rubrique => $titre_rubrique) {
110
-			if (autoriser('voir', 'rubrique', $id_rubrique)) {
111
-				$ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i);
112
-				$i++;
113
-			}
114
-		}
115
-
116
-		$class_cols = ($nb_col > 1 ? "cols-$nb_col" : '');
117
-		$ret = "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"1\">"
118
-			. $ret
119
-			. "\n</ul>\n";
120
-	} else {
121
-		$ret = "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n";
122
-	}
123
-
124
-	return $ret;
87
+    $ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">'
88
+        . '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">'
89
+        . '<span class="libelle">' . _T('info_tout_site') . '</span>'
90
+        . '</a>'
91
+        . '</li>';
92
+
93
+    if (!$complet) {
94
+        return "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n";
95
+    }
96
+
97
+    if (!isset($GLOBALS['db_art_cache'])) {
98
+        gen_liste_rubriques();
99
+    }
100
+    $arr_low = extraire_article(0, $GLOBALS['db_art_cache']);
101
+
102
+    $total_lignes = $i = sizeof($arr_low);
103
+
104
+    if ($i > 0) {
105
+        $nb_col = min(8, ceil($total_lignes / 30));
106
+        if ($nb_col <= 1) {
107
+            $nb_col = ceil($total_lignes / 10);
108
+        }
109
+        foreach ($arr_low as $id_rubrique => $titre_rubrique) {
110
+            if (autoriser('voir', 'rubrique', $id_rubrique)) {
111
+                $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i);
112
+                $i++;
113
+            }
114
+        }
115
+
116
+        $class_cols = ($nb_col > 1 ? "cols-$nb_col" : '');
117
+        $ret = "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"1\">"
118
+            . $ret
119
+            . "\n</ul>\n";
120
+    } else {
121
+        $ret = "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n";
122
+    }
123
+
124
+    return $ret;
125 125
 }
126 126
 
127 127
 /**
@@ -142,48 +142,48 @@  discard block
 block discarded – undo
142 142
  *     Code HTML présentant la liste des rubriques
143 143
  **/
144 144
 function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal, $profondeur = 1) {
145
-	static $zmax = 6;
146
-	$profondeur_next = $profondeur + 1;
147
-
148
-	$nav = '<a class="deroulant__lien" href="' . generer_url_entite($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">"
149
-		. '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>'
150
-		. "</a>\n";
151
-
152
-	// Limiter volontairement le nombre de sous-menus
153
-	if (!(--$zmax)) {
154
-		$zmax++;
155
-
156
-		return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>";
157
-	}
158
-
159
-	$arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']);
160
-	$i = sizeof($arr_rub);
161
-	if (!$i) {
162
-		$zmax++;
163
-
164
-		return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>";
165
-	}
166
-
167
-
168
-	$nb_col = 1;
169
-	if ($nb_rub = count($arr_rub)) {
170
-		$nb_col = min(10, max(1, ceil($nb_rub / 10)));
171
-	}
172
-	$class_cols = ($nb_col > 1 ? "cols-$nb_col" : '');
173
-	$ret = "<li class=\"deroulant__item deroulant__item_parent\" data-profondeur=\"$profondeur\">"
174
-	 . $nav
175
-	 . "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"$profondeur_next\">";
176
-	foreach ($arr_rub as $id_rub => $titre_rub) {
177
-		if (autoriser('voir', 'rubrique', $id_rub)) {
178
-			$titre = supprimer_numero(typo($titre_rub));
179
-			$ret .= bandeau_rubrique($id_rub, $titre, $zdecal + $i, $profondeur_next);
180
-			$i++;
181
-		}
182
-	}
183
-	$ret .= "</ul></li>\n";
184
-	$zmax++;
185
-
186
-	return $ret;
145
+    static $zmax = 6;
146
+    $profondeur_next = $profondeur + 1;
147
+
148
+    $nav = '<a class="deroulant__lien" href="' . generer_url_entite($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">"
149
+        . '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>'
150
+        . "</a>\n";
151
+
152
+    // Limiter volontairement le nombre de sous-menus
153
+    if (!(--$zmax)) {
154
+        $zmax++;
155
+
156
+        return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>";
157
+    }
158
+
159
+    $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']);
160
+    $i = sizeof($arr_rub);
161
+    if (!$i) {
162
+        $zmax++;
163
+
164
+        return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>";
165
+    }
166
+
167
+
168
+    $nb_col = 1;
169
+    if ($nb_rub = count($arr_rub)) {
170
+        $nb_col = min(10, max(1, ceil($nb_rub / 10)));
171
+    }
172
+    $class_cols = ($nb_col > 1 ? "cols-$nb_col" : '');
173
+    $ret = "<li class=\"deroulant__item deroulant__item_parent\" data-profondeur=\"$profondeur\">"
174
+        . $nav
175
+        . "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"$profondeur_next\">";
176
+    foreach ($arr_rub as $id_rub => $titre_rub) {
177
+        if (autoriser('voir', 'rubrique', $id_rub)) {
178
+            $titre = supprimer_numero(typo($titre_rub));
179
+            $ret .= bandeau_rubrique($id_rub, $titre, $zdecal + $i, $profondeur_next);
180
+            $i++;
181
+        }
182
+    }
183
+    $ret .= "</ul></li>\n";
184
+    $zmax++;
185
+
186
+    return $ret;
187 187
 }
188 188
 
189 189
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
  *     Liste des rubriques enfants de la rubrique (et leur titre)
202 202
  **/
203 203
 function extraire_article($id_p, $t) {
204
-	return array_key_exists($id_p, $t) ? $t[$id_p] : [];
204
+    return array_key_exists($id_p, $t) ? $t[$id_p] : [];
205 205
 }
206 206
 
207 207
 /**
@@ -217,41 +217,41 @@  discard block
 block discarded – undo
217 217
  **/
218 218
 function gen_liste_rubriques() {
219 219
 
220
-	include_spip('inc/config');
221
-	// ici, un petit fichier cache ne fait pas de mal
222
-	$last = lire_config('date_calcul_rubriques', 0);
223
-	if (lire_fichier(_CACHE_RUBRIQUES, $cache)) {
224
-		list($date, $GLOBALS['db_art_cache']) = @unserialize($cache);
225
-		if ($date == $last) {
226
-			return false;
227
-		} // c'etait en cache :-)
228
-	}
229
-	// se restreindre aux rubriques utilisees recemment +secteurs
230
-
231
-	$where = sql_in_select(
232
-		'id_rubrique',
233
-		'id_rubrique',
234
-		'spip_rubriques',
235
-		'',
236
-		'',
237
-		'id_parent=0 DESC, date DESC',
238
-		_CACHE_RUBRIQUES_MAX
239
-	);
240
-
241
-	// puis refaire la requete pour avoir l'ordre alphabetique
242
-
243
-	$res = sql_select('id_rubrique, titre, id_parent', 'spip_rubriques', $where, '', 'id_parent, 0+titre, titre');
244
-
245
-	// il ne faut pas filtrer le autoriser voir ici
246
-	// car on met le resultat en cache, commun a tout le monde
247
-	$GLOBALS['db_art_cache'] = [];
248
-	while ($r = sql_fetch($res)) {
249
-		$t = sinon($r['titre'], _T('ecrire:info_sans_titre'));
250
-		$GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t));
251
-	}
252
-
253
-	$t = [$last ? $last : time(), $GLOBALS['db_art_cache']];
254
-	ecrire_fichier(_CACHE_RUBRIQUES, serialize($t));
255
-
256
-	return true;
220
+    include_spip('inc/config');
221
+    // ici, un petit fichier cache ne fait pas de mal
222
+    $last = lire_config('date_calcul_rubriques', 0);
223
+    if (lire_fichier(_CACHE_RUBRIQUES, $cache)) {
224
+        list($date, $GLOBALS['db_art_cache']) = @unserialize($cache);
225
+        if ($date == $last) {
226
+            return false;
227
+        } // c'etait en cache :-)
228
+    }
229
+    // se restreindre aux rubriques utilisees recemment +secteurs
230
+
231
+    $where = sql_in_select(
232
+        'id_rubrique',
233
+        'id_rubrique',
234
+        'spip_rubriques',
235
+        '',
236
+        '',
237
+        'id_parent=0 DESC, date DESC',
238
+        _CACHE_RUBRIQUES_MAX
239
+    );
240
+
241
+    // puis refaire la requete pour avoir l'ordre alphabetique
242
+
243
+    $res = sql_select('id_rubrique, titre, id_parent', 'spip_rubriques', $where, '', 'id_parent, 0+titre, titre');
244
+
245
+    // il ne faut pas filtrer le autoriser voir ici
246
+    // car on met le resultat en cache, commun a tout le monde
247
+    $GLOBALS['db_art_cache'] = [];
248
+    while ($r = sql_fetch($res)) {
249
+        $t = sinon($r['titre'], _T('ecrire:info_sans_titre'));
250
+        $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t));
251
+    }
252
+
253
+    $t = [$last ? $last : time(), $GLOBALS['db_art_cache']];
254
+    ecrire_fichier(_CACHE_RUBRIQUES, serialize($t));
255
+
256
+    return true;
257 257
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 	// on renvoi un 401 qui fait echouer la requete ajax silencieusement
40 40
 	if (!autoriser('ecrire')) {
41 41
 		$retour =
42
-		'<ul class="deroulant__sous-menu" data-profondeur="1">' .
43
-			'<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' .
44
-				'<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' .
45
-					'<span class="libelle">' . _T('public:lien_connecter') . '</span>' .
46
-				'</a>' .
47
-			'</li>' .
42
+		'<ul class="deroulant__sous-menu" data-profondeur="1">'.
43
+			'<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">'.
44
+				'<a class="deroulant__lien" href="'.generer_url_ecrire('accueil').'" data-profondeur="1">'.
45
+					'<span class="libelle">'._T('public:lien_connecter').'</span>'.
46
+				'</a>'.
47
+			'</li>'.
48 48
 		'</ul>';
49 49
 		include_spip('inc/actions');
50 50
 		ajax_retour($retour);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	}
53 53
 
54 54
 	if ($date = intval(_request('date'))) {
55
-		header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT');
55
+		header('Last-Modified: '.gmdate('D, d M Y H:i:s', $date).' GMT');
56 56
 	}
57 57
 
58 58
 	$r = gen_liste_rubriques();
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')
63 63
 	) {
64 64
 		include_spip('inc/headers');
65
-		header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
65
+		header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']);
66 66
 		http_response_code(304);
67 67
 		exit;
68 68
 	} else {
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
  **/
86 86
 function menu_rubriques($complet = true) {
87 87
 	$ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">'
88
-		. '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">'
89
-		. '<span class="libelle">' . _T('info_tout_site') . '</span>'
88
+		. '<a class="deroulant__lien" href="'.generer_url_ecrire('plan').'" data-profondeur="1">'
89
+		. '<span class="libelle">'._T('info_tout_site').'</span>'
90 90
 		. '</a>'
91 91
 		. '</li>';
92 92
 
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 	static $zmax = 6;
146 146
 	$profondeur_next = $profondeur + 1;
147 147
 
148
-	$nav = '<a class="deroulant__lien" href="' . generer_url_entite($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">"
149
-		. '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>'
148
+	$nav = '<a class="deroulant__lien" href="'.generer_url_entite($id_rubrique, 'rubrique', '', '', false)."\" data-profondeur=\"$profondeur\">"
149
+		. '<span class="libelle">'.supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)).'</span>'
150 150
 		. "</a>\n";
151 151
 
152 152
 	// Limiter volontairement le nombre de sous-menus
Please login to merge, or discard this patch.
ecrire/action/cookie.php 2 patches
Indentation   +85 added lines, -85 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/actions');
@@ -33,93 +33,93 @@  discard block
 block discarded – undo
33 33
  * @return void
34 34
  */
35 35
 function action_cookie_dist($set_cookie_admin = null, $change_session = null) {
36
-	$redirect_echec = $redirect = null;
37
-	$test_echec_cookie = null;
38
-	$url = '';
39
-	if (is_null($set_cookie_admin)) {
40
-		$set_cookie_admin = _request('cookie_admin');
41
-		$change_session = _request('change_session');
42
-		$test_echec_cookie = _request('test_echec_cookie');
36
+    $redirect_echec = $redirect = null;
37
+    $test_echec_cookie = null;
38
+    $url = '';
39
+    if (is_null($set_cookie_admin)) {
40
+        $set_cookie_admin = _request('cookie_admin');
41
+        $change_session = _request('change_session');
42
+        $test_echec_cookie = _request('test_echec_cookie');
43 43
 
44
-		// La cible de notre operation de connexion
45
-		$url = securiser_redirect_action(_request('url'));
46
-		$redirect = $url ? $url : generer_url_ecrire('accueil');
47
-		$redirect_echec = _request('url_echec');
48
-		if (!isset($redirect_echec)) {
49
-			if (strpos($redirect, _DIR_RESTREINT_ABS) !== false) {
50
-				$redirect_echec = generer_url_public('login', '', true);
51
-			} else {
52
-				$redirect_echec = $redirect;
53
-			}
54
-		}
55
-	}
44
+        // La cible de notre operation de connexion
45
+        $url = securiser_redirect_action(_request('url'));
46
+        $redirect = $url ? $url : generer_url_ecrire('accueil');
47
+        $redirect_echec = _request('url_echec');
48
+        if (!isset($redirect_echec)) {
49
+            if (strpos($redirect, _DIR_RESTREINT_ABS) !== false) {
50
+                $redirect_echec = generer_url_public('login', '', true);
51
+            } else {
52
+                $redirect_echec = $redirect;
53
+            }
54
+        }
55
+    }
56 56
 
57 57
 
58
-	// rejoue le cookie pour renouveler spip_session
59
-	if ($change_session == 'oui') {
60
-		$session = charger_fonction('session', 'inc');
61
-		$session(true);
62
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
63
-		http_response_code(204); // No Content
64
-		return;
65
-	}
58
+    // rejoue le cookie pour renouveler spip_session
59
+    if ($change_session == 'oui') {
60
+        $session = charger_fonction('session', 'inc');
61
+        $session(true);
62
+        spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
63
+        http_response_code(204); // No Content
64
+        return;
65
+    }
66 66
 
67
-	// tentative de connexion en auth_http
68
-	if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) {
69
-		include_spip('inc/auth');
70
-		if (
71
-			@$_SERVER['PHP_AUTH_USER']
72
-			and @$_SERVER['PHP_AUTH_PW']
73
-			and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
74
-		) {
75
-			auth_loger($auteur);
76
-			redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
77
-		} else {
78
-			ask_php_auth(
79
-				_T('info_connexion_refusee'),
80
-				_T('login_login_pass_incorrect'),
81
-				_T('login_retour_site'),
82
-				'url=' . rawurlencode($redirect),
83
-				_T('login_nouvelle_tentative'),
84
-				(strpos($url, _DIR_RESTREINT_ABS) !== false)
85
-			);
86
-		}
87
-	} else {
88
-		// en cas de login sur bonjour=oui, on tente de poser un cookie
89
-		// puis de passer au login qui diagnostiquera l'echec de cookie
90
-		// le cas echeant.
91
-		if ($test_echec_cookie == 'oui') {
92
-			spip_setcookie('spip_session', 'test_echec_cookie');
93
-			if ($redirect) {
94
-				$redirect = parametre_url(
95
-					parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
96
-					'url',
97
-					rawurlencode($redirect),
98
-					'&'
99
-				);
100
-			}
101
-		} else {
102
-			$cook = isset($_COOKIE['spip_admin']) ? $_COOKIE['spip_admin'] : '';
103
-			// Suppression cookie d'admin ?
104
-			if ($set_cookie_admin == 'non') {
105
-				if ($cook) {
106
-					spip_setcookie('spip_admin', $cook, [
107
-						'expires' => time() - 3600 * 24
108
-					]);
109
-				}
110
-			} // Ajout de cookie d'admin
111
-			else {
112
-				if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) {
113
-					spip_setcookie('spip_admin', $set_cookie_admin, [
114
-						'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA)
115
-					]);
116
-				}
117
-			}
118
-		}
119
-	}
67
+    // tentative de connexion en auth_http
68
+    if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) {
69
+        include_spip('inc/auth');
70
+        if (
71
+            @$_SERVER['PHP_AUTH_USER']
72
+            and @$_SERVER['PHP_AUTH_PW']
73
+            and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
74
+        ) {
75
+            auth_loger($auteur);
76
+            redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
77
+        } else {
78
+            ask_php_auth(
79
+                _T('info_connexion_refusee'),
80
+                _T('login_login_pass_incorrect'),
81
+                _T('login_retour_site'),
82
+                'url=' . rawurlencode($redirect),
83
+                _T('login_nouvelle_tentative'),
84
+                (strpos($url, _DIR_RESTREINT_ABS) !== false)
85
+            );
86
+        }
87
+    } else {
88
+        // en cas de login sur bonjour=oui, on tente de poser un cookie
89
+        // puis de passer au login qui diagnostiquera l'echec de cookie
90
+        // le cas echeant.
91
+        if ($test_echec_cookie == 'oui') {
92
+            spip_setcookie('spip_session', 'test_echec_cookie');
93
+            if ($redirect) {
94
+                $redirect = parametre_url(
95
+                    parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
96
+                    'url',
97
+                    rawurlencode($redirect),
98
+                    '&'
99
+                );
100
+            }
101
+        } else {
102
+            $cook = isset($_COOKIE['spip_admin']) ? $_COOKIE['spip_admin'] : '';
103
+            // Suppression cookie d'admin ?
104
+            if ($set_cookie_admin == 'non') {
105
+                if ($cook) {
106
+                    spip_setcookie('spip_admin', $cook, [
107
+                        'expires' => time() - 3600 * 24
108
+                    ]);
109
+                }
110
+            } // Ajout de cookie d'admin
111
+            else {
112
+                if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) {
113
+                    spip_setcookie('spip_admin', $set_cookie_admin, [
114
+                        'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA)
115
+                    ]);
116
+                }
117
+            }
118
+        }
119
+    }
120 120
 
121
-	// Redirection finale
122
-	if ($redirect) {
123
-		redirige_par_entete($redirect, true);
124
-	}
121
+    // Redirection finale
122
+    if ($redirect) {
123
+        redirige_par_entete($redirect, true);
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	if ($change_session == 'oui') {
60 60
 		$session = charger_fonction('session', 'inc');
61 61
 		$session(true);
62
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
62
+		spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']);
63 63
 		http_response_code(204); // No Content
64 64
 		return;
65 65
 	}
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 				_T('info_connexion_refusee'),
80 80
 				_T('login_login_pass_incorrect'),
81 81
 				_T('login_retour_site'),
82
-				'url=' . rawurlencode($redirect),
82
+				'url='.rawurlencode($redirect),
83 83
 				_T('login_nouvelle_tentative'),
84 84
 				(strpos($url, _DIR_RESTREINT_ABS) !== false)
85 85
 			);
Please login to merge, or discard this patch.
ecrire/public.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -21,193 +21,193 @@
 block discarded – undo
21 21
 // par souci de compatiilite).
22 22
 
23 23
 if (isset($GLOBALS['_INC_PUBLIC']) and $GLOBALS['_INC_PUBLIC']) {
24
-	echo recuperer_fond($fond, $contexte_inclus, [], _request('connect'));
24
+    echo recuperer_fond($fond, $contexte_inclus, [], _request('connect'));
25 25
 } else {
26
-	$GLOBALS['_INC_PUBLIC'] = 1;
27
-	define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : '');
28
-
29
-	// Faut-il initialiser SPIP ? (oui dans le cas general)
30
-	if (!defined('_DIR_RESTREINT_ABS')) {
31
-		if (
32
-			defined('_DIR_RESTREINT')
33
-			and @file_exists(_ROOT_RESTREINT . 'inc_version.php')
34
-		) {
35
-			include_once _ROOT_RESTREINT . 'inc_version.php';
36
-		} else {
37
-			die('inc_version absent ?');
38
-		}
39
-	} // $fond defini dans le fichier d'appel ?
40
-
41
-	else {
42
-		if (isset($fond) and !_request('fond')) {
43
-		} // fond demande dans l'url par page=xxxx ?
44
-		else {
45
-			if (isset($_GET[_SPIP_PAGE])) {
46
-				$fond = (string)$_GET[_SPIP_PAGE];
47
-
48
-				// Securite
49
-				if (
50
-					strstr($fond, '/')
51
-					and !(
52
-						isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes
53
-						and include_spip('inc/autoriser')
54
-						and autoriser('webmestre'))
55
-				) {
56
-					include_spip('inc/minipres');
57
-					echo minipres();
58
-					exit;
59
-				}
60
-				// l'argument Page a priorite sur l'argument action
61
-				// le cas se presente a cause des RewriteRule d'Apache
62
-				// qui permettent d'ajouter un argument dans la QueryString
63
-				// mais pas d'en retirer un en conservant les autres.
64
-				if (isset($_GET['action']) and $_GET['action'] === $fond) {
65
-					unset($_GET['action']);
66
-				}
67
-				# sinon, fond par defaut
68
-			} else {
69
-				// sinon fond par defaut (cf. assembler.php)
70
-				$fond = pipeline('detecter_fond_par_defaut', '');
71
-			}
72
-		}
73
-	}
74
-
75
-	$tableau_des_temps = [];
76
-
77
-	// Particularites de certains squelettes
78
-	if ($fond == 'login') {
79
-		$forcer_lang = true;
80
-	}
81
-
82
-	if (
83
-		isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non')
84
-		and !_request('action')
85
-		and $_SERVER['REQUEST_METHOD'] != 'POST'
86
-	) {
87
-		include_spip('inc/lang');
88
-		verifier_lang_url();
89
-	}
90
-
91
-	$lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']);
92
-
93
-	// Charger l'aiguilleur des traitements derogatoires
94
-	// (action en base SQL, formulaires CVT, AJax)
95
-	if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
96
-		include_spip('public/aiguiller');
97
-		if (
98
-			// cas des appels actions ?action=xxx
99
-			traiter_appels_actions()
100
-			or
101
-			// cas des hits ajax sur les inclusions ajax
102
-			traiter_appels_inclusions_ajax()
103
-			or
104
-			// cas des formulaires charger/verifier/traiter
105
-			traiter_formulaires_dynamiques()
106
-		) {
107
-			// lancer les taches sur affichage final, comme le cron
108
-			// mais sans rien afficher
109
-			$GLOBALS['html'] = false; // ne rien afficher
110
-			pipeline('affichage_final' . _PIPELINE_SUFFIX, '');
111
-			exit; // le hit est fini !
112
-		}
113
-	}
114
-
115
-	// Il y a du texte a produire, charger le metteur en page
116
-	include_spip('public/assembler');
117
-	$page = assembler($fond, _request('connect'));
118
-
119
-	if (isset($page['status'])) {
120
-		include_spip('inc/headers');
121
-		http_response_code($page['status']);
122
-	}
123
-
124
-	// Content-Type ?
125
-	if (!isset($page['entetes']['Content-Type'])) {
126
-		$charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : 'utf-8';
127
-		$page['entetes']['Content-Type'] = 'text/html; charset=' . $charset;
128
-		$html = true;
129
-	} else {
130
-		$html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']);
131
-	}
132
-
133
-	// Tester si on est admin et il y a des choses supplementaires a dire
134
-	// type tableau pour y mettre des choses au besoin.
135
-	$debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : [];
136
-
137
-	// affiche-t-on les boutons d'administration ? voir f_admin()
138
-	$affiche_boutons_admin = ($html and (
139
-			(isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver))
140
-			or ($debug and include_spip('inc/autoriser') and autoriser('debug'))
141
-			or (defined('_VAR_PREVIEW') and _VAR_PREVIEW)
142
-		));
143
-
144
-	if ($affiche_boutons_admin) {
145
-		include_spip('balise/formulaire_admin');
146
-	}
147
-
148
-
149
-	// Execution de la page calculee
150
-
151
-	// traitements sur les entetes avant envoi
152
-	// peut servir pour le plugin de stats
153
-	$page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']);
154
-
155
-
156
-	// eval $page et affecte $res
157
-	include _ROOT_RESTREINT . 'public/evaluer_page.php';
158
-	envoyer_entetes($page['entetes']);
159
-	if ($res === false) {
160
-		include_spip('inc/autoriser');
161
-		$err = _T('zbug_erreur_execution_page');
162
-		if (autoriser('webmestre')) {
163
-			$err .= "\n<hr />\n"
164
-				. highlight_string($page['codephp'], true)
165
-				. "\n<hr />\n";
166
-		}
167
-		$msg = [$err];
168
-		erreur_squelette($msg);
169
-	}
170
-
171
-	//
172
-	// Envoyer le resultat apres post-traitements
173
-	//
174
-	// (c'est ici qu'on fait var_recherche, validation, boutons d'admin,
175
-	// cf. public/assembler.php)
176
-	echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']);
177
-
178
-	if ($lang) {
179
-		lang_select();
180
-	}
181
-	// l'affichage de la page a pu lever des erreurs (inclusion manquante)
182
-	// il faut tester a nouveau
183
-	$debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : [];
184
-
185
-	// Appel au debusqueur en cas d'erreurs ou de demande de trace
186
-	// at last
187
-	if ($debug) {
188
-		// en cas d'erreur, retester l'affichage
189
-		if ($html and ($affiche_boutons_admin or $debug)) {
190
-			$var_mode_affiche = _request('var_mode_affiche');
191
-			$var_mode_objet = _request('var_mode_objet');
192
-			$GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : '');
193
-			echo erreur_squelette(false);
194
-		}
195
-	} else {
196
-		if (
197
-			isset($GLOBALS['meta']['date_prochain_postdate'])
198
-			and $GLOBALS['meta']['date_prochain_postdate'] <= time()
199
-		) {
200
-			include_spip('inc/rubriques');
201
-			calculer_prochain_postdate(true);
202
-		}
203
-
204
-		// Effectuer une tache de fond ?
205
-		// si _DIRECT_CRON_FORCE est present, on force l'appel
206
-		if (defined('_DIRECT_CRON_FORCE')) {
207
-			cron();
208
-		}
209
-
210
-		// sauver le cache chemin si necessaire
211
-		save_path_cache();
212
-	}
26
+    $GLOBALS['_INC_PUBLIC'] = 1;
27
+    define('_PIPELINE_SUFFIX', test_espace_prive() ? '_prive' : '');
28
+
29
+    // Faut-il initialiser SPIP ? (oui dans le cas general)
30
+    if (!defined('_DIR_RESTREINT_ABS')) {
31
+        if (
32
+            defined('_DIR_RESTREINT')
33
+            and @file_exists(_ROOT_RESTREINT . 'inc_version.php')
34
+        ) {
35
+            include_once _ROOT_RESTREINT . 'inc_version.php';
36
+        } else {
37
+            die('inc_version absent ?');
38
+        }
39
+    } // $fond defini dans le fichier d'appel ?
40
+
41
+    else {
42
+        if (isset($fond) and !_request('fond')) {
43
+        } // fond demande dans l'url par page=xxxx ?
44
+        else {
45
+            if (isset($_GET[_SPIP_PAGE])) {
46
+                $fond = (string)$_GET[_SPIP_PAGE];
47
+
48
+                // Securite
49
+                if (
50
+                    strstr($fond, '/')
51
+                    and !(
52
+                        isset($GLOBALS['visiteur_session']) // pour eviter d'evaluer la suite pour les anonymes
53
+                        and include_spip('inc/autoriser')
54
+                        and autoriser('webmestre'))
55
+                ) {
56
+                    include_spip('inc/minipres');
57
+                    echo minipres();
58
+                    exit;
59
+                }
60
+                // l'argument Page a priorite sur l'argument action
61
+                // le cas se presente a cause des RewriteRule d'Apache
62
+                // qui permettent d'ajouter un argument dans la QueryString
63
+                // mais pas d'en retirer un en conservant les autres.
64
+                if (isset($_GET['action']) and $_GET['action'] === $fond) {
65
+                    unset($_GET['action']);
66
+                }
67
+                # sinon, fond par defaut
68
+            } else {
69
+                // sinon fond par defaut (cf. assembler.php)
70
+                $fond = pipeline('detecter_fond_par_defaut', '');
71
+            }
72
+        }
73
+    }
74
+
75
+    $tableau_des_temps = [];
76
+
77
+    // Particularites de certains squelettes
78
+    if ($fond == 'login') {
79
+        $forcer_lang = true;
80
+    }
81
+
82
+    if (
83
+        isset($forcer_lang) and $forcer_lang and ($forcer_lang !== 'non')
84
+        and !_request('action')
85
+        and $_SERVER['REQUEST_METHOD'] != 'POST'
86
+    ) {
87
+        include_spip('inc/lang');
88
+        verifier_lang_url();
89
+    }
90
+
91
+    $lang = !isset($_GET['lang']) ? '' : lang_select($_GET['lang']);
92
+
93
+    // Charger l'aiguilleur des traitements derogatoires
94
+    // (action en base SQL, formulaires CVT, AJax)
95
+    if (_request('action') or _request('var_ajax') or _request('formulaire_action')) {
96
+        include_spip('public/aiguiller');
97
+        if (
98
+            // cas des appels actions ?action=xxx
99
+            traiter_appels_actions()
100
+            or
101
+            // cas des hits ajax sur les inclusions ajax
102
+            traiter_appels_inclusions_ajax()
103
+            or
104
+            // cas des formulaires charger/verifier/traiter
105
+            traiter_formulaires_dynamiques()
106
+        ) {
107
+            // lancer les taches sur affichage final, comme le cron
108
+            // mais sans rien afficher
109
+            $GLOBALS['html'] = false; // ne rien afficher
110
+            pipeline('affichage_final' . _PIPELINE_SUFFIX, '');
111
+            exit; // le hit est fini !
112
+        }
113
+    }
114
+
115
+    // Il y a du texte a produire, charger le metteur en page
116
+    include_spip('public/assembler');
117
+    $page = assembler($fond, _request('connect'));
118
+
119
+    if (isset($page['status'])) {
120
+        include_spip('inc/headers');
121
+        http_response_code($page['status']);
122
+    }
123
+
124
+    // Content-Type ?
125
+    if (!isset($page['entetes']['Content-Type'])) {
126
+        $charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : 'utf-8';
127
+        $page['entetes']['Content-Type'] = 'text/html; charset=' . $charset;
128
+        $html = true;
129
+    } else {
130
+        $html = preg_match(',^\s*text/html,', $page['entetes']['Content-Type']);
131
+    }
132
+
133
+    // Tester si on est admin et il y a des choses supplementaires a dire
134
+    // type tableau pour y mettre des choses au besoin.
135
+    $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : [];
136
+
137
+    // affiche-t-on les boutons d'administration ? voir f_admin()
138
+    $affiche_boutons_admin = ($html and (
139
+            (isset($_COOKIE['spip_admin']) and (!isset($flag_preserver) or !$flag_preserver))
140
+            or ($debug and include_spip('inc/autoriser') and autoriser('debug'))
141
+            or (defined('_VAR_PREVIEW') and _VAR_PREVIEW)
142
+        ));
143
+
144
+    if ($affiche_boutons_admin) {
145
+        include_spip('balise/formulaire_admin');
146
+    }
147
+
148
+
149
+    // Execution de la page calculee
150
+
151
+    // traitements sur les entetes avant envoi
152
+    // peut servir pour le plugin de stats
153
+    $page['entetes'] = pipeline('affichage_entetes_final' . _PIPELINE_SUFFIX, $page['entetes']);
154
+
155
+
156
+    // eval $page et affecte $res
157
+    include _ROOT_RESTREINT . 'public/evaluer_page.php';
158
+    envoyer_entetes($page['entetes']);
159
+    if ($res === false) {
160
+        include_spip('inc/autoriser');
161
+        $err = _T('zbug_erreur_execution_page');
162
+        if (autoriser('webmestre')) {
163
+            $err .= "\n<hr />\n"
164
+                . highlight_string($page['codephp'], true)
165
+                . "\n<hr />\n";
166
+        }
167
+        $msg = [$err];
168
+        erreur_squelette($msg);
169
+    }
170
+
171
+    //
172
+    // Envoyer le resultat apres post-traitements
173
+    //
174
+    // (c'est ici qu'on fait var_recherche, validation, boutons d'admin,
175
+    // cf. public/assembler.php)
176
+    echo pipeline('affichage_final' . _PIPELINE_SUFFIX, $page['texte']);
177
+
178
+    if ($lang) {
179
+        lang_select();
180
+    }
181
+    // l'affichage de la page a pu lever des erreurs (inclusion manquante)
182
+    // il faut tester a nouveau
183
+    $debug = ((_request('var_mode') == 'debug') or $tableau_des_temps) ? [1] : [];
184
+
185
+    // Appel au debusqueur en cas d'erreurs ou de demande de trace
186
+    // at last
187
+    if ($debug) {
188
+        // en cas d'erreur, retester l'affichage
189
+        if ($html and ($affiche_boutons_admin or $debug)) {
190
+            $var_mode_affiche = _request('var_mode_affiche');
191
+            $var_mode_objet = _request('var_mode_objet');
192
+            $GLOBALS['debug_objets'][$var_mode_affiche][$var_mode_objet . 'tout'] = ($var_mode_affiche == 'validation' ? $page['texte'] : '');
193
+            echo erreur_squelette(false);
194
+        }
195
+    } else {
196
+        if (
197
+            isset($GLOBALS['meta']['date_prochain_postdate'])
198
+            and $GLOBALS['meta']['date_prochain_postdate'] <= time()
199
+        ) {
200
+            include_spip('inc/rubriques');
201
+            calculer_prochain_postdate(true);
202
+        }
203
+
204
+        // Effectuer une tache de fond ?
205
+        // si _DIRECT_CRON_FORCE est present, on force l'appel
206
+        if (defined('_DIRECT_CRON_FORCE')) {
207
+            cron();
208
+        }
209
+
210
+        // sauver le cache chemin si necessaire
211
+        save_path_cache();
212
+    }
213 213
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2402 added lines, -2402 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,38 +77,38 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if (!strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if (!strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	list($h, $l) = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    list($h, $l) = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	list($h, $l) = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    list($h, $l) = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
-	static $to = null;
870
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -911,40 +911,40 @@  discard block
 block discarded – undo
911 911
  */
912 912
 function texte_backend($texte) {
913 913
 
914
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
914
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
915 915
 
916
-	// si on a des liens ou des images, les passer en absolu
917
-	$texte = liens_absolus($texte);
916
+    // si on a des liens ou des images, les passer en absolu
917
+    $texte = liens_absolus($texte);
918 918
 
919
-	// echapper les tags &gt; &lt;
920
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
919
+    // echapper les tags &gt; &lt;
920
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
921 921
 
922
-	// importer les &eacute;
923
-	$texte = filtrer_entites($texte);
922
+    // importer les &eacute;
923
+    $texte = filtrer_entites($texte);
924 924
 
925
-	// " -> &quot; et tout ce genre de choses
926
-	$u = $GLOBALS['meta']['pcre_u'];
927
-	$texte = str_replace('&nbsp;', ' ', $texte);
928
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
-	$texte = entites_html($texte, false, false);
931
-	// mais bien echapper les double quotes !
932
-	$texte = str_replace('"', '&#034;', $texte);
925
+    // " -> &quot; et tout ce genre de choses
926
+    $u = $GLOBALS['meta']['pcre_u'];
927
+    $texte = str_replace('&nbsp;', ' ', $texte);
928
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
+    $texte = entites_html($texte, false, false);
931
+    // mais bien echapper les double quotes !
932
+    $texte = str_replace('"', '&#034;', $texte);
933 933
 
934
-	// verifier le charset
935
-	$texte = charset2unicode($texte);
934
+    // verifier le charset
935
+    $texte = charset2unicode($texte);
936 936
 
937
-	// Caracteres problematiques en iso-latin 1
938
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
-		$texte = str_replace(chr(156), '&#156;', $texte);
940
-		$texte = str_replace(chr(140), '&#140;', $texte);
941
-		$texte = str_replace(chr(159), '&#159;', $texte);
942
-	}
937
+    // Caracteres problematiques en iso-latin 1
938
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
+        $texte = str_replace(chr(156), '&#156;', $texte);
940
+        $texte = str_replace(chr(140), '&#140;', $texte);
941
+        $texte = str_replace(chr(159), '&#159;', $texte);
942
+    }
943 943
 
944
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
945
-	// et le caractere apostrophe alourdit les squelettes avec PHP
946
-	// ==> on les remplace par l'entite HTML
947
-	return str_replace($apostrophe, "'", $texte);
944
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
945
+    // et le caractere apostrophe alourdit les squelettes avec PHP
946
+    // ==> on les remplace par l'entite HTML
947
+    return str_replace($apostrophe, "'", $texte);
948 948
 }
949 949
 
950 950
 /**
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
  *     Texte encodé et quote pour XML
962 962
  */
963 963
 function texte_backendq($texte) {
964
-	return addslashes(texte_backend($texte));
964
+    return addslashes(texte_backend($texte));
965 965
 }
966 966
 
967 967
 
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
  *     Numéro de titre, sinon chaîne vide
985 985
  **/
986 986
 function supprimer_numero($texte) {
987
-	return preg_replace(
988
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
-		'',
990
-		$texte
991
-	);
987
+    return preg_replace(
988
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
+        '',
990
+        $texte
991
+    );
992 992
 }
993 993
 
994 994
 /**
@@ -1011,17 +1011,17 @@  discard block
 block discarded – undo
1011 1011
  *     Numéro de titre, sinon chaîne vide
1012 1012
  **/
1013 1013
 function recuperer_numero($texte) {
1014
-	if (
1015
-		preg_match(
1016
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
-			$texte,
1018
-			$regs
1019
-		)
1020
-	) {
1021
-		return strval($regs[1]);
1022
-	} else {
1023
-		return '';
1024
-	}
1014
+    if (
1015
+        preg_match(
1016
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
+            $texte,
1018
+            $regs
1019
+        )
1020
+    ) {
1021
+        return strval($regs[1]);
1022
+    } else {
1023
+        return '';
1024
+    }
1025 1025
 }
1026 1026
 
1027 1027
 /**
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
  *     Texte converti
1049 1049
  **/
1050 1050
 function supprimer_tags($texte, $rempl = '') {
1051
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
-	// ne pas oublier un < final non ferme car coupe
1053
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
-	// mais qui peut aussi etre un simple signe plus petit que
1055
-	$texte = str_replace('<', '&lt;', $texte);
1051
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
+    // ne pas oublier un < final non ferme car coupe
1053
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
+    // mais qui peut aussi etre un simple signe plus petit que
1055
+    $texte = str_replace('<', '&lt;', $texte);
1056 1056
 
1057
-	return $texte;
1057
+    return $texte;
1058 1058
 }
1059 1059
 
1060 1060
 /**
@@ -1077,9 +1077,9 @@  discard block
 block discarded – undo
1077 1077
  *     Texte converti
1078 1078
  **/
1079 1079
 function echapper_tags($texte, $rempl = '') {
1080
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1080
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1100,18 +1100,18 @@  discard block
 block discarded – undo
1100 1100
  *     Texte converti
1101 1101
  **/
1102 1102
 function textebrut($texte) {
1103
-	$u = $GLOBALS['meta']['pcre_u'];
1104
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
-	$texte = preg_replace("/^\n+/", '', $texte);
1107
-	$texte = preg_replace("/\n+$/", '', $texte);
1108
-	$texte = preg_replace("/\n +/", "\n", $texte);
1109
-	$texte = supprimer_tags($texte);
1110
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
-	$texte = str_replace('&#8217;', "'", $texte);
1103
+    $u = $GLOBALS['meta']['pcre_u'];
1104
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
+    $texte = preg_replace("/^\n+/", '', $texte);
1107
+    $texte = preg_replace("/\n+$/", '', $texte);
1108
+    $texte = preg_replace("/\n +/", "\n", $texte);
1109
+    $texte = supprimer_tags($texte);
1110
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
+    $texte = str_replace('&#8217;', "'", $texte);
1113 1113
 
1114
-	return $texte;
1114
+    return $texte;
1115 1115
 }
1116 1116
 
1117 1117
 
@@ -1127,23 +1127,23 @@  discard block
 block discarded – undo
1127 1127
  *     Texte avec liens ouvrants
1128 1128
  **/
1129 1129
 function liens_ouvrants($texte) {
1130
-	if (
1131
-		preg_match_all(
1132
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
-			$texte,
1134
-			$liens,
1135
-			PREG_PATTERN_ORDER
1136
-		)
1137
-	) {
1138
-		foreach ($liens[0] as $a) {
1139
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
-			$ablank = inserer_attribut($a, 'rel', $rel);
1141
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1142
-			$texte = str_replace($a, $ablank, $texte);
1143
-		}
1144
-	}
1145
-
1146
-	return $texte;
1130
+    if (
1131
+        preg_match_all(
1132
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
+            $texte,
1134
+            $liens,
1135
+            PREG_PATTERN_ORDER
1136
+        )
1137
+    ) {
1138
+        foreach ($liens[0] as $a) {
1139
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
+            $ablank = inserer_attribut($a, 'rel', $rel);
1141
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1142
+            $texte = str_replace($a, $ablank, $texte);
1143
+        }
1144
+    }
1145
+
1146
+    return $texte;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1153,22 +1153,22 @@  discard block
 block discarded – undo
1153 1153
  * @return string
1154 1154
  */
1155 1155
 function liens_nofollow($texte) {
1156
-	if (stripos($texte, '<a') === false) {
1157
-		return $texte;
1158
-	}
1156
+    if (stripos($texte, '<a') === false) {
1157
+        return $texte;
1158
+    }
1159 1159
 
1160
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
-		foreach ($regs[0] as $a) {
1162
-			$rel = extraire_attribut($a, 'rel');
1163
-			if (strpos($rel, 'nofollow') === false) {
1164
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1165
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1166
-				$texte = str_replace($a, $anofollow, $texte);
1167
-			}
1168
-		}
1169
-	}
1160
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
+        foreach ($regs[0] as $a) {
1162
+            $rel = extraire_attribut($a, 'rel');
1163
+            if (strpos($rel, 'nofollow') === false) {
1164
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1165
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1166
+                $texte = str_replace($a, $anofollow, $texte);
1167
+            }
1168
+        }
1169
+    }
1170 1170
 
1171
-	return $texte;
1171
+    return $texte;
1172 1172
 }
1173 1173
 
1174 1174
 /**
@@ -1187,12 +1187,12 @@  discard block
 block discarded – undo
1187 1187
  *     Texte sans paraghaphes
1188 1188
  **/
1189 1189
 function PtoBR($texte) {
1190
-	$u = $GLOBALS['meta']['pcre_u'];
1191
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1192
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1190
+    $u = $GLOBALS['meta']['pcre_u'];
1191
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1192
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1194 1194
 
1195
-	return $texte;
1195
+    return $texte;
1196 1196
 }
1197 1197
 
1198 1198
 
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
  * @return string Texte encadré du style CSS
1218 1218
  */
1219 1219
 function lignes_longues($texte) {
1220
-	if (!strlen(trim($texte))) {
1221
-		return $texte;
1222
-	}
1223
-	include_spip('inc/texte');
1224
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
-		'div' : 'span';
1220
+    if (!strlen(trim($texte))) {
1221
+        return $texte;
1222
+    }
1223
+    include_spip('inc/texte');
1224
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
+        'div' : 'span';
1226 1226
 
1227
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1227
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1243,30 +1243,30 @@  discard block
 block discarded – undo
1243 1243
  * @return string Texte en majuscule
1244 1244
  */
1245 1245
 function majuscules($texte) {
1246
-	if (!strlen($texte)) {
1247
-		return '';
1248
-	}
1246
+    if (!strlen($texte)) {
1247
+        return '';
1248
+    }
1249 1249
 
1250
-	// Cas du turc
1251
-	if ($GLOBALS['spip_lang'] == 'tr') {
1252
-		# remplacer hors des tags et des entites
1253
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
-			foreach ($regs as $n => $match) {
1255
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
-			}
1257
-		}
1250
+    // Cas du turc
1251
+    if ($GLOBALS['spip_lang'] == 'tr') {
1252
+        # remplacer hors des tags et des entites
1253
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
+            foreach ($regs as $n => $match) {
1255
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
+            }
1257
+        }
1258 1258
 
1259
-		$texte = str_replace('i', '&#304;', $texte);
1259
+        $texte = str_replace('i', '&#304;', $texte);
1260 1260
 
1261
-		if ($regs) {
1262
-			foreach ($regs as $n => $match) {
1263
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
-			}
1265
-		}
1266
-	}
1261
+        if ($regs) {
1262
+            foreach ($regs as $n => $match) {
1263
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
+            }
1265
+        }
1266
+    }
1267 1267
 
1268
-	// Cas general
1269
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1268
+    // Cas general
1269
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1270 1270
 }
1271 1271
 
1272 1272
 /**
@@ -1284,29 +1284,29 @@  discard block
 block discarded – undo
1284 1284
  * @return string
1285 1285
  **/
1286 1286
 function taille_en_octets($taille) {
1287
-	if (!defined('_KILOBYTE')) {
1288
-		/**
1289
-		 * Définit le nombre d'octets dans un Kilobyte
1290
-		 *
1291
-		 * @var int
1292
-		 **/
1293
-		define('_KILOBYTE', 1024);
1294
-	}
1287
+    if (!defined('_KILOBYTE')) {
1288
+        /**
1289
+         * Définit le nombre d'octets dans un Kilobyte
1290
+         *
1291
+         * @var int
1292
+         **/
1293
+        define('_KILOBYTE', 1024);
1294
+    }
1295 1295
 
1296
-	if ($taille < 1) {
1297
-		return '';
1298
-	}
1299
-	if ($taille < _KILOBYTE) {
1300
-		$taille = _T('taille_octets', ['taille' => $taille]);
1301
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
-	} else {
1306
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
-	}
1296
+    if ($taille < 1) {
1297
+        return '';
1298
+    }
1299
+    if ($taille < _KILOBYTE) {
1300
+        $taille = _T('taille_octets', ['taille' => $taille]);
1301
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
+    } else {
1306
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
+    }
1308 1308
 
1309
-	return $taille;
1309
+    return $taille;
1310 1310
 }
1311 1311
 
1312 1312
 
@@ -1328,18 +1328,18 @@  discard block
 block discarded – undo
1328 1328
  *     Texte prêt pour être utilisé en attribut HTML
1329 1329
  **/
1330 1330
 function attribut_html($texte, $textebrut = true) {
1331
-	$u = $GLOBALS['meta']['pcre_u'];
1332
-	if ($textebrut) {
1333
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
-	}
1335
-	$texte = texte_backend($texte);
1336
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1331
+    $u = $GLOBALS['meta']['pcre_u'];
1332
+    if ($textebrut) {
1333
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
+    }
1335
+    $texte = texte_backend($texte);
1336
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337 1337
 
1338
-	return preg_replace(
1339
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
-		['&', '&#38;'],
1341
-		$texte
1342
-	);
1338
+    return preg_replace(
1339
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
+        ['&', '&#38;'],
1341
+        $texte
1342
+    );
1343 1343
 }
1344 1344
 
1345 1345
 
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
  *     URL ou chaîne vide
1360 1360
  **/
1361 1361
 function vider_url($url, $entites = true) {
1362
-	# un message pour abs_url
1363
-	$GLOBALS['mode_abs_url'] = 'url';
1364
-	$url = trim($url);
1365
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1362
+    # un message pour abs_url
1363
+    $GLOBALS['mode_abs_url'] = 'url';
1364
+    $url = trim($url);
1365
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1366 1366
 
1367
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1367
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1368 1368
 }
1369 1369
 
1370 1370
 
@@ -1379,10 +1379,10 @@  discard block
 block discarded – undo
1379 1379
  * @return string Adresse email maquillée
1380 1380
  **/
1381 1381
 function antispam($texte) {
1382
-	include_spip('inc/acces');
1383
-	$masque = creer_pass_aleatoire(3);
1382
+    include_spip('inc/acces');
1383
+    $masque = creer_pass_aleatoire(3);
1384 1384
 
1385
-	return preg_replace('/@/', " $masque ", $texte);
1385
+    return preg_replace('/@/', " $masque ", $texte);
1386 1386
 }
1387 1387
 
1388 1388
 /**
@@ -1414,12 +1414,12 @@  discard block
 block discarded – undo
1414 1414
  *     True si on a le droit d'accès, false sinon.
1415 1415
  **/
1416 1416
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1417
-	include_spip('inc/acces');
1418
-	if ($op) {
1419
-		$dir .= " $op $args";
1420
-	}
1417
+    include_spip('inc/acces');
1418
+    if ($op) {
1419
+        $dir .= " $op $args";
1420
+    }
1421 1421
 
1422
-	return verifier_low_sec($id_auteur, $cle, $dir);
1422
+    return verifier_low_sec($id_auteur, $cle, $dir);
1423 1423
 }
1424 1424
 
1425 1425
 /**
@@ -1444,11 +1444,11 @@  discard block
 block discarded – undo
1444 1444
  *     Retourne $texte, sinon $sinon.
1445 1445
  **/
1446 1446
 function sinon($texte, $sinon = '') {
1447
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1448
-		return $texte;
1449
-	} else {
1450
-		return $sinon;
1451
-	}
1447
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1448
+        return $texte;
1449
+    } else {
1450
+        return $sinon;
1451
+    }
1452 1452
 }
1453 1453
 
1454 1454
 /**
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
  * @return mixed
1473 1473
  **/
1474 1474
 function choixsivide($a, $vide, $pasvide) {
1475
-	return $a ? $pasvide : $vide;
1475
+    return $a ? $pasvide : $vide;
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
  * @return mixed
1497 1497
  **/
1498 1498
 function choixsiegal($a1, $a2, $v, $f) {
1499
-	return ($a1 == $a2) ? $v : $f;
1499
+    return ($a1 == $a2) ? $v : $f;
1500 1500
 }
1501 1501
 
1502 1502
 //
@@ -1515,13 +1515,13 @@  discard block
 block discarded – undo
1515 1515
  * @return string
1516 1516
  **/
1517 1517
 function filtrer_ical($texte) {
1518
-	#include_spip('inc/charsets');
1519
-	$texte = html2unicode($texte);
1520
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
-	$texte = preg_replace("/\n/", ' ', $texte);
1522
-	$texte = preg_replace('/,/', '\,', $texte);
1518
+    #include_spip('inc/charsets');
1519
+    $texte = html2unicode($texte);
1520
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
+    $texte = preg_replace("/\n/", ' ', $texte);
1522
+    $texte = preg_replace('/,/', '\,', $texte);
1523 1523
 
1524
-	return $texte;
1524
+    return $texte;
1525 1525
 }
1526 1526
 
1527 1527
 
@@ -1546,54 +1546,54 @@  discard block
 block discarded – undo
1546 1546
  * @return string
1547 1547
  **/
1548 1548
 function post_autobr($texte, $delim = "\n_ ") {
1549
-	if (!function_exists('echappe_html')) {
1550
-		include_spip('inc/texte_mini');
1551
-	}
1552
-	$texte = str_replace("\r\n", "\r", $texte);
1553
-	$texte = str_replace("\r", "\n", $texte);
1554
-
1555
-	if (preg_match(",\n+$,", $texte, $fin)) {
1556
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
-	} else {
1558
-		$fin = '';
1559
-	}
1560
-
1561
-	$texte = echappe_html($texte, '', true);
1562
-
1563
-	// echapper les modeles
1564
-	if (strpos($texte, '<') !== false) {
1565
-		include_spip('inc/lien');
1566
-		if (defined('_PREG_MODELE')) {
1567
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1569
-		}
1570
-	}
1571
-
1572
-	$debut = '';
1573
-	$suite = $texte;
1574
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1575
-		$debut .= substr($suite, 0, $t - 1);
1576
-		$suite = substr($suite, $t);
1577
-		$car = substr($suite, 0, 1);
1578
-		if (
1579
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
-		) {
1583
-			$debut .= $delim;
1584
-		} else {
1585
-			$debut .= "\n";
1586
-		}
1587
-		if (preg_match(",^\n+,", $suite, $regs)) {
1588
-			$debut .= $regs[0];
1589
-			$suite = substr($suite, strlen($regs[0]));
1590
-		}
1591
-	}
1592
-	$texte = $debut . $suite;
1593
-
1594
-	$texte = echappe_retour($texte);
1595
-
1596
-	return $texte . $fin;
1549
+    if (!function_exists('echappe_html')) {
1550
+        include_spip('inc/texte_mini');
1551
+    }
1552
+    $texte = str_replace("\r\n", "\r", $texte);
1553
+    $texte = str_replace("\r", "\n", $texte);
1554
+
1555
+    if (preg_match(",\n+$,", $texte, $fin)) {
1556
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
+    } else {
1558
+        $fin = '';
1559
+    }
1560
+
1561
+    $texte = echappe_html($texte, '', true);
1562
+
1563
+    // echapper les modeles
1564
+    if (strpos($texte, '<') !== false) {
1565
+        include_spip('inc/lien');
1566
+        if (defined('_PREG_MODELE')) {
1567
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1569
+        }
1570
+    }
1571
+
1572
+    $debut = '';
1573
+    $suite = $texte;
1574
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1575
+        $debut .= substr($suite, 0, $t - 1);
1576
+        $suite = substr($suite, $t);
1577
+        $car = substr($suite, 0, 1);
1578
+        if (
1579
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
+        ) {
1583
+            $debut .= $delim;
1584
+        } else {
1585
+            $debut .= "\n";
1586
+        }
1587
+        if (preg_match(",^\n+,", $suite, $regs)) {
1588
+            $debut .= $regs[0];
1589
+            $suite = substr($suite, strlen($regs[0]));
1590
+        }
1591
+    }
1592
+    $texte = $debut . $suite;
1593
+
1594
+    $texte = echappe_retour($texte);
1595
+
1596
+    return $texte . $fin;
1597 1597
 }
1598 1598
 
1599 1599
 
@@ -1634,47 +1634,47 @@  discard block
 block discarded – undo
1634 1634
  * @return string
1635 1635
  **/
1636 1636
 function extraire_idiome($letexte, $lang = null, $options = []) {
1637
-	static $traduire = false;
1638
-	if (
1639
-		$letexte
1640
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
-	) {
1642
-		if (!$traduire) {
1643
-			$traduire = charger_fonction('traduire', 'inc');
1644
-			include_spip('inc/lang');
1645
-		}
1646
-		if (!$lang) {
1647
-			$lang = $GLOBALS['spip_lang'];
1648
-		}
1649
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
-		if (is_bool($options)) {
1651
-			$options = ['echappe_span' => $options];
1652
-		}
1653
-		if (!isset($options['echappe_span'])) {
1654
-			$options = array_merge($options, ['echappe_span' => false]);
1655
-		}
1656
-
1657
-		foreach ($regs as $reg) {
1658
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
-			$desc = $traduire($cle, $lang, true);
1660
-			$l = $desc->langue;
1661
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
-			if (strlen($desc->texte)) {
1663
-				$trad = code_echappement($desc->texte, 'idiome', false);
1664
-				if ($l !== $lang) {
1665
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
-				}
1667
-				if (lang_dir($l) !== lang_dir($lang)) {
1668
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
-				}
1670
-				if (!$options['echappe_span']) {
1671
-					$trad = echappe_retour($trad, 'idiome');
1672
-				}
1673
-				$letexte = str_replace($reg[0], $trad, $letexte);
1674
-			}
1675
-		}
1676
-	}
1677
-	return $letexte;
1637
+    static $traduire = false;
1638
+    if (
1639
+        $letexte
1640
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
+    ) {
1642
+        if (!$traduire) {
1643
+            $traduire = charger_fonction('traduire', 'inc');
1644
+            include_spip('inc/lang');
1645
+        }
1646
+        if (!$lang) {
1647
+            $lang = $GLOBALS['spip_lang'];
1648
+        }
1649
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
+        if (is_bool($options)) {
1651
+            $options = ['echappe_span' => $options];
1652
+        }
1653
+        if (!isset($options['echappe_span'])) {
1654
+            $options = array_merge($options, ['echappe_span' => false]);
1655
+        }
1656
+
1657
+        foreach ($regs as $reg) {
1658
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
+            $desc = $traduire($cle, $lang, true);
1660
+            $l = $desc->langue;
1661
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
+            if (strlen($desc->texte)) {
1663
+                $trad = code_echappement($desc->texte, 'idiome', false);
1664
+                if ($l !== $lang) {
1665
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
+                }
1667
+                if (lang_dir($l) !== lang_dir($lang)) {
1668
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
+                }
1670
+                if (!$options['echappe_span']) {
1671
+                    $trad = echappe_retour($trad, 'idiome');
1672
+                }
1673
+                $letexte = str_replace($reg[0], $trad, $letexte);
1674
+            }
1675
+        }
1676
+    }
1677
+    return $letexte;
1678 1678
 }
1679 1679
 
1680 1680
 /**
@@ -1726,68 +1726,68 @@  discard block
 block discarded – undo
1726 1726
  **/
1727 1727
 function extraire_multi($letexte, $lang = null, $options = []) {
1728 1728
 
1729
-	if (
1730
-		$letexte
1731
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
-	) {
1733
-		if (!$lang) {
1734
-			$lang = $GLOBALS['spip_lang'];
1735
-		}
1736
-
1737
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
-		if (is_bool($options)) {
1739
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
-		}
1741
-		if (!isset($options['echappe_span'])) {
1742
-			$options = array_merge($options, ['echappe_span' => false]);
1743
-		}
1744
-		if (!isset($options['lang_defaut'])) {
1745
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
-		}
1747
-
1748
-		include_spip('inc/lang');
1749
-		foreach ($regs as $reg) {
1750
-			// chercher la version de la langue courante
1751
-			$trads = extraire_trads($reg[1]);
1752
-			if ($l = approcher_langue($trads, $lang)) {
1753
-				$trad = $trads[$l];
1754
-			} else {
1755
-				if ($options['lang_defaut'] == 'aucune') {
1756
-					$trad = '';
1757
-				} else {
1758
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
-					// ou la premiere dispo
1760
-					// mais typographier le texte selon les regles de celle-ci
1761
-					// Attention aux blocs multi sur plusieurs lignes
1762
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
-						$l = key($trads);
1764
-					}
1765
-					$trad = $trads[$l];
1766
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1767
-					$trad = $typographie($trad);
1768
-					// Tester si on echappe en span ou en div
1769
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1770
-					include_spip('inc/texte');
1771
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
-					if ($mode === 'div') {
1774
-						$trad = rtrim($trad) . "\n\n";
1775
-					}
1776
-					$trad = code_echappement($trad, 'multi', false, $mode);
1777
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
-					if (lang_dir($l) !== lang_dir($lang)) {
1779
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
-					}
1781
-					if (!$options['echappe_span']) {
1782
-						$trad = echappe_retour($trad, 'multi');
1783
-					}
1784
-				}
1785
-			}
1786
-			$letexte = str_replace($reg[0], $trad, $letexte);
1787
-		}
1788
-	}
1789
-
1790
-	return $letexte;
1729
+    if (
1730
+        $letexte
1731
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
+    ) {
1733
+        if (!$lang) {
1734
+            $lang = $GLOBALS['spip_lang'];
1735
+        }
1736
+
1737
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
+        if (is_bool($options)) {
1739
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
+        }
1741
+        if (!isset($options['echappe_span'])) {
1742
+            $options = array_merge($options, ['echappe_span' => false]);
1743
+        }
1744
+        if (!isset($options['lang_defaut'])) {
1745
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
+        }
1747
+
1748
+        include_spip('inc/lang');
1749
+        foreach ($regs as $reg) {
1750
+            // chercher la version de la langue courante
1751
+            $trads = extraire_trads($reg[1]);
1752
+            if ($l = approcher_langue($trads, $lang)) {
1753
+                $trad = $trads[$l];
1754
+            } else {
1755
+                if ($options['lang_defaut'] == 'aucune') {
1756
+                    $trad = '';
1757
+                } else {
1758
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
+                    // ou la premiere dispo
1760
+                    // mais typographier le texte selon les regles de celle-ci
1761
+                    // Attention aux blocs multi sur plusieurs lignes
1762
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
+                        $l = key($trads);
1764
+                    }
1765
+                    $trad = $trads[$l];
1766
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1767
+                    $trad = $typographie($trad);
1768
+                    // Tester si on echappe en span ou en div
1769
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1770
+                    include_spip('inc/texte');
1771
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
+                    if ($mode === 'div') {
1774
+                        $trad = rtrim($trad) . "\n\n";
1775
+                    }
1776
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1777
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
+                    if (lang_dir($l) !== lang_dir($lang)) {
1779
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
+                    }
1781
+                    if (!$options['echappe_span']) {
1782
+                        $trad = echappe_retour($trad, 'multi');
1783
+                    }
1784
+                }
1785
+            }
1786
+            $letexte = str_replace($reg[0], $trad, $letexte);
1787
+        }
1788
+    }
1789
+
1790
+    return $letexte;
1791 1791
 }
1792 1792
 
1793 1793
 /**
@@ -1803,20 +1803,20 @@  discard block
 block discarded – undo
1803 1803
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1804 1804
  **/
1805 1805
 function extraire_trads($bloc) {
1806
-	$lang = '';
1806
+    $lang = '';
1807 1807
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1808 1808
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1809
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
-		$texte = trim($regs[1]);
1811
-		if ($texte or $lang) {
1812
-			$trads[$lang] = $texte;
1813
-		}
1814
-		$bloc = substr($bloc, strlen($regs[0]));
1815
-		$lang = $regs[2];
1816
-	}
1817
-	$trads[$lang] = $bloc;
1809
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
+        $texte = trim($regs[1]);
1811
+        if ($texte or $lang) {
1812
+            $trads[$lang] = $texte;
1813
+        }
1814
+        $bloc = substr($bloc, strlen($regs[0]));
1815
+        $lang = $regs[2];
1816
+    }
1817
+    $trads[$lang] = $bloc;
1818 1818
 
1819
-	return $trads;
1819
+    return $trads;
1820 1820
 }
1821 1821
 
1822 1822
 
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
  * @return string L'initiale en majuscule
1828 1828
  */
1829 1829
 function filtre_initiale($nom) {
1830
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1830
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1831 1831
 }
1832 1832
 
1833 1833
 
@@ -1872,33 +1872,33 @@  discard block
 block discarded – undo
1872 1872
  *      - null (interne) : si on empile
1873 1873
  **/
1874 1874
 function unique($donnee, $famille = '', $cpt = false) {
1875
-	static $mem = [];
1876
-	// permettre de vider la pile et de la restaurer
1877
-	// pour le calcul de introduction...
1878
-	if ($famille == '_spip_raz_') {
1879
-		$tmp = $mem;
1880
-		$mem = [];
1881
-
1882
-		return $tmp;
1883
-	} elseif ($famille == '_spip_set_') {
1884
-		$mem = $donnee;
1885
-
1886
-		return;
1887
-	}
1888
-	// eviter une notice
1889
-	if (!isset($mem[$famille])) {
1890
-		$mem[$famille] = [];
1891
-	}
1892
-	if ($cpt) {
1893
-		return count($mem[$famille]);
1894
-	}
1895
-	// eviter une notice
1896
-	if (!isset($mem[$famille][$donnee])) {
1897
-		$mem[$famille][$donnee] = 0;
1898
-	}
1899
-	if (!($mem[$famille][$donnee]++)) {
1900
-		return $donnee;
1901
-	}
1875
+    static $mem = [];
1876
+    // permettre de vider la pile et de la restaurer
1877
+    // pour le calcul de introduction...
1878
+    if ($famille == '_spip_raz_') {
1879
+        $tmp = $mem;
1880
+        $mem = [];
1881
+
1882
+        return $tmp;
1883
+    } elseif ($famille == '_spip_set_') {
1884
+        $mem = $donnee;
1885
+
1886
+        return;
1887
+    }
1888
+    // eviter une notice
1889
+    if (!isset($mem[$famille])) {
1890
+        $mem[$famille] = [];
1891
+    }
1892
+    if ($cpt) {
1893
+        return count($mem[$famille]);
1894
+    }
1895
+    // eviter une notice
1896
+    if (!isset($mem[$famille][$donnee])) {
1897
+        $mem[$famille][$donnee] = 0;
1898
+    }
1899
+    if (!($mem[$famille][$donnee]++)) {
1900
+        return $donnee;
1901
+    }
1902 1902
 }
1903 1903
 
1904 1904
 
@@ -1928,16 +1928,16 @@  discard block
 block discarded – undo
1928 1928
  *     Une des valeurs en fonction du compteur.
1929 1929
  **/
1930 1930
 function alterner($i, ...$args) {
1931
-	// recuperer les arguments (attention fonctions un peu space)
1932
-	$num = count($args);
1931
+    // recuperer les arguments (attention fonctions un peu space)
1932
+    $num = count($args);
1933 1933
 
1934
-	if ($num === 1 && is_array($args[0])) {
1935
-		$args = $args[0];
1936
-		$num = count($args);
1937
-	}
1934
+    if ($num === 1 && is_array($args[0])) {
1935
+        $args = $args[0];
1936
+        $num = count($args);
1937
+    }
1938 1938
 
1939
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
-	return $args[(intval($i) - 1) % $num];
1939
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
+    return $args[(intval($i) - 1) % $num];
1941 1941
 }
1942 1942
 
1943 1943
 
@@ -1962,49 +1962,49 @@  discard block
 block discarded – undo
1962 1962
  *     - Tableau complet (si 2e argument)
1963 1963
  **/
1964 1964
 function extraire_attribut($balise, $attribut, $complet = false) {
1965
-	if (is_array($balise)) {
1966
-		array_walk(
1967
-			$balise,
1968
-			function (&$a, $key, $t) {
1969
-				$a = extraire_attribut($a, $t);
1970
-			},
1971
-			$attribut
1972
-		);
1973
-
1974
-		return $balise;
1975
-	}
1976
-	if (
1977
-		preg_match(
1978
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
-			. $attribut
1980
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
-			$balise,
1982
-			$r
1983
-		)
1984
-	) {
1985
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
-			$r[4] = substr($r[3], 1, -1);
1987
-			$r[3] = $r[3][0];
1988
-		} elseif ($r[3] !== '') {
1989
-			$r[4] = $r[3];
1990
-			$r[3] = '';
1991
-		} else {
1992
-			$r[4] = trim($r[2]);
1993
-		}
1994
-		$att = $r[4];
1995
-		if (strpos($att, '&#') !== false) {
1996
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
-		}
1998
-		$att = filtrer_entites($att);
1999
-	} else {
2000
-		$att = null;
2001
-	}
2002
-
2003
-	if ($complet) {
2004
-		return [$att, $r];
2005
-	} else {
2006
-		return $att;
2007
-	}
1965
+    if (is_array($balise)) {
1966
+        array_walk(
1967
+            $balise,
1968
+            function (&$a, $key, $t) {
1969
+                $a = extraire_attribut($a, $t);
1970
+            },
1971
+            $attribut
1972
+        );
1973
+
1974
+        return $balise;
1975
+    }
1976
+    if (
1977
+        preg_match(
1978
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
+            . $attribut
1980
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
+            $balise,
1982
+            $r
1983
+        )
1984
+    ) {
1985
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
+            $r[4] = substr($r[3], 1, -1);
1987
+            $r[3] = $r[3][0];
1988
+        } elseif ($r[3] !== '') {
1989
+            $r[4] = $r[3];
1990
+            $r[3] = '';
1991
+        } else {
1992
+            $r[4] = trim($r[2]);
1993
+        }
1994
+        $att = $r[4];
1995
+        if (strpos($att, '&#') !== false) {
1996
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
+        }
1998
+        $att = filtrer_entites($att);
1999
+    } else {
2000
+        $att = null;
2001
+    }
2002
+
2003
+    if ($complet) {
2004
+        return [$att, $r];
2005
+    } else {
2006
+        return $att;
2007
+    }
2008 2008
 }
2009 2009
 
2010 2010
 /**
@@ -2036,37 +2036,37 @@  discard block
 block discarded – undo
2036 2036
  *     Code html modifié
2037 2037
  **/
2038 2038
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2039
-	// preparer l'attribut
2040
-	// supprimer les &nbsp; etc mais pas les balises html
2041
-	// qui ont un sens dans un attribut value d'un input
2042
-	if ($proteger) {
2043
-		$val = attribut_html($val, false);
2044
-	}
2045
-
2046
-	// echapper les ' pour eviter tout bug
2047
-	$val = str_replace("'", '&#039;', $val);
2048
-	if ($vider and strlen($val) == 0) {
2049
-		$insert = '';
2050
-	} else {
2051
-		$insert = " $attribut='$val'";
2052
-	}
2053
-
2054
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
-
2056
-	if ($old !== null) {
2057
-		// Remplacer l'ancien attribut du meme nom
2058
-		$balise = $r[1] . $insert . $r[5];
2059
-	} else {
2060
-		// preferer une balise " />" (comme <img />)
2061
-		if (preg_match(',/>,', $balise)) {
2062
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
-		} // sinon une balise <a ...> ... </a>
2064
-		else {
2065
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
-		}
2067
-	}
2068
-
2069
-	return $balise;
2039
+    // preparer l'attribut
2040
+    // supprimer les &nbsp; etc mais pas les balises html
2041
+    // qui ont un sens dans un attribut value d'un input
2042
+    if ($proteger) {
2043
+        $val = attribut_html($val, false);
2044
+    }
2045
+
2046
+    // echapper les ' pour eviter tout bug
2047
+    $val = str_replace("'", '&#039;', $val);
2048
+    if ($vider and strlen($val) == 0) {
2049
+        $insert = '';
2050
+    } else {
2051
+        $insert = " $attribut='$val'";
2052
+    }
2053
+
2054
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
+
2056
+    if ($old !== null) {
2057
+        // Remplacer l'ancien attribut du meme nom
2058
+        $balise = $r[1] . $insert . $r[5];
2059
+    } else {
2060
+        // preferer une balise " />" (comme <img />)
2061
+        if (preg_match(',/>,', $balise)) {
2062
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
+        } // sinon une balise <a ...> ... </a>
2064
+        else {
2065
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
+        }
2067
+    }
2068
+
2069
+    return $balise;
2070 2070
 }
2071 2071
 
2072 2072
 /**
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
  * @return string Code HTML sans l'attribut
2085 2085
  **/
2086 2086
 function vider_attribut($balise, $attribut) {
2087
-	return inserer_attribut($balise, $attribut, '', false, true);
2087
+    return inserer_attribut($balise, $attribut, '', false, true);
2088 2088
 }
2089 2089
 
2090 2090
 /**
@@ -2096,56 +2096,56 @@  discard block
 block discarded – undo
2096 2096
  * @return string
2097 2097
  */
2098 2098
 function modifier_class($balise, $class, $operation = 'ajouter') {
2099
-	if (is_string($class)) {
2100
-		$class = explode(' ', trim($class));
2101
-	}
2102
-	$class = array_filter($class);
2103
-
2104
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2105
-	if (preg_match(',[^\w-],', implode('', $class))) {
2106
-		return $balise;
2107
-	}
2108
-
2109
-	if ($class) {
2110
-		$class = array_unique($class);
2111
-		$class_courante = extraire_attribut($balise, 'class');
2112
-
2113
-		$class_new = $class_courante;
2114
-		foreach ($class as $c) {
2115
-			if ($c) {
2116
-				$is_class_presente = false;
2117
-				if (
2118
-					strpos($class_courante, $c) !== false
2119
-					and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
-				) {
2121
-					$is_class_presente = true;
2122
-				}
2123
-				if (
2124
-					in_array($operation, ['ajouter', 'commuter'])
2125
-					and !$is_class_presente
2126
-				) {
2127
-					$class_new = rtrim($class_new) . ' ' . $c;
2128
-				}
2129
-				elseif (
2130
-					in_array($operation, ['supprimer', 'commuter'])
2131
-					and $is_class_presente
2132
-				) {
2133
-					$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
-				}
2135
-			}
2136
-		}
2137
-
2138
-		if ($class_new !== $class_courante) {
2139
-			if (strlen($class_new)) {
2140
-				$balise = inserer_attribut($balise, 'class', $class_new);
2141
-			}
2142
-			elseif ($class_courante) {
2143
-				$balise = vider_attribut($balise, 'class');
2144
-			}
2145
-		}
2146
-	}
2147
-
2148
-	return $balise;
2099
+    if (is_string($class)) {
2100
+        $class = explode(' ', trim($class));
2101
+    }
2102
+    $class = array_filter($class);
2103
+
2104
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2105
+    if (preg_match(',[^\w-],', implode('', $class))) {
2106
+        return $balise;
2107
+    }
2108
+
2109
+    if ($class) {
2110
+        $class = array_unique($class);
2111
+        $class_courante = extraire_attribut($balise, 'class');
2112
+
2113
+        $class_new = $class_courante;
2114
+        foreach ($class as $c) {
2115
+            if ($c) {
2116
+                $is_class_presente = false;
2117
+                if (
2118
+                    strpos($class_courante, $c) !== false
2119
+                    and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
+                ) {
2121
+                    $is_class_presente = true;
2122
+                }
2123
+                if (
2124
+                    in_array($operation, ['ajouter', 'commuter'])
2125
+                    and !$is_class_presente
2126
+                ) {
2127
+                    $class_new = rtrim($class_new) . ' ' . $c;
2128
+                }
2129
+                elseif (
2130
+                    in_array($operation, ['supprimer', 'commuter'])
2131
+                    and $is_class_presente
2132
+                ) {
2133
+                    $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
+                }
2135
+            }
2136
+        }
2137
+
2138
+        if ($class_new !== $class_courante) {
2139
+            if (strlen($class_new)) {
2140
+                $balise = inserer_attribut($balise, 'class', $class_new);
2141
+            }
2142
+            elseif ($class_courante) {
2143
+                $balise = vider_attribut($balise, 'class');
2144
+            }
2145
+        }
2146
+    }
2147
+
2148
+    return $balise;
2149 2149
 }
2150 2150
 
2151 2151
 /**
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
  * @return string
2156 2156
  */
2157 2157
 function ajouter_class($balise, $class) {
2158
-	return modifier_class($balise, $class, 'ajouter');
2158
+    return modifier_class($balise, $class, 'ajouter');
2159 2159
 }
2160 2160
 
2161 2161
 /**
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
  * @return string
2166 2166
  */
2167 2167
 function supprimer_class($balise, $class) {
2168
-	return modifier_class($balise, $class, 'supprimer');
2168
+    return modifier_class($balise, $class, 'supprimer');
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
  * @return string
2177 2177
  */
2178 2178
 function commuter_class($balise, $class) {
2179
-	return modifier_class($balise, $class, 'commuter');
2179
+    return modifier_class($balise, $class, 'commuter');
2180 2180
 }
2181 2181
 
2182 2182
 /**
@@ -2187,19 +2187,19 @@  discard block
 block discarded – undo
2187 2187
  * @return string
2188 2188
  */
2189 2189
 function tester_config($id, $mode = '') {
2190
-	include_spip('action/inscrire_auteur');
2190
+    include_spip('action/inscrire_auteur');
2191 2191
 
2192
-	return tester_statut_inscription($mode, $id);
2192
+    return tester_statut_inscription($mode, $id);
2193 2193
 }
2194 2194
 
2195 2195
 //
2196 2196
 // Quelques fonctions de calcul arithmetique
2197 2197
 //
2198 2198
 function floatstr($a) {
2199
- return str_replace(',', '.', (string)floatval($a));
2199
+    return str_replace(',', '.', (string)floatval($a));
2200 2200
 }
2201 2201
 function strize($f, $a, $b) {
2202
- return floatstr($f(floatstr($a), floatstr($b)));
2202
+    return floatstr($f(floatstr($a), floatstr($b)));
2203 2203
 }
2204 2204
 
2205 2205
 /**
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
  * @return int $a+$b
2219 2219
  **/
2220 2220
 function plus($a, $b) {
2221
-	return $a + $b;
2221
+    return $a + $b;
2222 2222
 }
2223 2223
 function strplus($a, $b) {
2224 2224
 return strize('plus', $a, $b);
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
  * @return int $a-$b
2240 2240
  **/
2241 2241
 function moins($a, $b) {
2242
-	return $a - $b;
2242
+    return $a - $b;
2243 2243
 }
2244 2244
 function strmoins($a, $b) {
2245 2245
 return strize('moins', $a, $b);
@@ -2262,7 +2262,7 @@  discard block
 block discarded – undo
2262 2262
  * @return int $a*$b
2263 2263
  **/
2264 2264
 function mult($a, $b) {
2265
-	return $a * $b;
2265
+    return $a * $b;
2266 2266
 }
2267 2267
 function strmult($a, $b) {
2268 2268
 return strize('mult', $a, $b);
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
  * @return int $a/$b (ou 0 si $b est nul)
2286 2286
  **/
2287 2287
 function div($a, $b) {
2288
-	return $b ? $a / $b : 0;
2288
+    return $b ? $a / $b : 0;
2289 2289
 }
2290 2290
 function strdiv($a, $b) {
2291 2291
 return strize('div', $a, $b);
@@ -2309,7 +2309,7 @@  discard block
 block discarded – undo
2309 2309
  * @return int ($nb % $mod) + $add
2310 2310
  **/
2311 2311
 function modulo($nb, $mod, $add = 0) {
2312
-	return ($mod ? $nb % $mod : 0) + $add;
2312
+    return ($mod ? $nb % $mod : 0) + $add;
2313 2313
 }
2314 2314
 
2315 2315
 
@@ -2324,24 +2324,24 @@  discard block
 block discarded – undo
2324 2324
  *      - true sinon
2325 2325
  **/
2326 2326
 function nom_acceptable($nom) {
2327
-	if (!is_string($nom)) {
2328
-		return false;
2329
-	}
2330
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2331
-		define('_TAGS_NOM_AUTEUR', '');
2332
-	}
2333
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
-	foreach ($tags_acceptes as $tag) {
2335
-		if (strlen($tag)) {
2336
-			$remp1[] = '<' . trim($tag) . '>';
2337
-			$remp1[] = '</' . trim($tag) . '>';
2338
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2339
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2340
-		}
2341
-	}
2342
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2327
+    if (!is_string($nom)) {
2328
+        return false;
2329
+    }
2330
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2331
+        define('_TAGS_NOM_AUTEUR', '');
2332
+    }
2333
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
+    foreach ($tags_acceptes as $tag) {
2335
+        if (strlen($tag)) {
2336
+            $remp1[] = '<' . trim($tag) . '>';
2337
+            $remp1[] = '</' . trim($tag) . '>';
2338
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2339
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2340
+        }
2341
+    }
2342
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2343 2343
 
2344
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2344
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2345 2345
 }
2346 2346
 
2347 2347
 
@@ -2357,14 +2357,14 @@  discard block
 block discarded – undo
2357 2357
  *      - renvoie un tableau si l'entree est un tableau
2358 2358
  **/
2359 2359
 function email_valide($adresses) {
2360
-	if (is_array($adresses)) {
2361
-		$adresses = array_map('email_valide', $adresses);
2362
-		$adresses = array_filter($adresses);
2363
-		return $adresses;
2364
-	}
2360
+    if (is_array($adresses)) {
2361
+        $adresses = array_map('email_valide', $adresses);
2362
+        $adresses = array_filter($adresses);
2363
+        return $adresses;
2364
+    }
2365 2365
 
2366
-	$email_valide = charger_fonction('email_valide', 'inc');
2367
-	return $email_valide($adresses);
2366
+    $email_valide = charger_fonction('email_valide', 'inc');
2367
+    return $email_valide($adresses);
2368 2368
 }
2369 2369
 
2370 2370
 /**
@@ -2378,27 +2378,27 @@  discard block
 block discarded – undo
2378 2378
  * @return string Texte
2379 2379
  **/
2380 2380
 function afficher_enclosures($tags) {
2381
-	$s = [];
2382
-	foreach (extraire_balises($tags, 'a') as $tag) {
2383
-		if (
2384
-			extraire_attribut($tag, 'rel') == 'enclosure'
2385
-			and $t = extraire_attribut($tag, 'href')
2386
-		) {
2387
-			$s[] = preg_replace(
2388
-				',>[^<]+</a>,S',
2389
-				'>'
2390
-				. http_img_pack(
2391
-					'attachment-16.png',
2392
-					$t,
2393
-					'title="' . attribut_html($t) . '"'
2394
-				)
2395
-				. '</a>',
2396
-				$tag
2397
-			);
2398
-		}
2399
-	}
2400
-
2401
-	return join('&nbsp;', $s);
2381
+    $s = [];
2382
+    foreach (extraire_balises($tags, 'a') as $tag) {
2383
+        if (
2384
+            extraire_attribut($tag, 'rel') == 'enclosure'
2385
+            and $t = extraire_attribut($tag, 'href')
2386
+        ) {
2387
+            $s[] = preg_replace(
2388
+                ',>[^<]+</a>,S',
2389
+                '>'
2390
+                . http_img_pack(
2391
+                    'attachment-16.png',
2392
+                    $t,
2393
+                    'title="' . attribut_html($t) . '"'
2394
+                )
2395
+                . '</a>',
2396
+                $tag
2397
+            );
2398
+        }
2399
+    }
2400
+
2401
+    return join('&nbsp;', $s);
2402 2402
 }
2403 2403
 
2404 2404
 /**
@@ -2413,15 +2413,15 @@  discard block
 block discarded – undo
2413 2413
  * @return string Liens trouvés
2414 2414
  **/
2415 2415
 function afficher_tags($tags, $rels = 'tag,directory') {
2416
-	$s = [];
2417
-	foreach (extraire_balises($tags, 'a') as $tag) {
2418
-		$rel = extraire_attribut($tag, 'rel');
2419
-		if (strstr(",$rels,", ",$rel,")) {
2420
-			$s[] = $tag;
2421
-		}
2422
-	}
2416
+    $s = [];
2417
+    foreach (extraire_balises($tags, 'a') as $tag) {
2418
+        $rel = extraire_attribut($tag, 'rel');
2419
+        if (strstr(",$rels,", ",$rel,")) {
2420
+            $s[] = $tag;
2421
+        }
2422
+    }
2423 2423
 
2424
-	return join(', ', $s);
2424
+    return join(', ', $s);
2425 2425
 }
2426 2426
 
2427 2427
 
@@ -2443,21 +2443,21 @@  discard block
 block discarded – undo
2443 2443
  * @return string Tag HTML `<a>` avec microformat.
2444 2444
  **/
2445 2445
 function enclosure2microformat($e) {
2446
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2448
-	}
2449
-	$type = extraire_attribut($e, 'type');
2450
-	if (!$length = extraire_attribut($e, 'length')) {
2451
-		# <media:content : longeur dans fileSize. On tente.
2452
-		$length = extraire_attribut($e, 'fileSize');
2453
-	}
2454
-	$fichier = basename($url);
2446
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2448
+    }
2449
+    $type = extraire_attribut($e, 'type');
2450
+    if (!$length = extraire_attribut($e, 'length')) {
2451
+        # <media:content : longeur dans fileSize. On tente.
2452
+        $length = extraire_attribut($e, 'fileSize');
2453
+    }
2454
+    $fichier = basename($url);
2455 2455
 
2456
-	return '<a rel="enclosure"'
2457
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
-	. '>' . $fichier . '</a>';
2456
+    return '<a rel="enclosure"'
2457
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
+    . '>' . $fichier . '</a>';
2461 2461
 }
2462 2462
 
2463 2463
 /**
@@ -2475,24 +2475,24 @@  discard block
 block discarded – undo
2475 2475
  * @return string Tags RSS `<enclosure>`.
2476 2476
  **/
2477 2477
 function microformat2enclosure($tags) {
2478
-	$enclosures = [];
2479
-	foreach (extraire_balises($tags, 'a') as $e) {
2480
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2482
-			$type = extraire_attribut($e, 'type');
2483
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
-				$length = intval(extraire_attribut($e, 'length'));
2485
-			} # vieux data
2486
-			$fichier = basename($url);
2487
-			$enclosures[] = '<enclosure'
2488
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
-				. ($length ? ' length="' . $length . '"' : '')
2491
-				. ' />';
2492
-		}
2493
-	}
2478
+    $enclosures = [];
2479
+    foreach (extraire_balises($tags, 'a') as $e) {
2480
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2482
+            $type = extraire_attribut($e, 'type');
2483
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
+                $length = intval(extraire_attribut($e, 'length'));
2485
+            } # vieux data
2486
+            $fichier = basename($url);
2487
+            $enclosures[] = '<enclosure'
2488
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
+                . ($length ? ' length="' . $length . '"' : '')
2491
+                . ' />';
2492
+        }
2493
+    }
2494 2494
 
2495
-	return join("\n", $enclosures);
2495
+    return join("\n", $enclosures);
2496 2496
 }
2497 2497
 
2498 2498
 
@@ -2508,16 +2508,16 @@  discard block
 block discarded – undo
2508 2508
  * @return string Tags RSS Atom `<dc:subject>`.
2509 2509
  **/
2510 2510
 function tags2dcsubject($tags) {
2511
-	$subjects = '';
2512
-	foreach (extraire_balises($tags, 'a') as $e) {
2513
-		if (extraire_attribut($e, 'rel') == 'tag') {
2514
-			$subjects .= '<dc:subject>'
2515
-				. texte_backend(textebrut($e))
2516
-				. '</dc:subject>' . "\n";
2517
-		}
2518
-	}
2511
+    $subjects = '';
2512
+    foreach (extraire_balises($tags, 'a') as $e) {
2513
+        if (extraire_attribut($e, 'rel') == 'tag') {
2514
+            $subjects .= '<dc:subject>'
2515
+                . texte_backend(textebrut($e))
2516
+                . '</dc:subject>' . "\n";
2517
+        }
2518
+    }
2519 2519
 
2520
-	return $subjects;
2520
+    return $subjects;
2521 2521
 }
2522 2522
 
2523 2523
 /**
@@ -2546,27 +2546,27 @@  discard block
 block discarded – undo
2546 2546
  *     - Tableau de résultats, si tableau en entrée.
2547 2547
  **/
2548 2548
 function extraire_balise($texte, $tag = 'a') {
2549
-	if (is_array($texte)) {
2550
-		array_walk(
2551
-			$texte,
2552
-			function (&$a, $key, $t) {
2553
-				$a = extraire_balise($a, $t);
2554
-			},
2555
-			$tag
2556
-		);
2557
-
2558
-		return $texte;
2559
-	}
2560
-
2561
-	if (
2562
-		preg_match(
2563
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
-			$texte,
2565
-			$regs
2566
-		)
2567
-	) {
2568
-		return $regs[0];
2569
-	}
2549
+    if (is_array($texte)) {
2550
+        array_walk(
2551
+            $texte,
2552
+            function (&$a, $key, $t) {
2553
+                $a = extraire_balise($a, $t);
2554
+            },
2555
+            $tag
2556
+        );
2557
+
2558
+        return $texte;
2559
+    }
2560
+
2561
+    if (
2562
+        preg_match(
2563
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
+            $texte,
2565
+            $regs
2566
+        )
2567
+    ) {
2568
+        return $regs[0];
2569
+    }
2570 2570
 }
2571 2571
 
2572 2572
 /**
@@ -2594,30 +2594,30 @@  discard block
 block discarded – undo
2594 2594
  *     - Tableau de résultats, si tableau en entrée.
2595 2595
  **/
2596 2596
 function extraire_balises($texte, $tag = 'a') {
2597
-	if (is_array($texte)) {
2598
-		array_walk(
2599
-			$texte,
2600
-			function (&$a, $key, $t) {
2601
-				$a = extraire_balises($a, $t);
2602
-			},
2603
-			$tag
2604
-		);
2605
-
2606
-		return $texte;
2607
-	}
2608
-
2609
-	if (
2610
-		preg_match_all(
2611
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
-			$texte,
2613
-			$regs,
2614
-			PREG_PATTERN_ORDER
2615
-		)
2616
-	) {
2617
-		return $regs[0];
2618
-	} else {
2619
-		return [];
2620
-	}
2597
+    if (is_array($texte)) {
2598
+        array_walk(
2599
+            $texte,
2600
+            function (&$a, $key, $t) {
2601
+                $a = extraire_balises($a, $t);
2602
+            },
2603
+            $tag
2604
+        );
2605
+
2606
+        return $texte;
2607
+    }
2608
+
2609
+    if (
2610
+        preg_match_all(
2611
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
+            $texte,
2613
+            $regs,
2614
+            PREG_PATTERN_ORDER
2615
+        )
2616
+    ) {
2617
+        return $regs[0];
2618
+    } else {
2619
+        return [];
2620
+    }
2621 2621
 }
2622 2622
 
2623 2623
 /**
@@ -2646,11 +2646,11 @@  discard block
 block discarded – undo
2646 2646
  *     - `$def` si on n'a pas transmis de tableau
2647 2647
  **/
2648 2648
 function in_any($val, $vals, $def = '') {
2649
-	if (!is_array($vals) and $v = unserialize($vals)) {
2650
-		$vals = $v;
2651
-	}
2649
+    if (!is_array($vals) and $v = unserialize($vals)) {
2650
+        $vals = $v;
2651
+    }
2652 2652
 
2653
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2653
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2654 2654
 }
2655 2655
 
2656 2656
 
@@ -2671,12 +2671,12 @@  discard block
 block discarded – undo
2671 2671
  *     Résultat du calcul
2672 2672
  **/
2673 2673
 function valeur_numerique($expr) {
2674
-	$a = 0;
2675
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
-		eval("\$a = $expr;");
2677
-	}
2674
+    $a = 0;
2675
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
+        eval("\$a = $expr;");
2677
+    }
2678 2678
 
2679
-	return intval($a);
2679
+    return intval($a);
2680 2680
 }
2681 2681
 
2682 2682
 /**
@@ -2695,7 +2695,7 @@  discard block
 block discarded – undo
2695 2695
  *      Retourne `$a*$b/$c`
2696 2696
  **/
2697 2697
 function regledetrois($a, $b, $c) {
2698
-	return round($a * $b / $c);
2698
+    return round($a * $b / $c);
2699 2699
 }
2700 2700
 
2701 2701
 
@@ -2719,77 +2719,77 @@  discard block
 block discarded – undo
2719 2719
  **/
2720 2720
 function form_hidden($action) {
2721 2721
 
2722
-	$contexte = [];
2723
-	include_spip('inc/urls');
2724
-	if (
2725
-		$p = urls_decoder_url($action, '')
2726
-		and reset($p)
2727
-	) {
2728
-		$fond = array_shift($p);
2729
-		if ($fond != '404') {
2730
-			$contexte = array_shift($p);
2731
-			$contexte['page'] = $fond;
2732
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
-		}
2734
-	}
2735
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
-		unset($contexte['type']);
2738
-	}
2739
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
-		unset($contexte['type-page']);
2741
-	}
2742
-
2743
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2745
-	$values = [];
2746
-
2747
-	// d'abord avec celles de l'url
2748
-	if (false !== ($p = strpos($action, '?'))) {
2749
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
-			$c = explode('=', $c, 2);
2751
-			$var = array_shift($c);
2752
-			$val = array_shift($c);
2753
-			if ($var) {
2754
-				$val = rawurldecode($val);
2755
-				$var = rawurldecode($var); // decoder les [] eventuels
2756
-				if (preg_match(',\[\]$,S', $var)) {
2757
-					$values[] = [$var, $val];
2758
-				} else {
2759
-					if (!isset($values[$var])) {
2760
-						$values[$var] = [$var, $val];
2761
-					}
2762
-				}
2763
-			}
2764
-		}
2765
-	}
2766
-
2767
-	// ensuite avec celles du contexte, sans doublonner !
2768
-	foreach ($contexte as $var => $val) {
2769
-		if (preg_match(',\[\]$,S', $var)) {
2770
-			$values[] = [$var, $val];
2771
-		} else {
2772
-			if (!isset($values[$var])) {
2773
-				$values[$var] = [$var, $val];
2774
-			}
2775
-		}
2776
-	}
2777
-
2778
-	// puis on rassemble le tout
2779
-	$hidden = [];
2780
-	foreach ($values as $value) {
2781
-		list($var, $val) = $value;
2782
-		$hidden[] = '<input name="'
2783
-			. entites_html($var)
2784
-			. '"'
2785
-			. (is_null($val)
2786
-				? ''
2787
-				: ' value="' . entites_html($val) . '"'
2788
-			)
2789
-			. ' type="hidden"' . "\n/>";
2790
-	}
2791
-
2792
-	return join('', $hidden);
2722
+    $contexte = [];
2723
+    include_spip('inc/urls');
2724
+    if (
2725
+        $p = urls_decoder_url($action, '')
2726
+        and reset($p)
2727
+    ) {
2728
+        $fond = array_shift($p);
2729
+        if ($fond != '404') {
2730
+            $contexte = array_shift($p);
2731
+            $contexte['page'] = $fond;
2732
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
+        }
2734
+    }
2735
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
+        unset($contexte['type']);
2738
+    }
2739
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
+        unset($contexte['type-page']);
2741
+    }
2742
+
2743
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2745
+    $values = [];
2746
+
2747
+    // d'abord avec celles de l'url
2748
+    if (false !== ($p = strpos($action, '?'))) {
2749
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
+            $c = explode('=', $c, 2);
2751
+            $var = array_shift($c);
2752
+            $val = array_shift($c);
2753
+            if ($var) {
2754
+                $val = rawurldecode($val);
2755
+                $var = rawurldecode($var); // decoder les [] eventuels
2756
+                if (preg_match(',\[\]$,S', $var)) {
2757
+                    $values[] = [$var, $val];
2758
+                } else {
2759
+                    if (!isset($values[$var])) {
2760
+                        $values[$var] = [$var, $val];
2761
+                    }
2762
+                }
2763
+            }
2764
+        }
2765
+    }
2766
+
2767
+    // ensuite avec celles du contexte, sans doublonner !
2768
+    foreach ($contexte as $var => $val) {
2769
+        if (preg_match(',\[\]$,S', $var)) {
2770
+            $values[] = [$var, $val];
2771
+        } else {
2772
+            if (!isset($values[$var])) {
2773
+                $values[$var] = [$var, $val];
2774
+            }
2775
+        }
2776
+    }
2777
+
2778
+    // puis on rassemble le tout
2779
+    $hidden = [];
2780
+    foreach ($values as $value) {
2781
+        list($var, $val) = $value;
2782
+        $hidden[] = '<input name="'
2783
+            . entites_html($var)
2784
+            . '"'
2785
+            . (is_null($val)
2786
+                ? ''
2787
+                : ' value="' . entites_html($val) . '"'
2788
+            )
2789
+            . ' type="hidden"' . "\n/>";
2790
+    }
2791
+
2792
+    return join('', $hidden);
2793 2793
 }
2794 2794
 
2795 2795
 
@@ -2811,7 +2811,7 @@  discard block
 block discarded – undo
2811 2811
  *    - la première valeur du tableau sinon.
2812 2812
  **/
2813 2813
 function filtre_reset($array) {
2814
-	return !is_array($array) ? null : reset($array);
2814
+    return !is_array($array) ? null : reset($array);
2815 2815
 }
2816 2816
 
2817 2817
 /**
@@ -2832,7 +2832,7 @@  discard block
 block discarded – undo
2832 2832
  *    - la dernière valeur du tableau sinon.
2833 2833
  **/
2834 2834
 function filtre_end($array) {
2835
-	return !is_array($array) ? null : end($array);
2835
+    return !is_array($array) ? null : end($array);
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2852,11 +2852,11 @@  discard block
 block discarded – undo
2852 2852
  *
2853 2853
  **/
2854 2854
 function filtre_push($array, $val) {
2855
-	if (!is_array($array) or !array_push($array, $val)) {
2856
-		return '';
2857
-	}
2855
+    if (!is_array($array) or !array_push($array, $val)) {
2856
+        return '';
2857
+    }
2858 2858
 
2859
-	return $array;
2859
+    return $array;
2860 2860
 }
2861 2861
 
2862 2862
 /**
@@ -2875,7 +2875,7 @@  discard block
 block discarded – undo
2875 2875
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2876 2876
  **/
2877 2877
 function filtre_find($array, $val) {
2878
-	return (is_array($array) and in_array($val, $array));
2878
+    return (is_array($array) and in_array($val, $array));
2879 2879
 }
2880 2880
 
2881 2881
 
@@ -2892,15 +2892,15 @@  discard block
 block discarded – undo
2892 2892
  *     Contenu avec urls en absolus
2893 2893
  **/
2894 2894
 function urls_absolues_css($contenu, $source) {
2895
-	$path = suivre_lien(url_absolue($source), './');
2895
+    $path = suivre_lien(url_absolue($source), './');
2896 2896
 
2897
-	return preg_replace_callback(
2898
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
-		function ($x) use ($path) {
2900
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2901
-		},
2902
-		$contenu
2903
-	);
2897
+    return preg_replace_callback(
2898
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
+        function ($x) use ($path) {
2900
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2901
+        },
2902
+        $contenu
2903
+    );
2904 2904
 }
2905 2905
 
2906 2906
 
@@ -2929,119 +2929,119 @@  discard block
 block discarded – undo
2929 2929
  *     Chemin du fichier CSS inversé
2930 2930
  **/
2931 2931
 function direction_css($css, $voulue = '') {
2932
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
-		return $css;
2934
-	}
2935
-	include_spip('inc/lang');
2936
-	// si on a precise le sens voulu en argument, le prendre en compte
2937
-	if ($voulue = strtolower($voulue)) {
2938
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
-			$voulue = lang_dir($voulue);
2940
-		}
2941
-	} else {
2942
-		$voulue = lang_dir();
2943
-	}
2944
-
2945
-	$r = count($r) > 1;
2946
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
-	$dir = $r ? 'rtl' : 'ltr';
2948
-	$ndir = $r ? 'ltr' : 'rtl';
2949
-
2950
-	if ($voulue == $dir) {
2951
-		return $css;
2952
-	}
2953
-
2954
-	if (
2955
-		// url absolue
2956
-		preg_match(',^https?:,i', $css)
2957
-		// ou qui contient un ?
2958
-		or (($p = strpos($css, '?')) !== false)
2959
-	) {
2960
-		$distant = true;
2961
-		$cssf = parse_url($css);
2962
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
-	} else {
2965
-		$distant = false;
2966
-		$cssf = $css;
2967
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
-		//propose (rien a faire dans ce cas)
2969
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
-		if (@file_exists($f)) {
2971
-			return $f;
2972
-		}
2973
-	}
2974
-
2975
-	// 2.
2976
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
-	$f = $dir_var
2978
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
-
2981
-	// la css peut etre distante (url absolue !)
2982
-	if ($distant) {
2983
-		include_spip('inc/distant');
2984
-		$res = recuperer_url($css);
2985
-		if (!$res or !$contenu = $res['page']) {
2986
-			return $css;
2987
-		}
2988
-	} else {
2989
-		if (
2990
-			(@filemtime($f) > @filemtime($css))
2991
-			and (_VAR_MODE != 'recalcul')
2992
-		) {
2993
-			return $f;
2994
-		}
2995
-		if (!lire_fichier($css, $contenu)) {
2996
-			return $css;
2997
-		}
2998
-	}
2999
-
3000
-
3001
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
-	include_spip('lib/csstidy/class.csstidy');
3003
-	$parser = new csstidy();
3004
-	$parser->set_cfg('optimise_shorthands', 0);
3005
-	$parser->set_cfg('reverse_left_and_right', true);
3006
-	$parser->parse($contenu);
3007
-
3008
-	$contenu = $parser->print->plain();
3009
-
3010
-
3011
-	// reperer les @import auxquels il faut propager le direction_css
3012
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
-	$src = [];
3014
-	$src_direction_css = [];
3015
-	$src_faux_abs = [];
3016
-	$d = dirname($css);
3017
-	foreach ($regs[1] as $k => $import_css) {
3018
-		$css_direction = direction_css("$d/$import_css", $voulue);
3019
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
-			$css_direction = substr($css_direction, strlen($d) + 1);
3022
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
-			$css_direction = substr($css_direction, strlen($dir_var));
3025
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
-			$css_direction = '/@@@@@@/' . $css_direction;
3027
-		}
3028
-		$src[] = $regs[0][$k];
3029
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
-	}
3031
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3032
-
3033
-	$contenu = urls_absolues_css($contenu, $css);
3034
-
3035
-	// virer les fausses url absolues que l'on a mis dans les import
3036
-	if (count($src_faux_abs)) {
3037
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
-	}
3039
-
3040
-	if (!ecrire_fichier($f, $contenu)) {
3041
-		return $css;
3042
-	}
3043
-
3044
-	return $f;
2932
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
+        return $css;
2934
+    }
2935
+    include_spip('inc/lang');
2936
+    // si on a precise le sens voulu en argument, le prendre en compte
2937
+    if ($voulue = strtolower($voulue)) {
2938
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
+            $voulue = lang_dir($voulue);
2940
+        }
2941
+    } else {
2942
+        $voulue = lang_dir();
2943
+    }
2944
+
2945
+    $r = count($r) > 1;
2946
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
+    $dir = $r ? 'rtl' : 'ltr';
2948
+    $ndir = $r ? 'ltr' : 'rtl';
2949
+
2950
+    if ($voulue == $dir) {
2951
+        return $css;
2952
+    }
2953
+
2954
+    if (
2955
+        // url absolue
2956
+        preg_match(',^https?:,i', $css)
2957
+        // ou qui contient un ?
2958
+        or (($p = strpos($css, '?')) !== false)
2959
+    ) {
2960
+        $distant = true;
2961
+        $cssf = parse_url($css);
2962
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
+    } else {
2965
+        $distant = false;
2966
+        $cssf = $css;
2967
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
+        //propose (rien a faire dans ce cas)
2969
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
+        if (@file_exists($f)) {
2971
+            return $f;
2972
+        }
2973
+    }
2974
+
2975
+    // 2.
2976
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
+    $f = $dir_var
2978
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
+
2981
+    // la css peut etre distante (url absolue !)
2982
+    if ($distant) {
2983
+        include_spip('inc/distant');
2984
+        $res = recuperer_url($css);
2985
+        if (!$res or !$contenu = $res['page']) {
2986
+            return $css;
2987
+        }
2988
+    } else {
2989
+        if (
2990
+            (@filemtime($f) > @filemtime($css))
2991
+            and (_VAR_MODE != 'recalcul')
2992
+        ) {
2993
+            return $f;
2994
+        }
2995
+        if (!lire_fichier($css, $contenu)) {
2996
+            return $css;
2997
+        }
2998
+    }
2999
+
3000
+
3001
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
+    include_spip('lib/csstidy/class.csstidy');
3003
+    $parser = new csstidy();
3004
+    $parser->set_cfg('optimise_shorthands', 0);
3005
+    $parser->set_cfg('reverse_left_and_right', true);
3006
+    $parser->parse($contenu);
3007
+
3008
+    $contenu = $parser->print->plain();
3009
+
3010
+
3011
+    // reperer les @import auxquels il faut propager le direction_css
3012
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
+    $src = [];
3014
+    $src_direction_css = [];
3015
+    $src_faux_abs = [];
3016
+    $d = dirname($css);
3017
+    foreach ($regs[1] as $k => $import_css) {
3018
+        $css_direction = direction_css("$d/$import_css", $voulue);
3019
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
+            $css_direction = substr($css_direction, strlen($d) + 1);
3022
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
+            $css_direction = substr($css_direction, strlen($dir_var));
3025
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
+            $css_direction = '/@@@@@@/' . $css_direction;
3027
+        }
3028
+        $src[] = $regs[0][$k];
3029
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
+    }
3031
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3032
+
3033
+    $contenu = urls_absolues_css($contenu, $css);
3034
+
3035
+    // virer les fausses url absolues que l'on a mis dans les import
3036
+    if (count($src_faux_abs)) {
3037
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
+    }
3039
+
3040
+    if (!ecrire_fichier($f, $contenu)) {
3041
+        return $css;
3042
+    }
3043
+
3044
+    return $f;
3045 3045
 }
3046 3046
 
3047 3047
 
@@ -3064,46 +3064,46 @@  discard block
 block discarded – undo
3064 3064
  *     - Chemin ou URL du fichier CSS source sinon.
3065 3065
  **/
3066 3066
 function url_absolue_css($css) {
3067
-	if (!preg_match(',\.css$,i', $css, $r)) {
3068
-		return $css;
3069
-	}
3067
+    if (!preg_match(',\.css$,i', $css, $r)) {
3068
+        return $css;
3069
+    }
3070 3070
 
3071
-	$url_absolue_css = url_absolue($css);
3071
+    $url_absolue_css = url_absolue($css);
3072 3072
 
3073
-	$f = basename($css, '.css');
3074
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
-		. '.css';
3073
+    $f = basename($css, '.css');
3074
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
+        . '.css';
3077 3077
 
3078
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
-		return $f;
3080
-	}
3078
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
+        return $f;
3080
+    }
3081 3081
 
3082
-	if ($url_absolue_css == $css) {
3083
-		if (
3084
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
-		) {
3087
-			include_spip('inc/distant');
3088
-			$contenu = recuperer_url($css);
3089
-			$contenu = $contenu['page'] ?? '';
3090
-			if (!$contenu) {
3091
-				return $css;
3092
-			}
3093
-		}
3094
-	} elseif (!lire_fichier($css, $contenu)) {
3095
-		return $css;
3096
-	}
3082
+    if ($url_absolue_css == $css) {
3083
+        if (
3084
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
+        ) {
3087
+            include_spip('inc/distant');
3088
+            $contenu = recuperer_url($css);
3089
+            $contenu = $contenu['page'] ?? '';
3090
+            if (!$contenu) {
3091
+                return $css;
3092
+            }
3093
+        }
3094
+    } elseif (!lire_fichier($css, $contenu)) {
3095
+        return $css;
3096
+    }
3097 3097
 
3098
-	// passer les url relatives a la css d'origine en url absolues
3099
-	$contenu = urls_absolues_css($contenu, $css);
3098
+    // passer les url relatives a la css d'origine en url absolues
3099
+    $contenu = urls_absolues_css($contenu, $css);
3100 3100
 
3101
-	// ecrire la css
3102
-	if (!ecrire_fichier($f, $contenu)) {
3103
-		return $css;
3104
-	}
3101
+    // ecrire la css
3102
+    if (!ecrire_fichier($f, $contenu)) {
3103
+        return $css;
3104
+    }
3105 3105
 
3106
-	return $f;
3106
+    return $f;
3107 3107
 }
3108 3108
 
3109 3109
 
@@ -3137,24 +3137,24 @@  discard block
 block discarded – undo
3137 3137
  *     Valeur trouvée ou valeur par défaut.
3138 3138
  **/
3139 3139
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3140
-	foreach (explode('/', $cle) as $k) {
3141
-		$table = (is_string($table) ? @unserialize($table) : $table);
3140
+    foreach (explode('/', $cle) as $k) {
3141
+        $table = (is_string($table) ? @unserialize($table) : $table);
3142 3142
 
3143
-		if (is_object($table)) {
3144
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
-		} elseif (is_array($table)) {
3146
-			if ($conserver_null) {
3147
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
-			} else {
3149
-				$table = ($table[$k] ?? $defaut);
3150
-			}
3151
-		} else {
3152
-			$table = $defaut;
3153
-			break;
3154
-		}
3155
-	}
3143
+        if (is_object($table)) {
3144
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
+        } elseif (is_array($table)) {
3146
+            if ($conserver_null) {
3147
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
+            } else {
3149
+                $table = ($table[$k] ?? $defaut);
3150
+            }
3151
+        } else {
3152
+            $table = $defaut;
3153
+            break;
3154
+        }
3155
+    }
3156 3156
 
3157
-	return $table;
3157
+    return $table;
3158 3158
 }
3159 3159
 
3160 3160
 /**
@@ -3187,22 +3187,22 @@  discard block
 block discarded – undo
3187 3187
  *     - string : expression trouvée.
3188 3188
  **/
3189 3189
 function filtre_match_dist($texte, $expression, $modif = 'UimsS', $capte = 0) {
3190
-	if (intval($modif) and $capte == 0) {
3191
-		$capte = $modif;
3192
-		$modif = 'UimsS';
3193
-	}
3194
-	$expression = str_replace('\/', '/', $expression);
3195
-	$expression = str_replace('/', '\/', $expression);
3190
+    if (intval($modif) and $capte == 0) {
3191
+        $capte = $modif;
3192
+        $modif = 'UimsS';
3193
+    }
3194
+    $expression = str_replace('\/', '/', $expression);
3195
+    $expression = str_replace('/', '\/', $expression);
3196 3196
 
3197
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
-		if (isset($r[$capte])) {
3199
-			return $r[$capte];
3200
-		} else {
3201
-			return true;
3202
-		}
3203
-	}
3197
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
+        if (isset($r[$capte])) {
3199
+            return $r[$capte];
3200
+        } else {
3201
+            return true;
3202
+        }
3203
+    }
3204 3204
 
3205
-	return false;
3205
+    return false;
3206 3206
 }
3207 3207
 
3208 3208
 
@@ -3229,10 +3229,10 @@  discard block
 block discarded – undo
3229 3229
  *     Texte
3230 3230
  **/
3231 3231
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3232
-	$expression = str_replace('\/', '/', $expression);
3233
-	$expression = str_replace('/', '\/', $expression);
3232
+    $expression = str_replace('\/', '/', $expression);
3233
+    $expression = str_replace('/', '\/', $expression);
3234 3234
 
3235
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3235
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3236 3236
 }
3237 3237
 
3238 3238
 
@@ -3250,25 +3250,25 @@  discard block
 block discarded – undo
3250 3250
  **/
3251 3251
 function traiter_doublons_documents(&$doublons, $letexte) {
3252 3252
 
3253
-	// Verifier dans le texte & les notes (pas beau, helas)
3254
-	$t = $letexte . $GLOBALS['les_notes'];
3253
+    // Verifier dans le texte & les notes (pas beau, helas)
3254
+    $t = $letexte . $GLOBALS['les_notes'];
3255 3255
 
3256
-	if (
3257
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
-		and preg_match_all(
3259
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
-			$t,
3261
-			$matches,
3262
-			PREG_PATTERN_ORDER
3263
-		)
3264
-	) {
3265
-		if (!isset($doublons['documents'])) {
3266
-			$doublons['documents'] = '';
3267
-		}
3268
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3269
-	}
3256
+    if (
3257
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
+        and preg_match_all(
3259
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
+            $t,
3261
+            $matches,
3262
+            PREG_PATTERN_ORDER
3263
+        )
3264
+    ) {
3265
+        if (!isset($doublons['documents'])) {
3266
+            $doublons['documents'] = '';
3267
+        }
3268
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3269
+    }
3270 3270
 
3271
-	return $letexte;
3271
+    return $letexte;
3272 3272
 }
3273 3273
 
3274 3274
 /**
@@ -3282,7 +3282,7 @@  discard block
 block discarded – undo
3282 3282
  * @return string Chaîne vide
3283 3283
  **/
3284 3284
 function vide($texte) {
3285
-	return '';
3285
+    return '';
3286 3286
 }
3287 3287
 
3288 3288
 //
@@ -3311,23 +3311,23 @@  discard block
 block discarded – undo
3311 3311
  *      Code HTML résultant
3312 3312
  **/
3313 3313
 function env_to_params($env, $ignore_params = []) {
3314
-	$ignore_params = array_merge(
3315
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
-		$ignore_params
3317
-	);
3318
-	if (!is_array($env)) {
3319
-		$env = unserialize($env);
3320
-	}
3321
-	$texte = '';
3322
-	if ($env) {
3323
-		foreach ($env as $i => $j) {
3324
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
-			}
3327
-		}
3328
-	}
3329
-
3330
-	return $texte;
3314
+    $ignore_params = array_merge(
3315
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
+        $ignore_params
3317
+    );
3318
+    if (!is_array($env)) {
3319
+        $env = unserialize($env);
3320
+    }
3321
+    $texte = '';
3322
+    if ($env) {
3323
+        foreach ($env as $i => $j) {
3324
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3325
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
+            }
3327
+        }
3328
+    }
3329
+
3330
+    return $texte;
3331 3331
 }
3332 3332
 
3333 3333
 /**
@@ -3350,23 +3350,23 @@  discard block
 block discarded – undo
3350 3350
  *      Code HTML résultant
3351 3351
  **/
3352 3352
 function env_to_attributs($env, $ignore_params = []) {
3353
-	$ignore_params = array_merge(
3354
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
-		$ignore_params
3356
-	);
3357
-	if (!is_array($env)) {
3358
-		$env = unserialize($env);
3359
-	}
3360
-	$texte = '';
3361
-	if ($env) {
3362
-		foreach ($env as $i => $j) {
3363
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3364
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
-			}
3366
-		}
3367
-	}
3353
+    $ignore_params = array_merge(
3354
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
+        $ignore_params
3356
+    );
3357
+    if (!is_array($env)) {
3358
+        $env = unserialize($env);
3359
+    }
3360
+    $texte = '';
3361
+    if ($env) {
3362
+        foreach ($env as $i => $j) {
3363
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3364
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
+            }
3366
+        }
3367
+    }
3368 3368
 
3369
-	return $texte;
3369
+    return $texte;
3370 3370
 }
3371 3371
 
3372 3372
 
@@ -3384,7 +3384,7 @@  discard block
 block discarded – undo
3384 3384
  * @return string Chaînes concaténés
3385 3385
  **/
3386 3386
 function concat(...$args): string {
3387
-	return join('', $args);
3387
+    return join('', $args);
3388 3388
 }
3389 3389
 
3390 3390
 
@@ -3404,23 +3404,23 @@  discard block
 block discarded – undo
3404 3404
  *     Contenu du ou des fichiers, concaténé
3405 3405
  **/
3406 3406
 function charge_scripts($files, $script = true) {
3407
-	$flux = '';
3408
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
-		if (!is_string($file)) {
3410
-			continue;
3411
-		}
3412
-		if ($script) {
3413
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
-		}
3415
-		if ($file) {
3416
-			$path = find_in_path($file);
3417
-			if ($path) {
3418
-				$flux .= spip_file_get_contents($path);
3419
-			}
3420
-		}
3421
-	}
3422
-
3423
-	return $flux;
3407
+    $flux = '';
3408
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
+        if (!is_string($file)) {
3410
+            continue;
3411
+        }
3412
+        if ($script) {
3413
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
+        }
3415
+        if ($file) {
3416
+            $path = find_in_path($file);
3417
+            if ($path) {
3418
+                $flux .= spip_file_get_contents($path);
3419
+            }
3420
+        }
3421
+    }
3422
+
3423
+    return $flux;
3424 3424
 }
3425 3425
 
3426 3426
 /**
@@ -3431,22 +3431,22 @@  discard block
 block discarded – undo
3431 3431
  * @return string
3432 3432
  */
3433 3433
 function http_img_variante_svg_si_possible($img_file) {
3434
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
-	if (
3437
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
-		and file_exists($variante_svg_generique)
3440
-	) {
3441
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
-			$img_file = $variante_svg_size;
3443
-		}
3444
-		else {
3445
-			$img_file = $variante_svg_generique;
3446
-		}
3447
-	}
3434
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
+    if (
3437
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
+        and file_exists($variante_svg_generique)
3440
+    ) {
3441
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
+            $img_file = $variante_svg_size;
3443
+        }
3444
+        else {
3445
+            $img_file = $variante_svg_generique;
3446
+        }
3447
+    }
3448 3448
 
3449
-	return $img_file;
3449
+    return $img_file;
3450 3450
 }
3451 3451
 
3452 3452
 /**
@@ -3467,54 +3467,54 @@  discard block
 block discarded – undo
3467 3467
  */
3468 3468
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3469 3469
 
3470
-	$img_file = $img;
3471
-	if ($p = strpos($img_file, '?')) {
3472
-		$img_file = substr($img_file, 0, $p);
3473
-	}
3474
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
-		$img_file = chemin_image($img);
3476
-	}
3477
-	else {
3478
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
-			$img_file = http_img_variante_svg_si_possible($img_file);
3480
-		}
3481
-	}
3482
-	if (stripos($atts, 'width') === false) {
3483
-		// utiliser directement l'info de taille presente dans le nom
3484
-		if (
3485
-			(!isset($options['utiliser_suffixe_size'])
3486
-				or $options['utiliser_suffixe_size'] == true
3487
-			  or strpos($img_file, '-xx.svg') !== false)
3488
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
-		) {
3491
-			$largeur = $hauteur = intval($regs[1]);
3492
-		} else {
3493
-			$taille = taille_image($img_file);
3494
-			list($hauteur, $largeur) = $taille;
3495
-			if (!$hauteur or !$largeur) {
3496
-				return '';
3497
-			}
3498
-		}
3499
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
-	}
3501
-
3502
-	if (file_exists($img_file)) {
3503
-		$img_file = timestamp($img_file);
3504
-	}
3505
-	if ($alt === false) {
3506
-		$alt = '';
3507
-	}
3508
-	elseif ($alt or $alt === '') {
3509
-		$alt = " alt='" . attribut_html($alt) . "'";
3510
-	}
3511
-	else {
3512
-		$alt = " alt='" . attribut_html($title) . "'";
3513
-	}
3514
-	return "<img src='$img_file'$alt"
3515
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
-	. ' ' . ltrim($atts)
3517
-	. ' />';
3470
+    $img_file = $img;
3471
+    if ($p = strpos($img_file, '?')) {
3472
+        $img_file = substr($img_file, 0, $p);
3473
+    }
3474
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
+        $img_file = chemin_image($img);
3476
+    }
3477
+    else {
3478
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
+            $img_file = http_img_variante_svg_si_possible($img_file);
3480
+        }
3481
+    }
3482
+    if (stripos($atts, 'width') === false) {
3483
+        // utiliser directement l'info de taille presente dans le nom
3484
+        if (
3485
+            (!isset($options['utiliser_suffixe_size'])
3486
+                or $options['utiliser_suffixe_size'] == true
3487
+              or strpos($img_file, '-xx.svg') !== false)
3488
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
+        ) {
3491
+            $largeur = $hauteur = intval($regs[1]);
3492
+        } else {
3493
+            $taille = taille_image($img_file);
3494
+            list($hauteur, $largeur) = $taille;
3495
+            if (!$hauteur or !$largeur) {
3496
+                return '';
3497
+            }
3498
+        }
3499
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
+    }
3501
+
3502
+    if (file_exists($img_file)) {
3503
+        $img_file = timestamp($img_file);
3504
+    }
3505
+    if ($alt === false) {
3506
+        $alt = '';
3507
+    }
3508
+    elseif ($alt or $alt === '') {
3509
+        $alt = " alt='" . attribut_html($alt) . "'";
3510
+    }
3511
+    else {
3512
+        $alt = " alt='" . attribut_html($title) . "'";
3513
+    }
3514
+    return "<img src='$img_file'$alt"
3515
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
+    . ' ' . ltrim($atts)
3517
+    . ' />';
3518 3518
 }
3519 3519
 
3520 3520
 /**
@@ -3526,70 +3526,70 @@  discard block
 block discarded – undo
3526 3526
  * @return string
3527 3527
  */
3528 3528
 function http_style_background($img, $att = '', $size = null) {
3529
-	if ($size and is_numeric($size)) {
3530
-		$size = trim($size) . 'px';
3531
-	}
3532
-	return " style='background" .
3533
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
-		. ($size ? "background-size:{$size};" : '')
3535
-		. "'";
3529
+    if ($size and is_numeric($size)) {
3530
+        $size = trim($size) . 'px';
3531
+    }
3532
+    return " style='background" .
3533
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
+        . ($size ? "background-size:{$size};" : '')
3535
+        . "'";
3536 3536
 }
3537 3537
 
3538 3538
 
3539 3539
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3540
-	$args = [$alt_or_size, $class_or_size, $size];
3541
-	while (is_null(end($args)) and count($args)) {
3542
-		array_pop($args);
3543
-	}
3544
-	if (!count($args)) {
3545
-		return [null, null, null];
3546
-	}
3547
-	if (count($args) < 3) {
3548
-		$maybe_size = array_pop($args);
3549
-		// @2x
3550
-		// @1.5x
3551
-		// 512
3552
-		// 512x*
3553
-		// 512x300
3554
-		if (
3555
-			!strlen($maybe_size)
3556
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
-		) {
3558
-			$args[] = $maybe_size;
3559
-			$maybe_size = null;
3560
-		}
3561
-		while (count($args) < 2) {
3562
-			$args[] = null; // default alt or class
3563
-		}
3564
-		$args[] = $maybe_size;
3565
-	}
3566
-	return $args;
3540
+    $args = [$alt_or_size, $class_or_size, $size];
3541
+    while (is_null(end($args)) and count($args)) {
3542
+        array_pop($args);
3543
+    }
3544
+    if (!count($args)) {
3545
+        return [null, null, null];
3546
+    }
3547
+    if (count($args) < 3) {
3548
+        $maybe_size = array_pop($args);
3549
+        // @2x
3550
+        // @1.5x
3551
+        // 512
3552
+        // 512x*
3553
+        // 512x300
3554
+        if (
3555
+            !strlen($maybe_size)
3556
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
+        ) {
3558
+            $args[] = $maybe_size;
3559
+            $maybe_size = null;
3560
+        }
3561
+        while (count($args) < 2) {
3562
+            $args[] = null; // default alt or class
3563
+        }
3564
+        $args[] = $maybe_size;
3565
+    }
3566
+    return $args;
3567 3567
 }
3568 3568
 
3569 3569
 function helper_filtre_balise_img_svg_size($img, $size) {
3570
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
-		$coef = floatval(substr($size, 1, -1));
3573
-		list($h, $w) = taille_image($img);
3574
-		$height = intval(round($h / $coef));
3575
-		$width = intval(round($w / $coef));
3576
-	}
3577
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
-	else {
3579
-		$size = explode('x', $size, 2);
3580
-		$size = array_map('trim', $size);
3581
-		$height = $width = intval(array_shift($size));
3582
-
3583
-		if (count($size) and reset($size)) {
3584
-			$height = array_shift($size);
3585
-			if ($height === '*') {
3586
-				list($h, $w) = taille_image($img);
3587
-				$height = intval(round($h * $width / $w));
3588
-			}
3589
-		}
3590
-	}
3591
-
3592
-	return [$width, $height];
3570
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
+        $coef = floatval(substr($size, 1, -1));
3573
+        list($h, $w) = taille_image($img);
3574
+        $height = intval(round($h / $coef));
3575
+        $width = intval(round($w / $coef));
3576
+    }
3577
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
+    else {
3579
+        $size = explode('x', $size, 2);
3580
+        $size = array_map('trim', $size);
3581
+        $height = $width = intval(array_shift($size));
3582
+
3583
+        if (count($size) and reset($size)) {
3584
+            $height = array_shift($size);
3585
+            if ($height === '*') {
3586
+                list($h, $w) = taille_image($img);
3587
+                $height = intval(round($h * $width / $w));
3588
+            }
3589
+        }
3590
+    }
3591
+
3592
+    return [$width, $height];
3593 3593
 }
3594 3594
 
3595 3595
 /**
@@ -3625,43 +3625,43 @@  discard block
 block discarded – undo
3625 3625
  */
3626 3626
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3627 3627
 
3628
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
-
3630
-	$img = trim($img);
3631
-	if (strpos($img, '<img') === 0) {
3632
-		if (!is_null($alt)) {
3633
-			$img = inserer_attribut($img, 'alt', $alt);
3634
-		}
3635
-		if (!is_null($class)) {
3636
-			if (strlen($class)) {
3637
-				$img = inserer_attribut($img, 'class', $class);
3638
-			}
3639
-			else {
3640
-				$img = vider_attribut($img, 'class');
3641
-			}
3642
-		}
3643
-	}
3644
-	else {
3645
-		$img = http_img_pack(
3646
-			$img,
3647
-			$alt,
3648
-			$class ? " class='" . attribut_html($class) . "'" : '',
3649
-			'',
3650
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
-		);
3652
-		if (is_null($alt)) {
3653
-			$img = vider_attribut($img, 'alt');
3654
-		}
3655
-	}
3656
-
3657
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
-
3660
-		$img = inserer_attribut($img, 'width', $width);
3661
-		$img = inserer_attribut($img, 'height', $height);
3662
-	}
3663
-
3664
-	return $img;
3628
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
+
3630
+    $img = trim($img);
3631
+    if (strpos($img, '<img') === 0) {
3632
+        if (!is_null($alt)) {
3633
+            $img = inserer_attribut($img, 'alt', $alt);
3634
+        }
3635
+        if (!is_null($class)) {
3636
+            if (strlen($class)) {
3637
+                $img = inserer_attribut($img, 'class', $class);
3638
+            }
3639
+            else {
3640
+                $img = vider_attribut($img, 'class');
3641
+            }
3642
+        }
3643
+    }
3644
+    else {
3645
+        $img = http_img_pack(
3646
+            $img,
3647
+            $alt,
3648
+            $class ? " class='" . attribut_html($class) . "'" : '',
3649
+            '',
3650
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
+        );
3652
+        if (is_null($alt)) {
3653
+            $img = vider_attribut($img, 'alt');
3654
+        }
3655
+    }
3656
+
3657
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
+
3660
+        $img = inserer_attribut($img, 'width', $width);
3661
+        $img = inserer_attribut($img, 'height', $height);
3662
+    }
3663
+
3664
+    return $img;
3665 3665
 }
3666 3666
 
3667 3667
 
@@ -3695,67 +3695,67 @@  discard block
 block discarded – undo
3695 3695
  */
3696 3696
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3697 3697
 
3698
-	$img = trim($img);
3699
-	$img_file = $img;
3700
-	if (strpos($img, '<svg') === false) {
3701
-		if ($p = strpos($img_file, '?')) {
3702
-			$img_file = substr($img_file, 0, $p);
3703
-		}
3698
+    $img = trim($img);
3699
+    $img_file = $img;
3700
+    if (strpos($img, '<svg') === false) {
3701
+        if ($p = strpos($img_file, '?')) {
3702
+            $img_file = substr($img_file, 0, $p);
3703
+        }
3704 3704
 
3705
-		if (!$img_file or !$svg = file_get_contents($img_file)) {
3706
-			return '';
3707
-		}
3708
-	}
3705
+        if (!$img_file or !$svg = file_get_contents($img_file)) {
3706
+            return '';
3707
+        }
3708
+    }
3709 3709
 
3710
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3711
-		return '';
3712
-	}
3710
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3711
+        return '';
3712
+    }
3713 3713
 
3714
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3714
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3715 3715
 
3716
-	$balise_svg = $match[0];
3717
-	$balise_svg_source = $balise_svg;
3716
+    $balise_svg = $match[0];
3717
+    $balise_svg_source = $balise_svg;
3718 3718
 
3719
-	// entete XML à supprimer
3720
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3719
+    // entete XML à supprimer
3720
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3721 3721
 
3722
-	// IE est toujours mon ami
3723
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3722
+    // IE est toujours mon ami
3723
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3724 3724
 
3725
-	// regler la classe
3726
-	if (!is_null($class)) {
3727
-		if (strlen($class)) {
3728
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3729
-		}
3730
-		else {
3731
-			$balise_svg = vider_attribut($balise_svg, 'class');
3732
-		}
3733
-	}
3725
+    // regler la classe
3726
+    if (!is_null($class)) {
3727
+        if (strlen($class)) {
3728
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3729
+        }
3730
+        else {
3731
+            $balise_svg = vider_attribut($balise_svg, 'class');
3732
+        }
3733
+    }
3734 3734
 
3735
-	// regler le alt
3736
-	if ($alt) {
3737
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3738
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3739
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3741
-		$balise_svg .= $title;
3742
-	}
3743
-	else {
3744
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3745
-	}
3735
+    // regler le alt
3736
+    if ($alt) {
3737
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3738
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3739
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3740
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3741
+        $balise_svg .= $title;
3742
+    }
3743
+    else {
3744
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3745
+    }
3746 3746
 
3747
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3747
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3748 3748
 
3749
-	if (!is_null($size) and strlen($size = trim($size))) {
3750
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3749
+    if (!is_null($size) and strlen($size = trim($size))) {
3750
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3751 3751
 
3752
-		if (!function_exists('svg_redimensionner')) {
3753
-			include_spip('inc/svg');
3754
-		}
3755
-		$svg = svg_redimensionner($svg, $width, $height);
3756
-	}
3752
+        if (!function_exists('svg_redimensionner')) {
3753
+            include_spip('inc/svg');
3754
+        }
3755
+        $svg = svg_redimensionner($svg, $width, $height);
3756
+    }
3757 3757
 
3758
-	return $svg;
3758
+    return $svg;
3759 3759
 }
3760 3760
 
3761 3761
 
@@ -3781,18 +3781,18 @@  discard block
 block discarded – undo
3781 3781
  *     Code HTML résultant
3782 3782
  **/
3783 3783
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3784
-	$texte = '';
3785
-	if (is_array($tableau)) {
3786
-		foreach ($tableau as $k => $v) {
3787
-			$res = recuperer_fond(
3788
-				'modeles/' . $modele,
3789
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3790
-			);
3791
-			$texte .= $res;
3792
-		}
3793
-	}
3784
+    $texte = '';
3785
+    if (is_array($tableau)) {
3786
+        foreach ($tableau as $k => $v) {
3787
+            $res = recuperer_fond(
3788
+                'modeles/' . $modele,
3789
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3790
+            );
3791
+            $texte .= $res;
3792
+        }
3793
+    }
3794 3794
 
3795
-	return $texte;
3795
+    return $texte;
3796 3796
 }
3797 3797
 
3798 3798
 
@@ -3817,37 +3817,37 @@  discard block
 block discarded – undo
3817 3817
  *         - tout : retourne toutes les informations du plugin actif
3818 3818
  **/
3819 3819
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3820
-	include_spip('inc/plugin');
3821
-	$plugin = strtoupper($plugin);
3822
-	$plugins_actifs = liste_plugin_actifs();
3823
-
3824
-	if (!$plugin) {
3825
-		return serialize(array_keys($plugins_actifs));
3826
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3827
-		return '';
3828
-	} elseif (($type_info == 'est_actif') and !$reload) {
3829
-		return $plugins_actifs[$plugin] ? 1 : 0;
3830
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3831
-		return $plugins_actifs[$plugin][$type_info];
3832
-	} else {
3833
-		$get_infos = charger_fonction('get_infos', 'plugins');
3834
-		// On prend en compte les extensions
3835
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3836
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3837
-		} else {
3838
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3839
-		}
3840
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3841
-			return '';
3842
-		}
3843
-		if ($type_info == 'tout') {
3844
-			return $infos;
3845
-		} elseif ($type_info == 'est_actif') {
3846
-			return $infos ? 1 : 0;
3847
-		} else {
3848
-			return strval($infos[$type_info]);
3849
-		}
3850
-	}
3820
+    include_spip('inc/plugin');
3821
+    $plugin = strtoupper($plugin);
3822
+    $plugins_actifs = liste_plugin_actifs();
3823
+
3824
+    if (!$plugin) {
3825
+        return serialize(array_keys($plugins_actifs));
3826
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3827
+        return '';
3828
+    } elseif (($type_info == 'est_actif') and !$reload) {
3829
+        return $plugins_actifs[$plugin] ? 1 : 0;
3830
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3831
+        return $plugins_actifs[$plugin][$type_info];
3832
+    } else {
3833
+        $get_infos = charger_fonction('get_infos', 'plugins');
3834
+        // On prend en compte les extensions
3835
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3836
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3837
+        } else {
3838
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3839
+        }
3840
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3841
+            return '';
3842
+        }
3843
+        if ($type_info == 'tout') {
3844
+            return $infos;
3845
+        } elseif ($type_info == 'est_actif') {
3846
+            return $infos ? 1 : 0;
3847
+        } else {
3848
+            return strval($infos[$type_info]);
3849
+        }
3850
+    }
3851 3851
 }
3852 3852
 
3853 3853
 
@@ -3874,9 +3874,9 @@  discard block
 block discarded – undo
3874 3874
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3875 3875
  */
3876 3876
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3877
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3877
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3878 3878
 
3879
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3879
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3880 3880
 }
3881 3881
 
3882 3882
 
@@ -3906,19 +3906,19 @@  discard block
 block discarded – undo
3906 3906
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3907 3907
  */
3908 3908
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3909
-	static $puce_statut = null;
3910
-	if (!$puce_statut) {
3911
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3912
-	}
3909
+    static $puce_statut = null;
3910
+    if (!$puce_statut) {
3911
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3912
+    }
3913 3913
 
3914
-	return $puce_statut(
3915
-		$id_objet,
3916
-		$statut,
3917
-		$id_parent,
3918
-		$objet,
3919
-		false,
3920
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3921
-	);
3914
+    return $puce_statut(
3915
+        $id_objet,
3916
+        $statut,
3917
+        $id_parent,
3918
+        $objet,
3919
+        false,
3920
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3921
+    );
3922 3922
 }
3923 3923
 
3924 3924
 
@@ -3945,97 +3945,97 @@  discard block
 block discarded – undo
3945 3945
  *   hash du contexte
3946 3946
  */
3947 3947
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3948
-	if (
3949
-		is_string($c)
3950
-		and @unserialize($c) !== false
3951
-	) {
3952
-		$c = unserialize($c);
3953
-	}
3954
-
3955
-	// supprimer les parametres debut_x
3956
-	// pour que la pagination ajax ne soit pas plantee
3957
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3958
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3959
-	if (is_array($c)) {
3960
-		foreach ($c as $k => $v) {
3961
-			if (strpos($k, 'debut_') === 0) {
3962
-				unset($c[$k]);
3963
-			}
3964
-		}
3965
-	}
3966
-
3967
-	if (!function_exists('calculer_cle_action')) {
3968
-		include_spip('inc/securiser_action');
3969
-	}
3970
-
3971
-	$c = serialize($c);
3972
-	$cle = calculer_cle_action($form . $c);
3973
-	$c = "$cle:$c";
3974
-
3975
-	// on ne stocke pas les contextes dans des fichiers en cache
3976
-	// par defaut, sauf si cette configuration a été forcée
3977
-	// OU que la longueur de l’argument géneré est plus long
3978
-	// que ce qui est toléré.
3979
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3980
-	if (!$cache_contextes_ajax) {
3981
-		$env = $c;
3982
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3983
-			$env = gzdeflate($env);
3984
-		}
3985
-		$env = _xor($env);
3986
-		$env = base64_encode($env);
3987
-		$len = strlen($env);
3988
-		// Si l’url est trop longue pour le navigateur
3989
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3990
-		if ($len > $max_len) {
3991
-			$cache_contextes_ajax = true;
3992
-			spip_log(
3993
-				'Contextes AJAX forces en fichiers !'
3994
-				. ' Cela arrive lorsque la valeur du contexte'
3995
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3996
-				_LOG_AVERTISSEMENT
3997
-			);
3998
-		}
3999
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4000
-		elseif (
4001
-			$max_len = @ini_get('suhosin.get.max_value_length')
4002
-			and $max_len < $len
4003
-		) {
4004
-			$cache_contextes_ajax = true;
4005
-			spip_log('Contextes AJAX forces en fichiers !'
4006
-				. ' Cela arrive lorsque la valeur du contexte'
4007
-				. ' depasse la longueur maximale autorisee par Suhosin'
4008
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4009
-				. ' Vous devriez modifier les parametres de Suhosin'
4010
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4011
-		}
4012
-	}
4013
-
4014
-	if ($cache_contextes_ajax) {
4015
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4016
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4017
-		$md5 = md5($c);
4018
-		ecrire_fichier("$dir/c$md5", $c);
4019
-		$env = $md5;
4020
-	}
4021
-
4022
-	if ($emboite === null) {
4023
-		return $env;
4024
-	}
4025
-	if (!trim($emboite)) {
4026
-		return '';
4027
-	}
4028
-	// toujours encoder l'url source dans le bloc ajax
4029
-	$r = self();
4030
-	$r = ' data-origin="' . $r . '"';
4031
-	$class = 'ajaxbloc';
4032
-	if ($ajaxid and is_string($ajaxid)) {
4033
-		// ajaxid est normalement conforme a un nom de classe css
4034
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4035
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4036
-	}
4037
-
4038
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3948
+    if (
3949
+        is_string($c)
3950
+        and @unserialize($c) !== false
3951
+    ) {
3952
+        $c = unserialize($c);
3953
+    }
3954
+
3955
+    // supprimer les parametres debut_x
3956
+    // pour que la pagination ajax ne soit pas plantee
3957
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3958
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3959
+    if (is_array($c)) {
3960
+        foreach ($c as $k => $v) {
3961
+            if (strpos($k, 'debut_') === 0) {
3962
+                unset($c[$k]);
3963
+            }
3964
+        }
3965
+    }
3966
+
3967
+    if (!function_exists('calculer_cle_action')) {
3968
+        include_spip('inc/securiser_action');
3969
+    }
3970
+
3971
+    $c = serialize($c);
3972
+    $cle = calculer_cle_action($form . $c);
3973
+    $c = "$cle:$c";
3974
+
3975
+    // on ne stocke pas les contextes dans des fichiers en cache
3976
+    // par defaut, sauf si cette configuration a été forcée
3977
+    // OU que la longueur de l’argument géneré est plus long
3978
+    // que ce qui est toléré.
3979
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3980
+    if (!$cache_contextes_ajax) {
3981
+        $env = $c;
3982
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3983
+            $env = gzdeflate($env);
3984
+        }
3985
+        $env = _xor($env);
3986
+        $env = base64_encode($env);
3987
+        $len = strlen($env);
3988
+        // Si l’url est trop longue pour le navigateur
3989
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3990
+        if ($len > $max_len) {
3991
+            $cache_contextes_ajax = true;
3992
+            spip_log(
3993
+                'Contextes AJAX forces en fichiers !'
3994
+                . ' Cela arrive lorsque la valeur du contexte'
3995
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3996
+                _LOG_AVERTISSEMENT
3997
+            );
3998
+        }
3999
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4000
+        elseif (
4001
+            $max_len = @ini_get('suhosin.get.max_value_length')
4002
+            and $max_len < $len
4003
+        ) {
4004
+            $cache_contextes_ajax = true;
4005
+            spip_log('Contextes AJAX forces en fichiers !'
4006
+                . ' Cela arrive lorsque la valeur du contexte'
4007
+                . ' depasse la longueur maximale autorisee par Suhosin'
4008
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4009
+                . ' Vous devriez modifier les parametres de Suhosin'
4010
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4011
+        }
4012
+    }
4013
+
4014
+    if ($cache_contextes_ajax) {
4015
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4016
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4017
+        $md5 = md5($c);
4018
+        ecrire_fichier("$dir/c$md5", $c);
4019
+        $env = $md5;
4020
+    }
4021
+
4022
+    if ($emboite === null) {
4023
+        return $env;
4024
+    }
4025
+    if (!trim($emboite)) {
4026
+        return '';
4027
+    }
4028
+    // toujours encoder l'url source dans le bloc ajax
4029
+    $r = self();
4030
+    $r = ' data-origin="' . $r . '"';
4031
+    $class = 'ajaxbloc';
4032
+    if ($ajaxid and is_string($ajaxid)) {
4033
+        // ajaxid est normalement conforme a un nom de classe css
4034
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4035
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4036
+    }
4037
+
4038
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4039 4039
 }
4040 4040
 
4041 4041
 /**
@@ -4055,37 +4055,37 @@  discard block
 block discarded – undo
4055 4055
  *   - false : erreur de décodage
4056 4056
  */
4057 4057
 function decoder_contexte_ajax($c, $form = '') {
4058
-	if (!function_exists('calculer_cle_action')) {
4059
-		include_spip('inc/securiser_action');
4060
-	}
4061
-	if (
4062
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4063
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4064
-		and lire_fichier("$dir/c$c", $contexte)
4065
-	) {
4066
-		$c = $contexte;
4067
-	} else {
4068
-		$c = @base64_decode($c);
4069
-		$c = _xor($c);
4070
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4071
-			$c = @gzinflate($c);
4072
-		}
4073
-	}
4074
-
4075
-	// extraire la signature en debut de contexte
4076
-	// et la verifier avant de deserializer
4077
-	// format : signature:donneesserializees
4078
-	if ($p = strpos($c, ':')) {
4079
-		$cle = substr($c, 0, $p);
4080
-		$c = substr($c, $p + 1);
4081
-
4082
-		if ($cle == calculer_cle_action($form . $c)) {
4083
-			$env = @unserialize($c);
4084
-			return $env;
4085
-		}
4086
-	}
4087
-
4088
-	return false;
4058
+    if (!function_exists('calculer_cle_action')) {
4059
+        include_spip('inc/securiser_action');
4060
+    }
4061
+    if (
4062
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4063
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4064
+        and lire_fichier("$dir/c$c", $contexte)
4065
+    ) {
4066
+        $c = $contexte;
4067
+    } else {
4068
+        $c = @base64_decode($c);
4069
+        $c = _xor($c);
4070
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4071
+            $c = @gzinflate($c);
4072
+        }
4073
+    }
4074
+
4075
+    // extraire la signature en debut de contexte
4076
+    // et la verifier avant de deserializer
4077
+    // format : signature:donneesserializees
4078
+    if ($p = strpos($c, ':')) {
4079
+        $cle = substr($c, 0, $p);
4080
+        $c = substr($c, $p + 1);
4081
+
4082
+        if ($cle == calculer_cle_action($form . $c)) {
4083
+            $env = @unserialize($c);
4084
+            return $env;
4085
+        }
4086
+    }
4087
+
4088
+    return false;
4089 4089
 }
4090 4090
 
4091 4091
 
@@ -4103,20 +4103,20 @@  discard block
 block discarded – undo
4103 4103
  *    Message décrypté ou encrypté
4104 4104
  **/
4105 4105
 function _xor($message, $key = null) {
4106
-	if (is_null($key)) {
4107
-		if (!function_exists('calculer_cle_action')) {
4108
-			include_spip('inc/securiser_action');
4109
-		}
4110
-		$key = pack('H*', calculer_cle_action('_xor'));
4111
-	}
4106
+    if (is_null($key)) {
4107
+        if (!function_exists('calculer_cle_action')) {
4108
+            include_spip('inc/securiser_action');
4109
+        }
4110
+        $key = pack('H*', calculer_cle_action('_xor'));
4111
+    }
4112 4112
 
4113
-	$keylen = strlen($key);
4114
-	$messagelen = strlen($message);
4115
-	for ($i = 0; $i < $messagelen; $i++) {
4116
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4117
-	}
4113
+    $keylen = strlen($key);
4114
+    $messagelen = strlen($message);
4115
+    for ($i = 0; $i < $messagelen; $i++) {
4116
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4117
+    }
4118 4118
 
4119
-	return $message;
4119
+    return $message;
4120 4120
 }
4121 4121
 
4122 4122
 /**
@@ -4130,7 +4130,7 @@  discard block
 block discarded – undo
4130 4130
  * @return string
4131 4131
  */
4132 4132
 function url_reponse_forum($texte) {
4133
- return $texte;
4133
+    return $texte;
4134 4134
 }
4135 4135
 
4136 4136
 /**
@@ -4144,7 +4144,7 @@  discard block
 block discarded – undo
4144 4144
  * @return string
4145 4145
  */
4146 4146
 function url_rss_forum($texte) {
4147
- return $texte;
4147
+    return $texte;
4148 4148
 }
4149 4149
 
4150 4150
 
@@ -4183,37 +4183,37 @@  discard block
 block discarded – undo
4183 4183
  *   Code HTML
4184 4184
  */
4185 4185
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4186
-	if ($on) {
4187
-		$bal = 'strong';
4188
-		$class = '';
4189
-		$att = '';
4190
-		// si $on passe la balise et optionnelement une ou ++classe
4191
-		// a.active span.selected.active etc....
4192
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4193
-			$on = explode('.', $on);
4194
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4195
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4196
-				$bal = array_shift($on);
4197
-				$class = implode(' ', $on);
4198
-				if ($bal == 'a') {
4199
-					$att = 'href="#" ';
4200
-				}
4201
-			}
4202
-		}
4203
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4204
-	} else {
4205
-		$bal = 'a';
4206
-		$att = "href='$url'"
4207
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4208
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4209
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4210
-			. $evt;
4211
-	}
4212
-	if ($libelle === null) {
4213
-		$libelle = $url;
4214
-	}
4215
-
4216
-	return "<$bal $att>$libelle</$bal>";
4186
+    if ($on) {
4187
+        $bal = 'strong';
4188
+        $class = '';
4189
+        $att = '';
4190
+        // si $on passe la balise et optionnelement une ou ++classe
4191
+        // a.active span.selected.active etc....
4192
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4193
+            $on = explode('.', $on);
4194
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4195
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4196
+                $bal = array_shift($on);
4197
+                $class = implode(' ', $on);
4198
+                if ($bal == 'a') {
4199
+                    $att = 'href="#" ';
4200
+                }
4201
+            }
4202
+        }
4203
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4204
+    } else {
4205
+        $bal = 'a';
4206
+        $att = "href='$url'"
4207
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4208
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4209
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4210
+            . $evt;
4211
+    }
4212
+    if ($libelle === null) {
4213
+        $libelle = $url;
4214
+    }
4215
+
4216
+    return "<$bal $att>$libelle</$bal>";
4217 4217
 }
4218 4218
 
4219 4219
 
@@ -4230,39 +4230,39 @@  discard block
 block discarded – undo
4230 4230
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4231 4231
  */
4232 4232
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4233
-	static $local_singulier_ou_pluriel = [];
4234
-
4235
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4236
-	if (!is_numeric($nb) or $nb == 0) {
4237
-		return '';
4238
-	}
4239
-	if (!is_array($vars)) {
4240
-		return '';
4241
-	}
4242
-
4243
-	$langue = $GLOBALS['spip_lang'];
4244
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4245
-		$local_singulier_ou_pluriel[$langue] = false;
4246
-		if (
4247
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4248
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4249
-		) {
4250
-			$local_singulier_ou_pluriel[$langue] = $f;
4251
-		}
4252
-	}
4253
-
4254
-	// si on a une surcharge on l'utilise
4255
-	if ($local_singulier_ou_pluriel[$langue]) {
4256
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4257
-	}
4258
-
4259
-	// sinon traitement par defaut
4260
-	$vars[$var] = $nb;
4261
-	if ($nb >= 2) {
4262
-		return _T($chaine_plusieurs, $vars);
4263
-	} else {
4264
-		return _T($chaine_un, $vars);
4265
-	}
4233
+    static $local_singulier_ou_pluriel = [];
4234
+
4235
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4236
+    if (!is_numeric($nb) or $nb == 0) {
4237
+        return '';
4238
+    }
4239
+    if (!is_array($vars)) {
4240
+        return '';
4241
+    }
4242
+
4243
+    $langue = $GLOBALS['spip_lang'];
4244
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4245
+        $local_singulier_ou_pluriel[$langue] = false;
4246
+        if (
4247
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4248
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4249
+        ) {
4250
+            $local_singulier_ou_pluriel[$langue] = $f;
4251
+        }
4252
+    }
4253
+
4254
+    // si on a une surcharge on l'utilise
4255
+    if ($local_singulier_ou_pluriel[$langue]) {
4256
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4257
+    }
4258
+
4259
+    // sinon traitement par defaut
4260
+    $vars[$var] = $nb;
4261
+    if ($nb >= 2) {
4262
+        return _T($chaine_plusieurs, $vars);
4263
+    } else {
4264
+        return _T($chaine_un, $vars);
4265
+    }
4266 4266
 }
4267 4267
 
4268 4268
 
@@ -4290,73 +4290,73 @@  discard block
 block discarded – undo
4290 4290
  */
4291 4291
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4292 4292
 
4293
-	$class_lien = $class_bouton = $class;
4294
-
4295
-	// Normaliser la fonction et compléter la classe en fonction
4296
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4297
-		$class_lien .= ' danger';
4298
-		$class_bouton .= ' btn_danger';
4299
-	} elseif ($fonction == 'rien.gif') {
4300
-		$fonction = '';
4301
-	} elseif ($fonction == 'delsafe') {
4302
-		$fonction = 'del';
4303
-	}
4304
-
4305
-	$fond_origine = $fond;
4306
-	// Remappage des icone : article-24.png+new => article-new-24.png
4307
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4308
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4309
-	}
4310
-
4311
-	// Ajouter le type d'objet dans la classe
4312
-	$objet_type = substr(basename($fond), 0, -4);
4313
-	$class_lien .= " $objet_type";
4314
-	$class_bouton .= " $objet_type";
4315
-
4316
-	// Texte
4317
-	$alt = attribut_html($texte);
4318
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4319
-
4320
-	// Liens : préparer les classes ajax
4321
-	$ajax = '';
4322
-	if ($type === 'lien') {
4323
-		if (strpos($class_lien, 'ajax') !== false) {
4324
-			$ajax = 'ajax';
4325
-			if (strpos($class_lien, 'preload') !== false) {
4326
-				$ajax .= ' preload';
4327
-			}
4328
-			if (strpos($class_lien, 'nocache') !== false) {
4329
-				$ajax .= ' nocache';
4330
-			}
4331
-			$ajax = " class='$ajax'";
4332
-		}
4333
-	}
4334
-
4335
-	// Repérer la taille et l'ajouter dans la classe
4336
-	$size = 24;
4337
-	if (
4338
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4339
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4340
-	) {
4341
-		$size = $match[1];
4342
-	}
4343
-	$class_lien .= " s$size";
4344
-	$class_bouton .= " s$size";
4345
-
4346
-	// Icône
4347
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4348
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4349
-
4350
-	// Markup final
4351
-	if ($type == 'lien') {
4352
-		return "<span class='icone $class_lien'>"
4353
-		. "<a href='$lien'$title$ajax$javascript>"
4354
-		. $icone
4355
-		. "<b>$texte</b>"
4356
-		. "</a></span>\n";
4357
-	} else {
4358
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4359
-	}
4293
+    $class_lien = $class_bouton = $class;
4294
+
4295
+    // Normaliser la fonction et compléter la classe en fonction
4296
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4297
+        $class_lien .= ' danger';
4298
+        $class_bouton .= ' btn_danger';
4299
+    } elseif ($fonction == 'rien.gif') {
4300
+        $fonction = '';
4301
+    } elseif ($fonction == 'delsafe') {
4302
+        $fonction = 'del';
4303
+    }
4304
+
4305
+    $fond_origine = $fond;
4306
+    // Remappage des icone : article-24.png+new => article-new-24.png
4307
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4308
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4309
+    }
4310
+
4311
+    // Ajouter le type d'objet dans la classe
4312
+    $objet_type = substr(basename($fond), 0, -4);
4313
+    $class_lien .= " $objet_type";
4314
+    $class_bouton .= " $objet_type";
4315
+
4316
+    // Texte
4317
+    $alt = attribut_html($texte);
4318
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4319
+
4320
+    // Liens : préparer les classes ajax
4321
+    $ajax = '';
4322
+    if ($type === 'lien') {
4323
+        if (strpos($class_lien, 'ajax') !== false) {
4324
+            $ajax = 'ajax';
4325
+            if (strpos($class_lien, 'preload') !== false) {
4326
+                $ajax .= ' preload';
4327
+            }
4328
+            if (strpos($class_lien, 'nocache') !== false) {
4329
+                $ajax .= ' nocache';
4330
+            }
4331
+            $ajax = " class='$ajax'";
4332
+        }
4333
+    }
4334
+
4335
+    // Repérer la taille et l'ajouter dans la classe
4336
+    $size = 24;
4337
+    if (
4338
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4339
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4340
+    ) {
4341
+        $size = $match[1];
4342
+    }
4343
+    $class_lien .= " s$size";
4344
+    $class_bouton .= " s$size";
4345
+
4346
+    // Icône
4347
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4348
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4349
+
4350
+    // Markup final
4351
+    if ($type == 'lien') {
4352
+        return "<span class='icone $class_lien'>"
4353
+        . "<a href='$lien'$title$ajax$javascript>"
4354
+        . $icone
4355
+        . "<b>$texte</b>"
4356
+        . "</a></span>\n";
4357
+    } else {
4358
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4359
+    }
4360 4360
 }
4361 4361
 
4362 4362
 /**
@@ -4380,7 +4380,7 @@  discard block
 block discarded – undo
4380 4380
  *     Code HTML du lien
4381 4381
  **/
4382 4382
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4383
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4383
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4384 4384
 }
4385 4385
 
4386 4386
 /**
@@ -4415,7 +4415,7 @@  discard block
 block discarded – undo
4415 4415
  *     Code HTML du lien
4416 4416
  **/
4417 4417
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4418
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4418
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4419 4419
 }
4420 4420
 
4421 4421
 /**
@@ -4460,7 +4460,7 @@  discard block
 block discarded – undo
4460 4460
  *     Code HTML du lien
4461 4461
  **/
4462 4462
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4463
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4463
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4464 4464
 }
4465 4465
 
4466 4466
 /**
@@ -4491,7 +4491,7 @@  discard block
 block discarded – undo
4491 4491
  *     Code HTML du lien
4492 4492
  **/
4493 4493
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4494
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4494
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4495 4495
 }
4496 4496
 
4497 4497
 /**
@@ -4522,7 +4522,7 @@  discard block
 block discarded – undo
4522 4522
  *     Code HTML du lien
4523 4523
  */
4524 4524
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4525
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4525
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4526 4526
 }
4527 4527
 
4528 4528
 
@@ -4544,7 +4544,7 @@  discard block
 block discarded – undo
4544 4544
  * @return array Liste des éléments
4545 4545
  */
4546 4546
 function filtre_explode_dist($a, $b) {
4547
- return explode($b, $a);
4547
+    return explode($b, $a);
4548 4548
 }
4549 4549
 
4550 4550
 /**
@@ -4565,7 +4565,7 @@  discard block
 block discarded – undo
4565 4565
  * @return string Texte
4566 4566
  */
4567 4567
 function filtre_implode_dist($a, $b) {
4568
- return is_array($a) ? implode($b, $a) : $a;
4568
+    return is_array($a) ? implode($b, $a) : $a;
4569 4569
 }
4570 4570
 
4571 4571
 /**
@@ -4574,24 +4574,24 @@  discard block
 block discarded – undo
4574 4574
  * @return string Code CSS
4575 4575
  */
4576 4576
 function bando_images_background() {
4577
-	include_spip('inc/bandeau');
4578
-	// recuperer tous les boutons et leurs images
4579
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4577
+    include_spip('inc/bandeau');
4578
+    // recuperer tous les boutons et leurs images
4579
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4580 4580
 
4581
-	$res = '';
4582
-	foreach ($boutons as $page => $detail) {
4583
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4584
-		if (is_array($detail->sousmenu)) {
4585
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4586
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4587
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4588
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4589
-				}
4590
-			}
4591
-		}
4592
-	}
4581
+    $res = '';
4582
+    foreach ($boutons as $page => $detail) {
4583
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4584
+        if (is_array($detail->sousmenu)) {
4585
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4586
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4587
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4588
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4589
+                }
4590
+            }
4591
+        }
4592
+    }
4593 4593
 
4594
-	return $res;
4594
+    return $res;
4595 4595
 }
4596 4596
 
4597 4597
 /**
@@ -4616,27 +4616,27 @@  discard block
 block discarded – undo
4616 4616
  */
4617 4617
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4618 4618
 
4619
-	// Classes : dispatcher `ajax` sur le formulaire
4620
-	$class_form = '';
4621
-	if (strpos($class, 'ajax') !== false) {
4622
-		$class_form = 'ajax';
4623
-		$class = str_replace('ajax', '', $class);
4624
-	}
4625
-	$class_btn = 'submit ' . trim($class);
4619
+    // Classes : dispatcher `ajax` sur le formulaire
4620
+    $class_form = '';
4621
+    if (strpos($class, 'ajax') !== false) {
4622
+        $class_form = 'ajax';
4623
+        $class = str_replace('ajax', '', $class);
4624
+    }
4625
+    $class_btn = 'submit ' . trim($class);
4626 4626
 
4627
-	if ($confirm) {
4628
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4629
-		if ($callback) {
4630
-			$callback = "$confirm?($callback):false";
4631
-		} else {
4632
-			$callback = $confirm;
4633
-		}
4634
-	}
4635
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4636
-	$title = $title ? " title='$title'" : '';
4627
+    if ($confirm) {
4628
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4629
+        if ($callback) {
4630
+            $callback = "$confirm?($callback):false";
4631
+        } else {
4632
+            $callback = $confirm;
4633
+        }
4634
+    }
4635
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4636
+    $title = $title ? " title='$title'" : '';
4637 4637
 
4638
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4639
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4638
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4639
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4640 4640
 }
4641 4641
 
4642 4642
 /**
@@ -4659,94 +4659,94 @@  discard block
 block discarded – undo
4659 4659
  * @return string
4660 4660
  */
4661 4661
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4662
-	static $trouver_table = null;
4663
-	static $objets;
4664
-
4665
-	// On verifie qu'on a tout ce qu'il faut
4666
-	$id_objet = intval($id_objet);
4667
-	if (!($id_objet and $type_objet and $info)) {
4668
-		return '';
4669
-	}
4670
-
4671
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4672
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4673
-		return '';
4674
-	}
4675
-
4676
-	// Si on demande l'url, on retourne direct la fonction
4677
-	if ($info == 'url') {
4678
-		return generer_url_entite($id_objet, $type_objet, ...$params);
4679
-	}
4680
-
4681
-	// Sinon on va tout chercher dans la table et on garde en memoire
4682
-	$demande_titre = ($info === 'titre');
4683
-	$demande_introduction = ($info === 'introduction');
4684
-
4685
-	// 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
4686
-	if (
4687
-		!isset($objets[$type_objet][$id_objet])
4688
-		or
4689
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4690
-	) {
4691
-		if (!$trouver_table) {
4692
-			$trouver_table = charger_fonction('trouver_table', 'base');
4693
-		}
4694
-		$desc = $trouver_table(table_objet_sql($type_objet));
4695
-		if (!$desc) {
4696
-			return $objets[$type_objet] = false;
4697
-		}
4698
-
4699
-		// Si on demande le titre, on le gere en interne
4700
-		$champ_titre = '';
4701
-		if ($demande_titre) {
4702
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4703
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4704
-		}
4705
-		include_spip('base/abstract_sql');
4706
-		include_spip('base/connect_sql');
4707
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4708
-			'*' . $champ_titre,
4709
-			$desc['table_sql'],
4710
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4711
-		);
4712
-
4713
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4714
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4715
-	}
4716
-
4717
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4718
-	// ajouter la longueur au début des params supplémentaires
4719
-	if ($demande_introduction) {
4720
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4721
-		array_unshift($params, $introduction_longueur);
4722
-	}
4723
-
4724
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4725
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4726
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4727
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4728
-	else {
4729
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4730
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4731
-		} // Sinon on prend directement le champ SQL tel quel
4732
-		else {
4733
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4734
-		}
4735
-	}
4736
-
4737
-	// On va ensuite appliquer les traitements automatiques si besoin
4738
-	if (!$etoile) {
4739
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4740
-		// mais ce fonctionnement est a ameliorer !
4741
-		$info_generee = appliquer_traitement_champ(
4742
-			$info_generee,
4743
-			$info,
4744
-			table_objet($type_objet),
4745
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4746
-		);
4747
-	}
4748
-
4749
-	return $info_generee;
4662
+    static $trouver_table = null;
4663
+    static $objets;
4664
+
4665
+    // On verifie qu'on a tout ce qu'il faut
4666
+    $id_objet = intval($id_objet);
4667
+    if (!($id_objet and $type_objet and $info)) {
4668
+        return '';
4669
+    }
4670
+
4671
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4672
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4673
+        return '';
4674
+    }
4675
+
4676
+    // Si on demande l'url, on retourne direct la fonction
4677
+    if ($info == 'url') {
4678
+        return generer_url_entite($id_objet, $type_objet, ...$params);
4679
+    }
4680
+
4681
+    // Sinon on va tout chercher dans la table et on garde en memoire
4682
+    $demande_titre = ($info === 'titre');
4683
+    $demande_introduction = ($info === 'introduction');
4684
+
4685
+    // 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
4686
+    if (
4687
+        !isset($objets[$type_objet][$id_objet])
4688
+        or
4689
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4690
+    ) {
4691
+        if (!$trouver_table) {
4692
+            $trouver_table = charger_fonction('trouver_table', 'base');
4693
+        }
4694
+        $desc = $trouver_table(table_objet_sql($type_objet));
4695
+        if (!$desc) {
4696
+            return $objets[$type_objet] = false;
4697
+        }
4698
+
4699
+        // Si on demande le titre, on le gere en interne
4700
+        $champ_titre = '';
4701
+        if ($demande_titre) {
4702
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4703
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4704
+        }
4705
+        include_spip('base/abstract_sql');
4706
+        include_spip('base/connect_sql');
4707
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4708
+            '*' . $champ_titre,
4709
+            $desc['table_sql'],
4710
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4711
+        );
4712
+
4713
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4714
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4715
+    }
4716
+
4717
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4718
+    // ajouter la longueur au début des params supplémentaires
4719
+    if ($demande_introduction) {
4720
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4721
+        array_unshift($params, $introduction_longueur);
4722
+    }
4723
+
4724
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4725
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4726
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4727
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4728
+    else {
4729
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4730
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4731
+        } // Sinon on prend directement le champ SQL tel quel
4732
+        else {
4733
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4734
+        }
4735
+    }
4736
+
4737
+    // On va ensuite appliquer les traitements automatiques si besoin
4738
+    if (!$etoile) {
4739
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4740
+        // mais ce fonctionnement est a ameliorer !
4741
+        $info_generee = appliquer_traitement_champ(
4742
+            $info_generee,
4743
+            $info,
4744
+            table_objet($type_objet),
4745
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4746
+        );
4747
+    }
4748
+
4749
+    return $info_generee;
4750 4750
 }
4751 4751
 
4752 4752
 /**
@@ -4779,36 +4779,36 @@  discard block
 block discarded – undo
4779 4779
  */
4780 4780
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, $connect = '') {
4781 4781
 
4782
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4783
-	$texte = $ligne_sql['texte'] ?? '';
4784
-	// En absence de descriptif, on se rabat sur chapo + texte
4785
-	if (isset($ligne_sql['chapo'])) {
4786
-		$chapo = $ligne_sql['chapo'];
4787
-		$texte = strlen($descriptif) ?
4788
-			'' :
4789
-			"$chapo \n\n $texte";
4790
-	}
4782
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4783
+    $texte = $ligne_sql['texte'] ?? '';
4784
+    // En absence de descriptif, on se rabat sur chapo + texte
4785
+    if (isset($ligne_sql['chapo'])) {
4786
+        $chapo = $ligne_sql['chapo'];
4787
+        $texte = strlen($descriptif) ?
4788
+            '' :
4789
+            "$chapo \n\n $texte";
4790
+    }
4791 4791
 
4792
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4793
-	if (!intval($longueur_ou_suite)) {
4794
-		$longueur = intval($introduction_longueur ?: 600);
4795
-	} else {
4796
-		$longueur = intval($longueur_ou_suite);
4797
-	}
4792
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4793
+    if (!intval($longueur_ou_suite)) {
4794
+        $longueur = intval($introduction_longueur ?: 600);
4795
+    } else {
4796
+        $longueur = intval($longueur_ou_suite);
4797
+    }
4798 4798
 
4799
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4800
-	// Ex : #INTRODUCTION{...}
4801
-	if (
4802
-		is_null($suite)
4803
-		and !intval($longueur_ou_suite)
4804
-	) {
4805
-		$suite = $longueur_ou_suite;
4806
-	}
4799
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4800
+    // Ex : #INTRODUCTION{...}
4801
+    if (
4802
+        is_null($suite)
4803
+        and !intval($longueur_ou_suite)
4804
+    ) {
4805
+        $suite = $longueur_ou_suite;
4806
+    }
4807 4807
 
4808
-	$f = chercher_filtre('introduction');
4809
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4808
+    $f = chercher_filtre('introduction');
4809
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4810 4810
 
4811
-	return $introduction;
4811
+    return $introduction;
4812 4812
 }
4813 4813
 
4814 4814
 /**
@@ -4822,44 +4822,44 @@  discard block
 block discarded – undo
4822 4822
  * @return string
4823 4823
  */
4824 4824
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], $connect = '') {
4825
-	if (!$champ) {
4826
-		return $texte;
4827
-	}
4825
+    if (!$champ) {
4826
+        return $texte;
4827
+    }
4828 4828
 
4829
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
-	include_fichiers_fonctions();
4829
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
+    include_fichiers_fonctions();
4832 4832
 
4833
-	$champ = strtoupper($champ);
4834
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4835
-	if (!$traitements or !is_array($traitements)) {
4836
-		return $texte;
4837
-	}
4833
+    $champ = strtoupper($champ);
4834
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4835
+    if (!$traitements or !is_array($traitements)) {
4836
+        return $texte;
4837
+    }
4838 4838
 
4839
-	$traitement = '';
4840
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
-		$table_objet = table_objet($table_objet);
4843
-		if (isset($traitements[$table_objet])) {
4844
-			$traitement = $traitements[$table_objet];
4845
-		}
4846
-	}
4847
-	if (!$traitement and isset($traitements[0])) {
4848
-		$traitement = $traitements[0];
4849
-	}
4850
-	// (sinon prendre le premier de la liste par defaut ?)
4839
+    $traitement = '';
4840
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
+        $table_objet = table_objet($table_objet);
4843
+        if (isset($traitements[$table_objet])) {
4844
+            $traitement = $traitements[$table_objet];
4845
+        }
4846
+    }
4847
+    if (!$traitement and isset($traitements[0])) {
4848
+        $traitement = $traitements[0];
4849
+    }
4850
+    // (sinon prendre le premier de la liste par defaut ?)
4851 4851
 
4852
-	if (!$traitement) {
4853
-		return $texte;
4854
-	}
4852
+    if (!$traitement) {
4853
+        return $texte;
4854
+    }
4855 4855
 
4856
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4856
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4857 4857
 
4858
-	// Fournir $connect et $Pile[0] au traitement si besoin
4859
-	$Pile = [0 => $env];
4860
-	eval("\$texte = $traitement;");
4858
+    // Fournir $connect et $Pile[0] au traitement si besoin
4859
+    $Pile = [0 => $env];
4860
+    eval("\$texte = $traitement;");
4861 4861
 
4862
-	return $texte;
4862
+    return $texte;
4863 4863
 }
4864 4864
 
4865 4865
 
@@ -4873,21 +4873,21 @@  discard block
 block discarded – undo
4873 4873
  * @return string
4874 4874
  */
4875 4875
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4876
-	include_spip('inc/liens');
4877
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
-	// le raccourcis n'est plus valide
4880
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4881
-	// on essaye avec generer_info_entite ?
4882
-	if (!strlen($titre) and !$connect) {
4883
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4884
-	}
4885
-	if (!strlen($titre)) {
4886
-		$titre = _T('info_sans_titre');
4887
-	}
4888
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4876
+    include_spip('inc/liens');
4877
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
+    // le raccourcis n'est plus valide
4880
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4881
+    // on essaye avec generer_info_entite ?
4882
+    if (!strlen($titre) and !$connect) {
4883
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4884
+    }
4885
+    if (!strlen($titre)) {
4886
+        $titre = _T('info_sans_titre');
4887
+    }
4888
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4889 4889
 
4890
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4890
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4891 4891
 }
4892 4892
 
4893 4893
 
@@ -4904,15 +4904,15 @@  discard block
 block discarded – undo
4904 4904
  * @return string
4905 4905
  */
4906 4906
 function wrap($texte, $wrap) {
4907
-	$balises = extraire_balises($wrap);
4908
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4909
-		$texte = $wrap . $texte;
4910
-		$regs = array_reverse($regs[1]);
4911
-		$wrap = '</' . implode('></', $regs) . '>';
4912
-		$texte = $texte . $wrap;
4913
-	}
4907
+    $balises = extraire_balises($wrap);
4908
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4909
+        $texte = $wrap . $texte;
4910
+        $regs = array_reverse($regs[1]);
4911
+        $wrap = '</' . implode('></', $regs) . '>';
4912
+        $texte = $texte . $wrap;
4913
+    }
4914 4914
 
4915
-	return $texte;
4915
+    return $texte;
4916 4916
 }
4917 4917
 
4918 4918
 
@@ -4932,44 +4932,44 @@  discard block
 block discarded – undo
4932 4932
  * @return array|mixed|string
4933 4933
  */
4934 4934
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4935
-	if (is_string($u)) {
4936
-		$u = typo($u);
4935
+    if (is_string($u)) {
4936
+        $u = typo($u);
4937 4937
 
4938
-		return $u;
4939
-	}
4938
+        return $u;
4939
+    }
4940 4940
 
4941
-	// caster $u en array si besoin
4942
-	if (is_object($u)) {
4943
-		$u = (array)$u;
4944
-	}
4941
+    // caster $u en array si besoin
4942
+    if (is_object($u)) {
4943
+        $u = (array)$u;
4944
+    }
4945 4945
 
4946
-	if (is_array($u)) {
4947
-		$out = '';
4948
-		// toutes les cles sont numeriques ?
4949
-		// et aucun enfant n'est un tableau
4950
-		// liste simple separee par des virgules
4951
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4952
-		$array_values = array_map('is_array', $u);
4953
-		$object_values = array_map('is_object', $u);
4954
-		if (
4955
-			array_sum($numeric_keys) == count($numeric_keys)
4956
-			and !array_sum($array_values)
4957
-			and !array_sum($object_values)
4958
-		) {
4959
-			return join(', ', array_map('filtre_print_dist', $u));
4960
-		}
4946
+    if (is_array($u)) {
4947
+        $out = '';
4948
+        // toutes les cles sont numeriques ?
4949
+        // et aucun enfant n'est un tableau
4950
+        // liste simple separee par des virgules
4951
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4952
+        $array_values = array_map('is_array', $u);
4953
+        $object_values = array_map('is_object', $u);
4954
+        if (
4955
+            array_sum($numeric_keys) == count($numeric_keys)
4956
+            and !array_sum($array_values)
4957
+            and !array_sum($object_values)
4958
+        ) {
4959
+            return join(', ', array_map('filtre_print_dist', $u));
4960
+        }
4961 4961
 
4962
-		// sinon on passe a la ligne et on indente
4963
-		$i_str = str_pad('', $indent, ' ');
4964
-		foreach ($u as $k => $v) {
4965
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4966
-		}
4962
+        // sinon on passe a la ligne et on indente
4963
+        $i_str = str_pad('', $indent, ' ');
4964
+        foreach ($u as $k => $v) {
4965
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4966
+        }
4967 4967
 
4968
-		return $out;
4969
-	}
4968
+        return $out;
4969
+    }
4970 4970
 
4971
-	// on sait pas quoi faire...
4972
-	return $u;
4971
+    // on sait pas quoi faire...
4972
+    return $u;
4973 4973
 }
4974 4974
 
4975 4975
 
@@ -4982,10 +4982,10 @@  discard block
 block discarded – undo
4982 4982
  * @return string|array
4983 4983
  */
4984 4984
 function objet_info($objet, $info) {
4985
-	$table = table_objet_sql($objet);
4986
-	$infos = lister_tables_objets_sql($table);
4985
+    $table = table_objet_sql($objet);
4986
+    $infos = lister_tables_objets_sql($table);
4987 4987
 
4988
-	return (isset($infos[$info]) ? $infos[$info] : '');
4988
+    return (isset($infos[$info]) ? $infos[$info] : '');
4989 4989
 }
4990 4990
 
4991 4991
 /**
@@ -5000,11 +5000,11 @@  discard block
 block discarded – undo
5000 5000
  *     Texte traduit du comptage, tel que '3 articles'
5001 5001
  */
5002 5002
 function objet_afficher_nb($nb, $objet) {
5003
-	if (!$nb) {
5004
-		return _T(objet_info($objet, 'info_aucun_objet'));
5005
-	} else {
5006
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5007
-	}
5003
+    if (!$nb) {
5004
+        return _T(objet_info($objet, 'info_aucun_objet'));
5005
+    } else {
5006
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5007
+    }
5008 5008
 }
5009 5009
 
5010 5010
 /**
@@ -5016,11 +5016,11 @@  discard block
 block discarded – undo
5016 5016
  * @return string
5017 5017
  */
5018 5018
 function objet_icone($objet, $taille = 24, $class = '') {
5019
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5020
-	$icone = chemin_image($icone);
5021
-	$balise_img = charger_filtre('balise_img');
5019
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5020
+    $icone = chemin_image($icone);
5021
+    $balise_img = charger_filtre('balise_img');
5022 5022
 
5023
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5023
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5024 5024
 }
5025 5025
 
5026 5026
 /**
@@ -5041,12 +5041,12 @@  discard block
 block discarded – undo
5041 5041
  * @return string
5042 5042
  */
5043 5043
 function objet_T($objet, $chaine, $args = [], $options = []) {
5044
-	$chaine = explode(':', $chaine);
5045
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5046
-		return $t;
5047
-	}
5048
-	$chaine = implode(':', $chaine);
5049
-	return _T($chaine, $args, $options);
5044
+    $chaine = explode(':', $chaine);
5045
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5046
+        return $t;
5047
+    }
5048
+    $chaine = implode(':', $chaine);
5049
+    return _T($chaine, $args, $options);
5050 5050
 }
5051 5051
 
5052 5052
 /**
@@ -5060,18 +5060,18 @@  discard block
 block discarded – undo
5060 5060
  * @return string      Code HTML
5061 5061
  */
5062 5062
 function insert_head_css_conditionnel($flux) {
5063
-	if (
5064
-		strpos($flux, '<!-- insert_head_css -->') === false
5065
-		and $p = strpos($flux, '<!-- insert_head -->')
5066
-	) {
5067
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5068
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5069
-			$p = $p1;
5070
-		}
5071
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5072
-	}
5063
+    if (
5064
+        strpos($flux, '<!-- insert_head_css -->') === false
5065
+        and $p = strpos($flux, '<!-- insert_head -->')
5066
+    ) {
5067
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5068
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5069
+            $p = $p1;
5070
+        }
5071
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5072
+    }
5073 5073
 
5074
-	return $flux;
5074
+    return $flux;
5075 5075
 }
5076 5076
 
5077 5077
 /**
@@ -5094,72 +5094,72 @@  discard block
 block discarded – undo
5094 5094
  * @return string
5095 5095
  */
5096 5096
 function produire_fond_statique($fond, $contexte = [], $options = [], $connect = '') {
5097
-	if (isset($contexte['format'])) {
5098
-		$extension = $contexte['format'];
5099
-		unset($contexte['format']);
5100
-	} else {
5101
-		$extension = 'html';
5102
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5103
-			$extension = $m[1];
5104
-		}
5105
-	}
5106
-	// recuperer le contenu produit par le squelette
5107
-	$options['raw'] = true;
5108
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5109
-
5110
-	// calculer le nom de la css
5111
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5112
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5113
-	$contexte_implicite = calculer_contexte_implicite();
5114
-
5115
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5116
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5117
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5120
-	}
5121
-	else {
5122
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123
-		ksort($contexte);
5124
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5125
-	}
5126
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5127
-
5128
-	// mettre a jour le fichier si il n'existe pas
5129
-	// ou trop ancien
5130
-	// le dernier fichier produit est toujours suffixe par .last
5131
-	// et recopie sur le fichier cible uniquement si il change
5132
-	if (
5133
-		!file_exists($filename)
5134
-		or !file_exists($filename . '.last')
5135
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5136
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5137
-	) {
5138
-		$contenu = $cache['texte'];
5139
-		// passer les urls en absolu si c'est une css
5140
-		if ($extension == 'css') {
5141
-			$contenu = urls_absolues_css(
5142
-				$contenu,
5143
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5144
-			);
5145
-		}
5146
-
5147
-		$comment = '';
5148
-		// ne pas insérer de commentaire sur certains formats
5149
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5150
-			$comment = "/* #PRODUIRE{fond=$fond";
5151
-			foreach ($contexte as $k => $v) {
5152
-				$comment .= ",$k=$v";
5153
-			}
5154
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5155
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5156
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5157
-		}
5158
-		// et ecrire le fichier si il change
5159
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5160
-	}
5161
-
5162
-	return timestamp($filename);
5097
+    if (isset($contexte['format'])) {
5098
+        $extension = $contexte['format'];
5099
+        unset($contexte['format']);
5100
+    } else {
5101
+        $extension = 'html';
5102
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5103
+            $extension = $m[1];
5104
+        }
5105
+    }
5106
+    // recuperer le contenu produit par le squelette
5107
+    $options['raw'] = true;
5108
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5109
+
5110
+    // calculer le nom de la css
5111
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5112
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5113
+    $contexte_implicite = calculer_contexte_implicite();
5114
+
5115
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5116
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5117
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5118
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5119
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5120
+    }
5121
+    else {
5122
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5123
+        ksort($contexte);
5124
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5125
+    }
5126
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5127
+
5128
+    // mettre a jour le fichier si il n'existe pas
5129
+    // ou trop ancien
5130
+    // le dernier fichier produit est toujours suffixe par .last
5131
+    // et recopie sur le fichier cible uniquement si il change
5132
+    if (
5133
+        !file_exists($filename)
5134
+        or !file_exists($filename . '.last')
5135
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5136
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5137
+    ) {
5138
+        $contenu = $cache['texte'];
5139
+        // passer les urls en absolu si c'est une css
5140
+        if ($extension == 'css') {
5141
+            $contenu = urls_absolues_css(
5142
+                $contenu,
5143
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5144
+            );
5145
+        }
5146
+
5147
+        $comment = '';
5148
+        // ne pas insérer de commentaire sur certains formats
5149
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5150
+            $comment = "/* #PRODUIRE{fond=$fond";
5151
+            foreach ($contexte as $k => $v) {
5152
+                $comment .= ",$k=$v";
5153
+            }
5154
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5155
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5156
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5157
+        }
5158
+        // et ecrire le fichier si il change
5159
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5160
+    }
5161
+
5162
+    return timestamp($filename);
5163 5163
 }
5164 5164
 
5165 5165
 /**
@@ -5172,15 +5172,15 @@  discard block
 block discarded – undo
5172 5172
  *    $fichier auquel on a ajouté le timestamp
5173 5173
  */
5174 5174
 function timestamp($fichier) {
5175
-	if (
5176
-		!$fichier
5177
-		or !file_exists($fichier)
5178
-		or !$m = filemtime($fichier)
5179
-	) {
5180
-		return $fichier;
5181
-	}
5175
+    if (
5176
+        !$fichier
5177
+        or !file_exists($fichier)
5178
+        or !$m = filemtime($fichier)
5179
+    ) {
5180
+        return $fichier;
5181
+    }
5182 5182
 
5183
-	return "$fichier?$m";
5183
+    return "$fichier?$m";
5184 5184
 }
5185 5185
 
5186 5186
 /**
@@ -5190,11 +5190,11 @@  discard block
 block discarded – undo
5190 5190
  * @return string
5191 5191
  */
5192 5192
 function supprimer_timestamp($url) {
5193
-	if (strpos($url, '?') === false) {
5194
-		return $url;
5195
-	}
5193
+    if (strpos($url, '?') === false) {
5194
+        return $url;
5195
+    }
5196 5196
 
5197
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5197
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5198 5198
 }
5199 5199
 
5200 5200
 /**
@@ -5209,9 +5209,9 @@  discard block
 block discarded – undo
5209 5209
  * @return string
5210 5210
  */
5211 5211
 function filtre_nettoyer_titre_email_dist($titre) {
5212
-	include_spip('inc/envoyer_mail');
5212
+    include_spip('inc/envoyer_mail');
5213 5213
 
5214
-	return nettoyer_titre_email($titre);
5214
+    return nettoyer_titre_email($titre);
5215 5215
 }
5216 5216
 
5217 5217
 /**
@@ -5233,27 +5233,27 @@  discard block
 block discarded – undo
5233 5233
  * @return string
5234 5234
  */
5235 5235
 function filtre_chercher_rubrique_dist(
5236
-	$titre,
5237
-	$id_objet,
5238
-	$id_parent,
5239
-	$objet,
5240
-	$id_secteur,
5241
-	$restreint,
5242
-	$actionable = false,
5243
-	$retour_sans_cadre = false
5236
+    $titre,
5237
+    $id_objet,
5238
+    $id_parent,
5239
+    $objet,
5240
+    $id_secteur,
5241
+    $restreint,
5242
+    $actionable = false,
5243
+    $retour_sans_cadre = false
5244 5244
 ) {
5245
-	include_spip('inc/filtres_ecrire');
5245
+    include_spip('inc/filtres_ecrire');
5246 5246
 
5247
-	return chercher_rubrique(
5248
-		$titre,
5249
-		$id_objet,
5250
-		$id_parent,
5251
-		$objet,
5252
-		$id_secteur,
5253
-		$restreint,
5254
-		$actionable,
5255
-		$retour_sans_cadre
5256
-	);
5247
+    return chercher_rubrique(
5248
+        $titre,
5249
+        $id_objet,
5250
+        $id_parent,
5251
+        $objet,
5252
+        $id_secteur,
5253
+        $restreint,
5254
+        $actionable,
5255
+        $retour_sans_cadre
5256
+    );
5257 5257
 }
5258 5258
 
5259 5259
 /**
@@ -5282,56 +5282,56 @@  discard block
 block discarded – undo
5282 5282
  *     Chaîne vide si l'accès est autorisé
5283 5283
  */
5284 5284
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5285
-	if ($ok) {
5286
-		return '';
5287
-	}
5288
-
5289
-	// Vider tous les tampons
5290
-	$level = @ob_get_level();
5291
-	while ($level--) {
5292
-		@ob_end_clean();
5293
-	}
5294
-
5295
-	include_spip('inc/headers');
5296
-
5297
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5298
-	if ($url) {
5299
-		redirige_par_entete($url, '', $statut);
5300
-	}
5301
-
5302
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5303
-	if (!is_numeric($statut) and is_null($message)) {
5304
-		$message = $statut;
5305
-		$statut = 0;
5306
-	}
5307
-	if (!$message) {
5308
-		$message = '';
5309
-	}
5310
-	$statut = intval($statut);
5311
-
5312
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5313
-	if (test_espace_prive()) {
5314
-		if (!$statut or !in_array($statut, [404, 403])) {
5315
-			$statut = 403;
5316
-		}
5317
-		http_response_code(403);
5318
-		$echec = charger_fonction('403', 'exec');
5319
-		$echec($message);
5320
-	} else {
5321
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5322
-		if (!$statut) {
5323
-			$statut = 404;
5324
-		}
5325
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5326
-		http_response_code($statut);
5327
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5328
-		if ($statut >= 400) {
5329
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5330
-		}
5331
-	}
5332
-
5333
-
5334
-	exit;
5285
+    if ($ok) {
5286
+        return '';
5287
+    }
5288
+
5289
+    // Vider tous les tampons
5290
+    $level = @ob_get_level();
5291
+    while ($level--) {
5292
+        @ob_end_clean();
5293
+    }
5294
+
5295
+    include_spip('inc/headers');
5296
+
5297
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5298
+    if ($url) {
5299
+        redirige_par_entete($url, '', $statut);
5300
+    }
5301
+
5302
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5303
+    if (!is_numeric($statut) and is_null($message)) {
5304
+        $message = $statut;
5305
+        $statut = 0;
5306
+    }
5307
+    if (!$message) {
5308
+        $message = '';
5309
+    }
5310
+    $statut = intval($statut);
5311
+
5312
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5313
+    if (test_espace_prive()) {
5314
+        if (!$statut or !in_array($statut, [404, 403])) {
5315
+            $statut = 403;
5316
+        }
5317
+        http_response_code(403);
5318
+        $echec = charger_fonction('403', 'exec');
5319
+        $echec($message);
5320
+    } else {
5321
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5322
+        if (!$statut) {
5323
+            $statut = 404;
5324
+        }
5325
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5326
+        http_response_code($statut);
5327
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5328
+        if ($statut >= 400) {
5329
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5330
+        }
5331
+    }
5332
+
5333
+
5334
+    exit;
5335 5335
 }
5336 5336
 
5337 5337
 /**
@@ -5342,11 +5342,11 @@  discard block
 block discarded – undo
5342 5342
  * @return string
5343 5343
  */
5344 5344
 function filtre_compacte_dist($source, $format = null) {
5345
-	if (function_exists('compacte')) {
5346
-		return compacte($source, $format);
5347
-	}
5345
+    if (function_exists('compacte')) {
5346
+        return compacte($source, $format);
5347
+    }
5348 5348
 
5349
-	return $source;
5349
+    return $source;
5350 5350
 }
5351 5351
 
5352 5352
 
@@ -5358,31 +5358,31 @@  discard block
 block discarded – undo
5358 5358
  * @return string
5359 5359
  */
5360 5360
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5361
-	$l = strlen($passe);
5362
-
5363
-	if ($l <= 8 or !$afficher_partiellement) {
5364
-		if (!$l) {
5365
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5366
-		}
5367
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5368
-	}
5369
-
5370
-	if (is_null($portion_pourcent)) {
5371
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5372
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5373
-		}
5374
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5375
-	}
5376
-	if ($portion_pourcent >= 100) {
5377
-		return $passe;
5378
-	}
5379
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5380
-	$e = max($e, 0);
5381
-	$mid = str_pad('', $l - 2 * $e, '*');
5382
-	if ($e > 0 and strlen($mid) > 8) {
5383
-		$mid = '***...***';
5384
-	}
5385
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5361
+    $l = strlen($passe);
5362
+
5363
+    if ($l <= 8 or !$afficher_partiellement) {
5364
+        if (!$l) {
5365
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5366
+        }
5367
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5368
+    }
5369
+
5370
+    if (is_null($portion_pourcent)) {
5371
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5372
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5373
+        }
5374
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5375
+    }
5376
+    if ($portion_pourcent >= 100) {
5377
+        return $passe;
5378
+    }
5379
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5380
+    $e = max($e, 0);
5381
+    $mid = str_pad('', $l - 2 * $e, '*');
5382
+    if ($e > 0 and strlen($mid) > 8) {
5383
+        $mid = '***...***';
5384
+    }
5385
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5386 5386
 }
5387 5387
 
5388 5388
 
@@ -5403,64 +5403,64 @@  discard block
 block discarded – undo
5403 5403
  */
5404 5404
 function identifiant_slug($texte, $type = '', $options = []) {
5405 5405
 
5406
-	$original = $texte;
5407
-	$separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5408
-	$longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5409
-	$longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5406
+    $original = $texte;
5407
+    $separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5408
+    $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5409
+    $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5410 5410
 
5411
-	if (!function_exists('translitteration')) {
5412
-		include_spip('inc/charsets');
5413
-	}
5411
+    if (!function_exists('translitteration')) {
5412
+        include_spip('inc/charsets');
5413
+    }
5414 5414
 
5415
-	// pas de balise html
5416
-	if (strpos($texte, '<') !== false) {
5417
-		$texte = strip_tags($texte);
5418
-	}
5419
-	if (strpos($texte, '&') !== false) {
5420
-		$texte = unicode2charset($texte);
5421
-	}
5422
-	// On enlève les espaces indésirables
5423
-	$texte = trim($texte);
5415
+    // pas de balise html
5416
+    if (strpos($texte, '<') !== false) {
5417
+        $texte = strip_tags($texte);
5418
+    }
5419
+    if (strpos($texte, '&') !== false) {
5420
+        $texte = unicode2charset($texte);
5421
+    }
5422
+    // On enlève les espaces indésirables
5423
+    $texte = trim($texte);
5424 5424
 
5425
-	// On enlève les accents et cie
5426
-	$texte = translitteration($texte);
5425
+    // On enlève les accents et cie
5426
+    $texte = translitteration($texte);
5427 5427
 
5428
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5429
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5428
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5429
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5430 5430
 
5431
-	// nettoyer les doubles occurences du separateur si besoin
5432
-	while (strpos($texte, "$separateur$separateur") !== false) {
5433
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5434
-	}
5431
+    // nettoyer les doubles occurences du separateur si besoin
5432
+    while (strpos($texte, "$separateur$separateur") !== false) {
5433
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5434
+    }
5435 5435
 
5436
-	// pas de separateur au debut ni a la fin
5437
-	$texte = trim($texte, $separateur);
5436
+    // pas de separateur au debut ni a la fin
5437
+    $texte = trim($texte, $separateur);
5438 5438
 
5439
-	// en minuscules
5440
-	$texte = strtolower($texte);
5439
+    // en minuscules
5440
+    $texte = strtolower($texte);
5441 5441
 
5442
-	switch ($type) {
5443
-		case 'class':
5444
-		case 'id':
5445
-		case 'anchor':
5446
-			if (preg_match(',^\d,', $texte)) {
5447
-				$texte = substr($type, 0, 1) . $texte;
5448
-			}
5449
-	}
5442
+    switch ($type) {
5443
+        case 'class':
5444
+        case 'id':
5445
+        case 'anchor':
5446
+            if (preg_match(',^\d,', $texte)) {
5447
+                $texte = substr($type, 0, 1) . $texte;
5448
+            }
5449
+    }
5450 5450
 
5451
-	if (strlen($texte) > $longueur_maxi) {
5452
-		$texte = substr($texte, 0, $longueur_maxi);
5453
-	}
5451
+    if (strlen($texte) > $longueur_maxi) {
5452
+        $texte = substr($texte, 0, $longueur_maxi);
5453
+    }
5454 5454
 
5455
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5456
-		if (preg_match(',^\d,', $texte)) {
5457
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5458
-		}
5459
-		$texte .= $separateur . md5($original);
5460
-		$texte = substr($texte, 0, $longueur_mini);
5461
-	}
5455
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5456
+        if (preg_match(',^\d,', $texte)) {
5457
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5458
+        }
5459
+        $texte .= $separateur . md5($original);
5460
+        $texte = substr($texte, 0, $longueur_mini);
5461
+    }
5462 5462
 
5463
-	return $texte;
5463
+    return $texte;
5464 5464
 }
5465 5465
 
5466 5466
 
@@ -5481,14 +5481,14 @@  discard block
 block discarded – undo
5481 5481
  * @exemple `<:info_maximum|label_nettoyer:>`
5482 5482
  */
5483 5483
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5484
-	$label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5485
-	if ($label and $label[-1] === ';') {
5486
-		$label = preg_replace('#(\&nbsp;)+$#', '', $label);
5487
-	}
5488
-	if ($ucfirst) {
5489
-		$label = spip_ucfirst($label);
5490
-	}
5491
-	return $label;
5484
+    $label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5485
+    if ($label and $label[-1] === ';') {
5486
+        $label = preg_replace('#(\&nbsp;)+$#', '', $label);
5487
+    }
5488
+    if ($ucfirst) {
5489
+        $label = spip_ucfirst($label);
5490
+    }
5491
+    return $label;
5492 5492
 }
5493 5493
 
5494 5494
 /**
@@ -5501,8 +5501,8 @@  discard block
 block discarded – undo
5501 5501
  * @exemple `<:info_maximum|label_ponctuer:>`
5502 5502
  */
5503 5503
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5504
-	$label = label_nettoyer($text, $ucfirst);
5505
-	return _T('label_ponctuer', ['label' => $label]);
5504
+    $label = label_nettoyer($text, $ucfirst);
5505
+    return _T('label_ponctuer', ['label' => $label]);
5506 5506
 }
5507 5507
 
5508 5508
 
@@ -5515,19 +5515,19 @@  discard block
 block discarded – undo
5515 5515
  * @return array
5516 5516
  */
5517 5517
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5518
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5519
-		return [];
5520
-	}
5518
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5519
+        return [];
5520
+    }
5521 5521
 
5522
-	// compatibilite signature inversee
5523
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5524
-		list($objet, $id_objet) = [$id_objet, $objet];
5525
-	}
5522
+    // compatibilite signature inversee
5523
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5524
+        list($objet, $id_objet) = [$id_objet, $objet];
5525
+    }
5526 5526
 
5527
-	if (!function_exists($fonction)) {
5528
-		include_spip('base/objets');
5529
-	}
5530
-	return $fonction($objet, $id_objet);
5527
+    if (!function_exists($fonction)) {
5528
+        include_spip('base/objets');
5529
+    }
5530
+    return $fonction($objet, $id_objet);
5531 5531
 }
5532 5532
 
5533 5533
 
@@ -5542,7 +5542,7 @@  discard block
 block discarded – undo
5542 5542
  * @return array
5543 5543
  */
5544 5544
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5545
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5545
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5546 5546
 }
5547 5547
 
5548 5548
 /**
@@ -5556,7 +5556,7 @@  discard block
 block discarded – undo
5556 5556
  * @return array
5557 5557
  */
5558 5558
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5559
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5559
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5560 5560
 }
5561 5561
 
5562 5562
 /**
@@ -5570,7 +5570,7 @@  discard block
 block discarded – undo
5570 5570
  * @return array
5571 5571
  */
5572 5572
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5573
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5573
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5574 5574
 }
5575 5575
 
5576 5576
 /**
@@ -5584,5 +5584,5 @@  discard block
 block discarded – undo
5584 5584
  * @return array
5585 5585
  */
5586 5586
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5587
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5587
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5588 5588
 }
Please login to merge, or discard this patch.
ecrire/inc/flock.php 1 patch
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_TEST_FILE_EXISTS')) {
24
-	/** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
-	define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : ''));
24
+    /** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
+    define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : ''));
26 26
 }
27 27
 
28 28
 #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille)
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
31 31
 
32 32
 if (_SPIP_LOCK_MODE == 2) {
33
-	include_spip('inc/nfslock');
33
+    include_spip('inc/nfslock');
34 34
 }
35 35
 
36 36
 $GLOBALS['liste_verrous'] = [];
@@ -53,24 +53,24 @@  discard block
 block discarded – undo
53 53
  *     Ressource sur le fichier ouvert, sinon false.
54 54
  **/
55 55
 function spip_fopen_lock($fichier, $mode, $verrou) {
56
-	if (_SPIP_LOCK_MODE == 1) {
57
-		if ($fl = @fopen($fichier, $mode)) {
58
-			// verrou
59
-			@flock($fl, $verrou);
60
-		}
61
-
62
-		return $fl;
63
-	} elseif (_SPIP_LOCK_MODE == 2) {
64
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
-			$GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou];
66
-
67
-			return $fl;
68
-		} else {
69
-			return false;
70
-		}
71
-	}
72
-
73
-	return @fopen($fichier, $mode);
56
+    if (_SPIP_LOCK_MODE == 1) {
57
+        if ($fl = @fopen($fichier, $mode)) {
58
+            // verrou
59
+            @flock($fl, $verrou);
60
+        }
61
+
62
+        return $fl;
63
+    } elseif (_SPIP_LOCK_MODE == 2) {
64
+        if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
+            $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou];
66
+
67
+            return $fl;
68
+        } else {
69
+            return false;
70
+        }
71
+    }
72
+
73
+    return @fopen($fichier, $mode);
74 74
 }
75 75
 
76 76
 /**
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
  *     true si succès, false sinon.
86 86
  **/
87 87
 function spip_fclose_unlock($handle) {
88
-	if (_SPIP_LOCK_MODE == 1) {
89
-		@flock($handle, LOCK_UN);
90
-	} elseif (_SPIP_LOCK_MODE == 2) {
91
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
-		unset($GLOBALS['liste_verrous'][$handle]);
93
-	}
94
-
95
-	return @fclose($handle);
88
+    if (_SPIP_LOCK_MODE == 1) {
89
+        @flock($handle, LOCK_UN);
90
+    } elseif (_SPIP_LOCK_MODE == 2) {
91
+        spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
+        unset($GLOBALS['liste_verrous'][$handle]);
93
+    }
94
+
95
+    return @fclose($handle);
96 96
 }
97 97
 
98 98
 
@@ -106,23 +106,23 @@  discard block
 block discarded – undo
106 106
  *     Contenu du fichier
107 107
  **/
108 108
 function spip_file_get_contents($fichier) {
109
-	if (substr($fichier, -3) != '.gz') {
110
-		if (function_exists('file_get_contents')) {
111
-			// quand on est sous windows on ne sait pas si file_get_contents marche
112
-			// on essaye : si ca retourne du contenu alors c'est bon
113
-			// sinon on fait un file() pour avoir le coeur net
114
-			$contenu = @file_get_contents($fichier);
115
-			if (!$contenu and _OS_SERVEUR == 'windows') {
116
-				$contenu = @file($fichier);
117
-			}
118
-		} else {
119
-			$contenu = @file($fichier);
120
-		}
121
-	} else {
122
-		$contenu = @gzfile($fichier);
123
-	}
124
-
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
109
+    if (substr($fichier, -3) != '.gz') {
110
+        if (function_exists('file_get_contents')) {
111
+            // quand on est sous windows on ne sait pas si file_get_contents marche
112
+            // on essaye : si ca retourne du contenu alors c'est bon
113
+            // sinon on fait un file() pour avoir le coeur net
114
+            $contenu = @file_get_contents($fichier);
115
+            if (!$contenu and _OS_SERVEUR == 'windows') {
116
+                $contenu = @file($fichier);
117
+            }
118
+        } else {
119
+            $contenu = @file($fichier);
120
+        }
121
+    } else {
122
+        $contenu = @gzfile($fichier);
123
+    }
124
+
125
+    return is_array($contenu) ? join('', $contenu) : (string)$contenu;
126 126
 }
127 127
 
128 128
 
@@ -147,48 +147,48 @@  discard block
 block discarded – undo
147 147
  *     true si l'opération a réussie, false sinon.
148 148
  **/
149 149
 function lire_fichier($fichier, &$contenu, $options = []) {
150
-	$contenu = '';
151
-	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
-	// economisons donc les acces disque, sauf chez free qui rale pour un rien
153
-	if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
-		return false;
155
-	}
156
-
157
-	#spip_timer('lire_fichier');
158
-
159
-	// pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
-	if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
-		// lire le fichier avant tout
162
-		$contenu = spip_file_get_contents($fichier);
163
-
164
-		// le fichier a-t-il ete supprime par le locker ?
165
-		// on ne verifie que si la tentative de lecture a echoue
166
-		// pour discriminer un contenu vide d'un fichier absent
167
-		// et eviter un acces disque
168
-		if (!$contenu and !@file_exists($fichier)) {
169
-			spip_fclose_unlock($fl);
170
-
171
-			return false;
172
-		}
173
-
174
-		// liberer le verrou
175
-		spip_fclose_unlock($fl);
176
-
177
-		// Verifications
178
-		$ok = true;
179
-		if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
181
-		}
182
-
183
-		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
-		if (!$ok) {
185
-			spip_log("echec lecture $fichier");
186
-		}
187
-
188
-		return $ok;
189
-	}
190
-
191
-	return false;
150
+    $contenu = '';
151
+    // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
+    // economisons donc les acces disque, sauf chez free qui rale pour un rien
153
+    if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
+        return false;
155
+    }
156
+
157
+    #spip_timer('lire_fichier');
158
+
159
+    // pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
+    if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
+        // lire le fichier avant tout
162
+        $contenu = spip_file_get_contents($fichier);
163
+
164
+        // le fichier a-t-il ete supprime par le locker ?
165
+        // on ne verifie que si la tentative de lecture a echoue
166
+        // pour discriminer un contenu vide d'un fichier absent
167
+        // et eviter un acces disque
168
+        if (!$contenu and !@file_exists($fichier)) {
169
+            spip_fclose_unlock($fl);
170
+
171
+            return false;
172
+        }
173
+
174
+        // liberer le verrou
175
+        spip_fclose_unlock($fl);
176
+
177
+        // Verifications
178
+        $ok = true;
179
+        if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
+            $ok &= (preg_match(",[?]>\n?$,", $contenu));
181
+        }
182
+
183
+        #spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
+        if (!$ok) {
185
+            spip_log("echec lecture $fichier");
186
+        }
187
+
188
+        return $ok;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 
@@ -216,85 +216,85 @@  discard block
 block discarded – undo
216 216
  **/
217 217
 function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) {
218 218
 
219
-	#spip_timer('ecrire_fichier');
220
-
221
-	// verrouiller le fichier destination
222
-	if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
-		// ecrire les donnees, compressees le cas echeant
224
-		// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
-		// de le recreer si le locker qui nous precede l'avait supprime...)
226
-		if (substr($fichier, -3) == '.gz') {
227
-			$contenu = gzencode($contenu);
228
-		}
229
-		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
-		// pour etre sur d'avoir une operation atomique
231
-		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
-		// sauf sous wintruc ou ca ne marche pas
233
-		$ok = false;
234
-		if ($truncate and _OS_SERVEUR != 'windows') {
235
-			if (!function_exists('creer_uniqid')) {
236
-				include_spip('inc/acces');
237
-			}
238
-			$id = creer_uniqid();
239
-			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
-				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
-				$ok = ($s == $a);
243
-				spip_fclose_unlock($fp2);
244
-				spip_fclose_unlock($fp);
245
-				// unlink direct et pas spip_unlink car on avait deja le verrou
246
-				// a priori pas besoin car rename ecrase la cible
247
-				// @unlink($fichier);
248
-				// le rename aussitot, atomique quand on est pas sous windows
249
-				// au pire on arrive en second en cas de concourance, et le rename echoue
250
-				// --> on a la version de l'autre process qui doit etre identique
251
-				@rename("$fichier.$id", $fichier);
252
-				// precaution en cas d'echec du rename
253
-				if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
-					@unlink("$fichier.$id");
255
-				}
256
-				if ($ok) {
257
-					$ok = file_exists($fichier);
258
-				}
259
-			} else // echec mais penser a fermer ..
260
-			{
261
-				spip_fclose_unlock($fp);
262
-			}
263
-		}
264
-		// sinon ou si methode precedente a echoueee
265
-		// on se rabat sur la methode ancienne
266
-		if (!$ok) {
267
-			// ici on est en ajout ou sous windows, cas desespere
268
-			if ($truncate) {
269
-				@ftruncate($fp, 0);
270
-			}
271
-			$s = @fputs($fp, $contenu, $a = strlen($contenu));
272
-
273
-			$ok = ($s == $a);
274
-			spip_fclose_unlock($fp);
275
-		}
276
-
277
-		// liberer le verrou et fermer le fichier
278
-		@chmod($fichier, _SPIP_CHMOD & 0666);
279
-		if ($ok) {
280
-			if (strpos($fichier, '.php') !== false) {
281
-				spip_clear_opcode_cache(realpath($fichier));
282
-			}
283
-
284
-			return $ok;
285
-		}
286
-	}
287
-
288
-	if (!$ignorer_echec) {
289
-		include_spip('inc/autoriser');
290
-		if (autoriser('chargerftp')) {
291
-			raler_fichier($fichier);
292
-		}
293
-		spip_unlink($fichier);
294
-	}
295
-	spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
-
297
-	return false;
219
+    #spip_timer('ecrire_fichier');
220
+
221
+    // verrouiller le fichier destination
222
+    if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
+        // ecrire les donnees, compressees le cas echeant
224
+        // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
+        // de le recreer si le locker qui nous precede l'avait supprime...)
226
+        if (substr($fichier, -3) == '.gz') {
227
+            $contenu = gzencode($contenu);
228
+        }
229
+        // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
+        // pour etre sur d'avoir une operation atomique
231
+        // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
+        // sauf sous wintruc ou ca ne marche pas
233
+        $ok = false;
234
+        if ($truncate and _OS_SERVEUR != 'windows') {
235
+            if (!function_exists('creer_uniqid')) {
236
+                include_spip('inc/acces');
237
+            }
238
+            $id = creer_uniqid();
239
+            // on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
+            if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
+                $s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
+                $ok = ($s == $a);
243
+                spip_fclose_unlock($fp2);
244
+                spip_fclose_unlock($fp);
245
+                // unlink direct et pas spip_unlink car on avait deja le verrou
246
+                // a priori pas besoin car rename ecrase la cible
247
+                // @unlink($fichier);
248
+                // le rename aussitot, atomique quand on est pas sous windows
249
+                // au pire on arrive en second en cas de concourance, et le rename echoue
250
+                // --> on a la version de l'autre process qui doit etre identique
251
+                @rename("$fichier.$id", $fichier);
252
+                // precaution en cas d'echec du rename
253
+                if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
+                    @unlink("$fichier.$id");
255
+                }
256
+                if ($ok) {
257
+                    $ok = file_exists($fichier);
258
+                }
259
+            } else // echec mais penser a fermer ..
260
+            {
261
+                spip_fclose_unlock($fp);
262
+            }
263
+        }
264
+        // sinon ou si methode precedente a echoueee
265
+        // on se rabat sur la methode ancienne
266
+        if (!$ok) {
267
+            // ici on est en ajout ou sous windows, cas desespere
268
+            if ($truncate) {
269
+                @ftruncate($fp, 0);
270
+            }
271
+            $s = @fputs($fp, $contenu, $a = strlen($contenu));
272
+
273
+            $ok = ($s == $a);
274
+            spip_fclose_unlock($fp);
275
+        }
276
+
277
+        // liberer le verrou et fermer le fichier
278
+        @chmod($fichier, _SPIP_CHMOD & 0666);
279
+        if ($ok) {
280
+            if (strpos($fichier, '.php') !== false) {
281
+                spip_clear_opcode_cache(realpath($fichier));
282
+            }
283
+
284
+            return $ok;
285
+        }
286
+    }
287
+
288
+    if (!$ignorer_echec) {
289
+        include_spip('inc/autoriser');
290
+        if (autoriser('chargerftp')) {
291
+            raler_fichier($fichier);
292
+        }
293
+        spip_unlink($fichier);
294
+    }
295
+    spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
+
297
+    return false;
298 298
 }
299 299
 
300 300
 /**
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
314 314
  *     Écriture avec troncation ?
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317
-	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
-	}
320
-	$contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
317
+    if (substr($fichier, -4) !== '.php') {
318
+        spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
+    }
320
+    $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
321 321
 
322
-	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
322
+    return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
324 324
 
325 325
 
@@ -330,25 +330,25 @@  discard block
 block discarded – undo
330 330
  * @return bool
331 331
  */
332 332
 function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) {
333
-	$fichier_tmp = $fichier . '.last';
334
-	if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335
-		return false;
336
-	}
337
-	if (
338
-		$force
339
-		or !file_exists($fichier)
340
-		or md5_file($fichier) != md5_file($fichier_tmp)
341
-	) {
342
-		if ($use_copy) {
343
-			@copy($fichier_tmp, $fichier);
344
-		}
345
-		else {
346
-			@rename($fichier_tmp, $fichier);
347
-		}
348
-		// eviter que PHP ne reserve le vieux timestamp
349
-		clearstatcache(true, $fichier);
350
-	}
351
-	return true;
333
+    $fichier_tmp = $fichier . '.last';
334
+    if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335
+        return false;
336
+    }
337
+    if (
338
+        $force
339
+        or !file_exists($fichier)
340
+        or md5_file($fichier) != md5_file($fichier_tmp)
341
+    ) {
342
+        if ($use_copy) {
343
+            @copy($fichier_tmp, $fichier);
344
+        }
345
+        else {
346
+            @rename($fichier_tmp, $fichier);
347
+        }
348
+        // eviter que PHP ne reserve le vieux timestamp
349
+        clearstatcache(true, $fichier);
350
+    }
351
+    return true;
352 352
 }
353 353
 
354 354
 
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
  *     true si l'opération a réussie, false sinon.
370 370
  */
371 371
 function lire_fichier_securise($fichier, &$contenu, $options = []) {
372
-	if ($res = lire_fichier($fichier, $contenu, $options)) {
373
-		$contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
-	}
372
+    if ($res = lire_fichier($fichier, $contenu, $options)) {
373
+        $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
+    }
375 375
 
376
-	return $res;
376
+    return $res;
377 377
 }
378 378
 
379 379
 /**
@@ -388,22 +388,22 @@  discard block
 block discarded – undo
388 388
  *     Chemin du fichier
389 389
  **/
390 390
 function raler_fichier($fichier) {
391
-	include_spip('inc/minipres');
392
-	$dir = dirname($fichier);
393
-	http_response_code(401);
394
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
395
-		. _T('texte_inc_meta_1', ['fichier' => $fichier])
396
-		. " <a href='"
397
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
398
-		. "'>"
399
-		. _T('texte_inc_meta_2')
400
-		. '</a> '
401
-		. _T(
402
-			'texte_inc_meta_3',
403
-			['repertoire' => joli_repertoire($dir)]
404
-		)
405
-		. "</h4>\n");
406
-	exit;
391
+    include_spip('inc/minipres');
392
+    $dir = dirname($fichier);
393
+    http_response_code(401);
394
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
395
+        . _T('texte_inc_meta_1', ['fichier' => $fichier])
396
+        . " <a href='"
397
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
398
+        . "'>"
399
+        . _T('texte_inc_meta_2')
400
+        . '</a> '
401
+        . _T(
402
+            'texte_inc_meta_3',
403
+            ['repertoire' => joli_repertoire($dir)]
404
+        )
405
+        . "</h4>\n");
406
+    exit;
407 407
 }
408 408
 
409 409
 
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
  *     - true si récent, false sinon
419 419
  */
420 420
 function jeune_fichier($fichier, $n) {
421
-	if (!file_exists($fichier)) {
422
-		return false;
423
-	}
424
-	if (!$c = @filemtime($fichier)) {
425
-		return false;
426
-	}
427
-
428
-	return (time() - $n <= $c);
421
+    if (!file_exists($fichier)) {
422
+        return false;
423
+    }
424
+    if (!$c = @filemtime($fichier)) {
425
+        return false;
426
+    }
427
+
428
+    return (time() - $n <= $c);
429 429
 }
430 430
 
431 431
 /**
@@ -440,22 +440,22 @@  discard block
 block discarded – undo
440 440
  *     - false si on n'arrive pas poser le verrou ou si la suppression échoue
441 441
  */
442 442
 function supprimer_fichier($fichier, $lock = true) {
443
-	if (!@file_exists($fichier)) {
444
-		return true;
445
-	}
446
-
447
-	if ($lock) {
448
-		// verrouiller le fichier destination
449
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
450
-			return false;
451
-		}
452
-
453
-		// liberer le verrou
454
-		spip_fclose_unlock($fp);
455
-	}
456
-
457
-	// supprimer
458
-	return @unlink($fichier);
443
+    if (!@file_exists($fichier)) {
444
+        return true;
445
+    }
446
+
447
+    if ($lock) {
448
+        // verrouiller le fichier destination
449
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
450
+            return false;
451
+        }
452
+
453
+        // liberer le verrou
454
+        spip_fclose_unlock($fp);
455
+    }
456
+
457
+    // supprimer
458
+    return @unlink($fichier);
459 459
 }
460 460
 
461 461
 /**
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
  *     Chemin du fichier
466 466
  */
467 467
 function spip_unlink($f) {
468
-	if (!is_dir($f)) {
469
-		supprimer_fichier($f, false);
470
-	} else {
471
-		@unlink("$f/.ok");
472
-		@rmdir($f);
473
-	}
468
+    if (!is_dir($f)) {
469
+        supprimer_fichier($f, false);
470
+    } else {
471
+        @unlink("$f/.ok");
472
+        @rmdir($f);
473
+    }
474 474
 }
475 475
 
476 476
 /**
@@ -484,26 +484,26 @@  discard block
 block discarded – undo
484 484
  *   The absolute path of the PHP file to invalidate.
485 485
  */
486 486
 function spip_clear_opcode_cache($filepath) {
487
-	clearstatcache(true, $filepath);
488
-
489
-	// Zend OPcache
490
-	if (function_exists('opcache_invalidate')) {
491
-		$invalidate = @opcache_invalidate($filepath, true);
492
-		// si l'invalidation a echoue lever un flag
493
-		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
494
-			define('_spip_attend_invalidation_opcode_cache', true);
495
-		}
496
-	} elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
497
-		// n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
498
-		define('_spip_attend_invalidation_opcode_cache', true);
499
-	}
500
-	// APC.
501
-	if (function_exists('apc_delete_file')) {
502
-		// apc_delete_file() throws a PHP warning in case the specified file was
503
-		// not compiled yet.
504
-		// @see http://php.net/apc-delete-file
505
-		@apc_delete_file($filepath);
506
-	}
487
+    clearstatcache(true, $filepath);
488
+
489
+    // Zend OPcache
490
+    if (function_exists('opcache_invalidate')) {
491
+        $invalidate = @opcache_invalidate($filepath, true);
492
+        // si l'invalidation a echoue lever un flag
493
+        if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
494
+            define('_spip_attend_invalidation_opcode_cache', true);
495
+        }
496
+    } elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
497
+        // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
498
+        define('_spip_attend_invalidation_opcode_cache', true);
499
+    }
500
+    // APC.
501
+    if (function_exists('apc_delete_file')) {
502
+        // apc_delete_file() throws a PHP warning in case the specified file was
503
+        // not compiled yet.
504
+        // @see http://php.net/apc-delete-file
505
+        @apc_delete_file($filepath);
506
+    }
507 507
 }
508 508
 
509 509
 /**
@@ -526,25 +526,25 @@  discard block
 block discarded – undo
526 526
  *
527 527
  */
528 528
 function spip_attend_invalidation_opcode_cache($timestamp = null) {
529
-	if (
530
-		function_exists('opcache_get_configuration')
531
-		and @ini_get('opcache.enable')
532
-		and @ini_get('opcache.validate_timestamps')
533
-		and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
534
-		and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
535
-	) {
536
-		$wait = $duree + 1;
537
-		if ($timestamp) {
538
-			$wait -= (time() - $timestamp);
539
-			if ($wait < 0) {
540
-				$wait = 0;
541
-			}
542
-		}
543
-		spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
544
-		if ($wait) {
545
-			sleep($duree + 1);
546
-		}
547
-	}
529
+    if (
530
+        function_exists('opcache_get_configuration')
531
+        and @ini_get('opcache.enable')
532
+        and @ini_get('opcache.validate_timestamps')
533
+        and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
534
+        and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
535
+    ) {
536
+        $wait = $duree + 1;
537
+        if ($timestamp) {
538
+            $wait -= (time() - $timestamp);
539
+            if ($wait < 0) {
540
+                $wait = 0;
541
+            }
542
+        }
543
+        spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
544
+        if ($wait) {
545
+            sleep($duree + 1);
546
+        }
547
+    }
548 548
 }
549 549
 
550 550
 
@@ -557,26 +557,26 @@  discard block
 block discarded – undo
557 557
  * @return bool Suppression reussie.
558 558
  */
559 559
 function supprimer_repertoire($dir) {
560
-	if (!file_exists($dir)) {
561
-		return true;
562
-	}
563
-	if (!is_dir($dir) || is_link($dir)) {
564
-		return @unlink($dir);
565
-	}
566
-
567
-	foreach (scandir($dir) as $item) {
568
-		if ($item == '.' || $item == '..') {
569
-			continue;
570
-		}
571
-		if (!supprimer_repertoire($dir . '/' . $item)) {
572
-			@chmod($dir . '/' . $item, 0777);
573
-			if (!supprimer_repertoire($dir . '/' . $item)) {
574
-				return false;
575
-			}
576
-		};
577
-	}
578
-
579
-	return @rmdir($dir);
560
+    if (!file_exists($dir)) {
561
+        return true;
562
+    }
563
+    if (!is_dir($dir) || is_link($dir)) {
564
+        return @unlink($dir);
565
+    }
566
+
567
+    foreach (scandir($dir) as $item) {
568
+        if ($item == '.' || $item == '..') {
569
+            continue;
570
+        }
571
+        if (!supprimer_repertoire($dir . '/' . $item)) {
572
+            @chmod($dir . '/' . $item, 0777);
573
+            if (!supprimer_repertoire($dir . '/' . $item)) {
574
+                return false;
575
+            }
576
+        };
577
+    }
578
+
579
+    return @rmdir($dir);
580 580
 }
581 581
 
582 582
 
@@ -605,57 +605,57 @@  discard block
 block discarded – undo
605 605
  *     Chemin du répertoire créé.
606 606
  **/
607 607
 function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
608
-	static $dirs = [];
609
-
610
-	$base = str_replace('//', '/', $base);
611
-
612
-	# suppr le dernier caractere si c'est un /
613
-	$base = rtrim($base, '/');
614
-
615
-	if (!strlen($subdir)) {
616
-		$n = strrpos($base, '/');
617
-		if ($n === false) {
618
-			return $nobase ? '' : ($base . '/');
619
-		}
620
-		$subdir = substr($base, $n + 1);
621
-		$base = substr($base, 0, $n + 1);
622
-	} else {
623
-		$base .= '/';
624
-		$subdir = str_replace('/', '', $subdir);
625
-	}
626
-
627
-	$baseaff = $nobase ? '' : $base;
628
-	if (isset($dirs[$base . $subdir])) {
629
-		return $baseaff . $dirs[$base . $subdir];
630
-	}
631
-
632
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
633
-
634
-	if (file_exists("$path/.ok")) {
635
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
636
-	}
637
-
638
-	@mkdir($path, _SPIP_CHMOD);
639
-	@chmod($path, _SPIP_CHMOD);
640
-
641
-	if (is_dir($path) && is_writable($path)) {
642
-		@touch("$path/.ok");
643
-		spip_log("creation $base$subdir/");
644
-
645
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
646
-	}
647
-
648
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
649
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
650
-	spip_log("echec creation $base${subdir}");
651
-	if ($tantpis) {
652
-		return '';
653
-	}
654
-	if (!_DIR_RESTREINT) {
655
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
656
-	}
657
-	$base .= $subdir;
658
-	raler_fichier($base . '/.ok');
608
+    static $dirs = [];
609
+
610
+    $base = str_replace('//', '/', $base);
611
+
612
+    # suppr le dernier caractere si c'est un /
613
+    $base = rtrim($base, '/');
614
+
615
+    if (!strlen($subdir)) {
616
+        $n = strrpos($base, '/');
617
+        if ($n === false) {
618
+            return $nobase ? '' : ($base . '/');
619
+        }
620
+        $subdir = substr($base, $n + 1);
621
+        $base = substr($base, 0, $n + 1);
622
+    } else {
623
+        $base .= '/';
624
+        $subdir = str_replace('/', '', $subdir);
625
+    }
626
+
627
+    $baseaff = $nobase ? '' : $base;
628
+    if (isset($dirs[$base . $subdir])) {
629
+        return $baseaff . $dirs[$base . $subdir];
630
+    }
631
+
632
+    $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
633
+
634
+    if (file_exists("$path/.ok")) {
635
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
636
+    }
637
+
638
+    @mkdir($path, _SPIP_CHMOD);
639
+    @chmod($path, _SPIP_CHMOD);
640
+
641
+    if (is_dir($path) && is_writable($path)) {
642
+        @touch("$path/.ok");
643
+        spip_log("creation $base$subdir/");
644
+
645
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
646
+    }
647
+
648
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
649
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
650
+    spip_log("echec creation $base${subdir}");
651
+    if ($tantpis) {
652
+        return '';
653
+    }
654
+    if (!_DIR_RESTREINT) {
655
+        $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
656
+    }
657
+    $base .= $subdir;
658
+    raler_fichier($base . '/.ok');
659 659
 }
660 660
 
661 661
 
@@ -688,56 +688,56 @@  discard block
 block discarded – undo
688 688
  *     Chemins des fichiers trouvés.
689 689
  **/
690 690
 function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) {
691
-	$nbfiles = 0;
692
-	if ($pattern == -1) {
693
-		$pattern = "^$dir";
694
-	}
695
-	$fichiers = [];
696
-	// revenir au repertoire racine si on a recu dossier/truc
697
-	// pour regarder dossier/truc/ ne pas oublier le / final
698
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
699
-	if ($dir == '') {
700
-		$dir = '.';
701
-	}
702
-
703
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
704
-		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
705
-			if (
706
-				$f[0] != '.' # ignorer . .. .svn etc
707
-				and $f != 'CVS'
708
-				and $f != 'remove.txt'
709
-				and is_readable($f = "$dir/$f")
710
-			) {
711
-				if (is_file($f)) {
712
-					if (preg_match(";$pattern;iS", $f)) {
713
-						$fichiers[] = $f;
714
-						$nbfiles++;
715
-					}
716
-				} else {
717
-					if (is_dir($f) and is_array($recurs)) {
718
-						$rp = @realpath($f);
719
-						if (!is_string($rp) or !strlen($rp)) {
720
-							$rp = $f;
721
-						} # realpath n'est peut etre pas autorise
722
-						if (!isset($recurs[$rp])) {
723
-							$recurs[$rp] = true;
724
-							$beginning = $fichiers;
725
-							$end = preg_files(
726
-								"$f/",
727
-								$pattern,
728
-								$maxfiles - $nbfiles,
729
-								$recurs
730
-							);
731
-							$fichiers = array_merge((array)$beginning, (array)$end);
732
-							$nbfiles = count($fichiers);
733
-						}
734
-					}
735
-				}
736
-			}
737
-		}
738
-		closedir($d);
739
-	}
740
-	sort($fichiers);
741
-
742
-	return $fichiers;
691
+    $nbfiles = 0;
692
+    if ($pattern == -1) {
693
+        $pattern = "^$dir";
694
+    }
695
+    $fichiers = [];
696
+    // revenir au repertoire racine si on a recu dossier/truc
697
+    // pour regarder dossier/truc/ ne pas oublier le / final
698
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
699
+    if ($dir == '') {
700
+        $dir = '.';
701
+    }
702
+
703
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
704
+        while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
705
+            if (
706
+                $f[0] != '.' # ignorer . .. .svn etc
707
+                and $f != 'CVS'
708
+                and $f != 'remove.txt'
709
+                and is_readable($f = "$dir/$f")
710
+            ) {
711
+                if (is_file($f)) {
712
+                    if (preg_match(";$pattern;iS", $f)) {
713
+                        $fichiers[] = $f;
714
+                        $nbfiles++;
715
+                    }
716
+                } else {
717
+                    if (is_dir($f) and is_array($recurs)) {
718
+                        $rp = @realpath($f);
719
+                        if (!is_string($rp) or !strlen($rp)) {
720
+                            $rp = $f;
721
+                        } # realpath n'est peut etre pas autorise
722
+                        if (!isset($recurs[$rp])) {
723
+                            $recurs[$rp] = true;
724
+                            $beginning = $fichiers;
725
+                            $end = preg_files(
726
+                                "$f/",
727
+                                $pattern,
728
+                                $maxfiles - $nbfiles,
729
+                                $recurs
730
+                            );
731
+                            $fichiers = array_merge((array)$beginning, (array)$end);
732
+                            $nbfiles = count($fichiers);
733
+                        }
734
+                    }
735
+                }
736
+            }
737
+        }
738
+        closedir($d);
739
+    }
740
+    sort($fichiers);
741
+
742
+    return $fichiers;
743 743
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2224 added lines, -2225 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,66 +48,66 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = [];
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
83
-		// si le fichier truc/machin/nom.php n'existe pas,
84
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
-	) {
87
-		include_spip(substr($dossier, 0, -1));
88
-	}
89
-	if (function_exists($f)) {
90
-		return $f;
91
-	}
92
-	if (function_exists($g)) {
93
-		return $g;
94
-	}
95
-
96
-	if ($continue) {
97
-		return $echecs[$f] = false;
98
-	}
99
-
100
-	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
102
-		($inc ? '' : " (fichier $d absent de $dossier)"));
103
-
104
-	include_spip('inc/minipres');
105
-	echo minipres(
106
-		_T('forum_titre_erreur'),
107
-		_T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
-		['all_inline' => true,'status' => 404]
109
-	);
110
-	exit;
51
+    static $echecs = [];
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (
82
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
83
+        // si le fichier truc/machin/nom.php n'existe pas,
84
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
+    ) {
87
+        include_spip(substr($dossier, 0, -1));
88
+    }
89
+    if (function_exists($f)) {
90
+        return $f;
91
+    }
92
+    if (function_exists($g)) {
93
+        return $g;
94
+    }
95
+
96
+    if ($continue) {
97
+        return $echecs[$f] = false;
98
+    }
99
+
100
+    // Echec : message d'erreur
101
+    spip_log("fonction $nom ($f ou $g) indisponible" .
102
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
103
+
104
+    include_spip('inc/minipres');
105
+    echo minipres(
106
+        _T('forum_titre_erreur'),
107
+        _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
+        ['all_inline' => true,'status' => 404]
109
+    );
110
+    exit;
111 111
 }
112 112
 
113 113
 /**
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
  * @return bool
118 118
  */
119 119
 function include_once_check($file) {
120
-	if (file_exists($file)) {
121
-		include_once $file;
120
+    if (file_exists($file)) {
121
+        include_once $file;
122 122
 
123
-		return true;
124
-	}
125
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
-	$crash = ($crash ? $crash : []);
127
-	$crash[$file] = true;
128
-	ecrire_meta('message_crash_plugins', serialize($crash));
123
+        return true;
124
+    }
125
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
+    $crash = ($crash ? $crash : []);
127
+    $crash[$file] = true;
128
+    ecrire_meta('message_crash_plugins', serialize($crash));
129 129
 
130
-	return false;
130
+    return false;
131 131
 }
132 132
 
133 133
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
  *     - string : chemin du fichier trouvé
152 152
  **/
153 153
 function include_spip($f, $include = true) {
154
-	return find_in_path($f . '.php', '', $include);
154
+    return find_in_path($f . '.php', '', $include);
155 155
 }
156 156
 
157 157
 /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
  *     - string : chemin du fichier trouvé
172 172
  **/
173 173
 function require_spip($f) {
174
-	return find_in_path($f . '.php', '', 'required');
174
+    return find_in_path($f . '.php', '', 'required');
175 175
 }
176 176
 
177 177
 
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
181 181
  */
182 182
 function include_fichiers_fonctions() {
183
-	static $done = false;
184
-	if (!$done) {
185
-		include_spip('inc/lang');
186
-
187
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
-		// donc il faut l'inclure "en globals"
189
-		if ($f = find_in_path('mes_fonctions.php')) {
190
-			global $dossier_squelettes;
191
-			include_once(_ROOT_CWD . $f);
192
-		}
193
-
194
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
-			// chargement optimise precompile
196
-			include_once(_CACHE_PLUGINS_FCT);
197
-		}
198
-		if (test_espace_prive()) {
199
-			include_spip('inc/filtres_ecrire');
200
-		}
201
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
-		$done = true;
203
-	}
183
+    static $done = false;
184
+    if (!$done) {
185
+        include_spip('inc/lang');
186
+
187
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
+        // donc il faut l'inclure "en globals"
189
+        if ($f = find_in_path('mes_fonctions.php')) {
190
+            global $dossier_squelettes;
191
+            include_once(_ROOT_CWD . $f);
192
+        }
193
+
194
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
+            // chargement optimise precompile
196
+            include_once(_CACHE_PLUGINS_FCT);
197
+        }
198
+        if (test_espace_prive()) {
199
+            include_spip('inc/filtres_ecrire');
200
+        }
201
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
+        $done = true;
203
+    }
204 204
 }
205 205
 
206 206
 /**
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
  *     Les paramètres du pipeline modifiés
227 227
  **/
228 228
 function minipipe($fonc, &$val) {
229
-	// fonction
230
-	if (function_exists($fonc)) {
231
-		$val = call_user_func($fonc, $val);
232
-	} // Class::Methode
233
-	else {
234
-		if (
235
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
-			and $methode = [$regs[1], $regs[2]]
237
-			and is_callable($methode)
238
-		) {
239
-			$val = call_user_func($methode, $val);
240
-		} else {
241
-			spip_log("Erreur - '$fonc' non definie !");
242
-		}
243
-	}
244
-
245
-	return $val;
229
+    // fonction
230
+    if (function_exists($fonc)) {
231
+        $val = call_user_func($fonc, $val);
232
+    } // Class::Methode
233
+    else {
234
+        if (
235
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
+            and $methode = [$regs[1], $regs[2]]
237
+            and is_callable($methode)
238
+        ) {
239
+            $val = call_user_func($methode, $val);
240
+        } else {
241
+            spip_log("Erreur - '$fonc' non definie !");
242
+        }
243
+    }
244
+
245
+    return $val;
246 246
 }
247 247
 
248 248
 /**
@@ -273,46 +273,46 @@  discard block
 block discarded – undo
273 273
  *     Résultat
274 274
  */
275 275
 function pipeline($action, $val = null) {
276
-	static $charger;
277
-
278
-	// chargement initial des fonctions mises en cache, ou generation du cache
279
-	if (!$charger) {
280
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
-			include_spip('inc/plugin');
282
-			// generer les fichiers php precompiles
283
-			// de chargement des plugins et des pipelines
284
-			actualise_plugins_actifs();
285
-			if (!($ok = @is_readable($charger))) {
286
-				spip_log("fichier $charger pas cree");
287
-			}
288
-		}
289
-
290
-		if ($ok) {
291
-			include_once $charger;
292
-		}
293
-	}
294
-
295
-	// appliquer notre fonction si elle existe
296
-	$fonc = 'execute_pipeline_' . strtolower($action);
297
-	if (function_exists($fonc)) {
298
-		$val = $fonc($val);
299
-	} // plantage ?
300
-	else {
301
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
-	}
303
-
304
-	// si le flux est une table avec 2 cle args&data
305
-	// on ne ressort du pipe que les donnees dans 'data'
306
-	// array_key_exists pour php 4.1.0
307
-	if (
308
-		is_array($val)
309
-		and count($val) == 2
310
-		and (array_key_exists('data', $val))
311
-	) {
312
-		$val = $val['data'];
313
-	}
314
-
315
-	return $val;
276
+    static $charger;
277
+
278
+    // chargement initial des fonctions mises en cache, ou generation du cache
279
+    if (!$charger) {
280
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
+            include_spip('inc/plugin');
282
+            // generer les fichiers php precompiles
283
+            // de chargement des plugins et des pipelines
284
+            actualise_plugins_actifs();
285
+            if (!($ok = @is_readable($charger))) {
286
+                spip_log("fichier $charger pas cree");
287
+            }
288
+        }
289
+
290
+        if ($ok) {
291
+            include_once $charger;
292
+        }
293
+    }
294
+
295
+    // appliquer notre fonction si elle existe
296
+    $fonc = 'execute_pipeline_' . strtolower($action);
297
+    if (function_exists($fonc)) {
298
+        $val = $fonc($val);
299
+    } // plantage ?
300
+    else {
301
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
+    }
303
+
304
+    // si le flux est une table avec 2 cle args&data
305
+    // on ne ressort du pipe que les donnees dans 'data'
306
+    // array_key_exists pour php 4.1.0
307
+    if (
308
+        is_array($val)
309
+        and count($val) == 2
310
+        and (array_key_exists('data', $val))
311
+    ) {
312
+        $val = $val['data'];
313
+    }
314
+
315
+    return $val;
316 316
 }
317 317
 
318 318
 /**
@@ -356,38 +356,38 @@  discard block
 block discarded – undo
356 356
  *     paramètre est planté pour cause de compatibilité ascendante.
357 357
  */
358 358
 function spip_log($message = null, $name = null) {
359
-	static $pre = [];
360
-	static $log;
361
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
363
-		$logname = null;
364
-	}
365
-	if (!isset($regs[2])) {
366
-		$niveau = _LOG_INFO;
367
-	}
368
-	else {
369
-		$niveau = intval($regs[2]);
370
-	}
371
-
372
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
-		if (!$pre) {
374
-			$pre = [
375
-				_LOG_HS => 'HS:',
376
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
377
-				_LOG_CRITIQUE => 'CRITIQUE:',
378
-				_LOG_ERREUR => 'ERREUR:',
379
-				_LOG_AVERTISSEMENT => 'WARNING:',
380
-				_LOG_INFO_IMPORTANTE => '!INFO:',
381
-				_LOG_INFO => 'info:',
382
-				_LOG_DEBUG => 'debug:'
383
-			];
384
-			$log = charger_fonction('log', 'inc');
385
-		}
386
-		if (!is_string($message)) {
387
-			$message = print_r($message, true);
388
-		}
389
-		$log($pre[$niveau] . ' ' . $message, $logname);
390
-	}
359
+    static $pre = [];
360
+    static $log;
361
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
363
+        $logname = null;
364
+    }
365
+    if (!isset($regs[2])) {
366
+        $niveau = _LOG_INFO;
367
+    }
368
+    else {
369
+        $niveau = intval($regs[2]);
370
+    }
371
+
372
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
+        if (!$pre) {
374
+            $pre = [
375
+                _LOG_HS => 'HS:',
376
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
377
+                _LOG_CRITIQUE => 'CRITIQUE:',
378
+                _LOG_ERREUR => 'ERREUR:',
379
+                _LOG_AVERTISSEMENT => 'WARNING:',
380
+                _LOG_INFO_IMPORTANTE => '!INFO:',
381
+                _LOG_INFO => 'info:',
382
+                _LOG_DEBUG => 'debug:'
383
+            ];
384
+            $log = charger_fonction('log', 'inc');
385
+        }
386
+        if (!is_string($message)) {
387
+            $message = print_r($message, true);
388
+        }
389
+        $log($pre[$niveau] . ' ' . $message, $logname);
390
+    }
391 391
 }
392 392
 
393 393
 /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
  * @param array $opt Tableau d'options
399 399
  **/
400 400
 function journal($phrase, $opt = []) {
401
-	$journal = charger_fonction('journal', 'inc');
402
-	$journal($phrase, $opt);
401
+    $journal = charger_fonction('journal', 'inc');
402
+    $journal($phrase, $opt);
403 403
 }
404 404
 
405 405
 
@@ -418,37 +418,37 @@  discard block
 block discarded – undo
418 418
  **/
419 419
 function _request($var, $c = false) {
420 420
 
421
-	if (is_array($c)) {
422
-		return isset($c[$var]) ? $c[$var] : null;
423
-	}
424
-
425
-	if (isset($_GET[$var])) {
426
-		$a = $_GET[$var];
427
-	} elseif (isset($_POST[$var])) {
428
-		$a = $_POST[$var];
429
-	} else {
430
-		return null;
431
-	}
432
-
433
-	// Si on est en ajax et en POST tout a ete encode
434
-	// via encodeURIComponent, il faut donc repasser
435
-	// dans le charset local...
436
-	if (
437
-		defined('_AJAX')
438
-		and _AJAX
439
-		and isset($GLOBALS['meta']['charset'])
440
-		and $GLOBALS['meta']['charset'] != 'utf-8'
441
-		and is_string($a)
442
-		// check rapide mais pas fiable
443
-		and preg_match(',[\x80-\xFF],', $a)
444
-		// check fiable
445
-		and include_spip('inc/charsets')
446
-		and is_utf8($a)
447
-	) {
448
-		return importer_charset($a, 'utf-8');
449
-	}
450
-
451
-	return $a;
421
+    if (is_array($c)) {
422
+        return isset($c[$var]) ? $c[$var] : null;
423
+    }
424
+
425
+    if (isset($_GET[$var])) {
426
+        $a = $_GET[$var];
427
+    } elseif (isset($_POST[$var])) {
428
+        $a = $_POST[$var];
429
+    } else {
430
+        return null;
431
+    }
432
+
433
+    // Si on est en ajax et en POST tout a ete encode
434
+    // via encodeURIComponent, il faut donc repasser
435
+    // dans le charset local...
436
+    if (
437
+        defined('_AJAX')
438
+        and _AJAX
439
+        and isset($GLOBALS['meta']['charset'])
440
+        and $GLOBALS['meta']['charset'] != 'utf-8'
441
+        and is_string($a)
442
+        // check rapide mais pas fiable
443
+        and preg_match(',[\x80-\xFF],', $a)
444
+        // check fiable
445
+        and include_spip('inc/charsets')
446
+        and is_utf8($a)
447
+    ) {
448
+        return importer_charset($a, 'utf-8');
449
+    }
450
+
451
+    return $a;
452 452
 }
453 453
 
454 454
 
@@ -466,22 +466,22 @@  discard block
 block discarded – undo
466 466
  *     - false sinon
467 467
  **/
468 468
 function set_request($var, $val = null, $c = false) {
469
-	if (is_array($c)) {
470
-		unset($c[$var]);
471
-		if ($val !== null) {
472
-			$c[$var] = $val;
473
-		}
469
+    if (is_array($c)) {
470
+        unset($c[$var]);
471
+        if ($val !== null) {
472
+            $c[$var] = $val;
473
+        }
474 474
 
475
-		return $c;
476
-	}
475
+        return $c;
476
+    }
477 477
 
478
-	unset($_GET[$var]);
479
-	unset($_POST[$var]);
480
-	if ($val !== null) {
481
-		$_GET[$var] = $val;
482
-	}
478
+    unset($_GET[$var]);
479
+    unset($_POST[$var]);
480
+    if ($val !== null) {
481
+        $_GET[$var] = $val;
482
+    }
483 483
 
484
-	return false; # n'affecte pas $c
484
+    return false; # n'affecte pas $c
485 485
 }
486 486
 
487 487
 /**
@@ -501,25 +501,25 @@  discard block
 block discarded – undo
501 501
  * @return array|mixed|string
502 502
  */
503 503
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
504
-	if (is_array($value)) {
505
-		if ($key == '*') {
506
-			$key = array_keys($value);
507
-		}
508
-		if (!is_array($key)) {
509
-			$key = [$key];
510
-		}
511
-		foreach ($key as $k) {
512
-			if (!empty($value[$k])) {
513
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
-			}
515
-		}
516
-		return $value;
517
-	}
518
-	// si la valeur vient des GET ou POST on la sanitize
519
-	if (!empty($value) and $value == _request($key)) {
520
-		$value = $sanitize_function($value);
521
-	}
522
-	return $value;
504
+    if (is_array($value)) {
505
+        if ($key == '*') {
506
+            $key = array_keys($value);
507
+        }
508
+        if (!is_array($key)) {
509
+            $key = [$key];
510
+        }
511
+        foreach ($key as $k) {
512
+            if (!empty($value[$k])) {
513
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
+            }
515
+        }
516
+        return $value;
517
+    }
518
+    // si la valeur vient des GET ou POST on la sanitize
519
+    if (!empty($value) and $value == _request($key)) {
520
+        $value = $sanitize_function($value);
521
+    }
522
+    return $value;
523 523
 }
524 524
 
525 525
 /**
@@ -527,23 +527,22 @@  discard block
 block discarded – undo
527 527
  *
528 528
  * On est sur le web, on exclut certains protocoles,
529 529
  * notamment 'file://', 'php://' et d'autres…
530
-
531 530
  * @param string $url
532 531
  * @return bool
533 532
  */
534 533
 function tester_url_absolue($url) {
535
-	$url = trim($url);
536
-	if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
537
-		if (
538
-			isset($m[1])
539
-			and $p = strtolower(rtrim($m[1], ':'))
540
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
541
-		) {
542
-			return false;
543
-		}
544
-		return true;
545
-	}
546
-	return false;
534
+    $url = trim($url);
535
+    if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
536
+        if (
537
+            isset($m[1])
538
+            and $p = strtolower(rtrim($m[1], ':'))
539
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
540
+        ) {
541
+            return false;
542
+        }
543
+        return true;
544
+    }
545
+    return false;
547 546
 }
548 547
 
549 548
 /**
@@ -565,95 +564,95 @@  discard block
 block discarded – undo
565 564
  * @return string URL
566 565
  */
567 566
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
568
-	// requete erronnee : plusieurs variable dans $c et aucun $v
569
-	if (strpos($c, '|') !== false and is_null($v)) {
570
-		return null;
571
-	}
572
-
573
-	// lever l'#ancre
574
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
575
-		$url = $r[1];
576
-		$ancre = $r[2];
577
-	} else {
578
-		$ancre = '';
579
-	}
580
-
581
-	// eclater
582
-	$url = preg_split(',[?]|&amp;|&,', $url);
583
-
584
-	// recuperer la base
585
-	$a = array_shift($url);
586
-	if (!$a) {
587
-		$a = './';
588
-	}
589
-
590
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
591
-	$ajouts = array_flip(explode('|', $c));
592
-	$u = is_array($v) ? $v : rawurlencode($v);
593
-	$testv = (is_array($v) ? count($v) : strlen($v));
594
-	$v_read = null;
595
-	// lire les variables et agir
596
-	foreach ($url as $n => $val) {
597
-		if (preg_match($regexp, urldecode($val), $r)) {
598
-			$r = array_pad($r, 3, null);
599
-			if ($v === null) {
600
-				// c'est un tableau, on memorise les valeurs
601
-				if (substr($r[1], -2) == '[]') {
602
-					if (!$v_read) {
603
-						$v_read = [];
604
-					}
605
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
606
-				} // c'est un scalaire, on retourne direct
607
-				else {
608
-					return $r[2] ? substr($r[2], 1) : '';
609
-				}
610
-			} // suppression
611
-			elseif (!$testv) {
612
-				unset($url[$n]);
613
-			}
614
-			// Ajout. Pour une variable, remplacer au meme endroit,
615
-			// pour un tableau ce sera fait dans la prochaine boucle
616
-			elseif (substr($r[1], -2) != '[]') {
617
-				$url[$n] = $r[1] . '=' . $u;
618
-				unset($ajouts[$r[1]]);
619
-			}
620
-			// Pour les tableaux on laisse tomber les valeurs de
621
-			// départ, on remplira à l'étape suivante
622
-			else {
623
-				unset($url[$n]);
624
-			}
625
-		}
626
-	}
627
-
628
-	// traiter les parametres pas encore trouves
629
-	if (
630
-		$v === null
631
-		and $args = func_get_args()
632
-		and count($args) == 2
633
-	) {
634
-		return $v_read; // rien trouve ou un tableau
635
-	} elseif ($testv) {
636
-		foreach ($ajouts as $k => $n) {
637
-			if (!is_array($v)) {
638
-				$url[] = $k . '=' . $u;
639
-			} else {
640
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
641
-				foreach ($v as $w) {
642
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
643
-				}
644
-			}
645
-		}
646
-	}
647
-
648
-	// eliminer les vides
649
-	$url = array_filter($url);
650
-
651
-	// recomposer l'adresse
652
-	if ($url) {
653
-		$a .= '?' . join($sep, $url);
654
-	}
655
-
656
-	return $a . $ancre;
567
+    // requete erronnee : plusieurs variable dans $c et aucun $v
568
+    if (strpos($c, '|') !== false and is_null($v)) {
569
+        return null;
570
+    }
571
+
572
+    // lever l'#ancre
573
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
574
+        $url = $r[1];
575
+        $ancre = $r[2];
576
+    } else {
577
+        $ancre = '';
578
+    }
579
+
580
+    // eclater
581
+    $url = preg_split(',[?]|&amp;|&,', $url);
582
+
583
+    // recuperer la base
584
+    $a = array_shift($url);
585
+    if (!$a) {
586
+        $a = './';
587
+    }
588
+
589
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
590
+    $ajouts = array_flip(explode('|', $c));
591
+    $u = is_array($v) ? $v : rawurlencode($v);
592
+    $testv = (is_array($v) ? count($v) : strlen($v));
593
+    $v_read = null;
594
+    // lire les variables et agir
595
+    foreach ($url as $n => $val) {
596
+        if (preg_match($regexp, urldecode($val), $r)) {
597
+            $r = array_pad($r, 3, null);
598
+            if ($v === null) {
599
+                // c'est un tableau, on memorise les valeurs
600
+                if (substr($r[1], -2) == '[]') {
601
+                    if (!$v_read) {
602
+                        $v_read = [];
603
+                    }
604
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
605
+                } // c'est un scalaire, on retourne direct
606
+                else {
607
+                    return $r[2] ? substr($r[2], 1) : '';
608
+                }
609
+            } // suppression
610
+            elseif (!$testv) {
611
+                unset($url[$n]);
612
+            }
613
+            // Ajout. Pour une variable, remplacer au meme endroit,
614
+            // pour un tableau ce sera fait dans la prochaine boucle
615
+            elseif (substr($r[1], -2) != '[]') {
616
+                $url[$n] = $r[1] . '=' . $u;
617
+                unset($ajouts[$r[1]]);
618
+            }
619
+            // Pour les tableaux on laisse tomber les valeurs de
620
+            // départ, on remplira à l'étape suivante
621
+            else {
622
+                unset($url[$n]);
623
+            }
624
+        }
625
+    }
626
+
627
+    // traiter les parametres pas encore trouves
628
+    if (
629
+        $v === null
630
+        and $args = func_get_args()
631
+        and count($args) == 2
632
+    ) {
633
+        return $v_read; // rien trouve ou un tableau
634
+    } elseif ($testv) {
635
+        foreach ($ajouts as $k => $n) {
636
+            if (!is_array($v)) {
637
+                $url[] = $k . '=' . $u;
638
+            } else {
639
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
640
+                foreach ($v as $w) {
641
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
642
+                }
643
+            }
644
+        }
645
+    }
646
+
647
+    // eliminer les vides
648
+    $url = array_filter($url);
649
+
650
+    // recomposer l'adresse
651
+    if ($url) {
652
+        $a .= '?' . join($sep, $url);
653
+    }
654
+
655
+    return $a . $ancre;
657 656
 }
658 657
 
659 658
 /**
@@ -671,21 +670,21 @@  discard block
 block discarded – undo
671 670
  * @return string
672 671
  */
673 672
 function ancre_url($url, $ancre) {
674
-	// lever l'#ancre
675
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
676
-		$url = $r[1];
677
-	}
678
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
679
-		if (!function_exists('translitteration')) {
680
-			include_spip('inc/charsets');
681
-		}
682
-		$ancre = preg_replace(
683
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
684
-			['', '-'],
685
-			translitteration($ancre)
686
-		);
687
-	}
688
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
673
+    // lever l'#ancre
674
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
675
+        $url = $r[1];
676
+    }
677
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
678
+        if (!function_exists('translitteration')) {
679
+            include_spip('inc/charsets');
680
+        }
681
+        $ancre = preg_replace(
682
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
683
+            ['', '-'],
684
+            translitteration($ancre)
685
+        );
686
+    }
687
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
689 688
 }
690 689
 
691 690
 /**
@@ -695,16 +694,16 @@  discard block
 block discarded – undo
695 694
  * @return string
696 695
  */
697 696
 function nettoyer_uri($reset = null) {
698
-	static $done = false;
699
-	static $propre = '';
700
-	if (!is_null($reset)) {
701
-		return $propre = $reset;
702
-	}
703
-	if ($done) {
704
-		return $propre;
705
-	}
706
-	$done = true;
707
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
697
+    static $done = false;
698
+    static $propre = '';
699
+    if (!is_null($reset)) {
700
+        return $propre = $reset;
701
+    }
702
+    if ($done) {
703
+        return $propre;
704
+    }
705
+    $done = true;
706
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
708 707
 }
709 708
 
710 709
 /**
@@ -716,16 +715,16 @@  discard block
 block discarded – undo
716 715
  * @return string
717 716
  */
718 717
 function nettoyer_uri_var($request_uri) {
719
-	$uri1 = $request_uri;
720
-	do {
721
-		$uri = $uri1;
722
-		$uri1 = preg_replace(
723
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
724
-			'\1',
725
-			$uri
726
-		);
727
-	} while ($uri <> $uri1);
728
-	return preg_replace(',[?&]$,', '', $uri1);
718
+    $uri1 = $request_uri;
719
+    do {
720
+        $uri = $uri1;
721
+        $uri1 = preg_replace(
722
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
723
+            '\1',
724
+            $uri
725
+        );
726
+    } while ($uri <> $uri1);
727
+    return preg_replace(',[?&]$,', '', $uri1);
729 728
 }
730 729
 
731 730
 
@@ -739,48 +738,48 @@  discard block
 block discarded – undo
739 738
  *    URL vers soi-même
740 739
  **/
741 740
 function self($amp = '&amp;', $root = false) {
742
-	$url = nettoyer_uri();
743
-	if (
744
-		!$root
745
-		and (
746
-			// si pas de profondeur on peut tronquer
747
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
748
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
749
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
750
-	) {
751
-		$url = preg_replace(',^[^?]*/,', '', $url);
752
-	}
753
-	// ajouter le cas echeant les variables _POST['id_...']
754
-	foreach ($_POST as $v => $c) {
755
-		if (substr($v, 0, 3) == 'id_') {
756
-			$url = parametre_url($url, $v, $c, '&');
757
-		}
758
-	}
759
-
760
-	// supprimer les variables sans interet
761
-	if (test_espace_prive()) {
762
-		$url = preg_replace(',([?&])('
763
-			. 'lang|show_docs|'
764
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
765
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
766
-		$url = preg_replace(',[&]$,', '\1', $url);
767
-	}
768
-
769
-	// eviter les hacks
770
-	include_spip('inc/filtres_mini');
771
-	$url = spip_htmlspecialchars($url);
772
-
773
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
774
-
775
-	// &amp; ?
776
-	if ($amp != '&amp;') {
777
-		$url = str_replace('&amp;', $amp, $url);
778
-	}
779
-
780
-	// Si ca demarre par ? ou vide, donner './'
781
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
782
-
783
-	return $url;
741
+    $url = nettoyer_uri();
742
+    if (
743
+        !$root
744
+        and (
745
+            // si pas de profondeur on peut tronquer
746
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
747
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
748
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
749
+    ) {
750
+        $url = preg_replace(',^[^?]*/,', '', $url);
751
+    }
752
+    // ajouter le cas echeant les variables _POST['id_...']
753
+    foreach ($_POST as $v => $c) {
754
+        if (substr($v, 0, 3) == 'id_') {
755
+            $url = parametre_url($url, $v, $c, '&');
756
+        }
757
+    }
758
+
759
+    // supprimer les variables sans interet
760
+    if (test_espace_prive()) {
761
+        $url = preg_replace(',([?&])('
762
+            . 'lang|show_docs|'
763
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
764
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
765
+        $url = preg_replace(',[&]$,', '\1', $url);
766
+    }
767
+
768
+    // eviter les hacks
769
+    include_spip('inc/filtres_mini');
770
+    $url = spip_htmlspecialchars($url);
771
+
772
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
773
+
774
+    // &amp; ?
775
+    if ($amp != '&amp;') {
776
+        $url = str_replace('&amp;', $amp, $url);
777
+    }
778
+
779
+    // Si ca demarre par ? ou vide, donner './'
780
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
781
+
782
+    return $url;
784 783
 }
785 784
 
786 785
 
@@ -791,7 +790,7 @@  discard block
 block discarded – undo
791 790
  *     true si c'est le cas, false sinon.
792 791
  */
793 792
 function test_espace_prive() {
794
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
793
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
795 794
 }
796 795
 
797 796
 /**
@@ -801,7 +800,7 @@  discard block
 block discarded – undo
801 800
  * @return bool
802 801
  */
803 802
 function test_plugin_actif($plugin) {
804
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
803
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
805 804
 }
806 805
 
807 806
 /**
@@ -832,53 +831,53 @@  discard block
 block discarded – undo
832 831
  *     Texte
833 832
  */
834 833
 function _T($texte, $args = [], $options = []) {
835
-	static $traduire = false;
836
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
837
-	if ($options) {
838
-		// support de l'ancien argument $class
839
-		if (is_string($options)) {
840
-			$options = ['class' => $options];
841
-		}
842
-		$o = array_merge($o, $options);
843
-	}
844
-
845
-	if (!$traduire) {
846
-		$traduire = charger_fonction('traduire', 'inc');
847
-		include_spip('inc/lang');
848
-	}
849
-
850
-	// On peut passer explicitement la langue dans le tableau
851
-	// On utilise le même nom de variable que la globale
852
-	if (isset($args['spip_lang'])) {
853
-		$lang = $args['spip_lang'];
854
-		// On l'enleve pour ne pas le passer au remplacement
855
-		unset($args['spip_lang']);
856
-	} // Sinon on prend la langue du contexte
857
-	else {
858
-		$lang = $GLOBALS['spip_lang'];
859
-	}
860
-	$text = $traduire($texte, $lang);
861
-
862
-	if (!strlen($text)) {
863
-		if (!$o['force']) {
864
-			return '';
865
-		}
866
-
867
-		$text = $texte;
868
-
869
-		// pour les chaines non traduites, assurer un service minimum
870
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
871
-			$text = str_replace(
872
-				'_',
873
-				' ',
874
-				(($n = strpos($text, ':')) === false ? $texte :
875
-				substr($texte, $n + 1))
876
-			);
877
-		}
878
-		$o['class'] = null;
879
-	}
880
-
881
-	return _L($text, $args, $o);
834
+    static $traduire = false;
835
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
836
+    if ($options) {
837
+        // support de l'ancien argument $class
838
+        if (is_string($options)) {
839
+            $options = ['class' => $options];
840
+        }
841
+        $o = array_merge($o, $options);
842
+    }
843
+
844
+    if (!$traduire) {
845
+        $traduire = charger_fonction('traduire', 'inc');
846
+        include_spip('inc/lang');
847
+    }
848
+
849
+    // On peut passer explicitement la langue dans le tableau
850
+    // On utilise le même nom de variable que la globale
851
+    if (isset($args['spip_lang'])) {
852
+        $lang = $args['spip_lang'];
853
+        // On l'enleve pour ne pas le passer au remplacement
854
+        unset($args['spip_lang']);
855
+    } // Sinon on prend la langue du contexte
856
+    else {
857
+        $lang = $GLOBALS['spip_lang'];
858
+    }
859
+    $text = $traduire($texte, $lang);
860
+
861
+    if (!strlen($text)) {
862
+        if (!$o['force']) {
863
+            return '';
864
+        }
865
+
866
+        $text = $texte;
867
+
868
+        // pour les chaines non traduites, assurer un service minimum
869
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
870
+            $text = str_replace(
871
+                '_',
872
+                ' ',
873
+                (($n = strpos($text, ':')) === false ? $texte :
874
+                substr($texte, $n + 1))
875
+            );
876
+        }
877
+        $o['class'] = null;
878
+    }
879
+
880
+    return _L($text, $args, $o);
882 881
 }
883 882
 
884 883
 
@@ -905,53 +904,53 @@  discard block
 block discarded – undo
905 904
  *     Texte
906 905
  */
907 906
 function _L($text, $args = [], $options = []) {
908
-	$f = $text;
909
-	$defaut_options = [
910
-		'class' => null,
911
-		'sanitize' => true,
912
-	];
913
-	// support de l'ancien argument $class
914
-	if ($options and is_string($options)) {
915
-		$options = ['class' => $options];
916
-	}
917
-	if (is_array($options)) {
918
-		$options += $defaut_options;
919
-	} else {
920
-		$options = $defaut_options;
921
-	}
922
-
923
-	if (is_array($args) and count($args)) {
924
-		if (!function_exists('interdire_scripts')) {
925
-			include_spip('inc/texte');
926
-		}
927
-		if (!function_exists('echapper_html_suspect')) {
928
-			include_spip('inc/texte_mini');
929
-		}
930
-		foreach ($args as $name => $value) {
931
-			if (strpos($text, "@$name@") !== false) {
932
-				if ($options['sanitize']) {
933
-					$value = echapper_html_suspect($value);
934
-					$value = interdire_scripts($value, -1);
935
-				}
936
-				if (!empty($options['class'])) {
937
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
938
-				}
939
-				$text = str_replace("@$name@", $value, $text);
940
-				unset($args[$name]);
941
-			}
942
-		}
943
-		// Si des variables n'ont pas ete inserees, le signaler
944
-		// (chaines de langues pas a jour)
945
-		if ($args) {
946
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
947
-		}
948
-	}
949
-
950
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
951
-		return "<span class='debug-traduction-erreur'>$text</span>";
952
-	} else {
953
-		return $text;
954
-	}
907
+    $f = $text;
908
+    $defaut_options = [
909
+        'class' => null,
910
+        'sanitize' => true,
911
+    ];
912
+    // support de l'ancien argument $class
913
+    if ($options and is_string($options)) {
914
+        $options = ['class' => $options];
915
+    }
916
+    if (is_array($options)) {
917
+        $options += $defaut_options;
918
+    } else {
919
+        $options = $defaut_options;
920
+    }
921
+
922
+    if (is_array($args) and count($args)) {
923
+        if (!function_exists('interdire_scripts')) {
924
+            include_spip('inc/texte');
925
+        }
926
+        if (!function_exists('echapper_html_suspect')) {
927
+            include_spip('inc/texte_mini');
928
+        }
929
+        foreach ($args as $name => $value) {
930
+            if (strpos($text, "@$name@") !== false) {
931
+                if ($options['sanitize']) {
932
+                    $value = echapper_html_suspect($value);
933
+                    $value = interdire_scripts($value, -1);
934
+                }
935
+                if (!empty($options['class'])) {
936
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
937
+                }
938
+                $text = str_replace("@$name@", $value, $text);
939
+                unset($args[$name]);
940
+            }
941
+        }
942
+        // Si des variables n'ont pas ete inserees, le signaler
943
+        // (chaines de langues pas a jour)
944
+        if ($args) {
945
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
946
+        }
947
+    }
948
+
949
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
950
+        return "<span class='debug-traduction-erreur'>$text</span>";
951
+    } else {
952
+        return $text;
953
+    }
955 954
 }
956 955
 
957 956
 
@@ -965,13 +964,13 @@  discard block
 block discarded – undo
965 964
  * @return string
966 965
  */
967 966
 function joli_repertoire($rep) {
968
-	$a = substr($rep, 0, 1);
969
-	if ($a <> '.' and $a <> '/') {
970
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
971
-	}
972
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
967
+    $a = substr($rep, 0, 1);
968
+    if ($a <> '.' and $a <> '/') {
969
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
970
+    }
971
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
973 972
 
974
-	return $rep;
973
+    return $rep;
975 974
 }
976 975
 
977 976
 
@@ -996,33 +995,33 @@  discard block
 block discarded – undo
996 995
  * @return float|int|string|void
997 996
  */
998 997
 function spip_timer($t = 'rien', $raw = false) {
999
-	static $time;
1000
-	$a = time();
1001
-	$b = microtime();
1002
-	// microtime peut contenir les microsecondes et le temps
1003
-	$b = explode(' ', $b);
1004
-	if (count($b) == 2) {
1005
-		$a = end($b);
1006
-	} // plus precis !
1007
-	$b = reset($b);
1008
-	if (!isset($time[$t])) {
1009
-		$time[$t] = $a + $b;
1010
-	} else {
1011
-		$p = ($a + $b - $time[$t]) * 1000;
1012
-		unset($time[$t]);
998
+    static $time;
999
+    $a = time();
1000
+    $b = microtime();
1001
+    // microtime peut contenir les microsecondes et le temps
1002
+    $b = explode(' ', $b);
1003
+    if (count($b) == 2) {
1004
+        $a = end($b);
1005
+    } // plus precis !
1006
+    $b = reset($b);
1007
+    if (!isset($time[$t])) {
1008
+        $time[$t] = $a + $b;
1009
+    } else {
1010
+        $p = ($a + $b - $time[$t]) * 1000;
1011
+        unset($time[$t]);
1013 1012
 #			echo "'$p'";exit;
1014
-		if ($raw) {
1015
-			return $p;
1016
-		}
1017
-		if ($p < 1000) {
1018
-			$s = '';
1019
-		} else {
1020
-			$s = sprintf('%d ', $x = floor($p / 1000));
1021
-			$p -= ($x * 1000);
1022
-		}
1013
+        if ($raw) {
1014
+            return $p;
1015
+        }
1016
+        if ($p < 1000) {
1017
+            $s = '';
1018
+        } else {
1019
+            $s = sprintf('%d ', $x = floor($p / 1000));
1020
+            $p -= ($x * 1000);
1021
+        }
1023 1022
 
1024
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1025
-	}
1023
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1024
+    }
1026 1025
 }
1027 1026
 
1028 1027
 
@@ -1030,21 +1029,21 @@  discard block
 block discarded – undo
1030 1029
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1031 1030
 // https://code.spip.net/@spip_touch
1032 1031
 function spip_touch($fichier, $duree = 0, $touch = true) {
1033
-	if ($duree) {
1034
-		clearstatcache();
1035
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1036
-			return false;
1037
-		}
1038
-	}
1039
-	if ($touch !== false) {
1040
-		if (!@touch($fichier)) {
1041
-			spip_unlink($fichier);
1042
-			@touch($fichier);
1043
-		};
1044
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1045
-	}
1032
+    if ($duree) {
1033
+        clearstatcache();
1034
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1035
+            return false;
1036
+        }
1037
+    }
1038
+    if ($touch !== false) {
1039
+        if (!@touch($fichier)) {
1040
+            spip_unlink($fichier);
1041
+            @touch($fichier);
1042
+        };
1043
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1044
+    }
1046 1045
 
1047
-	return true;
1046
+    return true;
1048 1047
 }
1049 1048
 
1050 1049
 
@@ -1055,11 +1054,11 @@  discard block
 block discarded – undo
1055 1054
  * @uses cron()
1056 1055
  **/
1057 1056
 function action_cron() {
1058
-	include_spip('inc/headers');
1059
-	http_response_code(204); // No Content
1060
-	header('Connection: close');
1061
-	define('_DIRECT_CRON_FORCE', true);
1062
-	cron();
1057
+    include_spip('inc/headers');
1058
+    http_response_code(204); // No Content
1059
+    header('Connection: close');
1060
+    define('_DIRECT_CRON_FORCE', true);
1061
+    cron();
1063 1062
 }
1064 1063
 
1065 1064
 /**
@@ -1075,26 +1074,26 @@  discard block
 block discarded – undo
1075 1074
  *     True si la tache a pu être effectuée
1076 1075
  */
1077 1076
 function cron($taches = [], $taches_old = []) {
1078
-	// si pas en mode cron force, laisser tomber.
1079
-	if (!defined('_DIRECT_CRON_FORCE')) {
1080
-		return false;
1081
-	}
1082
-	if (!is_array($taches)) {
1083
-		$taches = $taches_old;
1084
-	} // compat anciens appels
1085
-	// si taches a inserer en base et base inaccessible, laisser tomber
1086
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1087
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1088
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1089
-	if ($taches and count($taches) and !spip_connect()) {
1090
-		return false;
1091
-	}
1092
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1093
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1094
-		return $genie($taches);
1095
-	}
1096
-
1097
-	return false;
1077
+    // si pas en mode cron force, laisser tomber.
1078
+    if (!defined('_DIRECT_CRON_FORCE')) {
1079
+        return false;
1080
+    }
1081
+    if (!is_array($taches)) {
1082
+        $taches = $taches_old;
1083
+    } // compat anciens appels
1084
+    // si taches a inserer en base et base inaccessible, laisser tomber
1085
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1086
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1087
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1088
+    if ($taches and count($taches) and !spip_connect()) {
1089
+        return false;
1090
+    }
1091
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1092
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1093
+        return $genie($taches);
1094
+    }
1095
+
1096
+    return false;
1098 1097
 }
1099 1098
 
1100 1099
 /**
@@ -1126,17 +1125,17 @@  discard block
 block discarded – undo
1126 1125
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1127 1126
  */
1128 1127
 function job_queue_add(
1129
-	$function,
1130
-	$description,
1131
-	$arguments = [],
1132
-	$file = '',
1133
-	$no_duplicate = false,
1134
-	$time = 0,
1135
-	$priority = 0
1128
+    $function,
1129
+    $description,
1130
+    $arguments = [],
1131
+    $file = '',
1132
+    $no_duplicate = false,
1133
+    $time = 0,
1134
+    $priority = 0
1136 1135
 ) {
1137
-	include_spip('inc/queue');
1136
+    include_spip('inc/queue');
1138 1137
 
1139
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1138
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1140 1139
 }
1141 1140
 
1142 1141
 /**
@@ -1147,9 +1146,9 @@  discard block
 block discarded – undo
1147 1146
  * @return bool
1148 1147
  */
1149 1148
 function job_queue_remove($id_job) {
1150
-	include_spip('inc/queue');
1149
+    include_spip('inc/queue');
1151 1150
 
1152
-	return queue_remove_job($id_job);
1151
+    return queue_remove_job($id_job);
1153 1152
 }
1154 1153
 
1155 1154
 /**
@@ -1162,9 +1161,9 @@  discard block
 block discarded – undo
1162 1161
  *     or an array of simple array to link multiples objet in one time
1163 1162
  */
1164 1163
 function job_queue_link($id_job, $objets) {
1165
-	include_spip('inc/queue');
1164
+    include_spip('inc/queue');
1166 1165
 
1167
-	return queue_link_job($id_job, $objets);
1166
+    return queue_link_job($id_job, $objets);
1168 1167
 }
1169 1168
 
1170 1169
 
@@ -1184,36 +1183,36 @@  discard block
 block discarded – undo
1184 1183
  *  - `null` si la queue n'est pas encore initialisée
1185 1184
  */
1186 1185
 function queue_sleep_time_to_next_job($force = null) {
1187
-	static $queue_next_job_time = -1;
1188
-	if ($force === true) {
1189
-		$queue_next_job_time = -1;
1190
-	} elseif ($force) {
1191
-		$queue_next_job_time = $force;
1192
-	}
1193
-
1194
-	if ($queue_next_job_time == -1) {
1195
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1196
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1197
-		}
1198
-		// utiliser un cache memoire si dispo
1199
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1200
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1201
-		} else {
1202
-			$queue_next_job_time = null;
1203
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1204
-				$queue_next_job_time = intval($contenu);
1205
-			}
1206
-		}
1207
-	}
1208
-
1209
-	if (is_null($queue_next_job_time)) {
1210
-		return null;
1211
-	}
1212
-	if (!$_SERVER['REQUEST_TIME']) {
1213
-		$_SERVER['REQUEST_TIME'] = time();
1214
-	}
1215
-
1216
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1186
+    static $queue_next_job_time = -1;
1187
+    if ($force === true) {
1188
+        $queue_next_job_time = -1;
1189
+    } elseif ($force) {
1190
+        $queue_next_job_time = $force;
1191
+    }
1192
+
1193
+    if ($queue_next_job_time == -1) {
1194
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1195
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1196
+        }
1197
+        // utiliser un cache memoire si dispo
1198
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1199
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1200
+        } else {
1201
+            $queue_next_job_time = null;
1202
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1203
+                $queue_next_job_time = intval($contenu);
1204
+            }
1205
+        }
1206
+    }
1207
+
1208
+    if (is_null($queue_next_job_time)) {
1209
+        return null;
1210
+    }
1211
+    if (!$_SERVER['REQUEST_TIME']) {
1212
+        $_SERVER['REQUEST_TIME'] = time();
1213
+    }
1214
+
1215
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1217 1216
 }
1218 1217
 
1219 1218
 
@@ -1225,11 +1224,11 @@  discard block
 block discarded – undo
1225 1224
  * @return string
1226 1225
  */
1227 1226
 function quote_amp($u) {
1228
-	return preg_replace(
1229
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1230
-		'&amp;',
1231
-		$u
1232
-	);
1227
+    return preg_replace(
1228
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1229
+        '&amp;',
1230
+        $u
1231
+    );
1233 1232
 }
1234 1233
 
1235 1234
 
@@ -1252,27 +1251,27 @@  discard block
 block discarded – undo
1252 1251
  *     Balise HTML `<script>` et son contenu
1253 1252
  **/
1254 1253
 function http_script($script, $src = '', $noscript = '') {
1255
-	static $done = [];
1254
+    static $done = [];
1256 1255
 
1257
-	if ($src && !isset($done[$src])) {
1258
-		$done[$src] = true;
1259
-		$src = find_in_path($src, _JAVASCRIPT);
1260
-		$src = " src='$src'";
1261
-	} else {
1262
-		$src = '';
1263
-	}
1264
-	if ($script) {
1265
-		$script = ("/*<![CDATA[*/\n" .
1266
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1267
-			'/*]]>*/');
1268
-	}
1269
-	if ($noscript) {
1270
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1271
-	}
1256
+    if ($src && !isset($done[$src])) {
1257
+        $done[$src] = true;
1258
+        $src = find_in_path($src, _JAVASCRIPT);
1259
+        $src = " src='$src'";
1260
+    } else {
1261
+        $src = '';
1262
+    }
1263
+    if ($script) {
1264
+        $script = ("/*<![CDATA[*/\n" .
1265
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1266
+            '/*]]>*/');
1267
+    }
1268
+    if ($noscript) {
1269
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1270
+    }
1272 1271
 
1273
-	return ($src or $script or $noscript)
1274
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1275
-		: '';
1272
+    return ($src or $script or $noscript)
1273
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1274
+        : '';
1276 1275
 }
1277 1276
 
1278 1277
 
@@ -1307,7 +1306,7 @@  discard block
 block discarded – undo
1307 1306
  *     Texte échappé
1308 1307
  **/
1309 1308
 function texte_script($texte) {
1310
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1309
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1311 1310
 }
1312 1311
 
1313 1312
 
@@ -1344,68 +1343,68 @@  discard block
 block discarded – undo
1344 1343
  *     Liste des chemins, par ordre de priorité.
1345 1344
  **/
1346 1345
 function _chemin($dir_path = null) {
1347
-	static $path_base = null;
1348
-	static $path_full = null;
1349
-	if ($path_base == null) {
1350
-		// Chemin standard depuis l'espace public
1351
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1352
-			_DIR_RACINE . ':' .
1353
-			_DIR_RACINE . 'squelettes-dist/:' .
1354
-			_DIR_RACINE . 'prive/:' .
1355
-			_DIR_RESTREINT;
1356
-		// Ajouter squelettes/
1357
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1358
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1359
-		}
1360
-		foreach (explode(':', $path) as $dir) {
1361
-			if (strlen($dir) and substr($dir, -1) != '/') {
1362
-				$dir .= '/';
1363
-			}
1364
-			$path_base[] = $dir;
1365
-		}
1366
-		$path_full = $path_base;
1367
-		// Et le(s) dossier(s) des squelettes nommes
1368
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1369
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1370
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1371
-			}
1372
-		}
1373
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1374
-	}
1375
-	if ($dir_path === null) {
1376
-		return $path_full;
1377
-	}
1378
-
1379
-	if (is_array($dir_path) or strlen($dir_path)) {
1380
-		$tete = '';
1381
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1382
-			$tete = array_shift($path_base);
1383
-		}
1384
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1385
-		$dirs = array_reverse($dirs);
1386
-		foreach ($dirs as $dir_path) {
1387
-			if (substr($dir_path, -1) != '/') {
1388
-				$dir_path .= '/';
1389
-			}
1390
-			if (!in_array($dir_path, $path_base)) {
1391
-				array_unshift($path_base, $dir_path);
1392
-			}
1393
-		}
1394
-		if (strlen($tete)) {
1395
-			array_unshift($path_base, $tete);
1396
-		}
1397
-	}
1398
-	$path_full = $path_base;
1399
-	// Et le(s) dossier(s) des squelettes nommes
1400
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1401
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1402
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1403
-		}
1404
-	}
1405
-
1406
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1407
-
1408
-	return $path_full;
1346
+    static $path_base = null;
1347
+    static $path_full = null;
1348
+    if ($path_base == null) {
1349
+        // Chemin standard depuis l'espace public
1350
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1351
+            _DIR_RACINE . ':' .
1352
+            _DIR_RACINE . 'squelettes-dist/:' .
1353
+            _DIR_RACINE . 'prive/:' .
1354
+            _DIR_RESTREINT;
1355
+        // Ajouter squelettes/
1356
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1357
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1358
+        }
1359
+        foreach (explode(':', $path) as $dir) {
1360
+            if (strlen($dir) and substr($dir, -1) != '/') {
1361
+                $dir .= '/';
1362
+            }
1363
+            $path_base[] = $dir;
1364
+        }
1365
+        $path_full = $path_base;
1366
+        // Et le(s) dossier(s) des squelettes nommes
1367
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1368
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1369
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1370
+            }
1371
+        }
1372
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1373
+    }
1374
+    if ($dir_path === null) {
1375
+        return $path_full;
1376
+    }
1377
+
1378
+    if (is_array($dir_path) or strlen($dir_path)) {
1379
+        $tete = '';
1380
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1381
+            $tete = array_shift($path_base);
1382
+        }
1383
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1384
+        $dirs = array_reverse($dirs);
1385
+        foreach ($dirs as $dir_path) {
1386
+            if (substr($dir_path, -1) != '/') {
1387
+                $dir_path .= '/';
1388
+            }
1389
+            if (!in_array($dir_path, $path_base)) {
1390
+                array_unshift($path_base, $dir_path);
1391
+            }
1392
+        }
1393
+        if (strlen($tete)) {
1394
+            array_unshift($path_base, $tete);
1395
+        }
1396
+    }
1397
+    $path_full = $path_base;
1398
+    // Et le(s) dossier(s) des squelettes nommes
1399
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1400
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1401
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1402
+        }
1403
+    }
1404
+
1405
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1406
+
1407
+    return $path_full;
1409 1408
 }
1410 1409
 
1411 1410
 /**
@@ -1418,78 +1417,78 @@  discard block
 block discarded – undo
1418 1417
  * @return array Liste de chemins
1419 1418
  **/
1420 1419
 function creer_chemin() {
1421
-	$path_a = _chemin();
1422
-	static $c = '';
1420
+    $path_a = _chemin();
1421
+    static $c = '';
1423 1422
 
1424
-	// on calcule le chemin si le dossier skel a change
1425
-	if ($c != $GLOBALS['dossier_squelettes']) {
1426
-		// assurer le non plantage lors de la montee de version :
1427
-		$c = $GLOBALS['dossier_squelettes'];
1428
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1429
-	}
1423
+    // on calcule le chemin si le dossier skel a change
1424
+    if ($c != $GLOBALS['dossier_squelettes']) {
1425
+        // assurer le non plantage lors de la montee de version :
1426
+        $c = $GLOBALS['dossier_squelettes'];
1427
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1428
+    }
1430 1429
 
1431
-	return $path_a;
1430
+    return $path_a;
1432 1431
 }
1433 1432
 
1434 1433
 
1435 1434
 function lister_themes_prives() {
1436
-	static $themes = null;
1437
-	if (is_null($themes)) {
1438
-		// si pas encore definie
1439
-		if (!defined('_SPIP_THEME_PRIVE')) {
1440
-			define('_SPIP_THEME_PRIVE', 'spip');
1441
-		}
1442
-		$themes = [_SPIP_THEME_PRIVE];
1443
-		// lors d'une installation neuve, prefs n'est pas definie.
1444
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1445
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1446
-		} else {
1447
-			$prefs = [];
1448
-		}
1449
-		if (is_string($prefs)) {
1450
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1451
-		}
1452
-		if (
1453
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1454
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1455
-			and $theme != _SPIP_THEME_PRIVE
1456
-		) {
1457
-			array_unshift($themes, $theme);
1458
-		} // placer le theme choisi en tete
1459
-	}
1460
-
1461
-	return $themes;
1435
+    static $themes = null;
1436
+    if (is_null($themes)) {
1437
+        // si pas encore definie
1438
+        if (!defined('_SPIP_THEME_PRIVE')) {
1439
+            define('_SPIP_THEME_PRIVE', 'spip');
1440
+        }
1441
+        $themes = [_SPIP_THEME_PRIVE];
1442
+        // lors d'une installation neuve, prefs n'est pas definie.
1443
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1444
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1445
+        } else {
1446
+            $prefs = [];
1447
+        }
1448
+        if (is_string($prefs)) {
1449
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1450
+        }
1451
+        if (
1452
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1453
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1454
+            and $theme != _SPIP_THEME_PRIVE
1455
+        ) {
1456
+            array_unshift($themes, $theme);
1457
+        } // placer le theme choisi en tete
1458
+    }
1459
+
1460
+    return $themes;
1462 1461
 }
1463 1462
 
1464 1463
 function find_in_theme($file, $subdir = '', $include = false) {
1465
-	static $themefiles = [];
1466
-	if (isset($themefiles["$subdir$file"])) {
1467
-		return $themefiles["$subdir$file"];
1468
-	}
1469
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1470
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1471
-	if (
1472
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1473
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1474
-		and $f = find_in_theme("$file_svg_generique")
1475
-	) {
1476
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1477
-			return $themefiles["$subdir$file"] = $fsize;
1478
-		}
1479
-		else {
1480
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1481
-		}
1482
-	}
1483
-
1484
-	$themes = lister_themes_prives();
1485
-	foreach ($themes as $theme) {
1486
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1487
-			return $themefiles["$subdir$file"] = $f;
1488
-		}
1489
-	}
1490
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1491
-
1492
-	return $themefiles["$subdir$file"] = '';
1464
+    static $themefiles = [];
1465
+    if (isset($themefiles["$subdir$file"])) {
1466
+        return $themefiles["$subdir$file"];
1467
+    }
1468
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1469
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1470
+    if (
1471
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1472
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1473
+        and $f = find_in_theme("$file_svg_generique")
1474
+    ) {
1475
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1476
+            return $themefiles["$subdir$file"] = $fsize;
1477
+        }
1478
+        else {
1479
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1480
+        }
1481
+    }
1482
+
1483
+    $themes = lister_themes_prives();
1484
+    foreach ($themes as $theme) {
1485
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1486
+            return $themefiles["$subdir$file"] = $f;
1487
+        }
1488
+    }
1489
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1490
+
1491
+    return $themefiles["$subdir$file"] = '';
1493 1492
 }
1494 1493
 
1495 1494
 
@@ -1513,31 +1512,31 @@  discard block
 block discarded – undo
1513 1512
  *     sinon chaîne vide.
1514 1513
  **/
1515 1514
 function chemin_image($icone) {
1516
-	static $icone_renommer;
1517
-	if ($p = strpos($icone, '?')) {
1518
-		$icone = substr($icone, 0, $p);
1519
-	}
1520
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1521
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1522
-		return $icone;
1523
-	}
1524
-
1525
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1526
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1527
-		return $f;
1528
-	}
1529
-	// sinon passer par le module de renommage
1530
-	if (is_null($icone_renommer)) {
1531
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1532
-	}
1533
-	if ($icone_renommer) {
1534
-		list($icone, $fonction) = $icone_renommer($icone, '');
1535
-		if (file_exists($icone)) {
1536
-			return $icone;
1537
-		}
1538
-	}
1539
-
1540
-	return find_in_path($icone, _NOM_IMG_PACK);
1515
+    static $icone_renommer;
1516
+    if ($p = strpos($icone, '?')) {
1517
+        $icone = substr($icone, 0, $p);
1518
+    }
1519
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1520
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1521
+        return $icone;
1522
+    }
1523
+
1524
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1525
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1526
+        return $f;
1527
+    }
1528
+    // sinon passer par le module de renommage
1529
+    if (is_null($icone_renommer)) {
1530
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1531
+    }
1532
+    if ($icone_renommer) {
1533
+        list($icone, $fonction) = $icone_renommer($icone, '');
1534
+        if (file_exists($icone)) {
1535
+            return $icone;
1536
+        }
1537
+    }
1538
+
1539
+    return find_in_path($icone, _NOM_IMG_PACK);
1541 1540
 }
1542 1541
 
1543 1542
 //
@@ -1575,128 +1574,128 @@  discard block
 block discarded – undo
1575 1574
  *     - false : fichier introuvable
1576 1575
  **/
1577 1576
 function find_in_path($file, $dirname = '', $include = false) {
1578
-	static $dirs = [];
1579
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1580
-	static $c = '';
1581
-
1582
-	if (!$file and !strlen($file)) {
1583
-		return false;
1584
-	}
1585
-
1586
-	// on calcule le chemin si le dossier skel a change
1587
-	if ($c != $GLOBALS['dossier_squelettes']) {
1588
-		// assurer le non plantage lors de la montee de version :
1589
-		$c = $GLOBALS['dossier_squelettes'];
1590
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1591
-	}
1592
-
1593
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1594
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1595
-			return false;
1596
-		}
1597
-		if ($include and !isset($inc[$dirname][$file])) {
1598
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1599
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1600
-		}
1601
-
1602
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1603
-	}
1604
-
1605
-	$a = strrpos($file, '/');
1606
-	if ($a !== false) {
1607
-		$dirname .= substr($file, 0, ++$a);
1608
-		$file = substr($file, $a);
1609
-	}
1610
-
1611
-	foreach (creer_chemin() as $dir) {
1612
-		if (!isset($dirs[$a = $dir . $dirname])) {
1613
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1614
-		}
1615
-		if ($dirs[$a]) {
1616
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1617
-				if ($include and !isset($inc[$dirname][$file])) {
1618
-					include_once _ROOT_CWD . $a;
1619
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1620
-				}
1621
-				if (!defined('_SAUVER_CHEMIN')) {
1622
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1623
-					if (is_null($GLOBALS['path_files'])) {
1624
-						return $a;
1625
-					}
1626
-					define('_SAUVER_CHEMIN', true);
1627
-				}
1628
-
1629
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1630
-			}
1631
-		}
1632
-	}
1633
-
1634
-	if ($include) {
1635
-		spip_log("include_spip $dirname$file non trouve");
1636
-		if ($include === 'required') {
1637
-			echo '<pre>',
1638
-			'<strong>Erreur Fatale</strong><br />';
1639
-			if (function_exists('debug_print_backtrace')) {
1640
-				echo debug_print_backtrace();
1641
-			}
1642
-			echo '</pre>';
1643
-			die("Erreur interne: ne peut inclure $dirname$file");
1644
-		}
1645
-	}
1646
-
1647
-	if (!defined('_SAUVER_CHEMIN')) {
1648
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1649
-		if (is_null($GLOBALS['path_files'])) {
1650
-			return false;
1651
-		}
1652
-		define('_SAUVER_CHEMIN', true);
1653
-	}
1654
-
1655
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1577
+    static $dirs = [];
1578
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1579
+    static $c = '';
1580
+
1581
+    if (!$file and !strlen($file)) {
1582
+        return false;
1583
+    }
1584
+
1585
+    // on calcule le chemin si le dossier skel a change
1586
+    if ($c != $GLOBALS['dossier_squelettes']) {
1587
+        // assurer le non plantage lors de la montee de version :
1588
+        $c = $GLOBALS['dossier_squelettes'];
1589
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1590
+    }
1591
+
1592
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1593
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1594
+            return false;
1595
+        }
1596
+        if ($include and !isset($inc[$dirname][$file])) {
1597
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1598
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1599
+        }
1600
+
1601
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1602
+    }
1603
+
1604
+    $a = strrpos($file, '/');
1605
+    if ($a !== false) {
1606
+        $dirname .= substr($file, 0, ++$a);
1607
+        $file = substr($file, $a);
1608
+    }
1609
+
1610
+    foreach (creer_chemin() as $dir) {
1611
+        if (!isset($dirs[$a = $dir . $dirname])) {
1612
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1613
+        }
1614
+        if ($dirs[$a]) {
1615
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1616
+                if ($include and !isset($inc[$dirname][$file])) {
1617
+                    include_once _ROOT_CWD . $a;
1618
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1619
+                }
1620
+                if (!defined('_SAUVER_CHEMIN')) {
1621
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1622
+                    if (is_null($GLOBALS['path_files'])) {
1623
+                        return $a;
1624
+                    }
1625
+                    define('_SAUVER_CHEMIN', true);
1626
+                }
1627
+
1628
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1629
+            }
1630
+        }
1631
+    }
1632
+
1633
+    if ($include) {
1634
+        spip_log("include_spip $dirname$file non trouve");
1635
+        if ($include === 'required') {
1636
+            echo '<pre>',
1637
+            '<strong>Erreur Fatale</strong><br />';
1638
+            if (function_exists('debug_print_backtrace')) {
1639
+                echo debug_print_backtrace();
1640
+            }
1641
+            echo '</pre>';
1642
+            die("Erreur interne: ne peut inclure $dirname$file");
1643
+        }
1644
+    }
1645
+
1646
+    if (!defined('_SAUVER_CHEMIN')) {
1647
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1648
+        if (is_null($GLOBALS['path_files'])) {
1649
+            return false;
1650
+        }
1651
+        define('_SAUVER_CHEMIN', true);
1652
+    }
1653
+
1654
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1656 1655
 }
1657 1656
 
1658 1657
 function clear_path_cache() {
1659
-	$GLOBALS['path_files'] = [];
1660
-	spip_unlink(_CACHE_CHEMIN);
1658
+    $GLOBALS['path_files'] = [];
1659
+    spip_unlink(_CACHE_CHEMIN);
1661 1660
 }
1662 1661
 
1663 1662
 function load_path_cache() {
1664
-	// charger le path des plugins
1665
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1666
-		include_once(_CACHE_PLUGINS_PATH);
1667
-	}
1668
-	$GLOBALS['path_files'] = [];
1669
-	// si le visiteur est admin,
1670
-	// on ne recharge pas le cache pour forcer sa mise a jour
1671
-	if (
1672
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1673
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1674
-		// utiliser le cookie est un pis aller qui marche 'en general'
1675
-		// on blinde par un second test au moment de la lecture de la session
1676
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1677
-		// et en ignorant ce cache en cas de recalcul explicite
1678
-		!_request('var_mode')
1679
-	) {
1680
-		// on essaye de lire directement sans verrou pour aller plus vite
1681
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1682
-			// mais si semble corrompu on relit avec un verrou
1683
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1684
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1685
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1686
-					$GLOBALS['path_files'] = [];
1687
-				}
1688
-			}
1689
-		}
1690
-	}
1663
+    // charger le path des plugins
1664
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1665
+        include_once(_CACHE_PLUGINS_PATH);
1666
+    }
1667
+    $GLOBALS['path_files'] = [];
1668
+    // si le visiteur est admin,
1669
+    // on ne recharge pas le cache pour forcer sa mise a jour
1670
+    if (
1671
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1672
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1673
+        // utiliser le cookie est un pis aller qui marche 'en general'
1674
+        // on blinde par un second test au moment de la lecture de la session
1675
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1676
+        // et en ignorant ce cache en cas de recalcul explicite
1677
+        !_request('var_mode')
1678
+    ) {
1679
+        // on essaye de lire directement sans verrou pour aller plus vite
1680
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1681
+            // mais si semble corrompu on relit avec un verrou
1682
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1683
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1684
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1685
+                    $GLOBALS['path_files'] = [];
1686
+                }
1687
+            }
1688
+        }
1689
+    }
1691 1690
 }
1692 1691
 
1693 1692
 function save_path_cache() {
1694
-	if (
1695
-		defined('_SAUVER_CHEMIN')
1696
-		and _SAUVER_CHEMIN
1697
-	) {
1698
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1699
-	}
1693
+    if (
1694
+        defined('_SAUVER_CHEMIN')
1695
+        and _SAUVER_CHEMIN
1696
+    ) {
1697
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1698
+    }
1700 1699
 }
1701 1700
 
1702 1701
 
@@ -1716,33 +1715,33 @@  discard block
 block discarded – undo
1716 1715
  * @return array
1717 1716
  */
1718 1717
 function find_all_in_path($dir, $pattern, $recurs = false) {
1719
-	$liste_fichiers = [];
1720
-	$maxfiles = 10000;
1721
-
1722
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1723
-	// on a pas encore inclus flock.php
1724
-	if (!function_exists('preg_files')) {
1725
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1726
-	}
1727
-
1728
-	// Parcourir le chemin
1729
-	foreach (creer_chemin() as $d) {
1730
-		$f = $d . $dir;
1731
-		if (@is_dir($f)) {
1732
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1733
-			foreach ($liste as $chemin) {
1734
-				$nom = basename($chemin);
1735
-				// ne prendre que les fichiers pas deja trouves
1736
-				// car find_in_path prend le premier qu'il trouve,
1737
-				// les autres sont donc masques
1738
-				if (!isset($liste_fichiers[$nom])) {
1739
-					$liste_fichiers[$nom] = $chemin;
1740
-				}
1741
-			}
1742
-		}
1743
-	}
1744
-
1745
-	return $liste_fichiers;
1718
+    $liste_fichiers = [];
1719
+    $maxfiles = 10000;
1720
+
1721
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1722
+    // on a pas encore inclus flock.php
1723
+    if (!function_exists('preg_files')) {
1724
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1725
+    }
1726
+
1727
+    // Parcourir le chemin
1728
+    foreach (creer_chemin() as $d) {
1729
+        $f = $d . $dir;
1730
+        if (@is_dir($f)) {
1731
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1732
+            foreach ($liste as $chemin) {
1733
+                $nom = basename($chemin);
1734
+                // ne prendre que les fichiers pas deja trouves
1735
+                // car find_in_path prend le premier qu'il trouve,
1736
+                // les autres sont donc masques
1737
+                if (!isset($liste_fichiers[$nom])) {
1738
+                    $liste_fichiers[$nom] = $chemin;
1739
+                }
1740
+            }
1741
+        }
1742
+    }
1743
+
1744
+    return $liste_fichiers;
1746 1745
 }
1747 1746
 
1748 1747
 /**
@@ -1754,17 +1753,17 @@  discard block
 block discarded – undo
1754 1753
  * @return bool
1755 1754
  */
1756 1755
 function autoriser_sans_cookie($nom, $strict = false) {
1757
-	static $autsanscookie = ['install', 'base_repair'];
1756
+    static $autsanscookie = ['install', 'base_repair'];
1758 1757
 
1759
-	if (in_array($nom, $autsanscookie)) {
1760
-		if (test_espace_prive()) {
1761
-			include_spip('base/connect_sql');
1762
-			if (!$strict or !spip_connect()) {
1763
-				return true;
1764
-			}
1765
-		}
1766
-	}
1767
-	return false;
1758
+    if (in_array($nom, $autsanscookie)) {
1759
+        if (test_espace_prive()) {
1760
+            include_spip('base/connect_sql');
1761
+            if (!$strict or !spip_connect()) {
1762
+                return true;
1763
+            }
1764
+        }
1765
+    }
1766
+    return false;
1768 1767
 }
1769 1768
 
1770 1769
 /**
@@ -1790,99 +1789,99 @@  discard block
 block discarded – undo
1790 1789
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1791 1790
  */
1792 1791
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1793
-	if ($public === null) {
1794
-		$public = !test_espace_prive();
1795
-	}
1796
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1797
-
1798
-	if (!$public) {
1799
-		if (!$entite) {
1800
-			return '';
1801
-		}
1802
-		if (!function_exists('generer_url_ecrire_objet')) {
1803
-			include_spip('inc/urls');
1804
-		}
1805
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1806
-	} else {
1807
-		if ($type === null) {
1808
-			$type = (isset($GLOBALS['type_urls']))
1809
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1810
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1811
-					? ($GLOBALS['meta']['type_urls']) : 'page'); // sinon type "page" par défaut
1812
-		}
1813
-
1814
-		$f = charger_fonction($type, 'urls', true);
1815
-		// se rabattre sur les urls page si les urls perso non dispo
1816
-		if (!$f) {
1817
-			$f = charger_fonction('page', 'urls', true);
1818
-		}
1819
-
1820
-		// si $entite='', on veut la fonction de passage URL ==> id
1821
-		// sinon on veut effectuer le passage id ==> URL
1822
-		if (!$entite) {
1823
-			return $f;
1824
-		}
1825
-
1826
-		// mais d'abord il faut tester le cas des urls sur une
1827
-		// base distante
1828
-		if (
1829
-			is_string($public)
1830
-			and $g = charger_fonction('connect', 'urls', true)
1831
-		) {
1832
-			$f = $g;
1833
-		}
1834
-
1835
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1836
-	}
1837
-	if ($res) {
1838
-		return $res;
1839
-	}
1840
-	// Sinon c'est un raccourci ou compat SPIP < 2
1841
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1842
-		if (!function_exists($f .= '_dist')) {
1843
-			$f = '';
1844
-		}
1845
-	}
1846
-	if ($f) {
1847
-		$url = $f($id, $args, $ancre);
1848
-		if (strlen($args)) {
1849
-			$url .= strstr($url, '?')
1850
-				? '&amp;' . $args
1851
-				: '?' . $args;
1852
-		}
1853
-
1854
-		return $url;
1855
-	}
1856
-	// On a ete gentil mais la ....
1857
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1858
-
1859
-	return '';
1792
+    if ($public === null) {
1793
+        $public = !test_espace_prive();
1794
+    }
1795
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1796
+
1797
+    if (!$public) {
1798
+        if (!$entite) {
1799
+            return '';
1800
+        }
1801
+        if (!function_exists('generer_url_ecrire_objet')) {
1802
+            include_spip('inc/urls');
1803
+        }
1804
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1805
+    } else {
1806
+        if ($type === null) {
1807
+            $type = (isset($GLOBALS['type_urls']))
1808
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1809
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1810
+                    ? ($GLOBALS['meta']['type_urls']) : 'page'); // sinon type "page" par défaut
1811
+        }
1812
+
1813
+        $f = charger_fonction($type, 'urls', true);
1814
+        // se rabattre sur les urls page si les urls perso non dispo
1815
+        if (!$f) {
1816
+            $f = charger_fonction('page', 'urls', true);
1817
+        }
1818
+
1819
+        // si $entite='', on veut la fonction de passage URL ==> id
1820
+        // sinon on veut effectuer le passage id ==> URL
1821
+        if (!$entite) {
1822
+            return $f;
1823
+        }
1824
+
1825
+        // mais d'abord il faut tester le cas des urls sur une
1826
+        // base distante
1827
+        if (
1828
+            is_string($public)
1829
+            and $g = charger_fonction('connect', 'urls', true)
1830
+        ) {
1831
+            $f = $g;
1832
+        }
1833
+
1834
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1835
+    }
1836
+    if ($res) {
1837
+        return $res;
1838
+    }
1839
+    // Sinon c'est un raccourci ou compat SPIP < 2
1840
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1841
+        if (!function_exists($f .= '_dist')) {
1842
+            $f = '';
1843
+        }
1844
+    }
1845
+    if ($f) {
1846
+        $url = $f($id, $args, $ancre);
1847
+        if (strlen($args)) {
1848
+            $url .= strstr($url, '?')
1849
+                ? '&amp;' . $args
1850
+                : '?' . $args;
1851
+        }
1852
+
1853
+        return $url;
1854
+    }
1855
+    // On a ete gentil mais la ....
1856
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1857
+
1858
+    return '';
1860 1859
 }
1861 1860
 
1862 1861
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1863
-	$exec = objet_info($entite, 'url_edit');
1864
-	$url = generer_url_ecrire($exec, $args);
1865
-	if (intval($id)) {
1866
-		$url = parametre_url($url, id_table_objet($entite), $id);
1867
-	} else {
1868
-		$url = parametre_url($url, 'new', 'oui');
1869
-	}
1870
-	if ($ancre) {
1871
-		$url = ancre_url($url, $ancre);
1872
-	}
1862
+    $exec = objet_info($entite, 'url_edit');
1863
+    $url = generer_url_ecrire($exec, $args);
1864
+    if (intval($id)) {
1865
+        $url = parametre_url($url, id_table_objet($entite), $id);
1866
+    } else {
1867
+        $url = parametre_url($url, 'new', 'oui');
1868
+    }
1869
+    if ($ancre) {
1870
+        $url = ancre_url($url, $ancre);
1871
+    }
1873 1872
 
1874
-	return $url;
1873
+    return $url;
1875 1874
 }
1876 1875
 
1877 1876
 // https://code.spip.net/@urls_connect_dist
1878 1877
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1879
-	include_spip('base/connect_sql');
1880
-	$id_type = id_table_objet($entite, $public);
1878
+    include_spip('base/connect_sql');
1879
+    $id_type = id_table_objet($entite, $public);
1881 1880
 
1882
-	return _DIR_RACINE . get_spip_script('./')
1883
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1884
-	. (!$args ? '' : "&$args")
1885
-	. (!$ancre ? '' : "#$ancre");
1881
+    return _DIR_RACINE . get_spip_script('./')
1882
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1883
+    . (!$args ? '' : "&$args")
1884
+    . (!$ancre ? '' : "#$ancre");
1886 1885
 }
1887 1886
 
1888 1887
 
@@ -1893,32 +1892,32 @@  discard block
 block discarded – undo
1893 1892
  * @return string
1894 1893
  */
1895 1894
 function urlencode_1738($url) {
1896
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1897
-		$uri = '';
1898
-		for ($i = 0; $i < strlen($url); $i++) {
1899
-			if (ord($a = $url[$i]) > 127) {
1900
-				$a = rawurlencode($a);
1901
-			}
1902
-			$uri .= $a;
1903
-		}
1904
-		$url = $uri;
1905
-	}
1895
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1896
+        $uri = '';
1897
+        for ($i = 0; $i < strlen($url); $i++) {
1898
+            if (ord($a = $url[$i]) > 127) {
1899
+                $a = rawurlencode($a);
1900
+            }
1901
+            $uri .= $a;
1902
+        }
1903
+        $url = $uri;
1904
+    }
1906 1905
 
1907
-	return quote_amp($url);
1906
+    return quote_amp($url);
1908 1907
 }
1909 1908
 
1910 1909
 // https://code.spip.net/@generer_url_entite_absolue
1911 1910
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1912
-	if (!$connect) {
1913
-		$connect = true;
1914
-	}
1915
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1916
-	if (!preg_match(',^\w+:,', $h)) {
1917
-		include_spip('inc/filtres_mini');
1918
-		$h = url_absolue($h);
1919
-	}
1911
+    if (!$connect) {
1912
+        $connect = true;
1913
+    }
1914
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1915
+    if (!preg_match(',^\w+:,', $h)) {
1916
+        include_spip('inc/filtres_mini');
1917
+        $h = url_absolue($h);
1918
+    }
1920 1919
 
1921
-	return $h;
1920
+    return $h;
1922 1921
 }
1923 1922
 
1924 1923
 
@@ -1934,11 +1933,11 @@  discard block
 block discarded – undo
1934 1933
  *     true si la valeur est considérée active ; false sinon.
1935 1934
  **/
1936 1935
 function test_valeur_serveur($truc) {
1937
-	if (!$truc) {
1938
-		return false;
1939
-	}
1936
+    if (!$truc) {
1937
+        return false;
1938
+    }
1940 1939
 
1941
-	return (strtolower($truc) !== 'off');
1940
+    return (strtolower($truc) !== 'off');
1942 1941
 }
1943 1942
 
1944 1943
 //
@@ -1966,82 +1965,82 @@  discard block
 block discarded – undo
1966 1965
  */
1967 1966
 function url_de_base($profondeur = null) {
1968 1967
 
1969
-	static $url = [];
1970
-	if (is_array($profondeur)) {
1971
-		return $url = $profondeur;
1972
-	}
1973
-	if ($profondeur === false) {
1974
-		return $url;
1975
-	}
1976
-
1977
-	if (is_null($profondeur)) {
1978
-		$profondeur = $GLOBALS['profondeur_url'];
1979
-	}
1980
-
1981
-	if (isset($url[$profondeur])) {
1982
-		return $url[$profondeur];
1983
-	}
1984
-
1985
-	$http = 'http';
1986
-
1987
-	if (
1988
-		isset($_SERVER['SCRIPT_URI'])
1989
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
1990
-	) {
1991
-		$http = 'https';
1992
-	} elseif (
1993
-		isset($_SERVER['HTTPS'])
1994
-		and test_valeur_serveur($_SERVER['HTTPS'])
1995
-	) {
1996
-		$http = 'https';
1997
-	}
1998
-
1999
-	// note : HTTP_HOST contient le :port si necessaire
2000
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
2001
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2002
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2003
-		$host = $GLOBALS['meta']['adresse_site'];
2004
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2005
-			$http = $scheme;
2006
-			$host = str_replace("{$scheme}://", '', $host);
2007
-		}
2008
-	}
2009
-	if (
2010
-		isset($_SERVER['SERVER_PORT'])
2011
-		and $port = $_SERVER['SERVER_PORT']
2012
-		and strpos($host, ':') == false
2013
-	) {
2014
-		if (!defined('_PORT_HTTP_STANDARD')) {
2015
-			define('_PORT_HTTP_STANDARD', '80');
2016
-		}
2017
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2018
-			define('_PORT_HTTPS_STANDARD', '443');
2019
-		}
2020
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2021
-			$host .= ":$port";
2022
-		}
2023
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2024
-			$host .= ":$port";
2025
-		}
2026
-	}
2027
-
2028
-	if (!$GLOBALS['REQUEST_URI']) {
2029
-		if (isset($_SERVER['REQUEST_URI'])) {
2030
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2031
-		} else {
2032
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2033
-			if (
2034
-				!empty($_SERVER['QUERY_STRING'])
2035
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2036
-			) {
2037
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2038
-			}
2039
-		}
2040
-	}
2041
-
2042
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2043
-
2044
-	return $url[$profondeur];
1968
+    static $url = [];
1969
+    if (is_array($profondeur)) {
1970
+        return $url = $profondeur;
1971
+    }
1972
+    if ($profondeur === false) {
1973
+        return $url;
1974
+    }
1975
+
1976
+    if (is_null($profondeur)) {
1977
+        $profondeur = $GLOBALS['profondeur_url'];
1978
+    }
1979
+
1980
+    if (isset($url[$profondeur])) {
1981
+        return $url[$profondeur];
1982
+    }
1983
+
1984
+    $http = 'http';
1985
+
1986
+    if (
1987
+        isset($_SERVER['SCRIPT_URI'])
1988
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
1989
+    ) {
1990
+        $http = 'https';
1991
+    } elseif (
1992
+        isset($_SERVER['HTTPS'])
1993
+        and test_valeur_serveur($_SERVER['HTTPS'])
1994
+    ) {
1995
+        $http = 'https';
1996
+    }
1997
+
1998
+    // note : HTTP_HOST contient le :port si necessaire
1999
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
2000
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2001
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2002
+        $host = $GLOBALS['meta']['adresse_site'];
2003
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2004
+            $http = $scheme;
2005
+            $host = str_replace("{$scheme}://", '', $host);
2006
+        }
2007
+    }
2008
+    if (
2009
+        isset($_SERVER['SERVER_PORT'])
2010
+        and $port = $_SERVER['SERVER_PORT']
2011
+        and strpos($host, ':') == false
2012
+    ) {
2013
+        if (!defined('_PORT_HTTP_STANDARD')) {
2014
+            define('_PORT_HTTP_STANDARD', '80');
2015
+        }
2016
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2017
+            define('_PORT_HTTPS_STANDARD', '443');
2018
+        }
2019
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2020
+            $host .= ":$port";
2021
+        }
2022
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2023
+            $host .= ":$port";
2024
+        }
2025
+    }
2026
+
2027
+    if (!$GLOBALS['REQUEST_URI']) {
2028
+        if (isset($_SERVER['REQUEST_URI'])) {
2029
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2030
+        } else {
2031
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2032
+            if (
2033
+                !empty($_SERVER['QUERY_STRING'])
2034
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2035
+            ) {
2036
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2037
+            }
2038
+        }
2039
+    }
2040
+
2041
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2042
+
2043
+    return $url[$profondeur];
2045 2044
 }
2046 2045
 
2047 2046
 /**
@@ -2054,26 +2053,26 @@  discard block
 block discarded – undo
2054 2053
  * @return string
2055 2054
  */
2056 2055
 function url_de_($http, $host, $request, $prof = 0) {
2057
-	$prof = max($prof, 0);
2056
+    $prof = max($prof, 0);
2058 2057
 
2059
-	$myself = ltrim($request, '/');
2060
-	# supprimer la chaine de GET
2061
-	list($myself) = explode('?', $myself);
2062
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2063
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2064
-	if (strpos($myself, '://') !== false) {
2065
-		$myself = explode('://', $myself);
2066
-		array_shift($myself);
2067
-		$myself = implode('://', $myself);
2068
-		$myself = explode('/', $myself);
2069
-		array_shift($myself);
2070
-		$myself = implode('/', $myself);
2071
-	}
2072
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2058
+    $myself = ltrim($request, '/');
2059
+    # supprimer la chaine de GET
2060
+    list($myself) = explode('?', $myself);
2061
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2062
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2063
+    if (strpos($myself, '://') !== false) {
2064
+        $myself = explode('://', $myself);
2065
+        array_shift($myself);
2066
+        $myself = implode('://', $myself);
2067
+        $myself = explode('/', $myself);
2068
+        array_shift($myself);
2069
+        $myself = implode('/', $myself);
2070
+    }
2071
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2073 2072
 
2074
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2073
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2075 2074
 
2076
-	return $url;
2075
+    return $url;
2077 2076
 }
2078 2077
 
2079 2078
 
@@ -2108,26 +2107,26 @@  discard block
 block discarded – undo
2108 2107
  * @return string URL
2109 2108
  **/
2110 2109
 function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) {
2111
-	if (!$rel) {
2112
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2113
-	} else {
2114
-		if (!is_string($rel)) {
2115
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2116
-				('./' . _SPIP_ECRIRE_SCRIPT);
2117
-		}
2118
-	}
2119
-
2120
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2121
-	if ($script and ($script <> 'accueil' or $rel)) {
2122
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2123
-	} elseif ($args) {
2124
-		$args = "?$args";
2125
-	}
2126
-	if ($ancre) {
2127
-		$args .= "#$ancre";
2128
-	}
2129
-
2130
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2110
+    if (!$rel) {
2111
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2112
+    } else {
2113
+        if (!is_string($rel)) {
2114
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2115
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2116
+        }
2117
+    }
2118
+
2119
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2120
+    if ($script and ($script <> 'accueil' or $rel)) {
2121
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2122
+    } elseif ($args) {
2123
+        $args = "?$args";
2124
+    }
2125
+    if ($ancre) {
2126
+        $args .= "#$ancre";
2127
+    }
2128
+
2129
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2131 2130
 }
2132 2131
 
2133 2132
 //
@@ -2149,12 +2148,12 @@  discard block
 block discarded – undo
2149 2148
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2150 2149
  **/
2151 2150
 function get_spip_script($default = '') {
2152
-	# cas define('_SPIP_SCRIPT', '');
2153
-	if (_SPIP_SCRIPT) {
2154
-		return _SPIP_SCRIPT;
2155
-	} else {
2156
-		return $default;
2157
-	}
2151
+    # cas define('_SPIP_SCRIPT', '');
2152
+    if (_SPIP_SCRIPT) {
2153
+        return _SPIP_SCRIPT;
2154
+    } else {
2155
+        return $default;
2156
+    }
2158 2157
 }
2159 2158
 
2160 2159
 /**
@@ -2183,39 +2182,39 @@  discard block
 block discarded – undo
2183 2182
  * @return string URL
2184 2183
  **/
2185 2184
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2186
-	// si le script est une action (spip_pass, spip_inscription),
2187
-	// standardiser vers la nouvelle API
2188
-
2189
-	if (!$action) {
2190
-		$action = get_spip_script();
2191
-	}
2192
-	if ($script) {
2193
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2194
-	}
2195
-
2196
-	if ($args) {
2197
-		if (is_array($args)) {
2198
-			$r = '';
2199
-			foreach ($args as $k => $v) {
2200
-				$r .= '&' . $k . '=' . $v;
2201
-			}
2202
-			$args = substr($r, 1);
2203
-		}
2204
-		$action .=
2205
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2206
-	}
2207
-	if (!$no_entities) {
2208
-		$action = quote_amp($action);
2209
-	}
2210
-
2211
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2212
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2185
+    // si le script est une action (spip_pass, spip_inscription),
2186
+    // standardiser vers la nouvelle API
2187
+
2188
+    if (!$action) {
2189
+        $action = get_spip_script();
2190
+    }
2191
+    if ($script) {
2192
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2193
+    }
2194
+
2195
+    if ($args) {
2196
+        if (is_array($args)) {
2197
+            $r = '';
2198
+            foreach ($args as $k => $v) {
2199
+                $r .= '&' . $k . '=' . $v;
2200
+            }
2201
+            $args = substr($r, 1);
2202
+        }
2203
+        $action .=
2204
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2205
+    }
2206
+    if (!$no_entities) {
2207
+        $action = quote_amp($action);
2208
+    }
2209
+
2210
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2211
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2213 2212
 }
2214 2213
 
2215 2214
 // https://code.spip.net/@generer_url_prive
2216 2215
 function generer_url_prive($script, $args = '', $no_entities = false) {
2217 2216
 
2218
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2217
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2219 2218
 }
2220 2219
 
2221 2220
 // Pour les formulaires en methode POST,
@@ -2240,19 +2239,19 @@  discard block
 block discarded – undo
2240 2239
  **/
2241 2240
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2242 2241
 
2243
-	$script1 = explode('&', $script);
2244
-	$script1 = reset($script1);
2242
+    $script1 = explode('&', $script);
2243
+    $script1 = reset($script1);
2245 2244
 
2246
-	return "<form action='"
2247
-	. ($script ? generer_url_ecrire($script) : '')
2248
-	. "' "
2249
-	. ($atts ? $atts : " method='post'")
2250
-	. "><div>\n"
2251
-	. "<input type='hidden' name='exec' value='$script1' />"
2252
-	. $corps
2253
-	. (!$submit ? '' :
2254
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2255
-	. "</div></form>\n";
2245
+    return "<form action='"
2246
+    . ($script ? generer_url_ecrire($script) : '')
2247
+    . "' "
2248
+    . ($atts ? $atts : " method='post'")
2249
+    . "><div>\n"
2250
+    . "<input type='hidden' name='exec' value='$script1' />"
2251
+    . $corps
2252
+    . (!$submit ? '' :
2253
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2254
+    . "</div></form>\n";
2256 2255
 }
2257 2256
 
2258 2257
 /**
@@ -2269,22 +2268,22 @@  discard block
 block discarded – undo
2269 2268
  * @return string
2270 2269
  */
2271 2270
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2272
-	// si l'on est dans l'espace prive, on garde dans l'url
2273
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2274
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2275
-	$h = (_DIR_RACINE and !$public)
2276
-		? generer_url_ecrire(_request('exec'))
2277
-		: generer_url_public();
2271
+    // si l'on est dans l'espace prive, on garde dans l'url
2272
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2273
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2274
+    $h = (_DIR_RACINE and !$public)
2275
+        ? generer_url_ecrire(_request('exec'))
2276
+        : generer_url_public();
2278 2277
 
2279
-	return "\n<form action='" .
2280
-	$h .
2281
-	"'" .
2282
-	$atts .
2283
-	">\n" .
2284
-	'<div>' .
2285
-	"\n<input type='hidden' name='action' value='$script' />" .
2286
-	$corps .
2287
-	'</div></form>';
2278
+    return "\n<form action='" .
2279
+    $h .
2280
+    "'" .
2281
+    $atts .
2282
+    ">\n" .
2283
+    '<div>' .
2284
+    "\n<input type='hidden' name='action' value='$script' />" .
2285
+    $corps .
2286
+    '</div></form>';
2288 2287
 }
2289 2288
 
2290 2289
 /**
@@ -2303,22 +2302,22 @@  discard block
 block discarded – undo
2303 2302
  *     URL
2304 2303
  */
2305 2304
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2306
-	// si l'on est dans l'espace prive, on garde dans l'url
2307
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2308
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2309
-	$url = (_DIR_RACINE and !$public)
2310
-		? generer_url_ecrire(_request('exec'))
2311
-		: generer_url_public('', '', false, false);
2312
-	$url = parametre_url($url, 'action', $script);
2313
-	if ($args) {
2314
-		$url .= quote_amp('&' . $args);
2315
-	}
2305
+    // si l'on est dans l'espace prive, on garde dans l'url
2306
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2307
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2308
+    $url = (_DIR_RACINE and !$public)
2309
+        ? generer_url_ecrire(_request('exec'))
2310
+        : generer_url_public('', '', false, false);
2311
+    $url = parametre_url($url, 'action', $script);
2312
+    if ($args) {
2313
+        $url .= quote_amp('&' . $args);
2314
+    }
2316 2315
 
2317
-	if ($no_entities) {
2318
-		$url = str_replace('&amp;', '&', $url);
2319
-	}
2316
+    if ($no_entities) {
2317
+        $url = str_replace('&amp;', '&', $url);
2318
+    }
2320 2319
 
2321
-	return $url;
2320
+    return $url;
2322 2321
 }
2323 2322
 
2324 2323
 
@@ -2331,8 +2330,8 @@  discard block
 block discarded – undo
2331 2330
  * @param string $ta Répertoire temporaire accessible
2332 2331
  */
2333 2332
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2334
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2335
-	spip_initialisation_suite();
2333
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2334
+    spip_initialisation_suite();
2336 2335
 }
2337 2336
 
2338 2337
 /**
@@ -2352,322 +2351,322 @@  discard block
 block discarded – undo
2352 2351
  * @param string $ta Répertoire temporaire accessible
2353 2352
  */
2354 2353
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2355
-	static $too_late = 0;
2356
-	if ($too_late++) {
2357
-		return;
2358
-	}
2359
-
2360
-	// Declaration des repertoires
2361
-
2362
-	// le nom du repertoire plugins/ activables/desactivables
2363
-	if (!defined('_DIR_PLUGINS')) {
2364
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2365
-	}
2366
-
2367
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2368
-	if (!defined('_DIR_PLUGINS_DIST')) {
2369
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2370
-	}
2371
-
2372
-	// le nom du repertoire des librairies
2373
-	if (!defined('_DIR_LIB')) {
2374
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2375
-	}
2376
-
2377
-	if (!defined('_DIR_IMG')) {
2378
-		define('_DIR_IMG', $pa);
2379
-	}
2380
-	if (!defined('_DIR_LOGOS')) {
2381
-		define('_DIR_LOGOS', $pa);
2382
-	}
2383
-	if (!defined('_DIR_IMG_ICONES')) {
2384
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2385
-	}
2386
-
2387
-	if (!defined('_DIR_DUMP')) {
2388
-		define('_DIR_DUMP', $ti . 'dump/');
2389
-	}
2390
-	if (!defined('_DIR_SESSIONS')) {
2391
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2392
-	}
2393
-	if (!defined('_DIR_TRANSFERT')) {
2394
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2395
-	}
2396
-	if (!defined('_DIR_CACHE')) {
2397
-		define('_DIR_CACHE', $ti . 'cache/');
2398
-	}
2399
-	if (!defined('_DIR_CACHE_XML')) {
2400
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2401
-	}
2402
-	if (!defined('_DIR_SKELS')) {
2403
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2404
-	}
2405
-	if (!defined('_DIR_AIDE')) {
2406
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2407
-	}
2408
-	if (!defined('_DIR_TMP')) {
2409
-		define('_DIR_TMP', $ti);
2410
-	}
2411
-
2412
-	if (!defined('_DIR_VAR')) {
2413
-		define('_DIR_VAR', $ta);
2414
-	}
2415
-
2416
-	if (!defined('_DIR_ETC')) {
2417
-		define('_DIR_ETC', $pi);
2418
-	}
2419
-	if (!defined('_DIR_CONNECT')) {
2420
-		define('_DIR_CONNECT', $pi);
2421
-	}
2422
-	if (!defined('_DIR_CHMOD')) {
2423
-		define('_DIR_CHMOD', $pi);
2424
-	}
2425
-
2426
-	if (!isset($GLOBALS['test_dirs'])) {
2427
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2428
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2429
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2430
-	}
2431
-
2432
-	// Declaration des fichiers
2433
-
2434
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2435
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2436
-	}
2437
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2438
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2439
-	}
2440
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2441
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2442
-	}
2443
-	if (!defined('_CACHE_PIPELINES')) {
2444
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2445
-	}
2446
-	if (!defined('_CACHE_CHEMIN')) {
2447
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2448
-	}
2449
-
2450
-	# attention .php obligatoire pour ecrire_fichier_securise
2451
-	if (!defined('_FILE_META')) {
2452
-		define('_FILE_META', $ti . 'meta_cache.php');
2453
-	}
2454
-	if (!defined('_DIR_LOG')) {
2455
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2456
-	}
2457
-	if (!defined('_FILE_LOG')) {
2458
-		define('_FILE_LOG', 'spip');
2459
-	}
2460
-	if (!defined('_FILE_LOG_SUFFIX')) {
2461
-		define('_FILE_LOG_SUFFIX', '.log');
2462
-	}
2463
-
2464
-	// Le fichier de connexion a la base de donnees
2465
-	// tient compte des anciennes versions (inc_connect...)
2466
-	if (!defined('_FILE_CONNECT_INS')) {
2467
-		define('_FILE_CONNECT_INS', 'connect');
2468
-	}
2469
-	if (!defined('_FILE_CONNECT')) {
2470
-		define(
2471
-			'_FILE_CONNECT',
2472
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2473
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2474
-			: false))
2475
-		);
2476
-	}
2477
-
2478
-	// Le fichier de reglages des droits
2479
-	if (!defined('_FILE_CHMOD_INS')) {
2480
-		define('_FILE_CHMOD_INS', 'chmod');
2481
-	}
2482
-	if (!defined('_FILE_CHMOD')) {
2483
-		define(
2484
-			'_FILE_CHMOD',
2485
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2486
-			: false)
2487
-		);
2488
-	}
2489
-
2490
-	if (!defined('_FILE_LDAP')) {
2491
-		define('_FILE_LDAP', 'ldap.php');
2492
-	}
2493
-
2494
-	if (!defined('_FILE_TMP_SUFFIX')) {
2495
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2496
-	}
2497
-	if (!defined('_FILE_CONNECT_TMP')) {
2498
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2499
-	}
2500
-	if (!defined('_FILE_CHMOD_TMP')) {
2501
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2502
-	}
2503
-
2504
-	// Definition des droits d'acces en ecriture
2505
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2506
-		include_once _FILE_CHMOD;
2507
-	}
2508
-
2509
-	// Se mefier des fichiers mal remplis!
2510
-	if (!defined('_SPIP_CHMOD')) {
2511
-		define('_SPIP_CHMOD', 0777);
2512
-	}
2513
-
2514
-	if (!defined('_DEFAULT_CHARSET')) {
2515
-		/** Le charset par défaut lors de l'installation */
2516
-		define('_DEFAULT_CHARSET', 'utf-8');
2517
-	}
2518
-	if (!defined('_ROOT_PLUGINS')) {
2519
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2520
-	}
2521
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2522
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2523
-	}
2524
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2525
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2526
-	}
2527
-
2528
-	// La taille des Log
2529
-	if (!defined('_MAX_LOG')) {
2530
-		define('_MAX_LOG', 100);
2531
-	}
2532
-
2533
-	// Sommes-nous dans l'empire du Mal ?
2534
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2535
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2536
-		if (!defined('_OS_SERVEUR')) {
2537
-			define('_OS_SERVEUR', 'windows');
2538
-		}
2539
-		if (!defined('_SPIP_LOCK_MODE')) {
2540
-			define('_SPIP_LOCK_MODE', 1);
2541
-		} // utiliser le flock php
2542
-	} else {
2543
-		if (!defined('_OS_SERVEUR')) {
2544
-			define('_OS_SERVEUR', '');
2545
-		}
2546
-		if (!defined('_SPIP_LOCK_MODE')) {
2547
-			define('_SPIP_LOCK_MODE', 1);
2548
-		} // utiliser le flock php
2549
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2550
-	}
2551
-
2552
-	// Langue par defaut
2553
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2554
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2555
-	}
2556
-
2557
-	//
2558
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2559
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2560
-	// pour le rendre surchargeable, on va provoquer un reecriture
2561
-	// systematique du noyau ou une baisse de perfs => a etudier)
2562
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2563
-
2564
-	// charger tout de suite le path et son cache
2565
-	load_path_cache();
2566
-
2567
-	// *********** traiter les variables ************
2568
-
2569
-	//
2570
-	// Securite
2571
-	//
2572
-
2573
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2574
-	if (isset($_REQUEST['GLOBALS'])) {
2575
-		die();
2576
-	}
2577
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2578
-	spip_desinfecte($_GET);
2579
-	spip_desinfecte($_POST);
2580
-	spip_desinfecte($_COOKIE);
2581
-	spip_desinfecte($_REQUEST);
2582
-
2583
-	// appliquer le cookie_prefix
2584
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2585
-		include_spip('inc/cookie');
2586
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2587
-	}
2588
-
2589
-	//
2590
-	// Capacites php (en fonction de la version)
2591
-	//
2592
-	$GLOBALS['flag_ob'] = (function_exists('ob_start')
2593
-		&& function_exists('ini_get')
2594
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2595
-	$GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2596
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2597
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2598
-		(get_cfg_var('upload_max_filesize') > 0));
2599
-
2600
-
2601
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2602
-	if (isset($_SERVER['REQUEST_URI'])) {
2603
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2604
-	} else {
2605
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2606
-		if (
2607
-			!empty($_SERVER['QUERY_STRING'])
2608
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2609
-		) {
2610
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2611
-		}
2612
-	}
2613
-
2614
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2615
-	if (!defined('_RENOUVELLE_ALEA')) {
2616
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2617
-	}
2618
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2619
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2620
-	}
2621
-
2622
-	// charger les meta si possible et renouveller l'alea au besoin
2623
-	// charge aussi effacer_meta et ecrire_meta
2624
-	$inc_meta = charger_fonction('meta', 'inc');
2625
-	$inc_meta();
2626
-
2627
-	// nombre de repertoires depuis la racine
2628
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2629
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2630
-	// le calcul est faux)
2631
-	if (!_DIR_RESTREINT) {
2632
-		$GLOBALS['profondeur_url'] = 1;
2633
-	} else {
2634
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2635
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2636
-		if (
2637
-			!$uri_ref
2638
-			// si on est appele avec un autre ti, on est sans doute en mutu
2639
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2640
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2641
-			// s'en remettre a l'adresse du site. alea jacta est.
2642
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2643
-		) {
2644
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2645
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2646
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2647
-			} else {
2648
-				$uri_ref = '';
2649
-			}
2650
-		}
2651
-		if (!$uri or !$uri_ref) {
2652
-			$GLOBALS['profondeur_url'] = 0;
2653
-		} else {
2654
-			$GLOBALS['profondeur_url'] = max(
2655
-				0,
2656
-				substr_count($uri[0], '/')
2657
-				- substr_count($uri_ref, '/')
2658
-			);
2659
-		}
2660
-	}
2661
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2662
-	if (_FILE_CONNECT) {
2663
-		if (
2664
-			verifier_visiteur() == '0minirezo'
2665
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2666
-			and !isset($_COOKIE['spip_admin'])
2667
-		) {
2668
-			clear_path_cache();
2669
-		}
2670
-	}
2354
+    static $too_late = 0;
2355
+    if ($too_late++) {
2356
+        return;
2357
+    }
2358
+
2359
+    // Declaration des repertoires
2360
+
2361
+    // le nom du repertoire plugins/ activables/desactivables
2362
+    if (!defined('_DIR_PLUGINS')) {
2363
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2364
+    }
2365
+
2366
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2367
+    if (!defined('_DIR_PLUGINS_DIST')) {
2368
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2369
+    }
2370
+
2371
+    // le nom du repertoire des librairies
2372
+    if (!defined('_DIR_LIB')) {
2373
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2374
+    }
2375
+
2376
+    if (!defined('_DIR_IMG')) {
2377
+        define('_DIR_IMG', $pa);
2378
+    }
2379
+    if (!defined('_DIR_LOGOS')) {
2380
+        define('_DIR_LOGOS', $pa);
2381
+    }
2382
+    if (!defined('_DIR_IMG_ICONES')) {
2383
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2384
+    }
2385
+
2386
+    if (!defined('_DIR_DUMP')) {
2387
+        define('_DIR_DUMP', $ti . 'dump/');
2388
+    }
2389
+    if (!defined('_DIR_SESSIONS')) {
2390
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2391
+    }
2392
+    if (!defined('_DIR_TRANSFERT')) {
2393
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2394
+    }
2395
+    if (!defined('_DIR_CACHE')) {
2396
+        define('_DIR_CACHE', $ti . 'cache/');
2397
+    }
2398
+    if (!defined('_DIR_CACHE_XML')) {
2399
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2400
+    }
2401
+    if (!defined('_DIR_SKELS')) {
2402
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2403
+    }
2404
+    if (!defined('_DIR_AIDE')) {
2405
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2406
+    }
2407
+    if (!defined('_DIR_TMP')) {
2408
+        define('_DIR_TMP', $ti);
2409
+    }
2410
+
2411
+    if (!defined('_DIR_VAR')) {
2412
+        define('_DIR_VAR', $ta);
2413
+    }
2414
+
2415
+    if (!defined('_DIR_ETC')) {
2416
+        define('_DIR_ETC', $pi);
2417
+    }
2418
+    if (!defined('_DIR_CONNECT')) {
2419
+        define('_DIR_CONNECT', $pi);
2420
+    }
2421
+    if (!defined('_DIR_CHMOD')) {
2422
+        define('_DIR_CHMOD', $pi);
2423
+    }
2424
+
2425
+    if (!isset($GLOBALS['test_dirs'])) {
2426
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2427
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2428
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2429
+    }
2430
+
2431
+    // Declaration des fichiers
2432
+
2433
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2434
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2435
+    }
2436
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2437
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2438
+    }
2439
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2440
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2441
+    }
2442
+    if (!defined('_CACHE_PIPELINES')) {
2443
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2444
+    }
2445
+    if (!defined('_CACHE_CHEMIN')) {
2446
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2447
+    }
2448
+
2449
+    # attention .php obligatoire pour ecrire_fichier_securise
2450
+    if (!defined('_FILE_META')) {
2451
+        define('_FILE_META', $ti . 'meta_cache.php');
2452
+    }
2453
+    if (!defined('_DIR_LOG')) {
2454
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2455
+    }
2456
+    if (!defined('_FILE_LOG')) {
2457
+        define('_FILE_LOG', 'spip');
2458
+    }
2459
+    if (!defined('_FILE_LOG_SUFFIX')) {
2460
+        define('_FILE_LOG_SUFFIX', '.log');
2461
+    }
2462
+
2463
+    // Le fichier de connexion a la base de donnees
2464
+    // tient compte des anciennes versions (inc_connect...)
2465
+    if (!defined('_FILE_CONNECT_INS')) {
2466
+        define('_FILE_CONNECT_INS', 'connect');
2467
+    }
2468
+    if (!defined('_FILE_CONNECT')) {
2469
+        define(
2470
+            '_FILE_CONNECT',
2471
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2472
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2473
+            : false))
2474
+        );
2475
+    }
2476
+
2477
+    // Le fichier de reglages des droits
2478
+    if (!defined('_FILE_CHMOD_INS')) {
2479
+        define('_FILE_CHMOD_INS', 'chmod');
2480
+    }
2481
+    if (!defined('_FILE_CHMOD')) {
2482
+        define(
2483
+            '_FILE_CHMOD',
2484
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2485
+            : false)
2486
+        );
2487
+    }
2488
+
2489
+    if (!defined('_FILE_LDAP')) {
2490
+        define('_FILE_LDAP', 'ldap.php');
2491
+    }
2492
+
2493
+    if (!defined('_FILE_TMP_SUFFIX')) {
2494
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2495
+    }
2496
+    if (!defined('_FILE_CONNECT_TMP')) {
2497
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2498
+    }
2499
+    if (!defined('_FILE_CHMOD_TMP')) {
2500
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2501
+    }
2502
+
2503
+    // Definition des droits d'acces en ecriture
2504
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2505
+        include_once _FILE_CHMOD;
2506
+    }
2507
+
2508
+    // Se mefier des fichiers mal remplis!
2509
+    if (!defined('_SPIP_CHMOD')) {
2510
+        define('_SPIP_CHMOD', 0777);
2511
+    }
2512
+
2513
+    if (!defined('_DEFAULT_CHARSET')) {
2514
+        /** Le charset par défaut lors de l'installation */
2515
+        define('_DEFAULT_CHARSET', 'utf-8');
2516
+    }
2517
+    if (!defined('_ROOT_PLUGINS')) {
2518
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2519
+    }
2520
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2521
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2522
+    }
2523
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2524
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2525
+    }
2526
+
2527
+    // La taille des Log
2528
+    if (!defined('_MAX_LOG')) {
2529
+        define('_MAX_LOG', 100);
2530
+    }
2531
+
2532
+    // Sommes-nous dans l'empire du Mal ?
2533
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2534
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2535
+        if (!defined('_OS_SERVEUR')) {
2536
+            define('_OS_SERVEUR', 'windows');
2537
+        }
2538
+        if (!defined('_SPIP_LOCK_MODE')) {
2539
+            define('_SPIP_LOCK_MODE', 1);
2540
+        } // utiliser le flock php
2541
+    } else {
2542
+        if (!defined('_OS_SERVEUR')) {
2543
+            define('_OS_SERVEUR', '');
2544
+        }
2545
+        if (!defined('_SPIP_LOCK_MODE')) {
2546
+            define('_SPIP_LOCK_MODE', 1);
2547
+        } // utiliser le flock php
2548
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2549
+    }
2550
+
2551
+    // Langue par defaut
2552
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2553
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2554
+    }
2555
+
2556
+    //
2557
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2558
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2559
+    // pour le rendre surchargeable, on va provoquer un reecriture
2560
+    // systematique du noyau ou une baisse de perfs => a etudier)
2561
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2562
+
2563
+    // charger tout de suite le path et son cache
2564
+    load_path_cache();
2565
+
2566
+    // *********** traiter les variables ************
2567
+
2568
+    //
2569
+    // Securite
2570
+    //
2571
+
2572
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2573
+    if (isset($_REQUEST['GLOBALS'])) {
2574
+        die();
2575
+    }
2576
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2577
+    spip_desinfecte($_GET);
2578
+    spip_desinfecte($_POST);
2579
+    spip_desinfecte($_COOKIE);
2580
+    spip_desinfecte($_REQUEST);
2581
+
2582
+    // appliquer le cookie_prefix
2583
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2584
+        include_spip('inc/cookie');
2585
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2586
+    }
2587
+
2588
+    //
2589
+    // Capacites php (en fonction de la version)
2590
+    //
2591
+    $GLOBALS['flag_ob'] = (function_exists('ob_start')
2592
+        && function_exists('ini_get')
2593
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2594
+    $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2595
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2596
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2597
+        (get_cfg_var('upload_max_filesize') > 0));
2598
+
2599
+
2600
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2601
+    if (isset($_SERVER['REQUEST_URI'])) {
2602
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2603
+    } else {
2604
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2605
+        if (
2606
+            !empty($_SERVER['QUERY_STRING'])
2607
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2608
+        ) {
2609
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2610
+        }
2611
+    }
2612
+
2613
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2614
+    if (!defined('_RENOUVELLE_ALEA')) {
2615
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2616
+    }
2617
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2618
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2619
+    }
2620
+
2621
+    // charger les meta si possible et renouveller l'alea au besoin
2622
+    // charge aussi effacer_meta et ecrire_meta
2623
+    $inc_meta = charger_fonction('meta', 'inc');
2624
+    $inc_meta();
2625
+
2626
+    // nombre de repertoires depuis la racine
2627
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2628
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2629
+    // le calcul est faux)
2630
+    if (!_DIR_RESTREINT) {
2631
+        $GLOBALS['profondeur_url'] = 1;
2632
+    } else {
2633
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2634
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2635
+        if (
2636
+            !$uri_ref
2637
+            // si on est appele avec un autre ti, on est sans doute en mutu
2638
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2639
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2640
+            // s'en remettre a l'adresse du site. alea jacta est.
2641
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2642
+        ) {
2643
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2644
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2645
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2646
+            } else {
2647
+                $uri_ref = '';
2648
+            }
2649
+        }
2650
+        if (!$uri or !$uri_ref) {
2651
+            $GLOBALS['profondeur_url'] = 0;
2652
+        } else {
2653
+            $GLOBALS['profondeur_url'] = max(
2654
+                0,
2655
+                substr_count($uri[0], '/')
2656
+                - substr_count($uri_ref, '/')
2657
+            );
2658
+        }
2659
+    }
2660
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2661
+    if (_FILE_CONNECT) {
2662
+        if (
2663
+            verifier_visiteur() == '0minirezo'
2664
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2665
+            and !isset($_COOKIE['spip_admin'])
2666
+        ) {
2667
+            clear_path_cache();
2668
+        }
2669
+    }
2671 2670
 }
2672 2671
 
2673 2672
 /**
@@ -2676,186 +2675,186 @@  discard block
 block discarded – undo
2676 2675
  *
2677 2676
  */
2678 2677
 function spip_initialisation_suite() {
2679
-	static $too_late = 0;
2680
-	if ($too_late++) {
2681
-		return;
2682
-	}
2683
-
2684
-	// taille mini des login
2685
-	if (!defined('_LOGIN_TROP_COURT')) {
2686
-		define('_LOGIN_TROP_COURT', 4);
2687
-	}
2688
-
2689
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2690
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2691
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2692
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2693
-
2694
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2695
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2696
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2697
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2698
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2699
-
2700
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2701
-		define('_PASS_LONGUEUR_MINI', 6);
2702
-	}
2703
-
2704
-
2705
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2706
-	if (!defined('_IMG_QUALITE')) {
2707
-		define('_IMG_QUALITE', 85);
2708
-	} # valeur par defaut
2709
-	if (!defined('_IMG_GD_QUALITE')) {
2710
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2711
-	} # surcharge pour la lib GD
2712
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2713
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2714
-	} # surcharge pour imagick en ligne de commande
2715
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2716
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2717
-		define('_IMG_IMAGICK_QUALITE', 75);
2718
-	} # surcharge pour imagick en PHP
2719
-
2720
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2721
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2722
-	} // poids en octet
2723
-
2724
-	// qq chaines standard
2725
-	if (!defined('_ACCESS_FILE_NAME')) {
2726
-		define('_ACCESS_FILE_NAME', '.htaccess');
2727
-	}
2728
-	if (!defined('_AUTH_USER_FILE')) {
2729
-		define('_AUTH_USER_FILE', '.htpasswd');
2730
-	}
2731
-	if (!defined('_SPIP_DUMP')) {
2732
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2733
-	}
2734
-	if (!defined('_CACHE_RUBRIQUES')) {
2735
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2736
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2737
-	}
2738
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2739
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2740
-		define('_CACHE_RUBRIQUES_MAX', 500);
2741
-	}
2742
-
2743
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2744
-		/**
2745
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2746
-		 * @var int Nombre de caractères */
2747
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2748
-	}
2749
-
2750
-	if (!defined('_EXTENSION_SQUELETTES')) {
2751
-		define('_EXTENSION_SQUELETTES', 'html');
2752
-	}
2753
-
2754
-	if (!defined('_DOCTYPE_ECRIRE')) {
2755
-		/** Définit le doctype de l’espace privé */
2756
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2757
-	}
2758
-	if (!defined('_DOCTYPE_AIDE')) {
2759
-		/** Définit le doctype de l’aide en ligne */
2760
-		define(
2761
-			'_DOCTYPE_AIDE',
2762
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2763
-		);
2764
-	}
2765
-
2766
-	if (!defined('_SPIP_SCRIPT')) {
2767
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2768
-		 * le script de l'espace public, alias index.php */
2769
-		define('_SPIP_SCRIPT', 'spip.php');
2770
-	}
2771
-	if (!defined('_SPIP_PAGE')) {
2772
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2773
-		define('_SPIP_PAGE', 'page');
2774
-	}
2775
-
2776
-	// le script de l'espace prive
2777
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2778
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2779
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2780
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2781
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2782
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2783
-		} else {
2784
-			define('_SPIP_ECRIRE_SCRIPT', '');
2785
-		}
2786
-	}
2787
-
2788
-
2789
-	if (!defined('_SPIP_AJAX')) {
2790
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2791
-			? 1
2792
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2793
-	}
2794
-
2795
-	// La requete est-elle en ajax ?
2796
-	if (!defined('_AJAX')) {
2797
-		define(
2798
-			'_AJAX',
2799
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2800
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2801
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2802
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2803
-			)
2804
-			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
2805
-		);
2806
-	}
2807
-
2808
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2809
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2810
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2811
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2812
-		define(
2813
-			'_IMG_GD_MAX_PIXELS',
2814
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2815
-			? $GLOBALS['meta']['max_taille_vignettes']
2816
-			: 0
2817
-		);
2818
-	}
2819
-
2820
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2821
-		define('_MEMORY_LIMIT_MIN', 16);
2822
-	} // en Mo
2823
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2824
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2825
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2826
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2827
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2828
-			$unit = strtolower(substr($memory, -1));
2829
-			$memory = substr($memory, 0, -1);
2830
-			switch ($unit) {
2831
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2832
-				case 'g':
2833
-					$memory *= 1024;
2834
-				case 'm':
2835
-					$memory *= 1024;
2836
-				case 'k':
2837
-					$memory *= 1024;
2838
-			}
2839
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2840
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2841
-				if (trim(ini_get('memory_limit')) != $m) {
2842
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2843
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2844
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2845
-				}
2846
-			}
2847
-		} else {
2848
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2849
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2850
-			}
2851
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2852
-	}
2853
-	// Protocoles a normaliser dans les chaines de langues
2854
-	if (!defined('_PROTOCOLES_STD')) {
2855
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2856
-	}
2857
-
2858
-	init_var_mode();
2678
+    static $too_late = 0;
2679
+    if ($too_late++) {
2680
+        return;
2681
+    }
2682
+
2683
+    // taille mini des login
2684
+    if (!defined('_LOGIN_TROP_COURT')) {
2685
+        define('_LOGIN_TROP_COURT', 4);
2686
+    }
2687
+
2688
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2689
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2690
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2691
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2692
+
2693
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2694
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2695
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2696
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2697
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2698
+
2699
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2700
+        define('_PASS_LONGUEUR_MINI', 6);
2701
+    }
2702
+
2703
+
2704
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2705
+    if (!defined('_IMG_QUALITE')) {
2706
+        define('_IMG_QUALITE', 85);
2707
+    } # valeur par defaut
2708
+    if (!defined('_IMG_GD_QUALITE')) {
2709
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2710
+    } # surcharge pour la lib GD
2711
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2712
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2713
+    } # surcharge pour imagick en ligne de commande
2714
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2715
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2716
+        define('_IMG_IMAGICK_QUALITE', 75);
2717
+    } # surcharge pour imagick en PHP
2718
+
2719
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2720
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2721
+    } // poids en octet
2722
+
2723
+    // qq chaines standard
2724
+    if (!defined('_ACCESS_FILE_NAME')) {
2725
+        define('_ACCESS_FILE_NAME', '.htaccess');
2726
+    }
2727
+    if (!defined('_AUTH_USER_FILE')) {
2728
+        define('_AUTH_USER_FILE', '.htpasswd');
2729
+    }
2730
+    if (!defined('_SPIP_DUMP')) {
2731
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2732
+    }
2733
+    if (!defined('_CACHE_RUBRIQUES')) {
2734
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2735
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2736
+    }
2737
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2738
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2739
+        define('_CACHE_RUBRIQUES_MAX', 500);
2740
+    }
2741
+
2742
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2743
+        /**
2744
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2745
+         * @var int Nombre de caractères */
2746
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2747
+    }
2748
+
2749
+    if (!defined('_EXTENSION_SQUELETTES')) {
2750
+        define('_EXTENSION_SQUELETTES', 'html');
2751
+    }
2752
+
2753
+    if (!defined('_DOCTYPE_ECRIRE')) {
2754
+        /** Définit le doctype de l’espace privé */
2755
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2756
+    }
2757
+    if (!defined('_DOCTYPE_AIDE')) {
2758
+        /** Définit le doctype de l’aide en ligne */
2759
+        define(
2760
+            '_DOCTYPE_AIDE',
2761
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2762
+        );
2763
+    }
2764
+
2765
+    if (!defined('_SPIP_SCRIPT')) {
2766
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2767
+         * le script de l'espace public, alias index.php */
2768
+        define('_SPIP_SCRIPT', 'spip.php');
2769
+    }
2770
+    if (!defined('_SPIP_PAGE')) {
2771
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2772
+        define('_SPIP_PAGE', 'page');
2773
+    }
2774
+
2775
+    // le script de l'espace prive
2776
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2777
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2778
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2779
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2780
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2781
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2782
+        } else {
2783
+            define('_SPIP_ECRIRE_SCRIPT', '');
2784
+        }
2785
+    }
2786
+
2787
+
2788
+    if (!defined('_SPIP_AJAX')) {
2789
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2790
+            ? 1
2791
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2792
+    }
2793
+
2794
+    // La requete est-elle en ajax ?
2795
+    if (!defined('_AJAX')) {
2796
+        define(
2797
+            '_AJAX',
2798
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2799
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2800
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2801
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2802
+            )
2803
+            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
2804
+        );
2805
+    }
2806
+
2807
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2808
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2809
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2810
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2811
+        define(
2812
+            '_IMG_GD_MAX_PIXELS',
2813
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2814
+            ? $GLOBALS['meta']['max_taille_vignettes']
2815
+            : 0
2816
+        );
2817
+    }
2818
+
2819
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2820
+        define('_MEMORY_LIMIT_MIN', 16);
2821
+    } // en Mo
2822
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2823
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2824
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2825
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2826
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2827
+            $unit = strtolower(substr($memory, -1));
2828
+            $memory = substr($memory, 0, -1);
2829
+            switch ($unit) {
2830
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2831
+                case 'g':
2832
+                    $memory *= 1024;
2833
+                case 'm':
2834
+                    $memory *= 1024;
2835
+                case 'k':
2836
+                    $memory *= 1024;
2837
+            }
2838
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2839
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2840
+                if (trim(ini_get('memory_limit')) != $m) {
2841
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2842
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2843
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2844
+                }
2845
+            }
2846
+        } else {
2847
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2848
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2849
+            }
2850
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2851
+    }
2852
+    // Protocoles a normaliser dans les chaines de langues
2853
+    if (!defined('_PROTOCOLES_STD')) {
2854
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2855
+    }
2856
+
2857
+    init_var_mode();
2859 2858
 }
2860 2859
 
2861 2860
 /**
@@ -2889,136 +2888,136 @@  discard block
 block discarded – undo
2889 2888
  * `   var_mode` (calcul ou recalcul).
2890 2889
  */
2891 2890
 function init_var_mode() {
2892
-	static $done = false;
2893
-	if (!$done) {
2894
-		if (isset($_GET['var_mode'])) {
2895
-			$var_mode = explode(',', $_GET['var_mode']);
2896
-			// tout le monde peut calcul/recalcul
2897
-			if (!defined('_VAR_MODE')) {
2898
-				if (in_array('recalcul', $var_mode)) {
2899
-					define('_VAR_MODE', 'recalcul');
2900
-				} elseif (in_array('calcul', $var_mode)) {
2901
-					define('_VAR_MODE', 'calcul');
2902
-				}
2903
-			}
2904
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2905
-			if ($var_mode) {
2906
-				include_spip('inc/autoriser');
2907
-				// autoriser preview si preview seulement, et sinon autoriser debug
2908
-				if (
2909
-					autoriser(
2910
-						($_GET['var_mode'] == 'preview')
2911
-						? 'previsualiser'
2912
-						: 'debug'
2913
-					)
2914
-				) {
2915
-					if (in_array('traduction', $var_mode)) {
2916
-						// forcer le calcul pour passer dans traduire
2917
-						if (!defined('_VAR_MODE')) {
2918
-							define('_VAR_MODE', 'calcul');
2919
-						}
2920
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2921
-						if (!defined('_VAR_NOCACHE')) {
2922
-							define('_VAR_NOCACHE', true);
2923
-						}
2924
-						$var_mode = array_diff($var_mode, ['traduction']);
2925
-					}
2926
-					if (in_array('preview', $var_mode)) {
2927
-						// basculer sur les criteres de preview dans les boucles
2928
-						if (!defined('_VAR_PREVIEW')) {
2929
-							define('_VAR_PREVIEW', true);
2930
-						}
2931
-						// forcer le calcul
2932
-						if (!defined('_VAR_MODE')) {
2933
-							define('_VAR_MODE', 'calcul');
2934
-						}
2935
-						// et ne pas enregistrer de cache
2936
-						if (!defined('_VAR_NOCACHE')) {
2937
-							define('_VAR_NOCACHE', true);
2938
-						}
2939
-						$var_mode = array_diff($var_mode, ['preview']);
2940
-					}
2941
-					if (in_array('inclure', $var_mode)) {
2942
-						// forcer le compilo et ignorer les caches existants
2943
-						if (!defined('_VAR_MODE')) {
2944
-							define('_VAR_MODE', 'calcul');
2945
-						}
2946
-						if (!defined('_VAR_INCLURE')) {
2947
-							define('_VAR_INCLURE', true);
2948
-						}
2949
-						// et ne pas enregistrer de cache
2950
-						if (!defined('_VAR_NOCACHE')) {
2951
-							define('_VAR_NOCACHE', true);
2952
-						}
2953
-						$var_mode = array_diff($var_mode, ['inclure']);
2954
-					}
2955
-					if (in_array('urls', $var_mode)) {
2956
-						// forcer le compilo et ignorer les caches existants
2957
-						if (!defined('_VAR_MODE')) {
2958
-							define('_VAR_MODE', 'calcul');
2959
-						}
2960
-						if (!defined('_VAR_URLS')) {
2961
-							define('_VAR_URLS', true);
2962
-						}
2963
-						$var_mode = array_diff($var_mode, ['urls']);
2964
-					}
2965
-					if (in_array('images', $var_mode)) {
2966
-						// forcer le compilo et ignorer les caches existants
2967
-						if (!defined('_VAR_MODE')) {
2968
-							define('_VAR_MODE', 'calcul');
2969
-						}
2970
-						// indiquer qu'on doit recalculer les images
2971
-						if (!defined('_VAR_IMAGES')) {
2972
-							define('_VAR_IMAGES', true);
2973
-						}
2974
-						$var_mode = array_diff($var_mode, ['images']);
2975
-					}
2976
-					if (in_array('debug', $var_mode)) {
2977
-						if (!defined('_VAR_MODE')) {
2978
-							define('_VAR_MODE', 'debug');
2979
-						}
2980
-						// et ne pas enregistrer de cache
2981
-						if (!defined('_VAR_NOCACHE')) {
2982
-							define('_VAR_NOCACHE', true);
2983
-						}
2984
-						$var_mode = array_diff($var_mode, ['debug']);
2985
-					}
2986
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2987
-						define('_VAR_MODE', reset($var_mode));
2988
-					}
2989
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2990
-						spip_log($GLOBALS['visiteur_session']['nom']
2991
-							. ' ' . _VAR_MODE);
2992
-					}
2993
-				} // pas autorise ?
2994
-				else {
2995
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
2996
-					if (
2997
-						!$GLOBALS['visiteur_session']
2998
-						and !empty($_SERVER['HTTP_HOST'])
2999
-						and !empty($_SERVER['REQUEST_METHOD'])
3000
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3001
-					) {
3002
-						$self = self('&', true);
3003
-						if (strpos($self, 'page=login') === false) {
3004
-							include_spip('inc/headers');
3005
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3006
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3007
-						}
3008
-					}
3009
-					// sinon tant pis
3010
-				}
3011
-			}
3012
-		}
3013
-		if (!defined('_VAR_MODE')) {
3014
-			/**
3015
-			 * Indique le mode de calcul ou d'affichage de la page.
3016
-			 * @see init_var_mode()
3017
-			 */
3018
-			define('_VAR_MODE', false);
3019
-		}
3020
-		$done = true;
3021
-	}
2891
+    static $done = false;
2892
+    if (!$done) {
2893
+        if (isset($_GET['var_mode'])) {
2894
+            $var_mode = explode(',', $_GET['var_mode']);
2895
+            // tout le monde peut calcul/recalcul
2896
+            if (!defined('_VAR_MODE')) {
2897
+                if (in_array('recalcul', $var_mode)) {
2898
+                    define('_VAR_MODE', 'recalcul');
2899
+                } elseif (in_array('calcul', $var_mode)) {
2900
+                    define('_VAR_MODE', 'calcul');
2901
+                }
2902
+            }
2903
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2904
+            if ($var_mode) {
2905
+                include_spip('inc/autoriser');
2906
+                // autoriser preview si preview seulement, et sinon autoriser debug
2907
+                if (
2908
+                    autoriser(
2909
+                        ($_GET['var_mode'] == 'preview')
2910
+                        ? 'previsualiser'
2911
+                        : 'debug'
2912
+                    )
2913
+                ) {
2914
+                    if (in_array('traduction', $var_mode)) {
2915
+                        // forcer le calcul pour passer dans traduire
2916
+                        if (!defined('_VAR_MODE')) {
2917
+                            define('_VAR_MODE', 'calcul');
2918
+                        }
2919
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2920
+                        if (!defined('_VAR_NOCACHE')) {
2921
+                            define('_VAR_NOCACHE', true);
2922
+                        }
2923
+                        $var_mode = array_diff($var_mode, ['traduction']);
2924
+                    }
2925
+                    if (in_array('preview', $var_mode)) {
2926
+                        // basculer sur les criteres de preview dans les boucles
2927
+                        if (!defined('_VAR_PREVIEW')) {
2928
+                            define('_VAR_PREVIEW', true);
2929
+                        }
2930
+                        // forcer le calcul
2931
+                        if (!defined('_VAR_MODE')) {
2932
+                            define('_VAR_MODE', 'calcul');
2933
+                        }
2934
+                        // et ne pas enregistrer de cache
2935
+                        if (!defined('_VAR_NOCACHE')) {
2936
+                            define('_VAR_NOCACHE', true);
2937
+                        }
2938
+                        $var_mode = array_diff($var_mode, ['preview']);
2939
+                    }
2940
+                    if (in_array('inclure', $var_mode)) {
2941
+                        // forcer le compilo et ignorer les caches existants
2942
+                        if (!defined('_VAR_MODE')) {
2943
+                            define('_VAR_MODE', 'calcul');
2944
+                        }
2945
+                        if (!defined('_VAR_INCLURE')) {
2946
+                            define('_VAR_INCLURE', true);
2947
+                        }
2948
+                        // et ne pas enregistrer de cache
2949
+                        if (!defined('_VAR_NOCACHE')) {
2950
+                            define('_VAR_NOCACHE', true);
2951
+                        }
2952
+                        $var_mode = array_diff($var_mode, ['inclure']);
2953
+                    }
2954
+                    if (in_array('urls', $var_mode)) {
2955
+                        // forcer le compilo et ignorer les caches existants
2956
+                        if (!defined('_VAR_MODE')) {
2957
+                            define('_VAR_MODE', 'calcul');
2958
+                        }
2959
+                        if (!defined('_VAR_URLS')) {
2960
+                            define('_VAR_URLS', true);
2961
+                        }
2962
+                        $var_mode = array_diff($var_mode, ['urls']);
2963
+                    }
2964
+                    if (in_array('images', $var_mode)) {
2965
+                        // forcer le compilo et ignorer les caches existants
2966
+                        if (!defined('_VAR_MODE')) {
2967
+                            define('_VAR_MODE', 'calcul');
2968
+                        }
2969
+                        // indiquer qu'on doit recalculer les images
2970
+                        if (!defined('_VAR_IMAGES')) {
2971
+                            define('_VAR_IMAGES', true);
2972
+                        }
2973
+                        $var_mode = array_diff($var_mode, ['images']);
2974
+                    }
2975
+                    if (in_array('debug', $var_mode)) {
2976
+                        if (!defined('_VAR_MODE')) {
2977
+                            define('_VAR_MODE', 'debug');
2978
+                        }
2979
+                        // et ne pas enregistrer de cache
2980
+                        if (!defined('_VAR_NOCACHE')) {
2981
+                            define('_VAR_NOCACHE', true);
2982
+                        }
2983
+                        $var_mode = array_diff($var_mode, ['debug']);
2984
+                    }
2985
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2986
+                        define('_VAR_MODE', reset($var_mode));
2987
+                    }
2988
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2989
+                        spip_log($GLOBALS['visiteur_session']['nom']
2990
+                            . ' ' . _VAR_MODE);
2991
+                    }
2992
+                } // pas autorise ?
2993
+                else {
2994
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
2995
+                    if (
2996
+                        !$GLOBALS['visiteur_session']
2997
+                        and !empty($_SERVER['HTTP_HOST'])
2998
+                        and !empty($_SERVER['REQUEST_METHOD'])
2999
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3000
+                    ) {
3001
+                        $self = self('&', true);
3002
+                        if (strpos($self, 'page=login') === false) {
3003
+                            include_spip('inc/headers');
3004
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3005
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3006
+                        }
3007
+                    }
3008
+                    // sinon tant pis
3009
+                }
3010
+            }
3011
+        }
3012
+        if (!defined('_VAR_MODE')) {
3013
+            /**
3014
+             * Indique le mode de calcul ou d'affichage de la page.
3015
+             * @see init_var_mode()
3016
+             */
3017
+            define('_VAR_MODE', false);
3018
+        }
3019
+        $done = true;
3020
+    }
3022 3021
 }
3023 3022
 
3024 3023
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -3026,84 +3025,84 @@  discard block
 block discarded – undo
3026 3025
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
3027 3026
 // https://code.spip.net/@spip_desinfecte
3028 3027
 function spip_desinfecte(&$t, $deep = true) {
3029
-	foreach ($t as $key => $val) {
3030
-		if (is_string($t[$key])) {
3031
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3032
-		} // traiter aussi les "texte_plus" de article_edit
3033
-		else {
3034
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3035
-				spip_desinfecte($t[$key], $deep);
3036
-			}
3037
-		}
3038
-	}
3028
+    foreach ($t as $key => $val) {
3029
+        if (is_string($t[$key])) {
3030
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3031
+        } // traiter aussi les "texte_plus" de article_edit
3032
+        else {
3033
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3034
+                spip_desinfecte($t[$key], $deep);
3035
+            }
3036
+        }
3037
+    }
3039 3038
 }
3040 3039
 
3041 3040
 //  retourne le statut du visiteur s'il s'annonce
3042 3041
 
3043 3042
 // https://code.spip.net/@verifier_visiteur
3044 3043
 function verifier_visiteur() {
3045
-	// Rq: pour que cette fonction marche depuis mes_options
3046
-	// il faut forcer l'init si ce n'est fait
3047
-	// mais on risque de perturber des plugins en initialisant trop tot
3048
-	// certaines constantes
3049
-	@spip_initialisation_core(
3050
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3051
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3052
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3053
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3054
-	);
3055
-
3056
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3057
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3058
-	// Attention on separe bien session_nom et nom, pour eviter
3059
-	// les melanges entre donnees SQL et variables plus aleatoires
3060
-	$variables_session = ['session_nom', 'session_email'];
3061
-	foreach ($variables_session as $var) {
3062
-		if (_request($var) !== null) {
3063
-			$init = true;
3064
-			break;
3065
-		}
3066
-	}
3067
-	if (isset($init)) {
3068
-		#@spip_initialisation_suite();
3069
-		$session = charger_fonction('session', 'inc');
3070
-		$session();
3071
-		include_spip('inc/texte');
3072
-		foreach ($variables_session as $var) {
3073
-			if (($a = _request($var)) !== null) {
3074
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3075
-			}
3076
-		}
3077
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3078
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3079
-		}
3080
-		$session($GLOBALS['visiteur_session']);
3081
-
3082
-		return 0;
3083
-	}
3084
-
3085
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3086
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3087
-		$session = charger_fonction('session', 'inc');
3088
-		if ($session()) {
3089
-			return $GLOBALS['visiteur_session']['statut'];
3090
-		}
3091
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3092
-			include_spip('inc/auth');
3093
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3094
-		}
3095
-		if ($h) {
3096
-			$GLOBALS['visiteur_session'] = $h;
3097
-
3098
-			return $GLOBALS['visiteur_session']['statut'];
3099
-		}
3100
-	}
3101
-
3102
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3103
-	include_spip('inc/lang');
3104
-	utiliser_langue_visiteur();
3105
-
3106
-	return false;
3044
+    // Rq: pour que cette fonction marche depuis mes_options
3045
+    // il faut forcer l'init si ce n'est fait
3046
+    // mais on risque de perturber des plugins en initialisant trop tot
3047
+    // certaines constantes
3048
+    @spip_initialisation_core(
3049
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3050
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3051
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3052
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3053
+    );
3054
+
3055
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3056
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3057
+    // Attention on separe bien session_nom et nom, pour eviter
3058
+    // les melanges entre donnees SQL et variables plus aleatoires
3059
+    $variables_session = ['session_nom', 'session_email'];
3060
+    foreach ($variables_session as $var) {
3061
+        if (_request($var) !== null) {
3062
+            $init = true;
3063
+            break;
3064
+        }
3065
+    }
3066
+    if (isset($init)) {
3067
+        #@spip_initialisation_suite();
3068
+        $session = charger_fonction('session', 'inc');
3069
+        $session();
3070
+        include_spip('inc/texte');
3071
+        foreach ($variables_session as $var) {
3072
+            if (($a = _request($var)) !== null) {
3073
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3074
+            }
3075
+        }
3076
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3077
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3078
+        }
3079
+        $session($GLOBALS['visiteur_session']);
3080
+
3081
+        return 0;
3082
+    }
3083
+
3084
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3085
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3086
+        $session = charger_fonction('session', 'inc');
3087
+        if ($session()) {
3088
+            return $GLOBALS['visiteur_session']['statut'];
3089
+        }
3090
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3091
+            include_spip('inc/auth');
3092
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3093
+        }
3094
+        if ($h) {
3095
+            $GLOBALS['visiteur_session'] = $h;
3096
+
3097
+            return $GLOBALS['visiteur_session']['statut'];
3098
+        }
3099
+    }
3100
+
3101
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3102
+    include_spip('inc/lang');
3103
+    utiliser_langue_visiteur();
3104
+
3105
+    return false;
3107 3106
 }
3108 3107
 
3109 3108
 
@@ -3126,21 +3125,21 @@  discard block
 block discarded – undo
3126 3125
  *     - string Langue utilisée.
3127 3126
  **/
3128 3127
 function lang_select($lang = null) {
3129
-	static $pile_langues = [];
3130
-	if (!function_exists('changer_langue')) {
3131
-		include_spip('inc/lang');
3132
-	}
3133
-	if ($lang === null) {
3134
-		$lang = array_pop($pile_langues);
3135
-	} else {
3136
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3137
-	}
3138
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3139
-		return $lang;
3140
-	}
3141
-	changer_langue($lang);
3128
+    static $pile_langues = [];
3129
+    if (!function_exists('changer_langue')) {
3130
+        include_spip('inc/lang');
3131
+    }
3132
+    if ($lang === null) {
3133
+        $lang = array_pop($pile_langues);
3134
+    } else {
3135
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3136
+    }
3137
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3138
+        return $lang;
3139
+    }
3140
+    changer_langue($lang);
3142 3141
 
3143
-	return $lang;
3142
+    return $lang;
3144 3143
 }
3145 3144
 
3146 3145
 /**
@@ -3157,20 +3156,20 @@  discard block
 block discarded – undo
3157 3156
  *     Identifiant de la session
3158 3157
  **/
3159 3158
 function spip_session($force = false) {
3160
-	static $session;
3161
-	if ($force or !isset($session)) {
3162
-		$s = pipeline(
3163
-			'definir_session',
3164
-			$GLOBALS['visiteur_session']
3165
-				? serialize($GLOBALS['visiteur_session'])
3166
-				. '_' . @$_COOKIE['spip_session']
3167
-				: ''
3168
-		);
3169
-		$session = $s ? substr(md5($s), 0, 8) : '';
3170
-	}
3159
+    static $session;
3160
+    if ($force or !isset($session)) {
3161
+        $s = pipeline(
3162
+            'definir_session',
3163
+            $GLOBALS['visiteur_session']
3164
+                ? serialize($GLOBALS['visiteur_session'])
3165
+                . '_' . @$_COOKIE['spip_session']
3166
+                : ''
3167
+        );
3168
+        $session = $s ? substr(md5($s), 0, 8) : '';
3169
+    }
3171 3170
 
3172
-	#spip_log('session: '.$session);
3173
-	return $session;
3171
+    #spip_log('session: '.$session);
3172
+    return $session;
3174 3173
 }
3175 3174
 
3176 3175
 
@@ -3189,9 +3188,9 @@  discard block
 block discarded – undo
3189 3188
  *    Lien sur une icone d'aide
3190 3189
  **/
3191 3190
 function aider($aide = '', $distante = false) {
3192
-	$aider = charger_fonction('aide', 'inc', true);
3191
+    $aider = charger_fonction('aide', 'inc', true);
3193 3192
 
3194
-	return $aider ? $aider($aide, '', [], $distante) : '';
3193
+    return $aider ? $aider($aide, '', [], $distante) : '';
3195 3194
 }
3196 3195
 
3197 3196
 /**
@@ -3201,24 +3200,24 @@  discard block
 block discarded – undo
3201 3200
  */
3202 3201
 function exec_info_dist() {
3203 3202
 
3204
-	include_spip('inc/autoriser');
3205
-	if (autoriser('phpinfos')) {
3206
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3207
-		$cookies_backup = [];
3208
-		foreach ($cookies_masques as $k) {
3209
-			if (!empty($_COOKIE[$k])) {
3210
-				$cookies_backup[$k] = $_COOKIE[$k];
3211
-				$_COOKIE[$k] = '******************************';
3212
-			}
3213
-		}
3214
-		phpinfo();
3215
-		foreach ($cookies_backup as $k => $v) {
3216
-			$_COOKIE[$k] = $v;
3217
-		}
3218
-	} else {
3219
-		include_spip('inc/filtres');
3220
-		sinon_interdire_acces();
3221
-	}
3203
+    include_spip('inc/autoriser');
3204
+    if (autoriser('phpinfos')) {
3205
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3206
+        $cookies_backup = [];
3207
+        foreach ($cookies_masques as $k) {
3208
+            if (!empty($_COOKIE[$k])) {
3209
+                $cookies_backup[$k] = $_COOKIE[$k];
3210
+                $_COOKIE[$k] = '******************************';
3211
+            }
3212
+        }
3213
+        phpinfo();
3214
+        foreach ($cookies_backup as $k => $v) {
3215
+            $_COOKIE[$k] = $v;
3216
+        }
3217
+    } else {
3218
+        include_spip('inc/filtres');
3219
+        sinon_interdire_acces();
3220
+    }
3222 3221
 }
3223 3222
 
3224 3223
 /**
@@ -3238,13 +3237,13 @@  discard block
 block discarded – undo
3238 3237
  *     - string si $message à false.
3239 3238
  **/
3240 3239
 function erreur_squelette($message = '', $lieu = '') {
3241
-	$debusquer = charger_fonction('debusquer', 'public');
3242
-	if (is_array($lieu)) {
3243
-		include_spip('public/compiler');
3244
-		$lieu = reconstruire_contexte_compil($lieu);
3245
-	}
3240
+    $debusquer = charger_fonction('debusquer', 'public');
3241
+    if (is_array($lieu)) {
3242
+        include_spip('public/compiler');
3243
+        $lieu = reconstruire_contexte_compil($lieu);
3244
+    }
3246 3245
 
3247
-	return $debusquer($message, $lieu);
3246
+    return $debusquer($message, $lieu);
3248 3247
 }
3249 3248
 
3250 3249
 /**
@@ -3281,108 +3280,108 @@  discard block
 block discarded – undo
3281 3280
  *     - ou tableau d'information sur le squelette.
3282 3281
  */
3283 3282
 function recuperer_fond($fond, $contexte = [], $options = [], $connect = '') {
3284
-	if (!function_exists('evaluer_fond')) {
3285
-		include_spip('public/assembler');
3286
-	}
3287
-	// assurer la compat avec l'ancienne syntaxe
3288
-	// (trim etait le 3eme argument, par defaut a true)
3289
-	if (!is_array($options)) {
3290
-		$options = ['trim' => $options];
3291
-	}
3292
-	if (!isset($options['trim'])) {
3293
-		$options['trim'] = true;
3294
-	}
3295
-
3296
-	if (isset($contexte['connect'])) {
3297
-		$connect = $contexte['connect'];
3298
-		unset($contexte['connect']);
3299
-	}
3300
-
3301
-	$texte = '';
3302
-	$pages = [];
3303
-	$lang_select = '';
3304
-	if (!isset($options['etoile']) or !$options['etoile']) {
3305
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3306
-		if (!isset($contexte['lang'])) {
3307
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3308
-		}
3309
-
3310
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3311
-			$lang_select = lang_select($contexte['lang']);
3312
-		}
3313
-	}
3314
-
3315
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3316
-		$GLOBALS['_INC_PUBLIC'] = 0;
3317
-	}
3318
-
3319
-	$GLOBALS['_INC_PUBLIC']++;
3320
-
3321
-	// fix #4235
3322
-	$cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3323
-
3324
-
3325
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3326
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3327
-
3328
-		$page = evaluer_fond($f, $contexte, $connect);
3329
-		if ($page === '') {
3330
-			$c = isset($options['compil']) ? $options['compil'] : '';
3331
-			$a = ['fichier' => $f];
3332
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3333
-			erreur_squelette($erreur, $c);
3334
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3335
-			$page = ['texte' => '', 'erreur' => $erreur];
3336
-		}
3337
-
3338
-		$page = pipeline('recuperer_fond', [
3339
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3340
-			'data' => $page
3341
-		]);
3342
-		if (isset($options['ajax']) and $options['ajax']) {
3343
-			if (!function_exists('encoder_contexte_ajax')) {
3344
-				include_spip('inc/filtres');
3345
-			}
3346
-			$page['texte'] = encoder_contexte_ajax(
3347
-				array_merge(
3348
-					$contexte,
3349
-					['fond' => $f],
3350
-					($connect ? ['connect' => $connect] : [])
3351
-				),
3352
-				'',
3353
-				$page['texte'],
3354
-				$options['ajax']
3355
-			);
3356
-		}
3357
-
3358
-		if (isset($options['raw']) and $options['raw']) {
3359
-			$pages[] = $page;
3360
-		} else {
3361
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3362
-		}
3363
-
3364
-		// contamination de la session appelante, pour les inclusions statiques
3365
-		if (isset($page['invalideurs']['session'])) {
3366
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3367
-		}
3368
-	}
3369
-
3370
-	// restaurer le sessionnement du contexte appelant,
3371
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3372
-	if (isset($cache_utilise_session_appelant)) {
3373
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3374
-	}
3375
-
3376
-	$GLOBALS['_INC_PUBLIC']--;
3377
-
3378
-	if ($lang_select) {
3379
-		lang_select();
3380
-	}
3381
-	if (isset($options['raw']) and $options['raw']) {
3382
-		return is_array($fond) ? $pages : reset($pages);
3383
-	} else {
3384
-		return $options['trim'] ? ltrim($texte) : $texte;
3385
-	}
3283
+    if (!function_exists('evaluer_fond')) {
3284
+        include_spip('public/assembler');
3285
+    }
3286
+    // assurer la compat avec l'ancienne syntaxe
3287
+    // (trim etait le 3eme argument, par defaut a true)
3288
+    if (!is_array($options)) {
3289
+        $options = ['trim' => $options];
3290
+    }
3291
+    if (!isset($options['trim'])) {
3292
+        $options['trim'] = true;
3293
+    }
3294
+
3295
+    if (isset($contexte['connect'])) {
3296
+        $connect = $contexte['connect'];
3297
+        unset($contexte['connect']);
3298
+    }
3299
+
3300
+    $texte = '';
3301
+    $pages = [];
3302
+    $lang_select = '';
3303
+    if (!isset($options['etoile']) or !$options['etoile']) {
3304
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3305
+        if (!isset($contexte['lang'])) {
3306
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3307
+        }
3308
+
3309
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3310
+            $lang_select = lang_select($contexte['lang']);
3311
+        }
3312
+    }
3313
+
3314
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3315
+        $GLOBALS['_INC_PUBLIC'] = 0;
3316
+    }
3317
+
3318
+    $GLOBALS['_INC_PUBLIC']++;
3319
+
3320
+    // fix #4235
3321
+    $cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3322
+
3323
+
3324
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3325
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3326
+
3327
+        $page = evaluer_fond($f, $contexte, $connect);
3328
+        if ($page === '') {
3329
+            $c = isset($options['compil']) ? $options['compil'] : '';
3330
+            $a = ['fichier' => $f];
3331
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3332
+            erreur_squelette($erreur, $c);
3333
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3334
+            $page = ['texte' => '', 'erreur' => $erreur];
3335
+        }
3336
+
3337
+        $page = pipeline('recuperer_fond', [
3338
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3339
+            'data' => $page
3340
+        ]);
3341
+        if (isset($options['ajax']) and $options['ajax']) {
3342
+            if (!function_exists('encoder_contexte_ajax')) {
3343
+                include_spip('inc/filtres');
3344
+            }
3345
+            $page['texte'] = encoder_contexte_ajax(
3346
+                array_merge(
3347
+                    $contexte,
3348
+                    ['fond' => $f],
3349
+                    ($connect ? ['connect' => $connect] : [])
3350
+                ),
3351
+                '',
3352
+                $page['texte'],
3353
+                $options['ajax']
3354
+            );
3355
+        }
3356
+
3357
+        if (isset($options['raw']) and $options['raw']) {
3358
+            $pages[] = $page;
3359
+        } else {
3360
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3361
+        }
3362
+
3363
+        // contamination de la session appelante, pour les inclusions statiques
3364
+        if (isset($page['invalideurs']['session'])) {
3365
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3366
+        }
3367
+    }
3368
+
3369
+    // restaurer le sessionnement du contexte appelant,
3370
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3371
+    if (isset($cache_utilise_session_appelant)) {
3372
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3373
+    }
3374
+
3375
+    $GLOBALS['_INC_PUBLIC']--;
3376
+
3377
+    if ($lang_select) {
3378
+        lang_select();
3379
+    }
3380
+    if (isset($options['raw']) and $options['raw']) {
3381
+        return is_array($fond) ? $pages : reset($pages);
3382
+    } else {
3383
+        return $options['trim'] ? ltrim($texte) : $texte;
3384
+    }
3386 3385
 }
3387 3386
 
3388 3387
 /**
@@ -3392,7 +3391,7 @@  discard block
 block discarded – undo
3392 3391
  * @return string
3393 3392
  */
3394 3393
 function trouve_modele($nom) {
3395
-	return trouver_fond($nom, 'modeles/');
3394
+    return trouver_fond($nom, 'modeles/');
3396 3395
 }
3397 3396
 
3398 3397
 /**
@@ -3408,21 +3407,21 @@  discard block
 block discarded – undo
3408 3407
  * @return array|string
3409 3408
  */
3410 3409
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3411
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3412
-	if (!$pathinfo) {
3413
-		return $f;
3414
-	}
3415
-	// renvoyer un tableau detaille si $pathinfo==true
3416
-	$p = pathinfo($f);
3417
-	if (!isset($p['extension']) or !$p['extension']) {
3418
-		$p['extension'] = _EXTENSION_SQUELETTES;
3419
-	}
3420
-	if (!isset($p['extension']) or !$p['filename']) {
3421
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3422
-	}
3423
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3410
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3411
+    if (!$pathinfo) {
3412
+        return $f;
3413
+    }
3414
+    // renvoyer un tableau detaille si $pathinfo==true
3415
+    $p = pathinfo($f);
3416
+    if (!isset($p['extension']) or !$p['extension']) {
3417
+        $p['extension'] = _EXTENSION_SQUELETTES;
3418
+    }
3419
+    if (!isset($p['extension']) or !$p['filename']) {
3420
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3421
+    }
3422
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3424 3423
 
3425
-	return $p;
3424
+    return $p;
3426 3425
 }
3427 3426
 
3428 3427
 /**
@@ -3442,21 +3441,21 @@  discard block
 block discarded – undo
3442 3441
  *     Nom de l'exec, sinon chaîne vide.
3443 3442
  **/
3444 3443
 function tester_url_ecrire($nom) {
3445
-	static $exec = [];
3446
-	if (isset($exec[$nom])) {
3447
-		return $exec[$nom];
3448
-	}
3449
-	// tester si c'est une page en squelette
3450
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3451
-		return $exec[$nom] = 'fond';
3452
-	} // echafaudage d'un fond !
3453
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3454
-		return $exec[$nom] = 'fond';
3455
-	}
3456
-	// attention, il ne faut pas inclure l'exec ici
3457
-	// car sinon #URL_ECRIRE provoque des inclusions
3458
-	// et des define intrusifs potentiels
3459
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3444
+    static $exec = [];
3445
+    if (isset($exec[$nom])) {
3446
+        return $exec[$nom];
3447
+    }
3448
+    // tester si c'est une page en squelette
3449
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3450
+        return $exec[$nom] = 'fond';
3451
+    } // echafaudage d'un fond !
3452
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3453
+        return $exec[$nom] = 'fond';
3454
+    }
3455
+    // attention, il ne faut pas inclure l'exec ici
3456
+    // car sinon #URL_ECRIRE provoque des inclusions
3457
+    // et des define intrusifs potentiels
3458
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3460 3459
 }
3461 3460
 
3462 3461
 /**
@@ -3466,8 +3465,8 @@  discard block
 block discarded – undo
3466 3465
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3467 3466
  **/
3468 3467
 function html5_permis() {
3469
-	return (!defined('_VERSION_HTML')
3470
-		or _VERSION_HTML !== 'html4');
3468
+    return (!defined('_VERSION_HTML')
3469
+        or _VERSION_HTML !== 'html4');
3471 3470
 }
3472 3471
 
3473 3472
 /**
@@ -3477,30 +3476,30 @@  discard block
 block discarded – undo
3477 3476
  * @return array
3478 3477
  */
3479 3478
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3480
-	$formats = null;
3481
-	if (!is_null($gd)) {
3482
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3483
-		if (isset($GLOBALS['meta'][$config])) {
3484
-			$formats = $GLOBALS['meta'][$config];
3485
-			$formats = explode(',', $formats);
3486
-			$formats = array_filter($formats);
3487
-			$formats = array_map('trim', $formats);
3488
-		}
3489
-	}
3490
-	if (is_null($formats)) {
3491
-		include_spip('inc/filtres_images_lib_mini');
3492
-		$formats = _image_extensions_acceptees_en_entree();
3493
-	}
3494
-
3495
-	if ($svg_allowed) {
3496
-		if (!in_array('svg', $formats)) {
3497
-			$formats[] = 'svg';
3498
-		}
3499
-	}
3500
-	else {
3501
-		$formats = array_diff($formats, ['svg']);
3502
-	}
3503
-	return $formats;
3479
+    $formats = null;
3480
+    if (!is_null($gd)) {
3481
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3482
+        if (isset($GLOBALS['meta'][$config])) {
3483
+            $formats = $GLOBALS['meta'][$config];
3484
+            $formats = explode(',', $formats);
3485
+            $formats = array_filter($formats);
3486
+            $formats = array_map('trim', $formats);
3487
+        }
3488
+    }
3489
+    if (is_null($formats)) {
3490
+        include_spip('inc/filtres_images_lib_mini');
3491
+        $formats = _image_extensions_acceptees_en_entree();
3492
+    }
3493
+
3494
+    if ($svg_allowed) {
3495
+        if (!in_array('svg', $formats)) {
3496
+            $formats[] = 'svg';
3497
+        }
3498
+    }
3499
+    else {
3500
+        $formats = array_diff($formats, ['svg']);
3501
+    }
3502
+    return $formats;
3504 3503
 }
3505 3504
 
3506 3505
 /**
@@ -3509,20 +3508,20 @@  discard block
 block discarded – undo
3509 3508
  * @return array|bool
3510 3509
  */
3511 3510
 function spip_getimagesize($fichier) {
3512
-	if (!$imagesize = @getimagesize($fichier)) {
3513
-		include_spip('inc/svg');
3514
-		if ($attrs = svg_lire_attributs($fichier)) {
3515
-			list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3516
-			$imagesize = [
3517
-				$width,
3518
-				$height,
3519
-				IMAGETYPE_SVG,
3520
-				"width=\"{$width}\" height=\"{$height}\"",
3521
-				'mime' => 'image/svg+xml'
3522
-			];
3523
-		}
3524
-	}
3525
-	return $imagesize;
3511
+    if (!$imagesize = @getimagesize($fichier)) {
3512
+        include_spip('inc/svg');
3513
+        if ($attrs = svg_lire_attributs($fichier)) {
3514
+            list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3515
+            $imagesize = [
3516
+                $width,
3517
+                $height,
3518
+                IMAGETYPE_SVG,
3519
+                "width=\"{$width}\" height=\"{$height}\"",
3520
+                'mime' => 'image/svg+xml'
3521
+            ];
3522
+        }
3523
+    }
3524
+    return $imagesize;
3526 3525
 }
3527 3526
 
3528 3527
 /**
@@ -3536,19 +3535,19 @@  discard block
 block discarded – undo
3536 3535
  * @param string $statut
3537 3536
  */
3538 3537
 function avertir_auteurs($nom, $message, $statut = '') {
3539
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3540
-	if (
3541
-		!$alertes
3542
-		or !is_array($alertes = unserialize($alertes))
3543
-	) {
3544
-		$alertes = [];
3545
-	}
3538
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3539
+    if (
3540
+        !$alertes
3541
+        or !is_array($alertes = unserialize($alertes))
3542
+    ) {
3543
+        $alertes = [];
3544
+    }
3546 3545
 
3547
-	if (!isset($alertes[$statut])) {
3548
-		$alertes[$statut] = [];
3549
-	}
3550
-	$alertes[$statut][$nom] = $message;
3551
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3546
+    if (!isset($alertes[$statut])) {
3547
+        $alertes[$statut] = [];
3548
+    }
3549
+    $alertes[$statut][$nom] = $message;
3550
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3552 3551
 }
3553 3552
 
3554 3553
 /**
@@ -3562,10 +3561,10 @@  discard block
 block discarded – undo
3562 3561
  * @return string|string[]
3563 3562
  */
3564 3563
 function spip_sanitize_classname($classes) {
3565
-	if (is_array($classes)) {
3566
-		return array_map('spip_sanitize_classname', $classes);
3567
-	}
3568
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3564
+    if (is_array($classes)) {
3565
+        return array_map('spip_sanitize_classname', $classes);
3566
+    }
3567
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3569 3568
 }
3570 3569
 
3571 3570
 
@@ -3590,32 +3589,32 @@  discard block
 block discarded – undo
3590 3589
  *    Avec operateur : bool.
3591 3590
  **/
3592 3591
 function spip_version_compare($v1, $v2, $op = null) {
3593
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3594
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3595
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3596
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3597
-
3598
-	$v1 = explode('.', $v1);
3599
-	$v2 = explode('.', $v2);
3600
-	// $v1 est toujours une version, donc sans etoile
3601
-	while (count($v1) < count($v2)) {
3602
-		$v1[] = '0';
3603
-	}
3604
-
3605
-	// $v2 peut etre une borne, donc accepte l'etoile
3606
-	$etoile = false;
3607
-	foreach ($v1 as $k => $v) {
3608
-		if (!isset($v2[$k])) {
3609
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3610
-		} else {
3611
-			if ($v2[$k] == '*') {
3612
-				$etoile = true;
3613
-				$v2[$k] = $v;
3614
-			}
3615
-		}
3616
-	}
3617
-	$v1 = implode('.', $v1);
3618
-	$v2 = implode('.', $v2);
3619
-
3620
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3592
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3593
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3594
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3595
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3596
+
3597
+    $v1 = explode('.', $v1);
3598
+    $v2 = explode('.', $v2);
3599
+    // $v1 est toujours une version, donc sans etoile
3600
+    while (count($v1) < count($v2)) {
3601
+        $v1[] = '0';
3602
+    }
3603
+
3604
+    // $v2 peut etre une borne, donc accepte l'etoile
3605
+    $etoile = false;
3606
+    foreach ($v1 as $k => $v) {
3607
+        if (!isset($v2[$k])) {
3608
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3609
+        } else {
3610
+            if ($v2[$k] == '*') {
3611
+                $etoile = true;
3612
+                $v2[$k] = $v;
3613
+            }
3614
+        }
3615
+    }
3616
+    $v1 = implode('.', $v1);
3617
+    $v2 = implode('.', $v2);
3618
+
3619
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3621 3620
 }
Please login to merge, or discard this patch.
ecrire/inc/headers.php 2 patches
Indentation   +136 added lines, -136 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
 
@@ -38,134 +38,134 @@  discard block
 block discarded – undo
38 38
  * @param int $status Code de redirection (301 ou 302)
39 39
  **/
40 40
 function redirige_par_entete($url, $equiv = '', $status = 302) {
41
-	if (!in_array($status, [301, 302])) {
42
-		$status = 302;
43
-	}
44
-
45
-	$url = trim(strtr($url, "\n\r", '  '));
46
-	# si l'url de redirection est relative, on la passe en absolue
47
-	if (!preg_match(',^(\w+:)?//,', $url)) {
48
-		include_spip('inc/filtres_mini');
49
-		$url = url_absolue($url);
50
-	}
51
-
52
-	if (defined('_AJAX') and _AJAX) {
53
-		$url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
-	}
55
-
56
-	// ne pas laisser passer n'importe quoi dans l'url
57
-	$url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
58
-	$url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
59
-	while (strpos($url, '%0A') !== false) {
60
-		$url = str_replace('%0A', '', $url);
61
-	}
62
-	// interdire les url inline avec des pseudo-protocoles :
63
-	if (
64
-		(preg_match(',data:,i', $url) and preg_match('/base64\s*,/i', $url))
65
-		or preg_match(',(javascript|mailto):,i', $url)
66
-	) {
67
-		$url = './';
68
-	}
69
-
70
-	// Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
-	include_spip('inc/cookie');
72
-	if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
-		define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
-	}
75
-	if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
-		define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
-	}
78
-	if (
79
-		(!$equiv and !spip_cookie_envoye()) or (
80
-			   (!empty($_SERVER['SERVER_SOFTWARE'])
81
-				   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
82
-				   and preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SOFTWARE']))
83
-			or (!empty($_SERVER['SERVER_SIGNATURE'])
84
-				   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
85
-				   and preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SIGNATURE']))
86
-			or function_exists('apache_getenv')
87
-			or defined('_SERVER_APACHE')
88
-		)
89
-	) {
90
-		@header('Location: ' . $url);
91
-		$equiv = '';
92
-	} else {
93
-		@header('Refresh: 0; url=' . $url);
94
-		if (isset($GLOBALS['meta']['charset'])) {
95
-			@header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
96
-		}
97
-		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
98
-	}
99
-	include_spip('inc/lang');
100
-	if ($status != 302) {
101
-		http_status($status);
102
-	}
103
-	echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
104
-	html_lang_attributes(), '
41
+    if (!in_array($status, [301, 302])) {
42
+        $status = 302;
43
+    }
44
+
45
+    $url = trim(strtr($url, "\n\r", '  '));
46
+    # si l'url de redirection est relative, on la passe en absolue
47
+    if (!preg_match(',^(\w+:)?//,', $url)) {
48
+        include_spip('inc/filtres_mini');
49
+        $url = url_absolue($url);
50
+    }
51
+
52
+    if (defined('_AJAX') and _AJAX) {
53
+        $url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
+    }
55
+
56
+    // ne pas laisser passer n'importe quoi dans l'url
57
+    $url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
58
+    $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
59
+    while (strpos($url, '%0A') !== false) {
60
+        $url = str_replace('%0A', '', $url);
61
+    }
62
+    // interdire les url inline avec des pseudo-protocoles :
63
+    if (
64
+        (preg_match(',data:,i', $url) and preg_match('/base64\s*,/i', $url))
65
+        or preg_match(',(javascript|mailto):,i', $url)
66
+    ) {
67
+        $url = './';
68
+    }
69
+
70
+    // Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
+    include_spip('inc/cookie');
72
+    if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
73
+        define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
74
+    }
75
+    if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
76
+        define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
77
+    }
78
+    if (
79
+        (!$equiv and !spip_cookie_envoye()) or (
80
+                (!empty($_SERVER['SERVER_SOFTWARE'])
81
+                   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
82
+                   and preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SOFTWARE']))
83
+            or (!empty($_SERVER['SERVER_SIGNATURE'])
84
+                   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
85
+                   and preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SIGNATURE']))
86
+            or function_exists('apache_getenv')
87
+            or defined('_SERVER_APACHE')
88
+        )
89
+    ) {
90
+        @header('Location: ' . $url);
91
+        $equiv = '';
92
+    } else {
93
+        @header('Refresh: 0; url=' . $url);
94
+        if (isset($GLOBALS['meta']['charset'])) {
95
+            @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
96
+        }
97
+        $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
98
+    }
99
+    include_spip('inc/lang');
100
+    if ($status != 302) {
101
+        http_status($status);
102
+    }
103
+    echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
104
+    html_lang_attributes(), '
105 105
 <head>',
106
-	$equiv, '
106
+    $equiv, '
107 107
 <title>HTTP ' . $status . '</title>
108 108
 ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
109 109
 </head>
110 110
 <body>
111 111
 <h1>HTTP ' . $status . '</h1>
112 112
 <a href="',
113
-	quote_amp($url),
114
-	'">',
115
-	_T('navigateur_pas_redirige'),
116
-	'</a></body></html>';
113
+    quote_amp($url),
114
+    '">',
115
+    _T('navigateur_pas_redirige'),
116
+    '</a></body></html>';
117 117
 
118
-	spip_log("redirige $status: $url");
118
+    spip_log("redirige $status: $url");
119 119
 
120
-	exit;
120
+    exit;
121 121
 }
122 122
 
123 123
 // https://code.spip.net/@redirige_formulaire
124 124
 function redirige_formulaire($url, $equiv = '', $format = 'message') {
125
-	if (
126
-		!_AJAX
127
-		and !headers_sent()
128
-		and !_request('var_ajax')
129
-	) {
130
-		redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
131
-	} // si c'est une ancre, fixer simplement le window.location.hash
132
-	elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
133
-		return [
134
-			// on renvoie un lien masque qui sera traite par ajaxCallback.js
135
-			"<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
136
-			// et rien dans le message ok
137
-			''
138
-		];
139
-	} else {
140
-		// ne pas laisser passer n'importe quoi dans l'url
141
-		$url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
142
-
143
-		$url = strtr($url, "\n\r", '  ');
144
-		# en theorie on devrait faire ca tout le temps, mais quand la chaine
145
-		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
146
-		if ($url[0] == '?') {
147
-			$url = url_de_base() . $url;
148
-		}
149
-		$url = str_replace('&amp;', '&', $url);
150
-		spip_log("redirige formulaire ajax: $url");
151
-		include_spip('inc/filtres');
152
-		if ($format == 'ajaxform') {
153
-			return [
154
-				// on renvoie un lien masque qui sera traite par ajaxCallback.js
155
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
156
-				// et un message au cas ou
157
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
158
-			];
159
-		} else // format message texte, tout en js inline
160
-		{
161
-			return
162
-				// ie poste les formulaires dans une iframe, il faut donc rediriger son parent
163
-				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
164
-				. http_img_pack('loader.svg', '', " class='loader'")
165
-				. '<br />'
166
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
167
-		}
168
-	}
125
+    if (
126
+        !_AJAX
127
+        and !headers_sent()
128
+        and !_request('var_ajax')
129
+    ) {
130
+        redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
131
+    } // si c'est une ancre, fixer simplement le window.location.hash
132
+    elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
133
+        return [
134
+            // on renvoie un lien masque qui sera traite par ajaxCallback.js
135
+            "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
136
+            // et rien dans le message ok
137
+            ''
138
+        ];
139
+    } else {
140
+        // ne pas laisser passer n'importe quoi dans l'url
141
+        $url = str_replace(['<', '"'], ['&lt;', '&quot;'], $url);
142
+
143
+        $url = strtr($url, "\n\r", '  ');
144
+        # en theorie on devrait faire ca tout le temps, mais quand la chaine
145
+        # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
146
+        if ($url[0] == '?') {
147
+            $url = url_de_base() . $url;
148
+        }
149
+        $url = str_replace('&amp;', '&', $url);
150
+        spip_log("redirige formulaire ajax: $url");
151
+        include_spip('inc/filtres');
152
+        if ($format == 'ajaxform') {
153
+            return [
154
+                // on renvoie un lien masque qui sera traite par ajaxCallback.js
155
+                '<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
156
+                // et un message au cas ou
157
+                '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
158
+            ];
159
+        } else // format message texte, tout en js inline
160
+        {
161
+            return
162
+                // ie poste les formulaires dans une iframe, il faut donc rediriger son parent
163
+                "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
164
+                . http_img_pack('loader.svg', '', " class='loader'")
165
+                . '<br />'
166
+                . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
167
+        }
168
+    }
169 169
 }
170 170
 
171 171
 /**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
  * @return void
187 187
  **/
188 188
 function redirige_url_ecrire($script = '', $args = '', $equiv = '') {
189
-	return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
189
+    return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
190 190
 }
191 191
 /**
192 192
  * Renvoie au client le header HTTP avec le message correspondant au code indiqué.
@@ -201,28 +201,28 @@  discard block
 block discarded – undo
201 201
  *     Code d'erreur
202 202
  **/
203 203
 function http_status($status) {
204
-	http_response_code($status);
204
+    http_response_code($status);
205 205
 }
206 206
 
207 207
 // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache
208 208
 // https://code.spip.net/@http_no_cache
209 209
 function http_no_cache() {
210
-	if (headers_sent()) {
211
-		spip_log('http_no_cache arrive trop tard');
212
-
213
-		return;
214
-	}
215
-	$charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
216
-
217
-	// selon http://developer.apple.com/internet/safari/faq.html#anchor5
218
-	// il faudrait aussi pour Safari
219
-	// header("Cache-Control: post-check=0, pre-check=0", false)
220
-	// mais ca ne respecte pas
221
-	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
222
-
223
-	header("Content-Type: text/html; charset=$charset");
224
-	header('Expires: 0');
225
-	header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
226
-	header('Cache-Control: no-cache, must-revalidate');
227
-	header('Pragma: no-cache');
210
+    if (headers_sent()) {
211
+        spip_log('http_no_cache arrive trop tard');
212
+
213
+        return;
214
+    }
215
+    $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
216
+
217
+    // selon http://developer.apple.com/internet/safari/faq.html#anchor5
218
+    // il faudrait aussi pour Safari
219
+    // header("Cache-Control: post-check=0, pre-check=0", false)
220
+    // mais ca ne respecte pas
221
+    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
222
+
223
+    header("Content-Type: text/html; charset=$charset");
224
+    header('Expires: 0');
225
+    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
226
+    header('Cache-Control: no-cache, must-revalidate');
227
+    header('Pragma: no-cache');
228 228
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 		(!$equiv and !spip_cookie_envoye()) or (
80 80
 			   (!empty($_SERVER['SERVER_SOFTWARE'])
81 81
 				   and _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
82
-				   and preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SOFTWARE']))
82
+				   and preg_match('/'._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', $_SERVER['SERVER_SOFTWARE']))
83 83
 			or (!empty($_SERVER['SERVER_SIGNATURE'])
84 84
 				   and _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
85
-				   and preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', $_SERVER['SERVER_SIGNATURE']))
85
+				   and preg_match('/'._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', $_SERVER['SERVER_SIGNATURE']))
86 86
 			or function_exists('apache_getenv')
87 87
 			or defined('_SERVER_APACHE')
88 88
 		)
89 89
 	) {
90
-		@header('Location: ' . $url);
90
+		@header('Location: '.$url);
91 91
 		$equiv = '';
92 92
 	} else {
93
-		@header('Refresh: 0; url=' . $url);
93
+		@header('Refresh: 0; url='.$url);
94 94
 		if (isset($GLOBALS['meta']['charset'])) {
95
-			@header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
95
+			@header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']);
96 96
 		}
97 97
 		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
98 98
 	}
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
 	html_lang_attributes(), '
105 105
 <head>',
106 106
 	$equiv, '
107
-<title>HTTP ' . $status . '</title>
108
-' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
107
+<title>HTTP ' . $status.'</title>
108
+' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset='.$GLOBALS['meta']['charset'].'">' : '').'
109 109
 </head>
110 110
 <body>
111
-<h1>HTTP ' . $status . '</h1>
111
+<h1>HTTP ' . $status.'</h1>
112 112
 <a href="',
113 113
 	quote_amp($url),
114 114
 	'">',
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		# en theorie on devrait faire ca tout le temps, mais quand la chaine
145 145
 		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
146 146
 		if ($url[0] == '?') {
147
-			$url = url_de_base() . $url;
147
+			$url = url_de_base().$url;
148 148
 		}
149 149
 		$url = str_replace('&amp;', '&', $url);
150 150
 		spip_log("redirige formulaire ajax: $url");
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 		if ($format == 'ajaxform') {
153 153
 			return [
154 154
 				// on renvoie un lien masque qui sera traite par ajaxCallback.js
155
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
155
+				'<a href="'.quote_amp($url).'" name="ajax_redirect"  style="display:none;">'._T('navigateur_pas_redirige').'</a>',
156 156
 				// et un message au cas ou
157
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
157
+				'<br /><a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>'
158 158
 			];
159 159
 		} else // format message texte, tout en js inline
160 160
 		{
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
164 164
 				. http_img_pack('loader.svg', '', " class='loader'")
165 165
 				. '<br />'
166
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
166
+				. '<a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>';
167 167
 		}
168 168
 	}
169 169
 }
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 
223 223
 	header("Content-Type: text/html; charset=$charset");
224 224
 	header('Expires: 0');
225
-	header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
225
+	header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
226 226
 	header('Cache-Control: no-cache, must-revalidate');
227 227
 	header('Pragma: no-cache');
228 228
 }
Please login to merge, or discard this patch.