Completed
Push — master ( f49af5...0c4aee )
by cam
08:14
created
ecrire/inc/utils.php 1 patch
Indentation   +2124 added lines, -2125 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
 /**
@@ -637,13 +636,13 @@  discard block
 block discarded – undo
637 636
  * @return string
638 637
  */
639 638
 function nettoyer_uri_var($request_uri) {
640
-	$uri1 = $request_uri;
641
-	do {
642
-		$uri = $uri1;
643
-		$uri1 = preg_replace(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
644
-			'\1', $uri);
645
-	} while ($uri <> $uri1);
646
-	return preg_replace(',[?&]$,', '', $uri1);
639
+    $uri1 = $request_uri;
640
+    do {
641
+        $uri = $uri1;
642
+        $uri1 = preg_replace(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
643
+            '\1', $uri);
644
+    } while ($uri <> $uri1);
645
+    return preg_replace(',[?&]$,', '', $uri1);
647 646
 }
648 647
 
649 648
 
@@ -657,47 +656,47 @@  discard block
 block discarded – undo
657 656
  *    URL vers soi-même
658 657
  **/
659 658
 function self($amp = '&amp;', $root = false) {
660
-	$url = nettoyer_uri();
661
-	if (!$root
662
-		and (
663
-			// si pas de profondeur on peut tronquer
664
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
665
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
666
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
667
-	) {
668
-		$url = preg_replace(',^[^?]*/,', '', $url);
669
-	}
670
-	// ajouter le cas echeant les variables _POST['id_...']
671
-	foreach ($_POST as $v => $c) {
672
-		if (substr($v, 0, 3) == 'id_') {
673
-			$url = parametre_url($url, $v, $c, '&');
674
-		}
675
-	}
676
-
677
-	// supprimer les variables sans interet
678
-	if (test_espace_prive()) {
679
-		$url = preg_replace(',([?&])('
680
-			. 'lang|show_docs|'
681
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
682
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
683
-		$url = preg_replace(',[&]$,', '\1', $url);
684
-	}
685
-
686
-	// eviter les hacks
687
-	include_spip('inc/filtres_mini');
688
-	$url = spip_htmlspecialchars($url);
659
+    $url = nettoyer_uri();
660
+    if (!$root
661
+        and (
662
+            // si pas de profondeur on peut tronquer
663
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
664
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
665
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
666
+    ) {
667
+        $url = preg_replace(',^[^?]*/,', '', $url);
668
+    }
669
+    // ajouter le cas echeant les variables _POST['id_...']
670
+    foreach ($_POST as $v => $c) {
671
+        if (substr($v, 0, 3) == 'id_') {
672
+            $url = parametre_url($url, $v, $c, '&');
673
+        }
674
+    }
675
+
676
+    // supprimer les variables sans interet
677
+    if (test_espace_prive()) {
678
+        $url = preg_replace(',([?&])('
679
+            . 'lang|show_docs|'
680
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
681
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
682
+        $url = preg_replace(',[&]$,', '\1', $url);
683
+    }
684
+
685
+    // eviter les hacks
686
+    include_spip('inc/filtres_mini');
687
+    $url = spip_htmlspecialchars($url);
689 688
 	
690
-	$url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
689
+    $url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
691 690
 
692
-	// &amp; ?
693
-	if ($amp != '&amp;') {
694
-		$url = str_replace('&amp;', $amp, $url);
695
-	}
691
+    // &amp; ?
692
+    if ($amp != '&amp;') {
693
+        $url = str_replace('&amp;', $amp, $url);
694
+    }
696 695
 
697
-	// Si ca demarre par ? ou vide, donner './'
698
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
696
+    // Si ca demarre par ? ou vide, donner './'
697
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
699 698
 
700
-	return $url;
699
+    return $url;
701 700
 }
702 701
 
703 702
 
@@ -708,7 +707,7 @@  discard block
 block discarded – undo
708 707
  *     true si c'est le cas, false sinon.
709 708
  */
710 709
 function test_espace_prive() {
711
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
710
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
712 711
 }
713 712
 
714 713
 /**
@@ -718,7 +717,7 @@  discard block
 block discarded – undo
718 717
  * @return bool
719 718
  */
720 719
 function test_plugin_actif($plugin) {
721
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
720
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
722 721
 }
723 722
 
724 723
 /**
@@ -749,51 +748,51 @@  discard block
 block discarded – undo
749 748
  *     Texte
750 749
  */
751 750
 function _T($texte, $args = array(), $options = array()) {
752
-	static $traduire = false;
753
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
754
-	if ($options) {
755
-		// support de l'ancien argument $class
756
-		if (is_string($options)) {
757
-			$options = array('class' => $options);
758
-		}
759
-		$o = array_merge($o, $options);
760
-	}
751
+    static $traduire = false;
752
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
753
+    if ($options) {
754
+        // support de l'ancien argument $class
755
+        if (is_string($options)) {
756
+            $options = array('class' => $options);
757
+        }
758
+        $o = array_merge($o, $options);
759
+    }
761 760
 
762
-	if (!$traduire) {
763
-		$traduire = charger_fonction('traduire', 'inc');
764
-		include_spip('inc/lang');
765
-	}
761
+    if (!$traduire) {
762
+        $traduire = charger_fonction('traduire', 'inc');
763
+        include_spip('inc/lang');
764
+    }
766 765
 
767
-	// On peut passer explicitement la langue dans le tableau
768
-	// On utilise le même nom de variable que la globale
769
-	if (isset($args['spip_lang'])) {
770
-		$lang = $args['spip_lang'];
771
-		// On l'enleve pour ne pas le passer au remplacement
772
-		unset($args['spip_lang']);
773
-	} // Sinon on prend la langue du contexte
774
-	else {
775
-		$lang = $GLOBALS['spip_lang'];
776
-	}
777
-	$text = $traduire($texte, $lang);
766
+    // On peut passer explicitement la langue dans le tableau
767
+    // On utilise le même nom de variable que la globale
768
+    if (isset($args['spip_lang'])) {
769
+        $lang = $args['spip_lang'];
770
+        // On l'enleve pour ne pas le passer au remplacement
771
+        unset($args['spip_lang']);
772
+    } // Sinon on prend la langue du contexte
773
+    else {
774
+        $lang = $GLOBALS['spip_lang'];
775
+    }
776
+    $text = $traduire($texte, $lang);
778 777
 
779
-	if (!strlen($text)) {
780
-		if (!$o['force']) {
781
-			return '';
782
-		}
778
+    if (!strlen($text)) {
779
+        if (!$o['force']) {
780
+            return '';
781
+        }
783 782
 
784
-		$text = $texte;
783
+        $text = $texte;
785 784
 
786
-		// pour les chaines non traduites, assurer un service minimum
787
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
788
-			$text = str_replace('_', ' ',
789
-				(($n = strpos($text, ':')) === false ? $texte :
790
-					substr($texte, $n + 1)));
791
-		}
792
-		$o['class'] = null;
785
+        // pour les chaines non traduites, assurer un service minimum
786
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
787
+            $text = str_replace('_', ' ',
788
+                (($n = strpos($text, ':')) === false ? $texte :
789
+                    substr($texte, $n + 1)));
790
+        }
791
+        $o['class'] = null;
793 792
 
794
-	}
793
+    }
795 794
 
796
-	return _L($text, $args, $o);
795
+    return _L($text, $args, $o);
797 796
 
798 797
 }
799 798
 
@@ -821,54 +820,54 @@  discard block
 block discarded – undo
821 820
  *     Texte
822 821
  */
823 822
 function _L($text, $args = array(), $options = array()) {
824
-	$f = $text;
825
-	$defaut_options = array(
826
-		'class' => null,
827
-		'sanitize' => true,
828
-	);
829
-	// support de l'ancien argument $class
830
-	if ($options and is_string($options)) {
831
-		$options = array('class' => $options);
832
-	}
833
-	if (is_array($options)) {
834
-		$options += $defaut_options;
835
-	} else {
836
-		$options = $defaut_options;
837
-	}
838
-
839
-	if (is_array($args)) {
840
-		if (!function_exists('interdire_scripts')) {
841
-			include_spip('inc/texte');
842
-		}
843
-		if (!function_exists('echapper_html_suspect')) {
844
-			include_spip('inc/texte_mini');
845
-		}
846
-		foreach ($args as $name => $value) {
847
-			if ($options['sanitize']) {
848
-				$value = echapper_html_suspect($value);
849
-				$value = interdire_scripts($value, -1);
850
-			}
851
-			if (!empty($options['class'])) {
852
-				$value = "<span class='".$options['class']."'>$value</span>";
853
-			}
854
-			$t = str_replace("@$name@", $value, $text);
855
-			if ($text !== $t) {
856
-				unset($args[$name]);
857
-				$text = $t;
858
-			}
859
-		}
860
-		// Si des variables n'ont pas ete inserees, le signaler
861
-		// (chaines de langues pas a jour)
862
-		if ($args) {
863
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
864
-		}
865
-	}
866
-
867
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
868
-		return "<span class=debug-traduction-erreur>$text</span>";
869
-	} else {
870
-		return $text;
871
-	}
823
+    $f = $text;
824
+    $defaut_options = array(
825
+        'class' => null,
826
+        'sanitize' => true,
827
+    );
828
+    // support de l'ancien argument $class
829
+    if ($options and is_string($options)) {
830
+        $options = array('class' => $options);
831
+    }
832
+    if (is_array($options)) {
833
+        $options += $defaut_options;
834
+    } else {
835
+        $options = $defaut_options;
836
+    }
837
+
838
+    if (is_array($args)) {
839
+        if (!function_exists('interdire_scripts')) {
840
+            include_spip('inc/texte');
841
+        }
842
+        if (!function_exists('echapper_html_suspect')) {
843
+            include_spip('inc/texte_mini');
844
+        }
845
+        foreach ($args as $name => $value) {
846
+            if ($options['sanitize']) {
847
+                $value = echapper_html_suspect($value);
848
+                $value = interdire_scripts($value, -1);
849
+            }
850
+            if (!empty($options['class'])) {
851
+                $value = "<span class='".$options['class']."'>$value</span>";
852
+            }
853
+            $t = str_replace("@$name@", $value, $text);
854
+            if ($text !== $t) {
855
+                unset($args[$name]);
856
+                $text = $t;
857
+            }
858
+        }
859
+        // Si des variables n'ont pas ete inserees, le signaler
860
+        // (chaines de langues pas a jour)
861
+        if ($args) {
862
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
863
+        }
864
+    }
865
+
866
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
867
+        return "<span class=debug-traduction-erreur>$text</span>";
868
+    } else {
869
+        return $text;
870
+    }
872 871
 }
873 872
 
874 873
 
@@ -882,13 +881,13 @@  discard block
 block discarded – undo
882 881
  * @return string
883 882
  */
884 883
 function joli_repertoire($rep) {
885
-	$a = substr($rep, 0, 1);
886
-	if ($a <> '.' and $a <> '/') {
887
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
888
-	}
889
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
884
+    $a = substr($rep, 0, 1);
885
+    if ($a <> '.' and $a <> '/') {
886
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
887
+    }
888
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
890 889
 
891
-	return $rep;
890
+    return $rep;
892 891
 }
893 892
 
894 893
 
@@ -913,33 +912,33 @@  discard block
 block discarded – undo
913 912
  * @return float|int|string|void
914 913
  */
915 914
 function spip_timer($t = 'rien', $raw = false) {
916
-	static $time;
917
-	$a = time();
918
-	$b = microtime();
919
-	// microtime peut contenir les microsecondes et le temps
920
-	$b = explode(' ', $b);
921
-	if (count($b) == 2) {
922
-		$a = end($b);
923
-	} // plus precis !
924
-	$b = reset($b);
925
-	if (!isset($time[$t])) {
926
-		$time[$t] = $a + $b;
927
-	} else {
928
-		$p = ($a + $b - $time[$t]) * 1000;
929
-		unset($time[$t]);
915
+    static $time;
916
+    $a = time();
917
+    $b = microtime();
918
+    // microtime peut contenir les microsecondes et le temps
919
+    $b = explode(' ', $b);
920
+    if (count($b) == 2) {
921
+        $a = end($b);
922
+    } // plus precis !
923
+    $b = reset($b);
924
+    if (!isset($time[$t])) {
925
+        $time[$t] = $a + $b;
926
+    } else {
927
+        $p = ($a + $b - $time[$t]) * 1000;
928
+        unset($time[$t]);
930 929
 #			echo "'$p'";exit;
931
-		if ($raw) {
932
-			return $p;
933
-		}
934
-		if ($p < 1000) {
935
-			$s = '';
936
-		} else {
937
-			$s = sprintf("%d ", $x = floor($p / 1000));
938
-			$p -= ($x * 1000);
939
-		}
930
+        if ($raw) {
931
+            return $p;
932
+        }
933
+        if ($p < 1000) {
934
+            $s = '';
935
+        } else {
936
+            $s = sprintf("%d ", $x = floor($p / 1000));
937
+            $p -= ($x * 1000);
938
+        }
940 939
 
941
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
942
-	}
940
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
941
+    }
943 942
 }
944 943
 
945 944
 
@@ -947,21 +946,21 @@  discard block
 block discarded – undo
947 946
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
948 947
 // http://code.spip.net/@spip_touch
949 948
 function spip_touch($fichier, $duree = 0, $touch = true) {
950
-	if ($duree) {
951
-		clearstatcache();
952
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
953
-			return false;
954
-		}
955
-	}
956
-	if ($touch !== false) {
957
-		if (!@touch($fichier)) {
958
-			spip_unlink($fichier);
959
-			@touch($fichier);
960
-		};
961
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
962
-	}
949
+    if ($duree) {
950
+        clearstatcache();
951
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
952
+            return false;
953
+        }
954
+    }
955
+    if ($touch !== false) {
956
+        if (!@touch($fichier)) {
957
+            spip_unlink($fichier);
958
+            @touch($fichier);
959
+        };
960
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
961
+    }
963 962
 
964
-	return true;
963
+    return true;
965 964
 }
966 965
 
967 966
 
@@ -973,11 +972,11 @@  discard block
 block discarded – undo
973 972
  * @uses cron()
974 973
  **/
975 974
 function action_cron() {
976
-	include_spip('inc/headers');
977
-	http_status(204); // No Content
978
-	header("Connection: close");
979
-	define('_DIRECT_CRON_FORCE', true);
980
-	cron();
975
+    include_spip('inc/headers');
976
+    http_status(204); // No Content
977
+    header("Connection: close");
978
+    define('_DIRECT_CRON_FORCE', true);
979
+    cron();
981 980
 }
982 981
 
983 982
 /**
@@ -993,26 +992,26 @@  discard block
 block discarded – undo
993 992
  *     True si la tache a pu être effectuée
994 993
  */
995 994
 function cron($taches = array(), $taches_old = array()) {
996
-	// si pas en mode cron force, laisser tomber.
997
-	if (!defined('_DIRECT_CRON_FORCE')) {
998
-		return false;
999
-	}
1000
-	if (!is_array($taches)) {
1001
-		$taches = $taches_old;
1002
-	} // compat anciens appels
1003
-	// si taches a inserer en base et base inaccessible, laisser tomber
1004
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1005
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1006
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1007
-	if ($taches and count($taches) and !spip_connect()) {
1008
-		return false;
1009
-	}
1010
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1011
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1012
-		return $genie($taches);
1013
-	}
1014
-
1015
-	return false;
995
+    // si pas en mode cron force, laisser tomber.
996
+    if (!defined('_DIRECT_CRON_FORCE')) {
997
+        return false;
998
+    }
999
+    if (!is_array($taches)) {
1000
+        $taches = $taches_old;
1001
+    } // compat anciens appels
1002
+    // si taches a inserer en base et base inaccessible, laisser tomber
1003
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1004
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1005
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1006
+    if ($taches and count($taches) and !spip_connect()) {
1007
+        return false;
1008
+    }
1009
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1010
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1011
+        return $genie($taches);
1012
+    }
1013
+
1014
+    return false;
1016 1015
 }
1017 1016
 
1018 1017
 /**
@@ -1044,17 +1043,17 @@  discard block
 block discarded – undo
1044 1043
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1045 1044
  */
1046 1045
 function job_queue_add(
1047
-	$function,
1048
-	$description,
1049
-	$arguments = array(),
1050
-	$file = '',
1051
-	$no_duplicate = false,
1052
-	$time = 0,
1053
-	$priority = 0
1046
+    $function,
1047
+    $description,
1048
+    $arguments = array(),
1049
+    $file = '',
1050
+    $no_duplicate = false,
1051
+    $time = 0,
1052
+    $priority = 0
1054 1053
 ) {
1055
-	include_spip('inc/queue');
1054
+    include_spip('inc/queue');
1056 1055
 
1057
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1056
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1058 1057
 }
