Completed
Push — master ( 3c0e7c...2db0be )
by cam
01:03
created
ecrire/public/quete.php 1 patch
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * @return array|bool|null
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36
-	return sql_getfetsel(
37
-		'virtuel',
38
-		'spip_articles',
39
-		['id_article=' . intval($id_article), "statut='publie'"],
40
-		'',
41
-		'',
42
-		'',
43
-		'',
44
-		$connect
45
-	);
36
+    return sql_getfetsel(
37
+        'virtuel',
38
+        'spip_articles',
39
+        ['id_article=' . intval($id_article), "statut='publie'"],
40
+        '',
41
+        '',
42
+        '',
43
+        '',
44
+        $connect
45
+    );
46 46
 }
47 47
 
48 48
 /**
@@ -57,41 +57,41 @@  discard block
 block discarded – undo
57 57
  * @return array
58 58
  */
59 59
 function quete_parent_lang($table, $id, string $connect = '') {
60
-	static $cache_quete = [];
61
-
62
-	if (!isset($cache_quete[$connect][$table][$id])) {
63
-		if (!isset($cache_quete[$connect][$table]['_select'])) {
64
-			$trouver_table = charger_fonction('trouver_table', 'base');
65
-			if (
66
-				!$desc = $trouver_table(
67
-					$table,
68
-					$connect
69
-				) or !isset($desc['field']['id_rubrique'])
70
-			) {
71
-				// pas de parent rubrique, on passe
72
-				$cache_quete[$connect][$table]['_select'] = false;
73
-			} else {
74
-				$select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
-				$select .= isset($desc['field']['lang']) ? ', lang' : '';
76
-				$cache_quete[$connect][$table]['_select'] = $select;
77
-				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
-			}
79
-		}
80
-		if ($cache_quete[$connect][$table]['_select']) {
81
-			$cache_quete[$connect][$table][$id] = sql_fetsel(
82
-				$cache_quete[$connect][$table]['_select'],
83
-				$table,
84
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
-				'',
86
-				'',
87
-				'',
88
-				'',
89
-				$connect
90
-			);
91
-		}
92
-	}
93
-
94
-	return $cache_quete[$connect][$table][$id] ?? null;
60
+    static $cache_quete = [];
61
+
62
+    if (!isset($cache_quete[$connect][$table][$id])) {
63
+        if (!isset($cache_quete[$connect][$table]['_select'])) {
64
+            $trouver_table = charger_fonction('trouver_table', 'base');
65
+            if (
66
+                !$desc = $trouver_table(
67
+                    $table,
68
+                    $connect
69
+                ) or !isset($desc['field']['id_rubrique'])
70
+            ) {
71
+                // pas de parent rubrique, on passe
72
+                $cache_quete[$connect][$table]['_select'] = false;
73
+            } else {
74
+                $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
+                $select .= isset($desc['field']['lang']) ? ', lang' : '';
76
+                $cache_quete[$connect][$table]['_select'] = $select;
77
+                $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
+            }
79
+        }
80
+        if ($cache_quete[$connect][$table]['_select']) {
81
+            $cache_quete[$connect][$table][$id] = sql_fetsel(
82
+                $cache_quete[$connect][$table]['_select'],
83
+                $table,
84
+                $cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
+                '',
86
+                '',
87
+                '',
88
+                '',
89
+                $connect
90
+            );
91
+        }
92
+    }
93
+
94
+    return $cache_quete[$connect][$table][$id] ?? null;
95 95
 }
96 96
 
97 97
 
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
  * @return int
109 109
  */
110 110
 function quete_parent($id_rubrique, string $connect = '') {
111
-	if (!$id_rubrique = intval($id_rubrique)) {
112
-		return 0;
113
-	}
114
-	$id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
-	return $id_parent ? $id_parent['id_parent'] : 0;
111
+    if (!$id_rubrique = intval($id_rubrique)) {
112
+        return 0;
113
+    }
114
+    $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
+    return $id_parent ? $id_parent['id_parent'] : 0;
116 116
 }
117 117
 
118 118
 /**
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
  * @return int
129 129
  */
130 130
 function quete_rubrique($id_article, $serveur) {
131
-	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
131
+    $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
132 132
 
133
-	return $id_parent['id_rubrique'];
133
+    return $id_parent['id_rubrique'];
134 134
 }
135 135
 
136 136
 
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
  * @return int
145 145
  */
146 146
 function quete_profondeur($id, string $connect = '') {
147
-	$n = 0;
148
-	while ($id) {
149
-		$n++;
150
-		$id = quete_parent($id, $connect);
151
-	}
147
+    $n = 0;
148
+    while ($id) {
149
+        $n++;
150
+        $id = quete_parent($id, $connect);
151
+    }
152 152
 
153
-	return $n;
153
+    return $n;
154 154
 }
155 155
 
156 156
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  *     Morceau de la requête SQL testant la date
167 167
  */
168 168
 function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
169
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
-		return '1=1';
171
-	}
172
-
173
-	return
174
-		(isset($GLOBALS['meta']['date_prochain_postdate'])
175
-			and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
-			: '1=1';
169
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
+        return '1=1';
171
+    }
172
+
173
+    return
174
+        (isset($GLOBALS['meta']['date_prochain_postdate'])
175
+            and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
+            ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
+            : '1=1';
178 178
 }
179 179
 
180 180
 
@@ -194,101 +194,101 @@  discard block
 block discarded – undo
194 194
  * @return array|string
195 195
  */
196 196
 function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
197
-	static $cond = [];
198
-	$key = func_get_args();
199
-	$key = implode('-', $key);
200
-	if (isset($cond[$key])) {
201
-		return $cond[$key];
202
-	}
203
-
204
-	$liste_statuts = $publie;
205
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
-		$liste_statuts = $previsu;
207
-	}
208
-	$not = false;
209
-	if (strncmp($liste_statuts, '!', 1) == 0) {
210
-		$not = true;
211
-		$liste_statuts = substr($liste_statuts, 1);
212
-	}
213
-	// '' => ne rien afficher, '!'=> ne rien filtrer
214
-	if (!strlen($liste_statuts)) {
215
-		return $cond[$key] = ($not ? '1=1' : '0=1');
216
-	}
217
-
218
-	$liste_statuts = explode(',', $liste_statuts);
219
-	$where = [];
220
-	foreach ($liste_statuts as $k => $v) {
221
-		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
-		// a ceux de l'auteur identifie
223
-		if (strpos($v, '/') !== false) {
224
-			$v = explode('/', $v);
225
-			$filtre = end($v);
226
-			$v = reset($v);
227
-			$v = preg_replace(',\W,', '', $v);
228
-			if (
229
-				$filtre == 'auteur'
230
-				and (strpos($mstatut, '.') !== false)
231
-				and $objet = explode('.', $mstatut)
232
-				and $id_table = reset($objet)
233
-				and $objet = objet_type($id_table)
234
-			) {
235
-				$w = "$mstatut<>" . sql_quote($v);
236
-
237
-				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
-				// sinon l’auteur en session
239
-				include_spip('inc/securiser_action');
240
-				if ($desc = decrire_token_previsu()) {
241
-					$id_auteur = $desc['id_auteur'];
242
-				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
-					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
-				} else {
245
-					$id_auteur = null;
246
-				}
247
-
248
-				// dans ce cas (admin en general), pas de filtrage sur ce statut
249
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
-					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
-					if (!$id_auteur) {
252
-						$where[] = $w;
253
-					} else {
254
-						$primary = id_table_objet($objet);
255
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
-							'ssss.id_objet',
257
-							'spip_auteurs_liens AS ssss',
258
-							'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
-							'',
260
-							'',
261
-							'',
262
-							'',
263
-							$serveur
264
-						) . '))';
265
-					}
266
-				}
267
-			} // ignorer ce statut si on ne sait pas comment le filtrer
268
-			else {
269
-				$v = '';
270
-			}
271
-		}
272
-		// securite
273
-		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
-	}
275
-	$liste_statuts = array_filter($liste_statuts);
276
-	if (count($liste_statuts) == 1) {
277
-		$where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
-	} else {
279
-		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
-	}
281
-
282
-	while (count($where) > 1) {
283
-		$and = ['AND', array_pop($where), array_pop($where)];
284
-		$where[] = $and;
285
-	}
286
-	$cond[$key] = reset($where);
287
-	if ($not) {
288
-		$cond[$key] = ['NOT', $cond[$key]];
289
-	}
290
-
291
-	return $cond[$key];
197
+    static $cond = [];
198
+    $key = func_get_args();
199
+    $key = implode('-', $key);
200
+    if (isset($cond[$key])) {
201
+        return $cond[$key];
202
+    }
203
+
204
+    $liste_statuts = $publie;
205
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
+        $liste_statuts = $previsu;
207
+    }
208
+    $not = false;
209
+    if (strncmp($liste_statuts, '!', 1) == 0) {
210
+        $not = true;
211
+        $liste_statuts = substr($liste_statuts, 1);
212
+    }
213
+    // '' => ne rien afficher, '!'=> ne rien filtrer
214
+    if (!strlen($liste_statuts)) {
215
+        return $cond[$key] = ($not ? '1=1' : '0=1');
216
+    }
217
+
218
+    $liste_statuts = explode(',', $liste_statuts);
219
+    $where = [];
220
+    foreach ($liste_statuts as $k => $v) {
221
+        // filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
+        // a ceux de l'auteur identifie
223
+        if (strpos($v, '/') !== false) {
224
+            $v = explode('/', $v);
225
+            $filtre = end($v);
226
+            $v = reset($v);
227
+            $v = preg_replace(',\W,', '', $v);
228
+            if (
229
+                $filtre == 'auteur'
230
+                and (strpos($mstatut, '.') !== false)
231
+                and $objet = explode('.', $mstatut)
232
+                and $id_table = reset($objet)
233
+                and $objet = objet_type($id_table)
234
+            ) {
235
+                $w = "$mstatut<>" . sql_quote($v);
236
+
237
+                // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
+                // sinon l’auteur en session
239
+                include_spip('inc/securiser_action');
240
+                if ($desc = decrire_token_previsu()) {
241
+                    $id_auteur = $desc['id_auteur'];
242
+                } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
+                    $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
+                } else {
245
+                    $id_auteur = null;
246
+                }
247
+
248
+                // dans ce cas (admin en general), pas de filtrage sur ce statut
249
+                if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
+                    // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
+                    if (!$id_auteur) {
252
+                        $where[] = $w;
253
+                    } else {
254
+                        $primary = id_table_objet($objet);
255
+                        $where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
+                            'ssss.id_objet',
257
+                            'spip_auteurs_liens AS ssss',
258
+                            'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
+                            '',
260
+                            '',
261
+                            '',
262
+                            '',
263
+                            $serveur
264
+                        ) . '))';
265
+                    }
266
+                }
267
+            } // ignorer ce statut si on ne sait pas comment le filtrer
268
+            else {
269
+                $v = '';
270
+            }
271
+        }
272
+        // securite
273
+        $liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
+    }
275
+    $liste_statuts = array_filter($liste_statuts);
276
+    if (count($liste_statuts) == 1) {
277
+        $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
+    } else {
279
+        $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
+    }
281
+
282
+    while (count($where) > 1) {
283
+        $and = ['AND', array_pop($where), array_pop($where)];
284
+        $where[] = $and;
285
+    }
286
+    $cond[$key] = reset($where);
287
+    if ($not) {
288
+        $cond[$key] = ['NOT', $cond[$key]];
289
+    }
290
+
291
+    return $cond[$key];
292 292
 }
293 293
 
294 294
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  * @return array|bool|null
300 300
  */
301 301
 function quete_fichier($id_document, $serveur = '') {
302
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
302
+    return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
303 303
 }
304 304
 
305 305
 /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
  * @return array|bool
311 311
  */
312 312
 function quete_document($id_document, $serveur = '') {
313
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
313
+    return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
314 314
 }
315 315
 
316 316
 /**
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @return array|bool|null
322 322
  */
323 323
 function quete_meta($nom, $serveur) {
324
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
324
+    return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
325 325
 }
326 326
 
327 327
 /**
@@ -347,66 +347,66 @@  discard block
 block discarded – undo
347 347
  *     Retourne soit un tableau, soit le chemin du fichier.
348 348
  */
349 349
 function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
350
-	include_spip('base/objets');
351
-	$nom = strtolower($onoff);
352
-
353
-	$cle_objet = id_table_objet($cle_objet);
354
-
355
-	while (1) {
356
-		$objet = objet_type($cle_objet);
357
-
358
-		$on = quete_logo_objet($id, $objet, $nom);
359
-
360
-		if ($on) {
361
-			if ($flag) {
362
-				return basename($on['chemin']);
363
-			} else {
364
-				$taille = @spip_getimagesize($on['chemin']);
365
-
366
-				// Si on a déjà demandé un survol directement ($onoff = off)
367
-				// ou qu'on a demandé uniquement le normal ($onoff = on)
368
-				// alors on ne cherche pas du tout le survol ici
369
-				if ($onoff != 'ON') {
370
-					$off = '';
371
-				} else {
372
-					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
-					$off = quete_logo_objet($id, $objet, 'off');
374
-				}
375
-
376
-				// on retourne une url du type IMG/artonXX?timestamp
377
-				// qui permet de distinguer le changement de logo
378
-				// et placer un expire sur le dossier IMG/
379
-				$res = [
380
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
-					(!$taille ? '' : (' ' . $taille[3]))
383
-				];
384
-				$res['src'] = $res[0];
385
-				$res['logo_on'] = $res[0];
386
-				$res['logo_off'] = $res[1];
387
-				$res['width'] = ($taille ? $taille[0] : '');
388
-				$res['height'] = ($taille ? $taille[1] : '');
389
-
390
-				return $res;
391
-			}
392
-		} else {
393
-			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
-				return '';
395
-			} else {
396
-				if ($id_rubrique) {
397
-					$cle_objet = 'id_rubrique';
398
-					$id = $id_rubrique;
399
-					$id_rubrique = 0;
400
-				} else {
401
-					if ($id and $cle_objet == 'id_rubrique') {
402
-						$id = quete_parent($id);
403
-					} else {
404
-						return '';
405
-					}
406
-				}
407
-			}
408
-		}
409
-	}
350
+    include_spip('base/objets');
351
+    $nom = strtolower($onoff);
352
+
353
+    $cle_objet = id_table_objet($cle_objet);
354
+
355
+    while (1) {
356
+        $objet = objet_type($cle_objet);
357
+
358
+        $on = quete_logo_objet($id, $objet, $nom);
359
+
360
+        if ($on) {
361
+            if ($flag) {
362
+                return basename($on['chemin']);
363
+            } else {
364
+                $taille = @spip_getimagesize($on['chemin']);
365
+
366
+                // Si on a déjà demandé un survol directement ($onoff = off)
367
+                // ou qu'on a demandé uniquement le normal ($onoff = on)
368
+                // alors on ne cherche pas du tout le survol ici
369
+                if ($onoff != 'ON') {
370
+                    $off = '';
371
+                } else {
372
+                    // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
+                    $off = quete_logo_objet($id, $objet, 'off');
374
+                }
375
+
376
+                // on retourne une url du type IMG/artonXX?timestamp
377
+                // qui permet de distinguer le changement de logo
378
+                // et placer un expire sur le dossier IMG/
379
+                $res = [
380
+                    $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
+                    ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
+                    (!$taille ? '' : (' ' . $taille[3]))
383
+                ];
384
+                $res['src'] = $res[0];
385
+                $res['logo_on'] = $res[0];
386
+                $res['logo_off'] = $res[1];
387
+                $res['width'] = ($taille ? $taille[0] : '');
388
+                $res['height'] = ($taille ? $taille[1] : '');
389
+
390
+                return $res;
391
+            }
392
+        } else {
393
+            if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
+                return '';
395
+            } else {
396
+                if ($id_rubrique) {
397
+                    $cle_objet = 'id_rubrique';
398
+                    $id = $id_rubrique;
399
+                    $id_rubrique = 0;
400
+                } else {
401
+                    if ($id and $cle_objet == 'id_rubrique') {
402
+                        $id = quete_parent($id);
403
+                    } else {
404
+                        return '';
405
+                    }
406
+                }
407
+            }
408
+        }
409
+    }
410 410
 }
411 411
 
412 412
 /**
@@ -420,37 +420,37 @@  discard block
 block discarded – undo
420 420
  * 		"on" ou "off" suivant le logo normal ou survol
421 421
  **/
422 422
 function quete_logo_objet($id_objet, $objet, $mode) {
423
-	static $chercher_logo;
424
-	if (is_null($chercher_logo)) {
425
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
426
-	}
427
-	$cle_objet = id_table_objet($objet);
428
-
429
-	// On cherche pas la méthode classique
430
-	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
-	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
-	if (!empty($infos_logo)) {
433
-		$infos_logo = [
434
-			'chemin' => $infos_logo[0],
435
-			'timestamp' => $infos_logo[4],
436
-		];
437
-	}
438
-
439
-	// On passe cette recherche de logo dans un pipeline
440
-	$infos_logo = pipeline(
441
-		'quete_logo_objet',
442
-		[
443
-			'args' => [
444
-				'id_objet' => $id_objet,
445
-				'objet' => $objet,
446
-				'cle_objet' => $cle_objet,
447
-				'mode' => $mode,
448
-			],
449
-			'data' => $infos_logo,
450
-		]
451
-	);
452
-
453
-	return $infos_logo;
423
+    static $chercher_logo;
424
+    if (is_null($chercher_logo)) {
425
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
426
+    }
427
+    $cle_objet = id_table_objet($objet);
428
+
429
+    // On cherche pas la méthode classique
430
+    $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
+    // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
+    if (!empty($infos_logo)) {
433
+        $infos_logo = [
434
+            'chemin' => $infos_logo[0],
435
+            'timestamp' => $infos_logo[4],
436
+        ];
437
+    }
438
+
439
+    // On passe cette recherche de logo dans un pipeline
440
+    $infos_logo = pipeline(
441
+        'quete_logo_objet',
442
+        [
443
+            'args' => [
444
+                'id_objet' => $id_objet,
445
+                'objet' => $objet,
446
+                'cle_objet' => $cle_objet,
447
+                'mode' => $mode,
448
+            ],
449
+            'data' => $infos_logo,
450
+        ]
451
+    );
452
+
453
+    return $infos_logo;
454 454
 }
455 455
 
456 456
 /**
@@ -463,25 +463,25 @@  discard block
 block discarded – undo
463 463
  * @return bool|string
464 464
  */
465 465
 function quete_logo_file($row, $connect = null) {
466
-	include_spip('inc/documents');
467
-	$logo = vignette_logo_document($row, $connect);
468
-	if (!$logo) {
469
-		$logo = image_du_document($row, $connect);
470
-	}
471
-	if (!$logo) {
472
-		$f = charger_fonction('vignette', 'inc');
473
-		$logo = $f($row['extension'], false);
474
-	}
475
-	// si c'est une vignette type doc, la renvoyer direct
476
-	if (
477
-		strcmp($logo, _DIR_PLUGINS) == 0
478
-		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
-	) {
481
-		return $logo;
482
-	}
483
-
484
-	return get_spip_doc($logo);
466
+    include_spip('inc/documents');
467
+    $logo = vignette_logo_document($row, $connect);
468
+    if (!$logo) {
469
+        $logo = image_du_document($row, $connect);
470
+    }
471
+    if (!$logo) {
472
+        $f = charger_fonction('vignette', 'inc');
473
+        $logo = $f($row['extension'], false);
474
+    }
475
+    // si c'est une vignette type doc, la renvoyer direct
476
+    if (
477
+        strcmp($logo, _DIR_PLUGINS) == 0
478
+        or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
+        or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
+    ) {
481
+        return $logo;
482
+    }
483
+
484
+    return get_spip_doc($logo);
485 485
 }
486 486
 
487 487
 /**
@@ -509,20 +509,20 @@  discard block
 block discarded – undo
509 509
  */
510 510
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') {
511 511
 
512
-	include_spip('inc/documents');
513
-	$logo = '';
514
-	if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
-		$logo = vignette_logo_document($row, $connect);
516
-	}
517
-	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
-	if ($mode_logo == 'vignette' and !$logo) {
519
-		return '';
520
-	}
521
-	if ($mode_logo == 'icone') {
522
-		$row['fichier'] = '';
523
-	}
524
-
525
-	return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
512
+    include_spip('inc/documents');
513
+    $logo = '';
514
+    if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
+        $logo = vignette_logo_document($row, $connect);
516
+    }
517
+    // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
+    if ($mode_logo == 'vignette' and !$logo) {
519
+        return '';
520
+    }
521
+    if ($mode_logo == 'icone') {
522
+        $row['fichier'] = '';
523
+    }
524
+
525
+    return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
526 526
 }
527 527
 
528 528
 /**
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function quete_html_logo($logo, $align, $lien) {
536 536
 
537
-	if (!is_array($logo)) {
538
-		return '';
539
-	}
540
-
541
-	$contexte = [];
542
-	foreach ($logo as $k => $v) {
543
-		if (!is_numeric($k)) {
544
-			$contexte[$k] = $v;
545
-		}
546
-	}
547
-	$contexte['align'] = $align;
548
-	$contexte['lien'] = $lien;
549
-	return recuperer_fond('modeles/logo', $contexte);
537
+    if (!is_array($logo)) {
538
+        return '';
539
+    }
540
+
541
+    $contexte = [];
542
+    foreach ($logo as $k => $v) {
543
+        if (!is_numeric($k)) {
544
+            $contexte[$k] = $v;
545
+        }
546
+    }
547
+    $contexte['align'] = $align;
548
+    $contexte['lien'] = $lien;
549
+    return recuperer_fond('modeles/logo', $contexte);
550 550
 }
551 551
 
552 552
 /**
@@ -560,14 +560,14 @@  discard block
 block discarded – undo
560 560
  * @return string|false
561 561
  */
562 562
 function document_spip_externe($fichier, $connect) {
563
-	if ($connect) {
564
-		$site = quete_meta('adresse_site', $connect);
565
-		if ($site) {
566
-			$dir = quete_meta('dir_img', $connect);
567
-			return "$site/$dir$fichier";
568
-		}
569
-	}
570
-	return false;
563
+    if ($connect) {
564
+        $site = quete_meta('adresse_site', $connect);
565
+        if ($site) {
566
+            $dir = quete_meta('dir_img', $connect);
567
+            return "$site/$dir$fichier";
568
+        }
569
+    }
570
+    return false;
571 571
 }
572 572
 
573 573
 /**
@@ -581,23 +581,23 @@  discard block
 block discarded – undo
581 581
  */
582 582
 function vignette_logo_document($row, string $connect = '') {
583 583
 
584
-	if (!$row or empty($row['id_vignette'])) {
585
-		return '';
586
-	}
587
-	$fichier = quete_fichier($row['id_vignette'], $connect);
588
-	if ($url = document_spip_externe($fichier, $connect)) {
589
-		return $url;
590
-	}
591
-
592
-	$f = get_spip_doc($fichier);
593
-	if ($f and @file_exists($f)) {
594
-		return $f;
595
-	}
596
-	if ($row['mode'] !== 'vignette') {
597
-		return '';
598
-	}
599
-
600
-	return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect);
584
+    if (!$row or empty($row['id_vignette'])) {
585
+        return '';
586
+    }
587
+    $fichier = quete_fichier($row['id_vignette'], $connect);
588
+    if ($url = document_spip_externe($fichier, $connect)) {
589
+        return $url;
590
+    }
591
+
592
+    $f = get_spip_doc($fichier);
593
+    if ($f and @file_exists($f)) {
594
+        return $f;
595
+    }
596
+    if ($row['mode'] !== 'vignette') {
597
+        return '';
598
+    }
599
+
600
+    return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect);
601 601
 }
602 602
 
603 603
 /**
@@ -613,66 +613,66 @@  discard block
 block discarded – undo
613 613
  * @return bool|string
614 614
  */
615 615
 function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') {
616
-	static $exposer = [];
617
-
618
-	// Que faut-il exposer ? Tous les elements de $reference
619
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
620
-	// qu'une fois (par squelette) et on conserve le resultat
621
-	// en static.
622
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
-		$principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
625
-		// il n'est donc pas utile
626
-		$parent = 0;
627
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
-			$enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
-			if (isset($enfants[$type])) {
630
-				foreach ($enfants[$type] as $t) {
631
-					if (
632
-						isset($reference[$t])
633
-						// cas de la reference donnee dynamiquement par la pagination
634
-						or isset($reference["@$t"])
635
-					) {
636
-						$type = $t;
637
-						$principal = $reference[$type] ?? $reference["@$type"];
638
-						continue;
639
-					}
640
-				}
641
-			}
642
-		}
643
-		$exposer[$m][$type] = [];
644
-		if ($principal) {
645
-			$principaux = is_array($principal) ? $principal : [$principal];
646
-			foreach ($principaux as $principal) {
647
-				$exposer[$m][$type][$principal] = true;
648
-				if ($type == 'id_mot') {
649
-					if (!$parent) {
650
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
-					}
652
-					if ($parent) {
653
-						$exposer[$m]['id_groupe'][$parent] = true;
654
-					}
655
-				} else {
656
-					if ($type != 'id_groupe') {
657
-						if (!$parent) {
658
-							if ($type == 'id_rubrique') {
659
-								$parent = $principal;
660
-							}
661
-							if ($type == 'id_article') {
662
-								$parent = quete_rubrique($principal, $connect);
663
-							}
664
-						}
665
-						do {
666
-							$exposer[$m]['id_rubrique'][$parent] = true;
667
-						} while ($parent = quete_parent($parent, $connect));
668
-					}
669
-				}
670
-			}
671
-		}
672
-	}
673
-
674
-	// And the winner is...
675
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
616
+    static $exposer = [];
617
+
618
+    // Que faut-il exposer ? Tous les elements de $reference
619
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
620
+    // qu'une fois (par squelette) et on conserve le resultat
621
+    // en static.
622
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
+        $principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
625
+        // il n'est donc pas utile
626
+        $parent = 0;
627
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
+            $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
+            if (isset($enfants[$type])) {
630
+                foreach ($enfants[$type] as $t) {
631
+                    if (
632
+                        isset($reference[$t])
633
+                        // cas de la reference donnee dynamiquement par la pagination
634
+                        or isset($reference["@$t"])
635
+                    ) {
636
+                        $type = $t;
637
+                        $principal = $reference[$type] ?? $reference["@$type"];
638
+                        continue;
639
+                    }
640
+                }
641
+            }
642
+        }
643
+        $exposer[$m][$type] = [];
644
+        if ($principal) {
645
+            $principaux = is_array($principal) ? $principal : [$principal];
646
+            foreach ($principaux as $principal) {
647
+                $exposer[$m][$type][$principal] = true;
648
+                if ($type == 'id_mot') {
649
+                    if (!$parent) {
650
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
+                    }
652
+                    if ($parent) {
653
+                        $exposer[$m]['id_groupe'][$parent] = true;
654
+                    }
655
+                } else {
656
+                    if ($type != 'id_groupe') {
657
+                        if (!$parent) {
658
+                            if ($type == 'id_rubrique') {
659
+                                $parent = $principal;
660
+                            }
661
+                            if ($type == 'id_article') {
662
+                                $parent = quete_rubrique($principal, $connect);
663
+                            }
664
+                        }
665
+                        do {
666
+                            $exposer[$m]['id_rubrique'][$parent] = true;
667
+                        } while ($parent = quete_parent($parent, $connect));
668
+                    }
669
+                }
670
+            }
671
+        }
672
+    }
673
+
674
+    // And the winner is...
675
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
676 676
 }
677 677
 
678 678
 /**
@@ -687,23 +687,23 @@  discard block
 block discarded – undo
687 687
  * @return int
688 688
  */
689 689
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
690
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
691
-	// ou composee, mais verifions
692
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
693
-		return 0;
694
-	}
695
-
696
-	$pos = 0;
697
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
-		$pos++;
699
-	}
700
-	// si on a pas trouve
701
-	if (!$row or $row[$primary] != $valeur) {
702
-		return 0;
703
-	}
704
-
705
-	// sinon, calculer le bon numero de page
706
-	return floor($pos / $pas) * $pas;
690
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
691
+    // ou composee, mais verifions
692
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
693
+        return 0;
694
+    }
695
+
696
+    $pos = 0;
697
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
+        $pos++;
699
+    }
700
+    // si on a pas trouve
701
+    if (!$row or $row[$primary] != $valeur) {
702
+        return 0;
703
+    }
704
+
705
+    // sinon, calculer le bon numero de page
706
+    return floor($pos / $pas) * $pas;
707 707
 }
708 708
 
709 709
 /**
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
  * @return boolean
715 715
  */
716 716
 function is_whereable($value): bool {
717
-	if (is_array($value) && count($value)) {
718
-		return true;
719
-	}
720
-	if (is_scalar($value) && strlen($value)) {
721
-		return true;
722
-	}
723
-	return false;
717
+    if (is_array($value) && count($value)) {
718
+        return true;
719
+    }
720
+    if (is_scalar($value) && strlen($value)) {
721
+        return true;
722
+    }
723
+    return false;
724 724
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2262 added lines, -2263 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,66 +48,66 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = [];
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
83
-		// si le fichier truc/machin/nom.php n'existe pas,
84
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
-	) {
87
-		include_spip(substr($dossier, 0, -1));
88
-	}
89
-	if (function_exists($f)) {
90
-		return $f;
91
-	}
92
-	if (function_exists($g)) {
93
-		return $g;
94
-	}
95
-
96
-	if ($continue) {
97
-		return $echecs[$f] = false;
98
-	}
99
-
100
-	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
102
-		($inc ? '' : " (fichier $d absent de $dossier)"));
103
-
104
-	include_spip('inc/minipres');
105
-	echo minipres(
106
-		_T('forum_titre_erreur'),
107
-		_T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
-		['all_inline' => true,'status' => 404]
109
-	);
110
-	exit;
51
+    static $echecs = [];
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (
82
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
83
+        // si le fichier truc/machin/nom.php n'existe pas,
84
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
+    ) {
87
+        include_spip(substr($dossier, 0, -1));
88
+    }
89
+    if (function_exists($f)) {
90
+        return $f;
91
+    }
92
+    if (function_exists($g)) {
93
+        return $g;
94
+    }
95
+
96
+    if ($continue) {
97
+        return $echecs[$f] = false;
98
+    }
99
+
100
+    // Echec : message d'erreur
101
+    spip_log("fonction $nom ($f ou $g) indisponible" .
102
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
103
+
104
+    include_spip('inc/minipres');
105
+    echo minipres(
106
+        _T('forum_titre_erreur'),
107
+        _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']),
108
+        ['all_inline' => true,'status' => 404]
109
+    );
110
+    exit;
111 111
 }
112 112
 
113 113
 /**
@@ -117,17 +117,17 @@  discard block
 block discarded – undo
117 117
  * @return bool
118 118
  */
119 119
 function include_once_check($file) {
120
-	if (file_exists($file)) {
121
-		include_once $file;
120
+    if (file_exists($file)) {
121
+        include_once $file;
122 122
 
123
-		return true;
124
-	}
125
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
-	$crash = ($crash ?: []);
127
-	$crash[$file] = true;
128
-	ecrire_meta('message_crash_plugins', serialize($crash));
123
+        return true;
124
+    }
125
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
126
+    $crash = ($crash ?: []);
127
+    $crash[$file] = true;
128
+    ecrire_meta('message_crash_plugins', serialize($crash));
129 129
 
130
-	return false;
130
+    return false;
131 131
 }
132 132
 
133 133
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
  *     - string : chemin du fichier trouvé
152 152
  **/
153 153
 function include_spip($f, $include = true) {
154
-	return find_in_path($f . '.php', '', $include);
154
+    return find_in_path($f . '.php', '', $include);
155 155
 }
156 156
 
157 157
 /**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
  *     - string : chemin du fichier trouvé
172 172
  **/
173 173
 function require_spip($f) {
174
-	return find_in_path($f . '.php', '', 'required');
174
+    return find_in_path($f . '.php', '', 'required');
175 175
 }
176 176
 
177 177
 
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
181 181
  */
182 182
 function include_fichiers_fonctions() {
183
-	static $done = false;
184
-	if (!$done) {
185
-		include_spip('inc/lang');
186
-
187
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
-		// donc il faut l'inclure "en globals"
189
-		if ($f = find_in_path('mes_fonctions.php')) {
190
-			global $dossier_squelettes;
191
-			include_once(_ROOT_CWD . $f);
192
-		}
193
-
194
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
-			// chargement optimise precompile
196
-			include_once(_CACHE_PLUGINS_FCT);
197
-		}
198
-		if (test_espace_prive()) {
199
-			include_spip('inc/filtres_ecrire');
200
-		}
201
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
-		$done = true;
203
-	}
183
+    static $done = false;
184
+    if (!$done) {
185
+        include_spip('inc/lang');
186
+
187
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
188
+        // donc il faut l'inclure "en globals"
189
+        if ($f = find_in_path('mes_fonctions.php')) {
190
+            global $dossier_squelettes;
191
+            include_once(_ROOT_CWD . $f);
192
+        }
193
+
194
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
195
+            // chargement optimise precompile
196
+            include_once(_CACHE_PLUGINS_FCT);
197
+        }
198
+        if (test_espace_prive()) {
199
+            include_spip('inc/filtres_ecrire');
200
+        }
201
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
202
+        $done = true;
203
+    }
204 204
 }
205 205
 
206 206
 /**
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
  *     Les paramètres du pipeline modifiés
227 227
  **/
228 228
 function minipipe($fonc, &$val) {
229
-	// fonction
230
-	if (function_exists($fonc)) {
231
-		$val = call_user_func($fonc, $val);
232
-	} // Class::Methode
233
-	else {
234
-		if (
235
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
-			and $methode = [$regs[1], $regs[2]]
237
-			and is_callable($methode)
238
-		) {
239
-			$val = call_user_func($methode, $val);
240
-		} else {
241
-			spip_log("Erreur - '$fonc' non definie !");
242
-		}
243
-	}
244
-
245
-	return $val;
229
+    // fonction
230
+    if (function_exists($fonc)) {
231
+        $val = call_user_func($fonc, $val);
232
+    } // Class::Methode
233
+    else {
234
+        if (
235
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
236
+            and $methode = [$regs[1], $regs[2]]
237
+            and is_callable($methode)
238
+        ) {
239
+            $val = call_user_func($methode, $val);
240
+        } else {
241
+            spip_log("Erreur - '$fonc' non definie !");
242
+        }
243
+    }
244
+
245
+    return $val;
246 246
 }
247 247
 
248 248
 /**
@@ -273,46 +273,46 @@  discard block
 block discarded – undo
273 273
  *     Résultat
274 274
  */
275 275
 function pipeline($action, $val = null) {
276
-	static $charger;
277
-
278
-	// chargement initial des fonctions mises en cache, ou generation du cache
279
-	if (!$charger) {
280
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
-			include_spip('inc/plugin');
282
-			// generer les fichiers php precompiles
283
-			// de chargement des plugins et des pipelines
284
-			actualise_plugins_actifs();
285
-			if (!($ok = @is_readable($charger))) {
286
-				spip_log("fichier $charger pas cree");
287
-			}
288
-		}
289
-
290
-		if ($ok) {
291
-			include_once $charger;
292
-		}
293
-	}
294
-
295
-	// appliquer notre fonction si elle existe
296
-	$fonc = 'execute_pipeline_' . strtolower($action);
297
-	if (function_exists($fonc)) {
298
-		$val = $fonc($val);
299
-	} // plantage ?
300
-	else {
301
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
-	}
303
-
304
-	// si le flux est une table avec 2 cle args&data
305
-	// on ne ressort du pipe que les donnees dans 'data'
306
-	// array_key_exists pour php 4.1.0
307
-	if (
308
-		is_array($val)
309
-		and count($val) == 2
310
-		and (array_key_exists('data', $val))
311
-	) {
312
-		$val = $val['data'];
313
-	}
314
-
315
-	return $val;
276
+    static $charger;
277
+
278
+    // chargement initial des fonctions mises en cache, ou generation du cache
279
+    if (!$charger) {
280
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
281
+            include_spip('inc/plugin');
282
+            // generer les fichiers php precompiles
283
+            // de chargement des plugins et des pipelines
284
+            actualise_plugins_actifs();
285
+            if (!($ok = @is_readable($charger))) {
286
+                spip_log("fichier $charger pas cree");
287
+            }
288
+        }
289
+
290
+        if ($ok) {
291
+            include_once $charger;
292
+        }
293
+    }
294
+
295
+    // appliquer notre fonction si elle existe
296
+    $fonc = 'execute_pipeline_' . strtolower($action);
297
+    if (function_exists($fonc)) {
298
+        $val = $fonc($val);
299
+    } // plantage ?
300
+    else {
301
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
302
+    }
303
+
304
+    // si le flux est une table avec 2 cle args&data
305
+    // on ne ressort du pipe que les donnees dans 'data'
306
+    // array_key_exists pour php 4.1.0
307
+    if (
308
+        is_array($val)
309
+        and count($val) == 2
310
+        and (array_key_exists('data', $val))
311
+    ) {
312
+        $val = $val['data'];
313
+    }
314
+
315
+    return $val;
316 316
 }
317 317
 
318 318
 /**
@@ -356,38 +356,38 @@  discard block
 block discarded – undo
356 356
  *     paramètre est planté pour cause de compatibilité ascendante.
357 357
  */
358 358
 function spip_log($message = null, $name = null) {
359
-	static $pre = [];
360
-	static $log;
361
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
363
-		$logname = null;
364
-	}
365
-	if (!isset($regs[2])) {
366
-		$niveau = _LOG_INFO;
367
-	}
368
-	else {
369
-		$niveau = intval($regs[2]);
370
-	}
371
-
372
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
-		if (!$pre) {
374
-			$pre = [
375
-				_LOG_HS => 'HS:',
376
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
377
-				_LOG_CRITIQUE => 'CRITIQUE:',
378
-				_LOG_ERREUR => 'ERREUR:',
379
-				_LOG_AVERTISSEMENT => 'WARNING:',
380
-				_LOG_INFO_IMPORTANTE => '!INFO:',
381
-				_LOG_INFO => 'info:',
382
-				_LOG_DEBUG => 'debug:'
383
-			];
384
-			$log = charger_fonction('log', 'inc');
385
-		}
386
-		if (!is_string($message)) {
387
-			$message = print_r($message, true);
388
-		}
389
-		$log($pre[$niveau] . ' ' . $message, $logname);
390
-	}
359
+    static $pre = [];
360
+    static $log;
361
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
362
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
363
+        $logname = null;
364
+    }
365
+    if (!isset($regs[2])) {
366
+        $niveau = _LOG_INFO;
367
+    }
368
+    else {
369
+        $niveau = intval($regs[2]);
370
+    }
371
+
372
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
373
+        if (!$pre) {
374
+            $pre = [
375
+                _LOG_HS => 'HS:',
376
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
377
+                _LOG_CRITIQUE => 'CRITIQUE:',
378
+                _LOG_ERREUR => 'ERREUR:',
379
+                _LOG_AVERTISSEMENT => 'WARNING:',
380
+                _LOG_INFO_IMPORTANTE => '!INFO:',
381
+                _LOG_INFO => 'info:',
382
+                _LOG_DEBUG => 'debug:'
383
+            ];
384
+            $log = charger_fonction('log', 'inc');
385
+        }
386
+        if (!is_string($message)) {
387
+            $message = print_r($message, true);
388
+        }
389
+        $log($pre[$niveau] . ' ' . $message, $logname);
390
+    }
391 391
 }
392 392
 
393 393
 /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
  * @param array $opt Tableau d'options
399 399
  **/
400 400
 function journal($phrase, $opt = []) {
401
-	$journal = charger_fonction('journal', 'inc');
402
-	$journal($phrase, $opt);
401
+    $journal = charger_fonction('journal', 'inc');
402
+    $journal($phrase, $opt);
403 403
 }
404 404
 
405 405
 
@@ -418,37 +418,37 @@  discard block
 block discarded – undo
418 418
  **/
419 419
 function _request($var, $c = false) {
420 420
 
421
-	if (is_array($c)) {
422
-		return $c[$var] ?? null;
423
-	}
424
-
425
-	if (isset($_GET[$var])) {
426
-		$a = $_GET[$var];
427
-	} elseif (isset($_POST[$var])) {
428
-		$a = $_POST[$var];
429
-	} else {
430
-		return null;
431
-	}
432
-
433
-	// Si on est en ajax et en POST tout a ete encode
434
-	// via encodeURIComponent, il faut donc repasser
435
-	// dans le charset local...
436
-	if (
437
-		defined('_AJAX')
438
-		and _AJAX
439
-		and isset($GLOBALS['meta']['charset'])
440
-		and $GLOBALS['meta']['charset'] != 'utf-8'
441
-		and is_string($a)
442
-		// check rapide mais pas fiable
443
-		and preg_match(',[\x80-\xFF],', $a)
444
-		// check fiable
445
-		and include_spip('inc/charsets')
446
-		and is_utf8($a)
447
-	) {
448
-		return importer_charset($a, 'utf-8');
449
-	}
450
-
451
-	return $a;
421
+    if (is_array($c)) {
422
+        return $c[$var] ?? null;
423
+    }
424
+
425
+    if (isset($_GET[$var])) {
426
+        $a = $_GET[$var];
427
+    } elseif (isset($_POST[$var])) {
428
+        $a = $_POST[$var];
429
+    } else {
430
+        return null;
431
+    }
432
+
433
+    // Si on est en ajax et en POST tout a ete encode
434
+    // via encodeURIComponent, il faut donc repasser
435
+    // dans le charset local...
436
+    if (
437
+        defined('_AJAX')
438
+        and _AJAX
439
+        and isset($GLOBALS['meta']['charset'])
440
+        and $GLOBALS['meta']['charset'] != 'utf-8'
441
+        and is_string($a)
442
+        // check rapide mais pas fiable
443
+        and preg_match(',[\x80-\xFF],', $a)
444
+        // check fiable
445
+        and include_spip('inc/charsets')
446
+        and is_utf8($a)
447
+    ) {
448
+        return importer_charset($a, 'utf-8');
449
+    }
450
+
451
+    return $a;
452 452
 }
453 453
 
454 454
 
@@ -466,22 +466,22 @@  discard block
 block discarded – undo
466 466
  *     - false sinon
467 467
  **/
468 468
 function set_request($var, $val = null, $c = false) {
469
-	if (is_array($c)) {
470
-		unset($c[$var]);
471
-		if ($val !== null) {
472
-			$c[$var] = $val;
473
-		}
469
+    if (is_array($c)) {
470
+        unset($c[$var]);
471
+        if ($val !== null) {
472
+            $c[$var] = $val;
473
+        }
474 474
 
475
-		return $c;
476
-	}
475
+        return $c;
476
+    }
477 477
 
478
-	unset($_GET[$var]);
479
-	unset($_POST[$var]);
480
-	if ($val !== null) {
481
-		$_GET[$var] = $val;
482
-	}
478
+    unset($_GET[$var]);
479
+    unset($_POST[$var]);
480
+    if ($val !== null) {
481
+        $_GET[$var] = $val;
482
+    }
483 483
 
484
-	return false; # n'affecte pas $c
484
+    return false; # n'affecte pas $c
485 485
 }
486 486
 
487 487
 /**
@@ -501,25 +501,25 @@  discard block
 block discarded – undo
501 501
  * @return array|mixed|string
502 502
  */
503 503
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
504
-	if (is_array($value)) {
505
-		if ($key == '*') {
506
-			$key = array_keys($value);
507
-		}
508
-		if (!is_array($key)) {
509
-			$key = [$key];
510
-		}
511
-		foreach ($key as $k) {
512
-			if (!empty($value[$k])) {
513
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
-			}
515
-		}
516
-		return $value;
517
-	}
518
-	// si la valeur vient des GET ou POST on la sanitize
519
-	if (!empty($value) and $value == _request($key)) {
520
-		$value = $sanitize_function($value);
521
-	}
522
-	return $value;
504
+    if (is_array($value)) {
505
+        if ($key == '*') {
506
+            $key = array_keys($value);
507
+        }
508
+        if (!is_array($key)) {
509
+            $key = [$key];
510
+        }
511
+        foreach ($key as $k) {
512
+            if (!empty($value[$k])) {
513
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
514
+            }
515
+        }
516
+        return $value;
517
+    }
518
+    // si la valeur vient des GET ou POST on la sanitize
519
+    if (!empty($value) and $value == _request($key)) {
520
+        $value = $sanitize_function($value);
521
+    }
522
+    return $value;
523 523
 }
524 524
 
525 525
 /**
@@ -527,23 +527,22 @@  discard block
 block discarded – undo
527 527
  *
528 528
  * On est sur le web, on exclut certains protocoles,
529 529
  * notamment 'file://', 'php://' et d'autres…
530
-
531 530
  * @param string $url
532 531
  * @return bool
533 532
  */
534 533
 function tester_url_absolue($url) {
535
-	$url = trim($url);
536
-	if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
537
-		if (
538
-			isset($m[1])
539
-			and $p = strtolower(rtrim($m[1], ':'))
540
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
541
-		) {
542
-			return false;
543
-		}
544
-		return true;
545
-	}
546
-	return false;
534
+    $url = trim($url);
535
+    if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
536
+        if (
537
+            isset($m[1])
538
+            and $p = strtolower(rtrim($m[1], ':'))
539
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
540
+        ) {
541
+            return false;
542
+        }
543
+        return true;
544
+    }
545
+    return false;
547 546
 }
548 547
 
549 548
 /**
@@ -565,95 +564,95 @@  discard block
 block discarded – undo
565 564
  * @return string URL
566 565
  */
567 566
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
568
-	// requete erronnee : plusieurs variable dans $c et aucun $v
569
-	if (strpos($c, '|') !== false and is_null($v)) {
570
-		return null;
571
-	}
572
-
573
-	// lever l'#ancre
574
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
575
-		$url = $r[1];
576
-		$ancre = $r[2];
577
-	} else {
578
-		$ancre = '';
579
-	}
580
-
581
-	// eclater
582
-	$url = preg_split(',[?]|&amp;|&,', $url);
583
-
584
-	// recuperer la base
585
-	$a = array_shift($url);
586
-	if (!$a) {
587
-		$a = './';
588
-	}
589
-
590
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
591
-	$ajouts = array_flip(explode('|', $c));
592
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
593
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
594
-	$v_read = null;
595
-	// lire les variables et agir
596
-	foreach ($url as $n => $val) {
597
-		if (preg_match($regexp, urldecode($val), $r)) {
598
-			$r = array_pad($r, 3, null);
599
-			if ($v === null) {
600
-				// c'est un tableau, on memorise les valeurs
601
-				if (substr($r[1], -2) == '[]') {
602
-					if (!$v_read) {
603
-						$v_read = [];
604
-					}
605
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
606
-				} // c'est un scalaire, on retourne direct
607
-				else {
608
-					return $r[2] ? substr($r[2], 1) : '';
609
-				}
610
-			} // suppression
611
-			elseif (!$testv) {
612
-				unset($url[$n]);
613
-			}
614
-			// Ajout. Pour une variable, remplacer au meme endroit,
615
-			// pour un tableau ce sera fait dans la prochaine boucle
616
-			elseif (substr($r[1], -2) != '[]') {
617
-				$url[$n] = $r[1] . '=' . $u;
618
-				unset($ajouts[$r[1]]);
619
-			}
620
-			// Pour les tableaux on laisse tomber les valeurs de
621
-			// départ, on remplira à l'étape suivante
622
-			else {
623
-				unset($url[$n]);
624
-			}
625
-		}
626
-	}
627
-
628
-	// traiter les parametres pas encore trouves
629
-	if (
630
-		$v === null
631
-		and $args = func_get_args()
632
-		and count($args) == 2
633
-	) {
634
-		return $v_read; // rien trouve ou un tableau
635
-	} elseif ($testv) {
636
-		foreach ($ajouts as $k => $n) {
637
-			if (!is_array($v)) {
638
-				$url[] = $k . '=' . $u;
639
-			} else {
640
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
641
-				foreach ($v as $w) {
642
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
643
-				}
644
-			}
645
-		}
646
-	}
647
-
648
-	// eliminer les vides
649
-	$url = array_filter($url);
650
-
651
-	// recomposer l'adresse
652
-	if ($url) {
653
-		$a .= '?' . join($sep, $url);
654
-	}
655
-
656
-	return $a . $ancre;
567
+    // requete erronnee : plusieurs variable dans $c et aucun $v
568
+    if (strpos($c, '|') !== false and is_null($v)) {
569
+        return null;
570
+    }
571
+
572
+    // lever l'#ancre
573
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
574
+        $url = $r[1];
575
+        $ancre = $r[2];
576
+    } else {
577
+        $ancre = '';
578
+    }
579
+
580
+    // eclater
581
+    $url = preg_split(',[?]|&amp;|&,', $url);
582
+
583
+    // recuperer la base
584
+    $a = array_shift($url);
585
+    if (!$a) {
586
+        $a = './';
587
+    }
588
+
589
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
590
+    $ajouts = array_flip(explode('|', $c));
591
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
592
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
593
+    $v_read = null;
594
+    // lire les variables et agir
595
+    foreach ($url as $n => $val) {
596
+        if (preg_match($regexp, urldecode($val), $r)) {
597
+            $r = array_pad($r, 3, null);
598
+            if ($v === null) {
599
+                // c'est un tableau, on memorise les valeurs
600
+                if (substr($r[1], -2) == '[]') {
601
+                    if (!$v_read) {
602
+                        $v_read = [];
603
+                    }
604
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
605
+                } // c'est un scalaire, on retourne direct
606
+                else {
607
+                    return $r[2] ? substr($r[2], 1) : '';
608
+                }
609
+            } // suppression
610
+            elseif (!$testv) {
611
+                unset($url[$n]);
612
+            }
613
+            // Ajout. Pour une variable, remplacer au meme endroit,
614
+            // pour un tableau ce sera fait dans la prochaine boucle
615
+            elseif (substr($r[1], -2) != '[]') {
616
+                $url[$n] = $r[1] . '=' . $u;
617
+                unset($ajouts[$r[1]]);
618
+            }
619
+            // Pour les tableaux on laisse tomber les valeurs de
620
+            // départ, on remplira à l'étape suivante
621
+            else {
622
+                unset($url[$n]);
623
+            }
624
+        }
625
+    }
626
+
627
+    // traiter les parametres pas encore trouves
628
+    if (
629
+        $v === null
630
+        and $args = func_get_args()
631
+        and count($args) == 2
632
+    ) {
633
+        return $v_read; // rien trouve ou un tableau
634
+    } elseif ($testv) {
635
+        foreach ($ajouts as $k => $n) {
636
+            if (!is_array($v)) {
637
+                $url[] = $k . '=' . $u;
638
+            } else {
639
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
640
+                foreach ($v as $w) {
641
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
642
+                }
643
+            }
644
+        }
645
+    }
646
+
647
+    // eliminer les vides
648
+    $url = array_filter($url);
649
+
650
+    // recomposer l'adresse
651
+    if ($url) {
652
+        $a .= '?' . join($sep, $url);
653
+    }
654
+
655
+    return $a . $ancre;
657 656
 }
658 657
 
659 658
 /**
@@ -671,21 +670,21 @@  discard block
 block discarded – undo
671 670
  * @return string
672 671
  */
673 672
 function ancre_url($url, $ancre) {
674
-	// lever l'#ancre
675
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
676
-		$url = $r[1];
677
-	}
678
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
679
-		if (!function_exists('translitteration')) {
680
-			include_spip('inc/charsets');
681
-		}
682
-		$ancre = preg_replace(
683
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
684
-			['', '-'],
685
-			translitteration($ancre)
686
-		);
687
-	}
688
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
673
+    // lever l'#ancre
674
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
675
+        $url = $r[1];
676
+    }
677
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
678
+        if (!function_exists('translitteration')) {
679
+            include_spip('inc/charsets');
680
+        }
681
+        $ancre = preg_replace(
682
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
683
+            ['', '-'],
684
+            translitteration($ancre)
685
+        );
686
+    }
687
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
689 688
 }
690 689
 
691 690
 /**
@@ -695,16 +694,16 @@  discard block
 block discarded – undo
695 694
  * @return string
696 695
  */
697 696
 function nettoyer_uri($reset = null) {
698
-	static $done = false;
699
-	static $propre = '';
700
-	if (!is_null($reset)) {
701
-		return $propre = $reset;
702
-	}
703
-	if ($done) {
704
-		return $propre;
705
-	}
706
-	$done = true;
707
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
697
+    static $done = false;
698
+    static $propre = '';
699
+    if (!is_null($reset)) {
700
+        return $propre = $reset;
701
+    }
702
+    if ($done) {
703
+        return $propre;
704
+    }
705
+    $done = true;
706
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
708 707
 }
709 708
 
710 709
 /**
@@ -716,16 +715,16 @@  discard block
 block discarded – undo
716 715
  * @return string
717 716
  */
718 717
 function nettoyer_uri_var($request_uri) {
719
-	$uri1 = $request_uri;
720
-	do {
721
-		$uri = $uri1;
722
-		$uri1 = preg_replace(
723
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
724
-			'\1',
725
-			$uri
726
-		);
727
-	} while ($uri <> $uri1);
728
-	return preg_replace(',[?&]$,', '', $uri1);
718
+    $uri1 = $request_uri;
719
+    do {
720
+        $uri = $uri1;
721
+        $uri1 = preg_replace(
722
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
723
+            '\1',
724
+            $uri
725
+        );
726
+    } while ($uri <> $uri1);
727
+    return preg_replace(',[?&]$,', '', $uri1);
729 728
 }
730 729
 
731 730
 
@@ -739,48 +738,48 @@  discard block
 block discarded – undo
739 738
  *    URL vers soi-même
740 739
  **/
741 740
 function self($amp = '&amp;', $root = false) {
742
-	$url = nettoyer_uri();
743
-	if (
744
-		!$root
745
-		and (
746
-			// si pas de profondeur on peut tronquer
747
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
748
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
749
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
750
-	) {
751
-		$url = preg_replace(',^[^?]*/,', '', $url);
752
-	}
753
-	// ajouter le cas echeant les variables _POST['id_...']
754
-	foreach ($_POST as $v => $c) {
755
-		if (substr($v, 0, 3) == 'id_') {
756
-			$url = parametre_url($url, $v, $c, '&');
757
-		}
758
-	}
759
-
760
-	// supprimer les variables sans interet
761
-	if (test_espace_prive()) {
762
-		$url = preg_replace(',([?&])('
763
-			. 'lang|show_docs|'
764
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
765
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
766
-		$url = preg_replace(',[&]$,', '\1', $url);
767
-	}
768
-
769
-	// eviter les hacks
770
-	include_spip('inc/filtres_mini');
771
-	$url = spip_htmlspecialchars($url);
772
-
773
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
774
-
775
-	// &amp; ?
776
-	if ($amp != '&amp;') {
777
-		$url = str_replace('&amp;', $amp, $url);
778
-	}
779
-
780
-	// Si ca demarre par ? ou vide, donner './'
781
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
782
-
783
-	return $url;
741
+    $url = nettoyer_uri();
742
+    if (
743
+        !$root
744
+        and (
745
+            // si pas de profondeur on peut tronquer
746
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
747
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
748
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
749
+    ) {
750
+        $url = preg_replace(',^[^?]*/,', '', $url);
751
+    }
752
+    // ajouter le cas echeant les variables _POST['id_...']
753
+    foreach ($_POST as $v => $c) {
754
+        if (substr($v, 0, 3) == 'id_') {
755
+            $url = parametre_url($url, $v, $c, '&');
756
+        }
757
+    }
758
+
759
+    // supprimer les variables sans interet
760
+    if (test_espace_prive()) {
761
+        $url = preg_replace(',([?&])('
762
+            . 'lang|show_docs|'
763
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
764
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
765
+        $url = preg_replace(',[&]$,', '\1', $url);
766
+    }
767
+
768
+    // eviter les hacks
769
+    include_spip('inc/filtres_mini');
770
+    $url = spip_htmlspecialchars($url);
771
+
772
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
773
+
774
+    // &amp; ?
775
+    if ($amp != '&amp;') {
776
+        $url = str_replace('&amp;', $amp, $url);
777
+    }
778
+
779
+    // Si ca demarre par ? ou vide, donner './'
780
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
781
+
782
+    return $url;
784 783
 }
785 784
 
786 785
 
@@ -791,7 +790,7 @@  discard block
 block discarded – undo
791 790
  *     true si c'est le cas, false sinon.
792 791
  */
793 792
 function test_espace_prive() {
794
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
793
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
795 794
 }
796 795
 
797 796
 /**
@@ -801,7 +800,7 @@  discard block
 block discarded – undo
801 800
  * @return bool
802 801
  */
803 802
 function test_plugin_actif($plugin) {
804
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
803
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
805 804
 }
806 805
 
807 806
 /**
@@ -832,52 +831,52 @@  discard block
 block discarded – undo
832 831
  *     Texte
833 832
  */
834 833
 function _T($texte, $args = [], $options = []) {
835
-	static $traduire = false;
836
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
837
-	if ($options) {
838
-		// support de l'ancien argument $class
839
-		if (is_string($options)) {
840
-			$options = ['class' => $options];
841
-		}
842
-		$o = array_merge($o, $options);
843
-	}
844
-
845
-	if (!$traduire) {
846
-		$traduire = charger_fonction('traduire', 'inc');
847
-		include_spip('inc/lang');
848
-	}
849
-
850
-	// On peut passer explicitement la langue dans le tableau
851
-	// On utilise le même nom de variable que la globale
852
-	if (isset($args['spip_lang'])) {
853
-		$lang = $args['spip_lang'];
854
-		// On l'enleve pour ne pas le passer au remplacement
855
-		unset($args['spip_lang']);
856
-	} // Sinon on prend la langue du contexte
857
-	else {
858
-		$lang = $GLOBALS['spip_lang'];
859
-	}
860
-	$text = $traduire($texte, $lang);
861
-
862
-	if ($text === null || !strlen($text)) {
863
-		if (!$o['force']) {
864
-			return '';
865
-		}
866
-
867
-		$text = $texte;
868
-
869
-		// pour les chaines non traduites, assurer un service minimum
870
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
871
-			$n = strpos($text, ':');
872
-			if ($n !== false) {
873
-				$text = substr($text, $n + 1);
874
-			}
875
-			$text = str_replace('_', ' ', $text);
876
-		}
877
-		$o['class'] = null;
878
-	}
879
-
880
-	return _L($text, $args, $o);
834
+    static $traduire = false;
835
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
836
+    if ($options) {
837
+        // support de l'ancien argument $class
838
+        if (is_string($options)) {
839
+            $options = ['class' => $options];
840
+        }
841
+        $o = array_merge($o, $options);
842
+    }
843
+
844
+    if (!$traduire) {
845
+        $traduire = charger_fonction('traduire', 'inc');
846
+        include_spip('inc/lang');
847
+    }
848
+
849
+    // On peut passer explicitement la langue dans le tableau
850
+    // On utilise le même nom de variable que la globale
851
+    if (isset($args['spip_lang'])) {
852
+        $lang = $args['spip_lang'];
853
+        // On l'enleve pour ne pas le passer au remplacement
854
+        unset($args['spip_lang']);
855
+    } // Sinon on prend la langue du contexte
856
+    else {
857
+        $lang = $GLOBALS['spip_lang'];
858
+    }
859
+    $text = $traduire($texte, $lang);
860
+
861
+    if ($text === null || !strlen($text)) {
862
+        if (!$o['force']) {
863
+            return '';
864
+        }
865
+
866
+        $text = $texte;
867
+
868
+        // pour les chaines non traduites, assurer un service minimum
869
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
870
+            $n = strpos($text, ':');
871
+            if ($n !== false) {
872
+                $text = substr($text, $n + 1);
873
+            }
874
+            $text = str_replace('_', ' ', $text);
875
+        }
876
+        $o['class'] = null;
877
+    }
878
+
879
+    return _L($text, $args, $o);
881 880
 }
882 881
 
883 882
 
@@ -904,53 +903,53 @@  discard block
 block discarded – undo
904 903
  *     Texte
905 904
  */
906 905
 function _L($text, $args = [], $options = []) {
907
-	$f = $text;
908
-	$defaut_options = [
909
-		'class' => null,
910
-		'sanitize' => true,
911
-	];
912
-	// support de l'ancien argument $class
913
-	if ($options and is_string($options)) {
914
-		$options = ['class' => $options];
915
-	}
916
-	if (is_array($options)) {
917
-		$options += $defaut_options;
918
-	} else {
919
-		$options = $defaut_options;
920
-	}
921
-
922
-	if (is_array($args) and count($args)) {
923
-		if (!function_exists('interdire_scripts')) {
924
-			include_spip('inc/texte');
925
-		}
926
-		if (!function_exists('echapper_html_suspect')) {
927
-			include_spip('inc/texte_mini');
928
-		}
929
-		foreach ($args as $name => $value) {
930
-			if (strpos($text, (string) "@$name@") !== false) {
931
-				if ($options['sanitize']) {
932
-					$value = echapper_html_suspect($value);
933
-					$value = interdire_scripts($value, -1);
934
-				}
935
-				if (!empty($options['class'])) {
936
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
937
-				}
938
-				$text = str_replace("@$name@", $value, $text);
939
-				unset($args[$name]);
940
-			}
941
-		}
942
-		// Si des variables n'ont pas ete inserees, le signaler
943
-		// (chaines de langues pas a jour)
944
-		if ($args) {
945
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
946
-		}
947
-	}
948
-
949
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
950
-		return "<span class='debug-traduction-erreur'>$text</span>";
951
-	} else {
952
-		return $text;
953
-	}
906
+    $f = $text;
907
+    $defaut_options = [
908
+        'class' => null,
909
+        'sanitize' => true,
910
+    ];
911
+    // support de l'ancien argument $class
912
+    if ($options and is_string($options)) {
913
+        $options = ['class' => $options];
914
+    }
915
+    if (is_array($options)) {
916
+        $options += $defaut_options;
917
+    } else {
918
+        $options = $defaut_options;
919
+    }
920
+
921
+    if (is_array($args) and count($args)) {
922
+        if (!function_exists('interdire_scripts')) {
923
+            include_spip('inc/texte');
924
+        }
925
+        if (!function_exists('echapper_html_suspect')) {
926
+            include_spip('inc/texte_mini');
927
+        }
928
+        foreach ($args as $name => $value) {
929
+            if (strpos($text, (string) "@$name@") !== false) {
930
+                if ($options['sanitize']) {
931
+                    $value = echapper_html_suspect($value);
932
+                    $value = interdire_scripts($value, -1);
933
+                }
934
+                if (!empty($options['class'])) {
935
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
936
+                }
937
+                $text = str_replace("@$name@", $value, $text);
938
+                unset($args[$name]);
939
+            }
940
+        }
941
+        // Si des variables n'ont pas ete inserees, le signaler
942
+        // (chaines de langues pas a jour)
943
+        if ($args) {
944
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
945
+        }
946
+    }
947
+
948
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
949
+        return "<span class='debug-traduction-erreur'>$text</span>";
950
+    } else {
951
+        return $text;
952
+    }
954 953
 }
955 954
 
956 955
 
@@ -964,13 +963,13 @@  discard block
 block discarded – undo
964 963
  * @return string
965 964
  */
966 965
 function joli_repertoire($rep) {
967
-	$a = substr($rep, 0, 1);
968
-	if ($a <> '.' and $a <> '/') {
969
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
970
-	}
971
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
966
+    $a = substr($rep, 0, 1);
967
+    if ($a <> '.' and $a <> '/') {
968
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
969
+    }
970
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
972 971
 
973
-	return $rep;
972
+    return $rep;
974 973
 }
975 974
 
976 975
 
@@ -995,54 +994,54 @@  discard block
 block discarded – undo
995 994
  * @return float|int|string|void
996 995
  */
997 996
 function spip_timer($t = 'rien', $raw = false) {
998
-	static $time;
999
-	$a = time();
1000
-	$b = microtime();
1001
-	// microtime peut contenir les microsecondes et le temps
1002
-	$b = explode(' ', $b);
1003
-	if (count($b) == 2) {
1004
-		$a = end($b);
1005
-	} // plus precis !
1006
-	$b = reset($b);
1007
-	if (!isset($time[$t])) {
1008
-		$time[$t] = $a + $b;
1009
-	} else {
1010
-		$p = ($a + $b - $time[$t]) * 1000;
1011
-		unset($time[$t]);
997
+    static $time;
998
+    $a = time();
999
+    $b = microtime();
1000
+    // microtime peut contenir les microsecondes et le temps
1001
+    $b = explode(' ', $b);
1002
+    if (count($b) == 2) {
1003
+        $a = end($b);
1004
+    } // plus precis !
1005
+    $b = reset($b);
1006
+    if (!isset($time[$t])) {
1007
+        $time[$t] = $a + $b;
1008
+    } else {
1009
+        $p = ($a + $b - $time[$t]) * 1000;
1010
+        unset($time[$t]);
1012 1011
 #			echo "'$p'";exit;
1013
-		if ($raw) {
1014
-			return $p;
1015
-		}
1016
-		if ($p < 1000) {
1017
-			$s = '';
1018
-		} else {
1019
-			$s = sprintf('%d ', $x = floor($p / 1000));
1020
-			$p -= ($x * 1000);
1021
-		}
1012
+        if ($raw) {
1013
+            return $p;
1014
+        }
1015
+        if ($p < 1000) {
1016
+            $s = '';
1017
+        } else {
1018
+            $s = sprintf('%d ', $x = floor($p / 1000));
1019
+            $p -= ($x * 1000);
1020
+        }
1022 1021
 
1023
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1024
-	}
1022
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1023
+    }
1025 1024
 }
1026 1025
 
1027 1026
 
1028 1027
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1029 1028
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1030 1029
 function spip_touch($fichier, $duree = 0, $touch = true) {
1031
-	if ($duree) {
1032
-		clearstatcache();
1033
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1034
-			return false;
1035
-		}
1036
-	}
1037
-	if ($touch !== false) {
1038
-		if (!@touch($fichier)) {
1039
-			spip_unlink($fichier);
1040
-			@touch($fichier);
1041
-		};
1042
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1043
-	}
1030
+    if ($duree) {
1031
+        clearstatcache();
1032
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1033
+            return false;
1034
+        }
1035
+    }
1036
+    if ($touch !== false) {
1037
+        if (!@touch($fichier)) {
1038
+            spip_unlink($fichier);
1039
+            @touch($fichier);
1040
+        };
1041
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1042
+    }
1044 1043
 
1045
-	return true;
1044
+    return true;
1046 1045
 }
1047 1046
 
1048 1047
 
@@ -1053,11 +1052,11 @@  discard block
 block discarded – undo
1053 1052
  * @uses cron()
1054 1053
  **/
1055 1054
 function action_cron() {
1056
-	include_spip('inc/headers');
1057
-	http_response_code(204); // No Content
1058
-	header('Connection: close');
1059
-	define('_DIRECT_CRON_FORCE', true);
1060
-	cron();
1055
+    include_spip('inc/headers');
1056
+    http_response_code(204); // No Content
1057
+    header('Connection: close');
1058
+    define('_DIRECT_CRON_FORCE', true);
1059
+    cron();
1061 1060
 }
1062 1061
 
1063 1062
 /**
@@ -1073,26 +1072,26 @@  discard block
 block discarded – undo
1073 1072
  *     True si la tache a pu être effectuée
1074 1073
  */
1075 1074
 function cron($taches = [], $taches_old = []) {
1076
-	// si pas en mode cron force, laisser tomber.
1077
-	if (!defined('_DIRECT_CRON_FORCE')) {
1078
-		return false;
1079
-	}
1080
-	if (!is_array($taches)) {
1081
-		$taches = $taches_old;
1082
-	} // compat anciens appels
1083
-	// si taches a inserer en base et base inaccessible, laisser tomber
1084
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1085
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1086
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1087
-	if ($taches and count($taches) and !spip_connect()) {
1088
-		return false;
1089
-	}
1090
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1091
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1092
-		return $genie($taches);
1093
-	}
1094
-
1095
-	return false;
1075
+    // si pas en mode cron force, laisser tomber.
1076
+    if (!defined('_DIRECT_CRON_FORCE')) {
1077
+        return false;
1078
+    }
1079
+    if (!is_array($taches)) {
1080
+        $taches = $taches_old;
1081
+    } // compat anciens appels
1082
+    // si taches a inserer en base et base inaccessible, laisser tomber
1083
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1084
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1085
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1086
+    if ($taches and count($taches) and !spip_connect()) {
1087
+        return false;
1088
+    }
1089
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1090
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1091
+        return $genie($taches);
1092
+    }
1093
+
1094
+    return false;
1096 1095
 }
1097 1096
 
1098 1097
 /**
@@ -1124,17 +1123,17 @@  discard block
 block discarded – undo
1124 1123
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1125 1124
  */
1126 1125
 function job_queue_add(
1127
-	$function,
1128
-	$description,
1129
-	$arguments = [],
1130
-	$file = '',
1131
-	$no_duplicate = false,
1132
-	$time = 0,
1133
-	$priority = 0
1126
+    $function,
1127
+    $description,
1128
+    $arguments = [],
1129
+    $file = '',
1130
+    $no_duplicate = false,
1131
+    $time = 0,
1132
+    $priority = 0
1134 1133
 ) {
1135
-	include_spip('inc/queue');
1134
+    include_spip('inc/queue');
1136 1135
 
1137
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1136
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1138 1137
 }
1139 1138
 
1140 1139
 /**
@@ -1145,9 +1144,9 @@  discard block
 block discarded – undo
1145 1144
  * @return bool
1146 1145
  */
1147 1146
 function job_queue_remove($id_job) {
1148
-	include_spip('inc/queue');
1147
+    include_spip('inc/queue');
1149 1148
 
1150
-	return queue_remove_job($id_job);
1149
+    return queue_remove_job($id_job);
1151 1150
 }
1152 1151
 
1153 1152
 /**
@@ -1160,9 +1159,9 @@  discard block
 block discarded – undo
1160 1159
  *     or an array of simple array to link multiples objet in one time
1161 1160
  */
1162 1161
 function job_queue_link($id_job, $objets) {
1163
-	include_spip('inc/queue');
1162
+    include_spip('inc/queue');
1164 1163
 
1165
-	return queue_link_job($id_job, $objets);
1164
+    return queue_link_job($id_job, $objets);
1166 1165
 }
1167 1166
 
1168 1167
 
@@ -1182,36 +1181,36 @@  discard block
 block discarded – undo
1182 1181
  *  - `null` si la queue n'est pas encore initialisée
1183 1182
  */
1184 1183
 function queue_sleep_time_to_next_job($force = null) {
1185
-	static $queue_next_job_time = -1;
1186
-	if ($force === true) {
1187
-		$queue_next_job_time = -1;
1188
-	} elseif ($force) {
1189
-		$queue_next_job_time = $force;
1190
-	}
1191
-
1192
-	if ($queue_next_job_time == -1) {
1193
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1194
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1195
-		}
1196
-		// utiliser un cache memoire si dispo
1197
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1198
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1199
-		} else {
1200
-			$queue_next_job_time = null;
1201
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1202
-				$queue_next_job_time = intval($contenu);
1203
-			}
1204
-		}
1205
-	}
1206
-
1207
-	if (is_null($queue_next_job_time)) {
1208
-		return null;
1209
-	}
1210
-	if (!$_SERVER['REQUEST_TIME']) {
1211
-		$_SERVER['REQUEST_TIME'] = time();
1212
-	}
1213
-
1214
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1184
+    static $queue_next_job_time = -1;
1185
+    if ($force === true) {
1186
+        $queue_next_job_time = -1;
1187
+    } elseif ($force) {
1188
+        $queue_next_job_time = $force;
1189
+    }
1190
+
1191
+    if ($queue_next_job_time == -1) {
1192
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1193
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1194
+        }
1195
+        // utiliser un cache memoire si dispo
1196
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1197
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1198
+        } else {
1199
+            $queue_next_job_time = null;
1200
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1201
+                $queue_next_job_time = intval($contenu);
1202
+            }
1203
+        }
1204
+    }
1205
+
1206
+    if (is_null($queue_next_job_time)) {
1207
+        return null;
1208
+    }
1209
+    if (!$_SERVER['REQUEST_TIME']) {
1210
+        $_SERVER['REQUEST_TIME'] = time();
1211
+    }
1212
+
1213
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1215 1214
 }
1216 1215
 
1217 1216
 
@@ -1223,11 +1222,11 @@  discard block
 block discarded – undo
1223 1222
  * @return string
1224 1223
  */
1225 1224
 function quote_amp($u) {
1226
-	return preg_replace(
1227
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1228
-		'&amp;',
1229
-		$u
1230
-	);
1225
+    return preg_replace(
1226
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1227
+        '&amp;',
1228
+        $u
1229
+    );
1231 1230
 }
1232 1231
 
1233 1232
 
@@ -1250,27 +1249,27 @@  discard block
 block discarded – undo
1250 1249
  *     Balise HTML `<script>` et son contenu
1251 1250
  **/
1252 1251
 function http_script($script, $src = '', $noscript = '') {
1253
-	static $done = [];
1252
+    static $done = [];
1254 1253
 
1255
-	if ($src && !isset($done[$src])) {
1256
-		$done[$src] = true;
1257
-		$src = find_in_path($src, _JAVASCRIPT);
1258
-		$src = " src='$src'";
1259
-	} else {
1260
-		$src = '';
1261
-	}
1262
-	if ($script) {
1263
-		$script = ("/*<![CDATA[*/\n" .
1264
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1265
-			'/*]]>*/');
1266
-	}
1267
-	if ($noscript) {
1268
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1269
-	}
1254
+    if ($src && !isset($done[$src])) {
1255
+        $done[$src] = true;
1256
+        $src = find_in_path($src, _JAVASCRIPT);
1257
+        $src = " src='$src'";
1258
+    } else {
1259
+        $src = '';
1260
+    }
1261
+    if ($script) {
1262
+        $script = ("/*<![CDATA[*/\n" .
1263
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1264
+            '/*]]>*/');
1265
+    }
1266
+    if ($noscript) {
1267
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1268
+    }
1270 1269
 
1271
-	return ($src or $script or $noscript)
1272
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1273
-		: '';
1270
+    return ($src or $script or $noscript)
1271
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1272
+        : '';
1274 1273
 }
1275 1274
 
1276 1275
 
@@ -1305,7 +1304,7 @@  discard block
 block discarded – undo
1305 1304
  *     Texte échappé
1306 1305
  **/
1307 1306
 function texte_script(string $texte): string {
1308
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1307
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1309 1308
 }
1310 1309
 
1311 1310
 
@@ -1342,68 +1341,68 @@  discard block
 block discarded – undo
1342 1341
  *     Liste des chemins, par ordre de priorité.
1343 1342
  **/
1344 1343
 function _chemin($dir_path = null) {
1345
-	static $path_base = null;
1346
-	static $path_full = null;
1347
-	if ($path_base == null) {
1348
-		// Chemin standard depuis l'espace public
1349
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1350
-			_DIR_RACINE . ':' .
1351
-			_DIR_RACINE . 'squelettes-dist/:' .
1352
-			_DIR_RACINE . 'prive/:' .
1353
-			_DIR_RESTREINT;
1354
-		// Ajouter squelettes/
1355
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1356
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1357
-		}
1358
-		foreach (explode(':', $path) as $dir) {
1359
-			if (strlen($dir) and substr($dir, -1) != '/') {
1360
-				$dir .= '/';
1361
-			}
1362
-			$path_base[] = $dir;
1363
-		}
1364
-		$path_full = $path_base;
1365
-		// Et le(s) dossier(s) des squelettes nommes
1366
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1367
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1368
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1369
-			}
1370
-		}
1371
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1372
-	}
1373
-	if ($dir_path === null) {
1374
-		return $path_full;
1375
-	}
1376
-
1377
-	if (is_array($dir_path) or strlen($dir_path)) {
1378
-		$tete = '';
1379
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1380
-			$tete = array_shift($path_base);
1381
-		}
1382
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1383
-		$dirs = array_reverse($dirs);
1384
-		foreach ($dirs as $dir_path) {
1385
-			if (substr($dir_path, -1) != '/') {
1386
-				$dir_path .= '/';
1387
-			}
1388
-			if (!in_array($dir_path, $path_base)) {
1389
-				array_unshift($path_base, $dir_path);
1390
-			}
1391
-		}
1392
-		if (strlen($tete)) {
1393
-			array_unshift($path_base, $tete);
1394
-		}
1395
-	}
1396
-	$path_full = $path_base;
1397
-	// Et le(s) dossier(s) des squelettes nommes
1398
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1399
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1400
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1401
-		}
1402
-	}
1403
-
1404
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1405
-
1406
-	return $path_full;
1344
+    static $path_base = null;
1345
+    static $path_full = null;
1346
+    if ($path_base == null) {
1347
+        // Chemin standard depuis l'espace public
1348
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1349
+            _DIR_RACINE . ':' .
1350
+            _DIR_RACINE . 'squelettes-dist/:' .
1351
+            _DIR_RACINE . 'prive/:' .
1352
+            _DIR_RESTREINT;
1353
+        // Ajouter squelettes/
1354
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1355
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1356
+        }
1357
+        foreach (explode(':', $path) as $dir) {
1358
+            if (strlen($dir) and substr($dir, -1) != '/') {
1359
+                $dir .= '/';
1360
+            }
1361
+            $path_base[] = $dir;
1362
+        }
1363
+        $path_full = $path_base;
1364
+        // Et le(s) dossier(s) des squelettes nommes
1365
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1366
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1367
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1368
+            }
1369
+        }
1370
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1371
+    }
1372
+    if ($dir_path === null) {
1373
+        return $path_full;
1374
+    }
1375
+
1376
+    if (is_array($dir_path) or strlen($dir_path)) {
1377
+        $tete = '';
1378
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1379
+            $tete = array_shift($path_base);
1380
+        }
1381
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1382
+        $dirs = array_reverse($dirs);
1383
+        foreach ($dirs as $dir_path) {
1384
+            if (substr($dir_path, -1) != '/') {
1385
+                $dir_path .= '/';
1386
+            }
1387
+            if (!in_array($dir_path, $path_base)) {
1388
+                array_unshift($path_base, $dir_path);
1389
+            }
1390
+        }
1391
+        if (strlen($tete)) {
1392
+            array_unshift($path_base, $tete);
1393
+        }
1394
+    }
1395
+    $path_full = $path_base;
1396
+    // Et le(s) dossier(s) des squelettes nommes
1397
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1398
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1399
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1400
+        }
1401
+    }
1402
+
1403
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1404
+
1405
+    return $path_full;
1407 1406
 }
1408 1407
 
1409 1408
 /**
@@ -1416,78 +1415,78 @@  discard block
 block discarded – undo
1416 1415
  * @return array Liste de chemins
1417 1416
  **/
1418 1417
 function creer_chemin() {
1419
-	$path_a = _chemin();
1420
-	static $c = '';
1418
+    $path_a = _chemin();
1419
+    static $c = '';
1421 1420
 
1422
-	// on calcule le chemin si le dossier skel a change
1423
-	if ($c != $GLOBALS['dossier_squelettes']) {
1424
-		// assurer le non plantage lors de la montee de version :
1425
-		$c = $GLOBALS['dossier_squelettes'];
1426
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1427
-	}
1421
+    // on calcule le chemin si le dossier skel a change
1422
+    if ($c != $GLOBALS['dossier_squelettes']) {
1423
+        // assurer le non plantage lors de la montee de version :
1424
+        $c = $GLOBALS['dossier_squelettes'];
1425
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1426
+    }
1428 1427
 
1429
-	return $path_a;
1428
+    return $path_a;
1430 1429
 }
1431 1430
 
1432 1431
 
1433 1432
 function lister_themes_prives() {
1434
-	static $themes = null;
1435
-	if (is_null($themes)) {
1436
-		// si pas encore definie
1437
-		if (!defined('_SPIP_THEME_PRIVE')) {
1438
-			define('_SPIP_THEME_PRIVE', 'spip');
1439
-		}
1440
-		$themes = [_SPIP_THEME_PRIVE];
1441
-		// lors d'une installation neuve, prefs n'est pas definie.
1442
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1443
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1444
-		} else {
1445
-			$prefs = [];
1446
-		}
1447
-		if (is_string($prefs)) {
1448
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1449
-		}
1450
-		if (
1451
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1452
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1453
-			and $theme != _SPIP_THEME_PRIVE
1454
-		) {
1455
-			array_unshift($themes, $theme);
1456
-		} // placer le theme choisi en tete
1457
-	}
1458
-
1459
-	return $themes;
1433
+    static $themes = null;
1434
+    if (is_null($themes)) {
1435
+        // si pas encore definie
1436
+        if (!defined('_SPIP_THEME_PRIVE')) {
1437
+            define('_SPIP_THEME_PRIVE', 'spip');
1438
+        }
1439
+        $themes = [_SPIP_THEME_PRIVE];
1440
+        // lors d'une installation neuve, prefs n'est pas definie.
1441
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1442
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1443
+        } else {
1444
+            $prefs = [];
1445
+        }
1446
+        if (is_string($prefs)) {
1447
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1448
+        }
1449
+        if (
1450
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1451
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1452
+            and $theme != _SPIP_THEME_PRIVE
1453
+        ) {
1454
+            array_unshift($themes, $theme);
1455
+        } // placer le theme choisi en tete
1456
+    }
1457
+
1458
+    return $themes;
1460 1459
 }
1461 1460
 
1462 1461
 function find_in_theme($file, $subdir = '', $include = false) {
1463
-	static $themefiles = [];
1464
-	if (isset($themefiles["$subdir$file"])) {
1465
-		return $themefiles["$subdir$file"];
1466
-	}
1467
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1468
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1469
-	if (
1470
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1471
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1472
-		and $f = find_in_theme("$file_svg_generique")
1473
-	) {
1474
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1475
-			return $themefiles["$subdir$file"] = $fsize;
1476
-		}
1477
-		else {
1478
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1479
-		}
1480
-	}
1481
-
1482
-	$themes = lister_themes_prives();
1483
-	foreach ($themes as $theme) {
1484
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1485
-			return $themefiles["$subdir$file"] = $f;
1486
-		}
1487
-	}
1488
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1489
-
1490
-	return $themefiles["$subdir$file"] = '';
1462
+    static $themefiles = [];
1463
+    if (isset($themefiles["$subdir$file"])) {
1464
+        return $themefiles["$subdir$file"];
1465
+    }
1466
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1467
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1468
+    if (
1469
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1470
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1471
+        and $f = find_in_theme("$file_svg_generique")
1472
+    ) {
1473
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1474
+            return $themefiles["$subdir$file"] = $fsize;
1475
+        }
1476
+        else {
1477
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1478
+        }
1479
+    }
1480
+
1481
+    $themes = lister_themes_prives();
1482
+    foreach ($themes as $theme) {
1483
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1484
+            return $themefiles["$subdir$file"] = $f;
1485
+        }
1486
+    }
1487
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1488
+
1489
+    return $themefiles["$subdir$file"] = '';
1491 1490
 }
1492 1491
 
1493 1492
 
@@ -1511,31 +1510,31 @@  discard block
 block discarded – undo
1511 1510
  *     sinon chaîne vide.
1512 1511
  **/
1513 1512
 function chemin_image($icone) {
1514
-	static $icone_renommer;
1515
-	if ($p = strpos($icone, '?')) {
1516
-		$icone = substr($icone, 0, $p);
1517
-	}
1518
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1519
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1520
-		return $icone;
1521
-	}
1522
-
1523
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1524
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1525
-		return $f;
1526
-	}
1527
-	// sinon passer par le module de renommage
1528
-	if (is_null($icone_renommer)) {
1529
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1530
-	}
1531
-	if ($icone_renommer) {
1532
-		[$icone, $fonction] = $icone_renommer($icone, '');
1533
-		if (file_exists($icone)) {
1534
-			return $icone;
1535
-		}
1536
-	}
1537
-
1538
-	return find_in_path($icone, _NOM_IMG_PACK);
1513
+    static $icone_renommer;
1514
+    if ($p = strpos($icone, '?')) {
1515
+        $icone = substr($icone, 0, $p);
1516
+    }
1517
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1518
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1519
+        return $icone;
1520
+    }
1521
+
1522
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1523
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1524
+        return $f;
1525
+    }
1526
+    // sinon passer par le module de renommage
1527
+    if (is_null($icone_renommer)) {
1528
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1529
+    }
1530
+    if ($icone_renommer) {
1531
+        [$icone, $fonction] = $icone_renommer($icone, '');
1532
+        if (file_exists($icone)) {
1533
+            return $icone;
1534
+        }
1535
+    }
1536
+
1537
+    return find_in_path($icone, _NOM_IMG_PACK);
1539 1538
 }
1540 1539
 
1541 1540
 //
@@ -1573,128 +1572,128 @@  discard block
 block discarded – undo
1573 1572
  *     - false : fichier introuvable
1574 1573
  **/
1575 1574
 function find_in_path($file, $dirname = '', $include = false) {
1576
-	static $dirs = [];
1577
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1578
-	static $c = '';
1579
-
1580
-	if (!$file and !strlen($file)) {
1581
-		return false;
1582
-	}
1583
-
1584
-	// on calcule le chemin si le dossier skel a change
1585
-	if ($c != $GLOBALS['dossier_squelettes']) {
1586
-		// assurer le non plantage lors de la montee de version :
1587
-		$c = $GLOBALS['dossier_squelettes'];
1588
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1589
-	}
1590
-
1591
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1592
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1593
-			return false;
1594
-		}
1595
-		if ($include and !isset($inc[$dirname][$file])) {
1596
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1597
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1598
-		}
1599
-
1600
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1601
-	}
1602
-
1603
-	$a = strrpos($file, '/');
1604
-	if ($a !== false) {
1605
-		$dirname .= substr($file, 0, ++$a);
1606
-		$file = substr($file, $a);
1607
-	}
1608
-
1609
-	foreach (creer_chemin() as $dir) {
1610
-		if (!isset($dirs[$a = $dir . $dirname])) {
1611
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1612
-		}
1613
-		if ($dirs[$a]) {
1614
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1615
-				if ($include and !isset($inc[$dirname][$file])) {
1616
-					include_once _ROOT_CWD . $a;
1617
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1618
-				}
1619
-				if (!defined('_SAUVER_CHEMIN')) {
1620
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1621
-					if (is_null($GLOBALS['path_files'])) {
1622
-						return $a;
1623
-					}
1624
-					define('_SAUVER_CHEMIN', true);
1625
-				}
1626
-
1627
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1628
-			}
1629
-		}
1630
-	}
1631
-
1632
-	if ($include) {
1633
-		spip_log("include_spip $dirname$file non trouve");
1634
-		if ($include === 'required') {
1635
-			echo '<pre>',
1636
-			'<strong>Erreur Fatale</strong><br />';
1637
-			if (function_exists('debug_print_backtrace')) {
1638
-				echo debug_print_backtrace();
1639
-			}
1640
-			echo '</pre>';
1641
-			die("Erreur interne: ne peut inclure $dirname$file");
1642
-		}
1643
-	}
1644
-
1645
-	if (!defined('_SAUVER_CHEMIN')) {
1646
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1647
-		if (is_null($GLOBALS['path_files'])) {
1648
-			return false;
1649
-		}
1650
-		define('_SAUVER_CHEMIN', true);
1651
-	}
1652
-
1653
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1575
+    static $dirs = [];
1576
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1577
+    static $c = '';
1578
+
1579
+    if (!$file and !strlen($file)) {
1580
+        return false;
1581
+    }
1582
+
1583
+    // on calcule le chemin si le dossier skel a change
1584
+    if ($c != $GLOBALS['dossier_squelettes']) {
1585
+        // assurer le non plantage lors de la montee de version :
1586
+        $c = $GLOBALS['dossier_squelettes'];
1587
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1588
+    }
1589
+
1590
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1591
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1592
+            return false;
1593
+        }
1594
+        if ($include and !isset($inc[$dirname][$file])) {
1595
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1596
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1597
+        }
1598
+
1599
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1600
+    }
1601
+
1602
+    $a = strrpos($file, '/');
1603
+    if ($a !== false) {
1604
+        $dirname .= substr($file, 0, ++$a);
1605
+        $file = substr($file, $a);
1606
+    }
1607
+
1608
+    foreach (creer_chemin() as $dir) {
1609
+        if (!isset($dirs[$a = $dir . $dirname])) {
1610
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1611
+        }
1612
+        if ($dirs[$a]) {
1613
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1614
+                if ($include and !isset($inc[$dirname][$file])) {
1615
+                    include_once _ROOT_CWD . $a;
1616
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1617
+                }
1618
+                if (!defined('_SAUVER_CHEMIN')) {
1619
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1620
+                    if (is_null($GLOBALS['path_files'])) {
1621
+                        return $a;
1622
+                    }
1623
+                    define('_SAUVER_CHEMIN', true);
1624
+                }
1625
+
1626
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1627
+            }
1628
+        }
1629
+    }
1630
+
1631
+    if ($include) {
1632
+        spip_log("include_spip $dirname$file non trouve");
1633
+        if ($include === 'required') {
1634
+            echo '<pre>',
1635
+            '<strong>Erreur Fatale</strong><br />';
1636
+            if (function_exists('debug_print_backtrace')) {
1637
+                echo debug_print_backtrace();
1638
+            }
1639
+            echo '</pre>';
1640
+            die("Erreur interne: ne peut inclure $dirname$file");
1641
+        }
1642
+    }
1643
+
1644
+    if (!defined('_SAUVER_CHEMIN')) {
1645
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1646
+        if (is_null($GLOBALS['path_files'])) {
1647
+            return false;
1648
+        }
1649
+        define('_SAUVER_CHEMIN', true);
1650
+    }
1651
+
1652
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1654 1653
 }
1655 1654
 
1656 1655
 function clear_path_cache() {
1657
-	$GLOBALS['path_files'] = [];
1658
-	spip_unlink(_CACHE_CHEMIN);
1656
+    $GLOBALS['path_files'] = [];
1657
+    spip_unlink(_CACHE_CHEMIN);
1659 1658
 }
1660 1659
 
1661 1660
 function load_path_cache() {
1662
-	// charger le path des plugins
1663
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1664
-		include_once(_CACHE_PLUGINS_PATH);
1665
-	}
1666
-	$GLOBALS['path_files'] = [];
1667
-	// si le visiteur est admin,
1668
-	// on ne recharge pas le cache pour forcer sa mise a jour
1669
-	if (
1670
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1671
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1672
-		// utiliser le cookie est un pis aller qui marche 'en general'
1673
-		// on blinde par un second test au moment de la lecture de la session
1674
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1675
-		// et en ignorant ce cache en cas de recalcul explicite
1676
-		!_request('var_mode')
1677
-	) {
1678
-		// on essaye de lire directement sans verrou pour aller plus vite
1679
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1680
-			// mais si semble corrompu on relit avec un verrou
1681
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1682
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1683
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1684
-					$GLOBALS['path_files'] = [];
1685
-				}
1686
-			}
1687
-		}
1688
-	}
1661
+    // charger le path des plugins
1662
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1663
+        include_once(_CACHE_PLUGINS_PATH);
1664
+    }
1665
+    $GLOBALS['path_files'] = [];
1666
+    // si le visiteur est admin,
1667
+    // on ne recharge pas le cache pour forcer sa mise a jour
1668
+    if (
1669
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1670
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1671
+        // utiliser le cookie est un pis aller qui marche 'en general'
1672
+        // on blinde par un second test au moment de la lecture de la session
1673
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1674
+        // et en ignorant ce cache en cas de recalcul explicite
1675
+        !_request('var_mode')
1676
+    ) {
1677
+        // on essaye de lire directement sans verrou pour aller plus vite
1678
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1679
+            // mais si semble corrompu on relit avec un verrou
1680
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1681
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1682
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1683
+                    $GLOBALS['path_files'] = [];
1684
+                }
1685
+            }
1686
+        }
1687
+    }
1689 1688
 }
1690 1689
 
1691 1690
 function save_path_cache() {
1692
-	if (
1693
-		defined('_SAUVER_CHEMIN')
1694
-		and _SAUVER_CHEMIN
1695
-	) {
1696
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1697
-	}
1691
+    if (
1692
+        defined('_SAUVER_CHEMIN')
1693
+        and _SAUVER_CHEMIN
1694
+    ) {
1695
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1696
+    }
1698 1697
 }
1699 1698
 
1700 1699
 
@@ -1714,33 +1713,33 @@  discard block
 block discarded – undo
1714 1713
  * @return array
1715 1714
  */
1716 1715
 function find_all_in_path($dir, $pattern, $recurs = false) {
1717
-	$liste_fichiers = [];
1718
-	$maxfiles = 10000;
1719
-
1720
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1721
-	// on a pas encore inclus flock.php
1722
-	if (!function_exists('preg_files')) {
1723
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1724
-	}
1725
-
1726
-	// Parcourir le chemin
1727
-	foreach (creer_chemin() as $d) {
1728
-		$f = $d . $dir;
1729
-		if (@is_dir($f)) {
1730
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1731
-			foreach ($liste as $chemin) {
1732
-				$nom = basename($chemin);
1733
-				// ne prendre que les fichiers pas deja trouves
1734
-				// car find_in_path prend le premier qu'il trouve,
1735
-				// les autres sont donc masques
1736
-				if (!isset($liste_fichiers[$nom])) {
1737
-					$liste_fichiers[$nom] = $chemin;
1738
-				}
1739
-			}
1740
-		}
1741
-	}
1742
-
1743
-	return $liste_fichiers;
1716
+    $liste_fichiers = [];
1717
+    $maxfiles = 10000;
1718
+
1719
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1720
+    // on a pas encore inclus flock.php
1721
+    if (!function_exists('preg_files')) {
1722
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1723
+    }
1724
+
1725
+    // Parcourir le chemin
1726
+    foreach (creer_chemin() as $d) {
1727
+        $f = $d . $dir;
1728
+        if (@is_dir($f)) {
1729
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1730
+            foreach ($liste as $chemin) {
1731
+                $nom = basename($chemin);
1732
+                // ne prendre que les fichiers pas deja trouves
1733
+                // car find_in_path prend le premier qu'il trouve,
1734
+                // les autres sont donc masques
1735
+                if (!isset($liste_fichiers[$nom])) {
1736
+                    $liste_fichiers[$nom] = $chemin;
1737
+                }
1738
+            }
1739
+        }
1740
+    }
1741
+
1742
+    return $liste_fichiers;
1744 1743
 }
1745 1744
 
1746 1745
 /**
@@ -1752,17 +1751,17 @@  discard block
 block discarded – undo
1752 1751
  * @return bool
1753 1752
  */
1754 1753
 function autoriser_sans_cookie($nom, $strict = false) {
1755
-	static $autsanscookie = ['install', 'base_repair'];
1754
+    static $autsanscookie = ['install', 'base_repair'];
1756 1755
 
1757
-	if (in_array($nom, $autsanscookie)) {
1758
-		if (test_espace_prive()) {
1759
-			include_spip('base/connect_sql');
1760
-			if (!$strict or !spip_connect()) {
1761
-				return true;
1762
-			}
1763
-		}
1764
-	}
1765
-	return false;
1756
+    if (in_array($nom, $autsanscookie)) {
1757
+        if (test_espace_prive()) {
1758
+            include_spip('base/connect_sql');
1759
+            if (!$strict or !spip_connect()) {
1760
+                return true;
1761
+            }
1762
+        }
1763
+    }
1764
+    return false;
1766 1765
 }
1767 1766
 
1768 1767
 /**
@@ -1772,56 +1771,56 @@  discard block
 block discarded – undo
1772 1771
  * @return string
1773 1772
  */
1774 1773
 function charger_fonction_url(string $quoi, string $type = '') {
1775
-	if ($type === 'defaut') {
1776
-		$objet = objet_type($quoi);
1777
-		if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1778
-			// deprecated
1779
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1780
-		) {
1781
-			return $f;
1782
-		}
1783
-		return '';
1784
-	}
1785
-
1786
-	if (!$type) {
1787
-		$type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1788
-	}
1789
-
1790
-	// inclure le module d'url
1791
-	include_spip('urls/'.$type);
1792
-
1793
-	switch ($quoi) {
1794
-		case 'page':
1795
-			if (
1796
-				 function_exists($f = "urls_{$type}_generer_url_page")
1797
-			  or function_exists($f .= "_dist")
1798
-			  // ou une fonction custom utilisateur independante du type d'url
1799
-			  or function_exists($f = "generer_url_page")
1800
-			  or function_exists($f .= "_dist")
1801
-			) {
1802
-				return $f;
1803
-			}
1804
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1805
-			return '';
1806
-		case 'objet':
1807
-		case 'decoder':
1808
-		default:
1809
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1810
-			if (function_exists($f = "urls_{$type}_{$fquoi}")
1811
-			  or function_exists($f .= "_dist")) {
1812
-				return $f;
1813
-			}
1814
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1815
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1816
-			if ($f = charger_fonction($type, 'urls', true)) {
1817
-				return $f;
1818
-			}
1819
-			// sinon on se rabat sur les urls page
1820
-			if ($type !== 'page') {
1821
-				return charger_fonction_url($quoi, 'page');
1822
-			}
1823
-			return '';
1824
-	}
1774
+    if ($type === 'defaut') {
1775
+        $objet = objet_type($quoi);
1776
+        if ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1777
+            // deprecated
1778
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1779
+        ) {
1780
+            return $f;
1781
+        }
1782
+        return '';
1783
+    }
1784
+
1785
+    if (!$type) {
1786
+        $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1787
+    }
1788
+
1789
+    // inclure le module d'url
1790
+    include_spip('urls/'.$type);
1791
+
1792
+    switch ($quoi) {
1793
+        case 'page':
1794
+            if (
1795
+                    function_exists($f = "urls_{$type}_generer_url_page")
1796
+              or function_exists($f .= "_dist")
1797
+                // ou une fonction custom utilisateur independante du type d'url
1798
+              or function_exists($f = "generer_url_page")
1799
+              or function_exists($f .= "_dist")
1800
+            ) {
1801
+                return $f;
1802
+            }
1803
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1804
+            return '';
1805
+        case 'objet':
1806
+        case 'decoder':
1807
+        default:
1808
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1809
+            if (function_exists($f = "urls_{$type}_{$fquoi}")
1810
+              or function_exists($f .= "_dist")) {
1811
+                return $f;
1812
+            }
1813
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1814
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1815
+            if ($f = charger_fonction($type, 'urls', true)) {
1816
+                return $f;
1817
+            }
1818
+            // sinon on se rabat sur les urls page
1819
+            if ($type !== 'page') {
1820
+                return charger_fonction_url($quoi, 'page');
1821
+            }
1822
+            return '';
1823
+    }
1825 1824
 }
1826 1825
 
1827 1826
 
@@ -1850,46 +1849,46 @@  discard block
 block discarded – undo
1850 1849
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire)
1851 1850
  */
1852 1851
 function generer_objet_url(int $id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1853
-	if ($public === null) {
1854
-		$public = !test_espace_prive();
1855
-	}
1856
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1857
-
1858
-	if (!$public) {
1859
-		if (!$entite) {
1860
-			return '';
1861
-		}
1862
-		if (!function_exists('generer_objet_url_ecrire')) {
1863
-			include_spip('inc/urls');
1864
-		}
1865
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1866
-	} else {
1867
-		$f = charger_fonction_url('objet', $type ?? '');
1868
-
1869
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1870
-		// @see charger_fonction_url
1871
-		if (!$entite) {
1872
-			return $f;
1873
-		}
1874
-
1875
-		// mais d'abord il faut tester le cas des urls sur une
1876
-		// base distante
1877
-		if ($connect
1878
-			and $g = charger_fonction('connect', 'urls', true)
1879
-		) {
1880
-			$f = $g;
1881
-		}
1882
-
1883
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1884
-	}
1885
-	if ($res) {
1886
-		return $res;
1887
-	}
1888
-
1889
-	// On a ete gentil mais la ....
1890
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1891
-
1892
-	return '';
1852
+    if ($public === null) {
1853
+        $public = !test_espace_prive();
1854
+    }
1855
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1856
+
1857
+    if (!$public) {
1858
+        if (!$entite) {
1859
+            return '';
1860
+        }
1861
+        if (!function_exists('generer_objet_url_ecrire')) {
1862
+            include_spip('inc/urls');
1863
+        }
1864
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1865
+    } else {
1866
+        $f = charger_fonction_url('objet', $type ?? '');
1867
+
1868
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1869
+        // @see charger_fonction_url
1870
+        if (!$entite) {
1871
+            return $f;
1872
+        }
1873
+
1874
+        // mais d'abord il faut tester le cas des urls sur une
1875
+        // base distante
1876
+        if ($connect
1877
+            and $g = charger_fonction('connect', 'urls', true)
1878
+        ) {
1879
+            $f = $g;
1880
+        }
1881
+
1882
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1883
+    }
1884
+    if ($res) {
1885
+        return $res;
1886
+    }
1887
+
1888
+    // On a ete gentil mais la ....
1889
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1890
+
1891
+    return '';
1893 1892
 }
1894 1893
 
1895 1894
 /**
@@ -1897,10 +1896,10 @@  discard block
 block discarded – undo
1897 1896
  * @see generer_objet_url
1898 1897
  */
1899 1898
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null){
1900
-	if ($public and is_string($public)) {
1901
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1902
-	}
1903
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1899
+    if ($public and is_string($public)) {
1900
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1901
+    }
1902
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1904 1903
 }
1905 1904
 
1906 1905
 /**
@@ -1912,18 +1911,18 @@  discard block
 block discarded – undo
1912 1911
  * @return string
1913 1912
  */
1914 1913
 function generer_objet_url_ecrire_edit(int $id, string $entite, string $args = '', string $ancre = ''): string {
1915
-	$exec = objet_info($entite, 'url_edit');
1916
-	$url = generer_url_ecrire($exec, $args);
1917
-	if (intval($id)) {
1918
-		$url = parametre_url($url, id_table_objet($entite), $id);
1919
-	} else {
1920
-		$url = parametre_url($url, 'new', 'oui');
1921
-	}
1922
-	if ($ancre) {
1923
-		$url = ancre_url($url, $ancre);
1924
-	}
1914
+    $exec = objet_info($entite, 'url_edit');
1915
+    $url = generer_url_ecrire($exec, $args);
1916
+    if (intval($id)) {
1917
+        $url = parametre_url($url, id_table_objet($entite), $id);
1918
+    } else {
1919
+        $url = parametre_url($url, 'new', 'oui');
1920
+    }
1921
+    if ($ancre) {
1922
+        $url = ancre_url($url, $ancre);
1923
+    }
1925 1924
 
1926
-	return $url;
1925
+    return $url;
1927 1926
 }
1928 1927
 
1929 1928
 /**
@@ -1931,18 +1930,18 @@  discard block
 block discarded – undo
1931 1930
  * @see generer_objet_url_ecrire_edit
1932 1931
  */
1933 1932
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = ''){
1934
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1933
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1935 1934
 }
1936 1935
 
1937 1936
 
1938 1937
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1939
-	include_spip('base/connect_sql');
1940
-	$id_type = id_table_objet($entite, $public);
1938
+    include_spip('base/connect_sql');
1939
+    $id_type = id_table_objet($entite, $public);
1941 1940
 
1942
-	return _DIR_RACINE . get_spip_script('./')
1943
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1944
-	. (!$args ? '' : "&$args")
1945
-	. (!$ancre ? '' : "#$ancre");
1941
+    return _DIR_RACINE . get_spip_script('./')
1942
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1943
+    . (!$args ? '' : "&$args")
1944
+    . (!$ancre ? '' : "#$ancre");
1946 1945
 }
1947 1946
 
1948 1947
 
@@ -1953,18 +1952,18 @@  discard block
 block discarded – undo
1953 1952
  * @return string
1954 1953
  */
1955 1954
 function urlencode_1738($url) {
1956
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1957
-		$uri = '';
1958
-		for ($i = 0; $i < strlen($url); $i++) {
1959
-			if (ord($a = $url[$i]) > 127) {
1960
-				$a = rawurlencode($a);
1961
-			}
1962
-			$uri .= $a;
1963
-		}
1964
-		$url = $uri;
1965
-	}
1955
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1956
+        $uri = '';
1957
+        for ($i = 0; $i < strlen($url); $i++) {
1958
+            if (ord($a = $url[$i]) > 127) {
1959
+                $a = rawurlencode($a);
1960
+            }
1961
+            $uri .= $a;
1962
+        }
1963
+        $url = $uri;
1964
+    }
1966 1965
 
1967
-	return quote_amp($url);
1966
+    return quote_amp($url);
1968 1967
 }
1969 1968
 
1970 1969
 /**
@@ -1980,13 +1979,13 @@  discard block
 block discarded – undo
1980 1979
  * @return string
1981 1980
  */
1982 1981
 function generer_objet_url_absolue(int $id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1983
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1984
-	if (!preg_match(',^\w+:,', $h)) {
1985
-		include_spip('inc/filtres_mini');
1986
-		$h = url_absolue($h);
1987
-	}
1982
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1983
+    if (!preg_match(',^\w+:,', $h)) {
1984
+        include_spip('inc/filtres_mini');
1985
+        $h = url_absolue($h);
1986
+    }
1988 1987
 
1989
-	return $h;
1988
+    return $h;
1990 1989
 }
1991 1990
 
1992 1991
 /**
@@ -1994,7 +1993,7 @@  discard block
 block discarded – undo
1994 1993
  * @see  generer_objet_url_absolue
1995 1994
  */
1996 1995
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null){
1997
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
1996
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
1998 1997
 }
1999 1998
 
2000 1999
 
@@ -2010,11 +2009,11 @@  discard block
 block discarded – undo
2010 2009
  *     true si la valeur est considérée active ; false sinon.
2011 2010
  **/
2012 2011
 function test_valeur_serveur($truc) {
2013
-	if (!$truc) {
2014
-		return false;
2015
-	}
2012
+    if (!$truc) {
2013
+        return false;
2014
+    }
2016 2015
 
2017
-	return (strtolower($truc) !== 'off');
2016
+    return (strtolower($truc) !== 'off');
2018 2017
 }
2019 2018
 
2020 2019
 //
@@ -2042,82 +2041,82 @@  discard block
 block discarded – undo
2042 2041
  */
2043 2042
 function url_de_base($profondeur = null) {
2044 2043
 
2045
-	static $url = [];
2046
-	if (is_array($profondeur)) {
2047
-		return $url = $profondeur;
2048
-	}
2049
-	if ($profondeur === false) {
2050
-		return $url;
2051
-	}
2052
-
2053
-	if (is_null($profondeur)) {
2054
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2055
-	}
2056
-
2057
-	if (isset($url[$profondeur])) {
2058
-		return $url[$profondeur];
2059
-	}
2060
-
2061
-	$http = 'http';
2062
-
2063
-	if (
2064
-		isset($_SERVER['SCRIPT_URI'])
2065
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2066
-	) {
2067
-		$http = 'https';
2068
-	} elseif (
2069
-		isset($_SERVER['HTTPS'])
2070
-		and test_valeur_serveur($_SERVER['HTTPS'])
2071
-	) {
2072
-		$http = 'https';
2073
-	}
2074
-
2075
-	// note : HTTP_HOST contient le :port si necessaire
2076
-	$host = $_SERVER['HTTP_HOST'] ?? null;
2077
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2078
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2079
-		$host = $GLOBALS['meta']['adresse_site'];
2080
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2081
-			$http = $scheme;
2082
-			$host = str_replace("{$scheme}://", '', $host);
2083
-		}
2084
-	}
2085
-	if (
2086
-		isset($_SERVER['SERVER_PORT'])
2087
-		and $port = $_SERVER['SERVER_PORT']
2088
-		and strpos($host, ':') == false
2089
-	) {
2090
-		if (!defined('_PORT_HTTP_STANDARD')) {
2091
-			define('_PORT_HTTP_STANDARD', '80');
2092
-		}
2093
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2094
-			define('_PORT_HTTPS_STANDARD', '443');
2095
-		}
2096
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2097
-			$host .= ":$port";
2098
-		}
2099
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2100
-			$host .= ":$port";
2101
-		}
2102
-	}
2103
-
2104
-	if (!$GLOBALS['REQUEST_URI']) {
2105
-		if (isset($_SERVER['REQUEST_URI'])) {
2106
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2107
-		} else {
2108
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2109
-			if (
2110
-				!empty($_SERVER['QUERY_STRING'])
2111
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2112
-			) {
2113
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2114
-			}
2115
-		}
2116
-	}
2117
-
2118
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2119
-
2120
-	return $url[$profondeur];
2044
+    static $url = [];
2045
+    if (is_array($profondeur)) {
2046
+        return $url = $profondeur;
2047
+    }
2048
+    if ($profondeur === false) {
2049
+        return $url;
2050
+    }
2051
+
2052
+    if (is_null($profondeur)) {
2053
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2054
+    }
2055
+
2056
+    if (isset($url[$profondeur])) {
2057
+        return $url[$profondeur];
2058
+    }
2059
+
2060
+    $http = 'http';
2061
+
2062
+    if (
2063
+        isset($_SERVER['SCRIPT_URI'])
2064
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2065
+    ) {
2066
+        $http = 'https';
2067
+    } elseif (
2068
+        isset($_SERVER['HTTPS'])
2069
+        and test_valeur_serveur($_SERVER['HTTPS'])
2070
+    ) {
2071
+        $http = 'https';
2072
+    }
2073
+
2074
+    // note : HTTP_HOST contient le :port si necessaire
2075
+    $host = $_SERVER['HTTP_HOST'] ?? null;
2076
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2077
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2078
+        $host = $GLOBALS['meta']['adresse_site'];
2079
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2080
+            $http = $scheme;
2081
+            $host = str_replace("{$scheme}://", '', $host);
2082
+        }
2083
+    }
2084
+    if (
2085
+        isset($_SERVER['SERVER_PORT'])
2086
+        and $port = $_SERVER['SERVER_PORT']
2087
+        and strpos($host, ':') == false
2088
+    ) {
2089
+        if (!defined('_PORT_HTTP_STANDARD')) {
2090
+            define('_PORT_HTTP_STANDARD', '80');
2091
+        }
2092
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2093
+            define('_PORT_HTTPS_STANDARD', '443');
2094
+        }
2095
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2096
+            $host .= ":$port";
2097
+        }
2098
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2099
+            $host .= ":$port";
2100
+        }
2101
+    }
2102
+
2103
+    if (!$GLOBALS['REQUEST_URI']) {
2104
+        if (isset($_SERVER['REQUEST_URI'])) {
2105
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2106
+        } else {
2107
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2108
+            if (
2109
+                !empty($_SERVER['QUERY_STRING'])
2110
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2111
+            ) {
2112
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2113
+            }
2114
+        }
2115
+    }
2116
+
2117
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2118
+
2119
+    return $url[$profondeur];
2121 2120
 }
2122 2121
 
2123 2122
 /**
@@ -2130,26 +2129,26 @@  discard block
 block discarded – undo
2130 2129
  * @return string
2131 2130
  */
2132 2131
 function url_de_($http, $host, $request, $prof = 0) {
2133
-	$prof = max($prof, 0);
2132
+    $prof = max($prof, 0);
2134 2133
 
2135
-	$myself = ltrim($request, '/');
2136
-	# supprimer la chaine de GET
2137
-	[$myself] = explode('?', $myself);
2138
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2139
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2140
-	if (strpos($myself, '://') !== false) {
2141
-		$myself = explode('://', $myself);
2142
-		array_shift($myself);
2143
-		$myself = implode('://', $myself);
2144
-		$myself = explode('/', $myself);
2145
-		array_shift($myself);
2146
-		$myself = implode('/', $myself);
2147
-	}
2148
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2134
+    $myself = ltrim($request, '/');
2135
+    # supprimer la chaine de GET
2136
+    [$myself] = explode('?', $myself);
2137
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2138
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2139
+    if (strpos($myself, '://') !== false) {
2140
+        $myself = explode('://', $myself);
2141
+        array_shift($myself);
2142
+        $myself = implode('://', $myself);
2143
+        $myself = explode('/', $myself);
2144
+        array_shift($myself);
2145
+        $myself = implode('/', $myself);
2146
+    }
2147
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2149 2148
 
2150
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2149
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2151 2150
 
2152
-	return $url;
2151
+    return $url;
2153 2152
 }
2154 2153
 
2155 2154
 
@@ -2184,25 +2183,25 @@  discard block
 block discarded – undo
2184 2183
  * @return string URL
2185 2184
  **/
2186 2185
 function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) {
2187
-	if (!$rel) {
2188
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2189
-	} else {
2190
-		if (!is_string($rel)) {
2191
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2192
-		}
2193
-	}
2194
-
2195
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2196
-	if ($script and ($script <> 'accueil' or $rel)) {
2197
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2198
-	} elseif ($args) {
2199
-		$args = "?$args";
2200
-	}
2201
-	if ($ancre) {
2202
-		$args .= "#$ancre";
2203
-	}
2204
-
2205
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2186
+    if (!$rel) {
2187
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2188
+    } else {
2189
+        if (!is_string($rel)) {
2190
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2191
+        }
2192
+    }
2193
+
2194
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2195
+    if ($script and ($script <> 'accueil' or $rel)) {
2196
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2197
+    } elseif ($args) {
2198
+        $args = "?$args";
2199
+    }
2200
+    if ($ancre) {
2201
+        $args .= "#$ancre";
2202
+    }
2203
+
2204
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2206 2205
 }
2207 2206
 
2208 2207
 //
@@ -2224,15 +2223,15 @@  discard block
 block discarded – undo
2224 2223
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2225 2224
  **/
2226 2225
 function get_spip_script($default = '') {
2227
-	if (!defined('_SPIP_SCRIPT')) {
2228
-		return 'spip.php';
2229
-	}
2230
-	# cas define('_SPIP_SCRIPT', '');
2231
-	if (_SPIP_SCRIPT) {
2232
-		return _SPIP_SCRIPT;
2233
-	} else {
2234
-		return $default;
2235
-	}
2226
+    if (!defined('_SPIP_SCRIPT')) {
2227
+        return 'spip.php';
2228
+    }
2229
+    # cas define('_SPIP_SCRIPT', '');
2230
+    if (_SPIP_SCRIPT) {
2231
+        return _SPIP_SCRIPT;
2232
+    } else {
2233
+        return $default;
2234
+    }
2236 2235
 }
2237 2236
 
2238 2237
 /**
@@ -2261,45 +2260,45 @@  discard block
 block discarded – undo
2261 2260
  * @return string URL
2262 2261
  **/
2263 2262
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2264
-	// si le script est une action (spip_pass, spip_inscription),
2265
-	// standardiser vers la nouvelle API
2266
-
2267
-	if (is_array($args)) {
2268
-		$args = http_build_query($args);
2269
-	}
2270
-
2271
-	$url = '';
2272
-	if ($f = charger_fonction_url('page')) {
2273
-		$url = $f($script, $args);
2274
-		if ($url and !$rel) {
2275
-			include_spip('inc/filtres_mini');
2276
-			$url = url_absolue($url);
2277
-		}
2278
-	}
2279
-	if (!$url) {
2280
-		if (!$action) {
2281
-			$action = get_spip_script();
2282
-		}
2283
-		if ($script) {
2284
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2285
-		}
2286
-		if ($args) {
2287
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2288
-		}
2289
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2290
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2291
-	}
2292
-
2293
-	if (!$no_entities) {
2294
-		$url = quote_amp($url);
2295
-	}
2296
-
2297
-	return $url;
2263
+    // si le script est une action (spip_pass, spip_inscription),
2264
+    // standardiser vers la nouvelle API
2265
+
2266
+    if (is_array($args)) {
2267
+        $args = http_build_query($args);
2268
+    }
2269
+
2270
+    $url = '';
2271
+    if ($f = charger_fonction_url('page')) {
2272
+        $url = $f($script, $args);
2273
+        if ($url and !$rel) {
2274
+            include_spip('inc/filtres_mini');
2275
+            $url = url_absolue($url);
2276
+        }
2277
+    }
2278
+    if (!$url) {
2279
+        if (!$action) {
2280
+            $action = get_spip_script();
2281
+        }
2282
+        if ($script) {
2283
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2284
+        }
2285
+        if ($args) {
2286
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2287
+        }
2288
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2289
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2290
+    }
2291
+
2292
+    if (!$no_entities) {
2293
+        $url = quote_amp($url);
2294
+    }
2295
+
2296
+    return $url;
2298 2297
 }
2299 2298
 
2300 2299
 function generer_url_prive($script, $args = '', $no_entities = false) {
2301 2300
 
2302
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2301
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2303 2302
 }
2304 2303
 
2305 2304
 // Pour les formulaires en methode POST,
@@ -2324,19 +2323,19 @@  discard block
 block discarded – undo
2324 2323
  **/
2325 2324
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2326 2325
 
2327
-	$script1 = explode('&', $script);
2328
-	$script1 = reset($script1);
2326
+    $script1 = explode('&', $script);
2327
+    $script1 = reset($script1);
2329 2328
 
2330
-	return "<form action='"
2331
-	. ($script ? generer_url_ecrire($script) : '')
2332
-	. "' "
2333
-	. ($atts ?: " method='post'")
2334
-	. "><div>\n"
2335
-	. "<input type='hidden' name='exec' value='$script1' />"
2336
-	. $corps
2337
-	. (!$submit ? '' :
2338
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2339
-	. "</div></form>\n";
2329
+    return "<form action='"
2330
+    . ($script ? generer_url_ecrire($script) : '')
2331
+    . "' "
2332
+    . ($atts ?: " method='post'")
2333
+    . "><div>\n"
2334
+    . "<input type='hidden' name='exec' value='$script1' />"
2335
+    . $corps
2336
+    . (!$submit ? '' :
2337
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2338
+    . "</div></form>\n";
2340 2339
 }
2341 2340
 
2342 2341
 /**
@@ -2353,22 +2352,22 @@  discard block
 block discarded – undo
2353 2352
  * @return string
2354 2353
  */
2355 2354
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2356
-	// si l'on est dans l'espace prive, on garde dans l'url
2357
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2358
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2359
-	$h = (_DIR_RACINE and !$public)
2360
-		? generer_url_ecrire(_request('exec'))
2361
-		: generer_url_public();
2355
+    // si l'on est dans l'espace prive, on garde dans l'url
2356
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2357
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2358
+    $h = (_DIR_RACINE and !$public)
2359
+        ? generer_url_ecrire(_request('exec'))
2360
+        : generer_url_public();
2362 2361
 
2363
-	return "\n<form action='" .
2364
-	$h .
2365
-	"'" .
2366
-	$atts .
2367
-	">\n" .
2368
-	'<div>' .
2369
-	"\n<input type='hidden' name='action' value='$script' />" .
2370
-	$corps .
2371
-	'</div></form>';
2362
+    return "\n<form action='" .
2363
+    $h .
2364
+    "'" .
2365
+    $atts .
2366
+    ">\n" .
2367
+    '<div>' .
2368
+    "\n<input type='hidden' name='action' value='$script' />" .
2369
+    $corps .
2370
+    '</div></form>';
2372 2371
 }
2373 2372
 
2374 2373
 /**
@@ -2387,22 +2386,22 @@  discard block
 block discarded – undo
2387 2386
  *     URL
2388 2387
  */
2389 2388
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2390
-	// si l'on est dans l'espace prive, on garde dans l'url
2391
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2392
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2393
-	$url = (_DIR_RACINE and !$public)
2394
-		? generer_url_ecrire(_request('exec'))
2395
-		: generer_url_public('', '', false, false);
2396
-	$url = parametre_url($url, 'action', $script);
2397
-	if ($args) {
2398
-		$url .= quote_amp('&' . $args);
2399
-	}
2389
+    // si l'on est dans l'espace prive, on garde dans l'url
2390
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2391
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2392
+    $url = (_DIR_RACINE and !$public)
2393
+        ? generer_url_ecrire(_request('exec'))
2394
+        : generer_url_public('', '', false, false);
2395
+    $url = parametre_url($url, 'action', $script);
2396
+    if ($args) {
2397
+        $url .= quote_amp('&' . $args);
2398
+    }
2400 2399
 
2401
-	if ($no_entities) {
2402
-		$url = str_replace('&amp;', '&', $url);
2403
-	}
2400
+    if ($no_entities) {
2401
+        $url = str_replace('&amp;', '&', $url);
2402
+    }
2404 2403
 
2405
-	return $url;
2404
+    return $url;
2406 2405
 }
2407 2406
 
2408 2407
 
@@ -2415,8 +2414,8 @@  discard block
 block discarded – undo
2415 2414
  * @param string $ta Répertoire temporaire accessible
2416 2415
  */
2417 2416
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2418
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2419
-	spip_initialisation_suite();
2417
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2418
+    spip_initialisation_suite();
2420 2419
 }
2421 2420
 
2422 2421
 /**
@@ -2436,322 +2435,322 @@  discard block
 block discarded – undo
2436 2435
  * @param string $ta Répertoire temporaire accessible
2437 2436
  */
2438 2437
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2439
-	static $too_late = 0;
2440
-	if ($too_late++) {
2441
-		return;
2442
-	}
2443
-
2444
-	// Declaration des repertoires
2445
-
2446
-	// le nom du repertoire plugins/ activables/desactivables
2447
-	if (!defined('_DIR_PLUGINS')) {
2448
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2449
-	}
2450
-
2451
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2452
-	if (!defined('_DIR_PLUGINS_DIST')) {
2453
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2454
-	}
2455
-
2456
-	// le nom du repertoire des librairies
2457
-	if (!defined('_DIR_LIB')) {
2458
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2459
-	}
2460
-
2461
-	if (!defined('_DIR_IMG')) {
2462
-		define('_DIR_IMG', $pa);
2463
-	}
2464
-	if (!defined('_DIR_LOGOS')) {
2465
-		define('_DIR_LOGOS', $pa);
2466
-	}
2467
-	if (!defined('_DIR_IMG_ICONES')) {
2468
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2469
-	}
2470
-
2471
-	if (!defined('_DIR_DUMP')) {
2472
-		define('_DIR_DUMP', $ti . 'dump/');
2473
-	}
2474
-	if (!defined('_DIR_SESSIONS')) {
2475
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2476
-	}
2477
-	if (!defined('_DIR_TRANSFERT')) {
2478
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2479
-	}
2480
-	if (!defined('_DIR_CACHE')) {
2481
-		define('_DIR_CACHE', $ti . 'cache/');
2482
-	}
2483
-	if (!defined('_DIR_CACHE_XML')) {
2484
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2485
-	}
2486
-	if (!defined('_DIR_SKELS')) {
2487
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2488
-	}
2489
-	if (!defined('_DIR_AIDE')) {
2490
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2491
-	}
2492
-	if (!defined('_DIR_TMP')) {
2493
-		define('_DIR_TMP', $ti);
2494
-	}
2495
-
2496
-	if (!defined('_DIR_VAR')) {
2497
-		define('_DIR_VAR', $ta);
2498
-	}
2499
-
2500
-	if (!defined('_DIR_ETC')) {
2501
-		define('_DIR_ETC', $pi);
2502
-	}
2503
-	if (!defined('_DIR_CONNECT')) {
2504
-		define('_DIR_CONNECT', $pi);
2505
-	}
2506
-	if (!defined('_DIR_CHMOD')) {
2507
-		define('_DIR_CHMOD', $pi);
2508
-	}
2509
-
2510
-	if (!isset($GLOBALS['test_dirs'])) {
2511
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2512
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2513
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2514
-	}
2515
-
2516
-	// Declaration des fichiers
2517
-
2518
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2519
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2520
-	}
2521
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2522
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2523
-	}
2524
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2525
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2526
-	}
2527
-	if (!defined('_CACHE_PIPELINES')) {
2528
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2529
-	}
2530
-	if (!defined('_CACHE_CHEMIN')) {
2531
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2532
-	}
2533
-
2534
-	# attention .php obligatoire pour ecrire_fichier_securise
2535
-	if (!defined('_FILE_META')) {
2536
-		define('_FILE_META', $ti . 'meta_cache.php');
2537
-	}
2538
-	if (!defined('_DIR_LOG')) {
2539
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2540
-	}
2541
-	if (!defined('_FILE_LOG')) {
2542
-		define('_FILE_LOG', 'spip');
2543
-	}
2544
-	if (!defined('_FILE_LOG_SUFFIX')) {
2545
-		define('_FILE_LOG_SUFFIX', '.log');
2546
-	}
2547
-
2548
-	// Le fichier de connexion a la base de donnees
2549
-	// tient compte des anciennes versions (inc_connect...)
2550
-	if (!defined('_FILE_CONNECT_INS')) {
2551
-		define('_FILE_CONNECT_INS', 'connect');
2552
-	}
2553
-	if (!defined('_FILE_CONNECT')) {
2554
-		define(
2555
-			'_FILE_CONNECT',
2556
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2557
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2558
-			: false))
2559
-		);
2560
-	}
2561
-
2562
-	// Le fichier de reglages des droits
2563
-	if (!defined('_FILE_CHMOD_INS')) {
2564
-		define('_FILE_CHMOD_INS', 'chmod');
2565
-	}
2566
-	if (!defined('_FILE_CHMOD')) {
2567
-		define(
2568
-			'_FILE_CHMOD',
2569
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2570
-			: false)
2571
-		);
2572
-	}
2573
-
2574
-	if (!defined('_FILE_LDAP')) {
2575
-		define('_FILE_LDAP', 'ldap.php');
2576
-	}
2577
-
2578
-	if (!defined('_FILE_TMP_SUFFIX')) {
2579
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2580
-	}
2581
-	if (!defined('_FILE_CONNECT_TMP')) {
2582
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2583
-	}
2584
-	if (!defined('_FILE_CHMOD_TMP')) {
2585
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2586
-	}
2587
-
2588
-	// Definition des droits d'acces en ecriture
2589
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2590
-		include_once _FILE_CHMOD;
2591
-	}
2592
-
2593
-	// Se mefier des fichiers mal remplis!
2594
-	if (!defined('_SPIP_CHMOD')) {
2595
-		define('_SPIP_CHMOD', 0777);
2596
-	}
2597
-
2598
-	if (!defined('_DEFAULT_CHARSET')) {
2599
-		/** Le charset par défaut lors de l'installation */
2600
-		define('_DEFAULT_CHARSET', 'utf-8');
2601
-	}
2602
-	if (!defined('_ROOT_PLUGINS')) {
2603
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2604
-	}
2605
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2606
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2607
-	}
2608
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2609
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2610
-	}
2611
-
2612
-	// La taille des Log
2613
-	if (!defined('_MAX_LOG')) {
2614
-		define('_MAX_LOG', 100);
2615
-	}
2616
-
2617
-	// Sommes-nous dans l'empire du Mal ?
2618
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2619
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2620
-		if (!defined('_OS_SERVEUR')) {
2621
-			define('_OS_SERVEUR', 'windows');
2622
-		}
2623
-		if (!defined('_SPIP_LOCK_MODE')) {
2624
-			define('_SPIP_LOCK_MODE', 1);
2625
-		} // utiliser le flock php
2626
-	} else {
2627
-		if (!defined('_OS_SERVEUR')) {
2628
-			define('_OS_SERVEUR', '');
2629
-		}
2630
-		if (!defined('_SPIP_LOCK_MODE')) {
2631
-			define('_SPIP_LOCK_MODE', 1);
2632
-		} // utiliser le flock php
2633
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2634
-	}
2635
-
2636
-	// Langue par defaut
2637
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2638
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2639
-	}
2640
-
2641
-	//
2642
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2643
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2644
-	// pour le rendre surchargeable, on va provoquer un reecriture
2645
-	// systematique du noyau ou une baisse de perfs => a etudier)
2646
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2647
-
2648
-	// charger tout de suite le path et son cache
2649
-	load_path_cache();
2650
-
2651
-	// *********** traiter les variables ************
2652
-
2653
-	//
2654
-	// Securite
2655
-	//
2656
-
2657
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2658
-	if (isset($_REQUEST['GLOBALS'])) {
2659
-		die();
2660
-	}
2661
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2662
-	spip_desinfecte($_GET);
2663
-	spip_desinfecte($_POST);
2664
-	spip_desinfecte($_COOKIE);
2665
-	spip_desinfecte($_REQUEST);
2666
-
2667
-	// appliquer le cookie_prefix
2668
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2669
-		include_spip('inc/cookie');
2670
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2671
-	}
2672
-
2673
-	//
2674
-	// Capacites php (en fonction de la version)
2675
-	//
2676
-	$GLOBALS['flag_ob'] = (function_exists('ob_start')
2677
-		&& function_exists('ini_get')
2678
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2679
-	$GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2680
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2681
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2682
-		(get_cfg_var('upload_max_filesize') > 0));
2683
-
2684
-
2685
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2686
-	if (isset($_SERVER['REQUEST_URI'])) {
2687
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2688
-	} else {
2689
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2690
-		if (
2691
-			!empty($_SERVER['QUERY_STRING'])
2692
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2693
-		) {
2694
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2695
-		}
2696
-	}
2697
-
2698
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2699
-	if (!defined('_RENOUVELLE_ALEA')) {
2700
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2701
-	}
2702
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2703
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2704
-	}
2705
-
2706
-	// charger les meta si possible et renouveller l'alea au besoin
2707
-	// charge aussi effacer_meta et ecrire_meta
2708
-	$inc_meta = charger_fonction('meta', 'inc');
2709
-	$inc_meta();
2710
-
2711
-	// nombre de repertoires depuis la racine
2712
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2713
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2714
-	// le calcul est faux)
2715
-	if (!_DIR_RESTREINT) {
2716
-		$GLOBALS['profondeur_url'] = 1;
2717
-	} else {
2718
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2719
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2720
-		if (
2721
-			!$uri_ref
2722
-			// si on est appele avec un autre ti, on est sans doute en mutu
2723
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2724
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2725
-			// s'en remettre a l'adresse du site. alea jacta est.
2726
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2727
-		) {
2728
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2729
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2730
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2731
-			} else {
2732
-				$uri_ref = '';
2733
-			}
2734
-		}
2735
-		if (!$uri or !$uri_ref) {
2736
-			$GLOBALS['profondeur_url'] = 0;
2737
-		} else {
2738
-			$GLOBALS['profondeur_url'] = max(
2739
-				0,
2740
-				substr_count($uri[0], '/')
2741
-				- substr_count($uri_ref, '/')
2742
-			);
2743
-		}
2744
-	}
2745
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2746
-	if (_FILE_CONNECT) {
2747
-		if (
2748
-			verifier_visiteur() == '0minirezo'
2749
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2750
-			and !isset($_COOKIE['spip_admin'])
2751
-		) {
2752
-			clear_path_cache();
2753
-		}
2754
-	}
2438
+    static $too_late = 0;
2439
+    if ($too_late++) {
2440
+        return;
2441
+    }
2442
+
2443
+    // Declaration des repertoires
2444
+
2445
+    // le nom du repertoire plugins/ activables/desactivables
2446
+    if (!defined('_DIR_PLUGINS')) {
2447
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2448
+    }
2449
+
2450
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2451
+    if (!defined('_DIR_PLUGINS_DIST')) {
2452
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2453
+    }
2454
+
2455
+    // le nom du repertoire des librairies
2456
+    if (!defined('_DIR_LIB')) {
2457
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2458
+    }
2459
+
2460
+    if (!defined('_DIR_IMG')) {
2461
+        define('_DIR_IMG', $pa);
2462
+    }
2463
+    if (!defined('_DIR_LOGOS')) {
2464
+        define('_DIR_LOGOS', $pa);
2465
+    }
2466
+    if (!defined('_DIR_IMG_ICONES')) {
2467
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2468
+    }
2469
+
2470
+    if (!defined('_DIR_DUMP')) {
2471
+        define('_DIR_DUMP', $ti . 'dump/');
2472
+    }
2473
+    if (!defined('_DIR_SESSIONS')) {
2474
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2475
+    }
2476
+    if (!defined('_DIR_TRANSFERT')) {
2477
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2478
+    }
2479
+    if (!defined('_DIR_CACHE')) {
2480
+        define('_DIR_CACHE', $ti . 'cache/');
2481
+    }
2482
+    if (!defined('_DIR_CACHE_XML')) {
2483
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2484
+    }
2485
+    if (!defined('_DIR_SKELS')) {
2486
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2487
+    }
2488
+    if (!defined('_DIR_AIDE')) {
2489
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2490
+    }
2491
+    if (!defined('_DIR_TMP')) {
2492
+        define('_DIR_TMP', $ti);
2493
+    }
2494
+
2495
+    if (!defined('_DIR_VAR')) {
2496
+        define('_DIR_VAR', $ta);
2497
+    }
2498
+
2499
+    if (!defined('_DIR_ETC')) {
2500
+        define('_DIR_ETC', $pi);
2501
+    }
2502
+    if (!defined('_DIR_CONNECT')) {
2503
+        define('_DIR_CONNECT', $pi);
2504
+    }
2505
+    if (!defined('_DIR_CHMOD')) {
2506
+        define('_DIR_CHMOD', $pi);
2507
+    }
2508
+
2509
+    if (!isset($GLOBALS['test_dirs'])) {
2510
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2511
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2512
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2513
+    }
2514
+
2515
+    // Declaration des fichiers
2516
+
2517
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2518
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2519
+    }
2520
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2521
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2522
+    }
2523
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2524
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2525
+    }
2526
+    if (!defined('_CACHE_PIPELINES')) {
2527
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2528
+    }
2529
+    if (!defined('_CACHE_CHEMIN')) {
2530
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2531
+    }
2532
+
2533
+    # attention .php obligatoire pour ecrire_fichier_securise
2534
+    if (!defined('_FILE_META')) {
2535
+        define('_FILE_META', $ti . 'meta_cache.php');
2536
+    }
2537
+    if (!defined('_DIR_LOG')) {
2538
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2539
+    }
2540
+    if (!defined('_FILE_LOG')) {
2541
+        define('_FILE_LOG', 'spip');
2542
+    }
2543
+    if (!defined('_FILE_LOG_SUFFIX')) {
2544
+        define('_FILE_LOG_SUFFIX', '.log');
2545
+    }
2546
+
2547
+    // Le fichier de connexion a la base de donnees
2548
+    // tient compte des anciennes versions (inc_connect...)
2549
+    if (!defined('_FILE_CONNECT_INS')) {
2550
+        define('_FILE_CONNECT_INS', 'connect');
2551
+    }
2552
+    if (!defined('_FILE_CONNECT')) {
2553
+        define(
2554
+            '_FILE_CONNECT',
2555
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2556
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2557
+            : false))
2558
+        );
2559
+    }
2560
+
2561
+    // Le fichier de reglages des droits
2562
+    if (!defined('_FILE_CHMOD_INS')) {
2563
+        define('_FILE_CHMOD_INS', 'chmod');
2564
+    }
2565
+    if (!defined('_FILE_CHMOD')) {
2566
+        define(
2567
+            '_FILE_CHMOD',
2568
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2569
+            : false)
2570
+        );
2571
+    }
2572
+
2573
+    if (!defined('_FILE_LDAP')) {
2574
+        define('_FILE_LDAP', 'ldap.php');
2575
+    }
2576
+
2577
+    if (!defined('_FILE_TMP_SUFFIX')) {
2578
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2579
+    }
2580
+    if (!defined('_FILE_CONNECT_TMP')) {
2581
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2582
+    }
2583
+    if (!defined('_FILE_CHMOD_TMP')) {
2584
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2585
+    }
2586
+
2587
+    // Definition des droits d'acces en ecriture
2588
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2589
+        include_once _FILE_CHMOD;
2590
+    }
2591
+
2592
+    // Se mefier des fichiers mal remplis!
2593
+    if (!defined('_SPIP_CHMOD')) {
2594
+        define('_SPIP_CHMOD', 0777);
2595
+    }
2596
+
2597
+    if (!defined('_DEFAULT_CHARSET')) {
2598
+        /** Le charset par défaut lors de l'installation */
2599
+        define('_DEFAULT_CHARSET', 'utf-8');
2600
+    }
2601
+    if (!defined('_ROOT_PLUGINS')) {
2602
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2603
+    }
2604
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2605
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2606
+    }
2607
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2608
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2609
+    }
2610
+
2611
+    // La taille des Log
2612
+    if (!defined('_MAX_LOG')) {
2613
+        define('_MAX_LOG', 100);
2614
+    }
2615
+
2616
+    // Sommes-nous dans l'empire du Mal ?
2617
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2618
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2619
+        if (!defined('_OS_SERVEUR')) {
2620
+            define('_OS_SERVEUR', 'windows');
2621
+        }
2622
+        if (!defined('_SPIP_LOCK_MODE')) {
2623
+            define('_SPIP_LOCK_MODE', 1);
2624
+        } // utiliser le flock php
2625
+    } else {
2626
+        if (!defined('_OS_SERVEUR')) {
2627
+            define('_OS_SERVEUR', '');
2628
+        }
2629
+        if (!defined('_SPIP_LOCK_MODE')) {
2630
+            define('_SPIP_LOCK_MODE', 1);
2631
+        } // utiliser le flock php
2632
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2633
+    }
2634
+
2635
+    // Langue par defaut
2636
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2637
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2638
+    }
2639
+
2640
+    //
2641
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2642
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2643
+    // pour le rendre surchargeable, on va provoquer un reecriture
2644
+    // systematique du noyau ou une baisse de perfs => a etudier)
2645
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2646
+
2647
+    // charger tout de suite le path et son cache
2648
+    load_path_cache();
2649
+
2650
+    // *********** traiter les variables ************
2651
+
2652
+    //
2653
+    // Securite
2654
+    //
2655
+
2656
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2657
+    if (isset($_REQUEST['GLOBALS'])) {
2658
+        die();
2659
+    }
2660
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2661
+    spip_desinfecte($_GET);
2662
+    spip_desinfecte($_POST);
2663
+    spip_desinfecte($_COOKIE);
2664
+    spip_desinfecte($_REQUEST);
2665
+
2666
+    // appliquer le cookie_prefix
2667
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2668
+        include_spip('inc/cookie');
2669
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2670
+    }
2671
+
2672
+    //
2673
+    // Capacites php (en fonction de la version)
2674
+    //
2675
+    $GLOBALS['flag_ob'] = (function_exists('ob_start')
2676
+        && function_exists('ini_get')
2677
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2678
+    $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name');
2679
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != '');
2680
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2681
+        (get_cfg_var('upload_max_filesize') > 0));
2682
+
2683
+
2684
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2685
+    if (isset($_SERVER['REQUEST_URI'])) {
2686
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2687
+    } else {
2688
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2689
+        if (
2690
+            !empty($_SERVER['QUERY_STRING'])
2691
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2692
+        ) {
2693
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2694
+        }
2695
+    }
2696
+
2697
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2698
+    if (!defined('_RENOUVELLE_ALEA')) {
2699
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2700
+    }
2701
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2702
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2703
+    }
2704
+
2705
+    // charger les meta si possible et renouveller l'alea au besoin
2706
+    // charge aussi effacer_meta et ecrire_meta
2707
+    $inc_meta = charger_fonction('meta', 'inc');
2708
+    $inc_meta();
2709
+
2710
+    // nombre de repertoires depuis la racine
2711
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2712
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2713
+    // le calcul est faux)
2714
+    if (!_DIR_RESTREINT) {
2715
+        $GLOBALS['profondeur_url'] = 1;
2716
+    } else {
2717
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2718
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2719
+        if (
2720
+            !$uri_ref
2721
+            // si on est appele avec un autre ti, on est sans doute en mutu
2722
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2723
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2724
+            // s'en remettre a l'adresse du site. alea jacta est.
2725
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2726
+        ) {
2727
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2728
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2729
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2730
+            } else {
2731
+                $uri_ref = '';
2732
+            }
2733
+        }
2734
+        if (!$uri or !$uri_ref) {
2735
+            $GLOBALS['profondeur_url'] = 0;
2736
+        } else {
2737
+            $GLOBALS['profondeur_url'] = max(
2738
+                0,
2739
+                substr_count($uri[0], '/')
2740
+                - substr_count($uri_ref, '/')
2741
+            );
2742
+        }
2743
+    }
2744
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2745
+    if (_FILE_CONNECT) {
2746
+        if (
2747
+            verifier_visiteur() == '0minirezo'
2748
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2749
+            and !isset($_COOKIE['spip_admin'])
2750
+        ) {
2751
+            clear_path_cache();
2752
+        }
2753
+    }
2755 2754
 }
2756 2755
 
2757 2756
 /**
@@ -2760,190 +2759,190 @@  discard block
 block discarded – undo
2760 2759
  *
2761 2760
  */
2762 2761
 function spip_initialisation_suite() {
2763
-	static $too_late = 0;
2764
-	if ($too_late++) {
2765
-		return;
2766
-	}
2767
-
2768
-	// taille mini des login
2769
-	if (!defined('_LOGIN_TROP_COURT')) {
2770
-		define('_LOGIN_TROP_COURT', 4);
2771
-	}
2772
-
2773
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2774
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2775
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2776
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2777
-
2778
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2779
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2780
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2781
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2782
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2783
-
2784
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2785
-		define('_PASS_LONGUEUR_MINI', 6);
2786
-	}
2787
-
2788
-	// largeur maximale des images dans l'administration
2789
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2790
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2791
-	}
2792
-
2793
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2794
-	if (!defined('_IMG_QUALITE')) {
2795
-		define('_IMG_QUALITE', 85);
2796
-	} # valeur par defaut
2797
-	if (!defined('_IMG_GD_QUALITE')) {
2798
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2799
-	} # surcharge pour la lib GD
2800
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2801
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2802
-	} # surcharge pour imagick en ligne de commande
2803
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2804
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2805
-		define('_IMG_IMAGICK_QUALITE', 75);
2806
-	} # surcharge pour imagick en PHP
2807
-
2808
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2809
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2810
-	} // poids en octet
2811
-
2812
-	// qq chaines standard
2813
-	if (!defined('_ACCESS_FILE_NAME')) {
2814
-		define('_ACCESS_FILE_NAME', '.htaccess');
2815
-	}
2816
-	if (!defined('_AUTH_USER_FILE')) {
2817
-		define('_AUTH_USER_FILE', '.htpasswd');
2818
-	}
2819
-	if (!defined('_SPIP_DUMP')) {
2820
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2821
-	}
2822
-	if (!defined('_CACHE_RUBRIQUES')) {
2823
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2824
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2825
-	}
2826
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2827
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2828
-		define('_CACHE_RUBRIQUES_MAX', 500);
2829
-	}
2830
-
2831
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2832
-		/**
2833
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2834
-		 * @var int Nombre de caractères */
2835
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2836
-	}
2837
-
2838
-	if (!defined('_EXTENSION_SQUELETTES')) {
2839
-		define('_EXTENSION_SQUELETTES', 'html');
2840
-	}
2841
-
2842
-	if (!defined('_DOCTYPE_ECRIRE')) {
2843
-		/** Définit le doctype de l’espace privé */
2844
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2845
-	}
2846
-	if (!defined('_DOCTYPE_AIDE')) {
2847
-		/** Définit le doctype de l’aide en ligne */
2848
-		define(
2849
-			'_DOCTYPE_AIDE',
2850
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2851
-		);
2852
-	}
2853
-
2854
-	if (!defined('_SPIP_SCRIPT')) {
2855
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2856
-		 * le script de l'espace public, alias index.php */
2857
-		define('_SPIP_SCRIPT', 'spip.php');
2858
-	}
2859
-	if (!defined('_SPIP_PAGE')) {
2860
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2861
-		define('_SPIP_PAGE', 'page');
2862
-	}
2863
-
2864
-	// le script de l'espace prive
2865
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2866
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2867
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2868
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2869
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2870
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2871
-		} else {
2872
-			define('_SPIP_ECRIRE_SCRIPT', '');
2873
-		}
2874
-	}
2875
-
2876
-
2877
-	if (!defined('_SPIP_AJAX')) {
2878
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2879
-			? 1
2880
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2881
-	}
2882
-
2883
-	// La requete est-elle en ajax ?
2884
-	if (!defined('_AJAX')) {
2885
-		define(
2886
-			'_AJAX',
2887
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2888
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2889
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2890
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2891
-			)
2892
-			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
2893
-		);
2894
-	}
2895
-
2896
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2897
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2898
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2899
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2900
-		define(
2901
-			'_IMG_GD_MAX_PIXELS',
2902
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2903
-			? $GLOBALS['meta']['max_taille_vignettes']
2904
-			: 0
2905
-		);
2906
-	}
2907
-
2908
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2909
-		define('_MEMORY_LIMIT_MIN', 16);
2910
-	} // en Mo
2911
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2912
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2913
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2914
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2915
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2916
-			$unit = strtolower(substr($memory, -1));
2917
-			$memory = substr($memory, 0, -1);
2918
-			switch ($unit) {
2919
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2920
-				case 'g':
2921
-					$memory *= 1024;
2922
-				case 'm':
2923
-					$memory *= 1024;
2924
-				case 'k':
2925
-					$memory *= 1024;
2926
-			}
2927
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2928
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2929
-				if (trim(ini_get('memory_limit')) != $m) {
2930
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2931
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2932
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2933
-				}
2934
-			}
2935
-		} else {
2936
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2937
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2938
-			}
2939
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2940
-	}
2941
-	// Protocoles a normaliser dans les chaines de langues
2942
-	if (!defined('_PROTOCOLES_STD')) {
2943
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2944
-	}
2945
-
2946
-	init_var_mode();
2762
+    static $too_late = 0;
2763
+    if ($too_late++) {
2764
+        return;
2765
+    }
2766
+
2767
+    // taille mini des login
2768
+    if (!defined('_LOGIN_TROP_COURT')) {
2769
+        define('_LOGIN_TROP_COURT', 4);
2770
+    }
2771
+
2772
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2773
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2774
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2775
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2776
+
2777
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2778
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2779
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2780
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2781
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2782
+
2783
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2784
+        define('_PASS_LONGUEUR_MINI', 6);
2785
+    }
2786
+
2787
+    // largeur maximale des images dans l'administration
2788
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2789
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2790
+    }
2791
+
2792
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2793
+    if (!defined('_IMG_QUALITE')) {
2794
+        define('_IMG_QUALITE', 85);
2795
+    } # valeur par defaut
2796
+    if (!defined('_IMG_GD_QUALITE')) {
2797
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2798
+    } # surcharge pour la lib GD
2799
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2800
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2801
+    } # surcharge pour imagick en ligne de commande
2802
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2803
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2804
+        define('_IMG_IMAGICK_QUALITE', 75);
2805
+    } # surcharge pour imagick en PHP
2806
+
2807
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2808
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2809
+    } // poids en octet
2810
+
2811
+    // qq chaines standard
2812
+    if (!defined('_ACCESS_FILE_NAME')) {
2813
+        define('_ACCESS_FILE_NAME', '.htaccess');
2814
+    }
2815
+    if (!defined('_AUTH_USER_FILE')) {
2816
+        define('_AUTH_USER_FILE', '.htpasswd');
2817
+    }
2818
+    if (!defined('_SPIP_DUMP')) {
2819
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2820
+    }
2821
+    if (!defined('_CACHE_RUBRIQUES')) {
2822
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2823
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2824
+    }
2825
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2826
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2827
+        define('_CACHE_RUBRIQUES_MAX', 500);
2828
+    }
2829
+
2830
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2831
+        /**
2832
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2833
+         * @var int Nombre de caractères */
2834
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2835
+    }
2836
+
2837
+    if (!defined('_EXTENSION_SQUELETTES')) {
2838
+        define('_EXTENSION_SQUELETTES', 'html');
2839
+    }
2840
+
2841
+    if (!defined('_DOCTYPE_ECRIRE')) {
2842
+        /** Définit le doctype de l’espace privé */
2843
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2844
+    }
2845
+    if (!defined('_DOCTYPE_AIDE')) {
2846
+        /** Définit le doctype de l’aide en ligne */
2847
+        define(
2848
+            '_DOCTYPE_AIDE',
2849
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2850
+        );
2851
+    }
2852
+
2853
+    if (!defined('_SPIP_SCRIPT')) {
2854
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2855
+         * le script de l'espace public, alias index.php */
2856
+        define('_SPIP_SCRIPT', 'spip.php');
2857
+    }
2858
+    if (!defined('_SPIP_PAGE')) {
2859
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2860
+        define('_SPIP_PAGE', 'page');
2861
+    }
2862
+
2863
+    // le script de l'espace prive
2864
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2865
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2866
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2867
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2868
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2869
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2870
+        } else {
2871
+            define('_SPIP_ECRIRE_SCRIPT', '');
2872
+        }
2873
+    }
2874
+
2875
+
2876
+    if (!defined('_SPIP_AJAX')) {
2877
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2878
+            ? 1
2879
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2880
+    }
2881
+
2882
+    // La requete est-elle en ajax ?
2883
+    if (!defined('_AJAX')) {
2884
+        define(
2885
+            '_AJAX',
2886
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2887
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2888
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2889
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2890
+            )
2891
+            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
2892
+        );
2893
+    }
2894
+
2895
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2896
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2897
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2898
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2899
+        define(
2900
+            '_IMG_GD_MAX_PIXELS',
2901
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2902
+            ? $GLOBALS['meta']['max_taille_vignettes']
2903
+            : 0
2904
+        );
2905
+    }
2906
+
2907
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2908
+        define('_MEMORY_LIMIT_MIN', 16);
2909
+    } // en Mo
2910
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2911
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2912
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2913
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2914
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2915
+            $unit = strtolower(substr($memory, -1));
2916
+            $memory = substr($memory, 0, -1);
2917
+            switch ($unit) {
2918
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2919
+                case 'g':
2920
+                    $memory *= 1024;
2921
+                case 'm':
2922
+                    $memory *= 1024;
2923
+                case 'k':
2924
+                    $memory *= 1024;
2925
+            }
2926
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2927
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2928
+                if (trim(ini_get('memory_limit')) != $m) {
2929
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2930
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2931
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2932
+                }
2933
+            }
2934
+        } else {
2935
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2936
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2937
+            }
2938
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2939
+    }
2940
+    // Protocoles a normaliser dans les chaines de langues
2941
+    if (!defined('_PROTOCOLES_STD')) {
2942
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2943
+    }
2944
+
2945
+    init_var_mode();
2947 2946
 }
2948 2947
 
2949 2948
 /**
@@ -2977,219 +2976,219 @@  discard block
 block discarded – undo
2977 2976
  * `   var_mode` (calcul ou recalcul).
2978 2977
  */
2979 2978
 function init_var_mode() {
2980
-	static $done = false;
2981
-	if (!$done) {
2982
-		if (isset($_GET['var_mode'])) {
2983
-			$var_mode = explode(',', $_GET['var_mode']);
2984
-			// tout le monde peut calcul/recalcul
2985
-			if (!defined('_VAR_MODE')) {
2986
-				if (in_array('recalcul', $var_mode)) {
2987
-					define('_VAR_MODE', 'recalcul');
2988
-				} elseif (in_array('calcul', $var_mode)) {
2989
-					define('_VAR_MODE', 'calcul');
2990
-				}
2991
-			}
2992
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2993
-			if ($var_mode) {
2994
-				include_spip('inc/autoriser');
2995
-				// autoriser preview si preview seulement, et sinon autoriser debug
2996
-				if (
2997
-					autoriser(
2998
-						($_GET['var_mode'] == 'preview')
2999
-						? 'previsualiser'
3000
-						: 'debug'
3001
-					)
3002
-				) {
3003
-					if (in_array('traduction', $var_mode)) {
3004
-						// forcer le calcul pour passer dans traduire
3005
-						if (!defined('_VAR_MODE')) {
3006
-							define('_VAR_MODE', 'calcul');
3007
-						}
3008
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3009
-						if (!defined('_VAR_NOCACHE')) {
3010
-							define('_VAR_NOCACHE', true);
3011
-						}
3012
-						$var_mode = array_diff($var_mode, ['traduction']);
3013
-					}
3014
-					if (in_array('preview', $var_mode)) {
3015
-						// basculer sur les criteres de preview dans les boucles
3016
-						if (!defined('_VAR_PREVIEW')) {
3017
-							define('_VAR_PREVIEW', true);
3018
-						}
3019
-						// forcer le calcul
3020
-						if (!defined('_VAR_MODE')) {
3021
-							define('_VAR_MODE', 'calcul');
3022
-						}
3023
-						// et ne pas enregistrer de cache
3024
-						if (!defined('_VAR_NOCACHE')) {
3025
-							define('_VAR_NOCACHE', true);
3026
-						}
3027
-						$var_mode = array_diff($var_mode, ['preview']);
3028
-					}
3029
-					if (in_array('inclure', $var_mode)) {
3030
-						// forcer le compilo et ignorer les caches existants
3031
-						if (!defined('_VAR_MODE')) {
3032
-							define('_VAR_MODE', 'calcul');
3033
-						}
3034
-						if (!defined('_VAR_INCLURE')) {
3035
-							define('_VAR_INCLURE', true);
3036
-						}
3037
-						// et ne pas enregistrer de cache
3038
-						if (!defined('_VAR_NOCACHE')) {
3039
-							define('_VAR_NOCACHE', true);
3040
-						}
3041
-						$var_mode = array_diff($var_mode, ['inclure']);
3042
-					}
3043
-					if (in_array('urls', $var_mode)) {
3044
-						// forcer le compilo et ignorer les caches existants
3045
-						if (!defined('_VAR_MODE')) {
3046
-							define('_VAR_MODE', 'calcul');
3047
-						}
3048
-						if (!defined('_VAR_URLS')) {
3049
-							define('_VAR_URLS', true);
3050
-						}
3051
-						$var_mode = array_diff($var_mode, ['urls']);
3052
-					}
3053
-					if (in_array('images', $var_mode)) {
3054
-						// forcer le compilo et ignorer les caches existants
3055
-						if (!defined('_VAR_MODE')) {
3056
-							define('_VAR_MODE', 'calcul');
3057
-						}
3058
-						// indiquer qu'on doit recalculer les images
3059
-						if (!defined('_VAR_IMAGES')) {
3060
-							define('_VAR_IMAGES', true);
3061
-						}
3062
-						$var_mode = array_diff($var_mode, ['images']);
3063
-					}
3064
-					if (in_array('debug', $var_mode)) {
3065
-						if (!defined('_VAR_MODE')) {
3066
-							define('_VAR_MODE', 'debug');
3067
-						}
3068
-						// et ne pas enregistrer de cache
3069
-						if (!defined('_VAR_NOCACHE')) {
3070
-							define('_VAR_NOCACHE', true);
3071
-						}
3072
-						$var_mode = array_diff($var_mode, ['debug']);
3073
-					}
3074
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3075
-						define('_VAR_MODE', reset($var_mode));
3076
-					}
3077
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3078
-						spip_log($GLOBALS['visiteur_session']['nom']
3079
-							. ' ' . _VAR_MODE);
3080
-					}
3081
-				} // pas autorise ?
3082
-				else {
3083
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3084
-					if (
3085
-						!$GLOBALS['visiteur_session']
3086
-						and !empty($_SERVER['HTTP_HOST'])
3087
-						and !empty($_SERVER['REQUEST_METHOD'])
3088
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3089
-					) {
3090
-						$self = self('&', true);
3091
-						if (strpos($self, 'page=login') === false) {
3092
-							include_spip('inc/headers');
3093
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3094
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3095
-						}
3096
-					}
3097
-					// sinon tant pis
3098
-				}
3099
-			}
3100
-		}
3101
-		if (!defined('_VAR_MODE')) {
3102
-			/**
3103
-			 * Indique le mode de calcul ou d'affichage de la page.
3104
-			 * @see init_var_mode()
3105
-			 */
3106
-			define('_VAR_MODE', false);
3107
-		}
3108
-		$done = true;
3109
-	}
2979
+    static $done = false;
2980
+    if (!$done) {
2981
+        if (isset($_GET['var_mode'])) {
2982
+            $var_mode = explode(',', $_GET['var_mode']);
2983
+            // tout le monde peut calcul/recalcul
2984
+            if (!defined('_VAR_MODE')) {
2985
+                if (in_array('recalcul', $var_mode)) {
2986
+                    define('_VAR_MODE', 'recalcul');
2987
+                } elseif (in_array('calcul', $var_mode)) {
2988
+                    define('_VAR_MODE', 'calcul');
2989
+                }
2990
+            }
2991
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
2992
+            if ($var_mode) {
2993
+                include_spip('inc/autoriser');
2994
+                // autoriser preview si preview seulement, et sinon autoriser debug
2995
+                if (
2996
+                    autoriser(
2997
+                        ($_GET['var_mode'] == 'preview')
2998
+                        ? 'previsualiser'
2999
+                        : 'debug'
3000
+                    )
3001
+                ) {
3002
+                    if (in_array('traduction', $var_mode)) {
3003
+                        // forcer le calcul pour passer dans traduire
3004
+                        if (!defined('_VAR_MODE')) {
3005
+                            define('_VAR_MODE', 'calcul');
3006
+                        }
3007
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3008
+                        if (!defined('_VAR_NOCACHE')) {
3009
+                            define('_VAR_NOCACHE', true);
3010
+                        }
3011
+                        $var_mode = array_diff($var_mode, ['traduction']);
3012
+                    }
3013
+                    if (in_array('preview', $var_mode)) {
3014
+                        // basculer sur les criteres de preview dans les boucles
3015
+                        if (!defined('_VAR_PREVIEW')) {
3016
+                            define('_VAR_PREVIEW', true);
3017
+                        }
3018
+                        // forcer le calcul
3019
+                        if (!defined('_VAR_MODE')) {
3020
+                            define('_VAR_MODE', 'calcul');
3021
+                        }
3022
+                        // et ne pas enregistrer de cache
3023
+                        if (!defined('_VAR_NOCACHE')) {
3024
+                            define('_VAR_NOCACHE', true);
3025
+                        }
3026
+                        $var_mode = array_diff($var_mode, ['preview']);
3027
+                    }
3028
+                    if (in_array('inclure', $var_mode)) {
3029
+                        // forcer le compilo et ignorer les caches existants
3030
+                        if (!defined('_VAR_MODE')) {
3031
+                            define('_VAR_MODE', 'calcul');
3032
+                        }
3033
+                        if (!defined('_VAR_INCLURE')) {
3034
+                            define('_VAR_INCLURE', true);
3035
+                        }
3036
+                        // et ne pas enregistrer de cache
3037
+                        if (!defined('_VAR_NOCACHE')) {
3038
+                            define('_VAR_NOCACHE', true);
3039
+                        }
3040
+                        $var_mode = array_diff($var_mode, ['inclure']);
3041
+                    }
3042
+                    if (in_array('urls', $var_mode)) {
3043
+                        // forcer le compilo et ignorer les caches existants
3044
+                        if (!defined('_VAR_MODE')) {
3045
+                            define('_VAR_MODE', 'calcul');
3046
+                        }
3047
+                        if (!defined('_VAR_URLS')) {
3048
+                            define('_VAR_URLS', true);
3049
+                        }
3050
+                        $var_mode = array_diff($var_mode, ['urls']);
3051
+                    }
3052
+                    if (in_array('images', $var_mode)) {
3053
+                        // forcer le compilo et ignorer les caches existants
3054
+                        if (!defined('_VAR_MODE')) {
3055
+                            define('_VAR_MODE', 'calcul');
3056
+                        }
3057
+                        // indiquer qu'on doit recalculer les images
3058
+                        if (!defined('_VAR_IMAGES')) {
3059
+                            define('_VAR_IMAGES', true);
3060
+                        }
3061
+                        $var_mode = array_diff($var_mode, ['images']);
3062
+                    }
3063
+                    if (in_array('debug', $var_mode)) {
3064
+                        if (!defined('_VAR_MODE')) {
3065
+                            define('_VAR_MODE', 'debug');
3066
+                        }
3067
+                        // et ne pas enregistrer de cache
3068
+                        if (!defined('_VAR_NOCACHE')) {
3069
+                            define('_VAR_NOCACHE', true);
3070
+                        }
3071
+                        $var_mode = array_diff($var_mode, ['debug']);
3072
+                    }
3073
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3074
+                        define('_VAR_MODE', reset($var_mode));
3075
+                    }
3076
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3077
+                        spip_log($GLOBALS['visiteur_session']['nom']
3078
+                            . ' ' . _VAR_MODE);
3079
+                    }
3080
+                } // pas autorise ?
3081
+                else {
3082
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3083
+                    if (
3084
+                        !$GLOBALS['visiteur_session']
3085
+                        and !empty($_SERVER['HTTP_HOST'])
3086
+                        and !empty($_SERVER['REQUEST_METHOD'])
3087
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3088
+                    ) {
3089
+                        $self = self('&', true);
3090
+                        if (strpos($self, 'page=login') === false) {
3091
+                            include_spip('inc/headers');
3092
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3093
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3094
+                        }
3095
+                    }
3096
+                    // sinon tant pis
3097
+                }
3098
+            }
3099
+        }
3100
+        if (!defined('_VAR_MODE')) {
3101
+            /**
3102
+             * Indique le mode de calcul ou d'affichage de la page.
3103
+             * @see init_var_mode()
3104
+             */
3105
+            define('_VAR_MODE', false);
3106
+        }
3107
+        $done = true;
3108
+    }
3110 3109
 }
3111 3110
 
3112 3111
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
3113 3112
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
3114 3113
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
3115 3114
 function spip_desinfecte(&$t, $deep = true) {
3116
-	foreach ($t as $key => $val) {
3117
-		if (is_string($t[$key])) {
3118
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3119
-		} // traiter aussi les "texte_plus" de article_edit
3120
-		else {
3121
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3122
-				spip_desinfecte($t[$key], $deep);
3123
-			}
3124
-		}
3125
-	}
3115
+    foreach ($t as $key => $val) {
3116
+        if (is_string($t[$key])) {
3117
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3118
+        } // traiter aussi les "texte_plus" de article_edit
3119
+        else {
3120
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3121
+                spip_desinfecte($t[$key], $deep);
3122
+            }
3123
+        }
3124
+    }
3126 3125
 }
3127 3126
 
3128 3127
 //  retourne le statut du visiteur s'il s'annonce
3129 3128
 
3130 3129
 function verifier_visiteur() {
3131
-	// Rq: pour que cette fonction marche depuis mes_options
3132
-	// il faut forcer l'init si ce n'est fait
3133
-	// mais on risque de perturber des plugins en initialisant trop tot
3134
-	// certaines constantes
3135
-	@spip_initialisation_core(
3136
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3137
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3138
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3139
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3140
-	);
3141
-
3142
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3143
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3144
-	// Attention on separe bien session_nom et nom, pour eviter
3145
-	// les melanges entre donnees SQL et variables plus aleatoires
3146
-	$variables_session = ['session_nom', 'session_email'];
3147
-	foreach ($variables_session as $var) {
3148
-		if (_request($var) !== null) {
3149
-			$init = true;
3150
-			break;
3151
-		}
3152
-	}
3153
-	if (isset($init)) {
3154
-		#@spip_initialisation_suite();
3155
-		$session = charger_fonction('session', 'inc');
3156
-		$session();
3157
-		include_spip('inc/texte');
3158
-		foreach ($variables_session as $var) {
3159
-			if (($a = _request($var)) !== null) {
3160
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3161
-			}
3162
-		}
3163
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3164
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3165
-		}
3166
-		$session($GLOBALS['visiteur_session']);
3167
-
3168
-		return 0;
3169
-	}
3170
-
3171
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3172
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3173
-		$session = charger_fonction('session', 'inc');
3174
-		if ($session()) {
3175
-			return $GLOBALS['visiteur_session']['statut'];
3176
-		}
3177
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3178
-			include_spip('inc/auth');
3179
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3180
-		}
3181
-		if ($h) {
3182
-			$GLOBALS['visiteur_session'] = $h;
3183
-
3184
-			return $GLOBALS['visiteur_session']['statut'];
3185
-		}
3186
-	}
3187
-
3188
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3189
-	include_spip('inc/lang');
3190
-	utiliser_langue_visiteur();
3191
-
3192
-	return false;
3130
+    // Rq: pour que cette fonction marche depuis mes_options
3131
+    // il faut forcer l'init si ce n'est fait
3132
+    // mais on risque de perturber des plugins en initialisant trop tot
3133
+    // certaines constantes
3134
+    @spip_initialisation_core(
3135
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3136
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3137
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3138
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3139
+    );
3140
+
3141
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3142
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3143
+    // Attention on separe bien session_nom et nom, pour eviter
3144
+    // les melanges entre donnees SQL et variables plus aleatoires
3145
+    $variables_session = ['session_nom', 'session_email'];
3146
+    foreach ($variables_session as $var) {
3147
+        if (_request($var) !== null) {
3148
+            $init = true;
3149
+            break;
3150
+        }
3151
+    }
3152
+    if (isset($init)) {
3153
+        #@spip_initialisation_suite();
3154
+        $session = charger_fonction('session', 'inc');
3155
+        $session();
3156
+        include_spip('inc/texte');
3157
+        foreach ($variables_session as $var) {
3158
+            if (($a = _request($var)) !== null) {
3159
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3160
+            }
3161
+        }
3162
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3163
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3164
+        }
3165
+        $session($GLOBALS['visiteur_session']);
3166
+
3167
+        return 0;
3168
+    }
3169
+
3170
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3171
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3172
+        $session = charger_fonction('session', 'inc');
3173
+        if ($session()) {
3174
+            return $GLOBALS['visiteur_session']['statut'];
3175
+        }
3176
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3177
+            include_spip('inc/auth');
3178
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3179
+        }
3180
+        if ($h) {
3181
+            $GLOBALS['visiteur_session'] = $h;
3182
+
3183
+            return $GLOBALS['visiteur_session']['statut'];
3184
+        }
3185
+    }
3186
+
3187
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3188
+    include_spip('inc/lang');
3189
+    utiliser_langue_visiteur();
3190
+
3191
+    return false;
3193 3192
 }
3194 3193
 
3195 3194
 
@@ -3212,21 +3211,21 @@  discard block
 block discarded – undo
3212 3211
  *     - string Langue utilisée.
3213 3212
  **/
3214 3213
 function lang_select($lang = null) {
3215
-	static $pile_langues = [];
3216
-	if (!function_exists('changer_langue')) {
3217
-		include_spip('inc/lang');
3218
-	}
3219
-	if ($lang === null) {
3220
-		$lang = array_pop($pile_langues);
3221
-	} else {
3222
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3223
-	}
3224
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3225
-		return $lang;
3226
-	}
3227
-	changer_langue($lang);
3214
+    static $pile_langues = [];
3215
+    if (!function_exists('changer_langue')) {
3216
+        include_spip('inc/lang');
3217
+    }
3218
+    if ($lang === null) {
3219
+        $lang = array_pop($pile_langues);
3220
+    } else {
3221
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3222
+    }
3223
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3224
+        return $lang;
3225
+    }
3226
+    changer_langue($lang);
3228 3227
 
3229
-	return $lang;
3228
+    return $lang;
3230 3229
 }
3231 3230
 
3232 3231
 /**
@@ -3243,20 +3242,20 @@  discard block
 block discarded – undo
3243 3242
  *     Identifiant de la session
3244 3243
  **/
3245 3244
 function spip_session($force = false) {
3246
-	static $session;
3247
-	if ($force or !isset($session)) {
3248
-		$s = pipeline(
3249
-			'definir_session',
3250
-			$GLOBALS['visiteur_session']
3251
-				? serialize($GLOBALS['visiteur_session'])
3252
-				. '_' . @$_COOKIE['spip_session']
3253
-				: ''
3254
-		);
3255
-		$session = $s ? substr(md5($s), 0, 8) : '';
3256
-	}
3245
+    static $session;
3246
+    if ($force or !isset($session)) {
3247
+        $s = pipeline(
3248
+            'definir_session',
3249
+            $GLOBALS['visiteur_session']
3250
+                ? serialize($GLOBALS['visiteur_session'])
3251
+                . '_' . @$_COOKIE['spip_session']
3252
+                : ''
3253
+        );
3254
+        $session = $s ? substr(md5($s), 0, 8) : '';
3255
+    }
3257 3256
 
3258
-	#spip_log('session: '.$session);
3259
-	return $session;
3257
+    #spip_log('session: '.$session);
3258
+    return $session;
3260 3259
 }
3261 3260
 
3262 3261
 
@@ -3275,9 +3274,9 @@  discard block
 block discarded – undo
3275 3274
  *    Lien sur une icone d'aide
3276 3275
  **/
3277 3276
 function aider($aide = '', $distante = false) {
3278
-	$aider = charger_fonction('aide', 'inc', true);
3277
+    $aider = charger_fonction('aide', 'inc', true);
3279 3278
 
3280
-	return $aider ? $aider($aide, '', [], $distante) : '';
3279
+    return $aider ? $aider($aide, '', [], $distante) : '';
3281 3280
 }
3282 3281
 
3283 3282
 /**
@@ -3287,24 +3286,24 @@  discard block
 block discarded – undo
3287 3286
  */
3288 3287
 function exec_info_dist() {
3289 3288
 
3290
-	include_spip('inc/autoriser');
3291
-	if (autoriser('phpinfos')) {
3292
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3293
-		$cookies_backup = [];
3294
-		foreach ($cookies_masques as $k) {
3295
-			if (!empty($_COOKIE[$k])) {
3296
-				$cookies_backup[$k] = $_COOKIE[$k];
3297
-				$_COOKIE[$k] = '******************************';
3298
-			}
3299
-		}
3300
-		phpinfo();
3301
-		foreach ($cookies_backup as $k => $v) {
3302
-			$_COOKIE[$k] = $v;
3303
-		}
3304
-	} else {
3305
-		include_spip('inc/filtres');
3306
-		sinon_interdire_acces();
3307
-	}
3289
+    include_spip('inc/autoriser');
3290
+    if (autoriser('phpinfos')) {
3291
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3292
+        $cookies_backup = [];
3293
+        foreach ($cookies_masques as $k) {
3294
+            if (!empty($_COOKIE[$k])) {
3295
+                $cookies_backup[$k] = $_COOKIE[$k];
3296
+                $_COOKIE[$k] = '******************************';
3297
+            }
3298
+        }
3299
+        phpinfo();
3300
+        foreach ($cookies_backup as $k => $v) {
3301
+            $_COOKIE[$k] = $v;
3302
+        }
3303
+    } else {
3304
+        include_spip('inc/filtres');
3305
+        sinon_interdire_acces();
3306
+    }
3308 3307
 }
3309 3308
 
3310 3309
 /**
@@ -3324,13 +3323,13 @@  discard block
 block discarded – undo
3324 3323
  *     - string si $message à false.
3325 3324
  **/
3326 3325
 function erreur_squelette($message = '', $lieu = '') {
3327
-	$debusquer = charger_fonction('debusquer', 'public');
3328
-	if (is_array($lieu)) {
3329
-		include_spip('public/compiler');
3330
-		$lieu = reconstruire_contexte_compil($lieu);
3331
-	}
3326
+    $debusquer = charger_fonction('debusquer', 'public');
3327
+    if (is_array($lieu)) {
3328
+        include_spip('public/compiler');
3329
+        $lieu = reconstruire_contexte_compil($lieu);
3330
+    }
3332 3331
 
3333
-	return $debusquer($message, $lieu);
3332
+    return $debusquer($message, $lieu);
3334 3333
 }
3335 3334
 
3336 3335
 /**
@@ -3367,108 +3366,108 @@  discard block
 block discarded – undo
3367 3366
  *     - ou tableau d'information sur le squelette.
3368 3367
  */
3369 3368
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3370
-	if (!function_exists('evaluer_fond')) {
3371
-		include_spip('public/assembler');
3372
-	}
3373
-	// assurer la compat avec l'ancienne syntaxe
3374
-	// (trim etait le 3eme argument, par defaut a true)
3375
-	if (!is_array($options)) {
3376
-		$options = ['trim' => $options];
3377
-	}
3378
-	if (!isset($options['trim'])) {
3379
-		$options['trim'] = true;
3380
-	}
3381
-
3382
-	if (isset($contexte['connect'])) {
3383
-		$connect = $contexte['connect'];
3384
-		unset($contexte['connect']);
3385
-	}
3386
-
3387
-	$texte = '';
3388
-	$pages = [];
3389
-	$lang_select = '';
3390
-	if (!isset($options['etoile']) or !$options['etoile']) {
3391
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3392
-		if (!isset($contexte['lang'])) {
3393
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3394
-		}
3395
-
3396
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3397
-			$lang_select = lang_select($contexte['lang']);
3398
-		}
3399
-	}
3400
-
3401
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3402
-		$GLOBALS['_INC_PUBLIC'] = 0;
3403
-	}
3404
-
3405
-	$GLOBALS['_INC_PUBLIC']++;
3406
-
3407
-	// fix #4235
3408
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3409
-
3410
-
3411
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3412
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3413
-
3414
-		$page = evaluer_fond($f, $contexte, $connect);
3415
-		if ($page === '') {
3416
-			$c = $options['compil'] ?? '';
3417
-			$a = ['fichier' => $f];
3418
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3419
-			erreur_squelette($erreur, $c);
3420
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3421
-			$page = ['texte' => '', 'erreur' => $erreur];
3422
-		}
3423
-
3424
-		$page = pipeline('recuperer_fond', [
3425
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3426
-			'data' => $page
3427
-		]);
3428
-		if (isset($options['ajax']) and $options['ajax']) {
3429
-			if (!function_exists('encoder_contexte_ajax')) {
3430
-				include_spip('inc/filtres');
3431
-			}
3432
-			$page['texte'] = encoder_contexte_ajax(
3433
-				array_merge(
3434
-					$contexte,
3435
-					['fond' => $f],
3436
-					($connect ? ['connect' => $connect] : [])
3437
-				),
3438
-				'',
3439
-				$page['texte'],
3440
-				$options['ajax']
3441
-			);
3442
-		}
3443
-
3444
-		if (isset($options['raw']) and $options['raw']) {
3445
-			$pages[] = $page;
3446
-		} else {
3447
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3448
-		}
3449
-
3450
-		// contamination de la session appelante, pour les inclusions statiques
3451
-		if (isset($page['invalideurs']['session'])) {
3452
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3453
-		}
3454
-	}
3455
-
3456
-	// restaurer le sessionnement du contexte appelant,
3457
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3458
-	if (isset($cache_utilise_session_appelant)) {
3459
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3460
-	}
3461
-
3462
-	$GLOBALS['_INC_PUBLIC']--;
3463
-
3464
-	if ($lang_select) {
3465
-		lang_select();
3466
-	}
3467
-	if (isset($options['raw']) and $options['raw']) {
3468
-		return is_array($fond) ? $pages : reset($pages);
3469
-	} else {
3470
-		return $options['trim'] ? ltrim($texte) : $texte;
3471
-	}
3369
+    if (!function_exists('evaluer_fond')) {
3370
+        include_spip('public/assembler');
3371
+    }
3372
+    // assurer la compat avec l'ancienne syntaxe
3373
+    // (trim etait le 3eme argument, par defaut a true)
3374
+    if (!is_array($options)) {
3375
+        $options = ['trim' => $options];
3376
+    }
3377
+    if (!isset($options['trim'])) {
3378
+        $options['trim'] = true;
3379
+    }
3380
+
3381
+    if (isset($contexte['connect'])) {
3382
+        $connect = $contexte['connect'];
3383
+        unset($contexte['connect']);
3384
+    }
3385
+
3386
+    $texte = '';
3387
+    $pages = [];
3388
+    $lang_select = '';
3389
+    if (!isset($options['etoile']) or !$options['etoile']) {
3390
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3391
+        if (!isset($contexte['lang'])) {
3392
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3393
+        }
3394
+
3395
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3396
+            $lang_select = lang_select($contexte['lang']);
3397
+        }
3398
+    }
3399
+
3400
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3401
+        $GLOBALS['_INC_PUBLIC'] = 0;
3402
+    }
3403
+
3404
+    $GLOBALS['_INC_PUBLIC']++;
3405
+
3406
+    // fix #4235
3407
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3408
+
3409
+
3410
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3411
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3412
+
3413
+        $page = evaluer_fond($f, $contexte, $connect);
3414
+        if ($page === '') {
3415
+            $c = $options['compil'] ?? '';
3416
+            $a = ['fichier' => $f];
3417
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3418
+            erreur_squelette($erreur, $c);
3419
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3420
+            $page = ['texte' => '', 'erreur' => $erreur];
3421
+        }
3422
+
3423
+        $page = pipeline('recuperer_fond', [
3424
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3425
+            'data' => $page
3426
+        ]);
3427
+        if (isset($options['ajax']) and $options['ajax']) {
3428
+            if (!function_exists('encoder_contexte_ajax')) {
3429
+                include_spip('inc/filtres');
3430
+            }
3431
+            $page['texte'] = encoder_contexte_ajax(
3432
+                array_merge(
3433
+                    $contexte,
3434
+                    ['fond' => $f],
3435
+                    ($connect ? ['connect' => $connect] : [])
3436
+                ),
3437
+                '',
3438
+                $page['texte'],
3439
+                $options['ajax']
3440
+            );
3441
+        }
3442
+
3443
+        if (isset($options['raw']) and $options['raw']) {
3444
+            $pages[] = $page;
3445
+        } else {
3446
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3447
+        }
3448
+
3449
+        // contamination de la session appelante, pour les inclusions statiques
3450
+        if (isset($page['invalideurs']['session'])) {
3451
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3452
+        }
3453
+    }
3454
+
3455
+    // restaurer le sessionnement du contexte appelant,
3456
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3457
+    if (isset($cache_utilise_session_appelant)) {
3458
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3459
+    }
3460
+
3461
+    $GLOBALS['_INC_PUBLIC']--;
3462
+
3463
+    if ($lang_select) {
3464
+        lang_select();
3465
+    }
3466
+    if (isset($options['raw']) and $options['raw']) {
3467
+        return is_array($fond) ? $pages : reset($pages);
3468
+    } else {
3469
+        return $options['trim'] ? ltrim($texte) : $texte;
3470
+    }
3472 3471
 }
3473 3472
 
3474 3473
 /**
@@ -3478,7 +3477,7 @@  discard block
 block discarded – undo
3478 3477
  * @return string
3479 3478
  */
3480 3479
 function trouve_modele($nom) {
3481
-	return trouver_fond($nom, 'modeles/');
3480
+    return trouver_fond($nom, 'modeles/');
3482 3481
 }
3483 3482
 
3484 3483
 /**
@@ -3494,21 +3493,21 @@  discard block
 block discarded – undo
3494 3493
  * @return array|string
3495 3494
  */
3496 3495
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3497
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3498
-	if (!$pathinfo) {
3499
-		return $f;
3500
-	}
3501
-	// renvoyer un tableau detaille si $pathinfo==true
3502
-	$p = pathinfo($f);
3503
-	if (!isset($p['extension']) or !$p['extension']) {
3504
-		$p['extension'] = _EXTENSION_SQUELETTES;
3505
-	}
3506
-	if (!isset($p['extension']) or !$p['filename']) {
3507
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3508
-	}
3509
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3496
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3497
+    if (!$pathinfo) {
3498
+        return $f;
3499
+    }
3500
+    // renvoyer un tableau detaille si $pathinfo==true
3501
+    $p = pathinfo($f);
3502
+    if (!isset($p['extension']) or !$p['extension']) {
3503
+        $p['extension'] = _EXTENSION_SQUELETTES;
3504
+    }
3505
+    if (!isset($p['extension']) or !$p['filename']) {
3506
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3507
+    }
3508
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3510 3509
 
3511
-	return $p;
3510
+    return $p;
3512 3511
 }
3513 3512
 
3514 3513
 /**
@@ -3528,21 +3527,21 @@  discard block
 block discarded – undo
3528 3527
  *     Nom de l'exec, sinon chaîne vide.
3529 3528
  **/
3530 3529
 function tester_url_ecrire($nom) {
3531
-	static $exec = [];
3532
-	if (isset($exec[$nom])) {
3533
-		return $exec[$nom];
3534
-	}
3535
-	// tester si c'est une page en squelette
3536
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3537
-		return $exec[$nom] = 'fond';
3538
-	} // echafaudage d'un fond !
3539
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3540
-		return $exec[$nom] = 'fond';
3541
-	}
3542
-	// attention, il ne faut pas inclure l'exec ici
3543
-	// car sinon #URL_ECRIRE provoque des inclusions
3544
-	// et des define intrusifs potentiels
3545
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3530
+    static $exec = [];
3531
+    if (isset($exec[$nom])) {
3532
+        return $exec[$nom];
3533
+    }
3534
+    // tester si c'est une page en squelette
3535
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3536
+        return $exec[$nom] = 'fond';
3537
+    } // echafaudage d'un fond !
3538
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3539
+        return $exec[$nom] = 'fond';
3540
+    }
3541
+    // attention, il ne faut pas inclure l'exec ici
3542
+    // car sinon #URL_ECRIRE provoque des inclusions
3543
+    // et des define intrusifs potentiels
3544
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3546 3545
 }
3547 3546
 
3548 3547
 /**
@@ -3552,8 +3551,8 @@  discard block
 block discarded – undo
3552 3551
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3553 3552
  **/
3554 3553
 function html5_permis() {
3555
-	return (!defined('_VERSION_HTML')
3556
-		or _VERSION_HTML !== 'html4');
3554
+    return (!defined('_VERSION_HTML')
3555
+        or _VERSION_HTML !== 'html4');
3557 3556
 }
3558 3557
 
3559 3558
 /**
@@ -3563,30 +3562,30 @@  discard block
 block discarded – undo
3563 3562
  * @return array
3564 3563
  */
3565 3564
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3566
-	$formats = null;
3567
-	if (!is_null($gd)) {
3568
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3569
-		if (isset($GLOBALS['meta'][$config])) {
3570
-			$formats = $GLOBALS['meta'][$config];
3571
-			$formats = explode(',', $formats);
3572
-			$formats = array_filter($formats);
3573
-			$formats = array_map('trim', $formats);
3574
-		}
3575
-	}
3576
-	if (is_null($formats)) {
3577
-		include_spip('inc/filtres_images_lib_mini');
3578
-		$formats = _image_extensions_acceptees_en_entree();
3579
-	}
3580
-
3581
-	if ($svg_allowed) {
3582
-		if (!in_array('svg', $formats)) {
3583
-			$formats[] = 'svg';
3584
-		}
3585
-	}
3586
-	else {
3587
-		$formats = array_diff($formats, ['svg']);
3588
-	}
3589
-	return $formats;
3565
+    $formats = null;
3566
+    if (!is_null($gd)) {
3567
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3568
+        if (isset($GLOBALS['meta'][$config])) {
3569
+            $formats = $GLOBALS['meta'][$config];
3570
+            $formats = explode(',', $formats);
3571
+            $formats = array_filter($formats);
3572
+            $formats = array_map('trim', $formats);
3573
+        }
3574
+    }
3575
+    if (is_null($formats)) {
3576
+        include_spip('inc/filtres_images_lib_mini');
3577
+        $formats = _image_extensions_acceptees_en_entree();
3578
+    }
3579
+
3580
+    if ($svg_allowed) {
3581
+        if (!in_array('svg', $formats)) {
3582
+            $formats[] = 'svg';
3583
+        }
3584
+    }
3585
+    else {
3586
+        $formats = array_diff($formats, ['svg']);
3587
+    }
3588
+    return $formats;
3590 3589
 }
3591 3590
 
3592 3591
 /**
@@ -3595,20 +3594,20 @@  discard block
 block discarded – undo
3595 3594
  * @return array|bool
3596 3595
  */
3597 3596
 function spip_getimagesize($fichier) {
3598
-	if (!$imagesize = @getimagesize($fichier)) {
3599
-		include_spip('inc/svg');
3600
-		if ($attrs = svg_lire_attributs($fichier)) {
3601
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3602
-			$imagesize = [
3603
-				$width,
3604
-				$height,
3605
-				IMAGETYPE_SVG,
3606
-				"width=\"{$width}\" height=\"{$height}\"",
3607
-				'mime' => 'image/svg+xml'
3608
-			];
3609
-		}
3610
-	}
3611
-	return $imagesize;
3597
+    if (!$imagesize = @getimagesize($fichier)) {
3598
+        include_spip('inc/svg');
3599
+        if ($attrs = svg_lire_attributs($fichier)) {
3600
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3601
+            $imagesize = [
3602
+                $width,
3603
+                $height,
3604
+                IMAGETYPE_SVG,
3605
+                "width=\"{$width}\" height=\"{$height}\"",
3606
+                'mime' => 'image/svg+xml'
3607
+            ];
3608
+        }
3609
+    }
3610
+    return $imagesize;
3612 3611
 }
3613 3612
 
3614 3613
 /**
@@ -3622,19 +3621,19 @@  discard block
 block discarded – undo
3622 3621
  * @param string $statut
3623 3622
  */
3624 3623
 function avertir_auteurs($nom, $message, $statut = '') {
3625
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3626
-	if (
3627
-		!$alertes
3628
-		or !is_array($alertes = unserialize($alertes))
3629
-	) {
3630
-		$alertes = [];
3631
-	}
3624
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3625
+    if (
3626
+        !$alertes
3627
+        or !is_array($alertes = unserialize($alertes))
3628
+    ) {
3629
+        $alertes = [];
3630
+    }
3632 3631
 
3633
-	if (!isset($alertes[$statut])) {
3634
-		$alertes[$statut] = [];
3635
-	}
3636
-	$alertes[$statut][$nom] = $message;
3637
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3632
+    if (!isset($alertes[$statut])) {
3633
+        $alertes[$statut] = [];
3634
+    }
3635
+    $alertes[$statut][$nom] = $message;
3636
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3638 3637
 }
3639 3638
 
3640 3639
 /**
@@ -3648,10 +3647,10 @@  discard block
 block discarded – undo
3648 3647
  * @return string|string[]
3649 3648
  */
3650 3649
 function spip_sanitize_classname($classes) {
3651
-	if (is_array($classes)) {
3652
-		return array_map('spip_sanitize_classname', $classes);
3653
-	}
3654
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3650
+    if (is_array($classes)) {
3651
+        return array_map('spip_sanitize_classname', $classes);
3652
+    }
3653
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3655 3654
 }
3656 3655
 
3657 3656
 
@@ -3676,32 +3675,32 @@  discard block
 block discarded – undo
3676 3675
  *    Avec operateur : bool.
3677 3676
  **/
3678 3677
 function spip_version_compare($v1, $v2, $op = null) {
3679
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3680
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3681
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3682
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3683
-
3684
-	$v1 = explode('.', $v1);
3685
-	$v2 = explode('.', $v2);
3686
-	// $v1 est toujours une version, donc sans etoile
3687
-	while (count($v1) < count($v2)) {
3688
-		$v1[] = '0';
3689
-	}
3690
-
3691
-	// $v2 peut etre une borne, donc accepte l'etoile
3692
-	$etoile = false;
3693
-	foreach ($v1 as $k => $v) {
3694
-		if (!isset($v2[$k])) {
3695
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3696
-		} else {
3697
-			if ($v2[$k] == '*') {
3698
-				$etoile = true;
3699
-				$v2[$k] = $v;
3700
-			}
3701
-		}
3702
-	}
3703
-	$v1 = implode('.', $v1);
3704
-	$v2 = implode('.', $v2);
3705
-
3706
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3678
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3679
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3680
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3681
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3682
+
3683
+    $v1 = explode('.', $v1);
3684
+    $v2 = explode('.', $v2);
3685
+    // $v1 est toujours une version, donc sans etoile
3686
+    while (count($v1) < count($v2)) {
3687
+        $v1[] = '0';
3688
+    }
3689
+
3690
+    // $v2 peut etre une borne, donc accepte l'etoile
3691
+    $etoile = false;
3692
+    foreach ($v1 as $k => $v) {
3693
+        if (!isset($v2[$k])) {
3694
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3695
+        } else {
3696
+            if ($v2[$k] == '*') {
3697
+                $etoile = true;
3698
+                $v2[$k] = $v;
3699
+            }
3700
+        }
3701
+    }
3702
+    $v1 = implode('.', $v1);
3703
+    $v2 = implode('.', $v2);
3704
+
3705
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3707 3706
 }
Please login to merge, or discard this patch.
ecrire/inc/urls.php 1 patch
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('base/objets');
23 23
 
@@ -57,106 +57,106 @@  discard block
 block discarded – undo
57 57
  *
58 58
  */
59 59
 function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) {
60
-	static $current_base = null;
60
+    static $current_base = null;
61 61
 
62
-	// les anciennes fonctions modifient directement les globales
63
-	// on les sauve avant l'appel, et on les retablit apres !
64
-	$save = [
65
-		$GLOBALS['fond'] ?? null,
66
-		$GLOBALS['contexte'] ?? null,
67
-		$_SERVER['REDIRECT_url_propre'] ?? null,
68
-		$_ENV['url_propre'] ?? null,
69
-		$GLOBALS['profondeur_url']
70
-	];
62
+    // les anciennes fonctions modifient directement les globales
63
+    // on les sauve avant l'appel, et on les retablit apres !
64
+    $save = [
65
+        $GLOBALS['fond'] ?? null,
66
+        $GLOBALS['contexte'] ?? null,
67
+        $_SERVER['REDIRECT_url_propre'] ?? null,
68
+        $_ENV['url_propre'] ?? null,
69
+        $GLOBALS['profondeur_url']
70
+    ];
71 71
 
72
-	if (is_null($current_base)) {
73
-		include_spip('inc/filtres_mini');
74
-		// le decodage des urls se fait toujours par rapport au site public
75
-		$current_base = url_absolue(_DIR_RACINE ?: './');
76
-	}
77
-	if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
-		$url = substr($url, strlen($current_base));
79
-	}
72
+    if (is_null($current_base)) {
73
+        include_spip('inc/filtres_mini');
74
+        // le decodage des urls se fait toujours par rapport au site public
75
+        $current_base = url_absolue(_DIR_RACINE ?: './');
76
+    }
77
+    if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
+        $url = substr($url, strlen($current_base));
79
+    }
80 80
 
81
-	// si on est en train d'assembler la page principale,
82
-	// recuperer l'url depuis les globales url propres si fournies
83
-	// sinon extraire la bonne portion d'url
84
-	if ($assembler) {
85
-		if (isset($_SERVER['REDIRECT_url_propre'])) {
86
-			$url = $_SERVER['REDIRECT_url_propre'];
87
-		} elseif (isset($_ENV['url_propre'])) {
88
-			$url = $_ENV['url_propre'];
89
-		} else {
90
-			$qs = explode('?', $url);
91
-			// ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
-			$url = ltrim($qs[0], '/');
93
-			$url = explode('/', $url);
94
-			while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
-				array_shift($url);
96
-			}
97
-			$qs[0] = implode('/', $url);
98
-			$url = implode('?', $qs);
99
-		}
100
-	}
81
+    // si on est en train d'assembler la page principale,
82
+    // recuperer l'url depuis les globales url propres si fournies
83
+    // sinon extraire la bonne portion d'url
84
+    if ($assembler) {
85
+        if (isset($_SERVER['REDIRECT_url_propre'])) {
86
+            $url = $_SERVER['REDIRECT_url_propre'];
87
+        } elseif (isset($_ENV['url_propre'])) {
88
+            $url = $_ENV['url_propre'];
89
+        } else {
90
+            $qs = explode('?', $url);
91
+            // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
+            $url = ltrim($qs[0], '/');
93
+            $url = explode('/', $url);
94
+            while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
+                array_shift($url);
96
+            }
97
+            $qs[0] = implode('/', $url);
98
+            $url = implode('?', $qs);
99
+        }
100
+    }
101 101
 
102
-	unset($_SERVER['REDIRECT_url_propre']);
103
-	unset($_ENV['url_propre']);
104
-	include_spip('inc/filtres_mini');
105
-	if (strpos($url, '://') === false) {
106
-		$GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
-	} else {
108
-		$GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
-	}
102
+    unset($_SERVER['REDIRECT_url_propre']);
103
+    unset($_ENV['url_propre']);
104
+    include_spip('inc/filtres_mini');
105
+    if (strpos($url, '://') === false) {
106
+        $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
+    } else {
108
+        $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
+    }
110 110
 
111
-	$url_redirect = '';
112
-	$decoder = charger_fonction_url('decoder');
113
-	if ($decoder) {
114
-		$a = $decoder($url, $fond, $contexte);
115
-		if (is_array($a)) {
116
-			[$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
117
-			$url_redirect ??= '';
118
-			if ($url_redirect === $url) {
119
-				$url_redirect = '';
120
-			} // securite pour eviter une redirection infinie
121
-			if ($assembler and strlen($url_redirect)) {
122
-				spip_log("Redirige $url vers $url_redirect");
123
-				include_spip('inc/headers');
124
-				redirige_par_entete($url_redirect, '', 301);
125
-			}
126
-			if (isset($nfond)) {
127
-				$fond = $nfond;
128
-			} else {
129
-				if (
130
-					$fond == ''
131
-					or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
132
-				) {
133
-					$fond = $type;
134
-				}
135
-			}
136
-			if (isset($ncontexte)) {
137
-				$contexte = $ncontexte;
138
-			}
139
-			if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
140
-				$contexte['type'] = $type;
141
-			}
142
-			if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
143
-				$contexte['type-page'] = $type;
144
-			}
145
-		}
146
-	}
111
+    $url_redirect = '';
112
+    $decoder = charger_fonction_url('decoder');
113
+    if ($decoder) {
114
+        $a = $decoder($url, $fond, $contexte);
115
+        if (is_array($a)) {
116
+            [$ncontexte, $type, $url_redirect, $nfond] = array_pad($a, 4, null);
117
+            $url_redirect ??= '';
118
+            if ($url_redirect === $url) {
119
+                $url_redirect = '';
120
+            } // securite pour eviter une redirection infinie
121
+            if ($assembler and strlen($url_redirect)) {
122
+                spip_log("Redirige $url vers $url_redirect");
123
+                include_spip('inc/headers');
124
+                redirige_par_entete($url_redirect, '', 301);
125
+            }
126
+            if (isset($nfond)) {
127
+                $fond = $nfond;
128
+            } else {
129
+                if (
130
+                    $fond == ''
131
+                    or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
132
+                ) {
133
+                    $fond = $type;
134
+                }
135
+            }
136
+            if (isset($ncontexte)) {
137
+                $contexte = $ncontexte;
138
+            }
139
+            if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
140
+                $contexte['type'] = $type;
141
+            }
142
+            if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
143
+                $contexte['type-page'] = $type;
144
+            }
145
+        }
146
+    }
147 147
 
148
-	// retablir les globales
149
-	[$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
148
+    // retablir les globales
149
+    [$GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']] = $save;
150 150
 
151
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
152
-	// d'inversion url => objet
153
-	// maintenir pour compat ?
154
-	#if ($assembler) {
155
-	#	unset($_SERVER['REDIRECT_url_propre']);
156
-	#	unset($_ENV['url_propre']);
157
-	#}
151
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
152
+    // d'inversion url => objet
153
+    // maintenir pour compat ?
154
+    #if ($assembler) {
155
+    #	unset($_SERVER['REDIRECT_url_propre']);
156
+    #	unset($_ENV['url_propre']);
157
+    #}
158 158
 
159
-	return [$fond, $contexte, $url_redirect];
159
+    return [$fond, $contexte, $url_redirect];
160 160
 }
161 161
 
162 162
 /**
@@ -169,20 +169,20 @@  discard block
 block discarded – undo
169 169
  * @return array|false|string
170 170
  */
171 171
 function urls_transition_retrouver_anciennes_url_propres(string $url_propre, string $entite, array $contexte = []): array {
172
-	if ($url_propre) {
173
-		if ($GLOBALS['profondeur_url'] <= 0) {
174
-			$urls_anciennes = charger_fonction_url('decoder', 'propres');
175
-		} else {
176
-			$urls_anciennes = charger_fonction_url('decoder', 'arbo');
177
-		}
172
+    if ($url_propre) {
173
+        if ($GLOBALS['profondeur_url'] <= 0) {
174
+            $urls_anciennes = charger_fonction_url('decoder', 'propres');
175
+        } else {
176
+            $urls_anciennes = charger_fonction_url('decoder', 'arbo');
177
+        }
178 178
 
179
-		if ($urls_anciennes) {
180
-			$urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
181
-		}
182
-		return $urls_anciennes ?: [];
183
-	}
179
+        if ($urls_anciennes) {
180
+            $urls_anciennes = $urls_anciennes($url_propre, $entite, $contexte);
181
+        }
182
+        return $urls_anciennes ?: [];
183
+    }
184 184
 
185
-	return [];
185
+    return [];
186 186
 }
187 187
 
188 188
 /**
@@ -195,41 +195,41 @@  discard block
 block discarded – undo
195 195
  * @return array|false|string
196 196
  */
197 197
 function urls_transition_retrouver_anciennes_url_html(string $url, string $entite, array $contexte = []): array {
198
-	// Migration depuis anciennes URLs ?
199
-	// traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
200
-	if (
201
-		$url
202
-		and $GLOBALS['profondeur_url'] <= 0
203
-	) {
204
-		$r = nettoyer_url_page($url, $contexte);
205
-		if ($r) {
206
-			[$contexte, $type, , , $suite] = $r;
207
-			$_id = id_table_objet($type);
208
-			$id_objet = $contexte[$_id];
209
-			$url_propre = generer_objet_url($id_objet, $type);
210
-			if (
211
-				strlen($url_propre)
212
-				and !strstr($url, (string) $url_propre)
213
-				and (
214
-					objet_test_si_publie($type, $id_objet)
215
-					or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
216
-				)
217
-			) {
218
-				[, $hash] = array_pad(explode('#', $url_propre), 2, null);
219
-				$args = [];
220
-				foreach (array_filter(explode('&', $suite)) as $fragment) {
221
-					if ($fragment != "$_id=$id_objet") {
222
-						$args[] = $fragment;
223
-					}
224
-				}
225
-				$url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
198
+    // Migration depuis anciennes URLs ?
199
+    // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
200
+    if (
201
+        $url
202
+        and $GLOBALS['profondeur_url'] <= 0
203
+    ) {
204
+        $r = nettoyer_url_page($url, $contexte);
205
+        if ($r) {
206
+            [$contexte, $type, , , $suite] = $r;
207
+            $_id = id_table_objet($type);
208
+            $id_objet = $contexte[$_id];
209
+            $url_propre = generer_objet_url($id_objet, $type);
210
+            if (
211
+                strlen($url_propre)
212
+                and !strstr($url, (string) $url_propre)
213
+                and (
214
+                    objet_test_si_publie($type, $id_objet)
215
+                    or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
216
+                )
217
+            ) {
218
+                [, $hash] = array_pad(explode('#', $url_propre), 2, null);
219
+                $args = [];
220
+                foreach (array_filter(explode('&', $suite)) as $fragment) {
221
+                    if ($fragment != "$_id=$id_objet") {
222
+                        $args[] = $fragment;
223
+                    }
224
+                }
225
+                $url_redirect = generer_objet_url($id_objet, $type, join('&', array_filter($args)), $hash);
226 226
 
227
-				return [$contexte, $type, $url_redirect, $type];
228
-			}
229
-		}
230
-	}
231
-	/* Fin compatibilite anciennes urls */
232
-	return [];
227
+                return [$contexte, $type, $url_redirect, $type];
228
+            }
229
+        }
230
+    }
231
+    /* Fin compatibilite anciennes urls */
232
+    return [];
233 233
 }
234 234
 
235 235
 /**
@@ -242,24 +242,24 @@  discard block
 block discarded – undo
242 242
  * @return string|array
243 243
  */
244 244
 function urls_liste_objets($preg = true) {
245
-	static $url_objets = null;
246
-	if (is_null($url_objets)) {
247
-		$url_objets = [];
248
-		// recuperer les tables_objets_sql declarees
249
-		$tables_objets = lister_tables_objets_sql();
250
-		foreach ($tables_objets as $t => $infos) {
251
-			if ($infos['page']) {
252
-				$url_objets[] = $infos['type'];
253
-				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
254
-			}
255
-		}
256
-		$url_objets = pipeline('declarer_url_objets', $url_objets);
257
-	}
258
-	if (!$preg) {
259
-		return $url_objets;
260
-	}
245
+    static $url_objets = null;
246
+    if (is_null($url_objets)) {
247
+        $url_objets = [];
248
+        // recuperer les tables_objets_sql declarees
249
+        $tables_objets = lister_tables_objets_sql();
250
+        foreach ($tables_objets as $t => $infos) {
251
+            if ($infos['page']) {
252
+                $url_objets[] = $infos['type'];
253
+                $url_objets = array_merge($url_objets, $infos['type_surnoms']);
254
+            }
255
+        }
256
+        $url_objets = pipeline('declarer_url_objets', $url_objets);
257
+    }
258
+    if (!$preg) {
259
+        return $url_objets;
260
+    }
261 261
 
262
-	return implode('|', array_map('preg_quote', $url_objets));
262
+    return implode('|', array_map('preg_quote', $url_objets));
263 263
 }
264 264
 
265 265
 /**
@@ -273,26 +273,26 @@  discard block
 block discarded – undo
273 273
  * @return array
274 274
  */
275 275
 function nettoyer_url_page($url, $contexte = []) {
276
-	$url_objets = urls_liste_objets();
277
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
278
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
276
+    $url_objets = urls_liste_objets();
277
+    $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
278
+    $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
279
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
280 280
 
281
-	if (
282
-		preg_match($raccourci_url_page_html, $url, $regs)
283
-		or preg_match($raccourci_url_page_id, $url, $regs)
284
-		or preg_match($raccourci_url_page_spip, $url, $regs)
285
-	) {
286
-		$regs = array_pad($regs, 4, null);
287
-		$type = objet_type($regs[1]);
288
-		$_id = id_table_objet($type);
289
-		$contexte[$_id] = $regs[2];
290
-		$suite = $regs[3];
281
+    if (
282
+        preg_match($raccourci_url_page_html, $url, $regs)
283
+        or preg_match($raccourci_url_page_id, $url, $regs)
284
+        or preg_match($raccourci_url_page_spip, $url, $regs)
285
+    ) {
286
+        $regs = array_pad($regs, 4, null);
287
+        $type = objet_type($regs[1]);
288
+        $_id = id_table_objet($type);
289
+        $contexte[$_id] = $regs[2];
290
+        $suite = $regs[3];
291 291
 
292
-		return [$contexte, $type, null, $type, $suite];
293
-	}
292
+        return [$contexte, $type, null, $type, $suite];
293
+    }
294 294
 
295
-	return [];
295
+    return [];
296 296
 }
297 297
 
298 298
 /**
@@ -310,37 +310,37 @@  discard block
 block discarded – undo
310 310
  * @return string
311 311
  */
312 312
 function generer_objet_url_ecrire(int $id, string $objet, string $args = '', string $ancre = '', ?bool $public = null, string $connect = ''): string {
313
-	static $furls = [];
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
-	}
313
+    static $furls = [];
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
 }
345 345
 
346 346
 /**
@@ -348,5 +348,5 @@  discard block
 block discarded – undo
348 348
  * @see generer_objet_url_ecrire
349 349
  */
350 350
 function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, string $connect = '') {
351
-	return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect);
351
+    return generer_objet_url_ecrire($id, $objet, $args, $ancre, $public, $connect);
352 352
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2449 added lines, -2449 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,38 +77,38 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = $desc['commit_short'] ?? $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = $desc['commit_short'] ?? $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if ($texte === null || !strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if ($texte === null || !strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	[$h, $l] = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    [$h, $l] = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	[$h, $l] = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    [$h, $l] = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
-	static $to = null;
870
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -910,44 +910,44 @@  discard block
 block discarded – undo
910 910
  *     Texte encodé pour XML
911 911
  */
912 912
 function texte_backend(string $texte): string {
913
-	if ($texte === '') {
914
-		return '';
915
-	}
913
+    if ($texte === '') {
914
+        return '';
915
+    }
916 916
 
917
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
917
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
918 918
 
919
-	// si on a des liens ou des images, les passer en absolu
920
-	$texte = liens_absolus($texte);
919
+    // si on a des liens ou des images, les passer en absolu
920
+    $texte = liens_absolus($texte);
921 921
 
922
-	// echapper les tags &gt; &lt;
923
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
922
+    // echapper les tags &gt; &lt;
923
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
924 924
 
925
-	// importer les &eacute;
926
-	$texte = filtrer_entites($texte);
925
+    // importer les &eacute;
926
+    $texte = filtrer_entites($texte);
927 927
 
928
-	// " -> &quot; et tout ce genre de choses
929
-	$u = $GLOBALS['meta']['pcre_u'];
930
-	$texte = str_replace('&nbsp;', ' ', $texte);
931
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
-	$texte = entites_html($texte, false, false);
934
-	// mais bien echapper les double quotes !
935
-	$texte = str_replace('"', '&#034;', $texte);
928
+    // " -> &quot; et tout ce genre de choses
929
+    $u = $GLOBALS['meta']['pcre_u'];
930
+    $texte = str_replace('&nbsp;', ' ', $texte);
931
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
+    $texte = entites_html($texte, false, false);
934
+    // mais bien echapper les double quotes !
935
+    $texte = str_replace('"', '&#034;', $texte);
936 936
 
937
-	// verifier le charset
938
-	$texte = charset2unicode($texte);
937
+    // verifier le charset
938
+    $texte = charset2unicode($texte);
939 939
 
940
-	// Caracteres problematiques en iso-latin 1
941
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
-		$texte = str_replace(chr(156), '&#156;', $texte);
943
-		$texte = str_replace(chr(140), '&#140;', $texte);
944
-		$texte = str_replace(chr(159), '&#159;', $texte);
945
-	}
940
+    // Caracteres problematiques en iso-latin 1
941
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
+        $texte = str_replace(chr(156), '&#156;', $texte);
943
+        $texte = str_replace(chr(140), '&#140;', $texte);
944
+        $texte = str_replace(chr(159), '&#159;', $texte);
945
+    }
946 946
 
947
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
948
-	// et le caractere apostrophe alourdit les squelettes avec PHP
949
-	// ==> on les remplace par l'entite HTML
950
-	return str_replace($apostrophe, "'", $texte);
947
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
948
+    // et le caractere apostrophe alourdit les squelettes avec PHP
949
+    // ==> on les remplace par l'entite HTML
950
+    return str_replace($apostrophe, "'", $texte);
951 951
 }
952 952
 
953 953
 /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
  *     Texte encodé et quote pour XML
965 965
  */
966 966
 function texte_backendq(string $texte): string {
967
-	return addslashes(texte_backend($texte));
967
+    return addslashes(texte_backend($texte));
968 968
 }
969 969
 
970 970
 
@@ -987,11 +987,11 @@  discard block
 block discarded – undo
987 987
  *     Numéro de titre, sinon chaîne vide
988 988
  **/
989 989
 function supprimer_numero($texte) {
990
-	return preg_replace(
991
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
-		'',
993
-		$texte
994
-	);
990
+    return preg_replace(
991
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
+        '',
993
+        $texte
994
+    );
995 995
 }
996 996
 
997 997
 /**
@@ -1014,17 +1014,17 @@  discard block
 block discarded – undo
1014 1014
  *     Numéro de titre, sinon chaîne vide
1015 1015
  **/
1016 1016
 function recuperer_numero($texte) {
1017
-	if (
1018
-		preg_match(
1019
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
-			$texte,
1021
-			$regs
1022
-		)
1023
-	) {
1024
-		return strval($regs[1]);
1025
-	} else {
1026
-		return '';
1027
-	}
1017
+    if (
1018
+        preg_match(
1019
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
+            $texte,
1021
+            $regs
1022
+        )
1023
+    ) {
1024
+        return strval($regs[1]);
1025
+    } else {
1026
+        return '';
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1051,16 +1051,16 @@  discard block
 block discarded – undo
1051 1051
  *     Texte converti
1052 1052
  **/
1053 1053
 function supprimer_tags(?string $texte, $rempl = ''): string {
1054
-	if ($texte === null || !strlen($texte)) {
1055
-		return '';
1056
-	}
1057
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
-	// ne pas oublier un < final non ferme car coupe
1059
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
-	// mais qui peut aussi etre un simple signe plus petit que
1061
-	$texte = str_replace('<', '&lt;', $texte);
1054
+    if ($texte === null || !strlen($texte)) {
1055
+        return '';
1056
+    }
1057
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
+    // ne pas oublier un < final non ferme car coupe
1059
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
+    // mais qui peut aussi etre un simple signe plus petit que
1061
+    $texte = str_replace('<', '&lt;', $texte);
1062 1062
 
1063
-	return $texte;
1063
+    return $texte;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1083,9 +1083,9 @@  discard block
 block discarded – undo
1083 1083
  *     Texte converti
1084 1084
  **/
1085 1085
 function echapper_tags($texte, $rempl = '') {
1086
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1086
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1087 1087
 
1088
-	return $texte;
1088
+    return $texte;
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1106,18 +1106,18 @@  discard block
 block discarded – undo
1106 1106
  *     Texte converti
1107 1107
  **/
1108 1108
 function textebrut($texte) {
1109
-	$u = $GLOBALS['meta']['pcre_u'];
1110
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
-	$texte = preg_replace("/^\n+/", '', $texte);
1113
-	$texte = preg_replace("/\n+$/", '', $texte);
1114
-	$texte = preg_replace("/\n +/", "\n", $texte);
1115
-	$texte = supprimer_tags($texte);
1116
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
-	$texte = str_replace('&#8217;', "'", $texte);
1109
+    $u = $GLOBALS['meta']['pcre_u'];
1110
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
+    $texte = preg_replace("/^\n+/", '', $texte);
1113
+    $texte = preg_replace("/\n+$/", '', $texte);
1114
+    $texte = preg_replace("/\n +/", "\n", $texte);
1115
+    $texte = supprimer_tags($texte);
1116
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
+    $texte = str_replace('&#8217;', "'", $texte);
1119 1119
 
1120
-	return $texte;
1120
+    return $texte;
1121 1121
 }
1122 1122
 
1123 1123
 
@@ -1133,23 +1133,23 @@  discard block
 block discarded – undo
1133 1133
  *     Texte avec liens ouvrants
1134 1134
  **/
1135 1135
 function liens_ouvrants($texte) {
1136
-	if (
1137
-		preg_match_all(
1138
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
-			$texte,
1140
-			$liens,
1141
-			PREG_PATTERN_ORDER
1142
-		)
1143
-	) {
1144
-		foreach ($liens[0] as $a) {
1145
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
-			$ablank = inserer_attribut($a, 'rel', $rel);
1147
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1148
-			$texte = str_replace($a, $ablank, $texte);
1149
-		}
1150
-	}
1151
-
1152
-	return $texte;
1136
+    if (
1137
+        preg_match_all(
1138
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
+            $texte,
1140
+            $liens,
1141
+            PREG_PATTERN_ORDER
1142
+        )
1143
+    ) {
1144
+        foreach ($liens[0] as $a) {
1145
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
+            $ablank = inserer_attribut($a, 'rel', $rel);
1147
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1148
+            $texte = str_replace($a, $ablank, $texte);
1149
+        }
1150
+    }
1151
+
1152
+    return $texte;
1153 1153
 }
1154 1154
 
1155 1155
 /**
@@ -1159,22 +1159,22 @@  discard block
 block discarded – undo
1159 1159
  * @return string
1160 1160
  */
1161 1161
 function liens_nofollow($texte) {
1162
-	if (stripos($texte, '<a') === false) {
1163
-		return $texte;
1164
-	}
1162
+    if (stripos($texte, '<a') === false) {
1163
+        return $texte;
1164
+    }
1165 1165
 
1166
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
-		foreach ($regs[0] as $a) {
1168
-			$rel = extraire_attribut($a, 'rel');
1169
-			if (strpos($rel, 'nofollow') === false) {
1170
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1171
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1172
-				$texte = str_replace($a, $anofollow, $texte);
1173
-			}
1174
-		}
1175
-	}
1166
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
+        foreach ($regs[0] as $a) {
1168
+            $rel = extraire_attribut($a, 'rel');
1169
+            if (strpos($rel, 'nofollow') === false) {
1170
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1171
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1172
+                $texte = str_replace($a, $anofollow, $texte);
1173
+            }
1174
+        }
1175
+    }
1176 1176
 
1177
-	return $texte;
1177
+    return $texte;
1178 1178
 }
1179 1179
 
1180 1180
 /**
@@ -1193,12 +1193,12 @@  discard block
 block discarded – undo
1193 1193
  *     Texte sans paraghaphes
1194 1194
  **/
1195 1195
 function PtoBR($texte) {
1196
-	$u = $GLOBALS['meta']['pcre_u'];
1197
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1198
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1196
+    $u = $GLOBALS['meta']['pcre_u'];
1197
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1198
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1200 1200
 
1201
-	return $texte;
1201
+    return $texte;
1202 1202
 }
1203 1203
 
1204 1204
 
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
  * @return string Texte encadré du style CSS
1224 1224
  */
1225 1225
 function lignes_longues($texte) {
1226
-	if (!strlen(trim($texte))) {
1227
-		return $texte;
1228
-	}
1229
-	include_spip('inc/texte');
1230
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
-		'div' : 'span';
1226
+    if (!strlen(trim($texte))) {
1227
+        return $texte;
1228
+    }
1229
+    include_spip('inc/texte');
1230
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
+        'div' : 'span';
1232 1232
 
1233
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1233
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1234 1234
 }
1235 1235
 
1236 1236
 /**
@@ -1249,30 +1249,30 @@  discard block
 block discarded – undo
1249 1249
  * @return string Texte en majuscule
1250 1250
  */
1251 1251
 function majuscules($texte) {
1252
-	if (!strlen($texte)) {
1253
-		return '';
1254
-	}
1252
+    if (!strlen($texte)) {
1253
+        return '';
1254
+    }
1255 1255
 
1256
-	// Cas du turc
1257
-	if ($GLOBALS['spip_lang'] == 'tr') {
1258
-		# remplacer hors des tags et des entites
1259
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
-			foreach ($regs as $n => $match) {
1261
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
-			}
1263
-		}
1256
+    // Cas du turc
1257
+    if ($GLOBALS['spip_lang'] == 'tr') {
1258
+        # remplacer hors des tags et des entites
1259
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
+            foreach ($regs as $n => $match) {
1261
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
+            }
1263
+        }
1264 1264
 
1265
-		$texte = str_replace('i', '&#304;', $texte);
1265
+        $texte = str_replace('i', '&#304;', $texte);
1266 1266
 
1267
-		if ($regs) {
1268
-			foreach ($regs as $n => $match) {
1269
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
-			}
1271
-		}
1272
-	}
1267
+        if ($regs) {
1268
+            foreach ($regs as $n => $match) {
1269
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
+            }
1271
+        }
1272
+    }
1273 1273
 
1274
-	// Cas general
1275
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1274
+    // Cas general
1275
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1276 1276
 }
1277 1277
 
1278 1278
 /**
@@ -1290,29 +1290,29 @@  discard block
 block discarded – undo
1290 1290
  * @return string
1291 1291
  **/
1292 1292
 function taille_en_octets($taille) {
1293
-	if (!defined('_KILOBYTE')) {
1294
-		/**
1295
-		 * Définit le nombre d'octets dans un Kilobyte
1296
-		 *
1297
-		 * @var int
1298
-		 **/
1299
-		define('_KILOBYTE', 1024);
1300
-	}
1293
+    if (!defined('_KILOBYTE')) {
1294
+        /**
1295
+         * Définit le nombre d'octets dans un Kilobyte
1296
+         *
1297
+         * @var int
1298
+         **/
1299
+        define('_KILOBYTE', 1024);
1300
+    }
1301 1301
 
1302
-	if ($taille < 1) {
1303
-		return '';
1304
-	}
1305
-	if ($taille < _KILOBYTE) {
1306
-		$taille = _T('taille_octets', ['taille' => $taille]);
1307
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
-	} else {
1312
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
-	}
1302
+    if ($taille < 1) {
1303
+        return '';
1304
+    }
1305
+    if ($taille < _KILOBYTE) {
1306
+        $taille = _T('taille_octets', ['taille' => $taille]);
1307
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
+    } else {
1312
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
+    }
1314 1314
 
1315
-	return $taille;
1315
+    return $taille;
1316 1316
 }
1317 1317
 
1318 1318
 
@@ -1334,21 +1334,21 @@  discard block
 block discarded – undo
1334 1334
  *     Texte prêt pour être utilisé en attribut HTML
1335 1335
  **/
1336 1336
 function attribut_html(?string $texte, $textebrut = true): string {
1337
-	if ($texte === null) {
1338
-		return '';
1339
-	}
1340
-	$u = $GLOBALS['meta']['pcre_u'];
1341
-	if ($textebrut) {
1342
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
-	}
1344
-	$texte = texte_backend($texte);
1345
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337
+    if ($texte === null) {
1338
+        return '';
1339
+    }
1340
+    $u = $GLOBALS['meta']['pcre_u'];
1341
+    if ($textebrut) {
1342
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
+    }
1344
+    $texte = texte_backend($texte);
1345
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346 1346
 
1347
-	return preg_replace(
1348
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
-		['&', '&#38;'],
1350
-		$texte
1351
-	);
1347
+    return preg_replace(
1348
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
+        ['&', '&#38;'],
1350
+        $texte
1351
+    );
1352 1352
 }
1353 1353
 
1354 1354
 
@@ -1368,15 +1368,15 @@  discard block
 block discarded – undo
1368 1368
  *     URL ou chaîne vide
1369 1369
  **/
1370 1370
 function vider_url(?string $url, $entites = true): string {
1371
-	if ($url === null) {
1372
-		return '';
1373
-	}
1374
-	# un message pour abs_url
1375
-	$GLOBALS['mode_abs_url'] = 'url';
1376
-	$url = trim($url);
1377
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1371
+    if ($url === null) {
1372
+        return '';
1373
+    }
1374
+    # un message pour abs_url
1375
+    $GLOBALS['mode_abs_url'] = 'url';
1376
+    $url = trim($url);
1377
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1378 1378
 
1379
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1379
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1380 1380
 }
1381 1381
 
1382 1382
 
@@ -1391,10 +1391,10 @@  discard block
 block discarded – undo
1391 1391
  * @return string Adresse email maquillée
1392 1392
  **/
1393 1393
 function antispam($texte) {
1394
-	include_spip('inc/acces');
1395
-	$masque = creer_pass_aleatoire(3);
1394
+    include_spip('inc/acces');
1395
+    $masque = creer_pass_aleatoire(3);
1396 1396
 
1397
-	return preg_replace('/@/', " $masque ", $texte);
1397
+    return preg_replace('/@/', " $masque ", $texte);
1398 1398
 }
1399 1399
 
1400 1400
 /**
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
  *     True si on a le droit d'accès, false sinon.
1427 1427
  **/
1428 1428
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1429
-	include_spip('inc/acces');
1430
-	if ($op) {
1431
-		$dir .= " $op $args";
1432
-	}
1429
+    include_spip('inc/acces');
1430
+    if ($op) {
1431
+        $dir .= " $op $args";
1432
+    }
1433 1433
 
1434
-	return verifier_low_sec($id_auteur, $cle, $dir);
1434
+    return verifier_low_sec($id_auteur, $cle, $dir);
1435 1435
 }
1436 1436
 
1437 1437
 /**
@@ -1456,13 +1456,13 @@  discard block
 block discarded – undo
1456 1456
  *     Retourne $texte, sinon $sinon.
1457 1457
  **/
1458 1458
 function sinon($texte, $sinon = '') {
1459
-	if ($texte) {
1460
-		return $texte;
1461
-	} elseif (is_scalar($texte) and strlen($texte)) {
1462
-		return $texte;
1463
-	} else {
1464
-		return $sinon;
1465
-	}
1459
+    if ($texte) {
1460
+        return $texte;
1461
+    } elseif (is_scalar($texte) and strlen($texte)) {
1462
+        return $texte;
1463
+    } else {
1464
+        return $sinon;
1465
+    }
1466 1466
 }
1467 1467
 
1468 1468
 /**
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
  * @return mixed
1487 1487
  **/
1488 1488
 function choixsivide($a, $vide, $pasvide) {
1489
-	return $a ? $pasvide : $vide;
1489
+    return $a ? $pasvide : $vide;
1490 1490
 }
1491 1491
 
1492 1492
 /**
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
  * @return mixed
1511 1511
  **/
1512 1512
 function choixsiegal($a1, $a2, $v, $f) {
1513
-	return ($a1 == $a2) ? $v : $f;
1513
+    return ($a1 == $a2) ? $v : $f;
1514 1514
 }
1515 1515
 
1516 1516
 //
@@ -1529,13 +1529,13 @@  discard block
 block discarded – undo
1529 1529
  * @return string
1530 1530
  **/
1531 1531
 function filtrer_ical($texte) {
1532
-	#include_spip('inc/charsets');
1533
-	$texte = html2unicode($texte);
1534
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
-	$texte = preg_replace('/,/', '\,', $texte);
1532
+    #include_spip('inc/charsets');
1533
+    $texte = html2unicode($texte);
1534
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
+    $texte = preg_replace("/\n/", ' ', $texte);
1536
+    $texte = preg_replace('/,/', '\,', $texte);
1537 1537
 
1538
-	return $texte;
1538
+    return $texte;
1539 1539
 }
1540 1540
 
1541 1541
 
@@ -1560,54 +1560,54 @@  discard block
 block discarded – undo
1560 1560
  * @return string
1561 1561
  **/
1562 1562
 function post_autobr($texte, $delim = "\n_ ") {
1563
-	if (!function_exists('echappe_html')) {
1564
-		include_spip('inc/texte_mini');
1565
-	}
1566
-	$texte = str_replace("\r\n", "\r", $texte);
1567
-	$texte = str_replace("\r", "\n", $texte);
1568
-
1569
-	if (preg_match(",\n+$,", $texte, $fin)) {
1570
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
-	} else {
1572
-		$fin = '';
1573
-	}
1574
-
1575
-	$texte = echappe_html($texte, '', true);
1576
-
1577
-	// echapper les modeles
1578
-	if (strpos($texte, '<') !== false) {
1579
-		include_spip('inc/lien');
1580
-		if (defined('_PREG_MODELE')) {
1581
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1583
-		}
1584
-	}
1585
-
1586
-	$debut = '';
1587
-	$suite = $texte;
1588
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1589
-		$debut .= substr($suite, 0, $t - 1);
1590
-		$suite = substr($suite, $t);
1591
-		$car = substr($suite, 0, 1);
1592
-		if (
1593
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
-		) {
1597
-			$debut .= $delim;
1598
-		} else {
1599
-			$debut .= "\n";
1600
-		}
1601
-		if (preg_match(",^\n+,", $suite, $regs)) {
1602
-			$debut .= $regs[0];
1603
-			$suite = substr($suite, strlen($regs[0]));
1604
-		}
1605
-	}
1606
-	$texte = $debut . $suite;
1607
-
1608
-	$texte = echappe_retour($texte);
1609
-
1610
-	return $texte . $fin;
1563
+    if (!function_exists('echappe_html')) {
1564
+        include_spip('inc/texte_mini');
1565
+    }
1566
+    $texte = str_replace("\r\n", "\r", $texte);
1567
+    $texte = str_replace("\r", "\n", $texte);
1568
+
1569
+    if (preg_match(",\n+$,", $texte, $fin)) {
1570
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
+    } else {
1572
+        $fin = '';
1573
+    }
1574
+
1575
+    $texte = echappe_html($texte, '', true);
1576
+
1577
+    // echapper les modeles
1578
+    if (strpos($texte, '<') !== false) {
1579
+        include_spip('inc/lien');
1580
+        if (defined('_PREG_MODELE')) {
1581
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1583
+        }
1584
+    }
1585
+
1586
+    $debut = '';
1587
+    $suite = $texte;
1588
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1589
+        $debut .= substr($suite, 0, $t - 1);
1590
+        $suite = substr($suite, $t);
1591
+        $car = substr($suite, 0, 1);
1592
+        if (
1593
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
+        ) {
1597
+            $debut .= $delim;
1598
+        } else {
1599
+            $debut .= "\n";
1600
+        }
1601
+        if (preg_match(",^\n+,", $suite, $regs)) {
1602
+            $debut .= $regs[0];
1603
+            $suite = substr($suite, strlen($regs[0]));
1604
+        }
1605
+    }
1606
+    $texte = $debut . $suite;
1607
+
1608
+    $texte = echappe_retour($texte);
1609
+
1610
+    return $texte . $fin;
1611 1611
 }
1612 1612
 
1613 1613
 
@@ -1648,47 +1648,47 @@  discard block
 block discarded – undo
1648 1648
  * @return string
1649 1649
  **/
1650 1650
 function extraire_idiome($letexte, $lang = null, $options = []) {
1651
-	static $traduire = false;
1652
-	if (
1653
-		$letexte
1654
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
-	) {
1656
-		if (!$traduire) {
1657
-			$traduire = charger_fonction('traduire', 'inc');
1658
-			include_spip('inc/lang');
1659
-		}
1660
-		if (!$lang) {
1661
-			$lang = $GLOBALS['spip_lang'];
1662
-		}
1663
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
-		if (is_bool($options)) {
1665
-			$options = ['echappe_span' => $options];
1666
-		}
1667
-		if (!isset($options['echappe_span'])) {
1668
-			$options = array_merge($options, ['echappe_span' => false]);
1669
-		}
1670
-
1671
-		foreach ($regs as $reg) {
1672
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
-			$desc = $traduire($cle, $lang, true);
1674
-			$l = $desc->langue;
1675
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
-			if (strlen($desc->texte)) {
1677
-				$trad = code_echappement($desc->texte, 'idiome', false);
1678
-				if ($l !== $lang) {
1679
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
-				}
1681
-				if (lang_dir($l) !== lang_dir($lang)) {
1682
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
-				}
1684
-				if (!$options['echappe_span']) {
1685
-					$trad = echappe_retour($trad, 'idiome');
1686
-				}
1687
-				$letexte = str_replace($reg[0], $trad, $letexte);
1688
-			}
1689
-		}
1690
-	}
1691
-	return $letexte;
1651
+    static $traduire = false;
1652
+    if (
1653
+        $letexte
1654
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
+    ) {
1656
+        if (!$traduire) {
1657
+            $traduire = charger_fonction('traduire', 'inc');
1658
+            include_spip('inc/lang');
1659
+        }
1660
+        if (!$lang) {
1661
+            $lang = $GLOBALS['spip_lang'];
1662
+        }
1663
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
+        if (is_bool($options)) {
1665
+            $options = ['echappe_span' => $options];
1666
+        }
1667
+        if (!isset($options['echappe_span'])) {
1668
+            $options = array_merge($options, ['echappe_span' => false]);
1669
+        }
1670
+
1671
+        foreach ($regs as $reg) {
1672
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
+            $desc = $traduire($cle, $lang, true);
1674
+            $l = $desc->langue;
1675
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
+            if (strlen($desc->texte)) {
1677
+                $trad = code_echappement($desc->texte, 'idiome', false);
1678
+                if ($l !== $lang) {
1679
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
+                }
1681
+                if (lang_dir($l) !== lang_dir($lang)) {
1682
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
+                }
1684
+                if (!$options['echappe_span']) {
1685
+                    $trad = echappe_retour($trad, 'idiome');
1686
+                }
1687
+                $letexte = str_replace($reg[0], $trad, $letexte);
1688
+            }
1689
+        }
1690
+    }
1691
+    return $letexte;
1692 1692
 }
1693 1693
 
1694 1694
 /**
@@ -1740,68 +1740,68 @@  discard block
 block discarded – undo
1740 1740
  **/
1741 1741
 function extraire_multi($letexte, $lang = null, $options = []) {
1742 1742
 
1743
-	if (
1744
-		$letexte
1745
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
-	) {
1747
-		if (!$lang) {
1748
-			$lang = $GLOBALS['spip_lang'];
1749
-		}
1750
-
1751
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
-		if (is_bool($options)) {
1753
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
-		}
1755
-		if (!isset($options['echappe_span'])) {
1756
-			$options = array_merge($options, ['echappe_span' => false]);
1757
-		}
1758
-		if (!isset($options['lang_defaut'])) {
1759
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
-		}
1761
-
1762
-		include_spip('inc/lang');
1763
-		foreach ($regs as $reg) {
1764
-			// chercher la version de la langue courante
1765
-			$trads = extraire_trads($reg[1]);
1766
-			if ($l = approcher_langue($trads, $lang)) {
1767
-				$trad = $trads[$l];
1768
-			} else {
1769
-				if ($options['lang_defaut'] == 'aucune') {
1770
-					$trad = '';
1771
-				} else {
1772
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
-					// ou la premiere dispo
1774
-					// mais typographier le texte selon les regles de celle-ci
1775
-					// Attention aux blocs multi sur plusieurs lignes
1776
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
-						$l = key($trads);
1778
-					}
1779
-					$trad = $trads[$l];
1780
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1781
-					$trad = $typographie($trad);
1782
-					// Tester si on echappe en span ou en div
1783
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1784
-					include_spip('inc/texte');
1785
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
-					if ($mode === 'div') {
1788
-						$trad = rtrim($trad) . "\n\n";
1789
-					}
1790
-					$trad = code_echappement($trad, 'multi', false, $mode);
1791
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
-					if (lang_dir($l) !== lang_dir($lang)) {
1793
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
-					}
1795
-					if (!$options['echappe_span']) {
1796
-						$trad = echappe_retour($trad, 'multi');
1797
-					}
1798
-				}
1799
-			}
1800
-			$letexte = str_replace($reg[0], $trad, $letexte);
1801
-		}
1802
-	}
1803
-
1804
-	return $letexte;
1743
+    if (
1744
+        $letexte
1745
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
+    ) {
1747
+        if (!$lang) {
1748
+            $lang = $GLOBALS['spip_lang'];
1749
+        }
1750
+
1751
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
+        if (is_bool($options)) {
1753
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
+        }
1755
+        if (!isset($options['echappe_span'])) {
1756
+            $options = array_merge($options, ['echappe_span' => false]);
1757
+        }
1758
+        if (!isset($options['lang_defaut'])) {
1759
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
+        }
1761
+
1762
+        include_spip('inc/lang');
1763
+        foreach ($regs as $reg) {
1764
+            // chercher la version de la langue courante
1765
+            $trads = extraire_trads($reg[1]);
1766
+            if ($l = approcher_langue($trads, $lang)) {
1767
+                $trad = $trads[$l];
1768
+            } else {
1769
+                if ($options['lang_defaut'] == 'aucune') {
1770
+                    $trad = '';
1771
+                } else {
1772
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
+                    // ou la premiere dispo
1774
+                    // mais typographier le texte selon les regles de celle-ci
1775
+                    // Attention aux blocs multi sur plusieurs lignes
1776
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
+                        $l = key($trads);
1778
+                    }
1779
+                    $trad = $trads[$l];
1780
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1781
+                    $trad = $typographie($trad);
1782
+                    // Tester si on echappe en span ou en div
1783
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1784
+                    include_spip('inc/texte');
1785
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
+                    if ($mode === 'div') {
1788
+                        $trad = rtrim($trad) . "\n\n";
1789
+                    }
1790
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1791
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
+                    if (lang_dir($l) !== lang_dir($lang)) {
1793
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
+                    }
1795
+                    if (!$options['echappe_span']) {
1796
+                        $trad = echappe_retour($trad, 'multi');
1797
+                    }
1798
+                }
1799
+            }
1800
+            $letexte = str_replace($reg[0], $trad, $letexte);
1801
+        }
1802
+    }
1803
+
1804
+    return $letexte;
1805 1805
 }
1806 1806
 
1807 1807
 /**
@@ -1817,21 +1817,21 @@  discard block
 block discarded – undo
1817 1817
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1818 1818
  **/
1819 1819
 function extraire_trads($bloc) {
1820
-	$trads = [];
1821
-	$lang = '';
1820
+    $trads = [];
1821
+    $lang = '';
1822 1822
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1823 1823
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1824
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
-		$texte = trim($regs[1]);
1826
-		if ($texte or $lang) {
1827
-			$trads[$lang] = $texte;
1828
-		}
1829
-		$bloc = substr($bloc, strlen($regs[0]));
1830
-		$lang = $regs[2];
1831
-	}
1832
-	$trads[$lang] = $bloc;
1824
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
+        $texte = trim($regs[1]);
1826
+        if ($texte or $lang) {
1827
+            $trads[$lang] = $texte;
1828
+        }
1829
+        $bloc = substr($bloc, strlen($regs[0]));
1830
+        $lang = $regs[2];
1831
+    }
1832
+    $trads[$lang] = $bloc;
1833 1833
 
1834
-	return $trads;
1834
+    return $trads;
1835 1835
 }
1836 1836
 
1837 1837
 
@@ -1842,7 +1842,7 @@  discard block
 block discarded – undo
1842 1842
  * @return string L'initiale en majuscule
1843 1843
  */
1844 1844
 function filtre_initiale($nom) {
1845
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1845
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1846 1846
 }
1847 1847
 
1848 1848
 
@@ -1887,33 +1887,33 @@  discard block
 block discarded – undo
1887 1887
  *      - null (interne) : si on empile
1888 1888
  **/
1889 1889
 function unique($donnee, $famille = '', $cpt = false) {
1890
-	static $mem = [];
1891
-	// permettre de vider la pile et de la restaurer
1892
-	// pour le calcul de introduction...
1893
-	if ($famille == '_spip_raz_') {
1894
-		$tmp = $mem;
1895
-		$mem = [];
1896
-
1897
-		return $tmp;
1898
-	} elseif ($famille == '_spip_set_') {
1899
-		$mem = $donnee;
1900
-
1901
-		return;
1902
-	}
1903
-	// eviter une notice
1904
-	if (!isset($mem[$famille])) {
1905
-		$mem[$famille] = [];
1906
-	}
1907
-	if ($cpt) {
1908
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
-	}
1910
-	// eviter une notice
1911
-	if (!isset($mem[$famille][$donnee])) {
1912
-		$mem[$famille][$donnee] = 0;
1913
-	}
1914
-	if (!($mem[$famille][$donnee]++)) {
1915
-		return $donnee;
1916
-	}
1890
+    static $mem = [];
1891
+    // permettre de vider la pile et de la restaurer
1892
+    // pour le calcul de introduction...
1893
+    if ($famille == '_spip_raz_') {
1894
+        $tmp = $mem;
1895
+        $mem = [];
1896
+
1897
+        return $tmp;
1898
+    } elseif ($famille == '_spip_set_') {
1899
+        $mem = $donnee;
1900
+
1901
+        return;
1902
+    }
1903
+    // eviter une notice
1904
+    if (!isset($mem[$famille])) {
1905
+        $mem[$famille] = [];
1906
+    }
1907
+    if ($cpt) {
1908
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
+    }
1910
+    // eviter une notice
1911
+    if (!isset($mem[$famille][$donnee])) {
1912
+        $mem[$famille][$donnee] = 0;
1913
+    }
1914
+    if (!($mem[$famille][$donnee]++)) {
1915
+        return $donnee;
1916
+    }
1917 1917
 }
1918 1918
 
1919 1919
 
@@ -1943,16 +1943,16 @@  discard block
 block discarded – undo
1943 1943
  *     Une des valeurs en fonction du compteur.
1944 1944
  **/
1945 1945
 function alterner($i, ...$args) {
1946
-	// recuperer les arguments (attention fonctions un peu space)
1947
-	$num = count($args);
1946
+    // recuperer les arguments (attention fonctions un peu space)
1947
+    $num = count($args);
1948 1948
 
1949
-	if ($num === 1 && is_array($args[0])) {
1950
-		$args = $args[0];
1951
-		$num = count($args);
1952
-	}
1949
+    if ($num === 1 && is_array($args[0])) {
1950
+        $args = $args[0];
1951
+        $num = count($args);
1952
+    }
1953 1953
 
1954
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
-	return $args[(intval($i) - 1) % $num];
1954
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
+    return $args[(intval($i) - 1) % $num];
1956 1956
 }
1957 1957
 
1958 1958
 
@@ -1978,51 +1978,51 @@  discard block
 block discarded – undo
1978 1978
  *     - null lorsque l’attribut n’existe pas.
1979 1979
  **/
1980 1980
 function extraire_attribut($balise, $attribut, $complet = false) {
1981
-	if (is_array($balise)) {
1982
-		array_walk(
1983
-			$balise,
1984
-			function (&$a, $key, $t) {
1985
-				$a = extraire_attribut($a, $t);
1986
-			},
1987
-			$attribut
1988
-		);
1989
-
1990
-		return $balise;
1991
-	}
1992
-	if (
1993
-		$balise
1994
-		&& preg_match(
1995
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
-			. $attribut
1997
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
-			$balise,
1999
-			$r
2000
-		)
2001
-	) {
2002
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
-			$r[4] = substr($r[3], 1, -1);
2004
-			$r[3] = $r[3][0];
2005
-		} elseif ($r[3] !== '') {
2006
-			$r[4] = $r[3];
2007
-			$r[3] = '';
2008
-		} else {
2009
-			$r[4] = trim($r[2]);
2010
-		}
2011
-		$att = $r[4];
2012
-		if (strpos($att, '&#') !== false) {
2013
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
-		}
2015
-		$att = filtrer_entites($att);
2016
-	} else {
2017
-		$att = null;
2018
-		$r = [];
2019
-	}
2020
-
2021
-	if ($complet) {
2022
-		return [$att, $r];
2023
-	} else {
2024
-		return $att;
2025
-	}
1981
+    if (is_array($balise)) {
1982
+        array_walk(
1983
+            $balise,
1984
+            function (&$a, $key, $t) {
1985
+                $a = extraire_attribut($a, $t);
1986
+            },
1987
+            $attribut
1988
+        );
1989
+
1990
+        return $balise;
1991
+    }
1992
+    if (
1993
+        $balise
1994
+        && preg_match(
1995
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
+            . $attribut
1997
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
+            $balise,
1999
+            $r
2000
+        )
2001
+    ) {
2002
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
+            $r[4] = substr($r[3], 1, -1);
2004
+            $r[3] = $r[3][0];
2005
+        } elseif ($r[3] !== '') {
2006
+            $r[4] = $r[3];
2007
+            $r[3] = '';
2008
+        } else {
2009
+            $r[4] = trim($r[2]);
2010
+        }
2011
+        $att = $r[4];
2012
+        if (strpos($att, '&#') !== false) {
2013
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
+        }
2015
+        $att = filtrer_entites($att);
2016
+    } else {
2017
+        $att = null;
2018
+        $r = [];
2019
+    }
2020
+
2021
+    if ($complet) {
2022
+        return [$att, $r];
2023
+    } else {
2024
+        return $att;
2025
+    }
2026 2026
 }
2027 2027
 
2028 2028
 /**
@@ -2055,41 +2055,41 @@  discard block
 block discarded – undo
2055 2055
  **/
2056 2056
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2057 2057
 
2058
-	if ($balise === null or $balise === '') {
2059
-		return '';
2060
-	}
2058
+    if ($balise === null or $balise === '') {
2059
+        return '';
2060
+    }
2061 2061
 
2062
-	// preparer l'attribut
2063
-	// supprimer les &nbsp; etc mais pas les balises html
2064
-	// qui ont un sens dans un attribut value d'un input
2065
-	if ($proteger) {
2066
-		$val = attribut_html($val, false);
2067
-	}
2062
+    // preparer l'attribut
2063
+    // supprimer les &nbsp; etc mais pas les balises html
2064
+    // qui ont un sens dans un attribut value d'un input
2065
+    if ($proteger) {
2066
+        $val = attribut_html($val, false);
2067
+    }
2068 2068
 
2069
-	// echapper les ' pour eviter tout bug
2070
-	$val = str_replace("'", '&#039;', $val);
2071
-	if ($vider and strlen($val) === 0) {
2072
-		$insert = '';
2073
-	} else {
2074
-		$insert = " $attribut='$val'";
2075
-	}
2069
+    // echapper les ' pour eviter tout bug
2070
+    $val = str_replace("'", '&#039;', $val);
2071
+    if ($vider and strlen($val) === 0) {
2072
+        $insert = '';
2073
+    } else {
2074
+        $insert = " $attribut='$val'";
2075
+    }
2076 2076
 
2077
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2077
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2078 2078
 
2079
-	if ($old !== null) {
2080
-		// Remplacer l'ancien attribut du meme nom
2081
-		$balise = $r[1] . $insert . $r[5];
2082
-	} else {
2083
-		// preferer une balise " />" (comme <img />)
2084
-		if (preg_match(',/>,', $balise)) {
2085
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
-		} // sinon une balise <a ...> ... </a>
2087
-		else {
2088
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
-		}
2090
-	}
2079
+    if ($old !== null) {
2080
+        // Remplacer l'ancien attribut du meme nom
2081
+        $balise = $r[1] . $insert . $r[5];
2082
+    } else {
2083
+        // preferer une balise " />" (comme <img />)
2084
+        if (preg_match(',/>,', $balise)) {
2085
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
+        } // sinon une balise <a ...> ... </a>
2087
+        else {
2088
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
+        }
2090
+    }
2091 2091
 
2092
-	return $balise;
2092
+    return $balise;
2093 2093
 }
2094 2094
 
2095 2095
 /**
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
  * @return string Code HTML sans l'attribut
2108 2108
  **/
2109 2109
 function vider_attribut(?string $balise, string $attribut): string {
2110
-	return inserer_attribut($balise, $attribut, '', false, true);
2110
+    return inserer_attribut($balise, $attribut, '', false, true);
2111 2111
 }
2112 2112
 
2113 2113
 /**
@@ -2119,53 +2119,53 @@  discard block
 block discarded – undo
2119 2119
  * @return string
2120 2120
  */
2121 2121
 function modifier_class($balise, $class, $operation = 'ajouter') {
2122
-	if (is_string($class)) {
2123
-		$class = explode(' ', trim($class));
2124
-	}
2125
-	$class = array_filter($class);
2126
-	$class = array_unique($class);
2127
-	if (!$class) {
2128
-		return $balise;
2129
-	}
2130
-
2131
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2132
-	if (preg_match(',[^\w-],', implode('', $class))) {
2133
-		return $balise;
2134
-	}
2135
-
2136
-	$class_courante = extraire_attribut($balise, 'class');
2137
-	$class_new = $class_courante;
2138
-	foreach ($class as $c) {
2139
-		$is_class_presente = false;
2140
-		if (
2141
-			$class_courante
2142
-			and strpos($class_courante, (string) $c) !== false
2143
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
-		) {
2145
-			$is_class_presente = true;
2146
-		}
2147
-		if (
2148
-			in_array($operation, ['ajouter', 'commuter'])
2149
-			and !$is_class_presente
2150
-		) {
2151
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
-		} elseif (
2153
-			in_array($operation, ['supprimer', 'commuter'])
2154
-			and $is_class_presente
2155
-		) {
2156
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
-		}
2158
-	}
2159
-
2160
-	if ($class_new !== $class_courante) {
2161
-		if (strlen($class_new)) {
2162
-			$balise = inserer_attribut($balise, 'class', $class_new);
2163
-		} elseif ($class_courante) {
2164
-			$balise = vider_attribut($balise, 'class');
2165
-		}
2166
-	}
2167
-
2168
-	return $balise;
2122
+    if (is_string($class)) {
2123
+        $class = explode(' ', trim($class));
2124
+    }
2125
+    $class = array_filter($class);
2126
+    $class = array_unique($class);
2127
+    if (!$class) {
2128
+        return $balise;
2129
+    }
2130
+
2131
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2132
+    if (preg_match(',[^\w-],', implode('', $class))) {
2133
+        return $balise;
2134
+    }
2135
+
2136
+    $class_courante = extraire_attribut($balise, 'class');
2137
+    $class_new = $class_courante;
2138
+    foreach ($class as $c) {
2139
+        $is_class_presente = false;
2140
+        if (
2141
+            $class_courante
2142
+            and strpos($class_courante, (string) $c) !== false
2143
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
+        ) {
2145
+            $is_class_presente = true;
2146
+        }
2147
+        if (
2148
+            in_array($operation, ['ajouter', 'commuter'])
2149
+            and !$is_class_presente
2150
+        ) {
2151
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
+        } elseif (
2153
+            in_array($operation, ['supprimer', 'commuter'])
2154
+            and $is_class_presente
2155
+        ) {
2156
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
+        }
2158
+    }
2159
+
2160
+    if ($class_new !== $class_courante) {
2161
+        if (strlen($class_new)) {
2162
+            $balise = inserer_attribut($balise, 'class', $class_new);
2163
+        } elseif ($class_courante) {
2164
+            $balise = vider_attribut($balise, 'class');
2165
+        }
2166
+    }
2167
+
2168
+    return $balise;
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
  * @return string
2176 2176
  */
2177 2177
 function ajouter_class($balise, $class) {
2178
-	return modifier_class($balise, $class, 'ajouter');
2178
+    return modifier_class($balise, $class, 'ajouter');
2179 2179
 }
2180 2180
 
2181 2181
 /**
@@ -2185,7 +2185,7 @@  discard block
 block discarded – undo
2185 2185
  * @return string
2186 2186
  */
2187 2187
 function supprimer_class($balise, $class) {
2188
-	return modifier_class($balise, $class, 'supprimer');
2188
+    return modifier_class($balise, $class, 'supprimer');
2189 2189
 }
2190 2190
 
2191 2191
 /**
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
  * @return string
2197 2197
  */
2198 2198
 function commuter_class($balise, $class) {
2199
-	return modifier_class($balise, $class, 'commuter');
2199
+    return modifier_class($balise, $class, 'commuter');
2200 2200
 }
2201 2201
 
2202 2202
 /**
@@ -2207,19 +2207,19 @@  discard block
 block discarded – undo
2207 2207
  * @return string
2208 2208
  */
2209 2209
 function tester_config($id, $mode = '') {
2210
-	include_spip('action/inscrire_auteur');
2210
+    include_spip('action/inscrire_auteur');
2211 2211
 
2212
-	return tester_statut_inscription($mode, $id);
2212
+    return tester_statut_inscription($mode, $id);
2213 2213
 }
2214 2214
 
2215 2215
 //
2216 2216
 // Quelques fonctions de calcul arithmetique
2217 2217
 //
2218 2218
 function floatstr($a) {
2219
- return str_replace(',', '.', (string)floatval($a));
2219
+    return str_replace(',', '.', (string)floatval($a));
2220 2220
 }
2221 2221
 function strize($f, $a, $b) {
2222
- return floatstr($f(floatstr($a), floatstr($b)));
2222
+    return floatstr($f(floatstr($a), floatstr($b)));
2223 2223
 }
2224 2224
 
2225 2225
 /**
@@ -2238,7 +2238,7 @@  discard block
 block discarded – undo
2238 2238
  * @return int $a+$b
2239 2239
  **/
2240 2240
 function plus($a, $b) {
2241
-	return $a + $b;
2241
+    return $a + $b;
2242 2242
 }
2243 2243
 function strplus($a, $b) {
2244 2244
 return strize('plus', $a, $b);
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
  * @return int $a-$b
2260 2260
  **/
2261 2261
 function moins($a, $b) {
2262
-	return $a - $b;
2262
+    return $a - $b;
2263 2263
 }
2264 2264
 function strmoins($a, $b) {
2265 2265
 return strize('moins', $a, $b);
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
  * @return int $a*$b
2283 2283
  **/
2284 2284
 function mult($a, $b) {
2285
-	return $a * $b;
2285
+    return $a * $b;
2286 2286
 }
2287 2287
 function strmult($a, $b) {
2288 2288
 return strize('mult', $a, $b);
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
  * @return int $a/$b (ou 0 si $b est nul)
2306 2306
  **/
2307 2307
 function div($a, $b) {
2308
-	return $b ? $a / $b : 0;
2308
+    return $b ? $a / $b : 0;
2309 2309
 }
2310 2310
 function strdiv($a, $b) {
2311 2311
 return strize('div', $a, $b);
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
  * @return int ($nb % $mod) + $add
2330 2330
  **/
2331 2331
 function modulo($nb, $mod, $add = 0) {
2332
-	return ($mod ? $nb % $mod : 0) + $add;
2332
+    return ($mod ? $nb % $mod : 0) + $add;
2333 2333
 }
2334 2334
 
2335 2335
 
@@ -2344,26 +2344,26 @@  discard block
 block discarded – undo
2344 2344
  *      - true sinon
2345 2345
  **/
2346 2346
 function nom_acceptable($nom) {
2347
-	$remp2 = [];
2348
-	$remp1 = [];
2349
-	if (!is_string($nom)) {
2350
-		return false;
2351
-	}
2352
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2353
-		define('_TAGS_NOM_AUTEUR', '');
2354
-	}
2355
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
-	foreach ($tags_acceptes as $tag) {
2357
-		if (strlen($tag)) {
2358
-			$remp1[] = '<' . trim($tag) . '>';
2359
-			$remp1[] = '</' . trim($tag) . '>';
2360
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2361
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2362
-		}
2363
-	}
2364
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
-
2366
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2347
+    $remp2 = [];
2348
+    $remp1 = [];
2349
+    if (!is_string($nom)) {
2350
+        return false;
2351
+    }
2352
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2353
+        define('_TAGS_NOM_AUTEUR', '');
2354
+    }
2355
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
+    foreach ($tags_acceptes as $tag) {
2357
+        if (strlen($tag)) {
2358
+            $remp1[] = '<' . trim($tag) . '>';
2359
+            $remp1[] = '</' . trim($tag) . '>';
2360
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2361
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2362
+        }
2363
+    }
2364
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
+
2366
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2367 2367
 }
2368 2368
 
2369 2369
 
@@ -2379,14 +2379,14 @@  discard block
 block discarded – undo
2379 2379
  *      - renvoie un tableau si l'entree est un tableau
2380 2380
  **/
2381 2381
 function email_valide($adresses) {
2382
-	if (is_array($adresses)) {
2383
-		$adresses = array_map('email_valide', $adresses);
2384
-		$adresses = array_filter($adresses);
2385
-		return $adresses;
2386
-	}
2382
+    if (is_array($adresses)) {
2383
+        $adresses = array_map('email_valide', $adresses);
2384
+        $adresses = array_filter($adresses);
2385
+        return $adresses;
2386
+    }
2387 2387
 
2388
-	$email_valide = charger_fonction('email_valide', 'inc');
2389
-	return $email_valide($adresses);
2388
+    $email_valide = charger_fonction('email_valide', 'inc');
2389
+    return $email_valide($adresses);
2390 2390
 }
2391 2391
 
2392 2392
 /**
@@ -2400,27 +2400,27 @@  discard block
 block discarded – undo
2400 2400
  * @return string Texte
2401 2401
  **/
2402 2402
 function afficher_enclosures($tags) {
2403
-	$s = [];
2404
-	foreach (extraire_balises($tags, 'a') as $tag) {
2405
-		if (
2406
-			extraire_attribut($tag, 'rel') == 'enclosure'
2407
-			and $t = extraire_attribut($tag, 'href')
2408
-		) {
2409
-			$s[] = preg_replace(
2410
-				',>[^<]+</a>,S',
2411
-				'>'
2412
-				. http_img_pack(
2413
-					'attachment-16.png',
2414
-					$t,
2415
-					'title="' . attribut_html($t) . '"'
2416
-				)
2417
-				. '</a>',
2418
-				$tag
2419
-			);
2420
-		}
2421
-	}
2422
-
2423
-	return join('&nbsp;', $s);
2403
+    $s = [];
2404
+    foreach (extraire_balises($tags, 'a') as $tag) {
2405
+        if (
2406
+            extraire_attribut($tag, 'rel') == 'enclosure'
2407
+            and $t = extraire_attribut($tag, 'href')
2408
+        ) {
2409
+            $s[] = preg_replace(
2410
+                ',>[^<]+</a>,S',
2411
+                '>'
2412
+                . http_img_pack(
2413
+                    'attachment-16.png',
2414
+                    $t,
2415
+                    'title="' . attribut_html($t) . '"'
2416
+                )
2417
+                . '</a>',
2418
+                $tag
2419
+            );
2420
+        }
2421
+    }
2422
+
2423
+    return join('&nbsp;', $s);
2424 2424
 }
2425 2425
 
2426 2426
 /**
@@ -2435,15 +2435,15 @@  discard block
 block discarded – undo
2435 2435
  * @return string Liens trouvés
2436 2436
  **/
2437 2437
 function afficher_tags($tags, $rels = 'tag,directory') {
2438
-	$s = [];
2439
-	foreach (extraire_balises($tags, 'a') as $tag) {
2440
-		$rel = extraire_attribut($tag, 'rel');
2441
-		if (strstr(",$rels,", (string) ",$rel,")) {
2442
-			$s[] = $tag;
2443
-		}
2444
-	}
2438
+    $s = [];
2439
+    foreach (extraire_balises($tags, 'a') as $tag) {
2440
+        $rel = extraire_attribut($tag, 'rel');
2441
+        if (strstr(",$rels,", (string) ",$rel,")) {
2442
+            $s[] = $tag;
2443
+        }
2444
+    }
2445 2445
 
2446
-	return join(', ', $s);
2446
+    return join(', ', $s);
2447 2447
 }
2448 2448
 
2449 2449
 
@@ -2465,21 +2465,21 @@  discard block
 block discarded – undo
2465 2465
  * @return string Tag HTML `<a>` avec microformat.
2466 2466
  **/
2467 2467
 function enclosure2microformat($e) {
2468
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2470
-	}
2471
-	$type = extraire_attribut($e, 'type');
2472
-	if (!$length = extraire_attribut($e, 'length')) {
2473
-		# <media:content : longeur dans fileSize. On tente.
2474
-		$length = extraire_attribut($e, 'fileSize');
2475
-	}
2476
-	$fichier = basename($url);
2468
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2470
+    }
2471
+    $type = extraire_attribut($e, 'type');
2472
+    if (!$length = extraire_attribut($e, 'length')) {
2473
+        # <media:content : longeur dans fileSize. On tente.
2474
+        $length = extraire_attribut($e, 'fileSize');
2475
+    }
2476
+    $fichier = basename($url);
2477 2477
 
2478
-	return '<a rel="enclosure"'
2479
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
-	. '>' . $fichier . '</a>';
2478
+    return '<a rel="enclosure"'
2479
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
+    . '>' . $fichier . '</a>';
2483 2483
 }
2484 2484
 
2485 2485
 /**
@@ -2497,24 +2497,24 @@  discard block
 block discarded – undo
2497 2497
  * @return string Tags RSS `<enclosure>`.
2498 2498
  **/
2499 2499
 function microformat2enclosure($tags) {
2500
-	$enclosures = [];
2501
-	foreach (extraire_balises($tags, 'a') as $e) {
2502
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2504
-			$type = extraire_attribut($e, 'type');
2505
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
-				$length = intval(extraire_attribut($e, 'length'));
2507
-			} # vieux data
2508
-			$fichier = basename($url);
2509
-			$enclosures[] = '<enclosure'
2510
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
-				. ($length ? ' length="' . $length . '"' : '')
2513
-				. ' />';
2514
-		}
2515
-	}
2500
+    $enclosures = [];
2501
+    foreach (extraire_balises($tags, 'a') as $e) {
2502
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2504
+            $type = extraire_attribut($e, 'type');
2505
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
+                $length = intval(extraire_attribut($e, 'length'));
2507
+            } # vieux data
2508
+            $fichier = basename($url);
2509
+            $enclosures[] = '<enclosure'
2510
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
+                . ($length ? ' length="' . $length . '"' : '')
2513
+                . ' />';
2514
+        }
2515
+    }
2516 2516
 
2517
-	return join("\n", $enclosures);
2517
+    return join("\n", $enclosures);
2518 2518
 }
2519 2519
 
2520 2520
 
@@ -2530,16 +2530,16 @@  discard block
 block discarded – undo
2530 2530
  * @return string Tags RSS Atom `<dc:subject>`.
2531 2531
  **/
2532 2532
 function tags2dcsubject($tags) {
2533
-	$subjects = '';
2534
-	foreach (extraire_balises($tags, 'a') as $e) {
2535
-		if (extraire_attribut($e, 'rel') == 'tag') {
2536
-			$subjects .= '<dc:subject>'
2537
-				. texte_backend(textebrut($e))
2538
-				. '</dc:subject>' . "\n";
2539
-		}
2540
-	}
2533
+    $subjects = '';
2534
+    foreach (extraire_balises($tags, 'a') as $e) {
2535
+        if (extraire_attribut($e, 'rel') == 'tag') {
2536
+            $subjects .= '<dc:subject>'
2537
+                . texte_backend(textebrut($e))
2538
+                . '</dc:subject>' . "\n";
2539
+        }
2540
+    }
2541 2541
 
2542
-	return $subjects;
2542
+    return $subjects;
2543 2543
 }
2544 2544
 
2545 2545
 /**
@@ -2568,27 +2568,27 @@  discard block
 block discarded – undo
2568 2568
  *     - Tableau de résultats, si tableau en entrée.
2569 2569
  **/
2570 2570
 function extraire_balise($texte, $tag = 'a') {
2571
-	if (is_array($texte)) {
2572
-		array_walk(
2573
-			$texte,
2574
-			function (&$a, $key, $t) {
2575
-				$a = extraire_balise($a, $t);
2576
-			},
2577
-			$tag
2578
-		);
2579
-
2580
-		return $texte;
2581
-	}
2582
-
2583
-	if (
2584
-		preg_match(
2585
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
-			$texte,
2587
-			$regs
2588
-		)
2589
-	) {
2590
-		return $regs[0];
2591
-	}
2571
+    if (is_array($texte)) {
2572
+        array_walk(
2573
+            $texte,
2574
+            function (&$a, $key, $t) {
2575
+                $a = extraire_balise($a, $t);
2576
+            },
2577
+            $tag
2578
+        );
2579
+
2580
+        return $texte;
2581
+    }
2582
+
2583
+    if (
2584
+        preg_match(
2585
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
+            $texte,
2587
+            $regs
2588
+        )
2589
+    ) {
2590
+        return $regs[0];
2591
+    }
2592 2592
 }
2593 2593
 
2594 2594
 /**
@@ -2616,30 +2616,30 @@  discard block
 block discarded – undo
2616 2616
  *     - Tableau de résultats, si tableau en entrée.
2617 2617
  **/
2618 2618
 function extraire_balises($texte, $tag = 'a') {
2619
-	if (is_array($texte)) {
2620
-		array_walk(
2621
-			$texte,
2622
-			function (&$a, $key, $t) {
2623
-				$a = extraire_balises($a, $t);
2624
-			},
2625
-			$tag
2626
-		);
2627
-
2628
-		return $texte;
2629
-	}
2630
-
2631
-	if (
2632
-		preg_match_all(
2633
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
-			$texte,
2635
-			$regs,
2636
-			PREG_PATTERN_ORDER
2637
-		)
2638
-	) {
2639
-		return $regs[0];
2640
-	} else {
2641
-		return [];
2642
-	}
2619
+    if (is_array($texte)) {
2620
+        array_walk(
2621
+            $texte,
2622
+            function (&$a, $key, $t) {
2623
+                $a = extraire_balises($a, $t);
2624
+            },
2625
+            $tag
2626
+        );
2627
+
2628
+        return $texte;
2629
+    }
2630
+
2631
+    if (
2632
+        preg_match_all(
2633
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
+            $texte,
2635
+            $regs,
2636
+            PREG_PATTERN_ORDER
2637
+        )
2638
+    ) {
2639
+        return $regs[0];
2640
+    } else {
2641
+        return [];
2642
+    }
2643 2643
 }
2644 2644
 
2645 2645
 /**
@@ -2668,11 +2668,11 @@  discard block
 block discarded – undo
2668 2668
  *     - `$def` si on n'a pas transmis de tableau
2669 2669
  **/
2670 2670
 function in_any($val, $vals, $def = '') {
2671
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
-		$vals = $v;
2673
-	}
2671
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
+        $vals = $v;
2673
+    }
2674 2674
 
2675
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2675
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2676 2676
 }
2677 2677
 
2678 2678
 
@@ -2693,12 +2693,12 @@  discard block
 block discarded – undo
2693 2693
  *     Résultat du calcul
2694 2694
  **/
2695 2695
 function valeur_numerique($expr) {
2696
-	$a = 0;
2697
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
-		eval("\$a = $expr;");
2699
-	}
2696
+    $a = 0;
2697
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
+        eval("\$a = $expr;");
2699
+    }
2700 2700
 
2701
-	return intval($a);
2701
+    return intval($a);
2702 2702
 }
2703 2703
 
2704 2704
 /**
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *      Retourne `$a*$b/$c`
2718 2718
  **/
2719 2719
 function regledetrois($a, $b, $c) {
2720
-	return round($a * $b / $c);
2720
+    return round($a * $b / $c);
2721 2721
 }
2722 2722
 
2723 2723
 
@@ -2741,77 +2741,77 @@  discard block
 block discarded – undo
2741 2741
  **/
2742 2742
 function form_hidden($action) {
2743 2743
 
2744
-	$contexte = [];
2745
-	include_spip('inc/urls');
2746
-	if (
2747
-		$p = urls_decoder_url($action, '')
2748
-		and reset($p)
2749
-	) {
2750
-		$fond = array_shift($p);
2751
-		if ($fond != '404') {
2752
-			$contexte = array_shift($p);
2753
-			$contexte['page'] = $fond;
2754
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2755
-		}
2756
-	}
2757
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2758
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2759
-		unset($contexte['type']);
2760
-	}
2761
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2762
-		unset($contexte['type-page']);
2763
-	}
2764
-
2765
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2766
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2767
-	$values = [];
2768
-
2769
-	// d'abord avec celles de l'url
2770
-	if (false !== ($p = strpos($action, '?'))) {
2771
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2772
-			$c = explode('=', $c, 2);
2773
-			$var = array_shift($c);
2774
-			$val = array_shift($c);
2775
-			if ($var) {
2776
-				$val = rawurldecode($val);
2777
-				$var = rawurldecode($var); // decoder les [] eventuels
2778
-				if (preg_match(',\[\]$,S', $var)) {
2779
-					$values[] = [$var, $val];
2780
-				} else {
2781
-					if (!isset($values[$var])) {
2782
-						$values[$var] = [$var, $val];
2783
-					}
2784
-				}
2785
-			}
2786
-		}
2787
-	}
2788
-
2789
-	// ensuite avec celles du contexte, sans doublonner !
2790
-	foreach ($contexte as $var => $val) {
2791
-		if (preg_match(',\[\]$,S', $var)) {
2792
-			$values[] = [$var, $val];
2793
-		} else {
2794
-			if (!isset($values[$var])) {
2795
-				$values[$var] = [$var, $val];
2796
-			}
2797
-		}
2798
-	}
2799
-
2800
-	// puis on rassemble le tout
2801
-	$hidden = [];
2802
-	foreach ($values as $value) {
2803
-		[$var, $val] = $value;
2804
-		$hidden[] = '<input name="'
2805
-			. entites_html($var)
2806
-			. '"'
2807
-			. (is_null($val)
2808
-				? ''
2809
-				: ' value="' . entites_html($val) . '"'
2810
-			)
2811
-			. ' type="hidden"' . "\n/>";
2812
-	}
2813
-
2814
-	return join('', $hidden);
2744
+    $contexte = [];
2745
+    include_spip('inc/urls');
2746
+    if (
2747
+        $p = urls_decoder_url($action, '')
2748
+        and reset($p)
2749
+    ) {
2750
+        $fond = array_shift($p);
2751
+        if ($fond != '404') {
2752
+            $contexte = array_shift($p);
2753
+            $contexte['page'] = $fond;
2754
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2755
+        }
2756
+    }
2757
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2758
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2759
+        unset($contexte['type']);
2760
+    }
2761
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2762
+        unset($contexte['type-page']);
2763
+    }
2764
+
2765
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2766
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2767
+    $values = [];
2768
+
2769
+    // d'abord avec celles de l'url
2770
+    if (false !== ($p = strpos($action, '?'))) {
2771
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2772
+            $c = explode('=', $c, 2);
2773
+            $var = array_shift($c);
2774
+            $val = array_shift($c);
2775
+            if ($var) {
2776
+                $val = rawurldecode($val);
2777
+                $var = rawurldecode($var); // decoder les [] eventuels
2778
+                if (preg_match(',\[\]$,S', $var)) {
2779
+                    $values[] = [$var, $val];
2780
+                } else {
2781
+                    if (!isset($values[$var])) {
2782
+                        $values[$var] = [$var, $val];
2783
+                    }
2784
+                }
2785
+            }
2786
+        }
2787
+    }
2788
+
2789
+    // ensuite avec celles du contexte, sans doublonner !
2790
+    foreach ($contexte as $var => $val) {
2791
+        if (preg_match(',\[\]$,S', $var)) {
2792
+            $values[] = [$var, $val];
2793
+        } else {
2794
+            if (!isset($values[$var])) {
2795
+                $values[$var] = [$var, $val];
2796
+            }
2797
+        }
2798
+    }
2799
+
2800
+    // puis on rassemble le tout
2801
+    $hidden = [];
2802
+    foreach ($values as $value) {
2803
+        [$var, $val] = $value;
2804
+        $hidden[] = '<input name="'
2805
+            . entites_html($var)
2806
+            . '"'
2807
+            . (is_null($val)
2808
+                ? ''
2809
+                : ' value="' . entites_html($val) . '"'
2810
+            )
2811
+            . ' type="hidden"' . "\n/>";
2812
+    }
2813
+
2814
+    return join('', $hidden);
2815 2815
 }
2816 2816
 
2817 2817
 
@@ -2833,7 +2833,7 @@  discard block
 block discarded – undo
2833 2833
  *    - la première valeur du tableau sinon.
2834 2834
  **/
2835 2835
 function filtre_reset($array) {
2836
-	return !is_array($array) ? null : reset($array);
2836
+    return !is_array($array) ? null : reset($array);
2837 2837
 }
2838 2838
 
2839 2839
 /**
@@ -2854,7 +2854,7 @@  discard block
 block discarded – undo
2854 2854
  *    - la dernière valeur du tableau sinon.
2855 2855
  **/
2856 2856
 function filtre_end($array) {
2857
-	return !is_array($array) ? null : end($array);
2857
+    return !is_array($array) ? null : end($array);
2858 2858
 }
2859 2859
 
2860 2860
 /**
@@ -2874,11 +2874,11 @@  discard block
 block discarded – undo
2874 2874
  *
2875 2875
  **/
2876 2876
 function filtre_push($array, $val) {
2877
-	if (!is_array($array) or !array_push($array, $val)) {
2878
-		return '';
2879
-	}
2877
+    if (!is_array($array) or !array_push($array, $val)) {
2878
+        return '';
2879
+    }
2880 2880
 
2881
-	return $array;
2881
+    return $array;
2882 2882
 }
2883 2883
 
2884 2884
 /**
@@ -2897,7 +2897,7 @@  discard block
 block discarded – undo
2897 2897
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2898 2898
  **/
2899 2899
 function filtre_find($array, $val) {
2900
-	return (is_array($array) and in_array($val, $array));
2900
+    return (is_array($array) and in_array($val, $array));
2901 2901
 }
2902 2902
 
2903 2903
 
@@ -2914,13 +2914,13 @@  discard block
 block discarded – undo
2914 2914
  *     Contenu avec urls en absolus
2915 2915
  **/
2916 2916
 function urls_absolues_css($contenu, $source) {
2917
-	$path = suivre_lien(url_absolue($source), './');
2917
+    $path = suivre_lien(url_absolue($source), './');
2918 2918
 
2919
-	return preg_replace_callback(
2920
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2921
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2922
-		$contenu
2923
-	);
2919
+    return preg_replace_callback(
2920
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2921
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2922
+        $contenu
2923
+    );
2924 2924
 }
2925 2925
 
2926 2926
 
@@ -2949,119 +2949,119 @@  discard block
 block discarded – undo
2949 2949
  *     Chemin du fichier CSS inversé
2950 2950
  **/
2951 2951
 function direction_css($css, $voulue = '') {
2952
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2953
-		return $css;
2954
-	}
2955
-	include_spip('inc/lang');
2956
-	// si on a precise le sens voulu en argument, le prendre en compte
2957
-	if ($voulue = strtolower($voulue)) {
2958
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2959
-			$voulue = lang_dir($voulue);
2960
-		}
2961
-	} else {
2962
-		$voulue = lang_dir();
2963
-	}
2964
-
2965
-	$r = count($r) > 1;
2966
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2967
-	$dir = $r ? 'rtl' : 'ltr';
2968
-	$ndir = $r ? 'ltr' : 'rtl';
2969
-
2970
-	if ($voulue == $dir) {
2971
-		return $css;
2972
-	}
2973
-
2974
-	if (
2975
-		// url absolue
2976
-		preg_match(',^https?:,i', $css)
2977
-		// ou qui contient un ?
2978
-		or (($p = strpos($css, '?')) !== false)
2979
-	) {
2980
-		$distant = true;
2981
-		$cssf = parse_url($css);
2982
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2983
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2984
-	} else {
2985
-		$distant = false;
2986
-		$cssf = $css;
2987
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2988
-		//propose (rien a faire dans ce cas)
2989
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2990
-		if (@file_exists($f)) {
2991
-			return $f;
2992
-		}
2993
-	}
2994
-
2995
-	// 2.
2996
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2997
-	$f = $dir_var
2998
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2999
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3000
-
3001
-	// la css peut etre distante (url absolue !)
3002
-	if ($distant) {
3003
-		include_spip('inc/distant');
3004
-		$res = recuperer_url($css);
3005
-		if (!$res or !$contenu = $res['page']) {
3006
-			return $css;
3007
-		}
3008
-	} else {
3009
-		if (
3010
-			(@filemtime($f) > @filemtime($css))
3011
-			and (_VAR_MODE != 'recalcul')
3012
-		) {
3013
-			return $f;
3014
-		}
3015
-		if (!lire_fichier($css, $contenu)) {
3016
-			return $css;
3017
-		}
3018
-	}
3019
-
3020
-
3021
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3022
-	include_spip('lib/csstidy/class.csstidy');
3023
-	$parser = new csstidy();
3024
-	$parser->set_cfg('optimise_shorthands', 0);
3025
-	$parser->set_cfg('reverse_left_and_right', true);
3026
-	$parser->parse($contenu);
3027
-
3028
-	$contenu = $parser->print->plain();
3029
-
3030
-
3031
-	// reperer les @import auxquels il faut propager le direction_css
3032
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3033
-	$src = [];
3034
-	$src_direction_css = [];
3035
-	$src_faux_abs = [];
3036
-	$d = dirname($css);
3037
-	foreach ($regs[1] as $k => $import_css) {
3038
-		$css_direction = direction_css("$d/$import_css", $voulue);
3039
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3040
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3041
-			$css_direction = substr($css_direction, strlen($d) + 1);
3042
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3043
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3044
-			$css_direction = substr($css_direction, strlen($dir_var));
3045
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3046
-			$css_direction = '/@@@@@@/' . $css_direction;
3047
-		}
3048
-		$src[] = $regs[0][$k];
3049
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3050
-	}
3051
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3052
-
3053
-	$contenu = urls_absolues_css($contenu, $css);
3054
-
3055
-	// virer les fausses url absolues que l'on a mis dans les import
3056
-	if (count($src_faux_abs)) {
3057
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3058
-	}
3059
-
3060
-	if (!ecrire_fichier($f, $contenu)) {
3061
-		return $css;
3062
-	}
3063
-
3064
-	return $f;
2952
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2953
+        return $css;
2954
+    }
2955
+    include_spip('inc/lang');
2956
+    // si on a precise le sens voulu en argument, le prendre en compte
2957
+    if ($voulue = strtolower($voulue)) {
2958
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2959
+            $voulue = lang_dir($voulue);
2960
+        }
2961
+    } else {
2962
+        $voulue = lang_dir();
2963
+    }
2964
+
2965
+    $r = count($r) > 1;
2966
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2967
+    $dir = $r ? 'rtl' : 'ltr';
2968
+    $ndir = $r ? 'ltr' : 'rtl';
2969
+
2970
+    if ($voulue == $dir) {
2971
+        return $css;
2972
+    }
2973
+
2974
+    if (
2975
+        // url absolue
2976
+        preg_match(',^https?:,i', $css)
2977
+        // ou qui contient un ?
2978
+        or (($p = strpos($css, '?')) !== false)
2979
+    ) {
2980
+        $distant = true;
2981
+        $cssf = parse_url($css);
2982
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2983
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2984
+    } else {
2985
+        $distant = false;
2986
+        $cssf = $css;
2987
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2988
+        //propose (rien a faire dans ce cas)
2989
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2990
+        if (@file_exists($f)) {
2991
+            return $f;
2992
+        }
2993
+    }
2994
+
2995
+    // 2.
2996
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2997
+    $f = $dir_var
2998
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2999
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3000
+
3001
+    // la css peut etre distante (url absolue !)
3002
+    if ($distant) {
3003
+        include_spip('inc/distant');
3004
+        $res = recuperer_url($css);
3005
+        if (!$res or !$contenu = $res['page']) {
3006
+            return $css;
3007
+        }
3008
+    } else {
3009
+        if (
3010
+            (@filemtime($f) > @filemtime($css))
3011
+            and (_VAR_MODE != 'recalcul')
3012
+        ) {
3013
+            return $f;
3014
+        }
3015
+        if (!lire_fichier($css, $contenu)) {
3016
+            return $css;
3017
+        }
3018
+    }
3019
+
3020
+
3021
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3022
+    include_spip('lib/csstidy/class.csstidy');
3023
+    $parser = new csstidy();
3024
+    $parser->set_cfg('optimise_shorthands', 0);
3025
+    $parser->set_cfg('reverse_left_and_right', true);
3026
+    $parser->parse($contenu);
3027
+
3028
+    $contenu = $parser->print->plain();
3029
+
3030
+
3031
+    // reperer les @import auxquels il faut propager le direction_css
3032
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3033
+    $src = [];
3034
+    $src_direction_css = [];
3035
+    $src_faux_abs = [];
3036
+    $d = dirname($css);
3037
+    foreach ($regs[1] as $k => $import_css) {
3038
+        $css_direction = direction_css("$d/$import_css", $voulue);
3039
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3040
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3041
+            $css_direction = substr($css_direction, strlen($d) + 1);
3042
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3043
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3044
+            $css_direction = substr($css_direction, strlen($dir_var));
3045
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3046
+            $css_direction = '/@@@@@@/' . $css_direction;
3047
+        }
3048
+        $src[] = $regs[0][$k];
3049
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3050
+    }
3051
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3052
+
3053
+    $contenu = urls_absolues_css($contenu, $css);
3054
+
3055
+    // virer les fausses url absolues que l'on a mis dans les import
3056
+    if (count($src_faux_abs)) {
3057
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3058
+    }
3059
+
3060
+    if (!ecrire_fichier($f, $contenu)) {
3061
+        return $css;
3062
+    }
3063
+
3064
+    return $f;
3065 3065
 }
3066 3066
 
3067 3067
 
@@ -3084,46 +3084,46 @@  discard block
 block discarded – undo
3084 3084
  *     - Chemin ou URL du fichier CSS source sinon.
3085 3085
  **/
3086 3086
 function url_absolue_css($css) {
3087
-	if (!preg_match(',\.css$,i', $css, $r)) {
3088
-		return $css;
3089
-	}
3087
+    if (!preg_match(',\.css$,i', $css, $r)) {
3088
+        return $css;
3089
+    }
3090 3090
 
3091
-	$url_absolue_css = url_absolue($css);
3091
+    $url_absolue_css = url_absolue($css);
3092 3092
 
3093
-	$f = basename($css, '.css');
3094
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3095
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3096
-		. '.css';
3093
+    $f = basename($css, '.css');
3094
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3095
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3096
+        . '.css';
3097 3097
 
3098
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3099
-		return $f;
3100
-	}
3098
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3099
+        return $f;
3100
+    }
3101 3101
 
3102
-	if ($url_absolue_css == $css) {
3103
-		if (
3104
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3105
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3106
-		) {
3107
-			include_spip('inc/distant');
3108
-			$contenu = recuperer_url($css);
3109
-			$contenu = $contenu['page'] ?? '';
3110
-			if (!$contenu) {
3111
-				return $css;
3112
-			}
3113
-		}
3114
-	} elseif (!lire_fichier($css, $contenu)) {
3115
-		return $css;
3116
-	}
3102
+    if ($url_absolue_css == $css) {
3103
+        if (
3104
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3105
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3106
+        ) {
3107
+            include_spip('inc/distant');
3108
+            $contenu = recuperer_url($css);
3109
+            $contenu = $contenu['page'] ?? '';
3110
+            if (!$contenu) {
3111
+                return $css;
3112
+            }
3113
+        }
3114
+    } elseif (!lire_fichier($css, $contenu)) {
3115
+        return $css;
3116
+    }
3117 3117
 
3118
-	// passer les url relatives a la css d'origine en url absolues
3119
-	$contenu = urls_absolues_css($contenu, $css);
3118
+    // passer les url relatives a la css d'origine en url absolues
3119
+    $contenu = urls_absolues_css($contenu, $css);
3120 3120
 
3121
-	// ecrire la css
3122
-	if (!ecrire_fichier($f, $contenu)) {
3123
-		return $css;
3124
-	}
3121
+    // ecrire la css
3122
+    if (!ecrire_fichier($f, $contenu)) {
3123
+        return $css;
3124
+    }
3125 3125
 
3126
-	return $f;
3126
+    return $f;
3127 3127
 }
3128 3128
 
3129 3129
 
@@ -3157,24 +3157,24 @@  discard block
 block discarded – undo
3157 3157
  *     Valeur trouvée ou valeur par défaut.
3158 3158
  **/
3159 3159
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3160
-	foreach (explode('/', $cle) as $k) {
3161
-		$table = (is_string($table) ? @unserialize($table) : $table);
3160
+    foreach (explode('/', $cle) as $k) {
3161
+        $table = (is_string($table) ? @unserialize($table) : $table);
3162 3162
 
3163
-		if (is_object($table)) {
3164
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3165
-		} elseif (is_array($table)) {
3166
-			if ($conserver_null) {
3167
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3168
-			} else {
3169
-				$table = ($table[$k] ?? $defaut);
3170
-			}
3171
-		} else {
3172
-			$table = $defaut;
3173
-			break;
3174
-		}
3175
-	}
3163
+        if (is_object($table)) {
3164
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3165
+        } elseif (is_array($table)) {
3166
+            if ($conserver_null) {
3167
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3168
+            } else {
3169
+                $table = ($table[$k] ?? $defaut);
3170
+            }
3171
+        } else {
3172
+            $table = $defaut;
3173
+            break;
3174
+        }
3175
+    }
3176 3176
 
3177
-	return $table;
3177
+    return $table;
3178 3178
 }
3179 3179
 
3180 3180
 /**
@@ -3207,22 +3207,22 @@  discard block
 block discarded – undo
3207 3207
  *     - string : expression trouvée.
3208 3208
  **/
3209 3209
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3210
-	if (intval($modif) and $capte == 0) {
3211
-		$capte = $modif;
3212
-		$modif = 'UimsS';
3213
-	}
3214
-	$expression = str_replace('\/', '/', $expression);
3215
-	$expression = str_replace('/', '\/', $expression);
3210
+    if (intval($modif) and $capte == 0) {
3211
+        $capte = $modif;
3212
+        $modif = 'UimsS';
3213
+    }
3214
+    $expression = str_replace('\/', '/', $expression);
3215
+    $expression = str_replace('/', '\/', $expression);
3216 3216
 
3217
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3218
-		if (isset($r[$capte])) {
3219
-			return $r[$capte];
3220
-		} else {
3221
-			return true;
3222
-		}
3223
-	}
3217
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3218
+        if (isset($r[$capte])) {
3219
+            return $r[$capte];
3220
+        } else {
3221
+            return true;
3222
+        }
3223
+    }
3224 3224
 
3225
-	return false;
3225
+    return false;
3226 3226
 }
3227 3227
 
3228 3228
 
@@ -3249,10 +3249,10 @@  discard block
 block discarded – undo
3249 3249
  *     Texte
3250 3250
  **/
3251 3251
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3252
-	$expression = str_replace('\/', '/', $expression);
3253
-	$expression = str_replace('/', '\/', $expression);
3252
+    $expression = str_replace('\/', '/', $expression);
3253
+    $expression = str_replace('/', '\/', $expression);
3254 3254
 
3255
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3255
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3256 3256
 }
3257 3257
 
3258 3258
 
@@ -3270,25 +3270,25 @@  discard block
 block discarded – undo
3270 3270
  **/
3271 3271
 function traiter_doublons_documents(&$doublons, $letexte) {
3272 3272
 
3273
-	// Verifier dans le texte & les notes (pas beau, helas)
3274
-	$t = $letexte . $GLOBALS['les_notes'];
3273
+    // Verifier dans le texte & les notes (pas beau, helas)
3274
+    $t = $letexte . $GLOBALS['les_notes'];
3275 3275
 
3276
-	if (
3277
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3278
-		and preg_match_all(
3279
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3280
-			$t,
3281
-			$matches,
3282
-			PREG_PATTERN_ORDER
3283
-		)
3284
-	) {
3285
-		if (!isset($doublons['documents'])) {
3286
-			$doublons['documents'] = '';
3287
-		}
3288
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3289
-	}
3276
+    if (
3277
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3278
+        and preg_match_all(
3279
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3280
+            $t,
3281
+            $matches,
3282
+            PREG_PATTERN_ORDER
3283
+        )
3284
+    ) {
3285
+        if (!isset($doublons['documents'])) {
3286
+            $doublons['documents'] = '';
3287
+        }
3288
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3289
+    }
3290 3290
 
3291
-	return $letexte;
3291
+    return $letexte;
3292 3292
 }
3293 3293
 
3294 3294
 /**
@@ -3302,7 +3302,7 @@  discard block
 block discarded – undo
3302 3302
  * @return string Chaîne vide
3303 3303
  **/
3304 3304
 function vide($texte) {
3305
-	return '';
3305
+    return '';
3306 3306
 }
3307 3307
 
3308 3308
 //
@@ -3331,23 +3331,23 @@  discard block
 block discarded – undo
3331 3331
  *      Code HTML résultant
3332 3332
  **/
3333 3333
 function env_to_params($env, $ignore_params = []) {
3334
-	$ignore_params = array_merge(
3335
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3336
-		$ignore_params
3337
-	);
3338
-	if (!is_array($env)) {
3339
-		$env = unserialize($env);
3340
-	}
3341
-	$texte = '';
3342
-	if ($env) {
3343
-		foreach ($env as $i => $j) {
3344
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3345
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3346
-			}
3347
-		}
3348
-	}
3349
-
3350
-	return $texte;
3334
+    $ignore_params = array_merge(
3335
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3336
+        $ignore_params
3337
+    );
3338
+    if (!is_array($env)) {
3339
+        $env = unserialize($env);
3340
+    }
3341
+    $texte = '';
3342
+    if ($env) {
3343
+        foreach ($env as $i => $j) {
3344
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3345
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3346
+            }
3347
+        }
3348
+    }
3349
+
3350
+    return $texte;
3351 3351
 }
3352 3352
 
3353 3353
 /**
@@ -3370,23 +3370,23 @@  discard block
 block discarded – undo
3370 3370
  *      Code HTML résultant
3371 3371
  **/
3372 3372
 function env_to_attributs($env, $ignore_params = []) {
3373
-	$ignore_params = array_merge(
3374
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3375
-		$ignore_params
3376
-	);
3377
-	if (!is_array($env)) {
3378
-		$env = unserialize($env);
3379
-	}
3380
-	$texte = '';
3381
-	if ($env) {
3382
-		foreach ($env as $i => $j) {
3383
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3384
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3385
-			}
3386
-		}
3387
-	}
3373
+    $ignore_params = array_merge(
3374
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3375
+        $ignore_params
3376
+    );
3377
+    if (!is_array($env)) {
3378
+        $env = unserialize($env);
3379
+    }
3380
+    $texte = '';
3381
+    if ($env) {
3382
+        foreach ($env as $i => $j) {
3383
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3384
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3385
+            }
3386
+        }
3387
+    }
3388 3388
 
3389
-	return $texte;
3389
+    return $texte;
3390 3390
 }
3391 3391
 
3392 3392
 
@@ -3404,7 +3404,7 @@  discard block
 block discarded – undo
3404 3404
  * @return string Chaînes concaténés
3405 3405
  **/
3406 3406
 function concat(...$args): string {
3407
-	return join('', $args);
3407
+    return join('', $args);
3408 3408
 }
3409 3409
 
3410 3410
 
@@ -3424,23 +3424,23 @@  discard block
 block discarded – undo
3424 3424
  *     Contenu du ou des fichiers, concaténé
3425 3425
  **/
3426 3426
 function charge_scripts($files, $script = true) {
3427
-	$flux = '';
3428
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3429
-		if (!is_string($file)) {
3430
-			continue;
3431
-		}
3432
-		if ($script) {
3433
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3434
-		}
3435
-		if ($file) {
3436
-			$path = find_in_path($file);
3437
-			if ($path) {
3438
-				$flux .= spip_file_get_contents($path);
3439
-			}
3440
-		}
3441
-	}
3442
-
3443
-	return $flux;
3427
+    $flux = '';
3428
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3429
+        if (!is_string($file)) {
3430
+            continue;
3431
+        }
3432
+        if ($script) {
3433
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3434
+        }
3435
+        if ($file) {
3436
+            $path = find_in_path($file);
3437
+            if ($path) {
3438
+                $flux .= spip_file_get_contents($path);
3439
+            }
3440
+        }
3441
+    }
3442
+
3443
+    return $flux;
3444 3444
 }
3445 3445
 
3446 3446
 /**
@@ -3451,22 +3451,22 @@  discard block
 block discarded – undo
3451 3451
  * @return string
3452 3452
  */
3453 3453
 function http_img_variante_svg_si_possible($img_file) {
3454
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3455
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3456
-	if (
3457
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3458
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3459
-		and file_exists($variante_svg_generique)
3460
-	) {
3461
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3462
-			$img_file = $variante_svg_size;
3463
-		}
3464
-		else {
3465
-			$img_file = $variante_svg_generique;
3466
-		}
3467
-	}
3454
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3455
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3456
+    if (
3457
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3458
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3459
+        and file_exists($variante_svg_generique)
3460
+    ) {
3461
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3462
+            $img_file = $variante_svg_size;
3463
+        }
3464
+        else {
3465
+            $img_file = $variante_svg_generique;
3466
+        }
3467
+    }
3468 3468
 
3469
-	return $img_file;
3469
+    return $img_file;
3470 3470
 }
3471 3471
 
3472 3472
 /**
@@ -3487,54 +3487,54 @@  discard block
 block discarded – undo
3487 3487
  */
3488 3488
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3489 3489
 
3490
-	$img_file = $img;
3491
-	if ($p = strpos($img_file, '?')) {
3492
-		$img_file = substr($img_file, 0, $p);
3493
-	}
3494
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3495
-		$img_file = chemin_image($img);
3496
-	}
3497
-	else {
3498
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3499
-			$img_file = http_img_variante_svg_si_possible($img_file);
3500
-		}
3501
-	}
3502
-	if (stripos($atts, 'width') === false) {
3503
-		// utiliser directement l'info de taille presente dans le nom
3504
-		if (
3505
-			(!isset($options['utiliser_suffixe_size'])
3506
-				or $options['utiliser_suffixe_size'] == true
3507
-			  or strpos($img_file, '-xx.svg') !== false)
3508
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3509
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3510
-		) {
3511
-			$largeur = $hauteur = intval($regs[1]);
3512
-		} else {
3513
-			$taille = taille_image($img_file);
3514
-			[$hauteur, $largeur] = $taille;
3515
-			if (!$hauteur or !$largeur) {
3516
-				return '';
3517
-			}
3518
-		}
3519
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3520
-	}
3521
-
3522
-	if (file_exists($img_file)) {
3523
-		$img_file = timestamp($img_file);
3524
-	}
3525
-	if ($alt === false) {
3526
-		$alt = '';
3527
-	}
3528
-	elseif ($alt or $alt === '') {
3529
-		$alt = " alt='" . attribut_html($alt) . "'";
3530
-	}
3531
-	else {
3532
-		$alt = " alt='" . attribut_html($title) . "'";
3533
-	}
3534
-	return "<img src='$img_file'$alt"
3535
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3536
-	. ' ' . ltrim($atts)
3537
-	. ' />';
3490
+    $img_file = $img;
3491
+    if ($p = strpos($img_file, '?')) {
3492
+        $img_file = substr($img_file, 0, $p);
3493
+    }
3494
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3495
+        $img_file = chemin_image($img);
3496
+    }
3497
+    else {
3498
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3499
+            $img_file = http_img_variante_svg_si_possible($img_file);
3500
+        }
3501
+    }
3502
+    if (stripos($atts, 'width') === false) {
3503
+        // utiliser directement l'info de taille presente dans le nom
3504
+        if (
3505
+            (!isset($options['utiliser_suffixe_size'])
3506
+                or $options['utiliser_suffixe_size'] == true
3507
+              or strpos($img_file, '-xx.svg') !== false)
3508
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3509
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3510
+        ) {
3511
+            $largeur = $hauteur = intval($regs[1]);
3512
+        } else {
3513
+            $taille = taille_image($img_file);
3514
+            [$hauteur, $largeur] = $taille;
3515
+            if (!$hauteur or !$largeur) {
3516
+                return '';
3517
+            }
3518
+        }
3519
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3520
+    }
3521
+
3522
+    if (file_exists($img_file)) {
3523
+        $img_file = timestamp($img_file);
3524
+    }
3525
+    if ($alt === false) {
3526
+        $alt = '';
3527
+    }
3528
+    elseif ($alt or $alt === '') {
3529
+        $alt = " alt='" . attribut_html($alt) . "'";
3530
+    }
3531
+    else {
3532
+        $alt = " alt='" . attribut_html($title) . "'";
3533
+    }
3534
+    return "<img src='$img_file'$alt"
3535
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3536
+    . ' ' . ltrim($atts)
3537
+    . ' />';
3538 3538
 }
3539 3539
 
3540 3540
 /**
@@ -3546,70 +3546,70 @@  discard block
 block discarded – undo
3546 3546
  * @return string
3547 3547
  */
3548 3548
 function http_style_background($img, $att = '', $size = null) {
3549
-	if ($size and is_numeric($size)) {
3550
-		$size = trim($size) . 'px';
3551
-	}
3552
-	return " style='background" .
3553
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3554
-		. ($size ? "background-size:{$size};" : '')
3555
-		. "'";
3549
+    if ($size and is_numeric($size)) {
3550
+        $size = trim($size) . 'px';
3551
+    }
3552
+    return " style='background" .
3553
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3554
+        . ($size ? "background-size:{$size};" : '')
3555
+        . "'";
3556 3556
 }
3557 3557
 
3558 3558
 
3559 3559
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3560
-	$args = [$alt_or_size, $class_or_size, $size];
3561
-	while (is_null(end($args)) and count($args)) {
3562
-		array_pop($args);
3563
-	}
3564
-	if (!count($args)) {
3565
-		return [null, null, null];
3566
-	}
3567
-	if (count($args) < 3) {
3568
-		$maybe_size = array_pop($args);
3569
-		// @2x
3570
-		// @1.5x
3571
-		// 512
3572
-		// 512x*
3573
-		// 512x300
3574
-		if (
3575
-			!strlen($maybe_size)
3576
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3577
-		) {
3578
-			$args[] = $maybe_size;
3579
-			$maybe_size = null;
3580
-		}
3581
-		while (count($args) < 2) {
3582
-			$args[] = null; // default alt or class
3583
-		}
3584
-		$args[] = $maybe_size;
3585
-	}
3586
-	return $args;
3560
+    $args = [$alt_or_size, $class_or_size, $size];
3561
+    while (is_null(end($args)) and count($args)) {
3562
+        array_pop($args);
3563
+    }
3564
+    if (!count($args)) {
3565
+        return [null, null, null];
3566
+    }
3567
+    if (count($args) < 3) {
3568
+        $maybe_size = array_pop($args);
3569
+        // @2x
3570
+        // @1.5x
3571
+        // 512
3572
+        // 512x*
3573
+        // 512x300
3574
+        if (
3575
+            !strlen($maybe_size)
3576
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3577
+        ) {
3578
+            $args[] = $maybe_size;
3579
+            $maybe_size = null;
3580
+        }
3581
+        while (count($args) < 2) {
3582
+            $args[] = null; // default alt or class
3583
+        }
3584
+        $args[] = $maybe_size;
3585
+    }
3586
+    return $args;
3587 3587
 }
3588 3588
 
3589 3589
 function helper_filtre_balise_img_svg_size($img, $size) {
3590
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3591
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3592
-		$coef = floatval(substr($size, 1, -1));
3593
-		[$h, $w] = taille_image($img);
3594
-		$height = intval(round($h / $coef));
3595
-		$width = intval(round($w / $coef));
3596
-	}
3597
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3598
-	else {
3599
-		$size = explode('x', $size, 2);
3600
-		$size = array_map('trim', $size);
3601
-		$height = $width = intval(array_shift($size));
3602
-
3603
-		if (count($size) and reset($size)) {
3604
-			$height = array_shift($size);
3605
-			if ($height === '*') {
3606
-				[$h, $w] = taille_image($img);
3607
-				$height = intval(round($h * $width / $w));
3608
-			}
3609
-		}
3610
-	}
3611
-
3612
-	return [$width, $height];
3590
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3591
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3592
+        $coef = floatval(substr($size, 1, -1));
3593
+        [$h, $w] = taille_image($img);
3594
+        $height = intval(round($h / $coef));
3595
+        $width = intval(round($w / $coef));
3596
+    }
3597
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3598
+    else {
3599
+        $size = explode('x', $size, 2);
3600
+        $size = array_map('trim', $size);
3601
+        $height = $width = intval(array_shift($size));
3602
+
3603
+        if (count($size) and reset($size)) {
3604
+            $height = array_shift($size);
3605
+            if ($height === '*') {
3606
+                [$h, $w] = taille_image($img);
3607
+                $height = intval(round($h * $width / $w));
3608
+            }
3609
+        }
3610
+    }
3611
+
3612
+    return [$width, $height];
3613 3613
 }
3614 3614
 
3615 3615
 /**
@@ -3645,43 +3645,43 @@  discard block
 block discarded – undo
3645 3645
  */
3646 3646
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3647 3647
 
3648
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3649
-
3650
-	$img = trim($img);
3651
-	if (strpos($img, '<img') === 0) {
3652
-		if (!is_null($alt)) {
3653
-			$img = inserer_attribut($img, 'alt', $alt);
3654
-		}
3655
-		if (!is_null($class)) {
3656
-			if (strlen($class)) {
3657
-				$img = inserer_attribut($img, 'class', $class);
3658
-			}
3659
-			else {
3660
-				$img = vider_attribut($img, 'class');
3661
-			}
3662
-		}
3663
-	}
3664
-	else {
3665
-		$img = http_img_pack(
3666
-			$img,
3667
-			$alt,
3668
-			$class ? " class='" . attribut_html($class) . "'" : '',
3669
-			'',
3670
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3671
-		);
3672
-		if (is_null($alt)) {
3673
-			$img = vider_attribut($img, 'alt');
3674
-		}
3675
-	}
3676
-
3677
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3678
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3679
-
3680
-		$img = inserer_attribut($img, 'width', $width);
3681
-		$img = inserer_attribut($img, 'height', $height);
3682
-	}
3683
-
3684
-	return $img;
3648
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3649
+
3650
+    $img = trim($img);
3651
+    if (strpos($img, '<img') === 0) {
3652
+        if (!is_null($alt)) {
3653
+            $img = inserer_attribut($img, 'alt', $alt);
3654
+        }
3655
+        if (!is_null($class)) {
3656
+            if (strlen($class)) {
3657
+                $img = inserer_attribut($img, 'class', $class);
3658
+            }
3659
+            else {
3660
+                $img = vider_attribut($img, 'class');
3661
+            }
3662
+        }
3663
+    }
3664
+    else {
3665
+        $img = http_img_pack(
3666
+            $img,
3667
+            $alt,
3668
+            $class ? " class='" . attribut_html($class) . "'" : '',
3669
+            '',
3670
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3671
+        );
3672
+        if (is_null($alt)) {
3673
+            $img = vider_attribut($img, 'alt');
3674
+        }
3675
+    }
3676
+
3677
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3678
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3679
+
3680
+        $img = inserer_attribut($img, 'width', $width);
3681
+        $img = inserer_attribut($img, 'height', $height);
3682
+    }
3683
+
3684
+    return $img;
3685 3685
 }
3686 3686
 
3687 3687
 
@@ -3715,80 +3715,80 @@  discard block
 block discarded – undo
3715 3715
  */
3716 3716
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3717 3717
 
3718
-	$svg = null;
3719
-	$img = trim($img);
3720
-	$img_file = $img;
3721
-	if (strpos($img, '<svg') === false) {
3722
-		if ($p = strpos($img_file, '?')) {
3723
-			$img_file = substr($img_file, 0, $p);
3724
-		}
3725
-
3726
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3727
-		// la copie locale a toutes les chances d'etre la ou de resservir
3728
-		if (tester_url_absolue($img_file)) {
3729
-			include_spip('inc/distant');
3730
-			$fichier = copie_locale($img_file);
3731
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3732
-		}
3733
-
3734
-		if (
3735
-			!$img_file
3736
-			or !file_exists($img_file)
3737
-			or !$svg = file_get_contents($img_file)
3738
-		) {
3739
-			return '';
3740
-		}
3741
-	}
3742
-
3743
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3744
-		return '';
3745
-	}
3746
-
3747
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3748
-
3749
-	$balise_svg = $match[0];
3750
-	$balise_svg_source = $balise_svg;
3751
-
3752
-	// entete XML à supprimer
3753
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3754
-
3755
-	// IE est toujours mon ami
3756
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3757
-
3758
-	// regler la classe
3759
-	if (!is_null($class)) {
3760
-		if (strlen($class)) {
3761
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3762
-		}
3763
-		else {
3764
-			$balise_svg = vider_attribut($balise_svg, 'class');
3765
-		}
3766
-	}
3767
-
3768
-	// regler le alt
3769
-	if ($alt) {
3770
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3771
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3772
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3773
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3774
-		$balise_svg .= $title;
3775
-	}
3776
-	else {
3777
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3778
-	}
3779
-
3780
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3781
-
3782
-	if (!is_null($size) and strlen($size = trim($size))) {
3783
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3784
-
3785
-		if (!function_exists('svg_redimensionner')) {
3786
-			include_spip('inc/svg');
3787
-		}
3788
-		$svg = svg_redimensionner($svg, $width, $height);
3789
-	}
3790
-
3791
-	return $svg;
3718
+    $svg = null;
3719
+    $img = trim($img);
3720
+    $img_file = $img;
3721
+    if (strpos($img, '<svg') === false) {
3722
+        if ($p = strpos($img_file, '?')) {
3723
+            $img_file = substr($img_file, 0, $p);
3724
+        }
3725
+
3726
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3727
+        // la copie locale a toutes les chances d'etre la ou de resservir
3728
+        if (tester_url_absolue($img_file)) {
3729
+            include_spip('inc/distant');
3730
+            $fichier = copie_locale($img_file);
3731
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3732
+        }
3733
+
3734
+        if (
3735
+            !$img_file
3736
+            or !file_exists($img_file)
3737
+            or !$svg = file_get_contents($img_file)
3738
+        ) {
3739
+            return '';
3740
+        }
3741
+    }
3742
+
3743
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3744
+        return '';
3745
+    }
3746
+
3747
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3748
+
3749
+    $balise_svg = $match[0];
3750
+    $balise_svg_source = $balise_svg;
3751
+
3752
+    // entete XML à supprimer
3753
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3754
+
3755
+    // IE est toujours mon ami
3756
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3757
+
3758
+    // regler la classe
3759
+    if (!is_null($class)) {
3760
+        if (strlen($class)) {
3761
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3762
+        }
3763
+        else {
3764
+            $balise_svg = vider_attribut($balise_svg, 'class');
3765
+        }
3766
+    }
3767
+
3768
+    // regler le alt
3769
+    if ($alt) {
3770
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3771
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3772
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3773
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3774
+        $balise_svg .= $title;
3775
+    }
3776
+    else {
3777
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3778
+    }
3779
+
3780
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3781
+
3782
+    if (!is_null($size) and strlen($size = trim($size))) {
3783
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3784
+
3785
+        if (!function_exists('svg_redimensionner')) {
3786
+            include_spip('inc/svg');
3787
+        }
3788
+        $svg = svg_redimensionner($svg, $width, $height);
3789
+    }
3790
+
3791
+    return $svg;
3792 3792
 }
3793 3793
 
3794 3794
 
@@ -3814,18 +3814,18 @@  discard block
 block discarded – undo
3814 3814
  *     Code HTML résultant
3815 3815
  **/
3816 3816
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3817
-	$texte = '';
3818
-	if (is_array($tableau)) {
3819
-		foreach ($tableau as $k => $v) {
3820
-			$res = recuperer_fond(
3821
-				'modeles/' . $modele,
3822
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3823
-			);
3824
-			$texte .= $res;
3825
-		}
3826
-	}
3817
+    $texte = '';
3818
+    if (is_array($tableau)) {
3819
+        foreach ($tableau as $k => $v) {
3820
+            $res = recuperer_fond(
3821
+                'modeles/' . $modele,
3822
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3823
+            );
3824
+            $texte .= $res;
3825
+        }
3826
+    }
3827 3827
 
3828
-	return $texte;
3828
+    return $texte;
3829 3829
 }
3830 3830
 
3831 3831
 
@@ -3850,37 +3850,37 @@  discard block
 block discarded – undo
3850 3850
  *         - tout : retourne toutes les informations du plugin actif
3851 3851
  **/
3852 3852
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3853
-	include_spip('inc/plugin');
3854
-	$plugin = strtoupper($plugin);
3855
-	$plugins_actifs = liste_plugin_actifs();
3856
-
3857
-	if (!$plugin) {
3858
-		return serialize(array_keys($plugins_actifs));
3859
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3860
-		return '';
3861
-	} elseif (($type_info == 'est_actif') and !$reload) {
3862
-		return $plugins_actifs[$plugin] ? 1 : 0;
3863
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3864
-		return $plugins_actifs[$plugin][$type_info];
3865
-	} else {
3866
-		$get_infos = charger_fonction('get_infos', 'plugins');
3867
-		// On prend en compte les extensions
3868
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3869
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3870
-		} else {
3871
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3872
-		}
3873
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3874
-			return '';
3875
-		}
3876
-		if ($type_info == 'tout') {
3877
-			return $infos;
3878
-		} elseif ($type_info == 'est_actif') {
3879
-			return $infos ? 1 : 0;
3880
-		} else {
3881
-			return strval($infos[$type_info]);
3882
-		}
3883
-	}
3853
+    include_spip('inc/plugin');
3854
+    $plugin = strtoupper($plugin);
3855
+    $plugins_actifs = liste_plugin_actifs();
3856
+
3857
+    if (!$plugin) {
3858
+        return serialize(array_keys($plugins_actifs));
3859
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3860
+        return '';
3861
+    } elseif (($type_info == 'est_actif') and !$reload) {
3862
+        return $plugins_actifs[$plugin] ? 1 : 0;
3863
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3864
+        return $plugins_actifs[$plugin][$type_info];
3865
+    } else {
3866
+        $get_infos = charger_fonction('get_infos', 'plugins');
3867
+        // On prend en compte les extensions
3868
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3869
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3870
+        } else {
3871
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3872
+        }
3873
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3874
+            return '';
3875
+        }
3876
+        if ($type_info == 'tout') {
3877
+            return $infos;
3878
+        } elseif ($type_info == 'est_actif') {
3879
+            return $infos ? 1 : 0;
3880
+        } else {
3881
+            return strval($infos[$type_info]);
3882
+        }
3883
+    }
3884 3884
 }
3885 3885
 
3886 3886
 
@@ -3907,9 +3907,9 @@  discard block
 block discarded – undo
3907 3907
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3908 3908
  */
3909 3909
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3910
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3910
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3911 3911
 
3912
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3912
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3913 3913
 }
3914 3914
 
3915 3915
 
@@ -3939,19 +3939,19 @@  discard block
 block discarded – undo
3939 3939
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3940 3940
  */
3941 3941
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3942
-	static $puce_statut = null;
3943
-	if (!$puce_statut) {
3944
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3945
-	}
3942
+    static $puce_statut = null;
3943
+    if (!$puce_statut) {
3944
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3945
+    }
3946 3946
 
3947
-	return $puce_statut(
3948
-		$id_objet,
3949
-		$statut,
3950
-		$id_parent,
3951
-		$objet,
3952
-		false,
3953
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3954
-	);
3947
+    return $puce_statut(
3948
+        $id_objet,
3949
+        $statut,
3950
+        $id_parent,
3951
+        $objet,
3952
+        false,
3953
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3954
+    );
3955 3955
 }
3956 3956
 
3957 3957
 
@@ -3978,98 +3978,98 @@  discard block
 block discarded – undo
3978 3978
  *   hash du contexte
3979 3979
  */
3980 3980
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3981
-	$env = null;
3982
-	if (
3983
-		is_string($c)
3984
-		and @unserialize($c) !== false
3985
-	) {
3986
-		$c = unserialize($c);
3987
-	}
3988
-
3989
-	// supprimer les parametres debut_x
3990
-	// pour que la pagination ajax ne soit pas plantee
3991
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3992
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3993
-	if (is_array($c)) {
3994
-		foreach ($c as $k => $v) {
3995
-			if (strpos($k, 'debut_') === 0) {
3996
-				unset($c[$k]);
3997
-			}
3998
-		}
3999
-	}
4000
-
4001
-	if (!function_exists('calculer_cle_action')) {
4002
-		include_spip('inc/securiser_action');
4003
-	}
4004
-
4005
-	$c = serialize($c);
4006
-	$cle = calculer_cle_action($form . $c);
4007
-	$c = "$cle:$c";
4008
-
4009
-	// on ne stocke pas les contextes dans des fichiers en cache
4010
-	// par defaut, sauf si cette configuration a été forcée
4011
-	// OU que la longueur de l’argument géneré est plus long
4012
-	// que ce qui est toléré.
4013
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4014
-	if (!$cache_contextes_ajax) {
4015
-		$env = $c;
4016
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4017
-			$env = gzdeflate($env);
4018
-		}
4019
-		$env = _xor($env);
4020
-		$env = base64_encode($env);
4021
-		$len = strlen($env);
4022
-		// Si l’url est trop longue pour le navigateur
4023
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4024
-		if ($len > $max_len) {
4025
-			$cache_contextes_ajax = true;
4026
-			spip_log(
4027
-				'Contextes AJAX forces en fichiers !'
4028
-				. ' Cela arrive lorsque la valeur du contexte'
4029
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4030
-				_LOG_AVERTISSEMENT
4031
-			);
4032
-		}
4033
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4034
-		elseif (
4035
-			$max_len = @ini_get('suhosin.get.max_value_length')
4036
-			and $max_len < $len
4037
-		) {
4038
-			$cache_contextes_ajax = true;
4039
-			spip_log('Contextes AJAX forces en fichiers !'
4040
-				. ' Cela arrive lorsque la valeur du contexte'
4041
-				. ' depasse la longueur maximale autorisee par Suhosin'
4042
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4043
-				. ' Vous devriez modifier les parametres de Suhosin'
4044
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4045
-		}
4046
-	}
4047
-
4048
-	if ($cache_contextes_ajax) {
4049
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4050
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4051
-		$md5 = md5($c);
4052
-		ecrire_fichier("$dir/c$md5", $c);
4053
-		$env = $md5;
4054
-	}
4055
-
4056
-	if ($emboite === null) {
4057
-		return $env;
4058
-	}
4059
-	if (!trim($emboite)) {
4060
-		return '';
4061
-	}
4062
-	// toujours encoder l'url source dans le bloc ajax
4063
-	$r = self();
4064
-	$r = ' data-origin="' . $r . '"';
4065
-	$class = 'ajaxbloc';
4066
-	if ($ajaxid and is_string($ajaxid)) {
4067
-		// ajaxid est normalement conforme a un nom de classe css
4068
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4069
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4070
-	}
4071
-
4072
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3981
+    $env = null;
3982
+    if (
3983
+        is_string($c)
3984
+        and @unserialize($c) !== false
3985
+    ) {
3986
+        $c = unserialize($c);
3987
+    }
3988
+
3989
+    // supprimer les parametres debut_x
3990
+    // pour que la pagination ajax ne soit pas plantee
3991
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3992
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3993
+    if (is_array($c)) {
3994
+        foreach ($c as $k => $v) {
3995
+            if (strpos($k, 'debut_') === 0) {
3996
+                unset($c[$k]);
3997
+            }
3998
+        }
3999
+    }
4000
+
4001
+    if (!function_exists('calculer_cle_action')) {
4002
+        include_spip('inc/securiser_action');
4003
+    }
4004
+
4005
+    $c = serialize($c);
4006
+    $cle = calculer_cle_action($form . $c);
4007
+    $c = "$cle:$c";
4008
+
4009
+    // on ne stocke pas les contextes dans des fichiers en cache
4010
+    // par defaut, sauf si cette configuration a été forcée
4011
+    // OU que la longueur de l’argument géneré est plus long
4012
+    // que ce qui est toléré.
4013
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4014
+    if (!$cache_contextes_ajax) {
4015
+        $env = $c;
4016
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4017
+            $env = gzdeflate($env);
4018
+        }
4019
+        $env = _xor($env);
4020
+        $env = base64_encode($env);
4021
+        $len = strlen($env);
4022
+        // Si l’url est trop longue pour le navigateur
4023
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4024
+        if ($len > $max_len) {
4025
+            $cache_contextes_ajax = true;
4026
+            spip_log(
4027
+                'Contextes AJAX forces en fichiers !'
4028
+                . ' Cela arrive lorsque la valeur du contexte'
4029
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4030
+                _LOG_AVERTISSEMENT
4031
+            );
4032
+        }
4033
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4034
+        elseif (
4035
+            $max_len = @ini_get('suhosin.get.max_value_length')
4036
+            and $max_len < $len
4037
+        ) {
4038
+            $cache_contextes_ajax = true;
4039
+            spip_log('Contextes AJAX forces en fichiers !'
4040
+                . ' Cela arrive lorsque la valeur du contexte'
4041
+                . ' depasse la longueur maximale autorisee par Suhosin'
4042
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4043
+                . ' Vous devriez modifier les parametres de Suhosin'
4044
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4045
+        }
4046
+    }
4047
+
4048
+    if ($cache_contextes_ajax) {
4049
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4050
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4051
+        $md5 = md5($c);
4052
+        ecrire_fichier("$dir/c$md5", $c);
4053
+        $env = $md5;
4054
+    }
4055
+
4056
+    if ($emboite === null) {
4057
+        return $env;
4058
+    }
4059
+    if (!trim($emboite)) {
4060
+        return '';
4061
+    }
4062
+    // toujours encoder l'url source dans le bloc ajax
4063
+    $r = self();
4064
+    $r = ' data-origin="' . $r . '"';
4065
+    $class = 'ajaxbloc';
4066
+    if ($ajaxid and is_string($ajaxid)) {
4067
+        // ajaxid est normalement conforme a un nom de classe css
4068
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4069
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4070
+    }
4071
+
4072
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4073 4073
 }
4074 4074
 
4075 4075
 /**
@@ -4089,37 +4089,37 @@  discard block
 block discarded – undo
4089 4089
  *   - false : erreur de décodage
4090 4090
  */
4091 4091
 function decoder_contexte_ajax($c, $form = '') {
4092
-	if (!function_exists('calculer_cle_action')) {
4093
-		include_spip('inc/securiser_action');
4094
-	}
4095
-	if (
4096
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4097
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4098
-		and lire_fichier("$dir/c$c", $contexte)
4099
-	) {
4100
-		$c = $contexte;
4101
-	} else {
4102
-		$c = @base64_decode($c);
4103
-		$c = _xor($c);
4104
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4105
-			$c = @gzinflate($c);
4106
-		}
4107
-	}
4108
-
4109
-	// extraire la signature en debut de contexte
4110
-	// et la verifier avant de deserializer
4111
-	// format : signature:donneesserializees
4112
-	if ($p = strpos($c, ':')) {
4113
-		$cle = substr($c, 0, $p);
4114
-		$c = substr($c, $p + 1);
4115
-
4116
-		if ($cle == calculer_cle_action($form . $c)) {
4117
-			$env = @unserialize($c);
4118
-			return $env;
4119
-		}
4120
-	}
4121
-
4122
-	return false;
4092
+    if (!function_exists('calculer_cle_action')) {
4093
+        include_spip('inc/securiser_action');
4094
+    }
4095
+    if (
4096
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4097
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4098
+        and lire_fichier("$dir/c$c", $contexte)
4099
+    ) {
4100
+        $c = $contexte;
4101
+    } else {
4102
+        $c = @base64_decode($c);
4103
+        $c = _xor($c);
4104
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4105
+            $c = @gzinflate($c);
4106
+        }
4107
+    }
4108
+
4109
+    // extraire la signature en debut de contexte
4110
+    // et la verifier avant de deserializer
4111
+    // format : signature:donneesserializees
4112
+    if ($p = strpos($c, ':')) {
4113
+        $cle = substr($c, 0, $p);
4114
+        $c = substr($c, $p + 1);
4115
+
4116
+        if ($cle == calculer_cle_action($form . $c)) {
4117
+            $env = @unserialize($c);
4118
+            return $env;
4119
+        }
4120
+    }
4121
+
4122
+    return false;
4123 4123
 }
4124 4124
 
4125 4125
 
@@ -4137,20 +4137,20 @@  discard block
 block discarded – undo
4137 4137
  *    Message décrypté ou encrypté
4138 4138
  **/
4139 4139
 function _xor($message, $key = null) {
4140
-	if (is_null($key)) {
4141
-		if (!function_exists('calculer_cle_action')) {
4142
-			include_spip('inc/securiser_action');
4143
-		}
4144
-		$key = pack('H*', calculer_cle_action('_xor'));
4145
-	}
4140
+    if (is_null($key)) {
4141
+        if (!function_exists('calculer_cle_action')) {
4142
+            include_spip('inc/securiser_action');
4143
+        }
4144
+        $key = pack('H*', calculer_cle_action('_xor'));
4145
+    }
4146 4146
 
4147
-	$keylen = strlen($key);
4148
-	$messagelen = strlen($message);
4149
-	for ($i = 0; $i < $messagelen; $i++) {
4150
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4151
-	}
4147
+    $keylen = strlen($key);
4148
+    $messagelen = strlen($message);
4149
+    for ($i = 0; $i < $messagelen; $i++) {
4150
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4151
+    }
4152 4152
 
4153
-	return $message;
4153
+    return $message;
4154 4154
 }
4155 4155
 
4156 4156
 /**
@@ -4164,7 +4164,7 @@  discard block
 block discarded – undo
4164 4164
  * @return string
4165 4165
  */
4166 4166
 function url_reponse_forum($texte) {
4167
- return $texte;
4167
+    return $texte;
4168 4168
 }
4169 4169
 
4170 4170
 /**
@@ -4178,7 +4178,7 @@  discard block
 block discarded – undo
4178 4178
  * @return string
4179 4179
  */
4180 4180
 function url_rss_forum($texte) {
4181
- return $texte;
4181
+    return $texte;
4182 4182
 }
4183 4183
 
4184 4184
 
@@ -4217,37 +4217,37 @@  discard block
 block discarded – undo
4217 4217
  *   Code HTML
4218 4218
  */
4219 4219
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4220
-	if ($on) {
4221
-		$bal = 'strong';
4222
-		$class = '';
4223
-		$att = '';
4224
-		// si $on passe la balise et optionnelement une ou ++classe
4225
-		// a.active span.selected.active etc....
4226
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4227
-			$on = explode('.', $on);
4228
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4229
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4230
-				$bal = array_shift($on);
4231
-				$class = implode(' ', $on);
4232
-				if ($bal == 'a') {
4233
-					$att = 'href="#" ';
4234
-				}
4235
-			}
4236
-		}
4237
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4238
-	} else {
4239
-		$bal = 'a';
4240
-		$att = "href='$url'"
4241
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4242
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4243
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4244
-			. $evt;
4245
-	}
4246
-	if ($libelle === null) {
4247
-		$libelle = $url;
4248
-	}
4249
-
4250
-	return "<$bal $att>$libelle</$bal>";
4220
+    if ($on) {
4221
+        $bal = 'strong';
4222
+        $class = '';
4223
+        $att = '';
4224
+        // si $on passe la balise et optionnelement une ou ++classe
4225
+        // a.active span.selected.active etc....
4226
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4227
+            $on = explode('.', $on);
4228
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4229
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4230
+                $bal = array_shift($on);
4231
+                $class = implode(' ', $on);
4232
+                if ($bal == 'a') {
4233
+                    $att = 'href="#" ';
4234
+                }
4235
+            }
4236
+        }
4237
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4238
+    } else {
4239
+        $bal = 'a';
4240
+        $att = "href='$url'"
4241
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4242
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4243
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4244
+            . $evt;
4245
+    }
4246
+    if ($libelle === null) {
4247
+        $libelle = $url;
4248
+    }
4249
+
4250
+    return "<$bal $att>$libelle</$bal>";
4251 4251
 }
4252 4252
 
4253 4253
 
@@ -4264,39 +4264,39 @@  discard block
 block discarded – undo
4264 4264
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4265 4265
  */
4266 4266
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4267
-	static $local_singulier_ou_pluriel = [];
4268
-
4269
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4270
-	if (!is_numeric($nb) or $nb == 0) {
4271
-		return '';
4272
-	}
4273
-	if (!is_array($vars)) {
4274
-		return '';
4275
-	}
4276
-
4277
-	$langue = $GLOBALS['spip_lang'];
4278
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4279
-		$local_singulier_ou_pluriel[$langue] = false;
4280
-		if (
4281
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4282
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4283
-		) {
4284
-			$local_singulier_ou_pluriel[$langue] = $f;
4285
-		}
4286
-	}
4287
-
4288
-	// si on a une surcharge on l'utilise
4289
-	if ($local_singulier_ou_pluriel[$langue]) {
4290
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4291
-	}
4292
-
4293
-	// sinon traitement par defaut
4294
-	$vars[$var] = $nb;
4295
-	if ($nb >= 2) {
4296
-		return _T($chaine_plusieurs, $vars);
4297
-	} else {
4298
-		return _T($chaine_un, $vars);
4299
-	}
4267
+    static $local_singulier_ou_pluriel = [];
4268
+
4269
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4270
+    if (!is_numeric($nb) or $nb == 0) {
4271
+        return '';
4272
+    }
4273
+    if (!is_array($vars)) {
4274
+        return '';
4275
+    }
4276
+
4277
+    $langue = $GLOBALS['spip_lang'];
4278
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4279
+        $local_singulier_ou_pluriel[$langue] = false;
4280
+        if (
4281
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4282
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4283
+        ) {
4284
+            $local_singulier_ou_pluriel[$langue] = $f;
4285
+        }
4286
+    }
4287
+
4288
+    // si on a une surcharge on l'utilise
4289
+    if ($local_singulier_ou_pluriel[$langue]) {
4290
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4291
+    }
4292
+
4293
+    // sinon traitement par defaut
4294
+    $vars[$var] = $nb;
4295
+    if ($nb >= 2) {
4296
+        return _T($chaine_plusieurs, $vars);
4297
+    } else {
4298
+        return _T($chaine_un, $vars);
4299
+    }
4300 4300
 }
4301 4301
 
4302 4302
 
@@ -4324,73 +4324,73 @@  discard block
 block discarded – undo
4324 4324
  */
4325 4325
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4326 4326
 
4327
-	$class_lien = $class_bouton = $class;
4328
-
4329
-	// Normaliser la fonction et compléter la classe en fonction
4330
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4331
-		$class_lien .= ' danger';
4332
-		$class_bouton .= ' btn_danger';
4333
-	} elseif ($fonction == 'rien.gif') {
4334
-		$fonction = '';
4335
-	} elseif ($fonction == 'delsafe') {
4336
-		$fonction = 'del';
4337
-	}
4338
-
4339
-	$fond_origine = $fond;
4340
-	// Remappage des icone : article-24.png+new => article-new-24.png
4341
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4342
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4343
-	}
4344
-
4345
-	// Ajouter le type d'objet dans la classe
4346
-	$objet_type = substr(basename($fond), 0, -4);
4347
-	$class_lien .= " $objet_type";
4348
-	$class_bouton .= " $objet_type";
4349
-
4350
-	// Texte
4351
-	$alt = attribut_html($texte);
4352
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4353
-
4354
-	// Liens : préparer les classes ajax
4355
-	$ajax = '';
4356
-	if ($type === 'lien') {
4357
-		if (strpos($class_lien, 'ajax') !== false) {
4358
-			$ajax = 'ajax';
4359
-			if (strpos($class_lien, 'preload') !== false) {
4360
-				$ajax .= ' preload';
4361
-			}
4362
-			if (strpos($class_lien, 'nocache') !== false) {
4363
-				$ajax .= ' nocache';
4364
-			}
4365
-			$ajax = " class='$ajax'";
4366
-		}
4367
-	}
4368
-
4369
-	// Repérer la taille et l'ajouter dans la classe
4370
-	$size = 24;
4371
-	if (
4372
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4373
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4374
-	) {
4375
-		$size = $match[1];
4376
-	}
4377
-	$class_lien .= " s$size";
4378
-	$class_bouton .= " s$size";
4379
-
4380
-	// Icône
4381
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4382
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4383
-
4384
-	// Markup final
4385
-	if ($type == 'lien') {
4386
-		return "<span class='icone $class_lien'>"
4387
-		. "<a href='$lien'$title$ajax$javascript>"
4388
-		. $icone
4389
-		. "<b>$texte</b>"
4390
-		. "</a></span>\n";
4391
-	} else {
4392
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4393
-	}
4327
+    $class_lien = $class_bouton = $class;
4328
+
4329
+    // Normaliser la fonction et compléter la classe en fonction
4330
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4331
+        $class_lien .= ' danger';
4332
+        $class_bouton .= ' btn_danger';
4333
+    } elseif ($fonction == 'rien.gif') {
4334
+        $fonction = '';
4335
+    } elseif ($fonction == 'delsafe') {
4336
+        $fonction = 'del';
4337
+    }
4338
+
4339
+    $fond_origine = $fond;
4340
+    // Remappage des icone : article-24.png+new => article-new-24.png
4341
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4342
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4343
+    }
4344
+
4345
+    // Ajouter le type d'objet dans la classe
4346
+    $objet_type = substr(basename($fond), 0, -4);
4347
+    $class_lien .= " $objet_type";
4348
+    $class_bouton .= " $objet_type";
4349
+
4350
+    // Texte
4351
+    $alt = attribut_html($texte);
4352
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4353
+
4354
+    // Liens : préparer les classes ajax
4355
+    $ajax = '';
4356
+    if ($type === 'lien') {
4357
+        if (strpos($class_lien, 'ajax') !== false) {
4358
+            $ajax = 'ajax';
4359
+            if (strpos($class_lien, 'preload') !== false) {
4360
+                $ajax .= ' preload';
4361
+            }
4362
+            if (strpos($class_lien, 'nocache') !== false) {
4363
+                $ajax .= ' nocache';
4364
+            }
4365
+            $ajax = " class='$ajax'";
4366
+        }
4367
+    }
4368
+
4369
+    // Repérer la taille et l'ajouter dans la classe
4370
+    $size = 24;
4371
+    if (
4372
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4373
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4374
+    ) {
4375
+        $size = $match[1];
4376
+    }
4377
+    $class_lien .= " s$size";
4378
+    $class_bouton .= " s$size";
4379
+
4380
+    // Icône
4381
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4382
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4383
+
4384
+    // Markup final
4385
+    if ($type == 'lien') {
4386
+        return "<span class='icone $class_lien'>"
4387
+        . "<a href='$lien'$title$ajax$javascript>"
4388
+        . $icone
4389
+        . "<b>$texte</b>"
4390
+        . "</a></span>\n";
4391
+    } else {
4392
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4393
+    }
4394 4394
 }
4395 4395
 
4396 4396
 /**
@@ -4414,7 +4414,7 @@  discard block
 block discarded – undo
4414 4414
  *     Code HTML du lien
4415 4415
  **/
4416 4416
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4417
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4417
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4418 4418
 }
4419 4419
 
4420 4420
 /**
@@ -4449,7 +4449,7 @@  discard block
 block discarded – undo
4449 4449
  *     Code HTML du lien
4450 4450
  **/
4451 4451
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4452
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4452
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4453 4453
 }
4454 4454
 
4455 4455
 /**
@@ -4494,7 +4494,7 @@  discard block
 block discarded – undo
4494 4494
  *     Code HTML du lien
4495 4495
  **/
4496 4496
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4497
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4497
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4498 4498
 }
4499 4499
 
4500 4500
 /**
@@ -4525,7 +4525,7 @@  discard block
 block discarded – undo
4525 4525
  *     Code HTML du lien
4526 4526
  **/
4527 4527
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4528
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4528
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4529 4529
 }
4530 4530
 
4531 4531
 /**
@@ -4556,7 +4556,7 @@  discard block
 block discarded – undo
4556 4556
  *     Code HTML du lien
4557 4557
  */
4558 4558
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4559
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4559
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4560 4560
 }
4561 4561
 
4562 4562
 
@@ -4578,7 +4578,7 @@  discard block
 block discarded – undo
4578 4578
  * @return array Liste des éléments
4579 4579
  */
4580 4580
 function filtre_explode_dist($a, $b) {
4581
- return explode($b, $a);
4581
+    return explode($b, $a);
4582 4582
 }
4583 4583
 
4584 4584
 /**
@@ -4599,7 +4599,7 @@  discard block
 block discarded – undo
4599 4599
  * @return string Texte
4600 4600
  */
4601 4601
 function filtre_implode_dist($a, $b) {
4602
- return is_array($a) ? implode($b, $a) : $a;
4602
+    return is_array($a) ? implode($b, $a) : $a;
4603 4603
 }
4604 4604
 
4605 4605
 /**
@@ -4608,24 +4608,24 @@  discard block
 block discarded – undo
4608 4608
  * @return string Code CSS
4609 4609
  */
4610 4610
 function bando_images_background() {
4611
-	include_spip('inc/bandeau');
4612
-	// recuperer tous les boutons et leurs images
4613
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4611
+    include_spip('inc/bandeau');
4612
+    // recuperer tous les boutons et leurs images
4613
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4614 4614
 
4615
-	$res = '';
4616
-	foreach ($boutons as $page => $detail) {
4617
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4618
-		if (is_array($detail->sousmenu)) {
4619
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4620
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4621
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4622
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4623
-				}
4624
-			}
4625
-		}
4626
-	}
4615
+    $res = '';
4616
+    foreach ($boutons as $page => $detail) {
4617
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4618
+        if (is_array($detail->sousmenu)) {
4619
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4620
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4621
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4622
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4623
+                }
4624
+            }
4625
+        }
4626
+    }
4627 4627
 
4628
-	return $res;
4628
+    return $res;
4629 4629
 }
4630 4630
 
4631 4631
 /**
@@ -4650,27 +4650,27 @@  discard block
 block discarded – undo
4650 4650
  */
4651 4651
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4652 4652
 
4653
-	// Classes : dispatcher `ajax` sur le formulaire
4654
-	$class_form = '';
4655
-	if (strpos($class, 'ajax') !== false) {
4656
-		$class_form = 'ajax';
4657
-		$class = str_replace('ajax', '', $class);
4658
-	}
4659
-	$class_btn = 'submit ' . trim($class);
4653
+    // Classes : dispatcher `ajax` sur le formulaire
4654
+    $class_form = '';
4655
+    if (strpos($class, 'ajax') !== false) {
4656
+        $class_form = 'ajax';
4657
+        $class = str_replace('ajax', '', $class);
4658
+    }
4659
+    $class_btn = 'submit ' . trim($class);
4660 4660
 
4661
-	if ($confirm) {
4662
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4663
-		if ($callback) {
4664
-			$callback = "$confirm?($callback):false";
4665
-		} else {
4666
-			$callback = $confirm;
4667
-		}
4668
-	}
4669
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4670
-	$title = $title ? " title='$title'" : '';
4661
+    if ($confirm) {
4662
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4663
+        if ($callback) {
4664
+            $callback = "$confirm?($callback):false";
4665
+        } else {
4666
+            $callback = $confirm;
4667
+        }
4668
+    }
4669
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4670
+    $title = $title ? " title='$title'" : '';
4671 4671
 
4672
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4673
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4672
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4673
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4674 4674
 }
4675 4675
 
4676 4676
 /**
@@ -4693,101 +4693,101 @@  discard block
 block discarded – undo
4693 4693
  * @return string
4694 4694
  */
4695 4695
 function generer_objet_info(int $id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4696
-	static $trouver_table = null;
4697
-	static $objets;
4698
-
4699
-	// On verifie qu'on a tout ce qu'il faut
4700
-	$id_objet = intval($id_objet);
4701
-	if (!($id_objet and $type_objet and $info)) {
4702
-		return '';
4703
-	}
4704
-
4705
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4706
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4707
-		return '';
4708
-	}
4709
-
4710
-	// Si on demande l'url, on retourne direct la fonction
4711
-	if ($info == 'url') {
4712
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4713
-	}
4714
-
4715
-	// Sinon on va tout chercher dans la table et on garde en memoire
4716
-	$demande_titre = ($info === 'titre');
4717
-	$demande_introduction = ($info === 'introduction');
4718
-
4719
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4720
-	if (
4721
-		!isset($objets[$type_objet][$id_objet])
4722
-		or
4723
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4724
-	) {
4725
-		if (!$trouver_table) {
4726
-			$trouver_table = charger_fonction('trouver_table', 'base');
4727
-		}
4728
-		$desc = $trouver_table(table_objet_sql($type_objet));
4729
-		if (!$desc) {
4730
-			return $objets[$type_objet] = false;
4731
-		}
4732
-
4733
-		// Si on demande le titre, on le gere en interne
4734
-		$champ_titre = '';
4735
-		if ($demande_titre) {
4736
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4737
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4738
-		}
4739
-		include_spip('base/abstract_sql');
4740
-		include_spip('base/connect_sql');
4741
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4742
-			'*' . $champ_titre,
4743
-			$desc['table_sql'],
4744
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4745
-		);
4746
-
4747
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4748
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4749
-	}
4750
-
4751
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4752
-	// ajouter la longueur au début des params supplémentaires
4753
-	if ($demande_introduction) {
4754
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4755
-		array_unshift($params, $introduction_longueur);
4756
-	}
4757
-
4758
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4759
-	if (
4760
-		$generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4761
-		// @deprecated 4.1 generer_TRUC_TYPE
4762
-		or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4763
-	) {
4764
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4765
-	}
4766
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4767
-	elseif (
4768
-		$generer = charger_fonction("generer_objet_${info}", '', true)
4769
-		// @deprecated 4.1 generer_TRUC_entite
4770
-		or $generer = charger_fonction("generer_${info}_entite", '', true)
4771
-	) {
4772
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4773
-	} // Sinon on prend directement le champ SQL tel quel
4774
-	else {
4775
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4776
-	}
4777
-
4778
-	// On va ensuite appliquer les traitements automatiques si besoin
4779
-	if (!$etoile) {
4780
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4781
-		// mais ce fonctionnement est a ameliorer !
4782
-		$info_generee = appliquer_traitement_champ(
4783
-			$info_generee,
4784
-			$info,
4785
-			table_objet($type_objet),
4786
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4787
-		);
4788
-	}
4789
-
4790
-	return $info_generee;
4696
+    static $trouver_table = null;
4697
+    static $objets;
4698
+
4699
+    // On verifie qu'on a tout ce qu'il faut
4700
+    $id_objet = intval($id_objet);
4701
+    if (!($id_objet and $type_objet and $info)) {
4702
+        return '';
4703
+    }
4704
+
4705
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4706
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4707
+        return '';
4708
+    }
4709
+
4710
+    // Si on demande l'url, on retourne direct la fonction
4711
+    if ($info == 'url') {
4712
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4713
+    }
4714
+
4715
+    // Sinon on va tout chercher dans la table et on garde en memoire
4716
+    $demande_titre = ($info === 'titre');
4717
+    $demande_introduction = ($info === 'introduction');
4718
+
4719
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4720
+    if (
4721
+        !isset($objets[$type_objet][$id_objet])
4722
+        or
4723
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4724
+    ) {
4725
+        if (!$trouver_table) {
4726
+            $trouver_table = charger_fonction('trouver_table', 'base');
4727
+        }
4728
+        $desc = $trouver_table(table_objet_sql($type_objet));
4729
+        if (!$desc) {
4730
+            return $objets[$type_objet] = false;
4731
+        }
4732
+
4733
+        // Si on demande le titre, on le gere en interne
4734
+        $champ_titre = '';
4735
+        if ($demande_titre) {
4736
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4737
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4738
+        }
4739
+        include_spip('base/abstract_sql');
4740
+        include_spip('base/connect_sql');
4741
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4742
+            '*' . $champ_titre,
4743
+            $desc['table_sql'],
4744
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4745
+        );
4746
+
4747
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4748
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4749
+    }
4750
+
4751
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4752
+    // ajouter la longueur au début des params supplémentaires
4753
+    if ($demande_introduction) {
4754
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4755
+        array_unshift($params, $introduction_longueur);
4756
+    }
4757
+
4758
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4759
+    if (
4760
+        $generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4761
+        // @deprecated 4.1 generer_TRUC_TYPE
4762
+        or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4763
+    ) {
4764
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4765
+    }
4766
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4767
+    elseif (
4768
+        $generer = charger_fonction("generer_objet_${info}", '', true)
4769
+        // @deprecated 4.1 generer_TRUC_entite
4770
+        or $generer = charger_fonction("generer_${info}_entite", '', true)
4771
+    ) {
4772
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4773
+    } // Sinon on prend directement le champ SQL tel quel
4774
+    else {
4775
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4776
+    }
4777
+
4778
+    // On va ensuite appliquer les traitements automatiques si besoin
4779
+    if (!$etoile) {
4780
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4781
+        // mais ce fonctionnement est a ameliorer !
4782
+        $info_generee = appliquer_traitement_champ(
4783
+            $info_generee,
4784
+            $info,
4785
+            table_objet($type_objet),
4786
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4787
+        );
4788
+    }
4789
+
4790
+    return $info_generee;
4791 4791
 }
4792 4792
 
4793 4793
 /**
@@ -4795,7 +4795,7 @@  discard block
 block discarded – undo
4795 4795
  * @see generer_objet_info
4796 4796
  */
4797 4797
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4798
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4798
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4799 4799
 }
4800 4800
 
4801 4801
 /**
@@ -4828,36 +4828,36 @@  discard block
 block discarded – undo
4828 4828
  */
4829 4829
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4830 4830
 
4831
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4832
-	$texte = $ligne_sql['texte'] ?? '';
4833
-	// En absence de descriptif, on se rabat sur chapo + texte
4834
-	if (isset($ligne_sql['chapo'])) {
4835
-		$chapo = $ligne_sql['chapo'];
4836
-		$texte = strlen($descriptif) ?
4837
-			'' :
4838
-			"$chapo \n\n $texte";
4839
-	}
4831
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4832
+    $texte = $ligne_sql['texte'] ?? '';
4833
+    // En absence de descriptif, on se rabat sur chapo + texte
4834
+    if (isset($ligne_sql['chapo'])) {
4835
+        $chapo = $ligne_sql['chapo'];
4836
+        $texte = strlen($descriptif) ?
4837
+            '' :
4838
+            "$chapo \n\n $texte";
4839
+    }
4840 4840
 
4841
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4842
-	if (!intval($longueur_ou_suite)) {
4843
-		$longueur = intval($introduction_longueur ?: 600);
4844
-	} else {
4845
-		$longueur = intval($longueur_ou_suite);
4846
-	}
4841
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4842
+    if (!intval($longueur_ou_suite)) {
4843
+        $longueur = intval($introduction_longueur ?: 600);
4844
+    } else {
4845
+        $longueur = intval($longueur_ou_suite);
4846
+    }
4847 4847
 
4848
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4849
-	// Ex : #INTRODUCTION{...}
4850
-	if (
4851
-		is_null($suite)
4852
-		and !intval($longueur_ou_suite)
4853
-	) {
4854
-		$suite = $longueur_ou_suite;
4855
-	}
4848
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4849
+    // Ex : #INTRODUCTION{...}
4850
+    if (
4851
+        is_null($suite)
4852
+        and !intval($longueur_ou_suite)
4853
+    ) {
4854
+        $suite = $longueur_ou_suite;
4855
+    }
4856 4856
 
4857
-	$f = chercher_filtre('introduction');
4858
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4857
+    $f = chercher_filtre('introduction');
4858
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4859 4859
 
4860
-	return $introduction;
4860
+    return $introduction;
4861 4861
 }
4862 4862
 
4863 4863
 /**
@@ -4865,7 +4865,7 @@  discard block
 block discarded – undo
4865 4865
  * @see generer_objet_introduction
4866 4866
  */
4867 4867
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4868
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4868
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4869 4869
 }
4870 4870
 
4871 4871
 /**
@@ -4879,44 +4879,44 @@  discard block
 block discarded – undo
4879 4879
  * @return string
4880 4880
  */
4881 4881
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4882
-	if (!$champ) {
4883
-		return $texte;
4884
-	}
4882
+    if (!$champ) {
4883
+        return $texte;
4884
+    }
4885 4885
 
4886
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4887
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4888
-	include_fichiers_fonctions();
4886
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4887
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4888
+    include_fichiers_fonctions();
4889 4889
 
4890
-	$champ = strtoupper($champ);
4891
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4892
-	if (!$traitements or !is_array($traitements)) {
4893
-		return $texte;
4894
-	}
4890
+    $champ = strtoupper($champ);
4891
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4892
+    if (!$traitements or !is_array($traitements)) {
4893
+        return $texte;
4894
+    }
4895 4895
 
4896
-	$traitement = '';
4897
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4898
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4899
-		$table_objet = table_objet($table_objet);
4900
-		if (isset($traitements[$table_objet])) {
4901
-			$traitement = $traitements[$table_objet];
4902
-		}
4903
-	}
4904
-	if (!$traitement and isset($traitements[0])) {
4905
-		$traitement = $traitements[0];
4906
-	}
4907
-	// (sinon prendre le premier de la liste par defaut ?)
4896
+    $traitement = '';
4897
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4898
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4899
+        $table_objet = table_objet($table_objet);
4900
+        if (isset($traitements[$table_objet])) {
4901
+            $traitement = $traitements[$table_objet];
4902
+        }
4903
+    }
4904
+    if (!$traitement and isset($traitements[0])) {
4905
+        $traitement = $traitements[0];
4906
+    }
4907
+    // (sinon prendre le premier de la liste par defaut ?)
4908 4908
 
4909
-	if (!$traitement) {
4910
-		return $texte;
4911
-	}
4909
+    if (!$traitement) {
4910
+        return $texte;
4911
+    }
4912 4912
 
4913
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4913
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4914 4914
 
4915
-	// Fournir $connect et $Pile[0] au traitement si besoin
4916
-	$Pile = [0 => $env];
4917
-	eval("\$texte = $traitement;");
4915
+    // Fournir $connect et $Pile[0] au traitement si besoin
4916
+    $Pile = [0 => $env];
4917
+    eval("\$texte = $traitement;");
4918 4918
 
4919
-	return $texte;
4919
+    return $texte;
4920 4920
 }
4921 4921
 
4922 4922
 
@@ -4930,21 +4930,21 @@  discard block
 block discarded – undo
4930 4930
  * @return string
4931 4931
  */
4932 4932
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4933
-	include_spip('inc/liens');
4934
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4935
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4936
-	// le raccourcis n'est plus valide
4937
-	$titre = typo($titre['titre']) ?? '';
4938
-	// on essaye avec generer_info_entite ?
4939
-	if (!strlen($titre) and !$connect) {
4940
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4941
-	}
4942
-	if (!strlen($titre)) {
4943
-		$titre = _T('info_sans_titre');
4944
-	}
4945
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4933
+    include_spip('inc/liens');
4934
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4935
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4936
+    // le raccourcis n'est plus valide
4937
+    $titre = typo($titre['titre']) ?? '';
4938
+    // on essaye avec generer_info_entite ?
4939
+    if (!strlen($titre) and !$connect) {
4940
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4941
+    }
4942
+    if (!strlen($titre)) {
4943
+        $titre = _T('info_sans_titre');
4944
+    }
4945
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4946 4946
 
4947
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4947
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4948 4948
 }
4949 4949
 
4950 4950
 /**
@@ -4952,7 +4952,7 @@  discard block
 block discarded – undo
4952 4952
  * @see generer_objet_lien
4953 4953
  */
4954 4954
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4955
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4955
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4956 4956
 }
4957 4957
 
4958 4958
 /**
@@ -4968,15 +4968,15 @@  discard block
 block discarded – undo
4968 4968
  * @return string
4969 4969
  */
4970 4970
 function wrap($texte, $wrap) {
4971
-	$balises = extraire_balises($wrap);
4972
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4973
-		$texte = $wrap . $texte;
4974
-		$regs = array_reverse($regs[1]);
4975
-		$wrap = '</' . implode('></', $regs) . '>';
4976
-		$texte = $texte . $wrap;
4977
-	}
4971
+    $balises = extraire_balises($wrap);
4972
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4973
+        $texte = $wrap . $texte;
4974
+        $regs = array_reverse($regs[1]);
4975
+        $wrap = '</' . implode('></', $regs) . '>';
4976
+        $texte = $texte . $wrap;
4977
+    }
4978 4978
 
4979
-	return $texte;
4979
+    return $texte;
4980 4980
 }
4981 4981
 
4982 4982
 
@@ -4996,44 +4996,44 @@  discard block
 block discarded – undo
4996 4996
  * @return array|mixed|string
4997 4997
  */
4998 4998
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4999
-	if (is_string($u)) {
5000
-		$u = typo($u);
4999
+    if (is_string($u)) {
5000
+        $u = typo($u);
5001 5001
 
5002
-		return $u;
5003
-	}
5002
+        return $u;
5003
+    }
5004 5004
 
5005
-	// caster $u en array si besoin
5006
-	if (is_object($u)) {
5007
-		$u = (array)$u;
5008
-	}
5005
+    // caster $u en array si besoin
5006
+    if (is_object($u)) {
5007
+        $u = (array)$u;
5008
+    }
5009 5009
 
5010
-	if (is_array($u)) {
5011
-		$out = '';
5012
-		// toutes les cles sont numeriques ?
5013
-		// et aucun enfant n'est un tableau
5014
-		// liste simple separee par des virgules
5015
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5016
-		$array_values = array_map('is_array', $u);
5017
-		$object_values = array_map('is_object', $u);
5018
-		if (
5019
-			array_sum($numeric_keys) == count($numeric_keys)
5020
-			and !array_sum($array_values)
5021
-			and !array_sum($object_values)
5022
-		) {
5023
-			return join(', ', array_map('filtre_print_dist', $u));
5024
-		}
5010
+    if (is_array($u)) {
5011
+        $out = '';
5012
+        // toutes les cles sont numeriques ?
5013
+        // et aucun enfant n'est un tableau
5014
+        // liste simple separee par des virgules
5015
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5016
+        $array_values = array_map('is_array', $u);
5017
+        $object_values = array_map('is_object', $u);
5018
+        if (
5019
+            array_sum($numeric_keys) == count($numeric_keys)
5020
+            and !array_sum($array_values)
5021
+            and !array_sum($object_values)
5022
+        ) {
5023
+            return join(', ', array_map('filtre_print_dist', $u));
5024
+        }
5025 5025
 
5026
-		// sinon on passe a la ligne et on indente
5027
-		$i_str = str_pad('', $indent, ' ');
5028
-		foreach ($u as $k => $v) {
5029
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5030
-		}
5026
+        // sinon on passe a la ligne et on indente
5027
+        $i_str = str_pad('', $indent, ' ');
5028
+        foreach ($u as $k => $v) {
5029
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5030
+        }
5031 5031
 
5032
-		return $out;
5033
-	}
5032
+        return $out;
5033
+    }
5034 5034
 
5035
-	// on sait pas quoi faire...
5036
-	return $u;
5035
+    // on sait pas quoi faire...
5036
+    return $u;
5037 5037
 }
5038 5038
 
5039 5039
 
@@ -5046,10 +5046,10 @@  discard block
 block discarded – undo
5046 5046
  * @return string|array
5047 5047
  */
5048 5048
 function objet_info($objet, $info) {
5049
-	$table = table_objet_sql($objet);
5050
-	$infos = lister_tables_objets_sql($table);
5049
+    $table = table_objet_sql($objet);
5050
+    $infos = lister_tables_objets_sql($table);
5051 5051
 
5052
-	return ($infos[$info] ?? '');
5052
+    return ($infos[$info] ?? '');
5053 5053
 }
5054 5054
 
5055 5055
 /**
@@ -5064,11 +5064,11 @@  discard block
 block discarded – undo
5064 5064
  *     Texte traduit du comptage, tel que '3 articles'
5065 5065
  */
5066 5066
 function objet_afficher_nb($nb, $objet) {
5067
-	if (!$nb) {
5068
-		return _T(objet_info($objet, 'info_aucun_objet'));
5069
-	} else {
5070
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5071
-	}
5067
+    if (!$nb) {
5068
+        return _T(objet_info($objet, 'info_aucun_objet'));
5069
+    } else {
5070
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5071
+    }
5072 5072
 }
5073 5073
 
5074 5074
 /**
@@ -5080,11 +5080,11 @@  discard block
 block discarded – undo
5080 5080
  * @return string
5081 5081
  */
5082 5082
 function objet_icone($objet, $taille = 24, $class = '') {
5083
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5084
-	$icone = chemin_image($icone);
5085
-	$balise_img = charger_filtre('balise_img');
5083
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5084
+    $icone = chemin_image($icone);
5085
+    $balise_img = charger_filtre('balise_img');
5086 5086
 
5087
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5087
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5088 5088
 }
5089 5089
 
5090 5090
 /**
@@ -5105,12 +5105,12 @@  discard block
 block discarded – undo
5105 5105
  * @return string
5106 5106
  */
5107 5107
 function objet_T($objet, $chaine, $args = [], $options = []) {
5108
-	$chaine = explode(':', $chaine);
5109
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5110
-		return $t;
5111
-	}
5112
-	$chaine = implode(':', $chaine);
5113
-	return _T($chaine, $args, $options);
5108
+    $chaine = explode(':', $chaine);
5109
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5110
+        return $t;
5111
+    }
5112
+    $chaine = implode(':', $chaine);
5113
+    return _T($chaine, $args, $options);
5114 5114
 }
5115 5115
 
5116 5116
 /**
@@ -5124,18 +5124,18 @@  discard block
 block discarded – undo
5124 5124
  * @return string      Code HTML
5125 5125
  */
5126 5126
 function insert_head_css_conditionnel($flux) {
5127
-	if (
5128
-		strpos($flux, '<!-- insert_head_css -->') === false
5129
-		and $p = strpos($flux, '<!-- insert_head -->')
5130
-	) {
5131
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5132
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5133
-			$p = $p1;
5134
-		}
5135
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5136
-	}
5127
+    if (
5128
+        strpos($flux, '<!-- insert_head_css -->') === false
5129
+        and $p = strpos($flux, '<!-- insert_head -->')
5130
+    ) {
5131
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5132
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5133
+            $p = $p1;
5134
+        }
5135
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5136
+    }
5137 5137
 
5138
-	return $flux;
5138
+    return $flux;
5139 5139
 }
5140 5140
 
5141 5141
 /**
@@ -5158,72 +5158,72 @@  discard block
 block discarded – undo
5158 5158
  * @return string
5159 5159
  */
5160 5160
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5161
-	if (isset($contexte['format'])) {
5162
-		$extension = $contexte['format'];
5163
-		unset($contexte['format']);
5164
-	} else {
5165
-		$extension = 'html';
5166
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5167
-			$extension = $m[1];
5168
-		}
5169
-	}
5170
-	// recuperer le contenu produit par le squelette
5171
-	$options['raw'] = true;
5172
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5173
-
5174
-	// calculer le nom de la css
5175
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5176
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5177
-	$contexte_implicite = calculer_contexte_implicite();
5178
-
5179
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5180
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5181
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5182
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5183
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5184
-	}
5185
-	else {
5186
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5187
-		ksort($contexte);
5188
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5189
-	}
5190
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5191
-
5192
-	// mettre a jour le fichier si il n'existe pas
5193
-	// ou trop ancien
5194
-	// le dernier fichier produit est toujours suffixe par .last
5195
-	// et recopie sur le fichier cible uniquement si il change
5196
-	if (
5197
-		!file_exists($filename)
5198
-		or !file_exists($filename . '.last')
5199
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5200
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5201
-	) {
5202
-		$contenu = $cache['texte'];
5203
-		// passer les urls en absolu si c'est une css
5204
-		if ($extension == 'css') {
5205
-			$contenu = urls_absolues_css(
5206
-				$contenu,
5207
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5208
-			);
5209
-		}
5210
-
5211
-		$comment = '';
5212
-		// ne pas insérer de commentaire sur certains formats
5213
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5214
-			$comment = "/* #PRODUIRE{fond=$fond";
5215
-			foreach ($contexte as $k => $v) {
5216
-				$comment .= ",$k=$v";
5217
-			}
5218
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5219
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5220
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5221
-		}
5222
-		// et ecrire le fichier si il change
5223
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5224
-	}
5225
-
5226
-	return timestamp($filename);
5161
+    if (isset($contexte['format'])) {
5162
+        $extension = $contexte['format'];
5163
+        unset($contexte['format']);
5164
+    } else {
5165
+        $extension = 'html';
5166
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5167
+            $extension = $m[1];
5168
+        }
5169
+    }
5170
+    // recuperer le contenu produit par le squelette
5171
+    $options['raw'] = true;
5172
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5173
+
5174
+    // calculer le nom de la css
5175
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5176
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5177
+    $contexte_implicite = calculer_contexte_implicite();
5178
+
5179
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5180
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5181
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5182
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5183
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5184
+    }
5185
+    else {
5186
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5187
+        ksort($contexte);
5188
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5189
+    }
5190
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5191
+
5192
+    // mettre a jour le fichier si il n'existe pas
5193
+    // ou trop ancien
5194
+    // le dernier fichier produit est toujours suffixe par .last
5195
+    // et recopie sur le fichier cible uniquement si il change
5196
+    if (
5197
+        !file_exists($filename)
5198
+        or !file_exists($filename . '.last')
5199
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5200
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5201
+    ) {
5202
+        $contenu = $cache['texte'];
5203
+        // passer les urls en absolu si c'est une css
5204
+        if ($extension == 'css') {
5205
+            $contenu = urls_absolues_css(
5206
+                $contenu,
5207
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5208
+            );
5209
+        }
5210
+
5211
+        $comment = '';
5212
+        // ne pas insérer de commentaire sur certains formats
5213
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5214
+            $comment = "/* #PRODUIRE{fond=$fond";
5215
+            foreach ($contexte as $k => $v) {
5216
+                $comment .= ",$k=$v";
5217
+            }
5218
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5219
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5220
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5221
+        }
5222
+        // et ecrire le fichier si il change
5223
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5224
+    }
5225
+
5226
+    return timestamp($filename);
5227 5227
 }
5228 5228
 
5229 5229
 /**
@@ -5236,15 +5236,15 @@  discard block
 block discarded – undo
5236 5236
  *    $fichier auquel on a ajouté le timestamp
5237 5237
  */
5238 5238
 function timestamp($fichier) {
5239
-	if (
5240
-		!$fichier
5241
-		or !file_exists($fichier)
5242
-		or !$m = filemtime($fichier)
5243
-	) {
5244
-		return $fichier;
5245
-	}
5239
+    if (
5240
+        !$fichier
5241
+        or !file_exists($fichier)
5242
+        or !$m = filemtime($fichier)
5243
+    ) {
5244
+        return $fichier;
5245
+    }
5246 5246
 
5247
-	return "$fichier?$m";
5247
+    return "$fichier?$m";
5248 5248
 }
5249 5249
 
5250 5250
 /**
@@ -5254,11 +5254,11 @@  discard block
 block discarded – undo
5254 5254
  * @return string
5255 5255
  */
5256 5256
 function supprimer_timestamp($url) {
5257
-	if (strpos($url, '?') === false) {
5258
-		return $url;
5259
-	}
5257
+    if (strpos($url, '?') === false) {
5258
+        return $url;
5259
+    }
5260 5260
 
5261
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5261
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5262 5262
 }
5263 5263
 
5264 5264
 /**
@@ -5273,9 +5273,9 @@  discard block
 block discarded – undo
5273 5273
  * @return string
5274 5274
  */
5275 5275
 function filtre_nettoyer_titre_email_dist($titre) {
5276
-	include_spip('inc/envoyer_mail');
5276
+    include_spip('inc/envoyer_mail');
5277 5277
 
5278
-	return nettoyer_titre_email($titre);
5278
+    return nettoyer_titre_email($titre);
5279 5279
 }
5280 5280
 
5281 5281
 /**
@@ -5297,27 +5297,27 @@  discard block
 block discarded – undo
5297 5297
  * @return string
5298 5298
  */
5299 5299
 function filtre_chercher_rubrique_dist(
5300
-	$titre,
5301
-	$id_objet,
5302
-	$id_parent,
5303
-	$objet,
5304
-	$id_secteur,
5305
-	$restreint,
5306
-	$actionable = false,
5307
-	$retour_sans_cadre = false
5300
+    $titre,
5301
+    $id_objet,
5302
+    $id_parent,
5303
+    $objet,
5304
+    $id_secteur,
5305
+    $restreint,
5306
+    $actionable = false,
5307
+    $retour_sans_cadre = false
5308 5308
 ) {
5309
-	include_spip('inc/filtres_ecrire');
5309
+    include_spip('inc/filtres_ecrire');
5310 5310
 
5311
-	return chercher_rubrique(
5312
-		$titre,
5313
-		$id_objet,
5314
-		$id_parent,
5315
-		$objet,
5316
-		$id_secteur,
5317
-		$restreint,
5318
-		$actionable,
5319
-		$retour_sans_cadre
5320
-	);
5311
+    return chercher_rubrique(
5312
+        $titre,
5313
+        $id_objet,
5314
+        $id_parent,
5315
+        $objet,
5316
+        $id_secteur,
5317
+        $restreint,
5318
+        $actionable,
5319
+        $retour_sans_cadre
5320
+    );
5321 5321
 }
5322 5322
 
5323 5323
 /**
@@ -5346,56 +5346,56 @@  discard block
 block discarded – undo
5346 5346
  *     Chaîne vide si l'accès est autorisé
5347 5347
  */
5348 5348
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5349
-	if ($ok) {
5350
-		return '';
5351
-	}
5352
-
5353
-	// Vider tous les tampons
5354
-	$level = @ob_get_level();
5355
-	while ($level--) {
5356
-		@ob_end_clean();
5357
-	}
5358
-
5359
-	include_spip('inc/headers');
5360
-
5361
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5362
-	if ($url) {
5363
-		redirige_par_entete($url, '', $statut);
5364
-	}
5365
-
5366
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5367
-	if (!is_numeric($statut) and is_null($message)) {
5368
-		$message = $statut;
5369
-		$statut = 0;
5370
-	}
5371
-	if (!$message) {
5372
-		$message = '';
5373
-	}
5374
-	$statut = intval($statut);
5375
-
5376
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5377
-	if (test_espace_prive()) {
5378
-		if (!$statut or !in_array($statut, [404, 403])) {
5379
-			$statut = 403;
5380
-		}
5381
-		http_response_code(403);
5382
-		$echec = charger_fonction('403', 'exec');
5383
-		$echec($message);
5384
-	} else {
5385
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5386
-		if (!$statut) {
5387
-			$statut = 404;
5388
-		}
5389
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5390
-		http_response_code($statut);
5391
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5392
-		if ($statut >= 400) {
5393
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5394
-		}
5395
-	}
5396
-
5397
-
5398
-	exit;
5349
+    if ($ok) {
5350
+        return '';
5351
+    }
5352
+
5353
+    // Vider tous les tampons
5354
+    $level = @ob_get_level();
5355
+    while ($level--) {
5356
+        @ob_end_clean();
5357
+    }
5358
+
5359
+    include_spip('inc/headers');
5360
+
5361
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5362
+    if ($url) {
5363
+        redirige_par_entete($url, '', $statut);
5364
+    }
5365
+
5366
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5367
+    if (!is_numeric($statut) and is_null($message)) {
5368
+        $message = $statut;
5369
+        $statut = 0;
5370
+    }
5371
+    if (!$message) {
5372
+        $message = '';
5373
+    }
5374
+    $statut = intval($statut);
5375
+
5376
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5377
+    if (test_espace_prive()) {
5378
+        if (!$statut or !in_array($statut, [404, 403])) {
5379
+            $statut = 403;
5380
+        }
5381
+        http_response_code(403);
5382
+        $echec = charger_fonction('403', 'exec');
5383
+        $echec($message);
5384
+    } else {
5385
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5386
+        if (!$statut) {
5387
+            $statut = 404;
5388
+        }
5389
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5390
+        http_response_code($statut);
5391
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5392
+        if ($statut >= 400) {
5393
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5394
+        }
5395
+    }
5396
+
5397
+
5398
+    exit;
5399 5399
 }
5400 5400
 
5401 5401
 /**
@@ -5406,11 +5406,11 @@  discard block
 block discarded – undo
5406 5406
  * @return string
5407 5407
  */
5408 5408
 function filtre_compacte_dist($source, $format = null) {
5409
-	if (function_exists('compacte')) {
5410
-		return compacte($source, $format);
5411
-	}
5409
+    if (function_exists('compacte')) {
5410
+        return compacte($source, $format);
5411
+    }
5412 5412
 
5413
-	return $source;
5413
+    return $source;
5414 5414
 }
5415 5415
 
5416 5416
 
@@ -5422,31 +5422,31 @@  discard block
 block discarded – undo
5422 5422
  * @return string
5423 5423
  */
5424 5424
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5425
-	$l = strlen($passe);
5426
-
5427
-	if ($l <= 8 or !$afficher_partiellement) {
5428
-		if (!$l) {
5429
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5430
-		}
5431
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5432
-	}
5433
-
5434
-	if (is_null($portion_pourcent)) {
5435
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5436
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5437
-		}
5438
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5439
-	}
5440
-	if ($portion_pourcent >= 100) {
5441
-		return $passe;
5442
-	}
5443
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5444
-	$e = max($e, 0);
5445
-	$mid = str_pad('', $l - 2 * $e, '*');
5446
-	if ($e > 0 and strlen($mid) > 8) {
5447
-		$mid = '***...***';
5448
-	}
5449
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5425
+    $l = strlen($passe);
5426
+
5427
+    if ($l <= 8 or !$afficher_partiellement) {
5428
+        if (!$l) {
5429
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5430
+        }
5431
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5432
+    }
5433
+
5434
+    if (is_null($portion_pourcent)) {
5435
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5436
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5437
+        }
5438
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5439
+    }
5440
+    if ($portion_pourcent >= 100) {
5441
+        return $passe;
5442
+    }
5443
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5444
+    $e = max($e, 0);
5445
+    $mid = str_pad('', $l - 2 * $e, '*');
5446
+    if ($e > 0 and strlen($mid) > 8) {
5447
+        $mid = '***...***';
5448
+    }
5449
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5450 5450
 }
5451 5451
 
5452 5452
 
@@ -5467,64 +5467,64 @@  discard block
 block discarded – undo
5467 5467
  */
5468 5468
 function identifiant_slug($texte, $type = '', $options = []) {
5469 5469
 
5470
-	$original = $texte;
5471
-	$separateur = ($options['separateur'] ?? '_');
5472
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5473
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5470
+    $original = $texte;
5471
+    $separateur = ($options['separateur'] ?? '_');
5472
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5473
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5474 5474
 
5475
-	if (!function_exists('translitteration')) {
5476
-		include_spip('inc/charsets');
5477
-	}
5475
+    if (!function_exists('translitteration')) {
5476
+        include_spip('inc/charsets');
5477
+    }
5478 5478
 
5479
-	// pas de balise html
5480
-	if (strpos($texte, '<') !== false) {
5481
-		$texte = strip_tags($texte);
5482
-	}
5483
-	if (strpos($texte, '&') !== false) {
5484
-		$texte = unicode2charset($texte);
5485
-	}
5486
-	// On enlève les espaces indésirables
5487
-	$texte = trim($texte);
5479
+    // pas de balise html
5480
+    if (strpos($texte, '<') !== false) {
5481
+        $texte = strip_tags($texte);
5482
+    }
5483
+    if (strpos($texte, '&') !== false) {
5484
+        $texte = unicode2charset($texte);
5485
+    }
5486
+    // On enlève les espaces indésirables
5487
+    $texte = trim($texte);
5488 5488
 
5489
-	// On enlève les accents et cie
5490
-	$texte = translitteration($texte);
5489
+    // On enlève les accents et cie
5490
+    $texte = translitteration($texte);
5491 5491
 
5492
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5493
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5492
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5493
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5494 5494
 
5495
-	// nettoyer les doubles occurences du separateur si besoin
5496
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5497
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5498
-	}
5495
+    // nettoyer les doubles occurences du separateur si besoin
5496
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5497
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5498
+    }
5499 5499
 
5500
-	// pas de separateur au debut ni a la fin
5501
-	$texte = trim($texte, $separateur);
5500
+    // pas de separateur au debut ni a la fin
5501
+    $texte = trim($texte, $separateur);
5502 5502
 
5503
-	// en minuscules
5504
-	$texte = strtolower($texte);
5503
+    // en minuscules
5504
+    $texte = strtolower($texte);
5505 5505
 
5506
-	switch ($type) {
5507
-		case 'class':
5508
-		case 'id':
5509
-		case 'anchor':
5510
-			if (preg_match(',^\d,', $texte)) {
5511
-				$texte = substr($type, 0, 1) . $texte;
5512
-			}
5513
-	}
5506
+    switch ($type) {
5507
+        case 'class':
5508
+        case 'id':
5509
+        case 'anchor':
5510
+            if (preg_match(',^\d,', $texte)) {
5511
+                $texte = substr($type, 0, 1) . $texte;
5512
+            }
5513
+    }
5514 5514
 
5515
-	if (strlen($texte) > $longueur_maxi) {
5516
-		$texte = substr($texte, 0, $longueur_maxi);
5517
-	}
5515
+    if (strlen($texte) > $longueur_maxi) {
5516
+        $texte = substr($texte, 0, $longueur_maxi);
5517
+    }
5518 5518
 
5519
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5520
-		if (preg_match(',^\d,', $texte)) {
5521
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5522
-		}
5523
-		$texte .= $separateur . md5($original);
5524
-		$texte = substr($texte, 0, $longueur_mini);
5525
-	}
5519
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5520
+        if (preg_match(',^\d,', $texte)) {
5521
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5522
+        }
5523
+        $texte .= $separateur . md5($original);
5524
+        $texte = substr($texte, 0, $longueur_mini);
5525
+    }
5526 5526
 
5527
-	return $texte;
5527
+    return $texte;
5528 5528
 }
5529 5529
 
5530 5530
 
@@ -5545,11 +5545,11 @@  discard block
 block discarded – undo
5545 5545
  * @exemple `<:info_maximum|label_nettoyer:>`
5546 5546
  */
5547 5547
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5548
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5549
-	if ($ucfirst) {
5550
-		$label = spip_ucfirst($label);
5551
-	}
5552
-	return $label;
5548
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5549
+    if ($ucfirst) {
5550
+        $label = spip_ucfirst($label);
5551
+    }
5552
+    return $label;
5553 5553
 }
5554 5554
 
5555 5555
 /**
@@ -5562,8 +5562,8 @@  discard block
 block discarded – undo
5562 5562
  * @exemple `<:info_maximum|label_ponctuer:>`
5563 5563
  */
5564 5564
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5565
-	$label = label_nettoyer($text, $ucfirst);
5566
-	return _T('label_ponctuer', ['label' => $label]);
5565
+    $label = label_nettoyer($text, $ucfirst);
5566
+    return _T('label_ponctuer', ['label' => $label]);
5567 5567
 }
5568 5568
 
5569 5569
 
@@ -5576,19 +5576,19 @@  discard block
 block discarded – undo
5576 5576
  * @return array
5577 5577
  */
5578 5578
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5579
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5580
-		return [];
5581
-	}
5579
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5580
+        return [];
5581
+    }
5582 5582
 
5583
-	// compatibilite signature inversee
5584
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5585
-		[$objet, $id_objet] = [$id_objet, $objet];
5586
-	}
5583
+    // compatibilite signature inversee
5584
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5585
+        [$objet, $id_objet] = [$id_objet, $objet];
5586
+    }
5587 5587
 
5588
-	if (!function_exists($fonction)) {
5589
-		include_spip('base/objets');
5590
-	}
5591
-	return $fonction($objet, $id_objet);
5588
+    if (!function_exists($fonction)) {
5589
+        include_spip('base/objets');
5590
+    }
5591
+    return $fonction($objet, $id_objet);
5592 5592
 }
5593 5593
 
5594 5594
 
@@ -5603,7 +5603,7 @@  discard block
 block discarded – undo
5603 5603
  * @return array
5604 5604
  */
5605 5605
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5606
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5606
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5607 5607
 }
5608 5608
 
5609 5609
 /**
@@ -5617,7 +5617,7 @@  discard block
 block discarded – undo
5617 5617
  * @return array
5618 5618
  */
5619 5619
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5620
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5620
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5621 5621
 }
5622 5622
 
5623 5623
 /**
@@ -5631,7 +5631,7 @@  discard block
 block discarded – undo
5631 5631
  * @return array
5632 5632
  */
5633 5633
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5634
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5634
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5635 5635
 }
5636 5636
 
5637 5637
 /**
@@ -5645,5 +5645,5 @@  discard block
 block discarded – undo
5645 5645
  * @return array
5646 5646
  */
5647 5647
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5648
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5648
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5649 5649
 }
Please login to merge, or discard this patch.
ecrire/inc/lien.php 1 patch
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('base/abstract_sql');
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 //
24 24
 
25 25
 function inc_lien_dist(
26
-	$lien,
27
-	$texte = '',
28
-	$class = '',
29
-	$title = '',
30
-	$hlang = '',
31
-	$rel = '',
32
-	string $connect = '',
33
-	$env = []
26
+    $lien,
27
+    $texte = '',
28
+    $class = '',
29
+    $title = '',
30
+    $hlang = '',
31
+    $rel = '',
32
+    string $connect = '',
33
+    $env = []
34 34
 ) {
35
-	return $lien;
35
+    return $lien;
36 36
 }
37 37
 
38 38
 // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip
@@ -43,28 +43,28 @@  discard block
 block discarded – undo
43 43
 
44 44
 function expanser_liens($t, string $connect = '', $env = []) {
45 45
 
46
-	$t = pipeline('pre_liens', $t);
46
+    $t = pipeline('pre_liens', $t);
47 47
 
48
-	// on passe a traiter_modeles la liste des liens reperes pour lui permettre
49
-	// de remettre le texte d'origine dans les parametres du modele
50
-	$t = traiter_modeles($t, false, false, $connect);
48
+    // on passe a traiter_modeles la liste des liens reperes pour lui permettre
49
+    // de remettre le texte d'origine dans les parametres du modele
50
+    $t = traiter_modeles($t, false, false, $connect);
51 51
 
52
-	return $t;
52
+    return $t;
53 53
 }
54 54
 
55 55
 // Meme analyse mais pour eliminer les liens
56 56
 // et ne laisser que leur titre, a expliciter si ce n'est fait
57 57
 function nettoyer_raccourcis_typo($texte, string $connect = '') {
58
-	return $texte;
58
+    return $texte;
59 59
 }
60 60
 
61 61
 // Repere dans la partie texte d'un raccourci [texte->...]
62 62
 // la langue et la bulle eventuelles
63 63
 function traiter_raccourci_lien_atts($texte) {
64
-	$bulle = '';
65
-	$hlang = '';
64
+    $bulle = '';
65
+    $hlang = '';
66 66
 
67
-	return [trim($texte), $bulle, $hlang];
67
+    return [trim($texte), $bulle, $hlang];
68 68
 }
69 69
 
70 70
 define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/');
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
  * @return string
81 81
  */
82 82
 function virtuel_redirige($virtuel, $url = false) {
83
-	return $virtuel;
83
+    return $virtuel;
84 84
 }
85 85
 
86 86
 // Cherche un lien du type [->raccourci 123]
@@ -93,121 +93,121 @@  discard block
 block discarded – undo
93 93
 // 'url':   seulement U  (i.e. generer_url_RACCOURCI)
94 94
 
95 95
 function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
96
-	$r = traiter_lien_implicite($ref, $texte, $pour, $connect);
96
+    $r = traiter_lien_implicite($ref, $texte, $pour, $connect);
97 97
 
98
-	return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
98
+    return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
99 99
 }
100 100
 
101 101
 define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
102 102
 
103 103
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
104
-	if (preg_match(_EXTRAIRE_LIEN, $ref)) {
105
-		return ($pour != 'tout') ? '' : ['', '', '', ''];
106
-	}
107
-
108
-	$lien = entites_html(trim($ref));
109
-
110
-	// Liens explicites
111
-	if (!$texte) {
112
-		$texte = str_replace('"', '', $lien);
113
-		// evite l'affichage de trops longues urls.
114
-		$lien_court = charger_fonction('lien_court', 'inc');
115
-		$texte = $lien_court($texte);
116
-		if ($echappe_typo) {
117
-			$texte = '<html>' . quote_amp($texte) . '</html>';
118
-		}
119
-	}
120
-
121
-	// petites corrections d'URL
122
-	if (preg_match('/^www\.[^@]+$/S', $lien)) {
123
-		$lien = 'http://' . $lien;
124
-	} else {
125
-		if (strpos($lien, '@') && email_valide($lien)) {
126
-			if (!$texte) {
127
-				$texte = $lien;
128
-			}
129
-			$lien = 'mailto:' . $lien;
130
-		}
131
-	}
132
-
133
-	if ($pour == 'url') {
134
-		return $lien;
135
-	}
136
-
137
-	if ($pour == 'titre') {
138
-		return $texte;
139
-	}
140
-
141
-	return ['url' => $lien, 'titre' => $texte];
104
+    if (preg_match(_EXTRAIRE_LIEN, $ref)) {
105
+        return ($pour != 'tout') ? '' : ['', '', '', ''];
106
+    }
107
+
108
+    $lien = entites_html(trim($ref));
109
+
110
+    // Liens explicites
111
+    if (!$texte) {
112
+        $texte = str_replace('"', '', $lien);
113
+        // evite l'affichage de trops longues urls.
114
+        $lien_court = charger_fonction('lien_court', 'inc');
115
+        $texte = $lien_court($texte);
116
+        if ($echappe_typo) {
117
+            $texte = '<html>' . quote_amp($texte) . '</html>';
118
+        }
119
+    }
120
+
121
+    // petites corrections d'URL
122
+    if (preg_match('/^www\.[^@]+$/S', $lien)) {
123
+        $lien = 'http://' . $lien;
124
+    } else {
125
+        if (strpos($lien, '@') && email_valide($lien)) {
126
+            if (!$texte) {
127
+                $texte = $lien;
128
+            }
129
+            $lien = 'mailto:' . $lien;
130
+        }
131
+    }
132
+
133
+    if ($pour == 'url') {
134
+        return $lien;
135
+    }
136
+
137
+    if ($pour == 'titre') {
138
+        return $texte;
139
+    }
140
+
141
+    return ['url' => $lien, 'titre' => $texte];
142 142
 }
143 143
 
144 144
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') {
145
-	if (function_exists($f = 'glossaire_' . $ancre)) {
146
-		$url = $f($texte, $id);
147
-	} else {
148
-		$url = glossaire_std($texte);
149
-	}
145
+    if (function_exists($f = 'glossaire_' . $ancre)) {
146
+        $url = $f($texte, $id);
147
+    } else {
148
+        $url = glossaire_std($texte);
149
+    }
150 150
 
151
-	return $url;
151
+    return $url;
152 152
 }
153 153
 
154 154
 function traiter_lien_implicite($ref, $texte = '', $pour = 'url', string $connect = '') {
155
-	$url = null;
156
-	if (!($match = typer_raccourci($ref))) {
157
-		return false;
158
-	}
159
-	[$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
160
-	// attention dans le cas des sites le lien doit pointer non pas sur
161
-	// la page locale du site, mais directement sur le site lui-meme
162
-	if ($f = charger_fonction("implicite_$type", 'liens', true)) {
163
-		$url = $f($texte, $id, $type, $args, $ancre, $connect);
164
-	}
165
-	if (!$url) {
166
-		$url = generer_objet_url($id, $type, $args, $ancre, null, '', $connect);
167
-	}
168
-	if (!$url) {
169
-		return false;
170
-	}
171
-	if (is_array($url)) {
172
-		[$type, $id] = array_pad($url, 2, null);
173
-		$url = generer_objet_url($id, $type, $args, $ancre, null, '', $connect);
174
-	}
175
-	if ($pour === 'url') {
176
-		return $url;
177
-	}
178
-	$r = traiter_raccourci_titre($id, $type, $connect);
179
-	if ($r) {
180
-		$r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
181
-	}
182
-	if ($texte = trim($texte)) {
183
-		$r['titre'] = $texte;
184
-	}
185
-	if (!@$r['titre']) {
186
-		$r['titre'] = _T($type) . " $id";
187
-	}
188
-	if ($pour == 'titre') {
189
-		return $r['titre'];
190
-	}
191
-	$r['url'] = $url;
192
-
193
-	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
194
-	if (
195
-		$type == 'document'
196
-		and $mime = sql_getfetsel(
197
-			'mime_type',
198
-			'spip_types_documents',
199
-			'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
200
-			'',
201
-			'',
202
-			'',
203
-			'',
204
-			$connect
205
-		)
206
-	) {
207
-		$r['mime'] = $mime;
208
-	}
209
-
210
-	return $r;
155
+    $url = null;
156
+    if (!($match = typer_raccourci($ref))) {
157
+        return false;
158
+    }
159
+    [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
160
+    // attention dans le cas des sites le lien doit pointer non pas sur
161
+    // la page locale du site, mais directement sur le site lui-meme
162
+    if ($f = charger_fonction("implicite_$type", 'liens', true)) {
163
+        $url = $f($texte, $id, $type, $args, $ancre, $connect);
164
+    }
165
+    if (!$url) {
166
+        $url = generer_objet_url($id, $type, $args, $ancre, null, '', $connect);
167
+    }
168
+    if (!$url) {
169
+        return false;
170
+    }
171
+    if (is_array($url)) {
172
+        [$type, $id] = array_pad($url, 2, null);
173
+        $url = generer_objet_url($id, $type, $args, $ancre, null, '', $connect);
174
+    }
175
+    if ($pour === 'url') {
176
+        return $url;
177
+    }
178
+    $r = traiter_raccourci_titre($id, $type, $connect);
179
+    if ($r) {
180
+        $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
181
+    }
182
+    if ($texte = trim($texte)) {
183
+        $r['titre'] = $texte;
184
+    }
185
+    if (!@$r['titre']) {
186
+        $r['titre'] = _T($type) . " $id";
187
+    }
188
+    if ($pour == 'titre') {
189
+        return $r['titre'];
190
+    }
191
+    $r['url'] = $url;
192
+
193
+    // dans le cas d'un lien vers un doc, ajouter le type='mime/type'
194
+    if (
195
+        $type == 'document'
196
+        and $mime = sql_getfetsel(
197
+            'mime_type',
198
+            'spip_types_documents',
199
+            'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
200
+            '',
201
+            '',
202
+            '',
203
+            '',
204
+            $connect
205
+        )
206
+    ) {
207
+        $r['mime'] = $mime;
208
+    }
209
+
210
+    return $r;
211 211
 }
212 212
 
213 213
 // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes
@@ -215,41 +215,41 @@  discard block
 block discarded – undo
215 215
 define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S');
216 216
 
217 217
 function typer_raccourci($lien) {
218
-	if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
219
-		return [];
220
-	}
221
-	$f = $match[1];
222
-	// valeur par defaut et alias historiques
223
-	if (!$f) {
224
-		$f = 'article';
225
-	} else {
226
-		if ($f == 'art') {
227
-			$f = 'article';
228
-		} else {
229
-			if ($f == 'br') {
230
-				$f = 'breve';
231
-			} else {
232
-				if ($f == 'rub') {
233
-					$f = 'rubrique';
234
-				} else {
235
-					if ($f == 'aut') {
236
-						$f = 'auteur';
237
-					} else {
238
-						if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
239
-							$f = 'document';
240
-						} else {
241
-							if (preg_match('/^br..?ve$/S', $f)) {
242
-								$f = 'breve';
243
-							}
244
-						}
245
-					}
246
-				}
247
-			}
248
-		}
249
-	} # accents :(
250
-	$match[0] = $f;
251
-
252
-	return $match;
218
+    if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
219
+        return [];
220
+    }
221
+    $f = $match[1];
222
+    // valeur par defaut et alias historiques
223
+    if (!$f) {
224
+        $f = 'article';
225
+    } else {
226
+        if ($f == 'art') {
227
+            $f = 'article';
228
+        } else {
229
+            if ($f == 'br') {
230
+                $f = 'breve';
231
+            } else {
232
+                if ($f == 'rub') {
233
+                    $f = 'rubrique';
234
+                } else {
235
+                    if ($f == 'aut') {
236
+                        $f = 'auteur';
237
+                    } else {
238
+                        if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') {
239
+                            $f = 'document';
240
+                        } else {
241
+                            if (preg_match('/^br..?ve$/S', $f)) {
242
+                                $f = 'breve';
243
+                            }
244
+                        }
245
+                    }
246
+                }
247
+            }
248
+        }
249
+    } # accents :(
250
+    $match[0] = $f;
251
+
252
+    return $match;
253 253
 }
254 254
 
255 255
 /**
@@ -264,25 +264,25 @@  discard block
 block discarded – undo
264 264
  * }
265 265
  **/
266 266
 function traiter_raccourci_titre($id, $type, $connect = null) {
267
-	$trouver_table = charger_fonction('trouver_table', 'base');
268
-	$desc = $trouver_table(table_objet($type));
269
-	if (!($desc and $s = $desc['titre'])) {
270
-		return [];
271
-	}
272
-	$_id = $desc['key']['PRIMARY KEY'];
273
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
274
-	if (!$r) {
275
-		return [];
276
-	}
277
-	$r['titre'] = supprimer_numero($r['titre']);
278
-	if (!$r['titre'] and !empty($r['surnom'])) {
279
-		$r['titre'] = $r['surnom'];
280
-	}
281
-	if (!isset($r['lang'])) {
282
-		$r['lang'] = '';
283
-	}
284
-
285
-	return $r;
267
+    $trouver_table = charger_fonction('trouver_table', 'base');
268
+    $desc = $trouver_table(table_objet($type));
269
+    if (!($desc and $s = $desc['titre'])) {
270
+        return [];
271
+    }
272
+    $_id = $desc['key']['PRIMARY KEY'];
273
+    $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
274
+    if (!$r) {
275
+        return [];
276
+    }
277
+    $r['titre'] = supprimer_numero($r['titre']);
278
+    if (!$r['titre'] and !empty($r['surnom'])) {
279
+        $r['titre'] = $r['surnom'];
280
+    }
281
+    if (!isset($r['lang'])) {
282
+        $r['lang'] = '';
283
+    }
284
+
285
+    return $r;
286 286
 }
287 287
 
288 288
 // traite les modeles (dans la fonction typo), en remplacant
@@ -293,136 +293,136 @@  discard block
 block discarded – undo
293 293
 // mais on renvoie les params (pour l'indexation par le moteur de recherche)
294 294
 
295 295
 define(
296
-	'_RACCOURCI_MODELE',
297
-	'(<([a-z_-]{3,})' # <modele
298
-	. '\s*([0-9]*)\s*' # id
299
-	. '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
300
-	. '\s*/?' . '>)' # fin du modele >
301
-	. '\s*(<\/a>)?' # eventuel </a>
296
+    '_RACCOURCI_MODELE',
297
+    '(<([a-z_-]{3,})' # <modele
298
+    . '\s*([0-9]*)\s*' # id
299
+    . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
300
+    . '\s*/?' . '>)' # fin du modele >
301
+    . '\s*(<\/a>)?' # eventuel </a>
302 302
 );
303 303
 
304 304
 define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
305 305
 
306 306
 function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) {
307
-	// preserver la compatibilite : true = recherche des documents
308
-	if ($doublons === true) {
309
-		$doublons = ['documents' => ['doc', 'emb', 'img']];
310
-	}
311
-	// detecter les modeles (rapide)
312
-	if (
313
-		strpos($texte, '<') !== false and
314
-		preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
315
-	) {
316
-		include_spip('public/assembler');
317
-		$wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
318
-		foreach ($matches as $match) {
319
-			// Recuperer l'appel complet (y compris un eventuel lien)
320
-
321
-			$a = strpos($texte, (string) $match[0]);
322
-			preg_match(
323
-				_RACCOURCI_MODELE_DEBUT,
324
-				substr($texte, $a),
325
-				$regs
326
-			);
327
-			$regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
328
-			[, $mod, $type, $id, $params, $fin] = $regs;
329
-			if (
330
-				$fin and
331
-				preg_match(
332
-					'/<a\s[^<>]*>\s*$/i',
333
-					substr($texte, 0, $a),
334
-					$r
335
-				)
336
-			) {
337
-				$lien = [
338
-					'href' => extraire_attribut($r[0], 'href'),
339
-					'class' => extraire_attribut($r[0], 'class'),
340
-					'mime' => extraire_attribut($r[0], 'type'),
341
-					'title' => extraire_attribut($r[0], 'title'),
342
-					'hreflang' => extraire_attribut($r[0], 'hreflang')
343
-				];
344
-				$n = strlen($r[0]);
345
-				$a -= $n;
346
-				$cherche = $n + strlen($regs[0]);
347
-			} else {
348
-				$lien = false;
349
-				$cherche = strlen($mod);
350
-			}
351
-
352
-			// calculer le modele
353
-			# hack indexation
354
-			if ($doublons) {
355
-				$texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
356
-			} # version normale
357
-			else {
358
-				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
359
-				// dans les parametres, plutot que les liens echappes
360
-				if (!is_null($liens)) {
361
-					$params = str_replace($liens[0], $liens[1], $params);
362
-				}
363
-				$modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
364
-				// en cas d'echec,
365
-				// si l'objet demande a une url,
366
-				// creer un petit encadre vers elle
367
-				if ($modele === false) {
368
-					if (!$lien) {
369
-						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
370
-					}
371
-					if ($lien) {
372
-						$modele = '<a href="'
373
-							. $lien['url']
374
-							. '" class="spip_modele'
375
-							. '">'
376
-							. sinon($lien['titre'], _T('ecrire:info_sans_titre'))
377
-							. '</a>';
378
-					} else {
379
-						$modele = '';
380
-						if (test_espace_prive()) {
381
-							$modele = entites_html(substr($texte, $a, $cherche));
382
-							if (!is_null($liens)) {
383
-								$modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>';
384
-							}
385
-						}
386
-					}
387
-				}
388
-				// le remplacer dans le texte
389
-				if ($modele !== false) {
390
-					$modele = protege_js_modeles($modele);
391
-					if ($wrap_embed_html) {
392
-						$modele = $wrap_embed_html($mod, $modele);
393
-					}
394
-					$rempl = code_echappement($modele, $echap);
395
-					$texte = substr($texte, 0, $a)
396
-						. $rempl
397
-						. substr($texte, $a + $cherche);
398
-				}
399
-			}
400
-
401
-			// hack pour tout l'espace prive
402
-			if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) {
403
-				foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) {
404
-					if (in_array($type, $modeles)) {
405
-						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
406
-					}
407
-				}
408
-			}
409
-		}
410
-	}
411
-
412
-	return $texte;
307
+    // preserver la compatibilite : true = recherche des documents
308
+    if ($doublons === true) {
309
+        $doublons = ['documents' => ['doc', 'emb', 'img']];
310
+    }
311
+    // detecter les modeles (rapide)
312
+    if (
313
+        strpos($texte, '<') !== false and
314
+        preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
315
+    ) {
316
+        include_spip('public/assembler');
317
+        $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
318
+        foreach ($matches as $match) {
319
+            // Recuperer l'appel complet (y compris un eventuel lien)
320
+
321
+            $a = strpos($texte, (string) $match[0]);
322
+            preg_match(
323
+                _RACCOURCI_MODELE_DEBUT,
324
+                substr($texte, $a),
325
+                $regs
326
+            );
327
+            $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
328
+            [, $mod, $type, $id, $params, $fin] = $regs;
329
+            if (
330
+                $fin and
331
+                preg_match(
332
+                    '/<a\s[^<>]*>\s*$/i',
333
+                    substr($texte, 0, $a),
334
+                    $r
335
+                )
336
+            ) {
337
+                $lien = [
338
+                    'href' => extraire_attribut($r[0], 'href'),
339
+                    'class' => extraire_attribut($r[0], 'class'),
340
+                    'mime' => extraire_attribut($r[0], 'type'),
341
+                    'title' => extraire_attribut($r[0], 'title'),
342
+                    'hreflang' => extraire_attribut($r[0], 'hreflang')
343
+                ];
344
+                $n = strlen($r[0]);
345
+                $a -= $n;
346
+                $cherche = $n + strlen($regs[0]);
347
+            } else {
348
+                $lien = false;
349
+                $cherche = strlen($mod);
350
+            }
351
+
352
+            // calculer le modele
353
+            # hack indexation
354
+            if ($doublons) {
355
+                $texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
356
+            } # version normale
357
+            else {
358
+                // si un tableau de liens a ete passe, reinjecter le contenu d'origine
359
+                // dans les parametres, plutot que les liens echappes
360
+                if (!is_null($liens)) {
361
+                    $params = str_replace($liens[0], $liens[1], $params);
362
+                }
363
+                $modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
364
+                // en cas d'echec,
365
+                // si l'objet demande a une url,
366
+                // creer un petit encadre vers elle
367
+                if ($modele === false) {
368
+                    if (!$lien) {
369
+                        $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
370
+                    }
371
+                    if ($lien) {
372
+                        $modele = '<a href="'
373
+                            . $lien['url']
374
+                            . '" class="spip_modele'
375
+                            . '">'
376
+                            . sinon($lien['titre'], _T('ecrire:info_sans_titre'))
377
+                            . '</a>';
378
+                    } else {
379
+                        $modele = '';
380
+                        if (test_espace_prive()) {
381
+                            $modele = entites_html(substr($texte, $a, $cherche));
382
+                            if (!is_null($liens)) {
383
+                                $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>';
384
+                            }
385
+                        }
386
+                    }
387
+                }
388
+                // le remplacer dans le texte
389
+                if ($modele !== false) {
390
+                    $modele = protege_js_modeles($modele);
391
+                    if ($wrap_embed_html) {
392
+                        $modele = $wrap_embed_html($mod, $modele);
393
+                    }
394
+                    $rempl = code_echappement($modele, $echap);
395
+                    $texte = substr($texte, 0, $a)
396
+                        . $rempl
397
+                        . substr($texte, $a + $cherche);
398
+                }
399
+            }
400
+
401
+            // hack pour tout l'espace prive
402
+            if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) {
403
+                foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) {
404
+                    if (in_array($type, $modeles)) {
405
+                        $GLOBALS["doublons_{$quoi}_inclus"][] = $id;
406
+                    }
407
+                }
408
+            }
409
+        }
410
+    }
411
+
412
+    return $texte;
413 413
 }
414 414
 
415 415
 //
416 416
 // Raccourcis ancre [#ancre<-]
417 417
 //
418 418
 function traiter_raccourci_ancre($letexte) {
419
-	return $letexte;
419
+    return $letexte;
420 420
 }
421 421
 
422 422
 function traiter_raccourci_glossaire($texte) {
423
-	return $texte;
423
+    return $texte;
424 424
 }
425 425
 
426 426
 function glossaire_std($terme) {
427
-	return $terme;
427
+    return $terme;
428 428
 }
Please login to merge, or discard this patch.