Completed
Push — master ( 6d727b...a5da4e )
by cam
01:51
created
ecrire/inc/urls.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 include_spip('base/objets');
22 22
 
@@ -56,106 +56,106 @@  discard block
 block discarded – undo
56 56
  *
57 57
  */
58 58
 function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) {
59
-	static $current_base = null;
59
+    static $current_base = null;
60 60
 
61
-	// les anciennes fonctions modifient directement les globales
62
-	// on les sauve avant l'appel, et on les retablit apres !
63
-	$save = [
64
-		$GLOBALS['fond'] ?? null,
65
-		$GLOBALS['contexte'] ?? null,
66
-		$_SERVER['REDIRECT_url_propre'] ?? null,
67
-		$_ENV['url_propre'] ?? null,
68
-		$GLOBALS['profondeur_url']
69
-	];
61
+    // les anciennes fonctions modifient directement les globales
62
+    // on les sauve avant l'appel, et on les retablit apres !
63
+    $save = [
64
+        $GLOBALS['fond'] ?? null,
65
+        $GLOBALS['contexte'] ?? null,
66
+        $_SERVER['REDIRECT_url_propre'] ?? null,
67
+        $_ENV['url_propre'] ?? null,
68
+        $GLOBALS['profondeur_url']
69
+    ];
70 70
 
71
-	if (is_null($current_base)) {
72
-		include_spip('inc/filtres_mini');
73
-		// le decodage des urls se fait toujours par rapport au site public
74
-		$current_base = url_absolue(_DIR_RACINE ?: './');
75
-	}
76
-	if (strncmp($url, $current_base, strlen($current_base)) == 0) {
77
-		$url = substr($url, strlen($current_base));
78
-	}
71
+    if (is_null($current_base)) {
72
+        include_spip('inc/filtres_mini');
73
+        // le decodage des urls se fait toujours par rapport au site public
74
+        $current_base = url_absolue(_DIR_RACINE ?: './');
75
+    }
76
+    if (strncmp($url, $current_base, strlen($current_base)) == 0) {
77
+        $url = substr($url, strlen($current_base));
78
+    }
79 79
 
80
-	// si on est en train d'assembler la page principale,
81
-	// recuperer l'url depuis les globales url propres si fournies
82
-	// sinon extraire la bonne portion d'url
83
-	if ($assembler) {
84
-		if (isset($_SERVER['REDIRECT_url_propre'])) {
85
-			$url = $_SERVER['REDIRECT_url_propre'];
86
-		} elseif (isset($_ENV['url_propre'])) {
87
-			$url = $_ENV['url_propre'];
88
-		} else {
89
-			$qs = explode('?', $url);
90
-			// ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
91
-			$url = ltrim($qs[0], '/');
92
-			$url = explode('/', $url);
93
-			while (count($url) > $GLOBALS['profondeur_url'] + 1) {
94
-				array_shift($url);
95
-			}
96
-			$qs[0] = implode('/', $url);
97
-			$url = implode('?', $qs);
98
-		}
99
-	}
80
+    // si on est en train d'assembler la page principale,
81
+    // recuperer l'url depuis les globales url propres si fournies
82
+    // sinon extraire la bonne portion d'url
83
+    if ($assembler) {
84
+        if (isset($_SERVER['REDIRECT_url_propre'])) {
85
+            $url = $_SERVER['REDIRECT_url_propre'];
86
+        } elseif (isset($_ENV['url_propre'])) {
87
+            $url = $_ENV['url_propre'];
88
+        } else {
89
+            $qs = explode('?', $url);
90
+            // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
91
+            $url = ltrim($qs[0], '/');
92
+            $url = explode('/', $url);
93
+            while (count($url) > $GLOBALS['profondeur_url'] + 1) {
94
+                array_shift($url);
95
+            }
96
+            $qs[0] = implode('/', $url);
97
+            $url = implode('?', $qs);
98
+        }
99
+    }
100 100
 
101
-	unset($_SERVER['REDIRECT_url_propre']);
102
-	unset($_ENV['url_propre']);
103
-	include_spip('inc/filtres_mini');
104
-	if (strpos($url, '://') === false) {
105
-		$GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
106
-	} else {
107
-		$GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
108
-	}
101
+    unset($_SERVER['REDIRECT_url_propre']);
102
+    unset($_ENV['url_propre']);
103
+    include_spip('inc/filtres_mini');
104
+    if (strpos($url, '://') === false) {
105
+        $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
106
+    } else {
107
+        $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
108
+    }
109 109
 
110
-	$url_redirect = '';
111
-	$decoder = charger_fonction_url('decoder');
112
-	if ($decoder) {
113
-		$a = $decoder($url, $fond, $contexte);
114
-		if (is_array($a)) {
115
-			[$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
116
-			$url_redirect ??= '';
117
-			if ($url_redirect === $url) {
118
-				$url_redirect = '';
119
-			} // securite pour eviter une redirection infinie
120
-			if ($assembler and strlen($url_redirect)) {
121
-				spip_log("Redirige $url vers $url_redirect");
122
-				include_spip('inc/headers');
123
-				redirige_par_entete($url_redirect, '', 301);
124
-			}
125
-			if (isset($nfond)) {
126
-				$fond = $nfond;
127
-			} else {
128
-				if (
129
-					$fond == ''
130
-					or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
131
-				) {
132
-					$fond = $type;
133
-				}
134
-			}
135
-			if (isset($ncontexte)) {
136
-				$contexte = $ncontexte;
137
-			}
138
-			if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
139
-				$contexte['type'] = $type;
140
-			}
141
-			if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
142
-				$contexte['type-page'] = $type;
143
-			}
144
-		}
145
-	}
110
+    $url_redirect = '';
111
+    $decoder = charger_fonction_url('decoder');
112
+    if ($decoder) {
113
+        $a = $decoder($url, $fond, $contexte);
114
+        if (is_array($a)) {
115
+            [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
116
+            $url_redirect ??= '';
117
+            if ($url_redirect === $url) {
118
+                $url_redirect = '';
119
+            } // securite pour eviter une redirection infinie
120
+            if ($assembler and strlen($url_redirect)) {
121
+                spip_log("Redirige $url vers $url_redirect");
122
+                include_spip('inc/headers');
123
+                redirige_par_entete($url_redirect, '', 301);
124
+            }
125
+            if (isset($nfond)) {
126
+                $fond = $nfond;
127
+            } else {
128
+                if (
129
+                    $fond == ''
130
+                    or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
131
+                ) {
132
+                    $fond = $type;
133
+                }
134
+            }
135
+            if (isset($ncontexte)) {
136
+                $contexte = $ncontexte;
137
+            }
138
+            if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
139
+                $contexte['type'] = $type;
140
+            }
141
+            if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
142
+                $contexte['type-page'] = $type;
143
+            }
144
+        }
145
+    }
146 146
 
147
-	// retablir les globales
148
-	[$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
147
+    // retablir les globales
148
+    [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
149 149
 
150
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
151
-	// d'inversion url => objet
152
-	// maintenir pour compat ?
153
-	#if ($assembler) {
154
-	#	unset($_SERVER['REDIRECT_url_propre']);
155
-	#	unset($_ENV['url_propre']);
156
-	#}
150
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
151
+    // d'inversion url => objet
152
+    // maintenir pour compat ?
153
+    #if ($assembler) {
154
+    #	unset($_SERVER['REDIRECT_url_propre']);
155
+    #	unset($_ENV['url_propre']);
156
+    #}
157 157
 
158
-	return [$fond, $contexte, $url_redirect];
158
+    return [$fond, $contexte, $url_redirect];
159 159
 }
160 160
 
161 161
 /**
@@ -168,20 +168,20 @@  discard block
 block discarded – undo
168 168
  * @return array|false|string
169 169
  */
170 170
 function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array {
171
-	if ($url_propre) {
172
-		if ($GLOBALS['profondeur_url'] <= 0) {
173
-			$urls_anciennes = charger_fonction_url('decoder', 'propres');
174
-		} else {
175
-			$urls_anciennes = charger_fonction_url('decoder', 'arbo');
176
-		}
171
+    if ($url_propre) {
172
+        if ($GLOBALS['profondeur_url'] <= 0) {
173
+            $urls_anciennes = charger_fonction_url('decoder', 'propres');
174
+        } else {
175
+            $urls_anciennes = charger_fonction_url('decoder', 'arbo');
176
+        }
177 177
 
178
-		if ($urls_anciennes) {
179
-			$urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
180
-		}
181
-		return $urls_anciennes ?: [];
182
-	}
178
+        if ($urls_anciennes) {
179
+            $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
180
+        }
181
+        return $urls_anciennes ?: [];
182
+    }
183 183
 
184
-	return [];
184
+    return [];
185 185
 }
186 186
 
187 187
 /**
@@ -194,41 +194,41 @@  discard block
 block discarded – undo
194 194
  * @return array|false|string
195 195
  */
196 196
 function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array {
197
-	// Migration depuis anciennes URLs ?
198
-	// traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
199
-	if (
200
-		$url
201
-		and $GLOBALS['profondeur_url'] <= 0
202
-	) {
203
-		$r = nettoyer_url_page($url, $contexte);
204
-		if ($r) {
205
-			[$contexte, $type, , , $suite] = $r;
206
-			$_id = id_table_objet($type);
207
-			$id_objet = $contexte[$_id];
208
-			$url_propre = generer_objet_url($id_objet, $type);
209
-			if (
210
-				strlen($url_propre)
211
-				and !strstr($url, (string) $url_propre)
212
-				and (
213
-					objet_test_si_publie($type, $id_objet)
214
-					or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
215
-				)
216
-			) {
217
-				[, $hash] = array_pad(explode('#', $url_propre), 2, '');
218
-				$args = [];
219
-				foreach (array_filter(explode('&', $suite ?? '')) as $fragment) {
220
-					if ($fragment != "$_id=$id_objet") {
221
-						$args[] = $fragment;
222
-					}
223
-				}
224
-				$url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
197
+    // Migration depuis anciennes URLs ?
198
+    // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
199
+    if (
200
+        $url
201
+        and $GLOBALS['profondeur_url'] <= 0
202
+    ) {
203
+        $r = nettoyer_url_page($url, $contexte);
204
+        if ($r) {
205
+            [$contexte, $type, , , $suite] = $r;
206
+            $_id = id_table_objet($type);
207
+            $id_objet = $contexte[$_id];
208
+            $url_propre = generer_objet_url($id_objet, $type);
209
+            if (
210
+                strlen($url_propre)
211
+                and !strstr($url, (string) $url_propre)
212
+                and (
213
+                    objet_test_si_publie($type, $id_objet)
214
+                    or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
215
+                )
216
+            ) {
217
+                [, $hash] = array_pad(explode('#', $url_propre), 2, '');
218
+                $args = [];
219
+                foreach (array_filter(explode('&', $suite ?? '')) as $fragment) {
220
+                    if ($fragment != "$_id=$id_objet") {
221
+                        $args[] = $fragment;
222
+                    }
223
+                }
224
+                $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
225 225
 
226
-				return [$contexte, $type, $url_redirect, $type];
227
-			}
228
-		}
229
-	}
230
-	/* Fin compatibilite anciennes urls */
231
-	return [];
226
+                return [$contexte, $type, $url_redirect, $type];
227
+            }
228
+        }
229
+    }
230
+    /* Fin compatibilite anciennes urls */
231
+    return [];
232 232
 }
233 233
 
234 234
 /**
@@ -241,24 +241,24 @@  discard block
 block discarded – undo
241 241
  * @return string|array
242 242
  */
243 243
 function urls_liste_objets($preg = true) {
244
-	static $url_objets = null;
245
-	if (is_null($url_objets)) {
246
-		$url_objets = [];
247
-		// recuperer les tables_objets_sql declarees
248
-		$tables_objets = lister_tables_objets_sql();
249
-		foreach ($tables_objets as $t => $infos) {
250
-			if ($infos['page']) {
251
-				$url_objets[] = $infos['type'];
252
-				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
253
-			}
254
-		}
255
-		$url_objets = pipeline('declarer_url_objets', $url_objets);
256
-	}
257
-	if (!$preg) {
258
-		return $url_objets;
259
-	}
244
+    static $url_objets = null;
245
+    if (is_null($url_objets)) {
246
+        $url_objets = [];
247
+        // recuperer les tables_objets_sql declarees
248
+        $tables_objets = lister_tables_objets_sql();
249
+        foreach ($tables_objets as $t => $infos) {
250
+            if ($infos['page']) {
251
+                $url_objets[] = $infos['type'];
252
+                $url_objets = array_merge($url_objets, $infos['type_surnoms']);
253
+            }
254
+        }
255
+        $url_objets = pipeline('declarer_url_objets', $url_objets);
256
+    }
257
+    if (!$preg) {
258
+        return $url_objets;
259
+    }
260 260
 
261
-	return implode('|', array_map('preg_quote', $url_objets));
261
+    return implode('|', array_map('preg_quote', $url_objets));
262 262
 }
263 263
 
264 264
 /**
@@ -272,26 +272,26 @@  discard block
 block discarded – undo
272 272
  * @return array
273 273
  */
274 274
 function nettoyer_url_page($url, $contexte = []) {
275
-	$url_objets = urls_liste_objets();
276
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
277
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
278
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
275
+    $url_objets = urls_liste_objets();
276
+    $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
277
+    $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
278
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
279 279
 
280
-	if (
281
-		preg_match($raccourci_url_page_html, $url, $regs)
282
-		or preg_match($raccourci_url_page_id, $url, $regs)
283
-		or preg_match($raccourci_url_page_spip, $url, $regs)
284
-	) {
285
-		$regs = array_pad($regs, 4, null);
286
-		$type = objet_type($regs[1]);
287
-		$_id = id_table_objet($type);
288
-		$contexte[$_id] = $regs[2];
289
-		$suite = $regs[3];
280
+    if (
281
+        preg_match($raccourci_url_page_html, $url, $regs)
282
+        or preg_match($raccourci_url_page_id, $url, $regs)
283
+        or preg_match($raccourci_url_page_spip, $url, $regs)
284
+    ) {
285
+        $regs = array_pad($regs, 4, null);
286
+        $type = objet_type($regs[1]);
287
+        $_id = id_table_objet($type);
288
+        $contexte[$_id] = $regs[2];
289
+        $suite = $regs[3];
290 290
 
291
-		return [$contexte, $type, null, $type, $suite];
292
-	}
291
+        return [$contexte, $type, null, $type, $suite];
292
+    }
293 293
 
294
-	return [];
294
+    return [];
295 295
 }
296 296
 
297 297
 /**
@@ -309,36 +309,36 @@  discard block
 block discarded – undo
309 309
  * @return string
310 310
  */
311 311
 function generer_objet_url_ecrire($id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string {
312
-	static $furls = [];
313
-	$id = intval($id);
314
-	if (!isset($furls[$objet])) {
315
-		if (
316
-			function_exists($f = 'generer_' . $objet . '_url_ecrire')
317
-			// ou definie par un plugin
318
-			or $f = charger_fonction($f, 'urls', true)
319
-			// deprecated
320
-			or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
321
-		) {
322
-			$furls[$objet] = $f;
323
-		} else {
324
-			$furls[$objet] = '';
325
-		}
326
-	}
327
-	if ($furls[$objet]) {
328
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
329
-	}
330
-	// si pas de flag public fourni
331
-	// le calculer en fonction de la declaration de statut
332
-	if (is_null($public) and !$connect) {
333
-		$public = objet_test_si_publie($objet, $id, $connect);
334
-	}
335
-	if ($public or $connect) {
336
-		return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
337
-	}
338
-	$a = id_table_objet($objet) . '=' . intval($id);
339
-	if (!function_exists('objet_info')) {
340
-		include_spip('inc/filtres');
341
-	}
312
+    static $furls = [];
313
+    $id = intval($id);
314
+    if (!isset($furls[$objet])) {
315
+        if (
316
+            function_exists($f = 'generer_' . $objet . '_url_ecrire')
317
+            // ou definie par un plugin
318
+            or $f = charger_fonction($f, 'urls', true)
319
+            // deprecated
320
+            or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
321
+        ) {
322
+            $furls[$objet] = $f;
323
+        } else {
324
+            $furls[$objet] = '';
325
+        }
326
+    }
327
+    if ($furls[$objet]) {
328
+        return $furls[$objet]($id, $args, $ancre, $public, $connect);
329
+    }
330
+    // si pas de flag public fourni
331
+    // le calculer en fonction de la declaration de statut
332
+    if (is_null($public) and !$connect) {
333
+        $public = objet_test_si_publie($objet, $id, $connect);
334
+    }
335
+    if ($public or $connect) {
336
+        return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
337
+    }
338
+    $a = id_table_objet($objet) . '=' . intval($id);
339
+    if (!function_exists('objet_info')) {
340
+        include_spip('inc/filtres');
341
+    }
342 342
 
343
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
343
+    return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
344 344
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	) {
203 203
 		$r = nettoyer_url_page($url, $contexte);
204 204
 		if ($r) {
205
-			[$contexte, $type, , , $suite] = $r;
205
+			[$contexte, $type,,, $suite] = $r;
206 206
 			$_id = id_table_objet($type);
207 207
 			$id_objet = $contexte[$_id];
208 208
 			$url_propre = generer_objet_url($id_objet, $type);
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
  */
274 274
 function nettoyer_url_page($url, $contexte = []) {
275 275
 	$url_objets = urls_liste_objets();
276
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
277
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
278
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
276
+	$raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,';
277
+	$raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
278
+	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,';
279 279
 
280 280
 	if (
281 281
 		preg_match($raccourci_url_page_html, $url, $regs)
@@ -313,11 +313,11 @@  discard block
 block discarded – undo
313 313
 	$id = intval($id);
314 314
 	if (!isset($furls[$objet])) {
315 315
 		if (
316
-			function_exists($f = 'generer_' . $objet . '_url_ecrire')
316
+			function_exists($f = 'generer_'.$objet.'_url_ecrire')
317 317
 			// ou definie par un plugin
318 318
 			or $f = charger_fonction($f, 'urls', true)
319 319
 			// deprecated
320
-			or function_exists($f = 'generer_url_ecrire_' . $objet) or $f = charger_fonction($f, 'urls', true)
320
+			or function_exists($f = 'generer_url_ecrire_'.$objet) or $f = charger_fonction($f, 'urls', true)
321 321
 		) {
322 322
 			$furls[$objet] = $f;
323 323
 		} else {
@@ -335,10 +335,10 @@  discard block
 block discarded – undo
335 335
 	if ($public or $connect) {
336 336
 		return generer_objet_url_absolue($id, $objet, $args, $ancre, $public, '', $connect);
337 337
 	}
338
-	$a = id_table_objet($objet) . '=' . intval($id);
338
+	$a = id_table_objet($objet).'='.intval($id);
339 339
 	if (!function_exists('objet_info')) {
340 340
 		include_spip('inc/filtres');
341 341
 	}
342 342
 
343
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
343
+	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : '');
344 344
 }
Please login to merge, or discard this patch.
ecrire/inc/headers.php 1 patch
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -37,133 +37,133 @@  discard block
 block discarded – undo
37 37
  * @param int $status Code de redirection (301 ou 302)
38 38
  **/
39 39
 function redirige_par_entete($url, $equiv = '', $status = 302) {
40
-	if (!in_array($status, [301, 302])) {
41
-		$status = 302;
42
-	}
43
-
44
-	$url = trim(strtr($url, "\n\r", '  '));
45
-	# si l'url de redirection est relative, on la passe en absolue
46
-	if (!preg_match(',^(\w+:)?//,', $url)) {
47
-		include_spip('inc/filtres_mini');
48
-		$url = url_absolue($url);
49
-	}
50
-
51
-	if (defined('_AJAX') && _AJAX) {
52
-		$url = parametre_url($url, 'var_ajax_redir', 1, '&');
53
-	}
54
-
55
-	// ne pas laisser passer n'importe quoi dans l'url
56
-	$url = str_replace(['<', '"'], ['&lt;', '&quot;'], (string) $url);
57
-	$url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
58
-	while (str_contains($url, '%0A')) {
59
-		$url = str_replace('%0A', '', $url);
60
-	}
61
-	// interdire les url inline avec des pseudo-protocoles :
62
-	if (
63
-		preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url)
64
-	) {
65
-		$url = './';
66
-	}
67
-
68
-	// Il n'y a que sous Apache que setcookie puis redirection fonctionne
69
-	include_spip('inc/cookie');
70
-	if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
71
-		define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
72
-	}
73
-	if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
74
-		define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
75
-	}
76
-	if (
77
-		!$equiv && !spip_cookie_envoye()
78
-		|| (
79
-			!empty($_SERVER['SERVER_SOFTWARE'])
80
-				&& _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
81
-				&& preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE'])
82
-			|| !empty($_SERVER['SERVER_SIGNATURE'])
83
-				&& _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
84
-				&& preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE'])
85
-			|| function_exists('apache_getenv')
86
-			|| defined('_SERVER_APACHE')
87
-		)
88
-	) {
89
-		@header('Location: ' . $url);
90
-		$equiv = '';
91
-	} else {
92
-		@header('Refresh: 0; url=' . $url);
93
-		if (isset($GLOBALS['meta']['charset'])) {
94
-			@header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
95
-		}
96
-		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
97
-	}
98
-	include_spip('inc/lang');
99
-	if ($status != 302) {
100
-		http_response_code($status);
101
-	}
102
-	echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
103
-	html_lang_attributes(), '
40
+    if (!in_array($status, [301, 302])) {
41
+        $status = 302;
42
+    }
43
+
44
+    $url = trim(strtr($url, "\n\r", '  '));
45
+    # si l'url de redirection est relative, on la passe en absolue
46
+    if (!preg_match(',^(\w+:)?//,', $url)) {
47
+        include_spip('inc/filtres_mini');
48
+        $url = url_absolue($url);
49
+    }
50
+
51
+    if (defined('_AJAX') && _AJAX) {
52
+        $url = parametre_url($url, 'var_ajax_redir', 1, '&');
53
+    }
54
+
55
+    // ne pas laisser passer n'importe quoi dans l'url
56
+    $url = str_replace(['<', '"'], ['&lt;', '&quot;'], (string) $url);
57
+    $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url);
58
+    while (str_contains($url, '%0A')) {
59
+        $url = str_replace('%0A', '', $url);
60
+    }
61
+    // interdire les url inline avec des pseudo-protocoles :
62
+    if (
63
+        preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url)
64
+    ) {
65
+        $url = './';
66
+    }
67
+
68
+    // Il n'y a que sous Apache que setcookie puis redirection fonctionne
69
+    include_spip('inc/cookie');
70
+    if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) {
71
+        define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)');
72
+    }
73
+    if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) {
74
+        define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx');
75
+    }
76
+    if (
77
+        !$equiv && !spip_cookie_envoye()
78
+        || (
79
+            !empty($_SERVER['SERVER_SOFTWARE'])
80
+                && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE
81
+                && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE'])
82
+            || !empty($_SERVER['SERVER_SIGNATURE'])
83
+                && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE
84
+                && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE'])
85
+            || function_exists('apache_getenv')
86
+            || defined('_SERVER_APACHE')
87
+        )
88
+    ) {
89
+        @header('Location: ' . $url);
90
+        $equiv = '';
91
+    } else {
92
+        @header('Refresh: 0; url=' . $url);
93
+        if (isset($GLOBALS['meta']['charset'])) {
94
+            @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']);
95
+        }
96
+        $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
97
+    }
98
+    include_spip('inc/lang');
99
+    if ($status != 302) {
100
+        http_response_code($status);
101
+    }
102
+    echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
103
+    html_lang_attributes(), '
104 104
 <head>',
105
-	$equiv, '
105
+    $equiv, '
106 106
 <title>HTTP ' . $status . '</title>
107 107
 ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
108 108
 </head>
109 109
 <body>
110 110
 <h1>HTTP ' . $status . '</h1>
111 111
 <a href="',
112
-	quote_amp($url),
113
-	'">',
114
-	_T('navigateur_pas_redirige'),
115
-	'</a></body></html>';
112
+    quote_amp($url),
113
+    '">',
114
+    _T('navigateur_pas_redirige'),
115
+    '</a></body></html>';
116 116
 
117
-	spip_log("redirige $status: $url");
117
+    spip_log("redirige $status: $url");
118 118
 
119
-	exit;
119
+    exit;
120 120
 }
121 121
 
122 122
 function redirige_formulaire($url, $equiv = '', $format = 'message') {
123
-	if (
124
-		!_AJAX
125
-		&& !headers_sent()
126
-		&& !_request('var_ajax')
127
-	) {
128
-		redirige_par_entete(str_replace('&amp;', '&', (string) $url), $equiv);
129
-	} // si c'est une ancre, fixer simplement le window.location.hash
130
-	elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) {
131
-		return [
132
-			// on renvoie un lien masque qui sera traite par ajaxCallback.js
133
-			"<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
134
-			// et rien dans le message ok
135
-			''
136
-		];
137
-	} else {
138
-		// ne pas laisser passer n'importe quoi dans l'url
139
-		$url = str_replace(['<', '"'], ['&lt;', '&quot;'], (string) $url);
140
-
141
-		$url = strtr($url, "\n\r", '  ');
142
-		# en theorie on devrait faire ca tout le temps, mais quand la chaine
143
-		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
144
-		if ($url[0] == '?') {
145
-			$url = url_de_base() . $url;
146
-		}
147
-		$url = str_replace('&amp;', '&', (string) $url);
148
-		spip_log("redirige formulaire ajax: $url");
149
-		include_spip('inc/filtres');
150
-		if ($format == 'ajaxform') {
151
-			return [
152
-				// on renvoie un lien masque qui sera traite par ajaxCallback.js
153
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
154
-				// et un message au cas ou
155
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
156
-			];
157
-		} else // format message texte, tout en js inline
158
-		{
159
-			return
160
-				// ie poste les formulaires dans une iframe, il faut donc rediriger son parent
161
-				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
162
-				. http_img_pack('loader.svg', '', " class='loader'")
163
-				. '<br />'
164
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
165
-		}
166
-	}
123
+    if (
124
+        !_AJAX
125
+        && !headers_sent()
126
+        && !_request('var_ajax')
127
+    ) {
128
+        redirige_par_entete(str_replace('&amp;', '&', (string) $url), $equiv);
129
+    } // si c'est une ancre, fixer simplement le window.location.hash
130
+    elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) {
131
+        return [
132
+            // on renvoie un lien masque qui sera traite par ajaxCallback.js
133
+            "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
134
+            // et rien dans le message ok
135
+            ''
136
+        ];
137
+    } else {
138
+        // ne pas laisser passer n'importe quoi dans l'url
139
+        $url = str_replace(['<', '"'], ['&lt;', '&quot;'], (string) $url);
140
+
141
+        $url = strtr($url, "\n\r", '  ');
142
+        # en theorie on devrait faire ca tout le temps, mais quand la chaine
143
+        # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
144
+        if ($url[0] == '?') {
145
+            $url = url_de_base() . $url;
146
+        }
147
+        $url = str_replace('&amp;', '&', (string) $url);
148
+        spip_log("redirige formulaire ajax: $url");
149
+        include_spip('inc/filtres');
150
+        if ($format == 'ajaxform') {
151
+            return [
152
+                // on renvoie un lien masque qui sera traite par ajaxCallback.js
153
+                '<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
154
+                // et un message au cas ou
155
+                '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
156
+            ];
157
+        } else // format message texte, tout en js inline
158
+        {
159
+            return
160
+                // ie poste les formulaires dans une iframe, il faut donc rediriger son parent
161
+                "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
162
+                . http_img_pack('loader.svg', '', " class='loader'")
163
+                . '<br />'
164
+                . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
165
+        }
166
+    }
167 167
 }
168 168
 
169 169
 /**
@@ -184,27 +184,27 @@  discard block
 block discarded – undo
184 184
  * @return void
185 185
  **/
186 186
 function redirige_url_ecrire($script = '', $args = '', $equiv = '') {
187
-	return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
187
+    return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
188 188
 }
189 189
 
190 190
 // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache
191 191
 function http_no_cache() {
192
-	if (headers_sent()) {
193
-		spip_log('http_no_cache arrive trop tard');
194
-
195
-		return;
196
-	}
197
-	$charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
198
-
199
-	// selon http://developer.apple.com/internet/safari/faq.html#anchor5
200
-	// il faudrait aussi pour Safari
201
-	// header("Cache-Control: post-check=0, pre-check=0", false)
202
-	// mais ca ne respecte pas
203
-	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
204
-
205
-	header("Content-Type: text/html; charset=$charset");
206
-	header('Expires: 0');
207
-	header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
208
-	header('Cache-Control: no-cache, must-revalidate');
209
-	header('Pragma: no-cache');
192
+    if (headers_sent()) {
193
+        spip_log('http_no_cache arrive trop tard');
194
+
195
+        return;
196
+    }
197
+    $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
198
+
199
+    // selon http://developer.apple.com/internet/safari/faq.html#anchor5
200
+    // il faudrait aussi pour Safari
201
+    // header("Cache-Control: post-check=0, pre-check=0", false)
202
+    // mais ca ne respecte pas
203
+    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
204
+
205
+    header("Content-Type: text/html; charset=$charset");
206
+    header('Expires: 0');
207
+    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
208
+    header('Cache-Control: no-cache, must-revalidate');
209
+    header('Pragma: no-cache');
210 210
 }
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 2 patches
Indentation   +631 added lines, -631 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Autorisations
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('base/abstract_sql');
@@ -37,89 +37,89 @@  discard block
 block discarded – undo
37 37
 
38 38
 
39 39
 if (!function_exists('autoriser')) {
40
-	/**
41
-	 * Autoriser une action
42
-	 *
43
-	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
44
-	 * une certaine action. Cette fonction est le point d'entrée de toutes
45
-	 * les autorisations.
46
-	 *
47
-	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
48
-	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
49
-	 * dans cet ordre :
50
-	 *
51
-	 * - autoriser_{type}_{faire}, sinon avec _dist
52
-	 * - autoriser_{type}, sinon avec _dist
53
-	 * - autoriser_{faire}, sinon avec _dist
54
-	 * - autoriser_{defaut}, sinon avec _dist
55
-	 *
56
-	 * Seul le premier argument est obligatoire.
57
-	 *
58
-	 * @note
59
-	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
60
-	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
61
-	 *     cette valeur.
62
-	 *
63
-	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
64
-	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
65
-	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
66
-	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
67
-	 *
68
-	 * @note
69
-	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
70
-	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
71
-	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
72
-	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
73
-	 *     quel serait le type, quel serait l'action ?
74
-	 *
75
-	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
76
-	 *     la fonction d'autorisation correspondante ne l'aura pas.
77
-	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
78
-	 *
79
-	 * @api
80
-	 * @see autoriser_dist()
81
-	 * @see objet_type()
82
-	 *
83
-	 * @param string $faire
84
-	 *   une action ('modifier', 'publier'...)
85
-	 * @param string|null $type
86
-	 *   Type d’objet ou élément sur lequel appliquer l’action.
87
-	 *   - null: indifférent à tout type d’élément ou objet éditorial
88
-	 *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
89
-	 *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
90
-	 *   Les soulignés seront retirés (cf. la note).
91
-	 * @param string|int|null $id
92
-	 *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
93
-	 *   - null: non utile pour l’autorisation
94
-	 *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
95
-	 *   - string: identifiant textuel
96
-	 * @param null|int|array $qui
97
-	 *   - si null on prend alors visiteur_session
98
-	 *   - un id_auteur (on regarde dans la base)
99
-	 *   - un tableau auteur complet, y compris [restreint]
100
-	 * @param array $opt
101
-	 *   options sous forme de tableau associatif
102
-	 * @return bool
103
-	 *   true si la personne peut effectuer l'action
104
-	 */
105
-	function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
106
-		// Charger les fonctions d'autorisation supplementaires
107
-		static $pipe;
108
-		if (!isset($pipe)) {
109
-			$pipe = 1;
110
-			pipeline('autoriser');
111
-		}
112
-
113
-		return autoriser_dist($faire, $type, $id, $qui, $opt);
114
-	}
40
+    /**
41
+     * Autoriser une action
42
+     *
43
+     * Teste si une personne (par défaut le visiteur en cours) peut effectuer
44
+     * une certaine action. Cette fonction est le point d'entrée de toutes
45
+     * les autorisations.
46
+     *
47
+     * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
48
+     * aux actions demandées si elles existent. Elle cherche donc les fonctions
49
+     * dans cet ordre :
50
+     *
51
+     * - autoriser_{type}_{faire}, sinon avec _dist
52
+     * - autoriser_{type}, sinon avec _dist
53
+     * - autoriser_{faire}, sinon avec _dist
54
+     * - autoriser_{defaut}, sinon avec _dist
55
+     *
56
+     * Seul le premier argument est obligatoire.
57
+     *
58
+     * @note
59
+     *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
60
+     *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
61
+     *     cette valeur.
62
+     *
63
+     *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
64
+     *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
65
+     *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
66
+     *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
67
+     *
68
+     * @note
69
+     *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
70
+     *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
71
+     *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
72
+     *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
73
+     *     quel serait le type, quel serait l'action ?
74
+     *
75
+     *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
76
+     *     la fonction d'autorisation correspondante ne l'aura pas.
77
+     *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
78
+     *
79
+     * @api
80
+     * @see autoriser_dist()
81
+     * @see objet_type()
82
+     *
83
+     * @param string $faire
84
+     *   une action ('modifier', 'publier'...)
85
+     * @param string|null $type
86
+     *   Type d’objet ou élément sur lequel appliquer l’action.
87
+     *   - null: indifférent à tout type d’élément ou objet éditorial
88
+     *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
89
+     *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
90
+     *   Les soulignés seront retirés (cf. la note).
91
+     * @param string|int|null $id
92
+     *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
93
+     *   - null: non utile pour l’autorisation
94
+     *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
95
+     *   - string: identifiant textuel
96
+     * @param null|int|array $qui
97
+     *   - si null on prend alors visiteur_session
98
+     *   - un id_auteur (on regarde dans la base)
99
+     *   - un tableau auteur complet, y compris [restreint]
100
+     * @param array $opt
101
+     *   options sous forme de tableau associatif
102
+     * @return bool
103
+     *   true si la personne peut effectuer l'action
104
+     */
105
+    function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
106
+        // Charger les fonctions d'autorisation supplementaires
107
+        static $pipe;
108
+        if (!isset($pipe)) {
109
+            $pipe = 1;
110
+            pipeline('autoriser');
111
+        }
112
+
113
+        return autoriser_dist($faire, $type, $id, $qui, $opt);
114
+    }
115 115
 }
116 116
 
117 117
 
118 118
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
119 119
 // mais apres la fonction autoriser()
120 120
 if ($f = find_in_path('mes_fonctions.php')) {
121
-	global $dossier_squelettes;
122
-	include_once(_ROOT_CWD . $f);
121
+    global $dossier_squelettes;
122
+    include_once(_ROOT_CWD . $f);
123 123
 }
124 124
 
125 125
 
@@ -150,85 +150,85 @@  discard block
 block discarded – undo
150 150
  */
151 151
 function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
152 152
 
153
-	if ($type === null) {
154
-		$type = '';
155
-	}
156
-
157
-	// Qui ? visiteur_session ?
158
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
159
-	if ($qui === null || $qui === '') {
160
-		$qui = $GLOBALS['visiteur_session'] ?: [];
161
-		$qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
162
-	} elseif (is_numeric($qui)) {
163
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
164
-		if (!$qui) {
165
-			return false;
166
-		}
167
-	}
168
-
169
-	// Admins restreints, on construit ici (pas generique mais...)
170
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
171
-	if (_ADMINS_RESTREINTS && is_array($qui)) {
172
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
173
-	}
174
-
175
-	spip_log(
176
-		"autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
177
-		'autoriser' . _LOG_DEBUG
178
-	);
179
-
180
-	// passer par objet_type pour avoir les alias
181
-	// sauf si _ est le premier caractère.
182
-	if ($type && $type[0] !== '_') {
183
-		$type = objet_type($type, false);
184
-	}
185
-	// et supprimer les _
186
-	$type = str_replace('_', '', (string) $type);
187
-
188
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
189
-	if (
190
-		isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
191
-		&& autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier')
192
-	) {
193
-		spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
194
-		return true;
195
-	}
196
-
197
-	// Chercher une fonction d'autorisation
198
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
199
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
200
-	$fonctions = $type
201
-		? [
202
-			'autoriser_' . $type . '_' . $faire,
203
-			'autoriser_' . $type . '_' . $faire . '_dist',
204
-			'autoriser_' . $type,
205
-			'autoriser_' . $type . '_dist',
206
-			'autoriser_' . $faire,
207
-			'autoriser_' . $faire . '_dist',
208
-			'autoriser_defaut',
209
-			'autoriser_defaut_dist'
210
-		]
211
-		: [
212
-			'autoriser_' . $faire,
213
-			'autoriser_' . $faire . '_dist',
214
-			'autoriser_defaut',
215
-			'autoriser_defaut_dist'
216
-		];
217
-
218
-	$a = false;
219
-	foreach ($fonctions as $f) {
220
-		if (function_exists($f)) {
221
-			$a = $f($faire, $type, $id, $qui, $opt);
222
-			break;
223
-		}
224
-	}
225
-
226
-	spip_log(
227
-		"$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
228
-		'autoriser' . _LOG_DEBUG
229
-	);
230
-
231
-	return $a;
153
+    if ($type === null) {
154
+        $type = '';
155
+    }
156
+
157
+    // Qui ? visiteur_session ?
158
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
159
+    if ($qui === null || $qui === '') {
160
+        $qui = $GLOBALS['visiteur_session'] ?: [];
161
+        $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
162
+    } elseif (is_numeric($qui)) {
163
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
164
+        if (!$qui) {
165
+            return false;
166
+        }
167
+    }
168
+
169
+    // Admins restreints, on construit ici (pas generique mais...)
170
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
171
+    if (_ADMINS_RESTREINTS && is_array($qui)) {
172
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
173
+    }
174
+
175
+    spip_log(
176
+        "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
177
+        'autoriser' . _LOG_DEBUG
178
+    );
179
+
180
+    // passer par objet_type pour avoir les alias
181
+    // sauf si _ est le premier caractère.
182
+    if ($type && $type[0] !== '_') {
183
+        $type = objet_type($type, false);
184
+    }
185
+    // et supprimer les _
186
+    $type = str_replace('_', '', (string) $type);
187
+
188
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
189
+    if (
190
+        isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
191
+        && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier')
192
+    ) {
193
+        spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
194
+        return true;
195
+    }
196
+
197
+    // Chercher une fonction d'autorisation
198
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
199
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
200
+    $fonctions = $type
201
+        ? [
202
+            'autoriser_' . $type . '_' . $faire,
203
+            'autoriser_' . $type . '_' . $faire . '_dist',
204
+            'autoriser_' . $type,
205
+            'autoriser_' . $type . '_dist',
206
+            'autoriser_' . $faire,
207
+            'autoriser_' . $faire . '_dist',
208
+            'autoriser_defaut',
209
+            'autoriser_defaut_dist'
210
+        ]
211
+        : [
212
+            'autoriser_' . $faire,
213
+            'autoriser_' . $faire . '_dist',
214
+            'autoriser_defaut',
215
+            'autoriser_defaut_dist'
216
+        ];
217
+
218
+    $a = false;
219
+    foreach ($fonctions as $f) {
220
+        if (function_exists($f)) {
221
+            $a = $f($faire, $type, $id, $qui, $opt);
222
+            break;
223
+        }
224
+    }
225
+
226
+    spip_log(
227
+        "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
228
+        'autoriser' . _LOG_DEBUG
229
+    );
230
+
231
+    return $a;
232 232
 }
233 233
 
234 234
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -248,33 +248,33 @@  discard block
 block discarded – undo
248 248
  * @return bool
249 249
  */
250 250
 function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool {
251
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
252
-	static $autorisation;
253
-	// Tolérance avec certains appels
254
-	if ($type === null) {
255
-		$type = '';
256
-	}
257
-	if ($id === null) {
258
-		$id = 0;
259
-	}
260
-	if ($autoriser === 'verifier') {
261
-		return isset($autorisation[$faire][$type][$id]);
262
-	}
263
-	if ($autoriser === true) {
264
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
265
-	}
266
-	if ($autoriser === false) {
267
-		if ($id === '*') {
268
-			unset($GLOBALS['autoriser_exception'][$faire][$type]);
269
-			unset($autorisation[$faire][$type]);
270
-		}
271
-		else {
272
-			unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
273
-			unset($autorisation[$faire][$type][$id]);
274
-		}
275
-	}
276
-
277
-	return false;
251
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
252
+    static $autorisation;
253
+    // Tolérance avec certains appels
254
+    if ($type === null) {
255
+        $type = '';
256
+    }
257
+    if ($id === null) {
258
+        $id = 0;
259
+    }
260
+    if ($autoriser === 'verifier') {
261
+        return isset($autorisation[$faire][$type][$id]);
262
+    }
263
+    if ($autoriser === true) {
264
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
265
+    }
266
+    if ($autoriser === false) {
267
+        if ($id === '*') {
268
+            unset($GLOBALS['autoriser_exception'][$faire][$type]);
269
+            unset($autorisation[$faire][$type]);
270
+        }
271
+        else {
272
+            unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
273
+            unset($autorisation[$faire][$type][$id]);
274
+        }
275
+    }
276
+
277
+    return false;
278 278
 }
279 279
 
280 280
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
  * @return bool true s'il a le droit, false sinon
294 294
  **/
295 295
 function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
296
-	return $qui['statut'] === '0minirezo' && !$qui['restreint'];
296
+    return $qui['statut'] === '0minirezo' && !$qui['restreint'];
297 297
 }
298 298
 
299 299
 /**
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
  * @return bool true s'il a le droit, false sinon
314 314
  */
315 315
 function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
316
-	return $qui['statut'] !== '5poubelle';
316
+    return $qui['statut'] !== '5poubelle';
317 317
 }
318 318
 
319 319
 /**
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
  * @return bool true s'il a le droit, false sinon
330 330
  **/
331 331
 function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
332
-	return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']);
332
+    return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']);
333 333
 }
334 334
 
335 335
 /**
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return bool true s'il a le droit, false sinon
349 349
  **/
350 350
 function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
351
-	return in_array($qui['statut'], ['0minirezo', '1comite']);
351
+    return in_array($qui['statut'], ['0minirezo', '1comite']);
352 352
 }
353 353
 
354 354
 /**
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
  **/
369 369
 function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
370 370
 
371
-	// Le visiteur a-t-il un statut prevu par la config ?
372
-	if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) {
373
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
374
-	}
371
+    // Le visiteur a-t-il un statut prevu par la config ?
372
+    if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) {
373
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
374
+    }
375 375
 
376
-	// A-t-on un token de prévisualisation valable ?
377
-	include_spip('inc/securiser_action');
378
-	return (bool) decrire_token_previsu();
376
+    // A-t-on un token de prévisualisation valable ?
377
+    include_spip('inc/securiser_action');
378
+    return (bool) decrire_token_previsu();
379 379
 }
380 380
 
381 381
 /**
@@ -404,58 +404,58 @@  discard block
 block discarded – undo
404 404
  */
405 405
 function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool {
406 406
 
407
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
408
-	if (!$type) {
409
-		return true;
410
-	}
411
-
412
-	include_spip('base/objets');
413
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
414
-	if (isset($infos['statut'])) {
415
-		foreach ($infos['statut'] as $c) {
416
-			if (isset($c['publie'])) {
417
-				if (!isset($c['previsu'])) {
418
-					return false;
419
-				} // pas de previsu definie => NIET
420
-				$champ = $c['champ'];
421
-				if (!isset($opt[$champ])) {
422
-					return false;
423
-				} // pas de champ passe a la demande => NIET
424
-				$previsu = explode(',', (string) $c['previsu']);
425
-				// regarder si ce statut est autorise pour l'auteur
426
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
427
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
428
-					// sinon l’auteur en session
429
-					include_spip('inc/securiser_action');
430
-					if ($desc = decrire_token_previsu()) {
431
-						$id_auteur = $desc['id_auteur'];
432
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
433
-						$id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur'];
434
-					} else {
435
-						$id_auteur = null;
436
-					}
437
-
438
-					if (!$id_auteur) {
439
-						return false;
440
-					} elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
441
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
442
-					} elseif (
443
-						!sql_countsel(
444
-							'spip_auteurs_liens',
445
-							'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id
446
-						)
447
-					) {
448
-						return false;
449
-					} // pas auteur de cet objet => NIET
450
-				} elseif (!in_array($opt[$champ], $previsu)) {
451
-					// le statut n'est pas dans ceux definis par la previsu => NIET
452
-					return false;
453
-				}
454
-			}
455
-		}
456
-	}
457
-
458
-	return true;
407
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
408
+    if (!$type) {
409
+        return true;
410
+    }
411
+
412
+    include_spip('base/objets');
413
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
414
+    if (isset($infos['statut'])) {
415
+        foreach ($infos['statut'] as $c) {
416
+            if (isset($c['publie'])) {
417
+                if (!isset($c['previsu'])) {
418
+                    return false;
419
+                } // pas de previsu definie => NIET
420
+                $champ = $c['champ'];
421
+                if (!isset($opt[$champ])) {
422
+                    return false;
423
+                } // pas de champ passe a la demande => NIET
424
+                $previsu = explode(',', (string) $c['previsu']);
425
+                // regarder si ce statut est autorise pour l'auteur
426
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
427
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
428
+                    // sinon l’auteur en session
429
+                    include_spip('inc/securiser_action');
430
+                    if ($desc = decrire_token_previsu()) {
431
+                        $id_auteur = $desc['id_auteur'];
432
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
433
+                        $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur'];
434
+                    } else {
435
+                        $id_auteur = null;
436
+                    }
437
+
438
+                    if (!$id_auteur) {
439
+                        return false;
440
+                    } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
441
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
442
+                    } elseif (
443
+                        !sql_countsel(
444
+                            'spip_auteurs_liens',
445
+                            'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id
446
+                        )
447
+                    ) {
448
+                        return false;
449
+                    } // pas auteur de cet objet => NIET
450
+                } elseif (!in_array($opt[$champ], $previsu)) {
451
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
452
+                    return false;
453
+                }
454
+            }
455
+        }
456
+    }
457
+
458
+    return true;
459 459
 }
460 460
 
461 461
 /**
@@ -471,49 +471,49 @@  discard block
 block discarded – undo
471 471
  * @return bool true s'il a le droit, false sinon
472 472
  **/
473 473
 function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
474
-	$multi_objets = explode(',', (string) lire_config('multi_objets'));
475
-	$gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets'));
476
-	$table = table_objet_sql($type);
477
-	if (
478
-		in_array($table, $multi_objets)
479
-		|| in_array($table, $gerer_trad_objets)
480
-	) { // affichage du formulaire si la configuration l'accepte
481
-		$multi_secteurs = lire_config('multi_secteurs');
482
-		$champs = objet_info($type, 'field');
483
-		if (
484
-			$multi_secteurs === 'oui'
485
-			&& array_key_exists('id_rubrique', $champs)
486
-		) {
487
-			// multilinguisme par secteur et objet rattaché à une rubrique
488
-			$primary = id_table_objet($type);
489
-			$id_rubrique = $table != 'spip_rubriques'
490
-				? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id)
491
-				: $id;
492
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
493
-			if (!$id_secteur > 0) {
494
-				$id_secteur = $id_rubrique;
495
-			}
496
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur);
497
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id);
498
-			if ($langue_secteur != $langue_objet) {
499
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
500
-				return true;
501
-			}
502
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
503
-				return false;
504
-			} else {
505
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id);
506
-				if ($id_parent != 0) {
507
-					// sous-rubriques : pas de choix de langue
508
-					return false;
509
-				}
510
-			}
511
-		}
512
-	} else {
513
-		return false;
514
-	}
515
-
516
-	return autoriser('modifier', $type, $id, $qui, $opt);
474
+    $multi_objets = explode(',', (string) lire_config('multi_objets'));
475
+    $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets'));
476
+    $table = table_objet_sql($type);
477
+    if (
478
+        in_array($table, $multi_objets)
479
+        || in_array($table, $gerer_trad_objets)
480
+    ) { // affichage du formulaire si la configuration l'accepte
481
+        $multi_secteurs = lire_config('multi_secteurs');
482
+        $champs = objet_info($type, 'field');
483
+        if (
484
+            $multi_secteurs === 'oui'
485
+            && array_key_exists('id_rubrique', $champs)
486
+        ) {
487
+            // multilinguisme par secteur et objet rattaché à une rubrique
488
+            $primary = id_table_objet($type);
489
+            $id_rubrique = $table != 'spip_rubriques'
490
+                ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id)
491
+                : $id;
492
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
493
+            if (!$id_secteur > 0) {
494
+                $id_secteur = $id_rubrique;
495
+            }
496
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur);
497
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id);
498
+            if ($langue_secteur != $langue_objet) {
499
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
500
+                return true;
501
+            }
502
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
503
+                return false;
504
+            } else {
505
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id);
506
+                if ($id_parent != 0) {
507
+                    // sous-rubriques : pas de choix de langue
508
+                    return false;
509
+                }
510
+            }
511
+        }
512
+    } else {
513
+        return false;
514
+    }
515
+
516
+    return autoriser('modifier', $type, $id, $qui, $opt);
517 517
 }
518 518
 
519 519
 /**
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
  * @return bool true s'il a le droit, false sinon
530 530
  **/
531 531
 function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
532
-	return autoriser('modifier', $type, $id, $qui, $opt);
532
+    return autoriser('modifier', $type, $id, $qui, $opt);
533 533
 }
534 534
 
535 535
 /**
@@ -545,38 +545,38 @@  discard block
 block discarded – undo
545 545
  * @return bool true s'il a le droit, false sinon
546 546
  **/
547 547
 function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
548
-	$table = table_objet($type);
549
-	$trouver_table = charger_fonction('trouver_table', 'base');
550
-	$desc = $trouver_table($table);
551
-	if (!$desc) {
552
-		return false;
553
-	}
554
-
555
-	if (!isset($opt['statut'])) {
556
-		if (isset($desc['field']['statut'])) {
557
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id);
558
-		} else {
559
-			$statut = 'publie';
560
-		} // pas de statut => publie
561
-	} else {
562
-		$statut = $opt['statut'];
563
-	}
564
-
565
-	// Liste des statuts publiés pour cet objet
566
-	// Sinon en dur le statut "publie"
567
-	$statuts_publies = isset($desc['statut'][0]['publie'])
568
-		? explode(',', (string) $desc['statut'][0]['publie'])
569
-		: ['publie'];
570
-
571
-	if (
572
-		in_array($statut, $statuts_publies)
573
-		// Ou cas particulier géré en dur ici pour les articles
574
-		|| $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non'
575
-	) {
576
-		return autoriser('modifier', $type, $id);
577
-	}
578
-
579
-	return false;
548
+    $table = table_objet($type);
549
+    $trouver_table = charger_fonction('trouver_table', 'base');
550
+    $desc = $trouver_table($table);
551
+    if (!$desc) {
552
+        return false;
553
+    }
554
+
555
+    if (!isset($opt['statut'])) {
556
+        if (isset($desc['field']['statut'])) {
557
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id);
558
+        } else {
559
+            $statut = 'publie';
560
+        } // pas de statut => publie
561
+    } else {
562
+        $statut = $opt['statut'];
563
+    }
564
+
565
+    // Liste des statuts publiés pour cet objet
566
+    // Sinon en dur le statut "publie"
567
+    $statuts_publies = isset($desc['statut'][0]['publie'])
568
+        ? explode(',', (string) $desc['statut'][0]['publie'])
569
+        : ['publie'];
570
+
571
+    if (
572
+        in_array($statut, $statuts_publies)
573
+        // Ou cas particulier géré en dur ici pour les articles
574
+        || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non'
575
+    ) {
576
+        return autoriser('modifier', $type, $id);
577
+    }
578
+
579
+    return false;
580 580
 }
581 581
 
582 582
 /**
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
  * @return bool true s'il a le droit, false sinon
596 596
  **/
597 597
 function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
598
-	return autoriser('modifier', $type, $id, $qui, $opt);
598
+    return autoriser('modifier', $type, $id, $qui, $opt);
599 599
 }
600 600
 
601 601
 /**
@@ -613,9 +613,9 @@  discard block
 block discarded – undo
613 613
  * @return bool true s'il a le droit, false sinon
614 614
  **/
615 615
 function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
616
-	return
617
-		$qui['statut'] === '0minirezo'
618
-		&& (!$qui['restreint'] || !$id || in_array($id, $qui['restreint']));
616
+    return
617
+        $qui['statut'] === '0minirezo'
618
+        && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint']));
619 619
 }
620 620
 
621 621
 /**
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
  * @return bool true s'il a le droit, false sinon
634 634
  **/
635 635
 function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
636
-	if (!empty($opt['id_parent'])) {
637
-		return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
638
-	}
639
-	else {
640
-		return autoriser('defaut', null, 0, $qui, $opt);
641
-	}
636
+    if (!empty($opt['id_parent'])) {
637
+        return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
638
+    }
639
+    else {
640
+        return autoriser('defaut', null, 0, $qui, $opt);
641
+    }
642 642
 }
643 643
 
644 644
 /**
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
  * @return bool true s'il a le droit, false sinon
657 657
  **/
658 658
 function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
659
-	return
660
-		($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id);
659
+    return
660
+        ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id);
661 661
 }
662 662
 
663 663
 /**
@@ -675,10 +675,10 @@  discard block
 block discarded – undo
675 675
  * @return bool true s'il a le droit, false sinon
676 676
  **/
677 677
 function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
678
-	return
679
-		$id
680
-		&& autoriser('voir', 'rubrique', $id)
681
-		&& autoriser('creer', 'article');
678
+    return
679
+        $id
680
+        && autoriser('voir', 'rubrique', $id)
681
+        && autoriser('creer', 'article');
682 682
 }
683 683
 
684 684
 
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
  * @return bool true s'il a le droit, false sinon
698 698
  **/
699 699
 function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
700
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
700
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
701 701
 }
702 702
 
703 703
 /**
@@ -715,29 +715,29 @@  discard block
 block discarded – undo
715 715
  * @return bool true s'il a le droit, false sinon
716 716
  **/
717 717
 function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
718
-	if (!$id = (int) $id) {
719
-		return false;
720
-	}
718
+    if (!$id = (int) $id) {
719
+        return false;
720
+    }
721 721
 
722
-	if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) {
723
-		return false;
724
-	}
722
+    if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) {
723
+        return false;
724
+    }
725 725
 
726
-	if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) {
727
-		return false;
728
-	}
726
+    if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) {
727
+        return false;
728
+    }
729 729
 
730
-	$compte = pipeline(
731
-		'objet_compte_enfants',
732
-		['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
733
-	);
734
-	foreach ($compte as $objet => $n) {
735
-		if ($n) {
736
-			return false;
737
-		}
738
-	}
730
+    $compte = pipeline(
731
+        'objet_compte_enfants',
732
+        ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
733
+    );
734
+    foreach ($compte as $objet => $n) {
735
+        if ($n) {
736
+            return false;
737
+        }
738
+    }
739 739
 
740
-	return autoriser('modifier', 'rubrique', $id);
740
+    return autoriser('modifier', 'rubrique', $id);
741 741
 }
742 742
 
743 743
 
@@ -757,20 +757,20 @@  discard block
 block discarded – undo
757 757
  * @return bool true s'il a le droit, false sinon
758 758
  **/
759 759
 function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
760
-	if (!$id) {
761
-		return false;
762
-	}
763
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
760
+    if (!$id) {
761
+        return false;
762
+    }
763
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
764 764
 
765
-	return $r && (
766
-		autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
767
-		|| (
768
-			(!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true))
769
-			&& in_array($qui['statut'], ['0minirezo', '1comite'])
770
-			&& in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
771
-			&& auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
772
-		)
773
-	);
765
+    return $r && (
766
+        autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
767
+        || (
768
+            (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true))
769
+            && in_array($qui['statut'], ['0minirezo', '1comite'])
770
+            && in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
771
+            && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
772
+        )
773
+    );
774 774
 }
775 775
 
776 776
 /**
@@ -788,13 +788,13 @@  discard block
 block discarded – undo
788 788
  * @return bool true s'il a le droit, false sinon
789 789
  **/
790 790
 function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
791
-	if (!empty($opt['id_parent'])) {
792
-		// creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
793
-		return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
794
-	}
795
-	else {
796
-		return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite']));
797
-	}
791
+    if (!empty($opt['id_parent'])) {
792
+        // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
793
+        return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
794
+    }
795
+    else {
796
+        return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite']));
797
+    }
798 798
 }
799 799
 
800 800
 /**
@@ -816,26 +816,26 @@  discard block
 block discarded – undo
816 816
  * @return bool true s'il a le droit, false sinon
817 817
  */
818 818
 function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
819
-	if ($qui['statut'] === '0minirezo') {
820
-		return true;
821
-	}
822
-	// cas des articles : depend du statut de l'article et de l'auteur
823
-	if (isset($opt['statut'])) {
824
-		$statut = $opt['statut'];
825
-	} else {
826
-		if (!$id) {
827
-			return false;
828
-		}
829
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id);
830
-	}
819
+    if ($qui['statut'] === '0minirezo') {
820
+        return true;
821
+    }
822
+    // cas des articles : depend du statut de l'article et de l'auteur
823
+    if (isset($opt['statut'])) {
824
+        $statut = $opt['statut'];
825
+    } else {
826
+        if (!$id) {
827
+            return false;
828
+        }
829
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id);
830
+    }
831 831
 
832
-	return
833
-		// si on est pas auteur de l'article,
834
-		// seuls les propose et publies sont visibles
835
-		in_array($statut, ['prop', 'publie'])
836
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
832
+    return
833
+        // si on est pas auteur de l'article,
834
+        // seuls les propose et publies sont visibles
835
+        in_array($statut, ['prop', 'publie'])
836
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
837 837
 
838
-		|| $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']);
838
+        || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']);
839 839
 }
840 840
 
841 841
 
@@ -854,24 +854,24 @@  discard block
 block discarded – undo
854 854
  * @return bool true s'il a le droit, false sinon
855 855
  **/
856 856
 function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
857
-	# securite, mais on aurait pas du arriver ici !
858
-	if (
859
-		function_exists($f = 'autoriser_' . $type . '_voir')
860
-		|| function_exists($f = 'autoriser_' . $type . '_voir_dist')
861
-	) {
862
-		return $f($faire, $type, $id, $qui, $opt);
863
-	}
857
+    # securite, mais on aurait pas du arriver ici !
858
+    if (
859
+        function_exists($f = 'autoriser_' . $type . '_voir')
860
+        || function_exists($f = 'autoriser_' . $type . '_voir_dist')
861
+    ) {
862
+        return $f($faire, $type, $id, $qui, $opt);
863
+    }
864 864
 
865
-	if ($qui['statut'] === '0minirezo') {
866
-		return true;
867
-	}
868
-	// admins et redacteurs peuvent voir un auteur
869
-	if ($type === 'auteur') {
870
-		return in_array($qui['statut'], ['0minirezo', '1comite']);
871
-	}
872
-	// sinon par defaut tout est visible
873
-	// sauf cas particuliers traites separemment (ie article)
874
-	return true;
865
+    if ($qui['statut'] === '0minirezo') {
866
+        return true;
867
+    }
868
+    // admins et redacteurs peuvent voir un auteur
869
+    if ($type === 'auteur') {
870
+        return in_array($qui['statut'], ['0minirezo', '1comite']);
871
+    }
872
+    // sinon par defaut tout est visible
873
+    // sauf cas particuliers traites separemment (ie article)
874
+    return true;
875 875
 }
876 876
 
877 877
 
@@ -894,12 +894,12 @@  discard block
 block discarded – undo
894 894
  * @return bool true s'il a le droit, false sinon
895 895
  **/
896 896
 function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
897
-	return
898
-		(defined('_ID_WEBMESTRES')
899
-			? in_array($qui['id_auteur'], explode(':', (string) _ID_WEBMESTRES))
900
-			: $qui['webmestre'] === 'oui')
901
-		&& $qui['statut'] === '0minirezo'
902
-		&& !$qui['restreint'];
897
+    return
898
+        (defined('_ID_WEBMESTRES')
899
+            ? in_array($qui['id_auteur'], explode(':', (string) _ID_WEBMESTRES))
900
+            : $qui['webmestre'] === 'oui')
901
+        && $qui['statut'] === '0minirezo'
902
+        && !$qui['restreint'];
903 903
 }
904 904
 
905 905
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  * @return bool true s'il a le droit, false sinon
918 918
  **/
919 919
 function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
920
-	return $qui['statut'] === '0minirezo' && !$qui['restreint'];
920
+    return $qui['statut'] === '0minirezo' && !$qui['restreint'];
921 921
 }
922 922
 
923 923
 /**
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
  * @return bool true s'il a le droit, false sinon
936 936
  **/
937 937
 function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
938
-	return $qui['statut'] === '0minirezo';
938
+    return $qui['statut'] === '0minirezo';
939 939
 }
940 940
 
941 941
 /**
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
  * @return bool true s'il a le droit, false sinon
954 954
  **/
955 955
 function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
956
-	return autoriser('webmestre', null, 0, $qui, $opt);
956
+    return autoriser('webmestre', null, 0, $qui, $opt);
957 957
 }
958 958
 
959 959
 /**
@@ -972,23 +972,23 @@  discard block
 block discarded – undo
972 972
  * @return bool true s'il a le droit, false sinon
973 973
  **/
974 974
 function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
975
-	// les admins peuvent "previsualiser" une page auteur
976
-	if (
977
-		$qui['statut'] === '0minirezo'
978
-		&& !$qui['restreint']
979
-	) {
980
-		return true;
981
-	} elseif ($id === 0) {
982
-		return false;
983
-	}
984
-	// "Voir en ligne" si l'auteur a un article publie
985
-	$n = sql_fetsel(
986
-		'A.id_article',
987
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
988
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
989
-	);
975
+    // les admins peuvent "previsualiser" une page auteur
976
+    if (
977
+        $qui['statut'] === '0minirezo'
978
+        && !$qui['restreint']
979
+    ) {
980
+        return true;
981
+    } elseif ($id === 0) {
982
+        return false;
983
+    }
984
+    // "Voir en ligne" si l'auteur a un article publie
985
+    $n = sql_fetsel(
986
+        'A.id_article',
987
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
988
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
989
+    );
990 990
 
991
-	return (bool) $n;
991
+    return (bool) $n;
992 992
 }
993 993
 
994 994
 
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
  * @return bool true s'il a le droit, false sinon
1018 1018
  **/
1019 1019
 function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1020
-	return ($qui['statut'] === '0minirezo');
1020
+    return ($qui['statut'] === '0minirezo');
1021 1021
 }
1022 1022
 
1023 1023
 
@@ -1038,68 +1038,68 @@  discard block
 block discarded – undo
1038 1038
  * @return bool true s'il a le droit, false sinon
1039 1039
  **/
1040 1040
 function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1041
-	$id = (int) $id;
1042
-
1043
-	// Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1044
-	// la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1045
-	if ($qui['statut'] != '0minirezo') {
1046
-		return $id == $qui['id_auteur']
1047
-			&& empty($opt['statut'])
1048
-			&& empty($opt['webmestre'])
1049
-			&& empty($opt['restreintes'])
1050
-			&& empty($opt['login']);
1051
-	}
1052
-
1053
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
1054
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1055
-	if ($qui['restreint']) {
1056
-		if (isset($opt['webmestre']) && $opt['webmestre']) {
1057
-			return false;
1058
-		} elseif (
1059
-			isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes']
1060
-		) {
1061
-			return false;
1062
-		} else {
1063
-			if ($id == $qui['id_auteur']) {
1064
-				if (isset($opt['statut']) && $opt['statut']) {
1065
-					return false;
1066
-				} else {
1067
-					return true;
1068
-				}
1069
-			} else {
1070
-				if ($id_auteur = (int) $id) {
1071
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1072
-					if ($t && $t['statut'] != '0minirezo') {
1073
-						return true;
1074
-					} else {
1075
-						return false;
1076
-					}
1077
-				} // id = 0 => creation
1078
-				else {
1079
-					return true;
1080
-				}
1081
-			}
1082
-		}
1083
-	}
1084
-
1085
-	// Un admin complet fait ce qu'il veut
1086
-	// sauf se degrader
1087
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) {
1088
-		return false;
1089
-	} elseif (
1090
-		isset($opt['webmestre'])
1091
-		&& $opt['webmestre']
1092
-		&& (defined('_ID_WEBMESTRES') || !autoriser('webmestre'))
1093
-	) {
1094
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1095
-		// ou si les webmestres sont fixes par constante (securite)
1096
-		return false;
1097
-	} // et modifier un webmestre si il ne l'est pas lui meme
1098
-	elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) {
1099
-		return false;
1100
-	} else {
1101
-		return true;
1102
-	}
1041
+    $id = (int) $id;
1042
+
1043
+    // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1044
+    // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1045
+    if ($qui['statut'] != '0minirezo') {
1046
+        return $id == $qui['id_auteur']
1047
+            && empty($opt['statut'])
1048
+            && empty($opt['webmestre'])
1049
+            && empty($opt['restreintes'])
1050
+            && empty($opt['login']);
1051
+    }
1052
+
1053
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
1054
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1055
+    if ($qui['restreint']) {
1056
+        if (isset($opt['webmestre']) && $opt['webmestre']) {
1057
+            return false;
1058
+        } elseif (
1059
+            isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes']
1060
+        ) {
1061
+            return false;
1062
+        } else {
1063
+            if ($id == $qui['id_auteur']) {
1064
+                if (isset($opt['statut']) && $opt['statut']) {
1065
+                    return false;
1066
+                } else {
1067
+                    return true;
1068
+                }
1069
+            } else {
1070
+                if ($id_auteur = (int) $id) {
1071
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1072
+                    if ($t && $t['statut'] != '0minirezo') {
1073
+                        return true;
1074
+                    } else {
1075
+                        return false;
1076
+                    }
1077
+                } // id = 0 => creation
1078
+                else {
1079
+                    return true;
1080
+                }
1081
+            }
1082
+        }
1083
+    }
1084
+
1085
+    // Un admin complet fait ce qu'il veut
1086
+    // sauf se degrader
1087
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) {
1088
+        return false;
1089
+    } elseif (
1090
+        isset($opt['webmestre'])
1091
+        && $opt['webmestre']
1092
+        && (defined('_ID_WEBMESTRES') || !autoriser('webmestre'))
1093
+    ) {
1094
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1095
+        // ou si les webmestres sont fixes par constante (securite)
1096
+        return false;
1097
+    } // et modifier un webmestre si il ne l'est pas lui meme
1098
+    elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) {
1099
+        return false;
1100
+    } else {
1101
+        return true;
1102
+    }
1103 1103
 }
1104 1104
 
1105 1105
 
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
  * @return bool true s'il a le droit, false sinon
1119 1119
  **/
1120 1120
 function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1121
-	return autoriser('modifier', $type, $id, $qui, $opt);
1121
+    return autoriser('modifier', $type, $id, $qui, $opt);
1122 1122
 }
1123 1123
 
1124 1124
 
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
  * @return bool true s'il a le droit, false sinon
1138 1138
  **/
1139 1139
 function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1140
-	return $qui['statut'] === '0minirezo';
1140
+    return $qui['statut'] === '0minirezo';
1141 1141
 }
1142 1142
 
1143 1143
 /**
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
  * @return bool true s'il a le droit, false sinon
1156 1156
  **/
1157 1157
 function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1158
-	return $qui['statut'] === '0minirezo';
1158
+    return $qui['statut'] === '0minirezo';
1159 1159
 }
1160 1160
 
1161 1161
 /**
@@ -1172,53 +1172,53 @@  discard block
 block discarded – undo
1172 1172
  * @return array          Liste des rubriques
1173 1173
  **/
1174 1174
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1175
-	static $restreint = [];
1176
-
1177
-	if (!$id_auteur = (int) $id_auteur) {
1178
-		return [];
1179
-	}
1180
-	if ($raz) {
1181
-		unset($restreint[$id_auteur]);
1182
-	} elseif (isset($restreint[$id_auteur])) {
1183
-		return $restreint[$id_auteur];
1184
-	}
1185
-
1186
-	$rubriques = [];
1187
-	if (
1188
-		(!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428)
1189
-		&& ($r = sql_allfetsel(
1190
-			'id_objet',
1191
-			'spip_auteurs_liens',
1192
-			'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0"
1193
-		))
1194
-		&& (is_countable($r) ? count($r) : 0)
1195
-	) {
1196
-		$r = array_column($r, 'id_objet');
1197
-
1198
-		// recuperer toute la branche, au format chaine enumeration
1199
-		include_spip('inc/rubriques');
1200
-		$r = calcul_branche_in($r);
1201
-		$r = explode(',', (string) $r);
1202
-
1203
-		// passer les rubriques en index, elimine les doublons
1204
-		$r = array_flip($r);
1205
-		// recuperer les index seuls
1206
-		$r = array_keys($r);
1207
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1208
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1209
-		$rubriques = array_combine($r, $r);
1210
-	}
1211
-
1212
-	// Affecter l'auteur session le cas echeant
1213
-	if (
1214
-		isset($GLOBALS['visiteur_session']['id_auteur'])
1215
-		&& $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1216
-	) {
1217
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1218
-	}
1219
-
1220
-
1221
-	return $restreint[$id_auteur] = $rubriques;
1175
+    static $restreint = [];
1176
+
1177
+    if (!$id_auteur = (int) $id_auteur) {
1178
+        return [];
1179
+    }
1180
+    if ($raz) {
1181
+        unset($restreint[$id_auteur]);
1182
+    } elseif (isset($restreint[$id_auteur])) {
1183
+        return $restreint[$id_auteur];
1184
+    }
1185
+
1186
+    $rubriques = [];
1187
+    if (
1188
+        (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428)
1189
+        && ($r = sql_allfetsel(
1190
+            'id_objet',
1191
+            'spip_auteurs_liens',
1192
+            'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0"
1193
+        ))
1194
+        && (is_countable($r) ? count($r) : 0)
1195
+    ) {
1196
+        $r = array_column($r, 'id_objet');
1197
+
1198
+        // recuperer toute la branche, au format chaine enumeration
1199
+        include_spip('inc/rubriques');
1200
+        $r = calcul_branche_in($r);
1201
+        $r = explode(',', (string) $r);
1202
+
1203
+        // passer les rubriques en index, elimine les doublons
1204
+        $r = array_flip($r);
1205
+        // recuperer les index seuls
1206
+        $r = array_keys($r);
1207
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1208
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1209
+        $rubriques = array_combine($r, $r);
1210
+    }
1211
+
1212
+    // Affecter l'auteur session le cas echeant
1213
+    if (
1214
+        isset($GLOBALS['visiteur_session']['id_auteur'])
1215
+        && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1216
+    ) {
1217
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1218
+    }
1219
+
1220
+
1221
+    return $restreint[$id_auteur] = $rubriques;
1222 1222
 }
1223 1223
 
1224 1224
 /**
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
  * @return bool true s'il a le droit, false sinon
1237 1237
  **/
1238 1238
 function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1239
-	return autoriser('previsualiser');
1239
+    return autoriser('previsualiser');
1240 1240
 }
1241 1241
 
1242 1242
 /**
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
  * @return bool true s'il a le droit, false sinon
1255 1255
  **/
1256 1256
 function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1257
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1257
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1258 1258
 }
1259 1259
 
1260 1260
 /**
@@ -1272,8 +1272,8 @@  discard block
 block discarded – undo
1272 1272
  * @return bool true s'il a le droit, false sinon
1273 1273
  **/
1274 1274
 function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1275
-	$id = (int) $id;
1276
-	return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']);
1275
+    $id = (int) $id;
1276
+    return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']);
1277 1277
 }
1278 1278
 
1279 1279
 /**
@@ -1291,8 +1291,8 @@  discard block
 block discarded – undo
1291 1291
  * @return bool true s'il a le droit, false sinon
1292 1292
  **/
1293 1293
 function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1294
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1295
-	return autoriser('modifier', $type, $id, $qui, $opt);
1294
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1295
+    return autoriser('modifier', $type, $id, $qui, $opt);
1296 1296
 }
1297 1297
 
1298 1298
 
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
  * @return true
1313 1313
  **/
1314 1314
 function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1315
-	return true;
1315
+    return true;
1316 1316
 }
1317 1317
 
1318 1318
 /**
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
  * @return false
1332 1332
  **/
1333 1333
 function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1334
-	return false;
1334
+    return false;
1335 1335
 }
1336 1336
 
1337 1337
 /**
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
  * @return bool true s'il a le droit, false sinon
1350 1350
  **/
1351 1351
 function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1352
-	return autoriser('detruire') && !_request('reinstall');
1352
+    return autoriser('detruire') && !_request('reinstall');
1353 1353
 }
1354 1354
 
1355 1355
 /**
@@ -1367,7 +1367,7 @@  discard block
 block discarded – undo
1367 1367
  * @return true
1368 1368
  **/
1369 1369
 function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1370
-	return true;
1370
+    return true;
1371 1371
 }
1372 1372
 
1373 1373
 /**
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
  * @return true
1386 1386
  **/
1387 1387
 function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1388
-	return true;
1388
+    return true;
1389 1389
 }
1390 1390
 
1391 1391
 /**
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
  * @return bool true s'il a le droit, false sinon
1404 1404
  **/
1405 1405
 function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1406
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1406
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1407 1407
 }
1408 1408
 
1409 1409
 /**
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
  * @return true
1422 1422
  **/
1423 1423
 function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1424
-	return true;
1424
+    return true;
1425 1425
 }
1426 1426
 
1427 1427
 /**
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
  * @return bool true s'il a le droit, false sinon
1440 1440
  **/
1441 1441
 function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1442
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1442
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1443 1443
 }
1444 1444
 
1445 1445
 /**
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
  * @return bool true s'il a le droit, false sinon
1458 1458
  **/
1459 1459
 function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1460
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1460
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1461 1461
 }
1462 1462
 
1463 1463
 /**
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
  * @return true
1477 1477
  **/
1478 1478
 function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1479
-	return true;
1479
+    return true;
1480 1480
 }
1481 1481
 
1482 1482
 /**
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
  * @return true
1495 1495
  **/
1496 1496
 function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1497
-	return true;
1497
+    return true;
1498 1498
 }
1499 1499
 
1500 1500
 /**
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
  * @return bool true s'il a le droit, false sinon
1513 1513
  **/
1514 1514
 function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1515
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1515
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1516 1516
 }
1517 1517
 
1518 1518
 /**
@@ -1530,7 +1530,7 @@  discard block
 block discarded – undo
1530 1530
  * @return true
1531 1531
  **/
1532 1532
 function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1533
-	return true;
1533
+    return true;
1534 1534
 }
1535 1535
 
1536 1536
 /**
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
  * @return bool true s'il a le droit, false sinon
1549 1549
  **/
1550 1550
 function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1551
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1551
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1552 1552
 }
1553 1553
 
1554 1554
 /**
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
  * @return true
1567 1567
  **/
1568 1568
 function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1569
-	return true;
1569
+    return true;
1570 1570
 }
1571 1571
 
1572 1572
 /**
@@ -1584,7 +1584,7 @@  discard block
 block discarded – undo
1584 1584
  * @return bool true s'il a le droit, false sinon
1585 1585
  **/
1586 1586
 function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1587
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1587
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1588 1588
 }
1589 1589
 
1590 1590
 /**
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
  * @return bool true s'il a le droit, false sinon
1603 1603
  **/
1604 1604
 function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1605
-	return verifier_table_non_vide();
1605
+    return verifier_table_non_vide();
1606 1606
 }
1607 1607
 
1608 1608
 
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
  * @return bool true s'il a le droit, false sinon
1624 1624
  **/
1625 1625
 function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1626
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1626
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1627 1627
 }
1628 1628
 
1629 1629
 /**
@@ -1641,11 +1641,11 @@  discard block
 block discarded – undo
1641 1641
  * @return bool true s'il a le droit, false sinon
1642 1642
  **/
1643 1643
 function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1644
-	include_spip('base/abstract_sql');
1645
-	return
1646
-		$qui['statut'] === '0minirezo'
1647
-		&& !$qui['restreint']
1648
-		&& ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0);
1644
+    include_spip('base/abstract_sql');
1645
+    return
1646
+        $qui['statut'] === '0minirezo'
1647
+        && !$qui['restreint']
1648
+        && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0);
1649 1649
 }
1650 1650
 
1651 1651
 /**
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
  * @return bool true s'il a le droit, false sinon
1664 1664
  **/
1665 1665
 function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1666
-	return $qui['statut'] === '0minirezo';
1666
+    return $qui['statut'] === '0minirezo';
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
  * @return bool true s'il a le droit, false sinon
1682 1682
  **/
1683 1683
 function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1684
-	return $qui['statut'] === '0minirezo';
1684
+    return $qui['statut'] === '0minirezo';
1685 1685
 }
1686 1686
 
1687 1687
 /**
@@ -1699,7 +1699,7 @@  discard block
 block discarded – undo
1699 1699
  * @return bool true s'il a le droit, false sinon
1700 1700
  **/
1701 1701
 function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1702
-	return autoriser('configurer', '_interactions', $id, $qui, $opt);
1702
+    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1703 1703
 }
1704 1704
 
1705 1705
 /**
@@ -1717,7 +1717,7 @@  discard block
 block discarded – undo
1717 1717
  * @return bool true s'il a le droit, false sinon
1718 1718
  **/
1719 1719
 function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1720
-	return autoriser('configurer', '_langue', $id, $qui, $opt);
1720
+    return autoriser('configurer', '_langue', $id, $qui, $opt);
1721 1721
 }
1722 1722
 
1723 1723
 /**
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
  * @return bool true s'il a le droit, false sinon
1736 1736
  **/
1737 1737
 function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1738
-	return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1738
+    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1739 1739
 }
1740 1740
 
1741 1741
 /**
@@ -1753,7 +1753,7 @@  discard block
 block discarded – undo
1753 1753
  * @return bool true s'il a le droit, false sinon
1754 1754
  **/
1755 1755
 function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1756
-	return autoriser('configurer', '_contenu', $id, $qui, $opt);
1756
+    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1757 1757
 }
1758 1758
 
1759 1759
 /**
@@ -1771,7 +1771,7 @@  discard block
 block discarded – undo
1771 1771
  * @return bool true s'il a le droit, false sinon
1772 1772
  **/
1773 1773
 function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1774
-	return autoriser('configurer', '_avancees', $id, $qui, $opt);
1774
+    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1775 1775
 }
1776 1776
 
1777 1777
 /**
@@ -1789,7 +1789,7 @@  discard block
 block discarded – undo
1789 1789
  * @return bool true s'il a le droit, false sinon
1790 1790
  **/
1791 1791
 function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1792
-	return autoriser('configurer', '_plugins', $id, $qui, $opt);
1792
+    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1793 1793
 }
1794 1794
 
1795 1795
 /**
@@ -1807,7 +1807,7 @@  discard block
 block discarded – undo
1807 1807
  * @return bool true s'il a le droit, false sinon
1808 1808
  **/
1809 1809
 function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1810
-	return autoriser('detruire', $type, $id, $qui, $opt);
1810
+    return autoriser('detruire', $type, $id, $qui, $opt);
1811 1811
 }
1812 1812
 
1813 1813
 /**
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
  * @return bool true s'il a le droit, false sinon
1826 1826
  **/
1827 1827
 function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1828
-	return autoriser('webmestre');
1828
+    return autoriser('webmestre');
1829 1829
 }
1830 1830
 
1831 1831
 
@@ -1845,11 +1845,11 @@  discard block
 block discarded – undo
1845 1845
  * @return bool true s'il a le droit, false sinon
1846 1846
  **/
1847 1847
 function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1848
-	if (test_espace_prive()) {
1849
-		return (bool) (int) $qui['id_auteur'];
1850
-	} else {
1851
-		return autoriser('webmestre', '', $id, $qui, $opt);
1852
-	}
1848
+    if (test_espace_prive()) {
1849
+        return (bool) (int) $qui['id_auteur'];
1850
+    } else {
1851
+        return autoriser('webmestre', '', $id, $qui, $opt);
1852
+    }
1853 1853
 }
1854 1854
 
1855 1855
 
@@ -1864,27 +1864,27 @@  discard block
 block discarded – undo
1864 1864
  *     Identifiants d'auteurs
1865 1865
  */
1866 1866
 function auteurs_objet($objet, $id_objet, $cond = '') {
1867
-	$objet = objet_type($objet);
1868
-	$where = [
1869
-		'objet=' . sql_quote($objet),
1870
-		'id_objet=' . (int) $id_objet
1871
-	];
1872
-	if (!empty($cond)) {
1873
-		if (is_array($cond)) {
1874
-			$where = array_merge($where, $cond);
1875
-		} else {
1876
-			$where[] = $cond;
1877
-		}
1878
-	}
1879
-	$auteurs = sql_allfetsel(
1880
-		'id_auteur',
1881
-		'spip_auteurs_liens',
1882
-		$where
1883
-	);
1884
-	if (is_array($auteurs)) {
1885
-		return array_column($auteurs, 'id_auteur');
1886
-	}
1887
-	return [];
1867
+    $objet = objet_type($objet);
1868
+    $where = [
1869
+        'objet=' . sql_quote($objet),
1870
+        'id_objet=' . (int) $id_objet
1871
+    ];
1872
+    if (!empty($cond)) {
1873
+        if (is_array($cond)) {
1874
+            $where = array_merge($where, $cond);
1875
+        } else {
1876
+            $where[] = $cond;
1877
+        }
1878
+    }
1879
+    $auteurs = sql_allfetsel(
1880
+        'id_auteur',
1881
+        'spip_auteurs_liens',
1882
+        $where
1883
+    );
1884
+    if (is_array($auteurs)) {
1885
+        return array_column($auteurs, 'id_auteur');
1886
+    }
1887
+    return [];
1888 1888
 }
1889 1889
 
1890 1890
 /**
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
  */
1898 1898
 function acces_restreint_rubrique($id_rubrique) {
1899 1899
 
1900
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1900
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1901 1901
 }
1902 1902
 
1903 1903
 
@@ -1910,12 +1910,12 @@  discard block
 block discarded – undo
1910 1910
  * @return bool             true si un parent existe
1911 1911
  */
1912 1912
 function verifier_table_non_vide($table = 'spip_rubriques') {
1913
-	static $done = [];
1914
-	if (!isset($done[$table])) {
1915
-		$done[$table] = sql_countsel($table) > 0;
1916
-	}
1913
+    static $done = [];
1914
+    if (!isset($done[$table])) {
1915
+        $done[$table] = sql_countsel($table) > 0;
1916
+    }
1917 1917
 
1918
-	return $done[$table];
1918
+    return $done[$table];
1919 1919
 }
1920 1920
 
1921 1921
 /**
@@ -1942,12 +1942,12 @@  discard block
 block discarded – undo
1942 1942
  */
1943 1943
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
1944 1944
 
1945
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1946
-	return match ($s) {
1947
-		'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui',
1948
-		'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo',
1949
-		default => false,
1950
-	};
1945
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1946
+    return match ($s) {
1947
+        'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui',
1948
+        'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo',
1949
+        default => false,
1950
+    };
1951 1951
 }
1952 1952
 
1953 1953
 /**
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
  * @return bool true s'il a le droit, false sinon
1966 1966
  **/
1967 1967
 function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1968
-	return $qui['statut'] === '0minirezo' && !$qui['restreint'];
1968
+    return $qui['statut'] === '0minirezo' && !$qui['restreint'];
1969 1969
 }
1970 1970
 
1971 1971
 /**
@@ -1983,5 +1983,5 @@  discard block
 block discarded – undo
1983 1983
  * @return bool true s'il a le droit, false sinon
1984 1984
  **/
1985 1985
 function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1986
-	return autoriser('webmestre');
1986
+    return autoriser('webmestre');
1987 1987
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 // mais apres la fonction autoriser()
120 120
 if ($f = find_in_path('mes_fonctions.php')) {
121 121
 	global $dossier_squelettes;
122
-	include_once(_ROOT_CWD . $f);
122
+	include_once(_ROOT_CWD.$f);
123 123
 }
124 124
 
125 125
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		$qui = $GLOBALS['visiteur_session'] ?: [];
161 161
 		$qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
162 162
 	} elseif (is_numeric($qui)) {
163
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
163
+		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui);
164 164
 		if (!$qui) {
165 165
 			return false;
166 166
 		}
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	}
174 174
 
175 175
 	spip_log(
176
-		"autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
177
-		'autoriser' . _LOG_DEBUG
176
+		"autoriser $faire $type $id (".($qui['nom'] ?? '').') ?',
177
+		'autoriser'._LOG_DEBUG
178 178
 	);
179 179
 
180 180
 	// passer par objet_type pour avoir les alias
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
191 191
 		&& autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier')
192 192
 	) {
193
-		spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
193
+		spip_log("autoriser ($faire, $type, $id, ".($qui['nom'] ?? '').') : OK Exception', 'autoriser'._LOG_DEBUG);
194 194
 		return true;
195 195
 	}
196 196
 
@@ -199,18 +199,18 @@  discard block
 block discarded – undo
199 199
 	// autoriser_faire[_dist], autoriser_defaut[_dist]
200 200
 	$fonctions = $type
201 201
 		? [
202
-			'autoriser_' . $type . '_' . $faire,
203
-			'autoriser_' . $type . '_' . $faire . '_dist',
204
-			'autoriser_' . $type,
205
-			'autoriser_' . $type . '_dist',
206
-			'autoriser_' . $faire,
207
-			'autoriser_' . $faire . '_dist',
202
+			'autoriser_'.$type.'_'.$faire,
203
+			'autoriser_'.$type.'_'.$faire.'_dist',
204
+			'autoriser_'.$type,
205
+			'autoriser_'.$type.'_dist',
206
+			'autoriser_'.$faire,
207
+			'autoriser_'.$faire.'_dist',
208 208
 			'autoriser_defaut',
209 209
 			'autoriser_defaut_dist'
210 210
 		]
211 211
 		: [
212
-			'autoriser_' . $faire,
213
-			'autoriser_' . $faire . '_dist',
212
+			'autoriser_'.$faire,
213
+			'autoriser_'.$faire.'_dist',
214 214
 			'autoriser_defaut',
215 215
 			'autoriser_defaut_dist'
216 216
 		];
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	}
225 225
 
226 226
 	spip_log(
227
-		"$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
228
-		'autoriser' . _LOG_DEBUG
227
+		"$f($faire, $type, $id, ".($qui['nom'] ?? '').') : '.($a ? 'OK' : 'niet'),
228
+		'autoriser'._LOG_DEBUG
229 229
 	);
230 230
 
231 231
 	return $a;
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
370 370
 
371 371
 	// Le visiteur a-t-il un statut prevu par la config ?
372
-	if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) {
372
+	if (str_contains((string) $GLOBALS['meta']['preview'], ','.$qui['statut'].',')) {
373 373
 		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
374 374
 	}
375 375
 
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 				} // pas de champ passe a la demande => NIET
424 424
 				$previsu = explode(',', (string) $c['previsu']);
425 425
 				// regarder si ce statut est autorise pour l'auteur
426
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
426
+				if (in_array($opt[$champ].'/auteur', $previsu)) {
427 427
 					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
428 428
 					// sinon l’auteur en session
429 429
 					include_spip('inc/securiser_action');
@@ -437,12 +437,12 @@  discard block
 block discarded – undo
437 437
 
438 438
 					if (!$id_auteur) {
439 439
 						return false;
440
-					} elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
440
+					} elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) {
441 441
 						// dans ce cas (admin en general), pas de filtrage sur ce statut
442 442
 					} elseif (
443 443
 						!sql_countsel(
444 444
 							'spip_auteurs_liens',
445
-							'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id
445
+							'id_auteur='.(int) $id_auteur.' AND objet='.sql_quote($type).' AND id_objet='.(int) $id
446 446
 						)
447 447
 					) {
448 448
 						return false;
@@ -487,14 +487,14 @@  discard block
 block discarded – undo
487 487
 			// multilinguisme par secteur et objet rattaché à une rubrique
488 488
 			$primary = id_table_objet($type);
489 489
 			$id_rubrique = $table != 'spip_rubriques'
490
-				? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id)
490
+				? sql_getfetsel('id_rubrique', "$table", "$primary=".(int) $id)
491 491
 				: $id;
492
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
492
+			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique);
493 493
 			if (!$id_secteur > 0) {
494 494
 				$id_secteur = $id_rubrique;
495 495
 			}
496
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur);
497
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id);
496
+			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.(int) $id_secteur);
497
+			$langue_objet = sql_getfetsel('lang', "$table", "$primary=".(int) $id);
498 498
 			if ($langue_secteur != $langue_objet) {
499 499
 				// configuration incohérente, on laisse l'utilisateur corriger la situation
500 500
 				return true;
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
503 503
 				return false;
504 504
 			} else {
505
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id);
505
+				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id);
506 506
 				if ($id_parent != 0) {
507 507
 					// sous-rubriques : pas de choix de langue
508 508
 					return false;
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 
555 555
 	if (!isset($opt['statut'])) {
556 556
 		if (isset($desc['field']['statut'])) {
557
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id);
557
+			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.(int) $id);
558 558
 		} else {
559 559
 			$statut = 'publie';
560 560
 		} // pas de statut => publie
@@ -719,11 +719,11 @@  discard block
 block discarded – undo
719 719
 		return false;
720 720
 	}
721 721
 
722
-	if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) {
722
+	if (sql_countsel('spip_rubriques', 'id_parent='.(int) $id)) {
723 723
 		return false;
724 724
 	}
725 725
 
726
-	if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) {
726
+	if (sql_countsel('spip_articles', 'id_rubrique='.(int) $id." AND (statut<>'poubelle')")) {
727 727
 		return false;
728 728
 	}
729 729
 
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 	if (!$id) {
761 761
 		return false;
762 762
 	}
763
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
763
+	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id));
764 764
 
765 765
 	return $r && (
766 766
 		autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
 			(!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true))
769 769
 			&& in_array($qui['statut'], ['0minirezo', '1comite'])
770 770
 			&& in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
771
-			&& auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
771
+			&& auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])
772 772
 		)
773 773
 	);
774 774
 }
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 		if (!$id) {
827 827
 			return false;
828 828
 		}
829
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id);
829
+		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.(int) $id);
830 830
 	}
831 831
 
832 832
 	return
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 		in_array($statut, ['prop', 'publie'])
836 836
 		// sinon si on est auteur, on a le droit de le voir, evidemment !
837 837
 
838
-		|| $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']);
838
+		|| $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']);
839 839
 }
840 840
 
841 841
 
@@ -856,8 +856,8 @@  discard block
 block discarded – undo
856 856
 function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
857 857
 	# securite, mais on aurait pas du arriver ici !
858 858
 	if (
859
-		function_exists($f = 'autoriser_' . $type . '_voir')
860
-		|| function_exists($f = 'autoriser_' . $type . '_voir_dist')
859
+		function_exists($f = 'autoriser_'.$type.'_voir')
860
+		|| function_exists($f = 'autoriser_'.$type.'_voir_dist')
861 861
 	) {
862 862
 		return $f($faire, $type, $id, $qui, $opt);
863 863
 	}
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 	$n = sql_fetsel(
986 986
 		'A.id_article',
987 987
 		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
988
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
988
+		"A.statut='publie' AND L.id_auteur=".sql_quote($id)
989 989
 	);
990 990
 
991 991
 	return (bool) $n;
@@ -1189,7 +1189,7 @@  discard block
 block discarded – undo
1189 1189
 		&& ($r = sql_allfetsel(
1190 1190
 			'id_objet',
1191 1191
 			'spip_auteurs_liens',
1192
-			'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0"
1192
+			'id_auteur='.(int) $id_auteur." AND objet='rubrique' AND id_objet!=0"
1193 1193
 		))
1194 1194
 		&& (is_countable($r) ? count($r) : 0)
1195 1195
 	) {
@@ -1866,8 +1866,8 @@  discard block
 block discarded – undo
1866 1866
 function auteurs_objet($objet, $id_objet, $cond = '') {
1867 1867
 	$objet = objet_type($objet);
1868 1868
 	$where = [
1869
-		'objet=' . sql_quote($objet),
1870
-		'id_objet=' . (int) $id_objet
1869
+		'objet='.sql_quote($objet),
1870
+		'id_objet='.(int) $id_objet
1871 1871
 	];
1872 1872
 	if (!empty($cond)) {
1873 1873
 		if (is_array($cond)) {
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 2 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Filtres
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -36,29 +36,29 @@  discard block
 block discarded – undo
36 36
  *     - une chaîne vide si la date est considérée nulle
37 37
  **/
38 38
 function normaliser_date($date, $forcer_jour = false): string {
39
-	$date = vider_date($date);
40
-	if ($date) {
41
-		if (preg_match('/^\d{8,10}$/', $date)) {
42
-			$date = date('Y-m-d H:i:s', $date);
43
-		}
44
-		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
-			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
47
-		} else {
48
-			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
-				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
-			} else {
52
-				$date = date('Y-m-d H:i:s', strtotime($date));
53
-			}
54
-		}
55
-
56
-		if ($forcer_jour) {
57
-			$date = str_replace('-00', '-01', $date);
58
-		}
59
-	}
60
-
61
-	return $date;
39
+    $date = vider_date($date);
40
+    if ($date) {
41
+        if (preg_match('/^\d{8,10}$/', $date)) {
42
+            $date = date('Y-m-d H:i:s', $date);
43
+        }
44
+        if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
+            $regs = array_pad($regs, 4, null); // eviter notice php
46
+            $date = $regs[1] . '-00-00' . $regs[3];
47
+        } else {
48
+            if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
+                $regs = array_pad($regs, 4, null); // eviter notice php
50
+                $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
+            } else {
52
+                $date = date('Y-m-d H:i:s', strtotime($date));
53
+            }
54
+        }
55
+
56
+        if ($forcer_jour) {
57
+            $date = str_replace('-00', '-01', $date);
58
+        }
59
+    }
60
+
61
+    return $date;
62 62
 }
63 63
 
64 64
 /**
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
  *     - Une chaine vide
72 72
  **/
73 73
 function vider_date($letexte, $verif_format_date = false): string {
74
-	$letexte ??= '';
75
-	if (
76
-		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
-	) {
79
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
-			return '';
81
-		}
82
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
-			return '';
84
-		}
85
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
-			return '';
87
-		}  // eviter le bug GMT-1
88
-	}
89
-	return $letexte;
74
+    $letexte ??= '';
75
+    if (
76
+        !$verif_format_date
77
+        || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
+    ) {
79
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
+            return '';
81
+        }
82
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
+            return '';
84
+        }
85
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
+            return '';
87
+        }  // eviter le bug GMT-1
88
+    }
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /**
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
  **/
103 103
 function recup_heure($date): array {
104 104
 
105
-	if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
-		array_shift($elements);
107
-		if (!isset($elements[2])) {
108
-			$elements[2] = 0;
109
-		}
110
-		$heure = $elements;
111
-	} else {
112
-		$heure = [0, 0, 0];
113
-	}
114
-
115
-	return $heure;
105
+    if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
+        array_shift($elements);
107
+        if (!isset($elements[2])) {
108
+            $elements[2] = 0;
109
+        }
110
+        $heure = $elements;
111
+    } else {
112
+        $heure = [0, 0, 0];
113
+    }
114
+
115
+    return $heure;
116 116
 }
117 117
 
118 118
 /**
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
  * @return string heures, sinon 0
127 127
  **/
128 128
 function heures($numdate): string {
129
-	$heures = null;
130
-	$date_array = recup_heure($numdate);
131
-	if ($date_array) {
132
-		[$heures, $minutes, $secondes] = $date_array;
133
-	}
129
+    $heures = null;
130
+    $date_array = recup_heure($numdate);
131
+    if ($date_array) {
132
+        [$heures, $minutes, $secondes] = $date_array;
133
+    }
134 134
 
135
-	return $heures;
135
+    return $heures;
136 136
 }
137 137
 
138 138
 /**
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
  * @return string minutes, sinon 0
147 147
  **/
148 148
 function minutes($numdate): string {
149
-	$minutes = null;
150
-	$date_array = recup_heure($numdate);
151
-	if ($date_array) {
152
-		[$heures, $minutes, $secondes] = $date_array;
153
-	}
149
+    $minutes = null;
150
+    $date_array = recup_heure($numdate);
151
+    if ($date_array) {
152
+        [$heures, $minutes, $secondes] = $date_array;
153
+    }
154 154
 
155
-	return $minutes;
155
+    return $minutes;
156 156
 }
157 157
 
158 158
 /**
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
  * @return string secondes, sinon 0
167 167
  **/
168 168
 function secondes($numdate): string {
169
-	$secondes = null;
170
-	$date_array = recup_heure($numdate);
171
-	if ($date_array) {
172
-		[$heures, $minutes, $secondes] = $date_array;
173
-	}
169
+    $secondes = null;
170
+    $date_array = recup_heure($numdate);
171
+    if ($date_array) {
172
+        [$heures, $minutes, $secondes] = $date_array;
173
+    }
174 174
 
175
-	return $secondes;
175
+    return $secondes;
176 176
 }
177 177
 
178 178
 /**
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
  * @return string L'heure formatée dans la langue en cours.
192 192
  **/
193 193
 function heures_minutes($numdate, $forme = ''): string {
194
-	if ($forme !== 'abbr') {
195
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
-	} else {
197
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
-	}
194
+    if ($forme !== 'abbr') {
195
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
+    } else {
197
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
+    }
199 199
 }
200 200
 
201 201
 /**
@@ -220,57 +220,57 @@  discard block
 block discarded – undo
220 220
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
221 221
  **/
222 222
 function recup_date($numdate, $forcer_jour = true): array {
223
-	if (!$numdate) {
224
-		return [];
225
-	}
226
-	$heures = $minutes = $secondes = 0;
227
-	if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
-		$jour = $regs[1];
229
-		$mois = $regs[2];
230
-		$annee = $regs[3];
231
-		if ($annee < 90) {
232
-			$annee = 2000 + $annee;
233
-		} elseif ($annee < 100) {
234
-			$annee = 1900 + $annee;
235
-		}
236
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
237
-	} elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
-		$annee = $regs[1];
239
-		$mois = $regs[2];
240
-		$jour = $regs[3];
241
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
242
-	} elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
-		$annee = $regs[1];
244
-		$mois = $regs[2];
245
-		$jour = '';
246
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
247
-	} elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
-		$annee = $regs[1];
249
-		$mois = $regs[2];
250
-		$jour = $regs[3];
251
-		$heures = $regs[4];
252
-		$minutes = $regs[5];
253
-		$secondes = $regs[6];
254
-	} else {
255
-		$annee = $mois = $jour = '';
256
-	}
257
-	if ($annee > 4000) {
258
-		$annee -= 9000;
259
-	}
260
-	if (strlen($jour) && str_starts_with($jour, '0')) {
261
-		$jour = substr($jour, 1);
262
-	}
263
-
264
-	if ($forcer_jour && $jour == '0') {
265
-		$jour = '1';
266
-	}
267
-	if ($forcer_jour && $mois == '0') {
268
-		$mois = '1';
269
-	}
270
-	if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
-	}
273
-	return [];
223
+    if (!$numdate) {
224
+        return [];
225
+    }
226
+    $heures = $minutes = $secondes = 0;
227
+    if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
+        $jour = $regs[1];
229
+        $mois = $regs[2];
230
+        $annee = $regs[3];
231
+        if ($annee < 90) {
232
+            $annee = 2000 + $annee;
233
+        } elseif ($annee < 100) {
234
+            $annee = 1900 + $annee;
235
+        }
236
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
237
+    } elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
+        $annee = $regs[1];
239
+        $mois = $regs[2];
240
+        $jour = $regs[3];
241
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
242
+    } elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
+        $annee = $regs[1];
244
+        $mois = $regs[2];
245
+        $jour = '';
246
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
247
+    } elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
+        $annee = $regs[1];
249
+        $mois = $regs[2];
250
+        $jour = $regs[3];
251
+        $heures = $regs[4];
252
+        $minutes = $regs[5];
253
+        $secondes = $regs[6];
254
+    } else {
255
+        $annee = $mois = $jour = '';
256
+    }
257
+    if ($annee > 4000) {
258
+        $annee -= 9000;
259
+    }
260
+    if (strlen($jour) && str_starts_with($jour, '0')) {
261
+        $jour = substr($jour, 1);
262
+    }
263
+
264
+    if ($forcer_jour && $jour == '0') {
265
+        $jour = '1';
266
+    }
267
+    if ($forcer_jour && $mois == '0') {
268
+        $mois = '1';
269
+    }
270
+    if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
+    }
273
+    return [];
274 274
 }
275 275
 
276 276
 /**
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
  *     La date relative ou complète
298 298
  **/
299 299
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
300
-	return sinon(
301
-		date_relative($date, $decalage_maxi),
302
-		affdate_heure($date)
303
-	);
300
+    return sinon(
301
+        date_relative($date, $decalage_maxi),
302
+        affdate_heure($date)
303
+    );
304 304
 }
305 305
 
306 306
 /**
@@ -333,72 +333,72 @@  discard block
 block discarded – undo
333 333
  **/
334 334
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
335 335
 
336
-	if (!$date) {
337
-		return '';
338
-	}
339
-
340
-	$ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
-
342
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
343
-
344
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
-		return '';
346
-	}
347
-
348
-	if ($decal < 0) {
349
-		$il_y_a = 'date_dans';
350
-		$decal = -1 * $decal;
351
-	} else {
352
-		$il_y_a = 'date_il_y_a';
353
-	}
354
-
355
-	if ($decal > 3600 * 24 * 30 * 6) {
356
-		return affdate_court($date);
357
-	}
358
-
359
-	if ($decal > 3600 * 24 * 30) {
360
-		$mois = floor($decal / (3600 * 24 * 30));
361
-		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
364
-	} else {
365
-		if ($decal > 3600 * 24 * 7) {
366
-			$semaines = floor($decal / (3600 * 24 * 7));
367
-			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
370
-		} else {
371
-			if ($decal > 3600 * 24) {
372
-				$jours = floor($decal / (3600 * 24));
373
-				if ($jours < 2) {
374
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
-				} else {
376
-					$delai = "$jours " . _T('date_jours');
377
-				}
378
-			} else {
379
-				if ($decal >= 3600) {
380
-					$heures = floor($decal / 3600);
381
-					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
384
-				} else {
385
-					if ($decal >= 60) {
386
-						$minutes = floor($decal / 60);
387
-						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
390
-					} else {
391
-						$secondes = ceil($decal);
392
-						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
395
-					}
396
-				}
397
-			}
398
-		}
399
-	}
400
-
401
-	return _T($il_y_a, ['delai' => $delai]);
336
+    if (!$date) {
337
+        return '';
338
+    }
339
+
340
+    $ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
+
342
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
343
+
344
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
+        return '';
346
+    }
347
+
348
+    if ($decal < 0) {
349
+        $il_y_a = 'date_dans';
350
+        $decal = -1 * $decal;
351
+    } else {
352
+        $il_y_a = 'date_il_y_a';
353
+    }
354
+
355
+    if ($decal > 3600 * 24 * 30 * 6) {
356
+        return affdate_court($date);
357
+    }
358
+
359
+    if ($decal > 3600 * 24 * 30) {
360
+        $mois = floor($decal / (3600 * 24 * 30));
361
+        $delai = $mois < 2
362
+            ? "$mois " . _T('date_un_mois')
363
+            : "$mois " . _T('date_mois');
364
+    } else {
365
+        if ($decal > 3600 * 24 * 7) {
366
+            $semaines = floor($decal / (3600 * 24 * 7));
367
+            $delai = $semaines < 2
368
+                ? "$semaines " . _T('date_une_semaine')
369
+                : "$semaines " . _T('date_semaines');
370
+        } else {
371
+            if ($decal > 3600 * 24) {
372
+                $jours = floor($decal / (3600 * 24));
373
+                if ($jours < 2) {
374
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
+                } else {
376
+                    $delai = "$jours " . _T('date_jours');
377
+                }
378
+            } else {
379
+                if ($decal >= 3600) {
380
+                    $heures = floor($decal / 3600);
381
+                    $delai = $heures < 2
382
+                        ? "$heures " . _T('date_une_heure')
383
+                        : "$heures " . _T('date_heures');
384
+                } else {
385
+                    if ($decal >= 60) {
386
+                        $minutes = floor($decal / 60);
387
+                        $delai = $minutes < 2
388
+                            ? "$minutes " . _T('date_une_minute')
389
+                            : "$minutes " . _T('date_minutes');
390
+                    } else {
391
+                        $secondes = ceil($decal);
392
+                        $delai = $secondes < 2
393
+                            ? "$secondes " . _T('date_une_seconde')
394
+                            : "$secondes " . _T('date_secondes');
395
+                    }
396
+                }
397
+            }
398
+        }
399
+    }
400
+
401
+    return _T($il_y_a, ['delai' => $delai]);
402 402
 }
403 403
 
404 404
 
@@ -424,30 +424,30 @@  discard block
 block discarded – undo
424 424
  **/
425 425
 function date_relativecourt($date, $decalage_maxi = 0): string {
426 426
 
427
-	if (!$date) {
428
-		return '';
429
-	}
430
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
-
432
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
-		return '';
434
-	}
435
-
436
-	if ($decal < -24 * 3600) {
437
-		$retour = date_relative($date, $decalage_maxi);
438
-	} elseif ($decal < 0) {
439
-		$retour = _T('date_demain');
440
-	} else {
441
-		if ($decal < (3600 * 24)) {
442
-			$retour = _T('date_aujourdhui');
443
-		} else {
444
-			$retour = $decal < (3600 * 24 * 2)
445
-				? _T('date_hier')
446
-				: date_relative($date, $decalage_maxi);
447
-		}
448
-	}
449
-
450
-	return $retour;
427
+    if (!$date) {
428
+        return '';
429
+    }
430
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
+
432
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
+        return '';
434
+    }
435
+
436
+    if ($decal < -24 * 3600) {
437
+        $retour = date_relative($date, $decalage_maxi);
438
+    } elseif ($decal < 0) {
439
+        $retour = _T('date_demain');
440
+    } else {
441
+        if ($decal < (3600 * 24)) {
442
+            $retour = _T('date_aujourdhui');
443
+        } else {
444
+            $retour = $decal < (3600 * 24 * 2)
445
+                ? _T('date_hier')
446
+                : date_relative($date, $decalage_maxi);
447
+        }
448
+    }
449
+
450
+    return $retour;
451 451
 }
452 452
 
453 453
 /**
@@ -464,173 +464,173 @@  discard block
 block discarded – undo
464 464
  * @return string
465 465
  */
466 466
 function affdate_base($numdate, $vue, $options = []): string {
467
-	if (is_string($options)) {
468
-		$options = ['param' => $options];
469
-	}
470
-	$date_array = recup_date($numdate, false);
471
-	if (!$date_array) {
472
-		return '';
473
-	}
474
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
-
476
-	// 1er, 21st, etc.
477
-	$journum = $jour;
478
-
479
-	if ($jour == 0) {
480
-		$jour = '';
481
-		$njour = 0;
482
-	} else {
483
-		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
485
-			$jour = $jourth;
486
-		}
487
-	}
488
-
489
-	$mois = (int) $mois;
490
-	if ($mois > 0 && $mois < 13) {
491
-		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
494
-		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
-			: $nommois;
497
-	} else {
498
-		$nommois = '';
499
-		$jourmois = '';
500
-	}
501
-
502
-	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
504
-		$avjc = true;
505
-	} else {
506
-		$avjc = false;
507
-	}
508
-
509
-	switch ($vue) {
510
-		case 'saison':
511
-		case 'saison_annee':
512
-			$saison = '';
513
-			if ($mois > 0) {
514
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
515
-				if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
517
-				}
518
-				if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
520
-				}
521
-				if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
523
-				}
524
-				if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
526
-				}
527
-			}
528
-			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
530
-			} else {
531
-				return $saison ? trim((string) _T(
532
-					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
-				)) : '';
535
-			}
536
-
537
-		case 'court':
538
-			if ($avjc) {
539
-				return $annee;
540
-			}
541
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
-				return $annee;
544
-			}
545
-			if ($annee != $a) {
546
-				return _T(
547
-					'date_fmt_mois_annee',
548
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
-				);
550
-			}
551
-
552
-			return _T(
553
-				'date_fmt_jour_mois',
554
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
-			);
556
-
557
-		case 'jourcourt':
558
-			if ($avjc) {
559
-				return $annee;
560
-			}
561
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
-				return $annee;
564
-			}
565
-			if ($annee != $a) {
566
-				return _T(
567
-					'date_fmt_jour_mois_annee',
568
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
-				);
570
-			}
571
-
572
-			return _T(
573
-				'date_fmt_jour_mois',
574
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
-			);
576
-
577
-		case 'entier':
578
-			if ($avjc) {
579
-				return $annee;
580
-			}
581
-			if ($jour) {
582
-				return _T(
583
-					'date_fmt_jour_mois_annee',
584
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
-				);
586
-			} elseif ($mois) {
587
-				return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
-			} else {
589
-				return $annee;
590
-			}
591
-
592
-		case 'nom_mois':
593
-			return $nommois;
594
-
595
-		case 'mois':
596
-			return sprintf('%02s', $mois);
597
-
598
-		case 'jour':
599
-			return $jour;
600
-
601
-		case 'journum':
602
-			return $journum;
603
-
604
-		case 'nom_jour':
605
-			if (!$mois || !$njour) {
606
-				return '';
607
-			}
608
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
-			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
-
612
-			return _T('date_jour_' . $nom . $param);
613
-
614
-		case 'mois_annee':
615
-			if ($avjc) {
616
-				return $annee;
617
-			}
618
-
619
-			return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
-
621
-		case 'annee':
622
-			return $annee;
623
-
624
-		// Cas d'une vue non definie : retomber sur le format
625
-		// de date propose par http://www.php.net/date
626
-		default:
627
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
-			// il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
-				$time = strtotime($numdate);
631
-			}
632
-			return date($vue, $time);
633
-	}
467
+    if (is_string($options)) {
468
+        $options = ['param' => $options];
469
+    }
470
+    $date_array = recup_date($numdate, false);
471
+    if (!$date_array) {
472
+        return '';
473
+    }
474
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
+
476
+    // 1er, 21st, etc.
477
+    $journum = $jour;
478
+
479
+    if ($jour == 0) {
480
+        $jour = '';
481
+        $njour = 0;
482
+    } else {
483
+        $njour = (int) $jour;
484
+        if ($jourth = _T('date_jnum' . $jour)) {
485
+            $jour = $jourth;
486
+        }
487
+    }
488
+
489
+    $mois = (int) $mois;
490
+    if ($mois > 0 && $mois < 13) {
491
+        /* Traiter le cas "abbr" pour les noms de mois */
492
+        $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
+        $nommois = _T('date_mois_' . $mois . $param);
494
+        $jourmois = $jour
495
+            ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
+            : $nommois;
497
+    } else {
498
+        $nommois = '';
499
+        $jourmois = '';
500
+    }
501
+
502
+    if ($annee < 0) {
503
+        $annee = -$annee . ' ' . _T('date_avant_jc');
504
+        $avjc = true;
505
+    } else {
506
+        $avjc = false;
507
+    }
508
+
509
+    switch ($vue) {
510
+        case 'saison':
511
+        case 'saison_annee':
512
+            $saison = '';
513
+            if ($mois > 0) {
514
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
515
+                if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
517
+                }
518
+                if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
520
+                }
521
+                if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
523
+                }
524
+                if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
526
+                }
527
+            }
528
+            if ($vue == 'saison') {
529
+                return $saison ? _T('date_saison_' . $saison) : '';
530
+            } else {
531
+                return $saison ? trim((string) _T(
532
+                    'date_fmt_saison_annee',
533
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
+                )) : '';
535
+            }
536
+
537
+        case 'court':
538
+            if ($avjc) {
539
+                return $annee;
540
+            }
541
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
+                return $annee;
544
+            }
545
+            if ($annee != $a) {
546
+                return _T(
547
+                    'date_fmt_mois_annee',
548
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
+                );
550
+            }
551
+
552
+            return _T(
553
+                'date_fmt_jour_mois',
554
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
+            );
556
+
557
+        case 'jourcourt':
558
+            if ($avjc) {
559
+                return $annee;
560
+            }
561
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
+                return $annee;
564
+            }
565
+            if ($annee != $a) {
566
+                return _T(
567
+                    'date_fmt_jour_mois_annee',
568
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
+                );
570
+            }
571
+
572
+            return _T(
573
+                'date_fmt_jour_mois',
574
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
+            );
576
+
577
+        case 'entier':
578
+            if ($avjc) {
579
+                return $annee;
580
+            }
581
+            if ($jour) {
582
+                return _T(
583
+                    'date_fmt_jour_mois_annee',
584
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
+                );
586
+            } elseif ($mois) {
587
+                return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
+            } else {
589
+                return $annee;
590
+            }
591
+
592
+        case 'nom_mois':
593
+            return $nommois;
594
+
595
+        case 'mois':
596
+            return sprintf('%02s', $mois);
597
+
598
+        case 'jour':
599
+            return $jour;
600
+
601
+        case 'journum':
602
+            return $journum;
603
+
604
+        case 'nom_jour':
605
+            if (!$mois || !$njour) {
606
+                return '';
607
+            }
608
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
+            $nom = 1 + (int) date('w', $nom);
610
+            $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
+
612
+            return _T('date_jour_' . $nom . $param);
613
+
614
+        case 'mois_annee':
615
+            if ($avjc) {
616
+                return $annee;
617
+            }
618
+
619
+            return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
+
621
+        case 'annee':
622
+            return $annee;
623
+
624
+        // Cas d'une vue non definie : retomber sur le format
625
+        // de date propose par http://www.php.net/date
626
+        default:
627
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
+            // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
+                $time = strtotime($numdate);
631
+            }
632
+            return date($vue, $time);
633
+    }
634 634
 }
635 635
 
636 636
 
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
  *     Nom du jour
658 658
  **/
659 659
 function nom_jour($numdate, $forme = ''): string {
660
-	if ($forme !== 'abbr' && $forme !== 'initiale') {
661
-		$forme = '';
662
-	}
660
+    if ($forme !== 'abbr' && $forme !== 'initiale') {
661
+        $forme = '';
662
+    }
663 663
 
664
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
664
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
665 665
 }
666 666
 
667 667
 /**
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
  *     Numéro du jour
684 684
  **/
685 685
 function jour($numdate): string {
686
-	return affdate_base($numdate, 'jour');
686
+    return affdate_base($numdate, 'jour');
687 687
 }
688 688
 
689 689
 /**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
  *     Numéro du jour
702 702
  **/
703 703
 function journum($numdate): string {
704
-	return affdate_base($numdate, 'journum');
704
+    return affdate_base($numdate, 'journum');
705 705
 }
706 706
 
707 707
 /**
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
  *     Numéro du mois (sur 2 chiffres)
720 720
  **/
721 721
 function mois($numdate): string {
722
-	return  affdate_base($numdate, 'mois');
722
+    return  affdate_base($numdate, 'mois');
723 723
 }
724 724
 
725 725
 /**
@@ -743,11 +743,11 @@  discard block
 block discarded – undo
743 743
  *     Nom du mois
744 744
  **/
745 745
 function nom_mois($numdate, $forme = ''): string {
746
-	if ($forme !== 'abbr') {
747
-		$forme = '';
748
-	}
746
+    if ($forme !== 'abbr') {
747
+        $forme = '';
748
+    }
749 749
 
750
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
750
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
751 751
 }
752 752
 
753 753
 /**
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
  *     Année (sur 4 chiffres)
766 766
  **/
767 767
 function annee($numdate): string {
768
-	return affdate_base($numdate, 'annee');
768
+    return affdate_base($numdate, 'annee');
769 769
 }
770 770
 
771 771
 
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
  *     La date formatée
796 796
  **/
797 797
 function saison($numdate, $hemisphere = 'nord'): string {
798
-	if ($hemisphere !== 'sud') {
799
-		$hemisphere = 'nord';
800
-	}
798
+    if ($hemisphere !== 'sud') {
799
+        $hemisphere = 'nord';
800
+    }
801 801
 
802
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
802
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
803 803
 }
804 804
 
805 805
 
@@ -828,11 +828,11 @@  discard block
 block discarded – undo
828 828
  *     La date formatée
829 829
  **/
830 830
 function saison_annee($numdate, $hemisphere = 'nord'): string {
831
-	if ($hemisphere !== 'sud') {
832
-		$hemisphere = 'nord';
833
-	}
831
+    if ($hemisphere !== 'sud') {
832
+        $hemisphere = 'nord';
833
+    }
834 834
 
835
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
835
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
836 836
 }
837 837
 
838 838
 /**
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
  *     La date formatée
861 861
  **/
862 862
 function affdate($numdate, $format = 'entier'): string {
863
-	return affdate_base($numdate, $format);
863
+    return affdate_base($numdate, $format);
864 864
 }
865 865
 
866 866
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
  *     La date formatée
888 888
  **/
889 889
 function affdate_court($numdate, $annee_courante = null): string {
890
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
890
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
891 891
 }
892 892
 
893 893
 
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
  *     La date formatée
915 915
  **/
916 916
 function affdate_jourcourt($numdate, $annee_courante = null): string {
917
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
917
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
918 918
 }
919 919
 
920 920
 /**
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
  *     La date formatée
933 933
  **/
934 934
 function affdate_mois_annee($numdate): string {
935
-	return affdate_base($numdate, 'mois_annee');
935
+    return affdate_base($numdate, 'mois_annee');
936 936
 }
937 937
 
938 938
 /**
@@ -950,16 +950,16 @@  discard block
 block discarded – undo
950 950
  *     La date formatée, sinon ''
951 951
  **/
952 952
 function affdate_heure($numdate): string {
953
-	$date_array = recup_date($numdate);
954
-	if (!$date_array) {
955
-		return '';
956
-	}
957
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
-
959
-	return _T('date_fmt_jour_heure', [
960
-		'jour' => affdate($numdate),
961
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
-	]);
953
+    $date_array = recup_date($numdate);
954
+    if (!$date_array) {
955
+        return '';
956
+    }
957
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
+
959
+    return _T('date_fmt_jour_heure', [
960
+        'jour' => affdate($numdate),
961
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
+    ]);
963 963
 }
964 964
 
965 965
 /**
@@ -991,113 +991,113 @@  discard block
 block discarded – undo
991 991
  *     texte de la date
992 992
  */
993 993
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
994
-	$abbr = $jour = '';
995
-	$affdate = 'affdate_jourcourt';
996
-	if (str_contains($forme, 'abbr')) {
997
-		$abbr = 'abbr';
998
-	}
999
-	if (str_contains($forme, 'annee')) {
1000
-		$affdate = 'affdate';
1001
-	}
1002
-	if (str_contains($forme, 'jour')) {
1003
-		$jour = 'jour';
1004
-	}
1005
-
1006
-	$dtstart = $dtend = $dtabbr = '';
1007
-	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
-		$dtabbr = '</abbr>';
1011
-	}
1012
-
1013
-	$date_debut = strtotime($date_debut);
1014
-	$date_fin = strtotime($date_fin);
1015
-	$d = date('Y-m-d', $date_debut);
1016
-	$f = date('Y-m-d', $date_fin);
1017
-	$h = ($horaire === 'oui' || $horaire === true);
1018
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
-
1021
-	if ($d === $f) { // meme jour
1022
-		$nomjour = nom_jour($d, $abbr);
1023
-		$s = $affdate($d);
1024
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
-		if ($h) {
1026
-			if ($hd === $hf) {
1027
-				// Lundi 20 fevrier a 18h25
1028
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
-				$s = "$dtstart$s$dtabbr";
1030
-			} else {
1031
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
-				if ($dtabbr && $dtstart && $dtend) {
1033
-					$s = _T(
1034
-						'date_fmt_jour_heure_debut_fin_abbr',
1035
-						[
1036
-						'jour' => spip_ucfirst($s),
1037
-						'heure_debut' => $hd,
1038
-						'heure_fin' => $hf,
1039
-						'dtstart' => $dtstart,
1040
-						'dtend' => $dtend,
1041
-						'dtabbr' => $dtabbr
1042
-						],
1043
-						[
1044
-							'sanitize' => false
1045
-						]
1046
-					);
1047
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1048
-				else {
1049
-					$s = spip_ucfirst(_T(
1050
-						'date_fmt_jour_heure_debut_fin',
1051
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
-					));
1053
-				}
1054
-			}
1055
-		} else {
1056
-			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1058
-				: spip_ucfirst($s);
1059
-		}
1060
-	} else {
1061
-		if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
-			$date_debut = $h
1063
-				? affdate_jourcourt($d, date('Y', $date_fin))
1064
-				: jour($d);
1065
-			$date_fin = $affdate($f);
1066
-			if ($jour) {
1067
-				$nomjour_debut = nom_jour($d, $abbr);
1068
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
-				$nomjour_fin = nom_jour($f, $abbr);
1070
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
-			}
1072
-			if ($h) {
1073
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
-			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1078
-
1079
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
-		} else {
1081
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
-			$date_fin = $affdate($f);
1083
-			if ($jour) {
1084
-				$nomjour_debut = nom_jour($d, $abbr);
1085
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
-				$nomjour_fin = nom_jour($f, $abbr);
1087
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
-			}
1089
-			if ($h) {
1090
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
-			}
1093
-
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1096
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
-		}
1098
-	}
1099
-
1100
-	return $s;
994
+    $abbr = $jour = '';
995
+    $affdate = 'affdate_jourcourt';
996
+    if (str_contains($forme, 'abbr')) {
997
+        $abbr = 'abbr';
998
+    }
999
+    if (str_contains($forme, 'annee')) {
1000
+        $affdate = 'affdate';
1001
+    }
1002
+    if (str_contains($forme, 'jour')) {
1003
+        $jour = 'jour';
1004
+    }
1005
+
1006
+    $dtstart = $dtend = $dtabbr = '';
1007
+    if (str_contains($forme, 'hcal')) {
1008
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
+        $dtabbr = '</abbr>';
1011
+    }
1012
+
1013
+    $date_debut = strtotime($date_debut);
1014
+    $date_fin = strtotime($date_fin);
1015
+    $d = date('Y-m-d', $date_debut);
1016
+    $f = date('Y-m-d', $date_fin);
1017
+    $h = ($horaire === 'oui' || $horaire === true);
1018
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
+
1021
+    if ($d === $f) { // meme jour
1022
+        $nomjour = nom_jour($d, $abbr);
1023
+        $s = $affdate($d);
1024
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
+        if ($h) {
1026
+            if ($hd === $hf) {
1027
+                // Lundi 20 fevrier a 18h25
1028
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
+                $s = "$dtstart$s$dtabbr";
1030
+            } else {
1031
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
+                if ($dtabbr && $dtstart && $dtend) {
1033
+                    $s = _T(
1034
+                        'date_fmt_jour_heure_debut_fin_abbr',
1035
+                        [
1036
+                        'jour' => spip_ucfirst($s),
1037
+                        'heure_debut' => $hd,
1038
+                        'heure_fin' => $hf,
1039
+                        'dtstart' => $dtstart,
1040
+                        'dtend' => $dtend,
1041
+                        'dtabbr' => $dtabbr
1042
+                        ],
1043
+                        [
1044
+                            'sanitize' => false
1045
+                        ]
1046
+                    );
1047
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1048
+                else {
1049
+                    $s = spip_ucfirst(_T(
1050
+                        'date_fmt_jour_heure_debut_fin',
1051
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
+                    ));
1053
+                }
1054
+            }
1055
+        } else {
1056
+            $s = $dtabbr && $dtstart
1057
+                ? $dtstart . spip_ucfirst($s) . $dtabbr
1058
+                : spip_ucfirst($s);
1059
+        }
1060
+    } else {
1061
+        if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
+            $date_debut = $h
1063
+                ? affdate_jourcourt($d, date('Y', $date_fin))
1064
+                : jour($d);
1065
+            $date_fin = $affdate($f);
1066
+            if ($jour) {
1067
+                $nomjour_debut = nom_jour($d, $abbr);
1068
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
+                $nomjour_fin = nom_jour($f, $abbr);
1070
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
+            }
1072
+            if ($h) {
1073
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
+            }
1076
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1077
+            $date_fin = $dtend . $date_fin . $dtabbr;
1078
+
1079
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
+        } else {
1081
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
+            $date_fin = $affdate($f);
1083
+            if ($jour) {
1084
+                $nomjour_debut = nom_jour($d, $abbr);
1085
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
+                $nomjour_fin = nom_jour($f, $abbr);
1087
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
+            }
1089
+            if ($h) {
1090
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
+            }
1093
+
1094
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1095
+            $date_fin = $dtend . $date_fin . $dtabbr;
1096
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
+        }
1098
+    }
1099
+
1100
+    return $s;
1101 1101
 }
1102 1102
 
1103 1103
 /**
@@ -1118,10 +1118,10 @@  discard block
 block discarded – undo
1118 1118
  *     Date au format ical
1119 1119
  **/
1120 1120
 function date_ical($date, $addminutes = 0): string {
1121
-	[$heures, $minutes, $secondes] = recup_heure($date);
1122
-	[$annee, $mois, $jour] = recup_date($date);
1121
+    [$heures, $minutes, $secondes] = recup_heure($date);
1122
+    [$annee, $mois, $jour] = recup_date($date);
1123 1123
 
1124
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1124
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1125 1125
 }
1126 1126
 
1127 1127
 
@@ -1145,14 +1145,14 @@  discard block
 block discarded – undo
1145 1145
  *     La date formatée
1146 1146
  **/
1147 1147
 function date_iso($date_heure): string {
1148
-	$date = recup_date($date_heure);
1149
-	$annee = $date[0] ?? null;
1150
-	$mois = $date[1] ?? null;
1151
-	$jour = $date[2] ?? null;
1152
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
-
1155
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1148
+    $date = recup_date($date_heure);
1149
+    $annee = $date[0] ?? null;
1150
+    $mois = $date[1] ?? null;
1151
+    $jour = $date[2] ?? null;
1152
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
+
1155
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1156 1156
 }
1157 1157
 
1158 1158
 /**
@@ -1175,11 +1175,11 @@  discard block
 block discarded – undo
1175 1175
  *     La date formatée
1176 1176
  **/
1177 1177
 function date_822($date_heure): string {
1178
-	[$annee, $mois, $jour] = recup_date($date_heure);
1179
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1178
+    [$annee, $mois, $jour] = recup_date($date_heure);
1179
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1181 1181
 
1182
-	return date('r', $time);
1182
+    return date('r', $time);
1183 1183
 }
1184 1184
 
1185 1185
 /**
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
  *     Date au format `Ymd`
1196 1196
  **/
1197 1197
 function date_anneemoisjour($d): string {
1198
-	if (!$d) {
1199
-		$d = date('Y-m-d');
1200
-	}
1198
+    if (!$d) {
1199
+        $d = date('Y-m-d');
1200
+    }
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1215,11 +1215,11 @@  discard block
 block discarded – undo
1215 1215
  *     Date au format `Ym`
1216 1216
  **/
1217 1217
 function date_anneemois($d): string {
1218
-	if (!$d) {
1219
-		$d = date('Y-m-d');
1220
-	}
1218
+    if (!$d) {
1219
+        $d = date('Y-m-d');
1220
+    }
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+    return substr($d, 0, 4) . substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1235,13 +1235,13 @@  discard block
 block discarded – undo
1235 1235
  *     Date au lundi de la même semaine au format `Ymd`
1236 1236
  **/
1237 1237
 function date_debut_semaine($annee, $mois, $jour): string {
1238
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
-	if ($w_day == 0) {
1240
-		$w_day = 7;
1241
-	} // Gaffe: le dimanche est zero
1242
-	$debut = $jour - $w_day + 1;
1238
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
+    if ($w_day == 0) {
1240
+        $w_day = 7;
1241
+    } // Gaffe: le dimanche est zero
1242
+    $debut = $jour - $w_day + 1;
1243 1243
 
1244
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1244
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1245 1245
 }
1246 1246
 
1247 1247
 /**
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  *     Date au dimanche de la même semaine au format `Ymd`
1258 1258
  **/
1259 1259
 function date_fin_semaine($annee, $mois, $jour): string {
1260
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
-	if ($w_day == 0) {
1262
-		$w_day = 7;
1263
-	} // Gaffe: le dimanche est zero
1264
-	$debut = $jour - $w_day + 1;
1260
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
+    if ($w_day == 0) {
1262
+        $w_day = 7;
1263
+    } // Gaffe: le dimanche est zero
1264
+    $debut = $jour - $w_day + 1;
1265 1265
 
1266
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1266
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1267 1267
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 		}
44 44
 		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45 45
 			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
46
+			$date = $regs[1].'-00-00'.$regs[3];
47 47
 		} else {
48 48
 			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49 49
 				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
50
+				$date = preg_replace('@/@', '-', (string) $regs[1]).'-00'.$regs[3];
51 51
 			} else {
52 52
 				$date = date('Y-m-d H:i:s', strtotime($date));
53 53
 			}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	$letexte ??= '';
75 75
 	if (
76 76
 		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
77
+		|| in_array(strlen($letexte), [10, 19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78 78
 	) {
79 79
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80 80
 			return '';
@@ -359,39 +359,39 @@  discard block
 block discarded – undo
359 359
 	if ($decal > 3600 * 24 * 30) {
360 360
 		$mois = floor($decal / (3600 * 24 * 30));
361 361
 		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
362
+			? "$mois "._T('date_un_mois')
363
+			: "$mois "._T('date_mois');
364 364
 	} else {
365 365
 		if ($decal > 3600 * 24 * 7) {
366 366
 			$semaines = floor($decal / (3600 * 24 * 7));
367 367
 			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
368
+				? "$semaines "._T('date_une_semaine')
369
+				: "$semaines "._T('date_semaines');
370 370
 		} else {
371 371
 			if ($decal > 3600 * 24) {
372 372
 				$jours = floor($decal / (3600 * 24));
373 373
 				if ($jours < 2) {
374 374
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375 375
 				} else {
376
-					$delai = "$jours " . _T('date_jours');
376
+					$delai = "$jours "._T('date_jours');
377 377
 				}
378 378
 			} else {
379 379
 				if ($decal >= 3600) {
380 380
 					$heures = floor($decal / 3600);
381 381
 					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
382
+						? "$heures "._T('date_une_heure')
383
+						: "$heures "._T('date_heures');
384 384
 				} else {
385 385
 					if ($decal >= 60) {
386 386
 						$minutes = floor($decal / 60);
387 387
 						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
388
+							? "$minutes "._T('date_une_minute')
389
+							: "$minutes "._T('date_minutes');
390 390
 					} else {
391 391
 						$secondes = ceil($decal);
392 392
 						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
393
+							? "$secondes "._T('date_une_seconde')
394
+							: "$secondes "._T('date_secondes');
395 395
 					}
396 396
 				}
397 397
 			}
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		$njour = 0;
482 482
 	} else {
483 483
 		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
484
+		if ($jourth = _T('date_jnum'.$jour)) {
485 485
 			$jour = $jourth;
486 486
 		}
487 487
 	}
@@ -489,10 +489,10 @@  discard block
 block discarded – undo
489 489
 	$mois = (int) $mois;
490 490
 	if ($mois > 0 && $mois < 13) {
491 491
 		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
492
+		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_'.$options['param'] : '');
493
+		$nommois = _T('date_mois_'.$mois.$param);
494 494
 		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
495
+			? _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois])
496 496
 			: $nommois;
497 497
 	} else {
498 498
 		$nommois = '';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	}
501 501
 
502 502
 	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
503
+		$annee = -$annee.' '._T('date_avant_jc');
504 504
 		$avjc = true;
505 505
 	} else {
506 506
 		$avjc = false;
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
 				}
527 527
 			}
528 528
 			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
529
+				return $saison ? _T('date_saison_'.$saison) : '';
530 530
 			} else {
531 531
 				return $saison ? trim((string) _T(
532 532
 					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
533
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
534 534
 				)) : '';
535 535
 			}
536 536
 
@@ -607,9 +607,9 @@  discard block
 block discarded – undo
607 607
 			}
608 608
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609 609
 			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
610
+			$param = ((isset($options['param']) && $options['param']) ? '_'.$options['param'] : '');
611 611
 
612
-			return _T('date_jour_' . $nom . $param);
612
+			return _T('date_jour_'.$nom.$param);
613 613
 
614 614
 		case 'mois_annee':
615 615
 			if ($avjc) {
@@ -1005,8 +1005,8 @@  discard block
 block discarded – undo
1005 1005
 
1006 1006
 	$dtstart = $dtend = $dtabbr = '';
1007 1007
 	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1008
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1009
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1010 1010
 		$dtabbr = '</abbr>';
1011 1011
 	}
1012 1012
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 			}
1055 1055
 		} else {
1056 1056
 			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1057
+				? $dtstart.spip_ucfirst($s).$dtabbr
1058 1058
 				: spip_ucfirst($s);
1059 1059
 		}
1060 1060
 	} else {
@@ -1073,8 +1073,8 @@  discard block
 block discarded – undo
1073 1073
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074 1074
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075 1075
 			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1076
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1077
+			$date_fin = $dtend.$date_fin.$dtabbr;
1078 1078
 
1079 1079
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080 1080
 		} else {
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092 1092
 			}
1093 1093
 
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1094
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1095
+			$date_fin = $dtend.$date_fin.$dtabbr;
1096 1096
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097 1097
 		}
1098 1098
 	}
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 		$d = date('Y-m-d');
1200 1200
 	}
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		$d = date('Y-m-d');
1220 1220
 	}
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+	return substr($d, 0, 4).substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
Please login to merge, or discard this patch.
ecrire/inc/cvt_multietapes.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
  */
66 66
 
67 67
 if (!defined('_ECRIRE_INC_VERSION')) {
68
-	return;
68
+    return;
69 69
 }
70 70
 
71 71
 /**
@@ -76,46 +76,46 @@  discard block
 block discarded – undo
76 76
  * @return array|false
77 77
  */
78 78
 function cvtmulti_recuperer_post_precedents($form) {
79
-	include_spip('inc/filtres');
80
-	if (
81
-		$form
82
-		&& ($c = _request('cvtm_prev_post'))
83
-		&& ($c = decoder_contexte_ajax($c, $form))
84
-	) {
85
-		#var_dump($c);
79
+    include_spip('inc/filtres');
80
+    if (
81
+        $form
82
+        && ($c = _request('cvtm_prev_post'))
83
+        && ($c = decoder_contexte_ajax($c, $form))
84
+    ) {
85
+        #var_dump($c);
86 86
 
87
-		# reinjecter dans la bonne variable pour permettre de retrouver
88
-		# toutes les saisies dans un seul tableau
89
-		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
90
-			$store = &$_POST;
91
-		} else {
92
-			$store = &$_GET;
93
-		}
87
+        # reinjecter dans la bonne variable pour permettre de retrouver
88
+        # toutes les saisies dans un seul tableau
89
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
90
+            $store = &$_POST;
91
+        } else {
92
+            $store = &$_GET;
93
+        }
94 94
 
95
-		foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
96
-		if (!isset($store[$k])) {
97
-				$_REQUEST[$k] = $store[$k] = $v;
98
-		} // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
99
-			elseif (
100
-				is_array($store[$k])
101
-				&& is_array($v)
102
-				&& ($z = array_keys($v))
103
-				&& !is_numeric(reset($z))
104
-				&& ($z = array_keys($store[$k]))
105
-				&& !is_numeric(reset($z))
106
-			) {
107
-				$_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
108
-			}
109
-		}
95
+        foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
96
+        if (!isset($store[$k])) {
97
+                $_REQUEST[$k] = $store[$k] = $v;
98
+        } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
99
+            elseif (
100
+                is_array($store[$k])
101
+                && is_array($v)
102
+                && ($z = array_keys($v))
103
+                && !is_numeric(reset($z))
104
+                && ($z = array_keys($store[$k]))
105
+                && !is_numeric(reset($z))
106
+            ) {
107
+                $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
108
+            }
109
+        }
110 110
 
111
-		// vider pour eviter un second appel a verifier_n
112
-		// en cas de double implementation (unipotence)
113
-		set_request('cvtm_prev_post');
111
+        // vider pour eviter un second appel a verifier_n
112
+        // en cas de double implementation (unipotence)
113
+        set_request('cvtm_prev_post');
114 114
 
115
-		return [$c['_etape'], $c['_etapes']];
116
-	}
115
+        return [$c['_etape'], $c['_etapes']];
116
+    }
117 117
 
118
-	return false;
118
+    return false;
119 119
 }
120 120
 
121 121
 /**
@@ -128,28 +128,28 @@  discard block
 block discarded – undo
128 128
  * @return array
129 129
  */
130 130
 function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) {
131
-	if (!isset($valeurs['_cvtm_prev_post'])) {
132
-		$post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
133
-		foreach (array_keys($valeurs) as $champ) {
134
-			if (
135
-				!str_starts_with($champ, '_')
136
-				&& ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']))
137
-				&& ($v = _request($champ)) !== null
138
-			) {
139
-				$post[$champ] = $v;
140
-			}
141
-		}
142
-		include_spip('inc/filtres');
143
-		$c = encoder_contexte_ajax($post, $form);
144
-		if (!isset($valeurs['_hidden'])) {
145
-			$valeurs['_hidden'] = '';
146
-		}
147
-		$valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
148
-		// marquer comme fait, pour eviter double encodage (unipotence)
149
-		$valeurs['_cvtm_prev_post'] = true;
150
-	}
131
+    if (!isset($valeurs['_cvtm_prev_post'])) {
132
+        $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
133
+        foreach (array_keys($valeurs) as $champ) {
134
+            if (
135
+                !str_starts_with($champ, '_')
136
+                && ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']))
137
+                && ($v = _request($champ)) !== null
138
+            ) {
139
+                $post[$champ] = $v;
140
+            }
141
+        }
142
+        include_spip('inc/filtres');
143
+        $c = encoder_contexte_ajax($post, $form);
144
+        if (!isset($valeurs['_hidden'])) {
145
+            $valeurs['_hidden'] = '';
146
+        }
147
+        $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
148
+        // marquer comme fait, pour eviter double encodage (unipotence)
149
+        $valeurs['_cvtm_prev_post'] = true;
150
+    }
151 151
 
152
-	return $valeurs;
152
+    return $valeurs;
153 153
 }
154 154
 
155 155
 /**
@@ -159,19 +159,19 @@  discard block
 block discarded – undo
159 159
  * @return array
160 160
  */
161 161
 function cvtmulti_formulaire_charger_etapes($args, $valeurs) {
162
-	if (!isset($valeurs['_etape'])) {
163
-		$form = $args['form'];
164
-		$je_suis_poste = $args['je_suis_poste'];
165
-		$nb_etapes = $valeurs['_etapes'];
166
-		$etape = _request('_etape');
167
-		$etape = min(max($etape, 1), $nb_etapes);
168
-		set_request('_etape', $etape);
169
-		$valeurs['_etape'] = $etape;
162
+    if (!isset($valeurs['_etape'])) {
163
+        $form = $args['form'];
164
+        $je_suis_poste = $args['je_suis_poste'];
165
+        $nb_etapes = $valeurs['_etapes'];
166
+        $etape = _request('_etape');
167
+        $etape = min(max($etape, 1), $nb_etapes);
168
+        set_request('_etape', $etape);
169
+        $valeurs['_etape'] = $etape;
170 170
 
171
-		// sauver les posts de cette etape pour les avoir a la prochaine etape
172
-		$valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
173
-	}
174
-	return $valeurs;
171
+        // sauver les posts de cette etape pour les avoir a la prochaine etape
172
+        $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
173
+    }
174
+    return $valeurs;
175 175
 }
176 176
 
177 177
 /**
@@ -182,87 +182,87 @@  discard block
 block discarded – undo
182 182
  * @return array
183 183
  */
184 184
 function cvtmulti_formulaire_verifier_etapes($args, $erreurs) {
185
-	#var_dump('Pipe verifier');
185
+    #var_dump('Pipe verifier');
186 186
 
187
-	if (
188
-		($form = $args['form'])
189
-		&& ($e = cvtmulti_recuperer_post_precedents($form)) !== false
190
-	) {
191
-		// recuperer l'etape saisie et le nombre d'etapes total
192
-		[$etape, $etapes] = $e;
193
-		$etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape
187
+    if (
188
+        ($form = $args['form'])
189
+        && ($e = cvtmulti_recuperer_post_precedents($form)) !== false
190
+    ) {
191
+        // recuperer l'etape saisie et le nombre d'etapes total
192
+        [$etape, $etapes] = $e;
193
+        $etape_demandee = (int) _request('aller_a_etape'); // possibilite de poster un entier dans aller_a_etape
194 194
 
195
-		$args['etape_saisie'] = $etape;
196
-		$args['etapes'] = $etapes;
197
-		// lancer les verifs pour chaque etape deja saisie de 1 a $etape
198
-		$erreurs_etapes = [];
199
-		$derniere_etape_ok = 0;
200
-		$e = 0;
201
-		while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) {
202
-			$e++;
203
-			$erreurs_etapes[$e] = [];
204
-			if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
205
-				$erreurs_etapes[$e] = $verifier(...$args['args']);
206
-			} elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
207
-				$a = $args['args'];
208
-				array_unshift($a, $e);
209
-				$erreurs_etapes[$e] = $verifier(...$a);
210
-			}
211
-			// et on appelle un pipeline dedie aux etapes, plus easy
212
-			$args['etape'] = $e;
213
-			$args['etape_demandee'] = $etape_demandee;
214
-			$erreurs_etapes[$e] = pipeline(
215
-				'formulaire_verifier_etape',
216
-				[
217
-					'args' => $args,
218
-					'data' => $erreurs_etapes[$e]
219
-				]
220
-			);
195
+        $args['etape_saisie'] = $etape;
196
+        $args['etapes'] = $etapes;
197
+        // lancer les verifs pour chaque etape deja saisie de 1 a $etape
198
+        $erreurs_etapes = [];
199
+        $derniere_etape_ok = 0;
200
+        $e = 0;
201
+        while ($e < max($etape, $etape_demandee - 1) && $e < $etapes) {
202
+            $e++;
203
+            $erreurs_etapes[$e] = [];
204
+            if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
205
+                $erreurs_etapes[$e] = $verifier(...$args['args']);
206
+            } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
207
+                $a = $args['args'];
208
+                array_unshift($a, $e);
209
+                $erreurs_etapes[$e] = $verifier(...$a);
210
+            }
211
+            // et on appelle un pipeline dedie aux etapes, plus easy
212
+            $args['etape'] = $e;
213
+            $args['etape_demandee'] = $etape_demandee;
214
+            $erreurs_etapes[$e] = pipeline(
215
+                'formulaire_verifier_etape',
216
+                [
217
+                    'args' => $args,
218
+                    'data' => $erreurs_etapes[$e]
219
+                ]
220
+            );
221 221
 
222
-			if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) {
223
-				$derniere_etape_ok = $e;
224
-			}
225
-			// possibilite de poster dans _retour_etape_x ou aller_a_etape
226
-			if (!is_null(_request("_retour_etape_$e"))) {
227
-				$etape_demandee = $e;
228
-			}
229
-			// Il se peut que les verifications ait décidé de faire sauter des étapes
230
-			if ($aller_a_etape = (int) _request('aller_a_etape')) {
231
-				$etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
232
-			}
233
-		}
222
+            if ($derniere_etape_ok === $e - 1 && !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) {
223
+                $derniere_etape_ok = $e;
224
+            }
225
+            // possibilite de poster dans _retour_etape_x ou aller_a_etape
226
+            if (!is_null(_request("_retour_etape_$e"))) {
227
+                $etape_demandee = $e;
228
+            }
229
+            // Il se peut que les verifications ait décidé de faire sauter des étapes
230
+            if ($aller_a_etape = (int) _request('aller_a_etape')) {
231
+                $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
232
+            }
233
+        }
234 234
 
235 235
 
236
-		// si la derniere etape OK etait la derniere
237
-		// on renvoie le flux inchange et ca declenche traiter
238
-		if (
239
-			$derniere_etape_ok == $etapes
240
-			&& (!$etape_demandee || $etape_demandee >= $etapes)
241
-		) {
242
-			return $erreurs;
243
-		} else {
244
-			$etape = $derniere_etape_ok + 1;
245
-			if ($etape_demandee > 0 && $etape_demandee < $etape) {
246
-				$etape = $etape_demandee;
247
-			}
248
-			$etape = min($etape, $etapes);
249
-			#var_dump("prochaine etape $etape");
250
-			// retourner les erreurs de l'etape ciblee
251
-			$erreurs = $erreurs_etapes[$etape] ?? [];
252
-			// Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
253
-			if ($erreurs) {
254
-				if (!isset($erreurs['message_erreur'])) {
255
-					$erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
256
-				}
257
-			} else {
258
-				$erreurs['message_erreur'] = '';
259
-			}
260
-			$erreurs['_etapes'] = "etape suivante $etape";
261
-			set_request('_etape', $etape);
262
-		}
263
-	}
236
+        // si la derniere etape OK etait la derniere
237
+        // on renvoie le flux inchange et ca declenche traiter
238
+        if (
239
+            $derniere_etape_ok == $etapes
240
+            && (!$etape_demandee || $etape_demandee >= $etapes)
241
+        ) {
242
+            return $erreurs;
243
+        } else {
244
+            $etape = $derniere_etape_ok + 1;
245
+            if ($etape_demandee > 0 && $etape_demandee < $etape) {
246
+                $etape = $etape_demandee;
247
+            }
248
+            $etape = min($etape, $etapes);
249
+            #var_dump("prochaine etape $etape");
250
+            // retourner les erreurs de l'etape ciblee
251
+            $erreurs = $erreurs_etapes[$etape] ?? [];
252
+            // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
253
+            if ($erreurs) {
254
+                if (!isset($erreurs['message_erreur'])) {
255
+                    $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
256
+                }
257
+            } else {
258
+                $erreurs['message_erreur'] = '';
259
+            }
260
+            $erreurs['_etapes'] = "etape suivante $etape";
261
+            set_request('_etape', $etape);
262
+        }
263
+    }
264 264
 
265
-	return $erreurs;
265
+    return $erreurs;
266 266
 }
267 267
 
268 268
 /**
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
  * @return array
275 275
  */
276 276
 function cvtmulti_styliser($flux) {
277
-	if (
278
-		str_starts_with((string) $flux['args']['fond'], 'formulaires/')
279
-		&& isset($flux['args']['contexte']['_etapes'])
280
-		&& isset($flux['args']['contexte']['_etape'])
281
-		&& ($e = $flux['args']['contexte']['_etape']) > 1
282
-		&& ($ext = $flux['args']['ext'])
283
-		&& ($f = $flux['data'])
284
-		&& file_exists($f . "_$e.$ext")
285
-	) {
286
-		$flux['data'] = $f . "_$e";
287
-	}
277
+    if (
278
+        str_starts_with((string) $flux['args']['fond'], 'formulaires/')
279
+        && isset($flux['args']['contexte']['_etapes'])
280
+        && isset($flux['args']['contexte']['_etape'])
281
+        && ($e = $flux['args']['contexte']['_etape']) > 1
282
+        && ($ext = $flux['args']['ext'])
283
+        && ($f = $flux['data'])
284
+        && file_exists($f . "_$e.$ext")
285
+    ) {
286
+        $flux['data'] = $f . "_$e";
287
+    }
288 288
 
289
-	return $flux;
289
+    return $flux;
290 290
 }
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
  * @return string
32 32
  */
33 33
 function exporter_csv_champ($champ) {
34
-	#$champ = str_replace("\r", "\n", $champ);
35
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
36
-	#$champ = str_replace("\n", ", ", $champ);
37
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
38
-	$champ = str_replace('"', '""', $champ);
34
+    #$champ = str_replace("\r", "\n", $champ);
35
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
36
+    #$champ = str_replace("\n", ", ", $champ);
37
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
38
+    $champ = str_replace('"', '""', $champ);
39 39
 
40
-	return '"' . $champ . '"';
40
+    return '"' . $champ . '"';
41 41
 }
42 42
 
43 43
 /**
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
  * @return string
55 55
  */
56 56
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) {
57
-	if ($callback) {
58
-		$ligne = $callback($nb, $ligne, $delim, $importer_charset);
59
-	}
60
-	$output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
61
-	if ($importer_charset) {
62
-		$output = str_replace('’', '\'', $output);
63
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
64
-	}
65
-	return $output;
57
+    if ($callback) {
58
+        $ligne = $callback($nb, $ligne, $delim, $importer_charset);
59
+    }
60
+    $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
61
+    if ($importer_charset) {
62
+        $output = str_replace('’', '\'', $output);
63
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
64
+    }
65
+    return $output;
66 66
 }
67 67
 
68 68
 /**
@@ -90,107 +90,107 @@  discard block
 block discarded – undo
90 90
  */
91 91
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
92 92
 
93
-	// support ancienne syntaxe
94
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
95
-	if (is_string($options)) {
96
-		$args = func_get_args();
97
-		$options = [];
98
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
99
-			if (!empty($args[$k])) {
100
-				$options[$option] = $args[$k];
101
-			}
102
-		}
103
-	}
104
-
105
-	$default_options = [
106
-		'fichier' => null, // par défaut = $titre
107
-		'extension' => null, // par défaut = choix auto
108
-		'delim' => ',',
109
-		'entetes' => null,
110
-		'envoyer' => true,
111
-		'charset' => null,
112
-		'callback' => null,
113
-	];
114
-	$options = array_merge($default_options, $options);
115
-
116
-	// Délimiteur
117
-	if ($options['delim'] == 'TAB') {
118
-		$options['delim'] = "\t";
119
-	}
120
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
121
-		$options['delim'] = ',';
122
-	}
123
-
124
-	// Nom du fichier : celui indiqué dans les options, sinon le titre
125
-	// Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores
126
-	$filename = $options['fichier'] ?? translitteration(textebrut(typo($titre)));
127
-	$filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename));
128
-	$filename = rtrim($filename, '.');
129
-
130
-	// Extension : celle indiquée en option, sinon choisie selon le délimiteur
131
-	// Normalisation : uniquement les charactères non spéciaux
132
-	if (!empty($options['extension'])) {
133
-		$options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension']));
134
-	}
135
-	$extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls');
136
-
137
-	// Fichier
138
-	$basename = "$filename.$extension";
139
-
140
-	// Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site
141
-	// Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
142
-	$charset_site = $GLOBALS['meta']['charset'];
143
-	$charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null);
144
-	$charset = $options['charset'] ?? $charset_excel ?? $charset_site;
145
-	$importer_charset = (($charset === $charset_site) ? null : $charset);
146
-
147
-	$output = '';
148
-	$nb = 0;
149
-	if (!empty($options['entetes']) && is_array($options['entetes'])) {
150
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
151
-	}
152
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
153
-	$nb++;
154
-
155
-	if ($options['envoyer']) {
156
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
157
-		header("Content-Type: text/comma-separated-values; charset=$charset");
158
-		header("Content-Disposition: $disposition; filename=$basename");
159
-
160
-		// Vider tous les tampons
161
-		$level = @ob_get_level();
162
-		while ($level--) {
163
-			@ob_end_flush();
164
-		}
165
-	}
166
-
167
-	// si envoyer=='attachment' on passe par un fichier temporaire
168
-	// sinon on ecrit directement sur stdout
169
-	if ($options['envoyer'] && $options['envoyer'] !== 'attachment') {
170
-		$fichier = 'php://output';
171
-	}
172
-	else {
173
-		$fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename;
174
-	}
175
-
176
-	$fp = fopen($fichier, 'w');
177
-	$length = fwrite($fp, $output);
178
-
179
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
180
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
181
-		$length += fwrite($fp, $output);
182
-		$nb++;
183
-	}
184
-	fclose($fp);
185
-
186
-	if ($options['envoyer']) {
187
-		if ($options['envoyer'] === 'attachment') {
188
-			header("Content-Length: $length");
189
-			readfile($fichier);
190
-		}
191
-		// si on a envoye inline, c'est deja tout bon
192
-		exit;
193
-	}
194
-
195
-	return $fichier;
93
+    // support ancienne syntaxe
94
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
95
+    if (is_string($options)) {
96
+        $args = func_get_args();
97
+        $options = [];
98
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
99
+            if (!empty($args[$k])) {
100
+                $options[$option] = $args[$k];
101
+            }
102
+        }
103
+    }
104
+
105
+    $default_options = [
106
+        'fichier' => null, // par défaut = $titre
107
+        'extension' => null, // par défaut = choix auto
108
+        'delim' => ',',
109
+        'entetes' => null,
110
+        'envoyer' => true,
111
+        'charset' => null,
112
+        'callback' => null,
113
+    ];
114
+    $options = array_merge($default_options, $options);
115
+
116
+    // Délimiteur
117
+    if ($options['delim'] == 'TAB') {
118
+        $options['delim'] = "\t";
119
+    }
120
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
121
+        $options['delim'] = ',';
122
+    }
123
+
124
+    // Nom du fichier : celui indiqué dans les options, sinon le titre
125
+    // Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores
126
+    $filename = $options['fichier'] ?? translitteration(textebrut(typo($titre)));
127
+    $filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename));
128
+    $filename = rtrim($filename, '.');
129
+
130
+    // Extension : celle indiquée en option, sinon choisie selon le délimiteur
131
+    // Normalisation : uniquement les charactères non spéciaux
132
+    if (!empty($options['extension'])) {
133
+        $options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension']));
134
+    }
135
+    $extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls');
136
+
137
+    // Fichier
138
+    $basename = "$filename.$extension";
139
+
140
+    // Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site
141
+    // Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
142
+    $charset_site = $GLOBALS['meta']['charset'];
143
+    $charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null);
144
+    $charset = $options['charset'] ?? $charset_excel ?? $charset_site;
145
+    $importer_charset = (($charset === $charset_site) ? null : $charset);
146
+
147
+    $output = '';
148
+    $nb = 0;
149
+    if (!empty($options['entetes']) && is_array($options['entetes'])) {
150
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
151
+    }
152
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
153
+    $nb++;
154
+
155
+    if ($options['envoyer']) {
156
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
157
+        header("Content-Type: text/comma-separated-values; charset=$charset");
158
+        header("Content-Disposition: $disposition; filename=$basename");
159
+
160
+        // Vider tous les tampons
161
+        $level = @ob_get_level();
162
+        while ($level--) {
163
+            @ob_end_flush();
164
+        }
165
+    }
166
+
167
+    // si envoyer=='attachment' on passe par un fichier temporaire
168
+    // sinon on ecrit directement sur stdout
169
+    if ($options['envoyer'] && $options['envoyer'] !== 'attachment') {
170
+        $fichier = 'php://output';
171
+    }
172
+    else {
173
+        $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename;
174
+    }
175
+
176
+    $fp = fopen($fichier, 'w');
177
+    $length = fwrite($fp, $output);
178
+
179
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
180
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
181
+        $length += fwrite($fp, $output);
182
+        $nb++;
183
+    }
184
+    fclose($fp);
185
+
186
+    if ($options['envoyer']) {
187
+        if ($options['envoyer'] === 'attachment') {
188
+            header("Content-Length: $length");
189
+            readfile($fichier);
190
+        }
191
+        // si on a envoye inline, c'est deja tout bon
192
+        exit;
193
+    }
194
+
195
+    return $fichier;
196 196
 }
Please login to merge, or discard this patch.
ecrire/inc/acces.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -30,41 +30,41 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
34
-
35
-	mt_srand($seed);
36
-	$s = '';
37
-	$pass = '';
38
-	for ($i = 0; $i < $longueur; $i++) {
39
-		if (!$s) {
40
-			$s = random_int(0, mt_getrandmax());
41
-			if (!$s) {
42
-				$s = random_int(0, mt_getrandmax());
43
-			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
45
-		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
47
-		$x = $r['r'] & 63;
48
-		if ($x < 10) {
49
-			$x = chr($x + 48);
50
-		} else {
51
-			if ($x < 36) {
52
-				$x = chr($x + 55);
53
-			} else {
54
-				if ($x < 62) {
55
-					$x = chr($x + 61);
56
-				} else {
57
-					$x = $x == 63 ? '/' : '.';
58
-				}
59
-			}
60
-		}
61
-		$pass .= $x;
62
-		$s = substr($s, 2);
63
-	}
64
-	$pass = preg_replace('@[./]@', 'a', $pass);
65
-	$pass = preg_replace('@[I1l]@', 'L', $pass);
66
-
67
-	return preg_replace('@[0O]@', 'o', $pass);
33
+    $seed = (int)round(((float)microtime() + 1) * time());
34
+
35
+    mt_srand($seed);
36
+    $s = '';
37
+    $pass = '';
38
+    for ($i = 0; $i < $longueur; $i++) {
39
+        if (!$s) {
40
+            $s = random_int(0, mt_getrandmax());
41
+            if (!$s) {
42
+                $s = random_int(0, mt_getrandmax());
43
+            }
44
+            $s = substr(md5(uniqid($s) . $sel), 0, 16);
45
+        }
46
+        $r = unpack('Cr', pack('H2', $s . $s));
47
+        $x = $r['r'] & 63;
48
+        if ($x < 10) {
49
+            $x = chr($x + 48);
50
+        } else {
51
+            if ($x < 36) {
52
+                $x = chr($x + 55);
53
+            } else {
54
+                if ($x < 62) {
55
+                    $x = chr($x + 61);
56
+                } else {
57
+                    $x = $x == 63 ? '/' : '.';
58
+                }
59
+            }
60
+        }
61
+        $pass .= $x;
62
+        $s = substr($s, 2);
63
+    }
64
+    $pass = preg_replace('@[./]@', 'a', $pass);
65
+    $pass = preg_replace('@[I1l]@', 'L', $pass);
66
+
67
+    return preg_replace('@[0O]@', 'o', $pass);
68 68
 }
69 69
 
70 70
 /**
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
  * @return string Identifiant
74 74
  */
75 75
 function creer_uniqid() {
76
-	static $seeded;
76
+    static $seeded;
77 77
 
78
-	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
80
-		mt_srand($seed);
81
-		$seeded = true;
82
-	}
78
+    if (!$seeded) {
79
+        $seed = (int)round(((float)microtime() + 1) * time());
80
+        mt_srand($seed);
81
+        $seeded = true;
82
+    }
83 83
 
84
-	$s = random_int(0, mt_getrandmax());
85
-	if (!$s) {
86
-		$s = random_int(0, mt_getrandmax());
87
-	}
84
+    $s = random_int(0, mt_getrandmax());
85
+    if (!$s) {
86
+        $s = random_int(0, mt_getrandmax());
87
+    }
88 88
 
89
-	return uniqid($s, 1);
89
+    return uniqid($s, 1);
90 90
 }
91 91
 
92 92
 /**
@@ -100,42 +100,42 @@  discard block
 block discarded – undo
100 100
  * @return string Retourne l'alea éphemère actuel au passage
101 101
  */
102 102
 function charger_aleas() {
103
-	if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
-		include_spip('base/abstract_sql');
105
-		$aleas = sql_allfetsel(
106
-			['nom', 'valeur'],
107
-			'spip_meta',
108
-			sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
-			'',
110
-			'',
111
-			'',
112
-			'',
113
-			'',
114
-			'continue'
115
-		);
116
-		if ($aleas) {
117
-			foreach ($aleas as $a) {
118
-				$GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
-			}
120
-			return $GLOBALS['meta']['alea_ephemere'];
121
-		} else {
122
-			spip_log('aleas indisponibles', 'session');
123
-			return '';
124
-		}
125
-	}
126
-	return $GLOBALS['meta']['alea_ephemere'];
103
+    if (!isset($GLOBALS['meta']['alea_ephemere'])) {
104
+        include_spip('base/abstract_sql');
105
+        $aleas = sql_allfetsel(
106
+            ['nom', 'valeur'],
107
+            'spip_meta',
108
+            sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']),
109
+            '',
110
+            '',
111
+            '',
112
+            '',
113
+            '',
114
+            'continue'
115
+        );
116
+        if ($aleas) {
117
+            foreach ($aleas as $a) {
118
+                $GLOBALS['meta'][$a['nom']] = $a['valeur'];
119
+            }
120
+            return $GLOBALS['meta']['alea_ephemere'];
121
+        } else {
122
+            spip_log('aleas indisponibles', 'session');
123
+            return '';
124
+        }
125
+    }
126
+    return $GLOBALS['meta']['alea_ephemere'];
127 127
 }
128 128
 
129 129
 /**
130 130
  * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`)
131 131
  **/
132 132
 function renouvelle_alea() {
133
-	charger_aleas();
134
-	ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
-	$GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
-	ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
-	ecrire_meta('alea_ephemere_date', time(), 'non');
138
-	spip_log("renouvellement de l'alea_ephemere");
133
+    charger_aleas();
134
+    ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non');
135
+    $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid());
136
+    ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non');
137
+    ecrire_meta('alea_ephemere_date', time(), 'non');
138
+    spip_log("renouvellement de l'alea_ephemere");
139 139
 }
140 140
 
141 141
 
@@ -155,21 +155,21 @@  discard block
 block discarded – undo
155 155
  *     Clé de sécurité.
156 156
  **/
157 157
 function low_sec($id_auteur) {
158
-	// Pas d'id_auteur : low_sec
159
-	if (!$id_auteur = (int) $id_auteur) {
160
-		include_spip('inc/config');
161
-		if (!$low_sec = lire_config('low_sec')) {
162
-			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
-		}
164
-	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
-		if (!$low_sec) {
167
-			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
-		}
170
-	}
171
-
172
-	return $low_sec;
158
+    // Pas d'id_auteur : low_sec
159
+    if (!$id_auteur = (int) $id_auteur) {
160
+        include_spip('inc/config');
161
+        if (!$low_sec = lire_config('low_sec')) {
162
+            ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163
+        }
164
+    } else {
165
+        $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
166
+        if (!$low_sec) {
167
+            $low_sec = creer_pass_aleatoire();
168
+            sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
169
+        }
170
+    }
171
+
172
+    return $low_sec;
173 173
 }
174 174
 
175 175
 
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
  * @filtre
203 203
  */
204 204
 function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') {
205
-	if ($op) {
206
-		$dir .= " $op $args";
207
-	}
205
+    if ($op) {
206
+        $dir .= " $op $args";
207
+    }
208 208
 
209
-	return verifier_low_sec($id_auteur, $cle, $dir);
209
+    return verifier_low_sec($id_auteur, $cle, $dir);
210 210
 }
211 211
 
212 212
 /**
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217
-	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
-	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
217
+    $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218
+    $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
+    $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
220 220
 
221
-	return generer_url_api($script, $path, $args, $no_entities = false, $public);
221
+    return generer_url_api($script, $path, $args, $no_entities = false, $public);
222 222
 }
223 223
 
224 224
 /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
  *     Clé
235 235
  **/
236 236
 function afficher_low_sec($id_auteur, $action = '') {
237
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
237
+    return substr(md5($action . low_sec($id_auteur)), 0, 8);
238 238
 }
239 239
 
240 240
 /**
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  *     true si les clés corresponde, false sinon
253 253
  **/
254 254
 function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') {
255
-	return ($cle == afficher_low_sec($id_auteur, $action));
255
+    return ($cle == afficher_low_sec($id_auteur, $action));
256 256
 }
257 257
 
258 258
 /**
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
  *     Identifiant de l'auteur
263 263
  **/
264 264
 function effacer_low_sec($id_auteur) {
265
-	if (!$id_auteur = (int) $id_auteur) {
266
-		return;
267
-	} // jamais trop prudent ;)
268
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
265
+    if (!$id_auteur = (int) $id_auteur) {
266
+        return;
267
+    } // jamais trop prudent ;)
268
+    sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
269 269
 }
270 270
 
271 271
 
@@ -283,29 +283,29 @@  discard block
 block discarded – undo
283 283
  *     - void sinon.
284 284
  **/
285 285
 function ecrire_acces() {
286
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
288
-
289
-	// Cette variable de configuration peut etre posee par un plugin
290
-	// par exemple acces_restreint ;
291
-	// si .htaccess existe, outrepasser spip_meta
292
-	if (
293
-		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294
-	) {
295
-		spip_unlink($htpasswd);
296
-		spip_unlink($htpasswd . '-admin');
297
-		return;
298
-	}
299
-
300
-	# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
301
-	# de devenir redacteur le cas echeant (auth http)... a nettoyer
302
-	// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
303
-	// TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
304
-	if (include_spip('auth/ldap') && auth_ldap_connect()) {
305
-		return;
306
-	}
307
-
308
-	generer_htpasswd_files($htpasswd, "$htpasswd-admin");
286
+    $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
+    $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
288
+
289
+    // Cette variable de configuration peut etre posee par un plugin
290
+    // par exemple acces_restreint ;
291
+    // si .htaccess existe, outrepasser spip_meta
292
+    if (
293
+        (!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294
+    ) {
295
+        spip_unlink($htpasswd);
296
+        spip_unlink($htpasswd . '-admin');
297
+        return;
298
+    }
299
+
300
+    # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
301
+    # de devenir redacteur le cas echeant (auth http)... a nettoyer
302
+    // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
303
+    // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect()
304
+    if (include_spip('auth/ldap') && auth_ldap_connect()) {
305
+        return;
306
+    }
307
+
308
+    generer_htpasswd_files($htpasswd, "$htpasswd-admin");
309 309
 }
310 310
 
311 311
 /**
@@ -314,29 +314,29 @@  discard block
 block discarded – undo
314 314
  * @param $htpasswd_admin
315 315
  */
316 316
 function generer_htpasswd_files($htpasswd, $htpasswd_admin) {
317
-	if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
318
-		$generer_htpasswd($htpasswd, $htpasswd_admin);
319
-	}
320
-
321
-	$pwd_all = ''; // login:htpass pour tous
322
-	$pwd_admin = ''; // login:htpass pour les admins
323
-
324
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325
-	while ($row = sql_fetch($res)) {
326
-		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
328
-			$pwd_all .= $ligne;
329
-			if ($row['statut'] == '0minirezo') {
330
-				$pwd_admin .= $ligne;
331
-			}
332
-		}
333
-	}
334
-
335
-	if ($pwd_all) {
336
-		ecrire_fichier($htpasswd, $pwd_all);
337
-		ecrire_fichier($htpasswd_admin, $pwd_admin);
338
-		spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
339
-	}
317
+    if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) {
318
+        $generer_htpasswd($htpasswd, $htpasswd_admin);
319
+    }
320
+
321
+    $pwd_all = ''; // login:htpass pour tous
322
+    $pwd_admin = ''; // login:htpass pour les admins
323
+
324
+    $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325
+    while ($row = sql_fetch($res)) {
326
+        if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
+            $ligne = $row['login'] . ':' . $row['htpass'] . "\n";
328
+            $pwd_all .= $ligne;
329
+            if ($row['statut'] == '0minirezo') {
330
+                $pwd_admin .= $ligne;
331
+            }
332
+        }
333
+    }
334
+
335
+    if ($pwd_all) {
336
+        ecrire_fichier($htpasswd, $pwd_all);
337
+        ecrire_fichier($htpasswd_admin, $pwd_admin);
338
+        spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass');
339
+    }
340 340
 }
341 341
 
342 342
 /**
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
  *  La chaîne hachée si fonction crypt présente, rien sinon.
351 351
  */
352 352
 function generer_htpass(#[\SensitiveParameter] $pass) {
353
-	if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
354
-		return $generer_htpass($pass);
355
-	}
353
+    if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) {
354
+        return $generer_htpass($pass);
355
+    }
356 356
 
357
-	return '';
357
+    return '';
358 358
 }
359 359
 
360 360
 /**
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
  * @return boolean
368 368
  */
369 369
 function verifier_htaccess($rep, $force = false) {
370
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
371
-	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372
-		return true;
373
-	}
374
-
375
-	// directive deny compatible Apache 2.0+
376
-	$deny =
377
-		'# Deny all requests from Apache 2.4+.
370
+    $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
371
+    if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372
+        return true;
373
+    }
374
+
375
+    // directive deny compatible Apache 2.0+
376
+    $deny =
377
+        '# Deny all requests from Apache 2.4+.
378 378
 <IfModule mod_authz_core.c>
379 379
   Require all denied
380 380
 </IfModule>
@@ -383,30 +383,30 @@  discard block
 block discarded – undo
383 383
   Deny from all
384 384
 </IfModule>
385 385
 ';
386
-	// support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
387
-	if (
388
-		function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
389
-	) {
390
-		$deny = "deny from all\n";
391
-	}
392
-
393
-	if ($ht = @fopen($htaccess, 'w')) {
394
-		fwrite($ht, $deny);
395
-		fclose($ht);
396
-		@chmod($htaccess, _SPIP_CHMOD & 0666);
397
-		$t = rtrim($rep, '/') . '/.ok';
398
-		if ($ht = @fopen($t, 'w')) {
399
-			@fclose($ht);
400
-			include_spip('inc/distant');
401
-			$t = substr($t, strlen(_DIR_RACINE));
402
-			$t = url_de_base() . $t;
403
-			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404
-			$ht = ($ht['status'] ?? null) === 403;
405
-		}
406
-	}
407
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
408
-
409
-	return $ht;
386
+    // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD)
387
+    if (
388
+        function_exists('apache_get_version') && ($v = apache_get_version()) && str_starts_with($v, 'Apache/1.')
389
+    ) {
390
+        $deny = "deny from all\n";
391
+    }
392
+
393
+    if ($ht = @fopen($htaccess, 'w')) {
394
+        fwrite($ht, $deny);
395
+        fclose($ht);
396
+        @chmod($htaccess, _SPIP_CHMOD & 0666);
397
+        $t = rtrim($rep, '/') . '/.ok';
398
+        if ($ht = @fopen($t, 'w')) {
399
+            @fclose($ht);
400
+            include_spip('inc/distant');
401
+            $t = substr($t, strlen(_DIR_RACINE));
402
+            $t = url_de_base() . $t;
403
+            $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404
+            $ht = ($ht['status'] ?? null) === 403;
405
+        }
406
+    }
407
+    spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
408
+
409
+    return $ht;
410 410
 }
411 411
 
412 412
 /**
@@ -424,20 +424,20 @@  discard block
 block discarded – undo
424 424
  *         Valeur de la configuration `creer_htaccess`
425 425
  */
426 426
 function gerer_htaccess() {
427
-	// Cette variable de configuration peut etre posee par un plugin
428
-	// par exemple acces_restreint
429
-	$f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
430
-	$dirs = sql_allfetsel('extension', 'spip_types_documents');
431
-	$dirs[] = ['extension' => 'distant'];
432
-	foreach ($dirs as $e) {
433
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
434
-			if ($f) {
435
-				verifier_htaccess($dir);
436
-			} else {
437
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
438
-			}
439
-		}
440
-	}
441
-
442
-	return $GLOBALS['meta']['creer_htaccess'] ?? '';
427
+    // Cette variable de configuration peut etre posee par un plugin
428
+    // par exemple acces_restreint
429
+    $f = (isset($GLOBALS['meta']['creer_htaccess']) && $GLOBALS['meta']['creer_htaccess'] === 'oui');
430
+    $dirs = sql_allfetsel('extension', 'spip_types_documents');
431
+    $dirs[] = ['extension' => 'distant'];
432
+    foreach ($dirs as $e) {
433
+        if (is_dir($dir = _DIR_IMG . $e['extension'])) {
434
+            if ($f) {
435
+                verifier_htaccess($dir);
436
+            } else {
437
+                spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
438
+            }
439
+        }
440
+    }
441
+
442
+    return $GLOBALS['meta']['creer_htaccess'] ?? '';
443 443
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  *     Mot de passe
31 31
  **/
32 32
 function creer_pass_aleatoire($longueur = 16, $sel = '') {
33
-	$seed = (int)round(((float)microtime() + 1) * time());
33
+	$seed = (int) round(((float) microtime() + 1) * time());
34 34
 
35 35
 	mt_srand($seed);
36 36
 	$s = '';
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 			if (!$s) {
42 42
 				$s = random_int(0, mt_getrandmax());
43 43
 			}
44
-			$s = substr(md5(uniqid($s) . $sel), 0, 16);
44
+			$s = substr(md5(uniqid($s).$sel), 0, 16);
45 45
 		}
46
-		$r = unpack('Cr', pack('H2', $s . $s));
46
+		$r = unpack('Cr', pack('H2', $s.$s));
47 47
 		$x = $r['r'] & 63;
48 48
 		if ($x < 10) {
49 49
 			$x = chr($x + 48);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	static $seeded;
77 77
 
78 78
 	if (!$seeded) {
79
-		$seed = (int)round(((float)microtime() + 1) * time());
79
+		$seed = (int) round(((float) microtime() + 1) * time());
80 80
 		mt_srand($seed);
81 81
 		$seeded = true;
82 82
 	}
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire());
163 163
 		}
164 164
 	} else {
165
-		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . (int) $id_auteur);
165
+		$low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.(int) $id_auteur);
166 166
 		if (!$low_sec) {
167 167
 			$low_sec = creer_pass_aleatoire();
168
-			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . (int) $id_auteur);
168
+			sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.(int) $id_auteur);
169 169
 		}
170 170
 	}
171 171
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
217 217
 	$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
218 218
 	$cle = afficher_low_sec($id_auteur, "$script/$format $fond $args");
219
-	$path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : '');
219
+	$path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : '');
220 220
 
221 221
 	return generer_url_api($script, $path, $args, $no_entities = false, $public);
222 222
 }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
  *     Clé
235 235
  **/
236 236
 function afficher_low_sec($id_auteur, $action = '') {
237
-	return substr(md5($action . low_sec($id_auteur)), 0, 8);
237
+	return substr(md5($action.low_sec($id_auteur)), 0, 8);
238 238
 }
239 239
 
240 240
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	if (!$id_auteur = (int) $id_auteur) {
266 266
 		return;
267 267
 	} // jamais trop prudent ;)
268
-	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . (int) $id_auteur);
268
+	sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.(int) $id_auteur);
269 269
 }
270 270
 
271 271
 
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
  *     - void sinon.
284 284
  **/
285 285
 function ecrire_acces() {
286
-	$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
287
-	$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
286
+	$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
287
+	$htpasswd = _DIR_TMP._AUTH_USER_FILE;
288 288
 
289 289
 	// Cette variable de configuration peut etre posee par un plugin
290 290
 	// par exemple acces_restreint ;
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		(!isset($GLOBALS['meta']['creer_htpasswd']) || $GLOBALS['meta']['creer_htpasswd'] != 'oui') && !@file_exists($htaccess)
294 294
 	) {
295 295
 		spip_unlink($htpasswd);
296
-		spip_unlink($htpasswd . '-admin');
296
+		spip_unlink($htpasswd.'-admin');
297 297
 		return;
298 298
 	}
299 299
 
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
 	$pwd_all = ''; // login:htpass pour tous
322 322
 	$pwd_admin = ''; // login:htpass pour les admins
323 323
 
324
-	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
324
+	$res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau']));
325 325
 	while ($row = sql_fetch($res)) {
326 326
 		if (strlen((string) $row['login']) && strlen((string) $row['htpass'])) {
327
-			$ligne = $row['login'] . ':' . $row['htpass'] . "\n";
327
+			$ligne = $row['login'].':'.$row['htpass']."\n";
328 328
 			$pwd_all .= $ligne;
329 329
 			if ($row['statut'] == '0minirezo') {
330 330
 				$pwd_admin .= $ligne;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
  * @return boolean
368 368
  */
369 369
 function verifier_htaccess($rep, $force = false) {
370
-	$htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME;
370
+	$htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME;
371 371
 	if ((@file_exists($htaccess) || defined('_TEST_DIRS')) && !$force) {
372 372
 		return true;
373 373
 	}
@@ -394,17 +394,17 @@  discard block
 block discarded – undo
394 394
 		fwrite($ht, $deny);
395 395
 		fclose($ht);
396 396
 		@chmod($htaccess, _SPIP_CHMOD & 0666);
397
-		$t = rtrim($rep, '/') . '/.ok';
397
+		$t = rtrim($rep, '/').'/.ok';
398 398
 		if ($ht = @fopen($t, 'w')) {
399 399
 			@fclose($ht);
400 400
 			include_spip('inc/distant');
401 401
 			$t = substr($t, strlen(_DIR_RACINE));
402
-			$t = url_de_base() . $t;
402
+			$t = url_de_base().$t;
403 403
 			$ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]);
404 404
 			$ht = ($ht['status'] ?? null) === 403;
405 405
 		}
406 406
 	}
407
-	spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee'));
407
+	spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee'));
408 408
 
409 409
 	return $ht;
410 410
 }
@@ -430,11 +430,11 @@  discard block
 block discarded – undo
430 430
 	$dirs = sql_allfetsel('extension', 'spip_types_documents');
431 431
 	$dirs[] = ['extension' => 'distant'];
432 432
 	foreach ($dirs as $e) {
433
-		if (is_dir($dir = _DIR_IMG . $e['extension'])) {
433
+		if (is_dir($dir = _DIR_IMG.$e['extension'])) {
434 434
 			if ($f) {
435 435
 				verifier_htaccess($dir);
436 436
 			} else {
437
-				spip_unlink($dir . '/' . _ACCESS_FILE_NAME);
437
+				spip_unlink($dir.'/'._ACCESS_FILE_NAME);
438 438
 			}
439 439
 		}
440 440
 	}
Please login to merge, or discard this patch.
ecrire/inc/chercher_logo.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Logos
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -34,23 +34,23 @@  discard block
 block discarded – undo
34 34
  **/
35 35
 function inc_chercher_logo_dist(int $id, string $_id_objet, string $mode = 'on', bool $compat_old_logos = false): array {
36 36
 
37
-	$mode = preg_replace(',\W,', '', $mode);
38
-	if ($mode) {
39
-		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
41
-		$objet = objet_type($_id_objet);
42
-		$doc = sql_fetsel(
43
-			'D.*',
44
-			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
-		);
47
-		if ($doc) {
48
-			include_spip('inc/documents');
49
-			$d = get_spip_doc($doc['fichier']);
50
-			return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
-		}
52
-	}
37
+    $mode = preg_replace(',\W,', '', $mode);
38
+    if ($mode) {
39
+        // chercher dans la base
40
+        $mode_document = 'logo' . $mode;
41
+        $objet = objet_type($_id_objet);
42
+        $doc = sql_fetsel(
43
+            'D.*',
44
+            'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
+            'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
+        );
47
+        if ($doc) {
48
+            include_spip('inc/documents');
49
+            $d = get_spip_doc($doc['fichier']);
50
+            return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
+        }
52
+    }
53 53
 
54
-	# coherence de type pour servir comme filtre (formulaire_login)
55
-	return [];
54
+    # coherence de type pour servir comme filtre (formulaire_login)
55
+    return [];
56 56
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@
 block discarded – undo
37 37
 	$mode = preg_replace(',\W,', '', $mode);
38 38
 	if ($mode) {
39 39
 		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
40
+		$mode_document = 'logo'.$mode;
41 41
 		$objet = objet_type($_id_objet);
42 42
 		$doc = sql_fetsel(
43 43
 			'D.*',
44 44
 			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
45
+			'D.mode='.sql_quote($mode_document).' AND L.objet='.sql_quote($objet).' AND id_objet='.$id
46 46
 		);
47 47
 		if ($doc) {
48 48
 			include_spip('inc/documents');
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2271 added lines, -2272 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -47,71 +47,71 @@  discard block
 block discarded – undo
47 47
  *     Nom de la fonction, ou false.
48 48
  */
49 49
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
50
-	static $echecs = [];
51
-
52
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
53
-		$dossier .= '/';
54
-	}
55
-	$f = str_replace('/', '_', $dossier) . $nom;
56
-
57
-	if (function_exists($f)) {
58
-		return $f;
59
-	}
60
-	if (function_exists($g = $f . '_dist')) {
61
-		return $g;
62
-	}
63
-
64
-	if (isset($echecs[$f])) {
65
-		return $echecs[$f];
66
-	}
67
-	// Sinon charger le fichier de declaration si plausible
68
-
69
-	if (!preg_match(',^\w+$,', $f)) {
70
-		if ($continue) {
71
-			return false;
72
-		} //appel interne, on passe
73
-		include_spip('inc/minipres');
74
-		echo minipres();
75
-		exit;
76
-	}
77
-
78
-	// passer en minuscules (cf les balises de formulaires)
79
-	// et inclure le fichier
80
-	if (
81
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
-		// si le fichier truc/machin/nom.php n'existe pas,
83
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
-	) {
86
-		include_spip(substr($dossier, 0, -1));
87
-	}
88
-	if (function_exists($f)) {
89
-		return $f;
90
-	}
91
-	if (function_exists($g)) {
92
-		return $g;
93
-	}
94
-
95
-	if ($continue) {
96
-		return $echecs[$f] = false;
97
-	}
98
-
99
-	// Echec : message d'erreur
100
-	spip_log("fonction $nom ($f ou $g) indisponible" .
101
-		($inc ? '' : " (fichier $d absent de $dossier)"));
102
-
103
-	include_spip('inc/minipres');
104
-	echo minipres(
105
-		_T('forum_titre_erreur'),
106
-		$inc ?
107
-			_T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
108
-			. '<br />'
109
-			. _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
110
-			:
111
-			_T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
112
-		['all_inline' => true,'status' => 404]
113
-	);
114
-	exit;
50
+    static $echecs = [];
51
+
52
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
53
+        $dossier .= '/';
54
+    }
55
+    $f = str_replace('/', '_', $dossier) . $nom;
56
+
57
+    if (function_exists($f)) {
58
+        return $f;
59
+    }
60
+    if (function_exists($g = $f . '_dist')) {
61
+        return $g;
62
+    }
63
+
64
+    if (isset($echecs[$f])) {
65
+        return $echecs[$f];
66
+    }
67
+    // Sinon charger le fichier de declaration si plausible
68
+
69
+    if (!preg_match(',^\w+$,', $f)) {
70
+        if ($continue) {
71
+            return false;
72
+        } //appel interne, on passe
73
+        include_spip('inc/minipres');
74
+        echo minipres();
75
+        exit;
76
+    }
77
+
78
+    // passer en minuscules (cf les balises de formulaires)
79
+    // et inclure le fichier
80
+    if (
81
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
82
+        // si le fichier truc/machin/nom.php n'existe pas,
83
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
+    ) {
86
+        include_spip(substr($dossier, 0, -1));
87
+    }
88
+    if (function_exists($f)) {
89
+        return $f;
90
+    }
91
+    if (function_exists($g)) {
92
+        return $g;
93
+    }
94
+
95
+    if ($continue) {
96
+        return $echecs[$f] = false;
97
+    }
98
+
99
+    // Echec : message d'erreur
100
+    spip_log("fonction $nom ($f ou $g) indisponible" .
101
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
102
+
103
+    include_spip('inc/minipres');
104
+    echo minipres(
105
+        _T('forum_titre_erreur'),
106
+        $inc ?
107
+            _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
108
+            . '<br />'
109
+            . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
110
+            :
111
+            _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
112
+        ['all_inline' => true,'status' => 404]
113
+    );
114
+    exit;
115 115
 }
116 116
 
117 117
 /**
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
  * @return bool
122 122
  */
123 123
 function include_once_check($file) {
124
-	if (file_exists($file)) {
125
-		include_once $file;
124
+    if (file_exists($file)) {
125
+        include_once $file;
126 126
 
127
-		return true;
128
-	}
129
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
130
-	$crash = ($crash ?: []);
131
-	$crash[$file] = true;
132
-	ecrire_meta('message_crash_plugins', serialize($crash));
127
+        return true;
128
+    }
129
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
130
+    $crash = ($crash ?: []);
131
+    $crash[$file] = true;
132
+    ecrire_meta('message_crash_plugins', serialize($crash));
133 133
 
134
-	return false;
134
+    return false;
135 135
 }
136 136
 
137 137
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
  *     - string : chemin du fichier trouvé
156 156
  **/
157 157
 function include_spip($f, $include = true) {
158
-	return find_in_path($f . '.php', '', $include);
158
+    return find_in_path($f . '.php', '', $include);
159 159
 }
160 160
 
161 161
 /**
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
  *     - string : chemin du fichier trouvé
176 176
  **/
177 177
 function require_spip($f) {
178
-	return find_in_path($f . '.php', '', 'required');
178
+    return find_in_path($f . '.php', '', 'required');
179 179
 }
180 180
 
181 181
 
@@ -184,27 +184,27 @@  discard block
 block discarded – undo
184 184
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
185 185
  */
186 186
 function include_fichiers_fonctions() {
187
-	static $done = false;
188
-	if (!$done) {
189
-		include_spip('inc/lang');
190
-
191
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
192
-		// donc il faut l'inclure "en globals"
193
-		if ($f = find_in_path('mes_fonctions.php')) {
194
-			global $dossier_squelettes;
195
-			include_once(_ROOT_CWD . $f);
196
-		}
197
-
198
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
199
-			// chargement optimise precompile
200
-			include_once(_CACHE_PLUGINS_FCT);
201
-		}
202
-		if (test_espace_prive()) {
203
-			include_spip('inc/filtres_ecrire');
204
-		}
205
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
206
-		$done = true;
207
-	}
187
+    static $done = false;
188
+    if (!$done) {
189
+        include_spip('inc/lang');
190
+
191
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
192
+        // donc il faut l'inclure "en globals"
193
+        if ($f = find_in_path('mes_fonctions.php')) {
194
+            global $dossier_squelettes;
195
+            include_once(_ROOT_CWD . $f);
196
+        }
197
+
198
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
199
+            // chargement optimise precompile
200
+            include_once(_CACHE_PLUGINS_FCT);
201
+        }
202
+        if (test_espace_prive()) {
203
+            include_spip('inc/filtres_ecrire');
204
+        }
205
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
206
+        $done = true;
207
+    }
208 208
 }
209 209
 
210 210
 /**
@@ -230,23 +230,23 @@  discard block
 block discarded – undo
230 230
  *     Les paramètres du pipeline modifiés
231 231
  **/
232 232
 function minipipe($fonc, &$val) {
233
-	// fonction
234
-	if (function_exists($fonc)) {
235
-		$val = $fonc($val);
236
-	} // Class::Methode
237
-	else {
238
-		if (
239
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
240
-			and $methode = [$regs[1], $regs[2]]
241
-			and is_callable($methode)
242
-		) {
243
-			$val = $methode($val);
244
-		} else {
245
-			spip_log("Erreur - '$fonc' non definie !");
246
-		}
247
-	}
248
-
249
-	return $val;
233
+    // fonction
234
+    if (function_exists($fonc)) {
235
+        $val = $fonc($val);
236
+    } // Class::Methode
237
+    else {
238
+        if (
239
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
240
+            and $methode = [$regs[1], $regs[2]]
241
+            and is_callable($methode)
242
+        ) {
243
+            $val = $methode($val);
244
+        } else {
245
+            spip_log("Erreur - '$fonc' non definie !");
246
+        }
247
+    }
248
+
249
+    return $val;
250 250
 }
251 251
 
252 252
 /**
@@ -277,46 +277,46 @@  discard block
 block discarded – undo
277 277
  *     Résultat
278 278
  */
279 279
 function pipeline($action, $val = null) {
280
-	static $charger;
281
-
282
-	// chargement initial des fonctions mises en cache, ou generation du cache
283
-	if (!$charger) {
284
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
285
-			include_spip('inc/plugin');
286
-			// generer les fichiers php precompiles
287
-			// de chargement des plugins et des pipelines
288
-			actualise_plugins_actifs();
289
-			if (!($ok = @is_readable($charger))) {
290
-				spip_log("fichier $charger pas cree");
291
-			}
292
-		}
293
-
294
-		if ($ok) {
295
-			include_once $charger;
296
-		}
297
-	}
298
-
299
-	// appliquer notre fonction si elle existe
300
-	$fonc = 'execute_pipeline_' . strtolower($action);
301
-	if (function_exists($fonc)) {
302
-		$val = $fonc($val);
303
-	} // plantage ?
304
-	else {
305
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
306
-	}
307
-
308
-	// si le flux est une table avec 2 cle args&data
309
-	// on ne ressort du pipe que les donnees dans 'data'
310
-	// array_key_exists pour php 4.1.0
311
-	if (
312
-		is_array($val)
313
-		and count($val) == 2
314
-		and (array_key_exists('data', $val))
315
-	) {
316
-		$val = $val['data'];
317
-	}
318
-
319
-	return $val;
280
+    static $charger;
281
+
282
+    // chargement initial des fonctions mises en cache, ou generation du cache
283
+    if (!$charger) {
284
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
285
+            include_spip('inc/plugin');
286
+            // generer les fichiers php precompiles
287
+            // de chargement des plugins et des pipelines
288
+            actualise_plugins_actifs();
289
+            if (!($ok = @is_readable($charger))) {
290
+                spip_log("fichier $charger pas cree");
291
+            }
292
+        }
293
+
294
+        if ($ok) {
295
+            include_once $charger;
296
+        }
297
+    }
298
+
299
+    // appliquer notre fonction si elle existe
300
+    $fonc = 'execute_pipeline_' . strtolower($action);
301
+    if (function_exists($fonc)) {
302
+        $val = $fonc($val);
303
+    } // plantage ?
304
+    else {
305
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
306
+    }
307
+
308
+    // si le flux est une table avec 2 cle args&data
309
+    // on ne ressort du pipe que les donnees dans 'data'
310
+    // array_key_exists pour php 4.1.0
311
+    if (
312
+        is_array($val)
313
+        and count($val) == 2
314
+        and (array_key_exists('data', $val))
315
+    ) {
316
+        $val = $val['data'];
317
+    }
318
+
319
+    return $val;
320 320
 }
321 321
 
322 322
 /**
@@ -360,38 +360,38 @@  discard block
 block discarded – undo
360 360
  *     paramètre est planté pour cause de compatibilité ascendante.
361 361
  */
362 362
 function spip_log($message = null, $name = null) {
363
-	static $pre = [];
364
-	static $log;
365
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
366
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
367
-		$logname = null;
368
-	}
369
-	if (!isset($regs[2])) {
370
-		$niveau = _LOG_INFO;
371
-	}
372
-	else {
373
-		$niveau = intval($regs[2]);
374
-	}
375
-
376
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
377
-		if (!$pre) {
378
-			$pre = [
379
-				_LOG_HS => 'HS:',
380
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
381
-				_LOG_CRITIQUE => 'CRITIQUE:',
382
-				_LOG_ERREUR => 'ERREUR:',
383
-				_LOG_AVERTISSEMENT => 'WARNING:',
384
-				_LOG_INFO_IMPORTANTE => '!INFO:',
385
-				_LOG_INFO => 'info:',
386
-				_LOG_DEBUG => 'debug:'
387
-			];
388
-			$log = charger_fonction('log', 'inc');
389
-		}
390
-		if (!is_string($message)) {
391
-			$message = print_r($message, true);
392
-		}
393
-		$log($pre[$niveau] . ' ' . $message, $logname);
394
-	}
363
+    static $pre = [];
364
+    static $log;
365
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
366
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
367
+        $logname = null;
368
+    }
369
+    if (!isset($regs[2])) {
370
+        $niveau = _LOG_INFO;
371
+    }
372
+    else {
373
+        $niveau = intval($regs[2]);
374
+    }
375
+
376
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
377
+        if (!$pre) {
378
+            $pre = [
379
+                _LOG_HS => 'HS:',
380
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
381
+                _LOG_CRITIQUE => 'CRITIQUE:',
382
+                _LOG_ERREUR => 'ERREUR:',
383
+                _LOG_AVERTISSEMENT => 'WARNING:',
384
+                _LOG_INFO_IMPORTANTE => '!INFO:',
385
+                _LOG_INFO => 'info:',
386
+                _LOG_DEBUG => 'debug:'
387
+            ];
388
+            $log = charger_fonction('log', 'inc');
389
+        }
390
+        if (!is_string($message)) {
391
+            $message = print_r($message, true);
392
+        }
393
+        $log($pre[$niveau] . ' ' . $message, $logname);
394
+    }
395 395
 }
396 396
 
397 397
 
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @param array $opt Tableau d'options
404 404
  **/
405 405
 function journal($phrase, $opt = []) {
406
-	$journal = charger_fonction('journal', 'inc');
407
-	$journal($phrase, $opt);
406
+    $journal = charger_fonction('journal', 'inc');
407
+    $journal($phrase, $opt);
408 408
 }
409 409
 
410 410
 
@@ -423,37 +423,37 @@  discard block
 block discarded – undo
423 423
  **/
424 424
 function _request($var, $c = false) {
425 425
 
426
-	if (is_array($c)) {
427
-		return $c[$var] ?? null;
428
-	}
429
-
430
-	if (isset($_GET[$var])) {
431
-		$a = $_GET[$var];
432
-	} elseif (isset($_POST[$var])) {
433
-		$a = $_POST[$var];
434
-	} else {
435
-		return null;
436
-	}
437
-
438
-	// Si on est en ajax et en POST tout a ete encode
439
-	// via encodeURIComponent, il faut donc repasser
440
-	// dans le charset local...
441
-	if (
442
-		defined('_AJAX')
443
-		and _AJAX
444
-		and isset($GLOBALS['meta']['charset'])
445
-		and $GLOBALS['meta']['charset'] != 'utf-8'
446
-		and is_string($a)
447
-		// check rapide mais pas fiable
448
-		and preg_match(',[\x80-\xFF],', $a)
449
-		// check fiable
450
-		and include_spip('inc/charsets')
451
-		and is_utf8($a)
452
-	) {
453
-		return importer_charset($a, 'utf-8');
454
-	}
455
-
456
-	return $a;
426
+    if (is_array($c)) {
427
+        return $c[$var] ?? null;
428
+    }
429
+
430
+    if (isset($_GET[$var])) {
431
+        $a = $_GET[$var];
432
+    } elseif (isset($_POST[$var])) {
433
+        $a = $_POST[$var];
434
+    } else {
435
+        return null;
436
+    }
437
+
438
+    // Si on est en ajax et en POST tout a ete encode
439
+    // via encodeURIComponent, il faut donc repasser
440
+    // dans le charset local...
441
+    if (
442
+        defined('_AJAX')
443
+        and _AJAX
444
+        and isset($GLOBALS['meta']['charset'])
445
+        and $GLOBALS['meta']['charset'] != 'utf-8'
446
+        and is_string($a)
447
+        // check rapide mais pas fiable
448
+        and preg_match(',[\x80-\xFF],', $a)
449
+        // check fiable
450
+        and include_spip('inc/charsets')
451
+        and is_utf8($a)
452
+    ) {
453
+        return importer_charset($a, 'utf-8');
454
+    }
455
+
456
+    return $a;
457 457
 }
458 458
 
459 459
 
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
  *     - false sinon
472 472
  **/
473 473
 function set_request($var, $val = null, $c = false) {
474
-	if (is_array($c)) {
475
-		unset($c[$var]);
476
-		if ($val !== null) {
477
-			$c[$var] = $val;
478
-		}
474
+    if (is_array($c)) {
475
+        unset($c[$var]);
476
+        if ($val !== null) {
477
+            $c[$var] = $val;
478
+        }
479 479
 
480
-		return $c;
481
-	}
480
+        return $c;
481
+    }
482 482
 
483
-	unset($_GET[$var]);
484
-	unset($_POST[$var]);
485
-	if ($val !== null) {
486
-		$_GET[$var] = $val;
487
-	}
483
+    unset($_GET[$var]);
484
+    unset($_POST[$var]);
485
+    if ($val !== null) {
486
+        $_GET[$var] = $val;
487
+    }
488 488
 
489
-	return false; # n'affecte pas $c
489
+    return false; # n'affecte pas $c
490 490
 }
491 491
 
492 492
 /**
@@ -506,25 +506,25 @@  discard block
 block discarded – undo
506 506
  * @return array|mixed|string
507 507
  */
508 508
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
509
-	if (is_array($value)) {
510
-		if ($key == '*') {
511
-			$key = array_keys($value);
512
-		}
513
-		if (!is_array($key)) {
514
-			$key = [$key];
515
-		}
516
-		foreach ($key as $k) {
517
-			if (!empty($value[$k])) {
518
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
-			}
520
-		}
521
-		return $value;
522
-	}
523
-	// si la valeur vient des GET ou POST on la sanitize
524
-	if (!empty($value) and $value == _request($key)) {
525
-		$value = $sanitize_function($value);
526
-	}
527
-	return $value;
509
+    if (is_array($value)) {
510
+        if ($key == '*') {
511
+            $key = array_keys($value);
512
+        }
513
+        if (!is_array($key)) {
514
+            $key = [$key];
515
+        }
516
+        foreach ($key as $k) {
517
+            if (!empty($value[$k])) {
518
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
+            }
520
+        }
521
+        return $value;
522
+    }
523
+    // si la valeur vient des GET ou POST on la sanitize
524
+    if (!empty($value) and $value == _request($key)) {
525
+        $value = $sanitize_function($value);
526
+    }
527
+    return $value;
528 528
 }
529 529
 
530 530
 /**
@@ -532,23 +532,22 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * On est sur le web, on exclut certains protocoles,
534 534
  * notamment 'file://', 'php://' et d'autres…
535
-
536 535
  * @param string $url
537 536
  * @return bool
538 537
  */
539 538
 function tester_url_absolue($url) {
540
-	$url = trim($url ?? '');
541
-	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
542
-		if (
543
-			isset($m[1])
544
-			and $p = strtolower(rtrim($m[1], ':'))
545
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
546
-		) {
547
-			return false;
548
-		}
549
-		return true;
550
-	}
551
-	return false;
539
+    $url = trim($url ?? '');
540
+    if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
541
+        if (
542
+            isset($m[1])
543
+            and $p = strtolower(rtrim($m[1], ':'))
544
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
545
+        ) {
546
+            return false;
547
+        }
548
+        return true;
549
+    }
550
+    return false;
552 551
 }
553 552
 
554 553
 /**
@@ -570,100 +569,100 @@  discard block
 block discarded – undo
570 569
  * @return string URL
571 570
  */
572 571
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
573
-	// requete erronnee : plusieurs variable dans $c et aucun $v
574
-	if (strpos($c, '|') !== false and is_null($v)) {
575
-		return null;
576
-	}
577
-
578
-	// lever l'#ancre
579
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
580
-		$url = $r[1];
581
-		$ancre = $r[2];
582
-	} else {
583
-		$ancre = '';
584
-	}
585
-
586
-	// eclater
587
-	$url = preg_split(',[?]|&amp;|&,', $url);
588
-
589
-	// recuperer la base
590
-	$a = array_shift($url);
591
-	if (!$a) {
592
-		$a = './';
593
-	}
594
-
595
-	// preparer la regexp de maniere securisee
596
-	$regexp = explode('|', $c);
597
-	foreach ($regexp as $r => $e) {
598
-		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
599
-	}
600
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
601
-	$ajouts = array_flip(explode('|', $c));
602
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
603
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
604
-	$v_read = null;
605
-	// lire les variables et agir
606
-	foreach ($url as $n => $val) {
607
-		if (preg_match($regexp, urldecode($val), $r)) {
608
-			$r = array_pad($r, 3, null);
609
-			if ($v === null) {
610
-				// c'est un tableau, on memorise les valeurs
611
-				if (substr($r[1], -2) == '[]') {
612
-					if (!$v_read) {
613
-						$v_read = [];
614
-					}
615
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
616
-				} // c'est un scalaire, on retourne direct
617
-				else {
618
-					return $r[2] ? substr($r[2], 1) : '';
619
-				}
620
-			} // suppression
621
-			elseif (!$testv) {
622
-				unset($url[$n]);
623
-			}
624
-			// Ajout. Pour une variable, remplacer au meme endroit,
625
-			// pour un tableau ce sera fait dans la prochaine boucle
626
-			elseif (substr($r[1], -2) != '[]') {
627
-				$url[$n] = $r[1] . '=' . $u;
628
-				unset($ajouts[$r[1]]);
629
-			}
630
-			// Pour les tableaux on laisse tomber les valeurs de
631
-			// départ, on remplira à l'étape suivante
632
-			else {
633
-				unset($url[$n]);
634
-			}
635
-		}
636
-	}
637
-
638
-	// traiter les parametres pas encore trouves
639
-	if (
640
-		$v === null
641
-		and $args = func_get_args()
642
-		and count($args) == 2
643
-	) {
644
-		return $v_read; // rien trouve ou un tableau
645
-	} elseif ($testv) {
646
-		foreach ($ajouts as $k => $n) {
647
-			if (!is_array($v)) {
648
-				$url[] = $k . '=' . $u;
649
-			} else {
650
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
651
-				foreach ($v as $w) {
652
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
653
-				}
654
-			}
655
-		}
656
-	}
657
-
658
-	// eliminer les vides
659
-	$url = array_filter($url);
660
-
661
-	// recomposer l'adresse
662
-	if ($url) {
663
-		$a .= '?' . join($sep, $url);
664
-	}
665
-
666
-	return $a . $ancre;
572
+    // requete erronnee : plusieurs variable dans $c et aucun $v
573
+    if (strpos($c, '|') !== false and is_null($v)) {
574
+        return null;
575
+    }
576
+
577
+    // lever l'#ancre
578
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
579
+        $url = $r[1];
580
+        $ancre = $r[2];
581
+    } else {
582
+        $ancre = '';
583
+    }
584
+
585
+    // eclater
586
+    $url = preg_split(',[?]|&amp;|&,', $url);
587
+
588
+    // recuperer la base
589
+    $a = array_shift($url);
590
+    if (!$a) {
591
+        $a = './';
592
+    }
593
+
594
+    // preparer la regexp de maniere securisee
595
+    $regexp = explode('|', $c);
596
+    foreach ($regexp as $r => $e) {
597
+        $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
598
+    }
599
+    $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
600
+    $ajouts = array_flip(explode('|', $c));
601
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
602
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
603
+    $v_read = null;
604
+    // lire les variables et agir
605
+    foreach ($url as $n => $val) {
606
+        if (preg_match($regexp, urldecode($val), $r)) {
607
+            $r = array_pad($r, 3, null);
608
+            if ($v === null) {
609
+                // c'est un tableau, on memorise les valeurs
610
+                if (substr($r[1], -2) == '[]') {
611
+                    if (!$v_read) {
612
+                        $v_read = [];
613
+                    }
614
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
615
+                } // c'est un scalaire, on retourne direct
616
+                else {
617
+                    return $r[2] ? substr($r[2], 1) : '';
618
+                }
619
+            } // suppression
620
+            elseif (!$testv) {
621
+                unset($url[$n]);
622
+            }
623
+            // Ajout. Pour une variable, remplacer au meme endroit,
624
+            // pour un tableau ce sera fait dans la prochaine boucle
625
+            elseif (substr($r[1], -2) != '[]') {
626
+                $url[$n] = $r[1] . '=' . $u;
627
+                unset($ajouts[$r[1]]);
628
+            }
629
+            // Pour les tableaux on laisse tomber les valeurs de
630
+            // départ, on remplira à l'étape suivante
631
+            else {
632
+                unset($url[$n]);
633
+            }
634
+        }
635
+    }
636
+
637
+    // traiter les parametres pas encore trouves
638
+    if (
639
+        $v === null
640
+        and $args = func_get_args()
641
+        and count($args) == 2
642
+    ) {
643
+        return $v_read; // rien trouve ou un tableau
644
+    } elseif ($testv) {
645
+        foreach ($ajouts as $k => $n) {
646
+            if (!is_array($v)) {
647
+                $url[] = $k . '=' . $u;
648
+            } else {
649
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
650
+                foreach ($v as $w) {
651
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
652
+                }
653
+            }
654
+        }
655
+    }
656
+
657
+    // eliminer les vides
658
+    $url = array_filter($url);
659
+
660
+    // recomposer l'adresse
661
+    if ($url) {
662
+        $a .= '?' . join($sep, $url);
663
+    }
664
+
665
+    return $a . $ancre;
667 666
 }
668 667
 
669 668
 /**
@@ -678,22 +677,22 @@  discard block
 block discarded – undo
678 677
  * @uses translitteration()
679 678
  */
680 679
 function ancre_url(string $url, ?string $ancre = ''): string {
681
-	$ancre ??= '';
682
-	// lever l'#ancre
683
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
684
-		$url = $r[1];
685
-	}
686
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
687
-		if (!function_exists('translitteration')) {
688
-			include_spip('inc/charsets');
689
-		}
690
-		$ancre = preg_replace(
691
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
692
-			['', '-'],
693
-			translitteration($ancre)
694
-		);
695
-	}
696
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
680
+    $ancre ??= '';
681
+    // lever l'#ancre
682
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
683
+        $url = $r[1];
684
+    }
685
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
686
+        if (!function_exists('translitteration')) {
687
+            include_spip('inc/charsets');
688
+        }
689
+        $ancre = preg_replace(
690
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
691
+            ['', '-'],
692
+            translitteration($ancre)
693
+        );
694
+    }
695
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
697 696
 }
698 697
 
699 698
 /**
@@ -703,16 +702,16 @@  discard block
 block discarded – undo
703 702
  * @return string
704 703
  */
705 704
 function nettoyer_uri($reset = null) {
706
-	static $done = false;
707
-	static $propre = '';
708
-	if (!is_null($reset)) {
709
-		return $propre = $reset;
710
-	}
711
-	if ($done) {
712
-		return $propre;
713
-	}
714
-	$done = true;
715
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
705
+    static $done = false;
706
+    static $propre = '';
707
+    if (!is_null($reset)) {
708
+        return $propre = $reset;
709
+    }
710
+    if ($done) {
711
+        return $propre;
712
+    }
713
+    $done = true;
714
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
716 715
 }
717 716
 
718 717
 /**
@@ -724,16 +723,16 @@  discard block
 block discarded – undo
724 723
  * @return string
725 724
  */
726 725
 function nettoyer_uri_var($request_uri) {
727
-	$uri1 = $request_uri;
728
-	do {
729
-		$uri = $uri1;
730
-		$uri1 = preg_replace(
731
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
732
-			'\1',
733
-			$uri
734
-		);
735
-	} while ($uri <> $uri1);
736
-	return preg_replace(',[?&]$,', '', $uri1);
726
+    $uri1 = $request_uri;
727
+    do {
728
+        $uri = $uri1;
729
+        $uri1 = preg_replace(
730
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
731
+            '\1',
732
+            $uri
733
+        );
734
+    } while ($uri <> $uri1);
735
+    return preg_replace(',[?&]$,', '', $uri1);
737 736
 }
738 737
 
739 738
 
@@ -747,48 +746,48 @@  discard block
 block discarded – undo
747 746
  *    URL vers soi-même
748 747
  **/
749 748
 function self($amp = '&amp;', $root = false) {
750
-	$url = nettoyer_uri();
751
-	if (
752
-		!$root
753
-		and (
754
-			// si pas de profondeur on peut tronquer
755
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
756
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
757
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
758
-	) {
759
-		$url = preg_replace(',^[^?]*/,', '', $url);
760
-	}
761
-	// ajouter le cas echeant les variables _POST['id_...']
762
-	foreach ($_POST as $v => $c) {
763
-		if (substr($v, 0, 3) == 'id_') {
764
-			$url = parametre_url($url, $v, $c, '&');
765
-		}
766
-	}
767
-
768
-	// supprimer les variables sans interet
769
-	if (test_espace_prive()) {
770
-		$url = preg_replace(',([?&])('
771
-			. 'lang|show_docs|'
772
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
773
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
774
-		$url = preg_replace(',[&]$,', '\1', $url);
775
-	}
776
-
777
-	// eviter les hacks
778
-	include_spip('inc/filtres_mini');
779
-	$url = spip_htmlspecialchars($url);
780
-
781
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
782
-
783
-	// &amp; ?
784
-	if ($amp != '&amp;') {
785
-		$url = str_replace('&amp;', $amp, $url);
786
-	}
787
-
788
-	// Si ca demarre par ? ou vide, donner './'
789
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
790
-
791
-	return $url;
749
+    $url = nettoyer_uri();
750
+    if (
751
+        !$root
752
+        and (
753
+            // si pas de profondeur on peut tronquer
754
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
755
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
756
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
757
+    ) {
758
+        $url = preg_replace(',^[^?]*/,', '', $url);
759
+    }
760
+    // ajouter le cas echeant les variables _POST['id_...']
761
+    foreach ($_POST as $v => $c) {
762
+        if (substr($v, 0, 3) == 'id_') {
763
+            $url = parametre_url($url, $v, $c, '&');
764
+        }
765
+    }
766
+
767
+    // supprimer les variables sans interet
768
+    if (test_espace_prive()) {
769
+        $url = preg_replace(',([?&])('
770
+            . 'lang|show_docs|'
771
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
772
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
773
+        $url = preg_replace(',[&]$,', '\1', $url);
774
+    }
775
+
776
+    // eviter les hacks
777
+    include_spip('inc/filtres_mini');
778
+    $url = spip_htmlspecialchars($url);
779
+
780
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
781
+
782
+    // &amp; ?
783
+    if ($amp != '&amp;') {
784
+        $url = str_replace('&amp;', $amp, $url);
785
+    }
786
+
787
+    // Si ca demarre par ? ou vide, donner './'
788
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
789
+
790
+    return $url;
792 791
 }
793 792
 
794 793
 
@@ -799,7 +798,7 @@  discard block
 block discarded – undo
799 798
  *     true si c'est le cas, false sinon.
800 799
  */
801 800
 function test_espace_prive() {
802
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
801
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
803 802
 }
804 803
 
805 804
 /**
@@ -809,7 +808,7 @@  discard block
 block discarded – undo
809 808
  * @return bool
810 809
  */
811 810
 function test_plugin_actif($plugin) {
812
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
811
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
813 812
 }
814 813
 
815 814
 /**
@@ -840,52 +839,52 @@  discard block
 block discarded – undo
840 839
  *     texte
841 840
  */
842 841
 function _T($texte, $args = [], $options = []) {
843
-	static $traduire = false;
844
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
845
-	if ($options) {
846
-		// support de l'ancien argument $class
847
-		if (is_string($options)) {
848
-			$options = ['class' => $options];
849
-		}
850
-		$o = array_merge($o, $options);
851
-	}
852
-
853
-	if (!$traduire) {
854
-		$traduire = charger_fonction('traduire', 'inc');
855
-		include_spip('inc/lang');
856
-	}
857
-
858
-	// On peut passer explicitement la langue dans le tableau
859
-	// On utilise le même nom de variable que la globale
860
-	if (isset($args['spip_lang'])) {
861
-		$lang = $args['spip_lang'];
862
-		// On l'enleve pour ne pas le passer au remplacement
863
-		unset($args['spip_lang']);
864
-	} // Sinon on prend la langue du contexte
865
-	else {
866
-		$lang = $GLOBALS['spip_lang'];
867
-	}
868
-	$text = $traduire($texte, $lang);
869
-
870
-	if ($text === null || !strlen($text)) {
871
-		if (!$o['force']) {
872
-			return '';
873
-		}
874
-
875
-		$text = $texte;
876
-
877
-		// pour les chaines non traduites, assurer un service minimum
878
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
879
-			$n = strpos($text, ':');
880
-			if ($n !== false) {
881
-				$text = substr($text, $n + 1);
882
-			}
883
-			$text = str_replace('_', ' ', $text);
884
-		}
885
-		$o['class'] = null;
886
-	}
887
-
888
-	return _L($text, $args, $o);
842
+    static $traduire = false;
843
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
844
+    if ($options) {
845
+        // support de l'ancien argument $class
846
+        if (is_string($options)) {
847
+            $options = ['class' => $options];
848
+        }
849
+        $o = array_merge($o, $options);
850
+    }
851
+
852
+    if (!$traduire) {
853
+        $traduire = charger_fonction('traduire', 'inc');
854
+        include_spip('inc/lang');
855
+    }
856
+
857
+    // On peut passer explicitement la langue dans le tableau
858
+    // On utilise le même nom de variable que la globale
859
+    if (isset($args['spip_lang'])) {
860
+        $lang = $args['spip_lang'];
861
+        // On l'enleve pour ne pas le passer au remplacement
862
+        unset($args['spip_lang']);
863
+    } // Sinon on prend la langue du contexte
864
+    else {
865
+        $lang = $GLOBALS['spip_lang'];
866
+    }
867
+    $text = $traduire($texte, $lang);
868
+
869
+    if ($text === null || !strlen($text)) {
870
+        if (!$o['force']) {
871
+            return '';
872
+        }
873
+
874
+        $text = $texte;
875
+
876
+        // pour les chaines non traduites, assurer un service minimum
877
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
878
+            $n = strpos($text, ':');
879
+            if ($n !== false) {
880
+                $text = substr($text, $n + 1);
881
+            }
882
+            $text = str_replace('_', ' ', $text);
883
+        }
884
+        $o['class'] = null;
885
+    }
886
+
887
+    return _L($text, $args, $o);
889 888
 }
890 889
 
891 890
 
@@ -912,53 +911,53 @@  discard block
 block discarded – undo
912 911
  *     texte
913 912
  */
914 913
 function _L($text, $args = [], $options = []) {
915
-	$f = $text;
916
-	$defaut_options = [
917
-		'class' => null,
918
-		'sanitize' => true,
919
-	];
920
-	// support de l'ancien argument $class
921
-	if ($options and is_string($options)) {
922
-		$options = ['class' => $options];
923
-	}
924
-	if (is_array($options)) {
925
-		$options += $defaut_options;
926
-	} else {
927
-		$options = $defaut_options;
928
-	}
929
-
930
-	if (is_array($args) and count($args)) {
931
-		if (!function_exists('interdire_scripts')) {
932
-			include_spip('inc/texte');
933
-		}
934
-		if (!function_exists('echapper_html_suspect')) {
935
-			include_spip('inc/texte_mini');
936
-		}
937
-		foreach ($args as $name => $value) {
938
-			if (strpos($text, (string) "@$name@") !== false) {
939
-				if ($options['sanitize']) {
940
-					$value = echapper_html_suspect($value);
941
-					$value = interdire_scripts($value, -1);
942
-				}
943
-				if (!empty($options['class'])) {
944
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
945
-				}
946
-				$text = str_replace("@$name@", $value, $text);
947
-				unset($args[$name]);
948
-			}
949
-		}
950
-		// Si des variables n'ont pas ete inserees, le signaler
951
-		// (chaines de langues pas a jour)
952
-		if ($args) {
953
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
954
-		}
955
-	}
956
-
957
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
958
-		return "<span class='debug-traduction-erreur'>$text</span>";
959
-	} else {
960
-		return $text;
961
-	}
914
+    $f = $text;
915
+    $defaut_options = [
916
+        'class' => null,
917
+        'sanitize' => true,
918
+    ];
919
+    // support de l'ancien argument $class
920
+    if ($options and is_string($options)) {
921
+        $options = ['class' => $options];
922
+    }
923
+    if (is_array($options)) {
924
+        $options += $defaut_options;
925
+    } else {
926
+        $options = $defaut_options;
927
+    }
928
+
929
+    if (is_array($args) and count($args)) {
930
+        if (!function_exists('interdire_scripts')) {
931
+            include_spip('inc/texte');
932
+        }
933
+        if (!function_exists('echapper_html_suspect')) {
934
+            include_spip('inc/texte_mini');
935
+        }
936
+        foreach ($args as $name => $value) {
937
+            if (strpos($text, (string) "@$name@") !== false) {
938
+                if ($options['sanitize']) {
939
+                    $value = echapper_html_suspect($value);
940
+                    $value = interdire_scripts($value, -1);
941
+                }
942
+                if (!empty($options['class'])) {
943
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
944
+                }
945
+                $text = str_replace("@$name@", $value, $text);
946
+                unset($args[$name]);
947
+            }
948
+        }
949
+        // Si des variables n'ont pas ete inserees, le signaler
950
+        // (chaines de langues pas a jour)
951
+        if ($args) {
952
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
953
+        }
954
+    }
955
+
956
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
957
+        return "<span class='debug-traduction-erreur'>$text</span>";
958
+    } else {
959
+        return $text;
960
+    }
962 961
 }
963 962
 
964 963
 
@@ -972,13 +971,13 @@  discard block
 block discarded – undo
972 971
  * @return string
973 972
  */
974 973
 function joli_repertoire($rep) {
975
-	$a = substr($rep, 0, 1);
976
-	if ($a <> '.' and $a <> '/') {
977
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
978
-	}
979
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
974
+    $a = substr($rep, 0, 1);
975
+    if ($a <> '.' and $a <> '/') {
976
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
977
+    }
978
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
980 979
 
981
-	return $rep;
980
+    return $rep;
982 981
 }
983 982
 
984 983
 
@@ -1003,54 +1002,54 @@  discard block
 block discarded – undo
1003 1002
  * @return float|int|string|void
1004 1003
  */
1005 1004
 function spip_timer($t = 'rien', $raw = false) {
1006
-	static $time;
1007
-	$a = time();
1008
-	$b = microtime();
1009
-	// microtime peut contenir les microsecondes et le temps
1010
-	$b = explode(' ', $b);
1011
-	if (count($b) == 2) {
1012
-		$a = end($b);
1013
-	} // plus precis !
1014
-	$b = reset($b);
1015
-	if (!isset($time[$t])) {
1016
-		$time[$t] = $a + $b;
1017
-	} else {
1018
-		$p = ($a + $b - $time[$t]) * 1000;
1019
-		unset($time[$t]);
1005
+    static $time;
1006
+    $a = time();
1007
+    $b = microtime();
1008
+    // microtime peut contenir les microsecondes et le temps
1009
+    $b = explode(' ', $b);
1010
+    if (count($b) == 2) {
1011
+        $a = end($b);
1012
+    } // plus precis !
1013
+    $b = reset($b);
1014
+    if (!isset($time[$t])) {
1015
+        $time[$t] = $a + $b;
1016
+    } else {
1017
+        $p = ($a + $b - $time[$t]) * 1000;
1018
+        unset($time[$t]);
1020 1019
 #			echo "'$p'";exit;
1021
-		if ($raw) {
1022
-			return $p;
1023
-		}
1024
-		if ($p < 1000) {
1025
-			$s = '';
1026
-		} else {
1027
-			$s = sprintf('%d ', $x = floor($p / 1000));
1028
-			$p -= ($x * 1000);
1029
-		}
1020
+        if ($raw) {
1021
+            return $p;
1022
+        }
1023
+        if ($p < 1000) {
1024
+            $s = '';
1025
+        } else {
1026
+            $s = sprintf('%d ', $x = floor($p / 1000));
1027
+            $p -= ($x * 1000);
1028
+        }
1030 1029
 
1031
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1032
-	}
1030
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1031
+    }
1033 1032
 }
1034 1033
 
1035 1034
 
1036 1035
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1037 1036
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1038 1037
 function spip_touch($fichier, $duree = 0, $touch = true) {
1039
-	if ($duree) {
1040
-		clearstatcache();
1041
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1042
-			return false;
1043
-		}
1044
-	}
1045
-	if ($touch !== false) {
1046
-		if (!@touch($fichier)) {
1047
-			spip_unlink($fichier);
1048
-			@touch($fichier);
1049
-		};
1050
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1051
-	}
1038
+    if ($duree) {
1039
+        clearstatcache();
1040
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1041
+            return false;
1042
+        }
1043
+    }
1044
+    if ($touch !== false) {
1045
+        if (!@touch($fichier)) {
1046
+            spip_unlink($fichier);
1047
+            @touch($fichier);
1048
+        };
1049
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1050
+    }
1052 1051
 
1053
-	return true;
1052
+    return true;
1054 1053
 }
1055 1054
 
1056 1055
 
@@ -1061,11 +1060,11 @@  discard block
 block discarded – undo
1061 1060
  * @uses cron()
1062 1061
  **/
1063 1062
 function action_cron() {
1064
-	include_spip('inc/headers');
1065
-	http_response_code(204); // No Content
1066
-	header('Connection: close');
1067
-	define('_DIRECT_CRON_FORCE', true);
1068
-	cron();
1063
+    include_spip('inc/headers');
1064
+    http_response_code(204); // No Content
1065
+    header('Connection: close');
1066
+    define('_DIRECT_CRON_FORCE', true);
1067
+    cron();
1069 1068
 }
1070 1069
 
1071 1070
 /**
@@ -1081,26 +1080,26 @@  discard block
 block discarded – undo
1081 1080
  *     True si la tache a pu être effectuée
1082 1081
  */
1083 1082
 function cron($taches = [], $taches_old = []) {
1084
-	// si pas en mode cron force, laisser tomber.
1085
-	if (!defined('_DIRECT_CRON_FORCE')) {
1086
-		return false;
1087
-	}
1088
-	if (!is_array($taches)) {
1089
-		$taches = $taches_old;
1090
-	} // compat anciens appels
1091
-	// si taches a inserer en base et base inaccessible, laisser tomber
1092
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1093
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1094
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1095
-	if ($taches and count($taches) and !spip_connect()) {
1096
-		return false;
1097
-	}
1098
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1099
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1100
-		return $genie($taches);
1101
-	}
1102
-
1103
-	return false;
1083
+    // si pas en mode cron force, laisser tomber.
1084
+    if (!defined('_DIRECT_CRON_FORCE')) {
1085
+        return false;
1086
+    }
1087
+    if (!is_array($taches)) {
1088
+        $taches = $taches_old;
1089
+    } // compat anciens appels
1090
+    // si taches a inserer en base et base inaccessible, laisser tomber
1091
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1092
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1093
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1094
+    if ($taches and count($taches) and !spip_connect()) {
1095
+        return false;
1096
+    }
1097
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1098
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1099
+        return $genie($taches);
1100
+    }
1101
+
1102
+    return false;
1104 1103
 }
1105 1104
 
1106 1105
 /**
@@ -1132,17 +1131,17 @@  discard block
 block discarded – undo
1132 1131
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1133 1132
  */
1134 1133
 function job_queue_add(
1135
-	$function,
1136
-	$description,
1137
-	$arguments = [],
1138
-	$file = '',
1139
-	$no_duplicate = false,
1140
-	$time = 0,
1141
-	$priority = 0
1134
+    $function,
1135
+    $description,
1136
+    $arguments = [],
1137
+    $file = '',
1138
+    $no_duplicate = false,
1139
+    $time = 0,
1140
+    $priority = 0
1142 1141
 ) {
1143
-	include_spip('inc/queue');
1142
+    include_spip('inc/queue');
1144 1143
 
1145
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1144
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1146 1145
 }
1147 1146
 
1148 1147
 /**
@@ -1153,9 +1152,9 @@  discard block
 block discarded – undo
1153 1152
  * @return bool
1154 1153
  */
1155 1154
 function job_queue_remove($id_job) {
1156
-	include_spip('inc/queue');
1155
+    include_spip('inc/queue');
1157 1156
 
1158
-	return queue_remove_job($id_job);
1157
+    return queue_remove_job($id_job);
1159 1158
 }
1160 1159
 
1161 1160
 /**
@@ -1168,9 +1167,9 @@  discard block
 block discarded – undo
1168 1167
  *     or an array of simple array to link multiples objet in one time
1169 1168
  */
1170 1169
 function job_queue_link($id_job, $objets) {
1171
-	include_spip('inc/queue');
1170
+    include_spip('inc/queue');
1172 1171
 
1173
-	return queue_link_job($id_job, $objets);
1172
+    return queue_link_job($id_job, $objets);
1174 1173
 }
1175 1174
 
1176 1175
 
@@ -1190,36 +1189,36 @@  discard block
 block discarded – undo
1190 1189
  *  - `null` si la queue n'est pas encore initialisée
1191 1190
  */
1192 1191
 function queue_sleep_time_to_next_job($force = null) {
1193
-	static $queue_next_job_time = -1;
1194
-	if ($force === true) {
1195
-		$queue_next_job_time = -1;
1196
-	} elseif ($force) {
1197
-		$queue_next_job_time = $force;
1198
-	}
1199
-
1200
-	if ($queue_next_job_time == -1) {
1201
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1202
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1203
-		}
1204
-		// utiliser un cache memoire si dispo
1205
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1206
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1207
-		} else {
1208
-			$queue_next_job_time = null;
1209
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1210
-				$queue_next_job_time = intval($contenu);
1211
-			}
1212
-		}
1213
-	}
1214
-
1215
-	if (is_null($queue_next_job_time)) {
1216
-		return null;
1217
-	}
1218
-	if (!$_SERVER['REQUEST_TIME']) {
1219
-		$_SERVER['REQUEST_TIME'] = time();
1220
-	}
1221
-
1222
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1192
+    static $queue_next_job_time = -1;
1193
+    if ($force === true) {
1194
+        $queue_next_job_time = -1;
1195
+    } elseif ($force) {
1196
+        $queue_next_job_time = $force;
1197
+    }
1198
+
1199
+    if ($queue_next_job_time == -1) {
1200
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1201
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1202
+        }
1203
+        // utiliser un cache memoire si dispo
1204
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1205
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1206
+        } else {
1207
+            $queue_next_job_time = null;
1208
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1209
+                $queue_next_job_time = intval($contenu);
1210
+            }
1211
+        }
1212
+    }
1213
+
1214
+    if (is_null($queue_next_job_time)) {
1215
+        return null;
1216
+    }
1217
+    if (!$_SERVER['REQUEST_TIME']) {
1218
+        $_SERVER['REQUEST_TIME'] = time();
1219
+    }
1220
+
1221
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1223 1222
 }
1224 1223
 
1225 1224
 
@@ -1231,11 +1230,11 @@  discard block
 block discarded – undo
1231 1230
  * @return string
1232 1231
  */
1233 1232
 function quote_amp($u) {
1234
-	return preg_replace(
1235
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1236
-		'&amp;',
1237
-		$u
1238
-	);
1233
+    return preg_replace(
1234
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1235
+        '&amp;',
1236
+        $u
1237
+    );
1239 1238
 }
1240 1239
 
1241 1240
 
@@ -1258,27 +1257,27 @@  discard block
 block discarded – undo
1258 1257
  *     Balise HTML `<script>` et son contenu
1259 1258
  **/
1260 1259
 function http_script($script, $src = '', $noscript = '') {
1261
-	static $done = [];
1260
+    static $done = [];
1262 1261
 
1263
-	if ($src && !isset($done[$src])) {
1264
-		$done[$src] = true;
1265
-		$src = find_in_path($src, _JAVASCRIPT);
1266
-		$src = " src='$src'";
1267
-	} else {
1268
-		$src = '';
1269
-	}
1270
-	if ($script) {
1271
-		$script = ("/*<![CDATA[*/\n" .
1272
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1273
-			'/*]]>*/');
1274
-	}
1275
-	if ($noscript) {
1276
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1277
-	}
1262
+    if ($src && !isset($done[$src])) {
1263
+        $done[$src] = true;
1264
+        $src = find_in_path($src, _JAVASCRIPT);
1265
+        $src = " src='$src'";
1266
+    } else {
1267
+        $src = '';
1268
+    }
1269
+    if ($script) {
1270
+        $script = ("/*<![CDATA[*/\n" .
1271
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1272
+            '/*]]>*/');
1273
+    }
1274
+    if ($noscript) {
1275
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1276
+    }
1278 1277
 
1279
-	return ($src or $script or $noscript)
1280
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1281
-		: '';
1278
+    return ($src or $script or $noscript)
1279
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1280
+        : '';
1282 1281
 }
1283 1282
 
1284 1283
 
@@ -1313,7 +1312,7 @@  discard block
 block discarded – undo
1313 1312
  *     texte échappé
1314 1313
  **/
1315 1314
 function texte_script(string $texte): string {
1316
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1315
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1317 1316
 }
1318 1317
 
1319 1318
 
@@ -1350,68 +1349,68 @@  discard block
 block discarded – undo
1350 1349
  *     Liste des chemins, par ordre de priorité.
1351 1350
  **/
1352 1351
 function _chemin($dir_path = null) {
1353
-	static $path_base = null;
1354
-	static $path_full = null;
1355
-	if ($path_base == null) {
1356
-		// Chemin standard depuis l'espace public
1357
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1358
-			_DIR_RACINE . ':' .
1359
-			_DIR_RACINE . 'squelettes-dist/:' .
1360
-			_DIR_RACINE . 'prive/:' .
1361
-			_DIR_RESTREINT;
1362
-		// Ajouter squelettes/
1363
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1364
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1365
-		}
1366
-		foreach (explode(':', $path) as $dir) {
1367
-			if (strlen($dir) and substr($dir, -1) != '/') {
1368
-				$dir .= '/';
1369
-			}
1370
-			$path_base[] = $dir;
1371
-		}
1372
-		$path_full = $path_base;
1373
-		// Et le(s) dossier(s) des squelettes nommes
1374
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1375
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1376
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1377
-			}
1378
-		}
1379
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1380
-	}
1381
-	if ($dir_path === null) {
1382
-		return $path_full;
1383
-	}
1384
-
1385
-	if (is_array($dir_path) or strlen($dir_path)) {
1386
-		$tete = '';
1387
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1388
-			$tete = array_shift($path_base);
1389
-		}
1390
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1391
-		$dirs = array_reverse($dirs);
1392
-		foreach ($dirs as $dir_path) {
1393
-			if (substr($dir_path, -1) != '/') {
1394
-				$dir_path .= '/';
1395
-			}
1396
-			if (!in_array($dir_path, $path_base)) {
1397
-				array_unshift($path_base, $dir_path);
1398
-			}
1399
-		}
1400
-		if (strlen($tete)) {
1401
-			array_unshift($path_base, $tete);
1402
-		}
1403
-	}
1404
-	$path_full = $path_base;
1405
-	// Et le(s) dossier(s) des squelettes nommes
1406
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1407
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1408
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1409
-		}
1410
-	}
1411
-
1412
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1413
-
1414
-	return $path_full;
1352
+    static $path_base = null;
1353
+    static $path_full = null;
1354
+    if ($path_base == null) {
1355
+        // Chemin standard depuis l'espace public
1356
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1357
+            _DIR_RACINE . ':' .
1358
+            _DIR_RACINE . 'squelettes-dist/:' .
1359
+            _DIR_RACINE . 'prive/:' .
1360
+            _DIR_RESTREINT;
1361
+        // Ajouter squelettes/
1362
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1363
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1364
+        }
1365
+        foreach (explode(':', $path) as $dir) {
1366
+            if (strlen($dir) and substr($dir, -1) != '/') {
1367
+                $dir .= '/';
1368
+            }
1369
+            $path_base[] = $dir;
1370
+        }
1371
+        $path_full = $path_base;
1372
+        // Et le(s) dossier(s) des squelettes nommes
1373
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1374
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1375
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1376
+            }
1377
+        }
1378
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1379
+    }
1380
+    if ($dir_path === null) {
1381
+        return $path_full;
1382
+    }
1383
+
1384
+    if (is_array($dir_path) or strlen($dir_path)) {
1385
+        $tete = '';
1386
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1387
+            $tete = array_shift($path_base);
1388
+        }
1389
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1390
+        $dirs = array_reverse($dirs);
1391
+        foreach ($dirs as $dir_path) {
1392
+            if (substr($dir_path, -1) != '/') {
1393
+                $dir_path .= '/';
1394
+            }
1395
+            if (!in_array($dir_path, $path_base)) {
1396
+                array_unshift($path_base, $dir_path);
1397
+            }
1398
+        }
1399
+        if (strlen($tete)) {
1400
+            array_unshift($path_base, $tete);
1401
+        }
1402
+    }
1403
+    $path_full = $path_base;
1404
+    // Et le(s) dossier(s) des squelettes nommes
1405
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1406
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1407
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1408
+        }
1409
+    }
1410
+
1411
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1412
+
1413
+    return $path_full;
1415 1414
 }
1416 1415
 
1417 1416
 /**
@@ -1424,17 +1423,17 @@  discard block
 block discarded – undo
1424 1423
  * @return array Liste de chemins
1425 1424
  **/
1426 1425
 function creer_chemin() {
1427
-	$path_a = _chemin();
1428
-	static $c = '';
1426
+    $path_a = _chemin();
1427
+    static $c = '';
1429 1428
 
1430
-	// on calcule le chemin si le dossier skel a change
1431
-	if ($c != $GLOBALS['dossier_squelettes']) {
1432
-		// assurer le non plantage lors de la montee de version :
1433
-		$c = $GLOBALS['dossier_squelettes'];
1434
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1435
-	}
1429
+    // on calcule le chemin si le dossier skel a change
1430
+    if ($c != $GLOBALS['dossier_squelettes']) {
1431
+        // assurer le non plantage lors de la montee de version :
1432
+        $c = $GLOBALS['dossier_squelettes'];
1433
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1434
+    }
1436 1435
 
1437
-	return $path_a;
1436
+    return $path_a;
1438 1437
 }
1439 1438
 
1440 1439
 
@@ -1446,61 +1445,61 @@  discard block
 block discarded – undo
1446 1445
  * @return string[] Nom des thèmes.
1447 1446
  */
1448 1447
 function lister_themes_prives(): array {
1449
-	static $themes = null;
1450
-	if (is_null($themes)) {
1451
-		// si pas encore definie
1452
-		if (!defined('_SPIP_THEME_PRIVE')) {
1453
-			define('_SPIP_THEME_PRIVE', 'spip');
1454
-		}
1455
-		$themes = [_SPIP_THEME_PRIVE];
1456
-		// Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1457
-		// FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1458
-		$prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1459
-		if (is_string($prefs) and (stripos($prefs, 'a:') === 0)) {
1460
-			$prefs = unserialize($prefs);
1461
-		} else {
1462
-			$prefs = [];
1463
-		}
1464
-
1465
-		$theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1466
-		if ($theme and $theme !== _SPIP_THEME_PRIVE) {
1467
-			// placer le theme choisi en tete
1468
-			array_unshift($themes, $theme);
1469
-		}
1470
-	}
1471
-
1472
-	return $themes;
1448
+    static $themes = null;
1449
+    if (is_null($themes)) {
1450
+        // si pas encore definie
1451
+        if (!defined('_SPIP_THEME_PRIVE')) {
1452
+            define('_SPIP_THEME_PRIVE', 'spip');
1453
+        }
1454
+        $themes = [_SPIP_THEME_PRIVE];
1455
+        // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1456
+        // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1457
+        $prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1458
+        if (is_string($prefs) and (stripos($prefs, 'a:') === 0)) {
1459
+            $prefs = unserialize($prefs);
1460
+        } else {
1461
+            $prefs = [];
1462
+        }
1463
+
1464
+        $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1465
+        if ($theme and $theme !== _SPIP_THEME_PRIVE) {
1466
+            // placer le theme choisi en tete
1467
+            array_unshift($themes, $theme);
1468
+        }
1469
+    }
1470
+
1471
+    return $themes;
1473 1472
 }
1474 1473
 
1475 1474
 function find_in_theme($file, $subdir = '', $include = false) {
1476
-	static $themefiles = [];
1477
-	if (isset($themefiles["$subdir$file"])) {
1478
-		return $themefiles["$subdir$file"];
1479
-	}
1480
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1481
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1482
-	if (
1483
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1484
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1485
-		and $f = find_in_theme("$file_svg_generique")
1486
-	) {
1487
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1488
-			return $themefiles["$subdir$file"] = $fsize;
1489
-		}
1490
-		else {
1491
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1492
-		}
1493
-	}
1494
-
1495
-	$themes = lister_themes_prives();
1496
-	foreach ($themes as $theme) {
1497
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1498
-			return $themefiles["$subdir$file"] = $f;
1499
-		}
1500
-	}
1501
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1502
-
1503
-	return $themefiles["$subdir$file"] = '';
1475
+    static $themefiles = [];
1476
+    if (isset($themefiles["$subdir$file"])) {
1477
+        return $themefiles["$subdir$file"];
1478
+    }
1479
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1480
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1481
+    if (
1482
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1483
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1484
+        and $f = find_in_theme("$file_svg_generique")
1485
+    ) {
1486
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1487
+            return $themefiles["$subdir$file"] = $fsize;
1488
+        }
1489
+        else {
1490
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1491
+        }
1492
+    }
1493
+
1494
+    $themes = lister_themes_prives();
1495
+    foreach ($themes as $theme) {
1496
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1497
+            return $themefiles["$subdir$file"] = $f;
1498
+        }
1499
+    }
1500
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1501
+
1502
+    return $themefiles["$subdir$file"] = '';
1504 1503
 }
1505 1504
 
1506 1505
 
@@ -1524,31 +1523,31 @@  discard block
 block discarded – undo
1524 1523
  *     sinon chaîne vide.
1525 1524
  **/
1526 1525
 function chemin_image($icone) {
1527
-	static $icone_renommer;
1528
-	if ($p = strpos($icone, '?')) {
1529
-		$icone = substr($icone, 0, $p);
1530
-	}
1531
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1532
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1533
-		return $icone;
1534
-	}
1535
-
1536
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1537
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1538
-		return $f;
1539
-	}
1540
-	// sinon passer par le module de renommage
1541
-	if (is_null($icone_renommer)) {
1542
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1543
-	}
1544
-	if ($icone_renommer) {
1545
-		[$icone, $fonction] = $icone_renommer($icone, '');
1546
-		if (file_exists($icone)) {
1547
-			return $icone;
1548
-		}
1549
-	}
1550
-
1551
-	return find_in_path($icone, _NOM_IMG_PACK);
1526
+    static $icone_renommer;
1527
+    if ($p = strpos($icone, '?')) {
1528
+        $icone = substr($icone, 0, $p);
1529
+    }
1530
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1531
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1532
+        return $icone;
1533
+    }
1534
+
1535
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1536
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1537
+        return $f;
1538
+    }
1539
+    // sinon passer par le module de renommage
1540
+    if (is_null($icone_renommer)) {
1541
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1542
+    }
1543
+    if ($icone_renommer) {
1544
+        [$icone, $fonction] = $icone_renommer($icone, '');
1545
+        if (file_exists($icone)) {
1546
+            return $icone;
1547
+        }
1548
+    }
1549
+
1550
+    return find_in_path($icone, _NOM_IMG_PACK);
1552 1551
 }
1553 1552
 
1554 1553
 //
@@ -1586,128 +1585,128 @@  discard block
 block discarded – undo
1586 1585
  *     - false : fichier introuvable
1587 1586
  **/
1588 1587
 function find_in_path($file, $dirname = '', $include = false) {
1589
-	static $dirs = [];
1590
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1591
-	static $c = '';
1592
-
1593
-	if (!$file and !strlen($file)) {
1594
-		return false;
1595
-	}
1596
-
1597
-	// on calcule le chemin si le dossier skel a change
1598
-	if ($c != $GLOBALS['dossier_squelettes']) {
1599
-		// assurer le non plantage lors de la montee de version :
1600
-		$c = $GLOBALS['dossier_squelettes'];
1601
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1602
-	}
1603
-
1604
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1605
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1606
-			return false;
1607
-		}
1608
-		if ($include and !isset($inc[$dirname][$file])) {
1609
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1610
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1611
-		}
1612
-
1613
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1614
-	}
1615
-
1616
-	$a = strrpos($file, '/');
1617
-	if ($a !== false) {
1618
-		$dirname .= substr($file, 0, ++$a);
1619
-		$file = substr($file, $a);
1620
-	}
1621
-
1622
-	foreach (creer_chemin() as $dir) {
1623
-		if (!isset($dirs[$a = $dir . $dirname])) {
1624
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1625
-		}
1626
-		if ($dirs[$a]) {
1627
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1628
-				if ($include and !isset($inc[$dirname][$file])) {
1629
-					include_once _ROOT_CWD . $a;
1630
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1631
-				}
1632
-				if (!defined('_SAUVER_CHEMIN')) {
1633
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1634
-					if (is_null($GLOBALS['path_files'])) {
1635
-						return $a;
1636
-					}
1637
-					define('_SAUVER_CHEMIN', true);
1638
-				}
1639
-
1640
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1641
-			}
1642
-		}
1643
-	}
1644
-
1645
-	if ($include) {
1646
-		spip_log("include_spip $dirname$file non trouve");
1647
-		if ($include === 'required') {
1648
-			echo '<pre>',
1649
-			'<strong>Erreur Fatale</strong><br />';
1650
-			if (function_exists('debug_print_backtrace')) {
1651
-				debug_print_backtrace();
1652
-			}
1653
-			echo '</pre>';
1654
-			die("Erreur interne: ne peut inclure $dirname$file");
1655
-		}
1656
-	}
1657
-
1658
-	if (!defined('_SAUVER_CHEMIN')) {
1659
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1660
-		if (is_null($GLOBALS['path_files'])) {
1661
-			return false;
1662
-		}
1663
-		define('_SAUVER_CHEMIN', true);
1664
-	}
1665
-
1666
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1588
+    static $dirs = [];
1589
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1590
+    static $c = '';
1591
+
1592
+    if (!$file and !strlen($file)) {
1593
+        return false;
1594
+    }
1595
+
1596
+    // on calcule le chemin si le dossier skel a change
1597
+    if ($c != $GLOBALS['dossier_squelettes']) {
1598
+        // assurer le non plantage lors de la montee de version :
1599
+        $c = $GLOBALS['dossier_squelettes'];
1600
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1601
+    }
1602
+
1603
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1604
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1605
+            return false;
1606
+        }
1607
+        if ($include and !isset($inc[$dirname][$file])) {
1608
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1609
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1610
+        }
1611
+
1612
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1613
+    }
1614
+
1615
+    $a = strrpos($file, '/');
1616
+    if ($a !== false) {
1617
+        $dirname .= substr($file, 0, ++$a);
1618
+        $file = substr($file, $a);
1619
+    }
1620
+
1621
+    foreach (creer_chemin() as $dir) {
1622
+        if (!isset($dirs[$a = $dir . $dirname])) {
1623
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1624
+        }
1625
+        if ($dirs[$a]) {
1626
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1627
+                if ($include and !isset($inc[$dirname][$file])) {
1628
+                    include_once _ROOT_CWD . $a;
1629
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1630
+                }
1631
+                if (!defined('_SAUVER_CHEMIN')) {
1632
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1633
+                    if (is_null($GLOBALS['path_files'])) {
1634
+                        return $a;
1635
+                    }
1636
+                    define('_SAUVER_CHEMIN', true);
1637
+                }
1638
+
1639
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1640
+            }
1641
+        }
1642
+    }
1643
+
1644
+    if ($include) {
1645
+        spip_log("include_spip $dirname$file non trouve");
1646
+        if ($include === 'required') {
1647
+            echo '<pre>',
1648
+            '<strong>Erreur Fatale</strong><br />';
1649
+            if (function_exists('debug_print_backtrace')) {
1650
+                debug_print_backtrace();
1651
+            }
1652
+            echo '</pre>';
1653
+            die("Erreur interne: ne peut inclure $dirname$file");
1654
+        }
1655
+    }
1656
+
1657
+    if (!defined('_SAUVER_CHEMIN')) {
1658
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1659
+        if (is_null($GLOBALS['path_files'])) {
1660
+            return false;
1661
+        }
1662
+        define('_SAUVER_CHEMIN', true);
1663
+    }
1664
+
1665
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1667 1666
 }
1668 1667
 
1669 1668
 function clear_path_cache() {
1670
-	$GLOBALS['path_files'] = [];
1671
-	spip_unlink(_CACHE_CHEMIN);
1669
+    $GLOBALS['path_files'] = [];
1670
+    spip_unlink(_CACHE_CHEMIN);
1672 1671
 }
1673 1672
 
1674 1673
 function load_path_cache() {
1675
-	// charger le path des plugins
1676
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1677
-		include_once(_CACHE_PLUGINS_PATH);
1678
-	}
1679
-	$GLOBALS['path_files'] = [];
1680
-	// si le visiteur est admin,
1681
-	// on ne recharge pas le cache pour forcer sa mise a jour
1682
-	if (
1683
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1684
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1685
-		// utiliser le cookie est un pis aller qui marche 'en general'
1686
-		// on blinde par un second test au moment de la lecture de la session
1687
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1688
-		// et en ignorant ce cache en cas de recalcul explicite
1689
-		!_request('var_mode')
1690
-	) {
1691
-		// on essaye de lire directement sans verrou pour aller plus vite
1692
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1693
-			// mais si semble corrompu on relit avec un verrou
1694
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1695
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1696
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1697
-					$GLOBALS['path_files'] = [];
1698
-				}
1699
-			}
1700
-		}
1701
-	}
1674
+    // charger le path des plugins
1675
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1676
+        include_once(_CACHE_PLUGINS_PATH);
1677
+    }
1678
+    $GLOBALS['path_files'] = [];
1679
+    // si le visiteur est admin,
1680
+    // on ne recharge pas le cache pour forcer sa mise a jour
1681
+    if (
1682
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1683
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1684
+        // utiliser le cookie est un pis aller qui marche 'en general'
1685
+        // on blinde par un second test au moment de la lecture de la session
1686
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1687
+        // et en ignorant ce cache en cas de recalcul explicite
1688
+        !_request('var_mode')
1689
+    ) {
1690
+        // on essaye de lire directement sans verrou pour aller plus vite
1691
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1692
+            // mais si semble corrompu on relit avec un verrou
1693
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1694
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1695
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1696
+                    $GLOBALS['path_files'] = [];
1697
+                }
1698
+            }
1699
+        }
1700
+    }
1702 1701
 }
1703 1702
 
1704 1703
 function save_path_cache() {
1705
-	if (
1706
-		defined('_SAUVER_CHEMIN')
1707
-		and _SAUVER_CHEMIN
1708
-	) {
1709
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1710
-	}
1704
+    if (
1705
+        defined('_SAUVER_CHEMIN')
1706
+        and _SAUVER_CHEMIN
1707
+    ) {
1708
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1709
+    }
1711 1710
 }
1712 1711
 
1713 1712
 
@@ -1727,33 +1726,33 @@  discard block
 block discarded – undo
1727 1726
  * @return array
1728 1727
  */
1729 1728
 function find_all_in_path($dir, $pattern, $recurs = false) {
1730
-	$liste_fichiers = [];
1731
-	$maxfiles = 10000;
1732
-
1733
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1734
-	// on a pas encore inclus flock.php
1735
-	if (!function_exists('preg_files')) {
1736
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1737
-	}
1738
-
1739
-	// Parcourir le chemin
1740
-	foreach (creer_chemin() as $d) {
1741
-		$f = $d . $dir;
1742
-		if (@is_dir($f)) {
1743
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1744
-			foreach ($liste as $chemin) {
1745
-				$nom = basename($chemin);
1746
-				// ne prendre que les fichiers pas deja trouves
1747
-				// car find_in_path prend le premier qu'il trouve,
1748
-				// les autres sont donc masques
1749
-				if (!isset($liste_fichiers[$nom])) {
1750
-					$liste_fichiers[$nom] = $chemin;
1751
-				}
1752
-			}
1753
-		}
1754
-	}
1755
-
1756
-	return $liste_fichiers;
1729
+    $liste_fichiers = [];
1730
+    $maxfiles = 10000;
1731
+
1732
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1733
+    // on a pas encore inclus flock.php
1734
+    if (!function_exists('preg_files')) {
1735
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1736
+    }
1737
+
1738
+    // Parcourir le chemin
1739
+    foreach (creer_chemin() as $d) {
1740
+        $f = $d . $dir;
1741
+        if (@is_dir($f)) {
1742
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1743
+            foreach ($liste as $chemin) {
1744
+                $nom = basename($chemin);
1745
+                // ne prendre que les fichiers pas deja trouves
1746
+                // car find_in_path prend le premier qu'il trouve,
1747
+                // les autres sont donc masques
1748
+                if (!isset($liste_fichiers[$nom])) {
1749
+                    $liste_fichiers[$nom] = $chemin;
1750
+                }
1751
+            }
1752
+        }
1753
+    }
1754
+
1755
+    return $liste_fichiers;
1757 1756
 }
1758 1757
 
1759 1758
 /**
@@ -1765,17 +1764,17 @@  discard block
 block discarded – undo
1765 1764
  * @return bool
1766 1765
  */
1767 1766
 function autoriser_sans_cookie($nom, $strict = false) {
1768
-	static $autsanscookie = ['install', 'base_repair'];
1767
+    static $autsanscookie = ['install', 'base_repair'];
1769 1768
 
1770
-	if (in_array($nom, $autsanscookie)) {
1771
-		if (test_espace_prive()) {
1772
-			include_spip('base/connect_sql');
1773
-			if (!$strict or !spip_connect()) {
1774
-				return true;
1775
-			}
1776
-		}
1777
-	}
1778
-	return false;
1769
+    if (in_array($nom, $autsanscookie)) {
1770
+        if (test_espace_prive()) {
1771
+            include_spip('base/connect_sql');
1772
+            if (!$strict or !spip_connect()) {
1773
+                return true;
1774
+            }
1775
+        }
1776
+    }
1777
+    return false;
1779 1778
 }
1780 1779
 
1781 1780
 /**
@@ -1785,60 +1784,60 @@  discard block
 block discarded – undo
1785 1784
  * @return string
1786 1785
  */
1787 1786
 function charger_fonction_url(string $quoi, string $type = '') {
1788
-	if ($type === 'defaut') {
1789
-		$objet = objet_type($quoi);
1790
-		if (
1791
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1792
-			// deprecated
1793
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1794
-		) {
1795
-			return $f;
1796
-		}
1797
-		return '';
1798
-	}
1799
-
1800
-	$url_type = $type;
1801
-	if (!$url_type) {
1802
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1803
-	}
1804
-
1805
-	// inclure le module d'url
1806
-	include_spip('urls/' . $url_type);
1807
-
1808
-	switch ($quoi) {
1809
-		case 'page':
1810
-			if (
1811
-				 function_exists($f = "urls_{$url_type}_generer_url_page")
1812
-				or function_exists($f .= '_dist')
1813
-				// ou une fonction custom utilisateur independante du type d'url
1814
-				or function_exists($f = 'generer_url_page')
1815
-				or function_exists($f .= '_dist')
1816
-			) {
1817
-				return $f;
1818
-			}
1819
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1820
-			return '';
1821
-		case 'objet':
1822
-		case 'decoder':
1823
-		default:
1824
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1825
-			if (
1826
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1827
-				or function_exists($f .= '_dist')
1828
-			) {
1829
-				return $f;
1830
-			}
1831
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1832
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1833
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1834
-				return $f;
1835
-			}
1836
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1837
-			if (!$type and $url_type !== 'page') {
1838
-				return charger_fonction_url($quoi, 'page');
1839
-			}
1840
-			return '';
1841
-	}
1787
+    if ($type === 'defaut') {
1788
+        $objet = objet_type($quoi);
1789
+        if (
1790
+            $f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1791
+            // deprecated
1792
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1793
+        ) {
1794
+            return $f;
1795
+        }
1796
+        return '';
1797
+    }
1798
+
1799
+    $url_type = $type;
1800
+    if (!$url_type) {
1801
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1802
+    }
1803
+
1804
+    // inclure le module d'url
1805
+    include_spip('urls/' . $url_type);
1806
+
1807
+    switch ($quoi) {
1808
+        case 'page':
1809
+            if (
1810
+                    function_exists($f = "urls_{$url_type}_generer_url_page")
1811
+                or function_exists($f .= '_dist')
1812
+                // ou une fonction custom utilisateur independante du type d'url
1813
+                or function_exists($f = 'generer_url_page')
1814
+                or function_exists($f .= '_dist')
1815
+            ) {
1816
+                return $f;
1817
+            }
1818
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1819
+            return '';
1820
+        case 'objet':
1821
+        case 'decoder':
1822
+        default:
1823
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1824
+            if (
1825
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1826
+                or function_exists($f .= '_dist')
1827
+            ) {
1828
+                return $f;
1829
+            }
1830
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1831
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1832
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1833
+                return $f;
1834
+            }
1835
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1836
+            if (!$type and $url_type !== 'page') {
1837
+                return charger_fonction_url($quoi, 'page');
1838
+            }
1839
+            return '';
1840
+    }
1842 1841
 }
1843 1842
 
1844 1843
 
@@ -1864,48 +1863,48 @@  discard block
 block discarded – undo
1864 1863
  *   url codee ou fonction de decodage
1865 1864
  */
1866 1865
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1867
-	if ($public === null) {
1868
-		$public = !test_espace_prive();
1869
-	}
1870
-	$id = intval($id);
1871
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1872
-
1873
-	if (!$public) {
1874
-		if (!$entite) {
1875
-			return '';
1876
-		}
1877
-		if (!function_exists('generer_objet_url_ecrire')) {
1878
-			include_spip('inc/urls');
1879
-		}
1880
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1881
-	} else {
1882
-		$f = charger_fonction_url('objet', $type ?? '');
1883
-
1884
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1885
-		// @see charger_fonction_url
1886
-		if (!$entite) {
1887
-			return $f;
1888
-		}
1889
-
1890
-		// mais d'abord il faut tester le cas des urls sur une
1891
-		// base distante
1892
-		if (
1893
-			$connect
1894
-			and $g = charger_fonction('connect', 'urls', true)
1895
-		) {
1896
-			$f = $g;
1897
-		}
1898
-
1899
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1900
-	}
1901
-	if ($res) {
1902
-		return $res;
1903
-	}
1904
-
1905
-	// On a ete gentil mais la ....
1906
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1907
-
1908
-	return '';
1866
+    if ($public === null) {
1867
+        $public = !test_espace_prive();
1868
+    }
1869
+    $id = intval($id);
1870
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1871
+
1872
+    if (!$public) {
1873
+        if (!$entite) {
1874
+            return '';
1875
+        }
1876
+        if (!function_exists('generer_objet_url_ecrire')) {
1877
+            include_spip('inc/urls');
1878
+        }
1879
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1880
+    } else {
1881
+        $f = charger_fonction_url('objet', $type ?? '');
1882
+
1883
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1884
+        // @see charger_fonction_url
1885
+        if (!$entite) {
1886
+            return $f;
1887
+        }
1888
+
1889
+        // mais d'abord il faut tester le cas des urls sur une
1890
+        // base distante
1891
+        if (
1892
+            $connect
1893
+            and $g = charger_fonction('connect', 'urls', true)
1894
+        ) {
1895
+            $f = $g;
1896
+        }
1897
+
1898
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1899
+    }
1900
+    if ($res) {
1901
+        return $res;
1902
+    }
1903
+
1904
+    // On a ete gentil mais la ....
1905
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1906
+
1907
+    return '';
1909 1908
 }
1910 1909
 
1911 1910
 /**
@@ -1913,11 +1912,11 @@  discard block
 block discarded – undo
1913 1912
  * @see generer_objet_url
1914 1913
  */
1915 1914
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1916
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
1917
-	if ($public and is_string($public)) {
1918
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1919
-	}
1920
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1915
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
1916
+    if ($public and is_string($public)) {
1917
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1918
+    }
1919
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1921 1920
 }
1922 1921
 
1923 1922
 /**
@@ -1929,19 +1928,19 @@  discard block
 block discarded – undo
1929 1928
  * @return string
1930 1929
  */
1931 1930
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1932
-	$id = intval($id);
1933
-	$exec = objet_info($entite, 'url_edit');
1934
-	$url = generer_url_ecrire($exec, $args);
1935
-	if (intval($id)) {
1936
-		$url = parametre_url($url, id_table_objet($entite), $id);
1937
-	} else {
1938
-		$url = parametre_url($url, 'new', 'oui');
1939
-	}
1940
-	if ($ancre) {
1941
-		$url = ancre_url($url, $ancre);
1942
-	}
1931
+    $id = intval($id);
1932
+    $exec = objet_info($entite, 'url_edit');
1933
+    $url = generer_url_ecrire($exec, $args);
1934
+    if (intval($id)) {
1935
+        $url = parametre_url($url, id_table_objet($entite), $id);
1936
+    } else {
1937
+        $url = parametre_url($url, 'new', 'oui');
1938
+    }
1939
+    if ($ancre) {
1940
+        $url = ancre_url($url, $ancre);
1941
+    }
1943 1942
 
1944
-	return $url;
1943
+    return $url;
1945 1944
 }
1946 1945
 
1947 1946
 /**
@@ -1949,19 +1948,19 @@  discard block
 block discarded – undo
1949 1948
  * @see generer_objet_url_ecrire_edit
1950 1949
  */
1951 1950
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1952
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
1953
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1951
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
1952
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1954 1953
 }
1955 1954
 
1956 1955
 
1957 1956
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1958
-	include_spip('base/connect_sql');
1959
-	$id_type = id_table_objet($entite, $public);
1957
+    include_spip('base/connect_sql');
1958
+    $id_type = id_table_objet($entite, $public);
1960 1959
 
1961
-	return _DIR_RACINE . get_spip_script('./')
1962
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1963
-	. (!$args ? '' : "&$args")
1964
-	. (!$ancre ? '' : "#$ancre");
1960
+    return _DIR_RACINE . get_spip_script('./')
1961
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1962
+    . (!$args ? '' : "&$args")
1963
+    . (!$ancre ? '' : "#$ancre");
1965 1964
 }
1966 1965
 
1967 1966
 
@@ -1972,18 +1971,18 @@  discard block
 block discarded – undo
1972 1971
  * @return string
1973 1972
  */
1974 1973
 function urlencode_1738($url) {
1975
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1976
-		$uri = '';
1977
-		for ($i = 0; $i < strlen($url); $i++) {
1978
-			if (ord($a = $url[$i]) > 127) {
1979
-				$a = rawurlencode($a);
1980
-			}
1981
-			$uri .= $a;
1982
-		}
1983
-		$url = $uri;
1984
-	}
1974
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1975
+        $uri = '';
1976
+        for ($i = 0; $i < strlen($url); $i++) {
1977
+            if (ord($a = $url[$i]) > 127) {
1978
+                $a = rawurlencode($a);
1979
+            }
1980
+            $uri .= $a;
1981
+        }
1982
+        $url = $uri;
1983
+    }
1985 1984
 
1986
-	return quote_amp($url);
1985
+    return quote_amp($url);
1987 1986
 }
1988 1987
 
1989 1988
 /**
@@ -1999,14 +1998,14 @@  discard block
 block discarded – undo
1999 1998
  * @return string
2000 1999
  */
2001 2000
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
2002
-	$id = intval($id);
2003
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2004
-	if (!preg_match(',^\w+:,', $h)) {
2005
-		include_spip('inc/filtres_mini');
2006
-		$h = url_absolue($h);
2007
-	}
2001
+    $id = intval($id);
2002
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2003
+    if (!preg_match(',^\w+:,', $h)) {
2004
+        include_spip('inc/filtres_mini');
2005
+        $h = url_absolue($h);
2006
+    }
2008 2007
 
2009
-	return $h;
2008
+    return $h;
2010 2009
 }
2011 2010
 
2012 2011
 /**
@@ -2014,8 +2013,8 @@  discard block
 block discarded – undo
2014 2013
  * @see  generer_objet_url_absolue
2015 2014
  */
2016 2015
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
2017
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
2018
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2016
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
2017
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2019 2018
 }
2020 2019
 
2021 2020
 
@@ -2031,11 +2030,11 @@  discard block
 block discarded – undo
2031 2030
  *     true si la valeur est considérée active ; false sinon.
2032 2031
  **/
2033 2032
 function test_valeur_serveur($truc) {
2034
-	if (!$truc) {
2035
-		return false;
2036
-	}
2033
+    if (!$truc) {
2034
+        return false;
2035
+    }
2037 2036
 
2038
-	return (strtolower($truc) !== 'off');
2037
+    return (strtolower($truc) !== 'off');
2039 2038
 }
2040 2039
 
2041 2040
 //
@@ -2063,89 +2062,89 @@  discard block
 block discarded – undo
2063 2062
  */
2064 2063
 function url_de_base($profondeur = null) {
2065 2064
 
2066
-	static $url = [];
2067
-	if (is_array($profondeur)) {
2068
-		return $url = $profondeur;
2069
-	}
2070
-	if ($profondeur === false) {
2071
-		return $url;
2072
-	}
2073
-
2074
-	if (is_null($profondeur)) {
2075
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2076
-	}
2077
-
2078
-	if (isset($url[$profondeur])) {
2079
-		return $url[$profondeur];
2080
-	}
2081
-
2082
-	$http = 'http';
2083
-
2084
-	if (
2085
-		isset($_SERVER['SCRIPT_URI'])
2086
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2087
-	) {
2088
-		$http = 'https';
2089
-	} elseif (
2090
-		isset($_SERVER['HTTPS'])
2091
-		and test_valeur_serveur($_SERVER['HTTPS'])
2092
-	) {
2093
-		$http = 'https';
2094
-	}
2095
-
2096
-	// note : HTTP_HOST contient le :port si necessaire
2097
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2098
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
2099
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2100
-	}
2101
-
2102
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2103
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2104
-		$host = $GLOBALS['meta']['adresse_site'];
2105
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2106
-			$http = $scheme;
2107
-			$host = str_replace("{$scheme}://", '', $host);
2108
-		}
2109
-	}
2110
-	if (
2111
-		isset($_SERVER['SERVER_PORT'])
2112
-		and $port = $_SERVER['SERVER_PORT']
2113
-		and strpos($host, ':') == false
2114
-	) {
2115
-		if (!defined('_PORT_HTTP_STANDARD')) {
2116
-			define('_PORT_HTTP_STANDARD', '80');
2117
-		}
2118
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2119
-			define('_PORT_HTTPS_STANDARD', '443');
2120
-		}
2121
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2122
-			$host .= ":$port";
2123
-		}
2124
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2125
-			$host .= ":$port";
2126
-		}
2127
-	}
2128
-
2129
-	if (!$GLOBALS['REQUEST_URI']) {
2130
-		if (isset($_SERVER['REQUEST_URI'])) {
2131
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2132
-		} else {
2133
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2134
-			if (
2135
-				!empty($_SERVER['QUERY_STRING'])
2136
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2137
-			) {
2138
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2139
-			}
2140
-		}
2141
-	}
2142
-
2143
-	// Et nettoyer l'url
2144
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2145
-
2146
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2147
-
2148
-	return $url[$profondeur];
2065
+    static $url = [];
2066
+    if (is_array($profondeur)) {
2067
+        return $url = $profondeur;
2068
+    }
2069
+    if ($profondeur === false) {
2070
+        return $url;
2071
+    }
2072
+
2073
+    if (is_null($profondeur)) {
2074
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2075
+    }
2076
+
2077
+    if (isset($url[$profondeur])) {
2078
+        return $url[$profondeur];
2079
+    }
2080
+
2081
+    $http = 'http';
2082
+
2083
+    if (
2084
+        isset($_SERVER['SCRIPT_URI'])
2085
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2086
+    ) {
2087
+        $http = 'https';
2088
+    } elseif (
2089
+        isset($_SERVER['HTTPS'])
2090
+        and test_valeur_serveur($_SERVER['HTTPS'])
2091
+    ) {
2092
+        $http = 'https';
2093
+    }
2094
+
2095
+    // note : HTTP_HOST contient le :port si necessaire
2096
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2097
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
2098
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2099
+    }
2100
+
2101
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2102
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2103
+        $host = $GLOBALS['meta']['adresse_site'];
2104
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2105
+            $http = $scheme;
2106
+            $host = str_replace("{$scheme}://", '', $host);
2107
+        }
2108
+    }
2109
+    if (
2110
+        isset($_SERVER['SERVER_PORT'])
2111
+        and $port = $_SERVER['SERVER_PORT']
2112
+        and strpos($host, ':') == false
2113
+    ) {
2114
+        if (!defined('_PORT_HTTP_STANDARD')) {
2115
+            define('_PORT_HTTP_STANDARD', '80');
2116
+        }
2117
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2118
+            define('_PORT_HTTPS_STANDARD', '443');
2119
+        }
2120
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2121
+            $host .= ":$port";
2122
+        }
2123
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2124
+            $host .= ":$port";
2125
+        }
2126
+    }
2127
+
2128
+    if (!$GLOBALS['REQUEST_URI']) {
2129
+        if (isset($_SERVER['REQUEST_URI'])) {
2130
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2131
+        } else {
2132
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2133
+            if (
2134
+                !empty($_SERVER['QUERY_STRING'])
2135
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2136
+            ) {
2137
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2138
+            }
2139
+        }
2140
+    }
2141
+
2142
+    // Et nettoyer l'url
2143
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2144
+
2145
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2146
+
2147
+    return $url[$profondeur];
2149 2148
 }
2150 2149
 
2151 2150
 /**
@@ -2158,26 +2157,26 @@  discard block
 block discarded – undo
2158 2157
  * @return string
2159 2158
  */
2160 2159
 function url_de_($http, $host, $request, $prof = 0) {
2161
-	$prof = max($prof, 0);
2160
+    $prof = max($prof, 0);
2162 2161
 
2163
-	$myself = ltrim($request, '/');
2164
-	# supprimer la chaine de GET
2165
-	[$myself] = explode('?', $myself);
2166
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2167
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2168
-	if (strpos($myself, '://') !== false) {
2169
-		$myself = explode('://', $myself);
2170
-		array_shift($myself);
2171
-		$myself = implode('://', $myself);
2172
-		$myself = explode('/', $myself);
2173
-		array_shift($myself);
2174
-		$myself = implode('/', $myself);
2175
-	}
2176
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2162
+    $myself = ltrim($request, '/');
2163
+    # supprimer la chaine de GET
2164
+    [$myself] = explode('?', $myself);
2165
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2166
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2167
+    if (strpos($myself, '://') !== false) {
2168
+        $myself = explode('://', $myself);
2169
+        array_shift($myself);
2170
+        $myself = implode('://', $myself);
2171
+        $myself = explode('/', $myself);
2172
+        array_shift($myself);
2173
+        $myself = implode('/', $myself);
2174
+    }
2175
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2177 2176
 
2178
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2177
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2179 2178
 
2180
-	return $url;
2179
+    return $url;
2181 2180
 }
2182 2181
 
2183 2182
 
@@ -2212,26 +2211,26 @@  discard block
 block discarded – undo
2212 2211
  * @return string URL
2213 2212
  **/
2214 2213
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2215
-	$script ??= '';
2216
-	if (!$rel) {
2217
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2218
-	} else {
2219
-		if (!is_string($rel)) {
2220
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2221
-		}
2222
-	}
2223
-
2224
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2225
-	if ($script and ($script <> 'accueil' or $rel)) {
2226
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2227
-	} elseif ($args) {
2228
-		$args = "?$args";
2229
-	}
2230
-	if ($ancre) {
2231
-		$args .= "#$ancre";
2232
-	}
2233
-
2234
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2214
+    $script ??= '';
2215
+    if (!$rel) {
2216
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2217
+    } else {
2218
+        if (!is_string($rel)) {
2219
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2220
+        }
2221
+    }
2222
+
2223
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2224
+    if ($script and ($script <> 'accueil' or $rel)) {
2225
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2226
+    } elseif ($args) {
2227
+        $args = "?$args";
2228
+    }
2229
+    if ($ancre) {
2230
+        $args .= "#$ancre";
2231
+    }
2232
+
2233
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2235 2234
 }
2236 2235
 
2237 2236
 //
@@ -2253,15 +2252,15 @@  discard block
 block discarded – undo
2253 2252
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2254 2253
  **/
2255 2254
 function get_spip_script($default = '') {
2256
-	if (!defined('_SPIP_SCRIPT')) {
2257
-		return 'spip.php';
2258
-	}
2259
-	# cas define('_SPIP_SCRIPT', '');
2260
-	if (_SPIP_SCRIPT) {
2261
-		return _SPIP_SCRIPT;
2262
-	} else {
2263
-		return $default;
2264
-	}
2255
+    if (!defined('_SPIP_SCRIPT')) {
2256
+        return 'spip.php';
2257
+    }
2258
+    # cas define('_SPIP_SCRIPT', '');
2259
+    if (_SPIP_SCRIPT) {
2260
+        return _SPIP_SCRIPT;
2261
+    } else {
2262
+        return $default;
2263
+    }
2265 2264
 }
2266 2265
 
2267 2266
 /**
@@ -2290,45 +2289,45 @@  discard block
 block discarded – undo
2290 2289
  * @return string URL
2291 2290
  **/
2292 2291
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2293
-	// si le script est une action (spip_pass, spip_inscription),
2294
-	// standardiser vers la nouvelle API
2295
-
2296
-	if (is_array($args)) {
2297
-		$args = http_build_query($args);
2298
-	}
2299
-
2300
-	$url = '';
2301
-	if ($f = charger_fonction_url('page')) {
2302
-		$url = $f($script, $args);
2303
-		if ($url and !$rel) {
2304
-			include_spip('inc/filtres_mini');
2305
-			$url = url_absolue($url);
2306
-		}
2307
-	}
2308
-	if (!$url) {
2309
-		if (!$action) {
2310
-			$action = get_spip_script();
2311
-		}
2312
-		if ($script) {
2313
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2314
-		}
2315
-		if ($args) {
2316
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2317
-		}
2318
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2319
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2320
-	}
2321
-
2322
-	if (!$no_entities) {
2323
-		$url = quote_amp($url);
2324
-	}
2325
-
2326
-	return $url;
2292
+    // si le script est une action (spip_pass, spip_inscription),
2293
+    // standardiser vers la nouvelle API
2294
+
2295
+    if (is_array($args)) {
2296
+        $args = http_build_query($args);
2297
+    }
2298
+
2299
+    $url = '';
2300
+    if ($f = charger_fonction_url('page')) {
2301
+        $url = $f($script, $args);
2302
+        if ($url and !$rel) {
2303
+            include_spip('inc/filtres_mini');
2304
+            $url = url_absolue($url);
2305
+        }
2306
+    }
2307
+    if (!$url) {
2308
+        if (!$action) {
2309
+            $action = get_spip_script();
2310
+        }
2311
+        if ($script) {
2312
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2313
+        }
2314
+        if ($args) {
2315
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2316
+        }
2317
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2318
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2319
+    }
2320
+
2321
+    if (!$no_entities) {
2322
+        $url = quote_amp($url);
2323
+    }
2324
+
2325
+    return $url;
2327 2326
 }
2328 2327
 
2329 2328
 function generer_url_prive($script, $args = '', $no_entities = false) {
2330 2329
 
2331
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2330
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2332 2331
 }
2333 2332
 
2334 2333
 // Pour les formulaires en methode POST,
@@ -2353,19 +2352,19 @@  discard block
 block discarded – undo
2353 2352
  **/
2354 2353
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2355 2354
 
2356
-	$script1 = explode('&', $script);
2357
-	$script1 = reset($script1);
2355
+    $script1 = explode('&', $script);
2356
+    $script1 = reset($script1);
2358 2357
 
2359
-	return "<form action='"
2360
-	. ($script ? generer_url_ecrire($script) : '')
2361
-	. "' "
2362
-	. ($atts ?: " method='post'")
2363
-	. "><div>\n"
2364
-	. "<input type='hidden' name='exec' value='$script1' />"
2365
-	. $corps
2366
-	. (!$submit ? '' :
2367
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2368
-	. "</div></form>\n";
2358
+    return "<form action='"
2359
+    . ($script ? generer_url_ecrire($script) : '')
2360
+    . "' "
2361
+    . ($atts ?: " method='post'")
2362
+    . "><div>\n"
2363
+    . "<input type='hidden' name='exec' value='$script1' />"
2364
+    . $corps
2365
+    . (!$submit ? '' :
2366
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2367
+    . "</div></form>\n";
2369 2368
 }
2370 2369
 
2371 2370
 /**
@@ -2382,22 +2381,22 @@  discard block
 block discarded – undo
2382 2381
  * @return string
2383 2382
  */
2384 2383
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2385
-	// si l'on est dans l'espace prive, on garde dans l'url
2386
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2387
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2388
-	$h = (_DIR_RACINE and !$public)
2389
-		? generer_url_ecrire(_request('exec'))
2390
-		: generer_url_public();
2384
+    // si l'on est dans l'espace prive, on garde dans l'url
2385
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2386
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2387
+    $h = (_DIR_RACINE and !$public)
2388
+        ? generer_url_ecrire(_request('exec'))
2389
+        : generer_url_public();
2391 2390
 
2392
-	return "\n<form action='" .
2393
-	$h .
2394
-	"'" .
2395
-	$atts .
2396
-	">\n" .
2397
-	'<div>' .
2398
-	"\n<input type='hidden' name='action' value='$script' />" .
2399
-	$corps .
2400
-	'</div></form>';
2391
+    return "\n<form action='" .
2392
+    $h .
2393
+    "'" .
2394
+    $atts .
2395
+    ">\n" .
2396
+    '<div>' .
2397
+    "\n<input type='hidden' name='action' value='$script' />" .
2398
+    $corps .
2399
+    '</div></form>';
2401 2400
 }
2402 2401
 
2403 2402
 /**
@@ -2416,22 +2415,22 @@  discard block
 block discarded – undo
2416 2415
  *     URL
2417 2416
  */
2418 2417
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2419
-	// si l'on est dans l'espace prive, on garde dans l'url
2420
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2421
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2422
-	$url = (_DIR_RACINE and !$public)
2423
-		? generer_url_ecrire(_request('exec'))
2424
-		: generer_url_public('', '', false, false);
2425
-	$url = parametre_url($url, 'action', $script);
2426
-	if ($args) {
2427
-		$url .= quote_amp('&' . $args);
2428
-	}
2418
+    // si l'on est dans l'espace prive, on garde dans l'url
2419
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2420
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2421
+    $url = (_DIR_RACINE and !$public)
2422
+        ? generer_url_ecrire(_request('exec'))
2423
+        : generer_url_public('', '', false, false);
2424
+    $url = parametre_url($url, 'action', $script);
2425
+    if ($args) {
2426
+        $url .= quote_amp('&' . $args);
2427
+    }
2429 2428
 
2430
-	if ($no_entities) {
2431
-		$url = str_replace('&amp;', '&', $url);
2432
-	}
2429
+    if ($no_entities) {
2430
+        $url = str_replace('&amp;', '&', $url);
2431
+    }
2433 2432
 
2434
-	return $url;
2433
+    return $url;
2435 2434
 }
2436 2435
 
2437 2436
 
@@ -2450,23 +2449,23 @@  discard block
 block discarded – undo
2450 2449
  *     URL
2451 2450
  */
2452 2451
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2453
-	if (is_null($public)) {
2454
-		$public = (_DIR_RACINE ? false : '');
2455
-	}
2456
-	if (substr($script, -4) !== '.api') {
2457
-		$script .= '.api';
2458
-	}
2459
-	$url =
2460
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2461
-	. $script . '/'
2462
-	. ($path ? trim($path, '/') : '')
2463
-	. ($args ? '?' . quote_amp($args) : '');
2452
+    if (is_null($public)) {
2453
+        $public = (_DIR_RACINE ? false : '');
2454
+    }
2455
+    if (substr($script, -4) !== '.api') {
2456
+        $script .= '.api';
2457
+    }
2458
+    $url =
2459
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2460
+    . $script . '/'
2461
+    . ($path ? trim($path, '/') : '')
2462
+    . ($args ? '?' . quote_amp($args) : '');
2464 2463
 
2465
-	if ($no_entities) {
2466
-		$url = str_replace('&amp;', '&', $url);
2467
-	}
2464
+    if ($no_entities) {
2465
+        $url = str_replace('&amp;', '&', $url);
2466
+    }
2468 2467
 
2469
-	return $url;
2468
+    return $url;
2470 2469
 }
2471 2470
 
2472 2471
 
@@ -2479,8 +2478,8 @@  discard block
 block discarded – undo
2479 2478
  * @param string $ta Répertoire temporaire accessible
2480 2479
  */
2481 2480
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2482
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2483
-	spip_initialisation_suite();
2481
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2482
+    spip_initialisation_suite();
2484 2483
 }
2485 2484
 
2486 2485
 /**
@@ -2500,315 +2499,315 @@  discard block
 block discarded – undo
2500 2499
  * @param string $ta Répertoire temporaire accessible
2501 2500
  */
2502 2501
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2503
-	static $too_late = 0;
2504
-	if ($too_late++) {
2505
-		return;
2506
-	}
2507
-
2508
-	// Declaration des repertoires
2509
-
2510
-	// le nom du repertoire plugins/ activables/desactivables
2511
-	if (!defined('_DIR_PLUGINS')) {
2512
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2513
-	}
2514
-
2515
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2516
-	if (!defined('_DIR_PLUGINS_DIST')) {
2517
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2518
-	}
2519
-
2520
-	// le nom du repertoire des librairies
2521
-	if (!defined('_DIR_LIB')) {
2522
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2523
-	}
2524
-
2525
-	// répertoire des libs via Composer
2526
-	if (!defined('_DIR_VENDOR')) {
2527
-		define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2528
-	}
2529
-
2530
-	if (!defined('_DIR_IMG')) {
2531
-		define('_DIR_IMG', $pa);
2532
-	}
2533
-	if (!defined('_DIR_LOGOS')) {
2534
-		define('_DIR_LOGOS', $pa);
2535
-	}
2536
-	if (!defined('_DIR_IMG_ICONES')) {
2537
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2538
-	}
2539
-
2540
-	if (!defined('_DIR_DUMP')) {
2541
-		define('_DIR_DUMP', $ti . 'dump/');
2542
-	}
2543
-	if (!defined('_DIR_SESSIONS')) {
2544
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2545
-	}
2546
-	if (!defined('_DIR_TRANSFERT')) {
2547
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2548
-	}
2549
-	if (!defined('_DIR_CACHE')) {
2550
-		define('_DIR_CACHE', $ti . 'cache/');
2551
-	}
2552
-	if (!defined('_DIR_CACHE_XML')) {
2553
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2554
-	}
2555
-	if (!defined('_DIR_SKELS')) {
2556
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2557
-	}
2558
-	if (!defined('_DIR_AIDE')) {
2559
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2560
-	}
2561
-	if (!defined('_DIR_TMP')) {
2562
-		define('_DIR_TMP', $ti);
2563
-	}
2564
-
2565
-	if (!defined('_DIR_VAR')) {
2566
-		define('_DIR_VAR', $ta);
2567
-	}
2568
-
2569
-	if (!defined('_DIR_ETC')) {
2570
-		define('_DIR_ETC', $pi);
2571
-	}
2572
-	if (!defined('_DIR_CONNECT')) {
2573
-		define('_DIR_CONNECT', $pi);
2574
-	}
2575
-	if (!defined('_DIR_CHMOD')) {
2576
-		define('_DIR_CHMOD', $pi);
2577
-	}
2578
-
2579
-	if (!isset($GLOBALS['test_dirs'])) {
2580
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2581
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2582
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2583
-	}
2584
-
2585
-	// Declaration des fichiers
2586
-
2587
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2588
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2589
-	}
2590
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2591
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2592
-	}
2593
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2594
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2595
-	}
2596
-	if (!defined('_CACHE_PIPELINES')) {
2597
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2598
-	}
2599
-	if (!defined('_CACHE_CHEMIN')) {
2600
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2601
-	}
2602
-
2603
-	# attention .php obligatoire pour ecrire_fichier_securise
2604
-	if (!defined('_FILE_META')) {
2605
-		define('_FILE_META', $ti . 'meta_cache.php');
2606
-	}
2607
-	if (!defined('_DIR_LOG')) {
2608
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2609
-	}
2610
-	if (!defined('_FILE_LOG')) {
2611
-		define('_FILE_LOG', 'spip');
2612
-	}
2613
-	if (!defined('_FILE_LOG_SUFFIX')) {
2614
-		define('_FILE_LOG_SUFFIX', '.log');
2615
-	}
2616
-
2617
-	// Le fichier de connexion a la base de donnees
2618
-	// tient compte des anciennes versions (inc_connect...)
2619
-	if (!defined('_FILE_CONNECT_INS')) {
2620
-		define('_FILE_CONNECT_INS', 'connect');
2621
-	}
2622
-	if (!defined('_FILE_CONNECT')) {
2623
-		define(
2624
-			'_FILE_CONNECT',
2625
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2626
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2627
-			: false))
2628
-		);
2629
-	}
2630
-
2631
-	// Le fichier de reglages des droits
2632
-	if (!defined('_FILE_CHMOD_INS')) {
2633
-		define('_FILE_CHMOD_INS', 'chmod');
2634
-	}
2635
-	if (!defined('_FILE_CHMOD')) {
2636
-		define(
2637
-			'_FILE_CHMOD',
2638
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2639
-			: false)
2640
-		);
2641
-	}
2642
-
2643
-	if (!defined('_FILE_LDAP')) {
2644
-		define('_FILE_LDAP', 'ldap.php');
2645
-	}
2646
-
2647
-	if (!defined('_FILE_TMP_SUFFIX')) {
2648
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2649
-	}
2650
-	if (!defined('_FILE_CONNECT_TMP')) {
2651
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2652
-	}
2653
-	if (!defined('_FILE_CHMOD_TMP')) {
2654
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2655
-	}
2656
-
2657
-	// Definition des droits d'acces en ecriture
2658
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2659
-		include_once _FILE_CHMOD;
2660
-	}
2661
-
2662
-	// Se mefier des fichiers mal remplis!
2663
-	if (!defined('_SPIP_CHMOD')) {
2664
-		define('_SPIP_CHMOD', 0777);
2665
-	}
2666
-
2667
-	if (!defined('_DEFAULT_CHARSET')) {
2668
-		/** Le charset par défaut lors de l'installation */
2669
-		define('_DEFAULT_CHARSET', 'utf-8');
2670
-	}
2671
-	if (!defined('_ROOT_PLUGINS')) {
2672
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2673
-	}
2674
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2675
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2676
-	}
2677
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2678
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2679
-	}
2680
-
2681
-	// La taille des Log
2682
-	if (!defined('_MAX_LOG')) {
2683
-		define('_MAX_LOG', 100);
2684
-	}
2685
-
2686
-	// Sommes-nous dans l'empire du Mal ?
2687
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2688
-	if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2689
-		if (!defined('_OS_SERVEUR')) {
2690
-			define('_OS_SERVEUR', 'windows');
2691
-		}
2692
-		if (!defined('_SPIP_LOCK_MODE')) {
2693
-			define('_SPIP_LOCK_MODE', 1);
2694
-		} // utiliser le flock php
2695
-	} else {
2696
-		if (!defined('_OS_SERVEUR')) {
2697
-			define('_OS_SERVEUR', '');
2698
-		}
2699
-		if (!defined('_SPIP_LOCK_MODE')) {
2700
-			define('_SPIP_LOCK_MODE', 1);
2701
-		} // utiliser le flock php
2702
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2703
-	}
2704
-
2705
-	// Langue par defaut
2706
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2707
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2708
-	}
2709
-
2710
-	//
2711
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2712
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2713
-	// pour le rendre surchargeable, on va provoquer un reecriture
2714
-	// systematique du noyau ou une baisse de perfs => a etudier)
2715
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2716
-
2717
-	// charger tout de suite le path et son cache
2718
-	load_path_cache();
2719
-
2720
-	// *********** traiter les variables ************
2721
-
2722
-	//
2723
-	// Securite
2724
-	//
2725
-
2726
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2727
-	if (isset($_REQUEST['GLOBALS'])) {
2728
-		die();
2729
-	}
2730
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2731
-	spip_desinfecte($_GET);
2732
-	spip_desinfecte($_POST);
2733
-	spip_desinfecte($_COOKIE);
2734
-	spip_desinfecte($_REQUEST);
2735
-
2736
-	// appliquer le cookie_prefix
2737
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2738
-		include_spip('inc/cookie');
2739
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2740
-	}
2741
-
2742
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2743
-	if (isset($_SERVER['REQUEST_URI'])) {
2744
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2745
-	} else {
2746
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2747
-		if (
2748
-			!empty($_SERVER['QUERY_STRING'])
2749
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2750
-		) {
2751
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2752
-		}
2753
-	}
2754
-
2755
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2756
-	if (!defined('_RENOUVELLE_ALEA')) {
2757
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2758
-	}
2759
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2760
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2761
-	}
2762
-
2763
-	// charger les meta si possible et renouveller l'alea au besoin
2764
-	// charge aussi effacer_meta et ecrire_meta
2765
-	$inc_meta = charger_fonction('meta', 'inc');
2766
-	$inc_meta();
2767
-
2768
-	// nombre de repertoires depuis la racine
2769
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2770
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2771
-	// le calcul est faux)
2772
-	if (!_DIR_RESTREINT) {
2773
-		$GLOBALS['profondeur_url'] = 1;
2774
-	} else {
2775
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2776
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2777
-		if (
2778
-			!$uri_ref
2779
-			// si on est appele avec un autre ti, on est sans doute en mutu
2780
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2781
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2782
-			// s'en remettre a l'adresse du site. alea jacta est.
2783
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2784
-		) {
2785
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2786
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2787
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2788
-			} else {
2789
-				$uri_ref = '';
2790
-			}
2791
-		}
2792
-		if (!$uri or !$uri_ref) {
2793
-			$GLOBALS['profondeur_url'] = 0;
2794
-		} else {
2795
-			$GLOBALS['profondeur_url'] = max(
2796
-				0,
2797
-				substr_count($uri[0], '/')
2798
-				- substr_count($uri_ref, '/')
2799
-			);
2800
-		}
2801
-	}
2802
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2803
-	if (_FILE_CONNECT) {
2804
-		if (
2805
-			verifier_visiteur() == '0minirezo'
2806
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2807
-			and !isset($_COOKIE['spip_admin'])
2808
-		) {
2809
-			clear_path_cache();
2810
-		}
2811
-	}
2502
+    static $too_late = 0;
2503
+    if ($too_late++) {
2504
+        return;
2505
+    }
2506
+
2507
+    // Declaration des repertoires
2508
+
2509
+    // le nom du repertoire plugins/ activables/desactivables
2510
+    if (!defined('_DIR_PLUGINS')) {
2511
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2512
+    }
2513
+
2514
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2515
+    if (!defined('_DIR_PLUGINS_DIST')) {
2516
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2517
+    }
2518
+
2519
+    // le nom du repertoire des librairies
2520
+    if (!defined('_DIR_LIB')) {
2521
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2522
+    }
2523
+
2524
+    // répertoire des libs via Composer
2525
+    if (!defined('_DIR_VENDOR')) {
2526
+        define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2527
+    }
2528
+
2529
+    if (!defined('_DIR_IMG')) {
2530
+        define('_DIR_IMG', $pa);
2531
+    }
2532
+    if (!defined('_DIR_LOGOS')) {
2533
+        define('_DIR_LOGOS', $pa);
2534
+    }
2535
+    if (!defined('_DIR_IMG_ICONES')) {
2536
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2537
+    }
2538
+
2539
+    if (!defined('_DIR_DUMP')) {
2540
+        define('_DIR_DUMP', $ti . 'dump/');
2541
+    }
2542
+    if (!defined('_DIR_SESSIONS')) {
2543
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2544
+    }
2545
+    if (!defined('_DIR_TRANSFERT')) {
2546
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2547
+    }
2548
+    if (!defined('_DIR_CACHE')) {
2549
+        define('_DIR_CACHE', $ti . 'cache/');
2550
+    }
2551
+    if (!defined('_DIR_CACHE_XML')) {
2552
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2553
+    }
2554
+    if (!defined('_DIR_SKELS')) {
2555
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2556
+    }
2557
+    if (!defined('_DIR_AIDE')) {
2558
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2559
+    }
2560
+    if (!defined('_DIR_TMP')) {
2561
+        define('_DIR_TMP', $ti);
2562
+    }
2563
+
2564
+    if (!defined('_DIR_VAR')) {
2565
+        define('_DIR_VAR', $ta);
2566
+    }
2567
+
2568
+    if (!defined('_DIR_ETC')) {
2569
+        define('_DIR_ETC', $pi);
2570
+    }
2571
+    if (!defined('_DIR_CONNECT')) {
2572
+        define('_DIR_CONNECT', $pi);
2573
+    }
2574
+    if (!defined('_DIR_CHMOD')) {
2575
+        define('_DIR_CHMOD', $pi);
2576
+    }
2577
+
2578
+    if (!isset($GLOBALS['test_dirs'])) {
2579
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2580
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2581
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2582
+    }
2583
+
2584
+    // Declaration des fichiers
2585
+
2586
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2587
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2588
+    }
2589
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2590
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2591
+    }
2592
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2593
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2594
+    }
2595
+    if (!defined('_CACHE_PIPELINES')) {
2596
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2597
+    }
2598
+    if (!defined('_CACHE_CHEMIN')) {
2599
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2600
+    }
2601
+
2602
+    # attention .php obligatoire pour ecrire_fichier_securise
2603
+    if (!defined('_FILE_META')) {
2604
+        define('_FILE_META', $ti . 'meta_cache.php');
2605
+    }
2606
+    if (!defined('_DIR_LOG')) {
2607
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2608
+    }
2609
+    if (!defined('_FILE_LOG')) {
2610
+        define('_FILE_LOG', 'spip');
2611
+    }
2612
+    if (!defined('_FILE_LOG_SUFFIX')) {
2613
+        define('_FILE_LOG_SUFFIX', '.log');
2614
+    }
2615
+
2616
+    // Le fichier de connexion a la base de donnees
2617
+    // tient compte des anciennes versions (inc_connect...)
2618
+    if (!defined('_FILE_CONNECT_INS')) {
2619
+        define('_FILE_CONNECT_INS', 'connect');
2620
+    }
2621
+    if (!defined('_FILE_CONNECT')) {
2622
+        define(
2623
+            '_FILE_CONNECT',
2624
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2625
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2626
+            : false))
2627
+        );
2628
+    }
2629
+
2630
+    // Le fichier de reglages des droits
2631
+    if (!defined('_FILE_CHMOD_INS')) {
2632
+        define('_FILE_CHMOD_INS', 'chmod');
2633
+    }
2634
+    if (!defined('_FILE_CHMOD')) {
2635
+        define(
2636
+            '_FILE_CHMOD',
2637
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2638
+            : false)
2639
+        );
2640
+    }
2641
+
2642
+    if (!defined('_FILE_LDAP')) {
2643
+        define('_FILE_LDAP', 'ldap.php');
2644
+    }
2645
+
2646
+    if (!defined('_FILE_TMP_SUFFIX')) {
2647
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2648
+    }
2649
+    if (!defined('_FILE_CONNECT_TMP')) {
2650
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2651
+    }
2652
+    if (!defined('_FILE_CHMOD_TMP')) {
2653
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2654
+    }
2655
+
2656
+    // Definition des droits d'acces en ecriture
2657
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2658
+        include_once _FILE_CHMOD;
2659
+    }
2660
+
2661
+    // Se mefier des fichiers mal remplis!
2662
+    if (!defined('_SPIP_CHMOD')) {
2663
+        define('_SPIP_CHMOD', 0777);
2664
+    }
2665
+
2666
+    if (!defined('_DEFAULT_CHARSET')) {
2667
+        /** Le charset par défaut lors de l'installation */
2668
+        define('_DEFAULT_CHARSET', 'utf-8');
2669
+    }
2670
+    if (!defined('_ROOT_PLUGINS')) {
2671
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2672
+    }
2673
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2674
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2675
+    }
2676
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2677
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2678
+    }
2679
+
2680
+    // La taille des Log
2681
+    if (!defined('_MAX_LOG')) {
2682
+        define('_MAX_LOG', 100);
2683
+    }
2684
+
2685
+    // Sommes-nous dans l'empire du Mal ?
2686
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2687
+    if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2688
+        if (!defined('_OS_SERVEUR')) {
2689
+            define('_OS_SERVEUR', 'windows');
2690
+        }
2691
+        if (!defined('_SPIP_LOCK_MODE')) {
2692
+            define('_SPIP_LOCK_MODE', 1);
2693
+        } // utiliser le flock php
2694
+    } else {
2695
+        if (!defined('_OS_SERVEUR')) {
2696
+            define('_OS_SERVEUR', '');
2697
+        }
2698
+        if (!defined('_SPIP_LOCK_MODE')) {
2699
+            define('_SPIP_LOCK_MODE', 1);
2700
+        } // utiliser le flock php
2701
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2702
+    }
2703
+
2704
+    // Langue par defaut
2705
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2706
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2707
+    }
2708
+
2709
+    //
2710
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2711
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2712
+    // pour le rendre surchargeable, on va provoquer un reecriture
2713
+    // systematique du noyau ou une baisse de perfs => a etudier)
2714
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2715
+
2716
+    // charger tout de suite le path et son cache
2717
+    load_path_cache();
2718
+
2719
+    // *********** traiter les variables ************
2720
+
2721
+    //
2722
+    // Securite
2723
+    //
2724
+
2725
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2726
+    if (isset($_REQUEST['GLOBALS'])) {
2727
+        die();
2728
+    }
2729
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2730
+    spip_desinfecte($_GET);
2731
+    spip_desinfecte($_POST);
2732
+    spip_desinfecte($_COOKIE);
2733
+    spip_desinfecte($_REQUEST);
2734
+
2735
+    // appliquer le cookie_prefix
2736
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2737
+        include_spip('inc/cookie');
2738
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2739
+    }
2740
+
2741
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2742
+    if (isset($_SERVER['REQUEST_URI'])) {
2743
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2744
+    } else {
2745
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2746
+        if (
2747
+            !empty($_SERVER['QUERY_STRING'])
2748
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2749
+        ) {
2750
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2751
+        }
2752
+    }
2753
+
2754
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2755
+    if (!defined('_RENOUVELLE_ALEA')) {
2756
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2757
+    }
2758
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2759
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2760
+    }
2761
+
2762
+    // charger les meta si possible et renouveller l'alea au besoin
2763
+    // charge aussi effacer_meta et ecrire_meta
2764
+    $inc_meta = charger_fonction('meta', 'inc');
2765
+    $inc_meta();
2766
+
2767
+    // nombre de repertoires depuis la racine
2768
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2769
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2770
+    // le calcul est faux)
2771
+    if (!_DIR_RESTREINT) {
2772
+        $GLOBALS['profondeur_url'] = 1;
2773
+    } else {
2774
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2775
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2776
+        if (
2777
+            !$uri_ref
2778
+            // si on est appele avec un autre ti, on est sans doute en mutu
2779
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2780
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2781
+            // s'en remettre a l'adresse du site. alea jacta est.
2782
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2783
+        ) {
2784
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2785
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2786
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2787
+            } else {
2788
+                $uri_ref = '';
2789
+            }
2790
+        }
2791
+        if (!$uri or !$uri_ref) {
2792
+            $GLOBALS['profondeur_url'] = 0;
2793
+        } else {
2794
+            $GLOBALS['profondeur_url'] = max(
2795
+                0,
2796
+                substr_count($uri[0], '/')
2797
+                - substr_count($uri_ref, '/')
2798
+            );
2799
+        }
2800
+    }
2801
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2802
+    if (_FILE_CONNECT) {
2803
+        if (
2804
+            verifier_visiteur() == '0minirezo'
2805
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2806
+            and !isset($_COOKIE['spip_admin'])
2807
+        ) {
2808
+            clear_path_cache();
2809
+        }
2810
+    }
2812 2811
 }
2813 2812
 
2814 2813
 /**
@@ -2817,157 +2816,157 @@  discard block
 block discarded – undo
2817 2816
  *
2818 2817
  */
2819 2818
 function spip_initialisation_suite() {
2820
-	static $too_late = 0;
2821
-	if ($too_late++) {
2822
-		return;
2823
-	}
2824
-
2825
-	// taille mini des login
2826
-	if (!defined('_LOGIN_TROP_COURT')) {
2827
-		define('_LOGIN_TROP_COURT', 4);
2828
-	}
2829
-
2830
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2831
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2832
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2833
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2834
-
2835
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2836
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2837
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2838
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2839
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2840
-
2841
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2842
-		define('_PASS_LONGUEUR_MINI', 6);
2843
-	}
2844
-
2845
-	// largeur maximale des images dans l'administration
2846
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2847
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2848
-	}
2849
-
2850
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2851
-	if (!defined('_IMG_QUALITE')) {
2852
-		define('_IMG_QUALITE', 85);
2853
-	} # valeur par defaut
2854
-	if (!defined('_IMG_GD_QUALITE')) {
2855
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2856
-	} # surcharge pour la lib GD
2857
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2858
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2859
-	} # surcharge pour imagick en ligne de commande
2860
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2861
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2862
-		define('_IMG_IMAGICK_QUALITE', 75);
2863
-	} # surcharge pour imagick en PHP
2864
-
2865
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2866
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2867
-	} // poids en octet
2868
-
2869
-	// qq chaines standard
2870
-	if (!defined('_ACCESS_FILE_NAME')) {
2871
-		define('_ACCESS_FILE_NAME', '.htaccess');
2872
-	}
2873
-	if (!defined('_AUTH_USER_FILE')) {
2874
-		define('_AUTH_USER_FILE', '.htpasswd');
2875
-	}
2876
-	if (!defined('_SPIP_DUMP')) {
2877
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2878
-	}
2879
-	if (!defined('_CACHE_RUBRIQUES')) {
2880
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2881
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2882
-	}
2883
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2884
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2885
-		define('_CACHE_RUBRIQUES_MAX', 500);
2886
-	}
2887
-
2888
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2889
-		/**
2890
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2891
-		 * @var int Nombre de caractères */
2892
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2893
-	}
2894
-
2895
-	if (!defined('_EXTENSION_SQUELETTES')) {
2896
-		define('_EXTENSION_SQUELETTES', 'html');
2897
-	}
2898
-
2899
-	if (!defined('_DOCTYPE_ECRIRE')) {
2900
-		/** Définit le doctype de l’espace privé */
2901
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2902
-	}
2903
-	if (!defined('_DOCTYPE_AIDE')) {
2904
-		/** Définit le doctype de l’aide en ligne */
2905
-		define(
2906
-			'_DOCTYPE_AIDE',
2907
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2908
-		);
2909
-	}
2910
-
2911
-	if (!defined('_SPIP_SCRIPT')) {
2912
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2913
-		 * le script de l'espace public, alias index.php */
2914
-		define('_SPIP_SCRIPT', 'spip.php');
2915
-	}
2916
-	if (!defined('_SPIP_PAGE')) {
2917
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2918
-		define('_SPIP_PAGE', 'page');
2919
-	}
2920
-
2921
-	// le script de l'espace prive
2922
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2923
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2924
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2925
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2926
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2927
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2928
-		} else {
2929
-			define('_SPIP_ECRIRE_SCRIPT', '');
2930
-		}
2931
-	}
2932
-
2933
-
2934
-	if (!defined('_SPIP_AJAX')) {
2935
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2936
-			? 1
2937
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2938
-	}
2939
-
2940
-	// La requete est-elle en ajax ?
2941
-	if (!defined('_AJAX')) {
2942
-		define(
2943
-			'_AJAX',
2944
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2945
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2946
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2947
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2948
-			)
2949
-			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
2950
-		);
2951
-	}
2952
-
2953
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2954
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2955
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2956
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2957
-		define(
2958
-			'_IMG_GD_MAX_PIXELS',
2959
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2960
-			? $GLOBALS['meta']['max_taille_vignettes']
2961
-			: 0
2962
-		);
2963
-	}
2964
-
2965
-	// Protocoles a normaliser dans les chaines de langues
2966
-	if (!defined('_PROTOCOLES_STD')) {
2967
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2968
-	}
2969
-
2970
-	init_var_mode();
2819
+    static $too_late = 0;
2820
+    if ($too_late++) {
2821
+        return;
2822
+    }
2823
+
2824
+    // taille mini des login
2825
+    if (!defined('_LOGIN_TROP_COURT')) {
2826
+        define('_LOGIN_TROP_COURT', 4);
2827
+    }
2828
+
2829
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2830
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2831
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2832
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2833
+
2834
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2835
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2836
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2837
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2838
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2839
+
2840
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2841
+        define('_PASS_LONGUEUR_MINI', 6);
2842
+    }
2843
+
2844
+    // largeur maximale des images dans l'administration
2845
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2846
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2847
+    }
2848
+
2849
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2850
+    if (!defined('_IMG_QUALITE')) {
2851
+        define('_IMG_QUALITE', 85);
2852
+    } # valeur par defaut
2853
+    if (!defined('_IMG_GD_QUALITE')) {
2854
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2855
+    } # surcharge pour la lib GD
2856
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2857
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2858
+    } # surcharge pour imagick en ligne de commande
2859
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2860
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2861
+        define('_IMG_IMAGICK_QUALITE', 75);
2862
+    } # surcharge pour imagick en PHP
2863
+
2864
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2865
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2866
+    } // poids en octet
2867
+
2868
+    // qq chaines standard
2869
+    if (!defined('_ACCESS_FILE_NAME')) {
2870
+        define('_ACCESS_FILE_NAME', '.htaccess');
2871
+    }
2872
+    if (!defined('_AUTH_USER_FILE')) {
2873
+        define('_AUTH_USER_FILE', '.htpasswd');
2874
+    }
2875
+    if (!defined('_SPIP_DUMP')) {
2876
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2877
+    }
2878
+    if (!defined('_CACHE_RUBRIQUES')) {
2879
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2880
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2881
+    }
2882
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2883
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2884
+        define('_CACHE_RUBRIQUES_MAX', 500);
2885
+    }
2886
+
2887
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2888
+        /**
2889
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2890
+         * @var int Nombre de caractères */
2891
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2892
+    }
2893
+
2894
+    if (!defined('_EXTENSION_SQUELETTES')) {
2895
+        define('_EXTENSION_SQUELETTES', 'html');
2896
+    }
2897
+
2898
+    if (!defined('_DOCTYPE_ECRIRE')) {
2899
+        /** Définit le doctype de l’espace privé */
2900
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2901
+    }
2902
+    if (!defined('_DOCTYPE_AIDE')) {
2903
+        /** Définit le doctype de l’aide en ligne */
2904
+        define(
2905
+            '_DOCTYPE_AIDE',
2906
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2907
+        );
2908
+    }
2909
+
2910
+    if (!defined('_SPIP_SCRIPT')) {
2911
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2912
+         * le script de l'espace public, alias index.php */
2913
+        define('_SPIP_SCRIPT', 'spip.php');
2914
+    }
2915
+    if (!defined('_SPIP_PAGE')) {
2916
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2917
+        define('_SPIP_PAGE', 'page');
2918
+    }
2919
+
2920
+    // le script de l'espace prive
2921
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2922
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2923
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2924
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2925
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2926
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2927
+        } else {
2928
+            define('_SPIP_ECRIRE_SCRIPT', '');
2929
+        }
2930
+    }
2931
+
2932
+
2933
+    if (!defined('_SPIP_AJAX')) {
2934
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2935
+            ? 1
2936
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2937
+    }
2938
+
2939
+    // La requete est-elle en ajax ?
2940
+    if (!defined('_AJAX')) {
2941
+        define(
2942
+            '_AJAX',
2943
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2944
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2945
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2946
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2947
+            )
2948
+            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
2949
+        );
2950
+    }
2951
+
2952
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2953
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2954
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2955
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2956
+        define(
2957
+            '_IMG_GD_MAX_PIXELS',
2958
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2959
+            ? $GLOBALS['meta']['max_taille_vignettes']
2960
+            : 0
2961
+        );
2962
+    }
2963
+
2964
+    // Protocoles a normaliser dans les chaines de langues
2965
+    if (!defined('_PROTOCOLES_STD')) {
2966
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2967
+    }
2968
+
2969
+    init_var_mode();
2971 2970
 }
2972 2971
 
2973 2972
 /**
@@ -3001,136 +3000,136 @@  discard block
 block discarded – undo
3001 3000
  * `   var_mode` (calcul ou recalcul).
3002 3001
  */
3003 3002
 function init_var_mode() {
3004
-	static $done = false;
3005
-	if (!$done) {
3006
-		if (isset($_GET['var_mode'])) {
3007
-			$var_mode = explode(',', $_GET['var_mode']);
3008
-			// tout le monde peut calcul/recalcul
3009
-			if (!defined('_VAR_MODE')) {
3010
-				if (in_array('recalcul', $var_mode)) {
3011
-					define('_VAR_MODE', 'recalcul');
3012
-				} elseif (in_array('calcul', $var_mode)) {
3013
-					define('_VAR_MODE', 'calcul');
3014
-				}
3015
-			}
3016
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3017
-			if ($var_mode) {
3018
-				include_spip('inc/autoriser');
3019
-				// autoriser preview si preview seulement, et sinon autoriser debug
3020
-				if (
3021
-					autoriser(
3022
-						($_GET['var_mode'] == 'preview')
3023
-						? 'previsualiser'
3024
-						: 'debug'
3025
-					)
3026
-				) {
3027
-					if (in_array('traduction', $var_mode)) {
3028
-						// forcer le calcul pour passer dans traduire
3029
-						if (!defined('_VAR_MODE')) {
3030
-							define('_VAR_MODE', 'calcul');
3031
-						}
3032
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3033
-						if (!defined('_VAR_NOCACHE')) {
3034
-							define('_VAR_NOCACHE', true);
3035
-						}
3036
-						$var_mode = array_diff($var_mode, ['traduction']);
3037
-					}
3038
-					if (in_array('preview', $var_mode)) {
3039
-						// basculer sur les criteres de preview dans les boucles
3040
-						if (!defined('_VAR_PREVIEW')) {
3041
-							define('_VAR_PREVIEW', true);
3042
-						}
3043
-						// forcer le calcul
3044
-						if (!defined('_VAR_MODE')) {
3045
-							define('_VAR_MODE', 'calcul');
3046
-						}
3047
-						// et ne pas enregistrer de cache
3048
-						if (!defined('_VAR_NOCACHE')) {
3049
-							define('_VAR_NOCACHE', true);
3050
-						}
3051
-						$var_mode = array_diff($var_mode, ['preview']);
3052
-					}
3053
-					if (in_array('inclure', $var_mode)) {
3054
-						// forcer le compilo et ignorer les caches existants
3055
-						if (!defined('_VAR_MODE')) {
3056
-							define('_VAR_MODE', 'calcul');
3057
-						}
3058
-						if (!defined('_VAR_INCLURE')) {
3059
-							define('_VAR_INCLURE', true);
3060
-						}
3061
-						// et ne pas enregistrer de cache
3062
-						if (!defined('_VAR_NOCACHE')) {
3063
-							define('_VAR_NOCACHE', true);
3064
-						}
3065
-						$var_mode = array_diff($var_mode, ['inclure']);
3066
-					}
3067
-					if (in_array('urls', $var_mode)) {
3068
-						// forcer le compilo et ignorer les caches existants
3069
-						if (!defined('_VAR_MODE')) {
3070
-							define('_VAR_MODE', 'calcul');
3071
-						}
3072
-						if (!defined('_VAR_URLS')) {
3073
-							define('_VAR_URLS', true);
3074
-						}
3075
-						$var_mode = array_diff($var_mode, ['urls']);
3076
-					}
3077
-					if (in_array('images', $var_mode)) {
3078
-						// forcer le compilo et ignorer les caches existants
3079
-						if (!defined('_VAR_MODE')) {
3080
-							define('_VAR_MODE', 'calcul');
3081
-						}
3082
-						// indiquer qu'on doit recalculer les images
3083
-						if (!defined('_VAR_IMAGES')) {
3084
-							define('_VAR_IMAGES', true);
3085
-						}
3086
-						$var_mode = array_diff($var_mode, ['images']);
3087
-					}
3088
-					if (in_array('debug', $var_mode)) {
3089
-						if (!defined('_VAR_MODE')) {
3090
-							define('_VAR_MODE', 'debug');
3091
-						}
3092
-						// et ne pas enregistrer de cache
3093
-						if (!defined('_VAR_NOCACHE')) {
3094
-							define('_VAR_NOCACHE', true);
3095
-						}
3096
-						$var_mode = array_diff($var_mode, ['debug']);
3097
-					}
3098
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3099
-						define('_VAR_MODE', reset($var_mode));
3100
-					}
3101
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3102
-						spip_log($GLOBALS['visiteur_session']['nom']
3103
-							. ' ' . _VAR_MODE);
3104
-					}
3105
-				} // pas autorise ?
3106
-				else {
3107
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3108
-					if (
3109
-						!$GLOBALS['visiteur_session']
3110
-						and !empty($_SERVER['HTTP_HOST'])
3111
-						and !empty($_SERVER['REQUEST_METHOD'])
3112
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3113
-					) {
3114
-						$self = self('&', true);
3115
-						if (strpos($self, 'page=login') === false) {
3116
-							include_spip('inc/headers');
3117
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3118
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3119
-						}
3120
-					}
3121
-					// sinon tant pis
3122
-				}
3123
-			}
3124
-		}
3125
-		if (!defined('_VAR_MODE')) {
3126
-			/**
3127
-			 * Indique le mode de calcul ou d'affichage de la page.
3128
-			 * @see init_var_mode()
3129
-			 */
3130
-			define('_VAR_MODE', false);
3131
-		}
3132
-		$done = true;
3133
-	}
3003
+    static $done = false;
3004
+    if (!$done) {
3005
+        if (isset($_GET['var_mode'])) {
3006
+            $var_mode = explode(',', $_GET['var_mode']);
3007
+            // tout le monde peut calcul/recalcul
3008
+            if (!defined('_VAR_MODE')) {
3009
+                if (in_array('recalcul', $var_mode)) {
3010
+                    define('_VAR_MODE', 'recalcul');
3011
+                } elseif (in_array('calcul', $var_mode)) {
3012
+                    define('_VAR_MODE', 'calcul');
3013
+                }
3014
+            }
3015
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3016
+            if ($var_mode) {
3017
+                include_spip('inc/autoriser');
3018
+                // autoriser preview si preview seulement, et sinon autoriser debug
3019
+                if (
3020
+                    autoriser(
3021
+                        ($_GET['var_mode'] == 'preview')
3022
+                        ? 'previsualiser'
3023
+                        : 'debug'
3024
+                    )
3025
+                ) {
3026
+                    if (in_array('traduction', $var_mode)) {
3027
+                        // forcer le calcul pour passer dans traduire
3028
+                        if (!defined('_VAR_MODE')) {
3029
+                            define('_VAR_MODE', 'calcul');
3030
+                        }
3031
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3032
+                        if (!defined('_VAR_NOCACHE')) {
3033
+                            define('_VAR_NOCACHE', true);
3034
+                        }
3035
+                        $var_mode = array_diff($var_mode, ['traduction']);
3036
+                    }
3037
+                    if (in_array('preview', $var_mode)) {
3038
+                        // basculer sur les criteres de preview dans les boucles
3039
+                        if (!defined('_VAR_PREVIEW')) {
3040
+                            define('_VAR_PREVIEW', true);
3041
+                        }
3042
+                        // forcer le calcul
3043
+                        if (!defined('_VAR_MODE')) {
3044
+                            define('_VAR_MODE', 'calcul');
3045
+                        }
3046
+                        // et ne pas enregistrer de cache
3047
+                        if (!defined('_VAR_NOCACHE')) {
3048
+                            define('_VAR_NOCACHE', true);
3049
+                        }
3050
+                        $var_mode = array_diff($var_mode, ['preview']);
3051
+                    }
3052
+                    if (in_array('inclure', $var_mode)) {
3053
+                        // forcer le compilo et ignorer les caches existants
3054
+                        if (!defined('_VAR_MODE')) {
3055
+                            define('_VAR_MODE', 'calcul');
3056
+                        }
3057
+                        if (!defined('_VAR_INCLURE')) {
3058
+                            define('_VAR_INCLURE', true);
3059
+                        }
3060
+                        // et ne pas enregistrer de cache
3061
+                        if (!defined('_VAR_NOCACHE')) {
3062
+                            define('_VAR_NOCACHE', true);
3063
+                        }
3064
+                        $var_mode = array_diff($var_mode, ['inclure']);
3065
+                    }
3066
+                    if (in_array('urls', $var_mode)) {
3067
+                        // forcer le compilo et ignorer les caches existants
3068
+                        if (!defined('_VAR_MODE')) {
3069
+                            define('_VAR_MODE', 'calcul');
3070
+                        }
3071
+                        if (!defined('_VAR_URLS')) {
3072
+                            define('_VAR_URLS', true);
3073
+                        }
3074
+                        $var_mode = array_diff($var_mode, ['urls']);
3075
+                    }
3076
+                    if (in_array('images', $var_mode)) {
3077
+                        // forcer le compilo et ignorer les caches existants
3078
+                        if (!defined('_VAR_MODE')) {
3079
+                            define('_VAR_MODE', 'calcul');
3080
+                        }
3081
+                        // indiquer qu'on doit recalculer les images
3082
+                        if (!defined('_VAR_IMAGES')) {
3083
+                            define('_VAR_IMAGES', true);
3084
+                        }
3085
+                        $var_mode = array_diff($var_mode, ['images']);
3086
+                    }
3087
+                    if (in_array('debug', $var_mode)) {
3088
+                        if (!defined('_VAR_MODE')) {
3089
+                            define('_VAR_MODE', 'debug');
3090
+                        }
3091
+                        // et ne pas enregistrer de cache
3092
+                        if (!defined('_VAR_NOCACHE')) {
3093
+                            define('_VAR_NOCACHE', true);
3094
+                        }
3095
+                        $var_mode = array_diff($var_mode, ['debug']);
3096
+                    }
3097
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3098
+                        define('_VAR_MODE', reset($var_mode));
3099
+                    }
3100
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3101
+                        spip_log($GLOBALS['visiteur_session']['nom']
3102
+                            . ' ' . _VAR_MODE);
3103
+                    }
3104
+                } // pas autorise ?
3105
+                else {
3106
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3107
+                    if (
3108
+                        !$GLOBALS['visiteur_session']
3109
+                        and !empty($_SERVER['HTTP_HOST'])
3110
+                        and !empty($_SERVER['REQUEST_METHOD'])
3111
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3112
+                    ) {
3113
+                        $self = self('&', true);
3114
+                        if (strpos($self, 'page=login') === false) {
3115
+                            include_spip('inc/headers');
3116
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3117
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3118
+                        }
3119
+                    }
3120
+                    // sinon tant pis
3121
+                }
3122
+            }
3123
+        }
3124
+        if (!defined('_VAR_MODE')) {
3125
+            /**
3126
+             * Indique le mode de calcul ou d'affichage de la page.
3127
+             * @see init_var_mode()
3128
+             */
3129
+            define('_VAR_MODE', false);
3130
+        }
3131
+        $done = true;
3132
+    }
3134 3133
 }
3135 3134
 
3136 3135
 /**
@@ -3142,16 +3141,16 @@  discard block
 block discarded – undo
3142 3141
  * @param bool $deep = true : appliquer récursivement
3143 3142
 **/
3144 3143
 function spip_desinfecte(&$t, $deep = true) {
3145
-	foreach ($t as $key => $val) {
3146
-		if (is_string($t[$key])) {
3147
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3148
-		} // traiter aussi les "texte_plus" de article_edit
3149
-		else {
3150
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3151
-				spip_desinfecte($t[$key], $deep);
3152
-			}
3153
-		}
3154
-	}
3144
+    foreach ($t as $key => $val) {
3145
+        if (is_string($t[$key])) {
3146
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3147
+        } // traiter aussi les "texte_plus" de article_edit
3148
+        else {
3149
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3150
+                spip_desinfecte($t[$key], $deep);
3151
+            }
3152
+        }
3153
+    }
3155 3154
 }
3156 3155
 
3157 3156
 /**
@@ -3164,64 +3163,64 @@  discard block
 block discarded – undo
3164 3163
  * @return string|0|false
3165 3164
 **/
3166 3165
 function verifier_visiteur() {
3167
-	@spip_initialisation_core(
3168
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3169
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3170
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3171
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3172
-	);
3173
-
3174
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3175
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3176
-	// Attention on separe bien session_nom et nom, pour eviter
3177
-	// les melanges entre donnees SQL et variables plus aleatoires
3178
-	$variables_session = ['session_nom', 'session_email'];
3179
-	foreach ($variables_session as $var) {
3180
-		if (_request($var) !== null) {
3181
-			$init = true;
3182
-			break;
3183
-		}
3184
-	}
3185
-	if (isset($init)) {
3186
-		#@spip_initialisation_suite();
3187
-		$session = charger_fonction('session', 'inc');
3188
-		$session();
3189
-		include_spip('inc/texte');
3190
-		foreach ($variables_session as $var) {
3191
-			if (($a = _request($var)) !== null) {
3192
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3193
-			}
3194
-		}
3195
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3196
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3197
-		}
3198
-		$session($GLOBALS['visiteur_session']);
3199
-
3200
-		return 0;
3201
-	}
3202
-
3203
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3204
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3205
-		$session = charger_fonction('session', 'inc');
3206
-		if ($session()) {
3207
-			return $GLOBALS['visiteur_session']['statut'];
3208
-		}
3209
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3210
-			include_spip('inc/auth');
3211
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3212
-		}
3213
-		if ($h) {
3214
-			$GLOBALS['visiteur_session'] = $h;
3215
-
3216
-			return $GLOBALS['visiteur_session']['statut'];
3217
-		}
3218
-	}
3219
-
3220
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3221
-	include_spip('inc/lang');
3222
-	utiliser_langue_visiteur();
3223
-
3224
-	return false;
3166
+    @spip_initialisation_core(
3167
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3168
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3169
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3170
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3171
+    );
3172
+
3173
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3174
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3175
+    // Attention on separe bien session_nom et nom, pour eviter
3176
+    // les melanges entre donnees SQL et variables plus aleatoires
3177
+    $variables_session = ['session_nom', 'session_email'];
3178
+    foreach ($variables_session as $var) {
3179
+        if (_request($var) !== null) {
3180
+            $init = true;
3181
+            break;
3182
+        }
3183
+    }
3184
+    if (isset($init)) {
3185
+        #@spip_initialisation_suite();
3186
+        $session = charger_fonction('session', 'inc');
3187
+        $session();
3188
+        include_spip('inc/texte');
3189
+        foreach ($variables_session as $var) {
3190
+            if (($a = _request($var)) !== null) {
3191
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3192
+            }
3193
+        }
3194
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3195
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3196
+        }
3197
+        $session($GLOBALS['visiteur_session']);
3198
+
3199
+        return 0;
3200
+    }
3201
+
3202
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3203
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3204
+        $session = charger_fonction('session', 'inc');
3205
+        if ($session()) {
3206
+            return $GLOBALS['visiteur_session']['statut'];
3207
+        }
3208
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3209
+            include_spip('inc/auth');
3210
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3211
+        }
3212
+        if ($h) {
3213
+            $GLOBALS['visiteur_session'] = $h;
3214
+
3215
+            return $GLOBALS['visiteur_session']['statut'];
3216
+        }
3217
+    }
3218
+
3219
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3220
+    include_spip('inc/lang');
3221
+    utiliser_langue_visiteur();
3222
+
3223
+    return false;
3225 3224
 }
3226 3225
 
3227 3226
 
@@ -3244,21 +3243,21 @@  discard block
 block discarded – undo
3244 3243
  *     - string Langue utilisée.
3245 3244
  **/
3246 3245
 function lang_select($lang = null) {
3247
-	static $pile_langues = [];
3248
-	if (!function_exists('changer_langue')) {
3249
-		include_spip('inc/lang');
3250
-	}
3251
-	if ($lang === null) {
3252
-		$lang = array_pop($pile_langues);
3253
-	} else {
3254
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3255
-	}
3256
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3257
-		return $lang;
3258
-	}
3259
-	changer_langue($lang);
3246
+    static $pile_langues = [];
3247
+    if (!function_exists('changer_langue')) {
3248
+        include_spip('inc/lang');
3249
+    }
3250
+    if ($lang === null) {
3251
+        $lang = array_pop($pile_langues);
3252
+    } else {
3253
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3254
+    }
3255
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3256
+        return $lang;
3257
+    }
3258
+    changer_langue($lang);
3260 3259
 
3261
-	return $lang;
3260
+    return $lang;
3262 3261
 }
3263 3262
 
3264 3263
 /**
@@ -3275,20 +3274,20 @@  discard block
 block discarded – undo
3275 3274
  *     Identifiant de la session
3276 3275
  **/
3277 3276
 function spip_session($force = false) {
3278
-	static $session;
3279
-	if ($force or !isset($session)) {
3280
-		$s = pipeline(
3281
-			'definir_session',
3282
-			$GLOBALS['visiteur_session']
3283
-				? serialize($GLOBALS['visiteur_session'])
3284
-				. '_' . @$_COOKIE['spip_session']
3285
-				: ''
3286
-		);
3287
-		$session = $s ? substr(md5($s), 0, 8) : '';
3288
-	}
3277
+    static $session;
3278
+    if ($force or !isset($session)) {
3279
+        $s = pipeline(
3280
+            'definir_session',
3281
+            $GLOBALS['visiteur_session']
3282
+                ? serialize($GLOBALS['visiteur_session'])
3283
+                . '_' . @$_COOKIE['spip_session']
3284
+                : ''
3285
+        );
3286
+        $session = $s ? substr(md5($s), 0, 8) : '';
3287
+    }
3289 3288
 
3290
-	#spip_log('session: '.$session);
3291
-	return $session;
3289
+    #spip_log('session: '.$session);
3290
+    return $session;
3292 3291
 }
3293 3292
 
3294 3293
 
@@ -3307,9 +3306,9 @@  discard block
 block discarded – undo
3307 3306
  *    Lien sur une icone d'aide
3308 3307
  **/
3309 3308
 function aider($aide = '', $distante = false) {
3310
-	$aider = charger_fonction('aide', 'inc', true);
3309
+    $aider = charger_fonction('aide', 'inc', true);
3311 3310
 
3312
-	return $aider ? $aider($aide, '', [], $distante) : '';
3311
+    return $aider ? $aider($aide, '', [], $distante) : '';
3313 3312
 }
3314 3313
 
3315 3314
 /**
@@ -3319,35 +3318,35 @@  discard block
 block discarded – undo
3319 3318
  */
3320 3319
 function exec_info_dist() {
3321 3320
 
3322
-	include_spip('inc/autoriser');
3323
-	if (autoriser('phpinfos')) {
3324
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3325
-		$cookies_backup = [];
3326
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3327
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3328
-		$mask = '******************************';
3329
-		foreach ($cookies_masques as $k) {
3330
-			if (!empty($_COOKIE[$k])) {
3331
-				$cookies_backup[$k] = $_COOKIE[$k];
3332
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3333
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3334
-				$_COOKIE[$k] = $mask;
3335
-			}
3336
-		}
3337
-		phpinfo();
3338
-		foreach ($cookies_backup as $k => $v) {
3339
-			$_COOKIE[$k] = $v;
3340
-		}
3341
-		foreach ($server_backup as $k => $v) {
3342
-			$_SERVER[$k] = $v;
3343
-		}
3344
-		foreach ($env_backup as $k => $v) {
3345
-			$_ENV[$k] = $v;
3346
-		}
3347
-	} else {
3348
-		include_spip('inc/filtres');
3349
-		sinon_interdire_acces();
3350
-	}
3321
+    include_spip('inc/autoriser');
3322
+    if (autoriser('phpinfos')) {
3323
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3324
+        $cookies_backup = [];
3325
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3326
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3327
+        $mask = '******************************';
3328
+        foreach ($cookies_masques as $k) {
3329
+            if (!empty($_COOKIE[$k])) {
3330
+                $cookies_backup[$k] = $_COOKIE[$k];
3331
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3332
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3333
+                $_COOKIE[$k] = $mask;
3334
+            }
3335
+        }
3336
+        phpinfo();
3337
+        foreach ($cookies_backup as $k => $v) {
3338
+            $_COOKIE[$k] = $v;
3339
+        }
3340
+        foreach ($server_backup as $k => $v) {
3341
+            $_SERVER[$k] = $v;
3342
+        }
3343
+        foreach ($env_backup as $k => $v) {
3344
+            $_ENV[$k] = $v;
3345
+        }
3346
+    } else {
3347
+        include_spip('inc/filtres');
3348
+        sinon_interdire_acces();
3349
+    }
3351 3350
 }
3352 3351
 
3353 3352
 /**
@@ -3367,13 +3366,13 @@  discard block
 block discarded – undo
3367 3366
  *     - string si $message à false.
3368 3367
  **/
3369 3368
 function erreur_squelette($message = '', $lieu = '') {
3370
-	$debusquer = charger_fonction('debusquer', 'public');
3371
-	if (is_array($lieu)) {
3372
-		include_spip('public/compiler');
3373
-		$lieu = reconstruire_contexte_compil($lieu);
3374
-	}
3369
+    $debusquer = charger_fonction('debusquer', 'public');
3370
+    if (is_array($lieu)) {
3371
+        include_spip('public/compiler');
3372
+        $lieu = reconstruire_contexte_compil($lieu);
3373
+    }
3375 3374
 
3376
-	return $debusquer($message, $lieu);
3375
+    return $debusquer($message, $lieu);
3377 3376
 }
3378 3377
 
3379 3378
 /**
@@ -3410,108 +3409,108 @@  discard block
 block discarded – undo
3410 3409
  *     - ou tableau d'information sur le squelette.
3411 3410
  */
3412 3411
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3413
-	if (!function_exists('evaluer_fond')) {
3414
-		include_spip('public/assembler');
3415
-	}
3416
-	// assurer la compat avec l'ancienne syntaxe
3417
-	// (trim etait le 3eme argument, par defaut a true)
3418
-	if (!is_array($options)) {
3419
-		$options = ['trim' => $options];
3420
-	}
3421
-	if (!isset($options['trim'])) {
3422
-		$options['trim'] = true;
3423
-	}
3424
-
3425
-	if (isset($contexte['connect'])) {
3426
-		$connect = $contexte['connect'];
3427
-		unset($contexte['connect']);
3428
-	}
3429
-
3430
-	$texte = '';
3431
-	$pages = [];
3432
-	$lang_select = '';
3433
-	if (!isset($options['etoile']) or !$options['etoile']) {
3434
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3435
-		if (!isset($contexte['lang'])) {
3436
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3437
-		}
3438
-
3439
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3440
-			$lang_select = lang_select($contexte['lang']);
3441
-		}
3442
-	}
3443
-
3444
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3445
-		$GLOBALS['_INC_PUBLIC'] = 0;
3446
-	}
3447
-
3448
-	$GLOBALS['_INC_PUBLIC']++;
3449
-
3450
-	// fix #4235
3451
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3452
-
3453
-
3454
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3455
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3456
-
3457
-		$page = evaluer_fond($f, $contexte, $connect);
3458
-		if ($page === '') {
3459
-			$c = $options['compil'] ?? '';
3460
-			$a = ['fichier' => $f];
3461
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3462
-			erreur_squelette($erreur, $c);
3463
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3464
-			$page = ['texte' => '', 'erreur' => $erreur];
3465
-		}
3466
-
3467
-		$page = pipeline('recuperer_fond', [
3468
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3469
-			'data' => $page
3470
-		]);
3471
-		if (isset($options['ajax']) and $options['ajax']) {
3472
-			if (!function_exists('encoder_contexte_ajax')) {
3473
-				include_spip('inc/filtres');
3474
-			}
3475
-			$page['texte'] = encoder_contexte_ajax(
3476
-				array_merge(
3477
-					$contexte,
3478
-					['fond' => $f],
3479
-					($connect ? ['connect' => $connect] : [])
3480
-				),
3481
-				'',
3482
-				$page['texte'],
3483
-				$options['ajax']
3484
-			);
3485
-		}
3486
-
3487
-		if (isset($options['raw']) and $options['raw']) {
3488
-			$pages[] = $page;
3489
-		} else {
3490
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3491
-		}
3492
-
3493
-		// contamination de la session appelante, pour les inclusions statiques
3494
-		if (isset($page['invalideurs']['session'])) {
3495
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3496
-		}
3497
-	}
3498
-
3499
-	// restaurer le sessionnement du contexte appelant,
3500
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3501
-	if (isset($cache_utilise_session_appelant)) {
3502
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3503
-	}
3504
-
3505
-	$GLOBALS['_INC_PUBLIC']--;
3506
-
3507
-	if ($lang_select) {
3508
-		lang_select();
3509
-	}
3510
-	if (isset($options['raw']) and $options['raw']) {
3511
-		return is_array($fond) ? $pages : reset($pages);
3512
-	} else {
3513
-		return $options['trim'] ? ltrim($texte) : $texte;
3514
-	}
3412
+    if (!function_exists('evaluer_fond')) {
3413
+        include_spip('public/assembler');
3414
+    }
3415
+    // assurer la compat avec l'ancienne syntaxe
3416
+    // (trim etait le 3eme argument, par defaut a true)
3417
+    if (!is_array($options)) {
3418
+        $options = ['trim' => $options];
3419
+    }
3420
+    if (!isset($options['trim'])) {
3421
+        $options['trim'] = true;
3422
+    }
3423
+
3424
+    if (isset($contexte['connect'])) {
3425
+        $connect = $contexte['connect'];
3426
+        unset($contexte['connect']);
3427
+    }
3428
+
3429
+    $texte = '';
3430
+    $pages = [];
3431
+    $lang_select = '';
3432
+    if (!isset($options['etoile']) or !$options['etoile']) {
3433
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3434
+        if (!isset($contexte['lang'])) {
3435
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3436
+        }
3437
+
3438
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3439
+            $lang_select = lang_select($contexte['lang']);
3440
+        }
3441
+    }
3442
+
3443
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3444
+        $GLOBALS['_INC_PUBLIC'] = 0;
3445
+    }
3446
+
3447
+    $GLOBALS['_INC_PUBLIC']++;
3448
+
3449
+    // fix #4235
3450
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3451
+
3452
+
3453
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3454
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3455
+
3456
+        $page = evaluer_fond($f, $contexte, $connect);
3457
+        if ($page === '') {
3458
+            $c = $options['compil'] ?? '';
3459
+            $a = ['fichier' => $f];
3460
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3461
+            erreur_squelette($erreur, $c);
3462
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3463
+            $page = ['texte' => '', 'erreur' => $erreur];
3464
+        }
3465
+
3466
+        $page = pipeline('recuperer_fond', [
3467
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3468
+            'data' => $page
3469
+        ]);
3470
+        if (isset($options['ajax']) and $options['ajax']) {
3471
+            if (!function_exists('encoder_contexte_ajax')) {
3472
+                include_spip('inc/filtres');
3473
+            }
3474
+            $page['texte'] = encoder_contexte_ajax(
3475
+                array_merge(
3476
+                    $contexte,
3477
+                    ['fond' => $f],
3478
+                    ($connect ? ['connect' => $connect] : [])
3479
+                ),
3480
+                '',
3481
+                $page['texte'],
3482
+                $options['ajax']
3483
+            );
3484
+        }
3485
+
3486
+        if (isset($options['raw']) and $options['raw']) {
3487
+            $pages[] = $page;
3488
+        } else {
3489
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3490
+        }
3491
+
3492
+        // contamination de la session appelante, pour les inclusions statiques
3493
+        if (isset($page['invalideurs']['session'])) {
3494
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3495
+        }
3496
+    }
3497
+
3498
+    // restaurer le sessionnement du contexte appelant,
3499
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3500
+    if (isset($cache_utilise_session_appelant)) {
3501
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3502
+    }
3503
+
3504
+    $GLOBALS['_INC_PUBLIC']--;
3505
+
3506
+    if ($lang_select) {
3507
+        lang_select();
3508
+    }
3509
+    if (isset($options['raw']) and $options['raw']) {
3510
+        return is_array($fond) ? $pages : reset($pages);
3511
+    } else {
3512
+        return $options['trim'] ? ltrim($texte) : $texte;
3513
+    }
3515 3514
 }
3516 3515
 
3517 3516
 /**
@@ -3521,7 +3520,7 @@  discard block
 block discarded – undo
3521 3520
  * @return string
3522 3521
  */
3523 3522
 function trouve_modele($nom) {
3524
-	return trouver_fond($nom, 'modeles/');
3523
+    return trouver_fond($nom, 'modeles/');
3525 3524
 }
3526 3525
 
3527 3526
 /**
@@ -3537,21 +3536,21 @@  discard block
 block discarded – undo
3537 3536
  * @return array|string
3538 3537
  */
3539 3538
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3540
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3541
-	if (!$pathinfo) {
3542
-		return $f;
3543
-	}
3544
-	// renvoyer un tableau detaille si $pathinfo==true
3545
-	$p = pathinfo($f);
3546
-	if (!isset($p['extension']) or !$p['extension']) {
3547
-		$p['extension'] = _EXTENSION_SQUELETTES;
3548
-	}
3549
-	if (!isset($p['extension']) or !$p['filename']) {
3550
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3551
-	}
3552
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3539
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3540
+    if (!$pathinfo) {
3541
+        return $f;
3542
+    }
3543
+    // renvoyer un tableau detaille si $pathinfo==true
3544
+    $p = pathinfo($f);
3545
+    if (!isset($p['extension']) or !$p['extension']) {
3546
+        $p['extension'] = _EXTENSION_SQUELETTES;
3547
+    }
3548
+    if (!isset($p['extension']) or !$p['filename']) {
3549
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3550
+    }
3551
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3553 3552
 
3554
-	return $p;
3553
+    return $p;
3555 3554
 }
3556 3555
 
3557 3556
 /**
@@ -3571,21 +3570,21 @@  discard block
 block discarded – undo
3571 3570
  *     Nom de l'exec, sinon chaîne vide.
3572 3571
  **/
3573 3572
 function tester_url_ecrire($nom) {
3574
-	static $exec = [];
3575
-	if (isset($exec[$nom])) {
3576
-		return $exec[$nom];
3577
-	}
3578
-	// tester si c'est une page en squelette
3579
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3580
-		return $exec[$nom] = 'fond';
3581
-	} // echafaudage d'un fond !
3582
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3583
-		return $exec[$nom] = 'fond';
3584
-	}
3585
-	// attention, il ne faut pas inclure l'exec ici
3586
-	// car sinon #URL_ECRIRE provoque des inclusions
3587
-	// et des define intrusifs potentiels
3588
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3573
+    static $exec = [];
3574
+    if (isset($exec[$nom])) {
3575
+        return $exec[$nom];
3576
+    }
3577
+    // tester si c'est une page en squelette
3578
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3579
+        return $exec[$nom] = 'fond';
3580
+    } // echafaudage d'un fond !
3581
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3582
+        return $exec[$nom] = 'fond';
3583
+    }
3584
+    // attention, il ne faut pas inclure l'exec ici
3585
+    // car sinon #URL_ECRIRE provoque des inclusions
3586
+    // et des define intrusifs potentiels
3587
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3589 3588
 }
3590 3589
 
3591 3590
 /**
@@ -3595,37 +3594,37 @@  discard block
 block discarded – undo
3595 3594
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3596 3595
  **/
3597 3596
 function html5_permis() {
3598
-	return (!defined('_VERSION_HTML')
3599
-		or _VERSION_HTML !== 'html4');
3597
+    return (!defined('_VERSION_HTML')
3598
+        or _VERSION_HTML !== 'html4');
3600 3599
 }
3601 3600
 
3602 3601
 /**
3603 3602
  * Lister les formats image acceptes par les lib et fonctions images
3604 3603
  */
3605 3604
 function formats_image_acceptables(?bool $gd = null, bool $svg_allowed = true): array {
3606
-	$formats = null;
3607
-	if (!is_null($gd)) {
3608
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3609
-		if (isset($GLOBALS['meta'][$config])) {
3610
-			$formats = $GLOBALS['meta'][$config];
3611
-			$formats = explode(',', $formats);
3612
-			$formats = array_filter($formats);
3613
-			$formats = array_map('trim', $formats);
3614
-		}
3615
-	}
3616
-	if (is_null($formats)) {
3617
-		include_spip('inc/filtres_images_lib_mini');
3618
-		$formats = _image_extensions_acceptees_en_entree();
3619
-	}
3620
-
3621
-	if ($svg_allowed) {
3622
-		if (!in_array('svg', $formats)) {
3623
-			$formats[] = 'svg';
3624
-		}
3625
-	} else {
3626
-		$formats = array_diff($formats, ['svg']);
3627
-	}
3628
-	return $formats;
3605
+    $formats = null;
3606
+    if (!is_null($gd)) {
3607
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3608
+        if (isset($GLOBALS['meta'][$config])) {
3609
+            $formats = $GLOBALS['meta'][$config];
3610
+            $formats = explode(',', $formats);
3611
+            $formats = array_filter($formats);
3612
+            $formats = array_map('trim', $formats);
3613
+        }
3614
+    }
3615
+    if (is_null($formats)) {
3616
+        include_spip('inc/filtres_images_lib_mini');
3617
+        $formats = _image_extensions_acceptees_en_entree();
3618
+    }
3619
+
3620
+    if ($svg_allowed) {
3621
+        if (!in_array('svg', $formats)) {
3622
+            $formats[] = 'svg';
3623
+        }
3624
+    } else {
3625
+        $formats = array_diff($formats, ['svg']);
3626
+    }
3627
+    return $formats;
3629 3628
 }
3630 3629
 
3631 3630
 /**
@@ -3634,20 +3633,20 @@  discard block
 block discarded – undo
3634 3633
  * @return array|bool
3635 3634
  */
3636 3635
 function spip_getimagesize($fichier) {
3637
-	if (!$imagesize = @getimagesize($fichier)) {
3638
-		include_spip('inc/svg');
3639
-		if ($attrs = svg_lire_attributs($fichier)) {
3640
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3641
-			$imagesize = [
3642
-				$width,
3643
-				$height,
3644
-				IMAGETYPE_SVG,
3645
-				"width=\"{$width}\" height=\"{$height}\"",
3646
-				'mime' => 'image/svg+xml'
3647
-			];
3648
-		}
3649
-	}
3650
-	return $imagesize;
3636
+    if (!$imagesize = @getimagesize($fichier)) {
3637
+        include_spip('inc/svg');
3638
+        if ($attrs = svg_lire_attributs($fichier)) {
3639
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3640
+            $imagesize = [
3641
+                $width,
3642
+                $height,
3643
+                IMAGETYPE_SVG,
3644
+                "width=\"{$width}\" height=\"{$height}\"",
3645
+                'mime' => 'image/svg+xml'
3646
+            ];
3647
+        }
3648
+    }
3649
+    return $imagesize;
3651 3650
 }
3652 3651
 
3653 3652
 /**
@@ -3661,19 +3660,19 @@  discard block
 block discarded – undo
3661 3660
  * @param string $statut
3662 3661
  */
3663 3662
 function avertir_auteurs($nom, $message, $statut = '') {
3664
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3665
-	if (
3666
-		!$alertes
3667
-		or !is_array($alertes = unserialize($alertes))
3668
-	) {
3669
-		$alertes = [];
3670
-	}
3663
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3664
+    if (
3665
+        !$alertes
3666
+        or !is_array($alertes = unserialize($alertes))
3667
+    ) {
3668
+        $alertes = [];
3669
+    }
3671 3670
 
3672
-	if (!isset($alertes[$statut])) {
3673
-		$alertes[$statut] = [];
3674
-	}
3675
-	$alertes[$statut][$nom] = $message;
3676
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3671
+    if (!isset($alertes[$statut])) {
3672
+        $alertes[$statut] = [];
3673
+    }
3674
+    $alertes[$statut][$nom] = $message;
3675
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3677 3676
 }
3678 3677
 
3679 3678
 /**
@@ -3687,10 +3686,10 @@  discard block
 block discarded – undo
3687 3686
  * @return string|string[]
3688 3687
  */
3689 3688
 function spip_sanitize_classname($classes) {
3690
-	if (is_array($classes)) {
3691
-		return array_map('spip_sanitize_classname', $classes);
3692
-	}
3693
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3689
+    if (is_array($classes)) {
3690
+        return array_map('spip_sanitize_classname', $classes);
3691
+    }
3692
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3694 3693
 }
3695 3694
 
3696 3695
 
@@ -3715,32 +3714,32 @@  discard block
 block discarded – undo
3715 3714
  *    Avec operateur : bool.
3716 3715
  **/
3717 3716
 function spip_version_compare($v1, $v2, $op = null) {
3718
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3719
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3720
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3721
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3722
-
3723
-	$v1 = explode('.', $v1);
3724
-	$v2 = explode('.', $v2);
3725
-	// $v1 est toujours une version, donc sans etoile
3726
-	while (count($v1) < count($v2)) {
3727
-		$v1[] = '0';
3728
-	}
3729
-
3730
-	// $v2 peut etre une borne, donc accepte l'etoile
3731
-	$etoile = false;
3732
-	foreach ($v1 as $k => $v) {
3733
-		if (!isset($v2[$k])) {
3734
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3735
-		} else {
3736
-			if ($v2[$k] == '*') {
3737
-				$etoile = true;
3738
-				$v2[$k] = $v;
3739
-			}
3740
-		}
3741
-	}
3742
-	$v1 = implode('.', $v1);
3743
-	$v2 = implode('.', $v2);
3744
-
3745
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3717
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3718
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3719
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3720
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3721
+
3722
+    $v1 = explode('.', $v1);
3723
+    $v2 = explode('.', $v2);
3724
+    // $v1 est toujours une version, donc sans etoile
3725
+    while (count($v1) < count($v2)) {
3726
+        $v1[] = '0';
3727
+    }
3728
+
3729
+    // $v2 peut etre une borne, donc accepte l'etoile
3730
+    $etoile = false;
3731
+    foreach ($v1 as $k => $v) {
3732
+        if (!isset($v2[$k])) {
3733
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3734
+        } else {
3735
+            if ($v2[$k] == '*') {
3736
+                $etoile = true;
3737
+                $v2[$k] = $v;
3738
+            }
3739
+        }
3740
+    }
3741
+    $v1 = implode('.', $v1);
3742
+    $v2 = implode('.', $v2);
3743
+
3744
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3746 3745
 }
Please login to merge, or discard this patch.