1059 1058
 
1060 1059
 /**
@@ -1065,9 +1064,9 @@  discard block
 block discarded – undo
1065 1064
  * @return bool
1066 1065
  */
1067 1066
 function job_queue_remove($id_job) {
1068
-	include_spip('inc/queue');
1067
+    include_spip('inc/queue');
1069 1068
 
1070
-	return queue_remove_job($id_job);
1069
+    return queue_remove_job($id_job);
1071 1070
 }
1072 1071
 
1073 1072
 /**
@@ -1080,9 +1079,9 @@  discard block
 block discarded – undo
1080 1079
  *     or an array of simple array to link multiples objet in one time
1081 1080
  */
1082 1081
 function job_queue_link($id_job, $objets) {
1083
-	include_spip('inc/queue');
1082
+    include_spip('inc/queue');
1084 1083
 
1085
-	return queue_link_job($id_job, $objets);
1084
+    return queue_link_job($id_job, $objets);
1086 1085
 }
1087 1086
 
1088 1087
 
@@ -1102,36 +1101,36 @@  discard block
 block discarded – undo
1102 1101
  *  - `null` si la queue n'est pas encore initialisée
1103 1102
  */
1104 1103
 function queue_sleep_time_to_next_job($force = null) {
1105
-	static $queue_next_job_time = -1;
1106
-	if ($force === true) {
1107
-		$queue_next_job_time = -1;
1108
-	} elseif ($force) {
1109
-		$queue_next_job_time = $force;
1110
-	}
1111
-
1112
-	if ($queue_next_job_time == -1) {
1113
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1114
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1115
-		}
1116
-		// utiliser un cache memoire si dispo
1117
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1118
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1119
-		} else {
1120
-			$queue_next_job_time = null;
1121
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1122
-				$queue_next_job_time = intval($contenu);
1123
-			}
1124
-		}
1125
-	}
1126
-
1127
-	if (is_null($queue_next_job_time)) {
1128
-		return null;
1129
-	}
1130
-	if (!$_SERVER['REQUEST_TIME']) {
1131
-		$_SERVER['REQUEST_TIME'] = time();
1132
-	}
1133
-
1134
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1104
+    static $queue_next_job_time = -1;
1105
+    if ($force === true) {
1106
+        $queue_next_job_time = -1;
1107
+    } elseif ($force) {
1108
+        $queue_next_job_time = $force;
1109
+    }
1110
+
1111
+    if ($queue_next_job_time == -1) {
1112
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1113
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1114
+        }
1115
+        // utiliser un cache memoire si dispo
1116
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1117
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1118
+        } else {
1119
+            $queue_next_job_time = null;
1120
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1121
+                $queue_next_job_time = intval($contenu);
1122
+            }
1123
+        }
1124
+    }
1125
+
1126
+    if (is_null($queue_next_job_time)) {
1127
+        return null;
1128
+    }
1129
+    if (!$_SERVER['REQUEST_TIME']) {
1130
+        $_SERVER['REQUEST_TIME'] = time();
1131
+    }
1132
+
1133
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1135 1134
 }
1136 1135
 
1137 1136
 
@@ -1143,9 +1142,9 @@  discard block
 block discarded – undo
1143 1142
  * @return string
1144 1143
  */
1145 1144
 function quote_amp($u) {
1146
-	return preg_replace(
1147
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1148
-		"&amp;", $u);
1145
+    return preg_replace(
1146
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1147
+        "&amp;", $u);
1149 1148
 }
1150 1149
 
1151 1150
 
@@ -1168,27 +1167,27 @@  discard block
 block discarded – undo
1168 1167
  *     Balise HTML `<script>` et son contenu
1169 1168
  **/
1170 1169
 function http_script($script, $src = '', $noscript = '') {
1171
-	static $done = array();
1170
+    static $done = array();
1172 1171
 
1173
-	if ($src && !isset($done[$src])) {
1174
-		$done[$src] = true;
1175
-		$src = find_in_path($src, _JAVASCRIPT);
1176
-		$src = " src='$src'";
1177
-	} else {
1178
-		$src = '';
1179
-	}
1180
-	if ($script) {
1181
-		$script = ("/*<![CDATA[*/\n" .
1182
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1183
-			"/*]]>*/");
1184
-	}
1185
-	if ($noscript) {
1186
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1187
-	}
1172
+    if ($src && !isset($done[$src])) {
1173
+        $done[$src] = true;
1174
+        $src = find_in_path($src, _JAVASCRIPT);
1175
+        $src = " src='$src'";
1176
+    } else {
1177
+        $src = '';
1178
+    }
1179
+    if ($script) {
1180
+        $script = ("/*<![CDATA[*/\n" .
1181
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1182
+            "/*]]>*/");
1183
+    }
1184
+    if ($noscript) {
1185
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1186
+    }
1188 1187
 
1189
-	return ($src or $script or $noscript)
1190
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1191
-		: '';
1188
+    return ($src or $script or $noscript)
1189
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1190
+        : '';
1192 1191
 }
1193 1192
 
1194 1193
 
@@ -1223,7 +1222,7 @@  discard block
 block discarded – undo
1223 1222
  *     Texte échappé
1224 1223
  **/
1225 1224
 function texte_script($texte) {
1226
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1225
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1227 1226
 }
1228 1227
 
1229 1228
 
@@ -1260,69 +1259,69 @@  discard block
 block discarded – undo
1260 1259
  *     Liste des chemins, par ordre de priorité.
1261 1260
  **/
1262 1261
 function _chemin($dir_path = null) {
1263
-	static $path_base = null;
1264
-	static $path_full = null;
1265
-	if ($path_base == null) {
1266
-		// Chemin standard depuis l'espace public
1267
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1268
-			_DIR_RACINE . ':' .
1269
-			_DIR_RACINE . 'squelettes-dist/:' .
1270
-			_DIR_RACINE . 'prive/:' .
1271
-			_DIR_RESTREINT;
1272
-		// Ajouter squelettes/
1273
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1274
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1275
-		}
1276
-		foreach (explode(':', $path) as $dir) {
1277
-			if (strlen($dir) and substr($dir, -1) != '/') {
1278
-				$dir .= "/";
1279
-			}
1280
-			$path_base[] = $dir;
1281
-		}
1282
-		$path_full = $path_base;
1283
-		// Et le(s) dossier(s) des squelettes nommes
1284
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1285
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1286
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1287
-			}
1288
-		}
1289
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1290
-	}
1291
-	if ($dir_path === null) {
1292
-		return $path_full;
1293
-	}
1294
-
1295
-	if (strlen($dir_path)) {
1296
-		$tete = "";
1297
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1298
-			$tete = array_shift($path_base);
1299
-		}
1300
-		$dirs = array_reverse(explode(':', $dir_path));
1301
-		foreach ($dirs as $dir_path) {
1302
-			#if ($dir_path{0}!='/')
1303
-			#	$dir_path = $dir_path;
1304
-			if (substr($dir_path, -1) != '/') {
1305
-				$dir_path .= "/";
1306
-			}
1307
-			if (!in_array($dir_path, $path_base)) {
1308
-				array_unshift($path_base, $dir_path);
1309
-			}
1310
-		}
1311
-		if (strlen($tete)) {
1312
-			array_unshift($path_base, $tete);
1313
-		}
1314
-	}
1315
-	$path_full = $path_base;
1316
-	// Et le(s) dossier(s) des squelettes nommes
1317
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1318
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1319
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1320
-		}
1321
-	}
1322
-
1323
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1324
-
1325
-	return $path_full;
1262
+    static $path_base = null;
1263
+    static $path_full = null;
1264
+    if ($path_base == null) {
1265
+        // Chemin standard depuis l'espace public
1266
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1267
+            _DIR_RACINE . ':' .
1268
+            _DIR_RACINE . 'squelettes-dist/:' .
1269
+            _DIR_RACINE . 'prive/:' .
1270
+            _DIR_RESTREINT;
1271
+        // Ajouter squelettes/
1272
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1273
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1274
+        }
1275
+        foreach (explode(':', $path) as $dir) {
1276
+            if (strlen($dir) and substr($dir, -1) != '/') {
1277
+                $dir .= "/";
1278
+            }
1279
+            $path_base[] = $dir;
1280
+        }
1281
+        $path_full = $path_base;
1282
+        // Et le(s) dossier(s) des squelettes nommes
1283
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1284
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1285
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1286
+            }
1287
+        }
1288
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1289
+    }
1290
+    if ($dir_path === null) {
1291
+        return $path_full;
1292
+    }
1293
+
1294
+    if (strlen($dir_path)) {
1295
+        $tete = "";
1296
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1297
+            $tete = array_shift($path_base);
1298
+        }
1299
+        $dirs = array_reverse(explode(':', $dir_path));
1300
+        foreach ($dirs as $dir_path) {
1301
+            #if ($dir_path{0}!='/')
1302
+            #	$dir_path = $dir_path;
1303
+            if (substr($dir_path, -1) != '/') {
1304
+                $dir_path .= "/";
1305
+            }
1306
+            if (!in_array($dir_path, $path_base)) {
1307
+                array_unshift($path_base, $dir_path);
1308
+            }
1309
+        }
1310
+        if (strlen($tete)) {
1311
+            array_unshift($path_base, $tete);
1312
+        }
1313
+    }
1314
+    $path_full = $path_base;
1315
+    // Et le(s) dossier(s) des squelettes nommes
1316
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1317
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1318
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1319
+        }
1320
+    }
1321
+
1322
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1323
+
1324
+    return $path_full;
1326 1325
 }
1327 1326
 
1328 1327
 /**
@@ -1335,63 +1334,63 @@  discard block
 block discarded – undo
1335 1334
  * @return array Liste de chemins
1336 1335
  **/
1337 1336
 function creer_chemin() {
1338
-	$path_a = _chemin();
1339
-	static $c = '';
1337
+    $path_a = _chemin();
1338
+    static $c = '';
1340 1339
 
1341
-	// on calcule le chemin si le dossier skel a change
1342
-	if ($c != $GLOBALS['dossier_squelettes']) {
1343
-		// assurer le non plantage lors de la montee de version :
1344
-		$c = $GLOBALS['dossier_squelettes'];
1345
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1346
-	}
1340
+    // on calcule le chemin si le dossier skel a change
1341
+    if ($c != $GLOBALS['dossier_squelettes']) {
1342
+        // assurer le non plantage lors de la montee de version :
1343
+        $c = $GLOBALS['dossier_squelettes'];
1344
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1345
+    }
1347 1346
 
1348
-	return $path_a;
1347
+    return $path_a;
1349 1348
 }
1350 1349
 
1351 1350
 
1352 1351
 function lister_themes_prives() {
1353
-	static $themes = null;
1354
-	if (is_null($themes)) {
1355
-		// si pas encore definie
1356
-		if (!defined('_SPIP_THEME_PRIVE')) {
1357
-			define('_SPIP_THEME_PRIVE', 'spip');
1358
-		}
1359
-		$themes = array(_SPIP_THEME_PRIVE);
1360
-		// lors d'une installation neuve, prefs n'est pas definie.
1361
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1362
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1363
-		} else {
1364
-			$prefs = array();
1365
-		}
1366
-		if (is_string($prefs)) {
1367
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1368
-		}
1369
-		if (
1370
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1371
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1372
-			and $theme != _SPIP_THEME_PRIVE
1373
-		) {
1374
-			array_unshift($themes, $theme);
1375
-		} // placer le theme choisi en tete
1376
-	}
1377
-
1378
-	return $themes;
1352
+    static $themes = null;
1353
+    if (is_null($themes)) {
1354
+        // si pas encore definie
1355
+        if (!defined('_SPIP_THEME_PRIVE')) {
1356
+            define('_SPIP_THEME_PRIVE', 'spip');
1357
+        }
1358
+        $themes = array(_SPIP_THEME_PRIVE);
1359
+        // lors d'une installation neuve, prefs n'est pas definie.
1360
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1361
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1362
+        } else {
1363
+            $prefs = array();
1364
+        }
1365
+        if (is_string($prefs)) {
1366
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1367
+        }
1368
+        if (
1369
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1370
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1371
+            and $theme != _SPIP_THEME_PRIVE
1372
+        ) {
1373
+            array_unshift($themes, $theme);
1374
+        } // placer le theme choisi en tete
1375
+    }
1376
+
1377
+    return $themes;
1379 1378
 }
1380 1379
 
1381 1380
 function find_in_theme($file, $subdir = '', $include = false) {
1382
-	static $themefiles = array();
1383
-	if (isset($themefiles["$subdir$file"])) {
1384
-		return $themefiles["$subdir$file"];
1385
-	}
1386
-	$themes = lister_themes_prives();
1387
-	foreach ($themes as $theme) {
1388
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1389
-			return $themefiles["$subdir$file"] = $f;
1390
-		}
1391
-	}
1392
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1381
+    static $themefiles = array();
1382
+    if (isset($themefiles["$subdir$file"])) {
1383
+        return $themefiles["$subdir$file"];
1384
+    }
1385
+    $themes = lister_themes_prives();
1386
+    foreach ($themes as $theme) {
1387
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1388
+            return $themefiles["$subdir$file"] = $f;
1389
+        }
1390
+    }
1391
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1393 1392
 
1394
-	return $themefiles["$subdir$file"] = "";
1393
+    return $themefiles["$subdir$file"] = "";
1395 1394
 }
1396 1395
 
1397 1396
 
@@ -1415,28 +1414,28 @@  discard block
 block discarded – undo
1415 1414
  *     sinon chaîne vide.
1416 1415
  **/
1417 1416
 function chemin_image($icone) {
1418
-	static $icone_renommer;
1419
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1420
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1421
-		return $icone;
1422
-	}
1423
-
1424
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1425
-	if (preg_match(',[.](png|gif|jpg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1426
-		return $f;
1427
-	}
1428
-	// sinon passer par le module de renommage
1429
-	if (is_null($icone_renommer)) {
1430
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1431
-	}
1432
-	if ($icone_renommer) {
1433
-		list($icone, $fonction) = $icone_renommer($icone, "");
1434
-		if (file_exists($icone)) {
1435
-			return $icone;
1436
-		}
1437
-	}
1438
-
1439
-	return find_in_path($icone, _NOM_IMG_PACK);
1417
+    static $icone_renommer;
1418
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1419
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1420
+        return $icone;
1421
+    }
1422
+
1423
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1424
+    if (preg_match(',[.](png|gif|jpg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1425
+        return $f;
1426
+    }
1427
+    // sinon passer par le module de renommage
1428
+    if (is_null($icone_renommer)) {
1429
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1430
+    }
1431
+    if ($icone_renommer) {
1432
+        list($icone, $fonction) = $icone_renommer($icone, "");
1433
+        if (file_exists($icone)) {
1434
+            return $icone;
1435
+        }
1436
+    }
1437
+
1438
+    return find_in_path($icone, _NOM_IMG_PACK);
1440 1439
 }
1441 1440
 
1442 1441
 //
@@ -1474,123 +1473,123 @@  discard block
 block discarded – undo
1474 1473
  *     - false : fichier introuvable
1475 1474
  **/
