Completed
Push — master ( b32f18...cfbd44 )
by cam
04:53
created
ecrire/inc/filtres.php 2 patches
Doc Comments   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  *
70 70
  * @param string $fonc
71 71
  *     Nom du filtre
72
- * @param null $default
72
+ * @param string $default
73 73
  *     Nom du filtre appliqué par défaut si celui demandé n'est pas trouvé
74 74
  * @return string
75 75
  *     Fonction PHP correspondante du filtre demandé
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
  * @see appliquer_si_filtre() Proche : retourne le texte d'origine si le filtre est absent
142 142
  * @uses appliquer_filtre_sinon()
143 143
  *
144
- * @param mixed $arg
144
+ * @param string $arg
145 145
  *     Texte (le plus souvent) sur lequel appliquer le filtre
146 146
  * @param string $filtre
147 147
  *     Nom du filtre à appliquer
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  *   corriger toutes les `&xx;` en `&xx;`
795 795
  * @param bool $quote
796 796
  *   Échapper aussi les simples quotes en `'`
797
- * @return mixed|string
797
+ * @return string
798 798
  */
799 799
 function entites_html($texte, $tout = false, $quote = true) {
800 800
 	if (!is_string($texte) or !$texte
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
  *
1430 1430
  * @param mixed $texte
1431 1431
  *     Contenu de reference a tester
1432
- * @param mixed $sinon
1432
+ * @param string|null $sinon
1433 1433
  *     Contenu a retourner si le contenu de reference est vide
1434 1434
  * @return mixed
1435 1435
  *     Retourne $texte, sinon $sinon.
@@ -1611,7 +1611,7 @@  discard block
 block discarded – undo
1611 1611
  * @param string $letexte
1612 1612
  * @param string $lang
1613 1613
  *     Langue à retrouver (si vide, utilise la langue en cours).
1614
- * @param array $options Options {
1614
+ * @param boolean $options Options {
1615 1615
  * @type bool $echappe_span
1616 1616
  *         True pour échapper les balises span (false par défaut)
1617 1617
  * @type string $lang_defaut
@@ -1701,7 +1701,7 @@  discard block
 block discarded – undo
1701 1701
  * @param string $letexte
1702 1702
  * @param string $lang
1703 1703
  *     Langue à retrouver (si vide, utilise la langue en cours).
1704
- * @param array $options Options {
1704
+ * @param boolean $options Options {
1705 1705
  * @type bool $echappe_span
1706 1706
  *         True pour échapper les balises span (false par défaut)
1707 1707
  * @type string $lang_defaut
@@ -2175,6 +2175,9 @@  discard block
 block discarded – undo
2175 2175
 // Quelques fonctions de calcul arithmetique
2176 2176
 //
2177 2177
 function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
2178
+/**
2179
+ * @param string $f
2180
+ */
2178 2181
 function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
2179 2182
 
2180 2183
 /**
@@ -2318,7 +2321,7 @@  discard block
 block discarded – undo
2318 2321
  * @param string|array $adresses
2319 2322
  *      Adresse ou liste d'adresse
2320 2323
  *      si on fournit un tableau, il est filtre et la fonction renvoie avec uniquement les adresses email valides (donc possiblement vide)
2321
- * @return bool|string|array
2324
+ * @return string|null
2322 2325
  *      - false si une des adresses n'est pas conforme,
2323 2326
  *      - la normalisation de la dernière adresse donnée sinon
2324 2327
  *      - renvoie un tableau si l'entree est un tableau
@@ -2642,7 +2645,7 @@  discard block
 block discarded – undo
2642 2645
  * @param int $a
2643 2646
  * @param int $b
2644 2647
  * @param int $c
2645
- * @return int
2648
+ * @return double
2646 2649
  *      Retourne `$a*$b/$c`
2647 2650
  **/
2648 2651
 function regledetrois($a, $b, $c) {
@@ -3490,6 +3493,10 @@  discard block
 block discarded – undo
3490 3493
 }
3491 3494
 
3492 3495
 
3496
+/**
3497
+ * @param string $alt_or_size
3498
+ * @param string|null $class_or_size
3499
+ */
3493 3500
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3494 3501
 	$args = [$alt_or_size, $class_or_size, $size];
3495 3502
 	while (is_null(end($args)) and count($args)) {
@@ -3518,6 +3525,10 @@  discard block
 block discarded – undo
3518 3525
 	return $args;
3519 3526
 }
3520 3527
 
3528
+/**
3529
+ * @param string $img
3530
+ * @param string $size
3531
+ */
3521 3532
 function helper_filtre_balise_img_svg_size($img, $size) {
3522 3533
 	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3523 3534
 	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
@@ -4811,7 +4822,7 @@  discard block
 block discarded – undo
4811 4822
  *     Nombre d'éléments
4812 4823
  * @param string $objet
4813 4824
  *     Objet
4814
- * @return mixed|string
4825
+ * @return string
4815 4826
  *     Texte traduit du comptage, tel que '3 articles'
4816 4827
  */
4817 4828
 function objet_afficher_nb($nb, $objet) {
Please login to merge, or discard this patch.
Indentation   +2221 added lines, -2221 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
 /**
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-
96
-	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
-		// fonction ou name\space\fonction
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
-			return $f;
106
-		}
107
-	}
108
-
109
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+
96
+    include_fichiers_fonctions();
97
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
+        // fonction ou name\space\fonction
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
+            return $f;
106
+        }
107
+    }
108
+
109
+    return $default;
110 110
 }
111 111
 
112 112
 /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
  *     Chaîne vide sinon.
151 151
  **/
152 152
 function appliquer_filtre($arg, $filtre) {
153
-	$args = func_get_args();
154
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
153
+    $args = func_get_args();
154
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
155 155
 }
156 156
 
157 157
 /**
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
  *     Texte d'origine sinon
177 177
  **/
178 178
 function appliquer_si_filtre($arg, $filtre) {
179
-	$args = func_get_args();
180
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
179
+    $args = func_get_args();
180
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181 181
 }
182 182
 
183 183
 /**
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
  *     Version de SPIP
194 194
  **/
195 195
 function spip_version() {
196
-	$version = $GLOBALS['spip_version_affichee'];
197
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
-		$version .= " $vcs_version";
199
-	}
196
+    $version = $GLOBALS['spip_version_affichee'];
197
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
+        $version .= " $vcs_version";
199
+    }
200 200
 
201
-	return $version;
201
+    return $version;
202 202
 }
203 203
 
204 204
 /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
  *    - string|null si $raw = false
212 212
  */
213 213
 function version_vcs_courante($dir, $raw = false) {
214
-	$desc = decrire_version_git($dir);
215
-	if ($desc === null) {
216
-		$desc = decrire_version_svn($dir);
217
-	}
218
-	if ($desc === null or $raw) {
219
-		return $desc;
220
-	}
221
-	// affichage "GIT [master: abcdef]"
222
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
-	if ($desc['branch']) {
224
-		$commit = $desc['branch'] . ': ' . $commit;
225
-	}
226
-	return "{$desc['vcs']} [$commit]";
214
+    $desc = decrire_version_git($dir);
215
+    if ($desc === null) {
216
+        $desc = decrire_version_svn($dir);
217
+    }
218
+    if ($desc === null or $raw) {
219
+        return $desc;
220
+    }
221
+    // affichage "GIT [master: abcdef]"
222
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
+    if ($desc['branch']) {
224
+        $commit = $desc['branch'] . ': ' . $commit;
225
+    }
226
+    return "{$desc['vcs']} [$commit]";
227 227
 }
228 228
 
229 229
 /**
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
  *      array ['branch' => xx, 'commit' => yy] sinon.
236 236
  **/
237 237
 function decrire_version_git($dir) {
238
-	if (!$dir) {
239
-		$dir = '.';
240
-	}
238
+    if (!$dir) {
239
+        $dir = '.';
240
+    }
241 241
 
242
-	// version installee par GIT
243
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
-		$currentHead = trim(substr($c, 4));
245
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
-			return [
247
-				'vcs' => 'GIT',
248
-				'branch' => basename($currentHead),
249
-				'commit' => trim($hash),
250
-				'commit_short' => substr(trim($hash), 0, 8),
251
-			];
252
-		}
253
-	}
242
+    // version installee par GIT
243
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
+        $currentHead = trim(substr($c, 4));
245
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
+            return [
247
+                'vcs' => 'GIT',
248
+                'branch' => basename($currentHead),
249
+                'commit' => trim($hash),
250
+                'commit_short' => substr(trim($hash), 0, 8),
251
+            ];
252
+        }
253
+    }
254 254
 
255
-	return null;
255
+    return null;
256 256
 }
257 257
 
258 258
 
@@ -265,25 +265,25 @@  discard block
 block discarded – undo
265 265
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
266 266
  **/
267 267
 function decrire_version_svn($dir) {
268
-	if (!$dir) {
269
-		$dir = '.';
270
-	}
271
-	// version installee par SVN
272
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
-		$db = new SQLite3($dir . '/.svn/wc.db');
274
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
-		if ($result) {
276
-			$row = $result->fetchArray();
277
-			if ($row['changed_revision'] != "") {
278
-				return [
279
-					'vcs' => 'SVN',
280
-					'branch' => '',
281
-					'commit' => $row['changed_revision'],
282
-				];
283
-			}
284
-		}
285
-	}
286
-	return null;
268
+    if (!$dir) {
269
+        $dir = '.';
270
+    }
271
+    // version installee par SVN
272
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
+        $db = new SQLite3($dir . '/.svn/wc.db');
274
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
+        if ($result) {
276
+            $row = $result->fetchArray();
277
+            if ($row['changed_revision'] != "") {
278
+                return [
279
+                    'vcs' => 'SVN',
280
+                    'branch' => '',
281
+                    'commit' => $row['changed_revision'],
282
+                ];
283
+            }
284
+        }
285
+    }
286
+    return null;
287 287
 }
288 288
 
289 289
 /**
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
  *
302 302
  **/
303 303
 function version_svn_courante($dir) {
304
-	if ($desc = decrire_version_svn($dir)) {
305
-		return -$desc['commit'];
306
-	}
307
-	return 0;
304
+    if ($desc = decrire_version_svn($dir)) {
305
+        return -$desc['commit'];
306
+    }
307
+    return 0;
308 308
 }
309 309
 
310 310
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
  *     Code HTML retourné par le filtre
349 349
  **/
350 350
 function filtrer($filtre) {
351
-	$tous = func_get_args();
352
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
353
-		return image_filtrer($tous);
354
-	} elseif ($f = chercher_filtre($filtre)) {
355
-		array_shift($tous);
356
-		return call_user_func_array($f, $tous);
357
-	} else {
358
-		// le filtre n'existe pas, on provoque une erreur
359
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
360
-		erreur_squelette($msg);
361
-		return '';
362
-	}
351
+    $tous = func_get_args();
352
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
353
+        return image_filtrer($tous);
354
+    } elseif ($f = chercher_filtre($filtre)) {
355
+        array_shift($tous);
356
+        return call_user_func_array($f, $tous);
357
+    } else {
358
+        // le filtre n'existe pas, on provoque une erreur
359
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
360
+        erreur_squelette($msg);
361
+        return '';
362
+    }
363 363
 }
364 364
 
365 365
 /**
@@ -376,11 +376,11 @@  discard block
 block discarded – undo
376 376
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
377 377
  */
378 378
 function trouver_filtre_matrice($filtre) {
379
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
380
-		find_in_path($f, '', true);
381
-		$GLOBALS['spip_matrice'][$filtre] = true;
382
-	}
383
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
379
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
380
+        find_in_path($f, '', true);
381
+        $GLOBALS['spip_matrice'][$filtre] = true;
382
+    }
383
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
384 384
 }
385 385
 
386 386
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
  * @return mixed
409 409
  */
410 410
 function filtre_set(&$Pile, $val, $key, $continue = null) {
411
-	$Pile['vars'][$key] = $val;
412
-	return $continue ? $val : '';
411
+    $Pile['vars'][$key] = $val;
412
+    return $continue ? $val : '';
413 413
 }
414 414
 
415 415
 /**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
436 436
  */
437 437
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
438
-	$Pile[0][$key] = $val;
439
-	return $continue ? $val : '';
438
+    $Pile[0][$key] = $val;
439
+    return $continue ? $val : '';
440 440
 }
441 441
 
442 442
 /**
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
  * @return string
446 446
  */
447 447
 function filtre_sanitize_env(&$Pile, $keys) {
448
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
449
-	return '';
448
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
449
+    return '';
450 450
 }
451 451
 
452 452
 
@@ -469,18 +469,18 @@  discard block
 block discarded – undo
469 469
  * @return mixed Retourne la valeur (sans la modifier).
470 470
  */
471 471
 function filtre_debug($val, $key = null) {
472
-	$debug = (
473
-		is_null($key) ? '' : (var_export($key, true) . " = ")
474
-		) . var_export($val, true);
472
+    $debug = (
473
+        is_null($key) ? '' : (var_export($key, true) . " = ")
474
+        ) . var_export($val, true);
475 475
 
476
-	include_spip('inc/autoriser');
477
-	if (autoriser('webmestre')) {
478
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
479
-	}
476
+    include_spip('inc/autoriser');
477
+    if (autoriser('webmestre')) {
478
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
479
+    }
480 480
 
481
-	spip_log($debug, 'debug');
481
+    spip_log($debug, 'debug');
482 482
 
483
-	return $val;
483
+    return $val;
484 484
 }
485 485
 
486 486
 
@@ -508,82 +508,82 @@  discard block
 block discarded – undo
508 508
  *     Texte qui a reçu les filtres
509 509
  **/
510 510
 function image_filtrer($args) {
511
-	$filtre = array_shift($args); # enlever $filtre
512
-	$texte = array_shift($args);
513
-	if (!strlen($texte)) {
514
-		return;
515
-	}
516
-	find_in_path('filtres_images_mini.php', 'inc/', true);
517
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
518
-	// Cas du nom de fichier local
519
-	$is_file = trim($texte);
520
-	if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
521
-		  or strpbrk($is_file, "<>\n\r\t") !== false
522
-		  or strpos($is_file, '/') === 0
523
-	) {
524
-		$is_file = false;
525
-	}
526
-	if ($is_file) {
527
-		$is_local_file = function($path) {
528
-			if (strpos($path, "?") !== false) {
529
-				$path = supprimer_timestamp($path);
530
-				// remove ?24px added by find_in_theme on .svg files
531
-				$path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
532
-			}
533
-			return file_exists($path);
534
-		};
535
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
536
-			array_unshift($args, "<img src='$is_file' />");
537
-			$res = call_user_func_array($filtre, $args);
538
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
539
-			return $res;
540
-		}
541
-	}
542
-
543
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
544
-	if (preg_match_all(
545
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
546
-		$texte, $tags, PREG_SET_ORDER)) {
547
-		foreach ($tags as $tag) {
548
-			$class = extraire_attribut($tag[3], 'class');
549
-			if (!$class or
550
-				(strpos($class, 'filtre_inactif') === false
551
-					// compat historique a virer en 3.2
552
-					and strpos($class, 'no_image_filtrer') === false)
553
-			) {
554
-				array_unshift($args, $tag[3]);
555
-				if ($reduit = call_user_func_array($filtre, $args)) {
556
-					// En cas de span spip_documents, modifier le style=...width:
557
-					if ($tag[1]) {
558
-						$w = extraire_attribut($reduit, 'width');
559
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
560
-							$w = $regs[1];
561
-						}
562
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
563
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
564
-							$replace = inserer_attribut($tag[1], 'style', $style);
565
-							$texte = str_replace($tag[1], $replace, $texte);
566
-						}
567
-					}
568
-					// traiter aussi un eventuel mouseover
569
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
570
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
571
-							$srcover = $match[1];
572
-							array_shift($args);
573
-							array_unshift($args, "<img src='" . $match[1] . "' />");
574
-							$srcover_filter = call_user_func_array($filtre, $args);
575
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
576
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
577
-						}
578
-					}
579
-					$texte = str_replace($tag[3], $reduit, $texte);
580
-				}
581
-				array_shift($args);
582
-			}
583
-		}
584
-	}
585
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
586
-	return $texte;
511
+    $filtre = array_shift($args); # enlever $filtre
512
+    $texte = array_shift($args);
513
+    if (!strlen($texte)) {
514
+        return;
515
+    }
516
+    find_in_path('filtres_images_mini.php', 'inc/', true);
517
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
518
+    // Cas du nom de fichier local
519
+    $is_file = trim($texte);
520
+    if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
521
+          or strpbrk($is_file, "<>\n\r\t") !== false
522
+          or strpos($is_file, '/') === 0
523
+    ) {
524
+        $is_file = false;
525
+    }
526
+    if ($is_file) {
527
+        $is_local_file = function($path) {
528
+            if (strpos($path, "?") !== false) {
529
+                $path = supprimer_timestamp($path);
530
+                // remove ?24px added by find_in_theme on .svg files
531
+                $path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
532
+            }
533
+            return file_exists($path);
534
+        };
535
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
536
+            array_unshift($args, "<img src='$is_file' />");
537
+            $res = call_user_func_array($filtre, $args);
538
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
539
+            return $res;
540
+        }
541
+    }
542
+
543
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
544
+    if (preg_match_all(
545
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
546
+        $texte, $tags, PREG_SET_ORDER)) {
547
+        foreach ($tags as $tag) {
548
+            $class = extraire_attribut($tag[3], 'class');
549
+            if (!$class or
550
+                (strpos($class, 'filtre_inactif') === false
551
+                    // compat historique a virer en 3.2
552
+                    and strpos($class, 'no_image_filtrer') === false)
553
+            ) {
554
+                array_unshift($args, $tag[3]);
555
+                if ($reduit = call_user_func_array($filtre, $args)) {
556
+                    // En cas de span spip_documents, modifier le style=...width:
557
+                    if ($tag[1]) {
558
+                        $w = extraire_attribut($reduit, 'width');
559
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
560
+                            $w = $regs[1];
561
+                        }
562
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
563
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
564
+                            $replace = inserer_attribut($tag[1], 'style', $style);
565
+                            $texte = str_replace($tag[1], $replace, $texte);
566
+                        }
567
+                    }
568
+                    // traiter aussi un eventuel mouseover
569
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
570
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
571
+                            $srcover = $match[1];
572
+                            array_shift($args);
573
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
574
+                            $srcover_filter = call_user_func_array($filtre, $args);
575
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
576
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
577
+                        }
578
+                    }
579
+                    $texte = str_replace($tag[3], $reduit, $texte);
580
+                }
581
+                array_shift($args);
582
+            }
583
+        }
584
+    }
585
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
586
+    return $texte;
587 587
 }
588 588
 
589 589
 /**
@@ -598,77 +598,77 @@  discard block
 block discarded – undo
598 598
  **/
599 599
 function taille_image($img, $force_refresh = false) {
600 600
 
601
-	static $largeur_img = array(), $hauteur_img = array();
602
-	$srcWidth = 0;
603
-	$srcHeight = 0;
604
-
605
-	$src = extraire_attribut($img, 'src');
606
-
607
-	if (!$src) {
608
-		$src = $img;
609
-	} else {
610
-		$srcWidth = extraire_attribut($img, 'width');
611
-		$srcHeight = extraire_attribut($img, 'height');
612
-	}
613
-
614
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
615
-	// la copie locale a toutes les chances d'etre la ou de resservir
616
-	if (tester_url_absolue($src)) {
617
-		include_spip('inc/distant');
618
-		$fichier = copie_locale($src);
619
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
620
-	}
621
-	if (($p = strpos($src, '?')) !== false) {
622
-		$src = substr($src, 0, $p);
623
-	}
624
-
625
-	$srcsize = false;
626
-	if (isset($largeur_img[$src]) and !$force_refresh) {
627
-		$srcWidth = $largeur_img[$src];
628
-	}
629
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
630
-		$srcHeight = $hauteur_img[$src];
631
-	}
632
-	if (!$srcWidth or !$srcHeight) {
633
-
634
-		if (file_exists($src)
635
-			and $srcsize = spip_getimagesize($src)
636
-		) {
637
-			if (!$srcWidth) {
638
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
639
-			}
640
-			if (!$srcHeight) {
641
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
642
-			}
643
-		}
644
-		elseif(strpos($src, "<svg") !== false) {
645
-			include_spip('inc/svg');
646
-			if ($attrs = svg_lire_attributs($src)){
647
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
648
-				if (!$srcWidth){
649
-					$largeur_img[$src] = $srcWidth = $width;
650
-				}
651
-				if (!$srcHeight){
652
-					$hauteur_img[$src] = $srcHeight = $height;
653
-				}
654
-			}
655
-		}
656
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
657
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
658
-		elseif (@file_exists($f = "$src.src")
659
-			and lire_fichier($f, $valeurs)
660
-			and $valeurs = unserialize($valeurs)
661
-		) {
662
-			if (!$srcWidth) {
663
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
664
-			}
665
-			if (!$srcHeight) {
666
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
667
-			}
668
-		}
669
-	}
670
-
671
-	return array($srcHeight, $srcWidth);
601
+    static $largeur_img = array(), $hauteur_img = array();
602
+    $srcWidth = 0;
603
+    $srcHeight = 0;
604
+
605
+    $src = extraire_attribut($img, 'src');
606
+
607
+    if (!$src) {
608
+        $src = $img;
609
+    } else {
610
+        $srcWidth = extraire_attribut($img, 'width');
611
+        $srcHeight = extraire_attribut($img, 'height');
612
+    }
613
+
614
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
615
+    // la copie locale a toutes les chances d'etre la ou de resservir
616
+    if (tester_url_absolue($src)) {
617
+        include_spip('inc/distant');
618
+        $fichier = copie_locale($src);
619
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
620
+    }
621
+    if (($p = strpos($src, '?')) !== false) {
622
+        $src = substr($src, 0, $p);
623
+    }
624
+
625
+    $srcsize = false;
626
+    if (isset($largeur_img[$src]) and !$force_refresh) {
627
+        $srcWidth = $largeur_img[$src];
628
+    }
629
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
630
+        $srcHeight = $hauteur_img[$src];
631
+    }
632
+    if (!$srcWidth or !$srcHeight) {
633
+
634
+        if (file_exists($src)
635
+            and $srcsize = spip_getimagesize($src)
636
+        ) {
637
+            if (!$srcWidth) {
638
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
639
+            }
640
+            if (!$srcHeight) {
641
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
642
+            }
643
+        }
644
+        elseif(strpos($src, "<svg") !== false) {
645
+            include_spip('inc/svg');
646
+            if ($attrs = svg_lire_attributs($src)){
647
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
648
+                if (!$srcWidth){
649
+                    $largeur_img[$src] = $srcWidth = $width;
650
+                }
651
+                if (!$srcHeight){
652
+                    $hauteur_img[$src] = $srcHeight = $height;
653
+                }
654
+            }
655
+        }
656
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
657
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
658
+        elseif (@file_exists($f = "$src.src")
659
+            and lire_fichier($f, $valeurs)
660
+            and $valeurs = unserialize($valeurs)
661
+        ) {
662
+            if (!$srcWidth) {
663
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
664
+            }
665
+            if (!$srcHeight) {
666
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
667
+            }
668
+        }
669
+    }
670
+
671
+    return array($srcHeight, $srcWidth);
672 672
 }
673 673
 
674 674
 
@@ -686,12 +686,12 @@  discard block
 block discarded – undo
686 686
  *     Largeur en pixels, NULL ou 0 si aucune image.
687 687
  **/
688 688
 function largeur($img) {
689
-	if (!$img) {
690
-		return;
691
-	}
692
-	list($h, $l) = taille_image($img);
689
+    if (!$img) {
690
+        return;
691
+    }
692
+    list($h, $l) = taille_image($img);
693 693
 
694
-	return $l;
694
+    return $l;
695 695
 }
696 696
 
697 697
 /**
@@ -708,12 +708,12 @@  discard block
 block discarded – undo
708 708
  *     Hauteur en pixels, NULL ou 0 si aucune image.
709 709
  **/
710 710
 function hauteur($img) {
711
-	if (!$img) {
712
-		return;
713
-	}
714
-	list($h, $l) = taille_image($img);
711
+    if (!$img) {
712
+        return;
713
+    }
714
+    list($h, $l) = taille_image($img);
715 715
 
716
-	return $h;
716
+    return $h;
717 717
 }
718 718
 
719 719
 
@@ -733,11 +733,11 @@  discard block
 block discarded – undo
733 733
  * @return string
734 734
  **/
735 735
 function corriger_entites_html($texte) {
736
-	if (strpos($texte, '&amp;') === false) {
737
-		return $texte;
738
-	}
736
+    if (strpos($texte, '&amp;') === false) {
737
+        return $texte;
738
+    }
739 739
 
740
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
740
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
741 741
 }
742 742
 
743 743
 /**
@@ -752,11 +752,11 @@  discard block
 block discarded – undo
752 752
  * @return string
753 753
  **/
754 754
 function corriger_toutes_entites_html($texte) {
755
-	if (strpos($texte, '&amp;') === false) {
756
-		return $texte;
757
-	}
755
+    if (strpos($texte, '&amp;') === false) {
756
+        return $texte;
757
+    }
758 758
 
759
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
759
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
760 760
 }
761 761
 
762 762
 /**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
  * @return string
767 767
  **/
768 768
 function proteger_amp($texte) {
769
-	return str_replace('&', '&amp;', $texte);
769
+    return str_replace('&', '&amp;', $texte);
770 770
 }
771 771
 
772 772
 
@@ -797,20 +797,20 @@  discard block
 block discarded – undo
797 797
  * @return mixed|string
798 798
  */
799 799
 function entites_html($texte, $tout = false, $quote = true) {
800
-	if (!is_string($texte) or !$texte
801
-		or strpbrk($texte, "&\"'<>") == false
802
-	) {
803
-		return $texte;
804
-	}
805
-	include_spip('inc/texte');
806
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
807
-	$flags |= ENT_HTML401;
808
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
809
-	if ($tout) {
810
-		return corriger_toutes_entites_html($texte);
811
-	} else {
812
-		return corriger_entites_html($texte);
813
-	}
800
+    if (!is_string($texte) or !$texte
801
+        or strpbrk($texte, "&\"'<>") == false
802
+    ) {
803
+        return $texte;
804
+    }
805
+    include_spip('inc/texte');
806
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
807
+    $flags |= ENT_HTML401;
808
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
809
+    if ($tout) {
810
+        return corriger_toutes_entites_html($texte);
811
+    } else {
812
+        return corriger_entites_html($texte);
813
+    }
814 814
 }
815 815
 
816 816
 /**
@@ -829,37 +829,37 @@  discard block
 block discarded – undo
829 829
  *     Texte converti
830 830
  **/
831 831
 function filtrer_entites($texte) {
832
-	if (strpos($texte, '&') === false) {
833
-		return $texte;
834
-	}
835
-	// filtrer
836
-	$texte = html2unicode($texte);
837
-	// remettre le tout dans le charset cible
838
-	$texte = unicode2charset($texte);
839
-	// cas particulier des " et ' qu'il faut filtrer aussi
840
-	// (on le faisait deja avec un &quot;)
841
-	if (strpos($texte, "&#") !== false) {
842
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
843
-	}
832
+    if (strpos($texte, '&') === false) {
833
+        return $texte;
834
+    }
835
+    // filtrer
836
+    $texte = html2unicode($texte);
837
+    // remettre le tout dans le charset cible
838
+    $texte = unicode2charset($texte);
839
+    // cas particulier des " et ' qu'il faut filtrer aussi
840
+    // (on le faisait deja avec un &quot;)
841
+    if (strpos($texte, "&#") !== false) {
842
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
843
+    }
844 844
 
845
-	return $texte;
845
+    return $texte;
846 846
 }
847 847
 
848 848
 
849 849
 if (!function_exists('filtre_filtrer_entites_dist')) {
850
-	/**
851
-	 * Version sécurisée de filtrer_entites
852
-	 * 
853
-	 * @uses interdire_scripts()
854
-	 * @uses filtrer_entites()
855
-	 * 
856
-	 * @param string $t
857
-	 * @return string
858
-	 */
859
-	function filtre_filtrer_entites_dist($t) {
860
-		include_spip('inc/texte');
861
-		return interdire_scripts(filtrer_entites($t));
862
-	}
850
+    /**
851
+     * Version sécurisée de filtrer_entites
852
+     * 
853
+     * @uses interdire_scripts()
854
+     * @uses filtrer_entites()
855
+     * 
856
+     * @param string $t
857
+     * @return string
858
+     */
859
+    function filtre_filtrer_entites_dist($t) {
860
+        include_spip('inc/texte');
861
+        return interdire_scripts(filtrer_entites($t));
862
+    }
863 863
 }
864 864
 
865 865
 
@@ -874,18 +874,18 @@  discard block
 block discarded – undo
874 874
  * @return string|array
875 875
  **/
876 876
 function supprimer_caracteres_illegaux($texte) {
877
-	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";
878
-	static $to = null;
877
+    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";
878
+    static $to = null;
879 879
 
880
-	if (is_array($texte)) {
881
-		return array_map('supprimer_caracteres_illegaux', $texte);
882
-	}
880
+    if (is_array($texte)) {
881
+        return array_map('supprimer_caracteres_illegaux', $texte);
882
+    }
883 883
 
884
-	if (!$to) {
885
-		$to = str_repeat('-', strlen($from));
886
-	}
884
+    if (!$to) {
885
+        $to = str_repeat('-', strlen($from));
886
+    }
887 887
 
888
-	return strtr($texte, $from, $to);
888
+    return strtr($texte, $from, $to);
889 889
 }
890 890
 
891 891
 /**
@@ -897,10 +897,10 @@  discard block
 block discarded – undo
897 897
  * @return string|array
898 898
  **/
899 899
 function corriger_caracteres($texte) {
900
-	$texte = corriger_caracteres_windows($texte);
901
-	$texte = supprimer_caracteres_illegaux($texte);
900
+    $texte = corriger_caracteres_windows($texte);
901
+    $texte = supprimer_caracteres_illegaux($texte);
902 902
 
903
-	return $texte;
903
+    return $texte;
904 904
 }
905 905
 
906 906
 /**
@@ -918,40 +918,40 @@  discard block
 block discarded – undo
918 918
  */
919 919
 function texte_backend($texte) {
920 920
 
921
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
921
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
922 922
 
923
-	// si on a des liens ou des images, les passer en absolu
924
-	$texte = liens_absolus($texte);
923
+    // si on a des liens ou des images, les passer en absolu
924
+    $texte = liens_absolus($texte);
925 925
 
926
-	// echapper les tags &gt; &lt;
927
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
926
+    // echapper les tags &gt; &lt;
927
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
928 928
 
929
-	// importer les &eacute;
930
-	$texte = filtrer_entites($texte);
929
+    // importer les &eacute;
930
+    $texte = filtrer_entites($texte);
931 931
 
932
-	// " -> &quot; et tout ce genre de choses
933
-	$u = $GLOBALS['meta']['pcre_u'];
934
-	$texte = str_replace("&nbsp;", " ", $texte);
935
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
936
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
937
-	$texte = entites_html($texte, false, false);
938
-	// mais bien echapper les double quotes !
939
-	$texte = str_replace('"', '&#034;', $texte);
932
+    // " -> &quot; et tout ce genre de choses
933
+    $u = $GLOBALS['meta']['pcre_u'];
934
+    $texte = str_replace("&nbsp;", " ", $texte);
935
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
936
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
937
+    $texte = entites_html($texte, false, false);
938
+    // mais bien echapper les double quotes !
939
+    $texte = str_replace('"', '&#034;', $texte);
940 940
 
941
-	// verifier le charset
942
-	$texte = charset2unicode($texte);
941
+    // verifier le charset
942
+    $texte = charset2unicode($texte);
943 943
 
944
-	// Caracteres problematiques en iso-latin 1
945
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
946
-		$texte = str_replace(chr(156), '&#156;', $texte);
947
-		$texte = str_replace(chr(140), '&#140;', $texte);
948
-		$texte = str_replace(chr(159), '&#159;', $texte);
949
-	}
944
+    // Caracteres problematiques en iso-latin 1
945
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
946
+        $texte = str_replace(chr(156), '&#156;', $texte);
947
+        $texte = str_replace(chr(140), '&#140;', $texte);
948
+        $texte = str_replace(chr(159), '&#159;', $texte);
949
+    }
950 950
 
951
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
952
-	// et le caractere apostrophe alourdit les squelettes avec PHP
953
-	// ==> on les remplace par l'entite HTML
954
-	return str_replace($apostrophe, "'", $texte);
951
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
952
+    // et le caractere apostrophe alourdit les squelettes avec PHP
953
+    // ==> on les remplace par l'entite HTML
954
+    return str_replace($apostrophe, "'", $texte);
955 955
 }
956 956
 
957 957
 /**
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
  *     Texte encodé et quote pour XML
969 969
  */
970 970
 function texte_backendq($texte) {
971
-	return addslashes(texte_backend($texte));
971
+    return addslashes(texte_backend($texte));
972 972
 }
973 973
 
974 974
 
@@ -991,9 +991,9 @@  discard block
 block discarded – undo
991 991
  *     Numéro de titre, sinon chaîne vide
992 992
  **/
993 993
 function supprimer_numero($texte) {
994
-	return preg_replace(
995
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
996
-		"", $texte);
994
+    return preg_replace(
995
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
996
+        "", $texte);
997 997
 }
998 998
 
999 999
 /**
@@ -1016,13 +1016,13 @@  discard block
 block discarded – undo
1016 1016
  *     Numéro de titre, sinon chaîne vide
1017 1017
  **/
1018 1018
 function recuperer_numero($texte) {
1019
-	if (preg_match(
1020
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1021
-		$texte, $regs)) {
1022
-		return strval($regs[1]);
1023
-	} else {
1024
-		return '';
1025
-	}
1019
+    if (preg_match(
1020
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1021
+        $texte, $regs)) {
1022
+        return strval($regs[1]);
1023
+    } else {
1024
+        return '';
1025
+    }
1026 1026
 }
1027 1027
 
1028 1028
 /**
@@ -1049,13 +1049,13 @@  discard block
 block discarded – undo
1049 1049
  *     Texte converti
1050 1050
  **/
1051 1051
 function supprimer_tags($texte, $rempl = "") {
1052
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1053
-	// ne pas oublier un < final non ferme car coupe
1054
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1055
-	// mais qui peut aussi etre un simple signe plus petit que
1056
-	$texte = str_replace('<', '&lt;', $texte);
1052
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1053
+    // ne pas oublier un < final non ferme car coupe
1054
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1055
+    // mais qui peut aussi etre un simple signe plus petit que
1056
+    $texte = str_replace('<', '&lt;', $texte);
1057 1057
 
1058
-	return $texte;
1058
+    return $texte;
1059 1059
 }
1060 1060
 
1061 1061
 /**
@@ -1078,9 +1078,9 @@  discard block
 block discarded – undo
1078 1078
  *     Texte converti
1079 1079
  **/
1080 1080
 function echapper_tags($texte, $rempl = "") {
1081
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1081
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1082 1082
 
1083
-	return $texte;
1083
+    return $texte;
1084 1084
 }
1085 1085
 
1086 1086
 /**
@@ -1101,18 +1101,18 @@  discard block
 block discarded – undo
1101 1101
  *     Texte converti
1102 1102
  **/
1103 1103
 function textebrut($texte) {
1104
-	$u = $GLOBALS['meta']['pcre_u'];
1105
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1106
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1107
-	$texte = preg_replace("/^\n+/", "", $texte);
1108
-	$texte = preg_replace("/\n+$/", "", $texte);
1109
-	$texte = preg_replace("/\n +/", "\n", $texte);
1110
-	$texte = supprimer_tags($texte);
1111
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1112
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1113
-	$texte = str_replace("&#8217;", "'", $texte);
1104
+    $u = $GLOBALS['meta']['pcre_u'];
1105
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1106
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1107
+    $texte = preg_replace("/^\n+/", "", $texte);
1108
+    $texte = preg_replace("/\n+$/", "", $texte);
1109
+    $texte = preg_replace("/\n +/", "\n", $texte);
1110
+    $texte = supprimer_tags($texte);
1111
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1112
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1113
+    $texte = str_replace("&#8217;", "'", $texte);
1114 1114
 
1115
-	return $texte;
1115
+    return $texte;
1116 1116
 }
1117 1117
 
1118 1118
 
@@ -1128,17 +1128,17 @@  discard block
 block discarded – undo
1128 1128
  *     Texte avec liens ouvrants
1129 1129
  **/
1130 1130
 function liens_ouvrants($texte) {
1131
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1132
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1133
-		foreach ($liens[0] as $a) {
1134
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1135
-			$ablank = inserer_attribut($a, 'rel', $rel);
1136
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1137
-			$texte = str_replace($a, $ablank, $texte);
1138
-		}
1139
-	}
1131
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1132
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1133
+        foreach ($liens[0] as $a) {
1134
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1135
+            $ablank = inserer_attribut($a, 'rel', $rel);
1136
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1137
+            $texte = str_replace($a, $ablank, $texte);
1138
+        }
1139
+    }
1140 1140
 
1141
-	return $texte;
1141
+    return $texte;
1142 1142
 }
1143 1143
 
1144 1144
 /**
@@ -1148,22 +1148,22 @@  discard block
 block discarded – undo
1148 1148
  * @return string
1149 1149
  */
1150 1150
 function liens_nofollow($texte) {
1151
-	if (stripos($texte, "<a") === false) {
1152
-		return $texte;
1153
-	}
1151
+    if (stripos($texte, "<a") === false) {
1152
+        return $texte;
1153
+    }
1154 1154
 
1155
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1156
-		foreach ($regs[0] as $a) {
1157
-			$rel = extraire_attribut($a, "rel");
1158
-			if (strpos($rel, "nofollow") === false) {
1159
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1160
-				$anofollow = inserer_attribut($a, "rel", $rel);
1161
-				$texte = str_replace($a, $anofollow, $texte);
1162
-			}
1163
-		}
1164
-	}
1155
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1156
+        foreach ($regs[0] as $a) {
1157
+            $rel = extraire_attribut($a, "rel");
1158
+            if (strpos($rel, "nofollow") === false) {
1159
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1160
+                $anofollow = inserer_attribut($a, "rel", $rel);
1161
+                $texte = str_replace($a, $anofollow, $texte);
1162
+            }
1163
+        }
1164
+    }
1165 1165
 
1166
-	return $texte;
1166
+    return $texte;
1167 1167
 }
1168 1168
 
1169 1169
 /**
@@ -1182,12 +1182,12 @@  discard block
 block discarded – undo
1182 1182
  *     Texte sans paraghaphes
1183 1183
  **/
1184 1184
 function PtoBR($texte) {
1185
-	$u = $GLOBALS['meta']['pcre_u'];
1186
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1187
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1188
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1185
+    $u = $GLOBALS['meta']['pcre_u'];
1186
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1187
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1188
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1189 1189
 
1190
-	return $texte;
1190
+    return $texte;
1191 1191
 }
1192 1192
 
1193 1193
 
@@ -1211,14 +1211,14 @@  discard block
 block discarded – undo
1211 1211
  * @return string Texte encadré du style CSS
1212 1212
  */
1213 1213
 function lignes_longues($texte) {
1214
-	if (!strlen(trim($texte))) {
1215
-		return $texte;
1216
-	}
1217
-	include_spip('inc/texte');
1218
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1219
-		'div' : 'span';
1214
+    if (!strlen(trim($texte))) {
1215
+        return $texte;
1216
+    }
1217
+    include_spip('inc/texte');
1218
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1219
+        'div' : 'span';
1220 1220
 
1221
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1221
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1222 1222
 }
1223 1223
 
1224 1224
 /**
@@ -1237,30 +1237,30 @@  discard block
 block discarded – undo
1237 1237
  * @return string Texte en majuscule
1238 1238
  */
1239 1239
 function majuscules($texte) {
1240
-	if (!strlen($texte)) {
1241
-		return '';
1242
-	}
1240
+    if (!strlen($texte)) {
1241
+        return '';
1242
+    }
1243 1243
 
1244
-	// Cas du turc
1245
-	if ($GLOBALS['spip_lang'] == 'tr') {
1246
-		# remplacer hors des tags et des entites
1247
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1248
-			foreach ($regs as $n => $match) {
1249
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1250
-			}
1251
-		}
1244
+    // Cas du turc
1245
+    if ($GLOBALS['spip_lang'] == 'tr') {
1246
+        # remplacer hors des tags et des entites
1247
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1248
+            foreach ($regs as $n => $match) {
1249
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1250
+            }
1251
+        }
1252 1252
 
1253
-		$texte = str_replace('i', '&#304;', $texte);
1253
+        $texte = str_replace('i', '&#304;', $texte);
1254 1254
 
1255
-		if ($regs) {
1256
-			foreach ($regs as $n => $match) {
1257
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1258
-			}
1259
-		}
1260
-	}
1255
+        if ($regs) {
1256
+            foreach ($regs as $n => $match) {
1257
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1258
+            }
1259
+        }
1260
+    }
1261 1261
 
1262
-	// Cas general
1263
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1262
+    // Cas general
1263
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1264 1264
 }
1265 1265
 
1266 1266
 /**
@@ -1278,29 +1278,29 @@  discard block
 block discarded – undo
1278 1278
  * @return string
1279 1279
  **/
1280 1280
 function taille_en_octets($taille) {
1281
-	if (!defined('_KILOBYTE')) {
1282
-		/**
1283
-		 * Définit le nombre d'octets dans un Kilobyte
1284
-		 *
1285
-		 * @var int
1286
-		 **/
1287
-		define('_KILOBYTE', 1024);
1288
-	}
1281
+    if (!defined('_KILOBYTE')) {
1282
+        /**
1283
+         * Définit le nombre d'octets dans un Kilobyte
1284
+         *
1285
+         * @var int
1286
+         **/
1287
+        define('_KILOBYTE', 1024);
1288
+    }
1289 1289
 
1290
-	if ($taille < 1) {
1291
-		return '';
1292
-	}
1293
-	if ($taille < _KILOBYTE) {
1294
-		$taille = _T('taille_octets', array('taille' => $taille));
1295
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1296
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1297
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1298
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1299
-	} else {
1300
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1301
-	}
1290
+    if ($taille < 1) {
1291
+        return '';
1292
+    }
1293
+    if ($taille < _KILOBYTE) {
1294
+        $taille = _T('taille_octets', array('taille' => $taille));
1295
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1296
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1297
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1298
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1299
+    } else {
1300
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1301
+    }
1302 1302
 
1303
-	return $taille;
1303
+    return $taille;
1304 1304
 }
1305 1305
 
1306 1306
 
@@ -1322,15 +1322,15 @@  discard block
 block discarded – undo
1322 1322
  *     Texte prêt pour être utilisé en attribut HTML
1323 1323
  **/
1324 1324
 function attribut_html($texte, $textebrut = true) {
1325
-	$u = $GLOBALS['meta']['pcre_u'];
1326
-	if ($textebrut) {
1327
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1328
-	}
1329
-	$texte = texte_backend($texte);
1330
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1325
+    $u = $GLOBALS['meta']['pcre_u'];
1326
+    if ($textebrut) {
1327
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1328
+    }
1329
+    $texte = texte_backend($texte);
1330
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1331 1331
 
1332
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1333
-		$texte);
1332
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1333
+        $texte);
1334 1334
 }
1335 1335
 
1336 1336
 
@@ -1350,12 +1350,12 @@  discard block
 block discarded – undo
1350 1350
  *     URL ou chaîne vide
1351 1351
  **/
1352 1352
 function vider_url($url, $entites = true) {
1353
-	# un message pour abs_url
1354
-	$GLOBALS['mode_abs_url'] = 'url';
1355
-	$url = trim($url);
1356
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1353
+    # un message pour abs_url
1354
+    $GLOBALS['mode_abs_url'] = 'url';
1355
+    $url = trim($url);
1356
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1357 1357
 
1358
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1358
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1359 1359
 }
1360 1360
 
1361 1361
 
@@ -1370,10 +1370,10 @@  discard block
 block discarded – undo
1370 1370
  * @return string Adresse email maquillée
1371 1371
  **/
1372 1372
 function antispam($texte) {
1373
-	include_spip('inc/acces');
1374
-	$masque = creer_pass_aleatoire(3);
1373
+    include_spip('inc/acces');
1374
+    $masque = creer_pass_aleatoire(3);
1375 1375
 
1376
-	return preg_replace("/@/", " $masque ", $texte);
1376
+    return preg_replace("/@/", " $masque ", $texte);
1377 1377
 }
1378 1378
 
1379 1379
 /**
@@ -1405,12 +1405,12 @@  discard block
 block discarded – undo
1405 1405
  *     True si on a le droit d'accès, false sinon.
1406 1406
  **/
1407 1407
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1408
-	include_spip('inc/acces');
1409
-	if ($op) {
1410
-		$dir .= " $op $args";
1411
-	}
1408
+    include_spip('inc/acces');
1409
+    if ($op) {
1410
+        $dir .= " $op $args";
1411
+    }
1412 1412
 
1413
-	return verifier_low_sec($id_auteur, $cle, $dir);
1413
+    return verifier_low_sec($id_auteur, $cle, $dir);
1414 1414
 }
1415 1415
 
1416 1416
 /**
@@ -1435,11 +1435,11 @@  discard block
 block discarded – undo
1435 1435
  *     Retourne $texte, sinon $sinon.
1436 1436
  **/
1437 1437
 function sinon($texte, $sinon = '') {
1438
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1439
-		return $texte;
1440
-	} else {
1441
-		return $sinon;
1442
-	}
1438
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1439
+        return $texte;
1440
+    } else {
1441
+        return $sinon;
1442
+    }
1443 1443
 }
1444 1444
 
1445 1445
 /**
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
  * @return mixed
1464 1464
  **/
1465 1465
 function choixsivide($a, $vide, $pasvide) {
1466
-	return $a ? $pasvide : $vide;
1466
+    return $a ? $pasvide : $vide;
1467 1467
 }
1468 1468
 
1469 1469
 /**
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
  * @return mixed
1488 1488
  **/
1489 1489
 function choixsiegal($a1, $a2, $v, $f) {
1490
-	return ($a1 == $a2) ? $v : $f;
1490
+    return ($a1 == $a2) ? $v : $f;
1491 1491
 }
1492 1492
 
1493 1493
 //
@@ -1506,13 +1506,13 @@  discard block
 block discarded – undo
1506 1506
  * @return string
1507 1507
  **/
1508 1508
 function filtrer_ical($texte) {
1509
-	#include_spip('inc/charsets');
1510
-	$texte = html2unicode($texte);
1511
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1512
-	$texte = preg_replace("/\n/", " ", $texte);
1513
-	$texte = preg_replace("/,/", "\,", $texte);
1509
+    #include_spip('inc/charsets');
1510
+    $texte = html2unicode($texte);
1511
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1512
+    $texte = preg_replace("/\n/", " ", $texte);
1513
+    $texte = preg_replace("/,/", "\,", $texte);
1514 1514
 
1515
-	return $texte;
1515
+    return $texte;
1516 1516
 }
1517 1517
 
1518 1518
 
@@ -1537,53 +1537,53 @@  discard block
 block discarded – undo
1537 1537
  * @return string
1538 1538
  **/
1539 1539
 function post_autobr($texte, $delim = "\n_ ") {
1540
-	if (!function_exists('echappe_html')) {
1541
-		include_spip('inc/texte_mini');
1542
-	}
1543
-	$texte = str_replace("\r\n", "\r", $texte);
1544
-	$texte = str_replace("\r", "\n", $texte);
1545
-
1546
-	if (preg_match(",\n+$,", $texte, $fin)) {
1547
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1548
-	} else {
1549
-		$fin = '';
1550
-	}
1551
-
1552
-	$texte = echappe_html($texte, '', true);
1553
-
1554
-	// echapper les modeles
1555
-	if (strpos($texte, "<") !== false) {
1556
-		include_spip('inc/lien');
1557
-		if (defined('_PREG_MODELE')) {
1558
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1559
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1560
-		}
1561
-	}
1562
-
1563
-	$debut = '';
1564
-	$suite = $texte;
1565
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1566
-		$debut .= substr($suite, 0, $t - 1);
1567
-		$suite = substr($suite, $t);
1568
-		$car = substr($suite, 0, 1);
1569
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1570
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1571
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1572
-		) {
1573
-			$debut .= $delim;
1574
-		} else {
1575
-			$debut .= "\n";
1576
-		}
1577
-		if (preg_match(",^\n+,", $suite, $regs)) {
1578
-			$debut .= $regs[0];
1579
-			$suite = substr($suite, strlen($regs[0]));
1580
-		}
1581
-	}
1582
-	$texte = $debut . $suite;
1583
-
1584
-	$texte = echappe_retour($texte);
1585
-
1586
-	return $texte . $fin;
1540
+    if (!function_exists('echappe_html')) {
1541
+        include_spip('inc/texte_mini');
1542
+    }
1543
+    $texte = str_replace("\r\n", "\r", $texte);
1544
+    $texte = str_replace("\r", "\n", $texte);
1545
+
1546
+    if (preg_match(",\n+$,", $texte, $fin)) {
1547
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1548
+    } else {
1549
+        $fin = '';
1550
+    }
1551
+
1552
+    $texte = echappe_html($texte, '', true);
1553
+
1554
+    // echapper les modeles
1555
+    if (strpos($texte, "<") !== false) {
1556
+        include_spip('inc/lien');
1557
+        if (defined('_PREG_MODELE')) {
1558
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1559
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1560
+        }
1561
+    }
1562
+
1563
+    $debut = '';
1564
+    $suite = $texte;
1565
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1566
+        $debut .= substr($suite, 0, $t - 1);
1567
+        $suite = substr($suite, $t);
1568
+        $car = substr($suite, 0, 1);
1569
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1570
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1571
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1572
+        ) {
1573
+            $debut .= $delim;
1574
+        } else {
1575
+            $debut .= "\n";
1576
+        }
1577
+        if (preg_match(",^\n+,", $suite, $regs)) {
1578
+            $debut .= $regs[0];
1579
+            $suite = substr($suite, strlen($regs[0]));
1580
+        }
1581
+    }
1582
+    $texte = $debut . $suite;
1583
+
1584
+    $texte = echappe_retour($texte);
1585
+
1586
+    return $texte . $fin;
1587 1587
 }
1588 1588
 
1589 1589
 
@@ -1624,46 +1624,46 @@  discard block
 block discarded – undo
1624 1624
  * @return string
1625 1625
  **/
1626 1626
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1627
-	static $traduire = false;
1628
-	if ($letexte
1629
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1630
-	) {
1631
-		if (!$traduire) {
1632
-			$traduire = charger_fonction('traduire', 'inc');
1633
-			include_spip('inc/lang');
1634
-		}
1635
-		if (!$lang) {
1636
-			$lang = $GLOBALS['spip_lang'];
1637
-		}
1638
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1639
-		if (is_bool($options)) {
1640
-			$options = array('echappe_span' => $options);
1641
-		}
1642
-		if (!isset($options['echappe_span'])) {
1643
-			$options = array_merge($options, array('echappe_span' => false));
1644
-		}
1645
-
1646
-		foreach ($regs as $reg) {
1647
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1648
-			$desc = $traduire($cle, $lang, true);
1649
-			$l = $desc->langue;
1650
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1651
-			if (strlen($desc->texte)) {
1652
-				$trad = code_echappement($desc->texte, 'idiome', false);
1653
-				if ($l !== $lang) {
1654
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1655
-				}
1656
-				if (lang_dir($l) !== lang_dir($lang)) {
1657
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1658
-				}
1659
-				if (!$options['echappe_span']) {
1660
-					$trad = echappe_retour($trad, 'idiome');
1661
-				}
1662
-				$letexte = str_replace($reg[0], $trad, $letexte);
1663
-			}
1664
-		}
1665
-	}
1666
-	return $letexte;
1627
+    static $traduire = false;
1628
+    if ($letexte
1629
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1630
+    ) {
1631
+        if (!$traduire) {
1632
+            $traduire = charger_fonction('traduire', 'inc');
1633
+            include_spip('inc/lang');
1634
+        }
1635
+        if (!$lang) {
1636
+            $lang = $GLOBALS['spip_lang'];
1637
+        }
1638
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1639
+        if (is_bool($options)) {
1640
+            $options = array('echappe_span' => $options);
1641
+        }
1642
+        if (!isset($options['echappe_span'])) {
1643
+            $options = array_merge($options, array('echappe_span' => false));
1644
+        }
1645
+
1646
+        foreach ($regs as $reg) {
1647
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1648
+            $desc = $traduire($cle, $lang, true);
1649
+            $l = $desc->langue;
1650
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1651
+            if (strlen($desc->texte)) {
1652
+                $trad = code_echappement($desc->texte, 'idiome', false);
1653
+                if ($l !== $lang) {
1654
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1655
+                }
1656
+                if (lang_dir($l) !== lang_dir($lang)) {
1657
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1658
+                }
1659
+                if (!$options['echappe_span']) {
1660
+                    $trad = echappe_retour($trad, 'idiome');
1661
+                }
1662
+                $letexte = str_replace($reg[0], $trad, $letexte);
1663
+            }
1664
+        }
1665
+    }
1666
+    return $letexte;
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1715,67 +1715,67 @@  discard block
 block discarded – undo
1715 1715
  **/
1716 1716
 function extraire_multi($letexte, $lang = null, $options = array()) {
1717 1717
 
1718
-	if ($letexte
1719
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1720
-	) {
1721
-		if (!$lang) {
1722
-			$lang = $GLOBALS['spip_lang'];
1723
-		}
1724
-
1725
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1726
-		if (is_bool($options)) {
1727
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1728
-		}
1729
-		if (!isset($options['echappe_span'])) {
1730
-			$options = array_merge($options, array('echappe_span' => false));
1731
-		}
1732
-		if (!isset($options['lang_defaut'])) {
1733
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1734
-		}
1735
-
1736
-		include_spip('inc/lang');
1737
-		foreach ($regs as $reg) {
1738
-			// chercher la version de la langue courante
1739
-			$trads = extraire_trads($reg[1]);
1740
-			if ($l = approcher_langue($trads, $lang)) {
1741
-				$trad = $trads[$l];
1742
-			} else {
1743
-				if ($options['lang_defaut'] == 'aucune') {
1744
-					$trad = '';
1745
-				} else {
1746
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1747
-					// ou la premiere dispo
1748
-					// mais typographier le texte selon les regles de celle-ci
1749
-					// Attention aux blocs multi sur plusieurs lignes
1750
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1751
-						$l = key($trads);
1752
-					}
1753
-					$trad = $trads[$l];
1754
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1755
-					$trad = $typographie($trad);
1756
-					// Tester si on echappe en span ou en div
1757
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1758
-					include_spip('inc/texte');
1759
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1760
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1761
-					if ($mode === 'div') {
1762
-						$trad = rtrim($trad) . "\n\n";
1763
-					}
1764
-					$trad = code_echappement($trad, 'multi', false, $mode);
1765
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1766
-					if (lang_dir($l) !== lang_dir($lang)) {
1767
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1768
-					}
1769
-					if (!$options['echappe_span']) {
1770
-						$trad = echappe_retour($trad, 'multi');
1771
-					}
1772
-				}
1773
-			}
1774
-			$letexte = str_replace($reg[0], $trad, $letexte);
1775
-		}
1776
-	}
1777
-
1778
-	return $letexte;
1718
+    if ($letexte
1719
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1720
+    ) {
1721
+        if (!$lang) {
1722
+            $lang = $GLOBALS['spip_lang'];
1723
+        }
1724
+
1725
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1726
+        if (is_bool($options)) {
1727
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1728
+        }
1729
+        if (!isset($options['echappe_span'])) {
1730
+            $options = array_merge($options, array('echappe_span' => false));
1731
+        }
1732
+        if (!isset($options['lang_defaut'])) {
1733
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1734
+        }
1735
+
1736
+        include_spip('inc/lang');
1737
+        foreach ($regs as $reg) {
1738
+            // chercher la version de la langue courante
1739
+            $trads = extraire_trads($reg[1]);
1740
+            if ($l = approcher_langue($trads, $lang)) {
1741
+                $trad = $trads[$l];
1742
+            } else {
1743
+                if ($options['lang_defaut'] == 'aucune') {
1744
+                    $trad = '';
1745
+                } else {
1746
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1747
+                    // ou la premiere dispo
1748
+                    // mais typographier le texte selon les regles de celle-ci
1749
+                    // Attention aux blocs multi sur plusieurs lignes
1750
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1751
+                        $l = key($trads);
1752
+                    }
1753
+                    $trad = $trads[$l];
1754
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1755
+                    $trad = $typographie($trad);
1756
+                    // Tester si on echappe en span ou en div
1757
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1758
+                    include_spip('inc/texte');
1759
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1760
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1761
+                    if ($mode === 'div') {
1762
+                        $trad = rtrim($trad) . "\n\n";
1763
+                    }
1764
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1765
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1766
+                    if (lang_dir($l) !== lang_dir($lang)) {
1767
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1768
+                    }
1769
+                    if (!$options['echappe_span']) {
1770
+                        $trad = echappe_retour($trad, 'multi');
1771
+                    }
1772
+                }
1773
+            }
1774
+            $letexte = str_replace($reg[0], $trad, $letexte);
1775
+        }
1776
+    }
1777
+
1778
+    return $letexte;
1779 1779
 }
1780 1780
 
1781 1781
 /**
@@ -1791,20 +1791,20 @@  discard block
 block discarded – undo
1791 1791
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1792 1792
  **/
1793 1793
 function extraire_trads($bloc) {
1794
-	$lang = '';
1794
+    $lang = '';
1795 1795
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1796 1796
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1797
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1798
-		$texte = trim($regs[1]);
1799
-		if ($texte or $lang) {
1800
-			$trads[$lang] = $texte;
1801
-		}
1802
-		$bloc = substr($bloc, strlen($regs[0]));
1803
-		$lang = $regs[2];
1804
-	}
1805
-	$trads[$lang] = $bloc;
1797
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1798
+        $texte = trim($regs[1]);
1799
+        if ($texte or $lang) {
1800
+            $trads[$lang] = $texte;
1801
+        }
1802
+        $bloc = substr($bloc, strlen($regs[0]));
1803
+        $lang = $regs[2];
1804
+    }
1805
+    $trads[$lang] = $bloc;
1806 1806
 
1807
-	return $trads;
1807
+    return $trads;
1808 1808
 }
1809 1809
 
1810 1810
 
@@ -1815,7 +1815,7 @@  discard block
 block discarded – undo
1815 1815
  * @return string L'initiale en majuscule
1816 1816
  */
1817 1817
 function filtre_initiale($nom) {
1818
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1818
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1819 1819
 }
1820 1820
 
1821 1821
 
@@ -1860,33 +1860,33 @@  discard block
 block discarded – undo
1860 1860
  *      - null (interne) : si on empile
1861 1861
  **/
1862 1862
 function unique($donnee, $famille = '', $cpt = false) {
1863
-	static $mem = array();
1864
-	// permettre de vider la pile et de la restaurer
1865
-	// pour le calcul de introduction...
1866
-	if ($famille == '_spip_raz_') {
1867
-		$tmp = $mem;
1868
-		$mem = array();
1869
-
1870
-		return $tmp;
1871
-	} elseif ($famille == '_spip_set_') {
1872
-		$mem = $donnee;
1873
-
1874
-		return;
1875
-	}
1876
-	// eviter une notice
1877
-	if (!isset($mem[$famille])) {
1878
-		$mem[$famille] = array();
1879
-	}
1880
-	if ($cpt) {
1881
-		return count($mem[$famille]);
1882
-	}
1883
-	// eviter une notice
1884
-	if (!isset($mem[$famille][$donnee])) {
1885
-		$mem[$famille][$donnee] = 0;
1886
-	}
1887
-	if (!($mem[$famille][$donnee]++)) {
1888
-		return $donnee;
1889
-	}
1863
+    static $mem = array();
1864
+    // permettre de vider la pile et de la restaurer
1865
+    // pour le calcul de introduction...
1866
+    if ($famille == '_spip_raz_') {
1867
+        $tmp = $mem;
1868
+        $mem = array();
1869
+
1870
+        return $tmp;
1871
+    } elseif ($famille == '_spip_set_') {
1872
+        $mem = $donnee;
1873
+
1874
+        return;
1875
+    }
1876
+    // eviter une notice
1877
+    if (!isset($mem[$famille])) {
1878
+        $mem[$famille] = array();
1879
+    }
1880
+    if ($cpt) {
1881
+        return count($mem[$famille]);
1882
+    }
1883
+    // eviter une notice
1884
+    if (!isset($mem[$famille][$donnee])) {
1885
+        $mem[$famille][$donnee] = 0;
1886
+    }
1887
+    if (!($mem[$famille][$donnee]++)) {
1888
+        return $donnee;
1889
+    }
1890 1890
 }
1891 1891
 
1892 1892
 
@@ -1914,18 +1914,18 @@  discard block
 block discarded – undo
1914 1914
  *     Une des valeurs en fonction du compteur.
1915 1915
  **/
1916 1916
 function alterner($i) {
1917
-	// recuperer les arguments (attention fonctions un peu space)
1918
-	$num = func_num_args();
1919
-	$args = func_get_args();
1917
+    // recuperer les arguments (attention fonctions un peu space)
1918
+    $num = func_num_args();
1919
+    $args = func_get_args();
1920 1920
 
1921
-	if ($num == 2 && is_array($args[1])) {
1922
-		$args = $args[1];
1923
-		array_unshift($args, '');
1924
-		$num = count($args);
1925
-	}
1921
+    if ($num == 2 && is_array($args[1])) {
1922
+        $args = $args[1];
1923
+        array_unshift($args, '');
1924
+        $num = count($args);
1925
+    }
1926 1926
 
1927
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1928
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1927
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1928
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1929 1929
 }
1930 1930
 
1931 1931
 
@@ -1950,46 +1950,46 @@  discard block
 block discarded – undo
1950 1950
  *     - Tableau complet (si 2e argument)
1951 1951
  **/
1952 1952
 function extraire_attribut($balise, $attribut, $complet = false) {
1953
-	if (is_array($balise)) {
1954
-		array_walk(
1955
-			$balise,
1956
-			function(&$a, $key, $t){
1957
-				$a = extraire_attribut($a, $t);
1958
-			},
1959
-			$attribut
1960
-		);
1961
-
1962
-		return $balise;
1963
-	}
1964
-	if (preg_match(
1965
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1966
-		. $attribut
1967
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1968
-
1969
-		$balise, $r)) {
1970
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1971
-			$r[4] = substr($r[3], 1, -1);
1972
-			$r[3] = $r[3][0];
1973
-		} elseif ($r[3] !== '') {
1974
-			$r[4] = $r[3];
1975
-			$r[3] = '';
1976
-		} else {
1977
-			$r[4] = trim($r[2]);
1978
-		}
1979
-		$att = $r[4];
1980
-		if (strpos($att, "&#") !== false) {
1981
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1982
-		}
1983
-		$att = filtrer_entites($att);
1984
-	} else {
1985
-		$att = null;
1986
-	}
1987
-
1988
-	if ($complet) {
1989
-		return array($att, $r);
1990
-	} else {
1991
-		return $att;
1992
-	}
1953
+    if (is_array($balise)) {
1954
+        array_walk(
1955
+            $balise,
1956
+            function(&$a, $key, $t){
1957
+                $a = extraire_attribut($a, $t);
1958
+            },
1959
+            $attribut
1960
+        );
1961
+
1962
+        return $balise;
1963
+    }
1964
+    if (preg_match(
1965
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1966
+        . $attribut
1967
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1968
+
1969
+        $balise, $r)) {
1970
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1971
+            $r[4] = substr($r[3], 1, -1);
1972
+            $r[3] = $r[3][0];
1973
+        } elseif ($r[3] !== '') {
1974
+            $r[4] = $r[3];
1975
+            $r[3] = '';
1976
+        } else {
1977
+            $r[4] = trim($r[2]);
1978
+        }
1979
+        $att = $r[4];
1980
+        if (strpos($att, "&#") !== false) {
1981
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1982
+        }
1983
+        $att = filtrer_entites($att);
1984
+    } else {
1985
+        $att = null;
1986
+    }
1987
+
1988
+    if ($complet) {
1989
+        return array($att, $r);
1990
+    } else {
1991
+        return $att;
1992
+    }
1993 1993
 }
1994 1994
 
1995 1995
 /**
@@ -2021,37 +2021,37 @@  discard block
 block discarded – undo
2021 2021
  *     Code html modifié
2022 2022
  **/
2023 2023
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2024
-	// preparer l'attribut
2025
-	// supprimer les &nbsp; etc mais pas les balises html
2026
-	// qui ont un sens dans un attribut value d'un input
2027
-	if ($proteger) {
2028
-		$val = attribut_html($val, false);
2029
-	}
2030
-
2031
-	// echapper les ' pour eviter tout bug
2032
-	$val = str_replace("'", "&#039;", $val);
2033
-	if ($vider and strlen($val) == 0) {
2034
-		$insert = '';
2035
-	} else {
2036
-		$insert = " $attribut='$val'";
2037
-	}
2038
-
2039
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2040
-
2041
-	if ($old !== null) {
2042
-		// Remplacer l'ancien attribut du meme nom
2043
-		$balise = $r[1] . $insert . $r[5];
2044
-	} else {
2045
-		// preferer une balise " />" (comme <img />)
2046
-		if (preg_match(',/>,', $balise)) {
2047
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2048
-		} // sinon une balise <a ...> ... </a>
2049
-		else {
2050
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2051
-		}
2052
-	}
2053
-
2054
-	return $balise;
2024
+    // preparer l'attribut
2025
+    // supprimer les &nbsp; etc mais pas les balises html
2026
+    // qui ont un sens dans un attribut value d'un input
2027
+    if ($proteger) {
2028
+        $val = attribut_html($val, false);
2029
+    }
2030
+
2031
+    // echapper les ' pour eviter tout bug
2032
+    $val = str_replace("'", "&#039;", $val);
2033
+    if ($vider and strlen($val) == 0) {
2034
+        $insert = '';
2035
+    } else {
2036
+        $insert = " $attribut='$val'";
2037
+    }
2038
+
2039
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2040
+
2041
+    if ($old !== null) {
2042
+        // Remplacer l'ancien attribut du meme nom
2043
+        $balise = $r[1] . $insert . $r[5];
2044
+    } else {
2045
+        // preferer une balise " />" (comme <img />)
2046
+        if (preg_match(',/>,', $balise)) {
2047
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2048
+        } // sinon une balise <a ...> ... </a>
2049
+        else {
2050
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2051
+        }
2052
+    }
2053
+
2054
+    return $balise;
2055 2055
 }
2056 2056
 
2057 2057
 /**
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
  * @return string Code HTML sans l'attribut
2070 2070
  **/
2071 2071
 function vider_attribut($balise, $attribut) {
2072
-	return inserer_attribut($balise, $attribut, '', false, true);
2072
+    return inserer_attribut($balise, $attribut, '', false, true);
2073 2073
 }
2074 2074
 
2075 2075
 /**
@@ -2081,50 +2081,50 @@  discard block
 block discarded – undo
2081 2081
  * @return string
2082 2082
  */
2083 2083
 function modifier_class($balise, $class, $operation='ajouter') {
2084
-	if (is_string($class)) {
2085
-		$class = explode(' ', trim($class));
2086
-	}
2087
-	$class = array_filter($class);
2088
-
2089
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2090
-	if (preg_match(",[^\w-],", implode('', $class))) {
2091
-		return $balise;
2092
-	}
2093
-
2094
-	if ($class) {
2095
-		$class = array_unique($class);
2096
-		$class_courante = extraire_attribut($balise, 'class');
2097
-
2098
-		$class_new = $class_courante;
2099
-		foreach ($class as $c) {
2100
-			if ($c) {
2101
-				$is_class_presente = false;
2102
-				if (strpos($class_courante, $c) !== false
2103
-					and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2104
-					$is_class_presente = true;
2105
-				}
2106
-				if (in_array($operation, ['ajouter', 'commuter'])
2107
-					and !$is_class_presente) {
2108
-					$class_new = rtrim($class_new) . " " . $c;
2109
-				}
2110
-				elseif (in_array($operation, ['supprimer', 'commuter'])
2111
-					and $is_class_presente) {
2112
-					$class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2113
-				}
2114
-			}
2115
-		}
2116
-
2117
-		if ($class_new !== $class_courante) {
2118
-			if (strlen($class_new)) {
2119
-				$balise = inserer_attribut($balise, 'class', $class_new);
2120
-			}
2121
-			elseif ($class_courante) {
2122
-				$balise = vider_attribut($balise, 'class');
2123
-			}
2124
-		}
2125
-	}
2126
-
2127
-	return $balise;
2084
+    if (is_string($class)) {
2085
+        $class = explode(' ', trim($class));
2086
+    }
2087
+    $class = array_filter($class);
2088
+
2089
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2090
+    if (preg_match(",[^\w-],", implode('', $class))) {
2091
+        return $balise;
2092
+    }
2093
+
2094
+    if ($class) {
2095
+        $class = array_unique($class);
2096
+        $class_courante = extraire_attribut($balise, 'class');
2097
+
2098
+        $class_new = $class_courante;
2099
+        foreach ($class as $c) {
2100
+            if ($c) {
2101
+                $is_class_presente = false;
2102
+                if (strpos($class_courante, $c) !== false
2103
+                    and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2104
+                    $is_class_presente = true;
2105
+                }
2106
+                if (in_array($operation, ['ajouter', 'commuter'])
2107
+                    and !$is_class_presente) {
2108
+                    $class_new = rtrim($class_new) . " " . $c;
2109
+                }
2110
+                elseif (in_array($operation, ['supprimer', 'commuter'])
2111
+                    and $is_class_presente) {
2112
+                    $class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2113
+                }
2114
+            }
2115
+        }
2116
+
2117
+        if ($class_new !== $class_courante) {
2118
+            if (strlen($class_new)) {
2119
+                $balise = inserer_attribut($balise, 'class', $class_new);
2120
+            }
2121
+            elseif ($class_courante) {
2122
+                $balise = vider_attribut($balise, 'class');
2123
+            }
2124
+        }
2125
+    }
2126
+
2127
+    return $balise;
2128 2128
 }
2129 2129
 
2130 2130
 /**
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
  * @return string
2135 2135
  */
2136 2136
 function ajouter_class($balise, $class){
2137
-	return modifier_class($balise, $class, 'ajouter');
2137
+    return modifier_class($balise, $class, 'ajouter');
2138 2138
 }
2139 2139
 
2140 2140
 /**
@@ -2144,7 +2144,7 @@  discard block
 block discarded – undo
2144 2144
  * @return string
2145 2145
  */
2146 2146
 function supprimer_class($balise, $class){
2147
-	return modifier_class($balise, $class, 'supprimer');
2147
+    return modifier_class($balise, $class, 'supprimer');
2148 2148
 }
2149 2149
 
2150 2150
 /**
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
  * @return string
2156 2156
  */
2157 2157
 function commuter_class($balise, $class){
2158
-	return modifier_class($balise, $class, 'commuter');
2158
+    return modifier_class($balise, $class, 'commuter');
2159 2159
 }
2160 2160
 
2161 2161
 /**
@@ -2166,9 +2166,9 @@  discard block
 block discarded – undo
2166 2166
  * @return string
2167 2167
  */
2168 2168
 function tester_config($id, $mode = '') {
2169
-	include_spip('action/inscrire_auteur');
2169
+    include_spip('action/inscrire_auteur');
2170 2170
 
2171
-	return tester_statut_inscription($mode, $id);
2171
+    return tester_statut_inscription($mode, $id);
2172 2172
 }
2173 2173
 
2174 2174
 //
@@ -2193,7 +2193,7 @@  discard block
 block discarded – undo
2193 2193
  * @return int $a+$b
2194 2194
  **/
2195 2195
 function plus($a, $b) {
2196
-	return $a + $b;
2196
+    return $a + $b;
2197 2197
 }
2198 2198
 function strplus($a, $b) {return strize('plus', $a, $b);}
2199 2199
 /**
@@ -2212,7 +2212,7 @@  discard block
 block discarded – undo
2212 2212
  * @return int $a-$b
2213 2213
  **/
2214 2214
 function moins($a, $b) {
2215
-	return $a - $b;
2215
+    return $a - $b;
2216 2216
 }
2217 2217
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2218 2218
 
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
  * @return int $a*$b
2234 2234
  **/
2235 2235
 function mult($a, $b) {
2236
-	return $a * $b;
2236
+    return $a * $b;
2237 2237
 }
2238 2238
 function strmult($a, $b) {return strize('mult', $a, $b);}
2239 2239
 
@@ -2254,7 +2254,7 @@  discard block
 block discarded – undo
2254 2254
  * @return int $a/$b (ou 0 si $b est nul)
2255 2255
  **/
2256 2256
 function div($a, $b) {
2257
-	return $b ? $a / $b : 0;
2257
+    return $b ? $a / $b : 0;
2258 2258
 }
2259 2259
 function strdiv($a, $b) {return strize('div', $a, $b);}
2260 2260
 
@@ -2276,7 +2276,7 @@  discard block
 block discarded – undo
2276 2276
  * @return int ($nb % $mod) + $add
2277 2277
  **/
2278 2278
 function modulo($nb, $mod, $add = 0) {
2279
-	return ($mod ? $nb % $mod : 0) + $add;
2279
+    return ($mod ? $nb % $mod : 0) + $add;
2280 2280
 }
2281 2281
 
2282 2282
 
@@ -2291,24 +2291,24 @@  discard block
 block discarded – undo
2291 2291
  *      - true sinon
2292 2292
  **/
2293 2293
 function nom_acceptable($nom) {
2294
-	if (!is_string($nom)) {
2295
-		return false;
2296
-	}
2297
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2298
-		define('_TAGS_NOM_AUTEUR', '');
2299
-	}
2300
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2301
-	foreach ($tags_acceptes as $tag) {
2302
-		if (strlen($tag)) {
2303
-			$remp1[] = '<' . trim($tag) . '>';
2304
-			$remp1[] = '</' . trim($tag) . '>';
2305
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2306
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2307
-		}
2308
-	}
2309
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2294
+    if (!is_string($nom)) {
2295
+        return false;
2296
+    }
2297
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2298
+        define('_TAGS_NOM_AUTEUR', '');
2299
+    }
2300
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2301
+    foreach ($tags_acceptes as $tag) {
2302
+        if (strlen($tag)) {
2303
+            $remp1[] = '<' . trim($tag) . '>';
2304
+            $remp1[] = '</' . trim($tag) . '>';
2305
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2306
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2307
+        }
2308
+    }
2309
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2310 2310
 
2311
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2311
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2312 2312
 }
2313 2313
 
2314 2314
 
@@ -2324,14 +2324,14 @@  discard block
 block discarded – undo
2324 2324
  *      - renvoie un tableau si l'entree est un tableau
2325 2325
  **/
2326 2326
 function email_valide($adresses) {
2327
-	if (is_array($adresses)) {
2328
-		$adresses = array_map('email_valide', $adresses);
2329
-		$adresses = array_filter($adresses);
2330
-		return $adresses;
2331
-	}
2327
+    if (is_array($adresses)) {
2328
+        $adresses = array_map('email_valide', $adresses);
2329
+        $adresses = array_filter($adresses);
2330
+        return $adresses;
2331
+    }
2332 2332
 
2333
-	$email_valide = charger_fonction('email_valide', 'inc');
2334
-	return $email_valide($adresses);
2333
+    $email_valide = charger_fonction('email_valide', 'inc');
2334
+    return $email_valide($adresses);
2335 2335
 }
2336 2336
 
2337 2337
 /**
@@ -2345,20 +2345,20 @@  discard block
 block discarded – undo
2345 2345
  * @return string Texte
2346 2346
  **/
2347 2347
 function afficher_enclosures($tags) {
2348
-	$s = array();
2349
-	foreach (extraire_balises($tags, 'a') as $tag) {
2350
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2351
-			and $t = extraire_attribut($tag, 'href')
2352
-		) {
2353
-			$s[] = preg_replace(',>[^<]+</a>,S',
2354
-				'>'
2355
-				. http_img_pack('attachment-16.png', $t,
2356
-					'title="' . attribut_html($t) . '"')
2357
-				. '</a>', $tag);
2358
-		}
2359
-	}
2348
+    $s = array();
2349
+    foreach (extraire_balises($tags, 'a') as $tag) {
2350
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2351
+            and $t = extraire_attribut($tag, 'href')
2352
+        ) {
2353
+            $s[] = preg_replace(',>[^<]+</a>,S',
2354
+                '>'
2355
+                . http_img_pack('attachment-16.png', $t,
2356
+                    'title="' . attribut_html($t) . '"')
2357
+                . '</a>', $tag);
2358
+        }
2359
+    }
2360 2360
 
2361
-	return join('&nbsp;', $s);
2361
+    return join('&nbsp;', $s);
2362 2362
 }
2363 2363
 
2364 2364
 /**
@@ -2373,15 +2373,15 @@  discard block
 block discarded – undo
2373 2373
  * @return string Liens trouvés
2374 2374
  **/
2375 2375
 function afficher_tags($tags, $rels = 'tag,directory') {
2376
-	$s = array();
2377
-	foreach (extraire_balises($tags, 'a') as $tag) {
2378
-		$rel = extraire_attribut($tag, 'rel');
2379
-		if (strstr(",$rels,", ",$rel,")) {
2380
-			$s[] = $tag;
2381
-		}
2382
-	}
2376
+    $s = array();
2377
+    foreach (extraire_balises($tags, 'a') as $tag) {
2378
+        $rel = extraire_attribut($tag, 'rel');
2379
+        if (strstr(",$rels,", ",$rel,")) {
2380
+            $s[] = $tag;
2381
+        }
2382
+    }
2383 2383
 
2384
-	return join(', ', $s);
2384
+    return join(', ', $s);
2385 2385
 }
2386 2386
 
2387 2387
 
@@ -2403,21 +2403,21 @@  discard block
 block discarded – undo
2403 2403
  * @return string Tag HTML `<a>` avec microformat.
2404 2404
  **/
2405 2405
 function enclosure2microformat($e) {
2406
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2407
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2408
-	}
2409
-	$type = extraire_attribut($e, 'type');
2410
-	if (!$length = extraire_attribut($e, 'length')) {
2411
-		# <media:content : longeur dans fileSize. On tente.
2412
-		$length = extraire_attribut($e, 'fileSize');
2413
-	}
2414
-	$fichier = basename($url);
2406
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2407
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2408
+    }
2409
+    $type = extraire_attribut($e, 'type');
2410
+    if (!$length = extraire_attribut($e, 'length')) {
2411
+        # <media:content : longeur dans fileSize. On tente.
2412
+        $length = extraire_attribut($e, 'fileSize');
2413
+    }
2414
+    $fichier = basename($url);
2415 2415
 
2416
-	return '<a rel="enclosure"'
2417
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2418
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2419
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2420
-	. '>' . $fichier . '</a>';
2416
+    return '<a rel="enclosure"'
2417
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2418
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2419
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2420
+    . '>' . $fichier . '</a>';
2421 2421
 }
2422 2422
 
2423 2423
 /**
@@ -2435,24 +2435,24 @@  discard block
 block discarded – undo
2435 2435
  * @return string Tags RSS `<enclosure>`.
2436 2436
  **/
2437 2437
 function microformat2enclosure($tags) {
2438
-	$enclosures = array();
2439
-	foreach (extraire_balises($tags, 'a') as $e) {
2440
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2441
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2442
-			$type = extraire_attribut($e, 'type');
2443
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2444
-				$length = intval(extraire_attribut($e, 'length'));
2445
-			} # vieux data
2446
-			$fichier = basename($url);
2447
-			$enclosures[] = '<enclosure'
2448
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2449
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2450
-				. ($length ? ' length="' . $length . '"' : '')
2451
-				. ' />';
2452
-		}
2453
-	}
2438
+    $enclosures = array();
2439
+    foreach (extraire_balises($tags, 'a') as $e) {
2440
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2441
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2442
+            $type = extraire_attribut($e, 'type');
2443
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2444
+                $length = intval(extraire_attribut($e, 'length'));
2445
+            } # vieux data
2446
+            $fichier = basename($url);
2447
+            $enclosures[] = '<enclosure'
2448
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2449
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2450
+                . ($length ? ' length="' . $length . '"' : '')
2451
+                . ' />';
2452
+        }
2453
+    }
2454 2454
 
2455
-	return join("\n", $enclosures);
2455
+    return join("\n", $enclosures);
2456 2456
 }
2457 2457
 
2458 2458
 
@@ -2468,16 +2468,16 @@  discard block
 block discarded – undo
2468 2468
  * @return string Tags RSS Atom `<dc:subject>`.
2469 2469
  **/
2470 2470
 function tags2dcsubject($tags) {
2471
-	$subjects = '';
2472
-	foreach (extraire_balises($tags, 'a') as $e) {
2473
-		if (extraire_attribut($e, rel) == 'tag') {
2474
-			$subjects .= '<dc:subject>'
2475
-				. texte_backend(textebrut($e))
2476
-				. '</dc:subject>' . "\n";
2477
-		}
2478
-	}
2471
+    $subjects = '';
2472
+    foreach (extraire_balises($tags, 'a') as $e) {
2473
+        if (extraire_attribut($e, rel) == 'tag') {
2474
+            $subjects .= '<dc:subject>'
2475
+                . texte_backend(textebrut($e))
2476
+                . '</dc:subject>' . "\n";
2477
+        }
2478
+    }
2479 2479
 
2480
-	return $subjects;
2480
+    return $subjects;
2481 2481
 }
2482 2482
 
2483 2483
 /**
@@ -2506,23 +2506,23 @@  discard block
 block discarded – undo
2506 2506
  *     - Tableau de résultats, si tableau en entrée.
2507 2507
  **/
2508 2508
 function extraire_balise($texte, $tag = 'a') {
2509
-	if (is_array($texte)) {
2510
-		array_walk(
2511
-			$texte,
2512
-			function(&$a, $key, $t){
2513
-				$a = extraire_balise($a, $t);
2514
-			},
2515
-			$tag
2516
-		);
2509
+    if (is_array($texte)) {
2510
+        array_walk(
2511
+            $texte,
2512
+            function(&$a, $key, $t){
2513
+                $a = extraire_balise($a, $t);
2514
+            },
2515
+            $tag
2516
+        );
2517 2517
 
2518
-		return $texte;
2519
-	}
2518
+        return $texte;
2519
+    }
2520 2520
 
2521
-	if (preg_match(
2522
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2523
-		$texte, $regs)) {
2524
-		return $regs[0];
2525
-	}
2521
+    if (preg_match(
2522
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2523
+        $texte, $regs)) {
2524
+        return $regs[0];
2525
+    }
2526 2526
 }
2527 2527
 
2528 2528
 /**
@@ -2550,25 +2550,25 @@  discard block
 block discarded – undo
2550 2550
  *     - Tableau de résultats, si tableau en entrée.
2551 2551
  **/
2552 2552
 function extraire_balises($texte, $tag = 'a') {
2553
-	if (is_array($texte)) {
2554
-		array_walk(
2555
-			$texte,
2556
-			function(&$a, $key, $t){
2557
-				$a = extraire_balises($a, $t);
2558
-			},
2559
-			$tag
2560
-		);
2553
+    if (is_array($texte)) {
2554
+        array_walk(
2555
+            $texte,
2556
+            function(&$a, $key, $t){
2557
+                $a = extraire_balises($a, $t);
2558
+            },
2559
+            $tag
2560
+        );
2561 2561
 
2562
-		return $texte;
2563
-	}
2562
+        return $texte;
2563
+    }
2564 2564
 
2565
-	if (preg_match_all(
2566
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2567
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2568
-		return $regs[0];
2569
-	} else {
2570
-		return array();
2571
-	}
2565
+    if (preg_match_all(
2566
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2567
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2568
+        return $regs[0];
2569
+    } else {
2570
+        return array();
2571
+    }
2572 2572
 }
2573 2573
 
2574 2574
 /**
@@ -2597,11 +2597,11 @@  discard block
 block discarded – undo
2597 2597
  *     - `$def` si on n'a pas transmis de tableau
2598 2598
  **/
2599 2599
 function in_any($val, $vals, $def = '') {
2600
-	if (!is_array($vals) and $v = unserialize($vals)) {
2601
-		$vals = $v;
2602
-	}
2600
+    if (!is_array($vals) and $v = unserialize($vals)) {
2601
+        $vals = $v;
2602
+    }
2603 2603
 
2604
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2604
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2605 2605
 }
2606 2606
 
2607 2607
 
@@ -2622,12 +2622,12 @@  discard block
 block discarded – undo
2622 2622
  *     Résultat du calcul
2623 2623
  **/
2624 2624
 function valeur_numerique($expr) {
2625
-	$a = 0;
2626
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2627
-		eval("\$a = $expr;");
2628
-	}
2625
+    $a = 0;
2626
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2627
+        eval("\$a = $expr;");
2628
+    }
2629 2629
 
2630
-	return intval($a);
2630
+    return intval($a);
2631 2631
 }
2632 2632
 
2633 2633
 /**
@@ -2646,7 +2646,7 @@  discard block
 block discarded – undo
2646 2646
  *      Retourne `$a*$b/$c`
2647 2647
  **/
2648 2648
 function regledetrois($a, $b, $c) {
2649
-	return round($a * $b / $c);
2649
+    return round($a * $b / $c);
2650 2650
 }
2651 2651
 
2652 2652
 
@@ -2670,76 +2670,76 @@  discard block
 block discarded – undo
2670 2670
  **/
2671 2671
 function form_hidden($action) {
2672 2672
 
2673
-	$contexte = array();
2674
-	include_spip('inc/urls');
2675
-	if ($p = urls_decoder_url($action, '')
2676
-		and reset($p)
2677
-	) {
2678
-		$fond = array_shift($p);
2679
-		if ($fond != '404') {
2680
-			$contexte = array_shift($p);
2681
-			$contexte['page'] = $fond;
2682
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2683
-		}
2684
-	}
2685
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2686
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2687
-		unset($contexte['type']);
2688
-	}
2689
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2690
-		unset($contexte['type-page']);
2691
-	}
2692
-
2693
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2694
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2695
-	$values = array();
2696
-
2697
-	// d'abord avec celles de l'url
2698
-	if (false !== ($p = strpos($action, '?'))) {
2699
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2700
-			$c = explode('=', $c, 2);
2701
-			$var = array_shift($c);
2702
-			$val = array_shift($c);
2703
-			if ($var) {
2704
-				$val = rawurldecode($val);
2705
-				$var = rawurldecode($var); // decoder les [] eventuels
2706
-				if (preg_match(',\[\]$,S', $var)) {
2707
-					$values[] = array($var, $val);
2708
-				} else {
2709
-					if (!isset($values[$var])) {
2710
-						$values[$var] = array($var, $val);
2711
-					}
2712
-				}
2713
-			}
2714
-		}
2715
-	}
2716
-
2717
-	// ensuite avec celles du contexte, sans doublonner !
2718
-	foreach ($contexte as $var => $val) {
2719
-		if (preg_match(',\[\]$,S', $var)) {
2720
-			$values[] = array($var, $val);
2721
-		} else {
2722
-			if (!isset($values[$var])) {
2723
-				$values[$var] = array($var, $val);
2724
-			}
2725
-		}
2726
-	}
2727
-
2728
-	// puis on rassemble le tout
2729
-	$hidden = array();
2730
-	foreach ($values as $value) {
2731
-		list($var, $val) = $value;
2732
-		$hidden[] = '<input name="'
2733
-			. entites_html($var)
2734
-			. '"'
2735
-			. (is_null($val)
2736
-				? ''
2737
-				: ' value="' . entites_html($val) . '"'
2738
-			)
2739
-			. ' type="hidden"' . "\n/>";
2740
-	}
2741
-
2742
-	return join("", $hidden);
2673
+    $contexte = array();
2674
+    include_spip('inc/urls');
2675
+    if ($p = urls_decoder_url($action, '')
2676
+        and reset($p)
2677
+    ) {
2678
+        $fond = array_shift($p);
2679
+        if ($fond != '404') {
2680
+            $contexte = array_shift($p);
2681
+            $contexte['page'] = $fond;
2682
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2683
+        }
2684
+    }
2685
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2686
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2687
+        unset($contexte['type']);
2688
+    }
2689
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2690
+        unset($contexte['type-page']);
2691
+    }
2692
+
2693
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2694
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2695
+    $values = array();
2696
+
2697
+    // d'abord avec celles de l'url
2698
+    if (false !== ($p = strpos($action, '?'))) {
2699
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2700
+            $c = explode('=', $c, 2);
2701
+            $var = array_shift($c);
2702
+            $val = array_shift($c);
2703
+            if ($var) {
2704
+                $val = rawurldecode($val);
2705
+                $var = rawurldecode($var); // decoder les [] eventuels
2706
+                if (preg_match(',\[\]$,S', $var)) {
2707
+                    $values[] = array($var, $val);
2708
+                } else {
2709
+                    if (!isset($values[$var])) {
2710
+                        $values[$var] = array($var, $val);
2711
+                    }
2712
+                }
2713
+            }
2714
+        }
2715
+    }
2716
+
2717
+    // ensuite avec celles du contexte, sans doublonner !
2718
+    foreach ($contexte as $var => $val) {
2719
+        if (preg_match(',\[\]$,S', $var)) {
2720
+            $values[] = array($var, $val);
2721
+        } else {
2722
+            if (!isset($values[$var])) {
2723
+                $values[$var] = array($var, $val);
2724
+            }
2725
+        }
2726
+    }
2727
+
2728
+    // puis on rassemble le tout
2729
+    $hidden = array();
2730
+    foreach ($values as $value) {
2731
+        list($var, $val) = $value;
2732
+        $hidden[] = '<input name="'
2733
+            . entites_html($var)
2734
+            . '"'
2735
+            . (is_null($val)
2736
+                ? ''
2737
+                : ' value="' . entites_html($val) . '"'
2738
+            )
2739
+            . ' type="hidden"' . "\n/>";
2740
+    }
2741
+
2742
+    return join("", $hidden);
2743 2743
 }
2744 2744
 
2745 2745
 /**
@@ -2757,15 +2757,15 @@  discard block
 block discarded – undo
2757 2757
  *     Liste (première page, dernière page).
2758 2758
  **/
2759 2759
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2760
-	if ($max <= 0 or $max >= $nombre) {
2761
-		return array(1, $nombre);
2762
-	}
2760
+    if ($max <= 0 or $max >= $nombre) {
2761
+        return array(1, $nombre);
2762
+    }
2763 2763
 
2764
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2765
-	$derniere = min($nombre, $premiere + $max - 2);
2766
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2764
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2765
+    $derniere = min($nombre, $premiere + $max - 2);
2766
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2767 2767
 
2768
-	return array($premiere, $derniere);
2768
+    return array($premiere, $derniere);
2769 2769
 }
2770 2770
 
2771 2771
 
@@ -2787,7 +2787,7 @@  discard block
 block discarded – undo
2787 2787
  *    - la première valeur du tableau sinon.
2788 2788
  **/
2789 2789
 function filtre_reset($array) {
2790
-	return !is_array($array) ? null : reset($array);
2790
+    return !is_array($array) ? null : reset($array);
2791 2791
 }
2792 2792
 
2793 2793
 /**
@@ -2808,7 +2808,7 @@  discard block
 block discarded – undo
2808 2808
  *    - la dernière valeur du tableau sinon.
2809 2809
  **/
2810 2810
 function filtre_end($array) {
2811
-	return !is_array($array) ? null : end($array);
2811
+    return !is_array($array) ? null : end($array);
2812 2812
 }
2813 2813
 
2814 2814
 /**
@@ -2828,11 +2828,11 @@  discard block
 block discarded – undo
2828 2828
  *
2829 2829
  **/
2830 2830
 function filtre_push($array, $val) {
2831
-	if (!is_array($array) or !array_push($array, $val)) {
2832
-		return '';
2833
-	}
2831
+    if (!is_array($array) or !array_push($array, $val)) {
2832
+        return '';
2833
+    }
2834 2834
 
2835
-	return $array;
2835
+    return $array;
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2851,7 +2851,7 @@  discard block
 block discarded – undo
2851 2851
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2852 2852
  **/
2853 2853
 function filtre_find($array, $val) {
2854
-	return (is_array($array) and in_array($val, $array));
2854
+    return (is_array($array) and in_array($val, $array));
2855 2855
 }
2856 2856
 
2857 2857
 
@@ -2868,15 +2868,15 @@  discard block
 block discarded – undo
2868 2868
  *     Contenu avec urls en absolus
2869 2869
  **/
2870 2870
 function urls_absolues_css($contenu, $source) {
2871
-	$path = suivre_lien(url_absolue($source), './');
2871
+    $path = suivre_lien(url_absolue($source), './');
2872 2872
 
2873
-	return preg_replace_callback(
2874
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2875
-		function($x) use ($path) {
2876
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2877
-		},
2878
-		$contenu
2879
-	);
2873
+    return preg_replace_callback(
2874
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2875
+        function($x) use ($path) {
2876
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2877
+        },
2878
+        $contenu
2879
+    );
2880 2880
 }
2881 2881
 
2882 2882
 
@@ -2905,118 +2905,118 @@  discard block
 block discarded – undo
2905 2905
  *     Chemin du fichier CSS inversé
2906 2906
  **/
2907 2907
 function direction_css($css, $voulue = '') {
2908
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2909
-		return $css;
2910
-	}
2911
-
2912
-	// si on a precise le sens voulu en argument, le prendre en compte
2913
-	if ($voulue = strtolower($voulue)) {
2914
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2915
-			$voulue = lang_dir($voulue);
2916
-		}
2917
-	} else {
2918
-		$voulue = lang_dir();
2919
-	}
2920
-
2921
-	$r = count($r) > 1;
2922
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2923
-	$dir = $r ? 'rtl' : 'ltr';
2924
-	$ndir = $r ? 'ltr' : 'rtl';
2925
-
2926
-	if ($voulue == $dir) {
2927
-		return $css;
2928
-	}
2929
-
2930
-	if (
2931
-		// url absolue
2932
-		preg_match(",^https?:,i", $css)
2933
-		// ou qui contient un ?
2934
-		or (($p = strpos($css, '?')) !== false)
2935
-	) {
2936
-		$distant = true;
2937
-		$cssf = parse_url($css);
2938
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2939
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2940
-	} else {
2941
-		$distant = false;
2942
-		$cssf = $css;
2943
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2944
-		//propose (rien a faire dans ce cas)
2945
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2946
-		if (@file_exists($f)) {
2947
-			return $f;
2948
-		}
2949
-	}
2950
-
2951
-	// 2.
2952
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2953
-	$f = $dir_var
2954
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2955
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2956
-
2957
-	// la css peut etre distante (url absolue !)
2958
-	if ($distant) {
2959
-		include_spip('inc/distant');
2960
-		$res = recuperer_url($css);
2961
-		if (!$res or !$contenu = $res['page']) {
2962
-			return $css;
2963
-		}
2964
-	} else {
2965
-		if ((@filemtime($f) > @filemtime($css))
2966
-			and (_VAR_MODE != 'recalcul')
2967
-		) {
2968
-			return $f;
2969
-		}
2970
-		if (!lire_fichier($css, $contenu)) {
2971
-			return $css;
2972
-		}
2973
-	}
2974
-
2975
-
2976
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2977
-	include_spip("lib/csstidy/class.csstidy");
2978
-	$parser = new csstidy();
2979
-	$parser->set_cfg('optimise_shorthands', 0);
2980
-	$parser->set_cfg('reverse_left_and_right', true);
2981
-	$parser->parse($contenu);
2982
-
2983
-	$contenu = $parser->print->plain();
2984
-
2985
-
2986
-	// reperer les @import auxquels il faut propager le direction_css
2987
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2988
-	$src = array();
2989
-	$src_direction_css = array();
2990
-	$src_faux_abs = array();
2991
-	$d = dirname($css);
2992
-	foreach ($regs[1] as $k => $import_css) {
2993
-		$css_direction = direction_css("$d/$import_css", $voulue);
2994
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2995
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2996
-			$css_direction = substr($css_direction, strlen($d) + 1);
2997
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2998
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2999
-			$css_direction = substr($css_direction, strlen($dir_var));
3000
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
3001
-			$css_direction = "/@@@@@@/" . $css_direction;
3002
-		}
3003
-		$src[] = $regs[0][$k];
3004
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3005
-	}
3006
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3007
-
3008
-	$contenu = urls_absolues_css($contenu, $css);
3009
-
3010
-	// virer les fausses url absolues que l'on a mis dans les import
3011
-	if (count($src_faux_abs)) {
3012
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3013
-	}
3014
-
3015
-	if (!ecrire_fichier($f, $contenu)) {
3016
-		return $css;
3017
-	}
3018
-
3019
-	return $f;
2908
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2909
+        return $css;
2910
+    }
2911
+
2912
+    // si on a precise le sens voulu en argument, le prendre en compte
2913
+    if ($voulue = strtolower($voulue)) {
2914
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2915
+            $voulue = lang_dir($voulue);
2916
+        }
2917
+    } else {
2918
+        $voulue = lang_dir();
2919
+    }
2920
+
2921
+    $r = count($r) > 1;
2922
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2923
+    $dir = $r ? 'rtl' : 'ltr';
2924
+    $ndir = $r ? 'ltr' : 'rtl';
2925
+
2926
+    if ($voulue == $dir) {
2927
+        return $css;
2928
+    }
2929
+
2930
+    if (
2931
+        // url absolue
2932
+        preg_match(",^https?:,i", $css)
2933
+        // ou qui contient un ?
2934
+        or (($p = strpos($css, '?')) !== false)
2935
+    ) {
2936
+        $distant = true;
2937
+        $cssf = parse_url($css);
2938
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2939
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2940
+    } else {
2941
+        $distant = false;
2942
+        $cssf = $css;
2943
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2944
+        //propose (rien a faire dans ce cas)
2945
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2946
+        if (@file_exists($f)) {
2947
+            return $f;
2948
+        }
2949
+    }
2950
+
2951
+    // 2.
2952
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2953
+    $f = $dir_var
2954
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2955
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2956
+
2957
+    // la css peut etre distante (url absolue !)
2958
+    if ($distant) {
2959
+        include_spip('inc/distant');
2960
+        $res = recuperer_url($css);
2961
+        if (!$res or !$contenu = $res['page']) {
2962
+            return $css;
2963
+        }
2964
+    } else {
2965
+        if ((@filemtime($f) > @filemtime($css))
2966
+            and (_VAR_MODE != 'recalcul')
2967
+        ) {
2968
+            return $f;
2969
+        }
2970
+        if (!lire_fichier($css, $contenu)) {
2971
+            return $css;
2972
+        }
2973
+    }
2974
+
2975
+
2976
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2977
+    include_spip("lib/csstidy/class.csstidy");
2978
+    $parser = new csstidy();
2979
+    $parser->set_cfg('optimise_shorthands', 0);
2980
+    $parser->set_cfg('reverse_left_and_right', true);
2981
+    $parser->parse($contenu);
2982
+
2983
+    $contenu = $parser->print->plain();
2984
+
2985
+
2986
+    // reperer les @import auxquels il faut propager le direction_css
2987
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2988
+    $src = array();
2989
+    $src_direction_css = array();
2990
+    $src_faux_abs = array();
2991
+    $d = dirname($css);
2992
+    foreach ($regs[1] as $k => $import_css) {
2993
+        $css_direction = direction_css("$d/$import_css", $voulue);
2994
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2995
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2996
+            $css_direction = substr($css_direction, strlen($d) + 1);
2997
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2998
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2999
+            $css_direction = substr($css_direction, strlen($dir_var));
3000
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
3001
+            $css_direction = "/@@@@@@/" . $css_direction;
3002
+        }
3003
+        $src[] = $regs[0][$k];
3004
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3005
+    }
3006
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3007
+
3008
+    $contenu = urls_absolues_css($contenu, $css);
3009
+
3010
+    // virer les fausses url absolues que l'on a mis dans les import
3011
+    if (count($src_faux_abs)) {
3012
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3013
+    }
3014
+
3015
+    if (!ecrire_fichier($f, $contenu)) {
3016
+        return $css;
3017
+    }
3018
+
3019
+    return $f;
3020 3020
 }
3021 3021
 
3022 3022
 
@@ -3039,43 +3039,43 @@  discard block
 block discarded – undo
3039 3039
  *     - Chemin ou URL du fichier CSS source sinon.
3040 3040
  **/
3041 3041
 function url_absolue_css($css) {
3042
-	if (!preg_match(',\.css$,i', $css, $r)) {
3043
-		return $css;
3044
-	}
3042
+    if (!preg_match(',\.css$,i', $css, $r)) {
3043
+        return $css;
3044
+    }
3045 3045
 
3046
-	$url_absolue_css = url_absolue($css);
3046
+    $url_absolue_css = url_absolue($css);
3047 3047
 
3048
-	$f = basename($css, '.css');
3049
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3050
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3051
-		. '.css';
3048
+    $f = basename($css, '.css');
3049
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3050
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3051
+        . '.css';
3052 3052
 
3053
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3054
-		return $f;
3055
-	}
3053
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3054
+        return $f;
3055
+    }
3056 3056
 
3057
-	if ($url_absolue_css == $css) {
3058
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3059
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3060
-		) {
3061
-			include_spip('inc/distant');
3062
-			if (!$contenu = recuperer_page($css)) {
3063
-				return $css;
3064
-			}
3065
-		}
3066
-	} elseif (!lire_fichier($css, $contenu)) {
3067
-		return $css;
3068
-	}
3057
+    if ($url_absolue_css == $css) {
3058
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3059
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3060
+        ) {
3061
+            include_spip('inc/distant');
3062
+            if (!$contenu = recuperer_page($css)) {
3063
+                return $css;
3064
+            }
3065
+        }
3066
+    } elseif (!lire_fichier($css, $contenu)) {
3067
+        return $css;
3068
+    }
3069 3069
 
3070
-	// passer les url relatives a la css d'origine en url absolues
3071
-	$contenu = urls_absolues_css($contenu, $css);
3070
+    // passer les url relatives a la css d'origine en url absolues
3071
+    $contenu = urls_absolues_css($contenu, $css);
3072 3072
 
3073
-	// ecrire la css
3074
-	if (!ecrire_fichier($f, $contenu)) {
3075
-		return $css;
3076
-	}
3073
+    // ecrire la css
3074
+    if (!ecrire_fichier($f, $contenu)) {
3075
+        return $css;
3076
+    }
3077 3077
 
3078
-	return $f;
3078
+    return $f;
3079 3079
 }
3080 3080
 
3081 3081
 
@@ -3109,24 +3109,24 @@  discard block
 block discarded – undo
3109 3109
  *     Valeur trouvée ou valeur par défaut.
3110 3110
  **/
3111 3111
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3112
-	foreach (explode('/', $cle) as $k) {
3112
+    foreach (explode('/', $cle) as $k) {
3113 3113
 
3114
-		$table = is_string($table) ? @unserialize($table) : $table;
3114
+        $table = is_string($table) ? @unserialize($table) : $table;
3115 3115
 
3116
-		if (is_object($table)) {
3117
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3118
-		} elseif (is_array($table)) {
3119
-			if ($conserver_null) {
3120
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3121
-			} else {
3122
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3123
-			}
3124
-		} else {
3125
-			$table = $defaut;
3126
-		}
3127
-	}
3116
+        if (is_object($table)) {
3117
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3118
+        } elseif (is_array($table)) {
3119
+            if ($conserver_null) {
3120
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3121
+            } else {
3122
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3123
+            }
3124
+        } else {
3125
+            $table = $defaut;
3126
+        }
3127
+    }
3128 3128
 
3129
-	return $table;
3129
+    return $table;
3130 3130
 }
3131 3131
 
3132 3132
 /**
@@ -3159,22 +3159,22 @@  discard block
 block discarded – undo
3159 3159
  *     - string : expression trouvée.
3160 3160
  **/
3161 3161
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3162
-	if (intval($modif) and $capte == 0) {
3163
-		$capte = $modif;
3164
-		$modif = "UimsS";
3165
-	}
3166
-	$expression = str_replace("\/", "/", $expression);
3167
-	$expression = str_replace("/", "\/", $expression);
3162
+    if (intval($modif) and $capte == 0) {
3163
+        $capte = $modif;
3164
+        $modif = "UimsS";
3165
+    }
3166
+    $expression = str_replace("\/", "/", $expression);
3167
+    $expression = str_replace("/", "\/", $expression);
3168 3168
 
3169
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3170
-		if (isset($r[$capte])) {
3171
-			return $r[$capte];
3172
-		} else {
3173
-			return true;
3174
-		}
3175
-	}
3169
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3170
+        if (isset($r[$capte])) {
3171
+            return $r[$capte];
3172
+        } else {
3173
+            return true;
3174
+        }
3175
+    }
3176 3176
 
3177
-	return false;
3177
+    return false;
3178 3178
 }
3179 3179
 
3180 3180
 
@@ -3201,10 +3201,10 @@  discard block
 block discarded – undo
3201 3201
  *     Texte
3202 3202
  **/
3203 3203
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3204
-	$expression = str_replace("\/", "/", $expression);
3205
-	$expression = str_replace("/", "\/", $expression);
3204
+    $expression = str_replace("\/", "/", $expression);
3205
+    $expression = str_replace("/", "\/", $expression);
3206 3206
 
3207
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3207
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3208 3208
 }
3209 3209
 
3210 3210
 
@@ -3222,21 +3222,21 @@  discard block
 block discarded – undo
3222 3222
  **/
3223 3223
 function traiter_doublons_documents(&$doublons, $letexte) {
3224 3224
 
3225
-	// Verifier dans le texte & les notes (pas beau, helas)
3226
-	$t = $letexte . $GLOBALS['les_notes'];
3225
+    // Verifier dans le texte & les notes (pas beau, helas)
3226
+    $t = $letexte . $GLOBALS['les_notes'];
3227 3227
 
3228
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3229
-		and preg_match_all(
3230
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3231
-			$t, $matches, PREG_PATTERN_ORDER)
3232
-	) {
3233
-		if (!isset($doublons['documents'])) {
3234
-			$doublons['documents'] = "";
3235
-		}
3236
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3237
-	}
3228
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3229
+        and preg_match_all(
3230
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3231
+            $t, $matches, PREG_PATTERN_ORDER)
3232
+    ) {
3233
+        if (!isset($doublons['documents'])) {
3234
+            $doublons['documents'] = "";
3235
+        }
3236
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3237
+    }
3238 3238
 
3239
-	return $letexte;
3239
+    return $letexte;
3240 3240
 }
3241 3241
 
3242 3242
 /**
@@ -3250,7 +3250,7 @@  discard block
 block discarded – undo
3250 3250
  * @return string Chaîne vide
3251 3251
  **/
3252 3252
 function vide($texte) {
3253
-	return "";
3253
+    return "";
3254 3254
 }
3255 3255
 
3256 3256
 //
@@ -3279,23 +3279,23 @@  discard block
 block discarded – undo
3279 3279
  *      Code HTML résultant
3280 3280
  **/
3281 3281
 function env_to_params($env, $ignore_params = array()) {
3282
-	$ignore_params = array_merge(
3283
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3284
-		$ignore_params
3285
-	);
3286
-	if (!is_array($env)) {
3287
-		$env = unserialize($env);
3288
-	}
3289
-	$texte = "";
3290
-	if ($env) {
3291
-		foreach ($env as $i => $j) {
3292
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3293
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3294
-			}
3295
-		}
3296
-	}
3297
-
3298
-	return $texte;
3282
+    $ignore_params = array_merge(
3283
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3284
+        $ignore_params
3285
+    );
3286
+    if (!is_array($env)) {
3287
+        $env = unserialize($env);
3288
+    }
3289
+    $texte = "";
3290
+    if ($env) {
3291
+        foreach ($env as $i => $j) {
3292
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3293
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3294
+            }
3295
+        }
3296
+    }
3297
+
3298
+    return $texte;
3299 3299
 }
3300 3300
 
3301 3301
 /**
@@ -3318,23 +3318,23 @@  discard block
 block discarded – undo
3318 3318
  *      Code HTML résultant
3319 3319
  **/
3320 3320
 function env_to_attributs($env, $ignore_params = array()) {
3321
-	$ignore_params = array_merge(
3322
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3323
-		$ignore_params
3324
-	);
3325
-	if (!is_array($env)) {
3326
-		$env = unserialize($env);
3327
-	}
3328
-	$texte = "";
3329
-	if ($env) {
3330
-		foreach ($env as $i => $j) {
3331
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3332
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3333
-			}
3334
-		}
3335
-	}
3321
+    $ignore_params = array_merge(
3322
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3323
+        $ignore_params
3324
+    );
3325
+    if (!is_array($env)) {
3326
+        $env = unserialize($env);
3327
+    }
3328
+    $texte = "";
3329
+    if ($env) {
3330
+        foreach ($env as $i => $j) {
3331
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3332
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3333
+            }
3334
+        }
3335
+    }
3336 3336
 
3337
-	return $texte;
3337
+    return $texte;
3338 3338
 }
3339 3339
 
3340 3340
 
@@ -3351,9 +3351,9 @@  discard block
 block discarded – undo
3351 3351
  * @return string Chaînes concaténés
3352 3352
  **/
3353 3353
 function concat() {
3354
-	$args = func_get_args();
3354
+    $args = func_get_args();
3355 3355
 
3356
-	return join('', $args);
3356
+    return join('', $args);
3357 3357
 }
3358 3358
 
3359 3359
 
@@ -3373,23 +3373,23 @@  discard block
 block discarded – undo
3373 3373
  *     Contenu du ou des fichiers, concaténé
3374 3374
  **/
3375 3375
 function charge_scripts($files, $script = true) {
3376
-	$flux = "";
3377
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3378
-		if (!is_string($file)) {
3379
-			continue;
3380
-		}
3381
-		if ($script) {
3382
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3383
-		}
3384
-		if ($file) {
3385
-			$path = find_in_path($file);
3386
-			if ($path) {
3387
-				$flux .= spip_file_get_contents($path);
3388
-			}
3389
-		}
3390
-	}
3376
+    $flux = "";
3377
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3378
+        if (!is_string($file)) {
3379
+            continue;
3380
+        }
3381
+        if ($script) {
3382
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3383
+        }
3384
+        if ($file) {
3385
+            $path = find_in_path($file);
3386
+            if ($path) {
3387
+                $flux .= spip_file_get_contents($path);
3388
+            }
3389
+        }
3390
+    }
3391 3391
 
3392
-	return $flux;
3392
+    return $flux;
3393 3393
 }
3394 3394
 
3395 3395
 
@@ -3411,64 +3411,64 @@  discard block
 block discarded – undo
3411 3411
  */
3412 3412
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3413 3413
 
3414
-	$img_file = $img;
3415
-	if ($p = strpos($img_file, '?')) {
3416
-		$img_file = substr($img_file,0, $p);
3417
-	}
3418
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3419
-		$img_file = chemin_image($img);
3420
-	}
3421
-	else {
3422
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3423
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3424
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3425
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3426
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3427
-			  and file_exists($variante_svg_generique)) {
3428
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3429
-					$img_file = $variante_svg_size;
3430
-				}
3431
-				else {
3432
-					$img_file = $variante_svg_generique;
3433
-				}
3434
-			}
3435
-		}
3436
-	}
3437
-	if (stripos($atts, 'width') === false) {
3438
-		// utiliser directement l'info de taille presente dans le nom
3439
-		if ((!isset($options['utiliser_suffixe_size'])
3440
-				or $options['utiliser_suffixe_size'] == true
3441
-			  or strpos($img_file, '-xx.svg') !== false)
3442
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3443
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3444
-		) {
3445
-			$largeur = $hauteur = intval($regs[1]);
3446
-		} else {
3447
-			$taille = taille_image($img_file);
3448
-			list($hauteur, $largeur) = $taille;
3449
-			if (!$hauteur or !$largeur) {
3450
-				return "";
3451
-			}
3452
-		}
3453
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3454
-	}
3455
-
3456
-	if (file_exists($img_file)) {
3457
-		$img_file = timestamp($img_file);
3458
-	}
3459
-	if ($alt === false) {
3460
-		$alt = '';
3461
-	}
3462
-	elseif($alt or $alt==='') {
3463
-		$alt = " alt='".attribut_html($alt)."'";
3464
-	}
3465
-	else {
3466
-		$alt = " alt='".attribut_html($title)."'";
3467
-	}
3468
-	return "<img src='$img_file'$alt"
3469
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3470
-	. " " . ltrim($atts)
3471
-	. " />";
3414
+    $img_file = $img;
3415
+    if ($p = strpos($img_file, '?')) {
3416
+        $img_file = substr($img_file,0, $p);
3417
+    }
3418
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3419
+        $img_file = chemin_image($img);
3420
+    }
3421
+    else {
3422
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3423
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3424
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3425
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3426
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3427
+              and file_exists($variante_svg_generique)) {
3428
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3429
+                    $img_file = $variante_svg_size;
3430
+                }
3431
+                else {
3432
+                    $img_file = $variante_svg_generique;
3433
+                }
3434
+            }
3435
+        }
3436
+    }
3437
+    if (stripos($atts, 'width') === false) {
3438
+        // utiliser directement l'info de taille presente dans le nom
3439
+        if ((!isset($options['utiliser_suffixe_size'])
3440
+                or $options['utiliser_suffixe_size'] == true
3441
+              or strpos($img_file, '-xx.svg') !== false)
3442
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3443
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3444
+        ) {
3445
+            $largeur = $hauteur = intval($regs[1]);
3446
+        } else {
3447
+            $taille = taille_image($img_file);
3448
+            list($hauteur, $largeur) = $taille;
3449
+            if (!$hauteur or !$largeur) {
3450
+                return "";
3451
+            }
3452
+        }
3453
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3454
+    }
3455
+
3456
+    if (file_exists($img_file)) {
3457
+        $img_file = timestamp($img_file);
3458
+    }
3459
+    if ($alt === false) {
3460
+        $alt = '';
3461
+    }
3462
+    elseif($alt or $alt==='') {
3463
+        $alt = " alt='".attribut_html($alt)."'";
3464
+    }
3465
+    else {
3466
+        $alt = " alt='".attribut_html($title)."'";
3467
+    }
3468
+    return "<img src='$img_file'$alt"
3469
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3470
+    . " " . ltrim($atts)
3471
+    . " />";
3472 3472
 }
3473 3473
 
3474 3474
 /**
@@ -3480,68 +3480,68 @@  discard block
 block discarded – undo
3480 3480
  * @return string
3481 3481
  */
3482 3482
 function http_style_background($img, $att = '', $size=null) {
3483
-	if ($size and is_numeric($size)){
3484
-		$size = trim($size) . "px";
3485
-	}
3486
-	return " style='background" .
3487
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3488
-		. ($size ? "background-size:{$size};" : '')
3489
-		. "'";
3483
+    if ($size and is_numeric($size)){
3484
+        $size = trim($size) . "px";
3485
+    }
3486
+    return " style='background" .
3487
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3488
+        . ($size ? "background-size:{$size};" : '')
3489
+        . "'";
3490 3490
 }
3491 3491
 
3492 3492
 
3493 3493
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3494
-	$args = [$alt_or_size, $class_or_size, $size];
3495
-	while (is_null(end($args)) and count($args)) {
3496
-		array_pop($args);
3497
-	}
3498
-	if (!count($args)) {
3499
-		return [null, null, null];
3500
-	}
3501
-	if (count($args) < 3) {
3502
-		$maybe_size = array_pop($args);
3503
-		// @2x
3504
-		// @1.5x
3505
-		// 512
3506
-		// 512x*
3507
-		// 512x300
3508
-		if (!strlen($maybe_size)
3509
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3510
-			$args[] = $maybe_size;
3511
-			$maybe_size = null;
3512
-		}
3513
-		while (count($args)<2) {
3514
-			$args[] = null; // default alt or class
3515
-		}
3516
-		$args[] = $maybe_size;
3517
-	}
3518
-	return $args;
3494
+    $args = [$alt_or_size, $class_or_size, $size];
3495
+    while (is_null(end($args)) and count($args)) {
3496
+        array_pop($args);
3497
+    }
3498
+    if (!count($args)) {
3499
+        return [null, null, null];
3500
+    }
3501
+    if (count($args) < 3) {
3502
+        $maybe_size = array_pop($args);
3503
+        // @2x
3504
+        // @1.5x
3505
+        // 512
3506
+        // 512x*
3507
+        // 512x300
3508
+        if (!strlen($maybe_size)
3509
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3510
+            $args[] = $maybe_size;
3511
+            $maybe_size = null;
3512
+        }
3513
+        while (count($args)<2) {
3514
+            $args[] = null; // default alt or class
3515
+        }
3516
+        $args[] = $maybe_size;
3517
+    }
3518
+    return $args;
3519 3519
 }
3520 3520
 
3521 3521
 function helper_filtre_balise_img_svg_size($img, $size) {
3522
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3523
-	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3524
-		$coef = floatval(substr($size, 1, -1));
3525
-		list($h, $w) = taille_image($img);
3526
-		$height = intval(round($h / $coef));
3527
-		$width = intval(round($w / $coef));
3528
-	}
3529
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3530
-	else {
3531
-		$size = explode('x', $size, 2);
3532
-		$size = array_map('trim', $size);
3533
-		$height = $width = intval(array_shift($size));
3534
-
3535
-		if (count($size) and reset($size)) {
3536
-			$height = array_shift($size);
3537
-			if ($height === '*') {
3538
-				list($h, $w) = taille_image($img);
3539
-				$height = intval(round($h * $width / $w));
3540
-			}
3541
-		}
3542
-	}
3543
-
3544
-	return [$width, $height];
3522
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3523
+    if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3524
+        $coef = floatval(substr($size, 1, -1));
3525
+        list($h, $w) = taille_image($img);
3526
+        $height = intval(round($h / $coef));
3527
+        $width = intval(round($w / $coef));
3528
+    }
3529
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3530
+    else {
3531
+        $size = explode('x', $size, 2);
3532
+        $size = array_map('trim', $size);
3533
+        $height = $width = intval(array_shift($size));
3534
+
3535
+        if (count($size) and reset($size)) {
3536
+            $height = array_shift($size);
3537
+            if ($height === '*') {
3538
+                list($h, $w) = taille_image($img);
3539
+                $height = intval(round($h * $width / $w));
3540
+            }
3541
+        }
3542
+    }
3543
+
3544
+    return [$width, $height];
3545 3545
 }
3546 3546
 
3547 3547
 /**
@@ -3577,38 +3577,38 @@  discard block
 block discarded – undo
3577 3577
  */
3578 3578
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size=null) {
3579 3579
 
3580
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3580
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3581 3581
 
3582
-	$img = trim($img);
3583
-	if (strpos($img, '<img') === 0) {
3584
-		if (!is_null($alt)) {
3585
-			$img = inserer_attribut($img, 'alt', $alt);
3586
-		}
3587
-		if (!is_null($class)) {
3588
-			if (strlen($class)) {
3589
-				$img = inserer_attribut($img, 'class', $class);
3590
-			}
3591
-			else {
3592
-				$img = vider_attribut($img, 'class');
3593
-			}
3594
-		}
3595
-	}
3596
-	else {
3597
-		$img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3598
-				array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3599
-		if (is_null($alt)) {
3600
-			$img = vider_attribut($img, 'alt');
3601
-		}
3602
-	}
3582
+    $img = trim($img);
3583
+    if (strpos($img, '<img') === 0) {
3584
+        if (!is_null($alt)) {
3585
+            $img = inserer_attribut($img, 'alt', $alt);
3586
+        }
3587
+        if (!is_null($class)) {
3588
+            if (strlen($class)) {
3589
+                $img = inserer_attribut($img, 'class', $class);
3590
+            }
3591
+            else {
3592
+                $img = vider_attribut($img, 'class');
3593
+            }
3594
+        }
3595
+    }
3596
+    else {
3597
+        $img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3598
+                array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3599
+        if (is_null($alt)) {
3600
+            $img = vider_attribut($img, 'alt');
3601
+        }
3602
+    }
3603 3603
 
3604
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3605
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3604
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3605
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3606 3606
 
3607
-		$img = inserer_attribut($img, 'width', $width);
3608
-		$img = inserer_attribut($img, 'height', $height);
3609
-	}
3607
+        $img = inserer_attribut($img, 'width', $width);
3608
+        $img = inserer_attribut($img, 'height', $height);
3609
+    }
3610 3610
 
3611
-	return $img;
3611
+    return $img;
3612 3612
 }
3613 3613
 
3614 3614
 
@@ -3642,67 +3642,67 @@  discard block
 block discarded – undo
3642 3642
  */
3643 3643
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size=null) {
3644 3644
 
3645
-	$img = trim($img);
3646
-	$img_file = $img;
3647
-	if (strpos($img, '<svg') === false){
3648
-		if ($p = strpos($img_file, '?')){
3649
-			$img_file = substr($img_file, 0, $p);
3650
-		}
3645
+    $img = trim($img);
3646
+    $img_file = $img;
3647
+    if (strpos($img, '<svg') === false){
3648
+        if ($p = strpos($img_file, '?')){
3649
+            $img_file = substr($img_file, 0, $p);
3650
+        }
3651 3651
 
3652
-		if (!$img_file or !$svg = file_get_contents($img_file)){
3653
-			return '';
3654
-		}
3655
-	}
3652
+        if (!$img_file or !$svg = file_get_contents($img_file)){
3653
+            return '';
3654
+        }
3655
+    }
3656 3656
 
3657
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3658
-		return '';
3659
-	}
3657
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3658
+        return '';
3659
+    }
3660 3660
 
3661
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3661
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3662 3662
 
3663
-	$balise_svg = $match[0];
3664
-	$balise_svg_source = $balise_svg;
3663
+    $balise_svg = $match[0];
3664
+    $balise_svg_source = $balise_svg;
3665 3665
 
3666
-	// entete XML à supprimer
3667
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3666
+    // entete XML à supprimer
3667
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3668 3668
 
3669
-	// IE est toujours mon ami
3670
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3669
+    // IE est toujours mon ami
3670
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3671 3671
 
3672
-	// regler la classe
3673
-	if (!is_null($class)) {
3674
-		if (strlen($class)) {
3675
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3676
-		}
3677
-		else {
3678
-			$balise_svg = vider_attribut($balise_svg, 'class');
3679
-		}
3680
-	}
3672
+    // regler la classe
3673
+    if (!is_null($class)) {
3674
+        if (strlen($class)) {
3675
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3676
+        }
3677
+        else {
3678
+            $balise_svg = vider_attribut($balise_svg, 'class');
3679
+        }
3680
+    }
3681 3681
 
3682
-	// regler le alt
3683
-	if ($alt){
3684
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3685
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3686
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3687
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3688
-		$balise_svg .= $title;
3689
-	}
3690
-	else {
3691
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3692
-	}
3682
+    // regler le alt
3683
+    if ($alt){
3684
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3685
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3686
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3687
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3688
+        $balise_svg .= $title;
3689
+    }
3690
+    else {
3691
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3692
+    }
3693 3693
 
3694
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3694
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3695 3695
 
3696
-	if (!is_null($size) and strlen($size = trim($size))) {
3697
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3696
+    if (!is_null($size) and strlen($size = trim($size))) {
3697
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3698 3698
 
3699
-		if (!function_exists('svg_redimensionner')) {
3700
-			include_spip('inc/svg');
3701
-		}
3702
-		$svg = svg_redimensionner($svg, $width, $height);
3703
-	}
3699
+        if (!function_exists('svg_redimensionner')) {
3700
+            include_spip('inc/svg');
3701
+        }
3702
+        $svg = svg_redimensionner($svg, $width, $height);
3703
+    }
3704 3704
 
3705
-	return $svg;
3705
+    return $svg;
3706 3706
 }
3707 3707
 
3708 3708
 
@@ -3725,17 +3725,17 @@  discard block
 block discarded – undo
3725 3725
  *     Code HTML résultant
3726 3726
  **/
3727 3727
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3728
-	$texte = '';
3729
-	if (is_array($tableau)) {
3730
-		foreach ($tableau as $k => $v) {
3731
-			$res = recuperer_fond('modeles/' . $modele,
3732
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3733
-			);
3734
-			$texte .= $res;
3735
-		}
3736
-	}
3728
+    $texte = '';
3729
+    if (is_array($tableau)) {
3730
+        foreach ($tableau as $k => $v) {
3731
+            $res = recuperer_fond('modeles/' . $modele,
3732
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3733
+            );
3734
+            $texte .= $res;
3735
+        }
3736
+    }
3737 3737
 
3738
-	return $texte;
3738
+    return $texte;
3739 3739
 }
3740 3740
 
3741 3741
 
@@ -3760,37 +3760,37 @@  discard block
 block discarded – undo
3760 3760
  *         - tout : retourne toutes les informations du plugin actif
3761 3761
  **/
3762 3762
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3763
-	include_spip('inc/plugin');
3764
-	$plugin = strtoupper($plugin);
3765
-	$plugins_actifs = liste_plugin_actifs();
3766
-
3767
-	if (!$plugin) {
3768
-		return serialize(array_keys($plugins_actifs));
3769
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3770
-		return '';
3771
-	} elseif (($type_info == 'est_actif') and !$reload) {
3772
-		return $plugins_actifs[$plugin] ? 1 : 0;
3773
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3774
-		return $plugins_actifs[$plugin][$type_info];
3775
-	} else {
3776
-		$get_infos = charger_fonction('get_infos', 'plugins');
3777
-		// On prend en compte les extensions
3778
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3779
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3780
-		} else {
3781
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3782
-		}
3783
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3784
-			return '';
3785
-		}
3786
-		if ($type_info == 'tout') {
3787
-			return $infos;
3788
-		} elseif ($type_info == 'est_actif') {
3789
-			return $infos ? 1 : 0;
3790
-		} else {
3791
-			return strval($infos[$type_info]);
3792
-		}
3793
-	}
3763
+    include_spip('inc/plugin');
3764
+    $plugin = strtoupper($plugin);
3765
+    $plugins_actifs = liste_plugin_actifs();
3766
+
3767
+    if (!$plugin) {
3768
+        return serialize(array_keys($plugins_actifs));
3769
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3770
+        return '';
3771
+    } elseif (($type_info == 'est_actif') and !$reload) {
3772
+        return $plugins_actifs[$plugin] ? 1 : 0;
3773
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3774
+        return $plugins_actifs[$plugin][$type_info];
3775
+    } else {
3776
+        $get_infos = charger_fonction('get_infos', 'plugins');
3777
+        // On prend en compte les extensions
3778
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3779
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3780
+        } else {
3781
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3782
+        }
3783
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3784
+            return '';
3785
+        }
3786
+        if ($type_info == 'tout') {
3787
+            return $infos;
3788
+        } elseif ($type_info == 'est_actif') {
3789
+            return $infos ? 1 : 0;
3790
+        } else {
3791
+            return strval($infos[$type_info]);
3792
+        }
3793
+    }
3794 3794
 }
3795 3795
 
3796 3796
 
@@ -3817,9 +3817,9 @@  discard block
 block discarded – undo
3817 3817
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3818 3818
  */
3819 3819
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3820
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3820
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3821 3821
 
3822
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3822
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3823 3823
 }
3824 3824
 
3825 3825
 
@@ -3849,13 +3849,13 @@  discard block
 block discarded – undo
3849 3849
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3850 3850
  */
3851 3851
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3852
-	static $puce_statut = null;
3853
-	if (!$puce_statut) {
3854
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3855
-	}
3852
+    static $puce_statut = null;
3853
+    if (!$puce_statut) {
3854
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3855
+    }
3856 3856
 
3857
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3858
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3857
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3858
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3859 3859
 }
3860 3860
 
3861 3861
 
@@ -3882,100 +3882,100 @@  discard block
 block discarded – undo
3882 3882
  *   hash du contexte
3883 3883
  */
3884 3884
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3885
-	if (is_string($c)
3886
-		and @unserialize($c) !== false
3887
-	) {
3888
-		$c = unserialize($c);
3889
-	}
3890
-
3891
-	// supprimer les parametres debut_x
3892
-	// pour que la pagination ajax ne soit pas plantee
3893
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3894
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3895
-	if (is_array($c)) {
3896
-		foreach ($c as $k => $v) {
3897
-			if (strpos($k, 'debut_') === 0) {
3898
-				unset($c[$k]);
3899
-			}
3900
-		}
3901
-	}
3902
-
3903
-	if (!function_exists('calculer_cle_action')) {
3904
-		include_spip("inc/securiser_action");
3905
-	}
3906
-
3907
-	$c = serialize($c);
3908
-	$cle = calculer_cle_action($form . $c);
3909
-	$c = "$cle:$c";
3910
-
3911
-	// on ne stocke pas les contextes dans des fichiers en cache
3912
-	// par defaut, sauf si cette configuration a été forcée
3913
-	// OU que la longueur de l’argument géneré est plus long
3914
-	// que ce qui est toléré.
3915
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3916
-	if (!$cache_contextes_ajax) {
3917
-		$env = $c;
3918
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3919
-			$env = gzdeflate($env);
3920
-			// https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3921
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3922
-				$cache_contextes_ajax = true;
3923
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3924
-			}
3925
-		}
3926
-		$env = _xor($env);
3927
-		$env = base64_encode($env);
3928
-		$len = strlen($env);
3929
-		// Si l’url est trop longue pour le navigateur
3930
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3931
-		if ($len > $max_len) {
3932
-			$cache_contextes_ajax = true;
3933
-			spip_log("Contextes AJAX forces en fichiers !"
3934
-				. " Cela arrive lorsque la valeur du contexte" 
3935
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3936
-				, _LOG_AVERTISSEMENT);
3937
-		}
3938
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3939
-		elseif (
3940
-			$max_len = @ini_get('suhosin.get.max_value_length')
3941
-			and $max_len < $len
3942
-		) {
3943
-			$cache_contextes_ajax = true;
3944
-			spip_log("Contextes AJAX forces en fichiers !"
3945
-				. " Cela arrive lorsque la valeur du contexte"
3946
-				. " depasse la longueur maximale autorisee par Suhosin"
3947
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3948
-				. " Vous devriez modifier les parametres de Suhosin"
3949
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3950
-		} 
3951
-
3952
-	}
3953
-
3954
-	if ($cache_contextes_ajax) {
3955
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3956
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3957
-		$md5 = md5($c);
3958
-		ecrire_fichier("$dir/c$md5", $c);
3959
-		$env = $md5;
3960
-	}
3961
-
3962
-	if ($emboite === null) {
3963
-		return $env;
3964
-	}
3965
-	if (!trim($emboite)) {
3966
-		return "";
3967
-	}
3968
-	// toujours encoder l'url source dans le bloc ajax
3969
-	$r = self();
3970
-	$r = ' data-origin="' . $r . '"';
3971
-	$class = 'ajaxbloc';
3972
-	if ($ajaxid and is_string($ajaxid)) {
3973
-		// ajaxid est normalement conforme a un nom de classe css
3974
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3975
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3976
-	}
3977
-
3978
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3885
+    if (is_string($c)
3886
+        and @unserialize($c) !== false
3887
+    ) {
3888
+        $c = unserialize($c);
3889
+    }
3890
+
3891
+    // supprimer les parametres debut_x
3892
+    // pour que la pagination ajax ne soit pas plantee
3893
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3894
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3895
+    if (is_array($c)) {
3896
+        foreach ($c as $k => $v) {
3897
+            if (strpos($k, 'debut_') === 0) {
3898
+                unset($c[$k]);
3899
+            }
3900
+        }
3901
+    }
3902
+
3903
+    if (!function_exists('calculer_cle_action')) {
3904
+        include_spip("inc/securiser_action");
3905
+    }
3906
+
3907
+    $c = serialize($c);
3908
+    $cle = calculer_cle_action($form . $c);
3909
+    $c = "$cle:$c";
3910
+
3911
+    // on ne stocke pas les contextes dans des fichiers en cache
3912
+    // par defaut, sauf si cette configuration a été forcée
3913
+    // OU que la longueur de l’argument géneré est plus long
3914
+    // que ce qui est toléré.
3915
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3916
+    if (!$cache_contextes_ajax) {
3917
+        $env = $c;
3918
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3919
+            $env = gzdeflate($env);
3920
+            // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3921
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3922
+                $cache_contextes_ajax = true;
3923
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3924
+            }
3925
+        }
3926
+        $env = _xor($env);
3927
+        $env = base64_encode($env);
3928
+        $len = strlen($env);
3929
+        // Si l’url est trop longue pour le navigateur
3930
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3931
+        if ($len > $max_len) {
3932
+            $cache_contextes_ajax = true;
3933
+            spip_log("Contextes AJAX forces en fichiers !"
3934
+                . " Cela arrive lorsque la valeur du contexte" 
3935
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3936
+                , _LOG_AVERTISSEMENT);
3937
+        }
3938
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3939
+        elseif (
3940
+            $max_len = @ini_get('suhosin.get.max_value_length')
3941
+            and $max_len < $len
3942
+        ) {
3943
+            $cache_contextes_ajax = true;
3944
+            spip_log("Contextes AJAX forces en fichiers !"
3945
+                . " Cela arrive lorsque la valeur du contexte"
3946
+                . " depasse la longueur maximale autorisee par Suhosin"
3947
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3948
+                . " Vous devriez modifier les parametres de Suhosin"
3949
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3950
+        } 
3951
+
3952
+    }
3953
+
3954
+    if ($cache_contextes_ajax) {
3955
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3956
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3957
+        $md5 = md5($c);
3958
+        ecrire_fichier("$dir/c$md5", $c);
3959
+        $env = $md5;
3960
+    }
3961
+
3962
+    if ($emboite === null) {
3963
+        return $env;
3964
+    }
3965
+    if (!trim($emboite)) {
3966
+        return "";
3967
+    }
3968
+    // toujours encoder l'url source dans le bloc ajax
3969
+    $r = self();
3970
+    $r = ' data-origin="' . $r . '"';
3971
+    $class = 'ajaxbloc';
3972
+    if ($ajaxid and is_string($ajaxid)) {
3973
+        // ajaxid est normalement conforme a un nom de classe css
3974
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3975
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3976
+    }
3977
+
3978
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3979 3979
 }
3980 3980
 
3981 3981
 /**
@@ -3995,36 +3995,36 @@  discard block
 block discarded – undo
3995 3995
  *   - false : erreur de décodage
3996 3996
  */
3997 3997
 function decoder_contexte_ajax($c, $form = '') {
3998
-	if (!function_exists('calculer_cle_action')) {
3999
-		include_spip("inc/securiser_action");
4000
-	}
4001
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4002
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4003
-		and lire_fichier("$dir/c$c", $contexte)
4004
-	) {
4005
-		$c = $contexte;
4006
-	} else {
4007
-		$c = @base64_decode($c);
4008
-		$c = _xor($c);
4009
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4010
-			$c = @gzinflate($c);
4011
-		}
4012
-	}
4013
-
4014
-	// extraire la signature en debut de contexte
4015
-	// et la verifier avant de deserializer
4016
-	// format : signature:donneesserializees
4017
-	if ($p = strpos($c,":")){
4018
-		$cle = substr($c,0,$p);
4019
-		$c = substr($c,$p+1);
4020
-
4021
-		if ($cle == calculer_cle_action($form . $c)) {
4022
-			$env = @unserialize($c);
4023
-			return $env;
4024
-		}
4025
-	}
4026
-
4027
-	return false;
3998
+    if (!function_exists('calculer_cle_action')) {
3999
+        include_spip("inc/securiser_action");
4000
+    }
4001
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4002
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4003
+        and lire_fichier("$dir/c$c", $contexte)
4004
+    ) {
4005
+        $c = $contexte;
4006
+    } else {
4007
+        $c = @base64_decode($c);
4008
+        $c = _xor($c);
4009
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4010
+            $c = @gzinflate($c);
4011
+        }
4012
+    }
4013
+
4014
+    // extraire la signature en debut de contexte
4015
+    // et la verifier avant de deserializer
4016
+    // format : signature:donneesserializees
4017
+    if ($p = strpos($c,":")){
4018
+        $cle = substr($c,0,$p);
4019
+        $c = substr($c,$p+1);
4020
+
4021
+        if ($cle == calculer_cle_action($form . $c)) {
4022
+            $env = @unserialize($c);
4023
+            return $env;
4024
+        }
4025
+    }
4026
+
4027
+    return false;
4028 4028
 }
4029 4029
 
4030 4030
 
@@ -4042,20 +4042,20 @@  discard block
 block discarded – undo
4042 4042
  *    Message décrypté ou encrypté
4043 4043
  **/
4044 4044
 function _xor($message, $key = null) {
4045
-	if (is_null($key)) {
4046
-		if (!function_exists('calculer_cle_action')) {
4047
-			include_spip("inc/securiser_action");
4048
-		}
4049
-		$key = pack("H*", calculer_cle_action('_xor'));
4050
-	}
4045
+    if (is_null($key)) {
4046
+        if (!function_exists('calculer_cle_action')) {
4047
+            include_spip("inc/securiser_action");
4048
+        }
4049
+        $key = pack("H*", calculer_cle_action('_xor'));
4050
+    }
4051 4051
 
4052
-	$keylen = strlen($key);
4053
-	$messagelen = strlen($message);
4054
-	for ($i = 0; $i < $messagelen; $i++) {
4055
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4056
-	}
4052
+    $keylen = strlen($key);
4053
+    $messagelen = strlen($message);
4054
+    for ($i = 0; $i < $messagelen; $i++) {
4055
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4056
+    }
4057 4057
 
4058
-	return $message;
4058
+    return $message;
4059 4059
 }
4060 4060
 
4061 4061
 /**
@@ -4118,37 +4118,37 @@  discard block
 block discarded – undo
4118 4118
  *   Code HTML
4119 4119
  */
4120 4120
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
4121
-	if ($on) {
4122
-		$bal = 'strong';
4123
-		$class = "";
4124
-		$att = "";
4125
-		// si $on passe la balise et optionnelement une ou ++classe
4126
-		// a.active span.selected.active etc....
4127
-		if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4128
-			$on = explode(".", $on);
4129
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4130
-			if (in_array(reset($on), array('a', 'span', 'strong'))){
4131
-				$bal = array_shift($on);
4132
-				$class = implode(" ", $on);
4133
-				if ($bal=="a"){
4134
-					$att = 'href="#" ';
4135
-				}
4136
-			}
4137
-		}
4138
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4139
-	} else {
4140
-		$bal = 'a';
4141
-		$att = "href='$url'"
4142
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4143
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4144
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4145
-			. $evt;
4146
-	}
4147
-	if ($libelle === null) {
4148
-		$libelle = $url;
4149
-	}
4150
-
4151
-	return "<$bal $att>$libelle</$bal>";
4121
+    if ($on) {
4122
+        $bal = 'strong';
4123
+        $class = "";
4124
+        $att = "";
4125
+        // si $on passe la balise et optionnelement une ou ++classe
4126
+        // a.active span.selected.active etc....
4127
+        if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4128
+            $on = explode(".", $on);
4129
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4130
+            if (in_array(reset($on), array('a', 'span', 'strong'))){
4131
+                $bal = array_shift($on);
4132
+                $class = implode(" ", $on);
4133
+                if ($bal=="a"){
4134
+                    $att = 'href="#" ';
4135
+                }
4136
+            }
4137
+        }
4138
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4139
+    } else {
4140
+        $bal = 'a';
4141
+        $att = "href='$url'"
4142
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4143
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4144
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4145
+            . $evt;
4146
+    }
4147
+    if ($libelle === null) {
4148
+        $libelle = $url;
4149
+    }
4150
+
4151
+    return "<$bal $att>$libelle</$bal>";
4152 4152
 }
4153 4153
 
4154 4154
 
@@ -4165,37 +4165,37 @@  discard block
 block discarded – undo
4165 4165
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4166 4166
  */
4167 4167
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
4168
-	static $local_singulier_ou_pluriel = array();
4168
+    static $local_singulier_ou_pluriel = array();
4169 4169
 
4170
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4171
-	if (!is_numeric($nb) or $nb == 0) {
4172
-		return "";
4173
-	}
4174
-	if (!is_array($vars)) {
4175
-		return "";
4176
-	}
4170
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4171
+    if (!is_numeric($nb) or $nb == 0) {
4172
+        return "";
4173
+    }
4174
+    if (!is_array($vars)) {
4175
+        return "";
4176
+    }
4177 4177
 
4178
-	$langue = $GLOBALS['spip_lang'];
4179
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4180
-		$local_singulier_ou_pluriel[$langue] = false;
4181
-		if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4182
-		  or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4183
-			$local_singulier_ou_pluriel[$langue] = $f;
4184
-		}
4185
-	}
4178
+    $langue = $GLOBALS['spip_lang'];
4179
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4180
+        $local_singulier_ou_pluriel[$langue] = false;
4181
+        if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4182
+          or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4183
+            $local_singulier_ou_pluriel[$langue] = $f;
4184
+        }
4185
+    }
4186 4186
 
4187
-	// si on a une surcharge on l'utilise
4188
-	if ($local_singulier_ou_pluriel[$langue]) {
4189
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4190
-	}
4187
+    // si on a une surcharge on l'utilise
4188
+    if ($local_singulier_ou_pluriel[$langue]) {
4189
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4190
+    }
4191 4191
 
4192
-	// sinon traitement par defaut
4193
-	$vars[$var] = $nb;
4194
-	if ($nb >= 2) {
4195
-		return _T($chaine_plusieurs, $vars);
4196
-	} else {
4197
-		return _T($chaine_un, $vars);
4198
-	}
4192
+    // sinon traitement par defaut
4193
+    $vars[$var] = $nb;
4194
+    if ($nb >= 2) {
4195
+        return _T($chaine_plusieurs, $vars);
4196
+    } else {
4197
+        return _T($chaine_un, $vars);
4198
+    }
4199 4199
 }
4200 4200
 
4201 4201
 
@@ -4220,56 +4220,56 @@  discard block
 block discarded – undo
4220 4220
  * @return string
4221 4221
  */
4222 4222
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4223
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
4224
-		$class .= ' danger';
4225
-	} elseif ($fonction == "rien.gif") {
4226
-		$fonction = "";
4227
-	} elseif ($fonction == "delsafe") {
4228
-		$fonction = "del";
4229
-	}
4230
-
4231
-	$fond_origine = $fond;
4232
-	// remappage des icone : article-24.png+new => article-new-24.png
4233
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4234
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4235
-	}
4236
-
4237
-	// ajouter le type d'objet dans la class de l'icone
4238
-	$class .= " " . substr(basename($fond), 0, -4);
4239
-
4240
-	$alt = attribut_html($texte);
4241
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4242
-
4243
-	$ajax = "";
4244
-	if (strpos($class, "ajax") !== false) {
4245
-		$ajax = "ajax";
4246
-		if (strpos($class, "preload") !== false) {
4247
-			$ajax .= " preload";
4248
-		}
4249
-		if (strpos($class, "nocache") !== false) {
4250
-			$ajax .= " nocache";
4251
-		}
4252
-		$ajax = " class='$ajax'";
4253
-	}
4254
-
4255
-	$size = 24;
4256
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4257
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4258
-		$size = $match[1];
4259
-	}
4260
-
4261
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4262
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4263
-
4264
-	if ($type == 'lien') {
4265
-		return "<span class='icone s$size $class'>"
4266
-		. "<a href='$lien'$title$ajax$javascript>"
4267
-		. $icone
4268
-		. "<b>$texte</b>"
4269
-		. "</a></span>\n";
4270
-	} else {
4271
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4272
-	}
4223
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
4224
+        $class .= ' danger';
4225
+    } elseif ($fonction == "rien.gif") {
4226
+        $fonction = "";
4227
+    } elseif ($fonction == "delsafe") {
4228
+        $fonction = "del";
4229
+    }
4230
+
4231
+    $fond_origine = $fond;
4232
+    // remappage des icone : article-24.png+new => article-new-24.png
4233
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4234
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4235
+    }
4236
+
4237
+    // ajouter le type d'objet dans la class de l'icone
4238
+    $class .= " " . substr(basename($fond), 0, -4);
4239
+
4240
+    $alt = attribut_html($texte);
4241
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4242
+
4243
+    $ajax = "";
4244
+    if (strpos($class, "ajax") !== false) {
4245
+        $ajax = "ajax";
4246
+        if (strpos($class, "preload") !== false) {
4247
+            $ajax .= " preload";
4248
+        }
4249
+        if (strpos($class, "nocache") !== false) {
4250
+            $ajax .= " nocache";
4251
+        }
4252
+        $ajax = " class='$ajax'";
4253
+    }
4254
+
4255
+    $size = 24;
4256
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4257
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4258
+        $size = $match[1];
4259
+    }
4260
+
4261
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4262
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4263
+
4264
+    if ($type == 'lien') {
4265
+        return "<span class='icone s$size $class'>"
4266
+        . "<a href='$lien'$title$ajax$javascript>"
4267
+        . $icone
4268
+        . "<b>$texte</b>"
4269
+        . "</a></span>\n";
4270
+    } else {
4271
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4272
+    }
4273 4273
 }
4274 4274
 
4275 4275
 /**
@@ -4293,7 +4293,7 @@  discard block
 block discarded – undo
4293 4293
  *     Code HTML du lien
4294 4294
  **/
4295 4295
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4296
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4296
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4297 4297
 }
4298 4298
 
4299 4299
 /**
@@ -4328,7 +4328,7 @@  discard block
 block discarded – undo
4328 4328
  *     Code HTML du lien
4329 4329
  **/
4330 4330
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4331
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4331
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4332 4332
 }
4333 4333
 
4334 4334
 /**
@@ -4373,7 +4373,7 @@  discard block
 block discarded – undo
4373 4373
  *     Code HTML du lien
4374 4374
  **/
4375 4375
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4376
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4376
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4377 4377
 }
4378 4378
 
4379 4379
 /**
@@ -4404,7 +4404,7 @@  discard block
 block discarded – undo
4404 4404
  *     Code HTML du lien
4405 4405
  **/
4406 4406
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4407
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4407
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4408 4408
 }
4409 4409
 
4410 4410
 /**
@@ -4434,7 +4434,7 @@  discard block
 block discarded – undo
4434 4434
  *     Code HTML du lien
4435 4435
  */
4436 4436
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4437
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4437
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4438 4438
 }
4439 4439
 
4440 4440
 
@@ -4482,26 +4482,26 @@  discard block
 block discarded – undo
4482 4482
  * @return string Code CSS
4483 4483
  */
4484 4484
 function bando_images_background() {
4485
-	include_spip('inc/bandeau');
4486
-	// recuperer tous les boutons et leurs images
4487
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4485
+    include_spip('inc/bandeau');
4486
+    // recuperer tous les boutons et leurs images
4487
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4488 4488
 
4489
-	$res = "";
4490
-	foreach ($boutons as $page => $detail) {
4491
-		if ($detail->icone and strlen(trim($detail->icone))) {
4492
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4493
-		}
4494
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4495
-		if (is_array($detail->sousmenu)) {
4496
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4497
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4498
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4499
-				}
4500
-			}
4501
-		}
4502
-	}
4489
+    $res = "";
4490
+    foreach ($boutons as $page => $detail) {
4491
+        if ($detail->icone and strlen(trim($detail->icone))) {
4492
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4493
+        }
4494
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4495
+        if (is_array($detail->sousmenu)) {
4496
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4497
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4498
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4499
+                }
4500
+            }
4501
+        }
4502
+    }
4503 4503
 
4504
-	return $res;
4504
+    return $res;
4505 4505
 }
4506 4506
 
4507 4507
 /**
@@ -4520,19 +4520,19 @@  discard block
 block discarded – undo
4520 4520
  * @return string
4521 4521
  */
4522 4522
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4523
-	if ($confirm) {
4524
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4525
-		if ($callback) {
4526
-			$callback = "$confirm?($callback):false";
4527
-		} else {
4528
-			$callback = $confirm;
4529
-		}
4530
-	}
4531
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4532
-	$title = $title ? " title='$title'" : "";
4523
+    if ($confirm) {
4524
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4525
+        if ($callback) {
4526
+            $callback = "$confirm?($callback):false";
4527
+        } else {
4528
+            $callback = $confirm;
4529
+        }
4530
+    }
4531
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4532
+    $title = $title ? " title='$title'" : "";
4533 4533
 
4534
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4535
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4534
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4535
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4536 4536
 }
4537 4537
 
4538 4538
 /**
@@ -4553,78 +4553,78 @@  discard block
 block discarded – undo
4553 4553
  * @return string
4554 4554
  */
4555 4555
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4556
-	static $trouver_table = null;
4557
-	static $objets;
4558
-
4559
-	// On verifie qu'on a tout ce qu'il faut
4560
-	$id_objet = intval($id_objet);
4561
-	if (!($id_objet and $type_objet and $info)) {
4562
-		return '';
4563
-	}
4564
-
4565
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4566
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4567
-		return '';
4568
-	}
4569
-
4570
-	// Si on demande l'url, on retourne direct la fonction
4571
-	if ($info == 'url') {
4572
-		return generer_url_entite($id_objet, $type_objet);
4573
-	}
4574
-
4575
-	// Sinon on va tout chercher dans la table et on garde en memoire
4576
-	$demande_titre = ($info == 'titre');
4577
-
4578
-	// 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
4579
-	if (!isset($objets[$type_objet][$id_objet])
4580
-		or
4581
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4582
-	) {
4583
-		if (!$trouver_table) {
4584
-			$trouver_table = charger_fonction('trouver_table', 'base');
4585
-		}
4586
-		$desc = $trouver_table(table_objet_sql($type_objet));
4587
-		if (!$desc) {
4588
-			return $objets[$type_objet] = false;
4589
-		}
4590
-
4591
-		// Si on demande le titre, on le gere en interne
4592
-		$champ_titre = "";
4593
-		if ($demande_titre) {
4594
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4595
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4596
-		}
4597
-		include_spip('base/abstract_sql');
4598
-		include_spip('base/connect_sql');
4599
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4600
-			'*' . $champ_titre,
4601
-			$desc['table_sql'],
4602
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4603
-		);
4604
-	}
4605
-
4606
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4607
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4608
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4609
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4610
-	else {
4611
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4612
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4613
-		} // Sinon on prend directement le champ SQL tel quel
4614
-		else {
4615
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4616
-		}
4617
-	}
4618
-
4619
-	// On va ensuite appliquer les traitements automatiques si besoin
4620
-	if (!$etoile) {
4621
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4622
-		// mais ce fonctionnement est a ameliorer !
4623
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4624
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4625
-	}
4626
-
4627
-	return $info_generee;
4556
+    static $trouver_table = null;
4557
+    static $objets;
4558
+
4559
+    // On verifie qu'on a tout ce qu'il faut
4560
+    $id_objet = intval($id_objet);
4561
+    if (!($id_objet and $type_objet and $info)) {
4562
+        return '';
4563
+    }
4564
+
4565
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4566
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4567
+        return '';
4568
+    }
4569
+
4570
+    // Si on demande l'url, on retourne direct la fonction
4571
+    if ($info == 'url') {
4572
+        return generer_url_entite($id_objet, $type_objet);
4573
+    }
4574
+
4575
+    // Sinon on va tout chercher dans la table et on garde en memoire
4576
+    $demande_titre = ($info == 'titre');
4577
+
4578
+    // 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
4579
+    if (!isset($objets[$type_objet][$id_objet])
4580
+        or
4581
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4582
+    ) {
4583
+        if (!$trouver_table) {
4584
+            $trouver_table = charger_fonction('trouver_table', 'base');
4585
+        }
4586
+        $desc = $trouver_table(table_objet_sql($type_objet));
4587
+        if (!$desc) {
4588
+            return $objets[$type_objet] = false;
4589
+        }
4590
+
4591
+        // Si on demande le titre, on le gere en interne
4592
+        $champ_titre = "";
4593
+        if ($demande_titre) {
4594
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4595
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4596
+        }
4597
+        include_spip('base/abstract_sql');
4598
+        include_spip('base/connect_sql');
4599
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4600
+            '*' . $champ_titre,
4601
+            $desc['table_sql'],
4602
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4603
+        );
4604
+    }
4605
+
4606
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4607
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4608
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4609
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4610
+    else {
4611
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4612
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4613
+        } // Sinon on prend directement le champ SQL tel quel
4614
+        else {
4615
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4616
+        }
4617
+    }
4618
+
4619
+    // On va ensuite appliquer les traitements automatiques si besoin
4620
+    if (!$etoile) {
4621
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4622
+        // mais ce fonctionnement est a ameliorer !
4623
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4624
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4625
+    }
4626
+
4627
+    return $info_generee;
4628 4628
 }
4629 4629
 
4630 4630
 /**
@@ -4638,44 +4638,44 @@  discard block
 block discarded – undo
4638 4638
  * @return string
4639 4639
  */
4640 4640
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4641
-	if (!$champ) {
4642
-		return $texte;
4643
-	}
4641
+    if (!$champ) {
4642
+        return $texte;
4643
+    }
4644 4644
 	
4645
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4646
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4647
-	include_spip('inc/texte');
4645
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4646
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4647
+    include_spip('inc/texte');
4648 4648
 	
4649
-	$champ = strtoupper($champ);
4650
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4651
-	if (!$traitements or !is_array($traitements)) {
4652
-		return $texte;
4653
-	}
4649
+    $champ = strtoupper($champ);
4650
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4651
+    if (!$traitements or !is_array($traitements)) {
4652
+        return $texte;
4653
+    }
4654 4654
 
4655
-	$traitement = '';
4656
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4657
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4658
-		$table_objet = table_objet($table_objet);
4659
-		if (isset($traitements[$table_objet])) {
4660
-			$traitement = $traitements[$table_objet];
4661
-		}
4662
-	}
4663
-	if (!$traitement and isset($traitements[0])) {
4664
-		$traitement = $traitements[0];
4665
-	}
4666
-	// (sinon prendre le premier de la liste par defaut ?)
4655
+    $traitement = '';
4656
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4657
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4658
+        $table_objet = table_objet($table_objet);
4659
+        if (isset($traitements[$table_objet])) {
4660
+            $traitement = $traitements[$table_objet];
4661
+        }
4662
+    }
4663
+    if (!$traitement and isset($traitements[0])) {
4664
+        $traitement = $traitements[0];
4665
+    }
4666
+    // (sinon prendre le premier de la liste par defaut ?)
4667 4667
 
4668
-	if (!$traitement) {
4669
-		return $texte;
4670
-	}
4668
+    if (!$traitement) {
4669
+        return $texte;
4670
+    }
4671 4671
 
4672
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4672
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4673 4673
 
4674
-	// Fournir $connect et $Pile[0] au traitement si besoin
4675
-	$Pile = array(0 => $env);
4676
-	eval("\$texte = $traitement;");
4674
+    // Fournir $connect et $Pile[0] au traitement si besoin
4675
+    $Pile = array(0 => $env);
4676
+    eval("\$texte = $traitement;");
4677 4677
 
4678
-	return $texte;
4678
+    return $texte;
4679 4679
 }
4680 4680
 
4681 4681
 
@@ -4689,21 +4689,21 @@  discard block
 block discarded – undo
4689 4689
  * @return string
4690 4690
  */
4691 4691
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4692
-	include_spip('inc/liens');
4693
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4694
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4695
-	// le raccourcis n'est plus valide
4696
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4697
-	// on essaye avec generer_info_entite ?
4698
-	if (!strlen($titre) and !$connect) {
4699
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4700
-	}
4701
-	if (!strlen($titre)) {
4702
-		$titre = _T('info_sans_titre');
4703
-	}
4704
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4692
+    include_spip('inc/liens');
4693
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4694
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4695
+    // le raccourcis n'est plus valide
4696
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4697
+    // on essaye avec generer_info_entite ?
4698
+    if (!strlen($titre) and !$connect) {
4699
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4700
+    }
4701
+    if (!strlen($titre)) {
4702
+        $titre = _T('info_sans_titre');
4703
+    }
4704
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4705 4705
 
4706
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4706
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4707 4707
 }
4708 4708
 
4709 4709
 
@@ -4720,15 +4720,15 @@  discard block
 block discarded – undo
4720 4720
  * @return string
4721 4721
  */
4722 4722
 function wrap($texte, $wrap) {
4723
-	$balises = extraire_balises($wrap);
4724
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4725
-		$texte = $wrap . $texte;
4726
-		$regs = array_reverse($regs[1]);
4727
-		$wrap = "</" . implode("></", $regs) . ">";
4728
-		$texte = $texte . $wrap;
4729
-	}
4723
+    $balises = extraire_balises($wrap);
4724
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4725
+        $texte = $wrap . $texte;
4726
+        $regs = array_reverse($regs[1]);
4727
+        $wrap = "</" . implode("></", $regs) . ">";
4728
+        $texte = $texte . $wrap;
4729
+    }
4730 4730
 
4731
-	return $texte;
4731
+    return $texte;
4732 4732
 }
4733 4733
 
4734 4734
 
@@ -4748,43 +4748,43 @@  discard block
 block discarded – undo
4748 4748
  * @return array|mixed|string
4749 4749
  */
4750 4750
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4751
-	if (is_string($u)) {
4752
-		$u = typo($u);
4751
+    if (is_string($u)) {
4752
+        $u = typo($u);
4753 4753
 
4754
-		return $u;
4755
-	}
4754
+        return $u;
4755
+    }
4756 4756
 
4757
-	// caster $u en array si besoin
4758
-	if (is_object($u)) {
4759
-		$u = (array)$u;
4760
-	}
4757
+    // caster $u en array si besoin
4758
+    if (is_object($u)) {
4759
+        $u = (array)$u;
4760
+    }
4761 4761
 
4762
-	if (is_array($u)) {
4763
-		$out = "";
4764
-		// toutes les cles sont numeriques ?
4765
-		// et aucun enfant n'est un tableau
4766
-		// liste simple separee par des virgules
4767
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4768
-		$array_values = array_map('is_array', $u);
4769
-		$object_values = array_map('is_object', $u);
4770
-		if (array_sum($numeric_keys) == count($numeric_keys)
4771
-			and !array_sum($array_values)
4772
-			and !array_sum($object_values)
4773
-		) {
4774
-			return join(", ", array_map('filtre_print_dist', $u));
4775
-		}
4762
+    if (is_array($u)) {
4763
+        $out = "";
4764
+        // toutes les cles sont numeriques ?
4765
+        // et aucun enfant n'est un tableau
4766
+        // liste simple separee par des virgules
4767
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4768
+        $array_values = array_map('is_array', $u);
4769
+        $object_values = array_map('is_object', $u);
4770
+        if (array_sum($numeric_keys) == count($numeric_keys)
4771
+            and !array_sum($array_values)
4772
+            and !array_sum($object_values)
4773
+        ) {
4774
+            return join(", ", array_map('filtre_print_dist', $u));
4775
+        }
4776 4776
 
4777
-		// sinon on passe a la ligne et on indente
4778
-		$i_str = str_pad("", $indent, " ");
4779
-		foreach ($u as $k => $v) {
4780
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4781
-		}
4777
+        // sinon on passe a la ligne et on indente
4778
+        $i_str = str_pad("", $indent, " ");
4779
+        foreach ($u as $k => $v) {
4780
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4781
+        }
4782 4782
 
4783
-		return $out;
4784
-	}
4783
+        return $out;
4784
+    }
4785 4785
 
4786
-	// on sait pas quoi faire...
4787
-	return $u;
4786
+    // on sait pas quoi faire...
4787
+    return $u;
4788 4788
 }
4789 4789
 
4790 4790
 
@@ -4797,10 +4797,10 @@  discard block
 block discarded – undo
4797 4797
  * @return string|array
4798 4798
  */
4799 4799
 function objet_info($objet, $info) {
4800
-	$table = table_objet_sql($objet);
4801
-	$infos = lister_tables_objets_sql($table);
4800
+    $table = table_objet_sql($objet);
4801
+    $infos = lister_tables_objets_sql($table);
4802 4802
 
4803
-	return (isset($infos[$info]) ? $infos[$info] : '');
4803
+    return (isset($infos[$info]) ? $infos[$info] : '');
4804 4804
 }
4805 4805
 
4806 4806
 /**
@@ -4815,11 +4815,11 @@  discard block
 block discarded – undo
4815 4815
  *     Texte traduit du comptage, tel que '3 articles'
4816 4816
  */
4817 4817
 function objet_afficher_nb($nb, $objet) {
4818
-	if (!$nb) {
4819
-		return _T(objet_info($objet, 'info_aucun_objet'));
4820
-	} else {
4821
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4822
-	}
4818
+    if (!$nb) {
4819
+        return _T(objet_info($objet, 'info_aucun_objet'));
4820
+    } else {
4821
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4822
+    }
4823 4823
 }
4824 4824
 
4825 4825
 /**
@@ -4831,11 +4831,11 @@  discard block
 block discarded – undo
4831 4831
  * @return string
4832 4832
  */
4833 4833
 function objet_icone($objet, $taille = 24, $class='') {
4834
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4835
-	$icone = chemin_image($icone);
4836
-	$balise_img = charger_filtre('balise_img');
4834
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4835
+    $icone = chemin_image($icone);
4836
+    $balise_img = charger_filtre('balise_img');
4837 4837
 
4838
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4838
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4839 4839
 }
4840 4840
 
4841 4841
 /**
@@ -4856,12 +4856,12 @@  discard block
 block discarded – undo
4856 4856
  * @return string
4857 4857
  */
4858 4858
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4859
-	$chaine = explode(':',$chaine);
4860
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4861
-		return $t;
4862
-	}
4863
-	$chaine = implode(':',$chaine);
4864
-	return _T($chaine, $args, $options);
4859
+    $chaine = explode(':',$chaine);
4860
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4861
+        return $t;
4862
+    }
4863
+    $chaine = implode(':',$chaine);
4864
+    return _T($chaine, $args, $options);
4865 4865
 }
4866 4866
 
4867 4867
 /**
@@ -4875,17 +4875,17 @@  discard block
 block discarded – undo
4875 4875
  * @return string      Code HTML
4876 4876
  */
4877 4877
 function insert_head_css_conditionnel($flux) {
4878
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4879
-		and $p = strpos($flux, '<!-- insert_head -->')
4880
-	) {
4881
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4882
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4883
-			$p = $p1;
4884
-		}
4885
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4886
-	}
4878
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4879
+        and $p = strpos($flux, '<!-- insert_head -->')
4880
+    ) {
4881
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4882
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4883
+            $p = $p1;
4884
+        }
4885
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4886
+    }
4887 4887
 
4888
-	return $flux;
4888
+    return $flux;
4889 4889
 }
4890 4890
 
4891 4891
 /**
@@ -4906,69 +4906,69 @@  discard block
 block discarded – undo
4906 4906
  * @return string
4907 4907
  */
4908 4908
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4909
-	if (isset($contexte['format'])) {
4910
-		$extension = $contexte['format'];
4911
-		unset($contexte['format']);
4912
-	} else {
4913
-		$extension = "html";
4914
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4915
-			$extension = $m[1];
4916
-		}
4917
-	}
4918
-	// recuperer le contenu produit par le squelette
4919
-	$options['raw'] = true;
4920
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4921
-
4922
-	// calculer le nom de la css
4923
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4924
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4925
-	$contexte_implicite = calculer_contexte_implicite();
4926
-
4927
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4928
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4929
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4930
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4931
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4932
-	}
4933
-	else {
4934
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4935
-		ksort($contexte);
4936
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4937
-	}
4938
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4939
-
4940
-	// mettre a jour le fichier si il n'existe pas
4941
-	// ou trop ancien
4942
-	// le dernier fichier produit est toujours suffixe par .last
4943
-	// et recopie sur le fichier cible uniquement si il change
4944
-	if (!file_exists($filename)
4945
-		or !file_exists($filename . ".last")
4946
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4947
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4948
-	) {
4949
-		$contenu = $cache['texte'];
4950
-		// passer les urls en absolu si c'est une css
4951
-		if ($extension == "css") {
4952
-			$contenu = urls_absolues_css($contenu,
4953
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4954
-		}
4955
-
4956
-		$comment = '';
4957
-		// ne pas insérer de commentaire si c'est du json
4958
-		if ($extension != "json") {
4959
-			$comment = "/* #PRODUIRE{fond=$fond";
4960
-			foreach ($contexte as $k => $v) {
4961
-				$comment .= ",$k=$v";
4962
-			}
4963
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4964
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4965
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4966
-		}
4967
-		// et ecrire le fichier si il change
4968
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4969
-	}
4970
-
4971
-	return timestamp($filename);
4909
+    if (isset($contexte['format'])) {
4910
+        $extension = $contexte['format'];
4911
+        unset($contexte['format']);
4912
+    } else {
4913
+        $extension = "html";
4914
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4915
+            $extension = $m[1];
4916
+        }
4917
+    }
4918
+    // recuperer le contenu produit par le squelette
4919
+    $options['raw'] = true;
4920
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4921
+
4922
+    // calculer le nom de la css
4923
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4924
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4925
+    $contexte_implicite = calculer_contexte_implicite();
4926
+
4927
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4928
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4929
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4930
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4931
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4932
+    }
4933
+    else {
4934
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4935
+        ksort($contexte);
4936
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4937
+    }
4938
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4939
+
4940
+    // mettre a jour le fichier si il n'existe pas
4941
+    // ou trop ancien
4942
+    // le dernier fichier produit est toujours suffixe par .last
4943
+    // et recopie sur le fichier cible uniquement si il change
4944
+    if (!file_exists($filename)
4945
+        or !file_exists($filename . ".last")
4946
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4947
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4948
+    ) {
4949
+        $contenu = $cache['texte'];
4950
+        // passer les urls en absolu si c'est une css
4951
+        if ($extension == "css") {
4952
+            $contenu = urls_absolues_css($contenu,
4953
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4954
+        }
4955
+
4956
+        $comment = '';
4957
+        // ne pas insérer de commentaire si c'est du json
4958
+        if ($extension != "json") {
4959
+            $comment = "/* #PRODUIRE{fond=$fond";
4960
+            foreach ($contexte as $k => $v) {
4961
+                $comment .= ",$k=$v";
4962
+            }
4963
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4964
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4965
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4966
+        }
4967
+        // et ecrire le fichier si il change
4968
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4969
+    }
4970
+
4971
+    return timestamp($filename);
4972 4972
 }
4973 4973
 
4974 4974
 /**
@@ -4981,14 +4981,14 @@  discard block
 block discarded – undo
4981 4981
  *    $fichier auquel on a ajouté le timestamp
4982 4982
  */
4983 4983
 function timestamp($fichier) {
4984
-	if (!$fichier
4985
-		or !file_exists($fichier)
4986
-		or !$m = filemtime($fichier)
4987
-	) {
4988
-		return $fichier;
4989
-	}
4984
+    if (!$fichier
4985
+        or !file_exists($fichier)
4986
+        or !$m = filemtime($fichier)
4987
+    ) {
4988
+        return $fichier;
4989
+    }
4990 4990
 
4991
-	return "$fichier?$m";
4991
+    return "$fichier?$m";
4992 4992
 }
4993 4993
 
4994 4994
 /**
@@ -4998,11 +4998,11 @@  discard block
 block discarded – undo
4998 4998
  * @return string
4999 4999
  */
5000 5000
 function supprimer_timestamp($url) {
5001
-	if (strpos($url, "?") === false) {
5002
-		return $url;
5003
-	}
5001
+    if (strpos($url, "?") === false) {
5002
+        return $url;
5003
+    }
5004 5004
 
5005
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
5005
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
5006 5006
 }
5007 5007
 
5008 5008
 /**
@@ -5017,9 +5017,9 @@  discard block
 block discarded – undo
5017 5017
  * @return string
5018 5018
  */
5019 5019
 function filtre_nettoyer_titre_email_dist($titre) {
5020
-	include_spip('inc/envoyer_mail');
5020
+    include_spip('inc/envoyer_mail');
5021 5021
 
5022
-	return nettoyer_titre_email($titre);
5022
+    return nettoyer_titre_email($titre);
5023 5023
 }
5024 5024
 
5025 5025
 /**
@@ -5041,19 +5041,19 @@  discard block
 block discarded – undo
5041 5041
  * @return string
5042 5042
  */
5043 5043
 function filtre_chercher_rubrique_dist(
5044
-	$titre,
5045
-	$id_objet,
5046
-	$id_parent,
5047
-	$objet,
5048
-	$id_secteur,
5049
-	$restreint,
5050
-	$actionable = false,
5051
-	$retour_sans_cadre = false
5044
+    $titre,
5045
+    $id_objet,
5046
+    $id_parent,
5047
+    $objet,
5048
+    $id_secteur,
5049
+    $restreint,
5050
+    $actionable = false,
5051
+    $retour_sans_cadre = false
5052 5052
 ) {
5053
-	include_spip('inc/filtres_ecrire');
5053
+    include_spip('inc/filtres_ecrire');
5054 5054
 
5055
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5056
-		$retour_sans_cadre);
5055
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5056
+        $retour_sans_cadre);
5057 5057
 }
5058 5058
 
5059 5059
 /**
@@ -5082,56 +5082,56 @@  discard block
 block discarded – undo
5082 5082
  *     Chaîne vide si l'accès est autorisé
5083 5083
  */
5084 5084
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5085
-	if ($ok) {
5086
-		return '';
5087
-	}
5088
-
5089
-	// Vider tous les tampons
5090
-	$level = @ob_get_level();
5091
-	while ($level--) {
5092
-		@ob_end_clean();
5093
-	}
5094
-
5095
-	include_spip('inc/headers');
5096
-
5097
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5098
-	if ($url) {
5099
-		redirige_par_entete($url, '', $statut);
5100
-	}
5101
-
5102
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5103
-	if (!is_numeric($statut) and is_null($message)) {
5104
-		$message = $statut;
5105
-		$statut = 0;
5106
-	}
5107
-	if (!$message) {
5108
-		$message = '';
5109
-	}
5110
-	$statut = intval($statut);
5111
-
5112
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5113
-	if (test_espace_prive()) {
5114
-		if (!$statut or !in_array($statut, array(404, 403))) {
5115
-			$statut = 403;
5116
-		}
5117
-		http_status(403);
5118
-		$echec = charger_fonction('403', 'exec');
5119
-		$echec($message);
5120
-	} else {
5121
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5122
-		if (!$statut) {
5123
-			$statut = 404;
5124
-		}
5125
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5126
-		http_status($statut);
5127
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5128
-		if ($statut >= 400) {
5129
-			echo recuperer_fond("$statut", array('erreur' => $message));
5130
-		}
5131
-	}
5132
-
5133
-
5134
-	exit;
5085
+    if ($ok) {
5086
+        return '';
5087
+    }
5088
+
5089
+    // Vider tous les tampons
5090
+    $level = @ob_get_level();
5091
+    while ($level--) {
5092
+        @ob_end_clean();
5093
+    }
5094
+
5095
+    include_spip('inc/headers');
5096
+
5097
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5098
+    if ($url) {
5099
+        redirige_par_entete($url, '', $statut);
5100
+    }
5101
+
5102
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5103
+    if (!is_numeric($statut) and is_null($message)) {
5104
+        $message = $statut;
5105
+        $statut = 0;
5106
+    }
5107
+    if (!$message) {
5108
+        $message = '';
5109
+    }
5110
+    $statut = intval($statut);
5111
+
5112
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5113
+    if (test_espace_prive()) {
5114
+        if (!$statut or !in_array($statut, array(404, 403))) {
5115
+            $statut = 403;
5116
+        }
5117
+        http_status(403);
5118
+        $echec = charger_fonction('403', 'exec');
5119
+        $echec($message);
5120
+    } else {
5121
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5122
+        if (!$statut) {
5123
+            $statut = 404;
5124
+        }
5125
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5126
+        http_status($statut);
5127
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5128
+        if ($statut >= 400) {
5129
+            echo recuperer_fond("$statut", array('erreur' => $message));
5130
+        }
5131
+    }
5132
+
5133
+
5134
+    exit;
5135 5135
 }
5136 5136
 
5137 5137
 /**
@@ -5142,11 +5142,11 @@  discard block
 block discarded – undo
5142 5142
  * @return string
5143 5143
  */
5144 5144
 function filtre_compacte_dist($source, $format = null) {
5145
-	if (function_exists('compacte')) {
5146
-		return compacte($source, $format);
5147
-	}
5145
+    if (function_exists('compacte')) {
5146
+        return compacte($source, $format);
5147
+    }
5148 5148
 
5149
-	return $source;
5149
+    return $source;
5150 5150
 }
5151 5151
 
5152 5152
 
@@ -5158,31 +5158,31 @@  discard block
 block discarded – undo
5158 5158
  * @return string
5159 5159
  */
5160 5160
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5161
-	$l = strlen($passe);
5162
-
5163
-	if ($l<=8 or !$afficher_partiellement){
5164
-		if (!$l) {
5165
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5166
-		}
5167
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
5168
-	}
5169
-
5170
-	if (is_null($portion_pourcent)) {
5171
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5172
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5173
-		}
5174
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5175
-	}
5176
-	if ($portion_pourcent >= 100) {
5177
-		return $passe;
5178
-	}
5179
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5180
-	$e = max($e, 0);
5181
-	$mid = str_pad('',$l-2*$e,'*');
5182
-	if ($e>0 and strlen($mid)>8){
5183
-		$mid = '***...***';
5184
-	}
5185
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5161
+    $l = strlen($passe);
5162
+
5163
+    if ($l<=8 or !$afficher_partiellement){
5164
+        if (!$l) {
5165
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5166
+        }
5167
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
5168
+    }
5169
+
5170
+    if (is_null($portion_pourcent)) {
5171
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5172
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5173
+        }
5174
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5175
+    }
5176
+    if ($portion_pourcent >= 100) {
5177
+        return $passe;
5178
+    }
5179
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5180
+    $e = max($e, 0);
5181
+    $mid = str_pad('',$l-2*$e,'*');
5182
+    if ($e>0 and strlen($mid)>8){
5183
+        $mid = '***...***';
5184
+    }
5185
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5186 5186
 }
5187 5187
 
5188 5188
 
@@ -5203,62 +5203,62 @@  discard block
 block discarded – undo
5203 5203
  */
5204 5204
 function identifiant_slug($texte, $type = '', $options = array()) {
5205 5205
 
5206
-	$original = $texte;
5207
-	$separateur = (isset($options['separateur'])?$options['separateur']:'_');
5208
-	$longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5209
-	$longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5210
-
5211
-	if (!function_exists('translitteration')) {
5212
-		include_spip('inc/charsets');
5213
-	}
5214
-
5215
-	// pas de balise html
5216
-	if (strpos($texte, '<') !== false) {
5217
-		$texte = strip_tags($texte);
5218
-	}
5219
-	if (strpos($texte, '&') !== false) {
5220
-		$texte = unicode2charset($texte);
5221
-	}
5222
-	// On enlève les espaces indésirables
5223
-	$texte = trim($texte);
5224
-
5225
-	// On enlève les accents et cie
5226
-	$texte = translitteration($texte);
5227
-
5228
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5229
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5230
-
5231
-	// nettoyer les doubles occurences du separateur si besoin
5232
-	while (strpos($texte, "$separateur$separateur") !== false) {
5233
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5234
-	}
5235
-
5236
-	// pas de separateur au debut ni a la fin
5237
-	$texte = trim($texte, $separateur);
5238
-
5239
-	// en minuscules
5240
-	$texte = strtolower($texte);
5241
-
5242
-	switch ($type) {
5243
-		case 'class':
5244
-		case 'id':
5245
-		case 'anchor':
5246
-			if (preg_match(',^\d,', $texte)) {
5247
-				$texte = substr($type, 0, 1).$texte;
5248
-			}
5249
-	}
5250
-
5251
-	if (strlen($texte)>$longueur_maxi) {
5252
-		$texte = substr($texte, 0, $longueur_maxi);
5253
-	}
5254
-
5255
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5256
-		if (preg_match(',^\d,', $texte)) {
5257
-			$texte = ($type ? substr($type,0,1) : "s") . $texte;
5258
-		}
5259
-		$texte .= $separateur . md5($original);
5260
-		$texte = substr($texte, 0, $longueur_mini);
5261
-	}
5262
-
5263
-	return $texte;
5206
+    $original = $texte;
5207
+    $separateur = (isset($options['separateur'])?$options['separateur']:'_');
5208
+    $longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5209
+    $longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5210
+
5211
+    if (!function_exists('translitteration')) {
5212
+        include_spip('inc/charsets');
5213
+    }
5214
+
5215
+    // pas de balise html
5216
+    if (strpos($texte, '<') !== false) {
5217
+        $texte = strip_tags($texte);
5218
+    }
5219
+    if (strpos($texte, '&') !== false) {
5220
+        $texte = unicode2charset($texte);
5221
+    }
5222
+    // On enlève les espaces indésirables
5223
+    $texte = trim($texte);
5224
+
5225
+    // On enlève les accents et cie
5226
+    $texte = translitteration($texte);
5227
+
5228
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5229
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5230
+
5231
+    // nettoyer les doubles occurences du separateur si besoin
5232
+    while (strpos($texte, "$separateur$separateur") !== false) {
5233
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5234
+    }
5235
+
5236
+    // pas de separateur au debut ni a la fin
5237
+    $texte = trim($texte, $separateur);
5238
+
5239
+    // en minuscules
5240
+    $texte = strtolower($texte);
5241
+
5242
+    switch ($type) {
5243
+        case 'class':
5244
+        case 'id':
5245
+        case 'anchor':
5246
+            if (preg_match(',^\d,', $texte)) {
5247
+                $texte = substr($type, 0, 1).$texte;
5248
+            }
5249
+    }
5250
+
5251
+    if (strlen($texte)>$longueur_maxi) {
5252
+        $texte = substr($texte, 0, $longueur_maxi);
5253
+    }
5254
+
5255
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5256
+        if (preg_match(',^\d,', $texte)) {
5257
+            $texte = ($type ? substr($type,0,1) : "s") . $texte;
5258
+        }
5259
+        $texte .= $separateur . md5($original);
5260
+        $texte = substr($texte, 0, $longueur_mini);
5261
+    }
5262
+
5263
+    return $texte;
5264 5264
 }
Please login to merge, or discard this patch.
ecrire/public/fonctions.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 
@@ -52,75 +52,75 @@  discard block
 block discarded – undo
52 52
  *     Introduction calculée
53 53
  **/
54 54
 function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) {
55
-	// Si un descriptif est envoye, on l'utilise directement
56
-	if (strlen($descriptif)) {
57
-		return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect);
58
-	}
59
-
60
-	// De preference ce qui est marque <intro>...</intro>
61
-	$intro = '';
62
-	$texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules
63
-	while ($fin = strpos($texte, "</intro>")) {
64
-		$zone = substr($texte, 0, $fin);
65
-		$texte = substr($texte, $fin + strlen("</intro>"));
66
-		if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") {
67
-			$zone = substr($zone, $deb + 7);
68
-		}
69
-		$intro .= $zone;
70
-	}
71
-
72
-	// [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
-	// qui inclus raccourcis et modeles
74
-	// un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
-	// par ailleurs le nettoyage des raccourcis ne tient pas compte
76
-	// des surcharges et enrichissement de propre
77
-	// couper doit se faire apres propre
78
-	//$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
-
80
-	// Cependant pour des questions de perfs on coupe quand meme, en prenant
81
-	// large et en se mefiant des tableaux #1323
82
-
83
-	if (strlen($intro)) {
84
-		$texte = $intro;
85
-	} else {
86
-		if (strpos("\n" . $texte, "\n|") === false
87
-			and strlen($texte) > 2.5 * $longueur
88
-		) {
89
-			if (strpos($texte, "<multi") !== false) {
90
-				$texte = extraire_multi($texte);
91
-			}
92
-			$texte = couper($texte, 2 * $longueur);
93
-		}
94
-	}
95
-
96
-	// ne pas tenir compte des notes
97
-	if ($notes = charger_fonction('notes', 'inc', true)) {
98
-		$notes('', 'empiler');
99
-	}
100
-	// Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
101
-	// dans l'introduction.
102
-	$texte = supprime_img($texte, '');
103
-	$texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect);
104
-
105
-	if ($notes) {
106
-		$notes('', 'depiler');
107
-	}
108
-
109
-	if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
110
-		$suite = _INTRODUCTION_SUITE;
111
-	}
112
-	$texte = couper($texte, $longueur, $suite);
113
-	// comme on a coupe il faut repasser la typo (on a perdu les insecables)
114
-	$texte = typo($texte, true, $connect, array());
115
-
116
-	// et reparagrapher si necessaire (coherence avec le cas descriptif)
117
-	// une introduction a tojours un <p>
118
-	if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes
119
-	{
120
-		$texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
-	}
122
-
123
-	return $texte;
55
+    // Si un descriptif est envoye, on l'utilise directement
56
+    if (strlen($descriptif)) {
57
+        return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect);
58
+    }
59
+
60
+    // De preference ce qui est marque <intro>...</intro>
61
+    $intro = '';
62
+    $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules
63
+    while ($fin = strpos($texte, "</intro>")) {
64
+        $zone = substr($texte, 0, $fin);
65
+        $texte = substr($texte, $fin + strlen("</intro>"));
66
+        if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") {
67
+            $zone = substr($zone, $deb + 7);
68
+        }
69
+        $intro .= $zone;
70
+    }
71
+
72
+    // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut,
73
+    // qui inclus raccourcis et modeles
74
+    // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ...
75
+    // par ailleurs le nettoyage des raccourcis ne tient pas compte
76
+    // des surcharges et enrichissement de propre
77
+    // couper doit se faire apres propre
78
+    //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect);
79
+
80
+    // Cependant pour des questions de perfs on coupe quand meme, en prenant
81
+    // large et en se mefiant des tableaux #1323
82
+
83
+    if (strlen($intro)) {
84
+        $texte = $intro;
85
+    } else {
86
+        if (strpos("\n" . $texte, "\n|") === false
87
+            and strlen($texte) > 2.5 * $longueur
88
+        ) {
89
+            if (strpos($texte, "<multi") !== false) {
90
+                $texte = extraire_multi($texte);
91
+            }
92
+            $texte = couper($texte, 2 * $longueur);
93
+        }
94
+    }
95
+
96
+    // ne pas tenir compte des notes
97
+    if ($notes = charger_fonction('notes', 'inc', true)) {
98
+        $notes('', 'empiler');
99
+    }
100
+    // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable
101
+    // dans l'introduction.
102
+    $texte = supprime_img($texte, '');
103
+    $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect);
104
+
105
+    if ($notes) {
106
+        $notes('', 'depiler');
107
+    }
108
+
109
+    if (is_null($suite) and defined('_INTRODUCTION_SUITE')) {
110
+        $suite = _INTRODUCTION_SUITE;
111
+    }
112
+    $texte = couper($texte, $longueur, $suite);
113
+    // comme on a coupe il faut repasser la typo (on a perdu les insecables)
114
+    $texte = typo($texte, true, $connect, array());
115
+
116
+    // et reparagrapher si necessaire (coherence avec le cas descriptif)
117
+    // une introduction a tojours un <p>
118
+    if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes
119
+    {
120
+        $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
121
+    }
122
+
123
+    return $texte;
124 124
 }
125 125
 
126 126
 
@@ -155,59 +155,59 @@  discard block
 block discarded – undo
155 155
  *     Code HTML de la pagination
156 156
  **/
157 157
 function filtre_pagination_dist(
158
-	$total,
159
-	$nom,
160
-	$position,
161
-	$pas,
162
-	$liste = true,
163
-	$modele = '',
164
-	$connect = '',
165
-	$env = array()
158
+    $total,
159
+    $nom,
160
+    $position,
161
+    $pas,
162
+    $liste = true,
163
+    $modele = '',
164
+    $connect = '',
165
+    $env = array()
166 166
 ) {
167
-	static $ancres = array();
168
-	if ($pas < 1) {
169
-		return '';
170
-	}
171
-	$ancre = 'pagination' . $nom; // #pagination_articles
172
-	$debut = 'debut' . $nom; // 'debut_articles'
173
-
174
-	// n'afficher l'ancre qu'une fois
175
-	if (!isset($ancres[$ancre])) {
176
-		$bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
-	} else {
178
-		$bloc_ancre = '';
179
-	}
180
-	// liste = false : on ne veut que l'ancre
181
-	if (!$liste) {
182
-		return $ancres[$ancre];
183
-	}
184
-
185
-	$self = (empty($env['self']) ? self() : $env['self']);
186
-	$pagination = array(
187
-		'debut' => $debut,
188
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
-		'total' => $total,
190
-		'position' => intval($position),
191
-		'pas' => $pas,
192
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
-		'page_courante' => floor(intval($position) / $pas) + 1,
194
-		'ancre' => $ancre,
195
-		'bloc_ancre' => $bloc_ancre
196
-	);
197
-	if (is_array($env)) {
198
-		$pagination = array_merge($env, $pagination);
199
-	}
200
-
201
-	// Pas de pagination
202
-	if ($pagination['nombre_pages'] <= 1) {
203
-		return '';
204
-	}
205
-
206
-	if ($modele) {
207
-		$modele = '_' . $modele;
208
-	}
209
-
210
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
167
+    static $ancres = array();
168
+    if ($pas < 1) {
169
+        return '';
170
+    }
171
+    $ancre = 'pagination' . $nom; // #pagination_articles
172
+    $debut = 'debut' . $nom; // 'debut_articles'
173
+
174
+    // n'afficher l'ancre qu'une fois
175
+    if (!isset($ancres[$ancre])) {
176
+        $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>";
177
+    } else {
178
+        $bloc_ancre = '';
179
+    }
180
+    // liste = false : on ne veut que l'ancre
181
+    if (!$liste) {
182
+        return $ancres[$ancre];
183
+    }
184
+
185
+    $self = (empty($env['self']) ? self() : $env['self']);
186
+    $pagination = array(
187
+        'debut' => $debut,
188
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
189
+        'total' => $total,
190
+        'position' => intval($position),
191
+        'pas' => $pas,
192
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
193
+        'page_courante' => floor(intval($position) / $pas) + 1,
194
+        'ancre' => $ancre,
195
+        'bloc_ancre' => $bloc_ancre
196
+    );
197
+    if (is_array($env)) {
198
+        $pagination = array_merge($env, $pagination);
199
+    }
200
+
201
+    // Pas de pagination
202
+    if ($pagination['nombre_pages'] <= 1) {
203
+        return '';
204
+    }
205
+
206
+    if ($modele) {
207
+        $modele = '_' . $modele;
208
+    }
209
+
210
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
211 211
 }
212 212
 
213 213
 
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
  **/
222 222
 function lister_objets_avec_logos($type) {
223 223
 
224
-	$objet = objet_type($type);
225
-	$ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet));
226
-	if ($ids) {
227
-		$ids = array_column($ids, 'id_objet');
228
-		return implode(',', $ids);
229
-	}
230
-	else {
231
-		return "0";
232
-	}
224
+    $objet = objet_type($type);
225
+    $ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet));
226
+    if ($ids) {
227
+        $ids = array_column($ids, 'id_objet');
228
+        return implode(',', $ids);
229
+    }
230
+    else {
231
+        return "0";
232
+    }
233 233
 }
234 234
 
235 235
 
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
  *     Code HTML des notes
246 246
  **/
247 247
 function calculer_notes() {
248
-	$r = '';
249
-	if ($notes = charger_fonction('notes', 'inc', true)) {
250
-		$r = $notes(array());
251
-		$notes('', 'depiler');
252
-		$notes('', 'empiler');
253
-	}
254
-
255
-	return $r;
248
+    $r = '';
249
+    if ($notes = charger_fonction('notes', 'inc', true)) {
250
+        $r = $notes(array());
251
+        $notes('', 'depiler');
252
+        $notes('', 'empiler');
253
+    }
254
+
255
+    return $r;
256 256
 }
257 257
 
258 258
 
@@ -269,10 +269,10 @@  discard block
 block discarded – undo
269 269
  * @return string
270 270
  */
271 271
 function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien){
272
-	$res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
273
-	$res = array_column($res, 'rang_lien', $objet_source);
272
+    $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien);
273
+    $res = array_column($res, 'rang_lien', $objet_source);
274 274
 
275
-	return (isset($res[$ids]) ? $res[$ids] : '');
275
+    return (isset($res[$ids]) ? $res[$ids] : '');
276 276
 }
277 277
 
278 278
 
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
  * @private
290 290
  */
291 291
 function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) {
292
-	static $liens = array();
293
-	if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
294
-		include_spip('action/editer_liens');
295
-		// quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
296
-		if ($objet_lien == $objet and $objet_lien !== $objet_source) {
297
-			$res = objet_trouver_liens(array($objet => $id_objet), array($objet_source => '*'));
298
-		} else {
299
-			$res = objet_trouver_liens(array($objet_source => '*'), array($objet => $id_objet));
300
-		}
301
-
302
-		$liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
303
-	}
304
-	return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
292
+    static $liens = array();
293
+    if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) {
294
+        include_spip('action/editer_liens');
295
+        // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source
296
+        if ($objet_lien == $objet and $objet_lien !== $objet_source) {
297
+            $res = objet_trouver_liens(array($objet => $id_objet), array($objet_source => '*'));
298
+        } else {
299
+            $res = objet_trouver_liens(array($objet_source => '*'), array($objet => $id_objet));
300
+        }
301
+
302
+        $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res;
303
+    }
304
+    return $liens["$objet_source-$objet-$id_objet-$objet_lien"];
305 305
 }
306 306
 
307 307
 /**
@@ -315,23 +315,23 @@  discard block
 block discarded – undo
315 315
  * @return int|string
316 316
  */
317 317
 function calculer_rang_smart($titre, $objet_source, $id, $env) {
318
-	// Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
319
-	// permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
320
-	if (isset($env['form']) and $env['form']
321
-		and isset($env['_objet_lien']) and $env['_objet_lien']
322
-		and (function_exists('lien_triables') or include_spip('action/editer_liens'))
323
-		and $r = objet_associable($env['_objet_lien'])
324
-		and list($p, $table_lien) = $r
325
-	  and lien_triables($table_lien)
326
-	  and isset($env['objet']) and $env['objet']
327
-		and isset($env['id_objet']) and $env['id_objet']
328
-		and $objet_source
329
-		and $id = intval($id)
330
-	) {
331
-		$rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
332
-		return ($rang ? $rang : '');
333
-	}
334
-	return recuperer_numero($titre);
318
+    // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien
319
+    // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens
320
+    if (isset($env['form']) and $env['form']
321
+        and isset($env['_objet_lien']) and $env['_objet_lien']
322
+        and (function_exists('lien_triables') or include_spip('action/editer_liens'))
323
+        and $r = objet_associable($env['_objet_lien'])
324
+        and list($p, $table_lien) = $r
325
+      and lien_triables($table_lien)
326
+      and isset($env['objet']) and $env['objet']
327
+        and isset($env['id_objet']) and $env['id_objet']
328
+        and $objet_source
329
+        and $id = intval($id)
330
+    ) {
331
+        $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']);
332
+        return ($rang ? $rang : '');
333
+    }
334
+    return recuperer_numero($titre);
335 335
 }
336 336
 
337 337
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
  * @return string
344 344
  */
345 345
 function tri_protege_champ($t) {
346
-	return preg_replace(',[^\s\w.+],', '', $t);
346
+    return preg_replace(',[^\s\w.+],', '', $t);
347 347
 }
348 348
 
349 349
 /**
@@ -356,34 +356,34 @@  discard block
 block discarded – undo
356 356
  * @return string
357 357
  */
358 358
 function tri_champ_order($t, $from = null) {
359
-	if (strncmp($t, 'multi ', 6) == 0) {
360
-		return "multi";
361
-	}
362
-
363
-	$champ = $t;
364
-
365
-	if (strncmp($t, 'num ', 4) == 0) {
366
-		$champ = substr($t, 4);
367
-	}
368
-	// enlever les autres espaces non evacues par tri_protege_champ
369
-	$champ = preg_replace(',\s,', '', $champ);
370
-
371
-	if (is_array($from)) {
372
-		$trouver_table = charger_fonction('trouver_table', 'base');
373
-		foreach ($from as $idt => $table_sql) {
374
-			if ($desc = $trouver_table($table_sql)
375
-				and isset($desc['field'][$champ])
376
-			) {
377
-				$champ = "$idt.$champ";
378
-				break;
379
-			}
380
-		}
381
-	}
382
-	if (strncmp($t, 'num ', 4) == 0) {
383
-		return "0+$champ";
384
-	} else {
385
-		return $champ;
386
-	}
359
+    if (strncmp($t, 'multi ', 6) == 0) {
360
+        return "multi";
361
+    }
362
+
363
+    $champ = $t;
364
+
365
+    if (strncmp($t, 'num ', 4) == 0) {
366
+        $champ = substr($t, 4);
367
+    }
368
+    // enlever les autres espaces non evacues par tri_protege_champ
369
+    $champ = preg_replace(',\s,', '', $champ);
370
+
371
+    if (is_array($from)) {
372
+        $trouver_table = charger_fonction('trouver_table', 'base');
373
+        foreach ($from as $idt => $table_sql) {
374
+            if ($desc = $trouver_table($table_sql)
375
+                and isset($desc['field'][$champ])
376
+            ) {
377
+                $champ = "$idt.$champ";
378
+                break;
379
+            }
380
+        }
381
+    }
382
+    if (strncmp($t, 'num ', 4) == 0) {
383
+        return "0+$champ";
384
+    } else {
385
+        return $champ;
386
+    }
387 387
 }
388 388
 
389 389
 /**
@@ -397,18 +397,18 @@  discard block
 block discarded – undo
397 397
  * @return string
398 398
  */
399 399
 function tri_champ_select($t) {
400
-	if (strncmp($t, 'multi ', 6) == 0) {
401
-		$t = substr($t, 6);
402
-		$t = preg_replace(',\s,', '', $t);
403
-		$t = sql_multi($t, $GLOBALS['spip_lang']);
404
-
405
-		return $t;
406
-	}
407
-	if (trim($t) == 'hasard') {
408
-		return 'rand() AS hasard';
409
-	}
410
-
411
-	return "''";
400
+    if (strncmp($t, 'multi ', 6) == 0) {
401
+        $t = substr($t, 6);
402
+        $t = preg_replace(',\s,', '', $t);
403
+        $t = sql_multi($t, $GLOBALS['spip_lang']);
404
+
405
+        return $t;
406
+    }
407
+    if (trim($t) == 'hasard') {
408
+        return 'rand() AS hasard';
409
+    }
410
+
411
+    return "''";
412 412
 }
413 413
 
414 414
 /**
@@ -420,16 +420,16 @@  discard block
 block discarded – undo
420 420
  * @return string
421 421
  */
422 422
 function formate_liste_critere_par_ordre_liste($valeurs, $serveur = ''){
423
-	if (!is_array($valeurs)){
424
-		return '';
425
-	}
426
-	$f = sql_serveur('quote', $serveur, true);
427
-	if (!is_string($f) or !$f){
428
-		return '';
429
-	}
430
-	$valeurs = implode(',', array_map($f, array_unique($valeurs)));
431
-
432
-	return $valeurs;
423
+    if (!is_array($valeurs)){
424
+        return '';
425
+    }
426
+    $f = sql_serveur('quote', $serveur, true);
427
+    if (!is_string($f) or !$f){
428
+        return '';
429
+    }
430
+    $valeurs = implode(',', array_map($f, array_unique($valeurs)));
431
+
432
+    return $valeurs;
433 433
 }
434 434
 
435 435
 /**
@@ -452,20 +452,20 @@  discard block
 block discarded – undo
452 452
  *     Valeur $defaut sinon.
453 453
  **/
454 454
 function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') {
455
-	// Si c'est un filtre d'image, on utilise image_filtrer()
456
-	// Attention : les 2 premiers arguments sont inversés dans ce cas
457
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
458
-		$args[1] = $args[0];
459
-		$args[0] = $filtre;
460
-		return image_graver(image_filtrer($args));
461
-	}
462
-
463
-	$f = chercher_filtre($filtre);
464
-	if (!$f) {
465
-		return $defaut;
466
-	}
467
-	array_shift($args); // enlever $arg
468
-	array_shift($args); // enlever $filtre
469
-	array_unshift($args, $arg); // remettre $arg
470
-	return call_user_func_array($f, $args);
455
+    // Si c'est un filtre d'image, on utilise image_filtrer()
456
+    // Attention : les 2 premiers arguments sont inversés dans ce cas
457
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
458
+        $args[1] = $args[0];
459
+        $args[0] = $filtre;
460
+        return image_graver(image_filtrer($args));
461
+    }
462
+
463
+    $f = chercher_filtre($filtre);
464
+    if (!$f) {
465
+        return $defaut;
466
+    }
467
+    array_shift($args); // enlever $arg
468
+    array_shift($args); // enlever $filtre
469
+    array_unshift($args, $arg); // remettre $arg
470
+    return call_user_func_array($f, $args);
471 471
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2253 added lines, -2254 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,63 +48,63 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = array();
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
-		// si le fichier truc/machin/nom.php n'existe pas,
83
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
-	) {
86
-		include_spip(substr($dossier, 0, -1));
87
-	}
88
-	if (function_exists($f)) {
89
-		return $f;
90
-	}
91
-	if (function_exists($g)) {
92
-		return $g;
93
-	}
94
-
95
-	if ($continue) {
96
-		return $echecs[$f] = false;
97
-	}
98
-
99
-	// Echec : message d'erreur
100
-	spip_log("fonction $nom ($f ou $g) indisponible" .
101
-		($inc ? "" : " (fichier $d absent de $dossier)"));
102
-
103
-	include_spip('inc/minipres');
104
-	echo minipres(_T('forum_titre_erreur'),
105
-		_T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
-		array('all_inline'=>true,'status'=>404));
107
-	exit;
51
+    static $echecs = array();
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
+        // si le fichier truc/machin/nom.php n'existe pas,
83
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
+    ) {
86
+        include_spip(substr($dossier, 0, -1));
87
+    }
88
+    if (function_exists($f)) {
89
+        return $f;
90
+    }
91
+    if (function_exists($g)) {
92
+        return $g;
93
+    }
94
+
95
+    if ($continue) {
96
+        return $echecs[$f] = false;
97
+    }
98
+
99
+    // Echec : message d'erreur
100
+    spip_log("fonction $nom ($f ou $g) indisponible" .
101
+        ($inc ? "" : " (fichier $d absent de $dossier)"));
102
+
103
+    include_spip('inc/minipres');
104
+    echo minipres(_T('forum_titre_erreur'),
105
+        _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
+        array('all_inline'=>true,'status'=>404));
107
+    exit;
108 108
 }
109 109
 
110 110
 /**
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
  * @return bool
115 115
  */
116 116
 function include_once_check($file) {
117
-	if (file_exists($file)) {
118
-		include_once $file;
117
+    if (file_exists($file)) {
118
+        include_once $file;
119 119
 
120
-		return true;
121
-	}
122
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
-	$crash = ($crash ? $crash : array());
124
-	$crash[$file] = true;
125
-	ecrire_meta('message_crash_plugins', serialize($crash));
120
+        return true;
121
+    }
122
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
+    $crash = ($crash ? $crash : array());
124
+    $crash[$file] = true;
125
+    ecrire_meta('message_crash_plugins', serialize($crash));
126 126
 
127
-	return false;
127
+    return false;
128 128
 }
129 129
 
130 130
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
  *     - string : chemin du fichier trouvé
149 149
  **/
150 150
 function include_spip($f, $include = true) {
151
-	return find_in_path($f . '.php', '', $include);
151
+    return find_in_path($f . '.php', '', $include);
152 152
 }
153 153
 
154 154
 /**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
  *     - string : chemin du fichier trouvé
169 169
  **/
170 170
 function require_spip($f) {
171
-	return find_in_path($f . '.php', '', 'required');
171
+    return find_in_path($f . '.php', '', 'required');
172 172
 }
173 173
 
174 174
 
@@ -177,27 +177,27 @@  discard block
 block discarded – undo
177 177
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
178 178
  */
179 179
 function include_fichiers_fonctions() {
180
-	static $done = false;
181
-	if (!$done) {
182
-		include_spip('inc/lang');
183
-
184
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
185
-		// donc il faut l'inclure "en globals"
186
-		if ($f = find_in_path('mes_fonctions.php')) {
187
-			global $dossier_squelettes;
188
-			include_once(_ROOT_CWD . $f);
189
-		}
190
-
191
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
192
-			// chargement optimise precompile
193
-			include_once(_CACHE_PLUGINS_FCT);
194
-		}
195
-		if (test_espace_prive()) {
196
-			include_spip('inc/filtres_ecrire');
197
-		}
198
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
199
-		$done = true;
200
-	}
180
+    static $done = false;
181
+    if (!$done) {
182
+        include_spip('inc/lang');
183
+
184
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
185
+        // donc il faut l'inclure "en globals"
186
+        if ($f = find_in_path('mes_fonctions.php')) {
187
+            global $dossier_squelettes;
188
+            include_once(_ROOT_CWD . $f);
189
+        }
190
+
191
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
192
+            // chargement optimise precompile
193
+            include_once(_CACHE_PLUGINS_FCT);
194
+        }
195
+        if (test_espace_prive()) {
196
+            include_spip('inc/filtres_ecrire');
197
+        }
198
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
199
+        $done = true;
200
+    }
201 201
 }
202 202
 
203 203
 /**
@@ -223,22 +223,22 @@  discard block
 block discarded – undo
223 223
  *     Les paramètres du pipeline modifiés
224 224
  **/
225 225
 function minipipe($fonc, &$val) {
226
-	// fonction
227
-	if (function_exists($fonc)) {
228
-		$val = call_user_func($fonc, $val);
229
-	} // Class::Methode
230
-	else {
231
-		if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
232
-			and $methode = array($regs[1], $regs[2])
233
-			and is_callable($methode)
234
-		) {
235
-			$val = call_user_func($methode, $val);
236
-		} else {
237
-			spip_log("Erreur - '$fonc' non definie !");
238
-		}
239
-	}
226
+    // fonction
227
+    if (function_exists($fonc)) {
228
+        $val = call_user_func($fonc, $val);
229
+    } // Class::Methode
230
+    else {
231
+        if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
232
+            and $methode = array($regs[1], $regs[2])
233
+            and is_callable($methode)
234
+        ) {
235
+            $val = call_user_func($methode, $val);
236
+        } else {
237
+            spip_log("Erreur - '$fonc' non definie !");
238
+        }
239
+    }
240 240
 
241
-	return $val;
241
+    return $val;
242 242
 }
243 243
 
244 244
 /**
@@ -269,45 +269,45 @@  discard block
 block discarded – undo
269 269
  *     Résultat
270 270
  */
271 271
 function pipeline($action, $val = null) {
272
-	static $charger;
273
-
274
-	// chargement initial des fonctions mises en cache, ou generation du cache
275
-	if (!$charger) {
276
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
277
-			include_spip('inc/plugin');
278
-			// generer les fichiers php precompiles
279
-			// de chargement des plugins et des pipelines
280
-			actualise_plugins_actifs();
281
-			if (!($ok = @is_readable($charger))) {
282
-				spip_log("fichier $charger pas cree");
283
-			}
284
-		}
285
-
286
-		if ($ok) {
287
-			include_once $charger;
288
-		}
289
-	}
290
-
291
-	// appliquer notre fonction si elle existe
292
-	$fonc = 'execute_pipeline_' . strtolower($action);
293
-	if (function_exists($fonc)) {
294
-		$val = $fonc($val);
295
-	} // plantage ?
296
-	else {
297
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
298
-	}
299
-
300
-	// si le flux est une table avec 2 cle args&data
301
-	// on ne ressort du pipe que les donnees dans 'data'
302
-	// array_key_exists pour php 4.1.0
303
-	if (is_array($val)
304
-		and count($val) == 2
305
-		and (array_key_exists('data', $val))
306
-	) {
307
-		$val = $val['data'];
308
-	}
309
-
310
-	return $val;
272
+    static $charger;
273
+
274
+    // chargement initial des fonctions mises en cache, ou generation du cache
275
+    if (!$charger) {
276
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
277
+            include_spip('inc/plugin');
278
+            // generer les fichiers php precompiles
279
+            // de chargement des plugins et des pipelines
280
+            actualise_plugins_actifs();
281
+            if (!($ok = @is_readable($charger))) {
282
+                spip_log("fichier $charger pas cree");
283
+            }
284
+        }
285
+
286
+        if ($ok) {
287
+            include_once $charger;
288
+        }
289
+    }
290
+
291
+    // appliquer notre fonction si elle existe
292
+    $fonc = 'execute_pipeline_' . strtolower($action);
293
+    if (function_exists($fonc)) {
294
+        $val = $fonc($val);
295
+    } // plantage ?
296
+    else {
297
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
298
+    }
299
+
300
+    // si le flux est une table avec 2 cle args&data
301
+    // on ne ressort du pipe que les donnees dans 'data'
302
+    // array_key_exists pour php 4.1.0
303
+    if (is_array($val)
304
+        and count($val) == 2
305
+        and (array_key_exists('data', $val))
306
+    ) {
307
+        $val = $val['data'];
308
+    }
309
+
310
+    return $val;
311 311
 }
312 312
 
313 313
 /**
@@ -351,38 +351,38 @@  discard block
 block discarded – undo
351 351
  *     paramètre est planté pour cause de compatibilité ascendante.
352 352
  */
353 353
 function spip_log($message = null, $name = null) {
354
-	static $pre = array();
355
-	static $log;
356
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
357
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
358
-		$logname = null;
359
-	}
360
-	if (!isset($regs[2])) {
361
-		$niveau = _LOG_INFO;
362
-	}
363
-	else {
364
-		$niveau = intval($regs[2]);
365
-	}
366
-
367
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
368
-		if (!$pre) {
369
-			$pre = array(
370
-				_LOG_HS => 'HS:',
371
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
372
-				_LOG_CRITIQUE => 'CRITIQUE:',
373
-				_LOG_ERREUR => 'ERREUR:',
374
-				_LOG_AVERTISSEMENT => 'WARNING:',
375
-				_LOG_INFO_IMPORTANTE => '!INFO:',
376
-				_LOG_INFO => 'info:',
377
-				_LOG_DEBUG => 'debug:'
378
-			);
379
-			$log = charger_fonction('log', 'inc');
380
-		}
381
-		if (!is_string($message)) {
382
-			$message = print_r($message, true);
383
-		}
384
-		$log($pre[$niveau] . ' ' . $message, $logname);
385
-	}
354
+    static $pre = array();
355
+    static $log;
356
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
357
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
358
+        $logname = null;
359
+    }
360
+    if (!isset($regs[2])) {
361
+        $niveau = _LOG_INFO;
362
+    }
363
+    else {
364
+        $niveau = intval($regs[2]);
365
+    }
366
+
367
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
368
+        if (!$pre) {
369
+            $pre = array(
370
+                _LOG_HS => 'HS:',
371
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
372
+                _LOG_CRITIQUE => 'CRITIQUE:',
373
+                _LOG_ERREUR => 'ERREUR:',
374
+                _LOG_AVERTISSEMENT => 'WARNING:',
375
+                _LOG_INFO_IMPORTANTE => '!INFO:',
376
+                _LOG_INFO => 'info:',
377
+                _LOG_DEBUG => 'debug:'
378
+            );
379
+            $log = charger_fonction('log', 'inc');
380
+        }
381
+        if (!is_string($message)) {
382
+            $message = print_r($message, true);
383
+        }
384
+        $log($pre[$niveau] . ' ' . $message, $logname);
385
+    }
386 386
 }
387 387
 
388 388
 /**
@@ -393,8 +393,8 @@  discard block
 block discarded – undo
393 393
  * @param array $opt Tableau d'options
394 394
  **/
395 395
 function journal($phrase, $opt = array()) {
396
-	$journal = charger_fonction('journal', 'inc');
397
-	$journal($phrase, $opt);
396
+    $journal = charger_fonction('journal', 'inc');
397
+    $journal($phrase, $opt);
398 398
 }
399 399
 
400 400
 
@@ -413,36 +413,36 @@  discard block
 block discarded – undo
413 413
  **/
414 414
 function _request($var, $c = false) {
415 415
 
416
-	if (is_array($c)) {
417
-		return isset($c[$var]) ? $c[$var] : null;
418
-	}
416
+    if (is_array($c)) {
417
+        return isset($c[$var]) ? $c[$var] : null;
418
+    }
419 419
 
420
-	if (isset($_GET[$var])) {
421
-		$a = $_GET[$var];
422
-	} elseif (isset($_POST[$var])) {
423
-		$a = $_POST[$var];
424
-	} else {
425
-		return null;
426
-	}
420
+    if (isset($_GET[$var])) {
421
+        $a = $_GET[$var];
422
+    } elseif (isset($_POST[$var])) {
423
+        $a = $_POST[$var];
424
+    } else {
425
+        return null;
426
+    }
427 427
 
428
-	// Si on est en ajax et en POST tout a ete encode
429
-	// via encodeURIComponent, il faut donc repasser
430
-	// dans le charset local...
431
-	if (defined('_AJAX')
432
-		and _AJAX
433
-		and isset($GLOBALS['meta']['charset'])
434
-		and $GLOBALS['meta']['charset'] != 'utf-8'
435
-		and is_string($a)
436
-		// check rapide mais pas fiable
437
-		and preg_match(',[\x80-\xFF],', $a)
438
-		// check fiable
439
-		and include_spip('inc/charsets')
440
-		and is_utf8($a)
441
-	) {
442
-		return importer_charset($a, 'utf-8');
443
-	}
428
+    // Si on est en ajax et en POST tout a ete encode
429
+    // via encodeURIComponent, il faut donc repasser
430
+    // dans le charset local...
431
+    if (defined('_AJAX')
432
+        and _AJAX
433
+        and isset($GLOBALS['meta']['charset'])
434
+        and $GLOBALS['meta']['charset'] != 'utf-8'
435
+        and is_string($a)
436
+        // check rapide mais pas fiable
437
+        and preg_match(',[\x80-\xFF],', $a)
438
+        // check fiable
439
+        and include_spip('inc/charsets')
440
+        and is_utf8($a)
441
+    ) {
442
+        return importer_charset($a, 'utf-8');
443
+    }
444 444
 
445
-	return $a;
445
+    return $a;
446 446
 }
447 447
 
448 448
 
@@ -460,22 +460,22 @@  discard block
 block discarded – undo
460 460
  *     - false sinon
461 461
  **/
462 462
 function set_request($var, $val = null, $c = false) {
463
-	if (is_array($c)) {
464
-		unset($c[$var]);
465
-		if ($val !== null) {
466
-			$c[$var] = $val;
467
-		}
463
+    if (is_array($c)) {
464
+        unset($c[$var]);
465
+        if ($val !== null) {
466
+            $c[$var] = $val;
467
+        }
468 468
 
469
-		return $c;
470
-	}
469
+        return $c;
470
+    }
471 471
 
472
-	unset($_GET[$var]);
473
-	unset($_POST[$var]);
474
-	if ($val !== null) {
475
-		$_GET[$var] = $val;
476
-	}
472
+    unset($_GET[$var]);
473
+    unset($_POST[$var]);
474
+    if ($val !== null) {
475
+        $_GET[$var] = $val;
476
+    }
477 477
 
478
-	return false; # n'affecte pas $c
478
+    return false; # n'affecte pas $c
479 479
 }
480 480
 
481 481
 /**
@@ -495,25 +495,25 @@  discard block
 block discarded – undo
495 495
  * @return array|mixed|string
496 496
  */
497 497
 function spip_sanitize_from_request($value, $key, $sanitize_function='entites_html') {
498
-	if (is_array($value)) {
499
-		if ($key=='*') {
500
-			$key = array_keys($value);
501
-		}
502
-		if (!is_array($key)) {
503
-			$key = [$key];
504
-		}
505
-		foreach ($key as $k) {
506
-			if (!empty($value[$k])) {
507
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
508
-			}
509
-		}
510
-		return $value;
511
-	}
512
-	// si la valeur vient des GET ou POST on la sanitize
513
-	if (!empty($value) and $value == _request($key)) {
514
-		$value = $sanitize_function($value);
515
-	}
516
-	return $value;
498
+    if (is_array($value)) {
499
+        if ($key=='*') {
500
+            $key = array_keys($value);
501
+        }
502
+        if (!is_array($key)) {
503
+            $key = [$key];
504
+        }
505
+        foreach ($key as $k) {
506
+            if (!empty($value[$k])) {
507
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
508
+            }
509
+        }
510
+        return $value;
511
+    }
512
+    // si la valeur vient des GET ou POST on la sanitize
513
+    if (!empty($value) and $value == _request($key)) {
514
+        $value = $sanitize_function($value);
515
+    }
516
+    return $value;
517 517
 }
518 518
 
519 519
 /**
@@ -521,23 +521,22 @@  discard block
 block discarded – undo
521 521
  * 
522 522
  * On est sur le web, on exclut certains protocoles, 
523 523
  * notamment 'file://', 'php://' et d'autres…
524
-
525 524
  * @param string $url
526 525
  * @return bool
527 526
  */
528 527
 function tester_url_absolue($url) {
529
-	$url = trim($url);
530
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
531
-		if (
532
-			isset($m[1])
533
-			and $p = strtolower(rtrim($m[1], ':'))
534
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
535
-		  ) {
536
-			return false;
537
-		}
538
-		return true;
539
-	}
540
-	return false;
528
+    $url = trim($url);
529
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
530
+        if (
531
+            isset($m[1])
532
+            and $p = strtolower(rtrim($m[1], ':'))
533
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
534
+            ) {
535
+            return false;
536
+        }
537
+        return true;
538
+    }
539
+    return false;
541 540
 }
542 541
 
543 542
 /**
@@ -559,94 +558,94 @@  discard block
 block discarded – undo
559 558
  * @return string URL
560 559
  */
561 560
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
562
-	// requete erronnee : plusieurs variable dans $c et aucun $v
563
-	if (strpos($c, "|") !== false and is_null($v)) {
564
-		return null;
565
-	}
566
-
567
-	// lever l'#ancre
568
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
569
-		$url = $r[1];
570
-		$ancre = $r[2];
571
-	} else {
572
-		$ancre = '';
573
-	}
574
-
575
-	// eclater
576
-	$url = preg_split(',[?]|&amp;|&,', $url);
577
-
578
-	// recuperer la base
579
-	$a = array_shift($url);
580
-	if (!$a) {
581
-		$a = './';
582
-	}
583
-
584
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
585
-	$ajouts = array_flip(explode('|', $c));
586
-	$u = is_array($v) ? $v : rawurlencode($v);
587
-	$testv = (is_array($v) ? count($v) : strlen($v));
588
-	$v_read = null;
589
-	// lire les variables et agir
590
-	foreach ($url as $n => $val) {
591
-		if (preg_match($regexp, urldecode($val), $r)) {
592
-			$r = array_pad($r, 3, null);
593
-			if ($v === null) {
594
-				// c'est un tableau, on memorise les valeurs
595
-				if (substr($r[1], -2) == "[]") {
596
-					if (!$v_read) {
597
-						$v_read = array();
598
-					}
599
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
600
-				} // c'est un scalaire, on retourne direct
601
-				else {
602
-					return $r[2] ? substr($r[2], 1) : '';
603
-				}
604
-			} // suppression
605
-			elseif (!$testv) {
606
-				unset($url[$n]);
607
-			}
608
-			// Ajout. Pour une variable, remplacer au meme endroit,
609
-			// pour un tableau ce sera fait dans la prochaine boucle
610
-			elseif (substr($r[1], -2) != '[]') {
611
-				$url[$n] = $r[1] . '=' . $u;
612
-				unset($ajouts[$r[1]]);
613
-			}
614
-			// Pour les tableaux on laisse tomber les valeurs de
615
-			// départ, on remplira à l'étape suivante
616
-			else {
617
-				unset($url[$n]);
618
-			}
619
-		}
620
-	}
621
-
622
-	// traiter les parametres pas encore trouves
623
-	if ($v === null
624
-		and $args = func_get_args()
625
-		and count($args) == 2
626
-	) {
627
-		return $v_read; // rien trouve ou un tableau
628
-	} elseif ($testv) {
629
-		foreach ($ajouts as $k => $n) {
630
-			if (!is_array($v)) {
631
-				$url[] = $k . '=' . $u;
632
-			} else {
633
-				$id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
634
-				foreach ($v as $w) {
635
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
636
-				}
637
-			}
638
-		}
639
-	}
640
-
641
-	// eliminer les vides
642
-	$url = array_filter($url);
643
-
644
-	// recomposer l'adresse
645
-	if ($url) {
646
-		$a .= '?' . join($sep, $url);
647
-	}
648
-
649
-	return $a . $ancre;
561
+    // requete erronnee : plusieurs variable dans $c et aucun $v
562
+    if (strpos($c, "|") !== false and is_null($v)) {
563
+        return null;
564
+    }
565
+
566
+    // lever l'#ancre
567
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
568
+        $url = $r[1];
569
+        $ancre = $r[2];
570
+    } else {
571
+        $ancre = '';
572
+    }
573
+
574
+    // eclater
575
+    $url = preg_split(',[?]|&amp;|&,', $url);
576
+
577
+    // recuperer la base
578
+    $a = array_shift($url);
579
+    if (!$a) {
580
+        $a = './';
581
+    }
582
+
583
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
584
+    $ajouts = array_flip(explode('|', $c));
585
+    $u = is_array($v) ? $v : rawurlencode($v);
586
+    $testv = (is_array($v) ? count($v) : strlen($v));
587
+    $v_read = null;
588
+    // lire les variables et agir
589
+    foreach ($url as $n => $val) {
590
+        if (preg_match($regexp, urldecode($val), $r)) {
591
+            $r = array_pad($r, 3, null);
592
+            if ($v === null) {
593
+                // c'est un tableau, on memorise les valeurs
594
+                if (substr($r[1], -2) == "[]") {
595
+                    if (!$v_read) {
596
+                        $v_read = array();
597
+                    }
598
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
599
+                } // c'est un scalaire, on retourne direct
600
+                else {
601
+                    return $r[2] ? substr($r[2], 1) : '';
602
+                }
603
+            } // suppression
604
+            elseif (!$testv) {
605
+                unset($url[$n]);
606
+            }
607
+            // Ajout. Pour une variable, remplacer au meme endroit,
608
+            // pour un tableau ce sera fait dans la prochaine boucle
609
+            elseif (substr($r[1], -2) != '[]') {
610
+                $url[$n] = $r[1] . '=' . $u;
611
+                unset($ajouts[$r[1]]);
612
+            }
613
+            // Pour les tableaux on laisse tomber les valeurs de
614
+            // départ, on remplira à l'étape suivante
615
+            else {
616
+                unset($url[$n]);
617
+            }
618
+        }
619
+    }
620
+
621
+    // traiter les parametres pas encore trouves
622
+    if ($v === null
623
+        and $args = func_get_args()
624
+        and count($args) == 2
625
+    ) {
626
+        return $v_read; // rien trouve ou un tableau
627
+    } elseif ($testv) {
628
+        foreach ($ajouts as $k => $n) {
629
+            if (!is_array($v)) {
630
+                $url[] = $k . '=' . $u;
631
+            } else {
632
+                $id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
633
+                foreach ($v as $w) {
634
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
635
+                }
636
+            }
637
+        }
638
+    }
639
+
640
+    // eliminer les vides
641
+    $url = array_filter($url);
642
+
643
+    // recomposer l'adresse
644
+    if ($url) {
645
+        $a .= '?' . join($sep, $url);
646
+    }
647
+
648
+    return $a . $ancre;
650 649
 }
651 650
 
652 651
 /**
@@ -664,21 +663,21 @@  discard block
 block discarded – undo
664 663
  * @return string
665 664
  */
666 665
 function ancre_url($url, $ancre) {
667
-	// lever l'#ancre
668
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
669
-		$url = $r[1];
670
-	}
671
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
672
-		if (!function_exists('translitteration')) {
673
-			include_spip('inc/charsets');
674
-		}
675
-		$ancre = preg_replace(
676
-			array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
677
-			array('', '-'),
678
-			translitteration($ancre)
679
-		);
680
-	}
681
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
666
+    // lever l'#ancre
667
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
668
+        $url = $r[1];
669
+    }
670
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
671
+        if (!function_exists('translitteration')) {
672
+            include_spip('inc/charsets');
673
+        }
674
+        $ancre = preg_replace(
675
+            array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
676
+            array('', '-'),
677
+            translitteration($ancre)
678
+        );
679
+    }
680
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
682 681
 }
683 682
 
684 683
 /**
@@ -688,16 +687,16 @@  discard block
 block discarded – undo
688 687
  * @return string
689 688
  */
690 689
 function nettoyer_uri($reset = null) {
691
-	static $done = false;
692
-	static $propre = '';
693
-	if (!is_null($reset)) {
694
-		return $propre = $reset;
695
-	}
696
-	if ($done) {
697
-		return $propre;
698
-	}
699
-	$done = true;
700
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
690
+    static $done = false;
691
+    static $propre = '';
692
+    if (!is_null($reset)) {
693
+        return $propre = $reset;
694
+    }
695
+    if ($done) {
696
+        return $propre;
697
+    }
698
+    $done = true;
699
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
701 700
 }
702 701
 
703 702
 /**
@@ -709,13 +708,13 @@  discard block
 block discarded – undo
709 708
  * @return string
710 709
  */
711 710
 function nettoyer_uri_var($request_uri) {
712
-	$uri1 = $request_uri;
713
-	do {
714
-		$uri = $uri1;
715
-		$uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
716
-			'\1', $uri);
717
-	} while ($uri <> $uri1);
718
-	return preg_replace(',[?&]$,', '', $uri1);
711
+    $uri1 = $request_uri;
712
+    do {
713
+        $uri = $uri1;
714
+        $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
715
+            '\1', $uri);
716
+    } while ($uri <> $uri1);
717
+    return preg_replace(',[?&]$,', '', $uri1);
719 718
 }
720 719
 
721 720
 
@@ -729,47 +728,47 @@  discard block
 block discarded – undo
729 728
  *    URL vers soi-même
730 729
  **/
731 730
 function self($amp = '&amp;', $root = false) {
732
-	$url = nettoyer_uri();
733
-	if (!$root
734
-		and (
735
-			// si pas de profondeur on peut tronquer
736
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
737
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
738
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
739
-	) {
740
-		$url = preg_replace(',^[^?]*/,', '', $url);
741
-	}
742
-	// ajouter le cas echeant les variables _POST['id_...']
743
-	foreach ($_POST as $v => $c) {
744
-		if (substr($v, 0, 3) == 'id_') {
745
-			$url = parametre_url($url, $v, $c, '&');
746
-		}
747
-	}
748
-
749
-	// supprimer les variables sans interet
750
-	if (test_espace_prive()) {
751
-		$url = preg_replace(',([?&])('
752
-			. 'lang|show_docs|'
753
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
754
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
755
-		$url = preg_replace(',[&]$,', '\1', $url);
756
-	}
757
-
758
-	// eviter les hacks
759
-	include_spip('inc/filtres_mini');
760
-	$url = spip_htmlspecialchars($url);
731
+    $url = nettoyer_uri();
732
+    if (!$root
733
+        and (
734
+            // si pas de profondeur on peut tronquer
735
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
736
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
737
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
738
+    ) {
739
+        $url = preg_replace(',^[^?]*/,', '', $url);
740
+    }
741
+    // ajouter le cas echeant les variables _POST['id_...']
742
+    foreach ($_POST as $v => $c) {
743
+        if (substr($v, 0, 3) == 'id_') {
744
+            $url = parametre_url($url, $v, $c, '&');
745
+        }
746
+    }
747
+
748
+    // supprimer les variables sans interet
749
+    if (test_espace_prive()) {
750
+        $url = preg_replace(',([?&])('
751
+            . 'lang|show_docs|'
752
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
753
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
754
+        $url = preg_replace(',[&]$,', '\1', $url);
755
+    }
756
+
757
+    // eviter les hacks
758
+    include_spip('inc/filtres_mini');
759
+    $url = spip_htmlspecialchars($url);
761 760
 	
762
-	$url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
761
+    $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
763 762
 
764
-	// &amp; ?
765
-	if ($amp != '&amp;') {
766
-		$url = str_replace('&amp;', $amp, $url);
767
-	}
763
+    // &amp; ?
764
+    if ($amp != '&amp;') {
765
+        $url = str_replace('&amp;', $amp, $url);
766
+    }
768 767
 
769
-	// Si ca demarre par ? ou vide, donner './'
770
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
768
+    // Si ca demarre par ? ou vide, donner './'
769
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
771 770
 
772
-	return $url;
771
+    return $url;
773 772
 }
774 773
 
775 774
 
@@ -780,7 +779,7 @@  discard block
 block discarded – undo
780 779
  *     true si c'est le cas, false sinon.
781 780
  */
782 781
 function test_espace_prive() {
783
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
782
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
784 783
 }
785 784
 
786 785
 /**
@@ -790,7 +789,7 @@  discard block
 block discarded – undo
790 789
  * @return bool
791 790
  */
792 791
 function test_plugin_actif($plugin) {
793
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
792
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
794 793
 }
795 794
 
796 795
 /**
@@ -821,51 +820,51 @@  discard block
 block discarded – undo
821 820
  *     Texte
822 821
  */
823 822
 function _T($texte, $args = array(), $options = array()) {
824
-	static $traduire = false;
825
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
826
-	if ($options) {
827
-		// support de l'ancien argument $class
828
-		if (is_string($options)) {
829
-			$options = array('class' => $options);
830
-		}
831
-		$o = array_merge($o, $options);
832
-	}
823
+    static $traduire = false;
824
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
825
+    if ($options) {
826
+        // support de l'ancien argument $class
827
+        if (is_string($options)) {
828
+            $options = array('class' => $options);
829
+        }
830
+        $o = array_merge($o, $options);
831
+    }
833 832
 
834
-	if (!$traduire) {
835
-		$traduire = charger_fonction('traduire', 'inc');
836
-		include_spip('inc/lang');
837
-	}
833
+    if (!$traduire) {
834
+        $traduire = charger_fonction('traduire', 'inc');
835
+        include_spip('inc/lang');
836
+    }
838 837
 
839
-	// On peut passer explicitement la langue dans le tableau
840
-	// On utilise le même nom de variable que la globale
841
-	if (isset($args['spip_lang'])) {
842
-		$lang = $args['spip_lang'];
843
-		// On l'enleve pour ne pas le passer au remplacement
844
-		unset($args['spip_lang']);
845
-	} // Sinon on prend la langue du contexte
846
-	else {
847
-		$lang = $GLOBALS['spip_lang'];
848
-	}
849
-	$text = $traduire($texte, $lang);
838
+    // On peut passer explicitement la langue dans le tableau
839
+    // On utilise le même nom de variable que la globale
840
+    if (isset($args['spip_lang'])) {
841
+        $lang = $args['spip_lang'];
842
+        // On l'enleve pour ne pas le passer au remplacement
843
+        unset($args['spip_lang']);
844
+    } // Sinon on prend la langue du contexte
845
+    else {
846
+        $lang = $GLOBALS['spip_lang'];
847
+    }
848
+    $text = $traduire($texte, $lang);
850 849
 
851
-	if (!strlen($text)) {
852
-		if (!$o['force']) {
853
-			return '';
854
-		}
850
+    if (!strlen($text)) {
851
+        if (!$o['force']) {
852
+            return '';
853
+        }
855 854
 
856
-		$text = $texte;
855
+        $text = $texte;
857 856
 
858
-		// pour les chaines non traduites, assurer un service minimum
859
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
860
-			$text = str_replace('_', ' ',
861
-				(($n = strpos($text, ':')) === false ? $texte :
862
-					substr($texte, $n + 1)));
863
-		}
864
-		$o['class'] = null;
857
+        // pour les chaines non traduites, assurer un service minimum
858
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
859
+            $text = str_replace('_', ' ',
860
+                (($n = strpos($text, ':')) === false ? $texte :
861
+                    substr($texte, $n + 1)));
862
+        }
863
+        $o['class'] = null;
865 864
 
866
-	}
865
+    }
867 866
 
868
-	return _L($text, $args, $o);
867
+    return _L($text, $args, $o);
869 868
 
870 869
 }
871 870
 
@@ -893,53 +892,53 @@  discard block
 block discarded – undo
893 892
  *     Texte
894 893
  */
895 894
 function _L($text, $args = array(), $options = array()) {
896
-	$f = $text;
897
-	$defaut_options = array(
898
-		'class' => null,
899
-		'sanitize' => true,
900
-	);
901
-	// support de l'ancien argument $class
902
-	if ($options and is_string($options)) {
903
-		$options = array('class' => $options);
904
-	}
905
-	if (is_array($options)) {
906
-		$options += $defaut_options;
907
-	} else {
908
-		$options = $defaut_options;
909
-	}
910
-
911
-	if (is_array($args) and count($args)) {
912
-		if (!function_exists('interdire_scripts')) {
913
-			include_spip('inc/texte');
914
-		}
915
-		if (!function_exists('echapper_html_suspect')) {
916
-			include_spip('inc/texte_mini');
917
-		}
918
-		foreach ($args as $name => $value) {
919
-			if (strpos($text, "@$name@") !== false) {
920
-				if ($options['sanitize']) {
921
-					$value = echapper_html_suspect($value);
922
-					$value = interdire_scripts($value, -1);
923
-				}
924
-				if (!empty($options['class'])) {
925
-					$value = "<span class='".$options['class']."'>$value</span>";
926
-				}
927
-				$text = str_replace("@$name@", $value, $text);
928
-				unset($args[$name]);
929
-			}
930
-		}
931
-		// Si des variables n'ont pas ete inserees, le signaler
932
-		// (chaines de langues pas a jour)
933
-		if ($args) {
934
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
935
-		}
936
-	}
937
-
938
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
939
-		return "<span class=debug-traduction-erreur>$text</span>";
940
-	} else {
941
-		return $text;
942
-	}
895
+    $f = $text;
896
+    $defaut_options = array(
897
+        'class' => null,
898
+        'sanitize' => true,
899
+    );
900
+    // support de l'ancien argument $class
901
+    if ($options and is_string($options)) {
902
+        $options = array('class' => $options);
903
+    }
904
+    if (is_array($options)) {
905
+        $options += $defaut_options;
906
+    } else {
907
+        $options = $defaut_options;
908
+    }
909
+
910
+    if (is_array($args) and count($args)) {
911
+        if (!function_exists('interdire_scripts')) {
912
+            include_spip('inc/texte');
913
+        }
914
+        if (!function_exists('echapper_html_suspect')) {
915
+            include_spip('inc/texte_mini');
916
+        }
917
+        foreach ($args as $name => $value) {
918
+            if (strpos($text, "@$name@") !== false) {
919
+                if ($options['sanitize']) {
920
+                    $value = echapper_html_suspect($value);
921
+                    $value = interdire_scripts($value, -1);
922
+                }
923
+                if (!empty($options['class'])) {
924
+                    $value = "<span class='".$options['class']."'>$value</span>";
925
+                }
926
+                $text = str_replace("@$name@", $value, $text);
927
+                unset($args[$name]);
928
+            }
929
+        }
930
+        // Si des variables n'ont pas ete inserees, le signaler
931
+        // (chaines de langues pas a jour)
932
+        if ($args) {
933
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
934
+        }
935
+    }
936
+
937
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
938
+        return "<span class=debug-traduction-erreur>$text</span>";
939
+    } else {
940
+        return $text;
941
+    }
943 942
 }
944 943
 
945 944
 
@@ -953,13 +952,13 @@  discard block
 block discarded – undo
953 952
  * @return string
954 953
  */
955 954
 function joli_repertoire($rep) {
956
-	$a = substr($rep, 0, 1);
957
-	if ($a <> '.' and $a <> '/') {
958
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
959
-	}
960
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
955
+    $a = substr($rep, 0, 1);
956
+    if ($a <> '.' and $a <> '/') {
957
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
958
+    }
959
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
961 960
 
962
-	return $rep;
961
+    return $rep;
963 962
 }
964 963
 
965 964
 
@@ -984,33 +983,33 @@  discard block
 block discarded – undo
984 983
  * @return float|int|string|void
985 984
  */
986 985
 function spip_timer($t = 'rien', $raw = false) {
987
-	static $time;
988
-	$a = time();
989
-	$b = microtime();
990
-	// microtime peut contenir les microsecondes et le temps
991
-	$b = explode(' ', $b);
992
-	if (count($b) == 2) {
993
-		$a = end($b);
994
-	} // plus precis !
995
-	$b = reset($b);
996
-	if (!isset($time[$t])) {
997
-		$time[$t] = $a + $b;
998
-	} else {
999
-		$p = ($a + $b - $time[$t]) * 1000;
1000
-		unset($time[$t]);
986
+    static $time;
987
+    $a = time();
988
+    $b = microtime();
989
+    // microtime peut contenir les microsecondes et le temps
990
+    $b = explode(' ', $b);
991
+    if (count($b) == 2) {
992
+        $a = end($b);
993
+    } // plus precis !
994
+    $b = reset($b);
995
+    if (!isset($time[$t])) {
996
+        $time[$t] = $a + $b;
997
+    } else {
998
+        $p = ($a + $b - $time[$t]) * 1000;
999
+        unset($time[$t]);
1001 1000
 #			echo "'$p'";exit;
1002
-		if ($raw) {
1003
-			return $p;
1004
-		}
1005
-		if ($p < 1000) {
1006
-			$s = '';
1007
-		} else {
1008
-			$s = sprintf("%d ", $x = floor($p / 1000));
1009
-			$p -= ($x * 1000);
1010
-		}
1001
+        if ($raw) {
1002
+            return $p;
1003
+        }
1004
+        if ($p < 1000) {
1005
+            $s = '';
1006
+        } else {
1007
+            $s = sprintf("%d ", $x = floor($p / 1000));
1008
+            $p -= ($x * 1000);
1009
+        }
1011 1010
 
1012
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
1013
-	}
1011
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
1012
+    }
1014 1013
 }
1015 1014
 
1016 1015
 
@@ -1018,21 +1017,21 @@  discard block
 block discarded – undo
1018 1017
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1019 1018
 // https://code.spip.net/@spip_touch
1020 1019
 function spip_touch($fichier, $duree = 0, $touch = true) {
1021
-	if ($duree) {
1022
-		clearstatcache();
1023
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1024
-			return false;
1025
-		}
1026
-	}
1027
-	if ($touch !== false) {
1028
-		if (!@touch($fichier)) {
1029
-			spip_unlink($fichier);
1030
-			@touch($fichier);
1031
-		};
1032
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1033
-	}
1020
+    if ($duree) {
1021
+        clearstatcache();
1022
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1023
+            return false;
1024
+        }
1025
+    }
1026
+    if ($touch !== false) {
1027
+        if (!@touch($fichier)) {
1028
+            spip_unlink($fichier);
1029
+            @touch($fichier);
1030
+        };
1031
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1032
+    }
1034 1033
 
1035
-	return true;
1034
+    return true;
1036 1035
 }
1037 1036
 
1038 1037
 
@@ -1044,11 +1043,11 @@  discard block
 block discarded – undo
1044 1043
  * @uses cron()
1045 1044
  **/
1046 1045
 function action_cron() {
1047
-	include_spip('inc/headers');
1048
-	http_status(204); // No Content
1049
-	header("Connection: close");
1050
-	define('_DIRECT_CRON_FORCE', true);
1051
-	cron();
1046
+    include_spip('inc/headers');
1047
+    http_status(204); // No Content
1048
+    header("Connection: close");
1049
+    define('_DIRECT_CRON_FORCE', true);
1050
+    cron();
1052 1051
 }
1053 1052
 
1054 1053
 /**
@@ -1064,26 +1063,26 @@  discard block
 block discarded – undo
1064 1063
  *     True si la tache a pu être effectuée
1065 1064
  */
1066 1065
 function cron($taches = array(), $taches_old = array()) {
1067
-	// si pas en mode cron force, laisser tomber.
1068
-	if (!defined('_DIRECT_CRON_FORCE')) {
1069
-		return false;
1070
-	}
1071
-	if (!is_array($taches)) {
1072
-		$taches = $taches_old;
1073
-	} // compat anciens appels
1074
-	// si taches a inserer en base et base inaccessible, laisser tomber
1075
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1076
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1077
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1078
-	if ($taches and count($taches) and !spip_connect()) {
1079
-		return false;
1080
-	}
1081
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1082
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1083
-		return $genie($taches);
1084
-	}
1085
-
1086
-	return false;
1066
+    // si pas en mode cron force, laisser tomber.
1067
+    if (!defined('_DIRECT_CRON_FORCE')) {
1068
+        return false;
1069
+    }
1070
+    if (!is_array($taches)) {
1071
+        $taches = $taches_old;
1072
+    } // compat anciens appels
1073
+    // si taches a inserer en base et base inaccessible, laisser tomber
1074
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1075
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1076
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1077
+    if ($taches and count($taches) and !spip_connect()) {
1078
+        return false;
1079
+    }
1080
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1081
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1082
+        return $genie($taches);
1083
+    }
1084
+
1085
+    return false;
1087 1086
 }
1088 1087
 
1089 1088
 /**
@@ -1115,17 +1114,17 @@  discard block
 block discarded – undo
1115 1114
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1116 1115
  */
1117 1116
 function job_queue_add(
1118
-	$function,
1119
-	$description,
1120
-	$arguments = array(),
1121
-	$file = '',
1122
-	$no_duplicate = false,
1123
-	$time = 0,
1124
-	$priority = 0
1117
+    $function,
1118
+    $description,
1119
+    $arguments = array(),
1120
+    $file = '',
1121
+    $no_duplicate = false,
1122
+    $time = 0,
1123
+    $priority = 0
1125 1124
 ) {
1126
-	include_spip('inc/queue');
1125
+    include_spip('inc/queue');
1127 1126
 
1128
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1127
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1129 1128
 }
1130 1129
 
1131 1130
 /**
@@ -1136,9 +1135,9 @@  discard block
 block discarded – undo
1136 1135
  * @return bool
1137 1136
  */
1138 1137
 function job_queue_remove($id_job) {
1139
-	include_spip('inc/queue');
1138
+    include_spip('inc/queue');
1140 1139
 
1141
-	return queue_remove_job($id_job);
1140
+    return queue_remove_job($id_job);
1142 1141
 }
1143 1142
 
1144 1143
 /**
@@ -1151,9 +1150,9 @@  discard block
 block discarded – undo
1151 1150
  *     or an array of simple array to link multiples objet in one time
1152 1151
  */
1153 1152
 function job_queue_link($id_job, $objets) {
1154
-	include_spip('inc/queue');
1153
+    include_spip('inc/queue');
1155 1154
 
1156
-	return queue_link_job($id_job, $objets);
1155
+    return queue_link_job($id_job, $objets);
1157 1156
 }
1158 1157
 
1159 1158
 
@@ -1173,36 +1172,36 @@  discard block
 block discarded – undo
1173 1172
  *  - `null` si la queue n'est pas encore initialisée
1174 1173
  */
1175 1174
 function queue_sleep_time_to_next_job($force = null) {
1176
-	static $queue_next_job_time = -1;
1177
-	if ($force === true) {
1178
-		$queue_next_job_time = -1;
1179
-	} elseif ($force) {
1180
-		$queue_next_job_time = $force;
1181
-	}
1182
-
1183
-	if ($queue_next_job_time == -1) {
1184
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1185
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1186
-		}
1187
-		// utiliser un cache memoire si dispo
1188
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1189
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1190
-		} else {
1191
-			$queue_next_job_time = null;
1192
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1193
-				$queue_next_job_time = intval($contenu);
1194
-			}
1195
-		}
1196
-	}
1197
-
1198
-	if (is_null($queue_next_job_time)) {
1199
-		return null;
1200
-	}
1201
-	if (!$_SERVER['REQUEST_TIME']) {
1202
-		$_SERVER['REQUEST_TIME'] = time();
1203
-	}
1204
-
1205
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1175
+    static $queue_next_job_time = -1;
1176
+    if ($force === true) {
1177
+        $queue_next_job_time = -1;
1178
+    } elseif ($force) {
1179
+        $queue_next_job_time = $force;
1180
+    }
1181
+
1182
+    if ($queue_next_job_time == -1) {
1183
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1184
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1185
+        }
1186
+        // utiliser un cache memoire si dispo
1187
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1188
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1189
+        } else {
1190
+            $queue_next_job_time = null;
1191
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1192
+                $queue_next_job_time = intval($contenu);
1193
+            }
1194
+        }
1195
+    }
1196
+
1197
+    if (is_null($queue_next_job_time)) {
1198
+        return null;
1199
+    }
1200
+    if (!$_SERVER['REQUEST_TIME']) {
1201
+        $_SERVER['REQUEST_TIME'] = time();
1202
+    }
1203
+
1204
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1206 1205
 }
1207 1206
 
1208 1207
 
@@ -1214,9 +1213,9 @@  discard block
 block discarded – undo
1214 1213
  * @return string
1215 1214
  */
1216 1215
 function quote_amp($u) {
1217
-	return preg_replace(
1218
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1219
-		"&amp;", $u);
1216
+    return preg_replace(
1217
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1218
+        "&amp;", $u);
1220 1219
 }
1221 1220
 
1222 1221
 
@@ -1239,27 +1238,27 @@  discard block
 block discarded – undo
1239 1238
  *     Balise HTML `<script>` et son contenu
1240 1239
  **/
1241 1240
 function http_script($script, $src = '', $noscript = '') {
1242
-	static $done = array();
1241
+    static $done = array();
1243 1242
 
1244
-	if ($src && !isset($done[$src])) {
1245
-		$done[$src] = true;
1246
-		$src = find_in_path($src, _JAVASCRIPT);
1247
-		$src = " src='$src'";
1248
-	} else {
1249
-		$src = '';
1250
-	}
1251
-	if ($script) {
1252
-		$script = ("/*<![CDATA[*/\n" .
1253
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1254
-			"/*]]>*/");
1255
-	}
1256
-	if ($noscript) {
1257
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1258
-	}
1243
+    if ($src && !isset($done[$src])) {
1244
+        $done[$src] = true;
1245
+        $src = find_in_path($src, _JAVASCRIPT);
1246
+        $src = " src='$src'";
1247
+    } else {
1248
+        $src = '';
1249
+    }
1250
+    if ($script) {
1251
+        $script = ("/*<![CDATA[*/\n" .
1252
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1253
+            "/*]]>*/");
1254
+    }
1255
+    if ($noscript) {
1256
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1257
+    }
1259 1258
 
1260
-	return ($src or $script or $noscript)
1261
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1262
-		: '';
1259
+    return ($src or $script or $noscript)
1260
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1261
+        : '';
1263 1262
 }
1264 1263
 
1265 1264
 
@@ -1294,7 +1293,7 @@  discard block
 block discarded – undo
1294 1293
  *     Texte échappé
1295 1294
  **/
1296 1295
 function texte_script($texte) {
1297
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1296
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1298 1297
 }
1299 1298
 
1300 1299
 
@@ -1331,69 +1330,69 @@  discard block
 block discarded – undo
1331 1330
  *     Liste des chemins, par ordre de priorité.
1332 1331
  **/
1333 1332
 function _chemin($dir_path = null) {
1334
-	static $path_base = null;
1335
-	static $path_full = null;
1336
-	if ($path_base == null) {
1337
-		// Chemin standard depuis l'espace public
1338
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1339
-			_DIR_RACINE . ':' .
1340
-			_DIR_RACINE . 'squelettes-dist/:' .
1341
-			_DIR_RACINE . 'prive/:' .
1342
-			_DIR_RESTREINT;
1343
-		// Ajouter squelettes/
1344
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1345
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1346
-		}
1347
-		foreach (explode(':', $path) as $dir) {
1348
-			if (strlen($dir) and substr($dir, -1) != '/') {
1349
-				$dir .= "/";
1350
-			}
1351
-			$path_base[] = $dir;
1352
-		}
1353
-		$path_full = $path_base;
1354
-		// Et le(s) dossier(s) des squelettes nommes
1355
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1356
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1357
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1358
-			}
1359
-		}
1360
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1361
-	}
1362
-	if ($dir_path === null) {
1363
-		return $path_full;
1364
-	}
1365
-
1366
-	if (strlen($dir_path)) {
1367
-		$tete = "";
1368
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1369
-			$tete = array_shift($path_base);
1370
-		}
1371
-		$dirs = array_reverse(explode(':', $dir_path));
1372
-		foreach ($dirs as $dir_path) {
1373
-			#if ($dir_path{0}!='/')
1374
-			#	$dir_path = $dir_path;
1375
-			if (substr($dir_path, -1) != '/') {
1376
-				$dir_path .= "/";
1377
-			}
1378
-			if (!in_array($dir_path, $path_base)) {
1379
-				array_unshift($path_base, $dir_path);
1380
-			}
1381
-		}
1382
-		if (strlen($tete)) {
1383
-			array_unshift($path_base, $tete);
1384
-		}
1385
-	}
1386
-	$path_full = $path_base;
1387
-	// Et le(s) dossier(s) des squelettes nommes
1388
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1389
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1390
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1391
-		}
1392
-	}
1393
-
1394
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1395
-
1396
-	return $path_full;
1333
+    static $path_base = null;
1334
+    static $path_full = null;
1335
+    if ($path_base == null) {
1336
+        // Chemin standard depuis l'espace public
1337
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1338
+            _DIR_RACINE . ':' .
1339
+            _DIR_RACINE . 'squelettes-dist/:' .
1340
+            _DIR_RACINE . 'prive/:' .
1341
+            _DIR_RESTREINT;
1342
+        // Ajouter squelettes/
1343
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1344
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1345
+        }
1346
+        foreach (explode(':', $path) as $dir) {
1347
+            if (strlen($dir) and substr($dir, -1) != '/') {
1348
+                $dir .= "/";
1349
+            }
1350
+            $path_base[] = $dir;
1351
+        }
1352
+        $path_full = $path_base;
1353
+        // Et le(s) dossier(s) des squelettes nommes
1354
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1355
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1356
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1357
+            }
1358
+        }
1359
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1360
+    }
1361
+    if ($dir_path === null) {
1362
+        return $path_full;
1363
+    }
1364
+
1365
+    if (strlen($dir_path)) {
1366
+        $tete = "";
1367
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1368
+            $tete = array_shift($path_base);
1369
+        }
1370
+        $dirs = array_reverse(explode(':', $dir_path));
1371
+        foreach ($dirs as $dir_path) {
1372
+            #if ($dir_path{0}!='/')
1373
+            #	$dir_path = $dir_path;
1374
+            if (substr($dir_path, -1) != '/') {
1375
+                $dir_path .= "/";
1376
+            }
1377
+            if (!in_array($dir_path, $path_base)) {
1378
+                array_unshift($path_base, $dir_path);
1379
+            }
1380
+        }
1381
+        if (strlen($tete)) {
1382
+            array_unshift($path_base, $tete);
1383
+        }
1384
+    }
1385
+    $path_full = $path_base;
1386
+    // Et le(s) dossier(s) des squelettes nommes
1387
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1388
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1389
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1390
+        }
1391
+    }
1392
+
1393
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1394
+
1395
+    return $path_full;
1397 1396
 }
1398 1397
 
1399 1398
 /**
@@ -1406,76 +1405,76 @@  discard block
 block discarded – undo
1406 1405
  * @return array Liste de chemins
1407 1406
  **/
1408 1407
 function creer_chemin() {
1409
-	$path_a = _chemin();
1410
-	static $c = '';
1408
+    $path_a = _chemin();
1409
+    static $c = '';
1411 1410
 
1412
-	// on calcule le chemin si le dossier skel a change
1413
-	if ($c != $GLOBALS['dossier_squelettes']) {
1414
-		// assurer le non plantage lors de la montee de version :
1415
-		$c = $GLOBALS['dossier_squelettes'];
1416
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1417
-	}
1411
+    // on calcule le chemin si le dossier skel a change
1412
+    if ($c != $GLOBALS['dossier_squelettes']) {
1413
+        // assurer le non plantage lors de la montee de version :
1414
+        $c = $GLOBALS['dossier_squelettes'];
1415
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1416
+    }
1418 1417
 
1419
-	return $path_a;
1418
+    return $path_a;
1420 1419
 }
1421 1420
 
1422 1421
 
1423 1422
 function lister_themes_prives() {
1424
-	static $themes = null;
1425
-	if (is_null($themes)) {
1426
-		// si pas encore definie
1427
-		if (!defined('_SPIP_THEME_PRIVE')) {
1428
-			define('_SPIP_THEME_PRIVE', 'spip');
1429
-		}
1430
-		$themes = array(_SPIP_THEME_PRIVE);
1431
-		// lors d'une installation neuve, prefs n'est pas definie.
1432
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1433
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1434
-		} else {
1435
-			$prefs = array();
1436
-		}
1437
-		if (is_string($prefs)) {
1438
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1439
-		}
1440
-		if (
1441
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1442
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1443
-			and $theme != _SPIP_THEME_PRIVE
1444
-		) {
1445
-			array_unshift($themes, $theme);
1446
-		} // placer le theme choisi en tete
1447
-	}
1448
-
1449
-	return $themes;
1423
+    static $themes = null;
1424
+    if (is_null($themes)) {
1425
+        // si pas encore definie
1426
+        if (!defined('_SPIP_THEME_PRIVE')) {
1427
+            define('_SPIP_THEME_PRIVE', 'spip');
1428
+        }
1429
+        $themes = array(_SPIP_THEME_PRIVE);
1430
+        // lors d'une installation neuve, prefs n'est pas definie.
1431
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1432
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1433
+        } else {
1434
+            $prefs = array();
1435
+        }
1436
+        if (is_string($prefs)) {
1437
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1438
+        }
1439
+        if (
1440
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1441
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1442
+            and $theme != _SPIP_THEME_PRIVE
1443
+        ) {
1444
+            array_unshift($themes, $theme);
1445
+        } // placer le theme choisi en tete
1446
+    }
1447
+
1448
+    return $themes;
1450 1449
 }
1451 1450
 
1452 1451
 function find_in_theme($file, $subdir = '', $include = false) {
1453
-	static $themefiles = array();
1454
-	if (isset($themefiles["$subdir$file"])) {
1455
-		return $themefiles["$subdir$file"];
1456
-	}
1457
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1458
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1459
-	if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1460
-	  and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1461
-		and $f = find_in_theme("$file_svg_generique")) {
1462
-		if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1463
-			return $themefiles["$subdir$file"] = $fsize;
1464
-		}
1465
-		else {
1466
-			return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1467
-		}
1468
-	}
1469
-
1470
-	$themes = lister_themes_prives();
1471
-	foreach ($themes as $theme) {
1472
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1473
-			return $themefiles["$subdir$file"] = $f;
1474
-		}
1475
-	}
1476
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1477
-
1478
-	return $themefiles["$subdir$file"] = "";
1452
+    static $themefiles = array();
1453
+    if (isset($themefiles["$subdir$file"])) {
1454
+        return $themefiles["$subdir$file"];
1455
+    }
1456
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1457
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1458
+    if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1459
+      and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1460
+        and $f = find_in_theme("$file_svg_generique")) {
1461
+        if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1462
+            return $themefiles["$subdir$file"] = $fsize;
1463
+        }
1464
+        else {
1465
+            return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1466
+        }
1467
+    }
1468
+
1469
+    $themes = lister_themes_prives();
1470
+    foreach ($themes as $theme) {
1471
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1472
+            return $themefiles["$subdir$file"] = $f;
1473
+        }
1474
+    }
1475
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1476
+
1477
+    return $themefiles["$subdir$file"] = "";
1479 1478
 }
1480 1479
 
1481 1480
 
@@ -1499,31 +1498,31 @@  discard block
 block discarded – undo
1499 1498
  *     sinon chaîne vide.
1500 1499
  **/
1501 1500
 function chemin_image($icone) {
1502
-	static $icone_renommer;
1503
-	if ($p = strpos($icone, '?')) {
1504
-		$icone = substr($icone,0, $p);
1505
-	}
1506
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1507
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1508
-		return $icone;
1509
-	}
1510
-
1511
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1512
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1513
-		return $f;
1514
-	}
1515
-	// sinon passer par le module de renommage
1516
-	if (is_null($icone_renommer)) {
1517
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1518
-	}
1519
-	if ($icone_renommer) {
1520
-		list($icone, $fonction) = $icone_renommer($icone, "");
1521
-		if (file_exists($icone)) {
1522
-			return $icone;
1523
-		}
1524
-	}
1525
-
1526
-	return find_in_path($icone, _NOM_IMG_PACK);
1501
+    static $icone_renommer;
1502
+    if ($p = strpos($icone, '?')) {
1503
+        $icone = substr($icone,0, $p);
1504
+    }
1505
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1506
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1507
+        return $icone;
1508
+    }
1509
+
1510
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1511
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1512
+        return $f;
1513
+    }
1514
+    // sinon passer par le module de renommage
1515
+    if (is_null($icone_renommer)) {
1516
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1517
+    }
1518
+    if ($icone_renommer) {
1519
+        list($icone, $fonction) = $icone_renommer($icone, "");
1520
+        if (file_exists($icone)) {
1521
+            return $icone;
1522
+        }
1523
+    }
1524
+
1525
+    return find_in_path($icone, _NOM_IMG_PACK);
1527 1526
 }
1528 1527
 
1529 1528
 //
@@ -1561,127 +1560,127 @@  discard block
 block discarded – undo
1561 1560
  *     - false : fichier introuvable
1562 1561
  **/
1563 1562
 function find_in_path($file, $dirname = '', $include = false) {
1564
-	static $dirs = array();
1565
-	static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1566
-	static $c = '';
1567
-
1568
-	if (!$file and !strlen($file)) {
1569
-		return false;
1570
-	}
1571
-
1572
-	// on calcule le chemin si le dossier skel a change
1573
-	if ($c != $GLOBALS['dossier_squelettes']) {
1574
-		// assurer le non plantage lors de la montee de version :
1575
-		$c = $GLOBALS['dossier_squelettes'];
1576
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1577
-	}
1578
-
1579
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1580
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1581
-			return false;
1582
-		}
1583
-		if ($include and !isset($inc[$dirname][$file])) {
1584
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1585
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1586
-		}
1587
-
1588
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1589
-	}
1590
-
1591
-	$a = strrpos($file, '/');
1592
-	if ($a !== false) {
1593
-		$dirname .= substr($file, 0, ++$a);
1594
-		$file = substr($file, $a);
1595
-	}
1596
-
1597
-	foreach (creer_chemin() as $dir) {
1598
-		if (!isset($dirs[$a = $dir . $dirname])) {
1599
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1600
-		}
1601
-		if ($dirs[$a]) {
1602
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1603
-				if ($include and !isset($inc[$dirname][$file])) {
1604
-					include_once _ROOT_CWD . $a;
1605
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1606
-				}
1607
-				if (!defined('_SAUVER_CHEMIN')) {
1608
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1609
-					if (is_null($GLOBALS['path_files'])) {
1610
-						return $a;
1611
-					}
1612
-					define('_SAUVER_CHEMIN', true);
1613
-				}
1614
-
1615
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1616
-			}
1617
-		}
1618
-	}
1619
-
1620
-	if ($include) {
1621
-		spip_log("include_spip $dirname$file non trouve");
1622
-		if ($include === 'required') {
1623
-			echo '<pre>',
1624
-			"<strong>Erreur Fatale</strong><br />";
1625
-			if (function_exists('debug_print_backtrace')) {
1626
-				echo debug_print_backtrace();
1627
-			}
1628
-			echo '</pre>';
1629
-			die("Erreur interne: ne peut inclure $dirname$file");
1630
-		}
1631
-	}
1632
-
1633
-	if (!defined('_SAUVER_CHEMIN')) {
1634
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1635
-		if (is_null($GLOBALS['path_files'])) {
1636
-			return false;
1637
-		}
1638
-		define('_SAUVER_CHEMIN', true);
1639
-	}
1640
-
1641
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1563
+    static $dirs = array();
1564
+    static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1565
+    static $c = '';
1566
+
1567
+    if (!$file and !strlen($file)) {
1568
+        return false;
1569
+    }
1570
+
1571
+    // on calcule le chemin si le dossier skel a change
1572
+    if ($c != $GLOBALS['dossier_squelettes']) {
1573
+        // assurer le non plantage lors de la montee de version :
1574
+        $c = $GLOBALS['dossier_squelettes'];
1575
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1576
+    }
1577
+
1578
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1579
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1580
+            return false;
1581
+        }
1582
+        if ($include and !isset($inc[$dirname][$file])) {
1583
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1584
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1585
+        }
1586
+
1587
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1588
+    }
1589
+
1590
+    $a = strrpos($file, '/');
1591
+    if ($a !== false) {
1592
+        $dirname .= substr($file, 0, ++$a);
1593
+        $file = substr($file, $a);
1594
+    }
1595
+
1596
+    foreach (creer_chemin() as $dir) {
1597
+        if (!isset($dirs[$a = $dir . $dirname])) {
1598
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1599
+        }
1600
+        if ($dirs[$a]) {
1601
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1602
+                if ($include and !isset($inc[$dirname][$file])) {
1603
+                    include_once _ROOT_CWD . $a;
1604
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1605
+                }
1606
+                if (!defined('_SAUVER_CHEMIN')) {
1607
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1608
+                    if (is_null($GLOBALS['path_files'])) {
1609
+                        return $a;
1610
+                    }
1611
+                    define('_SAUVER_CHEMIN', true);
1612
+                }
1613
+
1614
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1615
+            }
1616
+        }
1617
+    }
1618
+
1619
+    if ($include) {
1620
+        spip_log("include_spip $dirname$file non trouve");
1621
+        if ($include === 'required') {
1622
+            echo '<pre>',
1623
+            "<strong>Erreur Fatale</strong><br />";
1624
+            if (function_exists('debug_print_backtrace')) {
1625
+                echo debug_print_backtrace();
1626
+            }
1627
+            echo '</pre>';
1628
+            die("Erreur interne: ne peut inclure $dirname$file");
1629
+        }
1630
+    }
1631
+
1632
+    if (!defined('_SAUVER_CHEMIN')) {
1633
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1634
+        if (is_null($GLOBALS['path_files'])) {
1635
+            return false;
1636
+        }
1637
+        define('_SAUVER_CHEMIN', true);
1638
+    }
1639
+
1640
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1642 1641
 }
1643 1642
 
1644 1643
 function clear_path_cache() {
1645
-	$GLOBALS['path_files'] = array();
1646
-	spip_unlink(_CACHE_CHEMIN);
1644
+    $GLOBALS['path_files'] = array();
1645
+    spip_unlink(_CACHE_CHEMIN);
1647 1646
 }
1648 1647
 
1649 1648
 function load_path_cache() {
1650
-	// charger le path des plugins
1651
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1652
-		include_once(_CACHE_PLUGINS_PATH);
1653
-	}
1654
-	$GLOBALS['path_files'] = array();
1655
-	// si le visiteur est admin,
1656
-	// on ne recharge pas le cache pour forcer sa mise a jour
1657
-	if (
1658
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1659
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1660
-		// utiliser le cookie est un pis aller qui marche 'en general'
1661
-		// on blinde par un second test au moment de la lecture de la session
1662
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1663
-		// et en ignorant ce cache en cas de recalcul explicite
1664
-	!_request('var_mode')
1665
-	) {
1666
-		// on essaye de lire directement sans verrou pour aller plus vite
1667
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1668
-			// mais si semble corrompu on relit avec un verrou
1669
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1670
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1671
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1672
-					$GLOBALS['path_files'] = array();
1673
-				}
1674
-			}
1675
-		}
1676
-	}
1649
+    // charger le path des plugins
1650
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1651
+        include_once(_CACHE_PLUGINS_PATH);
1652
+    }
1653
+    $GLOBALS['path_files'] = array();
1654
+    // si le visiteur est admin,
1655
+    // on ne recharge pas le cache pour forcer sa mise a jour
1656
+    if (
1657
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1658
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1659
+        // utiliser le cookie est un pis aller qui marche 'en general'
1660
+        // on blinde par un second test au moment de la lecture de la session
1661
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1662
+        // et en ignorant ce cache en cas de recalcul explicite
1663
+    !_request('var_mode')
1664
+    ) {
1665
+        // on essaye de lire directement sans verrou pour aller plus vite
1666
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1667
+            // mais si semble corrompu on relit avec un verrou
1668
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1669
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1670
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1671
+                    $GLOBALS['path_files'] = array();
1672
+                }
1673
+            }
1674
+        }
1675
+    }
1677 1676
 }
1678 1677
 
1679 1678
 function save_path_cache() {
1680
-	if (defined('_SAUVER_CHEMIN')
1681
-		and _SAUVER_CHEMIN
1682
-	) {
1683
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1684
-	}
1679
+    if (defined('_SAUVER_CHEMIN')
1680
+        and _SAUVER_CHEMIN
1681
+    ) {
1682
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1683
+    }
1685 1684
 }
1686 1685
 
1687 1686
 
@@ -1701,33 +1700,33 @@  discard block
 block discarded – undo
1701 1700
  * @return array
1702 1701
  */
1703 1702
 function find_all_in_path($dir, $pattern, $recurs = false) {
1704
-	$liste_fichiers = array();
1705
-	$maxfiles = 10000;
1706
-
1707
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1708
-	// on a pas encore inclus flock.php
1709
-	if (!function_exists('preg_files')) {
1710
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1711
-	}
1712
-
1713
-	// Parcourir le chemin
1714
-	foreach (creer_chemin() as $d) {
1715
-		$f = $d . $dir;
1716
-		if (@is_dir($f)) {
1717
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1718
-			foreach ($liste as $chemin) {
1719
-				$nom = basename($chemin);
1720
-				// ne prendre que les fichiers pas deja trouves
1721
-				// car find_in_path prend le premier qu'il trouve,
1722
-				// les autres sont donc masques
1723
-				if (!isset($liste_fichiers[$nom])) {
1724
-					$liste_fichiers[$nom] = $chemin;
1725
-				}
1726
-			}
1727
-		}
1728
-	}
1729
-
1730
-	return $liste_fichiers;
1703
+    $liste_fichiers = array();
1704
+    $maxfiles = 10000;
1705
+
1706
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1707
+    // on a pas encore inclus flock.php
1708
+    if (!function_exists('preg_files')) {
1709
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1710
+    }
1711
+
1712
+    // Parcourir le chemin
1713
+    foreach (creer_chemin() as $d) {
1714
+        $f = $d . $dir;
1715
+        if (@is_dir($f)) {
1716
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1717
+            foreach ($liste as $chemin) {
1718
+                $nom = basename($chemin);
1719
+                // ne prendre que les fichiers pas deja trouves
1720
+                // car find_in_path prend le premier qu'il trouve,
1721
+                // les autres sont donc masques
1722
+                if (!isset($liste_fichiers[$nom])) {
1723
+                    $liste_fichiers[$nom] = $chemin;
1724
+                }
1725
+            }
1726
+        }
1727
+    }
1728
+
1729
+    return $liste_fichiers;
1731 1730
 }
1732 1731
 
1733 1732
 /**
@@ -1739,17 +1738,17 @@  discard block
 block discarded – undo
1739 1738
  * @return bool
1740 1739
  */
1741 1740
 function autoriser_sans_cookie($nom, $strict = false) {
1742
-	static $autsanscookie = array('install', 'base_repair');
1741
+    static $autsanscookie = array('install', 'base_repair');
1743 1742
 
1744
-	if (in_array($nom, $autsanscookie)) {
1745
-		if (test_espace_prive()){
1746
-			include_spip('base/connect_sql');
1747
-			if (!$strict or !spip_connect()){
1748
-				return true;
1749
-			}
1750
-		}
1751
-	}
1752
-	return false;
1743
+    if (in_array($nom, $autsanscookie)) {
1744
+        if (test_espace_prive()){
1745
+            include_spip('base/connect_sql');
1746
+            if (!$strict or !spip_connect()){
1747
+                return true;
1748
+            }
1749
+        }
1750
+    }
1751
+    return false;
1753 1752
 }
1754 1753
 
1755 1754
 /**
@@ -1775,99 +1774,99 @@  discard block
 block discarded – undo
1775 1774
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1776 1775
  */
1777 1776
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1778
-	if ($public === null) {
1779
-		$public = !test_espace_prive();
1780
-	}
1781
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1782
-
1783
-	if (!$public) {
1784
-		if (!$entite) {
1785
-			return '';
1786
-		}
1787
-		if (!function_exists('generer_url_ecrire_objet')) {
1788
-			include_spip('inc/urls');
1789
-		}
1790
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1791
-	} else {
1792
-		if ($type === null) {
1793
-			$type = (isset($GLOBALS['type_urls']))
1794
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1795
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1796
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1797
-		}
1798
-
1799
-		$f = charger_fonction($type, 'urls', true);
1800
-		// se rabattre sur les urls page si les urls perso non dispo
1801
-		if (!$f) {
1802
-			$f = charger_fonction('page', 'urls', true);
1803
-		}
1804
-
1805
-		// si $entite='', on veut la fonction de passage URL ==> id
1806
-		// sinon on veut effectuer le passage id ==> URL
1807
-		if (!$entite) {
1808
-			return $f;
1809
-		}
1810
-
1811
-		// mais d'abord il faut tester le cas des urls sur une
1812
-		// base distante
1813
-		if (is_string($public)
1814
-			and $g = charger_fonction('connect', 'urls', true)
1815
-		) {
1816
-			$f = $g;
1817
-		}
1818
-
1819
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1820
-
1821
-	}
1822
-	if ($res) {
1823
-		return $res;
1824
-	}
1825
-	// Sinon c'est un raccourci ou compat SPIP < 2
1826
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1827
-		if (!function_exists($f .= '_dist')) {
1828
-			$f = '';
1829
-		}
1830
-	}
1831
-	if ($f) {
1832
-		$url = $f($id, $args, $ancre);
1833
-		if (strlen($args)) {
1834
-			$url .= strstr($url, '?')
1835
-				? '&amp;' . $args
1836
-				: '?' . $args;
1837
-		}
1838
-
1839
-		return $url;
1840
-	}
1841
-	// On a ete gentil mais la ....
1842
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1843
-
1844
-	return '';
1777
+    if ($public === null) {
1778
+        $public = !test_espace_prive();
1779
+    }
1780
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1781
+
1782
+    if (!$public) {
1783
+        if (!$entite) {
1784
+            return '';
1785
+        }
1786
+        if (!function_exists('generer_url_ecrire_objet')) {
1787
+            include_spip('inc/urls');
1788
+        }
1789
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1790
+    } else {
1791
+        if ($type === null) {
1792
+            $type = (isset($GLOBALS['type_urls']))
1793
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1794
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1795
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1796
+        }
1797
+
1798
+        $f = charger_fonction($type, 'urls', true);
1799
+        // se rabattre sur les urls page si les urls perso non dispo
1800
+        if (!$f) {
1801
+            $f = charger_fonction('page', 'urls', true);
1802
+        }
1803
+
1804
+        // si $entite='', on veut la fonction de passage URL ==> id
1805
+        // sinon on veut effectuer le passage id ==> URL
1806
+        if (!$entite) {
1807
+            return $f;
1808
+        }
1809
+
1810
+        // mais d'abord il faut tester le cas des urls sur une
1811
+        // base distante
1812
+        if (is_string($public)
1813
+            and $g = charger_fonction('connect', 'urls', true)
1814
+        ) {
1815
+            $f = $g;
1816
+        }
1817
+
1818
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1819
+
1820
+    }
1821
+    if ($res) {
1822
+        return $res;
1823
+    }
1824
+    // Sinon c'est un raccourci ou compat SPIP < 2
1825
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1826
+        if (!function_exists($f .= '_dist')) {
1827
+            $f = '';
1828
+        }
1829
+    }
1830
+    if ($f) {
1831
+        $url = $f($id, $args, $ancre);
1832
+        if (strlen($args)) {
1833
+            $url .= strstr($url, '?')
1834
+                ? '&amp;' . $args
1835
+                : '?' . $args;
1836
+        }
1837
+
1838
+        return $url;
1839
+    }
1840
+    // On a ete gentil mais la ....
1841
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1842
+
1843
+    return '';
1845 1844
 }
1846 1845
 
1847 1846
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1848
-	$exec = objet_info($entite, 'url_edit');
1849
-	$url = generer_url_ecrire($exec, $args);
1850
-	if (intval($id)) {
1851
-		$url = parametre_url($url, id_table_objet($entite), $id);
1852
-	} else {
1853
-		$url = parametre_url($url, 'new', 'oui');
1854
-	}
1855
-	if ($ancre) {
1856
-		$url = ancre_url($url, $ancre);
1857
-	}
1847
+    $exec = objet_info($entite, 'url_edit');
1848
+    $url = generer_url_ecrire($exec, $args);
1849
+    if (intval($id)) {
1850
+        $url = parametre_url($url, id_table_objet($entite), $id);
1851
+    } else {
1852
+        $url = parametre_url($url, 'new', 'oui');
1853
+    }
1854
+    if ($ancre) {
1855
+        $url = ancre_url($url, $ancre);
1856
+    }
1858 1857
 
1859
-	return $url;
1858
+    return $url;
1860 1859
 }
1861 1860
 
1862 1861
 // https://code.spip.net/@urls_connect_dist
1863 1862
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1864
-	include_spip('base/connect_sql');
1865
-	$id_type = id_table_objet($entite, $public);
1863
+    include_spip('base/connect_sql');
1864
+    $id_type = id_table_objet($entite, $public);
1866 1865
 
1867
-	return _DIR_RACINE . get_spip_script('./')
1868
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1869
-	. (!$args ? '' : "&$args")
1870
-	. (!$ancre ? '' : "#$ancre");
1866
+    return _DIR_RACINE . get_spip_script('./')
1867
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1868
+    . (!$args ? '' : "&$args")
1869
+    . (!$ancre ? '' : "#$ancre");
1871 1870
 }
1872 1871
 
1873 1872
 
@@ -1878,32 +1877,32 @@  discard block
 block discarded – undo
1878 1877
  * @return string
1879 1878
  */
1880 1879
 function urlencode_1738($url) {
1881
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1882
-		$uri = '';
1883
-		for ($i = 0; $i < strlen($url); $i++) {
1884
-			if (ord($a = $url[$i]) > 127) {
1885
-				$a = rawurlencode($a);
1886
-			}
1887
-			$uri .= $a;
1888
-		}
1889
-		$url = $uri;
1890
-	}
1880
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1881
+        $uri = '';
1882
+        for ($i = 0; $i < strlen($url); $i++) {
1883
+            if (ord($a = $url[$i]) > 127) {
1884
+                $a = rawurlencode($a);
1885
+            }
1886
+            $uri .= $a;
1887
+        }
1888
+        $url = $uri;
1889
+    }
1891 1890
 
1892
-	return quote_amp($url);
1891
+    return quote_amp($url);
1893 1892
 }
1894 1893
 
1895 1894
 // https://code.spip.net/@generer_url_entite_absolue
1896 1895
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1897
-	if (!$connect) {
1898
-		$connect = true;
1899
-	}
1900
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1901
-	if (!preg_match(',^\w+:,', $h)) {
1902
-		include_spip('inc/filtres_mini');
1903
-		$h = url_absolue($h);
1904
-	}
1896
+    if (!$connect) {
1897
+        $connect = true;
1898
+    }
1899
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1900
+    if (!preg_match(',^\w+:,', $h)) {
1901
+        include_spip('inc/filtres_mini');
1902
+        $h = url_absolue($h);
1903
+    }
1905 1904
 
1906
-	return $h;
1905
+    return $h;
1907 1906
 }
1908 1907
 
1909 1908
 
@@ -1919,11 +1918,11 @@  discard block
 block discarded – undo
1919 1918
  *     true si la valeur est considérée active ; false sinon.
1920 1919
  **/
1921 1920
 function test_valeur_serveur($truc) {
1922
-	if (!$truc) {
1923
-		return false;
1924
-	}
1921
+    if (!$truc) {
1922
+        return false;
1923
+    }
1925 1924
 
1926
-	return (strtolower($truc) !== 'off');
1925
+    return (strtolower($truc) !== 'off');
1927 1926
 }
1928 1927
 
1929 1928
 //
@@ -1951,80 +1950,80 @@  discard block
 block discarded – undo
1951 1950
  */
1952 1951
 function url_de_base($profondeur = null) {
1953 1952
 
1954
-	static $url = array();
1955
-	if (is_array($profondeur)) {
1956
-		return $url = $profondeur;
1957
-	}
1958
-	if ($profondeur === false) {
1959
-		return $url;
1960
-	}
1961
-
1962
-	if (is_null($profondeur)) {
1963
-		$profondeur = $GLOBALS['profondeur_url'];
1964
-	}
1965
-
1966
-	if (isset($url[$profondeur])) {
1967
-		return $url[$profondeur];
1968
-	}
1969
-
1970
-	$http = 'http';
1971
-
1972
-	if (
1973
-		isset($_SERVER["SCRIPT_URI"])
1974
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1975
-	) {
1976
-		$http = 'https';
1977
-	} elseif (
1978
-		isset($_SERVER['HTTPS'])
1979
-		and test_valeur_serveur($_SERVER['HTTPS'])
1980
-	) {
1981
-		$http = 'https';
1982
-	}
1983
-
1984
-	// note : HTTP_HOST contient le :port si necessaire
1985
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1986
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1987
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1988
-		$host = $GLOBALS['meta']['adresse_site'];
1989
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1990
-			$http = $scheme;
1991
-			$host = str_replace("{$scheme}://", '', $host);
1992
-		}
1993
-	}
1994
-	if (isset($_SERVER['SERVER_PORT'])
1995
-		and $port = $_SERVER['SERVER_PORT']
1996
-		and strpos($host, ":") == false
1997
-	) {
1998
-		if (!defined('_PORT_HTTP_STANDARD')) {
1999
-			define('_PORT_HTTP_STANDARD', '80');
2000
-		}
2001
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2002
-			define('_PORT_HTTPS_STANDARD', '443');
2003
-		}
2004
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2005
-			$host .= ":$port";
2006
-		}
2007
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2008
-			$host .= ":$port";
2009
-		}
2010
-	}
2011
-
2012
-	if (!$GLOBALS['REQUEST_URI']) {
2013
-		if (isset($_SERVER['REQUEST_URI'])) {
2014
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2015
-		} else {
2016
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2017
-			if (!empty($_SERVER['QUERY_STRING'])
2018
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2019
-			) {
2020
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2021
-			}
2022
-		}
2023
-	}
2024
-
2025
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2026
-
2027
-	return $url[$profondeur];
1953
+    static $url = array();
1954
+    if (is_array($profondeur)) {
1955
+        return $url = $profondeur;
1956
+    }
1957
+    if ($profondeur === false) {
1958
+        return $url;
1959
+    }
1960
+
1961
+    if (is_null($profondeur)) {
1962
+        $profondeur = $GLOBALS['profondeur_url'];
1963
+    }
1964
+
1965
+    if (isset($url[$profondeur])) {
1966
+        return $url[$profondeur];
1967
+    }
1968
+
1969
+    $http = 'http';
1970
+
1971
+    if (
1972
+        isset($_SERVER["SCRIPT_URI"])
1973
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1974
+    ) {
1975
+        $http = 'https';
1976
+    } elseif (
1977
+        isset($_SERVER['HTTPS'])
1978
+        and test_valeur_serveur($_SERVER['HTTPS'])
1979
+    ) {
1980
+        $http = 'https';
1981
+    }
1982
+
1983
+    // note : HTTP_HOST contient le :port si necessaire
1984
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1985
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1986
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1987
+        $host = $GLOBALS['meta']['adresse_site'];
1988
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1989
+            $http = $scheme;
1990
+            $host = str_replace("{$scheme}://", '', $host);
1991
+        }
1992
+    }
1993
+    if (isset($_SERVER['SERVER_PORT'])
1994
+        and $port = $_SERVER['SERVER_PORT']
1995
+        and strpos($host, ":") == false
1996
+    ) {
1997
+        if (!defined('_PORT_HTTP_STANDARD')) {
1998
+            define('_PORT_HTTP_STANDARD', '80');
1999
+        }
2000
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2001
+            define('_PORT_HTTPS_STANDARD', '443');
2002
+        }
2003
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2004
+            $host .= ":$port";
2005
+        }
2006
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2007
+            $host .= ":$port";
2008
+        }
2009
+    }
2010
+
2011
+    if (!$GLOBALS['REQUEST_URI']) {
2012
+        if (isset($_SERVER['REQUEST_URI'])) {
2013
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2014
+        } else {
2015
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2016
+            if (!empty($_SERVER['QUERY_STRING'])
2017
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2018
+            ) {
2019
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2020
+            }
2021
+        }
2022
+    }
2023
+
2024
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2025
+
2026
+    return $url[$profondeur];
2028 2027
 }
2029 2028
 
2030 2029
 /**
@@ -2037,26 +2036,26 @@  discard block
 block discarded – undo
2037 2036
  * @return string
2038 2037
  */
2039 2038
 function url_de_($http, $host, $request, $prof = 0) {
2040
-	$prof = max($prof, 0);
2039
+    $prof = max($prof, 0);
2041 2040
 
2042
-	$myself = ltrim($request, '/');
2043
-	# supprimer la chaine de GET
2044
-	list($myself) = explode('?', $myself);
2045
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2046
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2047
-	if (strpos($myself,'://') !== false) {
2048
-		$myself = explode('://',$myself);
2049
-		array_shift($myself);
2050
-		$myself = implode('://',$myself);
2051
-		$myself = explode('/',$myself);
2052
-		array_shift($myself);
2053
-		$myself = implode('/',$myself);
2054
-	}
2055
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2041
+    $myself = ltrim($request, '/');
2042
+    # supprimer la chaine de GET
2043
+    list($myself) = explode('?', $myself);
2044
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2045
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2046
+    if (strpos($myself,'://') !== false) {
2047
+        $myself = explode('://',$myself);
2048
+        array_shift($myself);
2049
+        $myself = implode('://',$myself);
2050
+        $myself = explode('/',$myself);
2051
+        array_shift($myself);
2052
+        $myself = implode('/',$myself);
2053
+    }
2054
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2056 2055
 
2057
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2056
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2058 2057
 
2059
-	return $url;
2058
+    return $url;
2060 2059
 }
2061 2060
 
2062 2061
 
@@ -2091,26 +2090,26 @@  discard block
 block discarded – undo
2091 2090
  * @return string URL
2092 2091
  **/
2093 2092
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
2094
-	if (!$rel) {
2095
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2096
-	} else {
2097
-		if (!is_string($rel)) {
2098
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2099
-				('./' . _SPIP_ECRIRE_SCRIPT);
2100
-		}
2101
-	}
2102
-
2103
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2104
-	if ($script and ($script <> 'accueil' or $rel)) {
2105
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2106
-	} elseif ($args) {
2107
-		$args = "?$args";
2108
-	}
2109
-	if ($ancre) {
2110
-		$args .= "#$ancre";
2111
-	}
2112
-
2113
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2093
+    if (!$rel) {
2094
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2095
+    } else {
2096
+        if (!is_string($rel)) {
2097
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2098
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2099
+        }
2100
+    }
2101
+
2102
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2103
+    if ($script and ($script <> 'accueil' or $rel)) {
2104
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2105
+    } elseif ($args) {
2106
+        $args = "?$args";
2107
+    }
2108
+    if ($ancre) {
2109
+        $args .= "#$ancre";
2110
+    }
2111
+
2112
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2114 2113
 }
2115 2114
 
2116 2115
 //
@@ -2132,12 +2131,12 @@  discard block
 block discarded – undo
2132 2131
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2133 2132
  **/
2134 2133
 function get_spip_script($default = '') {
2135
-	# cas define('_SPIP_SCRIPT', '');
2136
-	if (_SPIP_SCRIPT) {
2137
-		return _SPIP_SCRIPT;
2138
-	} else {
2139
-		return $default;
2140
-	}
2134
+    # cas define('_SPIP_SCRIPT', '');
2135
+    if (_SPIP_SCRIPT) {
2136
+        return _SPIP_SCRIPT;
2137
+    } else {
2138
+        return $default;
2139
+    }
2141 2140
 }
2142 2141
 
2143 2142
 /**
@@ -2166,39 +2165,39 @@  discard block
 block discarded – undo
2166 2165
  * @return string URL
2167 2166
  **/
2168 2167
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2169
-	// si le script est une action (spip_pass, spip_inscription),
2170
-	// standardiser vers la nouvelle API
2171
-
2172
-	if (!$action) {
2173
-		$action = get_spip_script();
2174
-	}
2175
-	if ($script) {
2176
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2177
-	}
2178
-
2179
-	if ($args) {
2180
-		if (is_array($args)) {
2181
-			$r = '';
2182
-			foreach ($args as $k => $v) {
2183
-				$r .= '&' . $k . '=' . $v;
2184
-			}
2185
-			$args = substr($r, 1);
2186
-		}
2187
-		$action .=
2188
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2189
-	}
2190
-	if (!$no_entities) {
2191
-		$action = quote_amp($action);
2192
-	}
2193
-
2194
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2195
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2168
+    // si le script est une action (spip_pass, spip_inscription),
2169
+    // standardiser vers la nouvelle API
2170
+
2171
+    if (!$action) {
2172
+        $action = get_spip_script();
2173
+    }
2174
+    if ($script) {
2175
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2176
+    }
2177
+
2178
+    if ($args) {
2179
+        if (is_array($args)) {
2180
+            $r = '';
2181
+            foreach ($args as $k => $v) {
2182
+                $r .= '&' . $k . '=' . $v;
2183
+            }
2184
+            $args = substr($r, 1);
2185
+        }
2186
+        $action .=
2187
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2188
+    }
2189
+    if (!$no_entities) {
2190
+        $action = quote_amp($action);
2191
+    }
2192
+
2193
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2194
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2196 2195
 }
2197 2196
 
2198 2197
 // https://code.spip.net/@generer_url_prive
2199 2198
 function generer_url_prive($script, $args = "", $no_entities = false) {
2200 2199
 
2201
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2200
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2202 2201
 }
2203 2202
 
2204 2203
 // Pour les formulaires en methode POST,
@@ -2223,19 +2222,19 @@  discard block
 block discarded – undo
2223 2222
  **/
2224 2223
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2225 2224
 
2226
-	$script1 = explode('&', $script);
2227
-	$script1 = reset($script1);
2225
+    $script1 = explode('&', $script);
2226
+    $script1 = reset($script1);
2228 2227
 
2229
-	return "<form action='"
2230
-	. ($script ? generer_url_ecrire($script) : '')
2231
-	. "' "
2232
-	. ($atts ? $atts : " method='post'")
2233
-	. "><div>\n"
2234
-	. "<input type='hidden' name='exec' value='$script1' />"
2235
-	. $corps
2236
-	. (!$submit ? '' :
2237
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2238
-	. "</div></form>\n";
2228
+    return "<form action='"
2229
+    . ($script ? generer_url_ecrire($script) : '')
2230
+    . "' "
2231
+    . ($atts ? $atts : " method='post'")
2232
+    . "><div>\n"
2233
+    . "<input type='hidden' name='exec' value='$script1' />"
2234
+    . $corps
2235
+    . (!$submit ? '' :
2236
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2237
+    . "</div></form>\n";
2239 2238
 }
2240 2239
 
2241 2240
 /**
@@ -2252,22 +2251,22 @@  discard block
 block discarded – undo
2252 2251
  * @return string
2253 2252
  */
2254 2253
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2255
-	// si l'on est dans l'espace prive, on garde dans l'url
2256
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2257
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2258
-	$h = (_DIR_RACINE and !$public)
2259
-		? generer_url_ecrire(_request('exec'))
2260
-		: generer_url_public();
2254
+    // si l'on est dans l'espace prive, on garde dans l'url
2255
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2256
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2257
+    $h = (_DIR_RACINE and !$public)
2258
+        ? generer_url_ecrire(_request('exec'))
2259
+        : generer_url_public();
2261 2260
 
2262
-	return "\n<form action='" .
2263
-	$h .
2264
-	"'" .
2265
-	$atts .
2266
-	">\n" .
2267
-	"<div>" .
2268
-	"\n<input type='hidden' name='action' value='$script' />" .
2269
-	$corps .
2270
-	"</div></form>";
2261
+    return "\n<form action='" .
2262
+    $h .
2263
+    "'" .
2264
+    $atts .
2265
+    ">\n" .
2266
+    "<div>" .
2267
+    "\n<input type='hidden' name='action' value='$script' />" .
2268
+    $corps .
2269
+    "</div></form>";
2271 2270
 }
2272 2271
 
2273 2272
 /**
@@ -2286,22 +2285,22 @@  discard block
 block discarded – undo
2286 2285
  *     URL
2287 2286
  */
2288 2287
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2289
-	// si l'on est dans l'espace prive, on garde dans l'url
2290
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2291
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2292
-	$url = (_DIR_RACINE and !$public)
2293
-		? generer_url_ecrire(_request('exec'))
2294
-		: generer_url_public('', '', false, false);
2295
-	$url = parametre_url($url, 'action', $script);
2296
-	if ($args) {
2297
-		$url .= quote_amp('&' . $args);
2298
-	}
2288
+    // si l'on est dans l'espace prive, on garde dans l'url
2289
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2290
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2291
+    $url = (_DIR_RACINE and !$public)
2292
+        ? generer_url_ecrire(_request('exec'))
2293
+        : generer_url_public('', '', false, false);
2294
+    $url = parametre_url($url, 'action', $script);
2295
+    if ($args) {
2296
+        $url .= quote_amp('&' . $args);
2297
+    }
2299 2298
 
2300
-	if ($no_entities) {
2301
-		$url = str_replace('&amp;', '&', $url);
2302
-	}
2299
+    if ($no_entities) {
2300
+        $url = str_replace('&amp;', '&', $url);
2301
+    }
2303 2302
 
2304
-	return $url;
2303
+    return $url;
2305 2304
 }
2306 2305
 
2307 2306
 
@@ -2314,8 +2313,8 @@  discard block
 block discarded – undo
2314 2313
  * @param string $ta Répertoire temporaire accessible
2315 2314
  */
2316 2315
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2317
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2318
-	spip_initialisation_suite();
2316
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2317
+    spip_initialisation_suite();
2319 2318
 }
2320 2319
 
2321 2320
 /**
@@ -2335,315 +2334,315 @@  discard block
 block discarded – undo
2335 2334
  * @param string $ta Répertoire temporaire accessible
2336 2335
  */
2337 2336
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2338
-	static $too_late = 0;
2339
-	if ($too_late++) {
2340
-		return;
2341
-	}
2342
-
2343
-	// Declaration des repertoires
2344
-
2345
-	// le nom du repertoire plugins/ activables/desactivables
2346
-	if (!defined('_DIR_PLUGINS')) {
2347
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2348
-	}
2349
-
2350
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2351
-	if (!defined('_DIR_PLUGINS_DIST')) {
2352
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2353
-	}
2354
-
2355
-	// le nom du repertoire des librairies
2356
-	if (!defined('_DIR_LIB')) {
2357
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2358
-	}
2359
-
2360
-	if (!defined('_DIR_IMG')) {
2361
-		define('_DIR_IMG', $pa);
2362
-	}
2363
-	if (!defined('_DIR_LOGOS')) {
2364
-		define('_DIR_LOGOS', $pa);
2365
-	}
2366
-	if (!defined('_DIR_IMG_ICONES')) {
2367
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2368
-	}
2369
-
2370
-	if (!defined('_DIR_DUMP')) {
2371
-		define('_DIR_DUMP', $ti . "dump/");
2372
-	}
2373
-	if (!defined('_DIR_SESSIONS')) {
2374
-		define('_DIR_SESSIONS', $ti . "sessions/");
2375
-	}
2376
-	if (!defined('_DIR_TRANSFERT')) {
2377
-		define('_DIR_TRANSFERT', $ti . "upload/");
2378
-	}
2379
-	if (!defined('_DIR_CACHE')) {
2380
-		define('_DIR_CACHE', $ti . "cache/");
2381
-	}
2382
-	if (!defined('_DIR_CACHE_XML')) {
2383
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2384
-	}
2385
-	if (!defined('_DIR_SKELS')) {
2386
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2387
-	}
2388
-	if (!defined('_DIR_AIDE')) {
2389
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2390
-	}
2391
-	if (!defined('_DIR_TMP')) {
2392
-		define('_DIR_TMP', $ti);
2393
-	}
2394
-
2395
-	if (!defined('_DIR_VAR')) {
2396
-		define('_DIR_VAR', $ta);
2397
-	}
2398
-
2399
-	if (!defined('_DIR_ETC')) {
2400
-		define('_DIR_ETC', $pi);
2401
-	}
2402
-	if (!defined('_DIR_CONNECT')) {
2403
-		define('_DIR_CONNECT', $pi);
2404
-	}
2405
-	if (!defined('_DIR_CHMOD')) {
2406
-		define('_DIR_CHMOD', $pi);
2407
-	}
2408
-
2409
-	if (!isset($GLOBALS['test_dirs']))
2410
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2411
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2412
-	{
2413
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2414
-	}
2415
-
2416
-	// Declaration des fichiers
2417
-
2418
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2419
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2420
-	}
2421
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2422
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2423
-	}
2424
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2425
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2426
-	}
2427
-	if (!defined('_CACHE_PIPELINES')) {
2428
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2429
-	}
2430
-	if (!defined('_CACHE_CHEMIN')) {
2431
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2432
-	}
2433
-
2434
-	# attention .php obligatoire pour ecrire_fichier_securise
2435
-	if (!defined('_FILE_META')) {
2436
-		define('_FILE_META', $ti . 'meta_cache.php');
2437
-	}
2438
-	if (!defined('_DIR_LOG')) {
2439
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2440
-	}
2441
-	if (!defined('_FILE_LOG')) {
2442
-		define('_FILE_LOG', 'spip');
2443
-	}
2444
-	if (!defined('_FILE_LOG_SUFFIX')) {
2445
-		define('_FILE_LOG_SUFFIX', '.log');
2446
-	}
2447
-
2448
-	// Le fichier de connexion a la base de donnees
2449
-	// tient compte des anciennes versions (inc_connect...)
2450
-	if (!defined('_FILE_CONNECT_INS')) {
2451
-		define('_FILE_CONNECT_INS', 'connect');
2452
-	}
2453
-	if (!defined('_FILE_CONNECT')) {
2454
-		define('_FILE_CONNECT',
2455
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2456
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2457
-				: false)));
2458
-	}
2459
-
2460
-	// Le fichier de reglages des droits
2461
-	if (!defined('_FILE_CHMOD_INS')) {
2462
-		define('_FILE_CHMOD_INS', 'chmod');
2463
-	}
2464
-	if (!defined('_FILE_CHMOD')) {
2465
-		define('_FILE_CHMOD',
2466
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2467
-			: false));
2468
-	}
2469
-
2470
-	if (!defined('_FILE_LDAP')) {
2471
-		define('_FILE_LDAP', 'ldap.php');
2472
-	}
2473
-
2474
-	if (!defined('_FILE_TMP_SUFFIX')) {
2475
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2476
-	}
2477
-	if (!defined('_FILE_CONNECT_TMP')) {
2478
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2479
-	}
2480
-	if (!defined('_FILE_CHMOD_TMP')) {
2481
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2482
-	}
2483
-
2484
-	// Definition des droits d'acces en ecriture
2485
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2486
-		include_once _FILE_CHMOD;
2487
-	}
2488
-
2489
-	// Se mefier des fichiers mal remplis!
2490
-	if (!defined('_SPIP_CHMOD')) {
2491
-		define('_SPIP_CHMOD', 0777);
2492
-	}
2493
-
2494
-	if (!defined('_DEFAULT_CHARSET')) {
2495
-		/** Le charset par défaut lors de l'installation */
2496
-		define('_DEFAULT_CHARSET', 'utf-8');
2497
-	}
2498
-	if (!defined('_ROOT_PLUGINS')) {
2499
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2500
-	}
2501
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2502
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2503
-	}
2504
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2505
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2506
-	}
2507
-
2508
-	// La taille des Log
2509
-	if (!defined('_MAX_LOG')) {
2510
-		define('_MAX_LOG', 100);
2511
-	}
2512
-
2513
-	// Sommes-nous dans l'empire du Mal ?
2514
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2515
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2516
-		if (!defined('_OS_SERVEUR')) {
2517
-			define('_OS_SERVEUR', 'windows');
2518
-		}
2519
-		if (!defined('_SPIP_LOCK_MODE')) {
2520
-			define('_SPIP_LOCK_MODE', 1);
2521
-		} // utiliser le flock php
2522
-	} else {
2523
-		if (!defined('_OS_SERVEUR')) {
2524
-			define('_OS_SERVEUR', '');
2525
-		}
2526
-		if (!defined('_SPIP_LOCK_MODE')) {
2527
-			define('_SPIP_LOCK_MODE', 1);
2528
-		} // utiliser le flock php
2529
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2530
-	}
2531
-
2532
-	// Langue par defaut
2533
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2534
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2535
-	}
2536
-
2537
-	//
2538
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2539
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2540
-	// pour le rendre surchargeable, on va provoquer un reecriture
2541
-	// systematique du noyau ou une baisse de perfs => a etudier)
2542
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2543
-
2544
-	// charger tout de suite le path et son cache
2545
-	load_path_cache();
2546
-
2547
-	// *********** traiter les variables ************
2548
-
2549
-	//
2550
-	// Securite
2551
-	//
2552
-
2553
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2554
-	if (isset($_REQUEST['GLOBALS'])) {
2555
-		die();
2556
-	}
2557
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2558
-	spip_desinfecte($_GET);
2559
-	spip_desinfecte($_POST);
2560
-	spip_desinfecte($_COOKIE);
2561
-	spip_desinfecte($_REQUEST);
2562
-
2563
-	// appliquer le cookie_prefix
2564
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2565
-		include_spip('inc/cookie');
2566
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2567
-	}
2568
-
2569
-	//
2570
-	// Capacites php (en fonction de la version)
2571
-	//
2572
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2573
-		&& function_exists("ini_get")
2574
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2575
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2576
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2577
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2578
-		(get_cfg_var('upload_max_filesize') > 0));
2579
-
2580
-
2581
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2582
-	if (isset($_SERVER['REQUEST_URI'])) {
2583
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2584
-	} else {
2585
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2586
-		if (!empty($_SERVER['QUERY_STRING'])
2587
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2588
-		) {
2589
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2590
-		}
2591
-	}
2592
-
2593
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2594
-	if (!defined('_RENOUVELLE_ALEA')) {
2595
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2596
-	}
2597
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2598
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2599
-	}
2600
-
2601
-	// charger les meta si possible et renouveller l'alea au besoin
2602
-	// charge aussi effacer_meta et ecrire_meta
2603
-	$inc_meta = charger_fonction('meta', 'inc');
2604
-	$inc_meta();
2605
-
2606
-	// nombre de repertoires depuis la racine
2607
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2608
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2609
-	// le calcul est faux)
2610
-	if (!_DIR_RESTREINT) {
2611
-		$GLOBALS['profondeur_url'] = 1;
2612
-	} else {
2613
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2614
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2615
-		if (!$uri_ref
2616
-			// si on est appele avec un autre ti, on est sans doute en mutu
2617
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2618
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2619
-			// s'en remettre a l'adresse du site. alea jacta est.
2620
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2621
-		) {
2622
-
2623
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2624
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2625
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2626
-			} else {
2627
-				$uri_ref = "";
2628
-			}
2629
-		}
2630
-		if (!$uri or !$uri_ref) {
2631
-			$GLOBALS['profondeur_url'] = 0;
2632
-		} else {
2633
-			$GLOBALS['profondeur_url'] = max(0,
2634
-				substr_count($uri[0], '/')
2635
-				- substr_count($uri_ref, '/'));
2636
-		}
2637
-	}
2638
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2639
-	if (_FILE_CONNECT) {
2640
-		if (verifier_visiteur() == '0minirezo'
2641
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2642
-			and !isset($_COOKIE['spip_admin'])
2643
-		) {
2644
-			clear_path_cache();
2645
-		}
2646
-	}
2337
+    static $too_late = 0;
2338
+    if ($too_late++) {
2339
+        return;
2340
+    }
2341
+
2342
+    // Declaration des repertoires
2343
+
2344
+    // le nom du repertoire plugins/ activables/desactivables
2345
+    if (!defined('_DIR_PLUGINS')) {
2346
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2347
+    }
2348
+
2349
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2350
+    if (!defined('_DIR_PLUGINS_DIST')) {
2351
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2352
+    }
2353
+
2354
+    // le nom du repertoire des librairies
2355
+    if (!defined('_DIR_LIB')) {
2356
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2357
+    }
2358
+
2359
+    if (!defined('_DIR_IMG')) {
2360
+        define('_DIR_IMG', $pa);
2361
+    }
2362
+    if (!defined('_DIR_LOGOS')) {
2363
+        define('_DIR_LOGOS', $pa);
2364
+    }
2365
+    if (!defined('_DIR_IMG_ICONES')) {
2366
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2367
+    }
2368
+
2369
+    if (!defined('_DIR_DUMP')) {
2370
+        define('_DIR_DUMP', $ti . "dump/");
2371
+    }
2372
+    if (!defined('_DIR_SESSIONS')) {
2373
+        define('_DIR_SESSIONS', $ti . "sessions/");
2374
+    }
2375
+    if (!defined('_DIR_TRANSFERT')) {
2376
+        define('_DIR_TRANSFERT', $ti . "upload/");
2377
+    }
2378
+    if (!defined('_DIR_CACHE')) {
2379
+        define('_DIR_CACHE', $ti . "cache/");
2380
+    }
2381
+    if (!defined('_DIR_CACHE_XML')) {
2382
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2383
+    }
2384
+    if (!defined('_DIR_SKELS')) {
2385
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2386
+    }
2387
+    if (!defined('_DIR_AIDE')) {
2388
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2389
+    }
2390
+    if (!defined('_DIR_TMP')) {
2391
+        define('_DIR_TMP', $ti);
2392
+    }
2393
+
2394
+    if (!defined('_DIR_VAR')) {
2395
+        define('_DIR_VAR', $ta);
2396
+    }
2397
+
2398
+    if (!defined('_DIR_ETC')) {
2399
+        define('_DIR_ETC', $pi);
2400
+    }
2401
+    if (!defined('_DIR_CONNECT')) {
2402
+        define('_DIR_CONNECT', $pi);
2403
+    }
2404
+    if (!defined('_DIR_CHMOD')) {
2405
+        define('_DIR_CHMOD', $pi);
2406
+    }
2407
+
2408
+    if (!isset($GLOBALS['test_dirs']))
2409
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2410
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2411
+    {
2412
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2413
+    }
2414
+
2415
+    // Declaration des fichiers
2416
+
2417
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2418
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2419
+    }
2420
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2421
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2422
+    }
2423
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2424
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2425
+    }
2426
+    if (!defined('_CACHE_PIPELINES')) {
2427
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2428
+    }
2429
+    if (!defined('_CACHE_CHEMIN')) {
2430
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2431
+    }
2432
+
2433
+    # attention .php obligatoire pour ecrire_fichier_securise
2434
+    if (!defined('_FILE_META')) {
2435
+        define('_FILE_META', $ti . 'meta_cache.php');
2436
+    }
2437
+    if (!defined('_DIR_LOG')) {
2438
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2439
+    }
2440
+    if (!defined('_FILE_LOG')) {
2441
+        define('_FILE_LOG', 'spip');
2442
+    }
2443
+    if (!defined('_FILE_LOG_SUFFIX')) {
2444
+        define('_FILE_LOG_SUFFIX', '.log');
2445
+    }
2446
+
2447
+    // Le fichier de connexion a la base de donnees
2448
+    // tient compte des anciennes versions (inc_connect...)
2449
+    if (!defined('_FILE_CONNECT_INS')) {
2450
+        define('_FILE_CONNECT_INS', 'connect');
2451
+    }
2452
+    if (!defined('_FILE_CONNECT')) {
2453
+        define('_FILE_CONNECT',
2454
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2455
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2456
+                : false)));
2457
+    }
2458
+
2459
+    // Le fichier de reglages des droits
2460
+    if (!defined('_FILE_CHMOD_INS')) {
2461
+        define('_FILE_CHMOD_INS', 'chmod');
2462
+    }
2463
+    if (!defined('_FILE_CHMOD')) {
2464
+        define('_FILE_CHMOD',
2465
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2466
+            : false));
2467
+    }
2468
+
2469
+    if (!defined('_FILE_LDAP')) {
2470
+        define('_FILE_LDAP', 'ldap.php');
2471
+    }
2472
+
2473
+    if (!defined('_FILE_TMP_SUFFIX')) {
2474
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2475
+    }
2476
+    if (!defined('_FILE_CONNECT_TMP')) {
2477
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2478
+    }
2479
+    if (!defined('_FILE_CHMOD_TMP')) {
2480
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2481
+    }
2482
+
2483
+    // Definition des droits d'acces en ecriture
2484
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2485
+        include_once _FILE_CHMOD;
2486
+    }
2487
+
2488
+    // Se mefier des fichiers mal remplis!
2489
+    if (!defined('_SPIP_CHMOD')) {
2490
+        define('_SPIP_CHMOD', 0777);
2491
+    }
2492
+
2493
+    if (!defined('_DEFAULT_CHARSET')) {
2494
+        /** Le charset par défaut lors de l'installation */
2495
+        define('_DEFAULT_CHARSET', 'utf-8');
2496
+    }
2497
+    if (!defined('_ROOT_PLUGINS')) {
2498
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2499
+    }
2500
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2501
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2502
+    }
2503
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2504
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2505
+    }
2506
+
2507
+    // La taille des Log
2508
+    if (!defined('_MAX_LOG')) {
2509
+        define('_MAX_LOG', 100);
2510
+    }
2511
+
2512
+    // Sommes-nous dans l'empire du Mal ?
2513
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2514
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2515
+        if (!defined('_OS_SERVEUR')) {
2516
+            define('_OS_SERVEUR', 'windows');
2517
+        }
2518
+        if (!defined('_SPIP_LOCK_MODE')) {
2519
+            define('_SPIP_LOCK_MODE', 1);
2520
+        } // utiliser le flock php
2521
+    } else {
2522
+        if (!defined('_OS_SERVEUR')) {
2523
+            define('_OS_SERVEUR', '');
2524
+        }
2525
+        if (!defined('_SPIP_LOCK_MODE')) {
2526
+            define('_SPIP_LOCK_MODE', 1);
2527
+        } // utiliser le flock php
2528
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2529
+    }
2530
+
2531
+    // Langue par defaut
2532
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2533
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2534
+    }
2535
+
2536
+    //
2537
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2538
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2539
+    // pour le rendre surchargeable, on va provoquer un reecriture
2540
+    // systematique du noyau ou une baisse de perfs => a etudier)
2541
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2542
+
2543
+    // charger tout de suite le path et son cache
2544
+    load_path_cache();
2545
+
2546
+    // *********** traiter les variables ************
2547
+
2548
+    //
2549
+    // Securite
2550
+    //
2551
+
2552
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2553
+    if (isset($_REQUEST['GLOBALS'])) {
2554
+        die();
2555
+    }
2556
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2557
+    spip_desinfecte($_GET);
2558
+    spip_desinfecte($_POST);
2559
+    spip_desinfecte($_COOKIE);
2560
+    spip_desinfecte($_REQUEST);
2561
+
2562
+    // appliquer le cookie_prefix
2563
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2564
+        include_spip('inc/cookie');
2565
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2566
+    }
2567
+
2568
+    //
2569
+    // Capacites php (en fonction de la version)
2570
+    //
2571
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2572
+        && function_exists("ini_get")
2573
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2574
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2575
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2576
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2577
+        (get_cfg_var('upload_max_filesize') > 0));
2578
+
2579
+
2580
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2581
+    if (isset($_SERVER['REQUEST_URI'])) {
2582
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2583
+    } else {
2584
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2585
+        if (!empty($_SERVER['QUERY_STRING'])
2586
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2587
+        ) {
2588
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2589
+        }
2590
+    }
2591
+
2592
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2593
+    if (!defined('_RENOUVELLE_ALEA')) {
2594
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2595
+    }
2596
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2597
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2598
+    }
2599
+
2600
+    // charger les meta si possible et renouveller l'alea au besoin
2601
+    // charge aussi effacer_meta et ecrire_meta
2602
+    $inc_meta = charger_fonction('meta', 'inc');
2603
+    $inc_meta();
2604
+
2605
+    // nombre de repertoires depuis la racine
2606
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2607
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2608
+    // le calcul est faux)
2609
+    if (!_DIR_RESTREINT) {
2610
+        $GLOBALS['profondeur_url'] = 1;
2611
+    } else {
2612
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2613
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2614
+        if (!$uri_ref
2615
+            // si on est appele avec un autre ti, on est sans doute en mutu
2616
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2617
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2618
+            // s'en remettre a l'adresse du site. alea jacta est.
2619
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2620
+        ) {
2621
+
2622
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2623
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2624
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2625
+            } else {
2626
+                $uri_ref = "";
2627
+            }
2628
+        }
2629
+        if (!$uri or !$uri_ref) {
2630
+            $GLOBALS['profondeur_url'] = 0;
2631
+        } else {
2632
+            $GLOBALS['profondeur_url'] = max(0,
2633
+                substr_count($uri[0], '/')
2634
+                - substr_count($uri_ref, '/'));
2635
+        }
2636
+    }
2637
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2638
+    if (_FILE_CONNECT) {
2639
+        if (verifier_visiteur() == '0minirezo'
2640
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2641
+            and !isset($_COOKIE['spip_admin'])
2642
+        ) {
2643
+            clear_path_cache();
2644
+        }
2645
+    }
2647 2646
 
2648 2647
 }
2649 2648
 
@@ -2653,181 +2652,181 @@  discard block
 block discarded – undo
2653 2652
  *
2654 2653
  */
2655 2654
 function spip_initialisation_suite() {
2656
-	static $too_late = 0;
2657
-	if ($too_late++) {
2658
-		return;
2659
-	}
2660
-
2661
-	// taille mini des login
2662
-	if (!defined('_LOGIN_TROP_COURT')) {
2663
-		define('_LOGIN_TROP_COURT', 4);
2664
-	}
2665
-
2666
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2667
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2668
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2669
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2670
-
2671
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2672
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2673
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2674
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2675
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2676
-
2677
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2678
-		define('_PASS_LONGUEUR_MINI', 6);
2679
-	}
2680
-
2681
-
2682
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2683
-	if (!defined('_IMG_QUALITE')) {
2684
-		define('_IMG_QUALITE', 85);
2685
-	} # valeur par defaut
2686
-	if (!defined('_IMG_GD_QUALITE')) {
2687
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2688
-	} # surcharge pour la lib GD
2689
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2690
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2691
-	} # surcharge pour imagick en ligne de commande
2692
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2693
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2694
-		define('_IMG_IMAGICK_QUALITE', 75);
2695
-	} # surcharge pour imagick en PHP
2696
-
2697
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2698
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2699
-	} // poids en octet
2700
-
2701
-	// qq chaines standard
2702
-	if (!defined('_ACCESS_FILE_NAME')) {
2703
-		define('_ACCESS_FILE_NAME', '.htaccess');
2704
-	}
2705
-	if (!defined('_AUTH_USER_FILE')) {
2706
-		define('_AUTH_USER_FILE', '.htpasswd');
2707
-	}
2708
-	if (!defined('_SPIP_DUMP')) {
2709
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2710
-	}
2711
-	if (!defined('_CACHE_RUBRIQUES')) {
2712
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2713
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2714
-	}
2715
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2716
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2717
-		define('_CACHE_RUBRIQUES_MAX', 500);
2718
-	}
2719
-
2720
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2721
-		/**
2722
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2723
-		 * @var int Nombre de caractères */
2724
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2725
-	}
2726
-
2727
-	if (!defined('_EXTENSION_SQUELETTES')) {
2728
-		define('_EXTENSION_SQUELETTES', 'html');
2729
-	}
2730
-
2731
-	if (!defined('_DOCTYPE_ECRIRE')) {
2732
-		/** Définit le doctype de l’espace privé */
2733
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2734
-	}
2735
-	if (!defined('_DOCTYPE_AIDE')) {
2736
-		/** Définit le doctype de l’aide en ligne */
2737
-		define('_DOCTYPE_AIDE',
2738
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2739
-	}
2740
-
2741
-	if (!defined('_SPIP_SCRIPT')) {
2742
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2743
-		 * le script de l'espace public, alias index.php */
2744
-		define('_SPIP_SCRIPT', 'spip.php');
2745
-	}
2746
-	if (!defined('_SPIP_PAGE')) {
2747
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2748
-		define('_SPIP_PAGE', 'page');
2749
-	}
2750
-
2751
-	// le script de l'espace prive
2752
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2753
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2754
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2755
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2756
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2757
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2758
-		} else {
2759
-			define('_SPIP_ECRIRE_SCRIPT', '');
2760
-		}
2761
-	}
2762
-
2763
-
2764
-	if (!defined('_SPIP_AJAX')) {
2765
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2766
-			? 1
2767
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2768
-	}
2769
-
2770
-	// La requete est-elle en ajax ?
2771
-	if (!defined('_AJAX')) {
2772
-		define('_AJAX',
2773
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2774
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2775
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2776
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2777
-			)
2778
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2779
-		);
2780
-	}
2781
-
2782
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2783
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2784
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2785
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2786
-		define('_IMG_GD_MAX_PIXELS',
2787
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2788
-			? $GLOBALS['meta']['max_taille_vignettes']
2789
-			: 0);
2790
-	}
2791
-
2792
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2793
-		define('_MEMORY_LIMIT_MIN', 16);
2794
-	} // en Mo
2795
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2796
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2797
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2798
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2799
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2800
-			$unit = strtolower(substr($memory, -1));
2801
-			$memory = substr($memory, 0, -1);
2802
-			switch ($unit) {
2803
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2804
-				case 'g':
2805
-					$memory *= 1024;
2806
-				case 'm':
2807
-					$memory *= 1024;
2808
-				case 'k':
2809
-					$memory *= 1024;
2810
-			}
2811
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2812
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2813
-				if (trim(ini_get('memory_limit')) != $m) {
2814
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2815
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2816
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2817
-				}
2818
-			}
2819
-		} else {
2820
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2821
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2822
-			}
2823
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2824
-	}
2825
-	// Protocoles a normaliser dans les chaines de langues
2826
-	if (!defined('_PROTOCOLES_STD')) {
2827
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2828
-	}
2829
-
2830
-	init_var_mode();
2655
+    static $too_late = 0;
2656
+    if ($too_late++) {
2657
+        return;
2658
+    }
2659
+
2660
+    // taille mini des login
2661
+    if (!defined('_LOGIN_TROP_COURT')) {
2662
+        define('_LOGIN_TROP_COURT', 4);
2663
+    }
2664
+
2665
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2666
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2667
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2668
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2669
+
2670
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2671
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2672
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2673
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2674
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2675
+
2676
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2677
+        define('_PASS_LONGUEUR_MINI', 6);
2678
+    }
2679
+
2680
+
2681
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2682
+    if (!defined('_IMG_QUALITE')) {
2683
+        define('_IMG_QUALITE', 85);
2684
+    } # valeur par defaut
2685
+    if (!defined('_IMG_GD_QUALITE')) {
2686
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2687
+    } # surcharge pour la lib GD
2688
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2689
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2690
+    } # surcharge pour imagick en ligne de commande
2691
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2692
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2693
+        define('_IMG_IMAGICK_QUALITE', 75);
2694
+    } # surcharge pour imagick en PHP
2695
+
2696
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2697
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2698
+    } // poids en octet
2699
+
2700
+    // qq chaines standard
2701
+    if (!defined('_ACCESS_FILE_NAME')) {
2702
+        define('_ACCESS_FILE_NAME', '.htaccess');
2703
+    }
2704
+    if (!defined('_AUTH_USER_FILE')) {
2705
+        define('_AUTH_USER_FILE', '.htpasswd');
2706
+    }
2707
+    if (!defined('_SPIP_DUMP')) {
2708
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2709
+    }
2710
+    if (!defined('_CACHE_RUBRIQUES')) {
2711
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2712
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2713
+    }
2714
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2715
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2716
+        define('_CACHE_RUBRIQUES_MAX', 500);
2717
+    }
2718
+
2719
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2720
+        /**
2721
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2722
+         * @var int Nombre de caractères */
2723
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2724
+    }
2725
+
2726
+    if (!defined('_EXTENSION_SQUELETTES')) {
2727
+        define('_EXTENSION_SQUELETTES', 'html');
2728
+    }
2729
+
2730
+    if (!defined('_DOCTYPE_ECRIRE')) {
2731
+        /** Définit le doctype de l’espace privé */
2732
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2733
+    }
2734
+    if (!defined('_DOCTYPE_AIDE')) {
2735
+        /** Définit le doctype de l’aide en ligne */
2736
+        define('_DOCTYPE_AIDE',
2737
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2738
+    }
2739
+
2740
+    if (!defined('_SPIP_SCRIPT')) {
2741
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2742
+         * le script de l'espace public, alias index.php */
2743
+        define('_SPIP_SCRIPT', 'spip.php');
2744
+    }
2745
+    if (!defined('_SPIP_PAGE')) {
2746
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2747
+        define('_SPIP_PAGE', 'page');
2748
+    }
2749
+
2750
+    // le script de l'espace prive
2751
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2752
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2753
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2754
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2755
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2756
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2757
+        } else {
2758
+            define('_SPIP_ECRIRE_SCRIPT', '');
2759
+        }
2760
+    }
2761
+
2762
+
2763
+    if (!defined('_SPIP_AJAX')) {
2764
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2765
+            ? 1
2766
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2767
+    }
2768
+
2769
+    // La requete est-elle en ajax ?
2770
+    if (!defined('_AJAX')) {
2771
+        define('_AJAX',
2772
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2773
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2774
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2775
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2776
+            )
2777
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2778
+        );
2779
+    }
2780
+
2781
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2782
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2783
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2784
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2785
+        define('_IMG_GD_MAX_PIXELS',
2786
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2787
+            ? $GLOBALS['meta']['max_taille_vignettes']
2788
+            : 0);
2789
+    }
2790
+
2791
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2792
+        define('_MEMORY_LIMIT_MIN', 16);
2793
+    } // en Mo
2794
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2795
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2796
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2797
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2798
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2799
+            $unit = strtolower(substr($memory, -1));
2800
+            $memory = substr($memory, 0, -1);
2801
+            switch ($unit) {
2802
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2803
+                case 'g':
2804
+                    $memory *= 1024;
2805
+                case 'm':
2806
+                    $memory *= 1024;
2807
+                case 'k':
2808
+                    $memory *= 1024;
2809
+            }
2810
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2811
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2812
+                if (trim(ini_get('memory_limit')) != $m) {
2813
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2814
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2815
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2816
+                }
2817
+            }
2818
+        } else {
2819
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2820
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2821
+            }
2822
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2823
+    }
2824
+    // Protocoles a normaliser dans les chaines de langues
2825
+    if (!defined('_PROTOCOLES_STD')) {
2826
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2827
+    }
2828
+
2829
+    init_var_mode();
2831 2830
 }
2832 2831
 
2833 2832
 /**
@@ -2861,127 +2860,127 @@  discard block
 block discarded – undo
2861 2860
  * `   var_mode` (calcul ou recalcul).
2862 2861
  */
2863 2862
 function init_var_mode() {
2864
-	static $done = false;
2865
-	if (!$done) {
2866
-
2867
-		if (isset($_GET['var_mode'])) {
2868
-			$var_mode = explode(',', $_GET['var_mode']);
2869
-			// tout le monde peut calcul/recalcul
2870
-			if (!defined('_VAR_MODE')) {
2871
-				if (in_array('recalcul', $var_mode)) {
2872
-					define('_VAR_MODE', 'recalcul');
2873
-				} elseif (in_array('calcul', $var_mode)) {
2874
-					define('_VAR_MODE', 'calcul');
2875
-				}
2876
-			}
2877
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2878
-			if ($var_mode) {
2879
-				include_spip('inc/autoriser');
2880
-				// autoriser preview si preview seulement, et sinon autoriser debug
2881
-				if (autoriser(
2882
-					($_GET['var_mode'] == 'preview')
2883
-						? 'previsualiser'
2884
-						: 'debug'
2885
-				)) {
2886
-					if (in_array('traduction', $var_mode)) {
2887
-						// forcer le calcul pour passer dans traduire
2888
-						if (!defined('_VAR_MODE')) {
2889
-							define('_VAR_MODE', 'calcul');
2890
-						}
2891
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2892
-						if (!defined('_VAR_NOCACHE')) {
2893
-							define('_VAR_NOCACHE', true);
2894
-						}
2895
-						$var_mode = array_diff($var_mode, array('traduction'));
2896
-					}
2897
-					if (in_array('preview', $var_mode)) {
2898
-						// basculer sur les criteres de preview dans les boucles
2899
-						if (!defined('_VAR_PREVIEW')) {
2900
-							define('_VAR_PREVIEW', true);
2901
-						}
2902
-						// forcer le calcul
2903
-						if (!defined('_VAR_MODE')) {
2904
-							define('_VAR_MODE', 'calcul');
2905
-						}
2906
-						// et ne pas enregistrer de cache
2907
-						if (!defined('_VAR_NOCACHE')) {
2908
-							define('_VAR_NOCACHE', true);
2909
-						}
2910
-						$var_mode = array_diff($var_mode, array('preview'));
2911
-					}
2912
-					if (in_array('inclure', $var_mode)) {
2913
-						// forcer le compilo et ignorer les caches existants
2914
-						if (!defined('_VAR_MODE')) {
2915
-							define('_VAR_MODE', 'calcul');
2916
-						}
2917
-						if (!defined('_VAR_INCLURE')) {
2918
-							define('_VAR_INCLURE', true);
2919
-						}
2920
-						// et ne pas enregistrer de cache
2921
-						if (!defined('_VAR_NOCACHE')) {
2922
-							define('_VAR_NOCACHE', true);
2923
-						}
2924
-						$var_mode = array_diff($var_mode, array('inclure'));
2925
-					}
2926
-					if (in_array('urls', $var_mode)) {
2927
-						// forcer le compilo et ignorer les caches existants
2928
-						if (!defined('_VAR_MODE')) {
2929
-							define('_VAR_MODE', 'calcul');
2930
-						}
2931
-						if (!defined('_VAR_URLS')) {
2932
-							define('_VAR_URLS', true);
2933
-						}
2934
-						$var_mode = array_diff($var_mode, array('urls'));
2935
-					}
2936
-					if (in_array('images', $var_mode)) {
2937
-						// forcer le compilo et ignorer les caches existants
2938
-						if (!defined('_VAR_MODE')) {
2939
-							define('_VAR_MODE', 'calcul');
2940
-						}
2941
-						// indiquer qu'on doit recalculer les images
2942
-						if (!defined('_VAR_IMAGES')) {
2943
-							define('_VAR_IMAGES', true);
2944
-						}
2945
-						$var_mode = array_diff($var_mode, array('images'));
2946
-					}
2947
-					if (in_array('debug', $var_mode)) {
2948
-						if (!defined('_VAR_MODE')) {
2949
-							define('_VAR_MODE', 'debug');
2950
-						}
2951
-						// et ne pas enregistrer de cache
2952
-						if (!defined('_VAR_NOCACHE')) {
2953
-							define('_VAR_NOCACHE', true);
2954
-						}
2955
-						$var_mode = array_diff($var_mode, array('debug'));
2956
-					}
2957
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2958
-						define('_VAR_MODE', reset($var_mode));
2959
-					}
2960
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2961
-						spip_log($GLOBALS['visiteur_session']['nom']
2962
-							. " " . _VAR_MODE);
2963
-					}
2964
-				} // pas autorise ?
2965
-				else {
2966
-					// si on n'est pas connecte on se redirige
2967
-					if (!$GLOBALS['visiteur_session']) {
2968
-						include_spip('inc/headers');
2969
-						$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
2970
-						redirige_par_entete(generer_url_public('login','url=' . rawurlencode($redirect), true));
2971
-					}
2972
-					// sinon tant pis
2973
-				}
2974
-			}
2975
-		}
2976
-		if (!defined('_VAR_MODE')) {
2977
-			/**
2978
-			 * Indique le mode de calcul ou d'affichage de la page.
2979
-			 * @see init_var_mode()
2980
-			 */
2981
-			define('_VAR_MODE', false);
2982
-		}
2983
-		$done = true;
2984
-	}
2863
+    static $done = false;
2864
+    if (!$done) {
2865
+
2866
+        if (isset($_GET['var_mode'])) {
2867
+            $var_mode = explode(',', $_GET['var_mode']);
2868
+            // tout le monde peut calcul/recalcul
2869
+            if (!defined('_VAR_MODE')) {
2870
+                if (in_array('recalcul', $var_mode)) {
2871
+                    define('_VAR_MODE', 'recalcul');
2872
+                } elseif (in_array('calcul', $var_mode)) {
2873
+                    define('_VAR_MODE', 'calcul');
2874
+                }
2875
+            }
2876
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2877
+            if ($var_mode) {
2878
+                include_spip('inc/autoriser');
2879
+                // autoriser preview si preview seulement, et sinon autoriser debug
2880
+                if (autoriser(
2881
+                    ($_GET['var_mode'] == 'preview')
2882
+                        ? 'previsualiser'
2883
+                        : 'debug'
2884
+                )) {
2885
+                    if (in_array('traduction', $var_mode)) {
2886
+                        // forcer le calcul pour passer dans traduire
2887
+                        if (!defined('_VAR_MODE')) {
2888
+                            define('_VAR_MODE', 'calcul');
2889
+                        }
2890
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2891
+                        if (!defined('_VAR_NOCACHE')) {
2892
+                            define('_VAR_NOCACHE', true);
2893
+                        }
2894
+                        $var_mode = array_diff($var_mode, array('traduction'));
2895
+                    }
2896
+                    if (in_array('preview', $var_mode)) {
2897
+                        // basculer sur les criteres de preview dans les boucles
2898
+                        if (!defined('_VAR_PREVIEW')) {
2899
+                            define('_VAR_PREVIEW', true);
2900
+                        }
2901
+                        // forcer le calcul
2902
+                        if (!defined('_VAR_MODE')) {
2903
+                            define('_VAR_MODE', 'calcul');
2904
+                        }
2905
+                        // et ne pas enregistrer de cache
2906
+                        if (!defined('_VAR_NOCACHE')) {
2907
+                            define('_VAR_NOCACHE', true);
2908
+                        }
2909
+                        $var_mode = array_diff($var_mode, array('preview'));
2910
+                    }
2911
+                    if (in_array('inclure', $var_mode)) {
2912
+                        // forcer le compilo et ignorer les caches existants
2913
+                        if (!defined('_VAR_MODE')) {
2914
+                            define('_VAR_MODE', 'calcul');
2915
+                        }
2916
+                        if (!defined('_VAR_INCLURE')) {
2917
+                            define('_VAR_INCLURE', true);
2918
+                        }
2919
+                        // et ne pas enregistrer de cache
2920
+                        if (!defined('_VAR_NOCACHE')) {
2921
+                            define('_VAR_NOCACHE', true);
2922
+                        }
2923
+                        $var_mode = array_diff($var_mode, array('inclure'));
2924
+                    }
2925
+                    if (in_array('urls', $var_mode)) {
2926
+                        // forcer le compilo et ignorer les caches existants
2927
+                        if (!defined('_VAR_MODE')) {
2928
+                            define('_VAR_MODE', 'calcul');
2929
+                        }
2930
+                        if (!defined('_VAR_URLS')) {
2931
+                            define('_VAR_URLS', true);
2932
+                        }
2933
+                        $var_mode = array_diff($var_mode, array('urls'));
2934
+                    }
2935
+                    if (in_array('images', $var_mode)) {
2936
+                        // forcer le compilo et ignorer les caches existants
2937
+                        if (!defined('_VAR_MODE')) {
2938
+                            define('_VAR_MODE', 'calcul');
2939
+                        }
2940
+                        // indiquer qu'on doit recalculer les images
2941
+                        if (!defined('_VAR_IMAGES')) {
2942
+                            define('_VAR_IMAGES', true);
2943
+                        }
2944
+                        $var_mode = array_diff($var_mode, array('images'));
2945
+                    }
2946
+                    if (in_array('debug', $var_mode)) {
2947
+                        if (!defined('_VAR_MODE')) {
2948
+                            define('_VAR_MODE', 'debug');
2949
+                        }
2950
+                        // et ne pas enregistrer de cache
2951
+                        if (!defined('_VAR_NOCACHE')) {
2952
+                            define('_VAR_NOCACHE', true);
2953
+                        }
2954
+                        $var_mode = array_diff($var_mode, array('debug'));
2955
+                    }
2956
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2957
+                        define('_VAR_MODE', reset($var_mode));
2958
+                    }
2959
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2960
+                        spip_log($GLOBALS['visiteur_session']['nom']
2961
+                            . " " . _VAR_MODE);
2962
+                    }
2963
+                } // pas autorise ?
2964
+                else {
2965
+                    // si on n'est pas connecte on se redirige
2966
+                    if (!$GLOBALS['visiteur_session']) {
2967
+                        include_spip('inc/headers');
2968
+                        $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
2969
+                        redirige_par_entete(generer_url_public('login','url=' . rawurlencode($redirect), true));
2970
+                    }
2971
+                    // sinon tant pis
2972
+                }
2973
+            }
2974
+        }
2975
+        if (!defined('_VAR_MODE')) {
2976
+            /**
2977
+             * Indique le mode de calcul ou d'affichage de la page.
2978
+             * @see init_var_mode()
2979
+             */
2980
+            define('_VAR_MODE', false);
2981
+        }
2982
+        $done = true;
2983
+    }
2985 2984
 }
2986 2985
 
2987 2986
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2989,85 +2988,85 @@  discard block
 block discarded – undo
2989 2988
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2990 2989
 // https://code.spip.net/@spip_desinfecte
2991 2990
 function spip_desinfecte(&$t, $deep = true) {
2992
-	foreach ($t as $key => $val) {
2993
-		if (is_string($t[$key])) {
2994
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2995
-		} // traiter aussi les "texte_plus" de article_edit
2996
-		else {
2997
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2998
-				spip_desinfecte($t[$key], $deep);
2999
-			}
3000
-		}
3001
-	}
2991
+    foreach ($t as $key => $val) {
2992
+        if (is_string($t[$key])) {
2993
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2994
+        } // traiter aussi les "texte_plus" de article_edit
2995
+        else {
2996
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2997
+                spip_desinfecte($t[$key], $deep);
2998
+            }
2999
+        }
3000
+    }
3002 3001
 }
3003 3002
 
3004 3003
 //  retourne le statut du visiteur s'il s'annonce
3005 3004
 
3006 3005
 // https://code.spip.net/@verifier_visiteur
3007 3006
 function verifier_visiteur() {
3008
-	// Rq: pour que cette fonction marche depuis mes_options
3009
-	// il faut forcer l'init si ce n'est fait
3010
-	// mais on risque de perturber des plugins en initialisant trop tot
3011
-	// certaines constantes
3012
-	@spip_initialisation_core(
3013
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3014
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3015
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3016
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3017
-	);
3018
-
3019
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3020
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3021
-	// Attention on separe bien session_nom et nom, pour eviter
3022
-	// les melanges entre donnees SQL et variables plus aleatoires
3023
-	$variables_session = array('session_nom', 'session_email');
3024
-	foreach ($variables_session as $var) {
3025
-		if (_request($var) !== null) {
3026
-			$init = true;
3027
-			break;
3028
-		}
3029
-	}
3030
-	if (isset($init)) {
3031
-		#@spip_initialisation_suite();
3032
-		$session = charger_fonction('session', 'inc');
3033
-		$session();
3034
-		include_spip('inc/texte');
3035
-		foreach ($variables_session as $var) {
3036
-			if (($a = _request($var)) !== null) {
3037
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3038
-			}
3039
-		}
3040
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3041
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3042
-		}
3043
-		$session($GLOBALS['visiteur_session']);
3044
-
3045
-		return 0;
3046
-	}
3047
-
3048
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3049
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3050
-
3051
-		$session = charger_fonction('session', 'inc');
3052
-		if ($session()) {
3053
-			return $GLOBALS['visiteur_session']['statut'];
3054
-		}
3055
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3056
-			include_spip('inc/auth');
3057
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3058
-		}
3059
-		if ($h) {
3060
-			$GLOBALS['visiteur_session'] = $h;
3061
-
3062
-			return $GLOBALS['visiteur_session']['statut'];
3063
-		}
3064
-	}
3065
-
3066
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3067
-	include_spip('inc/lang');
3068
-	utiliser_langue_visiteur();
3069
-
3070
-	return false;
3007
+    // Rq: pour que cette fonction marche depuis mes_options
3008
+    // il faut forcer l'init si ce n'est fait
3009
+    // mais on risque de perturber des plugins en initialisant trop tot
3010
+    // certaines constantes
3011
+    @spip_initialisation_core(
3012
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3013
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3014
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3015
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3016
+    );
3017
+
3018
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3019
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3020
+    // Attention on separe bien session_nom et nom, pour eviter
3021
+    // les melanges entre donnees SQL et variables plus aleatoires
3022
+    $variables_session = array('session_nom', 'session_email');
3023
+    foreach ($variables_session as $var) {
3024
+        if (_request($var) !== null) {
3025
+            $init = true;
3026
+            break;
3027
+        }
3028
+    }
3029
+    if (isset($init)) {
3030
+        #@spip_initialisation_suite();
3031
+        $session = charger_fonction('session', 'inc');
3032
+        $session();
3033
+        include_spip('inc/texte');
3034
+        foreach ($variables_session as $var) {
3035
+            if (($a = _request($var)) !== null) {
3036
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3037
+            }
3038
+        }
3039
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3040
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3041
+        }
3042
+        $session($GLOBALS['visiteur_session']);
3043
+
3044
+        return 0;
3045
+    }
3046
+
3047
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3048
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3049
+
3050
+        $session = charger_fonction('session', 'inc');
3051
+        if ($session()) {
3052
+            return $GLOBALS['visiteur_session']['statut'];
3053
+        }
3054
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3055
+            include_spip('inc/auth');
3056
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3057
+        }
3058
+        if ($h) {
3059
+            $GLOBALS['visiteur_session'] = $h;
3060
+
3061
+            return $GLOBALS['visiteur_session']['statut'];
3062
+        }
3063
+    }
3064
+
3065
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3066
+    include_spip('inc/lang');
3067
+    utiliser_langue_visiteur();
3068
+
3069
+    return false;
3071 3070
 }
3072 3071
 
3073 3072
 
@@ -3090,21 +3089,21 @@  discard block
 block discarded – undo
3090 3089
  *     - string Langue utilisée.
3091 3090
  **/
3092 3091
 function lang_select($lang = null) {
3093
-	static $pile_langues = array();
3094
-	if (!function_exists('changer_langue')) {
3095
-		include_spip('inc/lang');
3096
-	}
3097
-	if ($lang === null) {
3098
-		$lang = array_pop($pile_langues);
3099
-	} else {
3100
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3101
-	}
3102
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3103
-		return $lang;
3104
-	}
3105
-	changer_langue($lang);
3092
+    static $pile_langues = array();
3093
+    if (!function_exists('changer_langue')) {
3094
+        include_spip('inc/lang');
3095
+    }
3096
+    if ($lang === null) {
3097
+        $lang = array_pop($pile_langues);
3098
+    } else {
3099
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3100
+    }
3101
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3102
+        return $lang;
3103
+    }
3104
+    changer_langue($lang);
3106 3105
 
3107
-	return $lang;
3106
+    return $lang;
3108 3107
 }
3109 3108
 
3110 3109
 /**
@@ -3121,19 +3120,19 @@  discard block
 block discarded – undo
3121 3120
  *     Identifiant de la session
3122 3121
  **/
3123 3122
 function spip_session($force = false) {
3124
-	static $session;
3125
-	if ($force or !isset($session)) {
3126
-		$s = pipeline('definir_session',
3127
-			$GLOBALS['visiteur_session']
3128
-				? serialize($GLOBALS['visiteur_session'])
3129
-				. '_' . @$_COOKIE['spip_session']
3130
-				: ''
3131
-		);
3132
-		$session = $s ? substr(md5($s), 0, 8) : '';
3133
-	}
3123
+    static $session;
3124
+    if ($force or !isset($session)) {
3125
+        $s = pipeline('definir_session',
3126
+            $GLOBALS['visiteur_session']
3127
+                ? serialize($GLOBALS['visiteur_session'])
3128
+                . '_' . @$_COOKIE['spip_session']
3129
+                : ''
3130
+        );
3131
+        $session = $s ? substr(md5($s), 0, 8) : '';
3132
+    }
3134 3133
 
3135
-	#spip_log('session: '.$session);
3136
-	return $session;
3134
+    #spip_log('session: '.$session);
3135
+    return $session;
3137 3136
 }
3138 3137
 
3139 3138
 
@@ -3152,9 +3151,9 @@  discard block
 block discarded – undo
3152 3151
  *    Lien sur une icone d'aide
3153 3152
  **/
3154 3153
 function aider($aide = '', $distante = false) {
3155
-	$aider = charger_fonction('aide', 'inc', true);
3154
+    $aider = charger_fonction('aide', 'inc', true);
3156 3155
 
3157
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3156
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3158 3157
 }
3159 3158
 
3160 3159
 /**
@@ -3164,24 +3163,24 @@  discard block
 block discarded – undo
3164 3163
  */
3165 3164
 function exec_info_dist() {
3166 3165
 
3167
-	include_spip('inc/autoriser');
3168
-	if (autoriser('phpinfos')) {
3169
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3170
-		$cookies_backup = [];
3171
-		foreach ($cookies_masques as $k) {
3172
-			if (!empty($_COOKIE[$k])) {
3173
-				$cookies_backup[$k] = $_COOKIE[$k];
3174
-				$_COOKIE[$k] = '******************************';
3175
-			}
3176
-		}
3177
-		phpinfo();
3178
-		foreach ($cookies_backup as $k => $v) {
3179
-			$_COOKIE[$k] = $v;
3180
-		}
3181
-	} else {
3182
-		include_spip('inc/filtres');
3183
-		sinon_interdire_acces();
3184
-	}
3166
+    include_spip('inc/autoriser');
3167
+    if (autoriser('phpinfos')) {
3168
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3169
+        $cookies_backup = [];
3170
+        foreach ($cookies_masques as $k) {
3171
+            if (!empty($_COOKIE[$k])) {
3172
+                $cookies_backup[$k] = $_COOKIE[$k];
3173
+                $_COOKIE[$k] = '******************************';
3174
+            }
3175
+        }
3176
+        phpinfo();
3177
+        foreach ($cookies_backup as $k => $v) {
3178
+            $_COOKIE[$k] = $v;
3179
+        }
3180
+    } else {
3181
+        include_spip('inc/filtres');
3182
+        sinon_interdire_acces();
3183
+    }
3185 3184
 }
3186 3185
 
3187 3186
 /**
@@ -3201,13 +3200,13 @@  discard block
 block discarded – undo
3201 3200
  *     - string si $message à false.
3202 3201
  **/
3203 3202
 function erreur_squelette($message = '', $lieu = '') {
3204
-	$debusquer = charger_fonction('debusquer', 'public');
3205
-	if (is_array($lieu)) {
3206
-		include_spip('public/compiler');
3207
-		$lieu = reconstruire_contexte_compil($lieu);
3208
-	}
3203
+    $debusquer = charger_fonction('debusquer', 'public');
3204
+    if (is_array($lieu)) {
3205
+        include_spip('public/compiler');
3206
+        $lieu = reconstruire_contexte_compil($lieu);
3207
+    }
3209 3208
 
3210
-	return $debusquer($message, $lieu);
3209
+    return $debusquer($message, $lieu);
3211 3210
 }
3212 3211
 
3213 3212
 /**
@@ -3244,109 +3243,109 @@  discard block
 block discarded – undo
3244 3243
  *     - ou tableau d'information sur le squelette.
3245 3244
  */
3246 3245
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3247
-	if (!function_exists('evaluer_fond')) {
3248
-		include_spip('public/assembler');
3249
-	}
3250
-	// assurer la compat avec l'ancienne syntaxe
3251
-	// (trim etait le 3eme argument, par defaut a true)
3252
-	if (!is_array($options)) {
3253
-		$options = array('trim' => $options);
3254
-	}
3255
-	if (!isset($options['trim'])) {
3256
-		$options['trim'] = true;
3257
-	}
3258
-
3259
-	if (isset($contexte['connect'])) {
3260
-		$connect = $contexte['connect'];
3261
-		unset($contexte['connect']);
3262
-	}
3263
-
3264
-	$texte = "";
3265
-	$pages = array();
3266
-	$lang_select = '';
3267
-	if (!isset($options['etoile']) or !$options['etoile']) {
3268
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3269
-		if (!isset($contexte['lang'])) {
3270
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3271
-		}
3272
-
3273
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3274
-			$lang_select = lang_select($contexte['lang']);
3275
-		}
3276
-	}
3277
-
3278
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3279
-		$GLOBALS['_INC_PUBLIC'] = 0;
3280
-	}
3281
-
3282
-	$GLOBALS['_INC_PUBLIC']++;
3283
-
3284
-	// fix #4235
3285
-	$cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3286
-
3287
-
3288
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3246
+    if (!function_exists('evaluer_fond')) {
3247
+        include_spip('public/assembler');
3248
+    }
3249
+    // assurer la compat avec l'ancienne syntaxe
3250
+    // (trim etait le 3eme argument, par defaut a true)
3251
+    if (!is_array($options)) {
3252
+        $options = array('trim' => $options);
3253
+    }
3254
+    if (!isset($options['trim'])) {
3255
+        $options['trim'] = true;
3256
+    }
3257
+
3258
+    if (isset($contexte['connect'])) {
3259
+        $connect = $contexte['connect'];
3260
+        unset($contexte['connect']);
3261
+    }
3262
+
3263
+    $texte = "";
3264
+    $pages = array();
3265
+    $lang_select = '';
3266
+    if (!isset($options['etoile']) or !$options['etoile']) {
3267
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3268
+        if (!isset($contexte['lang'])) {
3269
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3270
+        }
3271
+
3272
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3273
+            $lang_select = lang_select($contexte['lang']);
3274
+        }
3275
+    }
3276
+
3277
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3278
+        $GLOBALS['_INC_PUBLIC'] = 0;
3279
+    }
3280
+
3281
+    $GLOBALS['_INC_PUBLIC']++;
3282
+
3283
+    // fix #4235
3284
+    $cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3285
+
3286
+
3287
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3289 3288
 		
3290
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3291
-
3292
-		$page = evaluer_fond($f, $contexte, $connect);
3293
-		if ($page === '') {
3294
-			$c = isset($options['compil']) ? $options['compil'] : '';
3295
-			$a = array('fichier' => $f);
3296
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3297
-			erreur_squelette($erreur, $c);
3298
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3299
-			$page = array('texte' => '', 'erreur' => $erreur);
3300
-		}
3301
-
3302
-		$page = pipeline('recuperer_fond', array(
3303
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3304
-			'data' => $page
3305
-		));
3306
-		if (isset($options['ajax']) and $options['ajax']) {
3307
-			if (!function_exists('encoder_contexte_ajax')) {
3308
-				include_spip('inc/filtres');
3309
-			}
3310
-			$page['texte'] = encoder_contexte_ajax(
3311
-				array_merge(
3312
-					$contexte,
3313
-					array('fond' => $f),
3314
-					($connect ? array('connect' => $connect) : array())
3315
-				),
3316
-				'',
3317
-				$page['texte'],
3318
-				$options['ajax']
3319
-			);
3320
-		}
3321
-
3322
-		if (isset($options['raw']) and $options['raw']) {
3323
-			$pages[] = $page;
3324
-		} else {
3325
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3326
-		}
3289
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3290
+
3291
+        $page = evaluer_fond($f, $contexte, $connect);
3292
+        if ($page === '') {
3293
+            $c = isset($options['compil']) ? $options['compil'] : '';
3294
+            $a = array('fichier' => $f);
3295
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3296
+            erreur_squelette($erreur, $c);
3297
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3298
+            $page = array('texte' => '', 'erreur' => $erreur);
3299
+        }
3300
+
3301
+        $page = pipeline('recuperer_fond', array(
3302
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3303
+            'data' => $page
3304
+        ));
3305
+        if (isset($options['ajax']) and $options['ajax']) {
3306
+            if (!function_exists('encoder_contexte_ajax')) {
3307
+                include_spip('inc/filtres');
3308
+            }
3309
+            $page['texte'] = encoder_contexte_ajax(
3310
+                array_merge(
3311
+                    $contexte,
3312
+                    array('fond' => $f),
3313
+                    ($connect ? array('connect' => $connect) : array())
3314
+                ),
3315
+                '',
3316
+                $page['texte'],
3317
+                $options['ajax']
3318
+            );
3319
+        }
3320
+
3321
+        if (isset($options['raw']) and $options['raw']) {
3322
+            $pages[] = $page;
3323
+        } else {
3324
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3325
+        }
3327 3326
 		
3328
-		// contamination de la session appelante, pour les inclusions statiques
3329
-		if (isset($page['invalideurs']['session'])){
3330
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3331
-		}
3332
-	}
3327
+        // contamination de la session appelante, pour les inclusions statiques
3328
+        if (isset($page['invalideurs']['session'])){
3329
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3330
+        }
3331
+    }
3333 3332
 
3334
-	// restaurer le sessionnement du contexte appelant, 
3335
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3336
-	if (isset($cache_utilise_session_appelant)) {
3337
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3338
-	}
3333
+    // restaurer le sessionnement du contexte appelant, 
3334
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3335
+    if (isset($cache_utilise_session_appelant)) {
3336
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3337
+    }
3339 3338
 
3340
-	$GLOBALS['_INC_PUBLIC']--;
3339
+    $GLOBALS['_INC_PUBLIC']--;
3341 3340
 
3342
-	if ($lang_select) {
3343
-		lang_select();
3344
-	}
3345
-	if (isset($options['raw']) and $options['raw']) {
3346
-		return is_array($fond) ? $pages : reset($pages);
3347
-	} else {
3348
-		return $options['trim'] ? ltrim($texte) : $texte;
3349
-	}
3341
+    if ($lang_select) {
3342
+        lang_select();
3343
+    }
3344
+    if (isset($options['raw']) and $options['raw']) {
3345
+        return is_array($fond) ? $pages : reset($pages);
3346
+    } else {
3347
+        return $options['trim'] ? ltrim($texte) : $texte;
3348
+    }
3350 3349
 }
3351 3350
 
3352 3351
 /**
@@ -3356,7 +3355,7 @@  discard block
 block discarded – undo
3356 3355
  * @return string
3357 3356
  */
3358 3357
 function trouve_modele($nom) {
3359
-	return trouver_fond($nom, 'modeles/');
3358
+    return trouver_fond($nom, 'modeles/');
3360 3359
 }
3361 3360
 
3362 3361
 /**
@@ -3372,21 +3371,21 @@  discard block
 block discarded – undo
3372 3371
  * @return array|string
3373 3372
  */
3374 3373
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3375
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3376
-	if (!$pathinfo) {
3377
-		return $f;
3378
-	}
3379
-	// renvoyer un tableau detaille si $pathinfo==true
3380
-	$p = pathinfo($f);
3381
-	if (!isset($p['extension']) or !$p['extension']) {
3382
-		$p['extension'] = _EXTENSION_SQUELETTES;
3383
-	}
3384
-	if (!isset($p['extension']) or !$p['filename']) {
3385
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3386
-	}
3387
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3374
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3375
+    if (!$pathinfo) {
3376
+        return $f;
3377
+    }
3378
+    // renvoyer un tableau detaille si $pathinfo==true
3379
+    $p = pathinfo($f);
3380
+    if (!isset($p['extension']) or !$p['extension']) {
3381
+        $p['extension'] = _EXTENSION_SQUELETTES;
3382
+    }
3383
+    if (!isset($p['extension']) or !$p['filename']) {
3384
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3385
+    }
3386
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3388 3387
 
3389
-	return $p;
3388
+    return $p;
3390 3389
 }
3391 3390
 
3392 3391
 /**
@@ -3407,24 +3406,24 @@  discard block
 block discarded – undo
3407 3406
  *     Nom de l'exec, sinon chaîne vide.
3408 3407
  **/
3409 3408
 function tester_url_ecrire($nom) {
3410
-	static $exec = array();
3411
-	if (isset($exec[$nom])) {
3412
-		return $exec[$nom];
3413
-	}
3414
-	// tester si c'est une page en squelette
3415
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3416
-		return $exec[$nom] = 'fond';
3417
-	} // compat skels orthogonaux version precedente
3418
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3419
-		return $exec[$nom] = 'fond_monobloc';
3420
-	} // echafaudage d'un fond !
3421
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3422
-		return $exec[$nom] = 'fond';
3423
-	}
3424
-	// attention, il ne faut pas inclure l'exec ici
3425
-	// car sinon #URL_ECRIRE provoque des inclusions
3426
-	// et des define intrusifs potentiels
3427
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3409
+    static $exec = array();
3410
+    if (isset($exec[$nom])) {
3411
+        return $exec[$nom];
3412
+    }
3413
+    // tester si c'est une page en squelette
3414
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3415
+        return $exec[$nom] = 'fond';
3416
+    } // compat skels orthogonaux version precedente
3417
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3418
+        return $exec[$nom] = 'fond_monobloc';
3419
+    } // echafaudage d'un fond !
3420
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3421
+        return $exec[$nom] = 'fond';
3422
+    }
3423
+    // attention, il ne faut pas inclure l'exec ici
3424
+    // car sinon #URL_ECRIRE provoque des inclusions
3425
+    // et des define intrusifs potentiels
3426
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3428 3427
 }
3429 3428
 
3430 3429
 
@@ -3440,10 +3439,10 @@  discard block
 block discarded – undo
3440 3439
  * @return bool true si le module est chargé
3441 3440
  **/
3442 3441
 function charger_php_extension($module) {
3443
-	if (extension_loaded($module)) {
3444
-		return true;
3445
-	}
3446
-	return false;
3442
+    if (extension_loaded($module)) {
3443
+        return true;
3444
+    }
3445
+    return false;
3447 3446
 }
3448 3447
 
3449 3448
 
@@ -3454,8 +3453,8 @@  discard block
 block discarded – undo
3454 3453
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3455 3454
  **/
3456 3455
 function html5_permis() {
3457
-	return (!defined('_VERSION_HTML')
3458
-		or _VERSION_HTML !== 'html4');
3456
+    return (!defined('_VERSION_HTML')
3457
+        or _VERSION_HTML !== 'html4');
3459 3458
 }
3460 3459
 
3461 3460
 /**
@@ -3465,30 +3464,30 @@  discard block
 block discarded – undo
3465 3464
  * @return array
3466 3465
  */
3467 3466
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3468
-	$formats = null;
3469
-	if (!is_null($gd)) {
3470
-		$config = ($gd ? "gd_formats" : "formats_graphiques");
3471
-		if (isset($GLOBALS['meta'][$config])) {
3472
-			$formats = $GLOBALS['meta'][$config];
3473
-			$formats = explode(',', $formats);
3474
-			$formats = array_filter($formats);
3475
-			$formats = array_map('trim', $formats);
3476
-		}
3477
-	}
3478
-	if (is_null($formats)) {
3479
-		include_spip('inc/filtres_images_lib_mini');
3480
-		$formats = _image_extensions_acceptees_en_entree();
3481
-	}
3482
-
3483
-	if ($svg_allowed) {
3484
-		if (!in_array('svg', $formats)) {
3485
-			$formats[] = 'svg';
3486
-		}
3487
-	}
3488
-	else {
3489
-		$formats = array_diff($formats, ['svg']);
3490
-	}
3491
-	return $formats;
3467
+    $formats = null;
3468
+    if (!is_null($gd)) {
3469
+        $config = ($gd ? "gd_formats" : "formats_graphiques");
3470
+        if (isset($GLOBALS['meta'][$config])) {
3471
+            $formats = $GLOBALS['meta'][$config];
3472
+            $formats = explode(',', $formats);
3473
+            $formats = array_filter($formats);
3474
+            $formats = array_map('trim', $formats);
3475
+        }
3476
+    }
3477
+    if (is_null($formats)) {
3478
+        include_spip('inc/filtres_images_lib_mini');
3479
+        $formats = _image_extensions_acceptees_en_entree();
3480
+    }
3481
+
3482
+    if ($svg_allowed) {
3483
+        if (!in_array('svg', $formats)) {
3484
+            $formats[] = 'svg';
3485
+        }
3486
+    }
3487
+    else {
3488
+        $formats = array_diff($formats, ['svg']);
3489
+    }
3490
+    return $formats;
3492 3491
 }
3493 3492
 
3494 3493
 /**
@@ -3497,21 +3496,21 @@  discard block
 block discarded – undo
3497 3496
  * @return array|bool
3498 3497
  */
3499 3498
 function spip_getimagesize($fichier) {
3500
-	if (!$imagesize = @getimagesize($fichier)) {
3499
+    if (!$imagesize = @getimagesize($fichier)) {
3501 3500
 
3502
-		include_spip("inc/svg");
3503
-		if ($attrs = svg_lire_attributs($fichier)) {
3504
-			list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3505
-			$imagesize = [
3506
-				$width,
3507
-				$height,
3508
-				IMAGETYPE_SVG,
3509
-				"width=\"{$width}\" height=\"{$height}\"",
3510
-				"mime" => "image/svg+xml"
3511
-			];
3512
-		}
3513
-	}
3514
-	return $imagesize;
3501
+        include_spip("inc/svg");
3502
+        if ($attrs = svg_lire_attributs($fichier)) {
3503
+            list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3504
+            $imagesize = [
3505
+                $width,
3506
+                $height,
3507
+                IMAGETYPE_SVG,
3508
+                "width=\"{$width}\" height=\"{$height}\"",
3509
+                "mime" => "image/svg+xml"
3510
+            ];
3511
+        }
3512
+    }
3513
+    return $imagesize;
3515 3514
 }
3516 3515
 
3517 3516
 
@@ -3531,7 +3530,7 @@  discard block
 block discarded – undo
3531 3530
  * @return mixed Valeur de la meta.
3532 3531
  **/
3533 3532
 function lire_meta($nom) {
3534
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3533
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3535 3534
 }
3536 3535
 
3537 3536
 
@@ -3553,130 +3552,130 @@  discard block
 block discarded – undo
3553 3552
  * @param string $statut
3554 3553
  */
3555 3554
 function avertir_auteurs($nom, $message, $statut = '') {
3556
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3557
-	if (!$alertes
3558
-		or !is_array($alertes = unserialize($alertes))
3559
-	) {
3560
-		$alertes = array();
3561
-	}
3555
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3556
+    if (!$alertes
3557
+        or !is_array($alertes = unserialize($alertes))
3558
+    ) {
3559
+        $alertes = array();
3560
+    }
3562 3561
 
3563
-	if (!isset($alertes[$statut])) {
3564
-		$alertes[$statut] = array();
3565
-	}
3566
-	$alertes[$statut][$nom] = $message;
3567
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3562
+    if (!isset($alertes[$statut])) {
3563
+        $alertes[$statut] = array();
3564
+    }
3565
+    $alertes[$statut][$nom] = $message;
3566
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3568 3567
 }
3569 3568
 
3570 3569
 if (PHP_VERSION_ID < 50500) {
3571
-	if (!function_exists('array_column')) {
3572
-		/**
3573
-		 * Returns the values from a single column of the input array, identified by
3574
-		 * the $columnKey.
3575
-		 *
3576
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3577
-		 * array by the values from the $indexKey column in the input array.
3578
-		 *
3579
-		 * @link http://php.net/manual/fr/function.array-column.php
3580
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3581
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3582
-		 * @license http://opensource.org/licenses/MIT MIT
3583
-		 *
3584
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3585
-		 *                     a column of values.
3586
-		 * @param mixed $columnKey The column of values to return. This value may be the
3587
-		 *                         integer key of the column you wish to retrieve, or it
3588
-		 *                         may be the string key name for an associative array.
3589
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3590
-		 *                        the returned array. This value may be the integer key
3591
-		 *                        of the column, or it may be the string key name.
3592
-		 * @return array
3593
-		 */
3594
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3595
-		{
3596
-			// Using func_get_args() in order to check for proper number of
3597
-			// parameters and trigger errors exactly as the built-in array_column()
3598
-			// does in PHP 5.5.
3599
-			$argc = func_num_args();
3600
-			$params = func_get_args();
3601
-
3602
-			if ($argc < 2) {
3603
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3604
-				return null;
3605
-			}
3606
-
3607
-			if (!is_array($params[0])) {
3608
-				trigger_error(
3609
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3610
-					E_USER_WARNING
3611
-				);
3612
-				return null;
3613
-			}
3614
-
3615
-			if (!is_int($params[1])
3616
-				&& !is_float($params[1])
3617
-				&& !is_string($params[1])
3618
-				&& $params[1] !== null
3619
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3620
-			) {
3621
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3622
-				return false;
3623
-			}
3624
-
3625
-			if (isset($params[2])
3626
-				&& !is_int($params[2])
3627
-				&& !is_float($params[2])
3628
-				&& !is_string($params[2])
3629
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3630
-			) {
3631
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3632
-				return false;
3633
-			}
3634
-
3635
-			$paramsInput = $params[0];
3636
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3637
-
3638
-			$paramsIndexKey = null;
3639
-			if (isset($params[2])) {
3640
-				if (is_float($params[2]) || is_int($params[2])) {
3641
-					$paramsIndexKey = (int) $params[2];
3642
-				} else {
3643
-					$paramsIndexKey = (string) $params[2];
3644
-				}
3645
-			}
3646
-
3647
-			$resultArray = array();
3648
-
3649
-			foreach ($paramsInput as $row) {
3650
-				$key = $value = null;
3651
-				$keySet = $valueSet = false;
3652
-
3653
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3654
-					$keySet = true;
3655
-					$key = (string) $row[$paramsIndexKey];
3656
-				}
3657
-
3658
-				if ($paramsColumnKey === null) {
3659
-					$valueSet = true;
3660
-					$value = $row;
3661
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3662
-					$valueSet = true;
3663
-					$value = $row[$paramsColumnKey];
3664
-				}
3665
-
3666
-				if ($valueSet) {
3667
-					if ($keySet) {
3668
-						$resultArray[$key] = $value;
3669
-					} else {
3670
-						$resultArray[] = $value;
3671
-					}
3672
-				}
3673
-
3674
-			}
3675
-
3676
-			return $resultArray;
3677
-		}
3678
-
3679
-	}
3570
+    if (!function_exists('array_column')) {
3571
+        /**
3572
+         * Returns the values from a single column of the input array, identified by
3573
+         * the $columnKey.
3574
+         *
3575
+         * Optionally, you may provide an $indexKey to index the values in the returned
3576
+         * array by the values from the $indexKey column in the input array.
3577
+         *
3578
+         * @link http://php.net/manual/fr/function.array-column.php
3579
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3580
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3581
+         * @license http://opensource.org/licenses/MIT MIT
3582
+         *
3583
+         * @param array $input A multi-dimensional array (record set) from which to pull
3584
+         *                     a column of values.
3585
+         * @param mixed $columnKey The column of values to return. This value may be the
3586
+         *                         integer key of the column you wish to retrieve, or it
3587
+         *                         may be the string key name for an associative array.
3588
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3589
+         *                        the returned array. This value may be the integer key
3590
+         *                        of the column, or it may be the string key name.
3591
+         * @return array
3592
+         */
3593
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3594
+        {
3595
+            // Using func_get_args() in order to check for proper number of
3596
+            // parameters and trigger errors exactly as the built-in array_column()
3597
+            // does in PHP 5.5.
3598
+            $argc = func_num_args();
3599
+            $params = func_get_args();
3600
+
3601
+            if ($argc < 2) {
3602
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3603
+                return null;
3604
+            }
3605
+
3606
+            if (!is_array($params[0])) {
3607
+                trigger_error(
3608
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3609
+                    E_USER_WARNING
3610
+                );
3611
+                return null;
3612
+            }
3613
+
3614
+            if (!is_int($params[1])
3615
+                && !is_float($params[1])
3616
+                && !is_string($params[1])
3617
+                && $params[1] !== null
3618
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3619
+            ) {
3620
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3621
+                return false;
3622
+            }
3623
+
3624
+            if (isset($params[2])
3625
+                && !is_int($params[2])
3626
+                && !is_float($params[2])
3627
+                && !is_string($params[2])
3628
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3629
+            ) {
3630
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3631
+                return false;
3632
+            }
3633
+
3634
+            $paramsInput = $params[0];
3635
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3636
+
3637
+            $paramsIndexKey = null;
3638
+            if (isset($params[2])) {
3639
+                if (is_float($params[2]) || is_int($params[2])) {
3640
+                    $paramsIndexKey = (int) $params[2];
3641
+                } else {
3642
+                    $paramsIndexKey = (string) $params[2];
3643
+                }
3644
+            }
3645
+
3646
+            $resultArray = array();
3647
+
3648
+            foreach ($paramsInput as $row) {
3649
+                $key = $value = null;
3650
+                $keySet = $valueSet = false;
3651
+
3652
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3653
+                    $keySet = true;
3654
+                    $key = (string) $row[$paramsIndexKey];
3655
+                }
3656
+
3657
+                if ($paramsColumnKey === null) {
3658
+                    $valueSet = true;
3659
+                    $value = $row;
3660
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3661
+                    $valueSet = true;
3662
+                    $value = $row[$paramsColumnKey];
3663
+                }
3664
+
3665
+                if ($valueSet) {
3666
+                    if ($keySet) {
3667
+                        $resultArray[$key] = $value;
3668
+                    } else {
3669
+                        $resultArray[] = $value;
3670
+                    }
3671
+                }
3672
+
3673
+            }
3674
+
3675
+            return $resultArray;
3676
+        }
3677
+
3678
+    }
3680 3679
 }
3681 3680
 
3682 3681
 /**
@@ -3690,8 +3689,8 @@  discard block
 block discarded – undo
3690 3689
  * @return string|string[]
3691 3690
  */
3692 3691
 function spip_sanitize_classname($classes) {
3693
-	if (is_array($classes)) {
3694
-		return array_map('spip_sanitize_classname', $classes);
3695
-	}
3696
-	return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes);
3692
+    if (is_array($classes)) {
3693
+        return array_map('spip_sanitize_classname', $classes);
3694
+    }
3695
+    return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes);
3697 3696
 }
Please login to merge, or discard this patch.