Completed
Push — master ( 867977...48c029 )
by cam
04:23
created
ecrire/inc/utils.php 1 patch
Indentation   +2183 added lines, -2184 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
 /**
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
  *     Les paramètres du pipeline modifiés
195 195
  **/
196 196
 function minipipe($fonc, &$val) {
197
-	// fonction
198
-	if (function_exists($fonc)) {
199
-		$val = call_user_func($fonc, $val);
200
-	} // Class::Methode
201
-	else {
202
-		if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
-			and $methode = array($regs[1], $regs[2])
204
-			and is_callable($methode)
205
-		) {
206
-			$val = call_user_func($methode, $val);
207
-		} else {
208
-			spip_log("Erreur - '$fonc' non definie !");
209
-		}
210
-	}
197
+    // fonction
198
+    if (function_exists($fonc)) {
199
+        $val = call_user_func($fonc, $val);
200
+    } // Class::Methode
201
+    else {
202
+        if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
+            and $methode = array($regs[1], $regs[2])
204
+            and is_callable($methode)
205
+        ) {
206
+            $val = call_user_func($methode, $val);
207
+        } else {
208
+            spip_log("Erreur - '$fonc' non definie !");
209
+        }
210
+    }
211 211
 
212
-	return $val;
212
+    return $val;
213 213
 }
214 214
 
215 215
 /**
@@ -240,45 +240,45 @@  discard block
 block discarded – undo
240 240
  *     Résultat
241 241
  */
242 242
 function pipeline($action, $val = null) {
243
-	static $charger;
244
-
245
-	// chargement initial des fonctions mises en cache, ou generation du cache
246
-	if (!$charger) {
247
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
-			include_spip('inc/plugin');
249
-			// generer les fichiers php precompiles
250
-			// de chargement des plugins et des pipelines
251
-			actualise_plugins_actifs();
252
-			if (!($ok = @is_readable($charger))) {
253
-				spip_log("fichier $charger pas cree");
254
-			}
255
-		}
256
-
257
-		if ($ok) {
258
-			include_once $charger;
259
-		}
260
-	}
261
-
262
-	// appliquer notre fonction si elle existe
263
-	$fonc = 'execute_pipeline_' . strtolower($action);
264
-	if (function_exists($fonc)) {
265
-		$val = $fonc($val);
266
-	} // plantage ?
267
-	else {
268
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
-	}
270
-
271
-	// si le flux est une table avec 2 cle args&data
272
-	// on ne ressort du pipe que les donnees dans 'data'
273
-	// array_key_exists pour php 4.1.0
274
-	if (is_array($val)
275
-		and count($val) == 2
276
-		and (array_key_exists('data', $val))
277
-	) {
278
-		$val = $val['data'];
279
-	}
280
-
281
-	return $val;
243
+    static $charger;
244
+
245
+    // chargement initial des fonctions mises en cache, ou generation du cache
246
+    if (!$charger) {
247
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
+            include_spip('inc/plugin');
249
+            // generer les fichiers php precompiles
250
+            // de chargement des plugins et des pipelines
251
+            actualise_plugins_actifs();
252
+            if (!($ok = @is_readable($charger))) {
253
+                spip_log("fichier $charger pas cree");
254
+            }
255
+        }
256
+
257
+        if ($ok) {
258
+            include_once $charger;
259
+        }
260
+    }
261
+
262
+    // appliquer notre fonction si elle existe
263
+    $fonc = 'execute_pipeline_' . strtolower($action);
264
+    if (function_exists($fonc)) {
265
+        $val = $fonc($val);
266
+    } // plantage ?
267
+    else {
268
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
+    }
270
+
271
+    // si le flux est une table avec 2 cle args&data
272
+    // on ne ressort du pipe que les donnees dans 'data'
273
+    // array_key_exists pour php 4.1.0
274
+    if (is_array($val)
275
+        and count($val) == 2
276
+        and (array_key_exists('data', $val))
277
+    ) {
278
+        $val = $val['data'];
279
+    }
280
+
281
+    return $val;
282 282
 }
283 283
 
284 284
 /**
@@ -322,35 +322,35 @@  discard block
 block discarded – undo
322 322
  *     paramètre est planté pour cause de compatibilité ascendante.
323 323
  */
324 324
 function spip_log($message = null, $name = null) {
325
-	static $pre = array();
326
-	static $log;
327
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
329
-		$logname = null;
330
-	}
331
-	if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
-		$niveau = _LOG_INFO;
333
-	}
334
-
335
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
-		if (!$pre) {
337
-			$pre = array(
338
-				_LOG_HS => 'HS:',
339
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
340
-				_LOG_CRITIQUE => 'CRITIQUE:',
341
-				_LOG_ERREUR => 'ERREUR:',
342
-				_LOG_AVERTISSEMENT => 'WARNING:',
343
-				_LOG_INFO_IMPORTANTE => '!INFO:',
344
-				_LOG_INFO => 'info:',
345
-				_LOG_DEBUG => 'debug:'
346
-			);
347
-			$log = charger_fonction('log', 'inc');
348
-		}
349
-		if (!is_string($message)) {
350
-			$message = print_r($message, true);
351
-		}
352
-		$log($pre[$niveau] . ' ' . $message, $logname);
353
-	}
325
+    static $pre = array();
326
+    static $log;
327
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
329
+        $logname = null;
330
+    }
331
+    if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
+        $niveau = _LOG_INFO;
333
+    }
334
+
335
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
+        if (!$pre) {
337
+            $pre = array(
338
+                _LOG_HS => 'HS:',
339
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
340
+                _LOG_CRITIQUE => 'CRITIQUE:',
341
+                _LOG_ERREUR => 'ERREUR:',
342
+                _LOG_AVERTISSEMENT => 'WARNING:',
343
+                _LOG_INFO_IMPORTANTE => '!INFO:',
344
+                _LOG_INFO => 'info:',
345
+                _LOG_DEBUG => 'debug:'
346
+            );
347
+            $log = charger_fonction('log', 'inc');
348
+        }
349
+        if (!is_string($message)) {
350
+            $message = print_r($message, true);
351
+        }
352
+        $log($pre[$niveau] . ' ' . $message, $logname);
353
+    }
354 354
 }
355 355
 
356 356
 /**
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
  * @param array $opt Tableau d'options
362 362
  **/
363 363
 function journal($phrase, $opt = array()) {
364
-	$journal = charger_fonction('journal', 'inc');
365
-	$journal($phrase, $opt);
364
+    $journal = charger_fonction('journal', 'inc');
365
+    $journal($phrase, $opt);
366 366
 }
367 367
 
368 368
 
@@ -381,36 +381,36 @@  discard block
 block discarded – undo
381 381
  **/
382 382
 function _request($var, $c = false) {
383 383
 
384
-	if (is_array($c)) {
385
-		return isset($c[$var]) ? $c[$var] : null;
386
-	}
384
+    if (is_array($c)) {
385
+        return isset($c[$var]) ? $c[$var] : null;
386
+    }
387 387
 
388
-	if (isset($_GET[$var])) {
389
-		$a = $_GET[$var];
390
-	} elseif (isset($_POST[$var])) {
391
-		$a = $_POST[$var];
392
-	} else {
393
-		return null;
394
-	}
388
+    if (isset($_GET[$var])) {
389
+        $a = $_GET[$var];
390
+    } elseif (isset($_POST[$var])) {
391
+        $a = $_POST[$var];
392
+    } else {
393
+        return null;
394
+    }
395 395
 
396
-	// Si on est en ajax et en POST tout a ete encode
397
-	// via encodeURIComponent, il faut donc repasser
398
-	// dans le charset local...
399
-	if (defined('_AJAX')
400
-		and _AJAX
401
-		and isset($GLOBALS['meta']['charset'])
402
-		and $GLOBALS['meta']['charset'] != 'utf-8'
403
-		and is_string($a)
404
-		// check rapide mais pas fiable
405
-		and preg_match(',[\x80-\xFF],', $a)
406
-		// check fiable
407
-		and include_spip('inc/charsets')
408
-		and is_utf8($a)
409
-	) {
410
-		return importer_charset($a, 'utf-8');
411
-	}
396
+    // Si on est en ajax et en POST tout a ete encode
397
+    // via encodeURIComponent, il faut donc repasser
398
+    // dans le charset local...
399
+    if (defined('_AJAX')
400
+        and _AJAX
401
+        and isset($GLOBALS['meta']['charset'])
402
+        and $GLOBALS['meta']['charset'] != 'utf-8'
403
+        and is_string($a)
404
+        // check rapide mais pas fiable
405
+        and preg_match(',[\x80-\xFF],', $a)
406
+        // check fiable
407
+        and include_spip('inc/charsets')
408
+        and is_utf8($a)
409
+    ) {
410
+        return importer_charset($a, 'utf-8');
411
+    }
412 412
 
413
-	return $a;
413
+    return $a;
414 414
 }
415 415
 
416 416
 
@@ -428,22 +428,22 @@  discard block
 block discarded – undo
428 428
  *     - false sinon
429 429
  **/
430 430
 function set_request($var, $val = null, $c = false) {
431
-	if (is_array($c)) {
432
-		unset($c[$var]);
433
-		if ($val !== null) {
434
-			$c[$var] = $val;
435
-		}
431
+    if (is_array($c)) {
432
+        unset($c[$var]);
433
+        if ($val !== null) {
434
+            $c[$var] = $val;
435
+        }
436 436
 
437
-		return $c;
438
-	}
437
+        return $c;
438
+    }
439 439
 
440
-	unset($_GET[$var]);
441
-	unset($_POST[$var]);
442
-	if ($val !== null) {
443
-		$_GET[$var] = $val;
444
-	}
440
+    unset($_GET[$var]);
441
+    unset($_POST[$var]);
442
+    if ($val !== null) {
443
+        $_GET[$var] = $val;
444
+    }
445 445
 
446
-	return false; # n'affecte pas $c
446
+    return false; # n'affecte pas $c
447 447
 }
448 448
 
449 449
 
@@ -452,23 +452,22 @@  discard block
 block discarded – undo
452 452
  * 
453 453
  * On est sur le web, on exclut certains protocoles, 
454 454
  * notamment 'file://', 'php://' et d'autres…
455
-
456 455
  * @param string $url
457 456
  * @return bool
458 457
  */
459 458
 function tester_url_absolue($url) {
460
-	$url = trim($url);
461
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
462
-		if (
463
-			isset($m[1])
464
-			and $p = strtolower(rtrim($m[1], ':'))
465
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
466
-		  ) {
467
-			return false;
468
-		}
469
-		return true;
470
-	}
471
-	return false;
459
+    $url = trim($url);
460
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
461
+        if (
462
+            isset($m[1])
463
+            and $p = strtolower(rtrim($m[1], ':'))
464
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
465
+            ) {
466
+            return false;
467
+        }
468
+        return true;
469
+    }
470
+    return false;
472 471
 }
473 472
 
474 473
 /**
@@ -490,94 +489,94 @@  discard block
 block discarded – undo
490 489
  * @return string URL
491 490
  */
492 491
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
493
-	// requete erronnee : plusieurs variable dans $c et aucun $v
494
-	if (strpos($c, "|") !== false and is_null($v)) {
495
-		return null;
496
-	}
497
-
498
-	// lever l'#ancre
499
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
500
-		$url = $r[1];
501
-		$ancre = $r[2];
502
-	} else {
503
-		$ancre = '';
504
-	}
505
-
506
-	// eclater
507
-	$url = preg_split(',[?]|&amp;|&,', $url);
508
-
509
-	// recuperer la base
510
-	$a = array_shift($url);
511
-	if (!$a) {
512
-		$a = './';
513
-	}
514
-
515
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
516
-	$ajouts = array_flip(explode('|', $c));
517
-	$u = is_array($v) ? $v : rawurlencode($v);
518
-	$testv = (is_array($v) ? count($v) : strlen($v));
519
-	$v_read = null;
520
-	// lire les variables et agir
521
-	foreach ($url as $n => $val) {
522
-		if (preg_match($regexp, urldecode($val), $r)) {
523
-			$r = array_pad($r, 3, null);
524
-			if ($v === null) {
525
-				// c'est un tableau, on memorise les valeurs
526
-				if (substr($r[1], -2) == "[]") {
527
-					if (!$v_read) {
528
-						$v_read = array();
529
-					}
530
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
531
-				} // c'est un scalaire, on retourne direct
532
-				else {
533
-					return $r[2] ? substr($r[2], 1) : '';
534
-				}
535
-			} // suppression
536
-			elseif (!$testv) {
537
-				unset($url[$n]);
538
-			}
539
-			// Ajout. Pour une variable, remplacer au meme endroit,
540
-			// pour un tableau ce sera fait dans la prochaine boucle
541
-			elseif (substr($r[1], -2) != '[]') {
542
-				$url[$n] = $r[1] . '=' . $u;
543
-				unset($ajouts[$r[1]]);
544
-			}
545
-			// Pour les tableaux on laisse tomber les valeurs de
546
-			// départ, on remplira à l'étape suivante
547
-			else {
548
-				unset($url[$n]);
549
-			}
550
-		}
551
-	}
552
-
553
-	// traiter les parametres pas encore trouves
554
-	if ($v === null
555
-		and $args = func_get_args()
556
-		and count($args) == 2
557
-	) {
558
-		return $v_read; // rien trouve ou un tableau
559
-	} elseif ($testv) {
560
-		foreach ($ajouts as $k => $n) {
561
-			if (!is_array($v)) {
562
-				$url[] = $k . '=' . $u;
563
-			} else {
564
-				$id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
565
-				foreach ($v as $w) {
566
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
567
-				}
568
-			}
569
-		}
570
-	}
571
-
572
-	// eliminer les vides
573
-	$url = array_filter($url);
574
-
575
-	// recomposer l'adresse
576
-	if ($url) {
577
-		$a .= '?' . join($sep, $url);
578
-	}
579
-
580
-	return $a . $ancre;
492
+    // requete erronnee : plusieurs variable dans $c et aucun $v
493
+    if (strpos($c, "|") !== false and is_null($v)) {
494
+        return null;
495
+    }
496
+
497
+    // lever l'#ancre
498
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
499
+        $url = $r[1];
500
+        $ancre = $r[2];
501
+    } else {
502
+        $ancre = '';
503
+    }
504
+
505
+    // eclater
506
+    $url = preg_split(',[?]|&amp;|&,', $url);
507
+
508
+    // recuperer la base
509
+    $a = array_shift($url);
510
+    if (!$a) {
511
+        $a = './';
512
+    }
513
+
514
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
515
+    $ajouts = array_flip(explode('|', $c));
516
+    $u = is_array($v) ? $v : rawurlencode($v);
517
+    $testv = (is_array($v) ? count($v) : strlen($v));
518
+    $v_read = null;
519
+    // lire les variables et agir
520
+    foreach ($url as $n => $val) {
521
+        if (preg_match($regexp, urldecode($val), $r)) {
522
+            $r = array_pad($r, 3, null);
523
+            if ($v === null) {
524
+                // c'est un tableau, on memorise les valeurs
525
+                if (substr($r[1], -2) == "[]") {
526
+                    if (!$v_read) {
527
+                        $v_read = array();
528
+                    }
529
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
530
+                } // c'est un scalaire, on retourne direct
531
+                else {
532
+                    return $r[2] ? substr($r[2], 1) : '';
533
+                }
534
+            } // suppression
535
+            elseif (!$testv) {
536
+                unset($url[$n]);
537
+            }
538
+            // Ajout. Pour une variable, remplacer au meme endroit,
539
+            // pour un tableau ce sera fait dans la prochaine boucle
540
+            elseif (substr($r[1], -2) != '[]') {
541
+                $url[$n] = $r[1] . '=' . $u;
542
+                unset($ajouts[$r[1]]);
543
+            }
544
+            // Pour les tableaux on laisse tomber les valeurs de
545
+            // départ, on remplira à l'étape suivante
546
+            else {
547
+                unset($url[$n]);
548
+            }
549
+        }
550
+    }
551
+
552
+    // traiter les parametres pas encore trouves
553
+    if ($v === null
554
+        and $args = func_get_args()
555
+        and count($args) == 2
556
+    ) {
557
+        return $v_read; // rien trouve ou un tableau
558
+    } elseif ($testv) {
559
+        foreach ($ajouts as $k => $n) {
560
+            if (!is_array($v)) {
561
+                $url[] = $k . '=' . $u;
562
+            } else {
563
+                $id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
564
+                foreach ($v as $w) {
565
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
566
+                }
567
+            }
568
+        }
569
+    }
570
+
571
+    // eliminer les vides
572
+    $url = array_filter($url);
573
+
574
+    // recomposer l'adresse
575
+    if ($url) {
576
+        $a .= '?' . join($sep, $url);
577
+    }
578
+
579
+    return $a . $ancre;
581 580
 }
582 581
 
583 582
 /**
@@ -595,21 +594,21 @@  discard block
 block discarded – undo
595 594
  * @return string
596 595
  */
597 596
 function ancre_url($url, $ancre) {
598
-	// lever l'#ancre
599
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
600
-		$url = $r[1];
601
-	}
602
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
603
-		if (!function_exists('translitteration')) {
604
-			include_spip('inc/charsets');
605
-		}
606
-		$ancre = preg_replace(
607
-			array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
608
-			array('', '-'),
609
-			translitteration($ancre)
610
-		);
611
-	}
612
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
597
+    // lever l'#ancre
598
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
599
+        $url = $r[1];
600
+    }
601
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
602
+        if (!function_exists('translitteration')) {
603
+            include_spip('inc/charsets');
604
+        }
605
+        $ancre = preg_replace(
606
+            array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
607
+            array('', '-'),
608
+            translitteration($ancre)
609
+        );
610
+    }
611
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
613 612
 }
614 613
 
615 614
 /**
@@ -619,16 +618,16 @@  discard block
 block discarded – undo
619 618
  * @return string
620 619
  */
621 620
 function nettoyer_uri($reset = null) {
622
-	static $done = false;
623
-	static $propre = '';
624
-	if (!is_null($reset)) {
625
-		return $propre = $reset;
626
-	}
627
-	if ($done) {
628
-		return $propre;
629
-	}
630
-	$done = true;
631
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
621
+    static $done = false;
622
+    static $propre = '';
623
+    if (!is_null($reset)) {
624
+        return $propre = $reset;
625
+    }
626
+    if ($done) {
627
+        return $propre;
628
+    }
629
+    $done = true;
630
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
632 631
 }
633 632
 
634 633
 /**
@@ -640,13 +639,13 @@  discard block
 block discarded – undo
640 639
  * @return string
641 640
  */
642 641
 function nettoyer_uri_var($request_uri) {
643
-	$uri1 = $request_uri;
644
-	do {
645
-		$uri = $uri1;
646
-		$uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
647
-			'\1', $uri);
648
-	} while ($uri <> $uri1);
649
-	return preg_replace(',[?&]$,', '', $uri1);
642
+    $uri1 = $request_uri;
643
+    do {
644
+        $uri = $uri1;
645
+        $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
646
+            '\1', $uri);
647
+    } while ($uri <> $uri1);
648
+    return preg_replace(',[?&]$,', '', $uri1);
650 649
 }
651 650
 
652 651
 
@@ -660,47 +659,47 @@  discard block
 block discarded – undo
660 659
  *    URL vers soi-même
661 660
  **/
662 661
 function self($amp = '&amp;', $root = false) {
663
-	$url = nettoyer_uri();
664
-	if (!$root
665
-		and (
666
-			// si pas de profondeur on peut tronquer
667
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
668
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
669
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
670
-	) {
671
-		$url = preg_replace(',^[^?]*/,', '', $url);
672
-	}
673
-	// ajouter le cas echeant les variables _POST['id_...']
674
-	foreach ($_POST as $v => $c) {
675
-		if (substr($v, 0, 3) == 'id_') {
676
-			$url = parametre_url($url, $v, $c, '&');
677
-		}
678
-	}
679
-
680
-	// supprimer les variables sans interet
681
-	if (test_espace_prive()) {
682
-		$url = preg_replace(',([?&])('
683
-			. 'lang|show_docs|'
684
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
685
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
686
-		$url = preg_replace(',[&]$,', '\1', $url);
687
-	}
688
-
689
-	// eviter les hacks
690
-	include_spip('inc/filtres_mini');
691
-	$url = spip_htmlspecialchars($url);
662
+    $url = nettoyer_uri();
663
+    if (!$root
664
+        and (
665
+            // si pas de profondeur on peut tronquer
666
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
667
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
668
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
669
+    ) {
670
+        $url = preg_replace(',^[^?]*/,', '', $url);
671
+    }
672
+    // ajouter le cas echeant les variables _POST['id_...']
673
+    foreach ($_POST as $v => $c) {
674
+        if (substr($v, 0, 3) == 'id_') {
675
+            $url = parametre_url($url, $v, $c, '&');
676
+        }
677
+    }
678
+
679
+    // supprimer les variables sans interet
680
+    if (test_espace_prive()) {
681
+        $url = preg_replace(',([?&])('
682
+            . 'lang|show_docs|'
683
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
684
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
685
+        $url = preg_replace(',[&]$,', '\1', $url);
686
+    }
687
+
688
+    // eviter les hacks
689
+    include_spip('inc/filtres_mini');
690
+    $url = spip_htmlspecialchars($url);
692 691
 	
693
-	$url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
692
+    $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
694 693
 
695
-	// &amp; ?
696
-	if ($amp != '&amp;') {
697
-		$url = str_replace('&amp;', $amp, $url);
698
-	}
694
+    // &amp; ?
695
+    if ($amp != '&amp;') {
696
+        $url = str_replace('&amp;', $amp, $url);
697
+    }
699 698
 
700
-	// Si ca demarre par ? ou vide, donner './'
701
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
699
+    // Si ca demarre par ? ou vide, donner './'
700
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
702 701
 
703
-	return $url;
702
+    return $url;
704 703
 }
705 704
 
706 705
 
@@ -711,7 +710,7 @@  discard block
 block discarded – undo
711 710
  *     true si c'est le cas, false sinon.
712 711
  */
713 712
 function test_espace_prive() {
714
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
713
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
715 714
 }
716 715
 
717 716
 /**
@@ -721,7 +720,7 @@  discard block
 block discarded – undo
721 720
  * @return bool
722 721
  */
723 722
 function test_plugin_actif($plugin) {
724
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
723
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
725 724
 }
726 725
 
727 726
 /**
@@ -752,51 +751,51 @@  discard block
 block discarded – undo
752 751
  *     Texte
753 752
  */
754 753
 function _T($texte, $args = array(), $options = array()) {
755
-	static $traduire = false;
756
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
757
-	if ($options) {
758
-		// support de l'ancien argument $class
759
-		if (is_string($options)) {
760
-			$options = array('class' => $options);
761
-		}
762
-		$o = array_merge($o, $options);
763
-	}
754
+    static $traduire = false;
755
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
756
+    if ($options) {
757
+        // support de l'ancien argument $class
758
+        if (is_string($options)) {
759
+            $options = array('class' => $options);
760
+        }
761
+        $o = array_merge($o, $options);
762
+    }
764 763
 
765
-	if (!$traduire) {
766
-		$traduire = charger_fonction('traduire', 'inc');
767
-		include_spip('inc/lang');
768
-	}
764
+    if (!$traduire) {
765
+        $traduire = charger_fonction('traduire', 'inc');
766
+        include_spip('inc/lang');
767
+    }
769 768
 
770
-	// On peut passer explicitement la langue dans le tableau
771
-	// On utilise le même nom de variable que la globale
772
-	if (isset($args['spip_lang'])) {
773
-		$lang = $args['spip_lang'];
774
-		// On l'enleve pour ne pas le passer au remplacement
775
-		unset($args['spip_lang']);
776
-	} // Sinon on prend la langue du contexte
777
-	else {
778
-		$lang = $GLOBALS['spip_lang'];
779
-	}
780
-	$text = $traduire($texte, $lang);
769
+    // On peut passer explicitement la langue dans le tableau
770
+    // On utilise le même nom de variable que la globale
771
+    if (isset($args['spip_lang'])) {
772
+        $lang = $args['spip_lang'];
773
+        // On l'enleve pour ne pas le passer au remplacement
774
+        unset($args['spip_lang']);
775
+    } // Sinon on prend la langue du contexte
776
+    else {
777
+        $lang = $GLOBALS['spip_lang'];
778
+    }
779
+    $text = $traduire($texte, $lang);
781 780
 
782
-	if (!strlen($text)) {
783
-		if (!$o['force']) {
784
-			return '';
785
-		}
781
+    if (!strlen($text)) {
782
+        if (!$o['force']) {
783
+            return '';
784
+        }
786 785
 
787
-		$text = $texte;
786
+        $text = $texte;
788 787
 
789
-		// pour les chaines non traduites, assurer un service minimum
790
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
791
-			$text = str_replace('_', ' ',
792
-				(($n = strpos($text, ':')) === false ? $texte :
793
-					substr($texte, $n + 1)));
794
-		}
795
-		$o['class'] = null;
788
+        // pour les chaines non traduites, assurer un service minimum
789
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
790
+            $text = str_replace('_', ' ',
791
+                (($n = strpos($text, ':')) === false ? $texte :
792
+                    substr($texte, $n + 1)));
793
+        }
794
+        $o['class'] = null;
796 795
 
797
-	}
796
+    }
798 797
 
799
-	return _L($text, $args, $o);
798
+    return _L($text, $args, $o);
800 799
 
801 800
 }
802 801
 
@@ -824,53 +823,53 @@  discard block
 block discarded – undo
824 823
  *     Texte
825 824
  */
826 825
 function _L($text, $args = array(), $options = array()) {
827
-	$f = $text;
828
-	$defaut_options = array(
829
-		'class' => null,
830
-		'sanitize' => true,
831
-	);
832
-	// support de l'ancien argument $class
833
-	if ($options and is_string($options)) {
834
-		$options = array('class' => $options);
835
-	}
836
-	if (is_array($options)) {
837
-		$options += $defaut_options;
838
-	} else {
839
-		$options = $defaut_options;
840
-	}
841
-
842
-	if (is_array($args) and count($args)) {
843
-		if (!function_exists('interdire_scripts')) {
844
-			include_spip('inc/texte');
845
-		}
846
-		if (!function_exists('echapper_html_suspect')) {
847
-			include_spip('inc/texte_mini');
848
-		}
849
-		foreach ($args as $name => $value) {
850
-			if (strpos($text, "@$name@") !== false) {
851
-				if ($options['sanitize']) {
852
-					$value = echapper_html_suspect($value);
853
-					$value = interdire_scripts($value, -1);
854
-				}
855
-				if (!empty($options['class'])) {
856
-					$value = "<span class='".$options['class']."'>$value</span>";
857
-				}
858
-				$text = str_replace("@$name@", $value, $text);
859
-				unset($args[$name]);
860
-			}
861
-		}
862
-		// Si des variables n'ont pas ete inserees, le signaler
863
-		// (chaines de langues pas a jour)
864
-		if ($args) {
865
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
866
-		}
867
-	}
868
-
869
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
870
-		return "<span class=debug-traduction-erreur>$text</span>";
871
-	} else {
872
-		return $text;
873
-	}
826
+    $f = $text;
827
+    $defaut_options = array(
828
+        'class' => null,
829
+        'sanitize' => true,
830
+    );
831
+    // support de l'ancien argument $class
832
+    if ($options and is_string($options)) {
833
+        $options = array('class' => $options);
834
+    }
835
+    if (is_array($options)) {
836
+        $options += $defaut_options;
837
+    } else {
838
+        $options = $defaut_options;
839
+    }
840
+
841
+    if (is_array($args) and count($args)) {
842
+        if (!function_exists('interdire_scripts')) {
843
+            include_spip('inc/texte');
844
+        }
845
+        if (!function_exists('echapper_html_suspect')) {
846
+            include_spip('inc/texte_mini');
847
+        }
848
+        foreach ($args as $name => $value) {
849
+            if (strpos($text, "@$name@") !== false) {
850
+                if ($options['sanitize']) {
851
+                    $value = echapper_html_suspect($value);
852
+                    $value = interdire_scripts($value, -1);
853
+                }
854
+                if (!empty($options['class'])) {
855
+                    $value = "<span class='".$options['class']."'>$value</span>";
856
+                }
857
+                $text = str_replace("@$name@", $value, $text);
858
+                unset($args[$name]);
859
+            }
860
+        }
861
+        // Si des variables n'ont pas ete inserees, le signaler
862
+        // (chaines de langues pas a jour)
863
+        if ($args) {
864
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
865
+        }
866
+    }
867
+
868
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
869
+        return "<span class=debug-traduction-erreur>$text</span>";
870
+    } else {
871
+        return $text;
872
+    }
874 873
 }
875 874
 
876 875
 
@@ -884,13 +883,13 @@  discard block
 block discarded – undo
884 883
  * @return string
885 884
  */
886 885
 function joli_repertoire($rep) {
887
-	$a = substr($rep, 0, 1);
888
-	if ($a <> '.' and $a <> '/') {
889
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
890
-	}
891
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
886
+    $a = substr($rep, 0, 1);
887
+    if ($a <> '.' and $a <> '/') {
888
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
889
+    }
890
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
892 891
 
893
-	return $rep;
892
+    return $rep;
894 893
 }
895 894
 
896 895
 
@@ -915,33 +914,33 @@  discard block
 block discarded – undo
915 914
  * @return float|int|string|void
916 915
  */
917 916
 function spip_timer($t = 'rien', $raw = false) {
918
-	static $time;
919
-	$a = time();
920
-	$b = microtime();
921
-	// microtime peut contenir les microsecondes et le temps
922
-	$b = explode(' ', $b);
923
-	if (count($b) == 2) {
924
-		$a = end($b);
925
-	} // plus precis !
926
-	$b = reset($b);
927
-	if (!isset($time[$t])) {
928
-		$time[$t] = $a + $b;
929
-	} else {
930
-		$p = ($a + $b - $time[$t]) * 1000;
931
-		unset($time[$t]);
917
+    static $time;
918
+    $a = time();
919
+    $b = microtime();
920
+    // microtime peut contenir les microsecondes et le temps
921
+    $b = explode(' ', $b);
922
+    if (count($b) == 2) {
923
+        $a = end($b);
924
+    } // plus precis !
925
+    $b = reset($b);
926
+    if (!isset($time[$t])) {
927
+        $time[$t] = $a + $b;
928
+    } else {
929
+        $p = ($a + $b - $time[$t]) * 1000;
930
+        unset($time[$t]);
932 931
 #			echo "'$p'";exit;
933
-		if ($raw) {
934
-			return $p;
935
-		}
936
-		if ($p < 1000) {
937
-			$s = '';
938
-		} else {
939
-			$s = sprintf("%d ", $x = floor($p / 1000));
940
-			$p -= ($x * 1000);
941
-		}
932
+        if ($raw) {
933
+            return $p;
934
+        }
935
+        if ($p < 1000) {
936
+            $s = '';
937
+        } else {
938
+            $s = sprintf("%d ", $x = floor($p / 1000));
939
+            $p -= ($x * 1000);
940
+        }
942 941
 
943
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
944
-	}
942
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
943
+    }
945 944
 }
946 945
 
947 946
 
@@ -949,21 +948,21 @@  discard block
 block discarded – undo
949 948
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
950 949
 // http://code.spip.net/@spip_touch
951 950
 function spip_touch($fichier, $duree = 0, $touch = true) {
952
-	if ($duree) {
953
-		clearstatcache();
954
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
955
-			return false;
956
-		}
957
-	}
958
-	if ($touch !== false) {
959
-		if (!@touch($fichier)) {
960
-			spip_unlink($fichier);
961
-			@touch($fichier);
962
-		};
963
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
964
-	}
951
+    if ($duree) {
952
+        clearstatcache();
953
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
954
+            return false;
955
+        }
956
+    }
957
+    if ($touch !== false) {
958
+        if (!@touch($fichier)) {
959
+            spip_unlink($fichier);
960
+            @touch($fichier);
961
+        };
962
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
963
+    }
965 964
 
966
-	return true;
965
+    return true;
967 966
 }
968 967
 
969 968
 
@@ -975,11 +974,11 @@  discard block
 block discarded – undo
975 974
  * @uses cron()
976 975
  **/
977 976
 function action_cron() {
978
-	include_spip('inc/headers');
979
-	http_status(204); // No Content
980
-	header("Connection: close");
981
-	define('_DIRECT_CRON_FORCE', true);
982
-	cron();
977
+    include_spip('inc/headers');
978
+    http_status(204); // No Content
979
+    header("Connection: close");
980
+    define('_DIRECT_CRON_FORCE', true);
981
+    cron();
983 982
 }
984 983
 
985 984
 /**
@@ -995,26 +994,26 @@  discard block
 block discarded – undo
995 994
  *     True si la tache a pu être effectuée
996 995
  */
997 996
 function cron($taches = array(), $taches_old = array()) {
998
-	// si pas en mode cron force, laisser tomber.
999
-	if (!defined('_DIRECT_CRON_FORCE')) {
1000
-		return false;
1001
-	}
1002
-	if (!is_array($taches)) {
1003
-		$taches = $taches_old;
1004
-	} // compat anciens appels
1005
-	// si taches a inserer en base et base inaccessible, laisser tomber
1006
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1007
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1008
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1009
-	if ($taches and count($taches) and !spip_connect()) {
1010
-		return false;
1011
-	}
1012
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1013
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1014
-		return $genie($taches);
1015
-	}
1016
-
1017
-	return false;
997
+    // si pas en mode cron force, laisser tomber.
998
+    if (!defined('_DIRECT_CRON_FORCE')) {
999
+        return false;
1000
+    }
1001
+    if (!is_array($taches)) {
1002
+        $taches = $taches_old;
1003
+    } // compat anciens appels
1004
+    // si taches a inserer en base et base inaccessible, laisser tomber
1005
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1006
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1007
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1008
+    if ($taches and count($taches) and !spip_connect()) {
1009
+        return false;
1010
+    }
1011
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1012
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1013
+        return $genie($taches);
1014
+    }
1015
+
1016
+    return false;
1018 1017
 }
1019 1018
 
1020 1019
 /**
@@ -1046,17 +1045,17 @@  discard block
 block discarded – undo
1046 1045
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1047 1046
  */
1048 1047
 function job_queue_add(
1049
-	$function,
1050
-	$description,
1051
-	$arguments = array(),
1052
-	$file = '',
1053
-	$no_duplicate = false,
1054
-	$time = 0,
1055
-	$priority = 0
1048
+    $function,
1049
+    $description,
1050
+    $arguments = array(),
1051
+    $file = '',
1052
+    $no_duplicate = false,
1053
+    $time = 0,
1054
+    $priority = 0
1056 1055
 ) {
1057
-	include_spip('inc/queue');
1056
+    include_spip('inc/queue');
1058 1057
 
1059
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1058
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1060 1059
 }
1061 1060
 
1062 1061
 /**
@@ -1067,9 +1066,9 @@  discard block
 block discarded – undo
1067 1066
  * @return bool
1068 1067
  */
1069 1068
 function job_queue_remove($id_job) {
1070
-	include_spip('inc/queue');
1069
+    include_spip('inc/queue');
1071 1070
 
1072
-	return queue_remove_job($id_job);
1071
+    return queue_remove_job($id_job);
1073 1072
 }
1074 1073
 
1075 1074
 /**
@@ -1082,9 +1081,9 @@  discard block
 block discarded – undo
1082 1081
  *     or an array of simple array to link multiples objet in one time
1083 1082
  */
1084 1083
 function job_queue_link($id_job, $objets) {
1085
-	include_spip('inc/queue');
1084
+    include_spip('inc/queue');
1086 1085
 
1087
-	return queue_link_job($id_job, $objets);
1086
+    return queue_link_job($id_job, $objets);
1088 1087
 }
1089 1088
 
1090 1089
 
@@ -1104,36 +1103,36 @@  discard block
 block discarded – undo
1104 1103
  *  - `null` si la queue n'est pas encore initialisée
1105 1104
  */
1106 1105
 function queue_sleep_time_to_next_job($force = null) {
1107
-	static $queue_next_job_time = -1;
1108
-	if ($force === true) {
1109
-		$queue_next_job_time = -1;
1110
-	} elseif ($force) {
1111
-		$queue_next_job_time = $force;
1112
-	}
1113
-
1114
-	if ($queue_next_job_time == -1) {
1115
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1116
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1117
-		}
1118
-		// utiliser un cache memoire si dispo
1119
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1120
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1121
-		} else {
1122
-			$queue_next_job_time = null;
1123
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1124
-				$queue_next_job_time = intval($contenu);
1125
-			}
1126
-		}
1127
-	}
1128
-
1129
-	if (is_null($queue_next_job_time)) {
1130
-		return null;
1131
-	}
1132
-	if (!$_SERVER['REQUEST_TIME']) {
1133
-		$_SERVER['REQUEST_TIME'] = time();
1134
-	}
1135
-
1136
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1106
+    static $queue_next_job_time = -1;
1107
+    if ($force === true) {
1108
+        $queue_next_job_time = -1;
1109
+    } elseif ($force) {
1110
+        $queue_next_job_time = $force;
1111
+    }
1112
+
1113
+    if ($queue_next_job_time == -1) {
1114
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1115
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1116
+        }
1117
+        // utiliser un cache memoire si dispo
1118
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1119
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1120
+        } else {
1121
+            $queue_next_job_time = null;
1122
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1123
+                $queue_next_job_time = intval($contenu);
1124
+            }
1125
+        }
1126
+    }
1127
+
1128
+    if (is_null($queue_next_job_time)) {
1129
+        return null;
1130
+    }
1131
+    if (!$_SERVER['REQUEST_TIME']) {
1132
+        $_SERVER['REQUEST_TIME'] = time();
1133
+    }
1134
+
1135
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1137 1136
 }
1138 1137
 
1139 1138
 
@@ -1145,9 +1144,9 @@  discard block
 block discarded – undo
1145 1144
  * @return string
1146 1145
  */
1147 1146
 function quote_amp($u) {
1148
-	return preg_replace(
1149
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1150
-		"&amp;", $u);
1147
+    return preg_replace(
1148
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1149
+        "&amp;", $u);
1151 1150
 }
1152 1151
 
1153 1152
 
@@ -1170,27 +1169,27 @@  discard block
 block discarded – undo
1170 1169
  *     Balise HTML `<script>` et son contenu
1171 1170
  **/
1172 1171
 function http_script($script, $src = '', $noscript = '') {
1173
-	static $done = array();
1172
+    static $done = array();
1174 1173
 
1175
-	if ($src && !isset($done[$src])) {
1176
-		$done[$src] = true;
1177
-		$src = find_in_path($src, _JAVASCRIPT);
1178
-		$src = " src='$src'";
1179
-	} else {
1180
-		$src = '';
1181
-	}
1182
-	if ($script) {
1183
-		$script = ("/*<![CDATA[*/\n" .
1184
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1185
-			"/*]]>*/");
1186
-	}
1187
-	if ($noscript) {
1188
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1189
-	}
1174
+    if ($src && !isset($done[$src])) {
1175
+        $done[$src] = true;
1176
+        $src = find_in_path($src, _JAVASCRIPT);
1177
+        $src = " src='$src'";
1178
+    } else {
1179
+        $src = '';
1180
+    }
1181
+    if ($script) {
1182
+        $script = ("/*<![CDATA[*/\n" .
1183
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1184
+            "/*]]>*/");
1185
+    }
1186
+    if ($noscript) {
1187
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1188
+    }
1190 1189
 
1191
-	return ($src or $script or $noscript)
1192
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1193
-		: '';
1190
+    return ($src or $script or $noscript)
1191
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1192
+        : '';
1194 1193
 }
1195 1194
 
1196 1195
 
@@ -1225,7 +1224,7 @@  discard block
 block discarded – undo
1225 1224
  *     Texte échappé
1226 1225
  **/
1227 1226
 function texte_script($texte) {
1228
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1227
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1229 1228
 }
1230 1229
 
1231 1230
 
@@ -1262,69 +1261,69 @@  discard block
 block discarded – undo
1262 1261
  *     Liste des chemins, par ordre de priorité.
1263 1262
  **/
1264 1263
 function _chemin($dir_path = null) {
1265
-	static $path_base = null;
1266
-	static $path_full = null;
1267
-	if ($path_base == null) {
1268
-		// Chemin standard depuis l'espace public
1269
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1270
-			_DIR_RACINE . ':' .
1271
-			_DIR_RACINE . 'squelettes-dist/:' .
1272
-			_DIR_RACINE . 'prive/:' .
1273
-			_DIR_RESTREINT;
1274
-		// Ajouter squelettes/
1275
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1276
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1277
-		}
1278
-		foreach (explode(':', $path) as $dir) {
1279
-			if (strlen($dir) and substr($dir, -1) != '/') {
1280
-				$dir .= "/";
1281
-			}
1282
-			$path_base[] = $dir;
1283
-		}
1284
-		$path_full = $path_base;
1285
-		// Et le(s) dossier(s) des squelettes nommes
1286
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1287
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1288
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1289
-			}
1290
-		}
1291
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1292
-	}
1293
-	if ($dir_path === null) {
1294
-		return $path_full;
1295
-	}
1296
-
1297
-	if (strlen($dir_path)) {
1298
-		$tete = "";
1299
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1300
-			$tete = array_shift($path_base);
1301
-		}
1302
-		$dirs = array_reverse(explode(':', $dir_path));
1303
-		foreach ($dirs as $dir_path) {
1304
-			#if ($dir_path{0}!='/')
1305
-			#	$dir_path = $dir_path;
1306
-			if (substr($dir_path, -1) != '/') {
1307
-				$dir_path .= "/";
1308
-			}
1309
-			if (!in_array($dir_path, $path_base)) {
1310
-				array_unshift($path_base, $dir_path);
1311
-			}
1312
-		}
1313
-		if (strlen($tete)) {
1314
-			array_unshift($path_base, $tete);
1315
-		}
1316
-	}
1317
-	$path_full = $path_base;
1318
-	// Et le(s) dossier(s) des squelettes nommes
1319
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1320
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1321
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1322
-		}
1323
-	}
1324
-
1325
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1326
-
1327
-	return $path_full;
1264
+    static $path_base = null;
1265
+    static $path_full = null;
1266
+    if ($path_base == null) {
1267
+        // Chemin standard depuis l'espace public
1268
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1269
+            _DIR_RACINE . ':' .
1270
+            _DIR_RACINE . 'squelettes-dist/:' .
1271
+            _DIR_RACINE . 'prive/:' .
1272
+            _DIR_RESTREINT;
1273
+        // Ajouter squelettes/
1274
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1275
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1276
+        }
1277
+        foreach (explode(':', $path) as $dir) {
1278
+            if (strlen($dir) and substr($dir, -1) != '/') {
1279
+                $dir .= "/";
1280
+            }
1281
+            $path_base[] = $dir;
1282
+        }
1283
+        $path_full = $path_base;
1284
+        // Et le(s) dossier(s) des squelettes nommes
1285
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1286
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1287
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1288
+            }
1289
+        }
1290
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1291
+    }
1292
+    if ($dir_path === null) {
1293
+        return $path_full;
1294
+    }
1295
+
1296
+    if (strlen($dir_path)) {
1297
+        $tete = "";
1298
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1299
+            $tete = array_shift($path_base);
1300
+        }
1301
+        $dirs = array_reverse(explode(':', $dir_path));
1302
+        foreach ($dirs as $dir_path) {
1303
+            #if ($dir_path{0}!='/')
1304
+            #	$dir_path = $dir_path;
1305
+            if (substr($dir_path, -1) != '/') {
1306
+                $dir_path .= "/";
1307
+            }
1308
+            if (!in_array($dir_path, $path_base)) {
1309
+                array_unshift($path_base, $dir_path);
1310
+            }
1311
+        }
1312
+        if (strlen($tete)) {
1313
+            array_unshift($path_base, $tete);
1314
+        }
1315
+    }
1316
+    $path_full = $path_base;
1317
+    // Et le(s) dossier(s) des squelettes nommes
1318
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1319
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1320
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1321
+        }
1322
+    }
1323
+
1324
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1325
+
1326
+    return $path_full;
1328 1327
 }
1329 1328
 
1330 1329
 /**
@@ -1337,76 +1336,76 @@  discard block
 block discarded – undo
1337 1336
  * @return array Liste de chemins
1338 1337
  **/
1339 1338
 function creer_chemin() {
1340
-	$path_a = _chemin();
1341
-	static $c = '';
1339
+    $path_a = _chemin();
1340
+    static $c = '';
1342 1341
 
1343
-	// on calcule le chemin si le dossier skel a change
1344
-	if ($c != $GLOBALS['dossier_squelettes']) {
1345
-		// assurer le non plantage lors de la montee de version :
1346
-		$c = $GLOBALS['dossier_squelettes'];
1347
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1348
-	}
1342
+    // on calcule le chemin si le dossier skel a change
1343
+    if ($c != $GLOBALS['dossier_squelettes']) {
1344
+        // assurer le non plantage lors de la montee de version :
1345
+        $c = $GLOBALS['dossier_squelettes'];
1346
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1347
+    }
1349 1348
 
1350
-	return $path_a;
1349
+    return $path_a;
1351 1350
 }
1352 1351
 
1353 1352
 
1354 1353
 function lister_themes_prives() {
1355
-	static $themes = null;
1356
-	if (is_null($themes)) {
1357
-		// si pas encore definie
1358
-		if (!defined('_SPIP_THEME_PRIVE')) {
1359
-			define('_SPIP_THEME_PRIVE', 'spip');
1360
-		}
1361
-		$themes = array(_SPIP_THEME_PRIVE);
1362
-		// lors d'une installation neuve, prefs n'est pas definie.
1363
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1364
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1365
-		} else {
1366
-			$prefs = array();
1367
-		}
1368
-		if (is_string($prefs)) {
1369
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1370
-		}
1371
-		if (
1372
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1373
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1374
-			and $theme != _SPIP_THEME_PRIVE
1375
-		) {
1376
-			array_unshift($themes, $theme);
1377
-		} // placer le theme choisi en tete
1378
-	}
1379
-
1380
-	return $themes;
1354
+    static $themes = null;
1355
+    if (is_null($themes)) {
1356
+        // si pas encore definie
1357
+        if (!defined('_SPIP_THEME_PRIVE')) {
1358
+            define('_SPIP_THEME_PRIVE', 'spip');
1359
+        }
1360
+        $themes = array(_SPIP_THEME_PRIVE);
1361
+        // lors d'une installation neuve, prefs n'est pas definie.
1362
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1363
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1364
+        } else {
1365
+            $prefs = array();
1366
+        }
1367
+        if (is_string($prefs)) {
1368
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1369
+        }
1370
+        if (
1371
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1372
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1373
+            and $theme != _SPIP_THEME_PRIVE
1374
+        ) {
1375
+            array_unshift($themes, $theme);
1376
+        } // placer le theme choisi en tete
1377
+    }
1378
+
1379
+    return $themes;
1381 1380
 }
1382 1381
 
1383 1382
 function find_in_theme($file, $subdir = '', $include = false) {
1384
-	static $themefiles = array();
1385
-	if (isset($themefiles["$subdir$file"])) {
1386
-		return $themefiles["$subdir$file"];
1387
-	}
1388
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1389
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1390
-	if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1391
-	  and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1392
-		and $f = find_in_theme("$file_svg_generique")) {
1393
-		if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1394
-			return $themefiles["$subdir$file"] = $fsize;
1395
-		}
1396
-		else {
1397
-			return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1398
-		}
1399
-	}
1400
-
1401
-	$themes = lister_themes_prives();
1402
-	foreach ($themes as $theme) {
1403
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1404
-			return $themefiles["$subdir$file"] = $f;
1405
-		}
1406
-	}
1407
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1408
-
1409
-	return $themefiles["$subdir$file"] = "";
1383
+    static $themefiles = array();
1384
+    if (isset($themefiles["$subdir$file"])) {
1385
+        return $themefiles["$subdir$file"];
1386
+    }
1387
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1388
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1389
+    if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1390
+      and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1391
+        and $f = find_in_theme("$file_svg_generique")) {
1392
+        if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1393
+            return $themefiles["$subdir$file"] = $fsize;
1394
+        }
1395
+        else {
1396
+            return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1397
+        }
1398
+    }
1399
+
1400
+    $themes = lister_themes_prives();
1401
+    foreach ($themes as $theme) {
1402
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1403
+            return $themefiles["$subdir$file"] = $f;
1404
+        }
1405
+    }
1406
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1407
+
1408
+    return $themefiles["$subdir$file"] = "";
1410 1409
 }
1411 1410
 
1412 1411
 
@@ -1430,31 +1429,31 @@  discard block
 block discarded – undo
1430 1429
  *     sinon chaîne vide.
1431 1430
  **/
1432 1431
 function chemin_image($icone) {
1433
-	static $icone_renommer;
1434
-	if ($p = strpos($icone, '?')) {
1435
-		$icone = substr($icone,0, $p);
1436
-	}
1437
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1438
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1439
-		return $icone;
1440
-	}
1441
-
1442
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1443
-	if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1444
-		return $f;
1445
-	}
1446
-	// sinon passer par le module de renommage
1447
-	if (is_null($icone_renommer)) {
1448
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1449
-	}
1450
-	if ($icone_renommer) {
1451
-		list($icone, $fonction) = $icone_renommer($icone, "");
1452
-		if (file_exists($icone)) {
1453
-			return $icone;
1454
-		}
1455
-	}
1456
-
1457
-	return find_in_path($icone, _NOM_IMG_PACK);
1432
+    static $icone_renommer;
1433
+    if ($p = strpos($icone, '?')) {
1434
+        $icone = substr($icone,0, $p);
1435
+    }
1436
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1437
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1438
+        return $icone;
1439
+    }
1440
+
1441
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1442
+    if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1443
+        return $f;
1444
+    }
1445
+    // sinon passer par le module de renommage
1446
+    if (is_null($icone_renommer)) {
1447
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1448
+    }
1449
+    if ($icone_renommer) {
1450
+        list($icone, $fonction) = $icone_renommer($icone, "");
1451
+        if (file_exists($icone)) {
1452
+            return $icone;
1453
+        }
1454
+    }
1455
+
1456
+    return find_in_path($icone, _NOM_IMG_PACK);
1458 1457
 }
1459 1458
 
1460 1459
 //
@@ -1492,127 +1491,127 @@  discard block
 block discarded – undo
1492 1491
  *     - false : fichier introuvable
1493 1492
  **/
1494 1493
 function find_in_path($file, $dirname = '', $include = false) {
1495
-	static $dirs = array();
1496
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1497
-	static $c = '';
1498
-
1499
-	if (!$file and !strlen($file)) {
1500
-		return false;
1501
-	}
1502
-
1503
-	// on calcule le chemin si le dossier skel a change
1504
-	if ($c != $GLOBALS['dossier_squelettes']) {
1505
-		// assurer le non plantage lors de la montee de version :
1506
-		$c = $GLOBALS['dossier_squelettes'];
1507
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1508
-	}
1509
-
1510
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1511
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1512
-			return false;
1513
-		}
1514
-		if ($include and !isset($inc[$dirname][$file])) {
1515
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1516
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1517
-		}
1518
-
1519
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1520
-	}
1521
-
1522
-	$a = strrpos($file, '/');
1523
-	if ($a !== false) {
1524
-		$dirname .= substr($file, 0, ++$a);
1525
-		$file = substr($file, $a);
1526
-	}
1527
-
1528
-	foreach (creer_chemin() as $dir) {
1529
-		if (!isset($dirs[$a = $dir . $dirname])) {
1530
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1531
-		}
1532
-		if ($dirs[$a]) {
1533
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1534
-				if ($include and !isset($inc[$dirname][$file])) {
1535
-					include_once _ROOT_CWD . $a;
1536
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1537
-				}
1538
-				if (!defined('_SAUVER_CHEMIN')) {
1539
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1540
-					if (is_null($GLOBALS['path_files'])) {
1541
-						return $a;
1542
-					}
1543
-					define('_SAUVER_CHEMIN', true);
1544
-				}
1545
-
1546
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1547
-			}
1548
-		}
1549
-	}
1550
-
1551
-	if ($include) {
1552
-		spip_log("include_spip $dirname$file non trouve");
1553
-		if ($include === 'required') {
1554
-			echo '<pre>',
1555
-			"<strong>Erreur Fatale</strong><br />";
1556
-			if (function_exists('debug_print_backtrace')) {
1557
-				echo debug_print_backtrace();
1558
-			}
1559
-			echo '</pre>';
1560
-			die("Erreur interne: ne peut inclure $dirname$file");
1561
-		}
1562
-	}
1563
-
1564
-	if (!defined('_SAUVER_CHEMIN')) {
1565
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1566
-		if (is_null($GLOBALS['path_files'])) {
1567
-			return false;
1568
-		}
1569
-		define('_SAUVER_CHEMIN', true);
1570
-	}
1571
-
1572
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1494
+    static $dirs = array();
1495
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1496
+    static $c = '';
1497
+
1498
+    if (!$file and !strlen($file)) {
1499
+        return false;
1500
+    }
1501
+
1502
+    // on calcule le chemin si le dossier skel a change
1503
+    if ($c != $GLOBALS['dossier_squelettes']) {
1504
+        // assurer le non plantage lors de la montee de version :
1505
+        $c = $GLOBALS['dossier_squelettes'];
1506
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1507
+    }
1508
+
1509
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1510
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1511
+            return false;
1512
+        }
1513
+        if ($include and !isset($inc[$dirname][$file])) {
1514
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1515
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1516
+        }
1517
+
1518
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1519
+    }
1520
+
1521
+    $a = strrpos($file, '/');
1522
+    if ($a !== false) {
1523
+        $dirname .= substr($file, 0, ++$a);
1524
+        $file = substr($file, $a);
1525
+    }
1526
+
1527
+    foreach (creer_chemin() as $dir) {
1528
+        if (!isset($dirs[$a = $dir . $dirname])) {
1529
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1530
+        }
1531
+        if ($dirs[$a]) {
1532
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1533
+                if ($include and !isset($inc[$dirname][$file])) {
1534
+                    include_once _ROOT_CWD . $a;
1535
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1536
+                }
1537
+                if (!defined('_SAUVER_CHEMIN')) {
1538
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1539
+                    if (is_null($GLOBALS['path_files'])) {
1540
+                        return $a;
1541
+                    }
1542
+                    define('_SAUVER_CHEMIN', true);
1543
+                }
1544
+
1545
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1546
+            }
1547
+        }
1548
+    }
1549
+
1550
+    if ($include) {
1551
+        spip_log("include_spip $dirname$file non trouve");
1552
+        if ($include === 'required') {
1553
+            echo '<pre>',
1554
+            "<strong>Erreur Fatale</strong><br />";
1555
+            if (function_exists('debug_print_backtrace')) {
1556
+                echo debug_print_backtrace();
1557
+            }
1558
+            echo '</pre>';
1559
+            die("Erreur interne: ne peut inclure $dirname$file");
1560
+        }
1561
+    }
1562
+
1563
+    if (!defined('_SAUVER_CHEMIN')) {
1564
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1565
+        if (is_null($GLOBALS['path_files'])) {
1566
+            return false;
1567
+        }
1568
+        define('_SAUVER_CHEMIN', true);
1569
+    }
1570
+
1571
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1573 1572
 }
1574 1573
 
1575 1574
 function clear_path_cache() {
1576
-	$GLOBALS['path_files'] = array();
1577
-	spip_unlink(_CACHE_CHEMIN);
1575
+    $GLOBALS['path_files'] = array();
1576
+    spip_unlink(_CACHE_CHEMIN);
1578 1577
 }
1579 1578
 
1580 1579
 function load_path_cache() {
1581
-	// charger le path des plugins
1582
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1583
-		include_once(_CACHE_PLUGINS_PATH);
1584
-	}
1585
-	$GLOBALS['path_files'] = array();
1586
-	// si le visiteur est admin,
1587
-	// on ne recharge pas le cache pour forcer sa mise a jour
1588
-	if (
1589
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1590
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1591
-		// utiliser le cookie est un pis aller qui marche 'en general'
1592
-		// on blinde par un second test au moment de la lecture de la session
1593
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1594
-		// et en ignorant ce cache en cas de recalcul explicite
1595
-	!_request('var_mode')
1596
-	) {
1597
-		// on essaye de lire directement sans verrou pour aller plus vite
1598
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1599
-			// mais si semble corrompu on relit avec un verrou
1600
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1601
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1602
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1603
-					$GLOBALS['path_files'] = array();
1604
-				}
1605
-			}
1606
-		}
1607
-	}
1580
+    // charger le path des plugins
1581
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1582
+        include_once(_CACHE_PLUGINS_PATH);
1583
+    }
1584
+    $GLOBALS['path_files'] = array();
1585
+    // si le visiteur est admin,
1586
+    // on ne recharge pas le cache pour forcer sa mise a jour
1587
+    if (
1588
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1589
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1590
+        // utiliser le cookie est un pis aller qui marche 'en general'
1591
+        // on blinde par un second test au moment de la lecture de la session
1592
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1593
+        // et en ignorant ce cache en cas de recalcul explicite
1594
+    !_request('var_mode')
1595
+    ) {
1596
+        // on essaye de lire directement sans verrou pour aller plus vite
1597
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1598
+            // mais si semble corrompu on relit avec un verrou
1599
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1600
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1601
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1602
+                    $GLOBALS['path_files'] = array();
1603
+                }
1604
+            }
1605
+        }
1606
+    }
1608 1607
 }
1609 1608
 
1610 1609
 function save_path_cache() {
1611
-	if (defined('_SAUVER_CHEMIN')
1612
-		and _SAUVER_CHEMIN
1613
-	) {
1614
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1615
-	}
1610
+    if (defined('_SAUVER_CHEMIN')
1611
+        and _SAUVER_CHEMIN
1612
+    ) {
1613
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1614
+    }
1616 1615
 }
1617 1616
 
1618 1617
 
@@ -1632,33 +1631,33 @@  discard block
 block discarded – undo
1632 1631
  * @return array
1633 1632
  */
1634 1633
 function find_all_in_path($dir, $pattern, $recurs = false) {
1635
-	$liste_fichiers = array();
1636
-	$maxfiles = 10000;
1637
-
1638
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1639
-	// on a pas encore inclus flock.php
1640
-	if (!function_exists('preg_files')) {
1641
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1642
-	}
1643
-
1644
-	// Parcourir le chemin
1645
-	foreach (creer_chemin() as $d) {
1646
-		$f = $d . $dir;
1647
-		if (@is_dir($f)) {
1648
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1649
-			foreach ($liste as $chemin) {
1650
-				$nom = basename($chemin);
1651
-				// ne prendre que les fichiers pas deja trouves
1652
-				// car find_in_path prend le premier qu'il trouve,
1653
-				// les autres sont donc masques
1654
-				if (!isset($liste_fichiers[$nom])) {
1655
-					$liste_fichiers[$nom] = $chemin;
1656
-				}
1657
-			}
1658
-		}
1659
-	}
1660
-
1661
-	return $liste_fichiers;
1634
+    $liste_fichiers = array();
1635
+    $maxfiles = 10000;
1636
+
1637
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1638
+    // on a pas encore inclus flock.php
1639
+    if (!function_exists('preg_files')) {
1640
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1641
+    }
1642
+
1643
+    // Parcourir le chemin
1644
+    foreach (creer_chemin() as $d) {
1645
+        $f = $d . $dir;
1646
+        if (@is_dir($f)) {
1647
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1648
+            foreach ($liste as $chemin) {
1649
+                $nom = basename($chemin);
1650
+                // ne prendre que les fichiers pas deja trouves
1651
+                // car find_in_path prend le premier qu'il trouve,
1652
+                // les autres sont donc masques
1653
+                if (!isset($liste_fichiers[$nom])) {
1654
+                    $liste_fichiers[$nom] = $chemin;
1655
+                }
1656
+            }
1657
+        }
1658
+    }
1659
+
1660
+    return $liste_fichiers;
1662 1661
 }
1663 1662
 
1664 1663
 /**
@@ -1670,17 +1669,17 @@  discard block
 block discarded – undo
1670 1669
  * @return bool
1671 1670
  */
1672 1671
 function autoriser_sans_cookie($nom, $strict = false) {
1673
-	static $autsanscookie = array('install', 'base_repair');
1672
+    static $autsanscookie = array('install', 'base_repair');
1674 1673
 
1675
-	if (in_array($nom, $autsanscookie)) {
1676
-		if (test_espace_prive()){
1677
-			include_spip('base/connect_sql');
1678
-			if (!$strict or !spip_connect()){
1679
-				return true;
1680
-			}
1681
-		}
1682
-	}
1683
-	return false;
1674
+    if (in_array($nom, $autsanscookie)) {
1675
+        if (test_espace_prive()){
1676
+            include_spip('base/connect_sql');
1677
+            if (!$strict or !spip_connect()){
1678
+                return true;
1679
+            }
1680
+        }
1681
+    }
1682
+    return false;
1684 1683
 }
1685 1684
 
1686 1685
 /**
@@ -1706,99 +1705,99 @@  discard block
 block discarded – undo
1706 1705
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1707 1706
  */
1708 1707
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1709
-	if ($public === null) {
1710
-		$public = !test_espace_prive();
1711
-	}
1712
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1713
-
1714
-	if (!$public) {
1715
-		if (!$entite) {
1716
-			return '';
1717
-		}
1718
-		if (!function_exists('generer_url_ecrire_objet')) {
1719
-			include_spip('inc/urls');
1720
-		}
1721
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1722
-	} else {
1723
-		if ($type === null) {
1724
-			$type = (isset($GLOBALS['type_urls']))
1725
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1726
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1727
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1728
-		}
1729
-
1730
-		$f = charger_fonction($type, 'urls', true);
1731
-		// se rabattre sur les urls page si les urls perso non dispo
1732
-		if (!$f) {
1733
-			$f = charger_fonction('page', 'urls', true);
1734
-		}
1735
-
1736
-		// si $entite='', on veut la fonction de passage URL ==> id
1737
-		// sinon on veut effectuer le passage id ==> URL
1738
-		if (!$entite) {
1739
-			return $f;
1740
-		}
1741
-
1742
-		// mais d'abord il faut tester le cas des urls sur une
1743
-		// base distante
1744
-		if (is_string($public)
1745
-			and $g = charger_fonction('connect', 'urls', true)
1746
-		) {
1747
-			$f = $g;
1748
-		}
1749
-
1750
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1751
-
1752
-	}
1753
-	if ($res) {
1754
-		return $res;
1755
-	}
1756
-	// Sinon c'est un raccourci ou compat SPIP < 2
1757
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1758
-		if (!function_exists($f .= '_dist')) {
1759
-			$f = '';
1760
-		}
1761
-	}
1762
-	if ($f) {
1763
-		$url = $f($id, $args, $ancre);
1764
-		if (strlen($args)) {
1765
-			$url .= strstr($url, '?')
1766
-				? '&amp;' . $args
1767
-				: '?' . $args;
1768
-		}
1769
-
1770
-		return $url;
1771
-	}
1772
-	// On a ete gentil mais la ....
1773
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1774
-
1775
-	return '';
1708
+    if ($public === null) {
1709
+        $public = !test_espace_prive();
1710
+    }
1711
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1712
+
1713
+    if (!$public) {
1714
+        if (!$entite) {
1715
+            return '';
1716
+        }
1717
+        if (!function_exists('generer_url_ecrire_objet')) {
1718
+            include_spip('inc/urls');
1719
+        }
1720
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1721
+    } else {
1722
+        if ($type === null) {
1723
+            $type = (isset($GLOBALS['type_urls']))
1724
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1725
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1726
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1727
+        }
1728
+
1729
+        $f = charger_fonction($type, 'urls', true);
1730
+        // se rabattre sur les urls page si les urls perso non dispo
1731
+        if (!$f) {
1732
+            $f = charger_fonction('page', 'urls', true);
1733
+        }
1734
+
1735
+        // si $entite='', on veut la fonction de passage URL ==> id
1736
+        // sinon on veut effectuer le passage id ==> URL
1737
+        if (!$entite) {
1738
+            return $f;
1739
+        }
1740
+
1741
+        // mais d'abord il faut tester le cas des urls sur une
1742
+        // base distante
1743
+        if (is_string($public)
1744
+            and $g = charger_fonction('connect', 'urls', true)
1745
+        ) {
1746
+            $f = $g;
1747
+        }
1748
+
1749
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1750
+
1751
+    }
1752
+    if ($res) {
1753
+        return $res;
1754
+    }
1755
+    // Sinon c'est un raccourci ou compat SPIP < 2
1756
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1757
+        if (!function_exists($f .= '_dist')) {
1758
+            $f = '';
1759
+        }
1760
+    }
1761
+    if ($f) {
1762
+        $url = $f($id, $args, $ancre);
1763
+        if (strlen($args)) {
1764
+            $url .= strstr($url, '?')
1765
+                ? '&amp;' . $args
1766
+                : '?' . $args;
1767
+        }
1768
+
1769
+        return $url;
1770
+    }
1771
+    // On a ete gentil mais la ....
1772
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1773
+
1774
+    return '';
1776 1775
 }
1777 1776
 
1778 1777
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1779
-	$exec = objet_info($entite, 'url_edit');
1780
-	$url = generer_url_ecrire($exec, $args);
1781
-	if (intval($id)) {
1782
-		$url = parametre_url($url, id_table_objet($entite), $id);
1783
-	} else {
1784
-		$url = parametre_url($url, 'new', 'oui');
1785
-	}
1786
-	if ($ancre) {
1787
-		$url = ancre_url($url, $ancre);
1788
-	}
1778
+    $exec = objet_info($entite, 'url_edit');
1779
+    $url = generer_url_ecrire($exec, $args);
1780
+    if (intval($id)) {
1781
+        $url = parametre_url($url, id_table_objet($entite), $id);
1782
+    } else {
1783
+        $url = parametre_url($url, 'new', 'oui');
1784
+    }
1785
+    if ($ancre) {
1786
+        $url = ancre_url($url, $ancre);
1787
+    }
1789 1788
 
1790
-	return $url;
1789
+    return $url;
1791 1790
 }
1792 1791
 
1793 1792
 // http://code.spip.net/@urls_connect_dist
1794 1793
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1795
-	include_spip('base/connect_sql');
1796
-	$id_type = id_table_objet($entite, $public);
1794
+    include_spip('base/connect_sql');
1795
+    $id_type = id_table_objet($entite, $public);
1797 1796
 
1798
-	return _DIR_RACINE . get_spip_script('./')
1799
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1800
-	. (!$args ? '' : "&$args")
1801
-	. (!$ancre ? '' : "#$ancre");
1797
+    return _DIR_RACINE . get_spip_script('./')
1798
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1799
+    . (!$args ? '' : "&$args")
1800
+    . (!$ancre ? '' : "#$ancre");
1802 1801
 }
1803 1802
 
1804 1803
 
@@ -1809,32 +1808,32 @@  discard block
 block discarded – undo
1809 1808
  * @return string
1810 1809
  */
1811 1810
 function urlencode_1738($url) {
1812
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1813
-		$uri = '';
1814
-		for ($i = 0; $i < strlen($url); $i++) {
1815
-			if (ord($a = $url[$i]) > 127) {
1816
-				$a = rawurlencode($a);
1817
-			}
1818
-			$uri .= $a;
1819
-		}
1820
-		$url = $uri;
1821
-	}
1811
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1812
+        $uri = '';
1813
+        for ($i = 0; $i < strlen($url); $i++) {
1814
+            if (ord($a = $url[$i]) > 127) {
1815
+                $a = rawurlencode($a);
1816
+            }
1817
+            $uri .= $a;
1818
+        }
1819
+        $url = $uri;
1820
+    }
1822 1821
 
1823
-	return quote_amp($url);
1822
+    return quote_amp($url);
1824 1823
 }
1825 1824
 
1826 1825
 // http://code.spip.net/@generer_url_entite_absolue
1827 1826
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1828
-	if (!$connect) {
1829
-		$connect = true;
1830
-	}
1831
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1832
-	if (!preg_match(',^\w+:,', $h)) {
1833
-		include_spip('inc/filtres_mini');
1834
-		$h = url_absolue($h);
1835
-	}
1827
+    if (!$connect) {
1828
+        $connect = true;
1829
+    }
1830
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1831
+    if (!preg_match(',^\w+:,', $h)) {
1832
+        include_spip('inc/filtres_mini');
1833
+        $h = url_absolue($h);
1834
+    }
1836 1835
 
1837
-	return $h;
1836
+    return $h;
1838 1837
 }
1839 1838
 
1840 1839
 
@@ -1850,11 +1849,11 @@  discard block
 block discarded – undo
1850 1849
  *     true si la valeur est considérée active ; false sinon.
1851 1850
  **/
1852 1851
 function test_valeur_serveur($truc) {
1853
-	if (!$truc) {
1854
-		return false;
1855
-	}
1852
+    if (!$truc) {
1853
+        return false;
1854
+    }
1856 1855
 
1857
-	return (strtolower($truc) !== 'off');
1856
+    return (strtolower($truc) !== 'off');
1858 1857
 }
1859 1858
 
1860 1859
 //
@@ -1882,80 +1881,80 @@  discard block
 block discarded – undo
1882 1881
  */
1883 1882
 function url_de_base($profondeur = null) {
1884 1883
 
1885
-	static $url = array();
1886
-	if (is_array($profondeur)) {
1887
-		return $url = $profondeur;
1888
-	}
1889
-	if ($profondeur === false) {
1890
-		return $url;
1891
-	}
1892
-
1893
-	if (is_null($profondeur)) {
1894
-		$profondeur = $GLOBALS['profondeur_url'];
1895
-	}
1896
-
1897
-	if (isset($url[$profondeur])) {
1898
-		return $url[$profondeur];
1899
-	}
1900
-
1901
-	$http = 'http';
1902
-
1903
-	if (
1904
-		isset($_SERVER["SCRIPT_URI"])
1905
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1906
-	) {
1907
-		$http = 'https';
1908
-	} elseif (
1909
-		isset($_SERVER['HTTPS'])
1910
-		and test_valeur_serveur($_SERVER['HTTPS'])
1911
-	) {
1912
-		$http = 'https';
1913
-	}
1914
-
1915
-	// note : HTTP_HOST contient le :port si necessaire
1916
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1917
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1918
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1919
-		$host = $GLOBALS['meta']['adresse_site'];
1920
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1921
-			$http = $scheme;
1922
-			$host = str_replace("{$scheme}://", '', $host);
1923
-		}
1924
-	}
1925
-	if (isset($_SERVER['SERVER_PORT'])
1926
-		and $port = $_SERVER['SERVER_PORT']
1927
-		and strpos($host, ":") == false
1928
-	) {
1929
-		if (!defined('_PORT_HTTP_STANDARD')) {
1930
-			define('_PORT_HTTP_STANDARD', '80');
1931
-		}
1932
-		if (!defined('_PORT_HTTPS_STANDARD')) {
1933
-			define('_PORT_HTTPS_STANDARD', '443');
1934
-		}
1935
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1936
-			$host .= ":$port";
1937
-		}
1938
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1939
-			$host .= ":$port";
1940
-		}
1941
-	}
1942
-
1943
-	if (!$GLOBALS['REQUEST_URI']) {
1944
-		if (isset($_SERVER['REQUEST_URI'])) {
1945
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1946
-		} else {
1947
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1948
-			if (!empty($_SERVER['QUERY_STRING'])
1949
-				and !strpos($_SERVER['REQUEST_URI'], '?')
1950
-			) {
1951
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1952
-			}
1953
-		}
1954
-	}
1955
-
1956
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1957
-
1958
-	return $url[$profondeur];
1884
+    static $url = array();
1885
+    if (is_array($profondeur)) {
1886
+        return $url = $profondeur;
1887
+    }
1888
+    if ($profondeur === false) {
1889
+        return $url;
1890
+    }
1891
+
1892
+    if (is_null($profondeur)) {
1893
+        $profondeur = $GLOBALS['profondeur_url'];
1894
+    }
1895
+
1896
+    if (isset($url[$profondeur])) {
1897
+        return $url[$profondeur];
1898
+    }
1899
+
1900
+    $http = 'http';
1901
+
1902
+    if (
1903
+        isset($_SERVER["SCRIPT_URI"])
1904
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1905
+    ) {
1906
+        $http = 'https';
1907
+    } elseif (
1908
+        isset($_SERVER['HTTPS'])
1909
+        and test_valeur_serveur($_SERVER['HTTPS'])
1910
+    ) {
1911
+        $http = 'https';
1912
+    }
1913
+
1914
+    // note : HTTP_HOST contient le :port si necessaire
1915
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1916
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1917
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1918
+        $host = $GLOBALS['meta']['adresse_site'];
1919
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1920
+            $http = $scheme;
1921
+            $host = str_replace("{$scheme}://", '', $host);
1922
+        }
1923
+    }
1924
+    if (isset($_SERVER['SERVER_PORT'])
1925
+        and $port = $_SERVER['SERVER_PORT']
1926
+        and strpos($host, ":") == false
1927
+    ) {
1928
+        if (!defined('_PORT_HTTP_STANDARD')) {
1929
+            define('_PORT_HTTP_STANDARD', '80');
1930
+        }
1931
+        if (!defined('_PORT_HTTPS_STANDARD')) {
1932
+            define('_PORT_HTTPS_STANDARD', '443');
1933
+        }
1934
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1935
+            $host .= ":$port";
1936
+        }
1937
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1938
+            $host .= ":$port";
1939
+        }
1940
+    }
1941
+
1942
+    if (!$GLOBALS['REQUEST_URI']) {
1943
+        if (isset($_SERVER['REQUEST_URI'])) {
1944
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1945
+        } else {
1946
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1947
+            if (!empty($_SERVER['QUERY_STRING'])
1948
+                and !strpos($_SERVER['REQUEST_URI'], '?')
1949
+            ) {
1950
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1951
+            }
1952
+        }
1953
+    }
1954
+
1955
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1956
+
1957
+    return $url[$profondeur];
1959 1958
 }
1960 1959
 
1961 1960
 /**
@@ -1968,26 +1967,26 @@  discard block
 block discarded – undo
1968 1967
  * @return string
1969 1968
  */
1970 1969
 function url_de_($http, $host, $request, $prof = 0) {
1971
-	$prof = max($prof, 0);
1970
+    $prof = max($prof, 0);
1972 1971
 
1973
-	$myself = ltrim($request, '/');
1974
-	# supprimer la chaine de GET
1975
-	list($myself) = explode('?', $myself);
1976
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1977
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1978
-	if (strpos($myself,'://') !== false) {
1979
-		$myself = explode('://',$myself);
1980
-		array_shift($myself);
1981
-		$myself = implode('://',$myself);
1982
-		$myself = explode('/',$myself);
1983
-		array_shift($myself);
1984
-		$myself = implode('/',$myself);
1985
-	}
1986
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1972
+    $myself = ltrim($request, '/');
1973
+    # supprimer la chaine de GET
1974
+    list($myself) = explode('?', $myself);
1975
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1976
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1977
+    if (strpos($myself,'://') !== false) {
1978
+        $myself = explode('://',$myself);
1979
+        array_shift($myself);
1980
+        $myself = implode('://',$myself);
1981
+        $myself = explode('/',$myself);
1982
+        array_shift($myself);
1983
+        $myself = implode('/',$myself);
1984
+    }
1985
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1987 1986
 
1988
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1987
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1989 1988
 
1990
-	return $url;
1989
+    return $url;
1991 1990
 }
1992 1991
 
1993 1992
 
@@ -2022,26 +2021,26 @@  discard block
 block discarded – undo
2022 2021
  * @return string URL
2023 2022
  **/
2024 2023
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
2025
-	if (!$rel) {
2026
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2027
-	} else {
2028
-		if (!is_string($rel)) {
2029
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2030
-				('./' . _SPIP_ECRIRE_SCRIPT);
2031
-		}
2032
-	}
2033
-
2034
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2035
-	if ($script and ($script <> 'accueil' or $rel)) {
2036
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2037
-	} elseif ($args) {
2038
-		$args = "?$args";
2039
-	}
2040
-	if ($ancre) {
2041
-		$args .= "#$ancre";
2042
-	}
2043
-
2044
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2024
+    if (!$rel) {
2025
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2026
+    } else {
2027
+        if (!is_string($rel)) {
2028
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2029
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2030
+        }
2031
+    }
2032
+
2033
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2034
+    if ($script and ($script <> 'accueil' or $rel)) {
2035
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2036
+    } elseif ($args) {
2037
+        $args = "?$args";
2038
+    }
2039
+    if ($ancre) {
2040
+        $args .= "#$ancre";
2041
+    }
2042
+
2043
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2045 2044
 }
2046 2045
 
2047 2046
 //
@@ -2063,12 +2062,12 @@  discard block
 block discarded – undo
2063 2062
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2064 2063
  **/
2065 2064
 function get_spip_script($default = '') {
2066
-	# cas define('_SPIP_SCRIPT', '');
2067
-	if (_SPIP_SCRIPT) {
2068
-		return _SPIP_SCRIPT;
2069
-	} else {
2070
-		return $default;
2071
-	}
2065
+    # cas define('_SPIP_SCRIPT', '');
2066
+    if (_SPIP_SCRIPT) {
2067
+        return _SPIP_SCRIPT;
2068
+    } else {
2069
+        return $default;
2070
+    }
2072 2071
 }
2073 2072
 
2074 2073
 /**
@@ -2097,39 +2096,39 @@  discard block
 block discarded – undo
2097 2096
  * @return string URL
2098 2097
  **/
2099 2098
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2100
-	// si le script est une action (spip_pass, spip_inscription),
2101
-	// standardiser vers la nouvelle API
2102
-
2103
-	if (!$action) {
2104
-		$action = get_spip_script();
2105
-	}
2106
-	if ($script) {
2107
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2108
-	}
2109
-
2110
-	if ($args) {
2111
-		if (is_array($args)) {
2112
-			$r = '';
2113
-			foreach ($args as $k => $v) {
2114
-				$r .= '&' . $k . '=' . $v;
2115
-			}
2116
-			$args = substr($r, 1);
2117
-		}
2118
-		$action .=
2119
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2120
-	}
2121
-	if (!$no_entities) {
2122
-		$action = quote_amp($action);
2123
-	}
2124
-
2125
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2126
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2099
+    // si le script est une action (spip_pass, spip_inscription),
2100
+    // standardiser vers la nouvelle API
2101
+
2102
+    if (!$action) {
2103
+        $action = get_spip_script();
2104
+    }
2105
+    if ($script) {
2106
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2107
+    }
2108
+
2109
+    if ($args) {
2110
+        if (is_array($args)) {
2111
+            $r = '';
2112
+            foreach ($args as $k => $v) {
2113
+                $r .= '&' . $k . '=' . $v;
2114
+            }
2115
+            $args = substr($r, 1);
2116
+        }
2117
+        $action .=
2118
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2119
+    }
2120
+    if (!$no_entities) {
2121
+        $action = quote_amp($action);
2122
+    }
2123
+
2124
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2125
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2127 2126
 }
2128 2127
 
2129 2128
 // http://code.spip.net/@generer_url_prive
2130 2129
 function generer_url_prive($script, $args = "", $no_entities = false) {
2131 2130
 
2132
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2131
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2133 2132
 }
2134 2133
 
2135 2134
 // Pour les formulaires en methode POST,
@@ -2154,19 +2153,19 @@  discard block
 block discarded – undo
2154 2153
  **/
2155 2154
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2156 2155
 
2157
-	$script1 = explode('&', $script);
2158
-	$script1 = reset($script1);
2156
+    $script1 = explode('&', $script);
2157
+    $script1 = reset($script1);
2159 2158
 
2160
-	return "<form action='"
2161
-	. ($script ? generer_url_ecrire($script) : '')
2162
-	. "' "
2163
-	. ($atts ? $atts : " method='post'")
2164
-	. "><div>\n"
2165
-	. "<input type='hidden' name='exec' value='$script1' />"
2166
-	. $corps
2167
-	. (!$submit ? '' :
2168
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2169
-	. "</div></form>\n";
2159
+    return "<form action='"
2160
+    . ($script ? generer_url_ecrire($script) : '')
2161
+    . "' "
2162
+    . ($atts ? $atts : " method='post'")
2163
+    . "><div>\n"
2164
+    . "<input type='hidden' name='exec' value='$script1' />"
2165
+    . $corps
2166
+    . (!$submit ? '' :
2167
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2168
+    . "</div></form>\n";
2170 2169
 }
2171 2170
 
2172 2171
 /**
@@ -2183,22 +2182,22 @@  discard block
 block discarded – undo
2183 2182
  * @return string
2184 2183
  */
2185 2184
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2186
-	// si l'on est dans l'espace prive, on garde dans l'url
2187
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2188
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2189
-	$h = (_DIR_RACINE and !$public)
2190
-		? generer_url_ecrire(_request('exec'))
2191
-		: generer_url_public();
2185
+    // si l'on est dans l'espace prive, on garde dans l'url
2186
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2187
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2188
+    $h = (_DIR_RACINE and !$public)
2189
+        ? generer_url_ecrire(_request('exec'))
2190
+        : generer_url_public();
2192 2191
 
2193
-	return "\n<form action='" .
2194
-	$h .
2195
-	"'" .
2196
-	$atts .
2197
-	">\n" .
2198
-	"<div>" .
2199
-	"\n<input type='hidden' name='action' value='$script' />" .
2200
-	$corps .
2201
-	"</div></form>";
2192
+    return "\n<form action='" .
2193
+    $h .
2194
+    "'" .
2195
+    $atts .
2196
+    ">\n" .
2197
+    "<div>" .
2198
+    "\n<input type='hidden' name='action' value='$script' />" .
2199
+    $corps .
2200
+    "</div></form>";
2202 2201
 }
2203 2202
 
2204 2203
 /**
@@ -2217,22 +2216,22 @@  discard block
 block discarded – undo
2217 2216
  *     URL
2218 2217
  */
2219 2218
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2220
-	// si l'on est dans l'espace prive, on garde dans l'url
2221
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2222
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2223
-	$url = (_DIR_RACINE and !$public)
2224
-		? generer_url_ecrire(_request('exec'))
2225
-		: generer_url_public('', '', false, false);
2226
-	$url = parametre_url($url, 'action', $script);
2227
-	if ($args) {
2228
-		$url .= quote_amp('&' . $args);
2229
-	}
2219
+    // si l'on est dans l'espace prive, on garde dans l'url
2220
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2221
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2222
+    $url = (_DIR_RACINE and !$public)
2223
+        ? generer_url_ecrire(_request('exec'))
2224
+        : generer_url_public('', '', false, false);
2225
+    $url = parametre_url($url, 'action', $script);
2226
+    if ($args) {
2227
+        $url .= quote_amp('&' . $args);
2228
+    }
2230 2229
 
2231
-	if ($no_entities) {
2232
-		$url = str_replace('&amp;', '&', $url);
2233
-	}
2230
+    if ($no_entities) {
2231
+        $url = str_replace('&amp;', '&', $url);
2232
+    }
2234 2233
 
2235
-	return $url;
2234
+    return $url;
2236 2235
 }
2237 2236
 
2238 2237
 
@@ -2245,8 +2244,8 @@  discard block
 block discarded – undo
2245 2244
  * @param string $ta Répertoire temporaire accessible
2246 2245
  */
2247 2246
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2248
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2249
-	spip_initialisation_suite();
2247
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2248
+    spip_initialisation_suite();
2250 2249
 }
2251 2250
 
2252 2251
 /**
@@ -2266,315 +2265,315 @@  discard block
 block discarded – undo
2266 2265
  * @param string $ta Répertoire temporaire accessible
2267 2266
  */
2268 2267
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2269
-	static $too_late = 0;
2270
-	if ($too_late++) {
2271
-		return;
2272
-	}
2273
-
2274
-	// Declaration des repertoires
2275
-
2276
-	// le nom du repertoire plugins/ activables/desactivables
2277
-	if (!defined('_DIR_PLUGINS')) {
2278
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2279
-	}
2280
-
2281
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2282
-	if (!defined('_DIR_PLUGINS_DIST')) {
2283
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2284
-	}
2285
-
2286
-	// le nom du repertoire des librairies
2287
-	if (!defined('_DIR_LIB')) {
2288
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2289
-	}
2290
-
2291
-	if (!defined('_DIR_IMG')) {
2292
-		define('_DIR_IMG', $pa);
2293
-	}
2294
-	if (!defined('_DIR_LOGOS')) {
2295
-		define('_DIR_LOGOS', $pa);
2296
-	}
2297
-	if (!defined('_DIR_IMG_ICONES')) {
2298
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2299
-	}
2300
-
2301
-	if (!defined('_DIR_DUMP')) {
2302
-		define('_DIR_DUMP', $ti . "dump/");
2303
-	}
2304
-	if (!defined('_DIR_SESSIONS')) {
2305
-		define('_DIR_SESSIONS', $ti . "sessions/");
2306
-	}
2307
-	if (!defined('_DIR_TRANSFERT')) {
2308
-		define('_DIR_TRANSFERT', $ti . "upload/");
2309
-	}
2310
-	if (!defined('_DIR_CACHE')) {
2311
-		define('_DIR_CACHE', $ti . "cache/");
2312
-	}
2313
-	if (!defined('_DIR_CACHE_XML')) {
2314
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2315
-	}
2316
-	if (!defined('_DIR_SKELS')) {
2317
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2318
-	}
2319
-	if (!defined('_DIR_AIDE')) {
2320
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2321
-	}
2322
-	if (!defined('_DIR_TMP')) {
2323
-		define('_DIR_TMP', $ti);
2324
-	}
2325
-
2326
-	if (!defined('_DIR_VAR')) {
2327
-		define('_DIR_VAR', $ta);
2328
-	}
2329
-
2330
-	if (!defined('_DIR_ETC')) {
2331
-		define('_DIR_ETC', $pi);
2332
-	}
2333
-	if (!defined('_DIR_CONNECT')) {
2334
-		define('_DIR_CONNECT', $pi);
2335
-	}
2336
-	if (!defined('_DIR_CHMOD')) {
2337
-		define('_DIR_CHMOD', $pi);
2338
-	}
2339
-
2340
-	if (!isset($GLOBALS['test_dirs']))
2341
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2342
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2343
-	{
2344
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2345
-	}
2346
-
2347
-	// Declaration des fichiers
2348
-
2349
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2350
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2351
-	}
2352
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2353
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2354
-	}
2355
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2356
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2357
-	}
2358
-	if (!defined('_CACHE_PIPELINES')) {
2359
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2360
-	}
2361
-	if (!defined('_CACHE_CHEMIN')) {
2362
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2363
-	}
2364
-
2365
-	# attention .php obligatoire pour ecrire_fichier_securise
2366
-	if (!defined('_FILE_META')) {
2367
-		define('_FILE_META', $ti . 'meta_cache.php');
2368
-	}
2369
-	if (!defined('_DIR_LOG')) {
2370
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2371
-	}
2372
-	if (!defined('_FILE_LOG')) {
2373
-		define('_FILE_LOG', 'spip');
2374
-	}
2375
-	if (!defined('_FILE_LOG_SUFFIX')) {
2376
-		define('_FILE_LOG_SUFFIX', '.log');
2377
-	}
2378
-
2379
-	// Le fichier de connexion a la base de donnees
2380
-	// tient compte des anciennes versions (inc_connect...)
2381
-	if (!defined('_FILE_CONNECT_INS')) {
2382
-		define('_FILE_CONNECT_INS', 'connect');
2383
-	}
2384
-	if (!defined('_FILE_CONNECT')) {
2385
-		define('_FILE_CONNECT',
2386
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2387
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2388
-				: false)));
2389
-	}
2390
-
2391
-	// Le fichier de reglages des droits
2392
-	if (!defined('_FILE_CHMOD_INS')) {
2393
-		define('_FILE_CHMOD_INS', 'chmod');
2394
-	}
2395
-	if (!defined('_FILE_CHMOD')) {
2396
-		define('_FILE_CHMOD',
2397
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2398
-			: false));
2399
-	}
2400
-
2401
-	if (!defined('_FILE_LDAP')) {
2402
-		define('_FILE_LDAP', 'ldap.php');
2403
-	}
2404
-
2405
-	if (!defined('_FILE_TMP_SUFFIX')) {
2406
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2407
-	}
2408
-	if (!defined('_FILE_CONNECT_TMP')) {
2409
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2410
-	}
2411
-	if (!defined('_FILE_CHMOD_TMP')) {
2412
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2413
-	}
2414
-
2415
-	// Definition des droits d'acces en ecriture
2416
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2417
-		include_once _FILE_CHMOD;
2418
-	}
2419
-
2420
-	// Se mefier des fichiers mal remplis!
2421
-	if (!defined('_SPIP_CHMOD')) {
2422
-		define('_SPIP_CHMOD', 0777);
2423
-	}
2424
-
2425
-	if (!defined('_DEFAULT_CHARSET')) {
2426
-		/** Le charset par défaut lors de l'installation */
2427
-		define('_DEFAULT_CHARSET', 'utf-8');
2428
-	}
2429
-	if (!defined('_ROOT_PLUGINS')) {
2430
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2431
-	}
2432
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2433
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2434
-	}
2435
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2436
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2437
-	}
2438
-
2439
-	// La taille des Log
2440
-	if (!defined('_MAX_LOG')) {
2441
-		define('_MAX_LOG', 100);
2442
-	}
2443
-
2444
-	// Sommes-nous dans l'empire du Mal ?
2445
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2446
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2447
-		if (!defined('_OS_SERVEUR')) {
2448
-			define('_OS_SERVEUR', 'windows');
2449
-		}
2450
-		if (!defined('_SPIP_LOCK_MODE')) {
2451
-			define('_SPIP_LOCK_MODE', 1);
2452
-		} // utiliser le flock php
2453
-	} else {
2454
-		if (!defined('_OS_SERVEUR')) {
2455
-			define('_OS_SERVEUR', '');
2456
-		}
2457
-		if (!defined('_SPIP_LOCK_MODE')) {
2458
-			define('_SPIP_LOCK_MODE', 1);
2459
-		} // utiliser le flock php
2460
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2461
-	}
2462
-
2463
-	// Langue par defaut
2464
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2465
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2466
-	}
2467
-
2468
-	//
2469
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2470
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2471
-	// pour le rendre surchargeable, on va provoquer un reecriture
2472
-	// systematique du noyau ou une baisse de perfs => a etudier)
2473
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2474
-
2475
-	// charger tout de suite le path et son cache
2476
-	load_path_cache();
2477
-
2478
-	// *********** traiter les variables ************
2479
-
2480
-	//
2481
-	// Securite
2482
-	//
2483
-
2484
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2485
-	if (isset($_REQUEST['GLOBALS'])) {
2486
-		die();
2487
-	}
2488
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2489
-	spip_desinfecte($_GET);
2490
-	spip_desinfecte($_POST);
2491
-	spip_desinfecte($_COOKIE);
2492
-	spip_desinfecte($_REQUEST);
2493
-
2494
-	// appliquer le cookie_prefix
2495
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2496
-		include_spip('inc/cookie');
2497
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2498
-	}
2499
-
2500
-	//
2501
-	// Capacites php (en fonction de la version)
2502
-	//
2503
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2504
-		&& function_exists("ini_get")
2505
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2506
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2507
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2508
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2509
-		(get_cfg_var('upload_max_filesize') > 0));
2510
-
2511
-
2512
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2513
-	if (isset($_SERVER['REQUEST_URI'])) {
2514
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2515
-	} else {
2516
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2517
-		if (!empty($_SERVER['QUERY_STRING'])
2518
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2519
-		) {
2520
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2521
-		}
2522
-	}
2523
-
2524
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2525
-	if (!defined('_RENOUVELLE_ALEA')) {
2526
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2527
-	}
2528
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2529
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2530
-	}
2531
-
2532
-	// charger les meta si possible et renouveller l'alea au besoin
2533
-	// charge aussi effacer_meta et ecrire_meta
2534
-	$inc_meta = charger_fonction('meta', 'inc');
2535
-	$inc_meta();
2536
-
2537
-	// nombre de repertoires depuis la racine
2538
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2539
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2540
-	// le calcul est faux)
2541
-	if (!_DIR_RESTREINT) {
2542
-		$GLOBALS['profondeur_url'] = 1;
2543
-	} else {
2544
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2545
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2546
-		if (!$uri_ref
2547
-			// si on est appele avec un autre ti, on est sans doute en mutu
2548
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2549
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2550
-			// s'en remettre a l'adresse du site. alea jacta est.
2551
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2552
-		) {
2553
-
2554
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2555
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2556
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2557
-			} else {
2558
-				$uri_ref = "";
2559
-			}
2560
-		}
2561
-		if (!$uri or !$uri_ref) {
2562
-			$GLOBALS['profondeur_url'] = 0;
2563
-		} else {
2564
-			$GLOBALS['profondeur_url'] = max(0,
2565
-				substr_count($uri[0], '/')
2566
-				- substr_count($uri_ref, '/'));
2567
-		}
2568
-	}
2569
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2570
-	if (_FILE_CONNECT) {
2571
-		if (verifier_visiteur() == '0minirezo'
2572
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2573
-			and !isset($_COOKIE['spip_admin'])
2574
-		) {
2575
-			clear_path_cache();
2576
-		}
2577
-	}
2268
+    static $too_late = 0;
2269
+    if ($too_late++) {
2270
+        return;
2271
+    }
2272
+
2273
+    // Declaration des repertoires
2274
+
2275
+    // le nom du repertoire plugins/ activables/desactivables
2276
+    if (!defined('_DIR_PLUGINS')) {
2277
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2278
+    }
2279
+
2280
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2281
+    if (!defined('_DIR_PLUGINS_DIST')) {
2282
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2283
+    }
2284
+
2285
+    // le nom du repertoire des librairies
2286
+    if (!defined('_DIR_LIB')) {
2287
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2288
+    }
2289
+
2290
+    if (!defined('_DIR_IMG')) {
2291
+        define('_DIR_IMG', $pa);
2292
+    }
2293
+    if (!defined('_DIR_LOGOS')) {
2294
+        define('_DIR_LOGOS', $pa);
2295
+    }
2296
+    if (!defined('_DIR_IMG_ICONES')) {
2297
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2298
+    }
2299
+
2300
+    if (!defined('_DIR_DUMP')) {
2301
+        define('_DIR_DUMP', $ti . "dump/");
2302
+    }
2303
+    if (!defined('_DIR_SESSIONS')) {
2304
+        define('_DIR_SESSIONS', $ti . "sessions/");
2305
+    }
2306
+    if (!defined('_DIR_TRANSFERT')) {
2307
+        define('_DIR_TRANSFERT', $ti . "upload/");
2308
+    }
2309
+    if (!defined('_DIR_CACHE')) {
2310
+        define('_DIR_CACHE', $ti . "cache/");
2311
+    }
2312
+    if (!defined('_DIR_CACHE_XML')) {
2313
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2314
+    }
2315
+    if (!defined('_DIR_SKELS')) {
2316
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2317
+    }
2318
+    if (!defined('_DIR_AIDE')) {
2319
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2320
+    }
2321
+    if (!defined('_DIR_TMP')) {
2322
+        define('_DIR_TMP', $ti);
2323
+    }
2324
+
2325
+    if (!defined('_DIR_VAR')) {
2326
+        define('_DIR_VAR', $ta);
2327
+    }
2328
+
2329
+    if (!defined('_DIR_ETC')) {
2330
+        define('_DIR_ETC', $pi);
2331
+    }
2332
+    if (!defined('_DIR_CONNECT')) {
2333
+        define('_DIR_CONNECT', $pi);
2334
+    }
2335
+    if (!defined('_DIR_CHMOD')) {
2336
+        define('_DIR_CHMOD', $pi);
2337
+    }
2338
+
2339
+    if (!isset($GLOBALS['test_dirs']))
2340
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2341
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2342
+    {
2343
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2344
+    }
2345
+
2346
+    // Declaration des fichiers
2347
+
2348
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2349
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2350
+    }
2351
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2352
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2353
+    }
2354
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2355
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2356
+    }
2357
+    if (!defined('_CACHE_PIPELINES')) {
2358
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2359
+    }
2360
+    if (!defined('_CACHE_CHEMIN')) {
2361
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2362
+    }
2363
+
2364
+    # attention .php obligatoire pour ecrire_fichier_securise
2365
+    if (!defined('_FILE_META')) {
2366
+        define('_FILE_META', $ti . 'meta_cache.php');
2367
+    }
2368
+    if (!defined('_DIR_LOG')) {
2369
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2370
+    }
2371
+    if (!defined('_FILE_LOG')) {
2372
+        define('_FILE_LOG', 'spip');
2373
+    }
2374
+    if (!defined('_FILE_LOG_SUFFIX')) {
2375
+        define('_FILE_LOG_SUFFIX', '.log');
2376
+    }
2377
+
2378
+    // Le fichier de connexion a la base de donnees
2379
+    // tient compte des anciennes versions (inc_connect...)
2380
+    if (!defined('_FILE_CONNECT_INS')) {
2381
+        define('_FILE_CONNECT_INS', 'connect');
2382
+    }
2383
+    if (!defined('_FILE_CONNECT')) {
2384
+        define('_FILE_CONNECT',
2385
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2386
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2387
+                : false)));
2388
+    }
2389
+
2390
+    // Le fichier de reglages des droits
2391
+    if (!defined('_FILE_CHMOD_INS')) {
2392
+        define('_FILE_CHMOD_INS', 'chmod');
2393
+    }
2394
+    if (!defined('_FILE_CHMOD')) {
2395
+        define('_FILE_CHMOD',
2396
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2397
+            : false));
2398
+    }
2399
+
2400
+    if (!defined('_FILE_LDAP')) {
2401
+        define('_FILE_LDAP', 'ldap.php');
2402
+    }
2403
+
2404
+    if (!defined('_FILE_TMP_SUFFIX')) {
2405
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2406
+    }
2407
+    if (!defined('_FILE_CONNECT_TMP')) {
2408
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2409
+    }
2410
+    if (!defined('_FILE_CHMOD_TMP')) {
2411
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2412
+    }
2413
+
2414
+    // Definition des droits d'acces en ecriture
2415
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2416
+        include_once _FILE_CHMOD;
2417
+    }
2418
+
2419
+    // Se mefier des fichiers mal remplis!
2420
+    if (!defined('_SPIP_CHMOD')) {
2421
+        define('_SPIP_CHMOD', 0777);
2422
+    }
2423
+
2424
+    if (!defined('_DEFAULT_CHARSET')) {
2425
+        /** Le charset par défaut lors de l'installation */
2426
+        define('_DEFAULT_CHARSET', 'utf-8');
2427
+    }
2428
+    if (!defined('_ROOT_PLUGINS')) {
2429
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2430
+    }
2431
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2432
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2433
+    }
2434
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2435
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2436
+    }
2437
+
2438
+    // La taille des Log
2439
+    if (!defined('_MAX_LOG')) {
2440
+        define('_MAX_LOG', 100);
2441
+    }
2442
+
2443
+    // Sommes-nous dans l'empire du Mal ?
2444
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2445
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2446
+        if (!defined('_OS_SERVEUR')) {
2447
+            define('_OS_SERVEUR', 'windows');
2448
+        }
2449
+        if (!defined('_SPIP_LOCK_MODE')) {
2450
+            define('_SPIP_LOCK_MODE', 1);
2451
+        } // utiliser le flock php
2452
+    } else {
2453
+        if (!defined('_OS_SERVEUR')) {
2454
+            define('_OS_SERVEUR', '');
2455
+        }
2456
+        if (!defined('_SPIP_LOCK_MODE')) {
2457
+            define('_SPIP_LOCK_MODE', 1);
2458
+        } // utiliser le flock php
2459
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2460
+    }
2461
+
2462
+    // Langue par defaut
2463
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2464
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2465
+    }
2466
+
2467
+    //
2468
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2469
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2470
+    // pour le rendre surchargeable, on va provoquer un reecriture
2471
+    // systematique du noyau ou une baisse de perfs => a etudier)
2472
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2473
+
2474
+    // charger tout de suite le path et son cache
2475
+    load_path_cache();
2476
+
2477
+    // *********** traiter les variables ************
2478
+
2479
+    //
2480
+    // Securite
2481
+    //
2482
+
2483
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2484
+    if (isset($_REQUEST['GLOBALS'])) {
2485
+        die();
2486
+    }
2487
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2488
+    spip_desinfecte($_GET);
2489
+    spip_desinfecte($_POST);
2490
+    spip_desinfecte($_COOKIE);
2491
+    spip_desinfecte($_REQUEST);
2492
+
2493
+    // appliquer le cookie_prefix
2494
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2495
+        include_spip('inc/cookie');
2496
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2497
+    }
2498
+
2499
+    //
2500
+    // Capacites php (en fonction de la version)
2501
+    //
2502
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2503
+        && function_exists("ini_get")
2504
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2505
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2506
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2507
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2508
+        (get_cfg_var('upload_max_filesize') > 0));
2509
+
2510
+
2511
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2512
+    if (isset($_SERVER['REQUEST_URI'])) {
2513
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2514
+    } else {
2515
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2516
+        if (!empty($_SERVER['QUERY_STRING'])
2517
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2518
+        ) {
2519
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2520
+        }
2521
+    }
2522
+
2523
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2524
+    if (!defined('_RENOUVELLE_ALEA')) {
2525
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2526
+    }
2527
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2528
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2529
+    }
2530
+
2531
+    // charger les meta si possible et renouveller l'alea au besoin
2532
+    // charge aussi effacer_meta et ecrire_meta
2533
+    $inc_meta = charger_fonction('meta', 'inc');
2534
+    $inc_meta();
2535
+
2536
+    // nombre de repertoires depuis la racine
2537
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2538
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2539
+    // le calcul est faux)
2540
+    if (!_DIR_RESTREINT) {
2541
+        $GLOBALS['profondeur_url'] = 1;
2542
+    } else {
2543
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2544
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2545
+        if (!$uri_ref
2546
+            // si on est appele avec un autre ti, on est sans doute en mutu
2547
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2548
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2549
+            // s'en remettre a l'adresse du site. alea jacta est.
2550
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2551
+        ) {
2552
+
2553
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2554
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2555
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2556
+            } else {
2557
+                $uri_ref = "";
2558
+            }
2559
+        }
2560
+        if (!$uri or !$uri_ref) {
2561
+            $GLOBALS['profondeur_url'] = 0;
2562
+        } else {
2563
+            $GLOBALS['profondeur_url'] = max(0,
2564
+                substr_count($uri[0], '/')
2565
+                - substr_count($uri_ref, '/'));
2566
+        }
2567
+    }
2568
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2569
+    if (_FILE_CONNECT) {
2570
+        if (verifier_visiteur() == '0minirezo'
2571
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2572
+            and !isset($_COOKIE['spip_admin'])
2573
+        ) {
2574
+            clear_path_cache();
2575
+        }
2576
+    }
2578 2577
 
2579 2578
 }
2580 2579
 
@@ -2584,174 +2583,174 @@  discard block
 block discarded – undo
2584 2583
  *
2585 2584
  */
2586 2585
 function spip_initialisation_suite() {
2587
-	static $too_late = 0;
2588
-	if ($too_late++) {
2589
-		return;
2590
-	}
2591
-
2592
-	// taille mini des login
2593
-	if (!defined('_LOGIN_TROP_COURT')) {
2594
-		define('_LOGIN_TROP_COURT', 4);
2595
-	}
2596
-
2597
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2598
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2599
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2600
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2601
-
2602
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2603
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2604
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2605
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2606
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2607
-
2608
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2609
-		define('_PASS_LONGUEUR_MINI', 6);
2610
-	}
2611
-
2612
-
2613
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2614
-	if (!defined('_IMG_QUALITE')) {
2615
-		define('_IMG_QUALITE', 85);
2616
-	} # valeur par defaut
2617
-	if (!defined('_IMG_GD_QUALITE')) {
2618
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2619
-	} # surcharge pour la lib GD
2620
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2621
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2622
-	} # surcharge pour imagick en ligne de commande
2623
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2624
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2625
-		define('_IMG_IMAGICK_QUALITE', 75);
2626
-	} # surcharge pour imagick en PHP
2627
-
2628
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2629
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2630
-	} // poids en octet
2631
-
2632
-	// qq chaines standard
2633
-	if (!defined('_ACCESS_FILE_NAME')) {
2634
-		define('_ACCESS_FILE_NAME', '.htaccess');
2635
-	}
2636
-	if (!defined('_AUTH_USER_FILE')) {
2637
-		define('_AUTH_USER_FILE', '.htpasswd');
2638
-	}
2639
-	if (!defined('_SPIP_DUMP')) {
2640
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2641
-	}
2642
-	if (!defined('_CACHE_RUBRIQUES')) {
2643
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2644
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2645
-	}
2646
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2647
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2648
-		define('_CACHE_RUBRIQUES_MAX', 500);
2649
-	}
2650
-
2651
-	if (!defined('_EXTENSION_SQUELETTES')) {
2652
-		define('_EXTENSION_SQUELETTES', 'html');
2653
-	}
2654
-
2655
-	if (!defined('_DOCTYPE_ECRIRE')) {
2656
-		/** Définit le doctype de l’espace privé */
2657
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2658
-	}
2659
-	if (!defined('_DOCTYPE_AIDE')) {
2660
-		/** Définit le doctype de l’aide en ligne */
2661
-		define('_DOCTYPE_AIDE',
2662
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2663
-	}
2664
-
2665
-	if (!defined('_SPIP_SCRIPT')) {
2666
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2667
-		 * le script de l'espace public, alias index.php */
2668
-		define('_SPIP_SCRIPT', 'spip.php');
2669
-	}
2670
-	if (!defined('_SPIP_PAGE')) {
2671
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2672
-		define('_SPIP_PAGE', 'page');
2673
-	}
2674
-
2675
-	// le script de l'espace prive
2676
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2677
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2678
-	// meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2679
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2680
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2681
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2682
-		} else {
2683
-			define('_SPIP_ECRIRE_SCRIPT', '');
2684
-		}
2685
-	}
2686
-
2687
-
2688
-	if (!defined('_SPIP_AJAX')) {
2689
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2690
-			? 1
2691
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2692
-	}
2693
-
2694
-	// La requete est-elle en ajax ?
2695
-	if (!defined('_AJAX')) {
2696
-		define('_AJAX',
2697
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2698
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2699
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2700
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2701
-			)
2702
-			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
2703
-		);
2704
-	}
2705
-
2706
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2707
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2708
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2709
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2710
-		define('_IMG_GD_MAX_PIXELS',
2711
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2712
-			? $GLOBALS['meta']['max_taille_vignettes']
2713
-			: 0);
2714
-	}
2715
-
2716
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2717
-		define('_MEMORY_LIMIT_MIN', 16);
2718
-	} // en Mo
2719
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2720
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2721
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2722
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2723
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2724
-			$unit = strtolower(substr($memory, -1));
2725
-			$memory = substr($memory, 0, -1);
2726
-			switch ($unit) {
2727
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2728
-				case 'g':
2729
-					$memory *= 1024;
2730
-				case 'm':
2731
-					$memory *= 1024;
2732
-				case 'k':
2733
-					$memory *= 1024;
2734
-			}
2735
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2736
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2737
-				if (trim(ini_get('memory_limit')) != $m) {
2738
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2739
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2740
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2741
-				}
2742
-			}
2743
-		} else {
2744
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2745
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2746
-			}
2747
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2748
-	}
2749
-	// Protocoles a normaliser dans les chaines de langues
2750
-	if (!defined('_PROTOCOLES_STD')) {
2751
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2752
-	}
2753
-
2754
-	init_var_mode();
2586
+    static $too_late = 0;
2587
+    if ($too_late++) {
2588
+        return;
2589
+    }
2590
+
2591
+    // taille mini des login
2592
+    if (!defined('_LOGIN_TROP_COURT')) {
2593
+        define('_LOGIN_TROP_COURT', 4);
2594
+    }
2595
+
2596
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2597
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2598
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2599
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2600
+
2601
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2602
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2603
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2604
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2605
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2606
+
2607
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2608
+        define('_PASS_LONGUEUR_MINI', 6);
2609
+    }
2610
+
2611
+
2612
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2613
+    if (!defined('_IMG_QUALITE')) {
2614
+        define('_IMG_QUALITE', 85);
2615
+    } # valeur par defaut
2616
+    if (!defined('_IMG_GD_QUALITE')) {
2617
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2618
+    } # surcharge pour la lib GD
2619
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2620
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2621
+    } # surcharge pour imagick en ligne de commande
2622
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2623
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2624
+        define('_IMG_IMAGICK_QUALITE', 75);
2625
+    } # surcharge pour imagick en PHP
2626
+
2627
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2628
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2629
+    } // poids en octet
2630
+
2631
+    // qq chaines standard
2632
+    if (!defined('_ACCESS_FILE_NAME')) {
2633
+        define('_ACCESS_FILE_NAME', '.htaccess');
2634
+    }
2635
+    if (!defined('_AUTH_USER_FILE')) {
2636
+        define('_AUTH_USER_FILE', '.htpasswd');
2637
+    }
2638
+    if (!defined('_SPIP_DUMP')) {
2639
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2640
+    }
2641
+    if (!defined('_CACHE_RUBRIQUES')) {
2642
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2643
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2644
+    }
2645
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2646
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2647
+        define('_CACHE_RUBRIQUES_MAX', 500);
2648
+    }
2649
+
2650
+    if (!defined('_EXTENSION_SQUELETTES')) {
2651
+        define('_EXTENSION_SQUELETTES', 'html');
2652
+    }
2653
+
2654
+    if (!defined('_DOCTYPE_ECRIRE')) {
2655
+        /** Définit le doctype de l’espace privé */
2656
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2657
+    }
2658
+    if (!defined('_DOCTYPE_AIDE')) {
2659
+        /** Définit le doctype de l’aide en ligne */
2660
+        define('_DOCTYPE_AIDE',
2661
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2662
+    }
2663
+
2664
+    if (!defined('_SPIP_SCRIPT')) {
2665
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2666
+         * le script de l'espace public, alias index.php */
2667
+        define('_SPIP_SCRIPT', 'spip.php');
2668
+    }
2669
+    if (!defined('_SPIP_PAGE')) {
2670
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2671
+        define('_SPIP_PAGE', 'page');
2672
+    }
2673
+
2674
+    // le script de l'espace prive
2675
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2676
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2677
+    // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2678
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2679
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2680
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2681
+        } else {
2682
+            define('_SPIP_ECRIRE_SCRIPT', '');
2683
+        }
2684
+    }
2685
+
2686
+
2687
+    if (!defined('_SPIP_AJAX')) {
2688
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2689
+            ? 1
2690
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2691
+    }
2692
+
2693
+    // La requete est-elle en ajax ?
2694
+    if (!defined('_AJAX')) {
2695
+        define('_AJAX',
2696
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2697
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2698
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2699
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2700
+            )
2701
+            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
2702
+        );
2703
+    }
2704
+
2705
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2706
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2707
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2708
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2709
+        define('_IMG_GD_MAX_PIXELS',
2710
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2711
+            ? $GLOBALS['meta']['max_taille_vignettes']
2712
+            : 0);
2713
+    }
2714
+
2715
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2716
+        define('_MEMORY_LIMIT_MIN', 16);
2717
+    } // en Mo
2718
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2719
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2720
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2721
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2722
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2723
+            $unit = strtolower(substr($memory, -1));
2724
+            $memory = substr($memory, 0, -1);
2725
+            switch ($unit) {
2726
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2727
+                case 'g':
2728
+                    $memory *= 1024;
2729
+                case 'm':
2730
+                    $memory *= 1024;
2731
+                case 'k':
2732
+                    $memory *= 1024;
2733
+            }
2734
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2735
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2736
+                if (trim(ini_get('memory_limit')) != $m) {
2737
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2738
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2739
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2740
+                }
2741
+            }
2742
+        } else {
2743
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2744
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2745
+            }
2746
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2747
+    }
2748
+    // Protocoles a normaliser dans les chaines de langues
2749
+    if (!defined('_PROTOCOLES_STD')) {
2750
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2751
+    }
2752
+
2753
+    init_var_mode();
2755 2754
 }
2756 2755
 
2757 2756
 /**
@@ -2785,129 +2784,129 @@  discard block
 block discarded – undo
2785 2784
  * `   var_mode` (calcul ou recalcul).
2786 2785
  */
2787 2786
 function init_var_mode() {
2788
-	static $done = false;
2789
-	if (!$done) {
2790
-
2791
-		if (isset($_GET['var_mode'])) {
2792
-			$var_mode = explode(',', $_GET['var_mode']);
2793
-			// tout le monde peut calcul/recalcul
2794
-			if (!defined('_VAR_MODE')) {
2795
-				if (in_array('recalcul', $var_mode)) {
2796
-					define('_VAR_MODE', 'recalcul');
2797
-				} elseif (in_array('calcul', $var_mode)) {
2798
-					define('_VAR_MODE', 'calcul');
2799
-				}
2800
-			}
2801
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2802
-			if ($var_mode) {
2803
-				include_spip('inc/autoriser');
2804
-				// autoriser preview si preview seulement, et sinon autoriser debug
2805
-				if (autoriser(
2806
-					($_GET['var_mode'] == 'preview')
2807
-						? 'previsualiser'
2808
-						: 'debug'
2809
-				)) {
2810
-					if (in_array('traduction', $var_mode)) {
2811
-						// forcer le calcul pour passer dans traduire
2812
-						if (!defined('_VAR_MODE')) {
2813
-							define('_VAR_MODE', 'calcul');
2814
-						}
2815
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2816
-						if (!defined('_VAR_NOCACHE')) {
2817
-							define('_VAR_NOCACHE', true);
2818
-						}
2819
-						$var_mode = array_diff($var_mode, array('traduction'));
2820
-					}
2821
-					if (in_array('preview', $var_mode)) {
2822
-						// basculer sur les criteres de preview dans les boucles
2823
-						if (!defined('_VAR_PREVIEW')) {
2824
-							define('_VAR_PREVIEW', true);
2825
-						}
2826
-						// forcer le calcul
2827
-						if (!defined('_VAR_MODE')) {
2828
-							define('_VAR_MODE', 'calcul');
2829
-						}
2830
-						// et ne pas enregistrer de cache
2831
-						if (!defined('_VAR_NOCACHE')) {
2832
-							define('_VAR_NOCACHE', true);
2833
-						}
2834
-						$var_mode = array_diff($var_mode, array('preview'));
2835
-					}
2836
-					if (in_array('inclure', $var_mode)) {
2837
-						// forcer le compilo et ignorer les caches existants
2838
-						if (!defined('_VAR_MODE')) {
2839
-							define('_VAR_MODE', 'calcul');
2840
-						}
2841
-						if (!defined('_VAR_INCLURE')) {
2842
-							define('_VAR_INCLURE', true);
2843
-						}
2844
-						// et ne pas enregistrer de cache
2845
-						if (!defined('_VAR_NOCACHE')) {
2846
-							define('_VAR_NOCACHE', true);
2847
-						}
2848
-						$var_mode = array_diff($var_mode, array('inclure'));
2849
-					}
2850
-					if (in_array('urls', $var_mode)) {
2851
-						// forcer le compilo et ignorer les caches existants
2852
-						if (!defined('_VAR_MODE')) {
2853
-							define('_VAR_MODE', 'calcul');
2854
-						}
2855
-						if (!defined('_VAR_URLS')) {
2856
-							define('_VAR_URLS', true);
2857
-						}
2858
-						$var_mode = array_diff($var_mode, array('urls'));
2859
-					}
2860
-					if (in_array('images', $var_mode)) {
2861
-						// forcer le compilo et ignorer les caches existants
2862
-						if (!defined('_VAR_MODE')) {
2863
-							define('_VAR_MODE', 'calcul');
2864
-						}
2865
-						// indiquer qu'on doit recalculer les images
2866
-						if (!defined('_VAR_IMAGES')) {
2867
-							define('_VAR_IMAGES', true);
2868
-						}
2869
-						$var_mode = array_diff($var_mode, array('images'));
2870
-					}
2871
-					if (in_array('debug', $var_mode)) {
2872
-						if (!defined('_VAR_MODE')) {
2873
-							define('_VAR_MODE', 'debug');
2874
-						}
2875
-						// et ne pas enregistrer de cache
2876
-						if (!defined('_VAR_NOCACHE')) {
2877
-							define('_VAR_NOCACHE', true);
2878
-						}
2879
-						$var_mode = array_diff($var_mode, array('debug'));
2880
-					}
2881
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2882
-						define('_VAR_MODE', reset($var_mode));
2883
-					}
2884
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2885
-						spip_log($GLOBALS['visiteur_session']['nom']
2886
-							. " " . _VAR_MODE);
2887
-					}
2888
-				} // pas autorise ?
2889
-				else {
2890
-					// si on n'est pas connecte on se redirige
2891
-					if (!$GLOBALS['visiteur_session']) {
2892
-						include_spip('inc/headers');
2893
-						redirige_par_entete(generer_url_public('login',
2894
-							'url=' . rawurlencode(
2895
-								parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2896
-							), true));
2897
-					}
2898
-					// sinon tant pis
2899
-				}
2900
-			}
2901
-		}
2902
-		if (!defined('_VAR_MODE')) {
2903
-			/**
2904
-			 * Indique le mode de calcul ou d'affichage de la page.
2905
-			 * @see init_var_mode()
2906
-			 */
2907
-			define('_VAR_MODE', false);
2908
-		}
2909
-		$done = true;
2910
-	}
2787
+    static $done = false;
2788
+    if (!$done) {
2789
+
2790
+        if (isset($_GET['var_mode'])) {
2791
+            $var_mode = explode(',', $_GET['var_mode']);
2792
+            // tout le monde peut calcul/recalcul
2793
+            if (!defined('_VAR_MODE')) {
2794
+                if (in_array('recalcul', $var_mode)) {
2795
+                    define('_VAR_MODE', 'recalcul');
2796
+                } elseif (in_array('calcul', $var_mode)) {
2797
+                    define('_VAR_MODE', 'calcul');
2798
+                }
2799
+            }
2800
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2801
+            if ($var_mode) {
2802
+                include_spip('inc/autoriser');
2803
+                // autoriser preview si preview seulement, et sinon autoriser debug
2804
+                if (autoriser(
2805
+                    ($_GET['var_mode'] == 'preview')
2806
+                        ? 'previsualiser'
2807
+                        : 'debug'
2808
+                )) {
2809
+                    if (in_array('traduction', $var_mode)) {
2810
+                        // forcer le calcul pour passer dans traduire
2811
+                        if (!defined('_VAR_MODE')) {
2812
+                            define('_VAR_MODE', 'calcul');
2813
+                        }
2814
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2815
+                        if (!defined('_VAR_NOCACHE')) {
2816
+                            define('_VAR_NOCACHE', true);
2817
+                        }
2818
+                        $var_mode = array_diff($var_mode, array('traduction'));
2819
+                    }
2820
+                    if (in_array('preview', $var_mode)) {
2821
+                        // basculer sur les criteres de preview dans les boucles
2822
+                        if (!defined('_VAR_PREVIEW')) {
2823
+                            define('_VAR_PREVIEW', true);
2824
+                        }
2825
+                        // forcer le calcul
2826
+                        if (!defined('_VAR_MODE')) {
2827
+                            define('_VAR_MODE', 'calcul');
2828
+                        }
2829
+                        // et ne pas enregistrer de cache
2830
+                        if (!defined('_VAR_NOCACHE')) {
2831
+                            define('_VAR_NOCACHE', true);
2832
+                        }
2833
+                        $var_mode = array_diff($var_mode, array('preview'));
2834
+                    }
2835
+                    if (in_array('inclure', $var_mode)) {
2836
+                        // forcer le compilo et ignorer les caches existants
2837
+                        if (!defined('_VAR_MODE')) {
2838
+                            define('_VAR_MODE', 'calcul');
2839
+                        }
2840
+                        if (!defined('_VAR_INCLURE')) {
2841
+                            define('_VAR_INCLURE', true);
2842
+                        }
2843
+                        // et ne pas enregistrer de cache
2844
+                        if (!defined('_VAR_NOCACHE')) {
2845
+                            define('_VAR_NOCACHE', true);
2846
+                        }
2847
+                        $var_mode = array_diff($var_mode, array('inclure'));
2848
+                    }
2849
+                    if (in_array('urls', $var_mode)) {
2850
+                        // forcer le compilo et ignorer les caches existants
2851
+                        if (!defined('_VAR_MODE')) {
2852
+                            define('_VAR_MODE', 'calcul');
2853
+                        }
2854
+                        if (!defined('_VAR_URLS')) {
2855
+                            define('_VAR_URLS', true);
2856
+                        }
2857
+                        $var_mode = array_diff($var_mode, array('urls'));
2858
+                    }
2859
+                    if (in_array('images', $var_mode)) {
2860
+                        // forcer le compilo et ignorer les caches existants
2861
+                        if (!defined('_VAR_MODE')) {
2862
+                            define('_VAR_MODE', 'calcul');
2863
+                        }
2864
+                        // indiquer qu'on doit recalculer les images
2865
+                        if (!defined('_VAR_IMAGES')) {
2866
+                            define('_VAR_IMAGES', true);
2867
+                        }
2868
+                        $var_mode = array_diff($var_mode, array('images'));
2869
+                    }
2870
+                    if (in_array('debug', $var_mode)) {
2871
+                        if (!defined('_VAR_MODE')) {
2872
+                            define('_VAR_MODE', 'debug');
2873
+                        }
2874
+                        // et ne pas enregistrer de cache
2875
+                        if (!defined('_VAR_NOCACHE')) {
2876
+                            define('_VAR_NOCACHE', true);
2877
+                        }
2878
+                        $var_mode = array_diff($var_mode, array('debug'));
2879
+                    }
2880
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2881
+                        define('_VAR_MODE', reset($var_mode));
2882
+                    }
2883
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2884
+                        spip_log($GLOBALS['visiteur_session']['nom']
2885
+                            . " " . _VAR_MODE);
2886
+                    }
2887
+                } // pas autorise ?
2888
+                else {
2889
+                    // si on n'est pas connecte on se redirige
2890
+                    if (!$GLOBALS['visiteur_session']) {
2891
+                        include_spip('inc/headers');
2892
+                        redirige_par_entete(generer_url_public('login',
2893
+                            'url=' . rawurlencode(
2894
+                                parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2895
+                            ), true));
2896
+                    }
2897
+                    // sinon tant pis
2898
+                }
2899
+            }
2900
+        }
2901
+        if (!defined('_VAR_MODE')) {
2902
+            /**
2903
+             * Indique le mode de calcul ou d'affichage de la page.
2904
+             * @see init_var_mode()
2905
+             */
2906
+            define('_VAR_MODE', false);
2907
+        }
2908
+        $done = true;
2909
+    }
2911 2910
 }
2912 2911
 
2913 2912
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2915,93 +2914,93 @@  discard block
 block discarded – undo
2915 2914
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2916 2915
 // http://code.spip.net/@spip_desinfecte
2917 2916
 function spip_desinfecte(&$t, $deep = true) {
2918
-	static $magic_quotes;
2919
-	if (!isset($magic_quotes)) {
2920
-		$magic_quotes = @get_magic_quotes_gpc();
2921
-	}
2922
-
2923
-	foreach ($t as $key => $val) {
2924
-		if (is_string($t[$key])) {
2925
-			if ($magic_quotes) {
2926
-				$t[$key] = stripslashes($t[$key]);
2927
-			}
2928
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2929
-		} // traiter aussi les "texte_plus" de article_edit
2930
-		else {
2931
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2932
-				spip_desinfecte($t[$key], $deep);
2933
-			}
2934
-		}
2935
-	}
2917
+    static $magic_quotes;
2918
+    if (!isset($magic_quotes)) {
2919
+        $magic_quotes = @get_magic_quotes_gpc();
2920
+    }
2921
+
2922
+    foreach ($t as $key => $val) {
2923
+        if (is_string($t[$key])) {
2924
+            if ($magic_quotes) {
2925
+                $t[$key] = stripslashes($t[$key]);
2926
+            }
2927
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2928
+        } // traiter aussi les "texte_plus" de article_edit
2929
+        else {
2930
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2931
+                spip_desinfecte($t[$key], $deep);
2932
+            }
2933
+        }
2934
+    }
2936 2935
 }
2937 2936
 
2938 2937
 //  retourne le statut du visiteur s'il s'annonce
2939 2938
 
2940 2939
 // http://code.spip.net/@verifier_visiteur
2941 2940
 function verifier_visiteur() {
2942
-	// Rq: pour que cette fonction marche depuis mes_options
2943
-	// il faut forcer l'init si ce n'est fait
2944
-	// mais on risque de perturber des plugins en initialisant trop tot
2945
-	// certaines constantes
2946
-	@spip_initialisation_core(
2947
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2948
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2949
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2950
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2951
-	);
2952
-
2953
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
2954
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2955
-	// Attention on separe bien session_nom et nom, pour eviter
2956
-	// les melanges entre donnees SQL et variables plus aleatoires
2957
-	$variables_session = array('session_nom', 'session_email');
2958
-	foreach ($variables_session as $var) {
2959
-		if (_request($var) !== null) {
2960
-			$init = true;
2961
-			break;
2962
-		}
2963
-	}
2964
-	if (isset($init)) {
2965
-		#@spip_initialisation_suite();
2966
-		$session = charger_fonction('session', 'inc');
2967
-		$session();
2968
-		include_spip('inc/texte');
2969
-		foreach ($variables_session as $var) {
2970
-			if (($a = _request($var)) !== null) {
2971
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2972
-			}
2973
-		}
2974
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2975
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2976
-		}
2977
-		$session($GLOBALS['visiteur_session']);
2978
-
2979
-		return 0;
2980
-	}
2981
-
2982
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2983
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2984
-
2985
-		$session = charger_fonction('session', 'inc');
2986
-		if ($session()) {
2987
-			return $GLOBALS['visiteur_session']['statut'];
2988
-		}
2989
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2990
-			include_spip('inc/auth');
2991
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2992
-		}
2993
-		if ($h) {
2994
-			$GLOBALS['visiteur_session'] = $h;
2995
-
2996
-			return $GLOBALS['visiteur_session']['statut'];
2997
-		}
2998
-	}
2999
-
3000
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3001
-	include_spip('inc/lang');
3002
-	utiliser_langue_visiteur();
3003
-
3004
-	return false;
2941
+    // Rq: pour que cette fonction marche depuis mes_options
2942
+    // il faut forcer l'init si ce n'est fait
2943
+    // mais on risque de perturber des plugins en initialisant trop tot
2944
+    // certaines constantes
2945
+    @spip_initialisation_core(
2946
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2947
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2948
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2949
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2950
+    );
2951
+
2952
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
2953
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2954
+    // Attention on separe bien session_nom et nom, pour eviter
2955
+    // les melanges entre donnees SQL et variables plus aleatoires
2956
+    $variables_session = array('session_nom', 'session_email');
2957
+    foreach ($variables_session as $var) {
2958
+        if (_request($var) !== null) {
2959
+            $init = true;
2960
+            break;
2961
+        }
2962
+    }
2963
+    if (isset($init)) {
2964
+        #@spip_initialisation_suite();
2965
+        $session = charger_fonction('session', 'inc');
2966
+        $session();
2967
+        include_spip('inc/texte');
2968
+        foreach ($variables_session as $var) {
2969
+            if (($a = _request($var)) !== null) {
2970
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2971
+            }
2972
+        }
2973
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2974
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2975
+        }
2976
+        $session($GLOBALS['visiteur_session']);
2977
+
2978
+        return 0;
2979
+    }
2980
+
2981
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2982
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2983
+
2984
+        $session = charger_fonction('session', 'inc');
2985
+        if ($session()) {
2986
+            return $GLOBALS['visiteur_session']['statut'];
2987
+        }
2988
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2989
+            include_spip('inc/auth');
2990
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2991
+        }
2992
+        if ($h) {
2993
+            $GLOBALS['visiteur_session'] = $h;
2994
+
2995
+            return $GLOBALS['visiteur_session']['statut'];
2996
+        }
2997
+    }
2998
+
2999
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3000
+    include_spip('inc/lang');
3001
+    utiliser_langue_visiteur();
3002
+
3003
+    return false;
3005 3004
 }
3006 3005
 
3007 3006
 
@@ -3024,21 +3023,21 @@  discard block
 block discarded – undo
3024 3023
  *     - string Langue utilisée.
3025 3024
  **/
3026 3025
 function lang_select($lang = null) {
3027
-	static $pile_langues = array();
3028
-	if (!function_exists('changer_langue')) {
3029
-		include_spip('inc/lang');
3030
-	}
3031
-	if ($lang === null) {
3032
-		$lang = array_pop($pile_langues);
3033
-	} else {
3034
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3035
-	}
3036
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3037
-		return $lang;
3038
-	}
3039
-	changer_langue($lang);
3026
+    static $pile_langues = array();
3027
+    if (!function_exists('changer_langue')) {
3028
+        include_spip('inc/lang');
3029
+    }
3030
+    if ($lang === null) {
3031
+        $lang = array_pop($pile_langues);
3032
+    } else {
3033
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3034
+    }
3035
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3036
+        return $lang;
3037
+    }
3038
+    changer_langue($lang);
3040 3039
 
3041
-	return $lang;
3040
+    return $lang;
3042 3041
 }
3043 3042
 
3044 3043
 /**
@@ -3055,19 +3054,19 @@  discard block
 block discarded – undo
3055 3054
  *     Identifiant de la session
3056 3055
  **/
3057 3056
 function spip_session($force = false) {
3058
-	static $session;
3059
-	if ($force or !isset($session)) {
3060
-		$s = pipeline('definir_session',
3061
-			$GLOBALS['visiteur_session']
3062
-				? serialize($GLOBALS['visiteur_session'])
3063
-				. '_' . @$_COOKIE['spip_session']
3064
-				: ''
3065
-		);
3066
-		$session = $s ? substr(md5($s), 0, 8) : '';
3067
-	}
3057
+    static $session;
3058
+    if ($force or !isset($session)) {
3059
+        $s = pipeline('definir_session',
3060
+            $GLOBALS['visiteur_session']
3061
+                ? serialize($GLOBALS['visiteur_session'])
3062
+                . '_' . @$_COOKIE['spip_session']
3063
+                : ''
3064
+        );
3065
+        $session = $s ? substr(md5($s), 0, 8) : '';
3066
+    }
3068 3067
 
3069
-	#spip_log('session: '.$session);
3070
-	return $session;
3068
+    #spip_log('session: '.$session);
3069
+    return $session;
3071 3070
 }
3072 3071
 
3073 3072
 
@@ -3086,9 +3085,9 @@  discard block
 block discarded – undo
3086 3085
  *    Lien sur une icone d'aide
3087 3086
  **/
3088 3087
 function aider($aide = '', $distante = false) {
3089
-	$aider = charger_fonction('aide', 'inc', true);
3088
+    $aider = charger_fonction('aide', 'inc', true);
3090 3089
 
3091
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3090
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3092 3091
 }
3093 3092
 
3094 3093
 /**
@@ -3098,13 +3097,13 @@  discard block
 block discarded – undo
3098 3097
  */
3099 3098
 function exec_info_dist() {
3100 3099
 
3101
-	include_spip('inc/autoriser');
3102
-	if (autoriser('webmestre')) {
3103
-		phpinfo();
3104
-	} else {
3105
-		include_spip('inc/filtres');
3106
-		sinon_interdire_acces();
3107
-	}
3100
+    include_spip('inc/autoriser');
3101
+    if (autoriser('webmestre')) {
3102
+        phpinfo();
3103
+    } else {
3104
+        include_spip('inc/filtres');
3105
+        sinon_interdire_acces();
3106
+    }
3108 3107
 }
3109 3108
 
3110 3109
 /**
@@ -3124,13 +3123,13 @@  discard block
 block discarded – undo
3124 3123
  *     - string si $message à false.
3125 3124
  **/
3126 3125
 function erreur_squelette($message = '', $lieu = '') {
3127
-	$debusquer = charger_fonction('debusquer', 'public');
3128
-	if (is_array($lieu)) {
3129
-		include_spip('public/compiler');
3130
-		$lieu = reconstruire_contexte_compil($lieu);
3131
-	}
3126
+    $debusquer = charger_fonction('debusquer', 'public');
3127
+    if (is_array($lieu)) {
3128
+        include_spip('public/compiler');
3129
+        $lieu = reconstruire_contexte_compil($lieu);
3130
+    }
3132 3131
 
3133
-	return $debusquer($message, $lieu);
3132
+    return $debusquer($message, $lieu);
3134 3133
 }
3135 3134
 
3136 3135
 /**
@@ -3167,109 +3166,109 @@  discard block
 block discarded – undo
3167 3166
  *     - ou tableau d'information sur le squelette.
3168 3167
  */
3169 3168
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3170
-	if (!function_exists('evaluer_fond')) {
3171
-		include_spip('public/assembler');
3172
-	}
3173
-	// assurer la compat avec l'ancienne syntaxe
3174
-	// (trim etait le 3eme argument, par defaut a true)
3175
-	if (!is_array($options)) {
3176
-		$options = array('trim' => $options);
3177
-	}
3178
-	if (!isset($options['trim'])) {
3179
-		$options['trim'] = true;
3180
-	}
3181
-
3182
-	if (isset($contexte['connect'])) {
3183
-		$connect = $contexte['connect'];
3184
-		unset($contexte['connect']);
3185
-	}
3186
-
3187
-	$texte = "";
3188
-	$pages = array();
3189
-	$lang_select = '';
3190
-	if (!isset($options['etoile']) or !$options['etoile']) {
3191
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3192
-		if (!isset($contexte['lang'])) {
3193
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3194
-		}
3195
-
3196
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3197
-			$lang_select = lang_select($contexte['lang']);
3198
-		}
3199
-	}
3200
-
3201
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3202
-		$GLOBALS['_INC_PUBLIC'] = 0;
3203
-	}
3204
-
3205
-	$GLOBALS['_INC_PUBLIC']++;
3206
-
3207
-	// fix #4235
3208
-	$cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3209
-
3210
-
3211
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3169
+    if (!function_exists('evaluer_fond')) {
3170
+        include_spip('public/assembler');
3171
+    }
3172
+    // assurer la compat avec l'ancienne syntaxe
3173
+    // (trim etait le 3eme argument, par defaut a true)
3174
+    if (!is_array($options)) {
3175
+        $options = array('trim' => $options);
3176
+    }
3177
+    if (!isset($options['trim'])) {
3178
+        $options['trim'] = true;
3179
+    }
3180
+
3181
+    if (isset($contexte['connect'])) {
3182
+        $connect = $contexte['connect'];
3183
+        unset($contexte['connect']);
3184
+    }
3185
+
3186
+    $texte = "";
3187
+    $pages = array();
3188
+    $lang_select = '';
3189
+    if (!isset($options['etoile']) or !$options['etoile']) {
3190
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3191
+        if (!isset($contexte['lang'])) {
3192
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3193
+        }
3194
+
3195
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3196
+            $lang_select = lang_select($contexte['lang']);
3197
+        }
3198
+    }
3199
+
3200
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3201
+        $GLOBALS['_INC_PUBLIC'] = 0;
3202
+    }
3203
+
3204
+    $GLOBALS['_INC_PUBLIC']++;
3205
+
3206
+    // fix #4235
3207
+    $cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3208
+
3209
+
3210
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3212 3211
 		
3213
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3214
-
3215
-		$page = evaluer_fond($f, $contexte, $connect);
3216
-		if ($page === '') {
3217
-			$c = isset($options['compil']) ? $options['compil'] : '';
3218
-			$a = array('fichier' => $f);
3219
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3220
-			erreur_squelette($erreur, $c);
3221
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3222
-			$page = array('texte' => '', 'erreur' => $erreur);
3223
-		}
3224
-
3225
-		$page = pipeline('recuperer_fond', array(
3226
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3227
-			'data' => $page
3228
-		));
3229
-		if (isset($options['ajax']) and $options['ajax']) {
3230
-			if (!function_exists('encoder_contexte_ajax')) {
3231
-				include_spip('inc/filtres');
3232
-			}
3233
-			$page['texte'] = encoder_contexte_ajax(
3234
-				array_merge(
3235
-					$contexte,
3236
-					array('fond' => $f),
3237
-					($connect ? array('connect' => $connect) : array())
3238
-				),
3239
-				'',
3240
-				$page['texte'],
3241
-				$options['ajax']
3242
-			);
3243
-		}
3244
-
3245
-		if (isset($options['raw']) and $options['raw']) {
3246
-			$pages[] = $page;
3247
-		} else {
3248
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3249
-		}
3212
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3213
+
3214
+        $page = evaluer_fond($f, $contexte, $connect);
3215
+        if ($page === '') {
3216
+            $c = isset($options['compil']) ? $options['compil'] : '';
3217
+            $a = array('fichier' => $f);
3218
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3219
+            erreur_squelette($erreur, $c);
3220
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3221
+            $page = array('texte' => '', 'erreur' => $erreur);
3222
+        }
3223
+
3224
+        $page = pipeline('recuperer_fond', array(
3225
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3226
+            'data' => $page
3227
+        ));
3228
+        if (isset($options['ajax']) and $options['ajax']) {
3229
+            if (!function_exists('encoder_contexte_ajax')) {
3230
+                include_spip('inc/filtres');
3231
+            }
3232
+            $page['texte'] = encoder_contexte_ajax(
3233
+                array_merge(
3234
+                    $contexte,
3235
+                    array('fond' => $f),
3236
+                    ($connect ? array('connect' => $connect) : array())
3237
+                ),
3238
+                '',
3239
+                $page['texte'],
3240
+                $options['ajax']
3241
+            );
3242
+        }
3243
+
3244
+        if (isset($options['raw']) and $options['raw']) {
3245
+            $pages[] = $page;
3246
+        } else {
3247
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3248
+        }
3250 3249
 		
3251
-		// contamination de la session appelante, pour les inclusions statiques
3252
-		if (isset($page['invalideurs']['session'])){
3253
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3254
-		}
3255
-	}
3250
+        // contamination de la session appelante, pour les inclusions statiques
3251
+        if (isset($page['invalideurs']['session'])){
3252
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3253
+        }
3254
+    }
3256 3255
 
3257
-	// restaurer le sessionnement du contexte appelant, 
3258
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3259
-	if (isset($cache_utilise_session_appelant)) {
3260
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3261
-	}
3256
+    // restaurer le sessionnement du contexte appelant, 
3257
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3258
+    if (isset($cache_utilise_session_appelant)) {
3259
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3260
+    }
3262 3261
 
3263
-	$GLOBALS['_INC_PUBLIC']--;
3262
+    $GLOBALS['_INC_PUBLIC']--;
3264 3263
 
3265
-	if ($lang_select) {
3266
-		lang_select();
3267
-	}
3268
-	if (isset($options['raw']) and $options['raw']) {
3269
-		return is_array($fond) ? $pages : reset($pages);
3270
-	} else {
3271
-		return $options['trim'] ? ltrim($texte) : $texte;
3272
-	}
3264
+    if ($lang_select) {
3265
+        lang_select();
3266
+    }
3267
+    if (isset($options['raw']) and $options['raw']) {
3268
+        return is_array($fond) ? $pages : reset($pages);
3269
+    } else {
3270
+        return $options['trim'] ? ltrim($texte) : $texte;
3271
+    }
3273 3272
 }
3274 3273
 
3275 3274
 /**
@@ -3279,7 +3278,7 @@  discard block
 block discarded – undo
3279 3278
  * @return string
3280 3279
  */
3281 3280
 function trouve_modele($nom) {
3282
-	return trouver_fond($nom, 'modeles/');
3281
+    return trouver_fond($nom, 'modeles/');
3283 3282
 }
3284 3283
 
3285 3284
 /**
@@ -3295,21 +3294,21 @@  discard block
 block discarded – undo
3295 3294
  * @return array|string
3296 3295
  */
3297 3296
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3298
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3299
-	if (!$pathinfo) {
3300
-		return $f;
3301
-	}
3302
-	// renvoyer un tableau detaille si $pathinfo==true
3303
-	$p = pathinfo($f);
3304
-	if (!isset($p['extension']) or !$p['extension']) {
3305
-		$p['extension'] = _EXTENSION_SQUELETTES;
3306
-	}
3307
-	if (!isset($p['extension']) or !$p['filename']) {
3308
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3309
-	}
3310
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3297
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3298
+    if (!$pathinfo) {
3299
+        return $f;
3300
+    }
3301
+    // renvoyer un tableau detaille si $pathinfo==true
3302
+    $p = pathinfo($f);
3303
+    if (!isset($p['extension']) or !$p['extension']) {
3304
+        $p['extension'] = _EXTENSION_SQUELETTES;
3305
+    }
3306
+    if (!isset($p['extension']) or !$p['filename']) {
3307
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3308
+    }
3309
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3311 3310
 
3312
-	return $p;
3311
+    return $p;
3313 3312
 }
3314 3313
 
3315 3314
 /**
@@ -3330,24 +3329,24 @@  discard block
 block discarded – undo
3330 3329
  *     Nom de l'exec, sinon chaîne vide.
3331 3330
  **/
3332 3331
 function tester_url_ecrire($nom) {
3333
-	static $exec = array();
3334
-	if (isset($exec[$nom])) {
3335
-		return $exec[$nom];
3336
-	}
3337
-	// tester si c'est une page en squelette
3338
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3339
-		return $exec[$nom] = 'fond';
3340
-	} // compat skels orthogonaux version precedente
3341
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3342
-		return $exec[$nom] = 'fond_monobloc';
3343
-	} // echafaudage d'un fond !
3344
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3345
-		return $exec[$nom] = 'fond';
3346
-	}
3347
-	// attention, il ne faut pas inclure l'exec ici
3348
-	// car sinon #URL_ECRIRE provoque des inclusions
3349
-	// et des define intrusifs potentiels
3350
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3332
+    static $exec = array();
3333
+    if (isset($exec[$nom])) {
3334
+        return $exec[$nom];
3335
+    }
3336
+    // tester si c'est une page en squelette
3337
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3338
+        return $exec[$nom] = 'fond';
3339
+    } // compat skels orthogonaux version precedente
3340
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3341
+        return $exec[$nom] = 'fond_monobloc';
3342
+    } // echafaudage d'un fond !
3343
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3344
+        return $exec[$nom] = 'fond';
3345
+    }
3346
+    // attention, il ne faut pas inclure l'exec ici
3347
+    // car sinon #URL_ECRIRE provoque des inclusions
3348
+    // et des define intrusifs potentiels
3349
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3351 3350
 }
3352 3351
 
3353 3352
 
@@ -3363,10 +3362,10 @@  discard block
 block discarded – undo
3363 3362
  * @return bool true si le module est chargé
3364 3363
  **/
3365 3364
 function charger_php_extension($module) {
3366
-	if (extension_loaded($module)) {
3367
-		return true;
3368
-	}
3369
-	return false;
3365
+    if (extension_loaded($module)) {
3366
+        return true;
3367
+    }
3368
+    return false;
3370 3369
 }
3371 3370
 
3372 3371
 
@@ -3377,8 +3376,8 @@  discard block
 block discarded – undo
3377 3376
  *     true si et seulement si la configuration autorise le code HTML5 sur le site public
3378 3377
  **/
3379 3378
 function html5_permis() {
3380
-	return (isset($GLOBALS['meta']['version_html_max'])
3381
-		and ('html5' == $GLOBALS['meta']['version_html_max']));
3379
+    return (isset($GLOBALS['meta']['version_html_max'])
3380
+        and ('html5' == $GLOBALS['meta']['version_html_max']));
3382 3381
 }
3383 3382
 
3384 3383
 /**
@@ -3388,17 +3387,17 @@  discard block
 block discarded – undo
3388 3387
  * @return array
3389 3388
  */
3390 3389
 function formats_image_acceptables($gd = false, $svg_allowed = true) {
3391
-	$config = ($gd ? "gd_formats" : "formats_graphiques");
3392
-	$formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3393
-	$formats = explode(',', $formats);
3394
-	$formats = array_filter($formats);
3395
-	$formats = array_map('trim', $formats);
3390
+    $config = ($gd ? "gd_formats" : "formats_graphiques");
3391
+    $formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3392
+    $formats = explode(',', $formats);
3393
+    $formats = array_filter($formats);
3394
+    $formats = array_map('trim', $formats);
3396 3395
 
3397
-	if ($svg_allowed) {
3398
-		$formats[] = 'svg';
3399
-	}
3396
+    if ($svg_allowed) {
3397
+        $formats[] = 'svg';
3398
+    }
3400 3399
 
3401
-	return $formats;
3400
+    return $formats;
3402 3401
 }
3403 3402
 
3404 3403
 /**
@@ -3407,21 +3406,21 @@  discard block
 block discarded – undo
3407 3406
  * @return array|bool
3408 3407
  */
3409 3408
 function spip_getimagesize($fichier) {
3410
-	if (!$imagesize = @getimagesize($fichier)) {
3409
+    if (!$imagesize = @getimagesize($fichier)) {
3411 3410
 
3412
-		include_spip("inc/svg");
3413
-		if ($attrs = svg_lire_attributs($fichier)) {
3414
-			list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3415
-			$imagesize = [
3416
-				$width,
3417
-				$height,
3418
-				IMAGETYPE_SVG,
3419
-				"width=\"{$width}\" height=\"{$height}\"",
3420
-				"mime" => "image/svg+xml"
3421
-			];
3422
-		}
3423
-	}
3424
-	return $imagesize;
3411
+        include_spip("inc/svg");
3412
+        if ($attrs = svg_lire_attributs($fichier)) {
3413
+            list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3414
+            $imagesize = [
3415
+                $width,
3416
+                $height,
3417
+                IMAGETYPE_SVG,
3418
+                "width=\"{$width}\" height=\"{$height}\"",
3419
+                "mime" => "image/svg+xml"
3420
+            ];
3421
+        }
3422
+    }
3423
+    return $imagesize;
3425 3424
 }
3426 3425
 
3427 3426
 
@@ -3441,7 +3440,7 @@  discard block
 block discarded – undo
3441 3440
  * @return mixed Valeur de la meta.
3442 3441
  **/
3443 3442
 function lire_meta($nom) {
3444
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3443
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3445 3444
 }
3446 3445
 
3447 3446
 
@@ -3463,128 +3462,128 @@  discard block
 block discarded – undo
3463 3462
  * @param string $statut
3464 3463
  */
3465 3464
 function avertir_auteurs($nom, $message, $statut = '') {
3466
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3467
-	if (!$alertes
3468
-		or !is_array($alertes = unserialize($alertes))
3469
-	) {
3470
-		$alertes = array();
3471
-	}
3465
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3466
+    if (!$alertes
3467
+        or !is_array($alertes = unserialize($alertes))
3468
+    ) {
3469
+        $alertes = array();
3470
+    }
3472 3471
 
3473
-	if (!isset($alertes[$statut])) {
3474
-		$alertes[$statut] = array();
3475
-	}
3476
-	$alertes[$statut][$nom] = $message;
3477
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3472
+    if (!isset($alertes[$statut])) {
3473
+        $alertes[$statut] = array();
3474
+    }
3475
+    $alertes[$statut][$nom] = $message;
3476
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3478 3477
 }
3479 3478
 
3480 3479
 if (PHP_VERSION_ID < 50500) {
3481
-	if (!function_exists('array_column')) {
3482
-		/**
3483
-		 * Returns the values from a single column of the input array, identified by
3484
-		 * the $columnKey.
3485
-		 *
3486
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3487
-		 * array by the values from the $indexKey column in the input array.
3488
-		 *
3489
-		 * @link http://php.net/manual/fr/function.array-column.php
3490
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3491
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3492
-		 * @license http://opensource.org/licenses/MIT MIT
3493
-		 *
3494
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3495
-		 *                     a column of values.
3496
-		 * @param mixed $columnKey The column of values to return. This value may be the
3497
-		 *                         integer key of the column you wish to retrieve, or it
3498
-		 *                         may be the string key name for an associative array.
3499
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3500
-		 *                        the returned array. This value may be the integer key
3501
-		 *                        of the column, or it may be the string key name.
3502
-		 * @return array
3503
-		 */
3504
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3505
-		{
3506
-			// Using func_get_args() in order to check for proper number of
3507
-			// parameters and trigger errors exactly as the built-in array_column()
3508
-			// does in PHP 5.5.
3509
-			$argc = func_num_args();
3510
-			$params = func_get_args();
3511
-
3512
-			if ($argc < 2) {
3513
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3514
-				return null;
3515
-			}
3516
-
3517
-			if (!is_array($params[0])) {
3518
-				trigger_error(
3519
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3520
-					E_USER_WARNING
3521
-				);
3522
-				return null;
3523
-			}
3524
-
3525
-			if (!is_int($params[1])
3526
-				&& !is_float($params[1])
3527
-				&& !is_string($params[1])
3528
-				&& $params[1] !== null
3529
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3530
-			) {
3531
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3532
-				return false;
3533
-			}
3534
-
3535
-			if (isset($params[2])
3536
-				&& !is_int($params[2])
3537
-				&& !is_float($params[2])
3538
-				&& !is_string($params[2])
3539
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3540
-			) {
3541
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3542
-				return false;
3543
-			}
3544
-
3545
-			$paramsInput = $params[0];
3546
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3547
-
3548
-			$paramsIndexKey = null;
3549
-			if (isset($params[2])) {
3550
-				if (is_float($params[2]) || is_int($params[2])) {
3551
-					$paramsIndexKey = (int) $params[2];
3552
-				} else {
3553
-					$paramsIndexKey = (string) $params[2];
3554
-				}
3555
-			}
3556
-
3557
-			$resultArray = array();
3558
-
3559
-			foreach ($paramsInput as $row) {
3560
-				$key = $value = null;
3561
-				$keySet = $valueSet = false;
3562
-
3563
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3564
-					$keySet = true;
3565
-					$key = (string) $row[$paramsIndexKey];
3566
-				}
3567
-
3568
-				if ($paramsColumnKey === null) {
3569
-					$valueSet = true;
3570
-					$value = $row;
3571
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3572
-					$valueSet = true;
3573
-					$value = $row[$paramsColumnKey];
3574
-				}
3575
-
3576
-				if ($valueSet) {
3577
-					if ($keySet) {
3578
-						$resultArray[$key] = $value;
3579
-					} else {
3580
-						$resultArray[] = $value;
3581
-					}
3582
-				}
3583
-
3584
-			}
3585
-
3586
-			return $resultArray;
3587
-		}
3588
-
3589
-	}
3480
+    if (!function_exists('array_column')) {
3481
+        /**
3482
+         * Returns the values from a single column of the input array, identified by
3483
+         * the $columnKey.
3484
+         *
3485
+         * Optionally, you may provide an $indexKey to index the values in the returned
3486
+         * array by the values from the $indexKey column in the input array.
3487
+         *
3488
+         * @link http://php.net/manual/fr/function.array-column.php
3489
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3490
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3491
+         * @license http://opensource.org/licenses/MIT MIT
3492
+         *
3493
+         * @param array $input A multi-dimensional array (record set) from which to pull
3494
+         *                     a column of values.
3495
+         * @param mixed $columnKey The column of values to return. This value may be the
3496
+         *                         integer key of the column you wish to retrieve, or it
3497
+         *                         may be the string key name for an associative array.
3498
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3499
+         *                        the returned array. This value may be the integer key
3500
+         *                        of the column, or it may be the string key name.
3501
+         * @return array
3502
+         */
3503
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3504
+        {
3505
+            // Using func_get_args() in order to check for proper number of
3506
+            // parameters and trigger errors exactly as the built-in array_column()
3507
+            // does in PHP 5.5.
3508
+            $argc = func_num_args();
3509
+            $params = func_get_args();
3510
+
3511
+            if ($argc < 2) {
3512
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3513
+                return null;
3514
+            }
3515
+
3516
+            if (!is_array($params[0])) {
3517
+                trigger_error(
3518
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3519
+                    E_USER_WARNING
3520
+                );
3521
+                return null;
3522
+            }
3523
+
3524
+            if (!is_int($params[1])
3525
+                && !is_float($params[1])
3526
+                && !is_string($params[1])
3527
+                && $params[1] !== null
3528
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3529
+            ) {
3530
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3531
+                return false;
3532
+            }
3533
+
3534
+            if (isset($params[2])
3535
+                && !is_int($params[2])
3536
+                && !is_float($params[2])
3537
+                && !is_string($params[2])
3538
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3539
+            ) {
3540
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3541
+                return false;
3542
+            }
3543
+
3544
+            $paramsInput = $params[0];
3545
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3546
+
3547
+            $paramsIndexKey = null;
3548
+            if (isset($params[2])) {
3549
+                if (is_float($params[2]) || is_int($params[2])) {
3550
+                    $paramsIndexKey = (int) $params[2];
3551
+                } else {
3552
+                    $paramsIndexKey = (string) $params[2];
3553
+                }
3554
+            }
3555
+
3556
+            $resultArray = array();
3557
+
3558
+            foreach ($paramsInput as $row) {
3559
+                $key = $value = null;
3560
+                $keySet = $valueSet = false;
3561
+
3562
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3563
+                    $keySet = true;
3564
+                    $key = (string) $row[$paramsIndexKey];
3565
+                }
3566
+
3567
+                if ($paramsColumnKey === null) {
3568
+                    $valueSet = true;
3569
+                    $value = $row;
3570
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3571
+                    $valueSet = true;
3572
+                    $value = $row[$paramsColumnKey];
3573
+                }
3574
+
3575
+                if ($valueSet) {
3576
+                    if ($keySet) {
3577
+                        $resultArray[$key] = $value;
3578
+                    } else {
3579
+                        $resultArray[] = $value;
3580
+                    }
3581
+                }
3582
+
3583
+            }
3584
+
3585
+            return $resultArray;
3586
+        }
3587
+
3588
+    }
3590 3589
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 2 patches
Indentation   +2020 added lines, -2020 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_spip('public/parametrer'); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,36 +75,36 @@  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
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
-		// fonction ou name\space\fonction
98
-		if (is_callable($f)) {
99
-			return $f;
100
-		}
101
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
-			return $f;
104
-		}
105
-	}
106
-
107
-	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
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
+        // fonction ou name\space\fonction
98
+        if (is_callable($f)) {
99
+            return $f;
100
+        }
101
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
+            return $f;
104
+        }
105
+    }
106
+
107
+    return $default;
108 108
 }
109 109
 
110 110
 /**
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
  *     Chaîne vide sinon (filtre introuvable).
129 129
  **/
130 130
 function appliquer_filtre($arg, $filtre, $force = null) {
131
-	$f = chercher_filtre($filtre);
132
-	if (!$f) {
133
-		if (!$force) {
134
-			return '';
135
-		} else {
136
-			return $arg;
137
-		}
138
-	}
131
+    $f = chercher_filtre($filtre);
132
+    if (!$f) {
133
+        if (!$force) {
134
+            return '';
135
+        } else {
136
+            return $arg;
137
+        }
138
+    }
139 139
 
140
-	$args = func_get_args();
141
-	array_shift($args); // enlever $arg
142
-	array_shift($args); // enlever $filtre
143
-	array_unshift($args, $arg); // remettre $arg
144
-	return call_user_func_array($f, $args);
140
+    $args = func_get_args();
141
+    array_shift($args); // enlever $arg
142
+    array_shift($args); // enlever $filtre
143
+    array_unshift($args, $arg); // remettre $arg
144
+    return call_user_func_array($f, $args);
145 145
 }
146 146
 
147 147
 /**
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
  *     Version de SPIP
158 158
  **/
159 159
 function spip_version() {
160
-	$version = $GLOBALS['spip_version_affichee'];
161
-	if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
162
-		$version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']';
163
-	}
160
+    $version = $GLOBALS['spip_version_affichee'];
161
+    if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
162
+        $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']';
163
+    }
164 164
 
165
-	return $version;
165
+    return $version;
166 166
 }
167 167
 
168 168
 
@@ -181,43 +181,43 @@  discard block
 block discarded – undo
181 181
  *
182 182
  **/
183 183
 function version_svn_courante($dir) {
184
-	if (!$dir) {
185
-		$dir = '.';
186
-	}
187
-
188
-	// version installee par paquet ZIP
189
-	if (lire_fichier($dir . '/svn.revision', $c)
190
-		and preg_match(',Revision: (\d+),', $c, $d)
191
-	) {
192
-		return intval($d[1]);
193
-	}
194
-
195
-	// version installee par SVN
196
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
197
-		$db = new SQLite3($dir . '/.svn/wc.db');
198
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
199
-		if ($result) {
200
-			$row = $result->fetchArray();
201
-			if ($row['changed_revision'] != "") {
202
-				return -$row['changed_revision'];
203
-			}
204
-		}
205
-	} else if (lire_fichier($dir . '/.svn/entries', $c)
206
-		and (
207
-			(preg_match_all(
208
-					',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
209
-				and $v = max($r1[1])
210
-			)
211
-			or
212
-			(preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
213
-				and $v = $r1[1]
214
-			))
215
-	) {
216
-		return -$v;
217
-	}
218
-
219
-	// Bug ou paquet fait main
220
-	return 0;
184
+    if (!$dir) {
185
+        $dir = '.';
186
+    }
187
+
188
+    // version installee par paquet ZIP
189
+    if (lire_fichier($dir . '/svn.revision', $c)
190
+        and preg_match(',Revision: (\d+),', $c, $d)
191
+    ) {
192
+        return intval($d[1]);
193
+    }
194
+
195
+    // version installee par SVN
196
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
197
+        $db = new SQLite3($dir . '/.svn/wc.db');
198
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
199
+        if ($result) {
200
+            $row = $result->fetchArray();
201
+            if ($row['changed_revision'] != "") {
202
+                return -$row['changed_revision'];
203
+            }
204
+        }
205
+    } else if (lire_fichier($dir . '/.svn/entries', $c)
206
+        and (
207
+            (preg_match_all(
208
+                    ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
209
+                and $v = max($r1[1])
210
+            )
211
+            or
212
+            (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
213
+                and $v = $r1[1]
214
+            ))
215
+    ) {
216
+        return -$v;
217
+    }
218
+
219
+    // Bug ou paquet fait main
220
+    return 0;
221 221
 }
222 222
 
223 223
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
  *     Code HTML retourné par le filtre
262 262
  **/
263 263
 function filtrer($filtre) {
264
-	$tous = func_get_args();
265
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
266
-		return image_filtrer($tous);
267
-	} elseif ($f = chercher_filtre($filtre)) {
268
-		array_shift($tous);
269
-		return call_user_func_array($f, $tous);
270
-	} else {
271
-		// le filtre n'existe pas, on provoque une erreur
272
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
273
-		erreur_squelette($msg);
274
-		return '';
275
-	}
264
+    $tous = func_get_args();
265
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
266
+        return image_filtrer($tous);
267
+    } elseif ($f = chercher_filtre($filtre)) {
268
+        array_shift($tous);
269
+        return call_user_func_array($f, $tous);
270
+    } else {
271
+        // le filtre n'existe pas, on provoque une erreur
272
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
273
+        erreur_squelette($msg);
274
+        return '';
275
+    }
276 276
 }
277 277
 
278 278
 /**
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
290 290
  */
291 291
 function trouver_filtre_matrice($filtre) {
292
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
293
-		find_in_path($f, '', true);
294
-		$GLOBALS['spip_matrice'][$filtre] = true;
295
-	}
296
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
292
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
293
+        find_in_path($f, '', true);
294
+        $GLOBALS['spip_matrice'][$filtre] = true;
295
+    }
296
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
297 297
 }
298 298
 
299 299
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
  * @return mixed
322 322
  */
323 323
 function filtre_set(&$Pile, $val, $key, $continue = null) {
324
-	$Pile['vars'][$key] = $val;
325
-	return $continue ? $val : '';
324
+    $Pile['vars'][$key] = $val;
325
+    return $continue ? $val : '';
326 326
 }
327 327
 
328 328
 /**
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
349 349
  */
350 350
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
351
-	$Pile[0][$key] = $val;
352
-	return $continue ? $val : '';
351
+    $Pile[0][$key] = $val;
352
+    return $continue ? $val : '';
353 353
 }
354 354
 
355 355
 /**
@@ -371,18 +371,18 @@  discard block
 block discarded – undo
371 371
  * @return mixed Retourne la valeur (sans la modifier).
372 372
  */
373 373
 function filtre_debug($val, $key = null) {
374
-	$debug = (
375
-		is_null($key) ? '' : (var_export($key, true) . " = ")
376
-		) . var_export($val, true);
374
+    $debug = (
375
+        is_null($key) ? '' : (var_export($key, true) . " = ")
376
+        ) . var_export($val, true);
377 377
 
378
-	include_spip('inc/autoriser');
379
-	if (autoriser('webmestre')) {
380
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
381
-	}
378
+    include_spip('inc/autoriser');
379
+    if (autoriser('webmestre')) {
380
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
381
+    }
382 382
 
383
-	spip_log($debug, 'debug');
383
+    spip_log($debug, 'debug');
384 384
 
385
-	return $val;
385
+    return $val;
386 386
 }
387 387
 
388 388
 
@@ -410,71 +410,71 @@  discard block
 block discarded – undo
410 410
  *     Texte qui a reçu les filtres
411 411
  **/
412 412
 function image_filtrer($args) {
413
-	$filtre = array_shift($args); # enlever $filtre
414
-	$texte = array_shift($args);
415
-	if (!strlen($texte)) {
416
-		return;
417
-	}
418
-	find_in_path('filtres_images_mini.php', 'inc/', true);
419
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
420
-	// Cas du nom de fichier local
421
-	if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
422
-		and !preg_match(',^/|[<>]|\s,S', $texte)
423
-		and (
424
-			file_exists(preg_replace(',[?].*$,', '', $texte))
425
-			or tester_url_absolue($texte)
426
-		)
427
-	) {
428
-		array_unshift($args, "<img src='$texte' />");
429
-		$res = call_user_func_array($filtre, $args);
430
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
431
-		return $res;
432
-	}
433
-
434
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
435
-	if (preg_match_all(
436
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
437
-		$texte, $tags, PREG_SET_ORDER)) {
438
-		foreach ($tags as $tag) {
439
-			$class = extraire_attribut($tag[3], 'class');
440
-			if (!$class or
441
-				(strpos($class, 'filtre_inactif') === false
442
-					// compat historique a virer en 3.2
443
-					and strpos($class, 'no_image_filtrer') === false)
444
-			) {
445
-				array_unshift($args, $tag[3]);
446
-				if ($reduit = call_user_func_array($filtre, $args)) {
447
-					// En cas de span spip_documents, modifier le style=...width:
448
-					if ($tag[1]) {
449
-						$w = extraire_attribut($reduit, 'width');
450
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
451
-							$w = $regs[1];
452
-						}
453
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
454
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
455
-							$replace = inserer_attribut($tag[1], 'style', $style);
456
-							$texte = str_replace($tag[1], $replace, $texte);
457
-						}
458
-					}
459
-					// traiter aussi un eventuel mouseover
460
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
461
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
462
-							$srcover = $match[1];
463
-							array_shift($args);
464
-							array_unshift($args, "<img src='" . $match[1] . "' />");
465
-							$srcover_filter = call_user_func_array($filtre, $args);
466
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
467
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
468
-						}
469
-					}
470
-					$texte = str_replace($tag[3], $reduit, $texte);
471
-				}
472
-				array_shift($args);
473
-			}
474
-		}
475
-	}
476
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
477
-	return $texte;
413
+    $filtre = array_shift($args); # enlever $filtre
414
+    $texte = array_shift($args);
415
+    if (!strlen($texte)) {
416
+        return;
417
+    }
418
+    find_in_path('filtres_images_mini.php', 'inc/', true);
419
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
420
+    // Cas du nom de fichier local
421
+    if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
422
+        and !preg_match(',^/|[<>]|\s,S', $texte)
423
+        and (
424
+            file_exists(preg_replace(',[?].*$,', '', $texte))
425
+            or tester_url_absolue($texte)
426
+        )
427
+    ) {
428
+        array_unshift($args, "<img src='$texte' />");
429
+        $res = call_user_func_array($filtre, $args);
430
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
431
+        return $res;
432
+    }
433
+
434
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
435
+    if (preg_match_all(
436
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
437
+        $texte, $tags, PREG_SET_ORDER)) {
438
+        foreach ($tags as $tag) {
439
+            $class = extraire_attribut($tag[3], 'class');
440
+            if (!$class or
441
+                (strpos($class, 'filtre_inactif') === false
442
+                    // compat historique a virer en 3.2
443
+                    and strpos($class, 'no_image_filtrer') === false)
444
+            ) {
445
+                array_unshift($args, $tag[3]);
446
+                if ($reduit = call_user_func_array($filtre, $args)) {
447
+                    // En cas de span spip_documents, modifier le style=...width:
448
+                    if ($tag[1]) {
449
+                        $w = extraire_attribut($reduit, 'width');
450
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
451
+                            $w = $regs[1];
452
+                        }
453
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
454
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
455
+                            $replace = inserer_attribut($tag[1], 'style', $style);
456
+                            $texte = str_replace($tag[1], $replace, $texte);
457
+                        }
458
+                    }
459
+                    // traiter aussi un eventuel mouseover
460
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
461
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
462
+                            $srcover = $match[1];
463
+                            array_shift($args);
464
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
465
+                            $srcover_filter = call_user_func_array($filtre, $args);
466
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
467
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
468
+                        }
469
+                    }
470
+                    $texte = str_replace($tag[3], $reduit, $texte);
471
+                }
472
+                array_shift($args);
473
+            }
474
+        }
475
+    }
476
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
477
+    return $texte;
478 478
 }
479 479
 
480 480
 /**
@@ -489,65 +489,65 @@  discard block
 block discarded – undo
489 489
  **/
490 490
 function taille_image($img) {
491 491
 
492
-	static $largeur_img = array(), $hauteur_img = array();
493
-	$srcWidth = 0;
494
-	$srcHeight = 0;
495
-
496
-	$src = extraire_attribut($img, 'src');
497
-
498
-	if (!$src) {
499
-		$src = $img;
500
-	} else {
501
-		$srcWidth = extraire_attribut($img, 'width');
502
-		$srcHeight = extraire_attribut($img, 'height');
503
-	}
504
-
505
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
506
-	// la copie locale a toutes les chances d'etre la ou de resservir
507
-	if (tester_url_absolue($src)) {
508
-		include_spip('inc/distant');
509
-		$fichier = copie_locale($src);
510
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
511
-	}
512
-	if (($p = strpos($src, '?')) !== false) {
513
-		$src = substr($src, 0, $p);
514
-	}
515
-
516
-	$srcsize = false;
517
-	if (isset($largeur_img[$src])) {
518
-		$srcWidth = $largeur_img[$src];
519
-	}
520
-	if (isset($hauteur_img[$src])) {
521
-		$srcHeight = $hauteur_img[$src];
522
-	}
523
-	if (!$srcWidth or !$srcHeight) {
524
-
525
-		if (file_exists($src)
526
-			and $srcsize = spip_getimagesize($src)
527
-		) {
528
-			if (!$srcWidth) {
529
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
530
-			}
531
-			if (!$srcHeight) {
532
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
533
-			}
534
-		}
535
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
536
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
537
-		elseif (@file_exists($f = "$src.src")
538
-			and lire_fichier($f, $valeurs)
539
-			and $valeurs = unserialize($valeurs)
540
-		) {
541
-			if (!$srcWidth) {
542
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
543
-			}
544
-			if (!$srcHeight) {
545
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
546
-			}
547
-		}
548
-	}
549
-
550
-	return array($srcHeight, $srcWidth);
492
+    static $largeur_img = array(), $hauteur_img = array();
493
+    $srcWidth = 0;
494
+    $srcHeight = 0;
495
+
496
+    $src = extraire_attribut($img, 'src');
497
+
498
+    if (!$src) {
499
+        $src = $img;
500
+    } else {
501
+        $srcWidth = extraire_attribut($img, 'width');
502
+        $srcHeight = extraire_attribut($img, 'height');
503
+    }
504
+
505
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
506
+    // la copie locale a toutes les chances d'etre la ou de resservir
507
+    if (tester_url_absolue($src)) {
508
+        include_spip('inc/distant');
509
+        $fichier = copie_locale($src);
510
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
511
+    }
512
+    if (($p = strpos($src, '?')) !== false) {
513
+        $src = substr($src, 0, $p);
514
+    }
515
+
516
+    $srcsize = false;
517
+    if (isset($largeur_img[$src])) {
518
+        $srcWidth = $largeur_img[$src];
519
+    }
520
+    if (isset($hauteur_img[$src])) {
521
+        $srcHeight = $hauteur_img[$src];
522
+    }
523
+    if (!$srcWidth or !$srcHeight) {
524
+
525
+        if (file_exists($src)
526
+            and $srcsize = spip_getimagesize($src)
527
+        ) {
528
+            if (!$srcWidth) {
529
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
530
+            }
531
+            if (!$srcHeight) {
532
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
533
+            }
534
+        }
535
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
536
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
537
+        elseif (@file_exists($f = "$src.src")
538
+            and lire_fichier($f, $valeurs)
539
+            and $valeurs = unserialize($valeurs)
540
+        ) {
541
+            if (!$srcWidth) {
542
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
543
+            }
544
+            if (!$srcHeight) {
545
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
546
+            }
547
+        }
548
+    }
549
+
550
+    return array($srcHeight, $srcWidth);
551 551
 }
552 552
 
553 553
 
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
  *     Largeur en pixels, NULL ou 0 si aucune image.
566 566
  **/
567 567
 function largeur($img) {
568
-	if (!$img) {
569
-		return;
570
-	}
571
-	list($h, $l) = taille_image($img);
568
+    if (!$img) {
569
+        return;
570
+    }
571
+    list($h, $l) = taille_image($img);
572 572
 
573
-	return $l;
573
+    return $l;
574 574
 }
575 575
 
576 576
 /**
@@ -587,12 +587,12 @@  discard block
 block discarded – undo
587 587
  *     Hauteur en pixels, NULL ou 0 si aucune image.
588 588
  **/
589 589
 function hauteur($img) {
590
-	if (!$img) {
591
-		return;
592
-	}
593
-	list($h, $l) = taille_image($img);
590
+    if (!$img) {
591
+        return;
592
+    }
593
+    list($h, $l) = taille_image($img);
594 594
 
595
-	return $h;
595
+    return $h;
596 596
 }
597 597
 
598 598
 
@@ -612,11 +612,11 @@  discard block
 block discarded – undo
612 612
  * @return string
613 613
  **/
614 614
 function corriger_entites_html($texte) {
615
-	if (strpos($texte, '&amp;') === false) {
616
-		return $texte;
617
-	}
615
+    if (strpos($texte, '&amp;') === false) {
616
+        return $texte;
617
+    }
618 618
 
619
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
619
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
620 620
 }
621 621
 
622 622
 /**
@@ -631,11 +631,11 @@  discard block
 block discarded – undo
631 631
  * @return string
632 632
  **/
633 633
 function corriger_toutes_entites_html($texte) {
634
-	if (strpos($texte, '&amp;') === false) {
635
-		return $texte;
636
-	}
634
+    if (strpos($texte, '&amp;') === false) {
635
+        return $texte;
636
+    }
637 637
 
638
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
638
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
639 639
 }
640 640
 
641 641
 /**
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
  * @return string
646 646
  **/
647 647
 function proteger_amp($texte) {
648
-	return str_replace('&', '&amp;', $texte);
648
+    return str_replace('&', '&amp;', $texte);
649 649
 }
650 650
 
651 651
 
@@ -676,20 +676,20 @@  discard block
 block discarded – undo
676 676
  * @return mixed|string
677 677
  */
678 678
 function entites_html($texte, $tout = false, $quote = true) {
679
-	if (!is_string($texte) or !$texte
680
-		or strpbrk($texte, "&\"'<>") == false
681
-	) {
682
-		return $texte;
683
-	}
684
-	include_spip('inc/texte');
685
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
686
-	$flags |= ENT_HTML401;
687
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
688
-	if ($tout) {
689
-		return corriger_toutes_entites_html($texte);
690
-	} else {
691
-		return corriger_entites_html($texte);
692
-	}
679
+    if (!is_string($texte) or !$texte
680
+        or strpbrk($texte, "&\"'<>") == false
681
+    ) {
682
+        return $texte;
683
+    }
684
+    include_spip('inc/texte');
685
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
686
+    $flags |= ENT_HTML401;
687
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
688
+    if ($tout) {
689
+        return corriger_toutes_entites_html($texte);
690
+    } else {
691
+        return corriger_entites_html($texte);
692
+    }
693 693
 }
694 694
 
695 695
 /**
@@ -708,37 +708,37 @@  discard block
 block discarded – undo
708 708
  *     Texte converti
709 709
  **/
710 710
 function filtrer_entites($texte) {
711
-	if (strpos($texte, '&') === false) {
712
-		return $texte;
713
-	}
714
-	// filtrer
715
-	$texte = html2unicode($texte);
716
-	// remettre le tout dans le charset cible
717
-	$texte = unicode2charset($texte);
718
-	// cas particulier des " et ' qu'il faut filtrer aussi
719
-	// (on le faisait deja avec un &quot;)
720
-	if (strpos($texte, "&#") !== false) {
721
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
722
-	}
711
+    if (strpos($texte, '&') === false) {
712
+        return $texte;
713
+    }
714
+    // filtrer
715
+    $texte = html2unicode($texte);
716
+    // remettre le tout dans le charset cible
717
+    $texte = unicode2charset($texte);
718
+    // cas particulier des " et ' qu'il faut filtrer aussi
719
+    // (on le faisait deja avec un &quot;)
720
+    if (strpos($texte, "&#") !== false) {
721
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
722
+    }
723 723
 
724
-	return $texte;
724
+    return $texte;
725 725
 }
726 726
 
727 727
 
728 728
 if (!function_exists('filtre_filtrer_entites_dist')) {
729
-	/**
730
-	 * Version sécurisée de filtrer_entites
731
-	 * 
732
-	 * @uses interdire_scripts()
733
-	 * @uses filtrer_entites()
734
-	 * 
735
-	 * @param string $t
736
-	 * @return string
737
-	 */
738
-	function filtre_filtrer_entites_dist($t) {
739
-		include_spip('inc/texte');
740
-		return interdire_scripts(filtrer_entites($t));
741
-	}
729
+    /**
730
+     * Version sécurisée de filtrer_entites
731
+     * 
732
+     * @uses interdire_scripts()
733
+     * @uses filtrer_entites()
734
+     * 
735
+     * @param string $t
736
+     * @return string
737
+     */
738
+    function filtre_filtrer_entites_dist($t) {
739
+        include_spip('inc/texte');
740
+        return interdire_scripts(filtrer_entites($t));
741
+    }
742 742
 }
743 743
 
744 744
 
@@ -753,18 +753,18 @@  discard block
 block discarded – undo
753 753
  * @return string|array
754 754
  **/
755 755
 function supprimer_caracteres_illegaux($texte) {
756
-	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";
757
-	static $to = null;
756
+    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";
757
+    static $to = null;
758 758
 
759
-	if (is_array($texte)) {
760
-		return array_map('supprimer_caracteres_illegaux', $texte);
761
-	}
759
+    if (is_array($texte)) {
760
+        return array_map('supprimer_caracteres_illegaux', $texte);
761
+    }
762 762
 
763
-	if (!$to) {
764
-		$to = str_repeat('-', strlen($from));
765
-	}
763
+    if (!$to) {
764
+        $to = str_repeat('-', strlen($from));
765
+    }
766 766
 
767
-	return strtr($texte, $from, $to);
767
+    return strtr($texte, $from, $to);
768 768
 }
769 769
 
770 770
 /**
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
  * @return string|array
777 777
  **/
778 778
 function corriger_caracteres($texte) {
779
-	$texte = corriger_caracteres_windows($texte);
780
-	$texte = supprimer_caracteres_illegaux($texte);
779
+    $texte = corriger_caracteres_windows($texte);
780
+    $texte = supprimer_caracteres_illegaux($texte);
781 781
 
782
-	return $texte;
782
+    return $texte;
783 783
 }
784 784
 
785 785
 /**
@@ -797,40 +797,40 @@  discard block
 block discarded – undo
797 797
  */
798 798
 function texte_backend($texte) {
799 799
 
800
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
800
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
801 801
 
802
-	// si on a des liens ou des images, les passer en absolu
803
-	$texte = liens_absolus($texte);
802
+    // si on a des liens ou des images, les passer en absolu
803
+    $texte = liens_absolus($texte);
804 804
 
805
-	// echapper les tags &gt; &lt;
806
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
805
+    // echapper les tags &gt; &lt;
806
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
807 807
 
808
-	// importer les &eacute;
809
-	$texte = filtrer_entites($texte);
808
+    // importer les &eacute;
809
+    $texte = filtrer_entites($texte);
810 810
 
811
-	// " -> &quot; et tout ce genre de choses
812
-	$u = $GLOBALS['meta']['pcre_u'];
813
-	$texte = str_replace("&nbsp;", " ", $texte);
814
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
815
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
816
-	$texte = entites_html($texte, false, false);
817
-	// mais bien echapper les double quotes !
818
-	$texte = str_replace('"', '&#034;', $texte);
811
+    // " -> &quot; et tout ce genre de choses
812
+    $u = $GLOBALS['meta']['pcre_u'];
813
+    $texte = str_replace("&nbsp;", " ", $texte);
814
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
815
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
816
+    $texte = entites_html($texte, false, false);
817
+    // mais bien echapper les double quotes !
818
+    $texte = str_replace('"', '&#034;', $texte);
819 819
 
820
-	// verifier le charset
821
-	$texte = charset2unicode($texte);
820
+    // verifier le charset
821
+    $texte = charset2unicode($texte);
822 822
 
823
-	// Caracteres problematiques en iso-latin 1
824
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
825
-		$texte = str_replace(chr(156), '&#156;', $texte);
826
-		$texte = str_replace(chr(140), '&#140;', $texte);
827
-		$texte = str_replace(chr(159), '&#159;', $texte);
828
-	}
823
+    // Caracteres problematiques en iso-latin 1
824
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
825
+        $texte = str_replace(chr(156), '&#156;', $texte);
826
+        $texte = str_replace(chr(140), '&#140;', $texte);
827
+        $texte = str_replace(chr(159), '&#159;', $texte);
828
+    }
829 829
 
830
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
831
-	// et le caractere apostrophe alourdit les squelettes avec PHP
832
-	// ==> on les remplace par l'entite HTML
833
-	return str_replace($apostrophe, "'", $texte);
830
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
831
+    // et le caractere apostrophe alourdit les squelettes avec PHP
832
+    // ==> on les remplace par l'entite HTML
833
+    return str_replace($apostrophe, "'", $texte);
834 834
 }
835 835
 
836 836
 /**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
  *     Texte encodé et quote pour XML
848 848
  */
849 849
 function texte_backendq($texte) {
850
-	return addslashes(texte_backend($texte));
850
+    return addslashes(texte_backend($texte));
851 851
 }
852 852
 
853 853
 
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
  *     Numéro de titre, sinon chaîne vide
871 871
  **/
872 872
 function supprimer_numero($texte) {
873
-	return preg_replace(
874
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
875
-		"", $texte);
873
+    return preg_replace(
874
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
875
+        "", $texte);
876 876
 }
877 877
 
878 878
 /**
@@ -895,13 +895,13 @@  discard block
 block discarded – undo
895 895
  *     Numéro de titre, sinon chaîne vide
896 896
  **/
897 897
 function recuperer_numero($texte) {
898
-	if (preg_match(
899
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
900
-		$texte, $regs)) {
901
-		return strval($regs[1]);
902
-	} else {
903
-		return '';
904
-	}
898
+    if (preg_match(
899
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
900
+        $texte, $regs)) {
901
+        return strval($regs[1]);
902
+    } else {
903
+        return '';
904
+    }
905 905
 }
906 906
 
907 907
 /**
@@ -928,13 +928,13 @@  discard block
 block discarded – undo
928 928
  *     Texte converti
929 929
  **/
930 930
 function supprimer_tags($texte, $rempl = "") {
931
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
932
-	// ne pas oublier un < final non ferme car coupe
933
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
934
-	// mais qui peut aussi etre un simple signe plus petit que
935
-	$texte = str_replace('<', '&lt;', $texte);
931
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
932
+    // ne pas oublier un < final non ferme car coupe
933
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
934
+    // mais qui peut aussi etre un simple signe plus petit que
935
+    $texte = str_replace('<', '&lt;', $texte);
936 936
 
937
-	return $texte;
937
+    return $texte;
938 938
 }
939 939
 
940 940
 /**
@@ -957,9 +957,9 @@  discard block
 block discarded – undo
957 957
  *     Texte converti
958 958
  **/
959 959
 function echapper_tags($texte, $rempl = "") {
960
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
960
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
961 961
 
962
-	return $texte;
962
+    return $texte;
963 963
 }
964 964
 
965 965
 /**
@@ -980,18 +980,18 @@  discard block
 block discarded – undo
980 980
  *     Texte converti
981 981
  **/
982 982
 function textebrut($texte) {
983
-	$u = $GLOBALS['meta']['pcre_u'];
984
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
985
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
986
-	$texte = preg_replace("/^\n+/", "", $texte);
987
-	$texte = preg_replace("/\n+$/", "", $texte);
988
-	$texte = preg_replace("/\n +/", "\n", $texte);
989
-	$texte = supprimer_tags($texte);
990
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
991
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
992
-	$texte = str_replace("&#8217;", "'", $texte);
983
+    $u = $GLOBALS['meta']['pcre_u'];
984
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
985
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
986
+    $texte = preg_replace("/^\n+/", "", $texte);
987
+    $texte = preg_replace("/\n+$/", "", $texte);
988
+    $texte = preg_replace("/\n +/", "\n", $texte);
989
+    $texte = supprimer_tags($texte);
990
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
991
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
992
+    $texte = str_replace("&#8217;", "'", $texte);
993 993
 
994
-	return $texte;
994
+    return $texte;
995 995
 }
996 996
 
997 997
 
@@ -1007,17 +1007,17 @@  discard block
 block discarded – undo
1007 1007
  *     Texte avec liens ouvrants
1008 1008
  **/
1009 1009
 function liens_ouvrants($texte) {
1010
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1011
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1012
-		foreach ($liens[0] as $a) {
1013
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1014
-			$ablank = inserer_attribut($a, 'rel', $rel);
1015
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1016
-			$texte = str_replace($a, $ablank, $texte);
1017
-		}
1018
-	}
1010
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1011
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1012
+        foreach ($liens[0] as $a) {
1013
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1014
+            $ablank = inserer_attribut($a, 'rel', $rel);
1015
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1016
+            $texte = str_replace($a, $ablank, $texte);
1017
+        }
1018
+    }
1019 1019
 
1020
-	return $texte;
1020
+    return $texte;
1021 1021
 }
1022 1022
 
1023 1023
 /**
@@ -1027,22 +1027,22 @@  discard block
 block discarded – undo
1027 1027
  * @return string
1028 1028
  */
1029 1029
 function liens_nofollow($texte) {
1030
-	if (stripos($texte, "<a") === false) {
1031
-		return $texte;
1032
-	}
1030
+    if (stripos($texte, "<a") === false) {
1031
+        return $texte;
1032
+    }
1033 1033
 
1034
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1035
-		foreach ($regs[0] as $a) {
1036
-			$rel = extraire_attribut($a, "rel");
1037
-			if (strpos($rel, "nofollow") === false) {
1038
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1039
-				$anofollow = inserer_attribut($a, "rel", $rel);
1040
-				$texte = str_replace($a, $anofollow, $texte);
1041
-			}
1042
-		}
1043
-	}
1034
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1035
+        foreach ($regs[0] as $a) {
1036
+            $rel = extraire_attribut($a, "rel");
1037
+            if (strpos($rel, "nofollow") === false) {
1038
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1039
+                $anofollow = inserer_attribut($a, "rel", $rel);
1040
+                $texte = str_replace($a, $anofollow, $texte);
1041
+            }
1042
+        }
1043
+    }
1044 1044
 
1045
-	return $texte;
1045
+    return $texte;
1046 1046
 }
1047 1047
 
1048 1048
 /**
@@ -1061,12 +1061,12 @@  discard block
 block discarded – undo
1061 1061
  *     Texte sans paraghaphes
1062 1062
  **/
1063 1063
 function PtoBR($texte) {
1064
-	$u = $GLOBALS['meta']['pcre_u'];
1065
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1066
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1067
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1064
+    $u = $GLOBALS['meta']['pcre_u'];
1065
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1066
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1067
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1068 1068
 
1069
-	return $texte;
1069
+    return $texte;
1070 1070
 }
1071 1071
 
1072 1072
 
@@ -1090,14 +1090,14 @@  discard block
 block discarded – undo
1090 1090
  * @return string Texte encadré du style CSS
1091 1091
  */
1092 1092
 function lignes_longues($texte) {
1093
-	if (!strlen(trim($texte))) {
1094
-		return $texte;
1095
-	}
1096
-	include_spip('inc/texte');
1097
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1098
-		'div' : 'span';
1093
+    if (!strlen(trim($texte))) {
1094
+        return $texte;
1095
+    }
1096
+    include_spip('inc/texte');
1097
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1098
+        'div' : 'span';
1099 1099
 
1100
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1100
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1101 1101
 }
1102 1102
 
1103 1103
 /**
@@ -1116,30 +1116,30 @@  discard block
 block discarded – undo
1116 1116
  * @return string Texte en majuscule
1117 1117
  */
1118 1118
 function majuscules($texte) {
1119
-	if (!strlen($texte)) {
1120
-		return '';
1121
-	}
1119
+    if (!strlen($texte)) {
1120
+        return '';
1121
+    }
1122 1122
 
1123
-	// Cas du turc
1124
-	if ($GLOBALS['spip_lang'] == 'tr') {
1125
-		# remplacer hors des tags et des entites
1126
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1127
-			foreach ($regs as $n => $match) {
1128
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1129
-			}
1130
-		}
1123
+    // Cas du turc
1124
+    if ($GLOBALS['spip_lang'] == 'tr') {
1125
+        # remplacer hors des tags et des entites
1126
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1127
+            foreach ($regs as $n => $match) {
1128
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1129
+            }
1130
+        }
1131 1131
 
1132
-		$texte = str_replace('i', '&#304;', $texte);
1132
+        $texte = str_replace('i', '&#304;', $texte);
1133 1133
 
1134
-		if ($regs) {
1135
-			foreach ($regs as $n => $match) {
1136
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1137
-			}
1138
-		}
1139
-	}
1134
+        if ($regs) {
1135
+            foreach ($regs as $n => $match) {
1136
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1137
+            }
1138
+        }
1139
+    }
1140 1140
 
1141
-	// Cas general
1142
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1141
+    // Cas general
1142
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1143 1143
 }
1144 1144
 
1145 1145
 /**
@@ -1157,29 +1157,29 @@  discard block
 block discarded – undo
1157 1157
  * @return string
1158 1158
  **/
1159 1159
 function taille_en_octets($taille) {
1160
-	if (!defined('_KILOBYTE')) {
1161
-		/**
1162
-		 * Définit le nombre d'octets dans un Kilobyte
1163
-		 *
1164
-		 * @var int
1165
-		 **/
1166
-		define('_KILOBYTE', 1024);
1167
-	}
1160
+    if (!defined('_KILOBYTE')) {
1161
+        /**
1162
+         * Définit le nombre d'octets dans un Kilobyte
1163
+         *
1164
+         * @var int
1165
+         **/
1166
+        define('_KILOBYTE', 1024);
1167
+    }
1168 1168
 
1169
-	if ($taille < 1) {
1170
-		return '';
1171
-	}
1172
-	if ($taille < _KILOBYTE) {
1173
-		$taille = _T('taille_octets', array('taille' => $taille));
1174
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1175
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1176
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1177
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1178
-	} else {
1179
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1180
-	}
1169
+    if ($taille < 1) {
1170
+        return '';
1171
+    }
1172
+    if ($taille < _KILOBYTE) {
1173
+        $taille = _T('taille_octets', array('taille' => $taille));
1174
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1175
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1176
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1177
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1178
+    } else {
1179
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1180
+    }
1181 1181
 
1182
-	return $taille;
1182
+    return $taille;
1183 1183
 }
1184 1184
 
1185 1185
 
@@ -1201,15 +1201,15 @@  discard block
 block discarded – undo
1201 1201
  *     Texte prêt pour être utilisé en attribut HTML
1202 1202
  **/
1203 1203
 function attribut_html($texte, $textebrut = true) {
1204
-	$u = $GLOBALS['meta']['pcre_u'];
1205
-	if ($textebrut) {
1206
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1207
-	}
1208
-	$texte = texte_backend($texte);
1209
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1204
+    $u = $GLOBALS['meta']['pcre_u'];
1205
+    if ($textebrut) {
1206
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1207
+    }
1208
+    $texte = texte_backend($texte);
1209
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1210 1210
 
1211
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1212
-		$texte);
1211
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1212
+        $texte);
1213 1213
 }
1214 1214
 
1215 1215
 
@@ -1229,12 +1229,12 @@  discard block
 block discarded – undo
1229 1229
  *     URL ou chaîne vide
1230 1230
  **/
1231 1231
 function vider_url($url, $entites = true) {
1232
-	# un message pour abs_url
1233
-	$GLOBALS['mode_abs_url'] = 'url';
1234
-	$url = trim($url);
1235
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1232
+    # un message pour abs_url
1233
+    $GLOBALS['mode_abs_url'] = 'url';
1234
+    $url = trim($url);
1235
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1236 1236
 
1237
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1237
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1238 1238
 }
1239 1239
 
1240 1240
 
@@ -1249,10 +1249,10 @@  discard block
 block discarded – undo
1249 1249
  * @return string Adresse email maquillée
1250 1250
  **/
1251 1251
 function antispam($texte) {
1252
-	include_spip('inc/acces');
1253
-	$masque = creer_pass_aleatoire(3);
1252
+    include_spip('inc/acces');
1253
+    $masque = creer_pass_aleatoire(3);
1254 1254
 
1255
-	return preg_replace("/@/", " $masque ", $texte);
1255
+    return preg_replace("/@/", " $masque ", $texte);
1256 1256
 }
1257 1257
 
1258 1258
 /**
@@ -1284,12 +1284,12 @@  discard block
 block discarded – undo
1284 1284
  *     True si on a le droit d'accès, false sinon.
1285 1285
  **/
1286 1286
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1287
-	include_spip('inc/acces');
1288
-	if ($op) {
1289
-		$dir .= " $op $args";
1290
-	}
1287
+    include_spip('inc/acces');
1288
+    if ($op) {
1289
+        $dir .= " $op $args";
1290
+    }
1291 1291
 
1292
-	return verifier_low_sec($id_auteur, $cle, $dir);
1292
+    return verifier_low_sec($id_auteur, $cle, $dir);
1293 1293
 }
1294 1294
 
1295 1295
 /**
@@ -1314,11 +1314,11 @@  discard block
 block discarded – undo
1314 1314
  *     Retourne $texte, sinon $sinon.
1315 1315
  **/
1316 1316
 function sinon($texte, $sinon = '') {
1317
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1318
-		return $texte;
1319
-	} else {
1320
-		return $sinon;
1321
-	}
1317
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1318
+        return $texte;
1319
+    } else {
1320
+        return $sinon;
1321
+    }
1322 1322
 }
1323 1323
 
1324 1324
 /**
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
  * @return mixed
1343 1343
  **/
1344 1344
 function choixsivide($a, $vide, $pasvide) {
1345
-	return $a ? $pasvide : $vide;
1345
+    return $a ? $pasvide : $vide;
1346 1346
 }
1347 1347
 
1348 1348
 /**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
  * @return mixed
1367 1367
  **/
1368 1368
 function choixsiegal($a1, $a2, $v, $f) {
1369
-	return ($a1 == $a2) ? $v : $f;
1369
+    return ($a1 == $a2) ? $v : $f;
1370 1370
 }
1371 1371
 
1372 1372
 //
@@ -1385,13 +1385,13 @@  discard block
 block discarded – undo
1385 1385
  * @return string
1386 1386
  **/
1387 1387
 function filtrer_ical($texte) {
1388
-	#include_spip('inc/charsets');
1389
-	$texte = html2unicode($texte);
1390
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1391
-	$texte = preg_replace("/\n/", " ", $texte);
1392
-	$texte = preg_replace("/,/", "\,", $texte);
1388
+    #include_spip('inc/charsets');
1389
+    $texte = html2unicode($texte);
1390
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1391
+    $texte = preg_replace("/\n/", " ", $texte);
1392
+    $texte = preg_replace("/,/", "\,", $texte);
1393 1393
 
1394
-	return $texte;
1394
+    return $texte;
1395 1395
 }
1396 1396
 
1397 1397
 
@@ -1416,53 +1416,53 @@  discard block
 block discarded – undo
1416 1416
  * @return string
1417 1417
  **/
1418 1418
 function post_autobr($texte, $delim = "\n_ ") {
1419
-	if (!function_exists('echappe_html')) {
1420
-		include_spip('inc/texte_mini');
1421
-	}
1422
-	$texte = str_replace("\r\n", "\r", $texte);
1423
-	$texte = str_replace("\r", "\n", $texte);
1424
-
1425
-	if (preg_match(",\n+$,", $texte, $fin)) {
1426
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1427
-	} else {
1428
-		$fin = '';
1429
-	}
1430
-
1431
-	$texte = echappe_html($texte, '', true);
1432
-
1433
-	// echapper les modeles
1434
-	if (strpos($texte, "<") !== false) {
1435
-		include_spip('inc/lien');
1436
-		if (defined('_PREG_MODELE')) {
1437
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1438
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1439
-		}
1440
-	}
1441
-
1442
-	$debut = '';
1443
-	$suite = $texte;
1444
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1445
-		$debut .= substr($suite, 0, $t - 1);
1446
-		$suite = substr($suite, $t);
1447
-		$car = substr($suite, 0, 1);
1448
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1449
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1450
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1451
-		) {
1452
-			$debut .= $delim;
1453
-		} else {
1454
-			$debut .= "\n";
1455
-		}
1456
-		if (preg_match(",^\n+,", $suite, $regs)) {
1457
-			$debut .= $regs[0];
1458
-			$suite = substr($suite, strlen($regs[0]));
1459
-		}
1460
-	}
1461
-	$texte = $debut . $suite;
1462
-
1463
-	$texte = echappe_retour($texte);
1464
-
1465
-	return $texte . $fin;
1419
+    if (!function_exists('echappe_html')) {
1420
+        include_spip('inc/texte_mini');
1421
+    }
1422
+    $texte = str_replace("\r\n", "\r", $texte);
1423
+    $texte = str_replace("\r", "\n", $texte);
1424
+
1425
+    if (preg_match(",\n+$,", $texte, $fin)) {
1426
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1427
+    } else {
1428
+        $fin = '';
1429
+    }
1430
+
1431
+    $texte = echappe_html($texte, '', true);
1432
+
1433
+    // echapper les modeles
1434
+    if (strpos($texte, "<") !== false) {
1435
+        include_spip('inc/lien');
1436
+        if (defined('_PREG_MODELE')) {
1437
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1438
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1439
+        }
1440
+    }
1441
+
1442
+    $debut = '';
1443
+    $suite = $texte;
1444
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1445
+        $debut .= substr($suite, 0, $t - 1);
1446
+        $suite = substr($suite, $t);
1447
+        $car = substr($suite, 0, 1);
1448
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1449
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1450
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1451
+        ) {
1452
+            $debut .= $delim;
1453
+        } else {
1454
+            $debut .= "\n";
1455
+        }
1456
+        if (preg_match(",^\n+,", $suite, $regs)) {
1457
+            $debut .= $regs[0];
1458
+            $suite = substr($suite, strlen($regs[0]));
1459
+        }
1460
+    }
1461
+    $texte = $debut . $suite;
1462
+
1463
+    $texte = echappe_retour($texte);
1464
+
1465
+    return $texte . $fin;
1466 1466
 }
1467 1467
 
1468 1468
 
@@ -1503,46 +1503,46 @@  discard block
 block discarded – undo
1503 1503
  * @return string
1504 1504
  **/
1505 1505
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1506
-	static $traduire = false;
1507
-	if ($letexte
1508
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1509
-	) {
1510
-		if (!$traduire) {
1511
-			$traduire = charger_fonction('traduire', 'inc');
1512
-			include_spip('inc/lang');
1513
-		}
1514
-		if (!$lang) {
1515
-			$lang = $GLOBALS['spip_lang'];
1516
-		}
1517
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1518
-		if (is_bool($options)) {
1519
-			$options = array('echappe_span' => $options);
1520
-		}
1521
-		if (!isset($options['echappe_span'])) {
1522
-			$options = array_merge($options, array('echappe_span' => false));
1523
-		}
1524
-
1525
-		foreach ($regs as $reg) {
1526
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1527
-			$desc = $traduire($cle, $lang, true);
1528
-			$l = $desc->langue;
1529
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1530
-			if (strlen($desc->texte)) {
1531
-				$trad = code_echappement($desc->texte, 'idiome', false);
1532
-				if ($l !== $lang) {
1533
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1534
-				}
1535
-				if (lang_dir($l) !== lang_dir($lang)) {
1536
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1537
-				}
1538
-				if (!$options['echappe_span']) {
1539
-					$trad = echappe_retour($trad, 'idiome');
1540
-				}
1541
-				$letexte = str_replace($reg[0], $trad, $letexte);
1542
-			}
1543
-		}
1544
-	}
1545
-	return $letexte;
1506
+    static $traduire = false;
1507
+    if ($letexte
1508
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1509
+    ) {
1510
+        if (!$traduire) {
1511
+            $traduire = charger_fonction('traduire', 'inc');
1512
+            include_spip('inc/lang');
1513
+        }
1514
+        if (!$lang) {
1515
+            $lang = $GLOBALS['spip_lang'];
1516
+        }
1517
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1518
+        if (is_bool($options)) {
1519
+            $options = array('echappe_span' => $options);
1520
+        }
1521
+        if (!isset($options['echappe_span'])) {
1522
+            $options = array_merge($options, array('echappe_span' => false));
1523
+        }
1524
+
1525
+        foreach ($regs as $reg) {
1526
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1527
+            $desc = $traduire($cle, $lang, true);
1528
+            $l = $desc->langue;
1529
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1530
+            if (strlen($desc->texte)) {
1531
+                $trad = code_echappement($desc->texte, 'idiome', false);
1532
+                if ($l !== $lang) {
1533
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1534
+                }
1535
+                if (lang_dir($l) !== lang_dir($lang)) {
1536
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1537
+                }
1538
+                if (!$options['echappe_span']) {
1539
+                    $trad = echappe_retour($trad, 'idiome');
1540
+                }
1541
+                $letexte = str_replace($reg[0], $trad, $letexte);
1542
+            }
1543
+        }
1544
+    }
1545
+    return $letexte;
1546 1546
 }
1547 1547
 
1548 1548
 /**
@@ -1594,64 +1594,64 @@  discard block
 block discarded – undo
1594 1594
  **/
1595 1595
 function extraire_multi($letexte, $lang = null, $options = array()) {
1596 1596
 
1597
-	if ($letexte
1598
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1599
-	) {
1600
-		if (!$lang) {
1601
-			$lang = $GLOBALS['spip_lang'];
1602
-		}
1603
-
1604
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1605
-		if (is_bool($options)) {
1606
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1607
-		}
1608
-		if (!isset($options['echappe_span'])) {
1609
-			$options = array_merge($options, array('echappe_span' => false));
1610
-		}
1611
-		if (!isset($options['lang_defaut'])) {
1612
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1613
-		}
1614
-
1615
-		include_spip('inc/lang');
1616
-		foreach ($regs as $reg) {
1617
-			// chercher la version de la langue courante
1618
-			$trads = extraire_trads($reg[1]);
1619
-			if ($l = approcher_langue($trads, $lang)) {
1620
-				$trad = $trads[$l];
1621
-			} else {
1622
-				if ($options['lang_defaut'] == 'aucune') {
1623
-					$trad = '';
1624
-				} else {
1625
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1626
-					// ou la premiere dispo
1627
-					// mais typographier le texte selon les regles de celle-ci
1628
-					// Attention aux blocs multi sur plusieurs lignes
1629
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1630
-						$l = key($trads);
1631
-					}
1632
-					$trad = $trads[$l];
1633
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1634
-					$trad = $typographie($trad);
1635
-					// Tester si on echappe en span ou en div
1636
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1637
-					include_spip('inc/texte');
1638
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1639
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1640
-					$trad = code_echappement($trad, 'multi', false, $mode);
1641
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1642
-					if (lang_dir($l) !== lang_dir($lang)) {
1643
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1644
-					}
1645
-					if (!$options['echappe_span']) {
1646
-						$trad = echappe_retour($trad, 'multi');
1647
-					}
1648
-				}
1649
-			}
1650
-			$letexte = str_replace($reg[0], $trad, $letexte);
1651
-		}
1652
-	}
1653
-
1654
-	return $letexte;
1597
+    if ($letexte
1598
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1599
+    ) {
1600
+        if (!$lang) {
1601
+            $lang = $GLOBALS['spip_lang'];
1602
+        }
1603
+
1604
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1605
+        if (is_bool($options)) {
1606
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1607
+        }
1608
+        if (!isset($options['echappe_span'])) {
1609
+            $options = array_merge($options, array('echappe_span' => false));
1610
+        }
1611
+        if (!isset($options['lang_defaut'])) {
1612
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1613
+        }
1614
+
1615
+        include_spip('inc/lang');
1616
+        foreach ($regs as $reg) {
1617
+            // chercher la version de la langue courante
1618
+            $trads = extraire_trads($reg[1]);
1619
+            if ($l = approcher_langue($trads, $lang)) {
1620
+                $trad = $trads[$l];
1621
+            } else {
1622
+                if ($options['lang_defaut'] == 'aucune') {
1623
+                    $trad = '';
1624
+                } else {
1625
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1626
+                    // ou la premiere dispo
1627
+                    // mais typographier le texte selon les regles de celle-ci
1628
+                    // Attention aux blocs multi sur plusieurs lignes
1629
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1630
+                        $l = key($trads);
1631
+                    }
1632
+                    $trad = $trads[$l];
1633
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1634
+                    $trad = $typographie($trad);
1635
+                    // Tester si on echappe en span ou en div
1636
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1637
+                    include_spip('inc/texte');
1638
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1639
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1640
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1641
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1642
+                    if (lang_dir($l) !== lang_dir($lang)) {
1643
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1644
+                    }
1645
+                    if (!$options['echappe_span']) {
1646
+                        $trad = echappe_retour($trad, 'multi');
1647
+                    }
1648
+                }
1649
+            }
1650
+            $letexte = str_replace($reg[0], $trad, $letexte);
1651
+        }
1652
+    }
1653
+
1654
+    return $letexte;
1655 1655
 }
1656 1656
 
1657 1657
 /**
@@ -1667,20 +1667,20 @@  discard block
 block discarded – undo
1667 1667
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1668 1668
  **/
1669 1669
 function extraire_trads($bloc) {
1670
-	$lang = '';
1670
+    $lang = '';
1671 1671
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1672 1672
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1673
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1674
-		$texte = trim($regs[1]);
1675
-		if ($texte or $lang) {
1676
-			$trads[$lang] = $texte;
1677
-		}
1678
-		$bloc = substr($bloc, strlen($regs[0]));
1679
-		$lang = $regs[2];
1680
-	}
1681
-	$trads[$lang] = $bloc;
1673
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1674
+        $texte = trim($regs[1]);
1675
+        if ($texte or $lang) {
1676
+            $trads[$lang] = $texte;
1677
+        }
1678
+        $bloc = substr($bloc, strlen($regs[0]));
1679
+        $lang = $regs[2];
1680
+    }
1681
+    $trads[$lang] = $bloc;
1682 1682
 
1683
-	return $trads;
1683
+    return $trads;
1684 1684
 }
1685 1685
 
1686 1686
 
@@ -1691,7 +1691,7 @@  discard block
 block discarded – undo
1691 1691
  * @return string L'initiale en majuscule
1692 1692
  */
1693 1693
 function filtre_initiale($nom) {
1694
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1694
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1695 1695
 }
1696 1696
 
1697 1697
 
@@ -1736,33 +1736,33 @@  discard block
 block discarded – undo
1736 1736
  *      - null (interne) : si on empile
1737 1737
  **/
1738 1738
 function unique($donnee, $famille = '', $cpt = false) {
1739
-	static $mem = array();
1740
-	// permettre de vider la pile et de la restaurer
1741
-	// pour le calcul de introduction...
1742
-	if ($famille == '_spip_raz_') {
1743
-		$tmp = $mem;
1744
-		$mem = array();
1745
-
1746
-		return $tmp;
1747
-	} elseif ($famille == '_spip_set_') {
1748
-		$mem = $donnee;
1749
-
1750
-		return;
1751
-	}
1752
-	// eviter une notice
1753
-	if (!isset($mem[$famille])) {
1754
-		$mem[$famille] = array();
1755
-	}
1756
-	if ($cpt) {
1757
-		return count($mem[$famille]);
1758
-	}
1759
-	// eviter une notice
1760
-	if (!isset($mem[$famille][$donnee])) {
1761
-		$mem[$famille][$donnee] = 0;
1762
-	}
1763
-	if (!($mem[$famille][$donnee]++)) {
1764
-		return $donnee;
1765
-	}
1739
+    static $mem = array();
1740
+    // permettre de vider la pile et de la restaurer
1741
+    // pour le calcul de introduction...
1742
+    if ($famille == '_spip_raz_') {
1743
+        $tmp = $mem;
1744
+        $mem = array();
1745
+
1746
+        return $tmp;
1747
+    } elseif ($famille == '_spip_set_') {
1748
+        $mem = $donnee;
1749
+
1750
+        return;
1751
+    }
1752
+    // eviter une notice
1753
+    if (!isset($mem[$famille])) {
1754
+        $mem[$famille] = array();
1755
+    }
1756
+    if ($cpt) {
1757
+        return count($mem[$famille]);
1758
+    }
1759
+    // eviter une notice
1760
+    if (!isset($mem[$famille][$donnee])) {
1761
+        $mem[$famille][$donnee] = 0;
1762
+    }
1763
+    if (!($mem[$famille][$donnee]++)) {
1764
+        return $donnee;
1765
+    }
1766 1766
 }
1767 1767
 
1768 1768
 
@@ -1790,18 +1790,18 @@  discard block
 block discarded – undo
1790 1790
  *     Une des valeurs en fonction du compteur.
1791 1791
  **/
1792 1792
 function alterner($i) {
1793
-	// recuperer les arguments (attention fonctions un peu space)
1794
-	$num = func_num_args();
1795
-	$args = func_get_args();
1793
+    // recuperer les arguments (attention fonctions un peu space)
1794
+    $num = func_num_args();
1795
+    $args = func_get_args();
1796 1796
 
1797
-	if ($num == 2 && is_array($args[1])) {
1798
-		$args = $args[1];
1799
-		array_unshift($args, '');
1800
-		$num = count($args);
1801
-	}
1797
+    if ($num == 2 && is_array($args[1])) {
1798
+        $args = $args[1];
1799
+        array_unshift($args, '');
1800
+        $num = count($args);
1801
+    }
1802 1802
 
1803
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1804
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1803
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1804
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1805 1805
 }
1806 1806
 
1807 1807
 
@@ -1826,46 +1826,46 @@  discard block
 block discarded – undo
1826 1826
  *     - Tableau complet (si 2e argument)
1827 1827
  **/
1828 1828
 function extraire_attribut($balise, $attribut, $complet = false) {
1829
-	if (is_array($balise)) {
1830
-		array_walk(
1831
-			$balise,
1832
-			function(&$a, $key, $t){
1833
-				$a = extraire_attribut($a, $t);
1834
-			},
1835
-			$attribut
1836
-		);
1837
-
1838
-		return $balise;
1839
-	}
1840
-	if (preg_match(
1841
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1842
-		. $attribut
1843
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1844
-
1845
-		$balise, $r)) {
1846
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1847
-			$r[4] = substr($r[3], 1, -1);
1848
-			$r[3] = $r[3][0];
1849
-		} elseif ($r[3] !== '') {
1850
-			$r[4] = $r[3];
1851
-			$r[3] = '';
1852
-		} else {
1853
-			$r[4] = trim($r[2]);
1854
-		}
1855
-		$att = $r[4];
1856
-		if (strpos($att, "&#") !== false) {
1857
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1858
-		}
1859
-		$att = filtrer_entites($att);
1860
-	} else {
1861
-		$att = null;
1862
-	}
1863
-
1864
-	if ($complet) {
1865
-		return array($att, $r);
1866
-	} else {
1867
-		return $att;
1868
-	}
1829
+    if (is_array($balise)) {
1830
+        array_walk(
1831
+            $balise,
1832
+            function(&$a, $key, $t){
1833
+                $a = extraire_attribut($a, $t);
1834
+            },
1835
+            $attribut
1836
+        );
1837
+
1838
+        return $balise;
1839
+    }
1840
+    if (preg_match(
1841
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1842
+        . $attribut
1843
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1844
+
1845
+        $balise, $r)) {
1846
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1847
+            $r[4] = substr($r[3], 1, -1);
1848
+            $r[3] = $r[3][0];
1849
+        } elseif ($r[3] !== '') {
1850
+            $r[4] = $r[3];
1851
+            $r[3] = '';
1852
+        } else {
1853
+            $r[4] = trim($r[2]);
1854
+        }
1855
+        $att = $r[4];
1856
+        if (strpos($att, "&#") !== false) {
1857
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1858
+        }
1859
+        $att = filtrer_entites($att);
1860
+    } else {
1861
+        $att = null;
1862
+    }
1863
+
1864
+    if ($complet) {
1865
+        return array($att, $r);
1866
+    } else {
1867
+        return $att;
1868
+    }
1869 1869
 }
1870 1870
 
1871 1871
 /**
@@ -1897,37 +1897,37 @@  discard block
 block discarded – undo
1897 1897
  *     Code html modifié
1898 1898
  **/
1899 1899
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1900
-	// preparer l'attribut
1901
-	// supprimer les &nbsp; etc mais pas les balises html
1902
-	// qui ont un sens dans un attribut value d'un input
1903
-	if ($proteger) {
1904
-		$val = attribut_html($val, false);
1905
-	}
1906
-
1907
-	// echapper les ' pour eviter tout bug
1908
-	$val = str_replace("'", "&#039;", $val);
1909
-	if ($vider and strlen($val) == 0) {
1910
-		$insert = '';
1911
-	} else {
1912
-		$insert = " $attribut='$val'";
1913
-	}
1914
-
1915
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1916
-
1917
-	if ($old !== null) {
1918
-		// Remplacer l'ancien attribut du meme nom
1919
-		$balise = $r[1] . $insert . $r[5];
1920
-	} else {
1921
-		// preferer une balise " />" (comme <img />)
1922
-		if (preg_match(',/>,', $balise)) {
1923
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1924
-		} // sinon une balise <a ...> ... </a>
1925
-		else {
1926
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1927
-		}
1928
-	}
1929
-
1930
-	return $balise;
1900
+    // preparer l'attribut
1901
+    // supprimer les &nbsp; etc mais pas les balises html
1902
+    // qui ont un sens dans un attribut value d'un input
1903
+    if ($proteger) {
1904
+        $val = attribut_html($val, false);
1905
+    }
1906
+
1907
+    // echapper les ' pour eviter tout bug
1908
+    $val = str_replace("'", "&#039;", $val);
1909
+    if ($vider and strlen($val) == 0) {
1910
+        $insert = '';
1911
+    } else {
1912
+        $insert = " $attribut='$val'";
1913
+    }
1914
+
1915
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1916
+
1917
+    if ($old !== null) {
1918
+        // Remplacer l'ancien attribut du meme nom
1919
+        $balise = $r[1] . $insert . $r[5];
1920
+    } else {
1921
+        // preferer une balise " />" (comme <img />)
1922
+        if (preg_match(',/>,', $balise)) {
1923
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1924
+        } // sinon une balise <a ...> ... </a>
1925
+        else {
1926
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1927
+        }
1928
+    }
1929
+
1930
+    return $balise;
1931 1931
 }
1932 1932
 
1933 1933
 /**
@@ -1945,7 +1945,7 @@  discard block
 block discarded – undo
1945 1945
  * @return string Code HTML sans l'attribut
1946 1946
  **/
1947 1947
 function vider_attribut($balise, $attribut) {
1948
-	return inserer_attribut($balise, $attribut, '', false, true);
1948
+    return inserer_attribut($balise, $attribut, '', false, true);
1949 1949
 }
1950 1950
 
1951 1951
 
@@ -1957,9 +1957,9 @@  discard block
 block discarded – undo
1957 1957
  * @return string
1958 1958
  */
1959 1959
 function tester_config($id, $mode = '') {
1960
-	include_spip('action/inscrire_auteur');
1960
+    include_spip('action/inscrire_auteur');
1961 1961
 
1962
-	return tester_statut_inscription($mode, $id);
1962
+    return tester_statut_inscription($mode, $id);
1963 1963
 }
1964 1964
 
1965 1965
 //
@@ -1984,7 +1984,7 @@  discard block
 block discarded – undo
1984 1984
  * @return int $a+$b
1985 1985
  **/
1986 1986
 function plus($a, $b) {
1987
-	return $a + $b;
1987
+    return $a + $b;
1988 1988
 }
1989 1989
 function strplus($a, $b) {return strize('plus', $a, $b);}
1990 1990
 /**
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
  * @return int $a-$b
2004 2004
  **/
2005 2005
 function moins($a, $b) {
2006
-	return $a - $b;
2006
+    return $a - $b;
2007 2007
 }
2008 2008
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2009 2009
 
@@ -2024,7 +2024,7 @@  discard block
 block discarded – undo
2024 2024
  * @return int $a*$b
2025 2025
  **/
2026 2026
 function mult($a, $b) {
2027
-	return $a * $b;
2027
+    return $a * $b;
2028 2028
 }
2029 2029
 function strmult($a, $b) {return strize('mult', $a, $b);}
2030 2030
 
@@ -2045,7 +2045,7 @@  discard block
 block discarded – undo
2045 2045
  * @return int $a/$b (ou 0 si $b est nul)
2046 2046
  **/
2047 2047
 function div($a, $b) {
2048
-	return $b ? $a / $b : 0;
2048
+    return $b ? $a / $b : 0;
2049 2049
 }
2050 2050
 function strdiv($a, $b) {return strize('div', $a, $b);}
2051 2051
 
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
  * @return int ($nb % $mod) + $add
2068 2068
  **/
2069 2069
 function modulo($nb, $mod, $add = 0) {
2070
-	return ($mod ? $nb % $mod : 0) + $add;
2070
+    return ($mod ? $nb % $mod : 0) + $add;
2071 2071
 }
2072 2072
 
2073 2073
 
@@ -2082,24 +2082,24 @@  discard block
 block discarded – undo
2082 2082
  *      - true sinon
2083 2083
  **/
2084 2084
 function nom_acceptable($nom) {
2085
-	if (!is_string($nom)) {
2086
-		return false;
2087
-	}
2088
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2089
-		define('_TAGS_NOM_AUTEUR', '');
2090
-	}
2091
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2092
-	foreach ($tags_acceptes as $tag) {
2093
-		if (strlen($tag)) {
2094
-			$remp1[] = '<' . trim($tag) . '>';
2095
-			$remp1[] = '</' . trim($tag) . '>';
2096
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2097
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2098
-		}
2099
-	}
2100
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2085
+    if (!is_string($nom)) {
2086
+        return false;
2087
+    }
2088
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2089
+        define('_TAGS_NOM_AUTEUR', '');
2090
+    }
2091
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2092
+    foreach ($tags_acceptes as $tag) {
2093
+        if (strlen($tag)) {
2094
+            $remp1[] = '<' . trim($tag) . '>';
2095
+            $remp1[] = '</' . trim($tag) . '>';
2096
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2097
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2098
+        }
2099
+    }
2100
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2101 2101
 
2102
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2102
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2103 2103
 }
2104 2104
 
2105 2105
 
@@ -2113,29 +2113,29 @@  discard block
 block discarded – undo
2113 2113
  *      - la normalisation de la dernière adresse donnée sinon
2114 2114
  **/
2115 2115
 function email_valide($adresses) {
2116
-	// eviter d'injecter n'importe quoi dans preg_match
2117
-	if (!is_string($adresses)) {
2118
-		return false;
2119
-	}
2116
+    // eviter d'injecter n'importe quoi dans preg_match
2117
+    if (!is_string($adresses)) {
2118
+        return false;
2119
+    }
2120 2120
 
2121
-	// Si c'est un spammeur autant arreter tout de suite
2122
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2123
-		spip_log("Tentative d'injection de mail : $adresses");
2121
+    // Si c'est un spammeur autant arreter tout de suite
2122
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2123
+        spip_log("Tentative d'injection de mail : $adresses");
2124 2124
 
2125
-		return false;
2126
-	}
2125
+        return false;
2126
+    }
2127 2127
 
2128
-	foreach (explode(',', $adresses) as $v) {
2129
-		// nettoyer certains formats
2130
-		// "Marie Toto <[email protected]>"
2131
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2132
-		// RFC 822
2133
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2134
-			return false;
2135
-		}
2136
-	}
2128
+    foreach (explode(',', $adresses) as $v) {
2129
+        // nettoyer certains formats
2130
+        // "Marie Toto <[email protected]>"
2131
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2132
+        // RFC 822
2133
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2134
+            return false;
2135
+        }
2136
+    }
2137 2137
 
2138
-	return $adresse;
2138
+    return $adresse;
2139 2139
 }
2140 2140
 
2141 2141
 /**
@@ -2149,20 +2149,20 @@  discard block
 block discarded – undo
2149 2149
  * @return string Texte
2150 2150
  **/
2151 2151
 function afficher_enclosures($tags) {
2152
-	$s = array();
2153
-	foreach (extraire_balises($tags, 'a') as $tag) {
2154
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2155
-			and $t = extraire_attribut($tag, 'href')
2156
-		) {
2157
-			$s[] = preg_replace(',>[^<]+</a>,S',
2158
-				'>'
2159
-				. http_img_pack('attachment-16.png', $t,
2160
-					'title="' . attribut_html($t) . '"')
2161
-				. '</a>', $tag);
2162
-		}
2163
-	}
2152
+    $s = array();
2153
+    foreach (extraire_balises($tags, 'a') as $tag) {
2154
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2155
+            and $t = extraire_attribut($tag, 'href')
2156
+        ) {
2157
+            $s[] = preg_replace(',>[^<]+</a>,S',
2158
+                '>'
2159
+                . http_img_pack('attachment-16.png', $t,
2160
+                    'title="' . attribut_html($t) . '"')
2161
+                . '</a>', $tag);
2162
+        }
2163
+    }
2164 2164
 
2165
-	return join('&nbsp;', $s);
2165
+    return join('&nbsp;', $s);
2166 2166
 }
2167 2167
 
2168 2168
 /**
@@ -2177,15 +2177,15 @@  discard block
 block discarded – undo
2177 2177
  * @return string Liens trouvés
2178 2178
  **/
2179 2179
 function afficher_tags($tags, $rels = 'tag,directory') {
2180
-	$s = array();
2181
-	foreach (extraire_balises($tags, 'a') as $tag) {
2182
-		$rel = extraire_attribut($tag, 'rel');
2183
-		if (strstr(",$rels,", ",$rel,")) {
2184
-			$s[] = $tag;
2185
-		}
2186
-	}
2180
+    $s = array();
2181
+    foreach (extraire_balises($tags, 'a') as $tag) {
2182
+        $rel = extraire_attribut($tag, 'rel');
2183
+        if (strstr(",$rels,", ",$rel,")) {
2184
+            $s[] = $tag;
2185
+        }
2186
+    }
2187 2187
 
2188
-	return join(', ', $s);
2188
+    return join(', ', $s);
2189 2189
 }
2190 2190
 
2191 2191
 
@@ -2207,21 +2207,21 @@  discard block
 block discarded – undo
2207 2207
  * @return string Tag HTML `<a>` avec microformat.
2208 2208
  **/
2209 2209
 function enclosure2microformat($e) {
2210
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2211
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2212
-	}
2213
-	$type = extraire_attribut($e, 'type');
2214
-	if (!$length = extraire_attribut($e, 'length')) {
2215
-		# <media:content : longeur dans fileSize. On tente.
2216
-		$length = extraire_attribut($e, 'fileSize');
2217
-	}
2218
-	$fichier = basename($url);
2210
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2211
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2212
+    }
2213
+    $type = extraire_attribut($e, 'type');
2214
+    if (!$length = extraire_attribut($e, 'length')) {
2215
+        # <media:content : longeur dans fileSize. On tente.
2216
+        $length = extraire_attribut($e, 'fileSize');
2217
+    }
2218
+    $fichier = basename($url);
2219 2219
 
2220
-	return '<a rel="enclosure"'
2221
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2222
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2223
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2224
-	. '>' . $fichier . '</a>';
2220
+    return '<a rel="enclosure"'
2221
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2222
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2223
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2224
+    . '>' . $fichier . '</a>';
2225 2225
 }
2226 2226
 
2227 2227
 /**
@@ -2239,24 +2239,24 @@  discard block
 block discarded – undo
2239 2239
  * @return string Tags RSS `<enclosure>`.
2240 2240
  **/
2241 2241
 function microformat2enclosure($tags) {
2242
-	$enclosures = array();
2243
-	foreach (extraire_balises($tags, 'a') as $e) {
2244
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2245
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2246
-			$type = extraire_attribut($e, 'type');
2247
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2248
-				$length = intval(extraire_attribut($e, 'length'));
2249
-			} # vieux data
2250
-			$fichier = basename($url);
2251
-			$enclosures[] = '<enclosure'
2252
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2253
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2254
-				. ($length ? ' length="' . $length . '"' : '')
2255
-				. ' />';
2256
-		}
2257
-	}
2242
+    $enclosures = array();
2243
+    foreach (extraire_balises($tags, 'a') as $e) {
2244
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2245
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2246
+            $type = extraire_attribut($e, 'type');
2247
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2248
+                $length = intval(extraire_attribut($e, 'length'));
2249
+            } # vieux data
2250
+            $fichier = basename($url);
2251
+            $enclosures[] = '<enclosure'
2252
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2253
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2254
+                . ($length ? ' length="' . $length . '"' : '')
2255
+                . ' />';
2256
+        }
2257
+    }
2258 2258
 
2259
-	return join("\n", $enclosures);
2259
+    return join("\n", $enclosures);
2260 2260
 }
2261 2261
 
2262 2262
 
@@ -2272,16 +2272,16 @@  discard block
 block discarded – undo
2272 2272
  * @return string Tags RSS Atom `<dc:subject>`.
2273 2273
  **/
2274 2274
 function tags2dcsubject($tags) {
2275
-	$subjects = '';
2276
-	foreach (extraire_balises($tags, 'a') as $e) {
2277
-		if (extraire_attribut($e, rel) == 'tag') {
2278
-			$subjects .= '<dc:subject>'
2279
-				. texte_backend(textebrut($e))
2280
-				. '</dc:subject>' . "\n";
2281
-		}
2282
-	}
2275
+    $subjects = '';
2276
+    foreach (extraire_balises($tags, 'a') as $e) {
2277
+        if (extraire_attribut($e, rel) == 'tag') {
2278
+            $subjects .= '<dc:subject>'
2279
+                . texte_backend(textebrut($e))
2280
+                . '</dc:subject>' . "\n";
2281
+        }
2282
+    }
2283 2283
 
2284
-	return $subjects;
2284
+    return $subjects;
2285 2285
 }
2286 2286
 
2287 2287
 /**
@@ -2310,23 +2310,23 @@  discard block
 block discarded – undo
2310 2310
  *     - Tableau de résultats, si tableau en entrée.
2311 2311
  **/
2312 2312
 function extraire_balise($texte, $tag = 'a') {
2313
-	if (is_array($texte)) {
2314
-		array_walk(
2315
-			$texte,
2316
-			function(&$a, $key, $t){
2317
-				$a = extraire_balise($a, $t);
2318
-			},
2319
-			$tag
2320
-		);
2313
+    if (is_array($texte)) {
2314
+        array_walk(
2315
+            $texte,
2316
+            function(&$a, $key, $t){
2317
+                $a = extraire_balise($a, $t);
2318
+            },
2319
+            $tag
2320
+        );
2321 2321
 
2322
-		return $texte;
2323
-	}
2322
+        return $texte;
2323
+    }
2324 2324
 
2325
-	if (preg_match(
2326
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2327
-		$texte, $regs)) {
2328
-		return $regs[0];
2329
-	}
2325
+    if (preg_match(
2326
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2327
+        $texte, $regs)) {
2328
+        return $regs[0];
2329
+    }
2330 2330
 }
2331 2331
 
2332 2332
 /**
@@ -2354,25 +2354,25 @@  discard block
 block discarded – undo
2354 2354
  *     - Tableau de résultats, si tableau en entrée.
2355 2355
  **/
2356 2356
 function extraire_balises($texte, $tag = 'a') {
2357
-	if (is_array($texte)) {
2358
-		array_walk(
2359
-			$texte,
2360
-			function(&$a, $key, $t){
2361
-				$a = extraire_balises($a, $t);
2362
-			},
2363
-			$tag
2364
-		);
2357
+    if (is_array($texte)) {
2358
+        array_walk(
2359
+            $texte,
2360
+            function(&$a, $key, $t){
2361
+                $a = extraire_balises($a, $t);
2362
+            },
2363
+            $tag
2364
+        );
2365 2365
 
2366
-		return $texte;
2367
-	}
2366
+        return $texte;
2367
+    }
2368 2368
 
2369
-	if (preg_match_all(
2370
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2371
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2372
-		return $regs[0];
2373
-	} else {
2374
-		return array();
2375
-	}
2369
+    if (preg_match_all(
2370
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2371
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2372
+        return $regs[0];
2373
+    } else {
2374
+        return array();
2375
+    }
2376 2376
 }
2377 2377
 
2378 2378
 /**
@@ -2401,11 +2401,11 @@  discard block
 block discarded – undo
2401 2401
  *     - `$def` si on n'a pas transmis de tableau
2402 2402
  **/
2403 2403
 function in_any($val, $vals, $def = '') {
2404
-	if (!is_array($vals) and $v = unserialize($vals)) {
2405
-		$vals = $v;
2406
-	}
2404
+    if (!is_array($vals) and $v = unserialize($vals)) {
2405
+        $vals = $v;
2406
+    }
2407 2407
 
2408
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2408
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2409 2409
 }
2410 2410
 
2411 2411
 
@@ -2426,12 +2426,12 @@  discard block
 block discarded – undo
2426 2426
  *     Résultat du calcul
2427 2427
  **/
2428 2428
 function valeur_numerique($expr) {
2429
-	$a = 0;
2430
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2431
-		eval("\$a = $expr;");
2432
-	}
2429
+    $a = 0;
2430
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2431
+        eval("\$a = $expr;");
2432
+    }
2433 2433
 
2434
-	return intval($a);
2434
+    return intval($a);
2435 2435
 }
2436 2436
 
2437 2437
 /**
@@ -2450,7 +2450,7 @@  discard block
 block discarded – undo
2450 2450
  *      Retourne `$a*$b/$c`
2451 2451
  **/
2452 2452
 function regledetrois($a, $b, $c) {
2453
-	return round($a * $b / $c);
2453
+    return round($a * $b / $c);
2454 2454
 }
2455 2455
 
2456 2456
 
@@ -2474,76 +2474,76 @@  discard block
 block discarded – undo
2474 2474
  **/
2475 2475
 function form_hidden($action) {
2476 2476
 
2477
-	$contexte = array();
2478
-	include_spip('inc/urls');
2479
-	if ($p = urls_decoder_url($action, '')
2480
-		and reset($p)
2481
-	) {
2482
-		$fond = array_shift($p);
2483
-		if ($fond != '404') {
2484
-			$contexte = array_shift($p);
2485
-			$contexte['page'] = $fond;
2486
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2487
-		}
2488
-	}
2489
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2490
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2491
-		unset($contexte['type']);
2492
-	}
2493
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2494
-		unset($contexte['type-page']);
2495
-	}
2496
-
2497
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2498
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2499
-	$values = array();
2500
-
2501
-	// d'abord avec celles de l'url
2502
-	if (false !== ($p = strpos($action, '?'))) {
2503
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2504
-			$c = explode('=', $c, 2);
2505
-			$var = array_shift($c);
2506
-			$val = array_shift($c);
2507
-			if ($var) {
2508
-				$val = rawurldecode($val);
2509
-				$var = rawurldecode($var); // decoder les [] eventuels
2510
-				if (preg_match(',\[\]$,S', $var)) {
2511
-					$values[] = array($var, $val);
2512
-				} else {
2513
-					if (!isset($values[$var])) {
2514
-						$values[$var] = array($var, $val);
2515
-					}
2516
-				}
2517
-			}
2518
-		}
2519
-	}
2520
-
2521
-	// ensuite avec celles du contexte, sans doublonner !
2522
-	foreach ($contexte as $var => $val) {
2523
-		if (preg_match(',\[\]$,S', $var)) {
2524
-			$values[] = array($var, $val);
2525
-		} else {
2526
-			if (!isset($values[$var])) {
2527
-				$values[$var] = array($var, $val);
2528
-			}
2529
-		}
2530
-	}
2531
-
2532
-	// puis on rassemble le tout
2533
-	$hidden = array();
2534
-	foreach ($values as $value) {
2535
-		list($var, $val) = $value;
2536
-		$hidden[] = '<input name="'
2537
-			. entites_html($var)
2538
-			. '"'
2539
-			. (is_null($val)
2540
-				? ''
2541
-				: ' value="' . entites_html($val) . '"'
2542
-			)
2543
-			. ' type="hidden"' . "\n/>";
2544
-	}
2545
-
2546
-	return join("", $hidden);
2477
+    $contexte = array();
2478
+    include_spip('inc/urls');
2479
+    if ($p = urls_decoder_url($action, '')
2480
+        and reset($p)
2481
+    ) {
2482
+        $fond = array_shift($p);
2483
+        if ($fond != '404') {
2484
+            $contexte = array_shift($p);
2485
+            $contexte['page'] = $fond;
2486
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2487
+        }
2488
+    }
2489
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2490
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2491
+        unset($contexte['type']);
2492
+    }
2493
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2494
+        unset($contexte['type-page']);
2495
+    }
2496
+
2497
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2498
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2499
+    $values = array();
2500
+
2501
+    // d'abord avec celles de l'url
2502
+    if (false !== ($p = strpos($action, '?'))) {
2503
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2504
+            $c = explode('=', $c, 2);
2505
+            $var = array_shift($c);
2506
+            $val = array_shift($c);
2507
+            if ($var) {
2508
+                $val = rawurldecode($val);
2509
+                $var = rawurldecode($var); // decoder les [] eventuels
2510
+                if (preg_match(',\[\]$,S', $var)) {
2511
+                    $values[] = array($var, $val);
2512
+                } else {
2513
+                    if (!isset($values[$var])) {
2514
+                        $values[$var] = array($var, $val);
2515
+                    }
2516
+                }
2517
+            }
2518
+        }
2519
+    }
2520
+
2521
+    // ensuite avec celles du contexte, sans doublonner !
2522
+    foreach ($contexte as $var => $val) {
2523
+        if (preg_match(',\[\]$,S', $var)) {
2524
+            $values[] = array($var, $val);
2525
+        } else {
2526
+            if (!isset($values[$var])) {
2527
+                $values[$var] = array($var, $val);
2528
+            }
2529
+        }
2530
+    }
2531
+
2532
+    // puis on rassemble le tout
2533
+    $hidden = array();
2534
+    foreach ($values as $value) {
2535
+        list($var, $val) = $value;
2536
+        $hidden[] = '<input name="'
2537
+            . entites_html($var)
2538
+            . '"'
2539
+            . (is_null($val)
2540
+                ? ''
2541
+                : ' value="' . entites_html($val) . '"'
2542
+            )
2543
+            . ' type="hidden"' . "\n/>";
2544
+    }
2545
+
2546
+    return join("", $hidden);
2547 2547
 }
2548 2548
 
2549 2549
 /**
@@ -2561,15 +2561,15 @@  discard block
 block discarded – undo
2561 2561
  *     Liste (première page, dernière page).
2562 2562
  **/
2563 2563
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2564
-	if ($max <= 0 or $max >= $nombre) {
2565
-		return array(1, $nombre);
2566
-	}
2564
+    if ($max <= 0 or $max >= $nombre) {
2565
+        return array(1, $nombre);
2566
+    }
2567 2567
 
2568
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2569
-	$derniere = min($nombre, $premiere + $max - 2);
2570
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2568
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2569
+    $derniere = min($nombre, $premiere + $max - 2);
2570
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2571 2571
 
2572
-	return array($premiere, $derniere);
2572
+    return array($premiere, $derniere);
2573 2573
 }
2574 2574
 
2575 2575
 
@@ -2591,7 +2591,7 @@  discard block
 block discarded – undo
2591 2591
  *    - la première valeur du tableau sinon.
2592 2592
  **/
2593 2593
 function filtre_reset($array) {
2594
-	return !is_array($array) ? null : reset($array);
2594
+    return !is_array($array) ? null : reset($array);
2595 2595
 }
2596 2596
 
2597 2597
 /**
@@ -2612,7 +2612,7 @@  discard block
 block discarded – undo
2612 2612
  *    - la dernière valeur du tableau sinon.
2613 2613
  **/
2614 2614
 function filtre_end($array) {
2615
-	return !is_array($array) ? null : end($array);
2615
+    return !is_array($array) ? null : end($array);
2616 2616
 }
2617 2617
 
2618 2618
 /**
@@ -2632,11 +2632,11 @@  discard block
 block discarded – undo
2632 2632
  *
2633 2633
  **/
2634 2634
 function filtre_push($array, $val) {
2635
-	if (!is_array($array) or !array_push($array, $val)) {
2636
-		return '';
2637
-	}
2635
+    if (!is_array($array) or !array_push($array, $val)) {
2636
+        return '';
2637
+    }
2638 2638
 
2639
-	return $array;
2639
+    return $array;
2640 2640
 }
2641 2641
 
2642 2642
 /**
@@ -2655,7 +2655,7 @@  discard block
 block discarded – undo
2655 2655
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2656 2656
  **/
2657 2657
 function filtre_find($array, $val) {
2658
-	return (is_array($array) and in_array($val, $array));
2658
+    return (is_array($array) and in_array($val, $array));
2659 2659
 }
2660 2660
 
2661 2661
 
@@ -2690,59 +2690,59 @@  discard block
 block discarded – undo
2690 2690
  *     Code HTML de la pagination
2691 2691
  **/
2692 2692
 function filtre_pagination_dist(
2693
-	$total,
2694
-	$nom,
2695
-	$position,
2696
-	$pas,
2697
-	$liste = true,
2698
-	$modele = '',
2699
-	$connect = '',
2700
-	$env = array()
2693
+    $total,
2694
+    $nom,
2695
+    $position,
2696
+    $pas,
2697
+    $liste = true,
2698
+    $modele = '',
2699
+    $connect = '',
2700
+    $env = array()
2701 2701
 ) {
2702
-	static $ancres = array();
2703
-	if ($pas < 1) {
2704
-		return '';
2705
-	}
2706
-	$ancre = 'pagination' . $nom; // #pagination_articles
2707
-	$debut = 'debut' . $nom; // 'debut_articles'
2708
-
2709
-	// n'afficher l'ancre qu'une fois
2710
-	if (!isset($ancres[$ancre])) {
2711
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2712
-	} else {
2713
-		$bloc_ancre = '';
2714
-	}
2715
-	// liste = false : on ne veut que l'ancre
2716
-	if (!$liste) {
2717
-		return $ancres[$ancre];
2718
-	}
2719
-
2720
-	$self = (empty($env['self']) ? self() : $env['self']);
2721
-	$pagination = array(
2722
-		'debut' => $debut,
2723
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2724
-		'total' => $total,
2725
-		'position' => intval($position),
2726
-		'pas' => $pas,
2727
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
2728
-		'page_courante' => floor(intval($position) / $pas) + 1,
2729
-		'ancre' => $ancre,
2730
-		'bloc_ancre' => $bloc_ancre
2731
-	);
2732
-	if (is_array($env)) {
2733
-		$pagination = array_merge($env, $pagination);
2734
-	}
2735
-
2736
-	// Pas de pagination
2737
-	if ($pagination['nombre_pages'] <= 1) {
2738
-		return '';
2739
-	}
2740
-
2741
-	if ($modele) {
2742
-		$modele = '_' . $modele;
2743
-	}
2744
-
2745
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2702
+    static $ancres = array();
2703
+    if ($pas < 1) {
2704
+        return '';
2705
+    }
2706
+    $ancre = 'pagination' . $nom; // #pagination_articles
2707
+    $debut = 'debut' . $nom; // 'debut_articles'
2708
+
2709
+    // n'afficher l'ancre qu'une fois
2710
+    if (!isset($ancres[$ancre])) {
2711
+        $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2712
+    } else {
2713
+        $bloc_ancre = '';
2714
+    }
2715
+    // liste = false : on ne veut que l'ancre
2716
+    if (!$liste) {
2717
+        return $ancres[$ancre];
2718
+    }
2719
+
2720
+    $self = (empty($env['self']) ? self() : $env['self']);
2721
+    $pagination = array(
2722
+        'debut' => $debut,
2723
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2724
+        'total' => $total,
2725
+        'position' => intval($position),
2726
+        'pas' => $pas,
2727
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
2728
+        'page_courante' => floor(intval($position) / $pas) + 1,
2729
+        'ancre' => $ancre,
2730
+        'bloc_ancre' => $bloc_ancre
2731
+    );
2732
+    if (is_array($env)) {
2733
+        $pagination = array_merge($env, $pagination);
2734
+    }
2735
+
2736
+    // Pas de pagination
2737
+    if ($pagination['nombre_pages'] <= 1) {
2738
+        return '';
2739
+    }
2740
+
2741
+    if ($modele) {
2742
+        $modele = '_' . $modele;
2743
+    }
2744
+
2745
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2746 2746
 }
2747 2747
 
2748 2748
 
@@ -2759,15 +2759,15 @@  discard block
 block discarded – undo
2759 2759
  *     Contenu avec urls en absolus
2760 2760
  **/
2761 2761
 function urls_absolues_css($contenu, $source) {
2762
-	$path = suivre_lien(url_absolue($source), './');
2762
+    $path = suivre_lien(url_absolue($source), './');
2763 2763
 
2764
-	return preg_replace_callback(
2765
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2766
-		function($x) use ($path) {
2767
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2768
-		},
2769
-		$contenu
2770
-	);
2764
+    return preg_replace_callback(
2765
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2766
+        function($x) use ($path) {
2767
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2768
+        },
2769
+        $contenu
2770
+    );
2771 2771
 }
2772 2772
 
2773 2773
 
@@ -2796,118 +2796,118 @@  discard block
 block discarded – undo
2796 2796
  *     Chemin du fichier CSS inversé
2797 2797
  **/
2798 2798
 function direction_css($css, $voulue = '') {
2799
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2800
-		return $css;
2801
-	}
2802
-
2803
-	// si on a precise le sens voulu en argument, le prendre en compte
2804
-	if ($voulue = strtolower($voulue)) {
2805
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2806
-			$voulue = lang_dir($voulue);
2807
-		}
2808
-	} else {
2809
-		$voulue = lang_dir();
2810
-	}
2811
-
2812
-	$r = count($r) > 1;
2813
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2814
-	$dir = $r ? 'rtl' : 'ltr';
2815
-	$ndir = $r ? 'ltr' : 'rtl';
2816
-
2817
-	if ($voulue == $dir) {
2818
-		return $css;
2819
-	}
2820
-
2821
-	if (
2822
-		// url absolue
2823
-		preg_match(",^https?:,i", $css)
2824
-		// ou qui contient un ?
2825
-		or (($p = strpos($css, '?')) !== false)
2826
-	) {
2827
-		$distant = true;
2828
-		$cssf = parse_url($css);
2829
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2830
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2831
-	} else {
2832
-		$distant = false;
2833
-		$cssf = $css;
2834
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2835
-		//propose (rien a faire dans ce cas)
2836
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2837
-		if (@file_exists($f)) {
2838
-			return $f;
2839
-		}
2840
-	}
2841
-
2842
-	// 2.
2843
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2844
-	$f = $dir_var
2845
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2846
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2847
-
2848
-	// la css peut etre distante (url absolue !)
2849
-	if ($distant) {
2850
-		include_spip('inc/distant');
2851
-		$res = recuperer_url($css);
2852
-		if (!$res or !$contenu = $res['page']) {
2853
-			return $css;
2854
-		}
2855
-	} else {
2856
-		if ((@filemtime($f) > @filemtime($css))
2857
-			and (_VAR_MODE != 'recalcul')
2858
-		) {
2859
-			return $f;
2860
-		}
2861
-		if (!lire_fichier($css, $contenu)) {
2862
-			return $css;
2863
-		}
2864
-	}
2865
-
2866
-
2867
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2868
-	include_spip("lib/csstidy/class.csstidy");
2869
-	$parser = new csstidy();
2870
-	$parser->set_cfg('optimise_shorthands', 0);
2871
-	$parser->set_cfg('reverse_left_and_right', true);
2872
-	$parser->parse($contenu);
2873
-
2874
-	$contenu = $parser->print->plain();
2875
-
2876
-
2877
-	// reperer les @import auxquels il faut propager le direction_css
2878
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2879
-	$src = array();
2880
-	$src_direction_css = array();
2881
-	$src_faux_abs = array();
2882
-	$d = dirname($css);
2883
-	foreach ($regs[1] as $k => $import_css) {
2884
-		$css_direction = direction_css("$d/$import_css", $voulue);
2885
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2886
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2887
-			$css_direction = substr($css_direction, strlen($d) + 1);
2888
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2889
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2890
-			$css_direction = substr($css_direction, strlen($dir_var));
2891
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2892
-			$css_direction = "/@@@@@@/" . $css_direction;
2893
-		}
2894
-		$src[] = $regs[0][$k];
2895
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2896
-	}
2897
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2898
-
2899
-	$contenu = urls_absolues_css($contenu, $css);
2900
-
2901
-	// virer les fausses url absolues que l'on a mis dans les import
2902
-	if (count($src_faux_abs)) {
2903
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2904
-	}
2905
-
2906
-	if (!ecrire_fichier($f, $contenu)) {
2907
-		return $css;
2908
-	}
2909
-
2910
-	return $f;
2799
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2800
+        return $css;
2801
+    }
2802
+
2803
+    // si on a precise le sens voulu en argument, le prendre en compte
2804
+    if ($voulue = strtolower($voulue)) {
2805
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2806
+            $voulue = lang_dir($voulue);
2807
+        }
2808
+    } else {
2809
+        $voulue = lang_dir();
2810
+    }
2811
+
2812
+    $r = count($r) > 1;
2813
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2814
+    $dir = $r ? 'rtl' : 'ltr';
2815
+    $ndir = $r ? 'ltr' : 'rtl';
2816
+
2817
+    if ($voulue == $dir) {
2818
+        return $css;
2819
+    }
2820
+
2821
+    if (
2822
+        // url absolue
2823
+        preg_match(",^https?:,i", $css)
2824
+        // ou qui contient un ?
2825
+        or (($p = strpos($css, '?')) !== false)
2826
+    ) {
2827
+        $distant = true;
2828
+        $cssf = parse_url($css);
2829
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2830
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2831
+    } else {
2832
+        $distant = false;
2833
+        $cssf = $css;
2834
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2835
+        //propose (rien a faire dans ce cas)
2836
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2837
+        if (@file_exists($f)) {
2838
+            return $f;
2839
+        }
2840
+    }
2841
+
2842
+    // 2.
2843
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2844
+    $f = $dir_var
2845
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2846
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2847
+
2848
+    // la css peut etre distante (url absolue !)
2849
+    if ($distant) {
2850
+        include_spip('inc/distant');
2851
+        $res = recuperer_url($css);
2852
+        if (!$res or !$contenu = $res['page']) {
2853
+            return $css;
2854
+        }
2855
+    } else {
2856
+        if ((@filemtime($f) > @filemtime($css))
2857
+            and (_VAR_MODE != 'recalcul')
2858
+        ) {
2859
+            return $f;
2860
+        }
2861
+        if (!lire_fichier($css, $contenu)) {
2862
+            return $css;
2863
+        }
2864
+    }
2865
+
2866
+
2867
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2868
+    include_spip("lib/csstidy/class.csstidy");
2869
+    $parser = new csstidy();
2870
+    $parser->set_cfg('optimise_shorthands', 0);
2871
+    $parser->set_cfg('reverse_left_and_right', true);
2872
+    $parser->parse($contenu);
2873
+
2874
+    $contenu = $parser->print->plain();
2875
+
2876
+
2877
+    // reperer les @import auxquels il faut propager le direction_css
2878
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2879
+    $src = array();
2880
+    $src_direction_css = array();
2881
+    $src_faux_abs = array();
2882
+    $d = dirname($css);
2883
+    foreach ($regs[1] as $k => $import_css) {
2884
+        $css_direction = direction_css("$d/$import_css", $voulue);
2885
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2886
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2887
+            $css_direction = substr($css_direction, strlen($d) + 1);
2888
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2889
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2890
+            $css_direction = substr($css_direction, strlen($dir_var));
2891
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2892
+            $css_direction = "/@@@@@@/" . $css_direction;
2893
+        }
2894
+        $src[] = $regs[0][$k];
2895
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2896
+    }
2897
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2898
+
2899
+    $contenu = urls_absolues_css($contenu, $css);
2900
+
2901
+    // virer les fausses url absolues que l'on a mis dans les import
2902
+    if (count($src_faux_abs)) {
2903
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2904
+    }
2905
+
2906
+    if (!ecrire_fichier($f, $contenu)) {
2907
+        return $css;
2908
+    }
2909
+
2910
+    return $f;
2911 2911
 }
2912 2912
 
2913 2913
 
@@ -2930,43 +2930,43 @@  discard block
 block discarded – undo
2930 2930
  *     - Chemin ou URL du fichier CSS source sinon.
2931 2931
  **/
2932 2932
 function url_absolue_css($css) {
2933
-	if (!preg_match(',\.css$,i', $css, $r)) {
2934
-		return $css;
2935
-	}
2933
+    if (!preg_match(',\.css$,i', $css, $r)) {
2934
+        return $css;
2935
+    }
2936 2936
 
2937
-	$url_absolue_css = url_absolue($css);
2937
+    $url_absolue_css = url_absolue($css);
2938 2938
 
2939
-	$f = basename($css, '.css');
2940
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2941
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2942
-		. '.css';
2939
+    $f = basename($css, '.css');
2940
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2941
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2942
+        . '.css';
2943 2943
 
2944
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2945
-		return $f;
2946
-	}
2944
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2945
+        return $f;
2946
+    }
2947 2947
 
2948
-	if ($url_absolue_css == $css) {
2949
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2950
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2951
-		) {
2952
-			include_spip('inc/distant');
2953
-			if (!$contenu = recuperer_page($css)) {
2954
-				return $css;
2955
-			}
2956
-		}
2957
-	} elseif (!lire_fichier($css, $contenu)) {
2958
-		return $css;
2959
-	}
2948
+    if ($url_absolue_css == $css) {
2949
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2950
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2951
+        ) {
2952
+            include_spip('inc/distant');
2953
+            if (!$contenu = recuperer_page($css)) {
2954
+                return $css;
2955
+            }
2956
+        }
2957
+    } elseif (!lire_fichier($css, $contenu)) {
2958
+        return $css;
2959
+    }
2960 2960
 
2961
-	// passer les url relatives a la css d'origine en url absolues
2962
-	$contenu = urls_absolues_css($contenu, $css);
2961
+    // passer les url relatives a la css d'origine en url absolues
2962
+    $contenu = urls_absolues_css($contenu, $css);
2963 2963
 
2964
-	// ecrire la css
2965
-	if (!ecrire_fichier($f, $contenu)) {
2966
-		return $css;
2967
-	}
2964
+    // ecrire la css
2965
+    if (!ecrire_fichier($f, $contenu)) {
2966
+        return $css;
2967
+    }
2968 2968
 
2969
-	return $f;
2969
+    return $f;
2970 2970
 }
2971 2971
 
2972 2972
 
@@ -3000,24 +3000,24 @@  discard block
 block discarded – undo
3000 3000
  *     Valeur trouvée ou valeur par défaut.
3001 3001
  **/
3002 3002
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3003
-	foreach (explode('/', $cle) as $k) {
3003
+    foreach (explode('/', $cle) as $k) {
3004 3004
 
3005
-		$table = is_string($table) ? @unserialize($table) : $table;
3005
+        $table = is_string($table) ? @unserialize($table) : $table;
3006 3006
 
3007
-		if (is_object($table)) {
3008
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3009
-		} elseif (is_array($table)) {
3010
-			if ($conserver_null) {
3011
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3012
-			} else {
3013
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3014
-			}
3015
-		} else {
3016
-			$table = $defaut;
3017
-		}
3018
-	}
3007
+        if (is_object($table)) {
3008
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3009
+        } elseif (is_array($table)) {
3010
+            if ($conserver_null) {
3011
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3012
+            } else {
3013
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3014
+            }
3015
+        } else {
3016
+            $table = $defaut;
3017
+        }
3018
+    }
3019 3019
 
3020
-	return $table;
3020
+    return $table;
3021 3021
 }
3022 3022
 
3023 3023
 /**
@@ -3050,22 +3050,22 @@  discard block
 block discarded – undo
3050 3050
  *     - string : expression trouvée.
3051 3051
  **/
3052 3052
 function match($texte, $expression, $modif = "UimsS", $capte = 0) {
3053
-	if (intval($modif) and $capte == 0) {
3054
-		$capte = $modif;
3055
-		$modif = "UimsS";
3056
-	}
3057
-	$expression = str_replace("\/", "/", $expression);
3058
-	$expression = str_replace("/", "\/", $expression);
3053
+    if (intval($modif) and $capte == 0) {
3054
+        $capte = $modif;
3055
+        $modif = "UimsS";
3056
+    }
3057
+    $expression = str_replace("\/", "/", $expression);
3058
+    $expression = str_replace("/", "\/", $expression);
3059 3059
 
3060
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3061
-		if (isset($r[$capte])) {
3062
-			return $r[$capte];
3063
-		} else {
3064
-			return true;
3065
-		}
3066
-	}
3060
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3061
+        if (isset($r[$capte])) {
3062
+            return $r[$capte];
3063
+        } else {
3064
+            return true;
3065
+        }
3066
+    }
3067 3067
 
3068
-	return false;
3068
+    return false;
3069 3069
 }
3070 3070
 
3071 3071
 
@@ -3092,10 +3092,10 @@  discard block
 block discarded – undo
3092 3092
  *     Texte
3093 3093
  **/
3094 3094
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3095
-	$expression = str_replace("\/", "/", $expression);
3096
-	$expression = str_replace("/", "\/", $expression);
3095
+    $expression = str_replace("\/", "/", $expression);
3096
+    $expression = str_replace("/", "\/", $expression);
3097 3097
 
3098
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3098
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3099 3099
 }
3100 3100
 
3101 3101
 
@@ -3113,21 +3113,21 @@  discard block
 block discarded – undo
3113 3113
  **/
3114 3114
 function traiter_doublons_documents(&$doublons, $letexte) {
3115 3115
 
3116
-	// Verifier dans le texte & les notes (pas beau, helas)
3117
-	$t = $letexte . $GLOBALS['les_notes'];
3116
+    // Verifier dans le texte & les notes (pas beau, helas)
3117
+    $t = $letexte . $GLOBALS['les_notes'];
3118 3118
 
3119
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3120
-		and preg_match_all(
3121
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3122
-			$t, $matches, PREG_PATTERN_ORDER)
3123
-	) {
3124
-		if (!isset($doublons['documents'])) {
3125
-			$doublons['documents'] = "";
3126
-		}
3127
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3128
-	}
3119
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3120
+        and preg_match_all(
3121
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3122
+            $t, $matches, PREG_PATTERN_ORDER)
3123
+    ) {
3124
+        if (!isset($doublons['documents'])) {
3125
+            $doublons['documents'] = "";
3126
+        }
3127
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3128
+    }
3129 3129
 
3130
-	return $letexte;
3130
+    return $letexte;
3131 3131
 }
3132 3132
 
3133 3133
 /**
@@ -3141,7 +3141,7 @@  discard block
 block discarded – undo
3141 3141
  * @return string Chaîne vide
3142 3142
  **/
3143 3143
 function vide($texte) {
3144
-	return "";
3144
+    return "";
3145 3145
 }
3146 3146
 
3147 3147
 //
@@ -3170,23 +3170,23 @@  discard block
 block discarded – undo
3170 3170
  *      Code HTML résultant
3171 3171
  **/
3172 3172
 function env_to_params($env, $ignore_params = array()) {
3173
-	$ignore_params = array_merge(
3174
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3175
-		$ignore_params
3176
-	);
3177
-	if (!is_array($env)) {
3178
-		$env = unserialize($env);
3179
-	}
3180
-	$texte = "";
3181
-	if ($env) {
3182
-		foreach ($env as $i => $j) {
3183
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3184
-				$texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3185
-			}
3186
-		}
3187
-	}
3188
-
3189
-	return $texte;
3173
+    $ignore_params = array_merge(
3174
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3175
+        $ignore_params
3176
+    );
3177
+    if (!is_array($env)) {
3178
+        $env = unserialize($env);
3179
+    }
3180
+    $texte = "";
3181
+    if ($env) {
3182
+        foreach ($env as $i => $j) {
3183
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3184
+                $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3185
+            }
3186
+        }
3187
+    }
3188
+
3189
+    return $texte;
3190 3190
 }
3191 3191
 
3192 3192
 /**
@@ -3209,23 +3209,23 @@  discard block
 block discarded – undo
3209 3209
  *      Code HTML résultant
3210 3210
  **/
3211 3211
 function env_to_attributs($env, $ignore_params = array()) {
3212
-	$ignore_params = array_merge(
3213
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3214
-		$ignore_params
3215
-	);
3216
-	if (!is_array($env)) {
3217
-		$env = unserialize($env);
3218
-	}
3219
-	$texte = "";
3220
-	if ($env) {
3221
-		foreach ($env as $i => $j) {
3222
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3223
-				$texte .= $i . "='" . $j . "' ";
3224
-			}
3225
-		}
3226
-	}
3212
+    $ignore_params = array_merge(
3213
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3214
+        $ignore_params
3215
+    );
3216
+    if (!is_array($env)) {
3217
+        $env = unserialize($env);
3218
+    }
3219
+    $texte = "";
3220
+    if ($env) {
3221
+        foreach ($env as $i => $j) {
3222
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3223
+                $texte .= $i . "='" . $j . "' ";
3224
+            }
3225
+        }
3226
+    }
3227 3227
 
3228
-	return $texte;
3228
+    return $texte;
3229 3229
 }
3230 3230
 
3231 3231
 
@@ -3242,9 +3242,9 @@  discard block
 block discarded – undo
3242 3242
  * @return string Chaînes concaténés
3243 3243
  **/
3244 3244
 function concat() {
3245
-	$args = func_get_args();
3245
+    $args = func_get_args();
3246 3246
 
3247
-	return join('', $args);
3247
+    return join('', $args);
3248 3248
 }
3249 3249
 
3250 3250
 
@@ -3264,23 +3264,23 @@  discard block
 block discarded – undo
3264 3264
  *     Contenu du ou des fichiers, concaténé
3265 3265
  **/
3266 3266
 function charge_scripts($files, $script = true) {
3267
-	$flux = "";
3268
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3269
-		if (!is_string($file)) {
3270
-			continue;
3271
-		}
3272
-		if ($script) {
3273
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3274
-		}
3275
-		if ($file) {
3276
-			$path = find_in_path($file);
3277
-			if ($path) {
3278
-				$flux .= spip_file_get_contents($path);
3279
-			}
3280
-		}
3281
-	}
3267
+    $flux = "";
3268
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3269
+        if (!is_string($file)) {
3270
+            continue;
3271
+        }
3272
+        if ($script) {
3273
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3274
+        }
3275
+        if ($file) {
3276
+            $path = find_in_path($file);
3277
+            if ($path) {
3278
+                $flux .= spip_file_get_contents($path);
3279
+            }
3280
+        }
3281
+    }
3282 3282
 
3283
-	return $flux;
3283
+    return $flux;
3284 3284
 }
3285 3285
 
3286 3286
 
@@ -3302,55 +3302,55 @@  discard block
 block discarded – undo
3302 3302
  */
3303 3303
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3304 3304
 
3305
-	$img_file = $img;
3306
-	if ($p = strpos($img_file, '?')) {
3307
-		$img_file = substr($img_file,0, $p);
3308
-	}
3309
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3310
-		$img_file = chemin_image($img);
3311
-	}
3312
-	else {
3313
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3314
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3315
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3316
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3317
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3318
-			  and file_exists($variante_svg_generique)) {
3319
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3320
-					$img_file = $variante_svg_size;
3321
-				}
3322
-				else {
3323
-					$img_file = $variante_svg_generique;
3324
-				}
3325
-			}
3326
-		}
3327
-	}
3328
-	if (stripos($atts, 'width') === false) {
3329
-		// utiliser directement l'info de taille presente dans le nom
3330
-		if ((!isset($options['utiliser_suffixe_size'])
3331
-				or $options['utiliser_suffixe_size'] == true
3332
-			  or strpos($img_file, '-xx.svg') !== false)
3333
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3334
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3335
-		) {
3336
-			$largeur = $hauteur = intval($regs[1]);
3337
-		} else {
3338
-			$taille = taille_image($img_file);
3339
-			list($hauteur, $largeur) = $taille;
3340
-			if (!$hauteur or !$largeur) {
3341
-				return "";
3342
-			}
3343
-		}
3344
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3345
-	}
3346
-
3347
-	if (file_exists($img_file)) {
3348
-		$img_file = timestamp($img_file);
3349
-	}
3350
-	return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3351
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3352
-	. " " . ltrim($atts)
3353
-	. " />";
3305
+    $img_file = $img;
3306
+    if ($p = strpos($img_file, '?')) {
3307
+        $img_file = substr($img_file,0, $p);
3308
+    }
3309
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3310
+        $img_file = chemin_image($img);
3311
+    }
3312
+    else {
3313
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3314
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3315
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3316
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3317
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3318
+              and file_exists($variante_svg_generique)) {
3319
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3320
+                    $img_file = $variante_svg_size;
3321
+                }
3322
+                else {
3323
+                    $img_file = $variante_svg_generique;
3324
+                }
3325
+            }
3326
+        }
3327
+    }
3328
+    if (stripos($atts, 'width') === false) {
3329
+        // utiliser directement l'info de taille presente dans le nom
3330
+        if ((!isset($options['utiliser_suffixe_size'])
3331
+                or $options['utiliser_suffixe_size'] == true
3332
+              or strpos($img_file, '-xx.svg') !== false)
3333
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3334
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3335
+        ) {
3336
+            $largeur = $hauteur = intval($regs[1]);
3337
+        } else {
3338
+            $taille = taille_image($img_file);
3339
+            list($hauteur, $largeur) = $taille;
3340
+            if (!$hauteur or !$largeur) {
3341
+                return "";
3342
+            }
3343
+        }
3344
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3345
+    }
3346
+
3347
+    if (file_exists($img_file)) {
3348
+        $img_file = timestamp($img_file);
3349
+    }
3350
+    return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3351
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3352
+    . " " . ltrim($atts)
3353
+    . " />";
3354 3354
 }
3355 3355
 
3356 3356
 /**
@@ -3362,13 +3362,13 @@  discard block
 block discarded – undo
3362 3362
  * @return string
3363 3363
  */
3364 3364
 function http_style_background($img, $att = '', $size=null) {
3365
-	if ($size and is_numeric($size)){
3366
-		$size = trim($size) . "px";
3367
-	}
3368
-	return " style='background" .
3369
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3370
-		. ($size ? "background-size:{$size};" : '')
3371
-		. "'";
3365
+    if ($size and is_numeric($size)){
3366
+        $size = trim($size) . "px";
3367
+    }
3368
+    return " style='background" .
3369
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3370
+        . ($size ? "background-size:{$size};" : '')
3371
+        . "'";
3372 3372
 }
3373 3373
 
3374 3374
 /**
@@ -3384,17 +3384,17 @@  discard block
 block discarded – undo
3384 3384
  *     Code HTML de la balise IMG
3385 3385
  */
3386 3386
 function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3387
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3388
-	// ecriture courte : on donne le width en 2e arg
3389
-	if (empty($width) and is_numeric($alt)) {
3390
-		$width = $alt;
3391
-		$alt = '';
3392
-	}
3393
-	if ($width) {
3394
-		$atts .= " width='{$width}'";
3395
-	}
3396
-	return http_img_pack($img, $alt, $atts, '',
3397
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3387
+    $atts = $class ? " class='" . attribut_html($class) . "'" : '';
3388
+    // ecriture courte : on donne le width en 2e arg
3389
+    if (empty($width) and is_numeric($alt)) {
3390
+        $width = $alt;
3391
+        $alt = '';
3392
+    }
3393
+    if ($width) {
3394
+        $atts .= " width='{$width}'";
3395
+    }
3396
+    return http_img_pack($img, $alt, $atts, '',
3397
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3398 3398
 }
3399 3399
 
3400 3400
 
@@ -3410,42 +3410,42 @@  discard block
 block discarded – undo
3410 3410
  * @return string
3411 3411
  */
3412 3412
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3413
-	$img_file = $img;
3414
-	if ($p = strpos($img_file, '?')) {
3415
-		$img_file = substr($img_file,0, $p);
3416
-	}
3413
+    $img_file = $img;
3414
+    if ($p = strpos($img_file, '?')) {
3415
+        $img_file = substr($img_file,0, $p);
3416
+    }
3417 3417
 
3418
-	if (!$img_file or !$svg = file_get_contents($img_file)) {
3419
-		return '';
3420
-	}
3418
+    if (!$img_file or !$svg = file_get_contents($img_file)) {
3419
+        return '';
3420
+    }
3421 3421
 
3422
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3423
-		return '';
3424
-	}
3425
-	$balise_svg = $match[0];
3426
-	$balise_svg_source = $balise_svg;
3422
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3423
+        return '';
3424
+    }
3425
+    $balise_svg = $match[0];
3426
+    $balise_svg_source = $balise_svg;
3427 3427
 
3428
-	// entete XML à supprimer
3429
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3428
+    // entete XML à supprimer
3429
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3430 3430
 
3431
-	// IE est toujours mon ami
3432
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3433
-	if ($class) {
3434
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3435
-	}
3436
-	if ($alt){
3437
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3438
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3439
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3440
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3441
-		$balise_svg .= $title;
3442
-	}
3443
-	else {
3444
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3445
-	}
3446
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3431
+    // IE est toujours mon ami
3432
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3433
+    if ($class) {
3434
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3435
+    }
3436
+    if ($alt){
3437
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3438
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3439
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3440
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3441
+        $balise_svg .= $title;
3442
+    }
3443
+    else {
3444
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3445
+    }
3446
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3447 3447
 
3448
-	return $svg;
3448
+    return $svg;
3449 3449
 }
3450 3450
 
3451 3451
 
@@ -3468,17 +3468,17 @@  discard block
 block discarded – undo
3468 3468
  *     Code HTML résultant
3469 3469
  **/
3470 3470
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3471
-	$texte = '';
3472
-	if (is_array($tableau)) {
3473
-		foreach ($tableau as $k => $v) {
3474
-			$res = recuperer_fond('modeles/' . $modele,
3475
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3476
-			);
3477
-			$texte .= $res;
3478
-		}
3479
-	}
3471
+    $texte = '';
3472
+    if (is_array($tableau)) {
3473
+        foreach ($tableau as $k => $v) {
3474
+            $res = recuperer_fond('modeles/' . $modele,
3475
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3476
+            );
3477
+            $texte .= $res;
3478
+        }
3479
+    }
3480 3480
 
3481
-	return $texte;
3481
+    return $texte;
3482 3482
 }
3483 3483
 
3484 3484
 
@@ -3503,37 +3503,37 @@  discard block
 block discarded – undo
3503 3503
  *         - tout : retourne toutes les informations du plugin actif
3504 3504
  **/
3505 3505
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3506
-	include_spip('inc/plugin');
3507
-	$plugin = strtoupper($plugin);
3508
-	$plugins_actifs = liste_plugin_actifs();
3509
-
3510
-	if (!$plugin) {
3511
-		return serialize(array_keys($plugins_actifs));
3512
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3513
-		return '';
3514
-	} elseif (($type_info == 'est_actif') and !$reload) {
3515
-		return $plugins_actifs[$plugin] ? 1 : 0;
3516
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3517
-		return $plugins_actifs[$plugin][$type_info];
3518
-	} else {
3519
-		$get_infos = charger_fonction('get_infos', 'plugins');
3520
-		// On prend en compte les extensions
3521
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3522
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3523
-		} else {
3524
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3525
-		}
3526
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3527
-			return '';
3528
-		}
3529
-		if ($type_info == 'tout') {
3530
-			return $infos;
3531
-		} elseif ($type_info == 'est_actif') {
3532
-			return $infos ? 1 : 0;
3533
-		} else {
3534
-			return strval($infos[$type_info]);
3535
-		}
3536
-	}
3506
+    include_spip('inc/plugin');
3507
+    $plugin = strtoupper($plugin);
3508
+    $plugins_actifs = liste_plugin_actifs();
3509
+
3510
+    if (!$plugin) {
3511
+        return serialize(array_keys($plugins_actifs));
3512
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3513
+        return '';
3514
+    } elseif (($type_info == 'est_actif') and !$reload) {
3515
+        return $plugins_actifs[$plugin] ? 1 : 0;
3516
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3517
+        return $plugins_actifs[$plugin][$type_info];
3518
+    } else {
3519
+        $get_infos = charger_fonction('get_infos', 'plugins');
3520
+        // On prend en compte les extensions
3521
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3522
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3523
+        } else {
3524
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3525
+        }
3526
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3527
+            return '';
3528
+        }
3529
+        if ($type_info == 'tout') {
3530
+            return $infos;
3531
+        } elseif ($type_info == 'est_actif') {
3532
+            return $infos ? 1 : 0;
3533
+        } else {
3534
+            return strval($infos[$type_info]);
3535
+        }
3536
+    }
3537 3537
 }
3538 3538
 
3539 3539
 
@@ -3560,9 +3560,9 @@  discard block
 block discarded – undo
3560 3560
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3561 3561
  */
3562 3562
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3563
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3563
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3564 3564
 
3565
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3565
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3566 3566
 }
3567 3567
 
3568 3568
 
@@ -3592,13 +3592,13 @@  discard block
 block discarded – undo
3592 3592
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3593 3593
  */
3594 3594
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3595
-	static $puce_statut = null;
3596
-	if (!$puce_statut) {
3597
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3598
-	}
3595
+    static $puce_statut = null;
3596
+    if (!$puce_statut) {
3597
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3598
+    }
3599 3599
 
3600
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3601
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3600
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3601
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3602 3602
 }
3603 3603
 
3604 3604
 
@@ -3625,88 +3625,88 @@  discard block
 block discarded – undo
3625 3625
  *   hash du contexte
3626 3626
  */
3627 3627
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3628
-	if (is_string($c)
3629
-		and @unserialize($c) !== false
3630
-	) {
3631
-		$c = unserialize($c);
3632
-	}
3633
-
3634
-	// supprimer les parametres debut_x
3635
-	// pour que la pagination ajax ne soit pas plantee
3636
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3637
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3638
-	if (is_array($c)) {
3639
-		foreach ($c as $k => $v) {
3640
-			if (strpos($k, 'debut_') === 0) {
3641
-				unset($c[$k]);
3642
-			}
3643
-		}
3644
-	}
3645
-
3646
-	if (!function_exists('calculer_cle_action')) {
3647
-		include_spip("inc/securiser_action");
3648
-	}
3649
-
3650
-	$c = serialize($c);
3651
-	$cle = calculer_cle_action($form . $c);
3652
-	$c = "$cle:$c";
3653
-
3654
-	// on ne stocke pas les contextes dans des fichiers caches
3655
-	// par defaut, sauf si cette configuration a ete forcee
3656
-	// OU que la longueur de l''argument generee est plus long
3657
-	// que ce que telere Suhosin.
3658
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3659
-	if (!$cache_contextes_ajax) {
3660
-		$env = $c;
3661
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3662
-			$env = gzdeflate($env);
3663
-			// http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3664
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3665
-				$cache_contextes_ajax = true;
3666
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3667
-			}
3668
-		}
3669
-		$env = _xor($env);
3670
-		$env = base64_encode($env);
3671
-		// tester Suhosin et la valeur maximale des variables en GET...
3672
-		if ($max_len = @ini_get('suhosin.get.max_value_length')
3673
-			and $max_len < ($len = strlen($env))
3674
-		) {
3675
-			$cache_contextes_ajax = true;
3676
-			spip_log("Contextes AJAX forces en fichiers !"
3677
-				. " Cela arrive lorsque la valeur du contexte"
3678
-				. " depasse la longueur maximale autorisee par Suhosin"
3679
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3680
-				. " Vous devriez modifier les parametres de Suhosin"
3681
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3682
-		}
3683
-	}
3684
-
3685
-	if ($cache_contextes_ajax) {
3686
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3687
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3688
-		$md5 = md5($c);
3689
-		ecrire_fichier("$dir/c$md5", $c);
3690
-		$env = $md5;
3691
-	}
3692
-
3693
-	if ($emboite === null) {
3694
-		return $env;
3695
-	}
3696
-	if (!trim($emboite)) {
3697
-		return "";
3698
-	}
3699
-	// toujours encoder l'url source dans le bloc ajax
3700
-	$r = self();
3701
-	$r = ' data-origin="' . $r . '"';
3702
-	$class = 'ajaxbloc';
3703
-	if ($ajaxid and is_string($ajaxid)) {
3704
-		// ajaxid est normalement conforme a un nom de classe css
3705
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3706
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3707
-	}
3708
-
3709
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3628
+    if (is_string($c)
3629
+        and @unserialize($c) !== false
3630
+    ) {
3631
+        $c = unserialize($c);
3632
+    }
3633
+
3634
+    // supprimer les parametres debut_x
3635
+    // pour que la pagination ajax ne soit pas plantee
3636
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3637
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3638
+    if (is_array($c)) {
3639
+        foreach ($c as $k => $v) {
3640
+            if (strpos($k, 'debut_') === 0) {
3641
+                unset($c[$k]);
3642
+            }
3643
+        }
3644
+    }
3645
+
3646
+    if (!function_exists('calculer_cle_action')) {
3647
+        include_spip("inc/securiser_action");
3648
+    }
3649
+
3650
+    $c = serialize($c);
3651
+    $cle = calculer_cle_action($form . $c);
3652
+    $c = "$cle:$c";
3653
+
3654
+    // on ne stocke pas les contextes dans des fichiers caches
3655
+    // par defaut, sauf si cette configuration a ete forcee
3656
+    // OU que la longueur de l''argument generee est plus long
3657
+    // que ce que telere Suhosin.
3658
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3659
+    if (!$cache_contextes_ajax) {
3660
+        $env = $c;
3661
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3662
+            $env = gzdeflate($env);
3663
+            // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3664
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3665
+                $cache_contextes_ajax = true;
3666
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3667
+            }
3668
+        }
3669
+        $env = _xor($env);
3670
+        $env = base64_encode($env);
3671
+        // tester Suhosin et la valeur maximale des variables en GET...
3672
+        if ($max_len = @ini_get('suhosin.get.max_value_length')
3673
+            and $max_len < ($len = strlen($env))
3674
+        ) {
3675
+            $cache_contextes_ajax = true;
3676
+            spip_log("Contextes AJAX forces en fichiers !"
3677
+                . " Cela arrive lorsque la valeur du contexte"
3678
+                . " depasse la longueur maximale autorisee par Suhosin"
3679
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3680
+                . " Vous devriez modifier les parametres de Suhosin"
3681
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3682
+        }
3683
+    }
3684
+
3685
+    if ($cache_contextes_ajax) {
3686
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3687
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3688
+        $md5 = md5($c);
3689
+        ecrire_fichier("$dir/c$md5", $c);
3690
+        $env = $md5;
3691
+    }
3692
+
3693
+    if ($emboite === null) {
3694
+        return $env;
3695
+    }
3696
+    if (!trim($emboite)) {
3697
+        return "";
3698
+    }
3699
+    // toujours encoder l'url source dans le bloc ajax
3700
+    $r = self();
3701
+    $r = ' data-origin="' . $r . '"';
3702
+    $class = 'ajaxbloc';
3703
+    if ($ajaxid and is_string($ajaxid)) {
3704
+        // ajaxid est normalement conforme a un nom de classe css
3705
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3706
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3707
+    }
3708
+
3709
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3710 3710
 }
3711 3711
 
3712 3712
 /**
@@ -3726,36 +3726,36 @@  discard block
 block discarded – undo
3726 3726
  *   - false : erreur de décodage
3727 3727
  */
3728 3728
 function decoder_contexte_ajax($c, $form = '') {
3729
-	if (!function_exists('calculer_cle_action')) {
3730
-		include_spip("inc/securiser_action");
3731
-	}
3732
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3733
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3734
-		and lire_fichier("$dir/c$c", $contexte)
3735
-	) {
3736
-		$c = $contexte;
3737
-	} else {
3738
-		$c = @base64_decode($c);
3739
-		$c = _xor($c);
3740
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3741
-			$c = @gzinflate($c);
3742
-		}
3743
-	}
3744
-
3745
-	// extraire la signature en debut de contexte
3746
-	// et la verifier avant de deserializer
3747
-	// format : signature:donneesserializees
3748
-	if ($p = strpos($c,":")){
3749
-		$cle = substr($c,0,$p);
3750
-		$c = substr($c,$p+1);
3751
-
3752
-		if ($cle == calculer_cle_action($form . $c)) {
3753
-			$env = @unserialize($c);
3754
-			return $env;
3755
-		}
3756
-	}
3757
-
3758
-	return false;
3729
+    if (!function_exists('calculer_cle_action')) {
3730
+        include_spip("inc/securiser_action");
3731
+    }
3732
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3733
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3734
+        and lire_fichier("$dir/c$c", $contexte)
3735
+    ) {
3736
+        $c = $contexte;
3737
+    } else {
3738
+        $c = @base64_decode($c);
3739
+        $c = _xor($c);
3740
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3741
+            $c = @gzinflate($c);
3742
+        }
3743
+    }
3744
+
3745
+    // extraire la signature en debut de contexte
3746
+    // et la verifier avant de deserializer
3747
+    // format : signature:donneesserializees
3748
+    if ($p = strpos($c,":")){
3749
+        $cle = substr($c,0,$p);
3750
+        $c = substr($c,$p+1);
3751
+
3752
+        if ($cle == calculer_cle_action($form . $c)) {
3753
+            $env = @unserialize($c);
3754
+            return $env;
3755
+        }
3756
+    }
3757
+
3758
+    return false;
3759 3759
 }
3760 3760
 
3761 3761
 
@@ -3773,20 +3773,20 @@  discard block
 block discarded – undo
3773 3773
  *    Message décrypté ou encrypté
3774 3774
  **/
3775 3775
 function _xor($message, $key = null) {
3776
-	if (is_null($key)) {
3777
-		if (!function_exists('calculer_cle_action')) {
3778
-			include_spip("inc/securiser_action");
3779
-		}
3780
-		$key = pack("H*", calculer_cle_action('_xor'));
3781
-	}
3776
+    if (is_null($key)) {
3777
+        if (!function_exists('calculer_cle_action')) {
3778
+            include_spip("inc/securiser_action");
3779
+        }
3780
+        $key = pack("H*", calculer_cle_action('_xor'));
3781
+    }
3782 3782
 
3783
-	$keylen = strlen($key);
3784
-	$messagelen = strlen($message);
3785
-	for ($i = 0; $i < $messagelen; $i++) {
3786
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3787
-	}
3783
+    $keylen = strlen($key);
3784
+    $messagelen = strlen($message);
3785
+    for ($i = 0; $i < $messagelen; $i++) {
3786
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3787
+    }
3788 3788
 
3789
-	return $message;
3789
+    return $message;
3790 3790
 }
3791 3791
 
3792 3792
 /**
@@ -3844,22 +3844,22 @@  discard block
 block discarded – undo
3844 3844
  *   Code HTML
3845 3845
  */
3846 3846
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3847
-	if ($on) {
3848
-		$bal = "strong";
3849
-		$att = "class='on'";
3850
-	} else {
3851
-		$bal = 'a';
3852
-		$att = "href='$url'"
3853
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3854
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3855
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3856
-			. $evt;
3857
-	}
3858
-	if ($libelle === null) {
3859
-		$libelle = $url;
3860
-	}
3847
+    if ($on) {
3848
+        $bal = "strong";
3849
+        $att = "class='on'";
3850
+    } else {
3851
+        $bal = 'a';
3852
+        $att = "href='$url'"
3853
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3854
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3855
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3856
+            . $evt;
3857
+    }
3858
+    if ($libelle === null) {
3859
+        $libelle = $url;
3860
+    }
3861 3861
 
3862
-	return "<$bal $att>$libelle</$bal>";
3862
+    return "<$bal $att>$libelle</$bal>";
3863 3863
 }
3864 3864
 
3865 3865
 
@@ -3876,18 +3876,18 @@  discard block
 block discarded – undo
3876 3876
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3877 3877
  */
3878 3878
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3879
-	if (!$nb = intval($nb)) {
3880
-		return "";
3881
-	}
3882
-	if (!is_array($vars)) {
3883
-		return "";
3884
-	}
3885
-	$vars[$var] = $nb;
3886
-	if ($nb > 1) {
3887
-		return _T($chaine_plusieurs, $vars);
3888
-	} else {
3889
-		return _T($chaine_un, $vars);
3890
-	}
3879
+    if (!$nb = intval($nb)) {
3880
+        return "";
3881
+    }
3882
+    if (!is_array($vars)) {
3883
+        return "";
3884
+    }
3885
+    $vars[$var] = $nb;
3886
+    if ($nb > 1) {
3887
+        return _T($chaine_plusieurs, $vars);
3888
+    } else {
3889
+        return _T($chaine_un, $vars);
3890
+    }
3891 3891
 }
3892 3892
 
3893 3893
 
@@ -3912,56 +3912,56 @@  discard block
 block discarded – undo
3912 3912
  * @return string
3913 3913
  */
3914 3914
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3915
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3916
-		$class .= ' danger';
3917
-	} elseif ($fonction == "rien.gif") {
3918
-		$fonction = "";
3919
-	} elseif ($fonction == "delsafe") {
3920
-		$fonction = "del";
3921
-	}
3922
-
3923
-	$fond_origine = $fond;
3924
-	// remappage des icone : article-24.png+new => article-new-24.png
3925
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3926
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
3927
-	}
3928
-
3929
-	// ajouter le type d'objet dans la class de l'icone
3930
-	$class .= " " . substr(basename($fond), 0, -4);
3931
-
3932
-	$alt = attribut_html($texte);
3933
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3934
-
3935
-	$ajax = "";
3936
-	if (strpos($class, "ajax") !== false) {
3937
-		$ajax = "ajax";
3938
-		if (strpos($class, "preload") !== false) {
3939
-			$ajax .= " preload";
3940
-		}
3941
-		if (strpos($class, "nocache") !== false) {
3942
-			$ajax .= " nocache";
3943
-		}
3944
-		$ajax = " class='$ajax'";
3945
-	}
3946
-
3947
-	$size = 24;
3948
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3949
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3950
-		$size = $match[1];
3951
-	}
3952
-
3953
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3954
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3955
-
3956
-	if ($type == 'lien') {
3957
-		return "<span class='icone s$size $class'>"
3958
-		. "<a href='$lien'$title$ajax$javascript>"
3959
-		. $icone
3960
-		. "<b>$texte</b>"
3961
-		. "</a></span>\n";
3962
-	} else {
3963
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3964
-	}
3915
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3916
+        $class .= ' danger';
3917
+    } elseif ($fonction == "rien.gif") {
3918
+        $fonction = "";
3919
+    } elseif ($fonction == "delsafe") {
3920
+        $fonction = "del";
3921
+    }
3922
+
3923
+    $fond_origine = $fond;
3924
+    // remappage des icone : article-24.png+new => article-new-24.png
3925
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3926
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
3927
+    }
3928
+
3929
+    // ajouter le type d'objet dans la class de l'icone
3930
+    $class .= " " . substr(basename($fond), 0, -4);
3931
+
3932
+    $alt = attribut_html($texte);
3933
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3934
+
3935
+    $ajax = "";
3936
+    if (strpos($class, "ajax") !== false) {
3937
+        $ajax = "ajax";
3938
+        if (strpos($class, "preload") !== false) {
3939
+            $ajax .= " preload";
3940
+        }
3941
+        if (strpos($class, "nocache") !== false) {
3942
+            $ajax .= " nocache";
3943
+        }
3944
+        $ajax = " class='$ajax'";
3945
+    }
3946
+
3947
+    $size = 24;
3948
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3949
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3950
+        $size = $match[1];
3951
+    }
3952
+
3953
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3954
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3955
+
3956
+    if ($type == 'lien') {
3957
+        return "<span class='icone s$size $class'>"
3958
+        . "<a href='$lien'$title$ajax$javascript>"
3959
+        . $icone
3960
+        . "<b>$texte</b>"
3961
+        . "</a></span>\n";
3962
+    } else {
3963
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3964
+    }
3965 3965
 }
3966 3966
 
3967 3967
 /**
@@ -3985,7 +3985,7 @@  discard block
 block discarded – undo
3985 3985
  *     Code HTML du lien
3986 3986
  **/
3987 3987
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3988
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3988
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3989 3989
 }
3990 3990
 
3991 3991
 /**
@@ -4020,7 +4020,7 @@  discard block
 block discarded – undo
4020 4020
  *     Code HTML du lien
4021 4021
  **/
4022 4022
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4023
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4023
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4024 4024
 }
4025 4025
 
4026 4026
 /**
@@ -4065,7 +4065,7 @@  discard block
 block discarded – undo
4065 4065
  *     Code HTML du lien
4066 4066
  **/
4067 4067
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4068
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4068
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4069 4069
 }
4070 4070
 
4071 4071
 /**
@@ -4096,7 +4096,7 @@  discard block
 block discarded – undo
4096 4096
  *     Code HTML du lien
4097 4097
  **/
4098 4098
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4099
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4099
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4100 4100
 }
4101 4101
 
4102 4102
 /**
@@ -4126,7 +4126,7 @@  discard block
 block discarded – undo
4126 4126
  *     Code HTML du lien
4127 4127
  */
4128 4128
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4129
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4129
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4130 4130
 }
4131 4131
 
4132 4132
 
@@ -4174,26 +4174,26 @@  discard block
 block discarded – undo
4174 4174
  * @return string Code CSS
4175 4175
  */
4176 4176
 function bando_images_background() {
4177
-	include_spip('inc/bandeau');
4178
-	// recuperer tous les boutons et leurs images
4179
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4177
+    include_spip('inc/bandeau');
4178
+    // recuperer tous les boutons et leurs images
4179
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4180 4180
 
4181
-	$res = "";
4182
-	foreach ($boutons as $page => $detail) {
4183
-		if ($detail->icone and strlen(trim($detail->icone))) {
4184
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4185
-		}
4186
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4187
-		if (is_array($detail->sousmenu)) {
4188
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4189
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4190
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4191
-				}
4192
-			}
4193
-		}
4194
-	}
4181
+    $res = "";
4182
+    foreach ($boutons as $page => $detail) {
4183
+        if ($detail->icone and strlen(trim($detail->icone))) {
4184
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4185
+        }
4186
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4187
+        if (is_array($detail->sousmenu)) {
4188
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4189
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4190
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4191
+                }
4192
+            }
4193
+        }
4194
+    }
4195 4195
 
4196
-	return $res;
4196
+    return $res;
4197 4197
 }
4198 4198
 
4199 4199
 /**
@@ -4212,19 +4212,19 @@  discard block
 block discarded – undo
4212 4212
  * @return string
4213 4213
  */
4214 4214
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4215
-	if ($confirm) {
4216
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4217
-		if ($callback) {
4218
-			$callback = "$confirm?($callback):false";
4219
-		} else {
4220
-			$callback = $confirm;
4221
-		}
4222
-	}
4223
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4224
-	$title = $title ? " title='$title'" : "";
4215
+    if ($confirm) {
4216
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4217
+        if ($callback) {
4218
+            $callback = "$confirm?($callback):false";
4219
+        } else {
4220
+            $callback = $confirm;
4221
+        }
4222
+    }
4223
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4224
+    $title = $title ? " title='$title'" : "";
4225 4225
 
4226
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4227
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4226
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4227
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4228 4228
 }
4229 4229
 
4230 4230
 
@@ -4236,7 +4236,7 @@  discard block
 block discarded – undo
4236 4236
  * @return string
4237 4237
  */
4238 4238
 function tri_protege_champ($t) {
4239
-	return preg_replace(',[^\s\w.+],', '', $t);
4239
+    return preg_replace(',[^\s\w.+],', '', $t);
4240 4240
 }
4241 4241
 
4242 4242
 /**
@@ -4249,34 +4249,34 @@  discard block
 block discarded – undo
4249 4249
  * @return string
4250 4250
  */
4251 4251
 function tri_champ_order($t, $from = null) {
4252
-	if (strncmp($t, 'multi ', 6) == 0) {
4253
-		return "multi";
4254
-	}
4255
-
4256
-	$champ = $t;
4257
-
4258
-	if (strncmp($t, 'num ', 4) == 0) {
4259
-		$champ = substr($t, 4);
4260
-	}
4261
-	// enlever les autres espaces non evacues par tri_protege_champ
4262
-	$champ = preg_replace(',\s,', '', $champ);
4263
-
4264
-	if (is_array($from)) {
4265
-		$trouver_table = charger_fonction('trouver_table', 'base');
4266
-		foreach ($from as $idt => $table_sql) {
4267
-			if ($desc = $trouver_table($table_sql)
4268
-				and isset($desc['field'][$champ])
4269
-			) {
4270
-				$champ = "$idt.$champ";
4271
-				break;
4272
-			}
4273
-		}
4274
-	}
4275
-	if (strncmp($t, 'num ', 4) == 0) {
4276
-		return "0+$champ";
4277
-	} else {
4278
-		return $champ;
4279
-	}
4252
+    if (strncmp($t, 'multi ', 6) == 0) {
4253
+        return "multi";
4254
+    }
4255
+
4256
+    $champ = $t;
4257
+
4258
+    if (strncmp($t, 'num ', 4) == 0) {
4259
+        $champ = substr($t, 4);
4260
+    }
4261
+    // enlever les autres espaces non evacues par tri_protege_champ
4262
+    $champ = preg_replace(',\s,', '', $champ);
4263
+
4264
+    if (is_array($from)) {
4265
+        $trouver_table = charger_fonction('trouver_table', 'base');
4266
+        foreach ($from as $idt => $table_sql) {
4267
+            if ($desc = $trouver_table($table_sql)
4268
+                and isset($desc['field'][$champ])
4269
+            ) {
4270
+                $champ = "$idt.$champ";
4271
+                break;
4272
+            }
4273
+        }
4274
+    }
4275
+    if (strncmp($t, 'num ', 4) == 0) {
4276
+        return "0+$champ";
4277
+    } else {
4278
+        return $champ;
4279
+    }
4280 4280
 }
4281 4281
 
4282 4282
 /**
@@ -4290,18 +4290,18 @@  discard block
 block discarded – undo
4290 4290
  * @return string
4291 4291
  */
4292 4292
 function tri_champ_select($t) {
4293
-	if (strncmp($t, 'multi ', 6) == 0) {
4294
-		$t = substr($t, 6);
4295
-		$t = preg_replace(',\s,', '', $t);
4296
-		$t = sql_multi($t, $GLOBALS['spip_lang']);
4293
+    if (strncmp($t, 'multi ', 6) == 0) {
4294
+        $t = substr($t, 6);
4295
+        $t = preg_replace(',\s,', '', $t);
4296
+        $t = sql_multi($t, $GLOBALS['spip_lang']);
4297 4297
 
4298
-		return $t;
4299
-	}
4300
-	if (trim($t) == 'hasard') {
4301
-		return 'rand() AS hasard';
4302
-	}
4298
+        return $t;
4299
+    }
4300
+    if (trim($t) == 'hasard') {
4301
+        return 'rand() AS hasard';
4302
+    }
4303 4303
 
4304
-	return "''";
4304
+    return "''";
4305 4305
 }
4306 4306
 
4307 4307
 
@@ -4323,78 +4323,78 @@  discard block
 block discarded – undo
4323 4323
  * @return string
4324 4324
  */
4325 4325
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4326
-	static $trouver_table = null;
4327
-	static $objets;
4328
-
4329
-	// On verifie qu'on a tout ce qu'il faut
4330
-	$id_objet = intval($id_objet);
4331
-	if (!($id_objet and $type_objet and $info)) {
4332
-		return '';
4333
-	}
4334
-
4335
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4336
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4337
-		return '';
4338
-	}
4339
-
4340
-	// Si on demande l'url, on retourne direct la fonction
4341
-	if ($info == 'url') {
4342
-		return generer_url_entite($id_objet, $type_objet);
4343
-	}
4344
-
4345
-	// Sinon on va tout chercher dans la table et on garde en memoire
4346
-	$demande_titre = ($info == 'titre');
4347
-
4348
-	// 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
4349
-	if (!isset($objets[$type_objet][$id_objet])
4350
-		or
4351
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4352
-	) {
4353
-		if (!$trouver_table) {
4354
-			$trouver_table = charger_fonction('trouver_table', 'base');
4355
-		}
4356
-		$desc = $trouver_table(table_objet_sql($type_objet));
4357
-		if (!$desc) {
4358
-			return $objets[$type_objet] = false;
4359
-		}
4360
-
4361
-		// Si on demande le titre, on le gere en interne
4362
-		$champ_titre = "";
4363
-		if ($demande_titre) {
4364
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4365
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4366
-		}
4367
-		include_spip('base/abstract_sql');
4368
-		include_spip('base/connect_sql');
4369
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4370
-			'*' . $champ_titre,
4371
-			$desc['table_sql'],
4372
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4373
-		);
4374
-	}
4375
-
4376
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4377
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4378
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4379
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4380
-	else {
4381
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4382
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4383
-		} // Sinon on prend directement le champ SQL tel quel
4384
-		else {
4385
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4386
-		}
4387
-	}
4388
-
4389
-	// On va ensuite appliquer les traitements automatiques si besoin
4390
-	if (!$etoile) {
4391
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4392
-		// mais ce fonctionnement est a ameliorer !
4393
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4394
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4395
-	}
4396
-
4397
-	return $info_generee;
4326
+    static $trouver_table = null;
4327
+    static $objets;
4328
+
4329
+    // On verifie qu'on a tout ce qu'il faut
4330
+    $id_objet = intval($id_objet);
4331
+    if (!($id_objet and $type_objet and $info)) {
4332
+        return '';
4333
+    }
4334
+
4335
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4336
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4337
+        return '';
4338
+    }
4339
+
4340
+    // Si on demande l'url, on retourne direct la fonction
4341
+    if ($info == 'url') {
4342
+        return generer_url_entite($id_objet, $type_objet);
4343
+    }
4344
+
4345
+    // Sinon on va tout chercher dans la table et on garde en memoire
4346
+    $demande_titre = ($info == 'titre');
4347
+
4348
+    // 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
4349
+    if (!isset($objets[$type_objet][$id_objet])
4350
+        or
4351
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4352
+    ) {
4353
+        if (!$trouver_table) {
4354
+            $trouver_table = charger_fonction('trouver_table', 'base');
4355
+        }
4356
+        $desc = $trouver_table(table_objet_sql($type_objet));
4357
+        if (!$desc) {
4358
+            return $objets[$type_objet] = false;
4359
+        }
4360
+
4361
+        // Si on demande le titre, on le gere en interne
4362
+        $champ_titre = "";
4363
+        if ($demande_titre) {
4364
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4365
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4366
+        }
4367
+        include_spip('base/abstract_sql');
4368
+        include_spip('base/connect_sql');
4369
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4370
+            '*' . $champ_titre,
4371
+            $desc['table_sql'],
4372
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4373
+        );
4374
+    }
4375
+
4376
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4377
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4378
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4379
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4380
+    else {
4381
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4382
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4383
+        } // Sinon on prend directement le champ SQL tel quel
4384
+        else {
4385
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4386
+        }
4387
+    }
4388
+
4389
+    // On va ensuite appliquer les traitements automatiques si besoin
4390
+    if (!$etoile) {
4391
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4392
+        // mais ce fonctionnement est a ameliorer !
4393
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4394
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4395
+    }
4396
+
4397
+    return $info_generee;
4398 4398
 }
4399 4399
 
4400 4400
 /**
@@ -4408,44 +4408,44 @@  discard block
 block discarded – undo
4408 4408
  * @return string
4409 4409
  */
4410 4410
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4411
-	if (!$champ) {
4412
-		return $texte;
4413
-	}
4411
+    if (!$champ) {
4412
+        return $texte;
4413
+    }
4414 4414
 	
4415
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4416
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4417
-	include_spip('inc/texte');
4415
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4416
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4417
+    include_spip('inc/texte');
4418 4418
 	
4419
-	$champ = strtoupper($champ);
4420
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4421
-	if (!$traitements or !is_array($traitements)) {
4422
-		return $texte;
4423
-	}
4419
+    $champ = strtoupper($champ);
4420
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4421
+    if (!$traitements or !is_array($traitements)) {
4422
+        return $texte;
4423
+    }
4424 4424
 
4425
-	$traitement = '';
4426
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4427
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4428
-		$table_objet = table_objet($table_objet);
4429
-		if (isset($traitements[$table_objet])) {
4430
-			$traitement = $traitements[$table_objet];
4431
-		}
4432
-	}
4433
-	if (!$traitement and isset($traitements[0])) {
4434
-		$traitement = $traitements[0];
4435
-	}
4436
-	// (sinon prendre le premier de la liste par defaut ?)
4425
+    $traitement = '';
4426
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4427
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4428
+        $table_objet = table_objet($table_objet);
4429
+        if (isset($traitements[$table_objet])) {
4430
+            $traitement = $traitements[$table_objet];
4431
+        }
4432
+    }
4433
+    if (!$traitement and isset($traitements[0])) {
4434
+        $traitement = $traitements[0];
4435
+    }
4436
+    // (sinon prendre le premier de la liste par defaut ?)
4437 4437
 
4438
-	if (!$traitement) {
4439
-		return $texte;
4440
-	}
4438
+    if (!$traitement) {
4439
+        return $texte;
4440
+    }
4441 4441
 
4442
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4442
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4443 4443
 
4444
-	// Fournir $connect et $Pile[0] au traitement si besoin
4445
-	$Pile = array(0 => $env);
4446
-	eval("\$texte = $traitement;");
4444
+    // Fournir $connect et $Pile[0] au traitement si besoin
4445
+    $Pile = array(0 => $env);
4446
+    eval("\$texte = $traitement;");
4447 4447
 
4448
-	return $texte;
4448
+    return $texte;
4449 4449
 }
4450 4450
 
4451 4451
 
@@ -4459,21 +4459,21 @@  discard block
 block discarded – undo
4459 4459
  * @return string
4460 4460
  */
4461 4461
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4462
-	include_spip('inc/liens');
4463
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4464
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4465
-	// le raccourcis n'est plus valide
4466
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4467
-	// on essaye avec generer_info_entite ?
4468
-	if (!strlen($titre) and !$connect) {
4469
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4470
-	}
4471
-	if (!strlen($titre)) {
4472
-		$titre = _T('info_sans_titre');
4473
-	}
4474
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4462
+    include_spip('inc/liens');
4463
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4464
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4465
+    // le raccourcis n'est plus valide
4466
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4467
+    // on essaye avec generer_info_entite ?
4468
+    if (!strlen($titre) and !$connect) {
4469
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4470
+    }
4471
+    if (!strlen($titre)) {
4472
+        $titre = _T('info_sans_titre');
4473
+    }
4474
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4475 4475
 
4476
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4476
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4477 4477
 }
4478 4478
 
4479 4479
 
@@ -4490,15 +4490,15 @@  discard block
 block discarded – undo
4490 4490
  * @return string
4491 4491
  */
4492 4492
 function wrap($texte, $wrap) {
4493
-	$balises = extraire_balises($wrap);
4494
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4495
-		$texte = $wrap . $texte;
4496
-		$regs = array_reverse($regs[1]);
4497
-		$wrap = "</" . implode("></", $regs) . ">";
4498
-		$texte = $texte . $wrap;
4499
-	}
4493
+    $balises = extraire_balises($wrap);
4494
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4495
+        $texte = $wrap . $texte;
4496
+        $regs = array_reverse($regs[1]);
4497
+        $wrap = "</" . implode("></", $regs) . ">";
4498
+        $texte = $texte . $wrap;
4499
+    }
4500 4500
 
4501
-	return $texte;
4501
+    return $texte;
4502 4502
 }
4503 4503
 
4504 4504
 
@@ -4518,43 +4518,43 @@  discard block
 block discarded – undo
4518 4518
  * @return array|mixed|string
4519 4519
  */
4520 4520
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4521
-	if (is_string($u)) {
4522
-		$u = typo($u);
4521
+    if (is_string($u)) {
4522
+        $u = typo($u);
4523 4523
 
4524
-		return $u;
4525
-	}
4524
+        return $u;
4525
+    }
4526 4526
 
4527
-	// caster $u en array si besoin
4528
-	if (is_object($u)) {
4529
-		$u = (array)$u;
4530
-	}
4527
+    // caster $u en array si besoin
4528
+    if (is_object($u)) {
4529
+        $u = (array)$u;
4530
+    }
4531 4531
 
4532
-	if (is_array($u)) {
4533
-		$out = "";
4534
-		// toutes les cles sont numeriques ?
4535
-		// et aucun enfant n'est un tableau
4536
-		// liste simple separee par des virgules
4537
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4538
-		$array_values = array_map('is_array', $u);
4539
-		$object_values = array_map('is_object', $u);
4540
-		if (array_sum($numeric_keys) == count($numeric_keys)
4541
-			and !array_sum($array_values)
4542
-			and !array_sum($object_values)
4543
-		) {
4544
-			return join(", ", array_map('filtre_print_dist', $u));
4545
-		}
4532
+    if (is_array($u)) {
4533
+        $out = "";
4534
+        // toutes les cles sont numeriques ?
4535
+        // et aucun enfant n'est un tableau
4536
+        // liste simple separee par des virgules
4537
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4538
+        $array_values = array_map('is_array', $u);
4539
+        $object_values = array_map('is_object', $u);
4540
+        if (array_sum($numeric_keys) == count($numeric_keys)
4541
+            and !array_sum($array_values)
4542
+            and !array_sum($object_values)
4543
+        ) {
4544
+            return join(", ", array_map('filtre_print_dist', $u));
4545
+        }
4546 4546
 
4547
-		// sinon on passe a la ligne et on indente
4548
-		$i_str = str_pad("", $indent, " ");
4549
-		foreach ($u as $k => $v) {
4550
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4551
-		}
4547
+        // sinon on passe a la ligne et on indente
4548
+        $i_str = str_pad("", $indent, " ");
4549
+        foreach ($u as $k => $v) {
4550
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4551
+        }
4552 4552
 
4553
-		return $out;
4554
-	}
4553
+        return $out;
4554
+    }
4555 4555
 
4556
-	// on sait pas quoi faire...
4557
-	return $u;
4556
+    // on sait pas quoi faire...
4557
+    return $u;
4558 4558
 }
4559 4559
 
4560 4560
 
@@ -4567,10 +4567,10 @@  discard block
 block discarded – undo
4567 4567
  * @return string
4568 4568
  */
4569 4569
 function objet_info($objet, $info) {
4570
-	$table = table_objet_sql($objet);
4571
-	$infos = lister_tables_objets_sql($table);
4570
+    $table = table_objet_sql($objet);
4571
+    $infos = lister_tables_objets_sql($table);
4572 4572
 
4573
-	return (isset($infos[$info]) ? $infos[$info] : '');
4573
+    return (isset($infos[$info]) ? $infos[$info] : '');
4574 4574
 }
4575 4575
 
4576 4576
 /**
@@ -4585,11 +4585,11 @@  discard block
 block discarded – undo
4585 4585
  *     Texte traduit du comptage, tel que '3 articles'
4586 4586
  */
4587 4587
 function objet_afficher_nb($nb, $objet) {
4588
-	if (!$nb) {
4589
-		return _T(objet_info($objet, 'info_aucun_objet'));
4590
-	} else {
4591
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4592
-	}
4588
+    if (!$nb) {
4589
+        return _T(objet_info($objet, 'info_aucun_objet'));
4590
+    } else {
4591
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4592
+    }
4593 4593
 }
4594 4594
 
4595 4595
 /**
@@ -4601,11 +4601,11 @@  discard block
 block discarded – undo
4601 4601
  * @return string
4602 4602
  */
4603 4603
 function objet_icone($objet, $taille = 24, $class='') {
4604
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4605
-	$icone = chemin_image($icone);
4606
-	$balise_img = charger_filtre('balise_img');
4604
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4605
+    $icone = chemin_image($icone);
4606
+    $balise_img = charger_filtre('balise_img');
4607 4607
 
4608
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4608
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4609 4609
 }
4610 4610
 
4611 4611
 /**
@@ -4626,12 +4626,12 @@  discard block
 block discarded – undo
4626 4626
  * @return string
4627 4627
  */
4628 4628
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4629
-	$chaine = explode(':',$chaine);
4630
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4631
-		return $t;
4632
-	}
4633
-	$chaine = implode(':',$chaine);
4634
-	return _T($chaine, $args, $options);
4629
+    $chaine = explode(':',$chaine);
4630
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4631
+        return $t;
4632
+    }
4633
+    $chaine = implode(':',$chaine);
4634
+    return _T($chaine, $args, $options);
4635 4635
 }
4636 4636
 
4637 4637
 /**
@@ -4645,17 +4645,17 @@  discard block
 block discarded – undo
4645 4645
  * @return string      Code HTML
4646 4646
  */
4647 4647
 function insert_head_css_conditionnel($flux) {
4648
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4649
-		and $p = strpos($flux, '<!-- insert_head -->')
4650
-	) {
4651
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4652
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4653
-			$p = $p1;
4654
-		}
4655
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4656
-	}
4648
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4649
+        and $p = strpos($flux, '<!-- insert_head -->')
4650
+    ) {
4651
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4652
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4653
+            $p = $p1;
4654
+        }
4655
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4656
+    }
4657 4657
 
4658
-	return $flux;
4658
+    return $flux;
4659 4659
 }
4660 4660
 
4661 4661
 /**
@@ -4676,66 +4676,66 @@  discard block
 block discarded – undo
4676 4676
  * @return string
4677 4677
  */
4678 4678
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4679
-	if (isset($contexte['format'])) {
4680
-		$extension = $contexte['format'];
4681
-		unset($contexte['format']);
4682
-	} else {
4683
-		$extension = "html";
4684
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4685
-			$extension = $m[1];
4686
-		}
4687
-	}
4688
-	// recuperer le contenu produit par le squelette
4689
-	$options['raw'] = true;
4690
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4691
-
4692
-	// calculer le nom de la css
4693
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4694
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4695
-	$contexte_implicite = calculer_contexte_implicite();
4696
-	$filename = $dir_var . $extension . "dyn-$nom_safe-"
4697
-		. substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8)
4698
-		. ".$extension";
4699
-
4700
-	// mettre a jour le fichier si il n'existe pas
4701
-	// ou trop ancien
4702
-	// le dernier fichier produit est toujours suffixe par .last
4703
-	// et recopie sur le fichier cible uniquement si il change
4704
-	if (!file_exists($filename)
4705
-		or !file_exists($filename . ".last")
4706
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4707
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4708
-	) {
4709
-		$contenu = $cache['texte'];
4710
-		// passer les urls en absolu si c'est une css
4711
-		if ($extension == "css") {
4712
-			$contenu = urls_absolues_css($contenu,
4713
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4714
-		}
4715
-
4716
-		$comment = '';
4717
-		// ne pas insérer de commentaire si c'est du json
4718
-		if ($extension != "json") {
4719
-			$comment = "/* #PRODUIRE{fond=$fond";
4720
-			foreach ($contexte as $k => $v) {
4721
-				$comment .= ",$k=$v";
4722
-			}
4723
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4724
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4725
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4726
-		}
4727
-		// et ecrire le fichier
4728
-		ecrire_fichier($filename . ".last", $comment . $contenu);
4729
-		// regarder si on recopie
4730
-		if (!file_exists($filename)
4731
-			or md5_file($filename) !== md5_file($filename . ".last")
4732
-		) {
4733
-			@copy($filename . ".last", $filename);
4734
-			clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
4735
-		}
4736
-	}
4737
-
4738
-	return timestamp($filename);
4679
+    if (isset($contexte['format'])) {
4680
+        $extension = $contexte['format'];
4681
+        unset($contexte['format']);
4682
+    } else {
4683
+        $extension = "html";
4684
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4685
+            $extension = $m[1];
4686
+        }
4687
+    }
4688
+    // recuperer le contenu produit par le squelette
4689
+    $options['raw'] = true;
4690
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4691
+
4692
+    // calculer le nom de la css
4693
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4694
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4695
+    $contexte_implicite = calculer_contexte_implicite();
4696
+    $filename = $dir_var . $extension . "dyn-$nom_safe-"
4697
+        . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8)
4698
+        . ".$extension";
4699
+
4700
+    // mettre a jour le fichier si il n'existe pas
4701
+    // ou trop ancien
4702
+    // le dernier fichier produit est toujours suffixe par .last
4703
+    // et recopie sur le fichier cible uniquement si il change
4704
+    if (!file_exists($filename)
4705
+        or !file_exists($filename . ".last")
4706
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4707
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4708
+    ) {
4709
+        $contenu = $cache['texte'];
4710
+        // passer les urls en absolu si c'est une css
4711
+        if ($extension == "css") {
4712
+            $contenu = urls_absolues_css($contenu,
4713
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4714
+        }
4715
+
4716
+        $comment = '';
4717
+        // ne pas insérer de commentaire si c'est du json
4718
+        if ($extension != "json") {
4719
+            $comment = "/* #PRODUIRE{fond=$fond";
4720
+            foreach ($contexte as $k => $v) {
4721
+                $comment .= ",$k=$v";
4722
+            }
4723
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4724
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4725
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4726
+        }
4727
+        // et ecrire le fichier
4728
+        ecrire_fichier($filename . ".last", $comment . $contenu);
4729
+        // regarder si on recopie
4730
+        if (!file_exists($filename)
4731
+            or md5_file($filename) !== md5_file($filename . ".last")
4732
+        ) {
4733
+            @copy($filename . ".last", $filename);
4734
+            clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
4735
+        }
4736
+    }
4737
+
4738
+    return timestamp($filename);
4739 4739
 }
4740 4740
 
4741 4741
 /**
@@ -4748,14 +4748,14 @@  discard block
 block discarded – undo
4748 4748
  *    $fichier auquel on a ajouté le timestamp
4749 4749
  */
4750 4750
 function timestamp($fichier) {
4751
-	if (!$fichier
4752
-		or !file_exists($fichier)
4753
-		or !$m = filemtime($fichier)
4754
-	) {
4755
-		return $fichier;
4756
-	}
4751
+    if (!$fichier
4752
+        or !file_exists($fichier)
4753
+        or !$m = filemtime($fichier)
4754
+    ) {
4755
+        return $fichier;
4756
+    }
4757 4757
 
4758
-	return "$fichier?$m";
4758
+    return "$fichier?$m";
4759 4759
 }
4760 4760
 
4761 4761
 /**
@@ -4765,11 +4765,11 @@  discard block
 block discarded – undo
4765 4765
  * @return string
4766 4766
  */
4767 4767
 function supprimer_timestamp($url) {
4768
-	if (strpos($url, "?") === false) {
4769
-		return $url;
4770
-	}
4768
+    if (strpos($url, "?") === false) {
4769
+        return $url;
4770
+    }
4771 4771
 
4772
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4772
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4773 4773
 }
4774 4774
 
4775 4775
 /**
@@ -4784,9 +4784,9 @@  discard block
 block discarded – undo
4784 4784
  * @return string
4785 4785
  */
4786 4786
 function filtre_nettoyer_titre_email_dist($titre) {
4787
-	include_spip('inc/envoyer_mail');
4787
+    include_spip('inc/envoyer_mail');
4788 4788
 
4789
-	return nettoyer_titre_email($titre);
4789
+    return nettoyer_titre_email($titre);
4790 4790
 }
4791 4791
 
4792 4792
 /**
@@ -4808,19 +4808,19 @@  discard block
 block discarded – undo
4808 4808
  * @return string
4809 4809
  */
4810 4810
 function filtre_chercher_rubrique_dist(
4811
-	$titre,
4812
-	$id_objet,
4813
-	$id_parent,
4814
-	$objet,
4815
-	$id_secteur,
4816
-	$restreint,
4817
-	$actionable = false,
4818
-	$retour_sans_cadre = false
4811
+    $titre,
4812
+    $id_objet,
4813
+    $id_parent,
4814
+    $objet,
4815
+    $id_secteur,
4816
+    $restreint,
4817
+    $actionable = false,
4818
+    $retour_sans_cadre = false
4819 4819
 ) {
4820
-	include_spip('inc/filtres_ecrire');
4820
+    include_spip('inc/filtres_ecrire');
4821 4821
 
4822
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4823
-		$retour_sans_cadre);
4822
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4823
+        $retour_sans_cadre);
4824 4824
 }
4825 4825
 
4826 4826
 /**
@@ -4849,56 +4849,56 @@  discard block
 block discarded – undo
4849 4849
  *     Chaîne vide si l'accès est autorisé
4850 4850
  */
4851 4851
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4852
-	if ($ok) {
4853
-		return '';
4854
-	}
4855
-
4856
-	// Vider tous les tampons
4857
-	$level = @ob_get_level();
4858
-	while ($level--) {
4859
-		@ob_end_clean();
4860
-	}
4861
-
4862
-	include_spip('inc/headers');
4863
-
4864
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4865
-	if ($url) {
4866
-		redirige_par_entete($url, '', $statut);
4867
-	}
4868
-
4869
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4870
-	if (!is_numeric($statut) and is_null($message)) {
4871
-		$message = $statut;
4872
-		$statut = 0;
4873
-	}
4874
-	if (!$message) {
4875
-		$message = '';
4876
-	}
4877
-	$statut = intval($statut);
4878
-
4879
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4880
-	if (test_espace_prive()) {
4881
-		if (!$statut or !in_array($statut, array(404, 403))) {
4882
-			$statut = 403;
4883
-		}
4884
-		http_status(403);
4885
-		$echec = charger_fonction('403', 'exec');
4886
-		$echec($message);
4887
-	} else {
4888
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4889
-		if (!$statut) {
4890
-			$statut = 404;
4891
-		}
4892
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4893
-		http_status($statut);
4894
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4895
-		if ($statut >= 400) {
4896
-			echo recuperer_fond("$statut", array('erreur' => $message));
4897
-		}
4898
-	}
4899
-
4900
-
4901
-	exit;
4852
+    if ($ok) {
4853
+        return '';
4854
+    }
4855
+
4856
+    // Vider tous les tampons
4857
+    $level = @ob_get_level();
4858
+    while ($level--) {
4859
+        @ob_end_clean();
4860
+    }
4861
+
4862
+    include_spip('inc/headers');
4863
+
4864
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4865
+    if ($url) {
4866
+        redirige_par_entete($url, '', $statut);
4867
+    }
4868
+
4869
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4870
+    if (!is_numeric($statut) and is_null($message)) {
4871
+        $message = $statut;
4872
+        $statut = 0;
4873
+    }
4874
+    if (!$message) {
4875
+        $message = '';
4876
+    }
4877
+    $statut = intval($statut);
4878
+
4879
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4880
+    if (test_espace_prive()) {
4881
+        if (!$statut or !in_array($statut, array(404, 403))) {
4882
+            $statut = 403;
4883
+        }
4884
+        http_status(403);
4885
+        $echec = charger_fonction('403', 'exec');
4886
+        $echec($message);
4887
+    } else {
4888
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4889
+        if (!$statut) {
4890
+            $statut = 404;
4891
+        }
4892
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4893
+        http_status($statut);
4894
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4895
+        if ($statut >= 400) {
4896
+            echo recuperer_fond("$statut", array('erreur' => $message));
4897
+        }
4898
+    }
4899
+
4900
+
4901
+    exit;
4902 4902
 }
4903 4903
 
4904 4904
 /**
@@ -4909,9 +4909,9 @@  discard block
 block discarded – undo
4909 4909
  * @return string
4910 4910
  */
4911 4911
 function filtre_compacte_dist($source, $format = null) {
4912
-	if (function_exists('compacte')) {
4913
-		return compacte($source, $format);
4914
-	}
4912
+    if (function_exists('compacte')) {
4913
+        return compacte($source, $format);
4914
+    }
4915 4915
 
4916
-	return $source;
4916
+    return $source;
4917 4917
 }
Please login to merge, or discard this patch.
Spacing   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
 		return $f;
94 94
 	}
95
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
95
+	foreach (array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f) {
96 96
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97 97
 		// fonction ou name\space\fonction
98 98
 		if (is_callable($f)) {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 function spip_version() {
160 160
 	$version = $GLOBALS['spip_version_affichee'];
161 161
 	if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
162
-		$version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']';
162
+		$version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']';
163 163
 	}
164 164
 
165 165
 	return $version;
@@ -186,15 +186,15 @@  discard block
 block discarded – undo
186 186
 	}
187 187
 
188 188
 	// version installee par paquet ZIP
189
-	if (lire_fichier($dir . '/svn.revision', $c)
189
+	if (lire_fichier($dir.'/svn.revision', $c)
190 190
 		and preg_match(',Revision: (\d+),', $c, $d)
191 191
 	) {
192 192
 		return intval($d[1]);
193 193
 	}
194 194
 
195 195
 	// version installee par SVN
196
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
197
-		$db = new SQLite3($dir . '/.svn/wc.db');
196
+	if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) {
197
+		$db = new SQLite3($dir.'/.svn/wc.db');
198 198
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
199 199
 		if ($result) {
200 200
 			$row = $result->fetchArray();
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 				return -$row['changed_revision'];
203 203
 			}
204 204
 		}
205
-	} else if (lire_fichier($dir . '/.svn/entries', $c)
205
+	} else if (lire_fichier($dir.'/.svn/entries', $c)
206 206
 		and (
207 207
 			(preg_match_all(
208 208
 					',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
@@ -222,11 +222,11 @@  discard block
 block discarded – undo
222 222
 
223 223
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
224 224
 // et laisser passer les fonctions personnelles baptisees image_...
225
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
226
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
227
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
228
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
229
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
225
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
226
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
227
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
228
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
229
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
230 230
 
231 231
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
232 232
 $GLOBALS['spip_matrice']['couleur_foncer'] = 'inc/filtres_images_mini.php';
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
  */
373 373
 function filtre_debug($val, $key = null) {
374 374
 	$debug = (
375
-		is_null($key) ? '' : (var_export($key, true) . " = ")
376
-		) . var_export($val, true);
375
+		is_null($key) ? '' : (var_export($key, true)." = ")
376
+		).var_export($val, true);
377 377
 
378 378
 	include_spip('inc/autoriser');
379 379
 	if (autoriser('webmestre')) {
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
462 462
 							$srcover = $match[1];
463 463
 							array_shift($args);
464
-							array_unshift($args, "<img src='" . $match[1] . "' />");
464
+							array_unshift($args, "<img src='".$match[1]."' />");
465 465
 							$srcover_filter = call_user_func_array($filtre, $args);
466 466
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
467 467
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 	// " -> &quot; et tout ce genre de choses
812 812
 	$u = $GLOBALS['meta']['pcre_u'];
813 813
 	$texte = str_replace("&nbsp;", " ", $texte);
814
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
814
+	$texte = preg_replace('/\s{2,}/S'.$u, " ", $texte);
815 815
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
816 816
 	$texte = entites_html($texte, false, false);
817 817
 	// mais bien echapper les double quotes !
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
  **/
872 872
 function supprimer_numero($texte) {
873 873
 	return preg_replace(
874
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
874
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
875 875
 		"", $texte);
876 876
 }
877 877
 
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
  **/
897 897
 function recuperer_numero($texte) {
898 898
 	if (preg_match(
899
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
899
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
900 900
 		$texte, $regs)) {
901 901
 		return strval($regs[1]);
902 902
 	} else {
@@ -981,8 +981,8 @@  discard block
 block discarded – undo
981 981
  **/
982 982
 function textebrut($texte) {
983 983
 	$u = $GLOBALS['meta']['pcre_u'];
984
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
985
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
984
+	$texte = preg_replace('/\s+/S'.$u, " ", $texte);
985
+	$texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte);
986 986
 	$texte = preg_replace("/^\n+/", "", $texte);
987 987
 	$texte = preg_replace("/\n+$/", "", $texte);
988 988
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1011 1011
 		$texte, $liens, PREG_PATTERN_ORDER)) {
1012 1012
 		foreach ($liens[0] as $a) {
1013
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1013
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1014 1014
 			$ablank = inserer_attribut($a, 'rel', $rel);
1015 1015
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1016 1016
 			$texte = str_replace($a, $ablank, $texte);
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 		foreach ($regs[0] as $a) {
1036 1036
 			$rel = extraire_attribut($a, "rel");
1037 1037
 			if (strpos($rel, "nofollow") === false) {
1038
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1038
+				$rel = "nofollow".($rel ? " $rel" : "");
1039 1039
 				$anofollow = inserer_attribut($a, "rel", $rel);
1040 1040
 				$texte = str_replace($a, $anofollow, $texte);
1041 1041
 			}
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 	$u = $GLOBALS['meta']['pcre_u'];
1065 1065
 	$texte = preg_replace("@</p>@iS", "\n", $texte);
1066 1066
 	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1067
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1067
+	$texte = preg_replace("@^\s*<br />@S".$u, "", $texte);
1068 1068
 
1069 1069
 	return $texte;
1070 1070
 }
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 		return $texte;
1095 1095
 	}
1096 1096
 	include_spip('inc/texte');
1097
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1097
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1098 1098
 		'div' : 'span';
1099 1099
 
1100 1100
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
 function attribut_html($texte, $textebrut = true) {
1204 1204
 	$u = $GLOBALS['meta']['pcre_u'];
1205 1205
 	if ($textebrut) {
1206
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1206
+		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS".$u), array(" ", ""), textebrut($texte));
1207 1207
 	}
1208 1208
 	$texte = texte_backend($texte);
1209 1209
 	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
 	# un message pour abs_url
1233 1233
 	$GLOBALS['mode_abs_url'] = 'url';
1234 1234
 	$url = trim($url);
1235
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1235
+	$r = ",^(?:"._PROTOCOLES_STD.'):?/?/?$,iS';
1236 1236
 
1237 1237
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1238 1238
 }
@@ -1434,14 +1434,14 @@  discard block
 block discarded – undo
1434 1434
 	if (strpos($texte, "<") !== false) {
1435 1435
 		include_spip('inc/lien');
1436 1436
 		if (defined('_PREG_MODELE')) {
1437
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1437
+			$preg_modeles = "@"._PREG_MODELE."@imsS";
1438 1438
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1439 1439
 		}
1440 1440
 	}
1441 1441
 
1442 1442
 	$debut = '';
1443 1443
 	$suite = $texte;
1444
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1444
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1445 1445
 		$debut .= substr($suite, 0, $t - 1);
1446 1446
 		$suite = substr($suite, $t);
1447 1447
 		$car = substr($suite, 0, 1);
@@ -1458,11 +1458,11 @@  discard block
 block discarded – undo
1458 1458
 			$suite = substr($suite, strlen($regs[0]));
1459 1459
 		}
1460 1460
 	}
1461
-	$texte = $debut . $suite;
1461
+	$texte = $debut.$suite;
1462 1462
 
1463 1463
 	$texte = echappe_retour($texte);
1464 1464
 
1465
-	return $texte . $fin;
1465
+	return $texte.$fin;
1466 1466
 }
1467 1467
 
1468 1468
 
@@ -1523,7 +1523,7 @@  discard block
 block discarded – undo
1523 1523
 		}
1524 1524
 
1525 1525
 		foreach ($regs as $reg) {
1526
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1526
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1527 1527
 			$desc = $traduire($cle, $lang, true);
1528 1528
 			$l = $desc->langue;
1529 1529
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1637 1637
 					include_spip('inc/texte');
1638 1638
 					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1639
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1639
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1640 1640
 					$trad = code_echappement($trad, 'multi', false, $mode);
1641 1641
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1642 1642
 					if (lang_dir($l) !== lang_dir($lang)) {
@@ -1829,7 +1829,7 @@  discard block
 block discarded – undo
1829 1829
 	if (is_array($balise)) {
1830 1830
 		array_walk(
1831 1831
 			$balise,
1832
-			function(&$a, $key, $t){
1832
+			function(&$a, $key, $t) {
1833 1833
 				$a = extraire_attribut($a, $t);
1834 1834
 			},
1835 1835
 			$attribut
@@ -1916,14 +1916,14 @@  discard block
 block discarded – undo
1916 1916
 
1917 1917
 	if ($old !== null) {
1918 1918
 		// Remplacer l'ancien attribut du meme nom
1919
-		$balise = $r[1] . $insert . $r[5];
1919
+		$balise = $r[1].$insert.$r[5];
1920 1920
 	} else {
1921 1921
 		// preferer une balise " />" (comme <img />)
1922 1922
 		if (preg_match(',/>,', $balise)) {
1923
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1923
+			$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1924 1924
 		} // sinon une balise <a ...> ... </a>
1925 1925
 		else {
1926
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1926
+			$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1927 1927
 		}
1928 1928
 	}
1929 1929
 
@@ -1965,8 +1965,8 @@  discard block
 block discarded – undo
1965 1965
 //
1966 1966
 // Quelques fonctions de calcul arithmetique
1967 1967
 //
1968
-function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
1969
-function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
1968
+function floatstr($a) { return str_replace(',', '.', (string) floatval($a)); }
1969
+function strize($f, $a, $b) { return floatstr($f(floatstr($a), floatstr($b))); }
1970 1970
 
1971 1971
 /**
1972 1972
  * Additionne 2 nombres
@@ -1986,7 +1986,7 @@  discard block
 block discarded – undo
1986 1986
 function plus($a, $b) {
1987 1987
 	return $a + $b;
1988 1988
 }
1989
-function strplus($a, $b) {return strize('plus', $a, $b);}
1989
+function strplus($a, $b) {return strize('plus', $a, $b); }
1990 1990
 /**
1991 1991
  * Soustrait 2 nombres
1992 1992
  *
@@ -2005,7 +2005,7 @@  discard block
 block discarded – undo
2005 2005
 function moins($a, $b) {
2006 2006
 	return $a - $b;
2007 2007
 }
2008
-function strmoins($a, $b) {return strize('moins', $a, $b);}
2008
+function strmoins($a, $b) {return strize('moins', $a, $b); }
2009 2009
 
2010 2010
 /**
2011 2011
  * Multiplie 2 nombres
@@ -2026,7 +2026,7 @@  discard block
 block discarded – undo
2026 2026
 function mult($a, $b) {
2027 2027
 	return $a * $b;
2028 2028
 }
2029
-function strmult($a, $b) {return strize('mult', $a, $b);}
2029
+function strmult($a, $b) {return strize('mult', $a, $b); }
2030 2030
 
2031 2031
 /**
2032 2032
  * Divise 2 nombres
@@ -2047,7 +2047,7 @@  discard block
 block discarded – undo
2047 2047
 function div($a, $b) {
2048 2048
 	return $b ? $a / $b : 0;
2049 2049
 }
2050
-function strdiv($a, $b) {return strize('div', $a, $b);}
2050
+function strdiv($a, $b) {return strize('div', $a, $b); }
2051 2051
 
2052 2052
 /**
2053 2053
  * Retourne le modulo 2 nombres
@@ -2088,13 +2088,13 @@  discard block
 block discarded – undo
2088 2088
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2089 2089
 		define('_TAGS_NOM_AUTEUR', '');
2090 2090
 	}
2091
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2091
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2092 2092
 	foreach ($tags_acceptes as $tag) {
2093 2093
 		if (strlen($tag)) {
2094
-			$remp1[] = '<' . trim($tag) . '>';
2095
-			$remp1[] = '</' . trim($tag) . '>';
2096
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2097
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2094
+			$remp1[] = '<'.trim($tag).'>';
2095
+			$remp1[] = '</'.trim($tag).'>';
2096
+			$remp2[] = '\x60'.trim($tag).'\x61';
2097
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2098 2098
 		}
2099 2099
 	}
2100 2100
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2157,7 +2157,7 @@  discard block
 block discarded – undo
2157 2157
 			$s[] = preg_replace(',>[^<]+</a>,S',
2158 2158
 				'>'
2159 2159
 				. http_img_pack('attachment-16.png', $t,
2160
-					'title="' . attribut_html($t) . '"')
2160
+					'title="'.attribut_html($t).'"')
2161 2161
 				. '</a>', $tag);
2162 2162
 		}
2163 2163
 	}
@@ -2218,10 +2218,10 @@  discard block
 block discarded – undo
2218 2218
 	$fichier = basename($url);
2219 2219
 
2220 2220
 	return '<a rel="enclosure"'
2221
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2222
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2223
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2224
-	. '>' . $fichier . '</a>';
2221
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2222
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2223
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2224
+	. '>'.$fichier.'</a>';
2225 2225
 }
2226 2226
 
2227 2227
 /**
@@ -2249,9 +2249,9 @@  discard block
 block discarded – undo
2249 2249
 			} # vieux data
2250 2250
 			$fichier = basename($url);
2251 2251
 			$enclosures[] = '<enclosure'
2252
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2253
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2254
-				. ($length ? ' length="' . $length . '"' : '')
2252
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2253
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2254
+				. ($length ? ' length="'.$length.'"' : '')
2255 2255
 				. ' />';
2256 2256
 		}
2257 2257
 	}
@@ -2277,7 +2277,7 @@  discard block
 block discarded – undo
2277 2277
 		if (extraire_attribut($e, rel) == 'tag') {
2278 2278
 			$subjects .= '<dc:subject>'
2279 2279
 				. texte_backend(textebrut($e))
2280
-				. '</dc:subject>' . "\n";
2280
+				. '</dc:subject>'."\n";
2281 2281
 		}
2282 2282
 	}
2283 2283
 
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
 	if (is_array($texte)) {
2314 2314
 		array_walk(
2315 2315
 			$texte,
2316
-			function(&$a, $key, $t){
2316
+			function(&$a, $key, $t) {
2317 2317
 				$a = extraire_balise($a, $t);
2318 2318
 			},
2319 2319
 			$tag
@@ -2357,7 +2357,7 @@  discard block
 block discarded – undo
2357 2357
 	if (is_array($texte)) {
2358 2358
 		array_walk(
2359 2359
 			$texte,
2360
-			function(&$a, $key, $t){
2360
+			function(&$a, $key, $t) {
2361 2361
 				$a = extraire_balises($a, $t);
2362 2362
 			},
2363 2363
 			$tag
@@ -2483,7 +2483,7 @@  discard block
 block discarded – undo
2483 2483
 		if ($fond != '404') {
2484 2484
 			$contexte = array_shift($p);
2485 2485
 			$contexte['page'] = $fond;
2486
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2486
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2487 2487
 		}
2488 2488
 	}
2489 2489
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2538,9 +2538,9 @@  discard block
 block discarded – undo
2538 2538
 			. '"'
2539 2539
 			. (is_null($val)
2540 2540
 				? ''
2541
-				: ' value="' . entites_html($val) . '"'
2541
+				: ' value="'.entites_html($val).'"'
2542 2542
 			)
2543
-			. ' type="hidden"' . "\n/>";
2543
+			. ' type="hidden"'."\n/>";
2544 2544
 	}
2545 2545
 
2546 2546
 	return join("", $hidden);
@@ -2703,12 +2703,12 @@  discard block
 block discarded – undo
2703 2703
 	if ($pas < 1) {
2704 2704
 		return '';
2705 2705
 	}
2706
-	$ancre = 'pagination' . $nom; // #pagination_articles
2707
-	$debut = 'debut' . $nom; // 'debut_articles'
2706
+	$ancre = 'pagination'.$nom; // #pagination_articles
2707
+	$debut = 'debut'.$nom; // 'debut_articles'
2708 2708
 
2709 2709
 	// n'afficher l'ancre qu'une fois
2710 2710
 	if (!isset($ancres[$ancre])) {
2711
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2711
+		$bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2712 2712
 	} else {
2713 2713
 		$bloc_ancre = '';
2714 2714
 	}
@@ -2739,7 +2739,7 @@  discard block
 block discarded – undo
2739 2739
 	}
2740 2740
 
2741 2741
 	if ($modele) {
2742
-		$modele = '_' . $modele;
2742
+		$modele = '_'.$modele;
2743 2743
 	}
2744 2744
 
2745 2745
 	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
@@ -2764,7 +2764,7 @@  discard block
 block discarded – undo
2764 2764
 	return preg_replace_callback(
2765 2765
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2766 2766
 		function($x) use ($path) {
2767
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2767
+			return "url('".suivre_lien($path, $x[1])."')";
2768 2768
 		},
2769 2769
 		$contenu
2770 2770
 	);
@@ -2826,14 +2826,14 @@  discard block
 block discarded – undo
2826 2826
 	) {
2827 2827
 		$distant = true;
2828 2828
 		$cssf = parse_url($css);
2829
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2829
+		$cssf = $cssf['path'].($cssf['query'] ? "?".$cssf['query'] : "");
2830 2830
 		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2831 2831
 	} else {
2832 2832
 		$distant = false;
2833 2833
 		$cssf = $css;
2834 2834
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2835 2835
 		//propose (rien a faire dans ce cas)
2836
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2836
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2837 2837
 		if (@file_exists($f)) {
2838 2838
 			return $f;
2839 2839
 		}
@@ -2843,7 +2843,7 @@  discard block
 block discarded – undo
2843 2843
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2844 2844
 	$f = $dir_var
2845 2845
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2846
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2846
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2847 2847
 
2848 2848
 	// la css peut etre distante (url absolue !)
2849 2849
 	if ($distant) {
@@ -2888,8 +2888,8 @@  discard block
 block discarded – undo
2888 2888
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2889 2889
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2890 2890
 			$css_direction = substr($css_direction, strlen($dir_var));
2891
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2892
-			$css_direction = "/@@@@@@/" . $css_direction;
2891
+			$src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2892
+			$css_direction = "/@@@@@@/".$css_direction;
2893 2893
 		}
2894 2894
 		$src[] = $regs[0][$k];
2895 2895
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -2938,7 +2938,7 @@  discard block
 block discarded – undo
2938 2938
 
2939 2939
 	$f = basename($css, '.css');
2940 2940
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2941
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2941
+		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
2942 2942
 		. '.css';
2943 2943
 
2944 2944
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -2947,7 +2947,7 @@  discard block
 block discarded – undo
2947 2947
 
2948 2948
 	if ($url_absolue_css == $css) {
2949 2949
 		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2950
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2950
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
2951 2951
 		) {
2952 2952
 			include_spip('inc/distant');
2953 2953
 			if (!$contenu = recuperer_page($css)) {
@@ -3057,7 +3057,7 @@  discard block
 block discarded – undo
3057 3057
 	$expression = str_replace("\/", "/", $expression);
3058 3058
 	$expression = str_replace("/", "\/", $expression);
3059 3059
 
3060
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3060
+	if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) {
3061 3061
 		if (isset($r[$capte])) {
3062 3062
 			return $r[$capte];
3063 3063
 		} else {
@@ -3095,7 +3095,7 @@  discard block
 block discarded – undo
3095 3095
 	$expression = str_replace("\/", "/", $expression);
3096 3096
 	$expression = str_replace("/", "\/", $expression);
3097 3097
 
3098
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3098
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3099 3099
 }
3100 3100
 
3101 3101
 
@@ -3114,7 +3114,7 @@  discard block
 block discarded – undo
3114 3114
 function traiter_doublons_documents(&$doublons, $letexte) {
3115 3115
 
3116 3116
 	// Verifier dans le texte & les notes (pas beau, helas)
3117
-	$t = $letexte . $GLOBALS['les_notes'];
3117
+	$t = $letexte.$GLOBALS['les_notes'];
3118 3118
 
3119 3119
 	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3120 3120
 		and preg_match_all(
@@ -3124,7 +3124,7 @@  discard block
 block discarded – undo
3124 3124
 		if (!isset($doublons['documents'])) {
3125 3125
 			$doublons['documents'] = "";
3126 3126
 		}
3127
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3127
+		$doublons['documents'] .= ",".join(',', $matches[1]);
3128 3128
 	}
3129 3129
 
3130 3130
 	return $letexte;
@@ -3181,7 +3181,7 @@  discard block
 block discarded – undo
3181 3181
 	if ($env) {
3182 3182
 		foreach ($env as $i => $j) {
3183 3183
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3184
-				$texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3184
+				$texte .= "<param name='".$i."'\n\tvalue='".$j."' />";
3185 3185
 			}
3186 3186
 		}
3187 3187
 	}
@@ -3220,7 +3220,7 @@  discard block
 block discarded – undo
3220 3220
 	if ($env) {
3221 3221
 		foreach ($env as $i => $j) {
3222 3222
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3223
-				$texte .= $i . "='" . $j . "' ";
3223
+				$texte .= $i."='".$j."' ";
3224 3224
 			}
3225 3225
 		}
3226 3226
 	}
@@ -3304,19 +3304,19 @@  discard block
 block discarded – undo
3304 3304
 
3305 3305
 	$img_file = $img;
3306 3306
 	if ($p = strpos($img_file, '?')) {
3307
-		$img_file = substr($img_file,0, $p);
3307
+		$img_file = substr($img_file, 0, $p);
3308 3308
 	}
3309 3309
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3310 3310
 		$img_file = chemin_image($img);
3311 3311
 	}
3312 3312
 	else {
3313
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3313
+		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3314 3314
 			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3315 3315
 			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3316 3316
 			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3317
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3317
+			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0]))."-xx.svg"
3318 3318
 			  and file_exists($variante_svg_generique)) {
3319
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3319
+				if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].".svg" and file_exists($variante_svg_size)) {
3320 3320
 					$img_file = $variante_svg_size;
3321 3321
 				}
3322 3322
 				else {
@@ -3341,15 +3341,15 @@  discard block
 block discarded – undo
3341 3341
 				return "";
3342 3342
 			}
3343 3343
 		}
3344
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3344
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3345 3345
 	}
3346 3346
 
3347 3347
 	if (file_exists($img_file)) {
3348 3348
 		$img_file = timestamp($img_file);
3349 3349
 	}
3350
-	return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3351
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3352
-	. " " . ltrim($atts)
3350
+	return "<img src='$img_file' alt='".attribut_html($alt ? $alt : $title)."'"
3351
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3352
+	. " ".ltrim($atts)
3353 3353
 	. " />";
3354 3354
 }
3355 3355
 
@@ -3361,12 +3361,12 @@  discard block
 block discarded – undo
3361 3361
  * @param string $size
3362 3362
  * @return string
3363 3363
  */
3364
-function http_style_background($img, $att = '', $size=null) {
3365
-	if ($size and is_numeric($size)){
3366
-		$size = trim($size) . "px";
3364
+function http_style_background($img, $att = '', $size = null) {
3365
+	if ($size and is_numeric($size)) {
3366
+		$size = trim($size)."px";
3367 3367
 	}
3368
-	return " style='background" .
3369
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3368
+	return " style='background".
3369
+		($att ? "" : "-image").": url(\"".chemin_image($img)."\")".($att ? (' '.$att) : '').";"
3370 3370
 		. ($size ? "background-size:{$size};" : '')
3371 3371
 		. "'";
3372 3372
 }
@@ -3383,8 +3383,8 @@  discard block
 block discarded – undo
3383 3383
  * @return string
3384 3384
  *     Code HTML de la balise IMG
3385 3385
  */
3386
-function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3387
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3386
+function filtre_balise_img_dist($img, $alt = "", $class = "", $width = null) {
3387
+	$atts = $class ? " class='".attribut_html($class)."'" : '';
3388 3388
 	// ecriture courte : on donne le width en 2e arg
3389 3389
 	if (empty($width) and is_numeric($alt)) {
3390 3390
 		$width = $alt;
@@ -3412,7 +3412,7 @@  discard block
 block discarded – undo
3412 3412
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3413 3413
 	$img_file = $img;
3414 3414
 	if ($p = strpos($img_file, '?')) {
3415
-		$img_file = substr($img_file,0, $p);
3415
+		$img_file = substr($img_file, 0, $p);
3416 3416
 	}
3417 3417
 
3418 3418
 	if (!$img_file or !$svg = file_get_contents($img_file)) {
@@ -3426,18 +3426,18 @@  discard block
 block discarded – undo
3426 3426
 	$balise_svg_source = $balise_svg;
3427 3427
 
3428 3428
 	// entete XML à supprimer
3429
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3429
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3430 3430
 
3431 3431
 	// IE est toujours mon ami
3432 3432
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3433 3433
 	if ($class) {
3434 3434
 		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3435 3435
 	}
3436
-	if ($alt){
3436
+	if ($alt) {
3437 3437
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3438
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3438
+		$id = "img-svg-title-".substr(md5("$img_file:$svg:$alt"), 0, 4);
3439 3439
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3440
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3440
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3441 3441
 		$balise_svg .= $title;
3442 3442
 	}
3443 3443
 	else {
@@ -3471,7 +3471,7 @@  discard block
 block discarded – undo
3471 3471
 	$texte = '';
3472 3472
 	if (is_array($tableau)) {
3473 3473
 		foreach ($tableau as $k => $v) {
3474
-			$res = recuperer_fond('modeles/' . $modele,
3474
+			$res = recuperer_fond('modeles/'.$modele,
3475 3475
 				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3476 3476
 			);
3477 3477
 			$texte .= $res;
@@ -3648,7 +3648,7 @@  discard block
 block discarded – undo
3648 3648
 	}
3649 3649
 
3650 3650
 	$c = serialize($c);
3651
-	$cle = calculer_cle_action($form . $c);
3651
+	$cle = calculer_cle_action($form.$c);
3652 3652
 	$c = "$cle:$c";
3653 3653
 
3654 3654
 	// on ne stocke pas les contextes dans des fichiers caches
@@ -3698,15 +3698,15 @@  discard block
 block discarded – undo
3698 3698
 	}
3699 3699
 	// toujours encoder l'url source dans le bloc ajax
3700 3700
 	$r = self();
3701
-	$r = ' data-origin="' . $r . '"';
3701
+	$r = ' data-origin="'.$r.'"';
3702 3702
 	$class = 'ajaxbloc';
3703 3703
 	if ($ajaxid and is_string($ajaxid)) {
3704 3704
 		// ajaxid est normalement conforme a un nom de classe css
3705 3705
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3706
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3706
+		$class .= ' ajax-id-'.entites_html($ajaxid);
3707 3707
 	}
3708 3708
 
3709
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3709
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3710 3710
 }
3711 3711
 
3712 3712
 /**
@@ -3745,11 +3745,11 @@  discard block
 block discarded – undo
3745 3745
 	// extraire la signature en debut de contexte
3746 3746
 	// et la verifier avant de deserializer
3747 3747
 	// format : signature:donneesserializees
3748
-	if ($p = strpos($c,":")){
3749
-		$cle = substr($c,0,$p);
3750
-		$c = substr($c,$p+1);
3748
+	if ($p = strpos($c, ":")) {
3749
+		$cle = substr($c, 0, $p);
3750
+		$c = substr($c, $p + 1);
3751 3751
 
3752
-		if ($cle == calculer_cle_action($form . $c)) {
3752
+		if ($cle == calculer_cle_action($form.$c)) {
3753 3753
 			$env = @unserialize($c);
3754 3754
 			return $env;
3755 3755
 		}
@@ -3850,9 +3850,9 @@  discard block
 block discarded – undo
3850 3850
 	} else {
3851 3851
 		$bal = 'a';
3852 3852
 		$att = "href='$url'"
3853
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3854
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3855
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3853
+			. ($title ? " title='".attribut_html($title)."'" : '')
3854
+			. ($class ? " class='".attribut_html($class)."'" : '')
3855
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
3856 3856
 			. $evt;
3857 3857
 	}
3858 3858
 	if ($libelle === null) {
@@ -3927,7 +3927,7 @@  discard block
 block discarded – undo
3927 3927
 	}
3928 3928
 
3929 3929
 	// ajouter le type d'objet dans la class de l'icone
3930
-	$class .= " " . substr(basename($fond), 0, -4);
3930
+	$class .= " ".substr(basename($fond), 0, -4);
3931 3931
 
3932 3932
 	$alt = attribut_html($texte);
3933 3933
 	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
@@ -3951,7 +3951,7 @@  discard block
 block discarded – undo
3951 3951
 	}
3952 3952
 
3953 3953
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3954
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3954
+	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "")."\">$icone</span>";
3955 3955
 
3956 3956
 	if ($type == 'lien') {
3957 3957
 		return "<span class='icone s$size $class'>"
@@ -4181,13 +4181,13 @@  discard block
 block discarded – undo
4181 4181
 	$res = "";
4182 4182
 	foreach ($boutons as $page => $detail) {
4183 4183
 		if ($detail->icone and strlen(trim($detail->icone))) {
4184
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4184
+			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
4185 4185
 		}
4186 4186
 		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4187 4187
 		if (is_array($detail->sousmenu)) {
4188 4188
 			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4189 4189
 				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4190
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4190
+					$res .= "\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
4191 4191
 				}
4192 4192
 			}
4193 4193
 		}
@@ -4213,17 +4213,17 @@  discard block
 block discarded – undo
4213 4213
  */
4214 4214
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4215 4215
 	if ($confirm) {
4216
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4216
+		$confirm = "confirm(\"".attribut_html($confirm)."\")";
4217 4217
 		if ($callback) {
4218 4218
 			$callback = "$confirm?($callback):false";
4219 4219
 		} else {
4220 4220
 			$callback = $confirm;
4221 4221
 		}
4222 4222
 	}
4223
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4223
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : "";
4224 4224
 	$title = $title ? " title='$title'" : "";
4225 4225
 
4226
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4226
+	return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url)
4227 4227
 	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4228 4228
 }
4229 4229
 
@@ -4362,14 +4362,14 @@  discard block
 block discarded – undo
4362 4362
 		$champ_titre = "";
4363 4363
 		if ($demande_titre) {
4364 4364
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4365
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4365
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4366 4366
 		}
4367 4367
 		include_spip('base/abstract_sql');
4368 4368
 		include_spip('base/connect_sql');
4369 4369
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4370
-			'*' . $champ_titre,
4370
+			'*'.$champ_titre,
4371 4371
 			$desc['table_sql'],
4372
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4372
+			id_table_objet($type_objet).' = '.intval($id_objet)
4373 4373
 		);
4374 4374
 	}
4375 4375
 
@@ -4439,7 +4439,7 @@  discard block
 block discarded – undo
4439 4439
 		return $texte;
4440 4440
 	}
4441 4441
 
4442
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4442
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4443 4443
 
4444 4444
 	// Fournir $connect et $Pile[0] au traitement si besoin
4445 4445
 	$Pile = array(0 => $env);
@@ -4473,7 +4473,7 @@  discard block
 block discarded – undo
4473 4473
 	}
4474 4474
 	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4475 4475
 
4476
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4476
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur)."</a>";
4477 4477
 }
4478 4478
 
4479 4479
 
@@ -4492,10 +4492,10 @@  discard block
 block discarded – undo
4492 4492
 function wrap($texte, $wrap) {
4493 4493
 	$balises = extraire_balises($wrap);
4494 4494
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4495
-		$texte = $wrap . $texte;
4495
+		$texte = $wrap.$texte;
4496 4496
 		$regs = array_reverse($regs[1]);
4497
-		$wrap = "</" . implode("></", $regs) . ">";
4498
-		$texte = $texte . $wrap;
4497
+		$wrap = "</".implode("></", $regs).">";
4498
+		$texte = $texte.$wrap;
4499 4499
 	}
4500 4500
 
4501 4501
 	return $texte;
@@ -4526,7 +4526,7 @@  discard block
 block discarded – undo
4526 4526
 
4527 4527
 	// caster $u en array si besoin
4528 4528
 	if (is_object($u)) {
4529
-		$u = (array)$u;
4529
+		$u = (array) $u;
4530 4530
 	}
4531 4531
 
4532 4532
 	if (is_array($u)) {
@@ -4547,7 +4547,7 @@  discard block
 block discarded – undo
4547 4547
 		// sinon on passe a la ligne et on indente
4548 4548
 		$i_str = str_pad("", $indent, " ");
4549 4549
 		foreach ($u as $k => $v) {
4550
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4550
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4551 4551
 		}
4552 4552
 
4553 4553
 		return $out;
@@ -4600,8 +4600,8 @@  discard block
 block discarded – undo
4600 4600
  * @param string $class
4601 4601
  * @return string
4602 4602
  */
4603
-function objet_icone($objet, $taille = 24, $class='') {
4604
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4603
+function objet_icone($objet, $taille = 24, $class = '') {
4604
+	$icone = objet_info($objet, 'icone_objet')."-".$taille.".png";
4605 4605
 	$icone = chemin_image($icone);
4606 4606
 	$balise_img = charger_filtre('balise_img');
4607 4607
 
@@ -4625,12 +4625,12 @@  discard block
 block discarded – undo
4625 4625
  * @param array $options
4626 4626
  * @return string
4627 4627
  */
4628
-function objet_T($objet, $chaine, $args = array(), $options = array()){
4629
-	$chaine = explode(':',$chaine);
4630
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4628
+function objet_T($objet, $chaine, $args = array(), $options = array()) {
4629
+	$chaine = explode(':', $chaine);
4630
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, array('force'=>false)))) {
4631 4631
 		return $t;
4632 4632
 	}
4633
-	$chaine = implode(':',$chaine);
4633
+	$chaine = implode(':', $chaine);
4634 4634
 	return _T($chaine, $args, $options);
4635 4635
 }
4636 4636
 
@@ -4690,11 +4690,11 @@  discard block
 block discarded – undo
4690 4690
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4691 4691
 
4692 4692
 	// calculer le nom de la css
4693
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4693
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
4694 4694
 	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4695 4695
 	$contexte_implicite = calculer_contexte_implicite();
4696
-	$filename = $dir_var . $extension . "dyn-$nom_safe-"
4697
-		. substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8)
4696
+	$filename = $dir_var.$extension."dyn-$nom_safe-"
4697
+		. substr(md5($fond.serialize($contexte_implicite).serialize($contexte).$connect), 0, 8)
4698 4698
 		. ".$extension";
4699 4699
 
4700 4700
 	// mettre a jour le fichier si il n'existe pas
@@ -4702,8 +4702,8 @@  discard block
 block discarded – undo
4702 4702
 	// le dernier fichier produit est toujours suffixe par .last
4703 4703
 	// et recopie sur le fichier cible uniquement si il change
4704 4704
 	if (!file_exists($filename)
4705
-		or !file_exists($filename . ".last")
4706
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4705
+		or !file_exists($filename.".last")
4706
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.".last") < $cache['lastmodified'])
4707 4707
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4708 4708
 	) {
4709 4709
 		$contenu = $cache['texte'];
@@ -4722,15 +4722,15 @@  discard block
 block discarded – undo
4722 4722
 			}
4723 4723
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4724 4724
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4725
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4725
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
4726 4726
 		}
4727 4727
 		// et ecrire le fichier
4728
-		ecrire_fichier($filename . ".last", $comment . $contenu);
4728
+		ecrire_fichier($filename.".last", $comment.$contenu);
4729 4729
 		// regarder si on recopie
4730 4730
 		if (!file_exists($filename)
4731
-			or md5_file($filename) !== md5_file($filename . ".last")
4731
+			or md5_file($filename) !== md5_file($filename.".last")
4732 4732
 		) {
4733
-			@copy($filename . ".last", $filename);
4733
+			@copy($filename.".last", $filename);
4734 4734
 			clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
4735 4735
 		}
4736 4736
 	}
Please login to merge, or discard this patch.