1476 1475
 function find_in_path($file, $dirname = '', $include = false) {
1477
-	static $dirs = array();
1478
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1479
-	static $c = '';
1480
-
1481
-	// on calcule le chemin si le dossier skel a change
1482
-	if ($c != $GLOBALS['dossier_squelettes']) {
1483
-		// assurer le non plantage lors de la montee de version :
1484
-		$c = $GLOBALS['dossier_squelettes'];
1485
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1486
-	}
1487
-
1488
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1489
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1490
-			return false;
1491
-		}
1492
-		if ($include and !isset($inc[$dirname][$file])) {
1493
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1494
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1495
-		}
1496
-
1497
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1498
-	}
1499
-
1500
-	$a = strrpos($file, '/');
1501
-	if ($a !== false) {
1502
-		$dirname .= substr($file, 0, ++$a);
1503
-		$file = substr($file, $a);
1504
-	}
1505
-
1506
-	foreach (creer_chemin() as $dir) {
1507
-		if (!isset($dirs[$a = $dir . $dirname])) {
1508
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1509
-		}
1510
-		if ($dirs[$a]) {
1511
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1512
-				if ($include and !isset($inc[$dirname][$file])) {
1513
-					include_once _ROOT_CWD . $a;
1514
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1515
-				}
1516
-				if (!defined('_SAUVER_CHEMIN')) {
1517
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1518
-					if (is_null($GLOBALS['path_files'])) {
1519
-						return $a;
1520
-					}
1521
-					define('_SAUVER_CHEMIN', true);
1522
-				}
1523
-
1524
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1525
-			}
1526
-		}
1527
-	}
1528
-
1529
-	if ($include) {
1530
-		spip_log("include_spip $dirname$file non trouve");
1531
-		if ($include === 'required') {
1532
-			echo '<pre>',
1533
-			"<strong>Erreur Fatale</strong><br />";
1534
-			if (function_exists('debug_print_backtrace')) {
1535
-				echo debug_print_backtrace();
1536
-			}
1537
-			echo '</pre>';
1538
-			die("Erreur interne: ne peut inclure $dirname$file");
1539
-		}
1540
-	}
1541
-
1542
-	if (!defined('_SAUVER_CHEMIN')) {
1543
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1544
-		if (is_null($GLOBALS['path_files'])) {
1545
-			return false;
1546
-		}
1547
-		define('_SAUVER_CHEMIN', true);
1548
-	}
1549
-
1550
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1476
+    static $dirs = array();
1477
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1478
+    static $c = '';
1479
+
1480
+    // on calcule le chemin si le dossier skel a change
1481
+    if ($c != $GLOBALS['dossier_squelettes']) {
1482
+        // assurer le non plantage lors de la montee de version :
1483
+        $c = $GLOBALS['dossier_squelettes'];
1484
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1485
+    }
1486
+
1487
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1488
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1489
+            return false;
1490
+        }
1491
+        if ($include and !isset($inc[$dirname][$file])) {
1492
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1493
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1494
+        }
1495
+
1496
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1497
+    }
1498
+
1499
+    $a = strrpos($file, '/');
1500
+    if ($a !== false) {
1501
+        $dirname .= substr($file, 0, ++$a);
1502
+        $file = substr($file, $a);
1503
+    }
1504
+
1505
+    foreach (creer_chemin() as $dir) {
1506
+        if (!isset($dirs[$a = $dir . $dirname])) {
1507
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1508
+        }
1509
+        if ($dirs[$a]) {
1510
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1511
+                if ($include and !isset($inc[$dirname][$file])) {
1512
+                    include_once _ROOT_CWD . $a;
1513
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1514
+                }
1515
+                if (!defined('_SAUVER_CHEMIN')) {
1516
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1517
+                    if (is_null($GLOBALS['path_files'])) {
1518
+                        return $a;
1519
+                    }
1520
+                    define('_SAUVER_CHEMIN', true);
1521
+                }
1522
+
1523
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1524
+            }
1525
+        }
1526
+    }
1527
+
1528
+    if ($include) {
1529
+        spip_log("include_spip $dirname$file non trouve");
1530
+        if ($include === 'required') {
1531
+            echo '<pre>',
1532
+            "<strong>Erreur Fatale</strong><br />";
1533
+            if (function_exists('debug_print_backtrace')) {
1534
+                echo debug_print_backtrace();
1535
+            }
1536
+            echo '</pre>';
1537
+            die("Erreur interne: ne peut inclure $dirname$file");
1538
+        }
1539
+    }
1540
+
1541
+    if (!defined('_SAUVER_CHEMIN')) {
1542
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1543
+        if (is_null($GLOBALS['path_files'])) {
1544
+            return false;
1545
+        }
1546
+        define('_SAUVER_CHEMIN', true);
1547
+    }
1548
+
1549
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1551 1550
 }
1552 1551
 
1553 1552
 function clear_path_cache() {
1554
-	$GLOBALS['path_files'] = array();
1555
-	spip_unlink(_CACHE_CHEMIN);
1553
+    $GLOBALS['path_files'] = array();
1554
+    spip_unlink(_CACHE_CHEMIN);
1556 1555
 }
1557 1556
 
1558 1557
 function load_path_cache() {
1559
-	// charger le path des plugins
1560
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1561
-		include_once(_CACHE_PLUGINS_PATH);
1562
-	}
1563
-	$GLOBALS['path_files'] = array();
1564
-	// si le visiteur est admin,
1565
-	// on ne recharge pas le cache pour forcer sa mise a jour
1566
-	if (
1567
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1568
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1569
-		// utiliser le cookie est un pis aller qui marche 'en general'
1570
-		// on blinde par un second test au moment de la lecture de la session
1571
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1572
-		// et en ignorant ce cache en cas de recalcul explicite
1573
-	!_request('var_mode')
1574
-	) {
1575
-		// on essaye de lire directement sans verrou pour aller plus vite
1576
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1577
-			// mais si semble corrompu on relit avec un verrou
1578
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1579
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1580
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1581
-					$GLOBALS['path_files'] = array();
1582
-				}
1583
-			}
1584
-		}
1585
-	}
1558
+    // charger le path des plugins
1559
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1560
+        include_once(_CACHE_PLUGINS_PATH);
1561
+    }
1562
+    $GLOBALS['path_files'] = array();
1563
+    // si le visiteur est admin,
1564
+    // on ne recharge pas le cache pour forcer sa mise a jour
1565
+    if (
1566
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1567
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1568
+        // utiliser le cookie est un pis aller qui marche 'en general'
1569
+        // on blinde par un second test au moment de la lecture de la session
1570
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1571
+        // et en ignorant ce cache en cas de recalcul explicite
1572
+    !_request('var_mode')
1573
+    ) {
1574
+        // on essaye de lire directement sans verrou pour aller plus vite
1575
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1576
+            // mais si semble corrompu on relit avec un verrou
1577
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1578
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1579
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1580
+                    $GLOBALS['path_files'] = array();
1581
+                }
1582
+            }
1583
+        }
1584
+    }
1586 1585
 }
1587 1586
 
1588 1587
 function save_path_cache() {
1589
-	if (defined('_SAUVER_CHEMIN')
1590
-		and _SAUVER_CHEMIN
1591
-	) {
1592
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1593
-	}
1588
+    if (defined('_SAUVER_CHEMIN')
1589
+        and _SAUVER_CHEMIN
1590
+    ) {
1591
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1592
+    }
1594 1593
 }
1595 1594
 
1596 1595
 
@@ -1610,33 +1609,33 @@  discard block
 block discarded – undo
1610 1609
  * @return array
1611 1610
  */
1612 1611
 function find_all_in_path($dir, $pattern, $recurs = false) {
1613
-	$liste_fichiers = array();
1614
-	$maxfiles = 10000;
1615
-
1616
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1617
-	// on a pas encore inclus flock.php
1618
-	if (!function_exists('preg_files')) {
1619
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1620
-	}
1621
-
1622
-	// Parcourir le chemin
1623
-	foreach (creer_chemin() as $d) {
1624
-		$f = $d . $dir;
1625
-		if (@is_dir($f)) {
1626
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1627
-			foreach ($liste as $chemin) {
1628
-				$nom = basename($chemin);
1629
-				// ne prendre que les fichiers pas deja trouves
1630
-				// car find_in_path prend le premier qu'il trouve,
1631
-				// les autres sont donc masques
1632
-				if (!isset($liste_fichiers[$nom])) {
1633
-					$liste_fichiers[$nom] = $chemin;
1634
-				}
1635
-			}
1636
-		}
1637
-	}
1638
-
1639
-	return $liste_fichiers;
1612
+    $liste_fichiers = array();
1613
+    $maxfiles = 10000;
1614
+
1615
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1616
+    // on a pas encore inclus flock.php
1617
+    if (!function_exists('preg_files')) {
1618
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1619
+    }
1620
+
1621
+    // Parcourir le chemin
1622
+    foreach (creer_chemin() as $d) {
1623
+        $f = $d . $dir;
1624
+        if (@is_dir($f)) {
1625
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1626
+            foreach ($liste as $chemin) {
1627
+                $nom = basename($chemin);
1628
+                // ne prendre que les fichiers pas deja trouves
1629
+                // car find_in_path prend le premier qu'il trouve,
1630
+                // les autres sont donc masques
1631
+                if (!isset($liste_fichiers[$nom])) {
1632
+                    $liste_fichiers[$nom] = $chemin;
1633
+                }
1634
+            }
1635
+        }
1636
+    }
1637
+
1638
+    return $liste_fichiers;
1640 1639
 }
1641 1640
 
1642 1641
 /**
@@ -1645,10 +1644,10 @@  discard block
 block discarded – undo
1645 1644
  * @return bool
1646 1645
  */
1647 1646
 function autoriser_sans_cookie($nom) {
1648
-	static $autsanscookie = array('install', 'base_repair');
1649
-	$nom = preg_replace('/.php[3]?$/', '', basename($nom));
1647
+    static $autsanscookie = array('install', 'base_repair');
1648
+    $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1650 1649
 
1651
-	return in_array($nom, $autsanscookie);
1650
+    return in_array($nom, $autsanscookie);
1652 1651
 }
1653 1652
 
1654 1653
 /**
@@ -1674,99 +1673,99 @@  discard block
 block discarded – undo
1674 1673
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1675 1674
  */
1676 1675
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1677
-	if ($public === null) {
1678
-		$public = !test_espace_prive();
1679
-	}
1680
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1681
-
1682
-	if (!$public) {
1683
-		if (!$entite) {
1684
-			return '';
1685
-		}
1686
-		if (!function_exists('generer_url_ecrire_objet')) {
1687
-			include_spip('inc/urls');
1688
-		}
1689
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1690
-	} else {
1691
-		if ($type === null) {
1692
-			$type = (isset($GLOBALS['type_urls']))
1693
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1694
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1695
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1696
-		}
1697
-
1698
-		$f = charger_fonction($type, 'urls', true);
1699
-		// se rabattre sur les urls page si les urls perso non dispo
1700
-		if (!$f) {
1701
-			$f = charger_fonction('page', 'urls', true);
1702
-		}
1703
-
1704
-		// si $entite='', on veut la fonction de passage URL ==> id
1705
-		// sinon on veut effectuer le passage id ==> URL
1706
-		if (!$entite) {
1707
-			return $f;
1708
-		}
1709
-
1710
-		// mais d'abord il faut tester le cas des urls sur une
1711
-		// base distante
1712
-		if (is_string($public)
1713
-			and $g = charger_fonction('connect', 'urls', true)
1714
-		) {
1715
-			$f = $g;
1716
-		}
1717
-
1718
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1719
-
1720
-	}
1721
-	if ($res) {
1722
-		return $res;
1723
-	}
1724
-	// Sinon c'est un raccourci ou compat SPIP < 2
1725
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1726
-		if (!function_exists($f .= '_dist')) {
1727
-			$f = '';
1728
-		}
1729
-	}
1730
-	if ($f) {
1731
-		$url = $f($id, $args, $ancre);
1732
-		if (strlen($args)) {
1733
-			$url .= strstr($url, '?')
1734
-				? '&amp;' . $args
1735
-				: '?' . $args;
1736
-		}
1737
-
1738
-		return $url;
1739
-	}
1740
-	// On a ete gentil mais la ....
1741
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1742
-
1743
-	return '';
1676
+    if ($public === null) {
1677
+        $public = !test_espace_prive();
1678
+    }
1679
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1680
+
1681
+    if (!$public) {
1682
+        if (!$entite) {
1683
+            return '';
1684
+        }
1685
+        if (!function_exists('generer_url_ecrire_objet')) {
1686
+            include_spip('inc/urls');
1687
+        }
1688
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1689
+    } else {
1690
+        if ($type === null) {
1691
+            $type = (isset($GLOBALS['type_urls']))
1692
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1693
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1694
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1695
+        }
1696
+
1697
+        $f = charger_fonction($type, 'urls', true);
1698
+        // se rabattre sur les urls page si les urls perso non dispo
1699
+        if (!$f) {
1700
+            $f = charger_fonction('page', 'urls', true);
1701
+        }
1702
+
1703
+        // si $entite='', on veut la fonction de passage URL ==> id
1704
+        // sinon on veut effectuer le passage id ==> URL
1705
+        if (!$entite) {
1706
+            return $f;
1707
+        }
1708
+
1709
+        // mais d'abord il faut tester le cas des urls sur une
1710
+        // base distante
1711
+        if (is_string($public)
1712
+            and $g = charger_fonction('connect', 'urls', true)
1713
+        ) {
1714
+            $f = $g;
1715
+        }
1716
+
1717
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1718
+
1719
+    }
1720
+    if ($res) {
1721
+        return $res;
1722
+    }
1723
+    // Sinon c'est un raccourci ou compat SPIP < 2
1724
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1725
+        if (!function_exists($f .= '_dist')) {
1726
+            $f = '';
1727
+        }
1728
+    }
1729
+    if ($f) {
1730
+        $url = $f($id, $args, $ancre);
1731
+        if (strlen($args)) {
1732
+            $url .= strstr($url, '?')
1733
+                ? '&amp;' . $args
1734
+                : '?' . $args;
1735
+        }
1736
+
1737
+        return $url;
1738
+    }
1739
+    // On a ete gentil mais la ....
1740
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1741
+
1742
+    return '';
1744 1743
 }
1745 1744
 
1746 1745
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1747
-	$exec = objet_info($entite, 'url_edit');
1748
-	$url = generer_url_ecrire($exec, $args);
1749
-	if (intval($id)) {
1750
-		$url = parametre_url($url, id_table_objet($entite), $id);
1751
-	} else {
1752
-		$url = parametre_url($url, 'new', 'oui');
1753
-	}
1754
-	if ($ancre) {
1755
-		$url = ancre_url($url, $ancre);
1756
-	}
1746
+    $exec = objet_info($entite, 'url_edit');
1747
+    $url = generer_url_ecrire($exec, $args);
1748
+    if (intval($id)) {
1749
+        $url = parametre_url($url, id_table_objet($entite), $id);
1750
+    } else {
1751
+        $url = parametre_url($url, 'new', 'oui');
1752
+    }
1753
+    if ($ancre) {
1754
+        $url = ancre_url($url, $ancre);
1755
+    }
1757 1756
 
1758
-	return $url;
1757
+    return $url;
1759 1758
 }
1760 1759
 
1761 1760
 // http://code.spip.net/@urls_connect_dist
1762 1761
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1763
-	include_spip('base/connect_sql');
1764
-	$id_type = id_table_objet($entite, $public);
1762
+    include_spip('base/connect_sql');
1763
+    $id_type = id_table_objet($entite, $public);
1765 1764
 
1766
-	return _DIR_RACINE . get_spip_script('./')
1767
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1768
-	. (!$args ? '' : "&$args")
1769
-	. (!$ancre ? '' : "#$ancre");
1765
+    return _DIR_RACINE . get_spip_script('./')
1766
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1767
+    . (!$args ? '' : "&$args")
1768
+    . (!$ancre ? '' : "#$ancre");
1770 1769
 }
1771 1770
 
1772 1771
 
@@ -1777,32 +1776,32 @@  discard block
 block discarded – undo
1777 1776
  * @return string
1778 1777
  */
1779 1778
 function urlencode_1738($url) {
1780
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1781
-		$uri = '';
1782
-		for ($i = 0; $i < strlen($url); $i++) {
1783
-			if (ord($a = $url[$i]) > 127) {
1784
-				$a = rawurlencode($a);
1785
-			}
1786
-			$uri .= $a;
1787
-		}
1788
-		$url = $uri;
1789
-	}
1779
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1780
+        $uri = '';
1781
+        for ($i = 0; $i < strlen($url); $i++) {
1782
+            if (ord($a = $url[$i]) > 127) {
1783
+                $a = rawurlencode($a);
1784
+            }
1785
+            $uri .= $a;
1786
+        }
1787
+        $url = $uri;
1788
+    }
1790 1789
 
1791
-	return quote_amp($url);
1790
+    return quote_amp($url);
1792 1791
 }
1793 1792
 
1794 1793
 // http://code.spip.net/@generer_url_entite_absolue
1795 1794
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1796
-	if (!$connect) {
1797
-		$connect = true;
1798
-	}
1799
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1800
-	if (!preg_match(',^\w+:,', $h)) {
1801
-		include_spip('inc/filtres_mini');
1802
-		$h = url_absolue($h);
1803
-	}
1795
+    if (!$connect) {
1796
+        $connect = true;
1797
+    }
1798
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1799
+    if (!preg_match(',^\w+:,', $h)) {
1800
+        include_spip('inc/filtres_mini');
1801
+        $h = url_absolue($h);
1802
+    }
1804 1803
 
1805
-	return $h;
1804
+    return $h;
1806 1805
 }
1807 1806
 
1808 1807
 
@@ -1818,11 +1817,11 @@  discard block
 block discarded – undo
1818 1817
  *     true si la valeur est considérée active ; false sinon.
1819 1818
  **/
1820 1819
 function test_valeur_serveur($truc) {
1821
-	if (!$truc) {
1822
-		return false;
1823
-	}
1820
+    if (!$truc) {
1821
+        return false;
1822
+    }
1824 1823
 
1825
-	return (strtolower($truc) !== 'off');
1824
+    return (strtolower($truc) !== 'off');
1826 1825
 }
1827 1826
 
