Completed
Push — master ( 638d3f...342b7b )
by cam
01:55 queued 55s
created
ecrire/inc/config.php 1 patch
Indentation   +352 added lines, -352 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
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * @return void
29 29
  */
30 30
 function inc_config_dist() {
31
-	actualise_metas(liste_metas());
31
+    actualise_metas(liste_metas());
32 32
 }
33 33
 
34 34
 /**
@@ -45,34 +45,34 @@  discard block
 block discarded – undo
45 45
  *     Liste (table, casier, sous_casier)
46 46
  */
47 47
 function expliquer_config($cfg) {
48
-	// par defaut, sur la table des meta
49
-	$table = 'meta';
50
-	$casier = null;
51
-	$sous_casier = [];
52
-	$cfg = explode('/', $cfg);
53
-
54
-	// si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide ''
55
-	if (!reset($cfg) and count($cfg) > 1) {
56
-		array_shift($cfg);
57
-		$table = array_shift($cfg);
58
-		if (!isset($GLOBALS[$table])) {
59
-			lire_metas($table);
60
-		}
61
-	}
62
-
63
-	// si on a demande #CONFIG{/meta,'',0}
64
-	if (count($cfg)) {
65
-		// pas sur un appel vide ''
66
-		if ('' !== ($c = array_shift($cfg))) {
67
-			$casier = $c;
68
-		}
69
-	}
70
-
71
-	if (count($cfg)) {
72
-		$sous_casier = $cfg;
73
-	}
74
-
75
-	return [$table, $casier, $sous_casier];
48
+    // par defaut, sur la table des meta
49
+    $table = 'meta';
50
+    $casier = null;
51
+    $sous_casier = [];
52
+    $cfg = explode('/', $cfg);
53
+
54
+    // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide ''
55
+    if (!reset($cfg) and count($cfg) > 1) {
56
+        array_shift($cfg);
57
+        $table = array_shift($cfg);
58
+        if (!isset($GLOBALS[$table])) {
59
+            lire_metas($table);
60
+        }
61
+    }
62
+
63
+    // si on a demande #CONFIG{/meta,'',0}
64
+    if (count($cfg)) {
65
+        // pas sur un appel vide ''
66
+        if ('' !== ($c = array_shift($cfg))) {
67
+            $casier = $c;
68
+        }
69
+    }
70
+
71
+    if (count($cfg)) {
72
+        $sous_casier = $cfg;
73
+    }
74
+
75
+    return [$table, $casier, $sous_casier];
76 76
 }
77 77
 
78 78
 /**
@@ -100,65 +100,65 @@  discard block
 block discarded – undo
100 100
  *    Contenu de la configuration obtenue
101 101
  */
102 102
 function lire_config($cfg = '', $def = null, $unserialize = true) {
103
-	// lire le stockage sous la forme /table/valeur
104
-	// ou valeur qui est en fait implicitement /meta/valeur
105
-	// ou casier/valeur qui est en fait implicitement /meta/casier/valeur
106
-
107
-	// traiter en priorite le cas simple et frequent
108
-	// de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni :
109
-	if ($cfg and strpbrk($cfg, '/:') === false) {
110
-		$r = isset($GLOBALS['meta'][$cfg]) ?
111
-			((!$unserialize
112
-				// ne pas essayer de deserialiser autre chose qu'une chaine
113
-				or !is_string($GLOBALS['meta'][$cfg])
114
-				// ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee
115
-				or !str_contains($GLOBALS['meta'][$cfg], ':')
116
-				or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t)
117
-			: $def;
118
-
119
-		return $r;
120
-	}
121
-
122
-	// Brancher sur methodes externes si besoin
123
-	if ($cfg and $p = strpos($cfg, '::')) {
124
-		$methode = substr($cfg, 0, $p);
125
-		$lire_config = charger_fonction($methode, 'lire_config');
126
-
127
-		return $lire_config(substr($cfg, $p + 2), $def, $unserialize);
128
-	}
129
-
130
-	[$table, $casier, $sous_casier] = expliquer_config($cfg);
131
-
132
-	if (!isset($GLOBALS[$table])) {
133
-		return $def;
134
-	}
135
-
136
-	$r = $GLOBALS[$table];
137
-
138
-	// si on a demande #CONFIG{/meta,'',0}
139
-	if (!$casier) {
140
-		return $unserialize ? $r : serialize($r);
141
-	}
142
-
143
-	// casier principal :
144
-	// le deserializer si demande
145
-	// ou si on a besoin
146
-	// d'un sous casier
147
-	$r = $r[$casier] ?? null;
148
-	if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) {
149
-		$r = (($t = @unserialize($r)) === false ? $r : $t);
150
-	}
151
-
152
-	// aller chercher le sous_casier
153
-	while (!is_null($r) and $casier = array_shift($sous_casier)) {
154
-		$r = $r[$casier] ?? null;
155
-	}
156
-
157
-	if (is_null($r)) {
158
-		return $def;
159
-	}
160
-
161
-	return $r;
103
+    // lire le stockage sous la forme /table/valeur
104
+    // ou valeur qui est en fait implicitement /meta/valeur
105
+    // ou casier/valeur qui est en fait implicitement /meta/casier/valeur
106
+
107
+    // traiter en priorite le cas simple et frequent
108
+    // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni :
109
+    if ($cfg and strpbrk($cfg, '/:') === false) {
110
+        $r = isset($GLOBALS['meta'][$cfg]) ?
111
+            ((!$unserialize
112
+                // ne pas essayer de deserialiser autre chose qu'une chaine
113
+                or !is_string($GLOBALS['meta'][$cfg])
114
+                // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee
115
+                or !str_contains($GLOBALS['meta'][$cfg], ':')
116
+                or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t)
117
+            : $def;
118
+
119
+        return $r;
120
+    }
121
+
122
+    // Brancher sur methodes externes si besoin
123
+    if ($cfg and $p = strpos($cfg, '::')) {
124
+        $methode = substr($cfg, 0, $p);
125
+        $lire_config = charger_fonction($methode, 'lire_config');
126
+
127
+        return $lire_config(substr($cfg, $p + 2), $def, $unserialize);
128
+    }
129
+
130
+    [$table, $casier, $sous_casier] = expliquer_config($cfg);
131
+
132
+    if (!isset($GLOBALS[$table])) {
133
+        return $def;
134
+    }
135
+
136
+    $r = $GLOBALS[$table];
137
+
138
+    // si on a demande #CONFIG{/meta,'',0}
139
+    if (!$casier) {
140
+        return $unserialize ? $r : serialize($r);
141
+    }
142
+
143
+    // casier principal :
144
+    // le deserializer si demande
145
+    // ou si on a besoin
146
+    // d'un sous casier
147
+    $r = $r[$casier] ?? null;
148
+    if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) {
149
+        $r = (($t = @unserialize($r)) === false ? $r : $t);
150
+    }
151
+
152
+    // aller chercher le sous_casier
153
+    while (!is_null($r) and $casier = array_shift($sous_casier)) {
154
+        $r = $r[$casier] ?? null;
155
+    }
156
+
157
+    if (is_null($r)) {
158
+        return $def;
159
+    }
160
+
161
+    return $r;
162 162
 }
163 163
 
164 164
 /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
  * @return mixed
173 173
  */
174 174
 function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) {
175
-	return lire_config($cfg, $def, $unserialize);
175
+    return lire_config($cfg, $def, $unserialize);
176 176
 }
177 177
 
178 178
 
@@ -184,144 +184,144 @@  discard block
 block discarded – undo
184 184
  * @return bool
185 185
  */
186 186
 function ecrire_config($cfg, $store) {
187
-	// Brancher sur methodes externes si besoin
188
-	if ($cfg and $p = strpos($cfg, '::')) {
189
-		$methode = substr($cfg, 0, $p);
190
-		$ecrire_config = charger_fonction($methode, 'ecrire_config');
191
-
192
-		return $ecrire_config(substr($cfg, $p + 2), $store);
193
-	}
194
-
195
-	[$table, $casier, $sous_casier] = expliquer_config($cfg);
196
-	// il faut au moins un casier pour ecrire
197
-	if (!$casier) {
198
-		return false;
199
-	}
200
-
201
-	// trouvons ou creons le pointeur sur le casier
202
-	$st = $GLOBALS[$table][$casier] ?? null;
203
-	if (!is_array($st) and ($sous_casier or is_array($store))) {
204
-		if ($st === null) {
205
-			// ne rien creer si c'est une demande d'effacement
206
-			if ($store === null) {
207
-				return false;
208
-			}
209
-			$st = [];
210
-		} else {
211
-			$st = unserialize($st);
212
-			if ($st === false) {
213
-				// ne rien creer si c'est une demande d'effacement
214
-				if ($store === null) {
215
-					return false;
216
-				}
217
-				$st = [];
218
-			}
219
-		}
220
-	}
221
-
222
-	$has_planes = false;
223
-	// si on a affaire a un sous caiser
224
-	// il faut ecrire au bon endroit sans perdre les autres sous casier freres
225
-	if ($c = $sous_casier) {
226
-		$sc = &$st;
227
-		$pointeurs = [];
228
-		while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) {
229
-			// creer l'entree si elle n'existe pas
230
-			if (!isset($sc[$cc])) {
231
-				// si on essaye d'effacer une config qui n'existe pas
232
-				// ne rien creer mais sortir
233
-				if (is_null($store)) {
234
-					return false;
235
-				}
236
-				$sc[$cc] = [];
237
-			}
238
-			$pointeurs[$cc] = &$sc;
239
-			$sc = &$sc[$cc];
240
-		}
241
-
242
-		// si c'est une demande d'effacement
243
-		if (is_null($store)) {
244
-			$c = $sous_casier;
245
-			$sous = array_pop($c);
246
-			// effacer, et remonter pour effacer les parents vides
247
-			do {
248
-				unset($pointeurs[$sous][$sous]);
249
-			} while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0));
250
-
251
-			// si on a vide tous les sous casiers,
252
-			// et que le casier est vide
253
-			// vider aussi la meta
254
-			if (!$sous and !(is_countable($st) ? count($st) : 0)) {
255
-				$st = null;
256
-			}
257
-		} // dans tous les autres cas, on ecrase
258
-		else {
259
-			if (
260
-					defined('_MYSQL_NOPLANES')
261
-				and _MYSQL_NOPLANES
262
-				and !empty($GLOBALS['meta']['charset_sql_connexion'])
263
-				and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8'
264
-			) {
265
-				// detecter si la valeur qu'on veut ecrire a des planes
266
-				// @see utf8_noplanes
267
-				$serialized_store = (is_string($store) ? $store : serialize($store));
268
-				// un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes
269
-				if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) {
270
-					if (!function_exists('utf8_noplanes')) {
271
-						include_spip('inc/charsets');
272
-					}
273
-					if ($serialized_store !== utf8_noplanes($serialized_store)) {
274
-						$has_planes = true;
275
-					}
276
-				}
277
-			}
278
-
279
-			$sc = $store;
280
-		}
281
-
282
-		// Maintenant que $st est modifiee
283
-		// reprenons la comme valeur a stocker dans le casier principal
284
-		$store = $st;
285
-	}
286
-
287
-	if (is_null($store)) {
288
-		if (is_null($st) and !$sous_casier) {
289
-			return false;
290
-		} // la config n'existait deja pas !
291
-		effacer_meta($casier, $table);
292
-		supprimer_table_meta($table); // supprimons la table (si elle est bien vide)
293
-	} // les meta ne peuvent etre que des chaines : il faut serializer le reste
294
-	else {
295
-		if (!isset($GLOBALS[$table])) {
296
-			installer_table_meta($table);
297
-		}
298
-		// si ce n'est pas une chaine
299
-		// il faut serializer
300
-		if (!is_string($store)) {
301
-			$serialized_store = serialize($store);
302
-			ecrire_meta($casier, $serialized_store, null, $table);
303
-			// et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine
304
-			// car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4)
305
-			if ($has_planes) {
306
-				$check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier));
307
-				if ($check_store !== $serialized_store) {
308
-					array_walk_recursive($store, function (&$value, $key) {
309
-						if (is_string($value)) {
310
-							$value = utf8_noplanes($value);
311
-						}
312
-					});
313
-					$serialized_store = serialize($store);
314
-					ecrire_meta($casier, $serialized_store, null, $table);
315
-				}
316
-			}
317
-		}
318
-		else {
319
-			ecrire_meta($casier, $store, null, $table);
320
-		}
321
-	}
322
-
323
-	// verifier que lire_config($cfg)==$store ?
324
-	return true;
187
+    // Brancher sur methodes externes si besoin
188
+    if ($cfg and $p = strpos($cfg, '::')) {
189
+        $methode = substr($cfg, 0, $p);
190
+        $ecrire_config = charger_fonction($methode, 'ecrire_config');
191
+
192
+        return $ecrire_config(substr($cfg, $p + 2), $store);
193
+    }
194
+
195
+    [$table, $casier, $sous_casier] = expliquer_config($cfg);
196
+    // il faut au moins un casier pour ecrire
197
+    if (!$casier) {
198
+        return false;
199
+    }
200
+
201
+    // trouvons ou creons le pointeur sur le casier
202
+    $st = $GLOBALS[$table][$casier] ?? null;
203
+    if (!is_array($st) and ($sous_casier or is_array($store))) {
204
+        if ($st === null) {
205
+            // ne rien creer si c'est une demande d'effacement
206
+            if ($store === null) {
207
+                return false;
208
+            }
209
+            $st = [];
210
+        } else {
211
+            $st = unserialize($st);
212
+            if ($st === false) {
213
+                // ne rien creer si c'est une demande d'effacement
214
+                if ($store === null) {
215
+                    return false;
216
+                }
217
+                $st = [];
218
+            }
219
+        }
220
+    }
221
+
222
+    $has_planes = false;
223
+    // si on a affaire a un sous caiser
224
+    // il faut ecrire au bon endroit sans perdre les autres sous casier freres
225
+    if ($c = $sous_casier) {
226
+        $sc = &$st;
227
+        $pointeurs = [];
228
+        while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) {
229
+            // creer l'entree si elle n'existe pas
230
+            if (!isset($sc[$cc])) {
231
+                // si on essaye d'effacer une config qui n'existe pas
232
+                // ne rien creer mais sortir
233
+                if (is_null($store)) {
234
+                    return false;
235
+                }
236
+                $sc[$cc] = [];
237
+            }
238
+            $pointeurs[$cc] = &$sc;
239
+            $sc = &$sc[$cc];
240
+        }
241
+
242
+        // si c'est une demande d'effacement
243
+        if (is_null($store)) {
244
+            $c = $sous_casier;
245
+            $sous = array_pop($c);
246
+            // effacer, et remonter pour effacer les parents vides
247
+            do {
248
+                unset($pointeurs[$sous][$sous]);
249
+            } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0));
250
+
251
+            // si on a vide tous les sous casiers,
252
+            // et que le casier est vide
253
+            // vider aussi la meta
254
+            if (!$sous and !(is_countable($st) ? count($st) : 0)) {
255
+                $st = null;
256
+            }
257
+        } // dans tous les autres cas, on ecrase
258
+        else {
259
+            if (
260
+                    defined('_MYSQL_NOPLANES')
261
+                and _MYSQL_NOPLANES
262
+                and !empty($GLOBALS['meta']['charset_sql_connexion'])
263
+                and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8'
264
+            ) {
265
+                // detecter si la valeur qu'on veut ecrire a des planes
266
+                // @see utf8_noplanes
267
+                $serialized_store = (is_string($store) ? $store : serialize($store));
268
+                // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes
269
+                if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) {
270
+                    if (!function_exists('utf8_noplanes')) {
271
+                        include_spip('inc/charsets');
272
+                    }
273
+                    if ($serialized_store !== utf8_noplanes($serialized_store)) {
274
+                        $has_planes = true;
275
+                    }
276
+                }
277
+            }
278
+
279
+            $sc = $store;
280
+        }
281
+
282
+        // Maintenant que $st est modifiee
283
+        // reprenons la comme valeur a stocker dans le casier principal
284
+        $store = $st;
285
+    }
286
+
287
+    if (is_null($store)) {
288
+        if (is_null($st) and !$sous_casier) {
289
+            return false;
290
+        } // la config n'existait deja pas !
291
+        effacer_meta($casier, $table);
292
+        supprimer_table_meta($table); // supprimons la table (si elle est bien vide)
293
+    } // les meta ne peuvent etre que des chaines : il faut serializer le reste
294
+    else {
295
+        if (!isset($GLOBALS[$table])) {
296
+            installer_table_meta($table);
297
+        }
298
+        // si ce n'est pas une chaine
299
+        // il faut serializer
300
+        if (!is_string($store)) {
301
+            $serialized_store = serialize($store);
302
+            ecrire_meta($casier, $serialized_store, null, $table);
303
+            // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine
304
+            // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4)
305
+            if ($has_planes) {
306
+                $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier));
307
+                if ($check_store !== $serialized_store) {
308
+                    array_walk_recursive($store, function (&$value, $key) {
309
+                        if (is_string($value)) {
310
+                            $value = utf8_noplanes($value);
311
+                        }
312
+                    });
313
+                    $serialized_store = serialize($store);
314
+                    ecrire_meta($casier, $serialized_store, null, $table);
315
+                }
316
+            }
317
+        }
318
+        else {
319
+            ecrire_meta($casier, $store, null, $table);
320
+        }
321
+    }
322
+
323
+    // verifier que lire_config($cfg)==$store ?
324
+    return true;
325 325
 }
326 326
 
327 327
 
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
  * @return bool
336 336
  */
337 337
 function ecrire_config_metapack_dist($cfg, $store) {
338
-	// cas particulier en metapack::
339
-	// si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre
340
-	// intacte en sortie ...
341
-	if (is_string($store) and strpos($store, ':') and unserialize($store)) {
342
-		$store = serialize($store);
343
-	}
344
-
345
-	return ecrire_config($cfg, $store);
338
+    // cas particulier en metapack::
339
+    // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre
340
+    // intacte en sortie ...
341
+    if (is_string($store) and strpos($store, ':') and unserialize($store)) {
342
+        $store = serialize($store);
343
+    }
344
+
345
+    return ecrire_config($cfg, $store);
346 346
 }
347 347
 
348 348
 /**
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
  * @return bool
353 353
  */
354 354
 function effacer_config($cfg) {
355
-	ecrire_config($cfg, null);
355
+    ecrire_config($cfg, null);
356 356
 
357
-	return true;
357
+    return true;
358 358
 }
359 359
 
360 360
 /**
@@ -371,58 +371,58 @@  discard block
 block discarded – undo
371 371
  *    Couples nom de la `meta` => valeur par défaut
372 372
  */
373 373
 function liste_metas() {
374
-	return pipeline('configurer_liste_metas', [
375
-		'nom_site' => _T('info_mon_site_spip'),
376
-		'slogan_site' => '',
377
-		'adresse_site' => preg_replace(',/$,', '', url_de_base()),
378
-		'descriptif_site' => '',
379
-		'activer_logos' => 'oui',
380
-		'activer_logos_survol' => 'non',
381
-		'articles_surtitre' => 'non',
382
-		'articles_soustitre' => 'non',
383
-		'articles_descriptif' => 'non',
384
-		'articles_chapeau' => 'non',
385
-		'articles_texte' => 'oui',
386
-		'articles_ps' => 'non',
387
-		'articles_redac' => 'non',
388
-		'post_dates' => 'non',
389
-		'articles_urlref' => 'non',
390
-		'articles_redirection' => 'non',
391
-		'creer_preview' => 'non',
392
-		'taille_preview' => 150,
393
-		'articles_modif' => 'non',
394
-
395
-		'rubriques_descriptif' => 'non',
396
-		'rubriques_texte' => 'oui',
397
-
398
-		'accepter_inscriptions' => 'non',
399
-		'accepter_visiteurs' => 'non',
400
-		'prevenir_auteurs' => 'non',
401
-		'suivi_edito' => 'non',
402
-		'adresse_suivi' => '',
403
-		'adresse_suivi_inscription' => '',
404
-		'adresse_neuf' => '',
405
-		'jours_neuf' => '',
406
-		'quoi_de_neuf' => 'non',
407
-		'preview' => ',0minirezo,1comite,',
408
-
409
-		'syndication_integrale' => 'oui',
410
-		'charset' => _DEFAULT_CHARSET,
411
-		'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)),
412
-
413
-		'multi_rubriques' => 'non',
414
-		'multi_secteurs' => 'non',
415
-		'gerer_trad' => 'non',
416
-		'langues_multilingue' => '',
417
-
418
-		'version_html_max' => 'html4',
419
-
420
-		'type_urls' => 'page',
421
-
422
-		'email_envoi' => '',
423
-		'email_webmaster' => '',
424
-		'auto_compress_http' => 'non',
425
-	]);
374
+    return pipeline('configurer_liste_metas', [
375
+        'nom_site' => _T('info_mon_site_spip'),
376
+        'slogan_site' => '',
377
+        'adresse_site' => preg_replace(',/$,', '', url_de_base()),
378
+        'descriptif_site' => '',
379
+        'activer_logos' => 'oui',
380
+        'activer_logos_survol' => 'non',
381
+        'articles_surtitre' => 'non',
382
+        'articles_soustitre' => 'non',
383
+        'articles_descriptif' => 'non',
384
+        'articles_chapeau' => 'non',
385
+        'articles_texte' => 'oui',
386
+        'articles_ps' => 'non',
387
+        'articles_redac' => 'non',
388
+        'post_dates' => 'non',
389
+        'articles_urlref' => 'non',
390
+        'articles_redirection' => 'non',
391
+        'creer_preview' => 'non',
392
+        'taille_preview' => 150,
393
+        'articles_modif' => 'non',
394
+
395
+        'rubriques_descriptif' => 'non',
396
+        'rubriques_texte' => 'oui',
397
+
398
+        'accepter_inscriptions' => 'non',
399
+        'accepter_visiteurs' => 'non',
400
+        'prevenir_auteurs' => 'non',
401
+        'suivi_edito' => 'non',
402
+        'adresse_suivi' => '',
403
+        'adresse_suivi_inscription' => '',
404
+        'adresse_neuf' => '',
405
+        'jours_neuf' => '',
406
+        'quoi_de_neuf' => 'non',
407
+        'preview' => ',0minirezo,1comite,',
408
+
409
+        'syndication_integrale' => 'oui',
410
+        'charset' => _DEFAULT_CHARSET,
411
+        'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)),
412
+
413
+        'multi_rubriques' => 'non',
414
+        'multi_secteurs' => 'non',
415
+        'gerer_trad' => 'non',
416
+        'langues_multilingue' => '',
417
+
418
+        'version_html_max' => 'html4',
419
+
420
+        'type_urls' => 'page',
421
+
422
+        'email_envoi' => '',
423
+        'email_webmaster' => '',
424
+        'auto_compress_http' => 'non',
425
+    ]);
426 426
 }
427 427
 
428 428
 /**
@@ -433,43 +433,43 @@  discard block
 block discarded – undo
433 433
  * @return void
434 434
  */
435 435
 function actualise_metas($liste_meta) {
436
-	$meta_serveur =
437
-		[
438
-			'version_installee',
439
-			'adresse_site',
440
-			'alea_ephemere_ancien',
441
-			'alea_ephemere',
442
-			'alea_ephemere_date',
443
-			'langue_site',
444
-			'langues_proposees',
445
-			'date_calcul_rubriques',
446
-			'derniere_modif',
447
-			'optimiser_table',
448
-			'drapeau_edition',
449
-			'creer_preview',
450
-			'taille_preview',
451
-			'creer_htpasswd',
452
-			'creer_htaccess',
453
-			'gd_formats_read',
454
-			'gd_formats',
455
-			'netpbm_formats',
456
-			'formats_graphiques',
457
-			'image_process',
458
-			'plugin_header',
459
-			'plugin'
460
-		];
461
-	// verifier le impt=non
462
-	sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur));
463
-
464
-	foreach ($liste_meta as $nom => $valeur) {
465
-		if (empty($GLOBALS['meta'][$nom])) {
466
-			ecrire_meta($nom, $valeur);
467
-		}
468
-	}
469
-
470
-	include_spip('inc/rubriques');
471
-	$langues = calculer_langues_utilisees();
472
-	ecrire_meta('langues_utilisees', $langues);
436
+    $meta_serveur =
437
+        [
438
+            'version_installee',
439
+            'adresse_site',
440
+            'alea_ephemere_ancien',
441
+            'alea_ephemere',
442
+            'alea_ephemere_date',
443
+            'langue_site',
444
+            'langues_proposees',
445
+            'date_calcul_rubriques',
446
+            'derniere_modif',
447
+            'optimiser_table',
448
+            'drapeau_edition',
449
+            'creer_preview',
450
+            'taille_preview',
451
+            'creer_htpasswd',
452
+            'creer_htaccess',
453
+            'gd_formats_read',
454
+            'gd_formats',
455
+            'netpbm_formats',
456
+            'formats_graphiques',
457
+            'image_process',
458
+            'plugin_header',
459
+            'plugin'
460
+        ];
461
+    // verifier le impt=non
462
+    sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur));
463
+
464
+    foreach ($liste_meta as $nom => $valeur) {
465
+        if (empty($GLOBALS['meta'][$nom])) {
466
+            ecrire_meta($nom, $valeur);
467
+        }
468
+    }
469
+
470
+    include_spip('inc/rubriques');
471
+    $langues = calculer_langues_utilisees();
472
+    ecrire_meta('langues_utilisees', $langues);
473 473
 }
474 474
 
475 475
 
@@ -491,18 +491,18 @@  discard block
 block discarded – undo
491 491
  */
492 492
 function appliquer_modifs_config($purger_skel = false) {
493 493
 
494
-	foreach (liste_metas() as $i => $v) {
495
-		if (($x = _request($i)) !== null) {
496
-			ecrire_meta($i, $x);
497
-		} elseif (!isset($GLOBALS['meta'][$i])) {
498
-			ecrire_meta($i, $v);
499
-		}
500
-	}
501
-
502
-	if ($purger_skel) {
503
-		include_spip('inc/invalideur');
504
-		purger_repertoire(_DIR_SKELS);
505
-	}
494
+    foreach (liste_metas() as $i => $v) {
495
+        if (($x = _request($i)) !== null) {
496
+            ecrire_meta($i, $x);
497
+        } elseif (!isset($GLOBALS['meta'][$i])) {
498
+            ecrire_meta($i, $v);
499
+        }
500
+    }
501
+
502
+    if ($purger_skel) {
503
+        include_spip('inc/invalideur');
504
+        purger_repertoire(_DIR_SKELS);
505
+    }
506 506
 }
507 507
 
508 508
 /**
@@ -513,21 +513,21 @@  discard block
 block discarded – undo
513 513
  * @return string
514 514
  */
515 515
 function appliquer_adresse_site($adresse_site) {
516
-	if ($adresse_site !== null) {
517
-		if (!strlen($adresse_site)) {
518
-			$GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1;
519
-			$adresse_site = url_de_base();
520
-		}
521
-		$adresse_site = preg_replace(',/?\s*$,', '', $adresse_site);
516
+    if ($adresse_site !== null) {
517
+        if (!strlen($adresse_site)) {
518
+            $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1;
519
+            $adresse_site = url_de_base();
520
+        }
521
+        $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site);
522 522
 
523
-		if (!tester_url_absolue($adresse_site)) {
524
-			$adresse_site = "http://$adresse_site";
525
-		}
523
+        if (!tester_url_absolue($adresse_site)) {
524
+            $adresse_site = "http://$adresse_site";
525
+        }
526 526
 
527
-		$adresse_site = entites_html($adresse_site);
527
+        $adresse_site = entites_html($adresse_site);
528 528
 
529
-		ecrire_meta('adresse_site', $adresse_site);
530
-	}
529
+        ecrire_meta('adresse_site', $adresse_site);
530
+    }
531 531
 
532
-	return $adresse_site;
532
+    return $adresse_site;
533 533
 }
Please login to merge, or discard this patch.
ecrire/inc/actions.php 1 patch
Indentation   +26 added lines, -26 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
 /**
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
44 44
  */
45 45
 function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) {
46
-	$securiser_action = charger_fonction('securiser_action', 'inc');
46
+    $securiser_action = charger_fonction('securiser_action', 'inc');
47 47
 
48
-	return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
48
+    return $securiser_action($action, $arg, $redirect, $mode, $att, $public);
49 49
 }
50 50
 
51 51
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  *     Code HTML du formulaire
79 79
  */
80 80
 function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) {
81
-	$r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
81
+    $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true);
82 82
 
83
-	return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
83
+    return generer_action_auteur($action, $arg, $r, $mode, $atts, $public);
84 84
 }
85 85
 
86 86
 /**
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
  *     URL, code HTML du formulaire ou tableau (action, arg, hash)
106 106
  */
107 107
 function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') {
108
-	$r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
108
+    $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true);
109 109
 
110
-	return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
110
+    return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'");
111 111
 }
112 112
 
113 113
 
@@ -124,26 +124,26 @@  discard block
 block discarded – undo
124 124
  *   passer "text/html" comme $content_type
125 125
  */
126 126
 function ajax_retour($corps, $content_type = null): void {
127
-	$xml = false;
128
-	if (is_null($content_type) or $content_type === true) {
129
-		$xml = true;
130
-		$content_type = 'text/html';
131
-	} elseif (!$content_type or !is_string($content_type) or !str_contains($content_type, '/')) {
132
-		$content_type = 'text/html';
133
-	}
127
+    $xml = false;
128
+    if (is_null($content_type) or $content_type === true) {
129
+        $xml = true;
130
+        $content_type = 'text/html';
131
+    } elseif (!$content_type or !is_string($content_type) or !str_contains($content_type, '/')) {
132
+        $content_type = 'text/html';
133
+    }
134 134
 
135
-	$e = '';
136
-	if (
137
-		isset($_COOKIE['spip_admin'])
138
-		and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
139
-	) {
140
-		$e = erreur_squelette();
141
-	}
135
+    $e = '';
136
+    if (
137
+        isset($_COOKIE['spip_admin'])
138
+        and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps']))
139
+    ) {
140
+        $e = erreur_squelette();
141
+    }
142 142
 
143
-	$c = $GLOBALS['meta']['charset'];
144
-	header('Content-Type: ' . $content_type . '; charset=' . $c);
145
-	$debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
146
-	$fin = '';
143
+    $c = $GLOBALS['meta']['charset'];
144
+    header('Content-Type: ' . $content_type . '; charset=' . $c);
145
+    $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : '');
146
+    $fin = '';
147 147
 
148
-	echo $debut, $corps, $fin, $e;
148
+    echo $debut, $corps, $fin, $e;
149 149
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 1 patch
Indentation   +580 added lines, -580 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
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
  *    Date au format SQL tel que `2008-04-01` sinon ''
38 38
  **/
39 39
 function extraire_date($texte): string {
40
-	// format = 2001-08
41
-	if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
-		return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
43
-	}
44
-	return '';
40
+    // format = 2001-08
41
+    if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) {
42
+        return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01';
43
+    }
44
+    return '';
45 45
 }
46 46
 
47 47
 
@@ -63,29 +63,29 @@  discard block
 block discarded – undo
63 63
  *     - une chaîne vide si la date est considérée nulle
64 64
  **/
65 65
 function normaliser_date($date, $forcer_jour = false): string {
66
-	$date = vider_date($date);
67
-	if ($date) {
68
-		if (preg_match('/^[0-9]{8,10}$/', $date)) {
69
-			$date = date('Y-m-d H:i:s', $date);
70
-		}
71
-		if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72
-			$regs = array_pad($regs, 4, null); // eviter notice php
73
-			$date = $regs[1] . '-00-00' . $regs[3];
74
-		} else {
75
-			if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76
-				$regs = array_pad($regs, 4, null); // eviter notice php
77
-				$date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
78
-			} else {
79
-				$date = date('Y-m-d H:i:s', strtotime($date));
80
-			}
81
-		}
82
-
83
-		if ($forcer_jour) {
84
-			$date = str_replace('-00', '-01', $date);
85
-		}
86
-	}
87
-
88
-	return $date;
66
+    $date = vider_date($date);
67
+    if ($date) {
68
+        if (preg_match('/^[0-9]{8,10}$/', $date)) {
69
+            $date = date('Y-m-d H:i:s', $date);
70
+        }
71
+        if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
72
+            $regs = array_pad($regs, 4, null); // eviter notice php
73
+            $date = $regs[1] . '-00-00' . $regs[3];
74
+        } else {
75
+            if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
76
+                $regs = array_pad($regs, 4, null); // eviter notice php
77
+                $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3];
78
+            } else {
79
+                $date = date('Y-m-d H:i:s', strtotime($date));
80
+            }
81
+        }
82
+
83
+        if ($forcer_jour) {
84
+            $date = str_replace('-00', '-01', $date);
85
+        }
86
+    }
87
+
88
+    return $date;
89 89
 }
90 90
 
91 91
 /**
@@ -98,23 +98,23 @@  discard block
 block discarded – undo
98 98
  *     - Une chaine vide
99 99
  **/
100 100
 function vider_date($letexte, $verif_format_date = false): string {
101
-	$letexte ??= '';
102
-	if (
103
-		!$verif_format_date
104
-		or (in_array(strlen($letexte), [10,19]) and
105
-			  preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106
-	) {
107
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
108
-			return '';
109
-		}
110
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
111
-			return '';
112
-		}
113
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
114
-			return '';
115
-		}  // eviter le bug GMT-1
116
-	}
117
-	return $letexte;
101
+    $letexte ??= '';
102
+    if (
103
+        !$verif_format_date
104
+        or (in_array(strlen($letexte), [10,19]) and
105
+              preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte))
106
+    ) {
107
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
108
+            return '';
109
+        }
110
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
111
+            return '';
112
+        }
113
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
114
+            return '';
115
+        }  // eviter le bug GMT-1
116
+    }
117
+    return $letexte;
118 118
 }
119 119
 
120 120
 /**
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
  **/
131 131
 function recup_heure($date): array {
132 132
 
133
-	static $d = [0, 0, 0];
134
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
-		return $d;
136
-	}
133
+    static $d = [0, 0, 0];
134
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
135
+        return $d;
136
+    }
137 137
 
138
-	array_shift($r);
138
+    array_shift($r);
139 139
 
140
-	return $r;
140
+    return $r;
141 141
 }
142 142
 
143 143
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * @return string heures, sinon 0
152 152
  **/
153 153
 function heures($numdate): string {
154
-	$heures = null;
155
-	$date_array = recup_heure($numdate);
156
-	if ($date_array) {
157
-		[$heures, $minutes, $secondes] = $date_array;
158
-	}
154
+    $heures = null;
155
+    $date_array = recup_heure($numdate);
156
+    if ($date_array) {
157
+        [$heures, $minutes, $secondes] = $date_array;
158
+    }
159 159
 
160
-	return $heures;
160
+    return $heures;
161 161
 }
162 162
 
163 163
 /**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
  * @return string minutes, sinon 0
172 172
  **/
173 173
 function minutes($numdate): string {
174
-	$minutes = null;
175
-	$date_array = recup_heure($numdate);
176
-	if ($date_array) {
177
-		[$heures, $minutes, $secondes] = $date_array;
178
-	}
174
+    $minutes = null;
175
+    $date_array = recup_heure($numdate);
176
+    if ($date_array) {
177
+        [$heures, $minutes, $secondes] = $date_array;
178
+    }
179 179
 
180
-	return $minutes;
180
+    return $minutes;
181 181
 }
182 182
 
183 183
 /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @return string secondes, sinon 0
192 192
  **/
193 193
 function secondes($numdate): string {
194
-	$secondes = null;
195
-	$date_array = recup_heure($numdate);
196
-	if ($date_array) {
197
-		[$heures, $minutes, $secondes] = $date_array;
198
-	}
194
+    $secondes = null;
195
+    $date_array = recup_heure($numdate);
196
+    if ($date_array) {
197
+        [$heures, $minutes, $secondes] = $date_array;
198
+    }
199 199
 
200
-	return $secondes;
200
+    return $secondes;
201 201
 }
202 202
 
203 203
 /**
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
  * @return string L'heure formatée dans la langue en cours.
217 217
  **/
218 218
 function heures_minutes($numdate, $forme = ''): string {
219
-	if ($forme !== 'abbr') {
220
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
-	} else {
222
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
-	}
219
+    if ($forme !== 'abbr') {
220
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
221
+    } else {
222
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
223
+    }
224 224
 }
225 225
 
226 226
 /**
@@ -245,57 +245,57 @@  discard block
 block discarded – undo
245 245
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
246 246
  **/
247 247
 function recup_date($numdate, $forcer_jour = true): array {
248
-	if (!$numdate) {
249
-		return [];
250
-	}
251
-	$heures = $minutes = $secondes = 0;
252
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
-		$jour = $regs[1];
254
-		$mois = $regs[2];
255
-		$annee = $regs[3];
256
-		if ($annee < 90) {
257
-			$annee = 2000 + $annee;
258
-		} elseif ($annee < 100) {
259
-			$annee = 1900 + $annee;
260
-		}
261
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
262
-	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
-		$annee = $regs[1];
264
-		$mois = $regs[2];
265
-		$jour = $regs[3];
266
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
267
-	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
-		$annee = $regs[1];
269
-		$mois = $regs[2];
270
-		$jour = '';
271
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
272
-	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
-		$annee = $regs[1];
274
-		$mois = $regs[2];
275
-		$jour = $regs[3];
276
-		$heures = $regs[4];
277
-		$minutes = $regs[5];
278
-		$secondes = $regs[6];
279
-	} else {
280
-		$annee = $mois = $jour = '';
281
-	}
282
-	if ($annee > 4000) {
283
-		$annee -= 9000;
284
-	}
285
-	if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
-		$jour = substr($jour, 1);
287
-	}
288
-
289
-	if ($forcer_jour and $jour == '0') {
290
-		$jour = '1';
291
-	}
292
-	if ($forcer_jour and $mois == '0') {
293
-		$mois = '1';
294
-	}
295
-	if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
-	}
298
-	return [];
248
+    if (!$numdate) {
249
+        return [];
250
+    }
251
+    $heures = $minutes = $secondes = 0;
252
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
253
+        $jour = $regs[1];
254
+        $mois = $regs[2];
255
+        $annee = $regs[3];
256
+        if ($annee < 90) {
257
+            $annee = 2000 + $annee;
258
+        } elseif ($annee < 100) {
259
+            $annee = 1900 + $annee;
260
+        }
261
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
262
+    } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
263
+        $annee = $regs[1];
264
+        $mois = $regs[2];
265
+        $jour = $regs[3];
266
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
267
+    } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
268
+        $annee = $regs[1];
269
+        $mois = $regs[2];
270
+        $jour = '';
271
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
272
+    } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
273
+        $annee = $regs[1];
274
+        $mois = $regs[2];
275
+        $jour = $regs[3];
276
+        $heures = $regs[4];
277
+        $minutes = $regs[5];
278
+        $secondes = $regs[6];
279
+    } else {
280
+        $annee = $mois = $jour = '';
281
+    }
282
+    if ($annee > 4000) {
283
+        $annee -= 9000;
284
+    }
285
+    if (strlen($jour) and substr($jour, 0, 1) == '0') {
286
+        $jour = substr($jour, 1);
287
+    }
288
+
289
+    if ($forcer_jour and $jour == '0') {
290
+        $jour = '1';
291
+    }
292
+    if ($forcer_jour and $mois == '0') {
293
+        $mois = '1';
294
+    }
295
+    if ($annee or $mois or $jour or $heures or $minutes or $secondes) {
296
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
297
+    }
298
+    return [];
299 299
 }
300 300
 
301 301
 /**
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
  *     La date relative ou complète
323 323
  **/
324 324
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
325
-	return sinon(
326
-		date_relative($date, $decalage_maxi),
327
-		affdate_heure($date)
328
-	);
325
+    return sinon(
326
+        date_relative($date, $decalage_maxi),
327
+        affdate_heure($date)
328
+    );
329 329
 }
330 330
 
331 331
 /**
@@ -358,86 +358,86 @@  discard block
 block discarded – undo
358 358
  **/
359 359
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
360 360
 
361
-	if (!$date) {
362
-		return '';
363
-	}
364
-
365
-	if (is_null($ref_date)) {
366
-		$ref_time = time();
367
-	} else {
368
-		$ref_time = strtotime($ref_date);
369
-	}
370
-
371
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
372
-
373
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
-		return '';
375
-	}
376
-
377
-	if ($decal < 0) {
378
-		$il_y_a = 'date_dans';
379
-		$decal = -1 * $decal;
380
-	} else {
381
-		$il_y_a = 'date_il_y_a';
382
-	}
383
-
384
-	if ($decal > 3600 * 24 * 30 * 6) {
385
-		return affdate_court($date);
386
-	}
387
-
388
-	if ($decal > 3600 * 24 * 30) {
389
-		$mois = floor($decal / (3600 * 24 * 30));
390
-		if ($mois < 2) {
391
-			$delai = "$mois " . _T('date_un_mois');
392
-		} else {
393
-			$delai = "$mois " . _T('date_mois');
394
-		}
395
-	} else {
396
-		if ($decal > 3600 * 24 * 7) {
397
-			$semaines = floor($decal / (3600 * 24 * 7));
398
-			if ($semaines < 2) {
399
-				$delai = "$semaines " . _T('date_une_semaine');
400
-			} else {
401
-				$delai = "$semaines " . _T('date_semaines');
402
-			}
403
-		} else {
404
-			if ($decal > 3600 * 24) {
405
-				$jours = floor($decal / (3600 * 24));
406
-				if ($jours < 2) {
407
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
-				} else {
409
-					$delai = "$jours " . _T('date_jours');
410
-				}
411
-			} else {
412
-				if ($decal >= 3600) {
413
-					$heures = floor($decal / 3600);
414
-					if ($heures < 2) {
415
-						$delai = "$heures " . _T('date_une_heure');
416
-					} else {
417
-						$delai = "$heures " . _T('date_heures');
418
-					}
419
-				} else {
420
-					if ($decal >= 60) {
421
-						$minutes = floor($decal / 60);
422
-						if ($minutes < 2) {
423
-							$delai = "$minutes " . _T('date_une_minute');
424
-						} else {
425
-							$delai = "$minutes " . _T('date_minutes');
426
-						}
427
-					} else {
428
-						$secondes = ceil($decal);
429
-						if ($secondes < 2) {
430
-							$delai = "$secondes " . _T('date_une_seconde');
431
-						} else {
432
-							$delai = "$secondes " . _T('date_secondes');
433
-						}
434
-					}
435
-				}
436
-			}
437
-		}
438
-	}
439
-
440
-	return _T($il_y_a, ['delai' => $delai]);
361
+    if (!$date) {
362
+        return '';
363
+    }
364
+
365
+    if (is_null($ref_date)) {
366
+        $ref_time = time();
367
+    } else {
368
+        $ref_time = strtotime($ref_date);
369
+    }
370
+
371
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
372
+
373
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
374
+        return '';
375
+    }
376
+
377
+    if ($decal < 0) {
378
+        $il_y_a = 'date_dans';
379
+        $decal = -1 * $decal;
380
+    } else {
381
+        $il_y_a = 'date_il_y_a';
382
+    }
383
+
384
+    if ($decal > 3600 * 24 * 30 * 6) {
385
+        return affdate_court($date);
386
+    }
387
+
388
+    if ($decal > 3600 * 24 * 30) {
389
+        $mois = floor($decal / (3600 * 24 * 30));
390
+        if ($mois < 2) {
391
+            $delai = "$mois " . _T('date_un_mois');
392
+        } else {
393
+            $delai = "$mois " . _T('date_mois');
394
+        }
395
+    } else {
396
+        if ($decal > 3600 * 24 * 7) {
397
+            $semaines = floor($decal / (3600 * 24 * 7));
398
+            if ($semaines < 2) {
399
+                $delai = "$semaines " . _T('date_une_semaine');
400
+            } else {
401
+                $delai = "$semaines " . _T('date_semaines');
402
+            }
403
+        } else {
404
+            if ($decal > 3600 * 24) {
405
+                $jours = floor($decal / (3600 * 24));
406
+                if ($jours < 2) {
407
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
408
+                } else {
409
+                    $delai = "$jours " . _T('date_jours');
410
+                }
411
+            } else {
412
+                if ($decal >= 3600) {
413
+                    $heures = floor($decal / 3600);
414
+                    if ($heures < 2) {
415
+                        $delai = "$heures " . _T('date_une_heure');
416
+                    } else {
417
+                        $delai = "$heures " . _T('date_heures');
418
+                    }
419
+                } else {
420
+                    if ($decal >= 60) {
421
+                        $minutes = floor($decal / 60);
422
+                        if ($minutes < 2) {
423
+                            $delai = "$minutes " . _T('date_une_minute');
424
+                        } else {
425
+                            $delai = "$minutes " . _T('date_minutes');
426
+                        }
427
+                    } else {
428
+                        $secondes = ceil($decal);
429
+                        if ($secondes < 2) {
430
+                            $delai = "$secondes " . _T('date_une_seconde');
431
+                        } else {
432
+                            $delai = "$secondes " . _T('date_secondes');
433
+                        }
434
+                    }
435
+                }
436
+            }
437
+        }
438
+    }
439
+
440
+    return _T($il_y_a, ['delai' => $delai]);
441 441
 }
442 442
 
443 443
 
@@ -463,32 +463,32 @@  discard block
 block discarded – undo
463 463
  **/
464 464
 function date_relativecourt($date, $decalage_maxi = 0): string {
465 465
 
466
-	if (!$date) {
467
-		return '';
468
-	}
469
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
-
471
-	if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
-		return '';
473
-	}
474
-
475
-	if ($decal < -24 * 3600) {
476
-		$retour = date_relative($date, $decalage_maxi);
477
-	} elseif ($decal < 0) {
478
-		$retour = _T('date_demain');
479
-	} else {
480
-		if ($decal < (3600 * 24)) {
481
-			$retour = _T('date_aujourdhui');
482
-		} else {
483
-			if ($decal < (3600 * 24 * 2)) {
484
-				$retour = _T('date_hier');
485
-			} else {
486
-				$retour = date_relative($date, $decalage_maxi);
487
-			}
488
-		}
489
-	}
490
-
491
-	return $retour;
466
+    if (!$date) {
467
+        return '';
468
+    }
469
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
470
+
471
+    if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) {
472
+        return '';
473
+    }
474
+
475
+    if ($decal < -24 * 3600) {
476
+        $retour = date_relative($date, $decalage_maxi);
477
+    } elseif ($decal < 0) {
478
+        $retour = _T('date_demain');
479
+    } else {
480
+        if ($decal < (3600 * 24)) {
481
+            $retour = _T('date_aujourdhui');
482
+        } else {
483
+            if ($decal < (3600 * 24 * 2)) {
484
+                $retour = _T('date_hier');
485
+            } else {
486
+                $retour = date_relative($date, $decalage_maxi);
487
+            }
488
+        }
489
+    }
490
+
491
+    return $retour;
492 492
 }
493 493
 
494 494
 /**
@@ -505,174 +505,174 @@  discard block
 block discarded – undo
505 505
  * @return string
506 506
  */
507 507
 function affdate_base($numdate, $vue, $options = []): string {
508
-	if (is_string($options)) {
509
-		$options = ['param' => $options];
510
-	}
511
-	$date_array = recup_date($numdate, false);
512
-	if (!$date_array) {
513
-		return '';
514
-	}
515
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
-
517
-	// 1er, 21st, etc.
518
-	$journum = $jour;
519
-
520
-	if ($jour == 0) {
521
-		$jour = '';
522
-		$njour = 0;
523
-	} else {
524
-		$njour = intval($jour);
525
-		if ($jourth = _T('date_jnum' . $jour)) {
526
-			$jour = $jourth;
527
-		}
528
-	}
529
-
530
-	$mois = intval($mois);
531
-	if ($mois > 0 and $mois < 13) {
532
-		/* Traiter le cas "abbr" pour les noms de mois */
533
-		$param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
-		$nommois = _T('date_mois_' . $mois . $param);
535
-		if ($jour) {
536
-			$jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
-		} else {
538
-			$jourmois = $nommois;
539
-		}
540
-	} else {
541
-		$nommois = '';
542
-		$jourmois = '';
543
-	}
544
-
545
-	if ($annee < 0) {
546
-		$annee = -$annee . ' ' . _T('date_avant_jc');
547
-		$avjc = true;
548
-	} else {
549
-		$avjc = false;
550
-	}
551
-
552
-	switch ($vue) {
553
-		case 'saison':
554
-		case 'saison_annee':
555
-			$saison = '';
556
-			if ($mois > 0) {
557
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
558
-				if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
560
-				}
561
-				if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
563
-				}
564
-				if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
566
-				}
567
-				if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
569
-				}
570
-			}
571
-			if ($vue == 'saison') {
572
-				return $saison ? _T('date_saison_' . $saison) : '';
573
-			} else {
574
-				return $saison ? trim(_T(
575
-					'date_fmt_saison_annee',
576
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
-				)) : '';
578
-			}
579
-
580
-		case 'court':
581
-			if ($avjc) {
582
-				return $annee;
583
-			}
584
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
-				return $annee;
587
-			}
588
-			if ($annee != $a) {
589
-				return _T(
590
-					'date_fmt_mois_annee',
591
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
-				);
593
-			}
594
-
595
-			return _T(
596
-				'date_fmt_jour_mois',
597
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
-			);
599
-
600
-		case 'jourcourt':
601
-			if ($avjc) {
602
-				return $annee;
603
-			}
604
-			$a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
-			if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
-				return $annee;
607
-			}
608
-			if ($annee != $a) {
609
-				return _T(
610
-					'date_fmt_jour_mois_annee',
611
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
-				);
613
-			}
614
-
615
-			return _T(
616
-				'date_fmt_jour_mois',
617
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
-			);
619
-
620
-		case 'entier':
621
-			if ($avjc) {
622
-				return $annee;
623
-			}
624
-			if ($jour) {
625
-				return _T(
626
-					'date_fmt_jour_mois_annee',
627
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
-				);
629
-			} elseif ($mois) {
630
-				return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
-			} else {
632
-				return $annee;
633
-			}
634
-
635
-		case 'nom_mois':
636
-			return $nommois;
637
-
638
-		case 'mois':
639
-			return sprintf('%02s', $mois);
640
-
641
-		case 'jour':
642
-			return $jour;
643
-
644
-		case 'journum':
645
-			return $journum;
646
-
647
-		case 'nom_jour':
648
-			if (!$mois or !$njour) {
649
-				return '';
650
-			}
651
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
-			$nom = 1 + (int) date('w', $nom);
653
-			$param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
-
655
-			return _T('date_jour_' . $nom . $param);
656
-
657
-		case 'mois_annee':
658
-			if ($avjc) {
659
-				return $annee;
660
-			}
661
-
662
-			return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
-
664
-		case 'annee':
665
-			return $annee;
666
-
667
-		// Cas d'une vue non definie : retomber sur le format
668
-		// de date propose par http://www.php.net/date
669
-		default:
670
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
-				$time = strtotime($numdate);
673
-			}
674
-			return date($vue, $time);
675
-	}
508
+    if (is_string($options)) {
509
+        $options = ['param' => $options];
510
+    }
511
+    $date_array = recup_date($numdate, false);
512
+    if (!$date_array) {
513
+        return '';
514
+    }
515
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
516
+
517
+    // 1er, 21st, etc.
518
+    $journum = $jour;
519
+
520
+    if ($jour == 0) {
521
+        $jour = '';
522
+        $njour = 0;
523
+    } else {
524
+        $njour = intval($jour);
525
+        if ($jourth = _T('date_jnum' . $jour)) {
526
+            $jour = $jourth;
527
+        }
528
+    }
529
+
530
+    $mois = intval($mois);
531
+    if ($mois > 0 and $mois < 13) {
532
+        /* Traiter le cas "abbr" pour les noms de mois */
533
+        $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : '');
534
+        $nommois = _T('date_mois_' . $mois . $param);
535
+        if ($jour) {
536
+            $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]);
537
+        } else {
538
+            $jourmois = $nommois;
539
+        }
540
+    } else {
541
+        $nommois = '';
542
+        $jourmois = '';
543
+    }
544
+
545
+    if ($annee < 0) {
546
+        $annee = -$annee . ' ' . _T('date_avant_jc');
547
+        $avjc = true;
548
+    } else {
549
+        $avjc = false;
550
+    }
551
+
552
+    switch ($vue) {
553
+        case 'saison':
554
+        case 'saison_annee':
555
+            $saison = '';
556
+            if ($mois > 0) {
557
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
558
+                if (($mois == 3 and $jour >= 21) or $mois > 3) {
559
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
560
+                }
561
+                if (($mois == 6 and $jour >= 21) or $mois > 6) {
562
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
563
+                }
564
+                if (($mois == 9 and $jour >= 21) or $mois > 9) {
565
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
566
+                }
567
+                if (($mois == 12 and $jour >= 21) or $mois > 12) {
568
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
569
+                }
570
+            }
571
+            if ($vue == 'saison') {
572
+                return $saison ? _T('date_saison_' . $saison) : '';
573
+            } else {
574
+                return $saison ? trim(_T(
575
+                    'date_fmt_saison_annee',
576
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
577
+                )) : '';
578
+            }
579
+
580
+        case 'court':
581
+            if ($avjc) {
582
+                return $annee;
583
+            }
584
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
585
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
586
+                return $annee;
587
+            }
588
+            if ($annee != $a) {
589
+                return _T(
590
+                    'date_fmt_mois_annee',
591
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
592
+                );
593
+            }
594
+
595
+            return _T(
596
+                'date_fmt_jour_mois',
597
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
598
+            );
599
+
600
+        case 'jourcourt':
601
+            if ($avjc) {
602
+                return $annee;
603
+            }
604
+            $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
605
+            if ($annee < ($a - 100) or $annee > ($a + 100)) {
606
+                return $annee;
607
+            }
608
+            if ($annee != $a) {
609
+                return _T(
610
+                    'date_fmt_jour_mois_annee',
611
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
612
+                );
613
+            }
614
+
615
+            return _T(
616
+                'date_fmt_jour_mois',
617
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
618
+            );
619
+
620
+        case 'entier':
621
+            if ($avjc) {
622
+                return $annee;
623
+            }
624
+            if ($jour) {
625
+                return _T(
626
+                    'date_fmt_jour_mois_annee',
627
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
628
+                );
629
+            } elseif ($mois) {
630
+                return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
631
+            } else {
632
+                return $annee;
633
+            }
634
+
635
+        case 'nom_mois':
636
+            return $nommois;
637
+
638
+        case 'mois':
639
+            return sprintf('%02s', $mois);
640
+
641
+        case 'jour':
642
+            return $jour;
643
+
644
+        case 'journum':
645
+            return $journum;
646
+
647
+        case 'nom_jour':
648
+            if (!$mois or !$njour) {
649
+                return '';
650
+            }
651
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
652
+            $nom = 1 + (int) date('w', $nom);
653
+            $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : '');
654
+
655
+            return _T('date_jour_' . $nom . $param);
656
+
657
+        case 'mois_annee':
658
+            if ($avjc) {
659
+                return $annee;
660
+            }
661
+
662
+            return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
663
+
664
+        case 'annee':
665
+            return $annee;
666
+
667
+        // Cas d'une vue non definie : retomber sur le format
668
+        // de date propose par http://www.php.net/date
669
+        default:
670
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
671
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) {
672
+                $time = strtotime($numdate);
673
+            }
674
+            return date($vue, $time);
675
+    }
676 676
 }
677 677
 
678 678
 
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
699 699
  *     Nom du jour
700 700
  **/
701 701
 function nom_jour($numdate, $forme = ''): string {
702
-	if (!($forme === 'abbr' or $forme === 'initiale')) {
703
-		$forme = '';
704
-	}
702
+    if (!($forme === 'abbr' or $forme === 'initiale')) {
703
+        $forme = '';
704
+    }
705 705
 
706
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
706
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
707 707
 }
708 708
 
709 709
 /**
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
  *     Numéro du jour
726 726
  **/
727 727
 function jour($numdate): string {
728
-	return affdate_base($numdate, 'jour');
728
+    return affdate_base($numdate, 'jour');
729 729
 }
730 730
 
731 731
 /**
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
  *     Numéro du jour
744 744
  **/
745 745
 function journum($numdate): string {
746
-	return affdate_base($numdate, 'journum');
746
+    return affdate_base($numdate, 'journum');
747 747
 }
748 748
 
749 749
 /**
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
  *     Numéro du mois (sur 2 chiffres)
762 762
  **/
763 763
 function mois($numdate): string {
764
-	return  affdate_base($numdate, 'mois');
764
+    return  affdate_base($numdate, 'mois');
765 765
 }
766 766
 
767 767
 /**
@@ -785,11 +785,11 @@  discard block
 block discarded – undo
785 785
  *     Nom du mois
786 786
  **/
787 787
 function nom_mois($numdate, $forme = ''): string {
788
-	if (!($forme === 'abbr')) {
789
-		$forme = '';
790
-	}
788
+    if (!($forme === 'abbr')) {
789
+        $forme = '';
790
+    }
791 791
 
792
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
792
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
793 793
 }
794 794
 
795 795
 /**
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
  *     Année (sur 4 chiffres)
808 808
  **/
809 809
 function annee($numdate): string {
810
-	return affdate_base($numdate, 'annee');
810
+    return affdate_base($numdate, 'annee');
811 811
 }
812 812
 
813 813
 
@@ -837,11 +837,11 @@  discard block
 block discarded – undo
837 837
  *     La date formatée
838 838
  **/
839 839
 function saison($numdate, $hemisphere = 'nord'): string {
840
-	if ($hemisphere !== 'sud') {
841
-		$hemisphere = 'nord';
842
-	}
840
+    if ($hemisphere !== 'sud') {
841
+        $hemisphere = 'nord';
842
+    }
843 843
 
844
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
844
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
845 845
 }
846 846
 
847 847
 
@@ -870,11 +870,11 @@  discard block
 block discarded – undo
870 870
  *     La date formatée
871 871
  **/
872 872
 function saison_annee($numdate, $hemisphere = 'nord'): string {
873
-	if ($hemisphere !== 'sud') {
874
-		$hemisphere = 'nord';
875
-	}
873
+    if ($hemisphere !== 'sud') {
874
+        $hemisphere = 'nord';
875
+    }
876 876
 
877
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
877
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
878 878
 }
879 879
 
880 880
 /**
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
  *     La date formatée
903 903
  **/
904 904
 function affdate($numdate, $format = 'entier'): string {
905
-	return affdate_base($numdate, $format);
905
+    return affdate_base($numdate, $format);
906 906
 }
907 907
 
908 908
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
  *     La date formatée
930 930
  **/
931 931
 function affdate_court($numdate, $annee_courante = null): string {
932
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
932
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
933 933
 }
934 934
 
935 935
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *     La date formatée
957 957
  **/
958 958
 function affdate_jourcourt($numdate, $annee_courante = null): string {
959
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
959
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
960 960
 }
961 961
 
962 962
 /**
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  *     La date formatée
975 975
  **/
976 976
 function affdate_mois_annee($numdate): string {
977
-	return affdate_base($numdate, 'mois_annee');
977
+    return affdate_base($numdate, 'mois_annee');
978 978
 }
979 979
 
980 980
 /**
@@ -992,16 +992,16 @@  discard block
 block discarded – undo
992 992
  *     La date formatée, sinon ''
993 993
  **/
994 994
 function affdate_heure($numdate): string {
995
-	$date_array = recup_date($numdate);
996
-	if (!$date_array) {
997
-		return '';
998
-	}
999
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
-
1001
-	return _T('date_fmt_jour_heure', [
1002
-		'jour' => affdate($numdate),
1003
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
-	]);
995
+    $date_array = recup_date($numdate);
996
+    if (!$date_array) {
997
+        return '';
998
+    }
999
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
1000
+
1001
+    return _T('date_fmt_jour_heure', [
1002
+        'jour' => affdate($numdate),
1003
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
1004
+    ]);
1005 1005
 }
1006 1006
 
1007 1007
 /**
@@ -1033,117 +1033,117 @@  discard block
 block discarded – undo
1033 1033
  *     texte de la date
1034 1034
  */
1035 1035
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
1036
-	$abbr = $jour = '';
1037
-	$affdate = 'affdate_jourcourt';
1038
-	if (strpos($forme, 'abbr') !== false) {
1039
-		$abbr = 'abbr';
1040
-	}
1041
-	if (strpos($forme, 'annee') !== false) {
1042
-		$affdate = 'affdate';
1043
-	}
1044
-	if (strpos($forme, 'jour') !== false) {
1045
-		$jour = 'jour';
1046
-	}
1047
-
1048
-	$dtstart = $dtend = $dtabbr = '';
1049
-	if (strpos($forme, 'hcal') !== false) {
1050
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
-		$dtabbr = '</abbr>';
1053
-	}
1054
-
1055
-	$date_debut = strtotime($date_debut);
1056
-	$date_fin = strtotime($date_fin);
1057
-	$d = date('Y-m-d', $date_debut);
1058
-	$f = date('Y-m-d', $date_fin);
1059
-	$h = ($horaire === 'oui' or $horaire === true);
1060
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
-
1063
-	if ($d == $f) { // meme jour
1064
-		$nomjour = nom_jour($d, $abbr);
1065
-		$s = $affdate($d);
1066
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
-		if ($h) {
1068
-			if ($hd == $hf) {
1069
-				// Lundi 20 fevrier a 18h25
1070
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
-				$s = "$dtstart$s$dtabbr";
1072
-			} else {
1073
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
-				if ($dtabbr && $dtstart && $dtend) {
1075
-					$s = _T(
1076
-						'date_fmt_jour_heure_debut_fin_abbr',
1077
-						[
1078
-						'jour' => spip_ucfirst($s),
1079
-						'heure_debut' => $hd,
1080
-						'heure_fin' => $hf,
1081
-						'dtstart' => $dtstart,
1082
-						'dtend' => $dtend,
1083
-						'dtabbr' => $dtabbr
1084
-						],
1085
-						[
1086
-							'sanitize' => false
1087
-						]
1088
-					);
1089
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1090
-				else {
1091
-					$s = spip_ucfirst(_T(
1092
-						'date_fmt_jour_heure_debut_fin',
1093
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
-					));
1095
-				}
1096
-			}
1097
-		} else {
1098
-			if ($dtabbr && $dtstart) {
1099
-				$s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
-			} else {
1101
-				$s = spip_ucfirst($s);
1102
-			}
1103
-		}
1104
-	} else {
1105
-		if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
-			if (!$h) {
1107
-				$date_debut = jour($d);
1108
-			} else {
1109
-				$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
-			}
1111
-			$date_fin = $affdate($f);
1112
-			if ($jour) {
1113
-				$nomjour_debut = nom_jour($d, $abbr);
1114
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
-				$nomjour_fin = nom_jour($f, $abbr);
1116
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
-			}
1118
-			if ($h) {
1119
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
-			}
1122
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1123
-			$date_fin = $dtend . $date_fin . $dtabbr;
1124
-
1125
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
-		} else {
1127
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
-			$date_fin = $affdate($f);
1129
-			if ($jour) {
1130
-				$nomjour_debut = nom_jour($d, $abbr);
1131
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
-				$nomjour_fin = nom_jour($f, $abbr);
1133
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
-			}
1135
-			if ($h) {
1136
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
-			}
1139
-
1140
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1141
-			$date_fin = $dtend . $date_fin . $dtabbr;
1142
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
-		}
1144
-	}
1145
-
1146
-	return $s;
1036
+    $abbr = $jour = '';
1037
+    $affdate = 'affdate_jourcourt';
1038
+    if (strpos($forme, 'abbr') !== false) {
1039
+        $abbr = 'abbr';
1040
+    }
1041
+    if (strpos($forme, 'annee') !== false) {
1042
+        $affdate = 'affdate';
1043
+    }
1044
+    if (strpos($forme, 'jour') !== false) {
1045
+        $jour = 'jour';
1046
+    }
1047
+
1048
+    $dtstart = $dtend = $dtabbr = '';
1049
+    if (strpos($forme, 'hcal') !== false) {
1050
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1051
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1052
+        $dtabbr = '</abbr>';
1053
+    }
1054
+
1055
+    $date_debut = strtotime($date_debut);
1056
+    $date_fin = strtotime($date_fin);
1057
+    $d = date('Y-m-d', $date_debut);
1058
+    $f = date('Y-m-d', $date_fin);
1059
+    $h = ($horaire === 'oui' or $horaire === true);
1060
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1061
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1062
+
1063
+    if ($d == $f) { // meme jour
1064
+        $nomjour = nom_jour($d, $abbr);
1065
+        $s = $affdate($d);
1066
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1067
+        if ($h) {
1068
+            if ($hd == $hf) {
1069
+                // Lundi 20 fevrier a 18h25
1070
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1071
+                $s = "$dtstart$s$dtabbr";
1072
+            } else {
1073
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1074
+                if ($dtabbr && $dtstart && $dtend) {
1075
+                    $s = _T(
1076
+                        'date_fmt_jour_heure_debut_fin_abbr',
1077
+                        [
1078
+                        'jour' => spip_ucfirst($s),
1079
+                        'heure_debut' => $hd,
1080
+                        'heure_fin' => $hf,
1081
+                        'dtstart' => $dtstart,
1082
+                        'dtend' => $dtend,
1083
+                        'dtabbr' => $dtabbr
1084
+                        ],
1085
+                        [
1086
+                            'sanitize' => false
1087
+                        ]
1088
+                    );
1089
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1090
+                else {
1091
+                    $s = spip_ucfirst(_T(
1092
+                        'date_fmt_jour_heure_debut_fin',
1093
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1094
+                    ));
1095
+                }
1096
+            }
1097
+        } else {
1098
+            if ($dtabbr && $dtstart) {
1099
+                $s = $dtstart . spip_ucfirst($s) . $dtabbr;
1100
+            } else {
1101
+                $s = spip_ucfirst($s);
1102
+            }
1103
+        }
1104
+    } else {
1105
+        if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1106
+            if (!$h) {
1107
+                $date_debut = jour($d);
1108
+            } else {
1109
+                $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1110
+            }
1111
+            $date_fin = $affdate($f);
1112
+            if ($jour) {
1113
+                $nomjour_debut = nom_jour($d, $abbr);
1114
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1115
+                $nomjour_fin = nom_jour($f, $abbr);
1116
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1117
+            }
1118
+            if ($h) {
1119
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1120
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1121
+            }
1122
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1123
+            $date_fin = $dtend . $date_fin . $dtabbr;
1124
+
1125
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1126
+        } else {
1127
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1128
+            $date_fin = $affdate($f);
1129
+            if ($jour) {
1130
+                $nomjour_debut = nom_jour($d, $abbr);
1131
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1132
+                $nomjour_fin = nom_jour($f, $abbr);
1133
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1134
+            }
1135
+            if ($h) {
1136
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1137
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1138
+            }
1139
+
1140
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1141
+            $date_fin = $dtend . $date_fin . $dtabbr;
1142
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1143
+        }
1144
+    }
1145
+
1146
+    return $s;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1164,10 +1164,10 @@  discard block
 block discarded – undo
1164 1164
  *     Date au format ical
1165 1165
  **/
1166 1166
 function date_ical($date, $addminutes = 0): string {
1167
-	[$heures, $minutes, $secondes] = recup_heure($date);
1168
-	[$annee, $mois, $jour] = recup_date($date);
1167
+    [$heures, $minutes, $secondes] = recup_heure($date);
1168
+    [$annee, $mois, $jour] = recup_date($date);
1169 1169
 
1170
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1170
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1171 1171
 }
1172 1172
 
1173 1173
 
@@ -1191,11 +1191,11 @@  discard block
 block discarded – undo
1191 1191
  *     La date formatée
1192 1192
  **/
1193 1193
 function date_iso($date_heure): string {
1194
-	[$annee, $mois, $jour] = recup_date($date_heure);
1195
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1194
+    [$annee, $mois, $jour] = recup_date($date_heure);
1195
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1196
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1197 1197
 
1198
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1198
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1199 1199
 }
1200 1200
 
1201 1201
 /**
@@ -1218,11 +1218,11 @@  discard block
 block discarded – undo
1218 1218
  *     La date formatée
1219 1219
  **/
1220 1220
 function date_822($date_heure): string {
1221
-	[$annee, $mois, $jour] = recup_date($date_heure);
1222
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1221
+    [$annee, $mois, $jour] = recup_date($date_heure);
1222
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1223
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1224 1224
 
1225
-	return date('r', $time);
1225
+    return date('r', $time);
1226 1226
 }
1227 1227
 
1228 1228
 /**
@@ -1238,11 +1238,11 @@  discard block
 block discarded – undo
1238 1238
  *     Date au format `Ymd`
1239 1239
  **/
1240 1240
 function date_anneemoisjour($d): string {
1241
-	if (!$d) {
1242
-		$d = date('Y-m-d');
1243
-	}
1241
+    if (!$d) {
1242
+        $d = date('Y-m-d');
1243
+    }
1244 1244
 
1245
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1245
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1246 1246
 }
1247 1247
 
1248 1248
 /**
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
  *     Date au format `Ym`
1259 1259
  **/
1260 1260
 function date_anneemois($d): string {
1261
-	if (!$d) {
1262
-		$d = date('Y-m-d');
1263
-	}
1261
+    if (!$d) {
1262
+        $d = date('Y-m-d');
1263
+    }
1264 1264
 
1265
-	return substr($d, 0, 4) . substr($d, 5, 2);
1265
+    return substr($d, 0, 4) . substr($d, 5, 2);
1266 1266
 }
1267 1267
 
1268 1268
 /**
@@ -1278,13 +1278,13 @@  discard block
 block discarded – undo
1278 1278
  *     Date au lundi de la même semaine au format `Ymd`
1279 1279
  **/
1280 1280
 function date_debut_semaine($annee, $mois, $jour): string {
1281
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
-	if ($w_day == 0) {
1283
-		$w_day = 7;
1284
-	} // Gaffe: le dimanche est zero
1285
-	$debut = $jour - $w_day + 1;
1281
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1282
+    if ($w_day == 0) {
1283
+        $w_day = 7;
1284
+    } // Gaffe: le dimanche est zero
1285
+    $debut = $jour - $w_day + 1;
1286 1286
 
1287
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1287
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1288 1288
 }
1289 1289
 
1290 1290
 /**
@@ -1300,11 +1300,11 @@  discard block
 block discarded – undo
1300 1300
  *     Date au dimanche de la même semaine au format `Ymd`
1301 1301
  **/
1302 1302
 function date_fin_semaine($annee, $mois, $jour): string {
1303
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
-	if ($w_day == 0) {
1305
-		$w_day = 7;
1306
-	} // Gaffe: le dimanche est zero
1307
-	$debut = $jour - $w_day + 1;
1303
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1304
+    if ($w_day == 0) {
1305
+        $w_day = 7;
1306
+    } // Gaffe: le dimanche est zero
1307
+    $debut = $jour - $w_day + 1;
1308 1308
 
1309
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1309
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1310 1310
 }
Please login to merge, or discard this patch.
ecrire/inc/texte.php 1 patch
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/texte_mini');
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return array Tablea ('','')
35 35
  */
36 36
 function definir_raccourcis_alineas() {
37
-	return ['', ''];
37
+    return ['', ''];
38 38
 }
39 39
 
40 40
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  * @return string
48 48
  */
49 49
 function traiter_tableau($bloc) {
50
-	return $bloc;
50
+    return $bloc;
51 51
 }
52 52
 
53 53
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
  * @return string
62 62
  */
63 63
 function traiter_listes($texte) {
64
-	return $texte;
64
+    return $texte;
65 65
 }
66 66
 
67 67
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function traiter_raccourcis($letexte) {
79 79
 
80
-	// Appeler les fonctions de pre_traitement
81
-	$letexte = pipeline('pre_propre', $letexte);
80
+    // Appeler les fonctions de pre_traitement
81
+    $letexte = pipeline('pre_propre', $letexte);
82 82
 
83
-	// APPELER ICI UN PIPELINE traiter_raccourcis ?
84
-	// $letexte = pipeline('traiter_raccourcis', $letexte);
83
+    // APPELER ICI UN PIPELINE traiter_raccourcis ?
84
+    // $letexte = pipeline('traiter_raccourcis', $letexte);
85 85
 
86
-	// Appeler les fonctions de post-traitement
87
-	$letexte = pipeline('post_propre', $letexte);
86
+    // Appeler les fonctions de post-traitement
87
+    $letexte = pipeline('post_propre', $letexte);
88 88
 
89
-	return $letexte;
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /*************************************************************************************************************************
@@ -102,22 +102,22 @@  discard block
 block discarded – undo
102 102
  * @return string
103 103
  */
104 104
 function echappe_js($t, $class = ' class = "echappe-js"') {
105
-	foreach (['script', 'iframe'] as $tag) {
106
-		if (
107
-			stripos($t, (string) "<$tag") !== false
108
-			and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
109
-		) {
110
-			foreach ($r as $regs) {
111
-				$t = str_replace(
112
-					$regs[0],
113
-					"<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
114
-					$t
115
-				);
116
-			}
117
-		}
118
-	}
119
-
120
-	return $t;
105
+    foreach (['script', 'iframe'] as $tag) {
106
+        if (
107
+            stripos($t, (string) "<$tag") !== false
108
+            and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER)
109
+        ) {
110
+            foreach ($r as $regs) {
111
+                $t = str_replace(
112
+                    $regs[0],
113
+                    "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>',
114
+                    $t
115
+                );
116
+            }
117
+        }
118
+    }
119
+
120
+    return $t;
121 121
 }
122 122
 
123 123
 
@@ -146,55 +146,55 @@  discard block
 block discarded – undo
146 146
  *     Code protégé
147 147
  **/
148 148
 function interdire_scripts($arg, $mode_filtre = null) {
149
-	// on memorise le resultat sur les arguments non triviaux
150
-	static $dejavu = [];
151
-
152
-	// Attention, si ce n'est pas une chaine, laisser intact
153
-	if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
154
-		return $arg;
155
-	}
156
-
157
-	if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
158
-		$mode_filtre = $GLOBALS['filtrer_javascript'];
159
-	}
160
-
161
-	if (isset($dejavu[$mode_filtre][$arg])) {
162
-		return $dejavu[$mode_filtre][$arg];
163
-	}
164
-
165
-	// echapper les tags asp/php
166
-	$t = str_replace('<' . '%', '&lt;%', $arg);
167
-
168
-	// echapper le php
169
-	$t = str_replace('<' . '?', '&lt;?', $t);
170
-
171
-	// echapper le < script language=php >
172
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
173
-
174
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
175
-	switch ($mode_filtre) {
176
-		case 0:
177
-			if (!_DIR_RESTREINT) {
178
-				$t = echappe_js($t);
179
-			}
180
-			break;
181
-		case -1:
182
-			$t = echappe_js($t);
183
-			break;
184
-	}
185
-
186
-	// pas de <base href /> svp !
187
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
188
-
189
-	// Reinserer les echappements des modeles
190
-	if (defined('_PROTEGE_JS_MODELES')) {
191
-		$t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
192
-	}
193
-	if (defined('_PROTEGE_PHP_MODELES')) {
194
-		$t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
195
-	}
196
-
197
-	return $dejavu[$mode_filtre][$arg] = $t;
149
+    // on memorise le resultat sur les arguments non triviaux
150
+    static $dejavu = [];
151
+
152
+    // Attention, si ce n'est pas une chaine, laisser intact
153
+    if (!$arg or !is_string($arg) or !strstr($arg, '<')) {
154
+        return $arg;
155
+    }
156
+
157
+    if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
158
+        $mode_filtre = $GLOBALS['filtrer_javascript'];
159
+    }
160
+
161
+    if (isset($dejavu[$mode_filtre][$arg])) {
162
+        return $dejavu[$mode_filtre][$arg];
163
+    }
164
+
165
+    // echapper les tags asp/php
166
+    $t = str_replace('<' . '%', '&lt;%', $arg);
167
+
168
+    // echapper le php
169
+    $t = str_replace('<' . '?', '&lt;?', $t);
170
+
171
+    // echapper le < script language=php >
172
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
173
+
174
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
175
+    switch ($mode_filtre) {
176
+        case 0:
177
+            if (!_DIR_RESTREINT) {
178
+                $t = echappe_js($t);
179
+            }
180
+            break;
181
+        case -1:
182
+            $t = echappe_js($t);
183
+            break;
184
+    }
185
+
186
+    // pas de <base href /> svp !
187
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
188
+
189
+    // Reinserer les echappements des modeles
190
+    if (defined('_PROTEGE_JS_MODELES')) {
191
+        $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
192
+    }
193
+    if (defined('_PROTEGE_PHP_MODELES')) {
194
+        $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
195
+    }
196
+
197
+    return $dejavu[$mode_filtre][$arg] = $t;
198 198
 }
199 199
 
200 200
 
@@ -223,66 +223,66 @@  discard block
 block discarded – undo
223 223
  *     texte transformé
224 224
  **/
225 225
 function typo($letexte, $echapper = true, $connect = null, $env = []) {
226
-	// Plus vite !
227
-	if (!$letexte) {
228
-		return $letexte;
229
-	}
230
-
231
-	// les appels directs a cette fonction depuis le php de l'espace
232
-	// prive etant historiquement ecrit sans argment $connect
233
-	// on utilise la presence de celui-ci pour distinguer les cas
234
-	// ou il faut passer interdire_script explicitement
235
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
236
-	// ne seront pas perturbes
237
-	$interdire_script = false;
238
-	if (is_null($connect)) {
239
-		$connect = '';
240
-		$interdire_script = true;
241
-		$env['espace_prive'] = test_espace_prive();
242
-	}
243
-
244
-	// Echapper les codes <html> etc
245
-	if ($echapper) {
246
-		$letexte = echappe_html($letexte, 'TYPO');
247
-	}
248
-
249
-	//
250
-	// Installer les modeles, notamment images et documents ;
251
-	//
252
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
253
-	// cf. inc/lien
254
-
255
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env);
256
-	if ($letexte != $mem) {
257
-		$echapper = true;
258
-	}
259
-	unset($mem);
260
-
261
-	$letexte = corriger_typo($letexte);
262
-	$letexte = echapper_faux_tags($letexte);
263
-
264
-	// reintegrer les echappements
265
-	if ($echapper) {
266
-		$letexte = echappe_retour($letexte, 'TYPO');
267
-	}
268
-
269
-	// Dans les appels directs hors squelette, securiser ici aussi
270
-	if ($interdire_script) {
271
-		$letexte = interdire_scripts($letexte);
272
-	}
273
-
274
-	// Dans l'espace prive on se mefie de tout contenu dangereux
275
-	// https://core.spip.net/issues/3371
276
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
277
-	// https://core.spip.net/issues/4166
278
-	if (
279
-		$GLOBALS['filtrer_javascript'] == -1
280
-		or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
281
-	) {
282
-		$letexte = echapper_html_suspect($letexte, [], $connect, $env);
283
-	}
284
-
285
-	return $letexte;
226
+    // Plus vite !
227
+    if (!$letexte) {
228
+        return $letexte;
229
+    }
230
+
231
+    // les appels directs a cette fonction depuis le php de l'espace
232
+    // prive etant historiquement ecrit sans argment $connect
233
+    // on utilise la presence de celui-ci pour distinguer les cas
234
+    // ou il faut passer interdire_script explicitement
235
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
236
+    // ne seront pas perturbes
237
+    $interdire_script = false;
238
+    if (is_null($connect)) {
239
+        $connect = '';
240
+        $interdire_script = true;
241
+        $env['espace_prive'] = test_espace_prive();
242
+    }
243
+
244
+    // Echapper les codes <html> etc
245
+    if ($echapper) {
246
+        $letexte = echappe_html($letexte, 'TYPO');
247
+    }
248
+
249
+    //
250
+    // Installer les modeles, notamment images et documents ;
251
+    //
252
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
253
+    // cf. inc/lien
254
+
255
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env);
256
+    if ($letexte != $mem) {
257
+        $echapper = true;
258
+    }
259
+    unset($mem);
260
+
261
+    $letexte = corriger_typo($letexte);
262
+    $letexte = echapper_faux_tags($letexte);
263
+
264
+    // reintegrer les echappements
265
+    if ($echapper) {
266
+        $letexte = echappe_retour($letexte, 'TYPO');
267
+    }
268
+
269
+    // Dans les appels directs hors squelette, securiser ici aussi
270
+    if ($interdire_script) {
271
+        $letexte = interdire_scripts($letexte);
272
+    }
273
+
274
+    // Dans l'espace prive on se mefie de tout contenu dangereux
275
+    // https://core.spip.net/issues/3371
276
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
277
+    // https://core.spip.net/issues/4166
278
+    if (
279
+        $GLOBALS['filtrer_javascript'] == -1
280
+        or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
281
+    ) {
282
+        $letexte = echapper_html_suspect($letexte, [], $connect, $env);
283
+    }
284
+
285
+    return $letexte;
286 286
 }
287 287
 
288 288
 // Correcteur typographique
@@ -307,57 +307,57 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function corriger_typo($letexte, $lang = '') {
309 309
 
310
-	// Plus vite !
311
-	if (!$letexte) {
312
-		return $letexte;
313
-	}
314
-
315
-	$letexte = pipeline('pre_typo', $letexte);
316
-
317
-	// Caracteres de controle "illegaux"
318
-	$letexte = corriger_caracteres($letexte);
319
-
320
-	// Proteger les caracteres typographiques a l'interieur des tags html
321
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
322
-		foreach ($regs as $reg) {
323
-			$insert = $reg[0];
324
-			// hack: on transforme les caracteres a proteger en les remplacant
325
-			// par des caracteres "illegaux". (cf corriger_caracteres())
326
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
327
-			$letexte = str_replace($reg[0], $insert, $letexte);
328
-		}
329
-	}
330
-
331
-	// trouver les blocs idiomes et les traiter à part
332
-	$letexte = extraire_idiome($ei = $letexte, $lang, true);
333
-	$ei = ($ei !== $letexte);
334
-
335
-	// trouver les blocs multi et les traiter a part
336
-	$letexte = extraire_multi($em = $letexte, $lang, true);
337
-	$em = ($em !== $letexte);
338
-
339
-	// Charger & appliquer les fonctions de typographie
340
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
341
-	$letexte = $typographie($letexte);
342
-
343
-	// Les citations en une autre langue, s'il y a lieu
344
-	if ($em) {
345
-		$letexte = echappe_retour($letexte, 'multi');
346
-	}
347
-	if ($ei) {
348
-		$letexte = echappe_retour($letexte, 'idiome');
349
-	}
350
-
351
-	// Retablir les caracteres proteges
352
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
353
-
354
-	// pipeline
355
-	$letexte = pipeline('post_typo', $letexte);
356
-
357
-	# un message pour abs_url - on est passe en mode texte
358
-	$GLOBALS['mode_abs_url'] = 'texte';
359
-
360
-	return $letexte;
310
+    // Plus vite !
311
+    if (!$letexte) {
312
+        return $letexte;
313
+    }
314
+
315
+    $letexte = pipeline('pre_typo', $letexte);
316
+
317
+    // Caracteres de controle "illegaux"
318
+    $letexte = corriger_caracteres($letexte);
319
+
320
+    // Proteger les caracteres typographiques a l'interieur des tags html
321
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
322
+        foreach ($regs as $reg) {
323
+            $insert = $reg[0];
324
+            // hack: on transforme les caracteres a proteger en les remplacant
325
+            // par des caracteres "illegaux". (cf corriger_caracteres())
326
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
327
+            $letexte = str_replace($reg[0], $insert, $letexte);
328
+        }
329
+    }
330
+
331
+    // trouver les blocs idiomes et les traiter à part
332
+    $letexte = extraire_idiome($ei = $letexte, $lang, true);
333
+    $ei = ($ei !== $letexte);
334
+
335
+    // trouver les blocs multi et les traiter a part
336
+    $letexte = extraire_multi($em = $letexte, $lang, true);
337
+    $em = ($em !== $letexte);
338
+
339
+    // Charger & appliquer les fonctions de typographie
340
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
341
+    $letexte = $typographie($letexte);
342
+
343
+    // Les citations en une autre langue, s'il y a lieu
344
+    if ($em) {
345
+        $letexte = echappe_retour($letexte, 'multi');
346
+    }
347
+    if ($ei) {
348
+        $letexte = echappe_retour($letexte, 'idiome');
349
+    }
350
+
351
+    // Retablir les caracteres proteges
352
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
353
+
354
+    // pipeline
355
+    $letexte = pipeline('post_typo', $letexte);
356
+
357
+    # un message pour abs_url - on est passe en mode texte
358
+    $GLOBALS['mode_abs_url'] = 'texte';
359
+
360
+    return $letexte;
361 361
 }
362 362
 
363 363
 
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
  * @return string
374 374
  */
375 375
 function paragrapher($letexte, $forcer = true) {
376
-	return $letexte;
376
+    return $letexte;
377 377
 }
378 378
 
379 379
 /**
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
  * @return string texte
386 386
  **/
387 387
 function traiter_retours_chariots($letexte) {
388
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
389
-	$letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
390
-	$letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
388
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
389
+    $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte);
390
+    $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte);
391 391
 
392
-	return $letexte;
392
+    return $letexte;
393 393
 }
394 394
 
395 395
 
@@ -415,40 +415,40 @@  discard block
 block discarded – undo
415 415
  *     texte transformé
416 416
  **/
417 417
 function propre($t, $connect = null, $env = []) {
418
-	// les appels directs a cette fonction depuis le php de l'espace
419
-	// prive etant historiquement ecrits sans argment $connect
420
-	// on utilise la presence de celui-ci pour distinguer les cas
421
-	// ou il faut passer interdire_script explicitement
422
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
423
-	// ne seront pas perturbes
424
-	$interdire_script = false;
425
-	if (is_null($connect)) {
426
-		$connect = '';
427
-		$interdire_script = true;
428
-		$env['espace_prive'] = true;
429
-	}
430
-
431
-	if (!$t) {
432
-		return strval($t);
433
-	}
434
-
435
-	// Dans l'espace prive on se mefie de tout contenu dangereux
436
-	// avant echappement des balises <html>
437
-	// https://core.spip.net/issues/3371
438
-	// et aussi dans l'espace public si la globale filtrer_javascript = -1
439
-	// https://core.spip.net/issues/4166
440
-	if (
441
-		$interdire_script
442
-		or $GLOBALS['filtrer_javascript'] == -1
443
-		or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0)
444
-		or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
445
-	) {
446
-		$t = echapper_html_suspect($t, ['strict' => false], $connect, $env);
447
-	}
448
-	$t = echappe_html($t);
449
-	$t = expanser_liens($t, $connect, $env);
450
-	$t = traiter_raccourcis($t);
451
-	$t = echappe_retour_modeles($t, $interdire_script);
452
-
453
-	return $t;
418
+    // les appels directs a cette fonction depuis le php de l'espace
419
+    // prive etant historiquement ecrits sans argment $connect
420
+    // on utilise la presence de celui-ci pour distinguer les cas
421
+    // ou il faut passer interdire_script explicitement
422
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
423
+    // ne seront pas perturbes
424
+    $interdire_script = false;
425
+    if (is_null($connect)) {
426
+        $connect = '';
427
+        $interdire_script = true;
428
+        $env['espace_prive'] = true;
429
+    }
430
+
431
+    if (!$t) {
432
+        return strval($t);
433
+    }
434
+
435
+    // Dans l'espace prive on se mefie de tout contenu dangereux
436
+    // avant echappement des balises <html>
437
+    // https://core.spip.net/issues/3371
438
+    // et aussi dans l'espace public si la globale filtrer_javascript = -1
439
+    // https://core.spip.net/issues/4166
440
+    if (
441
+        $interdire_script
442
+        or $GLOBALS['filtrer_javascript'] == -1
443
+        or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0)
444
+        or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
445
+    ) {
446
+        $t = echapper_html_suspect($t, ['strict' => false], $connect, $env);
447
+    }
448
+    $t = echappe_html($t);
449
+    $t = expanser_liens($t, $connect, $env);
450
+    $t = traiter_raccourcis($t);
451
+    $t = echappe_retour_modeles($t, $interdire_script);
452
+
453
+    return $t;
454 454
 }
Please login to merge, or discard this patch.
ecrire/inc/bandeau.php 1 patch
Indentation   +149 added lines, -149 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
 include_spip('inc/boutons');
@@ -39,33 +39,33 @@  discard block
 block discarded – undo
39 39
  *     contexte
40 40
  **/
41 41
 function definir_barre_contexte($contexte = null) {
42
-	if (is_null($contexte)) {
43
-		$contexte = $_GET;
44
-	} elseif (is_string($contexte)) {
45
-		$contexte = unserialize($contexte);
46
-	}
47
-	if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
48
-		if (!function_exists('trouver_objet_exec')) {
49
-			include_spip('inc/pipelines_ecrire');
50
-		}
51
-		if ($e = trouver_objet_exec($contexte['exec'])) {
52
-			$_id = $e['id_table_objet'];
53
-			if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
54
-				$table = $e['table_objet_sql'];
55
-				$row = sql_fetsel('*', $table, "$_id=" . intval($id));
56
-				if (isset($row['id_rubrique'])) {
57
-					$contexte['id_rubrique'] = $row['id_rubrique'];
58
-					if (isset($row['id_secteur'])) {
59
-						$contexte['id_secteur'] = $row['id_secteur'];
60
-					}
61
-				} elseif (isset($row['id_groupe'])) {
62
-					// TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
63
-					$contexte['id_groupe'] = $row['id_groupe'];
64
-				}
65
-			}
66
-		}
67
-	}
68
-	return $contexte;
42
+    if (is_null($contexte)) {
43
+        $contexte = $_GET;
44
+    } elseif (is_string($contexte)) {
45
+        $contexte = unserialize($contexte);
46
+    }
47
+    if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
48
+        if (!function_exists('trouver_objet_exec')) {
49
+            include_spip('inc/pipelines_ecrire');
50
+        }
51
+        if ($e = trouver_objet_exec($contexte['exec'])) {
52
+            $_id = $e['id_table_objet'];
53
+            if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
54
+                $table = $e['table_objet_sql'];
55
+                $row = sql_fetsel('*', $table, "$_id=" . intval($id));
56
+                if (isset($row['id_rubrique'])) {
57
+                    $contexte['id_rubrique'] = $row['id_rubrique'];
58
+                    if (isset($row['id_secteur'])) {
59
+                        $contexte['id_secteur'] = $row['id_secteur'];
60
+                    }
61
+                } elseif (isset($row['id_groupe'])) {
62
+                    // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
63
+                    $contexte['id_groupe'] = $row['id_groupe'];
64
+                }
65
+            }
66
+        }
67
+    }
68
+    return $contexte;
69 69
 }
70 70
 
71 71
 /**
@@ -81,89 +81,89 @@  discard block
 block discarded – undo
81 81
  * @return array
82 82
  */
83 83
 function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) {
84
-	include_spip('inc/autoriser');
85
-	$boutons_admin = [];
84
+    include_spip('inc/autoriser');
85
+    $boutons_admin = [];
86 86
 
87
-	// les boutons du core, issus de ecrire/paquet.xml
88
-	$liste_boutons = [];
87
+    // les boutons du core, issus de ecrire/paquet.xml
88
+    $liste_boutons = [];
89 89
 
90
-	// ajouter les boutons issus des plugin via paquet.xml
91
-	if (
92
-		function_exists('boutons_plugins')
93
-		and is_array($liste_boutons_plugins = boutons_plugins())
94
-	) {
95
-		$liste_boutons = &$liste_boutons_plugins;
96
-	}
90
+    // ajouter les boutons issus des plugin via paquet.xml
91
+    if (
92
+        function_exists('boutons_plugins')
93
+        and is_array($liste_boutons_plugins = boutons_plugins())
94
+    ) {
95
+        $liste_boutons = &$liste_boutons_plugins;
96
+    }
97 97
 
98
-	foreach ($liste_boutons as $id => $infos) {
99
-		$parent = '';
100
-		// les boutons principaux ne sont pas soumis a autorisation
101
-		if (
102
-			!isset($infos['parent'])
103
-			or !($parent = $infos['parent'])
104
-			or !$autorise
105
-			or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
106
-		) {
107
-			if (
108
-				$parent
109
-				and $parent = preg_replace(',^bando_,', 'menu_', $parent)
110
-				and isset($boutons_admin[$parent])
111
-			) {
112
-				$position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
113
-				if ($position < 0) {
114
-					$position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
115
-				}
116
-				$boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
117
-					+ [
118
-						$id => new Bouton(
119
-							($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
120
-							$infos['titre'],  // titre
121
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
122
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
123
-						)
124
-					]
125
-					+ array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
126
-			}
127
-			if (
128
-				!$parent
129
-				// provisoire, eviter les vieux boutons
130
-				and (!in_array($id, ['forum', 'statistiques_visites']))
131
-				and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
132
-			) {
133
-				$position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
134
-				$boutons_admin = array_slice($boutons_admin, 0, $position)
135
-					+ [
136
-						$id => new Bouton(
137
-							($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
138
-							$infos['titre'],  // titre
139
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
140
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
141
-						)
142
-					]
143
-					+ array_slice($boutons_admin, $position, 100);
144
-			}
145
-		}
146
-	}
147
-	$boutons_admin = pipeline('ajouter_menus', $boutons_admin);
98
+    foreach ($liste_boutons as $id => $infos) {
99
+        $parent = '';
100
+        // les boutons principaux ne sont pas soumis a autorisation
101
+        if (
102
+            !isset($infos['parent'])
103
+            or !($parent = $infos['parent'])
104
+            or !$autorise
105
+            or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
106
+        ) {
107
+            if (
108
+                $parent
109
+                and $parent = preg_replace(',^bando_,', 'menu_', $parent)
110
+                and isset($boutons_admin[$parent])
111
+            ) {
112
+                $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
113
+                if ($position < 0) {
114
+                    $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
115
+                }
116
+                $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
117
+                    + [
118
+                        $id => new Bouton(
119
+                            ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
120
+                            $infos['titre'],  // titre
121
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
122
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
123
+                        )
124
+                    ]
125
+                    + array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
126
+            }
127
+            if (
128
+                !$parent
129
+                // provisoire, eviter les vieux boutons
130
+                and (!in_array($id, ['forum', 'statistiques_visites']))
131
+                and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
132
+            ) {
133
+                $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
134
+                $boutons_admin = array_slice($boutons_admin, 0, $position)
135
+                    + [
136
+                        $id => new Bouton(
137
+                            ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
138
+                            $infos['titre'],  // titre
139
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
140
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
141
+                        )
142
+                    ]
143
+                    + array_slice($boutons_admin, $position, 100);
144
+            }
145
+        }
146
+    }
147
+    $boutons_admin = pipeline('ajouter_menus', $boutons_admin);
148 148
 
149
-	// définir les favoris et positions d’origine
150
-	if ($boutons_admin) {
151
-		$menus_favoris = obtenir_menus_favoris();
152
-		$i = 1;
153
-		foreach ($boutons_admin as $key => $menu) {
154
-			$menu->favori = (int) table_valeur($menus_favoris, $key, false);
155
-			$menu->position = $i++;
156
-			if ($menu->sousmenu) {
157
-				$j = 1;
158
-				foreach ($menu->sousmenu as $key => $bouton) {
159
-					$bouton->favori = (int) table_valeur($menus_favoris, $key, false);
160
-					$bouton->position = $j++;
161
-				}
162
-			}
163
-		}
164
-	}
149
+    // définir les favoris et positions d’origine
150
+    if ($boutons_admin) {
151
+        $menus_favoris = obtenir_menus_favoris();
152
+        $i = 1;
153
+        foreach ($boutons_admin as $key => $menu) {
154
+            $menu->favori = (int) table_valeur($menus_favoris, $key, false);
155
+            $menu->position = $i++;
156
+            if ($menu->sousmenu) {
157
+                $j = 1;
158
+                foreach ($menu->sousmenu as $key => $bouton) {
159
+                    $bouton->favori = (int) table_valeur($menus_favoris, $key, false);
160
+                    $bouton->position = $j++;
161
+                }
162
+            }
163
+        }
164
+    }
165 165
 
166
-	return $boutons_admin;
166
+    return $boutons_admin;
167 167
 }
168 168
 
169 169
 /**
@@ -175,22 +175,22 @@  discard block
 block discarded – undo
175 175
  * @return Bouton[]
176 176
  */
177 177
 function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) {
178
-	foreach ($menus as $menu) {
179
-		if ($menu->sousmenu) {
180
-			$libelles = $isfavoris = $favoris = [];
181
-			foreach ($menu->sousmenu as $key => $item) {
182
-				$libelles[$key] = strtolower(translitteration(_T($item->libelle)));
183
-				$isfavoris[$key] = (bool) $item->favori;
184
-				$favoris[$key] = $item->favori;
185
-			}
186
-			if ($avec_favoris) {
187
-				array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
188
-			} else {
189
-				array_multisort($libelles, SORT_ASC, $menu->sousmenu);
190
-			}
191
-		}
192
-	}
193
-	return $menus;
178
+    foreach ($menus as $menu) {
179
+        if ($menu->sousmenu) {
180
+            $libelles = $isfavoris = $favoris = [];
181
+            foreach ($menu->sousmenu as $key => $item) {
182
+                $libelles[$key] = strtolower(translitteration(_T($item->libelle)));
183
+                $isfavoris[$key] = (bool) $item->favori;
184
+                $favoris[$key] = $item->favori;
185
+            }
186
+            if ($avec_favoris) {
187
+                array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
188
+            } else {
189
+                array_multisort($libelles, SORT_ASC, $menu->sousmenu);
190
+            }
191
+        }
192
+    }
193
+    return $menus;
194 194
 }
195 195
 
196 196
 /**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
  * @return Bouton[]
202 202
  */
203 203
 function trier_boutons_enfants_par_favoris_alpha($menus) {
204
-	return trier_boutons_enfants_par_alpha($menus, true);
204
+    return trier_boutons_enfants_par_alpha($menus, true);
205 205
 }
206 206
 
207 207
 
@@ -214,23 +214,23 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function bandeau_creer_url($url, $args = '', $contexte = null) {
217
-	if (!preg_match(',[\/\?],', $url)) {
218
-		$url = generer_url_ecrire($url, $args, true);
219
-		// recuperer les parametres du contexte demande par l'url sous la forme
220
-		// &truc=@machin@
221
-		// @machin@ etant remplace par _request('machin')
222
-		$url = str_replace('&amp;', '&', $url);
223
-		while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
224
-			if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
225
-				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
226
-			}
227
-			$val = _request($matches[2], $contexte);
228
-			$url = parametre_url($url, $matches[1], $val ?: '', '&');
229
-		}
230
-		$url = str_replace('&', '&amp;', $url);
231
-	}
217
+    if (!preg_match(',[\/\?],', $url)) {
218
+        $url = generer_url_ecrire($url, $args, true);
219
+        // recuperer les parametres du contexte demande par l'url sous la forme
220
+        // &truc=@machin@
221
+        // @machin@ etant remplace par _request('machin')
222
+        $url = str_replace('&amp;', '&', $url);
223
+        while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
224
+            if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
225
+                $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
226
+            }
227
+            $val = _request($matches[2], $contexte);
228
+            $url = parametre_url($url, $matches[1], $val ?: '', '&');
229
+        }
230
+        $url = str_replace('&', '&amp;', $url);
231
+    }
232 232
 
233
-	return $url;
233
+    return $url;
234 234
 }
235 235
 
236 236
 /**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
  *     Code HTML du bandeau
241 241
  */
242 242
 function inc_bandeau_dist() {
243
-	return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
243
+    return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
244 244
 }
245 245
 
246 246
 
@@ -249,13 +249,13 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function obtenir_menus_favoris() {
252
-	if (
253
-		isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
-		and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
255
-		and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
256
-	) {
257
-		return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
258
-	}
259
-	$definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
260
-	return $definir_menus_favoris();
252
+    if (
253
+        isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
+        and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
255
+        and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
256
+    ) {
257
+        return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
258
+    }
259
+    $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
260
+    return $definir_menus_favoris();
261 261
 }
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 1 patch
Indentation   +194 added lines, -194 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
 /**
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
  *     Liste des fichiers de langue trouvés, dans l'ordre des chemins
41 41
  */
42 42
 function find_langs_in_path($file, $dirname = 'lang') {
43
-	static $dirs = [];
44
-	$liste = [];
45
-	foreach (creer_chemin() as $dir) {
46
-		if (!isset($dirs[$a = $dir . $dirname])) {
47
-			$dirs[$a] = (is_dir($a) || !$a);
48
-		}
49
-		if ($dirs[$a]) {
50
-			if (is_readable($a .= $file)) {
51
-				$liste[] = $a;
52
-			}
53
-		}
54
-	}
43
+    static $dirs = [];
44
+    $liste = [];
45
+    foreach (creer_chemin() as $dir) {
46
+        if (!isset($dirs[$a = $dir . $dirname])) {
47
+            $dirs[$a] = (is_dir($a) || !$a);
48
+        }
49
+        if ($dirs[$a]) {
50
+            if (is_readable($a .= $file)) {
51
+                $liste[] = $a;
52
+            }
53
+        }
54
+    }
55 55
 
56
-	return array_reverse($liste);
56
+    return array_reverse($liste);
57 57
 }
58 58
 
59 59
 /**
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
  *     Liste des fichiers touvés pour ce module et cette langue.
69 69
  **/
70 70
 function chercher_module_lang($module, $lang = '') {
71
-	if ($lang) {
72
-		$lang = '_' . $lang;
73
-	}
71
+    if ($lang) {
72
+        $lang = '_' . $lang;
73
+    }
74 74
 
75
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
-	if (
77
-		$f = ($module == 'local'
78
-		? find_in_path($module . $lang . '.php', 'lang/')
79
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
80
-	) {
81
-		return is_array($f) ? $f : [$f];
82
-	}
75
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
+    if (
77
+        $f = ($module == 'local'
78
+        ? find_in_path($module . $lang . '.php', 'lang/')
79
+        : find_langs_in_path($module . $lang . '.php', 'lang/'))
80
+    ) {
81
+        return is_array($f) ? $f : [$f];
82
+    }
83 83
 
84
-	// 2) directement dans le chemin (old style, uniquement pour local)
85
-	return (($module == 'local') or strpos($module, '/'))
86
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
-		: false;
84
+    // 2) directement dans le chemin (old style, uniquement pour local)
85
+    return (($module == 'local') or strpos($module, '/'))
86
+        ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
+        : false;
88 88
 }
89 89
 
90 90
 /**
@@ -106,33 +106,33 @@  discard block
 block discarded – undo
106 106
  * @return void
107 107
  **/
108 108
 function charger_langue($lang, $module = 'spip') {
109
-	static $langs = [];
110
-	$var = 'i18n_' . $module . '_' . $lang;
111
-	if (!isset($langs[$lang])) {
112
-		$langs[$lang] = [];
113
-		if ($lang) {
114
-			$langs[$lang][] = $lang;
115
-			if (strpos($lang, '_') !== false) {
116
-				$l = explode('_', $lang);
117
-				$langs[$lang][] = reset($l);
118
-			}
119
-		}
120
-		$langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
-		$langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
-	}
123
-	foreach ($langs[$lang] as $l) {
124
-		if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
-			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
-			surcharger_langue($fichiers_lang);
128
-			if ($l !== $lang) {
129
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
-			}
131
-			$GLOBALS['lang_' . $var] = $l;
132
-			#spip_log("module de langue : {$module}_$l.php", 'traduire');
133
-			break;
134
-		}
135
-	}
109
+    static $langs = [];
110
+    $var = 'i18n_' . $module . '_' . $lang;
111
+    if (!isset($langs[$lang])) {
112
+        $langs[$lang] = [];
113
+        if ($lang) {
114
+            $langs[$lang][] = $lang;
115
+            if (strpos($lang, '_') !== false) {
116
+                $l = explode('_', $lang);
117
+                $langs[$lang][] = reset($l);
118
+            }
119
+        }
120
+        $langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
+        $langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
+    }
123
+    foreach ($langs[$lang] as $l) {
124
+        if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
+            $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
+            $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
+            surcharger_langue($fichiers_lang);
128
+            if ($l !== $lang) {
129
+                $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
+            }
131
+            $GLOBALS['lang_' . $var] = $l;
132
+            #spip_log("module de langue : {$module}_$l.php", 'traduire');
133
+            break;
134
+        }
135
+    }
136 136
 }
137 137
 
138 138
 /**
@@ -145,21 +145,21 @@  discard block
 block discarded – undo
145 145
  * @return array<string, string>
146 146
  */
147 147
 function lire_fichier_langue(string $fichier): array {
148
-	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
-	$GLOBALS['idx_lang'] = $idx_lang_tmp;
151
-	$idx_lang = include $fichier;
152
-	$GLOBALS['idx_lang'] = $idx_lang_before;
153
-	if (!is_array($idx_lang)) {
154
-		if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
-			$idx_lang = $GLOBALS[$idx_lang_tmp];
156
-		} else {
157
-			$idx_lang = [];
158
-			spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
-		}
160
-		unset($GLOBALS[$idx_lang_tmp]);
161
-	}
162
-	return $idx_lang;
148
+    $idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
+    $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
+    $GLOBALS['idx_lang'] = $idx_lang_tmp;
151
+    $idx_lang = include $fichier;
152
+    $GLOBALS['idx_lang'] = $idx_lang_before;
153
+    if (!is_array($idx_lang)) {
154
+        if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
+            $idx_lang = $GLOBALS[$idx_lang_tmp];
156
+        } else {
157
+            $idx_lang = [];
158
+            spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
+        }
160
+        unset($GLOBALS[$idx_lang_tmp]);
161
+    }
162
+    return $idx_lang;
163 163
 }
164 164
 
165 165
 /**
@@ -179,29 +179,29 @@  discard block
 block discarded – undo
179 179
  *    Liste des chemins de fichiers de langue à surcharger.
180 180
  **/
181 181
 function surcharger_langue($fichiers) {
182
-	static $surcharges = [];
183
-	if (!isset($GLOBALS['idx_lang'])) {
184
-		return;
185
-	}
182
+    static $surcharges = [];
183
+    if (!isset($GLOBALS['idx_lang'])) {
184
+        return;
185
+    }
186 186
 
187
-	if (!is_array($fichiers)) {
188
-		$fichiers = [$fichiers];
189
-	}
190
-	if (!count($fichiers)) {
191
-		return;
192
-	}
193
-	foreach ($fichiers as $fichier) {
194
-		if (!isset($surcharges[$fichier])) {
195
-			$surcharges[$fichier] = lire_fichier_langue($fichier);
196
-		}
197
-		if (is_array($surcharges[$fichier])) {
198
-			$GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
-				$GLOBALS[$GLOBALS['idx_lang']],
201
-				$surcharges[$fichier]
202
-			);
203
-		}
204
-	}
187
+    if (!is_array($fichiers)) {
188
+        $fichiers = [$fichiers];
189
+    }
190
+    if (!count($fichiers)) {
191
+        return;
192
+    }
193
+    foreach ($fichiers as $fichier) {
194
+        if (!isset($surcharges[$fichier])) {
195
+            $surcharges[$fichier] = lire_fichier_langue($fichier);
196
+        }
197
+        if (is_array($surcharges[$fichier])) {
198
+            $GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
+                $GLOBALS[$GLOBALS['idx_lang']],
201
+                $surcharges[$fichier]
202
+            );
203
+        }
204
+    }
205 205
 }
206 206
 
207 207
 /**
@@ -242,99 +242,99 @@  discard block
 block discarded – undo
242 242
  *     - Description : traduction et description (texte, module, langue)
243 243
  **/
244 244
 function inc_traduire_dist($ori, $lang, $raw = false) {
245
-	static $deja_vu = [];
246
-	static $local = [];
245
+    static $deja_vu = [];
246
+    static $local = [];
247 247
 
248
-	if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
-		return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
-	}
248
+    if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
+        return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
+    }
251 251
 
252
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
-	if (strpos($ori, ':')) {
254
-		[$modules, $code] = explode(':', $ori, 2);
255
-		$modules = explode('|', $modules);
256
-		$ori_complet = $ori;
257
-	} else {
258
-		$modules = ['spip', 'ecrire'];
259
-		$code = $ori;
260
-		$ori_complet = implode('|', $modules) . ':' . $ori;
261
-	}
252
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
+    if (strpos($ori, ':')) {
254
+        [$modules, $code] = explode(':', $ori, 2);
255
+        $modules = explode('|', $modules);
256
+        $ori_complet = $ori;
257
+    } else {
258
+        $modules = ['spip', 'ecrire'];
259
+        $code = $ori;
260
+        $ori_complet = implode('|', $modules) . ':' . $ori;
261
+    }
262 262
 
263
-	$desc = new Description();
263
+    $desc = new Description();
264 264
 
265
-	// parcourir tous les modules jusqu'a ce qu'on trouve
266
-	foreach ($modules as $module) {
267
-		$var = 'i18n_' . $module . '_' . $lang;
265
+    // parcourir tous les modules jusqu'a ce qu'on trouve
266
+    foreach ($modules as $module) {
267
+        $var = 'i18n_' . $module . '_' . $lang;
268 268
 
269
-		if (empty($GLOBALS[$var])) {
270
-			charger_langue($lang, $module);
271
-			// surcharges persos -- on cherche
272
-			// (lang/)local_xx.php et/ou (lang/)local.php ...
273
-			if (!isset($local['local_' . $lang])) {
274
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
-				$GLOBALS['idx_lang'] = $var;
276
-				// ... (lang/)local_xx.php
277
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
278
-			}
279
-			if ($local['local_' . $lang]) {
280
-				surcharger_langue($local['local_' . $lang]);
281
-			}
282
-			// ... puis (lang/)local.php
283
-			if (!isset($local['local'])) {
284
-				$local['local'] = chercher_module_lang('local');
285
-			}
286
-			if ($local['local']) {
287
-				surcharger_langue($local['local']);
288
-			}
289
-		}
269
+        if (empty($GLOBALS[$var])) {
270
+            charger_langue($lang, $module);
271
+            // surcharges persos -- on cherche
272
+            // (lang/)local_xx.php et/ou (lang/)local.php ...
273
+            if (!isset($local['local_' . $lang])) {
274
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
+                $GLOBALS['idx_lang'] = $var;
276
+                // ... (lang/)local_xx.php
277
+                $local['local_' . $lang] = chercher_module_lang('local', $lang);
278
+            }
279
+            if ($local['local_' . $lang]) {
280
+                surcharger_langue($local['local_' . $lang]);
281
+            }
282
+            // ... puis (lang/)local.php
283
+            if (!isset($local['local'])) {
284
+                $local['local'] = chercher_module_lang('local');
285
+            }
286
+            if ($local['local']) {
287
+                surcharger_langue($local['local']);
288
+            }
289
+        }
290 290
 
291
-		if (isset($GLOBALS[$var][$code])) {
292
-			$desc->code = $code;
293
-			$desc->module = $module;
294
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
-			$desc->texte = $GLOBALS[$var][$code];
296
-			break;
297
-		}
298
-	}
291
+        if (isset($GLOBALS[$var][$code])) {
292
+            $desc->code = $code;
293
+            $desc->module = $module;
294
+            $desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
+            $desc->texte = $GLOBALS[$var][$code];
296
+            break;
297
+        }
298
+    }
299 299
 
300
-	if (!$desc->corrections) {
301
-		$desc->corrections = true;
302
-		// Retour aux sources si la chaine est absente dans la langue cible ;
303
-		// on essaie d'abord la langue du site, puis a defaut la langue fr
304
-		if (
305
-			($desc->texte === null || !strlen($desc->texte))
306
-			and $lang !== _LANGUE_PAR_DEFAUT
307
-		) {
308
-			if ($lang !== $GLOBALS['meta']['langue_site']) {
309
-				$desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
-			} else {
311
-				$desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
-			}
313
-		}
300
+    if (!$desc->corrections) {
301
+        $desc->corrections = true;
302
+        // Retour aux sources si la chaine est absente dans la langue cible ;
303
+        // on essaie d'abord la langue du site, puis a defaut la langue fr
304
+        if (
305
+            ($desc->texte === null || !strlen($desc->texte))
306
+            and $lang !== _LANGUE_PAR_DEFAUT
307
+        ) {
308
+            if ($lang !== $GLOBALS['meta']['langue_site']) {
309
+                $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
+            } else {
311
+                $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
+            }
313
+        }
314 314
 
315
-		// Supprimer la mention <NEW> ou <MODIF>
316
-		if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
-			$desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
-		}
315
+        // Supprimer la mention <NEW> ou <MODIF>
316
+        if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
+            $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
+        }
319 319
 
320
-		// Si on n'est pas en utf-8, la chaine peut l'etre...
321
-		// le cas echeant on la convertit en entites html &#xxx;
322
-		if (
323
-			(!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
-			and preg_match(',[\x7f-\xff],S', $desc->texte)
325
-		) {
326
-			include_spip('inc/charsets');
327
-			$desc->texte = charset2unicode($desc->texte, 'utf-8');
328
-		}
329
-	}
320
+        // Si on n'est pas en utf-8, la chaine peut l'etre...
321
+        // le cas echeant on la convertit en entites html &#xxx;
322
+        if (
323
+            (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
+            and preg_match(',[\x7f-\xff],S', $desc->texte)
325
+        ) {
326
+            include_spip('inc/charsets');
327
+            $desc->texte = charset2unicode($desc->texte, 'utf-8');
328
+        }
329
+    }
330 330
 
331
-	if (_request('var_mode') == 'traduction') {
332
-		$desc = definir_details_traduction($desc, $ori_complet);
333
-	} else {
334
-		$deja_vu[$lang][$ori] = $desc;
335
-	}
331
+    if (_request('var_mode') == 'traduction') {
332
+        $desc = definir_details_traduction($desc, $ori_complet);
333
+    } else {
334
+        $deja_vu[$lang][$ori] = $desc;
335
+    }
336 336
 
337
-	return $raw ? $desc : $desc->texte;
337
+    return $raw ? $desc : $desc->texte;
338 338
 }
339 339
 
340 340
 /**
@@ -346,23 +346,23 @@  discard block
 block discarded – undo
346 346
  * @return Description
347 347
  */
348 348
 function definir_details_traduction($desc, $modules) {
349
-	if (!$desc->mode and $desc->texte) {
350
-		// ne pas modifier 2 fois l'affichage
351
-		$desc->mode = 'traduction';
352
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
-		$desc->texte = '<span '
354
-			. 'lang=' . $desc->langue
355
-			. ' class=' . $classe
356
-			. ' data-module=' . $desc->module
357
-			. ' data-code=' . $desc->code
358
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
359
-			. $desc->texte
360
-			. '</span>';
361
-		$desc->texte = str_replace(
362
-			["$desc->module:", "$desc->module|"],
363
-			["*$desc->module*:", "*$desc->module*|"],
364
-			$desc->texte
365
-		);
366
-	}
367
-	return $desc;
349
+    if (!$desc->mode and $desc->texte) {
350
+        // ne pas modifier 2 fois l'affichage
351
+        $desc->mode = 'traduction';
352
+        $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
+        $desc->texte = '<span '
354
+            . 'lang=' . $desc->langue
355
+            . ' class=' . $classe
356
+            . ' data-module=' . $desc->module
357
+            . ' data-code=' . $desc->code
358
+            . ' title=' . $modules . '(' . $desc->langue . ')>'
359
+            . $desc->texte
360
+            . '</span>';
361
+        $desc->texte = str_replace(
362
+            ["$desc->module:", "$desc->module|"],
363
+            ["*$desc->module*:", "*$desc->module*|"],
364
+            $desc->texte
365
+        );
366
+    }
367
+    return $desc;
368 368
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2400 added lines, -2400 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,33 +77,33 @@  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
-		if (is_callable($f)) {
102
-			return $f;
103
-		}
104
-	}
105
-
106
-	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
+        if (is_callable($f)) {
102
+            return $f;
103
+        }
104
+    }
105
+
106
+    return $default;
107 107
 }
108 108
 
109 109
 /**
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
  *     Chaîne vide sinon.
148 148
  **/
149 149
 function appliquer_filtre($arg, $filtre) {
150
-	$args = func_get_args();
151
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
150
+    $args = func_get_args();
151
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
152 152
 }
153 153
 
154 154
 /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
  *     texte d'origine sinon
174 174
  **/
175 175
 function appliquer_si_filtre($arg, $filtre) {
176
-	$args = func_get_args();
177
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
176
+    $args = func_get_args();
177
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
178 178
 }
179 179
 
180 180
 /**
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
  *     Version de SPIP
191 191
  **/
192 192
 function spip_version() {
193
-	$version = $GLOBALS['spip_version_affichee'];
194
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
-		$version .= " $vcs_version";
196
-	}
193
+    $version = $GLOBALS['spip_version_affichee'];
194
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
+        $version .= " $vcs_version";
196
+    }
197 197
 
198
-	return $version;
198
+    return $version;
199 199
 }
200 200
 
201 201
 /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
  * @return string
208 208
  */
209 209
 function header_silencieux($version): string {
210
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
-		$version = '';
212
-	}
210
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
+        $version = '';
212
+    }
213 213
 
214
-	return (string) $version;
214
+    return (string) $version;
215 215
 }
216 216
 
217 217
 /**
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
  *    - string|null si $raw = false
225 225
  */
226 226
 function version_vcs_courante($dir, $raw = false) {
227
-	$desc = decrire_version_git($dir);
228
-	if ($desc === null or $raw) {
229
-		return $desc;
230
-	}
231
-	// affichage "GIT [master: abcdef]"
232
-	$commit = $desc['commit_short'] ?? $desc['commit'];
233
-	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
235
-	}
236
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null or $raw) {
229
+        return $desc;
230
+    }
231
+    // affichage "GIT [master: abcdef]"
232
+    $commit = $desc['commit_short'] ?? $desc['commit'];
233
+    if ($desc['branch']) {
234
+        $commit = $desc['branch'] . ': ' . $commit;
235
+    }
236
+    return "{$desc['vcs']} [$commit]";
237 237
 }
238 238
 
239 239
 /**
@@ -245,24 +245,24 @@  discard block
 block discarded – undo
245 245
  *      array ['branch' => xx, 'commit' => yy] sinon.
246 246
  **/
247 247
 function decrire_version_git($dir) {
248
-	if (!$dir) {
249
-		$dir = '.';
250
-	}
251
-
252
-	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
-		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
-			return [
257
-				'vcs' => 'GIT',
258
-				'branch' => basename($currentHead),
259
-				'commit' => trim($hash),
260
-				'commit_short' => substr(trim($hash), 0, 8),
261
-			];
262
-		}
263
-	}
264
-
265
-	return null;
248
+    if (!$dir) {
249
+        $dir = '.';
250
+    }
251
+
252
+    // version installee par GIT
253
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
+        $currentHead = trim(substr($c, 4));
255
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
+            return [
257
+                'vcs' => 'GIT',
258
+                'branch' => basename($currentHead),
259
+                'commit' => trim($hash),
260
+                'commit_short' => substr(trim($hash), 0, 8),
261
+            ];
262
+        }
263
+    }
264
+
265
+    return null;
266 266
 }
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
  *     Code HTML retourné par le filtre
310 310
  **/
311 311
 function filtrer($filtre) {
312
-	$tous = func_get_args();
313
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
-		return image_filtrer($tous);
315
-	} elseif ($f = chercher_filtre($filtre)) {
316
-		array_shift($tous);
317
-		return $f(...$tous);
318
-	} else {
319
-		// le filtre n'existe pas, on provoque une erreur
320
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
-		erreur_squelette($msg);
322
-		return '';
323
-	}
312
+    $tous = func_get_args();
313
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
+        return image_filtrer($tous);
315
+    } elseif ($f = chercher_filtre($filtre)) {
316
+        array_shift($tous);
317
+        return $f(...$tous);
318
+    } else {
319
+        // le filtre n'existe pas, on provoque une erreur
320
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
+        erreur_squelette($msg);
322
+        return '';
323
+    }
324 324
 }
325 325
 
326 326
 /**
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
338 338
  */
339 339
 function trouver_filtre_matrice($filtre) {
340
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
-		find_in_path($f, '', true);
342
-		$GLOBALS['spip_matrice'][$filtre] = true;
343
-	}
344
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
340
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
+        find_in_path($f, '', true);
342
+        $GLOBALS['spip_matrice'][$filtre] = true;
343
+    }
344
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
345 345
 }
346 346
 
347 347
 
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
  * @return mixed
370 370
  */
371 371
 function filtre_set(&$Pile, $val, $key, $continue = null) {
372
-	$Pile['vars'][$key] = $val;
373
-	return $continue ? $val : '';
372
+    $Pile['vars'][$key] = $val;
373
+    return $continue ? $val : '';
374 374
 }
375 375
 
376 376
 /**
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
397 397
  */
398 398
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
399
-	$Pile[0][$key] = $val;
400
-	return $continue ? $val : '';
399
+    $Pile[0][$key] = $val;
400
+    return $continue ? $val : '';
401 401
 }
402 402
 
403 403
 /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
  * @return string
407 407
  */
408 408
 function filtre_sanitize_env(&$Pile, $keys) {
409
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
-	return '';
409
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
+    return '';
411 411
 }
412 412
 
413 413
 
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
  * @return mixed Retourne la valeur (sans la modifier).
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433
-	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
433
+    $debug = (
434
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
435
+        ) . var_export($val, true);
436 436
 
437
-	include_spip('inc/autoriser');
438
-	if (autoriser('webmestre')) {
439
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
-	}
437
+    include_spip('inc/autoriser');
438
+    if (autoriser('webmestre')) {
439
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
+    }
441 441
 
442
-	spip_log($debug, 'debug');
442
+    spip_log($debug, 'debug');
443 443
 
444
-	return $val;
444
+    return $val;
445 445
 }
446 446
 
447 447
 
@@ -471,84 +471,84 @@  discard block
 block discarded – undo
471 471
  *     texte qui a reçu les filtres
472 472
  **/
473 473
 function image_filtrer($args) {
474
-	$filtre = array_shift($args); # enlever $filtre
475
-	$texte = array_shift($args);
476
-	if ($texte === null || !strlen($texte)) {
477
-		return '';
478
-	}
479
-	find_in_path('filtres_images_mini.php', 'inc/', true);
480
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
-	// Cas du nom de fichier local
482
-	$is_file = trim($texte);
483
-	if (
484
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
-		  or strpbrk($is_file, "<>\n\r\t") !== false
486
-		  or strpos($is_file, '/') === 0
487
-	) {
488
-		$is_file = false;
489
-	}
490
-	if ($is_file) {
491
-		$is_local_file = function ($path) {
492
-			if (strpos($path, '?') !== false) {
493
-				$path = supprimer_timestamp($path);
494
-				// remove ?24px added by find_in_theme on .svg files
495
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
-			}
497
-			return file_exists($path);
498
-		};
499
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
-			$res = $filtre("<img src='$is_file' />", ...$args);
501
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
-			return $res;
503
-		}
504
-	}
505
-
506
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
507
-	if (
508
-		preg_match_all(
509
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
-			$texte,
511
-			$tags,
512
-			PREG_SET_ORDER
513
-		)
514
-	) {
515
-		foreach ($tags as $tag) {
516
-			$class = extraire_attribut($tag[3], 'class');
517
-			if (
518
-				!$class or
519
-				(strpos($class, 'filtre_inactif') === false
520
-					// compat historique a virer en 3.2
521
-					and !str_contains($class, 'no_image_filtrer'))
522
-			) {
523
-				if ($reduit = $filtre($tag[3], ...$args)) {
524
-					// En cas de span spip_documents, modifier le style=...width:
525
-					if ($tag[1]) {
526
-						$w = extraire_attribut($reduit, 'width');
527
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
-							$w = $regs[1];
529
-						}
530
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
-							$replace = inserer_attribut($tag[1], 'style', $style);
533
-							$texte = str_replace($tag[1], $replace, $texte);
534
-						}
535
-					}
536
-					// traiter aussi un eventuel mouseover
537
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
-							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543
-						}
544
-					}
545
-					$texte = str_replace($tag[3], $reduit, $texte);
546
-				}
547
-			}
548
-		}
549
-	}
550
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
-	return $texte;
474
+    $filtre = array_shift($args); # enlever $filtre
475
+    $texte = array_shift($args);
476
+    if ($texte === null || !strlen($texte)) {
477
+        return '';
478
+    }
479
+    find_in_path('filtres_images_mini.php', 'inc/', true);
480
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
+    // Cas du nom de fichier local
482
+    $is_file = trim($texte);
483
+    if (
484
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
+          or strpbrk($is_file, "<>\n\r\t") !== false
486
+          or strpos($is_file, '/') === 0
487
+    ) {
488
+        $is_file = false;
489
+    }
490
+    if ($is_file) {
491
+        $is_local_file = function ($path) {
492
+            if (strpos($path, '?') !== false) {
493
+                $path = supprimer_timestamp($path);
494
+                // remove ?24px added by find_in_theme on .svg files
495
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
+            }
497
+            return file_exists($path);
498
+        };
499
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
+            $res = $filtre("<img src='$is_file' />", ...$args);
501
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
+            return $res;
503
+        }
504
+    }
505
+
506
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
507
+    if (
508
+        preg_match_all(
509
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
+            $texte,
511
+            $tags,
512
+            PREG_SET_ORDER
513
+        )
514
+    ) {
515
+        foreach ($tags as $tag) {
516
+            $class = extraire_attribut($tag[3], 'class');
517
+            if (
518
+                !$class or
519
+                (strpos($class, 'filtre_inactif') === false
520
+                    // compat historique a virer en 3.2
521
+                    and !str_contains($class, 'no_image_filtrer'))
522
+            ) {
523
+                if ($reduit = $filtre($tag[3], ...$args)) {
524
+                    // En cas de span spip_documents, modifier le style=...width:
525
+                    if ($tag[1]) {
526
+                        $w = extraire_attribut($reduit, 'width');
527
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
+                            $w = $regs[1];
529
+                        }
530
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
+                            $replace = inserer_attribut($tag[1], 'style', $style);
533
+                            $texte = str_replace($tag[1], $replace, $texte);
534
+                        }
535
+                    }
536
+                    // traiter aussi un eventuel mouseover
537
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
+                            $srcover = $match[1];
540
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
542
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
543
+                        }
544
+                    }
545
+                    $texte = str_replace($tag[3], $reduit, $texte);
546
+                }
547
+            }
548
+        }
549
+    }
550
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
+    return $texte;
552 552
 }
553 553
 
554 554
 /**
@@ -565,91 +565,91 @@  discard block
 block discarded – undo
565 565
  **/
566 566
 function infos_image($img, $force_refresh = false) {
567 567
 
568
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
-	$srcWidth = 0;
570
-	$srcHeight = 0;
571
-	$srcSize = null;
572
-
573
-	$src = extraire_attribut($img, 'src');
574
-
575
-	if (!$src) {
576
-		$src = $img;
577
-	} else {
578
-		$srcWidth = extraire_attribut($img, 'width');
579
-		$srcHeight = extraire_attribut($img, 'height');
580
-	}
581
-
582
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
583
-	// la copie locale a toutes les chances d'etre la ou de resservir
584
-	if (tester_url_absolue($src)) {
585
-		include_spip('inc/distant');
586
-		$fichier = copie_locale($src);
587
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
588
-	}
589
-	if (($p = strpos($src, '?')) !== false) {
590
-		$src = substr($src, 0, $p);
591
-	}
592
-
593
-	$imagesize = false;
594
-	if (isset($largeur_img[$src]) and !$force_refresh) {
595
-		$srcWidth = $largeur_img[$src];
596
-	}
597
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
598
-		$srcHeight = $hauteur_img[$src];
599
-	}
600
-	if (isset($poids_img[$src]) and !$force_refresh) {
601
-		$srcSize = $poids_img[$src];
602
-	}
603
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
604
-		if (
605
-			file_exists($src)
606
-			and $imagesize = spip_getimagesize($src)
607
-		) {
608
-			if (!$srcWidth) {
609
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
610
-			}
611
-			if (!$srcHeight) {
612
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
613
-			}
614
-			if (!$srcSize) {
615
-				$poids_img[$src] = filesize($src);
616
-			}
617
-		}
618
-		elseif (strpos($src, '<svg') !== false) {
619
-			include_spip('inc/svg');
620
-			if ($attrs = svg_lire_attributs($src)) {
621
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
622
-				if (!$srcWidth) {
623
-					$largeur_img[$src] = $srcWidth = $width;
624
-				}
625
-				if (!$srcHeight) {
626
-					$hauteur_img[$src] = $srcHeight = $height;
627
-				}
628
-				if (!$srcSize) {
629
-					$poids_img[$src] = $srcSize = strlen($src);
630
-				}
631
-			}
632
-		}
633
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
634
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
635
-		elseif (
636
-			@file_exists($f = "$src.src")
637
-			and lire_fichier($f, $valeurs)
638
-			and $valeurs = unserialize($valeurs)
639
-		) {
640
-			if (!$srcWidth) {
641
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
642
-			}
643
-			if (!$srcHeight) {
644
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
645
-			}
646
-			if (!$srcSize) {
647
-				$poids_img[$src] = $srcSize = 0;
648
-			}
649
-		}
650
-	}
651
-
652
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
568
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
+    $srcWidth = 0;
570
+    $srcHeight = 0;
571
+    $srcSize = null;
572
+
573
+    $src = extraire_attribut($img, 'src');
574
+
575
+    if (!$src) {
576
+        $src = $img;
577
+    } else {
578
+        $srcWidth = extraire_attribut($img, 'width');
579
+        $srcHeight = extraire_attribut($img, 'height');
580
+    }
581
+
582
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
583
+    // la copie locale a toutes les chances d'etre la ou de resservir
584
+    if (tester_url_absolue($src)) {
585
+        include_spip('inc/distant');
586
+        $fichier = copie_locale($src);
587
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
588
+    }
589
+    if (($p = strpos($src, '?')) !== false) {
590
+        $src = substr($src, 0, $p);
591
+    }
592
+
593
+    $imagesize = false;
594
+    if (isset($largeur_img[$src]) and !$force_refresh) {
595
+        $srcWidth = $largeur_img[$src];
596
+    }
597
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
598
+        $srcHeight = $hauteur_img[$src];
599
+    }
600
+    if (isset($poids_img[$src]) and !$force_refresh) {
601
+        $srcSize = $poids_img[$src];
602
+    }
603
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
604
+        if (
605
+            file_exists($src)
606
+            and $imagesize = spip_getimagesize($src)
607
+        ) {
608
+            if (!$srcWidth) {
609
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
610
+            }
611
+            if (!$srcHeight) {
612
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
613
+            }
614
+            if (!$srcSize) {
615
+                $poids_img[$src] = filesize($src);
616
+            }
617
+        }
618
+        elseif (strpos($src, '<svg') !== false) {
619
+            include_spip('inc/svg');
620
+            if ($attrs = svg_lire_attributs($src)) {
621
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
622
+                if (!$srcWidth) {
623
+                    $largeur_img[$src] = $srcWidth = $width;
624
+                }
625
+                if (!$srcHeight) {
626
+                    $hauteur_img[$src] = $srcHeight = $height;
627
+                }
628
+                if (!$srcSize) {
629
+                    $poids_img[$src] = $srcSize = strlen($src);
630
+                }
631
+            }
632
+        }
633
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
634
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
635
+        elseif (
636
+            @file_exists($f = "$src.src")
637
+            and lire_fichier($f, $valeurs)
638
+            and $valeurs = unserialize($valeurs)
639
+        ) {
640
+            if (!$srcWidth) {
641
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
642
+            }
643
+            if (!$srcHeight) {
644
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
645
+            }
646
+            if (!$srcSize) {
647
+                $poids_img[$src] = $srcSize = 0;
648
+            }
649
+        }
650
+    }
651
+
652
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
653 653
 }
654 654
 
655 655
 /**
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
  *     poids
666 666
  **/
667 667
 function poids_image($img, $force_refresh = false) {
668
-	$infos = infos_image($img, $force_refresh);
669
-	return $infos['poids'];
668
+    $infos = infos_image($img, $force_refresh);
669
+    return $infos['poids'];
670 670
 }
671 671
 
672 672
 function taille_image($img, $force_refresh = false) {
673
-	$infos = infos_image($img, $force_refresh);
674
-	return [$infos['hauteur'], $infos['largeur']];
673
+    $infos = infos_image($img, $force_refresh);
674
+    return [$infos['hauteur'], $infos['largeur']];
675 675
 }
676 676
 
677 677
 /**
@@ -688,12 +688,12 @@  discard block
 block discarded – undo
688 688
  *     Largeur en pixels, NULL ou 0 si aucune image.
689 689
  **/
690 690
 function largeur($img) {
691
-	if (!$img) {
692
-		return;
693
-	}
694
-	[$h, $l] = taille_image($img);
691
+    if (!$img) {
692
+        return;
693
+    }
694
+    [$h, $l] = taille_image($img);
695 695
 
696
-	return $l;
696
+    return $l;
697 697
 }
698 698
 
699 699
 /**
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
  *     Hauteur en pixels, NULL ou 0 si aucune image.
711 711
  **/
712 712
 function hauteur($img) {
713
-	if (!$img) {
714
-		return;
715
-	}
716
-	[$h, $l] = taille_image($img);
713
+    if (!$img) {
714
+        return;
715
+    }
716
+    [$h, $l] = taille_image($img);
717 717
 
718
-	return $h;
718
+    return $h;
719 719
 }
720 720
 
721 721
 
@@ -735,11 +735,11 @@  discard block
 block discarded – undo
735 735
  * @return string
736 736
  **/
737 737
 function corriger_entites_html($texte) {
738
-	if (strpos($texte, '&amp;') === false) {
739
-		return $texte;
740
-	}
738
+    if (strpos($texte, '&amp;') === false) {
739
+        return $texte;
740
+    }
741 741
 
742
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
742
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
743 743
 }
744 744
 
745 745
 /**
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
  * @return string
755 755
  **/
756 756
 function corriger_toutes_entites_html($texte) {
757
-	if (strpos($texte, '&amp;') === false) {
758
-		return $texte;
759
-	}
757
+    if (strpos($texte, '&amp;') === false) {
758
+        return $texte;
759
+    }
760 760
 
761
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
761
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
762 762
 }
763 763
 
764 764
 /**
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
  * @return string
769 769
  **/
770 770
 function proteger_amp($texte) {
771
-	return str_replace('&', '&amp;', $texte);
771
+    return str_replace('&', '&amp;', $texte);
772 772
 }
773 773
 
774 774
 
@@ -799,21 +799,21 @@  discard block
 block discarded – undo
799 799
  * @return mixed|string
800 800
  */
801 801
 function entites_html($texte, $tout = false, $quote = true) {
802
-	if (
803
-		!is_string($texte) or !$texte
804
-		or strpbrk($texte, "&\"'<>") == false
805
-	) {
806
-		return $texte;
807
-	}
808
-	include_spip('inc/texte');
809
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
810
-	$flags |= ENT_HTML401;
811
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
812
-	if ($tout) {
813
-		return corriger_toutes_entites_html($texte);
814
-	} else {
815
-		return corriger_entites_html($texte);
816
-	}
802
+    if (
803
+        !is_string($texte) or !$texte
804
+        or strpbrk($texte, "&\"'<>") == false
805
+    ) {
806
+        return $texte;
807
+    }
808
+    include_spip('inc/texte');
809
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
810
+    $flags |= ENT_HTML401;
811
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
812
+    if ($tout) {
813
+        return corriger_toutes_entites_html($texte);
814
+    } else {
815
+        return corriger_entites_html($texte);
816
+    }
817 817
 }
818 818
 
819 819
 /**
@@ -832,38 +832,38 @@  discard block
 block discarded – undo
832 832
  *     texte converti
833 833
  **/
834 834
 function filtrer_entites(?string $texte): string {
835
-	$texte ??= '';
836
-	if (strpos($texte, '&') === false) {
837
-		return $texte;
838
-	}
839
-	// filtrer
840
-	$texte = html2unicode($texte);
841
-	// remettre le tout dans le charset cible
842
-	$texte = unicode2charset($texte);
843
-	// cas particulier des " et ' qu'il faut filtrer aussi
844
-	// (on le faisait deja avec un &quot;)
845
-	if (strpos($texte, '&#') !== false) {
846
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
847
-	}
835
+    $texte ??= '';
836
+    if (strpos($texte, '&') === false) {
837
+        return $texte;
838
+    }
839
+    // filtrer
840
+    $texte = html2unicode($texte);
841
+    // remettre le tout dans le charset cible
842
+    $texte = unicode2charset($texte);
843
+    // cas particulier des " et ' qu'il faut filtrer aussi
844
+    // (on le faisait deja avec un &quot;)
845
+    if (strpos($texte, '&#') !== false) {
846
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
847
+    }
848 848
 
849
-	return $texte;
849
+    return $texte;
850 850
 }
851 851
 
852 852
 
853 853
 if (!function_exists('filtre_filtrer_entites_dist')) {
854
-	/**
855
-	 * Version sécurisée de filtrer_entites
856
-	 *
857
-	 * @uses interdire_scripts()
858
-	 * @uses filtrer_entites()
859
-	 *
860
-	 * @param string $t
861
-	 * @return string
862
-	 */
863
-	function filtre_filtrer_entites_dist($t) {
864
-		include_spip('inc/texte');
865
-		return interdire_scripts(filtrer_entites($t));
866
-	}
854
+    /**
855
+     * Version sécurisée de filtrer_entites
856
+     *
857
+     * @uses interdire_scripts()
858
+     * @uses filtrer_entites()
859
+     *
860
+     * @param string $t
861
+     * @return string
862
+     */
863
+    function filtre_filtrer_entites_dist($t) {
864
+        include_spip('inc/texte');
865
+        return interdire_scripts(filtrer_entites($t));
866
+    }
867 867
 }
868 868
 
869 869
 
@@ -878,18 +878,18 @@  discard block
 block discarded – undo
878 878
  * @return string|array
879 879
  **/
880 880
 function supprimer_caracteres_illegaux($texte) {
881
-	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";
882
-	static $to = null;
881
+    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";
882
+    static $to = null;
883 883
 
884
-	if (is_array($texte)) {
885
-		return array_map('supprimer_caracteres_illegaux', $texte);
886
-	}
884
+    if (is_array($texte)) {
885
+        return array_map('supprimer_caracteres_illegaux', $texte);
886
+    }
887 887
 
888
-	if (!$to) {
889
-		$to = str_repeat('-', strlen($from));
890
-	}
888
+    if (!$to) {
889
+        $to = str_repeat('-', strlen($from));
890
+    }
891 891
 
892
-	return strtr($texte, $from, $to);
892
+    return strtr($texte, $from, $to);
893 893
 }
894 894
 
895 895
 /**
@@ -901,10 +901,10 @@  discard block
 block discarded – undo
901 901
  * @return string|array
902 902
  **/
903 903
 function corriger_caracteres($texte) {
904
-	$texte = corriger_caracteres_windows($texte);
905
-	$texte = supprimer_caracteres_illegaux($texte);
904
+    $texte = corriger_caracteres_windows($texte);
905
+    $texte = supprimer_caracteres_illegaux($texte);
906 906
 
907
-	return $texte;
907
+    return $texte;
908 908
 }
909 909
 
910 910
 /**
@@ -921,44 +921,44 @@  discard block
 block discarded – undo
921 921
  *     texte encodé pour XML
922 922
  */
923 923
 function texte_backend(string $texte): string {
924
-	if ($texte === '') {
925
-		return '';
926
-	}
924
+    if ($texte === '') {
925
+        return '';
926
+    }
927 927
 
928
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
928
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
929 929
 
930
-	// si on a des liens ou des images, les passer en absolu
931
-	$texte = liens_absolus($texte);
930
+    // si on a des liens ou des images, les passer en absolu
931
+    $texte = liens_absolus($texte);
932 932
 
933
-	// echapper les tags &gt; &lt;
934
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
933
+    // echapper les tags &gt; &lt;
934
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
935 935
 
936
-	// importer les &eacute;
937
-	$texte = filtrer_entites($texte);
936
+    // importer les &eacute;
937
+    $texte = filtrer_entites($texte);
938 938
 
939
-	// " -> &quot; et tout ce genre de choses
940
-	$u = $GLOBALS['meta']['pcre_u'];
941
-	$texte = str_replace('&nbsp;', ' ', $texte);
942
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
943
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
944
-	$texte = entites_html($texte, false, false);
945
-	// mais bien echapper les double quotes !
946
-	$texte = str_replace('"', '&#034;', $texte);
939
+    // " -> &quot; et tout ce genre de choses
940
+    $u = $GLOBALS['meta']['pcre_u'];
941
+    $texte = str_replace('&nbsp;', ' ', $texte);
942
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
943
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
944
+    $texte = entites_html($texte, false, false);
945
+    // mais bien echapper les double quotes !
946
+    $texte = str_replace('"', '&#034;', $texte);
947 947
 
948
-	// verifier le charset
949
-	$texte = charset2unicode($texte);
948
+    // verifier le charset
949
+    $texte = charset2unicode($texte);
950 950
 
951
-	// Caracteres problematiques en iso-latin 1
952
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
953
-		$texte = str_replace(chr(156), '&#156;', $texte);
954
-		$texte = str_replace(chr(140), '&#140;', $texte);
955
-		$texte = str_replace(chr(159), '&#159;', $texte);
956
-	}
951
+    // Caracteres problematiques en iso-latin 1
952
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
953
+        $texte = str_replace(chr(156), '&#156;', $texte);
954
+        $texte = str_replace(chr(140), '&#140;', $texte);
955
+        $texte = str_replace(chr(159), '&#159;', $texte);
956
+    }
957 957
 
958
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
959
-	// et le caractere apostrophe alourdit les squelettes avec PHP
960
-	// ==> on les remplace par l'entite HTML
961
-	return str_replace($apostrophe, "'", $texte);
958
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
959
+    // et le caractere apostrophe alourdit les squelettes avec PHP
960
+    // ==> on les remplace par l'entite HTML
961
+    return str_replace($apostrophe, "'", $texte);
962 962
 }
963 963
 
964 964
 /**
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
  *     texte encodé et quote pour XML
976 976
  */
977 977
 function texte_backendq(string $texte): string {
978
-	return addslashes(texte_backend($texte));
978
+    return addslashes(texte_backend($texte));
979 979
 }
980 980
 
981 981
 
@@ -997,14 +997,14 @@  discard block
 block discarded – undo
997 997
  *     Texte sans son numéro éventuel
998 998
  **/
999 999
 function supprimer_numero(?string $texte): string {
1000
-	if ($texte === null) {
1001
-		return '';
1002
-	}
1003
-	return preg_replace(
1004
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1005
-		'',
1006
-		$texte
1007
-	);
1000
+    if ($texte === null) {
1001
+        return '';
1002
+    }
1003
+    return preg_replace(
1004
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1005
+        '',
1006
+        $texte
1007
+    );
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1027,18 +1027,18 @@  discard block
 block discarded – undo
1027 1027
  *     Numéro de titre, sinon chaîne vide
1028 1028
  **/
1029 1029
 function recuperer_numero(?string $texte): string {
1030
-	if (
1031
-		$texte and
1032
-		preg_match(
1033
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1034
-			$texte,
1035
-			$regs
1036
-		)
1037
-	) {
1038
-		return strval($regs[1]);
1039
-	} else {
1040
-		return '';
1041
-	}
1030
+    if (
1031
+        $texte and
1032
+        preg_match(
1033
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1034
+            $texte,
1035
+            $regs
1036
+        )
1037
+    ) {
1038
+        return strval($regs[1]);
1039
+    } else {
1040
+        return '';
1041
+    }
1042 1042
 }
1043 1043
 
1044 1044
 /**
@@ -1065,16 +1065,16 @@  discard block
 block discarded – undo
1065 1065
  *     texte ou tableau de textes converti
1066 1066
  **/
1067 1067
 function supprimer_tags($texte, $rempl = '') {
1068
-	if ($texte === null) {
1069
-		return '';
1070
-	}
1071
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1072
-	// ne pas oublier un < final non ferme car coupe
1073
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1074
-	// mais qui peut aussi etre un simple signe plus petit que
1075
-	$texte = str_replace('<', '&lt;', $texte);
1068
+    if ($texte === null) {
1069
+        return '';
1070
+    }
1071
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1072
+    // ne pas oublier un < final non ferme car coupe
1073
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1074
+    // mais qui peut aussi etre un simple signe plus petit que
1075
+    $texte = str_replace('<', '&lt;', $texte);
1076 1076
 
1077
-	return $texte;
1077
+    return $texte;
1078 1078
 }
1079 1079
 
1080 1080
 /**
@@ -1097,9 +1097,9 @@  discard block
 block discarded – undo
1097 1097
  *     texte converti
1098 1098
  **/
1099 1099
 function echapper_tags($texte, $rempl = '') {
1100
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1100
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1101 1101
 
1102
-	return $texte;
1102
+    return $texte;
1103 1103
 }
1104 1104
 
1105 1105
 /**
@@ -1120,18 +1120,18 @@  discard block
 block discarded – undo
1120 1120
  *     texte converti
1121 1121
  **/
1122 1122
 function textebrut($texte) {
1123
-	$u = $GLOBALS['meta']['pcre_u'];
1124
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1125
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1126
-	$texte = preg_replace("/^\n+/", '', $texte);
1127
-	$texte = preg_replace("/\n+$/", '', $texte);
1128
-	$texte = preg_replace("/\n +/", "\n", $texte);
1129
-	$texte = supprimer_tags($texte);
1130
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1131
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1132
-	$texte = str_replace('&#8217;', "'", $texte);
1123
+    $u = $GLOBALS['meta']['pcre_u'];
1124
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1125
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1126
+    $texte = preg_replace("/^\n+/", '', $texte);
1127
+    $texte = preg_replace("/\n+$/", '', $texte);
1128
+    $texte = preg_replace("/\n +/", "\n", $texte);
1129
+    $texte = supprimer_tags($texte);
1130
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1131
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1132
+    $texte = str_replace('&#8217;', "'", $texte);
1133 1133
 
1134
-	return $texte;
1134
+    return $texte;
1135 1135
 }
1136 1136
 
1137 1137
 
@@ -1147,23 +1147,23 @@  discard block
 block discarded – undo
1147 1147
  *     texte avec liens ouvrants
1148 1148
  **/
1149 1149
 function liens_ouvrants($texte) {
1150
-	if (
1151
-		preg_match_all(
1152
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1153
-			$texte,
1154
-			$liens,
1155
-			PREG_PATTERN_ORDER
1156
-		)
1157
-	) {
1158
-		foreach ($liens[0] as $a) {
1159
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1160
-			$ablank = inserer_attribut($a, 'rel', $rel);
1161
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1162
-			$texte = str_replace($a, $ablank, $texte);
1163
-		}
1164
-	}
1165
-
1166
-	return $texte;
1150
+    if (
1151
+        preg_match_all(
1152
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1153
+            $texte,
1154
+            $liens,
1155
+            PREG_PATTERN_ORDER
1156
+        )
1157
+    ) {
1158
+        foreach ($liens[0] as $a) {
1159
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1160
+            $ablank = inserer_attribut($a, 'rel', $rel);
1161
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1162
+            $texte = str_replace($a, $ablank, $texte);
1163
+        }
1164
+    }
1165
+
1166
+    return $texte;
1167 1167
 }
1168 1168
 
1169 1169
 /**
@@ -1173,22 +1173,22 @@  discard block
 block discarded – undo
1173 1173
  * @return string
1174 1174
  */
1175 1175
 function liens_nofollow($texte) {
1176
-	if (stripos($texte, '<a') === false) {
1177
-		return $texte;
1178
-	}
1176
+    if (stripos($texte, '<a') === false) {
1177
+        return $texte;
1178
+    }
1179 1179
 
1180
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1181
-		foreach ($regs[0] as $a) {
1182
-			$rel = extraire_attribut($a, 'rel') ?? '';
1183
-			if (strpos($rel, 'nofollow') === false) {
1184
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1185
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1186
-				$texte = str_replace($a, $anofollow, $texte);
1187
-			}
1188
-		}
1189
-	}
1180
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1181
+        foreach ($regs[0] as $a) {
1182
+            $rel = extraire_attribut($a, 'rel') ?? '';
1183
+            if (strpos($rel, 'nofollow') === false) {
1184
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1185
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1186
+                $texte = str_replace($a, $anofollow, $texte);
1187
+            }
1188
+        }
1189
+    }
1190 1190
 
1191
-	return $texte;
1191
+    return $texte;
1192 1192
 }
1193 1193
 
1194 1194
 /**
@@ -1207,12 +1207,12 @@  discard block
 block discarded – undo
1207 1207
  *     texte sans paraghaphes
1208 1208
  **/
1209 1209
 function PtoBR($texte) {
1210
-	$u = $GLOBALS['meta']['pcre_u'];
1211
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1212
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1213
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1210
+    $u = $GLOBALS['meta']['pcre_u'];
1211
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1212
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1213
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1214 1214
 
1215
-	return $texte;
1215
+    return $texte;
1216 1216
 }
1217 1217
 
1218 1218
 
@@ -1237,14 +1237,14 @@  discard block
 block discarded – undo
1237 1237
  * @return string texte encadré du style CSS
1238 1238
  */
1239 1239
 function lignes_longues($texte) {
1240
-	if (!strlen(trim($texte))) {
1241
-		return $texte;
1242
-	}
1243
-	include_spip('inc/texte');
1244
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1245
-		'div' : 'span';
1240
+    if (!strlen(trim($texte))) {
1241
+        return $texte;
1242
+    }
1243
+    include_spip('inc/texte');
1244
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1245
+        'div' : 'span';
1246 1246
 
1247
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1247
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1248 1248
 }
1249 1249
 
1250 1250
 /**
@@ -1263,30 +1263,30 @@  discard block
 block discarded – undo
1263 1263
  * @return string texte en majuscule
1264 1264
  */
1265 1265
 function majuscules($texte) {
1266
-	if (!strlen($texte)) {
1267
-		return '';
1268
-	}
1266
+    if (!strlen($texte)) {
1267
+        return '';
1268
+    }
1269 1269
 
1270
-	// Cas du turc
1271
-	if ($GLOBALS['spip_lang'] == 'tr') {
1272
-		# remplacer hors des tags et des entites
1273
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1274
-			foreach ($regs as $n => $match) {
1275
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1276
-			}
1277
-		}
1270
+    // Cas du turc
1271
+    if ($GLOBALS['spip_lang'] == 'tr') {
1272
+        # remplacer hors des tags et des entites
1273
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1274
+            foreach ($regs as $n => $match) {
1275
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1276
+            }
1277
+        }
1278 1278
 
1279
-		$texte = str_replace('i', '&#304;', $texte);
1279
+        $texte = str_replace('i', '&#304;', $texte);
1280 1280
 
1281
-		if ($regs) {
1282
-			foreach ($regs as $n => $match) {
1283
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1284
-			}
1285
-		}
1286
-	}
1281
+        if ($regs) {
1282
+            foreach ($regs as $n => $match) {
1283
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1284
+            }
1285
+        }
1286
+    }
1287 1287
 
1288
-	// Cas general
1289
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1288
+    // Cas general
1289
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1290 1290
 }
1291 1291
 
1292 1292
 /**
@@ -1304,29 +1304,29 @@  discard block
 block discarded – undo
1304 1304
  * @return string
1305 1305
  **/
1306 1306
 function taille_en_octets($taille) {
1307
-	if (!defined('_KILOBYTE')) {
1308
-		/**
1309
-		 * Définit le nombre d'octets dans un Kilobyte
1310
-		 *
1311
-		 * @var int
1312
-		 **/
1313
-		define('_KILOBYTE', 1024);
1314
-	}
1307
+    if (!defined('_KILOBYTE')) {
1308
+        /**
1309
+         * Définit le nombre d'octets dans un Kilobyte
1310
+         *
1311
+         * @var int
1312
+         **/
1313
+        define('_KILOBYTE', 1024);
1314
+    }
1315 1315
 
1316
-	if ($taille < 1) {
1317
-		return '';
1318
-	}
1319
-	if ($taille < _KILOBYTE) {
1320
-		$taille = _T('taille_octets', ['taille' => $taille]);
1321
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1322
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1323
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1324
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1325
-	} else {
1326
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1327
-	}
1316
+    if ($taille < 1) {
1317
+        return '';
1318
+    }
1319
+    if ($taille < _KILOBYTE) {
1320
+        $taille = _T('taille_octets', ['taille' => $taille]);
1321
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1322
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1323
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1324
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1325
+    } else {
1326
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1327
+    }
1328 1328
 
1329
-	return $taille;
1329
+    return $taille;
1330 1330
 }
1331 1331
 
1332 1332
 
@@ -1348,21 +1348,21 @@  discard block
 block discarded – undo
1348 1348
  *     texte prêt pour être utilisé en attribut HTML
1349 1349
  **/
1350 1350
 function attribut_html(?string $texte, $textebrut = true): string {
1351
-	if ($texte === null) {
1352
-		return '';
1353
-	}
1354
-	$u = $GLOBALS['meta']['pcre_u'];
1355
-	if ($textebrut) {
1356
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1357
-	}
1358
-	$texte = texte_backend($texte);
1359
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1351
+    if ($texte === null) {
1352
+        return '';
1353
+    }
1354
+    $u = $GLOBALS['meta']['pcre_u'];
1355
+    if ($textebrut) {
1356
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1357
+    }
1358
+    $texte = texte_backend($texte);
1359
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1360 1360
 
1361
-	return preg_replace(
1362
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1363
-		['&', '&#38;'],
1364
-		$texte
1365
-	);
1361
+    return preg_replace(
1362
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1363
+        ['&', '&#38;'],
1364
+        $texte
1365
+    );
1366 1366
 }
1367 1367
 
1368 1368
 
@@ -1382,15 +1382,15 @@  discard block
 block discarded – undo
1382 1382
  *     URL ou chaîne vide
1383 1383
  **/
1384 1384
 function vider_url(?string $url, $entites = true): string {
1385
-	if ($url === null) {
1386
-		return '';
1387
-	}
1388
-	# un message pour abs_url
1389
-	$GLOBALS['mode_abs_url'] = 'url';
1390
-	$url = trim($url);
1391
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1385
+    if ($url === null) {
1386
+        return '';
1387
+    }
1388
+    # un message pour abs_url
1389
+    $GLOBALS['mode_abs_url'] = 'url';
1390
+    $url = trim($url);
1391
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1392 1392
 
1393
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1393
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1394 1394
 }
1395 1395
 
1396 1396
 
@@ -1405,10 +1405,10 @@  discard block
 block discarded – undo
1405 1405
  * @return string Adresse email maquillée
1406 1406
  **/
1407 1407
 function antispam($texte) {
1408
-	include_spip('inc/acces');
1409
-	$masque = creer_pass_aleatoire(3);
1408
+    include_spip('inc/acces');
1409
+    $masque = creer_pass_aleatoire(3);
1410 1410
 
1411
-	return preg_replace('/@/', " $masque ", $texte);
1411
+    return preg_replace('/@/', " $masque ", $texte);
1412 1412
 }
1413 1413
 
1414 1414
 /**
@@ -1440,8 +1440,8 @@  discard block
 block discarded – undo
1440 1440
  *     True si on a le droit d'accès, false sinon.
1441 1441
  **/
1442 1442
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1443
-	include_spip('inc/acces');
1444
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1443
+    include_spip('inc/acces');
1444
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1445 1445
 }
1446 1446
 
1447 1447
 /**
@@ -1466,13 +1466,13 @@  discard block
 block discarded – undo
1466 1466
  *     Retourne $texte, sinon $sinon.
1467 1467
  **/
1468 1468
 function sinon($texte, $sinon = '') {
1469
-	if ($texte) {
1470
-		return $texte;
1471
-	} elseif (is_scalar($texte) and strlen($texte)) {
1472
-		return $texte;
1473
-	} else {
1474
-		return $sinon;
1475
-	}
1469
+    if ($texte) {
1470
+        return $texte;
1471
+    } elseif (is_scalar($texte) and strlen($texte)) {
1472
+        return $texte;
1473
+    } else {
1474
+        return $sinon;
1475
+    }
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
  * @return mixed
1497 1497
  **/
1498 1498
 function choixsivide($a, $vide, $pasvide) {
1499
-	return $a ? $pasvide : $vide;
1499
+    return $a ? $pasvide : $vide;
1500 1500
 }
1501 1501
 
1502 1502
 /**
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
  * @return mixed
1521 1521
  **/
1522 1522
 function choixsiegal($a1, $a2, $v, $f) {
1523
-	return ($a1 == $a2) ? $v : $f;
1523
+    return ($a1 == $a2) ? $v : $f;
1524 1524
 }
1525 1525
 
1526 1526
 //
@@ -1539,13 +1539,13 @@  discard block
 block discarded – undo
1539 1539
  * @return string
1540 1540
  **/
1541 1541
 function filtrer_ical($texte) {
1542
-	#include_spip('inc/charsets');
1543
-	$texte = html2unicode($texte);
1544
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1545
-	$texte = preg_replace("/\n/", ' ', $texte);
1546
-	$texte = preg_replace('/,/', '\,', $texte);
1542
+    #include_spip('inc/charsets');
1543
+    $texte = html2unicode($texte);
1544
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1545
+    $texte = preg_replace("/\n/", ' ', $texte);
1546
+    $texte = preg_replace('/,/', '\,', $texte);
1547 1547
 
1548
-	return $texte;
1548
+    return $texte;
1549 1549
 }
1550 1550
 
1551 1551
 
@@ -1570,58 +1570,58 @@  discard block
 block discarded – undo
1570 1570
  * @return string
1571 1571
  **/
1572 1572
 function post_autobr($texte, $delim = "\n_ ") {
1573
-	if (!function_exists('echappe_html')) {
1574
-		include_spip('inc/texte_mini');
1575
-	}
1576
-	$texte = str_replace("\r\n", "\r", $texte);
1577
-	$texte = str_replace("\r", "\n", $texte);
1578
-
1579
-	if (preg_match(",\n+$,", $texte, $fin)) {
1580
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1581
-	} else {
1582
-		$fin = '';
1583
-	}
1584
-
1585
-	$texte = echappe_html($texte, '', true);
1586
-
1587
-	// echapper les modeles
1588
-	$collecteurModeles = null;
1589
-	if (strpos($texte, '<') !== false) {
1590
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1591
-		include_spip("src/Texte/Collecteur/Modeles");
1592
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1593
-		$texte = $collecteurModeles->echapper($texte);
1594
-	}
1595
-
1596
-	$debut = '';
1597
-	$suite = $texte;
1598
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1599
-		$debut .= substr($suite, 0, $t - 1);
1600
-		$suite = substr($suite, $t);
1601
-		$car = substr($suite, 0, 1);
1602
-		if (
1603
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1604
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1605
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1606
-		) {
1607
-			$debut .= $delim;
1608
-		} else {
1609
-			$debut .= "\n";
1610
-		}
1611
-		if (preg_match(",^\n+,", $suite, $regs)) {
1612
-			$debut .= $regs[0];
1613
-			$suite = substr($suite, strlen($regs[0]));
1614
-		}
1615
-	}
1616
-	$texte = $debut . $suite;
1617
-
1618
-	if ($collecteurModeles) {
1619
-		$texte = $collecteurModeles->retablir($texte);
1620
-	}
1621
-
1622
-	$texte = echappe_retour($texte);
1623
-
1624
-	return $texte . $fin;
1573
+    if (!function_exists('echappe_html')) {
1574
+        include_spip('inc/texte_mini');
1575
+    }
1576
+    $texte = str_replace("\r\n", "\r", $texte);
1577
+    $texte = str_replace("\r", "\n", $texte);
1578
+
1579
+    if (preg_match(",\n+$,", $texte, $fin)) {
1580
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1581
+    } else {
1582
+        $fin = '';
1583
+    }
1584
+
1585
+    $texte = echappe_html($texte, '', true);
1586
+
1587
+    // echapper les modeles
1588
+    $collecteurModeles = null;
1589
+    if (strpos($texte, '<') !== false) {
1590
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1591
+        include_spip("src/Texte/Collecteur/Modeles");
1592
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1593
+        $texte = $collecteurModeles->echapper($texte);
1594
+    }
1595
+
1596
+    $debut = '';
1597
+    $suite = $texte;
1598
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1599
+        $debut .= substr($suite, 0, $t - 1);
1600
+        $suite = substr($suite, $t);
1601
+        $car = substr($suite, 0, 1);
1602
+        if (
1603
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1604
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1605
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1606
+        ) {
1607
+            $debut .= $delim;
1608
+        } else {
1609
+            $debut .= "\n";
1610
+        }
1611
+        if (preg_match(",^\n+,", $suite, $regs)) {
1612
+            $debut .= $regs[0];
1613
+            $suite = substr($suite, strlen($regs[0]));
1614
+        }
1615
+    }
1616
+    $texte = $debut . $suite;
1617
+
1618
+    if ($collecteurModeles) {
1619
+        $texte = $collecteurModeles->retablir($texte);
1620
+    }
1621
+
1622
+    $texte = echappe_retour($texte);
1623
+
1624
+    return $texte . $fin;
1625 1625
 }
1626 1626
 
1627 1627
 
@@ -1656,30 +1656,30 @@  discard block
 block discarded – undo
1656 1656
  **/
1657 1657
 function extraire_idiome($letexte, $lang = null, $options = []) {
1658 1658
 
1659
-	if (
1660
-		$letexte
1661
-		and strpos($letexte, '<:') !== false
1662
-	) {
1663
-		if (!$lang) {
1664
-			$lang = $GLOBALS['spip_lang'];
1665
-		}
1666
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
-		if (is_bool($options)) {
1668
-			$options = ['echappe_span' => $options];
1669
-		}
1670
-		if (!isset($options['echappe_span'])) {
1671
-			$options = array_merge($options, ['echappe_span' => false]);
1672
-		}
1673
-		$options['lang'] = $lang;
1659
+    if (
1660
+        $letexte
1661
+        and strpos($letexte, '<:') !== false
1662
+    ) {
1663
+        if (!$lang) {
1664
+            $lang = $GLOBALS['spip_lang'];
1665
+        }
1666
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
+        if (is_bool($options)) {
1668
+            $options = ['echappe_span' => $options];
1669
+        }
1670
+        if (!isset($options['echappe_span'])) {
1671
+            $options = array_merge($options, ['echappe_span' => false]);
1672
+        }
1673
+        $options['lang'] = $lang;
1674 1674
 
1675
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1676
-		include_spip("src/Texte/Collecteur/Idiomes");
1677
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1675
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1676
+        include_spip("src/Texte/Collecteur/Idiomes");
1677
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1678 1678
 
1679
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1679
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1680 1680
 
1681
-	}
1682
-	return $letexte;
1681
+    }
1682
+    return $letexte;
1683 1683
 }
1684 1684
 
1685 1685
 /**
@@ -1717,34 +1717,34 @@  discard block
 block discarded – undo
1717 1717
  **/
1718 1718
 function extraire_multi($letexte, $lang = null, $options = []) {
1719 1719
 
1720
-	if (
1721
-		$letexte
1722
-		and stripos($letexte, '<multi') !== false
1723
-	) {
1724
-		if (!$lang) {
1725
-			$lang = $GLOBALS['spip_lang'];
1726
-		}
1720
+    if (
1721
+        $letexte
1722
+        and stripos($letexte, '<multi') !== false
1723
+    ) {
1724
+        if (!$lang) {
1725
+            $lang = $GLOBALS['spip_lang'];
1726
+        }
1727 1727
 
1728
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1729
-		if (is_bool($options)) {
1730
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1731
-		}
1732
-		if (!isset($options['echappe_span'])) {
1733
-			$options = array_merge($options, ['echappe_span' => false]);
1734
-		}
1735
-		if (!isset($options['lang_defaut'])) {
1736
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1737
-		}
1738
-		$options['lang'] = $lang;
1728
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1729
+        if (is_bool($options)) {
1730
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1731
+        }
1732
+        if (!isset($options['echappe_span'])) {
1733
+            $options = array_merge($options, ['echappe_span' => false]);
1734
+        }
1735
+        if (!isset($options['lang_defaut'])) {
1736
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1737
+        }
1738
+        $options['lang'] = $lang;
1739 1739
 
1740
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1741
-		include_spip("src/Texte/Collecteur/Multis");
1742
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1740
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1741
+        include_spip("src/Texte/Collecteur/Multis");
1742
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1743 1743
 
1744
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1745
-	}
1744
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1745
+    }
1746 1746
 
1747
-	return $letexte;
1747
+    return $letexte;
1748 1748
 }
1749 1749
 
1750 1750
 /**
@@ -1754,7 +1754,7 @@  discard block
 block discarded – undo
1754 1754
  * @return string L'initiale en majuscule
1755 1755
  */
1756 1756
 function filtre_initiale($nom) {
1757
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1757
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1758 1758
 }
1759 1759
 
1760 1760
 
@@ -1799,33 +1799,33 @@  discard block
 block discarded – undo
1799 1799
  *      - null (interne) : si on empile
1800 1800
  **/
1801 1801
 function unique($donnee, $famille = '', $cpt = false) {
1802
-	static $mem = [];
1803
-	// permettre de vider la pile et de la restaurer
1804
-	// pour le calcul de introduction...
1805
-	if ($famille == '_spip_raz_') {
1806
-		$tmp = $mem;
1807
-		$mem = [];
1808
-
1809
-		return $tmp;
1810
-	} elseif ($famille == '_spip_set_') {
1811
-		$mem = $donnee;
1812
-
1813
-		return;
1814
-	}
1815
-	// eviter une notice
1816
-	if (!isset($mem[$famille])) {
1817
-		$mem[$famille] = [];
1818
-	}
1819
-	if ($cpt) {
1820
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1821
-	}
1822
-	// eviter une notice
1823
-	if (!isset($mem[$famille][$donnee])) {
1824
-		$mem[$famille][$donnee] = 0;
1825
-	}
1826
-	if (!($mem[$famille][$donnee]++)) {
1827
-		return $donnee;
1828
-	}
1802
+    static $mem = [];
1803
+    // permettre de vider la pile et de la restaurer
1804
+    // pour le calcul de introduction...
1805
+    if ($famille == '_spip_raz_') {
1806
+        $tmp = $mem;
1807
+        $mem = [];
1808
+
1809
+        return $tmp;
1810
+    } elseif ($famille == '_spip_set_') {
1811
+        $mem = $donnee;
1812
+
1813
+        return;
1814
+    }
1815
+    // eviter une notice
1816
+    if (!isset($mem[$famille])) {
1817
+        $mem[$famille] = [];
1818
+    }
1819
+    if ($cpt) {
1820
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1821
+    }
1822
+    // eviter une notice
1823
+    if (!isset($mem[$famille][$donnee])) {
1824
+        $mem[$famille][$donnee] = 0;
1825
+    }
1826
+    if (!($mem[$famille][$donnee]++)) {
1827
+        return $donnee;
1828
+    }
1829 1829
 }
1830 1830
 
1831 1831
 
@@ -1855,20 +1855,20 @@  discard block
 block discarded – undo
1855 1855
  *     Une des valeurs en fonction du compteur.
1856 1856
  **/
1857 1857
 function alterner($i, ...$args) {
1858
-	// recuperer les arguments (attention fonctions un peu space)
1859
-	$num = count($args);
1858
+    // recuperer les arguments (attention fonctions un peu space)
1859
+    $num = count($args);
1860 1860
 
1861
-	if ($num === 1 && is_array($args[0])) {
1862
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1863
-		$args = array_values($args[0]);
1864
-		$num = count($args);
1865
-	}
1861
+    if ($num === 1 && is_array($args[0])) {
1862
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1863
+        $args = array_values($args[0]);
1864
+        $num = count($args);
1865
+    }
1866 1866
 
1867
-	// un index compris entre 0 et num exclus
1868
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1869
-	$i = ($i + $num) % $num; // dans [0;$num[
1870
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1871
-	return $args[$i];
1867
+    // un index compris entre 0 et num exclus
1868
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1869
+    $i = ($i + $num) % $num; // dans [0;$num[
1870
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1871
+    return $args[$i];
1872 1872
 }
1873 1873
 
1874 1874
 
@@ -1894,52 +1894,52 @@  discard block
 block discarded – undo
1894 1894
  *     - null lorsque l’attribut n’existe pas.
1895 1895
  **/
1896 1896
 function extraire_attribut($balise, $attribut, $complet = false) {
1897
-	if (is_array($balise)) {
1898
-		array_walk(
1899
-			$balise,
1900
-			function (&$a, $key, $t) {
1901
-				$a = extraire_attribut($a, $t);
1902
-			},
1903
-			$attribut
1904
-		);
1905
-
1906
-		return $balise;
1907
-	}
1908
-	if (
1909
-		$balise
1910
-		&& stripos($balise, $attribut) !== false
1911
-		&& preg_match(
1912
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1913
-			. $attribut
1914
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1915
-			$balise,
1916
-			$r
1917
-		)
1918
-	) {
1919
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1920
-			$r[4] = substr($r[3], 1, -1);
1921
-			$r[3] = $r[3][0];
1922
-		} elseif ($r[3] !== '') {
1923
-			$r[4] = $r[3];
1924
-			$r[3] = '';
1925
-		} else {
1926
-			$r[4] = trim($r[2]);
1927
-		}
1928
-		$att = $r[4];
1929
-		if (strpos($att, '&#') !== false) {
1930
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1931
-		}
1932
-		$att = filtrer_entites($att);
1933
-	} else {
1934
-		$att = null;
1935
-		$r = [];
1936
-	}
1937
-
1938
-	if ($complet) {
1939
-		return [$att, $r];
1940
-	} else {
1941
-		return $att;
1942
-	}
1897
+    if (is_array($balise)) {
1898
+        array_walk(
1899
+            $balise,
1900
+            function (&$a, $key, $t) {
1901
+                $a = extraire_attribut($a, $t);
1902
+            },
1903
+            $attribut
1904
+        );
1905
+
1906
+        return $balise;
1907
+    }
1908
+    if (
1909
+        $balise
1910
+        && stripos($balise, $attribut) !== false
1911
+        && preg_match(
1912
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1913
+            . $attribut
1914
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1915
+            $balise,
1916
+            $r
1917
+        )
1918
+    ) {
1919
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1920
+            $r[4] = substr($r[3], 1, -1);
1921
+            $r[3] = $r[3][0];
1922
+        } elseif ($r[3] !== '') {
1923
+            $r[4] = $r[3];
1924
+            $r[3] = '';
1925
+        } else {
1926
+            $r[4] = trim($r[2]);
1927
+        }
1928
+        $att = $r[4];
1929
+        if (strpos($att, '&#') !== false) {
1930
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1931
+        }
1932
+        $att = filtrer_entites($att);
1933
+    } else {
1934
+        $att = null;
1935
+        $r = [];
1936
+    }
1937
+
1938
+    if ($complet) {
1939
+        return [$att, $r];
1940
+    } else {
1941
+        return $att;
1942
+    }
1943 1943
 }
1944 1944
 
1945 1945
 /**
@@ -1972,41 +1972,41 @@  discard block
 block discarded – undo
1972 1972
  **/
1973 1973
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
1974 1974
 
1975
-	if ($balise === null or $balise === '') {
1976
-		return '';
1977
-	}
1975
+    if ($balise === null or $balise === '') {
1976
+        return '';
1977
+    }
1978 1978
 
1979
-	// preparer l'attribut
1980
-	// supprimer les &nbsp; etc mais pas les balises html
1981
-	// qui ont un sens dans un attribut value d'un input
1982
-	if ($proteger) {
1983
-		$val = attribut_html($val, false);
1984
-	}
1979
+    // preparer l'attribut
1980
+    // supprimer les &nbsp; etc mais pas les balises html
1981
+    // qui ont un sens dans un attribut value d'un input
1982
+    if ($proteger) {
1983
+        $val = attribut_html($val, false);
1984
+    }
1985 1985
 
1986
-	// echapper les ' pour eviter tout bug
1987
-	$val = str_replace("'", '&#039;', $val);
1988
-	if ($vider and strlen($val) === 0) {
1989
-		$insert = '';
1990
-	} else {
1991
-		$insert = " $attribut='$val'";
1992
-	}
1986
+    // echapper les ' pour eviter tout bug
1987
+    $val = str_replace("'", '&#039;', $val);
1988
+    if ($vider and strlen($val) === 0) {
1989
+        $insert = '';
1990
+    } else {
1991
+        $insert = " $attribut='$val'";
1992
+    }
1993 1993
 
1994
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
1994
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
1995 1995
 
1996
-	if ($old !== null) {
1997
-		// Remplacer l'ancien attribut du meme nom
1998
-		$balise = $r[1] . $insert . $r[5];
1999
-	} else {
2000
-		// preferer une balise " />" (comme <img />)
2001
-		if (preg_match(',/>,', $balise)) {
2002
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2003
-		} // sinon une balise <a ...> ... </a>
2004
-		else {
2005
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2006
-		}
2007
-	}
1996
+    if ($old !== null) {
1997
+        // Remplacer l'ancien attribut du meme nom
1998
+        $balise = $r[1] . $insert . $r[5];
1999
+    } else {
2000
+        // preferer une balise " />" (comme <img />)
2001
+        if (preg_match(',/>,', $balise)) {
2002
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2003
+        } // sinon une balise <a ...> ... </a>
2004
+        else {
2005
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2006
+        }
2007
+    }
2008 2008
 
2009
-	return $balise;
2009
+    return $balise;
2010 2010
 }
2011 2011
 
2012 2012
 /**
@@ -2024,7 +2024,7 @@  discard block
 block discarded – undo
2024 2024
  * @return string Code HTML sans l'attribut
2025 2025
  **/
2026 2026
 function vider_attribut(?string $balise, string $attribut): string {
2027
-	return inserer_attribut($balise, $attribut, '', false, true);
2027
+    return inserer_attribut($balise, $attribut, '', false, true);
2028 2028
 }
2029 2029
 
2030 2030
 /**
@@ -2036,53 +2036,53 @@  discard block
 block discarded – undo
2036 2036
  * @return string
2037 2037
  */
2038 2038
 function modifier_class($balise, $class, $operation = 'ajouter') {
2039
-	if (is_string($class)) {
2040
-		$class = explode(' ', trim($class));
2041
-	}
2042
-	$class = array_filter($class);
2043
-	$class = array_unique($class);
2044
-	if (!$class) {
2045
-		return $balise;
2046
-	}
2047
-
2048
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2049
-	if (preg_match(',[^\w-],', implode('', $class))) {
2050
-		return $balise;
2051
-	}
2052
-
2053
-	$class_courante = extraire_attribut($balise, 'class');
2054
-	$class_new = $class_courante;
2055
-	foreach ($class as $c) {
2056
-		$is_class_presente = false;
2057
-		if (
2058
-			$class_courante
2059
-			and str_contains($class_courante, (string) $c)
2060
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2061
-		) {
2062
-			$is_class_presente = true;
2063
-		}
2064
-		if (
2065
-			in_array($operation, ['ajouter', 'commuter'])
2066
-			and !$is_class_presente
2067
-		) {
2068
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2069
-		} elseif (
2070
-			in_array($operation, ['supprimer', 'commuter'])
2071
-			and $is_class_presente
2072
-		) {
2073
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2074
-		}
2075
-	}
2076
-
2077
-	if ($class_new !== $class_courante) {
2078
-		if (strlen($class_new)) {
2079
-			$balise = inserer_attribut($balise, 'class', $class_new);
2080
-		} elseif ($class_courante) {
2081
-			$balise = vider_attribut($balise, 'class');
2082
-		}
2083
-	}
2084
-
2085
-	return $balise;
2039
+    if (is_string($class)) {
2040
+        $class = explode(' ', trim($class));
2041
+    }
2042
+    $class = array_filter($class);
2043
+    $class = array_unique($class);
2044
+    if (!$class) {
2045
+        return $balise;
2046
+    }
2047
+
2048
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2049
+    if (preg_match(',[^\w-],', implode('', $class))) {
2050
+        return $balise;
2051
+    }
2052
+
2053
+    $class_courante = extraire_attribut($balise, 'class');
2054
+    $class_new = $class_courante;
2055
+    foreach ($class as $c) {
2056
+        $is_class_presente = false;
2057
+        if (
2058
+            $class_courante
2059
+            and str_contains($class_courante, (string) $c)
2060
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2061
+        ) {
2062
+            $is_class_presente = true;
2063
+        }
2064
+        if (
2065
+            in_array($operation, ['ajouter', 'commuter'])
2066
+            and !$is_class_presente
2067
+        ) {
2068
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2069
+        } elseif (
2070
+            in_array($operation, ['supprimer', 'commuter'])
2071
+            and $is_class_presente
2072
+        ) {
2073
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2074
+        }
2075
+    }
2076
+
2077
+    if ($class_new !== $class_courante) {
2078
+        if (strlen($class_new)) {
2079
+            $balise = inserer_attribut($balise, 'class', $class_new);
2080
+        } elseif ($class_courante) {
2081
+            $balise = vider_attribut($balise, 'class');
2082
+        }
2083
+    }
2084
+
2085
+    return $balise;
2086 2086
 }
2087 2087
 
2088 2088
 /**
@@ -2092,7 +2092,7 @@  discard block
 block discarded – undo
2092 2092
  * @return string
2093 2093
  */
2094 2094
 function ajouter_class($balise, $class) {
2095
-	return modifier_class($balise, $class, 'ajouter');
2095
+    return modifier_class($balise, $class, 'ajouter');
2096 2096
 }
2097 2097
 
2098 2098
 /**
@@ -2102,7 +2102,7 @@  discard block
 block discarded – undo
2102 2102
  * @return string
2103 2103
  */
2104 2104
 function supprimer_class($balise, $class) {
2105
-	return modifier_class($balise, $class, 'supprimer');
2105
+    return modifier_class($balise, $class, 'supprimer');
2106 2106
 }
2107 2107
 
2108 2108
 /**
@@ -2113,7 +2113,7 @@  discard block
 block discarded – undo
2113 2113
  * @return string
2114 2114
  */
2115 2115
 function commuter_class($balise, $class) {
2116
-	return modifier_class($balise, $class, 'commuter');
2116
+    return modifier_class($balise, $class, 'commuter');
2117 2117
 }
2118 2118
 
2119 2119
 /**
@@ -2124,19 +2124,19 @@  discard block
 block discarded – undo
2124 2124
  * @return string
2125 2125
  */
2126 2126
 function tester_config($id, $mode = '') {
2127
-	include_spip('action/inscrire_auteur');
2127
+    include_spip('action/inscrire_auteur');
2128 2128
 
2129
-	return tester_statut_inscription($mode, $id);
2129
+    return tester_statut_inscription($mode, $id);
2130 2130
 }
2131 2131
 
2132 2132
 //
2133 2133
 // Quelques fonctions de calcul arithmetique
2134 2134
 //
2135 2135
 function floatstr($a) {
2136
- return str_replace(',', '.', (string)floatval($a));
2136
+    return str_replace(',', '.', (string)floatval($a));
2137 2137
 }
2138 2138
 function strize($f, $a, $b) {
2139
- return floatstr($f(floatstr($a), floatstr($b)));
2139
+    return floatstr($f(floatstr($a), floatstr($b)));
2140 2140
 }
2141 2141
 
2142 2142
 /**
@@ -2155,11 +2155,11 @@  discard block
 block discarded – undo
2155 2155
  * @return int $a+$b
2156 2156
  **/
2157 2157
 function plus($a, $b) {
2158
-	return $a + $b;
2158
+    return $a + $b;
2159 2159
 }
2160 2160
 
2161 2161
 function strplus($a, $b) {
2162
-	return strize('plus', $a, $b);
2162
+    return strize('plus', $a, $b);
2163 2163
 }
2164 2164
 
2165 2165
 /**
@@ -2178,11 +2178,11 @@  discard block
 block discarded – undo
2178 2178
  * @return int $a-$b
2179 2179
  **/
2180 2180
 function moins($a, $b) {
2181
-	return $a - $b;
2181
+    return $a - $b;
2182 2182
 }
2183 2183
 
2184 2184
 function strmoins($a, $b) {
2185
-	return strize('moins', $a, $b);
2185
+    return strize('moins', $a, $b);
2186 2186
 }
2187 2187
 
2188 2188
 /**
@@ -2202,11 +2202,11 @@  discard block
 block discarded – undo
2202 2202
  * @return int $a*$b
2203 2203
  **/
2204 2204
 function mult($a, $b) {
2205
-	return $a * $b;
2205
+    return $a * $b;
2206 2206
 }
2207 2207
 
2208 2208
 function strmult($a, $b) {
2209
-	return strize('mult', $a, $b);
2209
+    return strize('mult', $a, $b);
2210 2210
 }
2211 2211
 
2212 2212
 /**
@@ -2226,11 +2226,11 @@  discard block
 block discarded – undo
2226 2226
  * @return int $a/$b (ou 0 si $b est nul)
2227 2227
  **/
2228 2228
 function div($a, $b) {
2229
-	return $b ? $a / $b : 0;
2229
+    return $b ? $a / $b : 0;
2230 2230
 }
2231 2231
 
2232 2232
 function strdiv($a, $b) {
2233
-	return strize('div', $a, $b);
2233
+    return strize('div', $a, $b);
2234 2234
 }
2235 2235
 
2236 2236
 /**
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
  * @return int ($nb % $mod) + $add
2252 2252
  **/
2253 2253
 function modulo($nb, $mod, $add = 0) {
2254
-	return ($mod ? $nb % $mod : 0) + $add;
2254
+    return ($mod ? $nb % $mod : 0) + $add;
2255 2255
 }
2256 2256
 
2257 2257
 
@@ -2266,26 +2266,26 @@  discard block
 block discarded – undo
2266 2266
  *      - true sinon
2267 2267
  **/
2268 2268
 function nom_acceptable($nom) {
2269
-	$remp2 = [];
2270
-	$remp1 = [];
2271
-	if (!is_string($nom)) {
2272
-		return false;
2273
-	}
2274
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2275
-		define('_TAGS_NOM_AUTEUR', '');
2276
-	}
2277
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2278
-	foreach ($tags_acceptes as $tag) {
2279
-		if (strlen($tag)) {
2280
-			$remp1[] = '<' . trim($tag) . '>';
2281
-			$remp1[] = '</' . trim($tag) . '>';
2282
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2283
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2284
-		}
2285
-	}
2286
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2287
-
2288
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2269
+    $remp2 = [];
2270
+    $remp1 = [];
2271
+    if (!is_string($nom)) {
2272
+        return false;
2273
+    }
2274
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2275
+        define('_TAGS_NOM_AUTEUR', '');
2276
+    }
2277
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2278
+    foreach ($tags_acceptes as $tag) {
2279
+        if (strlen($tag)) {
2280
+            $remp1[] = '<' . trim($tag) . '>';
2281
+            $remp1[] = '</' . trim($tag) . '>';
2282
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2283
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2284
+        }
2285
+    }
2286
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2287
+
2288
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2289 2289
 }
2290 2290
 
2291 2291
 
@@ -2301,14 +2301,14 @@  discard block
 block discarded – undo
2301 2301
  *      - renvoie un tableau si l'entree est un tableau
2302 2302
  **/
2303 2303
 function email_valide($adresses) {
2304
-	if (is_array($adresses)) {
2305
-		$adresses = array_map('email_valide', $adresses);
2306
-		$adresses = array_filter($adresses);
2307
-		return $adresses;
2308
-	}
2304
+    if (is_array($adresses)) {
2305
+        $adresses = array_map('email_valide', $adresses);
2306
+        $adresses = array_filter($adresses);
2307
+        return $adresses;
2308
+    }
2309 2309
 
2310
-	$email_valide = charger_fonction('email_valide', 'inc');
2311
-	return $email_valide($adresses);
2310
+    $email_valide = charger_fonction('email_valide', 'inc');
2311
+    return $email_valide($adresses);
2312 2312
 }
2313 2313
 
2314 2314
 /**
@@ -2322,29 +2322,29 @@  discard block
 block discarded – undo
2322 2322
  * @return string texte
2323 2323
  **/
2324 2324
 function afficher_enclosures($tags) {
2325
-	$s = [];
2326
-	foreach (extraire_balises($tags, 'a') as $tag) {
2327
-		if (
2328
-			extraire_attribut($tag, 'rel') == 'enclosure'
2329
-			and $t = extraire_attribut($tag, 'href')
2330
-		) {
2331
-			$s[] = preg_replace(
2332
-				',>[^<]+</a>,S',
2333
-				'>'
2334
-				. http_img_pack(
2335
-					'attachment-16.png',
2336
-					$t,
2337
-					'',
2338
-					$t,
2339
-					['utiliser_suffixe_size' => true]
2340
-				)
2341
-				. '</a>',
2342
-				$tag
2343
-			);
2344
-		}
2345
-	}
2346
-
2347
-	return join('&nbsp;', $s);
2325
+    $s = [];
2326
+    foreach (extraire_balises($tags, 'a') as $tag) {
2327
+        if (
2328
+            extraire_attribut($tag, 'rel') == 'enclosure'
2329
+            and $t = extraire_attribut($tag, 'href')
2330
+        ) {
2331
+            $s[] = preg_replace(
2332
+                ',>[^<]+</a>,S',
2333
+                '>'
2334
+                . http_img_pack(
2335
+                    'attachment-16.png',
2336
+                    $t,
2337
+                    '',
2338
+                    $t,
2339
+                    ['utiliser_suffixe_size' => true]
2340
+                )
2341
+                . '</a>',
2342
+                $tag
2343
+            );
2344
+        }
2345
+    }
2346
+
2347
+    return join('&nbsp;', $s);
2348 2348
 }
2349 2349
 
2350 2350
 /**
@@ -2359,15 +2359,15 @@  discard block
 block discarded – undo
2359 2359
  * @return string Liens trouvés
2360 2360
  **/
2361 2361
 function afficher_tags($tags, $rels = 'tag,directory') {
2362
-	$s = [];
2363
-	foreach (extraire_balises($tags, 'a') as $tag) {
2364
-		$rel = extraire_attribut($tag, 'rel');
2365
-		if (strstr(",$rels,", (string) ",$rel,")) {
2366
-			$s[] = $tag;
2367
-		}
2368
-	}
2362
+    $s = [];
2363
+    foreach (extraire_balises($tags, 'a') as $tag) {
2364
+        $rel = extraire_attribut($tag, 'rel');
2365
+        if (strstr(",$rels,", (string) ",$rel,")) {
2366
+            $s[] = $tag;
2367
+        }
2368
+    }
2369 2369
 
2370
-	return join(', ', $s);
2370
+    return join(', ', $s);
2371 2371
 }
2372 2372
 
2373 2373
 
@@ -2389,21 +2389,21 @@  discard block
 block discarded – undo
2389 2389
  * @return string Tag HTML `<a>` avec microformat.
2390 2390
  **/
2391 2391
 function enclosure2microformat($e) {
2392
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2393
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2394
-	}
2395
-	$type = extraire_attribut($e, 'type');
2396
-	if (!$length = extraire_attribut($e, 'length')) {
2397
-		# <media:content : longeur dans fileSize. On tente.
2398
-		$length = extraire_attribut($e, 'fileSize');
2399
-	}
2400
-	$fichier = basename($url);
2392
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2393
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2394
+    }
2395
+    $type = extraire_attribut($e, 'type');
2396
+    if (!$length = extraire_attribut($e, 'length')) {
2397
+        # <media:content : longeur dans fileSize. On tente.
2398
+        $length = extraire_attribut($e, 'fileSize');
2399
+    }
2400
+    $fichier = basename($url);
2401 2401
 
2402
-	return '<a rel="enclosure"'
2403
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2404
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2405
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2406
-	. '>' . $fichier . '</a>';
2402
+    return '<a rel="enclosure"'
2403
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2404
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2405
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2406
+    . '>' . $fichier . '</a>';
2407 2407
 }
2408 2408
 
2409 2409
 /**
@@ -2421,24 +2421,24 @@  discard block
 block discarded – undo
2421 2421
  * @return string Tags RSS `<enclosure>`.
2422 2422
  **/
2423 2423
 function microformat2enclosure($tags) {
2424
-	$enclosures = [];
2425
-	foreach (extraire_balises($tags, 'a') as $e) {
2426
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2427
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2428
-			$type = extraire_attribut($e, 'type');
2429
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2430
-				$length = intval(extraire_attribut($e, 'length'));
2431
-			} # vieux data
2432
-			$fichier = basename($url);
2433
-			$enclosures[] = '<enclosure'
2434
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2435
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2436
-				. ($length ? ' length="' . $length . '"' : '')
2437
-				. ' />';
2438
-		}
2439
-	}
2424
+    $enclosures = [];
2425
+    foreach (extraire_balises($tags, 'a') as $e) {
2426
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2427
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2428
+            $type = extraire_attribut($e, 'type');
2429
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2430
+                $length = intval(extraire_attribut($e, 'length'));
2431
+            } # vieux data
2432
+            $fichier = basename($url);
2433
+            $enclosures[] = '<enclosure'
2434
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2435
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2436
+                . ($length ? ' length="' . $length . '"' : '')
2437
+                . ' />';
2438
+        }
2439
+    }
2440 2440
 
2441
-	return join("\n", $enclosures);
2441
+    return join("\n", $enclosures);
2442 2442
 }
2443 2443
 
2444 2444
 
@@ -2454,16 +2454,16 @@  discard block
 block discarded – undo
2454 2454
  * @return string Tags RSS Atom `<dc:subject>`.
2455 2455
  **/
2456 2456
 function tags2dcsubject($tags) {
2457
-	$subjects = '';
2458
-	foreach (extraire_balises($tags, 'a') as $e) {
2459
-		if (extraire_attribut($e, 'rel') == 'tag') {
2460
-			$subjects .= '<dc:subject>'
2461
-				. texte_backend(textebrut($e))
2462
-				. '</dc:subject>' . "\n";
2463
-		}
2464
-	}
2457
+    $subjects = '';
2458
+    foreach (extraire_balises($tags, 'a') as $e) {
2459
+        if (extraire_attribut($e, 'rel') == 'tag') {
2460
+            $subjects .= '<dc:subject>'
2461
+                . texte_backend(textebrut($e))
2462
+                . '</dc:subject>' . "\n";
2463
+        }
2464
+    }
2465 2465
 
2466
-	return $subjects;
2466
+    return $subjects;
2467 2467
 }
2468 2468
 
2469 2469
 /**
@@ -2492,27 +2492,27 @@  discard block
 block discarded – undo
2492 2492
  *     - Tableau de résultats, si tableau en entrée.
2493 2493
  **/
2494 2494
 function extraire_balise($texte, $tag = 'a') {
2495
-	if (is_array($texte)) {
2496
-		array_walk(
2497
-			$texte,
2498
-			function (&$a, $key, $t) {
2499
-				$a = extraire_balise($a, $t);
2500
-			},
2501
-			$tag
2502
-		);
2503
-
2504
-		return $texte;
2505
-	}
2506
-
2507
-	if (
2508
-		preg_match(
2509
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2510
-			$texte,
2511
-			$regs
2512
-		)
2513
-	) {
2514
-		return $regs[0];
2515
-	}
2495
+    if (is_array($texte)) {
2496
+        array_walk(
2497
+            $texte,
2498
+            function (&$a, $key, $t) {
2499
+                $a = extraire_balise($a, $t);
2500
+            },
2501
+            $tag
2502
+        );
2503
+
2504
+        return $texte;
2505
+    }
2506
+
2507
+    if (
2508
+        preg_match(
2509
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2510
+            $texte,
2511
+            $regs
2512
+        )
2513
+    ) {
2514
+        return $regs[0];
2515
+    }
2516 2516
 }
2517 2517
 
2518 2518
 /**
@@ -2540,30 +2540,30 @@  discard block
 block discarded – undo
2540 2540
  *     - Tableau de résultats, si tableau en entrée.
2541 2541
  **/
2542 2542
 function extraire_balises($texte, $tag = 'a') {
2543
-	if (is_array($texte)) {
2544
-		array_walk(
2545
-			$texte,
2546
-			function (&$a, $key, $t) {
2547
-				$a = extraire_balises($a, $t);
2548
-			},
2549
-			$tag
2550
-		);
2551
-
2552
-		return $texte;
2553
-	}
2554
-
2555
-	if (
2556
-		preg_match_all(
2557
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2558
-			$texte,
2559
-			$regs,
2560
-			PREG_PATTERN_ORDER
2561
-		)
2562
-	) {
2563
-		return $regs[0];
2564
-	} else {
2565
-		return [];
2566
-	}
2543
+    if (is_array($texte)) {
2544
+        array_walk(
2545
+            $texte,
2546
+            function (&$a, $key, $t) {
2547
+                $a = extraire_balises($a, $t);
2548
+            },
2549
+            $tag
2550
+        );
2551
+
2552
+        return $texte;
2553
+    }
2554
+
2555
+    if (
2556
+        preg_match_all(
2557
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2558
+            $texte,
2559
+            $regs,
2560
+            PREG_PATTERN_ORDER
2561
+        )
2562
+    ) {
2563
+        return $regs[0];
2564
+    } else {
2565
+        return [];
2566
+    }
2567 2567
 }
2568 2568
 
2569 2569
 /**
@@ -2592,11 +2592,11 @@  discard block
 block discarded – undo
2592 2592
  *     - `$def` si on n'a pas transmis de tableau
2593 2593
  **/
2594 2594
 function in_any($val, $vals, $def = '') {
2595
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2596
-		$vals = $v;
2597
-	}
2595
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2596
+        $vals = $v;
2597
+    }
2598 2598
 
2599
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2599
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2600 2600
 }
2601 2601
 
2602 2602
 
@@ -2617,12 +2617,12 @@  discard block
 block discarded – undo
2617 2617
  *     Résultat du calcul
2618 2618
  **/
2619 2619
 function valeur_numerique($expr) {
2620
-	$a = 0;
2621
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2622
-		eval("\$a = $expr;");
2623
-	}
2620
+    $a = 0;
2621
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2622
+        eval("\$a = $expr;");
2623
+    }
2624 2624
 
2625
-	return intval($a);
2625
+    return intval($a);
2626 2626
 }
2627 2627
 
2628 2628
 /**
@@ -2641,7 +2641,7 @@  discard block
 block discarded – undo
2641 2641
  *      Retourne `$a*$b/$c`
2642 2642
  **/
2643 2643
 function regledetrois($a, $b, $c) {
2644
-	return round($a * $b / $c);
2644
+    return round($a * $b / $c);
2645 2645
 }
2646 2646
 
2647 2647
 
@@ -2664,79 +2664,79 @@  discard block
 block discarded – undo
2664 2664
  * @return string Suite de champs input hidden
2665 2665
  **/
2666 2666
 function form_hidden(?string $action = ''): string {
2667
-	$action ??= '';
2668
-
2669
-	$contexte = [];
2670
-	include_spip('inc/urls');
2671
-	if (
2672
-		$p = urls_decoder_url($action, '')
2673
-		and reset($p)
2674
-	) {
2675
-		$fond = array_shift($p);
2676
-		if ($fond != '404') {
2677
-			$contexte = array_shift($p);
2678
-			$contexte['page'] = $fond;
2679
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2680
-		}
2681
-	}
2682
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2683
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2684
-		unset($contexte['type']);
2685
-	}
2686
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2687
-		unset($contexte['type-page']);
2688
-	}
2689
-
2690
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2691
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2692
-	$values = [];
2693
-
2694
-	// d'abord avec celles de l'url
2695
-	if (false !== ($p = strpos($action, '?'))) {
2696
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2697
-			$c = explode('=', $c, 2);
2698
-			$var = array_shift($c);
2699
-			$val = array_shift($c) ?? '';
2700
-			if ($var) {
2701
-				$val = rawurldecode($val);
2702
-				$var = rawurldecode($var); // decoder les [] eventuels
2703
-				if (preg_match(',\[\]$,S', $var)) {
2704
-					$values[] = [$var, $val];
2705
-				} else {
2706
-					if (!isset($values[$var])) {
2707
-						$values[$var] = [$var, $val];
2708
-					}
2709
-				}
2710
-			}
2711
-		}
2712
-	}
2713
-
2714
-	// ensuite avec celles du contexte, sans doublonner !
2715
-	foreach ($contexte as $var => $val) {
2716
-		if (preg_match(',\[\]$,S', $var)) {
2717
-			$values[] = [$var, $val];
2718
-		} else {
2719
-			if (!isset($values[$var])) {
2720
-				$values[$var] = [$var, $val];
2721
-			}
2722
-		}
2723
-	}
2724
-
2725
-	// puis on rassemble le tout
2726
-	$hidden = [];
2727
-	foreach ($values as $value) {
2728
-		[$var, $val] = $value;
2729
-		$hidden[] = '<input name="'
2730
-			. entites_html($var)
2731
-			. '"'
2732
-			. (is_null($val)
2733
-				? ''
2734
-				: ' value="' . entites_html($val) . '"'
2735
-			)
2736
-			. ' type="hidden"' . "\n/>";
2737
-	}
2738
-
2739
-	return join('', $hidden);
2667
+    $action ??= '';
2668
+
2669
+    $contexte = [];
2670
+    include_spip('inc/urls');
2671
+    if (
2672
+        $p = urls_decoder_url($action, '')
2673
+        and reset($p)
2674
+    ) {
2675
+        $fond = array_shift($p);
2676
+        if ($fond != '404') {
2677
+            $contexte = array_shift($p);
2678
+            $contexte['page'] = $fond;
2679
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2680
+        }
2681
+    }
2682
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2683
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2684
+        unset($contexte['type']);
2685
+    }
2686
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2687
+        unset($contexte['type-page']);
2688
+    }
2689
+
2690
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2691
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2692
+    $values = [];
2693
+
2694
+    // d'abord avec celles de l'url
2695
+    if (false !== ($p = strpos($action, '?'))) {
2696
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2697
+            $c = explode('=', $c, 2);
2698
+            $var = array_shift($c);
2699
+            $val = array_shift($c) ?? '';
2700
+            if ($var) {
2701
+                $val = rawurldecode($val);
2702
+                $var = rawurldecode($var); // decoder les [] eventuels
2703
+                if (preg_match(',\[\]$,S', $var)) {
2704
+                    $values[] = [$var, $val];
2705
+                } else {
2706
+                    if (!isset($values[$var])) {
2707
+                        $values[$var] = [$var, $val];
2708
+                    }
2709
+                }
2710
+            }
2711
+        }
2712
+    }
2713
+
2714
+    // ensuite avec celles du contexte, sans doublonner !
2715
+    foreach ($contexte as $var => $val) {
2716
+        if (preg_match(',\[\]$,S', $var)) {
2717
+            $values[] = [$var, $val];
2718
+        } else {
2719
+            if (!isset($values[$var])) {
2720
+                $values[$var] = [$var, $val];
2721
+            }
2722
+        }
2723
+    }
2724
+
2725
+    // puis on rassemble le tout
2726
+    $hidden = [];
2727
+    foreach ($values as $value) {
2728
+        [$var, $val] = $value;
2729
+        $hidden[] = '<input name="'
2730
+            . entites_html($var)
2731
+            . '"'
2732
+            . (is_null($val)
2733
+                ? ''
2734
+                : ' value="' . entites_html($val) . '"'
2735
+            )
2736
+            . ' type="hidden"' . "\n/>";
2737
+    }
2738
+
2739
+    return join('', $hidden);
2740 2740
 }
2741 2741
 
2742 2742
 
@@ -2758,7 +2758,7 @@  discard block
 block discarded – undo
2758 2758
  *    - la première valeur du tableau sinon.
2759 2759
  **/
2760 2760
 function filtre_reset($array) {
2761
-	return !is_array($array) ? null : reset($array);
2761
+    return !is_array($array) ? null : reset($array);
2762 2762
 }
2763 2763
 
2764 2764
 /**
@@ -2779,7 +2779,7 @@  discard block
 block discarded – undo
2779 2779
  *    - la dernière valeur du tableau sinon.
2780 2780
  **/
2781 2781
 function filtre_end($array) {
2782
-	return !is_array($array) ? null : end($array);
2782
+    return !is_array($array) ? null : end($array);
2783 2783
 }
2784 2784
 
2785 2785
 /**
@@ -2799,11 +2799,11 @@  discard block
 block discarded – undo
2799 2799
  *
2800 2800
  **/
2801 2801
 function filtre_push($array, $val) {
2802
-	if (!is_array($array) or !array_push($array, $val)) {
2803
-		return '';
2804
-	}
2802
+    if (!is_array($array) or !array_push($array, $val)) {
2803
+        return '';
2804
+    }
2805 2805
 
2806
-	return $array;
2806
+    return $array;
2807 2807
 }
2808 2808
 
2809 2809
 /**
@@ -2822,7 +2822,7 @@  discard block
 block discarded – undo
2822 2822
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2823 2823
  **/
2824 2824
 function filtre_find($array, $val) {
2825
-	return (is_array($array) and in_array($val, $array));
2825
+    return (is_array($array) and in_array($val, $array));
2826 2826
 }
2827 2827
 
2828 2828
 
@@ -2839,13 +2839,13 @@  discard block
 block discarded – undo
2839 2839
  *     Contenu avec urls en absolus
2840 2840
  **/
2841 2841
 function urls_absolues_css($contenu, $source) {
2842
-	$path = suivre_lien(url_absolue($source), './');
2842
+    $path = suivre_lien(url_absolue($source), './');
2843 2843
 
2844
-	return preg_replace_callback(
2845
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2846
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2847
-		$contenu
2848
-	);
2844
+    return preg_replace_callback(
2845
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2846
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2847
+        $contenu
2848
+    );
2849 2849
 }
2850 2850
 
2851 2851
 
@@ -2874,119 +2874,119 @@  discard block
 block discarded – undo
2874 2874
  *     Chemin du fichier CSS inversé
2875 2875
  **/
2876 2876
 function direction_css($css, $voulue = '') {
2877
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2878
-		return $css;
2879
-	}
2880
-	include_spip('inc/lang');
2881
-	// si on a precise le sens voulu en argument, le prendre en compte
2882
-	if ($voulue = strtolower($voulue)) {
2883
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2884
-			$voulue = lang_dir($voulue);
2885
-		}
2886
-	} else {
2887
-		$voulue = lang_dir();
2888
-	}
2889
-
2890
-	$r = count($r) > 1;
2891
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2892
-	$dir = $r ? 'rtl' : 'ltr';
2893
-	$ndir = $r ? 'ltr' : 'rtl';
2894
-
2895
-	if ($voulue == $dir) {
2896
-		return $css;
2897
-	}
2898
-
2899
-	if (
2900
-		// url absolue
2901
-		preg_match(',^https?:,i', $css)
2902
-		// ou qui contient un ?
2903
-		or (($p = strpos($css, '?')) !== false)
2904
-	) {
2905
-		$distant = true;
2906
-		$cssf = parse_url($css);
2907
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2908
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2909
-	} else {
2910
-		$distant = false;
2911
-		$cssf = $css;
2912
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2913
-		//propose (rien a faire dans ce cas)
2914
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2915
-		if (@file_exists($f)) {
2916
-			return $f;
2917
-		}
2918
-	}
2919
-
2920
-	// 2.
2921
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2922
-	$f = $dir_var
2923
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2924
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2925
-
2926
-	// la css peut etre distante (url absolue !)
2927
-	if ($distant) {
2928
-		include_spip('inc/distant');
2929
-		$res = recuperer_url($css);
2930
-		if (!$res or !$contenu = $res['page']) {
2931
-			return $css;
2932
-		}
2933
-	} else {
2934
-		if (
2935
-			(@filemtime($f) > @filemtime($css))
2936
-			and (_VAR_MODE != 'recalcul')
2937
-		) {
2938
-			return $f;
2939
-		}
2940
-		if (!lire_fichier($css, $contenu)) {
2941
-			return $css;
2942
-		}
2943
-	}
2944
-
2945
-
2946
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2947
-	include_spip('lib/csstidy/class.csstidy');
2948
-	$parser = new csstidy();
2949
-	$parser->set_cfg('optimise_shorthands', 0);
2950
-	$parser->set_cfg('reverse_left_and_right', true);
2951
-	$parser->parse($contenu);
2952
-
2953
-	$contenu = $parser->print->plain();
2954
-
2955
-
2956
-	// reperer les @import auxquels il faut propager le direction_css
2957
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2958
-	$src = [];
2959
-	$src_direction_css = [];
2960
-	$src_faux_abs = [];
2961
-	$d = dirname($css);
2962
-	foreach ($regs[1] as $k => $import_css) {
2963
-		$css_direction = direction_css("$d/$import_css", $voulue);
2964
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2965
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2966
-			$css_direction = substr($css_direction, strlen($d) + 1);
2967
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2968
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2969
-			$css_direction = substr($css_direction, strlen($dir_var));
2970
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2971
-			$css_direction = '/@@@@@@/' . $css_direction;
2972
-		}
2973
-		$src[] = $regs[0][$k];
2974
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2975
-	}
2976
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2977
-
2978
-	$contenu = urls_absolues_css($contenu, $css);
2979
-
2980
-	// virer les fausses url absolues que l'on a mis dans les import
2981
-	if (count($src_faux_abs)) {
2982
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2983
-	}
2984
-
2985
-	if (!ecrire_fichier($f, $contenu)) {
2986
-		return $css;
2987
-	}
2988
-
2989
-	return $f;
2877
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2878
+        return $css;
2879
+    }
2880
+    include_spip('inc/lang');
2881
+    // si on a precise le sens voulu en argument, le prendre en compte
2882
+    if ($voulue = strtolower($voulue)) {
2883
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2884
+            $voulue = lang_dir($voulue);
2885
+        }
2886
+    } else {
2887
+        $voulue = lang_dir();
2888
+    }
2889
+
2890
+    $r = count($r) > 1;
2891
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2892
+    $dir = $r ? 'rtl' : 'ltr';
2893
+    $ndir = $r ? 'ltr' : 'rtl';
2894
+
2895
+    if ($voulue == $dir) {
2896
+        return $css;
2897
+    }
2898
+
2899
+    if (
2900
+        // url absolue
2901
+        preg_match(',^https?:,i', $css)
2902
+        // ou qui contient un ?
2903
+        or (($p = strpos($css, '?')) !== false)
2904
+    ) {
2905
+        $distant = true;
2906
+        $cssf = parse_url($css);
2907
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2908
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2909
+    } else {
2910
+        $distant = false;
2911
+        $cssf = $css;
2912
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2913
+        //propose (rien a faire dans ce cas)
2914
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2915
+        if (@file_exists($f)) {
2916
+            return $f;
2917
+        }
2918
+    }
2919
+
2920
+    // 2.
2921
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2922
+    $f = $dir_var
2923
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2924
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2925
+
2926
+    // la css peut etre distante (url absolue !)
2927
+    if ($distant) {
2928
+        include_spip('inc/distant');
2929
+        $res = recuperer_url($css);
2930
+        if (!$res or !$contenu = $res['page']) {
2931
+            return $css;
2932
+        }
2933
+    } else {
2934
+        if (
2935
+            (@filemtime($f) > @filemtime($css))
2936
+            and (_VAR_MODE != 'recalcul')
2937
+        ) {
2938
+            return $f;
2939
+        }
2940
+        if (!lire_fichier($css, $contenu)) {
2941
+            return $css;
2942
+        }
2943
+    }
2944
+
2945
+
2946
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2947
+    include_spip('lib/csstidy/class.csstidy');
2948
+    $parser = new csstidy();
2949
+    $parser->set_cfg('optimise_shorthands', 0);
2950
+    $parser->set_cfg('reverse_left_and_right', true);
2951
+    $parser->parse($contenu);
2952
+
2953
+    $contenu = $parser->print->plain();
2954
+
2955
+
2956
+    // reperer les @import auxquels il faut propager le direction_css
2957
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2958
+    $src = [];
2959
+    $src_direction_css = [];
2960
+    $src_faux_abs = [];
2961
+    $d = dirname($css);
2962
+    foreach ($regs[1] as $k => $import_css) {
2963
+        $css_direction = direction_css("$d/$import_css", $voulue);
2964
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2965
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2966
+            $css_direction = substr($css_direction, strlen($d) + 1);
2967
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2968
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2969
+            $css_direction = substr($css_direction, strlen($dir_var));
2970
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2971
+            $css_direction = '/@@@@@@/' . $css_direction;
2972
+        }
2973
+        $src[] = $regs[0][$k];
2974
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2975
+    }
2976
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2977
+
2978
+    $contenu = urls_absolues_css($contenu, $css);
2979
+
2980
+    // virer les fausses url absolues que l'on a mis dans les import
2981
+    if (count($src_faux_abs)) {
2982
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2983
+    }
2984
+
2985
+    if (!ecrire_fichier($f, $contenu)) {
2986
+        return $css;
2987
+    }
2988
+
2989
+    return $f;
2990 2990
 }
2991 2991
 
2992 2992
 
@@ -3009,46 +3009,46 @@  discard block
 block discarded – undo
3009 3009
  *     - Chemin ou URL du fichier CSS source sinon.
3010 3010
  **/
3011 3011
 function url_absolue_css($css) {
3012
-	if (!preg_match(',\.css$,i', $css, $r)) {
3013
-		return $css;
3014
-	}
3012
+    if (!preg_match(',\.css$,i', $css, $r)) {
3013
+        return $css;
3014
+    }
3015 3015
 
3016
-	$url_absolue_css = url_absolue($css);
3016
+    $url_absolue_css = url_absolue($css);
3017 3017
 
3018
-	$f = basename($css, '.css');
3019
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3020
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3021
-		. '.css';
3018
+    $f = basename($css, '.css');
3019
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3020
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3021
+        . '.css';
3022 3022
 
3023
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3024
-		return $f;
3025
-	}
3023
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3024
+        return $f;
3025
+    }
3026 3026
 
3027
-	if ($url_absolue_css == $css) {
3028
-		if (
3029
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3030
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3031
-		) {
3032
-			include_spip('inc/distant');
3033
-			$contenu = recuperer_url($css);
3034
-			$contenu = $contenu['page'] ?? '';
3035
-			if (!$contenu) {
3036
-				return $css;
3037
-			}
3038
-		}
3039
-	} elseif (!lire_fichier($css, $contenu)) {
3040
-		return $css;
3041
-	}
3027
+    if ($url_absolue_css == $css) {
3028
+        if (
3029
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3030
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3031
+        ) {
3032
+            include_spip('inc/distant');
3033
+            $contenu = recuperer_url($css);
3034
+            $contenu = $contenu['page'] ?? '';
3035
+            if (!$contenu) {
3036
+                return $css;
3037
+            }
3038
+        }
3039
+    } elseif (!lire_fichier($css, $contenu)) {
3040
+        return $css;
3041
+    }
3042 3042
 
3043
-	// passer les url relatives a la css d'origine en url absolues
3044
-	$contenu = urls_absolues_css($contenu, $css);
3043
+    // passer les url relatives a la css d'origine en url absolues
3044
+    $contenu = urls_absolues_css($contenu, $css);
3045 3045
 
3046
-	// ecrire la css
3047
-	if (!ecrire_fichier($f, $contenu)) {
3048
-		return $css;
3049
-	}
3046
+    // ecrire la css
3047
+    if (!ecrire_fichier($f, $contenu)) {
3048
+        return $css;
3049
+    }
3050 3050
 
3051
-	return $f;
3051
+    return $f;
3052 3052
 }
3053 3053
 
3054 3054
 
@@ -3082,24 +3082,24 @@  discard block
 block discarded – undo
3082 3082
  *     Valeur trouvée ou valeur par défaut.
3083 3083
  **/
3084 3084
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3085
-	foreach (explode('/', $cle) as $k) {
3086
-		$table = (is_string($table) ? @unserialize($table) : $table);
3085
+    foreach (explode('/', $cle) as $k) {
3086
+        $table = (is_string($table) ? @unserialize($table) : $table);
3087 3087
 
3088
-		if (is_object($table)) {
3089
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3090
-		} elseif (is_array($table)) {
3091
-			if ($conserver_null) {
3092
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3093
-			} else {
3094
-				$table = ($table[$k] ?? $defaut);
3095
-			}
3096
-		} else {
3097
-			$table = $defaut;
3098
-			break;
3099
-		}
3100
-	}
3088
+        if (is_object($table)) {
3089
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3090
+        } elseif (is_array($table)) {
3091
+            if ($conserver_null) {
3092
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3093
+            } else {
3094
+                $table = ($table[$k] ?? $defaut);
3095
+            }
3096
+        } else {
3097
+            $table = $defaut;
3098
+            break;
3099
+        }
3100
+    }
3101 3101
 
3102
-	return $table;
3102
+    return $table;
3103 3103
 }
3104 3104
 
3105 3105
 /**
@@ -3132,22 +3132,22 @@  discard block
 block discarded – undo
3132 3132
  *     - string : expression trouvée.
3133 3133
  **/
3134 3134
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3135
-	if (intval($modif) and $capte == 0) {
3136
-		$capte = $modif;
3137
-		$modif = 'UuimsS';
3138
-	}
3139
-	$expression = str_replace('\/', '/', $expression);
3140
-	$expression = str_replace('/', '\/', $expression);
3135
+    if (intval($modif) and $capte == 0) {
3136
+        $capte = $modif;
3137
+        $modif = 'UuimsS';
3138
+    }
3139
+    $expression = str_replace('\/', '/', $expression);
3140
+    $expression = str_replace('/', '\/', $expression);
3141 3141
 
3142
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3143
-		if (isset($r[$capte])) {
3144
-			return $r[$capte];
3145
-		} else {
3146
-			return true;
3147
-		}
3148
-	}
3142
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3143
+        if (isset($r[$capte])) {
3144
+            return $r[$capte];
3145
+        } else {
3146
+            return true;
3147
+        }
3148
+    }
3149 3149
 
3150
-	return false;
3150
+    return false;
3151 3151
 }
3152 3152
 
3153 3153
 
@@ -3174,10 +3174,10 @@  discard block
 block discarded – undo
3174 3174
  *     texte
3175 3175
  **/
3176 3176
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3177
-	$expression = str_replace('\/', '/', $expression);
3178
-	$expression = str_replace('/', '\/', $expression);
3177
+    $expression = str_replace('\/', '/', $expression);
3178
+    $expression = str_replace('/', '\/', $expression);
3179 3179
 
3180
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3180
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3181 3181
 }
3182 3182
 
3183 3183
 
@@ -3195,25 +3195,25 @@  discard block
 block discarded – undo
3195 3195
  **/
3196 3196
 function traiter_doublons_documents(&$doublons, $letexte) {
3197 3197
 
3198
-	// Verifier dans le texte & les notes (pas beau, helas)
3199
-	$t = $letexte . $GLOBALS['les_notes'];
3198
+    // Verifier dans le texte & les notes (pas beau, helas)
3199
+    $t = $letexte . $GLOBALS['les_notes'];
3200 3200
 
3201
-	if (
3202
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3203
-		and preg_match_all(
3204
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3205
-			$t,
3206
-			$matches,
3207
-			PREG_PATTERN_ORDER
3208
-		)
3209
-	) {
3210
-		if (!isset($doublons['documents'])) {
3211
-			$doublons['documents'] = '';
3212
-		}
3213
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3214
-	}
3201
+    if (
3202
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3203
+        and preg_match_all(
3204
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3205
+            $t,
3206
+            $matches,
3207
+            PREG_PATTERN_ORDER
3208
+        )
3209
+    ) {
3210
+        if (!isset($doublons['documents'])) {
3211
+            $doublons['documents'] = '';
3212
+        }
3213
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3214
+    }
3215 3215
 
3216
-	return $letexte;
3216
+    return $letexte;
3217 3217
 }
3218 3218
 
3219 3219
 /**
@@ -3227,7 +3227,7 @@  discard block
 block discarded – undo
3227 3227
  * @return string Chaîne vide
3228 3228
  **/
3229 3229
 function vide($texte) {
3230
-	return '';
3230
+    return '';
3231 3231
 }
3232 3232
 
3233 3233
 //
@@ -3256,23 +3256,23 @@  discard block
 block discarded – undo
3256 3256
  *      Code HTML résultant
3257 3257
  **/
3258 3258
 function env_to_params($env, $ignore_params = []) {
3259
-	$ignore_params = array_merge(
3260
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3261
-		$ignore_params
3262
-	);
3263
-	if (!is_array($env)) {
3264
-		$env = unserialize($env);
3265
-	}
3266
-	$texte = '';
3267
-	if ($env) {
3268
-		foreach ($env as $i => $j) {
3269
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3270
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3271
-			}
3272
-		}
3273
-	}
3274
-
3275
-	return $texte;
3259
+    $ignore_params = array_merge(
3260
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3261
+        $ignore_params
3262
+    );
3263
+    if (!is_array($env)) {
3264
+        $env = unserialize($env);
3265
+    }
3266
+    $texte = '';
3267
+    if ($env) {
3268
+        foreach ($env as $i => $j) {
3269
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3270
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3271
+            }
3272
+        }
3273
+    }
3274
+
3275
+    return $texte;
3276 3276
 }
3277 3277
 
3278 3278
 /**
@@ -3295,23 +3295,23 @@  discard block
 block discarded – undo
3295 3295
  *      Code HTML résultant
3296 3296
  **/
3297 3297
 function env_to_attributs($env, $ignore_params = []) {
3298
-	$ignore_params = array_merge(
3299
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3300
-		$ignore_params
3301
-	);
3302
-	if (!is_array($env)) {
3303
-		$env = unserialize($env);
3304
-	}
3305
-	$texte = '';
3306
-	if ($env) {
3307
-		foreach ($env as $i => $j) {
3308
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3309
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3310
-			}
3311
-		}
3312
-	}
3298
+    $ignore_params = array_merge(
3299
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3300
+        $ignore_params
3301
+    );
3302
+    if (!is_array($env)) {
3303
+        $env = unserialize($env);
3304
+    }
3305
+    $texte = '';
3306
+    if ($env) {
3307
+        foreach ($env as $i => $j) {
3308
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3309
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3310
+            }
3311
+        }
3312
+    }
3313 3313
 
3314
-	return $texte;
3314
+    return $texte;
3315 3315
 }
3316 3316
 
3317 3317
 
@@ -3329,7 +3329,7 @@  discard block
 block discarded – undo
3329 3329
  * @return string Chaînes concaténés
3330 3330
  **/
3331 3331
 function concat(...$args): string {
3332
-	return join('', $args);
3332
+    return join('', $args);
3333 3333
 }
3334 3334
 
3335 3335
 
@@ -3349,23 +3349,23 @@  discard block
 block discarded – undo
3349 3349
  *     Contenu du ou des fichiers, concaténé
3350 3350
  **/
3351 3351
 function charge_scripts($files, $script = true) {
3352
-	$flux = '';
3353
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3354
-		if (!is_string($file)) {
3355
-			continue;
3356
-		}
3357
-		if ($script) {
3358
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3359
-		}
3360
-		if ($file) {
3361
-			$path = find_in_path($file);
3362
-			if ($path) {
3363
-				$flux .= spip_file_get_contents($path);
3364
-			}
3365
-		}
3366
-	}
3367
-
3368
-	return $flux;
3352
+    $flux = '';
3353
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3354
+        if (!is_string($file)) {
3355
+            continue;
3356
+        }
3357
+        if ($script) {
3358
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3359
+        }
3360
+        if ($file) {
3361
+            $path = find_in_path($file);
3362
+            if ($path) {
3363
+                $flux .= spip_file_get_contents($path);
3364
+            }
3365
+        }
3366
+    }
3367
+
3368
+    return $flux;
3369 3369
 }
3370 3370
 
3371 3371
 /**
@@ -3376,22 +3376,22 @@  discard block
 block discarded – undo
3376 3376
  * @return string
3377 3377
  */
3378 3378
 function http_img_variante_svg_si_possible($img_file) {
3379
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3380
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3381
-	if (
3382
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3383
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3384
-		and file_exists($variante_svg_generique)
3385
-	) {
3386
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3387
-			$img_file = $variante_svg_size;
3388
-		}
3389
-		else {
3390
-			$img_file = $variante_svg_generique;
3391
-		}
3392
-	}
3379
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3380
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3381
+    if (
3382
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3383
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3384
+        and file_exists($variante_svg_generique)
3385
+    ) {
3386
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3387
+            $img_file = $variante_svg_size;
3388
+        }
3389
+        else {
3390
+            $img_file = $variante_svg_generique;
3391
+        }
3392
+    }
3393 3393
 
3394
-	return $img_file;
3394
+    return $img_file;
3395 3395
 }
3396 3396
 
3397 3397
 /**
@@ -3412,54 +3412,54 @@  discard block
 block discarded – undo
3412 3412
  */
3413 3413
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3414 3414
 
3415
-	$img_file = $img;
3416
-	if ($p = strpos($img_file, '?')) {
3417
-		$img_file = substr($img_file, 0, $p);
3418
-	}
3419
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3420
-		$img_file = chemin_image($img);
3421
-	}
3422
-	else {
3423
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3424
-			$img_file = http_img_variante_svg_si_possible($img_file);
3425
-		}
3426
-	}
3427
-	if (stripos($atts, 'width') === false) {
3428
-		// utiliser directement l'info de taille presente dans le nom
3429
-		if (
3430
-			(!isset($options['utiliser_suffixe_size'])
3431
-				or $options['utiliser_suffixe_size'] == true
3432
-				or str_contains($img_file, '-xx.svg'))
3433
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3434
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3435
-		) {
3436
-			$largeur = $hauteur = intval($regs[1]);
3437
-		} else {
3438
-			$taille = taille_image($img_file);
3439
-			[$hauteur, $largeur] = $taille;
3440
-			if (!$hauteur or !$largeur) {
3441
-				return '';
3442
-			}
3443
-		}
3444
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3445
-	}
3446
-
3447
-	if (file_exists($img_file)) {
3448
-		$img_file = timestamp($img_file);
3449
-	}
3450
-	if ($alt === false) {
3451
-		$alt = '';
3452
-	}
3453
-	elseif ($alt or $alt === '') {
3454
-		$alt = " alt='" . attribut_html($alt) . "'";
3455
-	}
3456
-	else {
3457
-		$alt = " alt='" . attribut_html($title) . "'";
3458
-	}
3459
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3460
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3461
-	. ' ' . ltrim($atts)
3462
-	. ' />';
3415
+    $img_file = $img;
3416
+    if ($p = strpos($img_file, '?')) {
3417
+        $img_file = substr($img_file, 0, $p);
3418
+    }
3419
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3420
+        $img_file = chemin_image($img);
3421
+    }
3422
+    else {
3423
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3424
+            $img_file = http_img_variante_svg_si_possible($img_file);
3425
+        }
3426
+    }
3427
+    if (stripos($atts, 'width') === false) {
3428
+        // utiliser directement l'info de taille presente dans le nom
3429
+        if (
3430
+            (!isset($options['utiliser_suffixe_size'])
3431
+                or $options['utiliser_suffixe_size'] == true
3432
+                or str_contains($img_file, '-xx.svg'))
3433
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3434
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3435
+        ) {
3436
+            $largeur = $hauteur = intval($regs[1]);
3437
+        } else {
3438
+            $taille = taille_image($img_file);
3439
+            [$hauteur, $largeur] = $taille;
3440
+            if (!$hauteur or !$largeur) {
3441
+                return '';
3442
+            }
3443
+        }
3444
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3445
+    }
3446
+
3447
+    if (file_exists($img_file)) {
3448
+        $img_file = timestamp($img_file);
3449
+    }
3450
+    if ($alt === false) {
3451
+        $alt = '';
3452
+    }
3453
+    elseif ($alt or $alt === '') {
3454
+        $alt = " alt='" . attribut_html($alt) . "'";
3455
+    }
3456
+    else {
3457
+        $alt = " alt='" . attribut_html($title) . "'";
3458
+    }
3459
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3460
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3461
+    . ' ' . ltrim($atts)
3462
+    . ' />';
3463 3463
 }
3464 3464
 
3465 3465
 /**
@@ -3471,70 +3471,70 @@  discard block
 block discarded – undo
3471 3471
  * @return string
3472 3472
  */
3473 3473
 function http_style_background($img, $att = '', $size = null) {
3474
-	if ($size and is_numeric($size)) {
3475
-		$size = trim($size) . 'px';
3476
-	}
3477
-	return " style='background" .
3478
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3479
-		. ($size ? "background-size:{$size};" : '')
3480
-		. "'";
3474
+    if ($size and is_numeric($size)) {
3475
+        $size = trim($size) . 'px';
3476
+    }
3477
+    return " style='background" .
3478
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3479
+        . ($size ? "background-size:{$size};" : '')
3480
+        . "'";
3481 3481
 }
3482 3482
 
3483 3483
 
3484 3484
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3485
-	$args = [$alt_or_size, $class_or_size, $size];
3486
-	while (is_null(end($args)) and count($args)) {
3487
-		array_pop($args);
3488
-	}
3489
-	if (!count($args)) {
3490
-		return [null, null, null];
3491
-	}
3492
-	if (count($args) < 3) {
3493
-		$maybe_size = array_pop($args);
3494
-		// @2x
3495
-		// @1.5x
3496
-		// 512
3497
-		// 512x*
3498
-		// 512x300
3499
-		if (
3500
-			!strlen($maybe_size)
3501
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3502
-		) {
3503
-			$args[] = $maybe_size;
3504
-			$maybe_size = null;
3505
-		}
3506
-		while (count($args) < 2) {
3507
-			$args[] = null; // default alt or class
3508
-		}
3509
-		$args[] = $maybe_size;
3510
-	}
3511
-	return $args;
3485
+    $args = [$alt_or_size, $class_or_size, $size];
3486
+    while (is_null(end($args)) and count($args)) {
3487
+        array_pop($args);
3488
+    }
3489
+    if (!count($args)) {
3490
+        return [null, null, null];
3491
+    }
3492
+    if (count($args) < 3) {
3493
+        $maybe_size = array_pop($args);
3494
+        // @2x
3495
+        // @1.5x
3496
+        // 512
3497
+        // 512x*
3498
+        // 512x300
3499
+        if (
3500
+            !strlen($maybe_size)
3501
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3502
+        ) {
3503
+            $args[] = $maybe_size;
3504
+            $maybe_size = null;
3505
+        }
3506
+        while (count($args) < 2) {
3507
+            $args[] = null; // default alt or class
3508
+        }
3509
+        $args[] = $maybe_size;
3510
+    }
3511
+    return $args;
3512 3512
 }
3513 3513
 
3514 3514
 function helper_filtre_balise_img_svg_size($img, $size) {
3515
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3516
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3517
-		$coef = floatval(substr($size, 1, -1));
3518
-		[$h, $w] = taille_image($img);
3519
-		$height = intval(round($h / $coef));
3520
-		$width = intval(round($w / $coef));
3521
-	}
3522
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3523
-	else {
3524
-		$size = explode('x', $size, 2);
3525
-		$size = array_map('trim', $size);
3526
-		$height = $width = intval(array_shift($size));
3527
-
3528
-		if (count($size) and reset($size)) {
3529
-			$height = array_shift($size);
3530
-			if ($height === '*') {
3531
-				[$h, $w] = taille_image($img);
3532
-				$height = intval(round($h * $width / $w));
3533
-			}
3534
-		}
3535
-	}
3536
-
3537
-	return [$width, $height];
3515
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3516
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3517
+        $coef = floatval(substr($size, 1, -1));
3518
+        [$h, $w] = taille_image($img);
3519
+        $height = intval(round($h / $coef));
3520
+        $width = intval(round($w / $coef));
3521
+    }
3522
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3523
+    else {
3524
+        $size = explode('x', $size, 2);
3525
+        $size = array_map('trim', $size);
3526
+        $height = $width = intval(array_shift($size));
3527
+
3528
+        if (count($size) and reset($size)) {
3529
+            $height = array_shift($size);
3530
+            if ($height === '*') {
3531
+                [$h, $w] = taille_image($img);
3532
+                $height = intval(round($h * $width / $w));
3533
+            }
3534
+        }
3535
+    }
3536
+
3537
+    return [$width, $height];
3538 3538
 }
3539 3539
 
3540 3540
 /**
@@ -3570,43 +3570,43 @@  discard block
 block discarded – undo
3570 3570
  */
3571 3571
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3572 3572
 
3573
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3574
-
3575
-	$img = trim((string) $img);
3576
-	if (strpos($img, '<img') === 0) {
3577
-		if (!is_null($alt)) {
3578
-			$img = inserer_attribut($img, 'alt', $alt);
3579
-		}
3580
-		if (!is_null($class)) {
3581
-			if (strlen($class)) {
3582
-				$img = inserer_attribut($img, 'class', $class);
3583
-			}
3584
-			else {
3585
-				$img = vider_attribut($img, 'class');
3586
-			}
3587
-		}
3588
-	}
3589
-	else {
3590
-		$img = http_img_pack(
3591
-			$img,
3592
-			$alt,
3593
-			$class ? " class='" . attribut_html($class) . "'" : '',
3594
-			'',
3595
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3596
-		);
3597
-		if (is_null($alt)) {
3598
-			$img = vider_attribut($img, 'alt');
3599
-		}
3600
-	}
3601
-
3602
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3603
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3604
-
3605
-		$img = inserer_attribut($img, 'width', $width);
3606
-		$img = inserer_attribut($img, 'height', $height);
3607
-	}
3608
-
3609
-	return $img;
3573
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3574
+
3575
+    $img = trim((string) $img);
3576
+    if (strpos($img, '<img') === 0) {
3577
+        if (!is_null($alt)) {
3578
+            $img = inserer_attribut($img, 'alt', $alt);
3579
+        }
3580
+        if (!is_null($class)) {
3581
+            if (strlen($class)) {
3582
+                $img = inserer_attribut($img, 'class', $class);
3583
+            }
3584
+            else {
3585
+                $img = vider_attribut($img, 'class');
3586
+            }
3587
+        }
3588
+    }
3589
+    else {
3590
+        $img = http_img_pack(
3591
+            $img,
3592
+            $alt,
3593
+            $class ? " class='" . attribut_html($class) . "'" : '',
3594
+            '',
3595
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3596
+        );
3597
+        if (is_null($alt)) {
3598
+            $img = vider_attribut($img, 'alt');
3599
+        }
3600
+    }
3601
+
3602
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3603
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3604
+
3605
+        $img = inserer_attribut($img, 'width', $width);
3606
+        $img = inserer_attribut($img, 'height', $height);
3607
+    }
3608
+
3609
+    return $img;
3610 3610
 }
3611 3611
 
3612 3612
 
@@ -3640,80 +3640,80 @@  discard block
 block discarded – undo
3640 3640
  */
3641 3641
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3642 3642
 
3643
-	$svg = null;
3644
-	$img = trim($img);
3645
-	$img_file = $img;
3646
-	if (strpos($img, '<svg') === false) {
3647
-		if ($p = strpos($img_file, '?')) {
3648
-			$img_file = substr($img_file, 0, $p);
3649
-		}
3650
-
3651
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3652
-		// la copie locale a toutes les chances d'etre la ou de resservir
3653
-		if (tester_url_absolue($img_file)) {
3654
-			include_spip('inc/distant');
3655
-			$fichier = copie_locale($img_file);
3656
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3657
-		}
3658
-
3659
-		if (
3660
-			!$img_file
3661
-			or !file_exists($img_file)
3662
-			or !$svg = file_get_contents($img_file)
3663
-		) {
3664
-			return '';
3665
-		}
3666
-	}
3667
-
3668
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3669
-		return '';
3670
-	}
3671
-
3672
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3673
-
3674
-	$balise_svg = $match[0];
3675
-	$balise_svg_source = $balise_svg;
3676
-
3677
-	// entete XML à supprimer
3678
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3679
-
3680
-	// IE est toujours mon ami
3681
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3682
-
3683
-	// regler la classe
3684
-	if (!is_null($class)) {
3685
-		if (strlen($class)) {
3686
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3687
-		}
3688
-		else {
3689
-			$balise_svg = vider_attribut($balise_svg, 'class');
3690
-		}
3691
-	}
3692
-
3693
-	// regler le alt
3694
-	if ($alt) {
3695
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3696
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3697
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3698
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3699
-		$balise_svg .= $title;
3700
-	}
3701
-	else {
3702
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3703
-	}
3704
-
3705
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3706
-
3707
-	if (!is_null($size) and strlen($size = trim($size))) {
3708
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3709
-
3710
-		if (!function_exists('svg_redimensionner')) {
3711
-			include_spip('inc/svg');
3712
-		}
3713
-		$svg = svg_redimensionner($svg, $width, $height);
3714
-	}
3715
-
3716
-	return $svg;
3643
+    $svg = null;
3644
+    $img = trim($img);
3645
+    $img_file = $img;
3646
+    if (strpos($img, '<svg') === false) {
3647
+        if ($p = strpos($img_file, '?')) {
3648
+            $img_file = substr($img_file, 0, $p);
3649
+        }
3650
+
3651
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3652
+        // la copie locale a toutes les chances d'etre la ou de resservir
3653
+        if (tester_url_absolue($img_file)) {
3654
+            include_spip('inc/distant');
3655
+            $fichier = copie_locale($img_file);
3656
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3657
+        }
3658
+
3659
+        if (
3660
+            !$img_file
3661
+            or !file_exists($img_file)
3662
+            or !$svg = file_get_contents($img_file)
3663
+        ) {
3664
+            return '';
3665
+        }
3666
+    }
3667
+
3668
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3669
+        return '';
3670
+    }
3671
+
3672
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3673
+
3674
+    $balise_svg = $match[0];
3675
+    $balise_svg_source = $balise_svg;
3676
+
3677
+    // entete XML à supprimer
3678
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3679
+
3680
+    // IE est toujours mon ami
3681
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3682
+
3683
+    // regler la classe
3684
+    if (!is_null($class)) {
3685
+        if (strlen($class)) {
3686
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3687
+        }
3688
+        else {
3689
+            $balise_svg = vider_attribut($balise_svg, 'class');
3690
+        }
3691
+    }
3692
+
3693
+    // regler le alt
3694
+    if ($alt) {
3695
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3696
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3697
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3698
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3699
+        $balise_svg .= $title;
3700
+    }
3701
+    else {
3702
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3703
+    }
3704
+
3705
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3706
+
3707
+    if (!is_null($size) and strlen($size = trim($size))) {
3708
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3709
+
3710
+        if (!function_exists('svg_redimensionner')) {
3711
+            include_spip('inc/svg');
3712
+        }
3713
+        $svg = svg_redimensionner($svg, $width, $height);
3714
+    }
3715
+
3716
+    return $svg;
3717 3717
 }
3718 3718
 
3719 3719
 
@@ -3739,18 +3739,18 @@  discard block
 block discarded – undo
3739 3739
  *     Code HTML résultant
3740 3740
  **/
3741 3741
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3742
-	$texte = '';
3743
-	if (is_array($tableau)) {
3744
-		foreach ($tableau as $k => $v) {
3745
-			$res = recuperer_fond(
3746
-				'modeles/' . $modele,
3747
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3748
-			);
3749
-			$texte .= $res;
3750
-		}
3751
-	}
3742
+    $texte = '';
3743
+    if (is_array($tableau)) {
3744
+        foreach ($tableau as $k => $v) {
3745
+            $res = recuperer_fond(
3746
+                'modeles/' . $modele,
3747
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3748
+            );
3749
+            $texte .= $res;
3750
+        }
3751
+    }
3752 3752
 
3753
-	return $texte;
3753
+    return $texte;
3754 3754
 }
3755 3755
 
3756 3756
 
@@ -3775,37 +3775,37 @@  discard block
 block discarded – undo
3775 3775
  *         - tout : retourne toutes les informations du plugin actif
3776 3776
  **/
3777 3777
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3778
-	include_spip('inc/plugin');
3779
-	$plugin = strtoupper($plugin);
3780
-	$plugins_actifs = liste_plugin_actifs();
3781
-
3782
-	if (!$plugin) {
3783
-		return serialize(array_keys($plugins_actifs));
3784
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3785
-		return '';
3786
-	} elseif (($type_info == 'est_actif') and !$reload) {
3787
-		return $plugins_actifs[$plugin] ? 1 : 0;
3788
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3789
-		return $plugins_actifs[$plugin][$type_info];
3790
-	} else {
3791
-		$get_infos = charger_fonction('get_infos', 'plugins');
3792
-		// On prend en compte les extensions
3793
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3794
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3795
-		} else {
3796
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3797
-		}
3798
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3799
-			return '';
3800
-		}
3801
-		if ($type_info == 'tout') {
3802
-			return $infos;
3803
-		} elseif ($type_info == 'est_actif') {
3804
-			return $infos ? 1 : 0;
3805
-		} else {
3806
-			return strval($infos[$type_info]);
3807
-		}
3808
-	}
3778
+    include_spip('inc/plugin');
3779
+    $plugin = strtoupper($plugin);
3780
+    $plugins_actifs = liste_plugin_actifs();
3781
+
3782
+    if (!$plugin) {
3783
+        return serialize(array_keys($plugins_actifs));
3784
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3785
+        return '';
3786
+    } elseif (($type_info == 'est_actif') and !$reload) {
3787
+        return $plugins_actifs[$plugin] ? 1 : 0;
3788
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3789
+        return $plugins_actifs[$plugin][$type_info];
3790
+    } else {
3791
+        $get_infos = charger_fonction('get_infos', 'plugins');
3792
+        // On prend en compte les extensions
3793
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3794
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3795
+        } else {
3796
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3797
+        }
3798
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3799
+            return '';
3800
+        }
3801
+        if ($type_info == 'tout') {
3802
+            return $infos;
3803
+        } elseif ($type_info == 'est_actif') {
3804
+            return $infos ? 1 : 0;
3805
+        } else {
3806
+            return strval($infos[$type_info]);
3807
+        }
3808
+    }
3809 3809
 }
3810 3810
 
3811 3811
 
@@ -3832,9 +3832,9 @@  discard block
 block discarded – undo
3832 3832
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3833 3833
  */
3834 3834
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3835
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3835
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3836 3836
 
3837
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3837
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3838 3838
 }
3839 3839
 
3840 3840
 
@@ -3864,19 +3864,19 @@  discard block
 block discarded – undo
3864 3864
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3865 3865
  */
3866 3866
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3867
-	static $puce_statut = null;
3868
-	if (!$puce_statut) {
3869
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3870
-	}
3867
+    static $puce_statut = null;
3868
+    if (!$puce_statut) {
3869
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3870
+    }
3871 3871
 
3872
-	return $puce_statut(
3873
-		$id_objet,
3874
-		$statut,
3875
-		$id_parent,
3876
-		$objet,
3877
-		false,
3878
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3879
-	);
3872
+    return $puce_statut(
3873
+        $id_objet,
3874
+        $statut,
3875
+        $id_parent,
3876
+        $objet,
3877
+        false,
3878
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3879
+    );
3880 3880
 }
3881 3881
 
3882 3882
 
@@ -3903,98 +3903,98 @@  discard block
 block discarded – undo
3903 3903
  *   hash du contexte
3904 3904
  */
3905 3905
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3906
-	$env = null;
3907
-	if (
3908
-		is_string($c)
3909
-		and @unserialize($c) !== false
3910
-	) {
3911
-		$c = unserialize($c);
3912
-	}
3913
-
3914
-	// supprimer les parametres debut_x
3915
-	// pour que la pagination ajax ne soit pas plantee
3916
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3917
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3918
-	if (is_array($c)) {
3919
-		foreach ($c as $k => $v) {
3920
-			if (strpos($k, 'debut_') === 0) {
3921
-				unset($c[$k]);
3922
-			}
3923
-		}
3924
-	}
3925
-
3926
-	if (!function_exists('calculer_cle_action')) {
3927
-		include_spip('inc/securiser_action');
3928
-	}
3929
-
3930
-	$c = serialize($c);
3931
-	$cle = calculer_cle_action($form . $c);
3932
-	$c = "$cle:$c";
3933
-
3934
-	// on ne stocke pas les contextes dans des fichiers en cache
3935
-	// par defaut, sauf si cette configuration a été forcée
3936
-	// OU que la longueur de l’argument géneré est plus long
3937
-	// que ce qui est toléré.
3938
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3939
-	if (!$cache_contextes_ajax) {
3940
-		$env = $c;
3941
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3942
-			$env = gzdeflate($env);
3943
-		}
3944
-		$env = _xor($env);
3945
-		$env = base64_encode($env);
3946
-		$len = strlen($env);
3947
-		// Si l’url est trop longue pour le navigateur
3948
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3949
-		if ($len > $max_len) {
3950
-			$cache_contextes_ajax = true;
3951
-			spip_log(
3952
-				'Contextes AJAX forces en fichiers !'
3953
-				. ' Cela arrive lorsque la valeur du contexte'
3954
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3955
-				_LOG_AVERTISSEMENT
3956
-			);
3957
-		}
3958
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3959
-		elseif (
3960
-			$max_len = @ini_get('suhosin.get.max_value_length')
3961
-			and $max_len < $len
3962
-		) {
3963
-			$cache_contextes_ajax = true;
3964
-			spip_log('Contextes AJAX forces en fichiers !'
3965
-				. ' Cela arrive lorsque la valeur du contexte'
3966
-				. ' depasse la longueur maximale autorisee par Suhosin'
3967
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3968
-				. ' Vous devriez modifier les parametres de Suhosin'
3969
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3970
-		}
3971
-	}
3972
-
3973
-	if ($cache_contextes_ajax) {
3974
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3975
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3976
-		$md5 = md5($c);
3977
-		ecrire_fichier("$dir/c$md5", $c);
3978
-		$env = $md5;
3979
-	}
3980
-
3981
-	if ($emboite === null) {
3982
-		return $env;
3983
-	}
3984
-	if (!trim($emboite)) {
3985
-		return '';
3986
-	}
3987
-	// toujours encoder l'url source dans le bloc ajax
3988
-	$r = self();
3989
-	$r = ' data-origin="' . $r . '"';
3990
-	$class = 'ajaxbloc';
3991
-	if ($ajaxid and is_string($ajaxid)) {
3992
-		// ajaxid est normalement conforme a un nom de classe css
3993
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3994
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3995
-	}
3996
-
3997
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3906
+    $env = null;
3907
+    if (
3908
+        is_string($c)
3909
+        and @unserialize($c) !== false
3910
+    ) {
3911
+        $c = unserialize($c);
3912
+    }
3913
+
3914
+    // supprimer les parametres debut_x
3915
+    // pour que la pagination ajax ne soit pas plantee
3916
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3917
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3918
+    if (is_array($c)) {
3919
+        foreach ($c as $k => $v) {
3920
+            if (strpos($k, 'debut_') === 0) {
3921
+                unset($c[$k]);
3922
+            }
3923
+        }
3924
+    }
3925
+
3926
+    if (!function_exists('calculer_cle_action')) {
3927
+        include_spip('inc/securiser_action');
3928
+    }
3929
+
3930
+    $c = serialize($c);
3931
+    $cle = calculer_cle_action($form . $c);
3932
+    $c = "$cle:$c";
3933
+
3934
+    // on ne stocke pas les contextes dans des fichiers en cache
3935
+    // par defaut, sauf si cette configuration a été forcée
3936
+    // OU que la longueur de l’argument géneré est plus long
3937
+    // que ce qui est toléré.
3938
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3939
+    if (!$cache_contextes_ajax) {
3940
+        $env = $c;
3941
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3942
+            $env = gzdeflate($env);
3943
+        }
3944
+        $env = _xor($env);
3945
+        $env = base64_encode($env);
3946
+        $len = strlen($env);
3947
+        // Si l’url est trop longue pour le navigateur
3948
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3949
+        if ($len > $max_len) {
3950
+            $cache_contextes_ajax = true;
3951
+            spip_log(
3952
+                'Contextes AJAX forces en fichiers !'
3953
+                . ' Cela arrive lorsque la valeur du contexte'
3954
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3955
+                _LOG_AVERTISSEMENT
3956
+            );
3957
+        }
3958
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3959
+        elseif (
3960
+            $max_len = @ini_get('suhosin.get.max_value_length')
3961
+            and $max_len < $len
3962
+        ) {
3963
+            $cache_contextes_ajax = true;
3964
+            spip_log('Contextes AJAX forces en fichiers !'
3965
+                . ' Cela arrive lorsque la valeur du contexte'
3966
+                . ' depasse la longueur maximale autorisee par Suhosin'
3967
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3968
+                . ' Vous devriez modifier les parametres de Suhosin'
3969
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3970
+        }
3971
+    }
3972
+
3973
+    if ($cache_contextes_ajax) {
3974
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3975
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3976
+        $md5 = md5($c);
3977
+        ecrire_fichier("$dir/c$md5", $c);
3978
+        $env = $md5;
3979
+    }
3980
+
3981
+    if ($emboite === null) {
3982
+        return $env;
3983
+    }
3984
+    if (!trim($emboite)) {
3985
+        return '';
3986
+    }
3987
+    // toujours encoder l'url source dans le bloc ajax
3988
+    $r = self();
3989
+    $r = ' data-origin="' . $r . '"';
3990
+    $class = 'ajaxbloc';
3991
+    if ($ajaxid and is_string($ajaxid)) {
3992
+        // ajaxid est normalement conforme a un nom de classe css
3993
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3994
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3995
+    }
3996
+
3997
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3998 3998
 }
3999 3999
 
4000 4000
 /**
@@ -4014,37 +4014,37 @@  discard block
 block discarded – undo
4014 4014
  *   - false : erreur de décodage
4015 4015
  */
4016 4016
 function decoder_contexte_ajax($c, $form = '') {
4017
-	if (!function_exists('calculer_cle_action')) {
4018
-		include_spip('inc/securiser_action');
4019
-	}
4020
-	if (
4021
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4022
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4023
-		and lire_fichier("$dir/c$c", $contexte)
4024
-	) {
4025
-		$c = $contexte;
4026
-	} else {
4027
-		$c = @base64_decode($c);
4028
-		$c = _xor($c);
4029
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4030
-			$c = @gzinflate($c);
4031
-		}
4032
-	}
4033
-
4034
-	// extraire la signature en debut de contexte
4035
-	// et la verifier avant de deserializer
4036
-	// format : signature:donneesserializees
4037
-	if ($p = strpos($c, ':')) {
4038
-		$cle = substr($c, 0, $p);
4039
-		$c = substr($c, $p + 1);
4040
-
4041
-		if ($cle == calculer_cle_action($form . $c)) {
4042
-			$env = @unserialize($c);
4043
-			return $env;
4044
-		}
4045
-	}
4046
-
4047
-	return false;
4017
+    if (!function_exists('calculer_cle_action')) {
4018
+        include_spip('inc/securiser_action');
4019
+    }
4020
+    if (
4021
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4022
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4023
+        and lire_fichier("$dir/c$c", $contexte)
4024
+    ) {
4025
+        $c = $contexte;
4026
+    } else {
4027
+        $c = @base64_decode($c);
4028
+        $c = _xor($c);
4029
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4030
+            $c = @gzinflate($c);
4031
+        }
4032
+    }
4033
+
4034
+    // extraire la signature en debut de contexte
4035
+    // et la verifier avant de deserializer
4036
+    // format : signature:donneesserializees
4037
+    if ($p = strpos($c, ':')) {
4038
+        $cle = substr($c, 0, $p);
4039
+        $c = substr($c, $p + 1);
4040
+
4041
+        if ($cle == calculer_cle_action($form . $c)) {
4042
+            $env = @unserialize($c);
4043
+            return $env;
4044
+        }
4045
+    }
4046
+
4047
+    return false;
4048 4048
 }
4049 4049
 
4050 4050
 
@@ -4062,20 +4062,20 @@  discard block
 block discarded – undo
4062 4062
  *    Message décrypté ou encrypté
4063 4063
  **/
4064 4064
 function _xor($message, $key = null) {
4065
-	if (is_null($key)) {
4066
-		if (!function_exists('calculer_cle_action')) {
4067
-			include_spip('inc/securiser_action');
4068
-		}
4069
-		$key = pack('H*', calculer_cle_action('_xor'));
4070
-	}
4065
+    if (is_null($key)) {
4066
+        if (!function_exists('calculer_cle_action')) {
4067
+            include_spip('inc/securiser_action');
4068
+        }
4069
+        $key = pack('H*', calculer_cle_action('_xor'));
4070
+    }
4071 4071
 
4072
-	$keylen = strlen($key);
4073
-	$messagelen = strlen($message);
4074
-	for ($i = 0; $i < $messagelen; $i++) {
4075
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4076
-	}
4072
+    $keylen = strlen($key);
4073
+    $messagelen = strlen($message);
4074
+    for ($i = 0; $i < $messagelen; $i++) {
4075
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4076
+    }
4077 4077
 
4078
-	return $message;
4078
+    return $message;
4079 4079
 }
4080 4080
 
4081 4081
 /**
@@ -4089,7 +4089,7 @@  discard block
 block discarded – undo
4089 4089
  * @return string
4090 4090
  */
4091 4091
 function url_reponse_forum($texte) {
4092
- return $texte;
4092
+    return $texte;
4093 4093
 }
4094 4094
 
4095 4095
 /**
@@ -4103,7 +4103,7 @@  discard block
 block discarded – undo
4103 4103
  * @return string
4104 4104
  */
4105 4105
 function url_rss_forum($texte) {
4106
- return $texte;
4106
+    return $texte;
4107 4107
 }
4108 4108
 
4109 4109
 
@@ -4142,37 +4142,37 @@  discard block
 block discarded – undo
4142 4142
  *   Code HTML
4143 4143
  */
4144 4144
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4145
-	if ($on) {
4146
-		$bal = 'strong';
4147
-		$class = '';
4148
-		$att = '';
4149
-		// si $on passe la balise et optionnelement une ou ++classe
4150
-		// a.active span.selected.active etc....
4151
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4152
-			$on = explode('.', $on);
4153
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4154
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4155
-				$bal = array_shift($on);
4156
-				$class = implode(' ', $on);
4157
-				if ($bal == 'a') {
4158
-					$att = 'href="#" ';
4159
-				}
4160
-			}
4161
-		}
4162
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4163
-	} else {
4164
-		$bal = 'a';
4165
-		$att = "href='$url'"
4166
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4167
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4168
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4169
-			. $evt;
4170
-	}
4171
-	if ($libelle === null) {
4172
-		$libelle = $url;
4173
-	}
4174
-
4175
-	return "<$bal $att>$libelle</$bal>";
4145
+    if ($on) {
4146
+        $bal = 'strong';
4147
+        $class = '';
4148
+        $att = '';
4149
+        // si $on passe la balise et optionnelement une ou ++classe
4150
+        // a.active span.selected.active etc....
4151
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4152
+            $on = explode('.', $on);
4153
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4154
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4155
+                $bal = array_shift($on);
4156
+                $class = implode(' ', $on);
4157
+                if ($bal == 'a') {
4158
+                    $att = 'href="#" ';
4159
+                }
4160
+            }
4161
+        }
4162
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4163
+    } else {
4164
+        $bal = 'a';
4165
+        $att = "href='$url'"
4166
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4167
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4168
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4169
+            . $evt;
4170
+    }
4171
+    if ($libelle === null) {
4172
+        $libelle = $url;
4173
+    }
4174
+
4175
+    return "<$bal $att>$libelle</$bal>";
4176 4176
 }
4177 4177
 
4178 4178
 
@@ -4189,39 +4189,39 @@  discard block
 block discarded – undo
4189 4189
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4190 4190
  */
4191 4191
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4192
-	static $local_singulier_ou_pluriel = [];
4193
-
4194
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4195
-	if (!is_numeric($nb) or $nb == 0) {
4196
-		return '';
4197
-	}
4198
-	if (!is_array($vars)) {
4199
-		return '';
4200
-	}
4201
-
4202
-	$langue = $GLOBALS['spip_lang'];
4203
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4204
-		$local_singulier_ou_pluriel[$langue] = false;
4205
-		if (
4206
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4207
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4208
-		) {
4209
-			$local_singulier_ou_pluriel[$langue] = $f;
4210
-		}
4211
-	}
4212
-
4213
-	// si on a une surcharge on l'utilise
4214
-	if ($local_singulier_ou_pluriel[$langue]) {
4215
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4216
-	}
4217
-
4218
-	// sinon traitement par defaut
4219
-	$vars[$var] = $nb;
4220
-	if ($nb >= 2) {
4221
-		return _T($chaine_plusieurs, $vars);
4222
-	} else {
4223
-		return _T($chaine_un, $vars);
4224
-	}
4192
+    static $local_singulier_ou_pluriel = [];
4193
+
4194
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4195
+    if (!is_numeric($nb) or $nb == 0) {
4196
+        return '';
4197
+    }
4198
+    if (!is_array($vars)) {
4199
+        return '';
4200
+    }
4201
+
4202
+    $langue = $GLOBALS['spip_lang'];
4203
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4204
+        $local_singulier_ou_pluriel[$langue] = false;
4205
+        if (
4206
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4207
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4208
+        ) {
4209
+            $local_singulier_ou_pluriel[$langue] = $f;
4210
+        }
4211
+    }
4212
+
4213
+    // si on a une surcharge on l'utilise
4214
+    if ($local_singulier_ou_pluriel[$langue]) {
4215
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4216
+    }
4217
+
4218
+    // sinon traitement par defaut
4219
+    $vars[$var] = $nb;
4220
+    if ($nb >= 2) {
4221
+        return _T($chaine_plusieurs, $vars);
4222
+    } else {
4223
+        return _T($chaine_un, $vars);
4224
+    }
4225 4225
 }
4226 4226
 
4227 4227
 
@@ -4249,73 +4249,73 @@  discard block
 block discarded – undo
4249 4249
  */
4250 4250
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4251 4251
 
4252
-	$class_lien = $class_bouton = $class;
4253
-
4254
-	// Normaliser la fonction et compléter la classe en fonction
4255
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4256
-		$class_lien .= ' danger';
4257
-		$class_bouton .= ' btn_danger';
4258
-	} elseif ($fonction == 'rien.gif') {
4259
-		$fonction = '';
4260
-	} elseif ($fonction == 'delsafe') {
4261
-		$fonction = 'del';
4262
-	}
4263
-
4264
-	$fond_origine = $fond;
4265
-	// Remappage des icone : article-24.png+new => article-new-24.png
4266
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4267
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4268
-	}
4269
-
4270
-	// Ajouter le type d'objet dans la classe
4271
-	$objet_type = substr(basename($fond), 0, -4);
4272
-	$class_lien .= " $objet_type";
4273
-	$class_bouton .= " $objet_type";
4274
-
4275
-	// texte
4276
-	$alt = attribut_html($texte);
4277
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4278
-
4279
-	// Liens : préparer les classes ajax
4280
-	$ajax = '';
4281
-	if ($type === 'lien') {
4282
-		if (strpos($class_lien, 'ajax') !== false) {
4283
-			$ajax = 'ajax';
4284
-			if (strpos($class_lien, 'preload') !== false) {
4285
-				$ajax .= ' preload';
4286
-			}
4287
-			if (strpos($class_lien, 'nocache') !== false) {
4288
-				$ajax .= ' nocache';
4289
-			}
4290
-			$ajax = " class='$ajax'";
4291
-		}
4292
-	}
4293
-
4294
-	// Repérer la taille et l'ajouter dans la classe
4295
-	$size = 24;
4296
-	if (
4297
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4298
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4299
-	) {
4300
-		$size = $match[1];
4301
-	}
4302
-	$class_lien .= " s$size";
4303
-	$class_bouton .= " s$size";
4304
-
4305
-	// Icône
4306
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4307
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4308
-
4309
-	// Markup final
4310
-	if ($type == 'lien') {
4311
-		return "<span class='icone $class_lien'>"
4312
-		. "<a href='$lien'$title$ajax$javascript>"
4313
-		. $icone
4314
-		. "<b>$texte</b>"
4315
-		. "</a></span>\n";
4316
-	} else {
4317
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4318
-	}
4252
+    $class_lien = $class_bouton = $class;
4253
+
4254
+    // Normaliser la fonction et compléter la classe en fonction
4255
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4256
+        $class_lien .= ' danger';
4257
+        $class_bouton .= ' btn_danger';
4258
+    } elseif ($fonction == 'rien.gif') {
4259
+        $fonction = '';
4260
+    } elseif ($fonction == 'delsafe') {
4261
+        $fonction = 'del';
4262
+    }
4263
+
4264
+    $fond_origine = $fond;
4265
+    // Remappage des icone : article-24.png+new => article-new-24.png
4266
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4267
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4268
+    }
4269
+
4270
+    // Ajouter le type d'objet dans la classe
4271
+    $objet_type = substr(basename($fond), 0, -4);
4272
+    $class_lien .= " $objet_type";
4273
+    $class_bouton .= " $objet_type";
4274
+
4275
+    // texte
4276
+    $alt = attribut_html($texte);
4277
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4278
+
4279
+    // Liens : préparer les classes ajax
4280
+    $ajax = '';
4281
+    if ($type === 'lien') {
4282
+        if (strpos($class_lien, 'ajax') !== false) {
4283
+            $ajax = 'ajax';
4284
+            if (strpos($class_lien, 'preload') !== false) {
4285
+                $ajax .= ' preload';
4286
+            }
4287
+            if (strpos($class_lien, 'nocache') !== false) {
4288
+                $ajax .= ' nocache';
4289
+            }
4290
+            $ajax = " class='$ajax'";
4291
+        }
4292
+    }
4293
+
4294
+    // Repérer la taille et l'ajouter dans la classe
4295
+    $size = 24;
4296
+    if (
4297
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4298
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4299
+    ) {
4300
+        $size = $match[1];
4301
+    }
4302
+    $class_lien .= " s$size";
4303
+    $class_bouton .= " s$size";
4304
+
4305
+    // Icône
4306
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4307
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4308
+
4309
+    // Markup final
4310
+    if ($type == 'lien') {
4311
+        return "<span class='icone $class_lien'>"
4312
+        . "<a href='$lien'$title$ajax$javascript>"
4313
+        . $icone
4314
+        . "<b>$texte</b>"
4315
+        . "</a></span>\n";
4316
+    } else {
4317
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4318
+    }
4319 4319
 }
4320 4320
 
4321 4321
 /**
@@ -4339,7 +4339,7 @@  discard block
 block discarded – undo
4339 4339
  *     Code HTML du lien
4340 4340
  **/
4341 4341
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4342
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4342
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4343 4343
 }
4344 4344
 
4345 4345
 /**
@@ -4374,7 +4374,7 @@  discard block
 block discarded – undo
4374 4374
  *     Code HTML du lien
4375 4375
  **/
4376 4376
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4377
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4377
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4378 4378
 }
4379 4379
 
4380 4380
 /**
@@ -4419,7 +4419,7 @@  discard block
 block discarded – undo
4419 4419
  *     Code HTML du lien
4420 4420
  **/
4421 4421
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4422
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4422
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4423 4423
 }
4424 4424
 
4425 4425
 /**
@@ -4450,7 +4450,7 @@  discard block
 block discarded – undo
4450 4450
  *     Code HTML du lien
4451 4451
  **/
4452 4452
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4453
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4453
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4454 4454
 }
4455 4455
 
4456 4456
 /**
@@ -4481,7 +4481,7 @@  discard block
 block discarded – undo
4481 4481
  *     Code HTML du lien
4482 4482
  */
4483 4483
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4484
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4484
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4485 4485
 }
4486 4486
 
4487 4487
 
@@ -4503,7 +4503,7 @@  discard block
 block discarded – undo
4503 4503
  * @return array Liste des éléments
4504 4504
  */
4505 4505
 function filtre_explode_dist($a, $b) {
4506
-	return explode($b, (string) $a);
4506
+    return explode($b, (string) $a);
4507 4507
 }
4508 4508
 
4509 4509
 /**
@@ -4524,7 +4524,7 @@  discard block
 block discarded – undo
4524 4524
  * @return string texte
4525 4525
  */
4526 4526
 function filtre_implode_dist($a, $b) {
4527
-	return is_array($a) ? implode($b, $a) : $a;
4527
+    return is_array($a) ? implode($b, $a) : $a;
4528 4528
 }
4529 4529
 
4530 4530
 /**
@@ -4533,22 +4533,22 @@  discard block
 block discarded – undo
4533 4533
  * @return string Code CSS
4534 4534
  */
4535 4535
 function bando_images_background() {
4536
-	include_spip('inc/bandeau');
4537
-	// recuperer tous les boutons et leurs images
4538
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4536
+    include_spip('inc/bandeau');
4537
+    // recuperer tous les boutons et leurs images
4538
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4539 4539
 
4540
-	$res = '';
4541
-	foreach ($boutons as $page => $detail) {
4542
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4543
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4544
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4545
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4546
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4547
-			}
4548
-		}
4549
-	}
4540
+    $res = '';
4541
+    foreach ($boutons as $page => $detail) {
4542
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4543
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4544
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4545
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4546
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4547
+            }
4548
+        }
4549
+    }
4550 4550
 
4551
-	return $res;
4551
+    return $res;
4552 4552
 }
4553 4553
 
4554 4554
 /**
@@ -4573,27 +4573,27 @@  discard block
 block discarded – undo
4573 4573
  */
4574 4574
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4575 4575
 
4576
-	// Classes : dispatcher `ajax` sur le formulaire
4577
-	$class_form = '';
4578
-	if (strpos($class, 'ajax') !== false) {
4579
-		$class_form = 'ajax';
4580
-		$class = str_replace('ajax', '', $class);
4581
-	}
4582
-	$class_btn = 'submit ' . trim($class);
4576
+    // Classes : dispatcher `ajax` sur le formulaire
4577
+    $class_form = '';
4578
+    if (strpos($class, 'ajax') !== false) {
4579
+        $class_form = 'ajax';
4580
+        $class = str_replace('ajax', '', $class);
4581
+    }
4582
+    $class_btn = 'submit ' . trim($class);
4583 4583
 
4584
-	if ($confirm) {
4585
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4586
-		if ($callback) {
4587
-			$callback = "$confirm?($callback):false";
4588
-		} else {
4589
-			$callback = $confirm;
4590
-		}
4591
-	}
4592
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4593
-	$title = $title ? " title='$title'" : '';
4584
+    if ($confirm) {
4585
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4586
+        if ($callback) {
4587
+            $callback = "$confirm?($callback):false";
4588
+        } else {
4589
+            $callback = $confirm;
4590
+        }
4591
+    }
4592
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4593
+    $title = $title ? " title='$title'" : '';
4594 4594
 
4595
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4596
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4595
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4596
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4597 4597
 }
4598 4598
 
4599 4599
 /**
@@ -4616,101 +4616,101 @@  discard block
 block discarded – undo
4616 4616
  * @return string
4617 4617
  */
4618 4618
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4619
-	static $trouver_table = null;
4620
-	static $objets;
4621
-
4622
-	// On verifie qu'on a tout ce qu'il faut
4623
-	$id_objet = intval($id_objet);
4624
-	if (!($id_objet and $type_objet and $info)) {
4625
-		return '';
4626
-	}
4627
-
4628
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4629
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4630
-		return '';
4631
-	}
4632
-
4633
-	// Si on demande l'url, on retourne direct la fonction
4634
-	if ($info == 'url') {
4635
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4636
-	}
4637
-
4638
-	// Sinon on va tout chercher dans la table et on garde en memoire
4639
-	$demande_titre = ($info === 'titre');
4640
-	$demande_introduction = ($info === 'introduction');
4641
-
4642
-	// 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
4643
-	if (
4644
-		!isset($objets[$type_objet][$id_objet])
4645
-		or
4646
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4647
-	) {
4648
-		if (!$trouver_table) {
4649
-			$trouver_table = charger_fonction('trouver_table', 'base');
4650
-		}
4651
-		$desc = $trouver_table(table_objet_sql($type_objet));
4652
-		if (!$desc) {
4653
-			return $objets[$type_objet] = false;
4654
-		}
4655
-
4656
-		// Si on demande le titre, on le gere en interne
4657
-		$champ_titre = '';
4658
-		if ($demande_titre) {
4659
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4660
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4661
-		}
4662
-		include_spip('base/abstract_sql');
4663
-		include_spip('base/connect_sql');
4664
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4665
-			'*' . $champ_titre,
4666
-			$desc['table_sql'],
4667
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4668
-		);
4669
-
4670
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4671
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4672
-	}
4673
-
4674
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4675
-	// ajouter la longueur au début des params supplémentaires
4676
-	if ($demande_introduction) {
4677
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4678
-		array_unshift($params, $introduction_longueur);
4679
-	}
4680
-
4681
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4682
-	if (
4683
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4684
-		// @deprecated 4.1 generer_TRUC_TYPE
4685
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4686
-	) {
4687
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4688
-	}
4689
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4690
-	elseif (
4691
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4692
-		// @deprecated 4.1 generer_TRUC_entite
4693
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4694
-	) {
4695
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4696
-	} // Sinon on prend directement le champ SQL tel quel
4697
-	else {
4698
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4699
-	}
4700
-
4701
-	// On va ensuite appliquer les traitements automatiques si besoin
4702
-	if (!$etoile) {
4703
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4704
-		// mais ce fonctionnement est a ameliorer !
4705
-		$info_generee = appliquer_traitement_champ(
4706
-			$info_generee,
4707
-			$info,
4708
-			table_objet($type_objet),
4709
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4710
-		);
4711
-	}
4712
-
4713
-	return $info_generee;
4619
+    static $trouver_table = null;
4620
+    static $objets;
4621
+
4622
+    // On verifie qu'on a tout ce qu'il faut
4623
+    $id_objet = intval($id_objet);
4624
+    if (!($id_objet and $type_objet and $info)) {
4625
+        return '';
4626
+    }
4627
+
4628
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4629
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4630
+        return '';
4631
+    }
4632
+
4633
+    // Si on demande l'url, on retourne direct la fonction
4634
+    if ($info == 'url') {
4635
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4636
+    }
4637
+
4638
+    // Sinon on va tout chercher dans la table et on garde en memoire
4639
+    $demande_titre = ($info === 'titre');
4640
+    $demande_introduction = ($info === 'introduction');
4641
+
4642
+    // 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
4643
+    if (
4644
+        !isset($objets[$type_objet][$id_objet])
4645
+        or
4646
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4647
+    ) {
4648
+        if (!$trouver_table) {
4649
+            $trouver_table = charger_fonction('trouver_table', 'base');
4650
+        }
4651
+        $desc = $trouver_table(table_objet_sql($type_objet));
4652
+        if (!$desc) {
4653
+            return $objets[$type_objet] = false;
4654
+        }
4655
+
4656
+        // Si on demande le titre, on le gere en interne
4657
+        $champ_titre = '';
4658
+        if ($demande_titre) {
4659
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4660
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4661
+        }
4662
+        include_spip('base/abstract_sql');
4663
+        include_spip('base/connect_sql');
4664
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4665
+            '*' . $champ_titre,
4666
+            $desc['table_sql'],
4667
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4668
+        );
4669
+
4670
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4671
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4672
+    }
4673
+
4674
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4675
+    // ajouter la longueur au début des params supplémentaires
4676
+    if ($demande_introduction) {
4677
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4678
+        array_unshift($params, $introduction_longueur);
4679
+    }
4680
+
4681
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4682
+    if (
4683
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4684
+        // @deprecated 4.1 generer_TRUC_TYPE
4685
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4686
+    ) {
4687
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4688
+    }
4689
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4690
+    elseif (
4691
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4692
+        // @deprecated 4.1 generer_TRUC_entite
4693
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4694
+    ) {
4695
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4696
+    } // Sinon on prend directement le champ SQL tel quel
4697
+    else {
4698
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4699
+    }
4700
+
4701
+    // On va ensuite appliquer les traitements automatiques si besoin
4702
+    if (!$etoile) {
4703
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4704
+        // mais ce fonctionnement est a ameliorer !
4705
+        $info_generee = appliquer_traitement_champ(
4706
+            $info_generee,
4707
+            $info,
4708
+            table_objet($type_objet),
4709
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4710
+        );
4711
+    }
4712
+
4713
+    return $info_generee;
4714 4714
 }
4715 4715
 
4716 4716
 /**
@@ -4718,7 +4718,7 @@  discard block
 block discarded – undo
4718 4718
  * @see generer_objet_info
4719 4719
  */
4720 4720
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4721
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4721
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4722 4722
 }
4723 4723
 
4724 4724
 /**
@@ -4751,36 +4751,36 @@  discard block
 block discarded – undo
4751 4751
  */
4752 4752
 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 {
4753 4753
 
4754
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4755
-	$texte = $ligne_sql['texte'] ?? '';
4756
-	// En absence de descriptif, on se rabat sur chapo + texte
4757
-	if (isset($ligne_sql['chapo'])) {
4758
-		$chapo = $ligne_sql['chapo'];
4759
-		$texte = strlen($descriptif) ?
4760
-			'' :
4761
-			"$chapo \n\n $texte";
4762
-	}
4754
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4755
+    $texte = $ligne_sql['texte'] ?? '';
4756
+    // En absence de descriptif, on se rabat sur chapo + texte
4757
+    if (isset($ligne_sql['chapo'])) {
4758
+        $chapo = $ligne_sql['chapo'];
4759
+        $texte = strlen($descriptif) ?
4760
+            '' :
4761
+            "$chapo \n\n $texte";
4762
+    }
4763 4763
 
4764
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4765
-	if (!intval($longueur_ou_suite)) {
4766
-		$longueur = intval($introduction_longueur ?: 600);
4767
-	} else {
4768
-		$longueur = intval($longueur_ou_suite);
4769
-	}
4764
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4765
+    if (!intval($longueur_ou_suite)) {
4766
+        $longueur = intval($introduction_longueur ?: 600);
4767
+    } else {
4768
+        $longueur = intval($longueur_ou_suite);
4769
+    }
4770 4770
 
4771
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4772
-	// Ex : #INTRODUCTION{...}
4773
-	if (
4774
-		is_null($suite)
4775
-		and !intval($longueur_ou_suite)
4776
-	) {
4777
-		$suite = $longueur_ou_suite;
4778
-	}
4771
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4772
+    // Ex : #INTRODUCTION{...}
4773
+    if (
4774
+        is_null($suite)
4775
+        and !intval($longueur_ou_suite)
4776
+    ) {
4777
+        $suite = $longueur_ou_suite;
4778
+    }
4779 4779
 
4780
-	$f = chercher_filtre('introduction');
4781
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4780
+    $f = chercher_filtre('introduction');
4781
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4782 4782
 
4783
-	return $introduction;
4783
+    return $introduction;
4784 4784
 }
4785 4785
 
4786 4786
 /**
@@ -4788,7 +4788,7 @@  discard block
 block discarded – undo
4788 4788
  * @see generer_objet_introduction
4789 4789
  */
4790 4790
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4791
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4791
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4792 4792
 }
4793 4793
 
4794 4794
 /**
@@ -4802,49 +4802,49 @@  discard block
 block discarded – undo
4802 4802
  * @return string
4803 4803
  */
4804 4804
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4805
-	if (!$champ) {
4806
-		return $texte;
4807
-	}
4805
+    if (!$champ) {
4806
+        return $texte;
4807
+    }
4808 4808
 
4809
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4810
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4811
-	include_fichiers_fonctions();
4809
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4810
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4811
+    include_fichiers_fonctions();
4812 4812
 
4813
-	$champ = strtoupper($champ);
4814
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4815
-	if (!$traitements or !is_array($traitements)) {
4816
-		return $texte;
4817
-	}
4813
+    $champ = strtoupper($champ);
4814
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4815
+    if (!$traitements or !is_array($traitements)) {
4816
+        return $texte;
4817
+    }
4818 4818
 
4819
-	$traitement = '';
4820
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4821
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4822
-		$table_objet = table_objet($table_objet);
4823
-		if (isset($traitements[$table_objet])) {
4824
-			$traitement = $traitements[$table_objet];
4825
-		}
4826
-	}
4827
-	if (!$traitement and isset($traitements[0])) {
4828
-		$traitement = $traitements[0];
4829
-	}
4830
-	// (sinon prendre le premier de la liste par defaut ?)
4819
+    $traitement = '';
4820
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4821
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4822
+        $table_objet = table_objet($table_objet);
4823
+        if (isset($traitements[$table_objet])) {
4824
+            $traitement = $traitements[$table_objet];
4825
+        }
4826
+    }
4827
+    if (!$traitement and isset($traitements[0])) {
4828
+        $traitement = $traitements[0];
4829
+    }
4830
+    // (sinon prendre le premier de la liste par defaut ?)
4831 4831
 
4832
-	if (!$traitement) {
4833
-		return $texte;
4834
-	}
4832
+    if (!$traitement) {
4833
+        return $texte;
4834
+    }
4835 4835
 
4836
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4836
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4837 4837
 
4838
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4839
-	if (test_espace_prive()) {
4840
-		$env['espace_prive'] = 1;
4841
-	}
4838
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4839
+    if (test_espace_prive()) {
4840
+        $env['espace_prive'] = 1;
4841
+    }
4842 4842
 
4843
-	// Fournir $connect et $Pile[0] au traitement si besoin
4844
-	$Pile = [0 => $env];
4845
-	eval("\$texte = $traitement;");
4843
+    // Fournir $connect et $Pile[0] au traitement si besoin
4844
+    $Pile = [0 => $env];
4845
+    eval("\$texte = $traitement;");
4846 4846
 
4847
-	return $texte;
4847
+    return $texte;
4848 4848
 }
4849 4849
 
4850 4850
 
@@ -4858,21 +4858,21 @@  discard block
 block discarded – undo
4858 4858
  * @return string
4859 4859
  */
4860 4860
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4861
-	include_spip('inc/liens');
4862
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4863
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4864
-	// le raccourcis n'est plus valide
4865
-	$titre = typo($titre['titre'] ?? '');
4866
-	// on essaye avec generer_info_entite ?
4867
-	if (!strlen($titre) and !$connect) {
4868
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4869
-	}
4870
-	if (!strlen($titre)) {
4871
-		$titre = _T('info_sans_titre');
4872
-	}
4873
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4861
+    include_spip('inc/liens');
4862
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4863
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4864
+    // le raccourcis n'est plus valide
4865
+    $titre = typo($titre['titre'] ?? '');
4866
+    // on essaye avec generer_info_entite ?
4867
+    if (!strlen($titre) and !$connect) {
4868
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4869
+    }
4870
+    if (!strlen($titre)) {
4871
+        $titre = _T('info_sans_titre');
4872
+    }
4873
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4874 4874
 
4875
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4875
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4876 4876
 }
4877 4877
 
4878 4878
 /**
@@ -4880,7 +4880,7 @@  discard block
 block discarded – undo
4880 4880
  * @see generer_objet_lien
4881 4881
  */
4882 4882
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4883
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4883
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4884 4884
 }
4885 4885
 
4886 4886
 /**
@@ -4896,15 +4896,15 @@  discard block
 block discarded – undo
4896 4896
  * @return string
4897 4897
  */
4898 4898
 function wrap($texte, $wrap) {
4899
-	$balises = extraire_balises($wrap);
4900
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4901
-		$texte = $wrap . $texte;
4902
-		$regs = array_reverse($regs[1]);
4903
-		$wrap = '</' . implode('></', $regs) . '>';
4904
-		$texte = $texte . $wrap;
4905
-	}
4899
+    $balises = extraire_balises($wrap);
4900
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4901
+        $texte = $wrap . $texte;
4902
+        $regs = array_reverse($regs[1]);
4903
+        $wrap = '</' . implode('></', $regs) . '>';
4904
+        $texte = $texte . $wrap;
4905
+    }
4906 4906
 
4907
-	return $texte;
4907
+    return $texte;
4908 4908
 }
4909 4909
 
4910 4910
 
@@ -4924,44 +4924,44 @@  discard block
 block discarded – undo
4924 4924
  * @return array|mixed|string
4925 4925
  */
4926 4926
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4927
-	if (is_string($u)) {
4928
-		$u = typo($u);
4927
+    if (is_string($u)) {
4928
+        $u = typo($u);
4929 4929
 
4930
-		return $u;
4931
-	}
4930
+        return $u;
4931
+    }
4932 4932
 
4933
-	// caster $u en array si besoin
4934
-	if (is_object($u)) {
4935
-		$u = (array)$u;
4936
-	}
4933
+    // caster $u en array si besoin
4934
+    if (is_object($u)) {
4935
+        $u = (array)$u;
4936
+    }
4937 4937
 
4938
-	if (is_array($u)) {
4939
-		$out = '';
4940
-		// toutes les cles sont numeriques ?
4941
-		// et aucun enfant n'est un tableau
4942
-		// liste simple separee par des virgules
4943
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4944
-		$array_values = array_map('is_array', $u);
4945
-		$object_values = array_map('is_object', $u);
4946
-		if (
4947
-			array_sum($numeric_keys) == count($numeric_keys)
4948
-			and !array_sum($array_values)
4949
-			and !array_sum($object_values)
4950
-		) {
4951
-			return join(', ', array_map('filtre_print_dist', $u));
4952
-		}
4938
+    if (is_array($u)) {
4939
+        $out = '';
4940
+        // toutes les cles sont numeriques ?
4941
+        // et aucun enfant n'est un tableau
4942
+        // liste simple separee par des virgules
4943
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4944
+        $array_values = array_map('is_array', $u);
4945
+        $object_values = array_map('is_object', $u);
4946
+        if (
4947
+            array_sum($numeric_keys) == count($numeric_keys)
4948
+            and !array_sum($array_values)
4949
+            and !array_sum($object_values)
4950
+        ) {
4951
+            return join(', ', array_map('filtre_print_dist', $u));
4952
+        }
4953 4953
 
4954
-		// sinon on passe a la ligne et on indente
4955
-		$i_str = str_pad('', $indent, ' ');
4956
-		foreach ($u as $k => $v) {
4957
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4958
-		}
4954
+        // sinon on passe a la ligne et on indente
4955
+        $i_str = str_pad('', $indent, ' ');
4956
+        foreach ($u as $k => $v) {
4957
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4958
+        }
4959 4959
 
4960
-		return $out;
4961
-	}
4960
+        return $out;
4961
+    }
4962 4962
 
4963
-	// on sait pas quoi faire...
4964
-	return $u;
4963
+    // on sait pas quoi faire...
4964
+    return $u;
4965 4965
 }
4966 4966
 
4967 4967
 
@@ -4974,10 +4974,10 @@  discard block
 block discarded – undo
4974 4974
  * @return string|array
4975 4975
  */
4976 4976
 function objet_info($objet, $info) {
4977
-	$table = table_objet_sql($objet);
4978
-	$infos = lister_tables_objets_sql($table);
4977
+    $table = table_objet_sql($objet);
4978
+    $infos = lister_tables_objets_sql($table);
4979 4979
 
4980
-	return ($infos[$info] ?? '');
4980
+    return ($infos[$info] ?? '');
4981 4981
 }
4982 4982
 
4983 4983
 /**
@@ -4992,11 +4992,11 @@  discard block
 block discarded – undo
4992 4992
  *     texte traduit du comptage, tel que '3 articles'
4993 4993
  */
4994 4994
 function objet_afficher_nb($nb, $objet) {
4995
-	if (!$nb) {
4996
-		return _T(objet_info($objet, 'info_aucun_objet'));
4997
-	} else {
4998
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4999
-	}
4995
+    if (!$nb) {
4996
+        return _T(objet_info($objet, 'info_aucun_objet'));
4997
+    } else {
4998
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4999
+    }
5000 5000
 }
5001 5001
 
5002 5002
 /**
@@ -5008,11 +5008,11 @@  discard block
 block discarded – undo
5008 5008
  * @return string
5009 5009
  */
5010 5010
 function objet_icone($objet, $taille = 24, $class = '') {
5011
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5012
-	$icone = chemin_image($icone);
5013
-	$balise_img = charger_filtre('balise_img');
5011
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5012
+    $icone = chemin_image($icone);
5013
+    $balise_img = charger_filtre('balise_img');
5014 5014
 
5015
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5015
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5016 5016
 }
5017 5017
 
5018 5018
 /**
@@ -5033,12 +5033,12 @@  discard block
 block discarded – undo
5033 5033
  * @return string
5034 5034
  */
5035 5035
 function objet_T($objet, $chaine, $args = [], $options = []) {
5036
-	$chaine = explode(':', $chaine);
5037
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5038
-		return $t;
5039
-	}
5040
-	$chaine = implode(':', $chaine);
5041
-	return _T($chaine, $args, $options);
5036
+    $chaine = explode(':', $chaine);
5037
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5038
+        return $t;
5039
+    }
5040
+    $chaine = implode(':', $chaine);
5041
+    return _T($chaine, $args, $options);
5042 5042
 }
5043 5043
 
5044 5044
 /**
@@ -5052,18 +5052,18 @@  discard block
 block discarded – undo
5052 5052
  * @return string      Code HTML
5053 5053
  */
5054 5054
 function insert_head_css_conditionnel($flux) {
5055
-	if (
5056
-		strpos($flux, '<!-- insert_head_css -->') === false
5057
-		and $p = strpos($flux, '<!-- insert_head -->')
5058
-	) {
5059
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5060
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5061
-			$p = $p1;
5062
-		}
5063
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5064
-	}
5055
+    if (
5056
+        strpos($flux, '<!-- insert_head_css -->') === false
5057
+        and $p = strpos($flux, '<!-- insert_head -->')
5058
+    ) {
5059
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5060
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5061
+            $p = $p1;
5062
+        }
5063
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5064
+    }
5065 5065
 
5066
-	return $flux;
5066
+    return $flux;
5067 5067
 }
5068 5068
 
5069 5069
 /**
@@ -5086,75 +5086,75 @@  discard block
 block discarded – undo
5086 5086
  * @return string
5087 5087
  */
5088 5088
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5089
-	if (isset($contexte['format'])) {
5090
-		$extension = $contexte['format'];
5091
-		unset($contexte['format']);
5092
-	} else {
5093
-		$extension = 'html';
5094
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5095
-			$extension = $m[1];
5096
-		}
5097
-	}
5098
-	// recuperer le contenu produit par le squelette
5099
-	$options['raw'] = true;
5100
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5101
-
5102
-	// calculer le nom de la css
5103
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5104
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5105
-	$contexte_implicite = calculer_contexte_implicite();
5106
-
5107
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5108
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5109
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5110
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5111
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5112
-	}
5113
-	else {
5114
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5115
-		ksort($contexte);
5116
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5117
-	}
5118
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5119
-
5120
-	// mettre a jour le fichier si il n'existe pas
5121
-	// ou trop ancien
5122
-	// le dernier fichier produit est toujours suffixe par .last
5123
-	// et recopie sur le fichier cible uniquement si il change
5124
-	if (
5125
-		!file_exists($filename)
5126
-		or !file_exists($filename . '.last')
5127
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5128
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5129
-	) {
5130
-		$contenu = $cache['texte'];
5131
-		// passer les urls en absolu si c'est une css
5132
-		if ($extension == 'css') {
5133
-			$contenu = urls_absolues_css(
5134
-				$contenu,
5135
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5136
-			);
5137
-		}
5138
-
5139
-		$comment = '';
5140
-		// ne pas insérer de commentaire sur certains formats
5141
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5142
-			$comment = "/* #PRODUIRE{fond=$fond";
5143
-			foreach ($contexte as $k => $v) {
5144
-				if (is_array($v)) {
5145
-					$v = var_export($v, true);
5146
-				}
5147
-				$comment .= ",$k=$v";
5148
-			}
5149
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5150
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5151
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5152
-		}
5153
-		// et ecrire le fichier si il change
5154
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5155
-	}
5156
-
5157
-	return timestamp($filename);
5089
+    if (isset($contexte['format'])) {
5090
+        $extension = $contexte['format'];
5091
+        unset($contexte['format']);
5092
+    } else {
5093
+        $extension = 'html';
5094
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5095
+            $extension = $m[1];
5096
+        }
5097
+    }
5098
+    // recuperer le contenu produit par le squelette
5099
+    $options['raw'] = true;
5100
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5101
+
5102
+    // calculer le nom de la css
5103
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5104
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5105
+    $contexte_implicite = calculer_contexte_implicite();
5106
+
5107
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5108
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5109
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5110
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5111
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5112
+    }
5113
+    else {
5114
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5115
+        ksort($contexte);
5116
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5117
+    }
5118
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5119
+
5120
+    // mettre a jour le fichier si il n'existe pas
5121
+    // ou trop ancien
5122
+    // le dernier fichier produit est toujours suffixe par .last
5123
+    // et recopie sur le fichier cible uniquement si il change
5124
+    if (
5125
+        !file_exists($filename)
5126
+        or !file_exists($filename . '.last')
5127
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5128
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5129
+    ) {
5130
+        $contenu = $cache['texte'];
5131
+        // passer les urls en absolu si c'est une css
5132
+        if ($extension == 'css') {
5133
+            $contenu = urls_absolues_css(
5134
+                $contenu,
5135
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5136
+            );
5137
+        }
5138
+
5139
+        $comment = '';
5140
+        // ne pas insérer de commentaire sur certains formats
5141
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5142
+            $comment = "/* #PRODUIRE{fond=$fond";
5143
+            foreach ($contexte as $k => $v) {
5144
+                if (is_array($v)) {
5145
+                    $v = var_export($v, true);
5146
+                }
5147
+                $comment .= ",$k=$v";
5148
+            }
5149
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5150
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5151
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5152
+        }
5153
+        // et ecrire le fichier si il change
5154
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5155
+    }
5156
+
5157
+    return timestamp($filename);
5158 5158
 }
5159 5159
 
5160 5160
 /**
@@ -5167,15 +5167,15 @@  discard block
 block discarded – undo
5167 5167
  *    $fichier auquel on a ajouté le timestamp
5168 5168
  */
5169 5169
 function timestamp($fichier) {
5170
-	if (
5171
-		!$fichier
5172
-		or !file_exists($fichier)
5173
-		or !$m = filemtime($fichier)
5174
-	) {
5175
-		return $fichier;
5176
-	}
5170
+    if (
5171
+        !$fichier
5172
+        or !file_exists($fichier)
5173
+        or !$m = filemtime($fichier)
5174
+    ) {
5175
+        return $fichier;
5176
+    }
5177 5177
 
5178
-	return "$fichier?$m";
5178
+    return "$fichier?$m";
5179 5179
 }
5180 5180
 
5181 5181
 /**
@@ -5185,11 +5185,11 @@  discard block
 block discarded – undo
5185 5185
  * @return string
5186 5186
  */
5187 5187
 function supprimer_timestamp($url) {
5188
-	if (strpos($url, '?') === false) {
5189
-		return $url;
5190
-	}
5188
+    if (strpos($url, '?') === false) {
5189
+        return $url;
5190
+    }
5191 5191
 
5192
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5192
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5193 5193
 }
5194 5194
 
5195 5195
 /**
@@ -5204,15 +5204,15 @@  discard block
 block discarded – undo
5204 5204
  * @return string
5205 5205
  */
5206 5206
 function filtre_nettoyer_titre_email_dist($titre) {
5207
-	include_spip('inc/envoyer_mail');
5207
+    include_spip('inc/envoyer_mail');
5208 5208
 
5209
-	$titre = nettoyer_titre_email($titre);
5210
-	// on est dans un squelette : securiser le retour
5211
-	if (strpos($titre, '<') !== false) {
5212
-		$titre = interdire_scripts($titre);
5213
-	}
5209
+    $titre = nettoyer_titre_email($titre);
5210
+    // on est dans un squelette : securiser le retour
5211
+    if (strpos($titre, '<') !== false) {
5212
+        $titre = interdire_scripts($titre);
5213
+    }
5214 5214
 
5215
-	return $titre;
5215
+    return $titre;
5216 5216
 }
5217 5217
 
5218 5218
 /**
@@ -5234,27 +5234,27 @@  discard block
 block discarded – undo
5234 5234
  * @return string
5235 5235
  */
5236 5236
 function filtre_chercher_rubrique_dist(
5237
-	$titre,
5238
-	$id_objet,
5239
-	$id_parent,
5240
-	$objet,
5241
-	$id_secteur,
5242
-	$restreint,
5243
-	$actionable = false,
5244
-	$retour_sans_cadre = false
5237
+    $titre,
5238
+    $id_objet,
5239
+    $id_parent,
5240
+    $objet,
5241
+    $id_secteur,
5242
+    $restreint,
5243
+    $actionable = false,
5244
+    $retour_sans_cadre = false
5245 5245
 ) {
5246
-	include_spip('inc/filtres_ecrire');
5246
+    include_spip('inc/filtres_ecrire');
5247 5247
 
5248
-	return chercher_rubrique(
5249
-		$titre,
5250
-		$id_objet,
5251
-		$id_parent,
5252
-		$objet,
5253
-		$id_secteur,
5254
-		$restreint,
5255
-		$actionable,
5256
-		$retour_sans_cadre
5257
-	);
5248
+    return chercher_rubrique(
5249
+        $titre,
5250
+        $id_objet,
5251
+        $id_parent,
5252
+        $objet,
5253
+        $id_secteur,
5254
+        $restreint,
5255
+        $actionable,
5256
+        $retour_sans_cadre
5257
+    );
5258 5258
 }
5259 5259
 
5260 5260
 /**
@@ -5283,56 +5283,56 @@  discard block
 block discarded – undo
5283 5283
  *     Chaîne vide si l'accès est autorisé
5284 5284
  */
5285 5285
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5286
-	if ($ok) {
5287
-		return '';
5288
-	}
5289
-
5290
-	// Vider tous les tampons
5291
-	$level = @ob_get_level();
5292
-	while ($level--) {
5293
-		@ob_end_clean();
5294
-	}
5295
-
5296
-	include_spip('inc/headers');
5297
-
5298
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5299
-	if ($url) {
5300
-		redirige_par_entete($url, '', $statut);
5301
-	}
5302
-
5303
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5304
-	if (!is_numeric($statut) and is_null($message)) {
5305
-		$message = $statut;
5306
-		$statut = 0;
5307
-	}
5308
-	if (!$message) {
5309
-		$message = '';
5310
-	}
5311
-	$statut = intval($statut);
5312
-
5313
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5314
-	if (test_espace_prive()) {
5315
-		if (!$statut or !in_array($statut, [404, 403])) {
5316
-			$statut = 403;
5317
-		}
5318
-		http_response_code(403);
5319
-		$echec = charger_fonction('403', 'exec');
5320
-		$echec($message);
5321
-	} else {
5322
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5323
-		if (!$statut) {
5324
-			$statut = 404;
5325
-		}
5326
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5327
-		http_response_code($statut);
5328
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5329
-		if ($statut >= 400) {
5330
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5331
-		}
5332
-	}
5333
-
5334
-
5335
-	exit;
5286
+    if ($ok) {
5287
+        return '';
5288
+    }
5289
+
5290
+    // Vider tous les tampons
5291
+    $level = @ob_get_level();
5292
+    while ($level--) {
5293
+        @ob_end_clean();
5294
+    }
5295
+
5296
+    include_spip('inc/headers');
5297
+
5298
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5299
+    if ($url) {
5300
+        redirige_par_entete($url, '', $statut);
5301
+    }
5302
+
5303
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5304
+    if (!is_numeric($statut) and is_null($message)) {
5305
+        $message = $statut;
5306
+        $statut = 0;
5307
+    }
5308
+    if (!$message) {
5309
+        $message = '';
5310
+    }
5311
+    $statut = intval($statut);
5312
+
5313
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5314
+    if (test_espace_prive()) {
5315
+        if (!$statut or !in_array($statut, [404, 403])) {
5316
+            $statut = 403;
5317
+        }
5318
+        http_response_code(403);
5319
+        $echec = charger_fonction('403', 'exec');
5320
+        $echec($message);
5321
+    } else {
5322
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5323
+        if (!$statut) {
5324
+            $statut = 404;
5325
+        }
5326
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5327
+        http_response_code($statut);
5328
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5329
+        if ($statut >= 400) {
5330
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5331
+        }
5332
+    }
5333
+
5334
+
5335
+    exit;
5336 5336
 }
5337 5337
 
5338 5338
 /**
@@ -5343,11 +5343,11 @@  discard block
 block discarded – undo
5343 5343
  * @return string
5344 5344
  */
5345 5345
 function filtre_compacte_dist($source, $format = null) {
5346
-	if (function_exists('minifier')) {
5347
-		return minifier($source, $format);
5348
-	}
5346
+    if (function_exists('minifier')) {
5347
+        return minifier($source, $format);
5348
+    }
5349 5349
 
5350
-	return $source;
5350
+    return $source;
5351 5351
 }
5352 5352
 
5353 5353
 
@@ -5359,32 +5359,32 @@  discard block
 block discarded – undo
5359 5359
  * @return string
5360 5360
  */
5361 5361
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5362
-	$passe ??= '';
5363
-	$l = strlen($passe);
5364
-
5365
-	if ($l <= 8 or !$afficher_partiellement) {
5366
-		if (!$l) {
5367
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5368
-		}
5369
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5370
-	}
5371
-
5372
-	if (is_null($portion_pourcent)) {
5373
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5374
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5375
-		}
5376
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5377
-	}
5378
-	if ($portion_pourcent >= 100) {
5379
-		return $passe;
5380
-	}
5381
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5382
-	$e = max($e, 0);
5383
-	$mid = str_pad('', $l - 2 * $e, '*');
5384
-	if ($e > 0 and strlen($mid) > 8) {
5385
-		$mid = '***...***';
5386
-	}
5387
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5362
+    $passe ??= '';
5363
+    $l = strlen($passe);
5364
+
5365
+    if ($l <= 8 or !$afficher_partiellement) {
5366
+        if (!$l) {
5367
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5368
+        }
5369
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5370
+    }
5371
+
5372
+    if (is_null($portion_pourcent)) {
5373
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5374
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5375
+        }
5376
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5377
+    }
5378
+    if ($portion_pourcent >= 100) {
5379
+        return $passe;
5380
+    }
5381
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5382
+    $e = max($e, 0);
5383
+    $mid = str_pad('', $l - 2 * $e, '*');
5384
+    if ($e > 0 and strlen($mid) > 8) {
5385
+        $mid = '***...***';
5386
+    }
5387
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5388 5388
 }
5389 5389
 
5390 5390
 
@@ -5405,64 +5405,64 @@  discard block
 block discarded – undo
5405 5405
  */
5406 5406
 function identifiant_slug($texte, $type = '', $options = []) {
5407 5407
 
5408
-	$original = $texte;
5409
-	$separateur = ($options['separateur'] ?? '_');
5410
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5411
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5408
+    $original = $texte;
5409
+    $separateur = ($options['separateur'] ?? '_');
5410
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5411
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5412 5412
 
5413
-	if (!function_exists('translitteration')) {
5414
-		include_spip('inc/charsets');
5415
-	}
5413
+    if (!function_exists('translitteration')) {
5414
+        include_spip('inc/charsets');
5415
+    }
5416 5416
 
5417
-	// pas de balise html
5418
-	if (strpos($texte, '<') !== false) {
5419
-		$texte = strip_tags($texte);
5420
-	}
5421
-	if (strpos($texte, '&') !== false) {
5422
-		$texte = unicode2charset($texte);
5423
-	}
5424
-	// On enlève les espaces indésirables
5425
-	$texte = trim($texte);
5417
+    // pas de balise html
5418
+    if (strpos($texte, '<') !== false) {
5419
+        $texte = strip_tags($texte);
5420
+    }
5421
+    if (strpos($texte, '&') !== false) {
5422
+        $texte = unicode2charset($texte);
5423
+    }
5424
+    // On enlève les espaces indésirables
5425
+    $texte = trim($texte);
5426 5426
 
5427
-	// On enlève les accents et cie
5428
-	$texte = translitteration($texte);
5427
+    // On enlève les accents et cie
5428
+    $texte = translitteration($texte);
5429 5429
 
5430
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5431
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5430
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5431
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5432 5432
 
5433
-	// nettoyer les doubles occurences du separateur si besoin
5434
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5435
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5436
-	}
5433
+    // nettoyer les doubles occurences du separateur si besoin
5434
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5435
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5436
+    }
5437 5437
 
5438
-	// pas de separateur au debut ni a la fin
5439
-	$texte = trim($texte, $separateur);
5438
+    // pas de separateur au debut ni a la fin
5439
+    $texte = trim($texte, $separateur);
5440 5440
 
5441
-	// en minuscules
5442
-	$texte = strtolower($texte);
5441
+    // en minuscules
5442
+    $texte = strtolower($texte);
5443 5443
 
5444
-	switch ($type) {
5445
-		case 'class':
5446
-		case 'id':
5447
-		case 'anchor':
5448
-			if (preg_match(',^\d,', $texte)) {
5449
-				$texte = substr($type, 0, 1) . $texte;
5450
-			}
5451
-	}
5444
+    switch ($type) {
5445
+        case 'class':
5446
+        case 'id':
5447
+        case 'anchor':
5448
+            if (preg_match(',^\d,', $texte)) {
5449
+                $texte = substr($type, 0, 1) . $texte;
5450
+            }
5451
+    }
5452 5452
 
5453
-	if (strlen($texte) > $longueur_maxi) {
5454
-		$texte = substr($texte, 0, $longueur_maxi);
5455
-	}
5453
+    if (strlen($texte) > $longueur_maxi) {
5454
+        $texte = substr($texte, 0, $longueur_maxi);
5455
+    }
5456 5456
 
5457
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5458
-		if (preg_match(',^\d,', $texte)) {
5459
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5460
-		}
5461
-		$texte .= $separateur . md5($original);
5462
-		$texte = substr($texte, 0, $longueur_mini);
5463
-	}
5457
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5458
+        if (preg_match(',^\d,', $texte)) {
5459
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5460
+        }
5461
+        $texte .= $separateur . md5($original);
5462
+        $texte = substr($texte, 0, $longueur_mini);
5463
+    }
5464 5464
 
5465
-	return $texte;
5465
+    return $texte;
5466 5466
 }
5467 5467
 
5468 5468
 
@@ -5483,11 +5483,11 @@  discard block
 block discarded – undo
5483 5483
  * @exemple `<:info_maximum|label_nettoyer:>`
5484 5484
  */
5485 5485
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5486
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5487
-	if ($ucfirst) {
5488
-		$label = spip_ucfirst($label);
5489
-	}
5490
-	return $label;
5486
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5487
+    if ($ucfirst) {
5488
+        $label = spip_ucfirst($label);
5489
+    }
5490
+    return $label;
5491 5491
 }
5492 5492
 
5493 5493
 /**
@@ -5500,8 +5500,8 @@  discard block
 block discarded – undo
5500 5500
  * @exemple `<:info_maximum|label_ponctuer:>`
5501 5501
  */
5502 5502
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5503
-	$label = label_nettoyer($text, $ucfirst);
5504
-	return _T('label_ponctuer', ['label' => $label]);
5503
+    $label = label_nettoyer($text, $ucfirst);
5504
+    return _T('label_ponctuer', ['label' => $label]);
5505 5505
 }
5506 5506
 
5507 5507
 
@@ -5514,19 +5514,19 @@  discard block
 block discarded – undo
5514 5514
  * @return array
5515 5515
  */
5516 5516
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5517
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5518
-		return [];
5519
-	}
5517
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5518
+        return [];
5519
+    }
5520 5520
 
5521
-	// compatibilite signature inversee
5522
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5523
-		[$objet, $id_objet] = [$id_objet, $objet];
5524
-	}
5521
+    // compatibilite signature inversee
5522
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5523
+        [$objet, $id_objet] = [$id_objet, $objet];
5524
+    }
5525 5525
 
5526
-	if (!function_exists($fonction)) {
5527
-		include_spip('base/objets');
5528
-	}
5529
-	return $fonction($objet, $id_objet);
5526
+    if (!function_exists($fonction)) {
5527
+        include_spip('base/objets');
5528
+    }
5529
+    return $fonction($objet, $id_objet);
5530 5530
 }
5531 5531
 
5532 5532
 
@@ -5541,7 +5541,7 @@  discard block
 block discarded – undo
5541 5541
  * @return array
5542 5542
  */
5543 5543
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5544
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5544
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5545 5545
 }
5546 5546
 
5547 5547
 /**
@@ -5555,7 +5555,7 @@  discard block
 block discarded – undo
5555 5555
  * @return array
5556 5556
  */
5557 5557
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5558
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5558
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5559 5559
 }
5560 5560
 
5561 5561
 /**
@@ -5569,7 +5569,7 @@  discard block
 block discarded – undo
5569 5569
  * @return array
5570 5570
  */
5571 5571
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5572
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5572
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5573 5573
 }
5574 5574
 
5575 5575
 /**
@@ -5583,5 +5583,5 @@  discard block
 block discarded – undo
5583 5583
  * @return array
5584 5584
  */
5585 5585
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5586
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5586
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5587 5587
 }
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 1 patch
Indentation   +317 added lines, -317 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
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,198 +35,198 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
57 57
 // Recherche des auteurs et mots-cles associes
58 58
 // en ne regardant que le titre ou le nom
59 59
 function liste_des_jointures() {
60
-	static $liste = null;
61
-	if (is_null($liste)) {
62
-		$liste = [];
63
-		// recuperer les tables_objets_sql declarees
64
-		include_spip('base/objets');
65
-		$tables_objets = lister_tables_objets_sql();
66
-		foreach ($tables_objets as $t => $infos) {
67
-			if ($infos['rechercher_jointures']) {
68
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
69
-			}
70
-		}
71
-		// puis passer dans le pipeline
72
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
73
-	}
74
-
75
-	return $liste;
60
+    static $liste = null;
61
+    if (is_null($liste)) {
62
+        $liste = [];
63
+        // recuperer les tables_objets_sql declarees
64
+        include_spip('base/objets');
65
+        $tables_objets = lister_tables_objets_sql();
66
+        foreach ($tables_objets as $t => $infos) {
67
+            if ($infos['rechercher_jointures']) {
68
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
69
+            }
70
+        }
71
+        // puis passer dans le pipeline
72
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
73
+    }
74
+
75
+    return $liste;
76 76
 }
77 77
 
78 78
 function expression_recherche($recherche, $options) {
79
-	// ne calculer qu'une seule fois l'expression par hit
80
-	// (meme si utilisee dans plusieurs boucles)
81
-	static $expression = [];
82
-	$key = serialize([$recherche, $options['preg_flags']]);
83
-	if (isset($expression[$key])) {
84
-		return $expression[$key];
85
-	}
86
-
87
-	$u = $GLOBALS['meta']['pcre_u'];
88
-	if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
-		$options['preg_flags'] .= $u;
90
-	}
91
-	include_spip('inc/charsets');
92
-	$recherche = trim($recherche);
93
-
94
-	// retirer les + de +truc et les * de truc*
95
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
-
98
-	$is_preg = false;
99
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
-		// c'est une preg
101
-		$recherche_trans = translitteration($recherche);
102
-		$preg = $recherche_trans . $options['preg_flags'];
103
-		$is_preg = true;
104
-	} else {
105
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
-		// 'une', 'des' ...)
108
-
109
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
-
112
-		// les expressions entre " " sont un mot a chercher tel quel
113
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
114
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
-			foreach ($matches as $match) {
116
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
117
-				$word = trim($word, '"');
118
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
119
-			}
120
-		}
121
-
122
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
-			$is_preg = true;
124
-
125
-			$recherche_inter = '|';
126
-			$recherche_mots = explode(' ', $recherche_mod);
127
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
-			$petits_mots = true;
129
-			foreach ($recherche_mots as $mot) {
130
-				if (strlen($mot) >= $min_long) {
131
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
-					$recherche_inter .= preg_quote($mot) . ' ';
133
-					$petits_mots = false;
134
-				}
135
-			}
136
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
-
138
-			// mais on cherche quand même l'expression complète, même si elle
139
-			// comporte des mots de moins de quatre lettres
140
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
-			if (!$recherche or $petits_mots) {
142
-				$recherche = preg_quote($recherche_org);
143
-			}
144
-			$recherche_trans = translitteration($recherche);
145
-		}
146
-
147
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
-	}
149
-
150
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
-	// ou si l'expression reguliere est invalide
152
-	if (
153
-		!$is_preg
154
-		or (@preg_match($preg, '') === false)
155
-	) {
156
-		$methode = 'LIKE';
157
-		$u = $GLOBALS['meta']['pcre_u'];
158
-
159
-		// echapper les % et _
160
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
-
162
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
163
-		$recherche = preg_quote($recherche, '/');
164
-		$recherche_trans = translitteration($recherche);
165
-		$recherche_mod = $recherche_trans;
166
-
167
-		// les expressions entre " " sont un mot a chercher tel quel
168
-		// -> on remplace les espaces par un _ et on enleve les guillemets
169
-		// corriger le like dans le $q
170
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
-			foreach ($matches as $match) {
172
-				$word = preg_replace(',\s+,Uims', '_', $match);
173
-				$word = trim($word, '"');
174
-				$q = str_replace($match, $word, $q);
175
-			}
176
-		}
177
-		// corriger la regexp
178
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
-			foreach ($matches as $match) {
180
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
181
-				$word = trim($word, '"');
182
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
183
-			}
184
-		}
185
-		$q = sql_quote(
186
-			'%'
187
-			. preg_replace(',\s+,' . $u, '%', $q)
188
-			. '%'
189
-		);
190
-
191
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
-	} else {
193
-		$methode = 'REGEXP';
194
-		$q = sql_quote(trim($recherche, '/'));
195
-	}
196
-
197
-	// tous les caracteres transliterables de $q sont remplaces par un joker
198
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
-	$q_t = $q;
200
-	for ($i = 0; $i < spip_strlen($q); $i++) {
201
-		$char = spip_substr($q, $i, 1);
202
-		if (
203
-			!is_ascii($char)
204
-			and $char_t = translitteration($char)
205
-			and $char_t !== $char
206
-		) {
207
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
-			// mais c'est un pis aller cf #4354
209
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
-		}
211
-	}
212
-
213
-	$q = $q_t;
214
-
215
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
-	// les plus frequents qui peuvent etre accentues
217
-	// (oui c'est tres dicustable...)
218
-	if (
219
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
-	) {
222
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
-		// si il reste au moins un char significatif...
224
-		if (preg_match(",[^'%_.],", $q_t)) {
225
-			$q = $q_t;
226
-		}
227
-	}
228
-
229
-	return $expression[$key] = [$methode, $q, $preg];
79
+    // ne calculer qu'une seule fois l'expression par hit
80
+    // (meme si utilisee dans plusieurs boucles)
81
+    static $expression = [];
82
+    $key = serialize([$recherche, $options['preg_flags']]);
83
+    if (isset($expression[$key])) {
84
+        return $expression[$key];
85
+    }
86
+
87
+    $u = $GLOBALS['meta']['pcre_u'];
88
+    if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
+        $options['preg_flags'] .= $u;
90
+    }
91
+    include_spip('inc/charsets');
92
+    $recherche = trim($recherche);
93
+
94
+    // retirer les + de +truc et les * de truc*
95
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
+
98
+    $is_preg = false;
99
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
+        // c'est une preg
101
+        $recherche_trans = translitteration($recherche);
102
+        $preg = $recherche_trans . $options['preg_flags'];
103
+        $is_preg = true;
104
+    } else {
105
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
+        // 'une', 'des' ...)
108
+
109
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
+
112
+        // les expressions entre " " sont un mot a chercher tel quel
113
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
114
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
+            foreach ($matches as $match) {
116
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
117
+                $word = trim($word, '"');
118
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
119
+            }
120
+        }
121
+
122
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
+            $is_preg = true;
124
+
125
+            $recherche_inter = '|';
126
+            $recherche_mots = explode(' ', $recherche_mod);
127
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
+            $petits_mots = true;
129
+            foreach ($recherche_mots as $mot) {
130
+                if (strlen($mot) >= $min_long) {
131
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
+                    $recherche_inter .= preg_quote($mot) . ' ';
133
+                    $petits_mots = false;
134
+                }
135
+            }
136
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
+
138
+            // mais on cherche quand même l'expression complète, même si elle
139
+            // comporte des mots de moins de quatre lettres
140
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
+            if (!$recherche or $petits_mots) {
142
+                $recherche = preg_quote($recherche_org);
143
+            }
144
+            $recherche_trans = translitteration($recherche);
145
+        }
146
+
147
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
+    }
149
+
150
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
+    // ou si l'expression reguliere est invalide
152
+    if (
153
+        !$is_preg
154
+        or (@preg_match($preg, '') === false)
155
+    ) {
156
+        $methode = 'LIKE';
157
+        $u = $GLOBALS['meta']['pcre_u'];
158
+
159
+        // echapper les % et _
160
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
+
162
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
163
+        $recherche = preg_quote($recherche, '/');
164
+        $recherche_trans = translitteration($recherche);
165
+        $recherche_mod = $recherche_trans;
166
+
167
+        // les expressions entre " " sont un mot a chercher tel quel
168
+        // -> on remplace les espaces par un _ et on enleve les guillemets
169
+        // corriger le like dans le $q
170
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
+            foreach ($matches as $match) {
172
+                $word = preg_replace(',\s+,Uims', '_', $match);
173
+                $word = trim($word, '"');
174
+                $q = str_replace($match, $word, $q);
175
+            }
176
+        }
177
+        // corriger la regexp
178
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
+            foreach ($matches as $match) {
180
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
181
+                $word = trim($word, '"');
182
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
183
+            }
184
+        }
185
+        $q = sql_quote(
186
+            '%'
187
+            . preg_replace(',\s+,' . $u, '%', $q)
188
+            . '%'
189
+        );
190
+
191
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
+    } else {
193
+        $methode = 'REGEXP';
194
+        $q = sql_quote(trim($recherche, '/'));
195
+    }
196
+
197
+    // tous les caracteres transliterables de $q sont remplaces par un joker
198
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
+    $q_t = $q;
200
+    for ($i = 0; $i < spip_strlen($q); $i++) {
201
+        $char = spip_substr($q, $i, 1);
202
+        if (
203
+            !is_ascii($char)
204
+            and $char_t = translitteration($char)
205
+            and $char_t !== $char
206
+        ) {
207
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
+            // mais c'est un pis aller cf #4354
209
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
+        }
211
+    }
212
+
213
+    $q = $q_t;
214
+
215
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
+    // les plus frequents qui peuvent etre accentues
217
+    // (oui c'est tres dicustable...)
218
+    if (
219
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
+    ) {
222
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
+        // si il reste au moins un char significatif...
224
+        if (preg_match(",[^'%_.],", $q_t)) {
225
+            $q = $q_t;
226
+        }
227
+    }
228
+
229
+    return $expression[$key] = [$methode, $q, $preg];
230 230
 }
231 231
 
232 232
 
@@ -253,142 +253,142 @@  discard block
 block discarded – undo
253 253
  * @return array
254 254
  */
255 255
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
256
-	include_spip('base/abstract_sql');
257
-
258
-	if (!is_array($tables)) {
259
-		$liste = liste_des_champs();
260
-
261
-		if (
262
-			is_string($tables)
263
-			and $tables != ''
264
-		) {
265
-			$toutes = [];
266
-			foreach (explode(',', $tables) as $t) {
267
-				$t = trim($t);
268
-				if (isset($liste[$t])) {
269
-					$toutes[$t] = $liste[$t];
270
-				}
271
-			}
272
-			$tables = $toutes;
273
-			unset($toutes);
274
-		} else {
275
-			$tables = $liste;
276
-		}
277
-	}
278
-
279
-	if (!strlen($recherche) or !count($tables)) {
280
-		return [];
281
-	}
282
-
283
-	include_spip('inc/autoriser');
284
-
285
-	// options par defaut
286
-	$options = array_merge(
287
-		[
288
-		'preg_flags' => 'UimsS',
289
-		'toutvoir' => false,
290
-		'champs' => false,
291
-		'score' => false,
292
-		'matches' => false,
293
-		'jointures' => false,
294
-		'serveur' => $serveur
295
-		],
296
-		$options
297
-	);
298
-
299
-	$results = [];
300
-
301
-	// Utiliser l'iterateur (DATA:recherche)
302
-	// pour recuperer les couples (id_objet, score)
303
-	// Le resultat est au format {
304
-	//      id1 = { 'score' => x, attrs => { } },
305
-	//      id2 = { 'score' => x, attrs => { } },
306
-	// }
307
-
308
-	include_spip('inc/recherche_to_array');
309
-
310
-	foreach ($tables as $table => $champs) {
311
-		# lock via memoization, si dispo
312
-		if (function_exists('cache_lock')) {
313
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
-		}
315
-
316
-		spip_timer('rech');
317
-
318
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
319
-		$to_array = charger_fonction('recherche_to_array', 'inc');
320
-		$results[$table] = $to_array(
321
-			$recherche,
322
-			array_merge($options, ['table' => $table, 'champs' => $champs])
323
-		);
324
-		##var_dump($results[$table]);
325
-
326
-
327
-		spip_log(
328
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
-			'recherche'
330
-		);
331
-
332
-		if (isset($lock)) {
333
-			cache_unlock($lock);
334
-		}
335
-	}
336
-
337
-	return $results;
256
+    include_spip('base/abstract_sql');
257
+
258
+    if (!is_array($tables)) {
259
+        $liste = liste_des_champs();
260
+
261
+        if (
262
+            is_string($tables)
263
+            and $tables != ''
264
+        ) {
265
+            $toutes = [];
266
+            foreach (explode(',', $tables) as $t) {
267
+                $t = trim($t);
268
+                if (isset($liste[$t])) {
269
+                    $toutes[$t] = $liste[$t];
270
+                }
271
+            }
272
+            $tables = $toutes;
273
+            unset($toutes);
274
+        } else {
275
+            $tables = $liste;
276
+        }
277
+    }
278
+
279
+    if (!strlen($recherche) or !count($tables)) {
280
+        return [];
281
+    }
282
+
283
+    include_spip('inc/autoriser');
284
+
285
+    // options par defaut
286
+    $options = array_merge(
287
+        [
288
+        'preg_flags' => 'UimsS',
289
+        'toutvoir' => false,
290
+        'champs' => false,
291
+        'score' => false,
292
+        'matches' => false,
293
+        'jointures' => false,
294
+        'serveur' => $serveur
295
+        ],
296
+        $options
297
+    );
298
+
299
+    $results = [];
300
+
301
+    // Utiliser l'iterateur (DATA:recherche)
302
+    // pour recuperer les couples (id_objet, score)
303
+    // Le resultat est au format {
304
+    //      id1 = { 'score' => x, attrs => { } },
305
+    //      id2 = { 'score' => x, attrs => { } },
306
+    // }
307
+
308
+    include_spip('inc/recherche_to_array');
309
+
310
+    foreach ($tables as $table => $champs) {
311
+        # lock via memoization, si dispo
312
+        if (function_exists('cache_lock')) {
313
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
+        }
315
+
316
+        spip_timer('rech');
317
+
318
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
319
+        $to_array = charger_fonction('recherche_to_array', 'inc');
320
+        $results[$table] = $to_array(
321
+            $recherche,
322
+            array_merge($options, ['table' => $table, 'champs' => $champs])
323
+        );
324
+        ##var_dump($results[$table]);
325
+
326
+
327
+        spip_log(
328
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
+            'recherche'
330
+        );
331
+
332
+        if (isset($lock)) {
333
+            cache_unlock($lock);
334
+        }
335
+    }
336
+
337
+    return $results;
338 338
 }
339 339
 
340 340
 
341 341
 // Effectue une recherche sur toutes les tables de la base de donnees
342 342
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
343
-	include_spip('inc/modifier');
344
-
345
-	// options par defaut
346
-	$options = array_merge(
347
-		[
348
-		'preg_flags' => 'UimsS',
349
-		'toutmodifier' => false
350
-		],
351
-		$options
352
-	);
353
-	$options['champs'] = true;
354
-
355
-
356
-	if (!is_array($tables)) {
357
-		$tables = liste_des_champs();
358
-	}
359
-
360
-	$results = recherche_en_base($recherche, $tables, $options);
361
-
362
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
-
364
-	foreach ($results as $table => $r) {
365
-		$_id_table = id_table_objet($table);
366
-		foreach ($r as $id => $x) {
367
-			if (
368
-				$options['toutmodifier']
369
-				or autoriser('modifier', $table, $id)
370
-			) {
371
-				$modifs = [];
372
-				foreach ($x['champs'] as $key => $val) {
373
-					if ($key == $_id_table) {
374
-						continue;
375
-					}
376
-					$repl = preg_replace($preg, $remplace, $val);
377
-					if ($repl <> $val) {
378
-						$modifs[$key] = $repl;
379
-					}
380
-				}
381
-				if ($modifs) {
382
-					objet_modifier_champs(
383
-						$table,
384
-						$id,
385
-						[
386
-							'champs' => array_keys($modifs),
387
-						],
388
-						$modifs
389
-					);
390
-				}
391
-			}
392
-		}
393
-	}
343
+    include_spip('inc/modifier');
344
+
345
+    // options par defaut
346
+    $options = array_merge(
347
+        [
348
+        'preg_flags' => 'UimsS',
349
+        'toutmodifier' => false
350
+        ],
351
+        $options
352
+    );
353
+    $options['champs'] = true;
354
+
355
+
356
+    if (!is_array($tables)) {
357
+        $tables = liste_des_champs();
358
+    }
359
+
360
+    $results = recherche_en_base($recherche, $tables, $options);
361
+
362
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
+
364
+    foreach ($results as $table => $r) {
365
+        $_id_table = id_table_objet($table);
366
+        foreach ($r as $id => $x) {
367
+            if (
368
+                $options['toutmodifier']
369
+                or autoriser('modifier', $table, $id)
370
+            ) {
371
+                $modifs = [];
372
+                foreach ($x['champs'] as $key => $val) {
373
+                    if ($key == $_id_table) {
374
+                        continue;
375
+                    }
376
+                    $repl = preg_replace($preg, $remplace, $val);
377
+                    if ($repl <> $val) {
378
+                        $modifs[$key] = $repl;
379
+                    }
380
+                }
381
+                if ($modifs) {
382
+                    objet_modifier_champs(
383
+                        $table,
384
+                        $id,
385
+                        [
386
+                            'champs' => array_keys($modifs),
387
+                        ],
388
+                        $modifs
389
+                    );
390
+                }
391
+            }
392
+        }
393
+    }
394 394
 }
Please login to merge, or discard this patch.
ecrire/inc/securiser_action.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Actions
17 17
  **/
18 18
 
19
- use Spip\Chiffrer\SpipCles;
19
+    use Spip\Chiffrer\SpipCles;
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -52,19 +52,19 @@  discard block
 block discarded – undo
52 52
  * @return array|string
53 53
  */
54 54
 function inc_securiser_action_dist($action = '', $arg = '', $redirect = '', $mode = false, $att = '', $public = false) {
55
-	if ($action) {
56
-		return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
57
-	} else {
58
-		$arg = _request('arg');
59
-		$hash = _request('hash');
60
-		$action = _request('action') ?: _request('formulaire_action');
61
-		if ($a = verifier_action_auteur("$action-$arg", $hash)) {
62
-			return $arg;
63
-		}
64
-		include_spip('inc/minipres');
65
-		echo minipres();
66
-		exit;
67
-	}
55
+    if ($action) {
56
+        return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
57
+    } else {
58
+        $arg = _request('arg');
59
+        $hash = _request('hash');
60
+        $action = _request('action') ?: _request('formulaire_action');
61
+        if ($a = verifier_action_auteur("$action-$arg", $hash)) {
62
+            return $arg;
63
+        }
64
+        include_spip('inc/minipres');
65
+        echo minipres();
66
+        exit;
67
+    }
68 68
 }
69 69
 
70 70
 /**
@@ -83,29 +83,29 @@  discard block
 block discarded – undo
83 83
  */
84 84
 function demander_confirmation_avant_action($titre, $titre_bouton, $url_action = null) {
85 85
 
86
-	if (!$url_action) {
87
-		$url_action = self();
88
-		$action = _request('action');
89
-		$url_action = parametre_url($url_action, 'action', $action, '&');
90
-	}
91
-	else {
92
-		$action = parametre_url($url_action, 'action');
93
-	}
94
-
95
-	$arg = parametre_url($url_action, 'arg');
96
-	$confirm = md5("$action:$arg:" . realpath(__FILE__));
97
-	if (_request('confirm_action') === $confirm) {
98
-		return true;
99
-	}
100
-
101
-	$url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&');
102
-	include_spip('inc/filtres');
103
-	$bouton_action = bouton_action($titre_bouton, $url_confirm);
104
-	$corps = "<div style='text-align:center;'>$bouton_action</div>";
105
-
106
-	include_spip('inc/minipres');
107
-	echo minipres($titre, $corps);
108
-	exit;
86
+    if (!$url_action) {
87
+        $url_action = self();
88
+        $action = _request('action');
89
+        $url_action = parametre_url($url_action, 'action', $action, '&');
90
+    }
91
+    else {
92
+        $action = parametre_url($url_action, 'action');
93
+    }
94
+
95
+    $arg = parametre_url($url_action, 'arg');
96
+    $confirm = md5("$action:$arg:" . realpath(__FILE__));
97
+    if (_request('confirm_action') === $confirm) {
98
+        return true;
99
+    }
100
+
101
+    $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&');
102
+    include_spip('inc/filtres');
103
+    $bouton_action = bouton_action($titre_bouton, $url_confirm);
104
+    $corps = "<div style='text-align:center;'>$bouton_action</div>";
105
+
106
+    include_spip('inc/minipres');
107
+    echo minipres($titre, $corps);
108
+    exit;
109 109
 }
110 110
 
111 111
 /**
@@ -136,34 +136,34 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function securiser_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) {
138 138
 
139
-	// mode URL ou array
140
-	if (!is_string($mode)) {
141
-		$hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
142
-
143
-		$r = rawurlencode($redirect);
144
-		if ($mode === -1) {
145
-			return ['action' => $action, 'arg' => $arg, 'hash' => $hash];
146
-		} else {
147
-			return generer_url_action(
148
-				$action,
149
-				'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
150
-				$mode,
151
-				$public
152
-			);
153
-		}
154
-	}
155
-
156
-	// mode formulaire
157
-	$hash = calculer_action_auteur("$action-$arg");
158
-	$att .= " style='margin: 0px; border: 0px'";
159
-	if ($redirect) {
160
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
161
-	}
162
-	$mode .= $redirect . "
139
+    // mode URL ou array
140
+    if (!is_string($mode)) {
141
+        $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
142
+
143
+        $r = rawurlencode($redirect);
144
+        if ($mode === -1) {
145
+            return ['action' => $action, 'arg' => $arg, 'hash' => $hash];
146
+        } else {
147
+            return generer_url_action(
148
+                $action,
149
+                'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
150
+                $mode,
151
+                $public
152
+            );
153
+        }
154
+    }
155
+
156
+    // mode formulaire
157
+    $hash = calculer_action_auteur("$action-$arg");
158
+    $att .= " style='margin: 0px; border: 0px'";
159
+    if ($redirect) {
160
+        $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
161
+    }
162
+    $mode .= $redirect . "
163 163
 <input name='hash' type='hidden' value='$hash' />
164 164
 <input name='arg' type='hidden' value='$arg' />";
165 165
 
166
-	return generer_form_action($action, $mode, $att, $public);
166
+    return generer_form_action($action, $mode, $att, $public);
167 167
 }
168 168
 
169 169
 /**
@@ -173,48 +173,48 @@  discard block
 block discarded – undo
173 173
  * @return array
174 174
  */
175 175
 function caracteriser_auteur($id_auteur = null) {
176
-	static $caracterisation = [];
177
-
178
-	if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
179
-		// si l'auteur courant n'est pas connu alors qu'il peut demander une action
180
-		// c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
181
-		// S'il n'avait pas le droit de realiser cette action, le hash sera faux.
182
-		if (
183
-			isset($_COOKIE['spip_session'])
184
-			and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
185
-		) {
186
-			return [$r[1], ''];
187
-			// Necessaire aux forums anonymes.
188
-			// Pour le reste, ca echouera.
189
-		} else {
190
-			return ['0', ''];
191
-		}
192
-	}
193
-	// Eviter l'acces SQL si le pass est connu de PHP
194
-	if (is_null($id_auteur)) {
195
-		$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
196
-		if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
197
-			return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']];
198
-		}
199
-	}
200
-
201
-	if (isset($caracterisation[$id_auteur])) {
202
-		return $caracterisation[$id_auteur];
203
-	}
204
-
205
-	if ($id_auteur) {
206
-		include_spip('base/abstract_sql');
207
-		$t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur");
208
-		if ($t) {
209
-			return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']];
210
-		}
211
-		include_spip('inc/minipres');
212
-		echo minipres();
213
-		exit;
214
-	} // Visiteur anonyme, pour ls forums par exemple
215
-	else {
216
-		return ['0', ''];
217
-	}
176
+    static $caracterisation = [];
177
+
178
+    if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
179
+        // si l'auteur courant n'est pas connu alors qu'il peut demander une action
180
+        // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
181
+        // S'il n'avait pas le droit de realiser cette action, le hash sera faux.
182
+        if (
183
+            isset($_COOKIE['spip_session'])
184
+            and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
185
+        ) {
186
+            return [$r[1], ''];
187
+            // Necessaire aux forums anonymes.
188
+            // Pour le reste, ca echouera.
189
+        } else {
190
+            return ['0', ''];
191
+        }
192
+    }
193
+    // Eviter l'acces SQL si le pass est connu de PHP
194
+    if (is_null($id_auteur)) {
195
+        $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
196
+        if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
197
+            return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']];
198
+        }
199
+    }
200
+
201
+    if (isset($caracterisation[$id_auteur])) {
202
+        return $caracterisation[$id_auteur];
203
+    }
204
+
205
+    if ($id_auteur) {
206
+        include_spip('base/abstract_sql');
207
+        $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur");
208
+        if ($t) {
209
+            return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']];
210
+        }
211
+        include_spip('inc/minipres');
212
+        echo minipres();
213
+        exit;
214
+    } // Visiteur anonyme, pour ls forums par exemple
215
+    else {
216
+        return ['0', ''];
217
+    }
218 218
 }
219 219
 
220 220
 /**
@@ -229,30 +229,30 @@  discard block
 block discarded – undo
229 229
  * @return string
230 230
  */
231 231
 function _action_auteur(string $action, int $id_auteur, ?string $pass, string $alea): string {
232
-	static $sha = [];
233
-	$pass = $pass ?? '';
234
-	$entry = "$action:$id_auteur:$pass:$alea";
235
-	if (!isset($sha[$entry])) {
236
-		$sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea));
237
-	}
238
-
239
-	return $sha[$entry];
232
+    static $sha = [];
233
+    $pass = $pass ?? '';
234
+    $entry = "$action:$id_auteur:$pass:$alea";
235
+    if (!isset($sha[$entry])) {
236
+        $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea));
237
+    }
238
+
239
+    return $sha[$entry];
240 240
 }
241 241
 
242 242
 function _action_get_alea(string $alea): string {
243
-	if (!isset($GLOBALS['meta'][$alea])) {
244
-		if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) {
245
-			include_spip('inc/acces');
246
-			charger_aleas();
247
-			if (empty($GLOBALS['meta'][$alea])) {
248
-				include_spip('inc/minipres');
249
-				echo minipres();
250
-				spip_log("$alea indisponible");
251
-				exit;
252
-			}
253
-		}
254
-	}
255
-	return $GLOBALS['meta'][$alea] ?? '';
243
+    if (!isset($GLOBALS['meta'][$alea])) {
244
+        if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) {
245
+            include_spip('inc/acces');
246
+            charger_aleas();
247
+            if (empty($GLOBALS['meta'][$alea])) {
248
+                include_spip('inc/minipres');
249
+                echo minipres();
250
+                spip_log("$alea indisponible");
251
+                exit;
252
+            }
253
+        }
254
+    }
255
+    return $GLOBALS['meta'][$alea] ?? '';
256 256
 }
257 257
 
258 258
 /**
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
  * @return string
264 264
  */
265 265
 function calculer_action_auteur($action, $id_auteur = null) {
266
-	[$id_auteur, $pass] = caracteriser_auteur($id_auteur);
266
+    [$id_auteur, $pass] = caracteriser_auteur($id_auteur);
267 267
 
268
-	return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
268
+    return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
269 269
 }
270 270
 
271 271
 
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
  * @return bool
279 279
  */
280 280
 function verifier_action_auteur($action, $hash) {
281
-	[$id_auteur, $pass] = caracteriser_auteur();
282
-	if (
283
-		hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'))
284
-		or hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien'))
285
-	) {
286
-		return true;
287
-	}
288
-
289
-	return false;
281
+    [$id_auteur, $pass] = caracteriser_auteur();
282
+    if (
283
+        hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'))
284
+        or hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien'))
285
+    ) {
286
+        return true;
287
+    }
288
+
289
+    return false;
290 290
 }
291 291
 
292 292
 //
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
  * @return string
302 302
  */
303 303
 function secret_du_site() {
304
-	return SpipCles::secret_du_site();
304
+    return SpipCles::secret_du_site();
305 305
 }
306 306
 
307 307
 /**
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
  * @return string
312 312
  */
313 313
 function calculer_cle_action($action) {
314
-	return hash_hmac('sha256', $action, secret_du_site());
314
+    return hash_hmac('sha256', $action, secret_du_site());
315 315
 }
316 316
 
317 317
 /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
  * @return bool
323 323
  */
324 324
 function verifier_cle_action($action, $cle) {
325
-	return hash_equals($cle, calculer_cle_action($action));
325
+    return hash_equals($cle, calculer_cle_action($action));
326 326
 }
327 327
 
328 328
 
@@ -339,19 +339,19 @@  discard block
 block discarded – undo
339 339
  * @return string Token, de la forme "{id}*{hash}"
340 340
  */
341 341
 function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') {
342
-	if (is_null($id_auteur)) {
343
-		if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
344
-			$id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
345
-		}
346
-	}
347
-	if (!$id_auteur = intval($id_auteur)) {
348
-		return '';
349
-	}
350
-	// On nettoie l’URL de tous les var_.
351
-	$url = nettoyer_uri_var($url);
352
-
353
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea);
354
-	return "$id_auteur-$token";
342
+    if (is_null($id_auteur)) {
343
+        if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
344
+            $id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
345
+        }
346
+    }
347
+    if (!$id_auteur = intval($id_auteur)) {
348
+        return '';
349
+    }
350
+    // On nettoie l’URL de tous les var_.
351
+    $url = nettoyer_uri_var($url);
352
+
353
+    $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea);
354
+    return "$id_auteur-$token";
355 355
 }
356 356
 
357 357
 
@@ -369,31 +369,31 @@  discard block
 block discarded – undo
369 369
  *     + Tableau (id auteur, type d’objet, id_objet) sinon.
370 370
  */
371 371
 function verifier_token_previsu($token) {
372
-	// retrouver auteur / hash
373
-	$e = explode('-', $token, 2);
374
-	if (count($e) == 2 and is_numeric(reset($e))) {
375
-		$id_auteur = intval(reset($e));
376
-	} else {
377
-		return false;
378
-	}
379
-
380
-	// calculer le type et id de l’url actuelle
381
-	include_spip('inc/urls');
382
-	include_spip('inc/filtres_mini');
383
-	$url = url_absolue(self());
384
-
385
-	// verifier le token
386
-	$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
387
-	if (!$_token or !hash_equals($token, $_token)) {
388
-		$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
389
-		if (!$_token or !hash_equals($token, $_token)) {
390
-			return false;
391
-		}
392
-	}
393
-
394
-	return [
395
-		'id_auteur' => $id_auteur,
396
-	];
372
+    // retrouver auteur / hash
373
+    $e = explode('-', $token, 2);
374
+    if (count($e) == 2 and is_numeric(reset($e))) {
375
+        $id_auteur = intval(reset($e));
376
+    } else {
377
+        return false;
378
+    }
379
+
380
+    // calculer le type et id de l’url actuelle
381
+    include_spip('inc/urls');
382
+    include_spip('inc/filtres_mini');
383
+    $url = url_absolue(self());
384
+
385
+    // verifier le token
386
+    $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
387
+    if (!$_token or !hash_equals($token, $_token)) {
388
+        $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
389
+        if (!$_token or !hash_equals($token, $_token)) {
390
+            return false;
391
+        }
392
+    }
393
+
394
+    return [
395
+        'id_auteur' => $id_auteur,
396
+    ];
397 397
 }
398 398
 
399 399
 /**
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
  * @return bool|array
403 403
  */
404 404
 function decrire_token_previsu() {
405
-	static $desc = null;
406
-	if (is_null($desc)) {
407
-		if ($token = _request('var_previewtoken')) {
408
-			$desc = verifier_token_previsu($token);
409
-		} else {
410
-			$desc = false;
411
-		}
412
-	}
413
-	return $desc;
405
+    static $desc = null;
406
+    if (is_null($desc)) {
407
+        if ($token = _request('var_previewtoken')) {
408
+            $desc = verifier_token_previsu($token);
409
+        } else {
410
+            $desc = false;
411
+        }
412
+    }
413
+    return $desc;
414 414
 }
Please login to merge, or discard this patch.