1828 1827
 //
@@ -1850,85 +1849,85 @@  discard block
 block discarded – undo
1850 1849
  */
1851 1850
 function url_de_base($profondeur = null) {
1852 1851
 
1853
-	static $url = array();
1854
-	if (is_array($profondeur)) {
1855
-		return $url = $profondeur;
1856
-	}
1857
-	if ($profondeur === false) {
1858
-		return $url;
1859
-	}
1860
-
1861
-	if (is_null($profondeur)) {
1862
-		$profondeur = $GLOBALS['profondeur_url'];
1863
-	}
1864
-
1865
-	if (isset($url[$profondeur])) {
1866
-		return $url[$profondeur];
1867
-	}
1868
-
1869
-	$http = 'http';
1870
-
1871
-	if (
1872
-		isset($_SERVER["SCRIPT_URI"])
1873
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1874
-	) {
1875
-		$http = 'https';
1876
-	} elseif (
1877
-		isset($_SERVER['HTTPS'])
1878
-		and test_valeur_serveur($_SERVER['HTTPS'])
1879
-	) {
1880
-		$http = 'https';
1881
-	} elseif (
1882
-		isset($GLOBALS['meta']['adresse_site'])
1883
-		and parse_url($GLOBALS['meta']['adresse_site'], PHP_URL_SCHEME) == 'https'
1884
-	) {
1885
-		$http = 'https';
1886
-	}
1887
-
1888
-	// note : HTTP_HOST contient le :port si necessaire
1889
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1890
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1891
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1892
-		$host = $GLOBALS['meta']['adresse_site'];
1893
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1894
-			$http = $scheme;
1895
-			$host = str_replace("{$scheme}://", '', $host);
1896
-		}
1897
-	}
1898
-	if (isset($_SERVER['SERVER_PORT'])
1899
-		and $port = $_SERVER['SERVER_PORT']
1900
-		and strpos($host, ":") == false
1901
-	) {
1902
-		if (!defined('_PORT_HTTP_STANDARD')) {
1903
-			define('_PORT_HTTP_STANDARD', '80');
1904
-		}
1905
-		if (!defined('_PORT_HTTPS_STANDARD')) {
1906
-			define('_PORT_HTTPS_STANDARD', '443');
1907
-		}
1908
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1909
-			$host .= ":$port";
1910
-		}
1911
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1912
-			$host .= ":$port";
1913
-		}
1914
-	}
1915
-
1916
-	if (!$GLOBALS['REQUEST_URI']) {
1917
-		if (isset($_SERVER['REQUEST_URI'])) {
1918
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1919
-		} else {
1920
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1921
-			if (!empty($_SERVER['QUERY_STRING'])
1922
-				and !strpos($_SERVER['REQUEST_URI'], '?')
1923
-			) {
1924
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1925
-			}
1926
-		}
1927
-	}
1928
-
1929
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1930
-
1931
-	return $url[$profondeur];
1852
+    static $url = array();
1853
+    if (is_array($profondeur)) {
1854
+        return $url = $profondeur;
1855
+    }
1856
+    if ($profondeur === false) {
1857
+        return $url;
1858
+    }
1859
+
1860
+    if (is_null($profondeur)) {
1861
+        $profondeur = $GLOBALS['profondeur_url'];
1862
+    }
1863
+
1864
+    if (isset($url[$profondeur])) {
1865
+        return $url[$profondeur];
1866
+    }
1867
+
1868
+    $http = 'http';
1869
+
1870
+    if (
1871
+        isset($_SERVER["SCRIPT_URI"])
1872
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1873
+    ) {
1874
+        $http = 'https';
1875
+    } elseif (
1876
+        isset($_SERVER['HTTPS'])
1877
+        and test_valeur_serveur($_SERVER['HTTPS'])
1878
+    ) {
1879
+        $http = 'https';
1880
+    } elseif (
1881
+        isset($GLOBALS['meta']['adresse_site'])
1882
+        and parse_url($GLOBALS['meta']['adresse_site'], PHP_URL_SCHEME) == 'https'
1883
+    ) {
1884
+        $http = 'https';
1885
+    }
1886
+
1887
+    // note : HTTP_HOST contient le :port si necessaire
1888
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1889
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1890
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1891
+        $host = $GLOBALS['meta']['adresse_site'];
1892
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1893
+            $http = $scheme;
1894
+            $host = str_replace("{$scheme}://", '', $host);
1895
+        }
1896
+    }
1897
+    if (isset($_SERVER['SERVER_PORT'])
1898
+        and $port = $_SERVER['SERVER_PORT']
1899
+        and strpos($host, ":") == false
1900
+    ) {
1901
+        if (!defined('_PORT_HTTP_STANDARD')) {
1902
+            define('_PORT_HTTP_STANDARD', '80');
1903
+        }
1904
+        if (!defined('_PORT_HTTPS_STANDARD')) {
1905
+            define('_PORT_HTTPS_STANDARD', '443');
1906
+        }
1907
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1908
+            $host .= ":$port";
1909
+        }
1910
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1911
+            $host .= ":$port";
1912
+        }
1913
+    }
1914
+
1915
+    if (!$GLOBALS['REQUEST_URI']) {
1916
+        if (isset($_SERVER['REQUEST_URI'])) {
1917
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1918
+        } else {
1919
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1920
+            if (!empty($_SERVER['QUERY_STRING'])
1921
+                and !strpos($_SERVER['REQUEST_URI'], '?')
1922
+            ) {
1923
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1924
+            }
1925
+        }
1926
+    }
1927
+
1928
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1929
+
1930
+    return $url[$profondeur];
1932 1931
 }
1933 1932
 
1934 1933
 /**
@@ -1941,26 +1940,26 @@  discard block
 block discarded – undo
1941 1940
  * @return string
1942 1941
  */
1943 1942
 function url_de_($http, $host, $request, $prof = 0) {
1944
-	$prof = max($prof, 0);
1943
+    $prof = max($prof, 0);
1945 1944
 
1946
-	$myself = ltrim($request, '/');
1947
-	# supprimer la chaine de GET
1948
-	list($myself) = explode('?', $myself);
1949
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1950
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1951
-	if (strpos($myself,'://') !== false) {
1952
-		$myself = explode('://',$myself);
1953
-		array_shift($myself);
1954
-		$myself = implode('://',$myself);
1955
-		$myself = explode('/',$myself);
1956
-		array_shift($myself);
1957
-		$myself = implode('/',$myself);
1958
-	}
1959
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1945
+    $myself = ltrim($request, '/');
1946
+    # supprimer la chaine de GET
1947
+    list($myself) = explode('?', $myself);
1948
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1949
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1950
+    if (strpos($myself,'://') !== false) {
1951
+        $myself = explode('://',$myself);
1952
+        array_shift($myself);
1953
+        $myself = implode('://',$myself);
1954
+        $myself = explode('/',$myself);
1955
+        array_shift($myself);
1956
+        $myself = implode('/',$myself);
1957
+    }
1958
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1960 1959
 
1961
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1960
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1962 1961
 
1963
-	return $url;
1962
+    return $url;
1964 1963
 }
1965 1964
 
1966 1965
 
@@ -1995,26 +1994,26 @@  discard block
 block discarded – undo
1995 1994
  * @return string URL
1996 1995
  **/
1997 1996
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
1998
-	if (!$rel) {
1999
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2000
-	} else {
2001
-		if (!is_string($rel)) {
2002
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2003
-				('./' . _SPIP_ECRIRE_SCRIPT);
2004
-		}
2005
-	}
2006
-
2007
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2008
-	if ($script and ($script <> 'accueil' or $rel)) {
2009
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2010
-	} elseif ($args) {
2011
-		$args = "?$args";
2012
-	}
2013
-	if ($ancre) {
2014
-		$args .= "#$ancre";
2015
-	}
2016
-
2017
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1997
+    if (!$rel) {
1998
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1999
+    } else {
2000
+        if (!is_string($rel)) {
2001
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2002
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2003
+        }
2004
+    }
2005
+
2006
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2007
+    if ($script and ($script <> 'accueil' or $rel)) {
2008
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2009
+    } elseif ($args) {
2010
+        $args = "?$args";
2011
+    }
2012
+    if ($ancre) {
2013
+        $args .= "#$ancre";
2014
+    }
2015
+
2016
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2018 2017
 }
2019 2018
 
2020 2019
 //
@@ -2036,12 +2035,12 @@  discard block
 block discarded – undo
2036 2035
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2037 2036
  **/
2038 2037
 function get_spip_script($default = '') {
2039
-	# cas define('_SPIP_SCRIPT', '');
2040
-	if (_SPIP_SCRIPT) {
2041
-		return _SPIP_SCRIPT;
2042
-	} else {
2043
-		return $default;
2044
-	}
2038
+    # cas define('_SPIP_SCRIPT', '');
2039
+    if (_SPIP_SCRIPT) {
2040
+        return _SPIP_SCRIPT;
2041
+    } else {
2042
+        return $default;
2043
+    }
2045 2044
 }
2046 2045
 
2047 2046
 /**
@@ -2070,39 +2069,39 @@  discard block
 block discarded – undo
2070 2069
  * @return string URL
2071 2070
  **/
2072 2071
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2073
-	// si le script est une action (spip_pass, spip_inscription),
2074
-	// standardiser vers la nouvelle API
2075
-
2076
-	if (!$action) {
2077
-		$action = get_spip_script();
2078
-	}
2079
-	if ($script) {
2080
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2081
-	}
2082
-
2083
-	if ($args) {
2084
-		if (is_array($args)) {
2085
-			$r = '';
2086
-			foreach ($args as $k => $v) {
2087
-				$r .= '&' . $k . '=' . $v;
2088
-			}
2089
-			$args = substr($r, 1);
2090
-		}
2091
-		$action .=
2092
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2093
-	}
2094
-	if (!$no_entities) {
2095
-		$action = quote_amp($action);
2096
-	}
2097
-
2098
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2099
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2072
+    // si le script est une action (spip_pass, spip_inscription),
2073
+    // standardiser vers la nouvelle API
2074
+
2075
+    if (!$action) {
2076
+        $action = get_spip_script();
2077
+    }
2078
+    if ($script) {
2079
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2080
+    }
2081
+
2082
+    if ($args) {
2083
+        if (is_array($args)) {
2084
+            $r = '';
2085
+            foreach ($args as $k => $v) {
2086
+                $r .= '&' . $k . '=' . $v;
2087
+            }
2088
+            $args = substr($r, 1);
2089
+        }
2090
+        $action .=
2091
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2092
+    }
2093
+    if (!$no_entities) {
2094
+        $action = quote_amp($action);
2095
+    }
2096
+
2097
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2098
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2100 2099
 }
2101 2100
 
2102 2101
 // http://code.spip.net/@generer_url_prive
2103 2102
 function generer_url_prive($script, $args = "", $no_entities = false) {
2104 2103
 
2105
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2104
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2106 2105
 }
2107 2106
 
2108 2107
 // Pour les formulaires en methode POST,
@@ -2127,19 +2126,19 @@  discard block
 block discarded – undo
2127 2126
  **/
2128 2127
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2129 2128
 
2130
-	$script1 = explode('&', $script);
2131
-	$script1 = reset($script1);
2129
+    $script1 = explode('&', $script);
2130
+    $script1 = reset($script1);
2132 2131
 
2133
-	return "<form action='"
2134
-	. ($script ? generer_url_ecrire($script) : '')
2135
-	. "' "
2136
-	. ($atts ? $atts : " method='post'")
2137
-	. "><div>\n"
2138
-	. "<input type='hidden' name='exec' value='$script1' />"
2139
-	. $corps
2140
-	. (!$submit ? '' :
2141
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2142
-	. "</div></form>\n";
2132
+    return "<form action='"
2133
+    . ($script ? generer_url_ecrire($script) : '')
2134
+    . "' "
2135
+    . ($atts ? $atts : " method='post'")
2136
+    . "><div>\n"
2137
+    . "<input type='hidden' name='exec' value='$script1' />"
2138
+    . $corps
2139
+    . (!$submit ? '' :
2140
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2141
+    . "</div></form>\n";
2143 2142
 }
2144 2143
 
2145 2144
 /**
@@ -2156,22 +2155,22 @@  discard block
 block discarded – undo
2156 2155
  * @return string
2157 2156
  */
2158 2157
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2159
-	// si l'on est dans l'espace prive, on garde dans l'url
2160
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2161
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2162
-	$h = (_DIR_RACINE and !$public)
2163
-		? generer_url_ecrire(_request('exec'))
2164
-		: generer_url_public();
2158
+    // si l'on est dans l'espace prive, on garde dans l'url
2159
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2160
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2161
+    $h = (_DIR_RACINE and !$public)
2162
+        ? generer_url_ecrire(_request('exec'))
2163
+        : generer_url_public();
2165 2164
 
2166
-	return "\n<form action='" .
2167
-	$h .
2168
-	"'" .
2169
-	$atts .
2170
-	">\n" .
2171
-	"<div>" .
2172
-	"\n<input type='hidden' name='action' value='$script' />" .
2173
-	$corps .
2174
-	"</div></form>";
2165
+    return "\n<form action='" .
2166
+    $h .
2167
+    "'" .
2168
+    $atts .
2169
+    ">\n" .
2170
+    "<div>" .
2171
+    "\n<input type='hidden' name='action' value='$script' />" .
2172
+    $corps .
2173
+    "</div></form>";
2175 2174
 }
2176 2175
 
2177 2176
 /**
@@ -2190,22 +2189,22 @@  discard block
 block discarded – undo
2190 2189
  *     URL
2191 2190
  */
2192 2191
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2193
-	// si l'on est dans l'espace prive, on garde dans l'url
2194
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2195
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2196
-	$url = (_DIR_RACINE and !$public)
2197
-		? generer_url_ecrire(_request('exec'))
2198
-		: generer_url_public('', '', false, false);
2199
-	$url = parametre_url($url, 'action', $script);
2200
-	if ($args) {
2201
-		$url .= quote_amp('&' . $args);
2202
-	}
2192
+    // si l'on est dans l'espace prive, on garde dans l'url
2193
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2194
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2195
+    $url = (_DIR_RACINE and !$public)
2196
+        ? generer_url_ecrire(_request('exec'))
2197
+        : generer_url_public('', '', false, false);
2198
+    $url = parametre_url($url, 'action', $script);
2199
+    if ($args) {
2200
+        $url .= quote_amp('&' . $args);
2201
+    }
2203 2202
 
2204
-	if ($no_entities) {
2205
-		$url = str_replace('&amp;', '&', $url);
2206
-	}
2203
+    if ($no_entities) {
2204
+        $url = str_replace('&amp;', '&', $url);
2205
+    }
2207 2206
 
2208
-	return $url;
2207
+    return $url;
2209 2208
 }
2210 2209
 
2211 2210
 
@@ -2218,8 +2217,8 @@  discard block
 block discarded – undo
2218 2217
  * @param string $ta Répertoire temporaire accessible
2219 2218
  */
2220 2219
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2221
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2222
-	spip_initialisation_suite();
2220
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2221
+    spip_initialisation_suite();
2223 2222
 }
2224 2223
 
2225 2224
 /**
@@ -2239,315 +2238,315 @@  discard block
 block discarded – undo
2239 2238
  * @param string $ta Répertoire temporaire accessible
2240 2239
  */
2241 2240
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2242
-	static $too_late = 0;
2243
-	if ($too_late++) {
2244
-		return;
2245
-	}
2246
-
2247
-	// Declaration des repertoires
2248
-
2249
-	// le nom du repertoire plugins/ activables/desactivables
2250
-	if (!defined('_DIR_PLUGINS')) {
2251
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2252
-	}
2253
-
2254
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2255
-	if (!defined('_DIR_PLUGINS_DIST')) {
2256
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2257
-	}
2258
-
2259
-	// le nom du repertoire des librairies
2260
-	if (!defined('_DIR_LIB')) {
2261
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2262
-	}
2263
-
2264
-	if (!defined('_DIR_IMG')) {
2265
-		define('_DIR_IMG', $pa);
2266
-	}
2267
-	if (!defined('_DIR_LOGOS')) {
2268
-		define('_DIR_LOGOS', $pa);
2269
-	}
2270
-	if (!defined('_DIR_IMG_ICONES')) {
2271
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2272
-	}
2273
-
2274
-	if (!defined('_DIR_DUMP')) {
2275
-		define('_DIR_DUMP', $ti . "dump/");
2276
-	}
2277
-	if (!defined('_DIR_SESSIONS')) {
2278
-		define('_DIR_SESSIONS', $ti . "sessions/");
2279
-	}
2280
-	if (!defined('_DIR_TRANSFERT')) {
2281
-		define('_DIR_TRANSFERT', $ti . "upload/");
2282
-	}
2283
-	if (!defined('_DIR_CACHE')) {
2284
-		define('_DIR_CACHE', $ti . "cache/");
2285
-	}
2286
-	if (!defined('_DIR_CACHE_XML')) {
2287
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2288
-	}
2289
-	if (!defined('_DIR_SKELS')) {
2290
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2291
-	}
2292
-	if (!defined('_DIR_AIDE')) {
2293
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2294
-	}
2295
-	if (!defined('_DIR_TMP')) {
2296
-		define('_DIR_TMP', $ti);
2297
-	}
2298
-
2299
-	if (!defined('_DIR_VAR')) {
2300
-		define('_DIR_VAR', $ta);
2301
-	}
2302
-
2303
-	if (!defined('_DIR_ETC')) {
2304
-		define('_DIR_ETC', $pi);
2305
-	}
2306
-	if (!defined('_DIR_CONNECT')) {
2307
-		define('_DIR_CONNECT', $pi);
2308
-	}
2309
-	if (!defined('_DIR_CHMOD')) {
2310
-		define('_DIR_CHMOD', $pi);
2311
-	}
2312
-
2313
-	if (!isset($GLOBALS['test_dirs']))
2314
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2315
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2316
-	{
2317
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2318
-	}
2319
-
2320
-	// Declaration des fichiers
2321
-
2322
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2323
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2324
-	}
2325
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2326
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2327
-	}
2328
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2329
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2330
-	}
2331
-	if (!defined('_CACHE_PIPELINES')) {
2332
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2333
-	}
2334
-	if (!defined('_CACHE_CHEMIN')) {
2335
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2336
-	}
2337
-
2338
-	# attention .php obligatoire pour ecrire_fichier_securise
2339
-	if (!defined('_FILE_META')) {
2340
-		define('_FILE_META', $ti . 'meta_cache.php');
2341
-	}
2342
-	if (!defined('_DIR_LOG')) {
2343
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2344
-	}
2345
-	if (!defined('_FILE_LOG')) {
2346
-		define('_FILE_LOG', 'spip');
2347
-	}
2348
-	if (!defined('_FILE_LOG_SUFFIX')) {
2349
-		define('_FILE_LOG_SUFFIX', '.log');
2350
-	}
2351
-
2352
-	// Le fichier de connexion a la base de donnees
2353
-	// tient compte des anciennes versions (inc_connect...)
2354
-	if (!defined('_FILE_CONNECT_INS')) {
2355
-		define('_FILE_CONNECT_INS', 'connect');
2356
-	}
2357
-	if (!defined('_FILE_CONNECT')) {
2358
-		define('_FILE_CONNECT',
2359
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2360
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2361
-				: false)));
2362
-	}
2363
-
2364
-	// Le fichier de reglages des droits
2365
-	if (!defined('_FILE_CHMOD_INS')) {
2366
-		define('_FILE_CHMOD_INS', 'chmod');
2367
-	}
2368
-	if (!defined('_FILE_CHMOD')) {
2369
-		define('_FILE_CHMOD',
2370
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2371
-			: false));
2372
-	}
2373
-
2374
-	if (!defined('_FILE_LDAP')) {
2375
-		define('_FILE_LDAP', 'ldap.php');
2376
-	}
2377
-
2378
-	if (!defined('_FILE_TMP_SUFFIX')) {
2379
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2380
-	}
2381
-	if (!defined('_FILE_CONNECT_TMP')) {
2382
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2383
-	}
2384
-	if (!defined('_FILE_CHMOD_TMP')) {
2385
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2386
-	}
2387
-
2388
-	// Definition des droits d'acces en ecriture
2389
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2390
-		include_once _FILE_CHMOD;
2391
-	}
2392
-
2393
-	// Se mefier des fichiers mal remplis!
2394
-	if (!defined('_SPIP_CHMOD')) {
2395
-		define('_SPIP_CHMOD', 0777);
2396
-	}
2397
-
2398
-	if (!defined('_DEFAULT_CHARSET')) {
2399
-		/** Le charset par défaut lors de l'installation */
2400
-		define('_DEFAULT_CHARSET', 'utf-8');
2401
-	}
2402
-	if (!defined('_ROOT_PLUGINS')) {
2403
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2404
-	}
2405
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2406
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2407
-	}
2408
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2409
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2410
-	}
2411
-
2412
-	// La taille des Log
2413
-	if (!defined('_MAX_LOG')) {
2414
-		define('_MAX_LOG', 100);
2415
-	}
2416
-
2417
-	// Sommes-nous dans l'empire du Mal ?
2418
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2419
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2420
-		if (!defined('_OS_SERVEUR')) {
2421
-			define('_OS_SERVEUR', 'windows');
2422
-		}
2423
-		if (!defined('_SPIP_LOCK_MODE')) {
2424
-			define('_SPIP_LOCK_MODE', 1);
2425
-		} // utiliser le flock php
2426
-	} else {
2427
-		if (!defined('_OS_SERVEUR')) {
2428
-			define('_OS_SERVEUR', '');
2429
-		}
2430
-		if (!defined('_SPIP_LOCK_MODE')) {
2431
-			define('_SPIP_LOCK_MODE', 1);
2432
-		} // utiliser le flock php
2433
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2434
-	}
2435
-
2436
-	// Langue par defaut
2437
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2438
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2439
-	}
2440
-
2441
-	//
2442
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2443
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2444
-	// pour le rendre surchargeable, on va provoquer un reecriture
2445
-	// systematique du noyau ou une baisse de perfs => a etudier)
2446
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2447
-
2448
-	// charger tout de suite le path et son cache
2449
-	load_path_cache();
2450
-
2451
-	// *********** traiter les variables ************
2452
-
2453
-	//
2454
-	// Securite
2455
-	//
2456
-
2457
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2458
-	if (isset($_REQUEST['GLOBALS'])) {
2459
-		die();
2460
-	}
2461
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2462
-	spip_desinfecte($_GET);
2463
-	spip_desinfecte($_POST);
2464
-	spip_desinfecte($_COOKIE);
2465
-	spip_desinfecte($_REQUEST);
2466
-
2467
-	// appliquer le cookie_prefix
2468
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2469
-		include_spip('inc/cookie');
2470
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2471
-	}
2472
-
2473
-	//
2474
-	// Capacites php (en fonction de la version)
2475
-	//
2476
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2477
-		&& function_exists("ini_get")
2478
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2479
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2480
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2481
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2482
-		(get_cfg_var('upload_max_filesize') > 0));
2483
-
2484
-
2485
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2486
-	if (isset($_SERVER['REQUEST_URI'])) {
2487
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2488
-	} else {
2489
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2490
-		if (!empty($_SERVER['QUERY_STRING'])
2491
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2492
-		) {
2493
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2494
-		}
2495
-	}
2496
-
2497
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2498
-	if (!defined('_RENOUVELLE_ALEA')) {
2499
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2500
-	}
2501
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2502
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2503
-	}
2504
-
2505
-	// charger les meta si possible et renouveller l'alea au besoin
2506
-	// charge aussi effacer_meta et ecrire_meta
2507
-	$inc_meta = charger_fonction('meta', 'inc');
2508
-	$inc_meta();
2509
-
2510
-	// nombre de repertoires depuis la racine
2511
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2512
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2513
-	// le calcul est faux)
2514
-	if (!_DIR_RESTREINT) {
2515
-		$GLOBALS['profondeur_url'] = 1;
2516
-	} else {
2517
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2518
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2519
-		if (!$uri_ref
2520
-			// si on est appele avec un autre ti, on est sans doute en mutu
2521
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2522
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2523
-			// s'en remettre a l'adresse du site. alea jacta est.
2524
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2525
-		) {
2526
-
2527
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2528
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2529
-				$uri_ref = $uri_ref['path'] . '/';
2530
-			} else {
2531
-				$uri_ref = "";
2532
-			}
2533
-		}
2534
-		if (!$uri or !$uri_ref) {
2535
-			$GLOBALS['profondeur_url'] = 0;
2536
-		} else {
2537
-			$GLOBALS['profondeur_url'] = max(0,
2538
-				substr_count($uri[0], '/')
2539
-				- substr_count($uri_ref, '/'));
2540
-		}
2541
-	}
2542
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2543
-	if (_FILE_CONNECT) {
2544
-		if (verifier_visiteur() == '0minirezo'
2545
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2546
-			and !isset($_COOKIE['spip_admin'])
2547
-		) {
2548
-			clear_path_cache();
2549
-		}
2550
-	}
2241
+    static $too_late = 0;
2242
+    if ($too_late++) {
2243
+        return;
2244
+    }
2245
+
2246
+    // Declaration des repertoires
2247
+
2248
+    // le nom du repertoire plugins/ activables/desactivables
2249
+    if (!defined('_DIR_PLUGINS')) {
2250
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2251
+    }
2252
+
2253
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2254
+    if (!defined('_DIR_PLUGINS_DIST')) {
2255
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2256
+    }
2257
+
2258
+    // le nom du repertoire des librairies
2259
+    if (!defined('_DIR_LIB')) {
2260
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2261
+    }
2262
+
2263
+    if (!defined('_DIR_IMG')) {
2264
+        define('_DIR_IMG', $pa);
2265
+    }
2266
+    if (!defined('_DIR_LOGOS')) {
2267
+        define('_DIR_LOGOS', $pa);
2268
+    }
2269
+    if (!defined('_DIR_IMG_ICONES')) {
2270
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2271
+    }
2272
+
2273
+    if (!defined('_DIR_DUMP')) {
2274
+        define('_DIR_DUMP', $ti . "dump/");
2275
+    }
2276
+    if (!defined('_DIR_SESSIONS')) {
2277
+        define('_DIR_SESSIONS', $ti . "sessions/");
2278
+    }
2279
+    if (!defined('_DIR_TRANSFERT')) {
2280
+        define('_DIR_TRANSFERT', $ti . "upload/");
2281
+    }
2282
+    if (!defined('_DIR_CACHE')) {
2283
+        define('_DIR_CACHE', $ti . "cache/");
2284
+    }
2285
+    if (!defined('_DIR_CACHE_XML')) {
2286
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2287
+    }
2288
+    if (!defined('_DIR_SKELS')) {
2289
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2290
+    }
2291
+    if (!defined('_DIR_AIDE')) {
2292
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2293
+    }
2294
+    if (!defined('_DIR_TMP')) {
2295
+        define('_DIR_TMP', $ti);
2296
+    }
2297
+
2298
+    if (!defined('_DIR_VAR')) {
2299
+        define('_DIR_VAR', $ta);
2300
+    }
2301
+
2302
+    if (!defined('_DIR_ETC')) {
2303
+        define('_DIR_ETC', $pi);
2304
+    }
2305
+    if (!defined('_DIR_CONNECT')) {
2306
+        define('_DIR_CONNECT', $pi);
2307
+    }
2308
+    if (!defined('_DIR_CHMOD')) {
2309
+        define('_DIR_CHMOD', $pi);
2310
+    }
2311
+
2312
+    if (!isset($GLOBALS['test_dirs']))
2313
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2314
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2315
+    {
2316
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2317
+    }
2318
+
2319
+    // Declaration des fichiers
2320
+
2321
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2322
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2323
+    }
2324
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2325
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2326
+    }
2327
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2328
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2329
+    }
2330
+    if (!defined('_CACHE_PIPELINES')) {
2331
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2332
+    }
2333
+    if (!defined('_CACHE_CHEMIN')) {
2334
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2335
+    }
2336
+
2337
+    # attention .php obligatoire pour ecrire_fichier_securise
2338
+    if (!defined('_FILE_META')) {
2339
+        define('_FILE_META', $ti . 'meta_cache.php');
2340
+    }
2341
+    if (!defined('_DIR_LOG')) {
2342
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2343
+    }
2344
+    if (!defined('_FILE_LOG')) {
2345
+        define('_FILE_LOG', 'spip');
2346
+    }
2347
+    if (!defined('_FILE_LOG_SUFFIX')) {
2348
+        define('_FILE_LOG_SUFFIX', '.log');
2349
+    }
2350
+
2351
+    // Le fichier de connexion a la base de donnees
2352
+    // tient compte des anciennes versions (inc_connect...)
2353
+    if (!defined('_FILE_CONNECT_INS')) {
2354
+        define('_FILE_CONNECT_INS', 'connect');
2355
+    }
2356
+    if (!defined('_FILE_CONNECT')) {
2357
+        define('_FILE_CONNECT',
2358
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2359
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2360
+                : false)));
2361
+    }
2362
+
2363
+    // Le fichier de reglages des droits
2364
+    if (!defined('_FILE_CHMOD_INS')) {
2365
+        define('_FILE_CHMOD_INS', 'chmod');
2366
+    }
2367
+    if (!defined('_FILE_CHMOD')) {
2368
+        define('_FILE_CHMOD',
2369
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2370
+            : false));
2371
+    }
2372
+
2373
+    if (!defined('_FILE_LDAP')) {
2374
+        define('_FILE_LDAP', 'ldap.php');
2375
+    }
2376
+
2377
+    if (!defined('_FILE_TMP_SUFFIX')) {
2378
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2379
+    }
2380
+    if (!defined('_FILE_CONNECT_TMP')) {
2381
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2382
+    }
2383
+    if (!defined('_FILE_CHMOD_TMP')) {
2384
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2385
+    }
2386
+
2387
+    // Definition des droits d'acces en ecriture
2388
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2389
+        include_once _FILE_CHMOD;
2390
+    }
2391
+
2392
+    // Se mefier des fichiers mal remplis!
2393
+    if (!defined('_SPIP_CHMOD')) {
2394
+        define('_SPIP_CHMOD', 0777);
2395
+    }
2396
+
2397
+    if (!defined('_DEFAULT_CHARSET')) {
2398
+        /** Le charset par défaut lors de l'installation */
2399
+        define('_DEFAULT_CHARSET', 'utf-8');
2400
+    }
2401
+    if (!defined('_ROOT_PLUGINS')) {
2402
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2403
+    }
2404
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2405
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2406
+    }
2407
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2408
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2409
+    }
2410
+
2411
+    // La taille des Log
2412
+    if (!defined('_MAX_LOG')) {
2413
+        define('_MAX_LOG', 100);
2414
+    }
2415
+
2416
+    // Sommes-nous dans l'empire du Mal ?
2417
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2418
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2419
+        if (!defined('_OS_SERVEUR')) {
2420
+            define('_OS_SERVEUR', 'windows');
2421
+        }
2422
+        if (!defined('_SPIP_LOCK_MODE')) {
2423
+            define('_SPIP_LOCK_MODE', 1);
2424
+        } // utiliser le flock php
2425
+    } else {
2426
+        if (!defined('_OS_SERVEUR')) {
2427
+            define('_OS_SERVEUR', '');
2428
+        }
2429
+        if (!defined('_SPIP_LOCK_MODE')) {
2430
+            define('_SPIP_LOCK_MODE', 1);
2431
+        } // utiliser le flock php
2432
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2433
+    }
2434
+
2435
+    // Langue par defaut
2436
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2437
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2438
+    }
2439
+
2440
+    //
2441
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2442
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2443
+    // pour le rendre surchargeable, on va provoquer un reecriture
2444
+    // systematique du noyau ou une baisse de perfs => a etudier)
2445
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2446
+
2447
+    // charger tout de suite le path et son cache
2448
+    load_path_cache();
2449
+
2450
+    // *********** traiter les variables ************
2451
+
2452
+    //
2453
+    // Securite
2454
+    //
2455
+
2456
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2457
+    if (isset($_REQUEST['GLOBALS'])) {
2458
+        die();
2459
+    }
2460
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2461
+    spip_desinfecte($_GET);
2462
+    spip_desinfecte($_POST);
2463
+    spip_desinfecte($_COOKIE);
2464
+    spip_desinfecte($_REQUEST);
2465
+
2466
+    // appliquer le cookie_prefix
2467
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2468
+        include_spip('inc/cookie');
2469
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2470
+    }
2471
+
2472
+    //
2473
+    // Capacites php (en fonction de la version)
2474
+    //
2475
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2476
+        && function_exists("ini_get")
2477
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2478
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2479
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2480
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2481
+        (get_cfg_var('upload_max_filesize') > 0));
2482
+
2483
+
2484
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2485
+    if (isset($_SERVER['REQUEST_URI'])) {
2486
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2487
+    } else {
2488
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2489
+        if (!empty($_SERVER['QUERY_STRING'])
2490
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2491
+        ) {
2492
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2493
+        }
2494
+    }
2495
+
2496
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2497
+    if (!defined('_RENOUVELLE_ALEA')) {
2498
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2499
+    }
2500
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2501
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2502
+    }
2503
+
2504
+    // charger les meta si possible et renouveller l'alea au besoin
2505
+    // charge aussi effacer_meta et ecrire_meta
2506
+    $inc_meta = charger_fonction('meta', 'inc');
2507
+    $inc_meta();
2508
+
2509
+    // nombre de repertoires depuis la racine
2510
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2511
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2512
+    // le calcul est faux)
2513
+    if (!_DIR_RESTREINT) {
2514
+        $GLOBALS['profondeur_url'] = 1;
2515
+    } else {
2516
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2517
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2518
+        if (!$uri_ref
2519
+            // si on est appele avec un autre ti, on est sans doute en mutu
2520
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2521
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2522
+            // s'en remettre a l'adresse du site. alea jacta est.
2523
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2524
+        ) {
2525
+
2526
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2527
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2528
+                $uri_ref = $uri_ref['path'] . '/';
2529
+            } else {
2530
+                $uri_ref = "";
2531
+            }
2532
+        }
2533
+        if (!$uri or !$uri_ref) {
2534
+            $GLOBALS['profondeur_url'] = 0;
2535
+        } else {
2536
+            $GLOBALS['profondeur_url'] = max(0,
2537
+                substr_count($uri[0], '/')
2538
+                - substr_count($uri_ref, '/'));
2539
+        }
2540
+    }
2541
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2542
+    if (_FILE_CONNECT) {
2543
+        if (verifier_visiteur() == '0minirezo'
2544
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2545
+            and !isset($_COOKIE['spip_admin'])
2546
+        ) {
2547
+            clear_path_cache();
2548
+        }
2549
+    }
2551 2550
 
2552 2551
 }
2553 2552
 
@@ -2557,172 +2556,172 @@  discard block
 block discarded – undo
2557 2556
  *
2558 2557
  */
2559 2558
 function spip_initialisation_suite() {
2560
-	static $too_late = 0;
2561
-	if ($too_late++) {
2562
-		return;
2563
-	}
2564
-
2565
-	// taille mini des login
2566
-	if (!defined('_LOGIN_TROP_COURT')) {
2567
-		define('_LOGIN_TROP_COURT', 4);
2568
-	}
2569
-
2570
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2571
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2572
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2573
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2574
-
2575
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2576
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2577
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2578
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2579
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2580
-
2581
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2582
-		define('_PASS_LONGUEUR_MINI', 6);
2583
-	}
2584
-
2585
-
2586
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2587
-	if (!defined('_IMG_QUALITE')) {
2588
-		define('_IMG_QUALITE', 85);
2589
-	} # valeur par defaut
2590
-	if (!defined('_IMG_GD_QUALITE')) {
2591
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2592
-	} # surcharge pour la lib GD
2593
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2594
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2595
-	} # surcharge pour imagick en ligne de commande
2596
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2597
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2598
-		define('_IMG_IMAGICK_QUALITE', 75);
2599
-	} # surcharge pour imagick en PHP
2600
-
2601
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2602
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2603
-	} // poids en octet
2604
-
2605
-	// qq chaines standard
2606
-	if (!defined('_ACCESS_FILE_NAME')) {
2607
-		define('_ACCESS_FILE_NAME', '.htaccess');
2608
-	}
2609
-	if (!defined('_AUTH_USER_FILE')) {
2610
-		define('_AUTH_USER_FILE', '.htpasswd');
2611
-	}
2612
-	if (!defined('_SPIP_DUMP')) {
2613
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2614
-	}
2615
-	if (!defined('_CACHE_RUBRIQUES')) {
2616
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2617
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2618
-	}
2619
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2620
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2621
-		define('_CACHE_RUBRIQUES_MAX', 500);
2622
-	}
2623
-
2624
-	if (!defined('_EXTENSION_SQUELETTES')) {
2625
-		define('_EXTENSION_SQUELETTES', 'html');
2626
-	}
2627
-
2628
-	if (!defined('_DOCTYPE_ECRIRE')) {
2629
-		/** Définit le doctype de l’espace privé */
2630
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2631
-	}
2632
-	if (!defined('_DOCTYPE_AIDE')) {
2633
-		/** Définit le doctype de l’aide en ligne */
2634
-		define('_DOCTYPE_AIDE',
2635
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2636
-	}
2637
-
2638
-	if (!defined('_SPIP_SCRIPT')) {
2639
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2640
-		 * le script de l'espace public, alias index.php */
2641
-		define('_SPIP_SCRIPT', 'spip.php');
2642
-	}
2643
-	if (!defined('_SPIP_PAGE')) {
2644
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2645
-		define('_SPIP_PAGE', 'page');
2646
-	}
2647
-
2648
-	// le script de l'espace prive
2649
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2650
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2651
-	// meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2652
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2653
-		define('_SPIP_ECRIRE_SCRIPT', (empty($_SERVER['SERVER_SOFTWARE']) ? '' :
2654
-			preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
2655
-				'index.php' : ''));
2656
-	}
2657
-
2658
-
2659
-	if (!defined('_SPIP_AJAX')) {
2660
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2661
-			? 1
2662
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2663
-	}
2664
-
2665
-	// La requete est-elle en ajax ?
2666
-	if (!defined('_AJAX')) {
2667
-		define('_AJAX',
2668
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2669
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2670
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2671
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2672
-			)
2673
-			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
2674
-		);
2675
-	}
2676
-
2677
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2678
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2679
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2680
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2681
-		define('_IMG_GD_MAX_PIXELS',
2682
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2683
-			? $GLOBALS['meta']['max_taille_vignettes']
2684
-			: 0);
2685
-	}
2686
-
2687
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2688
-		define('_MEMORY_LIMIT_MIN', 16);
2689
-	} // en Mo
2690
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2691
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2692
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2693
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2694
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2695
-			$unit = strtolower(substr($memory, -1));
2696
-			$memory = substr($memory, 0, -1);
2697
-			switch ($unit) {
2698
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2699
-				case 'g':
2700
-					$memory *= 1024;
2701
-				case 'm':
2702
-					$memory *= 1024;
2703
-				case 'k':
2704
-					$memory *= 1024;
2705
-			}
2706
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2707
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2708
-				if (trim(ini_get('memory_limit')) != $m) {
2709
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2710
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2711
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2712
-				}
2713
-			}
2714
-		} else {
2715
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2716
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2717
-			}
2718
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2719
-	}
2720
-	// Protocoles a normaliser dans les chaines de langues
2721
-	if (!defined('_PROTOCOLES_STD')) {
2722
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2723
-	}
2724
-
2725
-	init_var_mode();
2559
+    static $too_late = 0;
2560
+    if ($too_late++) {
2561
+        return;
2562
+    }
2563
+
2564
+    // taille mini des login
2565
+    if (!defined('_LOGIN_TROP_COURT')) {
2566
+        define('_LOGIN_TROP_COURT', 4);
2567
+    }
2568
+
2569
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2570
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2571
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2572
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2573
+
2574
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2575
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2576
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2577
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2578
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2579
+
2580
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2581
+        define('_PASS_LONGUEUR_MINI', 6);
2582
+    }
2583
+
2584
+
2585
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2586
+    if (!defined('_IMG_QUALITE')) {
2587
+        define('_IMG_QUALITE', 85);
2588
+    } # valeur par defaut
2589
+    if (!defined('_IMG_GD_QUALITE')) {
2590
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2591
+    } # surcharge pour la lib GD
2592
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2593
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2594
+    } # surcharge pour imagick en ligne de commande
2595
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2596
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2597
+        define('_IMG_IMAGICK_QUALITE', 75);
2598
+    } # surcharge pour imagick en PHP
2599
+
2600
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2601
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2602
+    } // poids en octet
2603
+
2604
+    // qq chaines standard
2605
+    if (!defined('_ACCESS_FILE_NAME')) {
2606
+        define('_ACCESS_FILE_NAME', '.htaccess');
2607
+    }
2608
+    if (!defined('_AUTH_USER_FILE')) {
2609
+        define('_AUTH_USER_FILE', '.htpasswd');
2610
+    }
2611
+    if (!defined('_SPIP_DUMP')) {
2612
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2613
+    }
2614
+    if (!defined('_CACHE_RUBRIQUES')) {
2615
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2616
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2617
+    }
2618
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2619
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2620
+        define('_CACHE_RUBRIQUES_MAX', 500);
2621
+    }
2622
+
2623
+    if (!defined('_EXTENSION_SQUELETTES')) {
2624
+        define('_EXTENSION_SQUELETTES', 'html');
2625
+    }
2626
+
2627
+    if (!defined('_DOCTYPE_ECRIRE')) {
2628
+        /** Définit le doctype de l’espace privé */
2629
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2630
+    }
2631
+    if (!defined('_DOCTYPE_AIDE')) {
2632
+        /** Définit le doctype de l’aide en ligne */
2633
+        define('_DOCTYPE_AIDE',
2634
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2635
+    }
2636
+
2637
+    if (!defined('_SPIP_SCRIPT')) {
2638
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2639
+         * le script de l'espace public, alias index.php */
2640
+        define('_SPIP_SCRIPT', 'spip.php');
2641
+    }
2642
+    if (!defined('_SPIP_PAGE')) {
2643
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2644
+        define('_SPIP_PAGE', 'page');
2645
+    }
2646
+
2647
+    // le script de l'espace prive
2648
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2649
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2650
+    // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2651
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2652
+        define('_SPIP_ECRIRE_SCRIPT', (empty($_SERVER['SERVER_SOFTWARE']) ? '' :
2653
+            preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
2654
+                'index.php' : ''));
2655
+    }
2656
+
2657
+
2658
+    if (!defined('_SPIP_AJAX')) {
2659
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2660
+            ? 1
2661
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2662
+    }
2663
+
2664
+    // La requete est-elle en ajax ?
2665
+    if (!defined('_AJAX')) {
2666
+        define('_AJAX',
2667
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2668
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2669
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2670
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2671
+            )
2672
+            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
2673
+        );
2674
+    }
2675
+
2676
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2677
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2678
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2679
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2680
+        define('_IMG_GD_MAX_PIXELS',
2681
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2682
+            ? $GLOBALS['meta']['max_taille_vignettes']
2683
+            : 0);
2684
+    }
2685
+
2686
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2687
+        define('_MEMORY_LIMIT_MIN', 16);
2688
+    } // en Mo
2689
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2690
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2691
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2692
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2693
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2694
+            $unit = strtolower(substr($memory, -1));
2695
+            $memory = substr($memory, 0, -1);
2696
+            switch ($unit) {
2697
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2698
+                case 'g':
2699
+                    $memory *= 1024;
2700
+                case 'm':
2701
+                    $memory *= 1024;
2702
+                case 'k':
2703
+                    $memory *= 1024;
2704
+            }
2705
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2706
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2707
+                if (trim(ini_get('memory_limit')) != $m) {
2708
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2709
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2710
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2711
+                }
2712
+            }
2713
+        } else {
2714
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2715
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2716
+            }
2717
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2718
+    }
2719
+    // Protocoles a normaliser dans les chaines de langues
2720
+    if (!defined('_PROTOCOLES_STD')) {
2721
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2722
+    }
2723
+
2724
+    init_var_mode();
2726 2725
 }
2727 2726
 
2728 2727
 /**
@@ -2756,129 +2755,129 @@  discard block
 block discarded – undo
2756 2755
  * `   var_mode` (calcul ou recalcul).
2757 2756
  */
2758 2757
 function init_var_mode() {
2759
-	static $done = false;
2760
-	if (!$done) {
2761
-
2762
-		if (isset($_GET['var_mode'])) {
2763
-			$var_mode = explode(',', $_GET['var_mode']);
2764
-			// tout le monde peut calcul/recalcul
2765
-			if (!defined('_VAR_MODE')) {
2766
-				if (in_array('recalcul', $var_mode)) {
2767
-					define('_VAR_MODE', 'recalcul');
2768
-				} elseif (in_array('calcul', $var_mode)) {
2769
-					define('_VAR_MODE', 'calcul');
2770
-				}
2771
-			}
2772
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2773
-			if ($var_mode) {
2774
-				include_spip('inc/autoriser');
2775
-				// autoriser preview si preview seulement, et sinon autoriser debug
2776
-				if (autoriser(
2777
-					($_GET['var_mode'] == 'preview')
2778
-						? 'previsualiser'
2779
-						: 'debug'
2780
-				)) {
2781
-					if (in_array('traduction', $var_mode)) {
2782
-						// forcer le calcul pour passer dans traduire
2783
-						if (!defined('_VAR_MODE')) {
2784
-							define('_VAR_MODE', 'calcul');
2785
-						}
2786
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2787
-						if (!defined('_VAR_NOCACHE')) {
2788
-							define('_VAR_NOCACHE', true);
2789
-						}
2790
-						$var_mode = array_diff($var_mode, array('traduction'));
2791
-					}
2792
-					if (in_array('preview', $var_mode)) {
2793
-						// basculer sur les criteres de preview dans les boucles
2794
-						if (!defined('_VAR_PREVIEW')) {
2795
-							define('_VAR_PREVIEW', true);
2796
-						}
2797
-						// forcer le calcul
2798
-						if (!defined('_VAR_MODE')) {
2799
-							define('_VAR_MODE', 'calcul');
2800
-						}
2801
-						// et ne pas enregistrer de cache
2802
-						if (!defined('_VAR_NOCACHE')) {
2803
-							define('_VAR_NOCACHE', true);
2804
-						}
2805
-						$var_mode = array_diff($var_mode, array('preview'));
2806
-					}
2807
-					if (in_array('inclure', $var_mode)) {
2808
-						// forcer le compilo et ignorer les caches existants
2809
-						if (!defined('_VAR_MODE')) {
2810
-							define('_VAR_MODE', 'calcul');
2811
-						}
2812
-						if (!defined('_VAR_INCLURE')) {
2813
-							define('_VAR_INCLURE', true);
2814
-						}
2815
-						// et ne pas enregistrer de cache
2816
-						if (!defined('_VAR_NOCACHE')) {
2817
-							define('_VAR_NOCACHE', true);
2818
-						}
2819
-						$var_mode = array_diff($var_mode, array('inclure'));
2820
-					}
2821
-					if (in_array('urls', $var_mode)) {
2822
-						// forcer le compilo et ignorer les caches existants
2823
-						if (!defined('_VAR_MODE')) {
2824
-							define('_VAR_MODE', 'calcul');
2825
-						}
2826
-						if (!defined('_VAR_URLS')) {
2827
-							define('_VAR_URLS', true);
2828
-						}
2829
-						$var_mode = array_diff($var_mode, array('urls'));
2830
-					}
2831
-					if (in_array('images', $var_mode)) {
2832
-						// forcer le compilo et ignorer les caches existants
2833
-						if (!defined('_VAR_MODE')) {
2834
-							define('_VAR_MODE', 'calcul');
2835
-						}
2836
-						// indiquer qu'on doit recalculer les images
2837
-						if (!defined('_VAR_IMAGES')) {
2838
-							define('_VAR_IMAGES', true);
2839
-						}
2840
-						$var_mode = array_diff($var_mode, array('images'));
2841
-					}
2842
-					if (in_array('debug', $var_mode)) {
2843
-						if (!defined('_VAR_MODE')) {
2844
-							define('_VAR_MODE', 'debug');
2845
-						}
2846
-						// et ne pas enregistrer de cache
2847
-						if (!defined('_VAR_NOCACHE')) {
2848
-							define('_VAR_NOCACHE', true);
2849
-						}
2850
-						$var_mode = array_diff($var_mode, array('debug'));
2851
-					}
2852
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2853
-						define('_VAR_MODE', reset($var_mode));
2854
-					}
2855
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2856
-						spip_log($GLOBALS['visiteur_session']['nom']
2857
-							. " " . _VAR_MODE);
2858
-					}
2859
-				} // pas autorise ?
2860
-				else {
2861
-					// si on n'est pas connecte on se redirige
2862
-					if (!$GLOBALS['visiteur_session']) {
2863
-						include_spip('inc/headers');
2864
-						redirige_par_entete(generer_url_public('login',
2865
-							'url=' . rawurlencode(
2866
-								parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2867
-							), true));
2868
-					}
2869
-					// sinon tant pis
2870
-				}
2871
-			}
2872
-		}
2873
-		if (!defined('_VAR_MODE')) {
2874
-			/**
2875
-			 * Indique le mode de calcul ou d'affichage de la page.
2876
-			 * @see init_var_mode()
2877
-			 */
2878
-			define('_VAR_MODE', false);
2879
-		}
2880
-		$done = true;
2881
-	}
2758
+    static $done = false;
2759
+    if (!$done) {
2760
+
2761
+        if (isset($_GET['var_mode'])) {
2762
+            $var_mode = explode(',', $_GET['var_mode']);
2763
+            // tout le monde peut calcul/recalcul
2764
+            if (!defined('_VAR_MODE')) {
2765
+                if (in_array('recalcul', $var_mode)) {
2766
+                    define('_VAR_MODE', 'recalcul');
2767
+                } elseif (in_array('calcul', $var_mode)) {
2768
+                    define('_VAR_MODE', 'calcul');
2769
+                }
2770
+            }
2771
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2772
+            if ($var_mode) {
2773
+                include_spip('inc/autoriser');
2774
+                // autoriser preview si preview seulement, et sinon autoriser debug
2775
+                if (autoriser(
2776
+                    ($_GET['var_mode'] == 'preview')
2777
+                        ? 'previsualiser'
2778
+                        : 'debug'
2779
+                )) {
2780
+                    if (in_array('traduction', $var_mode)) {
2781
+                        // forcer le calcul pour passer dans traduire
2782
+                        if (!defined('_VAR_MODE')) {
2783
+                            define('_VAR_MODE', 'calcul');
2784
+                        }
2785
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2786
+                        if (!defined('_VAR_NOCACHE')) {
2787
+                            define('_VAR_NOCACHE', true);
2788
+                        }
2789
+                        $var_mode = array_diff($var_mode, array('traduction'));
2790
+                    }
2791
+                    if (in_array('preview', $var_mode)) {
2792
+                        // basculer sur les criteres de preview dans les boucles
2793
+                        if (!defined('_VAR_PREVIEW')) {
2794
+                            define('_VAR_PREVIEW', true);
2795
+                        }
2796
+                        // forcer le calcul
2797
+                        if (!defined('_VAR_MODE')) {
2798
+                            define('_VAR_MODE', 'calcul');
2799
+                        }
2800
+                        // et ne pas enregistrer de cache
2801
+                        if (!defined('_VAR_NOCACHE')) {
2802
+                            define('_VAR_NOCACHE', true);
2803
+                        }
2804
+                        $var_mode = array_diff($var_mode, array('preview'));
2805
+                    }
2806
+                    if (in_array('inclure', $var_mode)) {
2807
+                        // forcer le compilo et ignorer les caches existants
2808
+                        if (!defined('_VAR_MODE')) {
2809
+                            define('_VAR_MODE', 'calcul');
2810
+                        }
2811
+                        if (!defined('_VAR_INCLURE')) {
2812
+                            define('_VAR_INCLURE', true);
2813
+                        }
2814
+                        // et ne pas enregistrer de cache
2815
+                        if (!defined('_VAR_NOCACHE')) {
2816
+                            define('_VAR_NOCACHE', true);
2817
+                        }
2818
+                        $var_mode = array_diff($var_mode, array('inclure'));
2819
+                    }
2820
+                    if (in_array('urls', $var_mode)) {
2821
+                        // forcer le compilo et ignorer les caches existants
2822
+                        if (!defined('_VAR_MODE')) {
2823
+                            define('_VAR_MODE', 'calcul');
2824
+                        }
2825
+                        if (!defined('_VAR_URLS')) {
2826
+                            define('_VAR_URLS', true);
2827
+                        }
2828
+                        $var_mode = array_diff($var_mode, array('urls'));
2829
+                    }
2830
+                    if (in_array('images', $var_mode)) {
2831
+                        // forcer le compilo et ignorer les caches existants
2832
+                        if (!defined('_VAR_MODE')) {
2833
+                            define('_VAR_MODE', 'calcul');
2834
+                        }
2835
+                        // indiquer qu'on doit recalculer les images
2836
+                        if (!defined('_VAR_IMAGES')) {
2837
+                            define('_VAR_IMAGES', true);
2838
+                        }
2839
+                        $var_mode = array_diff($var_mode, array('images'));
2840
+                    }
2841
+                    if (in_array('debug', $var_mode)) {
2842
+                        if (!defined('_VAR_MODE')) {
2843
+                            define('_VAR_MODE', 'debug');
2844
+                        }
2845
+                        // et ne pas enregistrer de cache
2846
+                        if (!defined('_VAR_NOCACHE')) {
2847
+                            define('_VAR_NOCACHE', true);
2848
+                        }
2849
+                        $var_mode = array_diff($var_mode, array('debug'));
2850
+                    }
2851
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2852
+                        define('_VAR_MODE', reset($var_mode));
2853
+                    }
2854
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2855
+                        spip_log($GLOBALS['visiteur_session']['nom']
2856
+                            . " " . _VAR_MODE);
2857
+                    }
2858
+                } // pas autorise ?
2859
+                else {
2860
+                    // si on n'est pas connecte on se redirige
2861
+                    if (!$GLOBALS['visiteur_session']) {
2862
+                        include_spip('inc/headers');
2863
+                        redirige_par_entete(generer_url_public('login',
2864
+                            'url=' . rawurlencode(
2865
+                                parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2866
+                            ), true));
2867
+                    }
2868
+                    // sinon tant pis
2869
+                }
2870
+            }
2871
+        }
2872
+        if (!defined('_VAR_MODE')) {
2873
+            /**
2874
+             * Indique le mode de calcul ou d'affichage de la page.
2875
+             * @see init_var_mode()
2876
+             */
2877
+            define('_VAR_MODE', false);
2878
+        }
2879
+        $done = true;
2880
+    }
2882 2881
 }
2883 2882
 
2884 2883
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2886,93 +2885,93 @@  discard block
 block discarded – undo
2886 2885
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2887 2886
 // http://code.spip.net/@spip_desinfecte
2888 2887
 function spip_desinfecte(&$t, $deep = true) {
2889
-	static $magic_quotes;
2890
-	if (!isset($magic_quotes)) {
2891
-		$magic_quotes = @get_magic_quotes_gpc();
2892
-	}
2893
-
2894
-	foreach ($t as $key => $val) {
2895
-		if (is_string($t[$key])) {
2896
-			if ($magic_quotes) {
2897
-				$t[$key] = stripslashes($t[$key]);
2898
-			}
2899
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2900
-		} // traiter aussi les "texte_plus" de article_edit
2901
-		else {
2902
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2903
-				spip_desinfecte($t[$key], $deep);
2904
-			}
2905
-		}
2906
-	}
2888
+    static $magic_quotes;
2889
+    if (!isset($magic_quotes)) {
2890
+        $magic_quotes = @get_magic_quotes_gpc();
2891
+    }
2892
+
2893
+    foreach ($t as $key => $val) {
2894
+        if (is_string($t[$key])) {
2895
+            if ($magic_quotes) {
2896
+                $t[$key] = stripslashes($t[$key]);
2897
+            }
2898
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2899
+        } // traiter aussi les "texte_plus" de article_edit
2900
+        else {
2901
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2902
+                spip_desinfecte($t[$key], $deep);
2903
+            }
2904
+        }
2905
+    }
2907 2906
 }
2908 2907
 
2909 2908
 //  retourne le statut du visiteur s'il s'annonce
2910 2909
 
2911 2910
 // http://code.spip.net/@verifier_visiteur
2912 2911
 function verifier_visiteur() {
2913
-	// Rq: pour que cette fonction marche depuis mes_options
2914
-	// il faut forcer l'init si ce n'est fait
2915
-	// mais on risque de perturber des plugins en initialisant trop tot
2916
-	// certaines constantes
2917
-	@spip_initialisation_core(
2918
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2919
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2920
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2921
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2922
-	);
2923
-
2924
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
2925
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2926
-	// Attention on separe bien session_nom et nom, pour eviter
2927
-	// les melanges entre donnees SQL et variables plus aleatoires
2928
-	$variables_session = array('session_nom', 'session_email');
2929
-	foreach ($variables_session as $var) {
2930
-		if (_request($var) !== null) {
2931
-			$init = true;
2932
-			break;
2933
-		}
2934
-	}
2935
-	if (isset($init)) {
2936
-		#@spip_initialisation_suite();
2937
-		$session = charger_fonction('session', 'inc');
2938
-		$session();
2939
-		include_spip('inc/texte');
2940
-		foreach ($variables_session as $var) {
2941
-			if (($a = _request($var)) !== null) {
2942
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2943
-			}
2944
-		}
2945
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2946
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2947
-		}
2948
-		$session($GLOBALS['visiteur_session']);
2949
-
2950
-		return 0;
2951
-	}
2952
-
2953
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2954
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2955
-
2956
-		$session = charger_fonction('session', 'inc');
2957
-		if ($session()) {
2958
-			return $GLOBALS['visiteur_session']['statut'];
2959
-		}
2960
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2961
-			include_spip('inc/auth');
2962
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2963
-		}
2964
-		if ($h) {
2965
-			$GLOBALS['visiteur_session'] = $h;
2966
-
2967
-			return $GLOBALS['visiteur_session']['statut'];
2968
-		}
2969
-	}
2970
-
2971
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
2972
-	include_spip('inc/lang');
2973
-	utiliser_langue_visiteur();
2974
-
2975
-	return false;
2912
+    // Rq: pour que cette fonction marche depuis mes_options
2913
+    // il faut forcer l'init si ce n'est fait
2914
+    // mais on risque de perturber des plugins en initialisant trop tot
2915
+    // certaines constantes
2916
+    @spip_initialisation_core(
2917
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2918
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2919
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2920
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2921
+    );
2922
+
2923
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
2924
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2925
+    // Attention on separe bien session_nom et nom, pour eviter
2926
+    // les melanges entre donnees SQL et variables plus aleatoires
2927
+    $variables_session = array('session_nom', 'session_email');
2928
+    foreach ($variables_session as $var) {
2929
+        if (_request($var) !== null) {
2930
+            $init = true;
2931
+            break;
2932
+        }
2933
+    }
2934
+    if (isset($init)) {
2935
+        #@spip_initialisation_suite();
2936
+        $session = charger_fonction('session', 'inc');
2937
+        $session();
2938
+        include_spip('inc/texte');
2939
+        foreach ($variables_session as $var) {
2940
+            if (($a = _request($var)) !== null) {
2941
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2942
+            }
2943
+        }
2944
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2945
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2946
+        }
2947
+        $session($GLOBALS['visiteur_session']);
2948
+
2949
+        return 0;
2950
+    }
2951
+
2952
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2953
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2954
+
2955
+        $session = charger_fonction('session', 'inc');
2956
+        if ($session()) {
2957
+            return $GLOBALS['visiteur_session']['statut'];
2958
+        }
2959
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2960
+            include_spip('inc/auth');
2961
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2962
+        }
2963
+        if ($h) {
2964
+            $GLOBALS['visiteur_session'] = $h;
2965
+
2966
+            return $GLOBALS['visiteur_session']['statut'];
2967
+        }
2968
+    }
2969
+
2970
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
2971
+    include_spip('inc/lang');
2972
+    utiliser_langue_visiteur();
2973
+
2974
+    return false;
2976 2975
 }
2977 2976
 
2978 2977
 
@@ -2995,21 +2994,21 @@  discard block
 block discarded – undo
2995 2994
  *     - string Langue utilisée.
2996 2995
  **/
2997 2996
 function lang_select($lang = null) {
2998
-	static $pile_langues = array();
2999
-	if (!function_exists('changer_langue')) {
3000
-		include_spip('inc/lang');
3001
-	}
3002
-	if ($lang === null) {
3003
-		$lang = array_pop($pile_langues);
3004
-	} else {
3005
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3006
-	}
3007
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3008
-		return $lang;
3009
-	}
3010
-	changer_langue($lang);
2997
+    static $pile_langues = array();
2998
+    if (!function_exists('changer_langue')) {
2999
+        include_spip('inc/lang');
3000
+    }
3001
+    if ($lang === null) {
3002
+        $lang = array_pop($pile_langues);
3003
+    } else {
3004
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3005
+    }
3006
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3007
+        return $lang;
3008
+    }
3009
+    changer_langue($lang);
3011 3010
 
3012
-	return $lang;
3011
+    return $lang;
3013 3012
 }
3014 3013
 
3015 3014
 /**
@@ -3026,19 +3025,19 @@  discard block
 block discarded – undo
3026 3025
  *     Identifiant de la session
3027 3026
  **/
3028 3027
 function spip_session($force = false) {
3029
-	static $session;
3030
-	if ($force or !isset($session)) {
3031
-		$s = pipeline('definir_session',
3032
-			$GLOBALS['visiteur_session']
3033
-				? serialize($GLOBALS['visiteur_session'])
3034
-				. '_' . @$_COOKIE['spip_session']
3035
-				: ''
3036
-		);
3037
-		$session = $s ? substr(md5($s), 0, 8) : '';
3038
-	}
3028
+    static $session;
3029
+    if ($force or !isset($session)) {
3030
+        $s = pipeline('definir_session',
3031
+            $GLOBALS['visiteur_session']
3032
+                ? serialize($GLOBALS['visiteur_session'])
3033
+                . '_' . @$_COOKIE['spip_session']
3034
+                : ''
3035
+        );
3036
+        $session = $s ? substr(md5($s), 0, 8) : '';
3037
+    }
3039 3038
 
3040
-	#spip_log('session: '.$session);
3041
-	return $session;
3039
+    #spip_log('session: '.$session);
3040
+    return $session;
3042 3041
 }
3043 3042
 
3044 3043
 
@@ -3057,9 +3056,9 @@  discard block
 block discarded – undo
3057 3056
  *    Lien sur une icone d'aide
3058 3057
  **/
3059 3058
 function aider($aide = '', $distante = false) {
3060
-	$aider = charger_fonction('aide', 'inc', true);
3059
+    $aider = charger_fonction('aide', 'inc', true);
3061 3060
 
3062
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3061
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3063 3062
 }
3064 3063
 
3065 3064
 /**
@@ -3069,13 +3068,13 @@  discard block
 block discarded – undo
3069 3068
  */
3070 3069
 function exec_info_dist() {
3071 3070
 
3072
-	include_spip('inc/autoriser');
3073
-	if (autoriser('webmestre')) {
3074
-		phpinfo();
3075
-	} else {
3076
-		include_spip('inc/filtres');
3077
-		sinon_interdire_acces();
3078
-	}
3071
+    include_spip('inc/autoriser');
3072
+    if (autoriser('webmestre')) {
3073
+        phpinfo();
3074
+    } else {
3075
+        include_spip('inc/filtres');
3076
+        sinon_interdire_acces();
3077
+    }
3079 3078
 }
3080 3079
 
3081 3080
 /**
@@ -3095,13 +3094,13 @@  discard block
 block discarded – undo
3095 3094
  *     - string si $message à false.
3096 3095
  **/
3097 3096
 function erreur_squelette($message = '', $lieu = '') {
3098
-	$debusquer = charger_fonction('debusquer', 'public');
3099
-	if (is_array($lieu)) {
3100
-		include_spip('public/compiler');
3101
-		$lieu = reconstruire_contexte_compil($lieu);
3102
-	}
3097
+    $debusquer = charger_fonction('debusquer', 'public');
3098
+    if (is_array($lieu)) {
3099
+        include_spip('public/compiler');
3100
+        $lieu = reconstruire_contexte_compil($lieu);
3101
+    }
3103 3102
 
3104
-	return $debusquer($message, $lieu);
3103
+    return $debusquer($message, $lieu);
3105 3104
 }
3106 3105
 
3107 3106
 /**
@@ -3138,92 +3137,92 @@  discard block
 block discarded – undo
3138 3137
  *     - ou tableau d'information sur le squelette.
3139 3138
  */
3140 3139
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3141
-	if (!function_exists('evaluer_fond')) {
3142
-		include_spip('public/assembler');
3143
-	}
3144
-	// assurer la compat avec l'ancienne syntaxe
3145
-	// (trim etait le 3eme argument, par defaut a true)
3146
-	if (!is_array($options)) {
3147
-		$options = array('trim' => $options);
3148
-	}
3149
-	if (!isset($options['trim'])) {
3150
-		$options['trim'] = true;
3151
-	}
3152
-
3153
-	if (isset($contexte['connect'])) {
3154
-		$connect = $contexte['connect'];
3155
-		unset($contexte['connect']);
3156
-	}
3157
-
3158
-	$texte = "";
3159
-	$pages = array();
3160
-	$lang_select = '';
3161
-	if (!isset($options['etoile']) or !$options['etoile']) {
3162
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3163
-		if (!isset($contexte['lang'])) {
3164
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3165
-		}
3166
-
3167
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3168
-			$lang_select = lang_select($contexte['lang']);
3169
-		}
3170
-	}
3171
-
3172
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3173
-		$GLOBALS['_INC_PUBLIC'] = 0;
3174
-	}
3175
-
3176
-	$GLOBALS['_INC_PUBLIC']++;
3177
-
3178
-
3179
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3180
-		$page = evaluer_fond($f, $contexte, $connect);
3181
-		if ($page === '') {
3182
-			$c = isset($options['compil']) ? $options['compil'] : '';
3183
-			$a = array('fichier' => $fond);
3184
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3185
-			erreur_squelette($erreur, $c);
3186
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3187
-			$page = array('texte' => '', 'erreur' => $erreur);
3188
-		}
3189
-
3190
-		$page = pipeline('recuperer_fond', array(
3191
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3192
-			'data' => $page
3193
-		));
3194
-		if (isset($options['ajax']) and $options['ajax']) {
3195
-			if (!function_exists('encoder_contexte_ajax')) {
3196
-				include_spip('inc/filtres');
3197
-			}
3198
-			$page['texte'] = encoder_contexte_ajax(
3199
-				array_merge(
3200
-					$contexte,
3201
-					array('fond' => $f),
3202
-					($connect ? array('connect' => $connect) : array())
3203
-				),
3204
-				'',
3205
-				$page['texte'],
3206
-				$options['ajax']
3207
-			);
3208
-		}
3209
-
3210
-		if (isset($options['raw']) and $options['raw']) {
3211
-			$pages[] = $page;
3212
-		} else {
3213
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3214
-		}
3215
-	}
3216
-
3217
-	$GLOBALS['_INC_PUBLIC']--;
3218
-
3219
-	if ($lang_select) {
3220
-		lang_select();
3221
-	}
3222
-	if (isset($options['raw']) and $options['raw']) {
3223
-		return is_array($fond) ? $pages : reset($pages);
3224
-	} else {
3225
-		return $options['trim'] ? ltrim($texte) : $texte;
3226
-	}
3140
+    if (!function_exists('evaluer_fond')) {
3141
+        include_spip('public/assembler');
3142
+    }
3143
+    // assurer la compat avec l'ancienne syntaxe
3144
+    // (trim etait le 3eme argument, par defaut a true)
3145
+    if (!is_array($options)) {
3146
+        $options = array('trim' => $options);
3147
+    }
3148
+    if (!isset($options['trim'])) {
3149
+        $options['trim'] = true;
3150
+    }
3151
+
3152
+    if (isset($contexte['connect'])) {
3153
+        $connect = $contexte['connect'];
3154
+        unset($contexte['connect']);
3155
+    }
3156
+
3157
+    $texte = "";
3158
+    $pages = array();
3159
+    $lang_select = '';
3160
+    if (!isset($options['etoile']) or !$options['etoile']) {
3161
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3162
+        if (!isset($contexte['lang'])) {
3163
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3164
+        }
3165
+
3166
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3167
+            $lang_select = lang_select($contexte['lang']);
3168
+        }
3169
+    }
3170
+
3171
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3172
+        $GLOBALS['_INC_PUBLIC'] = 0;
3173
+    }
3174
+
3175
+    $GLOBALS['_INC_PUBLIC']++;
3176
+
3177
+
3178
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3179
+        $page = evaluer_fond($f, $contexte, $connect);
3180
+        if ($page === '') {
3181
+            $c = isset($options['compil']) ? $options['compil'] : '';
3182
+            $a = array('fichier' => $fond);
3183
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3184
+            erreur_squelette($erreur, $c);
3185
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3186
+            $page = array('texte' => '', 'erreur' => $erreur);
3187
+        }
3188
+
3189
+        $page = pipeline('recuperer_fond', array(
3190
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3191
+            'data' => $page
3192
+        ));
3193
+        if (isset($options['ajax']) and $options['ajax']) {
3194
+            if (!function_exists('encoder_contexte_ajax')) {
3195
+                include_spip('inc/filtres');
3196
+            }
3197
+            $page['texte'] = encoder_contexte_ajax(
3198
+                array_merge(
3199
+                    $contexte,
3200
+                    array('fond' => $f),
3201
+                    ($connect ? array('connect' => $connect) : array())
3202
+                ),
3203
+                '',
3204
+                $page['texte'],
3205
+                $options['ajax']
3206
+            );
3207
+        }
3208
+
3209
+        if (isset($options['raw']) and $options['raw']) {
3210
+            $pages[] = $page;
3211
+        } else {
3212
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3213
+        }
3214
+    }
3215
+
3216
+    $GLOBALS['_INC_PUBLIC']--;
3217
+
3218
+    if ($lang_select) {
3219
+        lang_select();
3220
+    }
3221
+    if (isset($options['raw']) and $options['raw']) {
3222
+        return is_array($fond) ? $pages : reset($pages);
3223
+    } else {
3224
+        return $options['trim'] ? ltrim($texte) : $texte;
3225
+    }
3227 3226
 }
3228 3227
 
3229 3228
 /**
@@ -3233,7 +3232,7 @@  discard block
 block discarded – undo
3233 3232
  * @return string
3234 3233
  */
3235 3234
 function trouve_modele($nom) {
3236
-	return trouver_fond($nom, 'modeles/');
3235
+    return trouver_fond($nom, 'modeles/');
3237 3236
 }
3238 3237
 
3239 3238
 /**
@@ -3249,21 +3248,21 @@  discard block
 block discarded – undo
3249 3248
  * @return array|string
3250 3249
  */
3251 3250
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3252
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3253
-	if (!$pathinfo) {
3254
-		return $f;
3255
-	}
3256
-	// renvoyer un tableau detaille si $pathinfo==true
3257
-	$p = pathinfo($f);
3258
-	if (!isset($p['extension']) or !$p['extension']) {
3259
-		$p['extension'] = _EXTENSION_SQUELETTES;
3260
-	}
3261
-	if (!isset($p['extension']) or !$p['filename']) {
3262
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3263
-	}
3264
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3251
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3252
+    if (!$pathinfo) {
3253
+        return $f;
3254
+    }
3255
+    // renvoyer un tableau detaille si $pathinfo==true
3256
+    $p = pathinfo($f);
3257
+    if (!isset($p['extension']) or !$p['extension']) {
3258
+        $p['extension'] = _EXTENSION_SQUELETTES;
3259
+    }
3260
+    if (!isset($p['extension']) or !$p['filename']) {
3261
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3262
+    }
3263
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3265 3264
 
3266
-	return $p;
3265
+    return $p;
3267 3266
 }
3268 3267
 
3269 3268
 /**
@@ -3284,24 +3283,24 @@  discard block
 block discarded – undo
3284 3283
  *     Nom de l'exec, sinon chaîne vide.
3285 3284
  **/
3286 3285
 function tester_url_ecrire($nom) {
3287
-	static $exec = array();
3288
-	if (isset($exec[$nom])) {
3289
-		return $exec[$nom];
3290
-	}
3291
-	// tester si c'est une page en squelette
3292
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3293
-		return $exec[$nom] = 'fond';
3294
-	} // compat skels orthogonaux version precedente
3295
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3296
-		return $exec[$nom] = 'fond_monobloc';
3297
-	} // echafaudage d'un fond !
3298
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3299
-		return $exec[$nom] = 'fond';
3300
-	}
3301
-	// attention, il ne faut pas inclure l'exec ici
3302
-	// car sinon #URL_ECRIRE provoque des inclusions
3303
-	// et des define intrusifs potentiels
3304
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3286
+    static $exec = array();
3287
+    if (isset($exec[$nom])) {
3288
+        return $exec[$nom];
3289
+    }
3290
+    // tester si c'est une page en squelette
3291
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3292
+        return $exec[$nom] = 'fond';
3293
+    } // compat skels orthogonaux version precedente
3294
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3295
+        return $exec[$nom] = 'fond_monobloc';
3296
+    } // echafaudage d'un fond !
3297
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3298
+        return $exec[$nom] = 'fond';
3299
+    }
3300
+    // attention, il ne faut pas inclure l'exec ici
3301
+    // car sinon #URL_ECRIRE provoque des inclusions
3302
+    // et des define intrusifs potentiels
3303
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3305 3304
 }
3306 3305
 
3307 3306
 
@@ -3317,10 +3316,10 @@  discard block
 block discarded – undo
3317 3316
  * @return bool true si le module est chargé
3318 3317
  **/
3319 3318
 function charger_php_extension($module) {
3320
-	if (extension_loaded($module)) {
3321
-		return true;
3322
-	}
3323
-	return false;
3319
+    if (extension_loaded($module)) {
3320
+        return true;
3321
+    }
3322
+    return false;
3324 3323
 }
3325 3324
 
3326 3325
 
@@ -3331,8 +3330,8 @@  discard block
 block discarded – undo
3331 3330
  *     true si et seulement si la configuration autorise le code HTML5 sur le site public
3332 3331
  **/
3333 3332
 function html5_permis() {
3334
-	return (isset($GLOBALS['meta']['version_html_max'])
3335
-		and ('html5' == $GLOBALS['meta']['version_html_max']));
3333
+    return (isset($GLOBALS['meta']['version_html_max'])
3334
+        and ('html5' == $GLOBALS['meta']['version_html_max']));
3336 3335
 }
3337 3336
 
3338 3337
 /*
@@ -3350,7 +3349,7 @@  discard block
 block discarded – undo
3350 3349
  * @return mixed Valeur de la meta.
3351 3350
  **/
3352 3351
 function lire_meta($nom) {
3353
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3352
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3354 3353
 }
3355 3354
 
3356 3355
 
@@ -3372,128 +3371,128 @@  discard block
 block discarded – undo
3372 3371
  * @param string $statut
3373 3372
  */
3374 3373
 function avertir_auteurs($nom, $message, $statut = '') {
3375
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3376
-	if (!$alertes
3377
-		or !is_array($alertes = unserialize($alertes))
3378
-	) {
3379
-		$alertes = array();
3380
-	}
3374
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3375
+    if (!$alertes
3376
+        or !is_array($alertes = unserialize($alertes))
3377
+    ) {
3378
+        $alertes = array();
3379
+    }
3381 3380
 
3382
-	if (!isset($alertes[$statut])) {
3383
-		$alertes[$statut] = array();
3384
-	}
3385
-	$alertes[$statut][$nom] = $message;
3386
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3381
+    if (!isset($alertes[$statut])) {
3382
+        $alertes[$statut] = array();
3383
+    }
3384
+    $alertes[$statut][$nom] = $message;
3385
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3387 3386
 }
3388 3387
 
3389 3388
 if (PHP_VERSION_ID < 50500) {
3390
-	if (!function_exists('array_column')) {
3391
-		/**
3392
-		 * Returns the values from a single column of the input array, identified by
3393
-		 * the $columnKey.
3394
-		 *
3395
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3396
-		 * array by the values from the $indexKey column in the input array.
3397
-		 *
3398
-		 * @link http://php.net/manual/fr/function.array-column.php
3399
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3400
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3401
-		 * @license http://opensource.org/licenses/MIT MIT
3402
-		 *
3403
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3404
-		 *                     a column of values.
3405
-		 * @param mixed $columnKey The column of values to return. This value may be the
3406
-		 *                         integer key of the column you wish to retrieve, or it
3407
-		 *                         may be the string key name for an associative array.
3408
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3409
-		 *                        the returned array. This value may be the integer key
3410
-		 *                        of the column, or it may be the string key name.
3411
-		 * @return array
3412
-		 */
3413
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3414
-		{
3415
-			// Using func_get_args() in order to check for proper number of
3416
-			// parameters and trigger errors exactly as the built-in array_column()
3417
-			// does in PHP 5.5.
3418
-			$argc = func_num_args();
3419
-			$params = func_get_args();
3420
-
3421
-			if ($argc < 2) {
3422
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3423
-				return null;
3424
-			}
3425
-
3426
-			if (!is_array($params[0])) {
3427
-				trigger_error(
3428
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3429
-					E_USER_WARNING
3430
-				);
3431
-				return null;
3432
-			}
3433
-
3434
-			if (!is_int($params[1])
3435
-				&& !is_float($params[1])
3436
-				&& !is_string($params[1])
3437
-				&& $params[1] !== null
3438
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3439
-			) {
3440
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3441
-				return false;
3442
-			}
3443
-
3444
-			if (isset($params[2])
3445
-				&& !is_int($params[2])
3446
-				&& !is_float($params[2])
3447
-				&& !is_string($params[2])
3448
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3449
-			) {
3450
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3451
-				return false;
3452
-			}
3453
-
3454
-			$paramsInput = $params[0];
3455
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3456
-
3457
-			$paramsIndexKey = null;
3458
-			if (isset($params[2])) {
3459
-				if (is_float($params[2]) || is_int($params[2])) {
3460
-					$paramsIndexKey = (int) $params[2];
3461
-				} else {
3462
-					$paramsIndexKey = (string) $params[2];
3463
-				}
3464
-			}
3465
-
3466
-			$resultArray = array();
3467
-
3468
-			foreach ($paramsInput as $row) {
3469
-				$key = $value = null;
3470
-				$keySet = $valueSet = false;
3471
-
3472
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3473
-					$keySet = true;
3474
-					$key = (string) $row[$paramsIndexKey];
3475
-				}
3476
-
3477
-				if ($paramsColumnKey === null) {
3478
-					$valueSet = true;
3479
-					$value = $row;
3480
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3481
-					$valueSet = true;
3482
-					$value = $row[$paramsColumnKey];
3483
-				}
3484
-
3485
-				if ($valueSet) {
3486
-					if ($keySet) {
3487
-						$resultArray[$key] = $value;
3488
-					} else {
3489
-						$resultArray[] = $value;
3490
-					}
3491
-				}
3492
-
3493
-			}
3494
-
3495
-			return $resultArray;
3496
-		}
3497
-
3498
-	}
3389
+    if (!function_exists('array_column')) {
3390
+        /**
3391
+         * Returns the values from a single column of the input array, identified by
3392
+         * the $columnKey.
3393
+         *
3394
+         * Optionally, you may provide an $indexKey to index the values in the returned
3395
+         * array by the values from the $indexKey column in the input array.
3396
+         *
3397
+         * @link http://php.net/manual/fr/function.array-column.php
3398
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3399
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3400
+         * @license http://opensource.org/licenses/MIT MIT
3401
+         *
3402
+         * @param array $input A multi-dimensional array (record set) from which to pull
3403
+         *                     a column of values.
3404
+         * @param mixed $columnKey The column of values to return. This value may be the
3405
+         *                         integer key of the column you wish to retrieve, or it
3406
+         *                         may be the string key name for an associative array.
3407
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3408
+         *                        the returned array. This value may be the integer key
3409
+         *                        of the column, or it may be the string key name.
3410
+         * @return array
3411
+         */
3412
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3413
+        {
3414
+            // Using func_get_args() in order to check for proper number of
3415
+            // parameters and trigger errors exactly as the built-in array_column()
3416
+            // does in PHP 5.5.
3417
+            $argc = func_num_args();
3418
+            $params = func_get_args();
3419
+
3420
+            if ($argc < 2) {
3421
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3422
+                return null;
3423
+            }
3424
+
3425
+            if (!is_array($params[0])) {
3426
+                trigger_error(
3427
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3428
+                    E_USER_WARNING
3429
+                );
3430
+                return null;
3431
+            }
3432
+
3433
+            if (!is_int($params[1])
3434
+                && !is_float($params[1])
3435
+                && !is_string($params[1])
3436
+                && $params[1] !== null
3437
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3438
+            ) {
3439
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3440
+                return false;
3441
+            }
3442
+
3443
+            if (isset($params[2])
3444
+                && !is_int($params[2])
3445
+                && !is_float($params[2])
3446
+                && !is_string($params[2])
3447
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3448
+            ) {
3449
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3450
+                return false;
3451
+            }
3452
+
3453
+            $paramsInput = $params[0];
3454
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3455
+
3456
+            $paramsIndexKey = null;
3457
+            if (isset($params[2])) {
3458
+                if (is_float($params[2]) || is_int($params[2])) {
3459
+                    $paramsIndexKey = (int) $params[2];
3460
+                } else {
3461
+                    $paramsIndexKey = (string) $params[2];
3462
+                }
3463
+            }
3464
+
3465
+            $resultArray = array();
3466
+
3467
+            foreach ($paramsInput as $row) {
3468
+                $key = $value = null;
3469
+                $keySet = $valueSet = false;
3470
+
3471
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3472
+                    $keySet = true;
3473
+                    $key = (string) $row[$paramsIndexKey];
3474
+                }
3475
+
3476
+                if ($paramsColumnKey === null) {
3477
+                    $valueSet = true;
3478
+                    $value = $row;
3479
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3480
+                    $valueSet = true;
3481
+                    $value = $row[$paramsColumnKey];
3482
+                }
3483
+
3484
+                if ($valueSet) {
3485
+                    if ($keySet) {
3486
+                        $resultArray[$key] = $value;
3487
+                    } else {
3488
+                        $resultArray[] = $value;
3489
+                    }
3490
+                }
3491
+
3492
+            }
3493
+
3494
+            return $resultArray;
3495
+        }
3496
+
3497
+    }
3499 3498
 }
3500 3499
\ No newline at end of file
Please login to merge, or discard this patch.