Completed
Push — master ( 1d2283...7fdd0e )
by cam
04:59
created
ecrire/inc/utils.php 1 patch
Indentation   +2209 added lines, -2210 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
 /**
@@ -463,25 +463,25 @@  discard block
 block discarded – undo
463 463
  * @return array|mixed|string
464 464
  */
465 465
 function spip_sanitize_from_request($value, $key, $sanitize_function='entites_html') {
466
-	if (is_array($value)) {
467
-		if ($key=='*') {
468
-			$key = array_keys($value);
469
-		}
470
-		if (!is_array($key)) {
471
-			$key = [$key];
472
-		}
473
-		foreach ($key as $k) {
474
-			if (!empty($value[$k])) {
475
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
476
-			}
477
-		}
478
-		return $value;
479
-	}
480
-	// si la valeur vient des GET ou POST on la sanitize
481
-	if (!empty($value) and $value == _request($key)) {
482
-		$value = $sanitize_function($value);
483
-	}
484
-	return $value;
466
+    if (is_array($value)) {
467
+        if ($key=='*') {
468
+            $key = array_keys($value);
469
+        }
470
+        if (!is_array($key)) {
471
+            $key = [$key];
472
+        }
473
+        foreach ($key as $k) {
474
+            if (!empty($value[$k])) {
475
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
476
+            }
477
+        }
478
+        return $value;
479
+    }
480
+    // si la valeur vient des GET ou POST on la sanitize
481
+    if (!empty($value) and $value == _request($key)) {
482
+        $value = $sanitize_function($value);
483
+    }
484
+    return $value;
485 485
 }
486 486
 
487 487
 /**
@@ -489,23 +489,22 @@  discard block
 block discarded – undo
489 489
  * 
490 490
  * On est sur le web, on exclut certains protocoles, 
491 491
  * notamment 'file://', 'php://' et d'autres…
492
-
493 492
  * @param string $url
494 493
  * @return bool
495 494
  */
496 495
 function tester_url_absolue($url) {
497
-	$url = trim($url);
498
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
499
-		if (
500
-			isset($m[1])
501
-			and $p = strtolower(rtrim($m[1], ':'))
502
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
503
-		  ) {
504
-			return false;
505
-		}
506
-		return true;
507
-	}
508
-	return false;
496
+    $url = trim($url);
497
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
498
+        if (
499
+            isset($m[1])
500
+            and $p = strtolower(rtrim($m[1], ':'))
501
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
502
+            ) {
503
+            return false;
504
+        }
505
+        return true;
506
+    }
507
+    return false;
509 508
 }
510 509
 
511 510
 /**
@@ -527,94 +526,94 @@  discard block
 block discarded – undo
527 526
  * @return string URL
528 527
  */
529 528
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
530
-	// requete erronnee : plusieurs variable dans $c et aucun $v
531
-	if (strpos($c, "|") !== false and is_null($v)) {
532
-		return null;
533
-	}
534
-
535
-	// lever l'#ancre
536
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
537
-		$url = $r[1];
538
-		$ancre = $r[2];
539
-	} else {
540
-		$ancre = '';
541
-	}
542
-
543
-	// eclater
544
-	$url = preg_split(',[?]|&amp;|&,', $url);
545
-
546
-	// recuperer la base
547
-	$a = array_shift($url);
548
-	if (!$a) {
549
-		$a = './';
550
-	}
551
-
552
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
553
-	$ajouts = array_flip(explode('|', $c));
554
-	$u = is_array($v) ? $v : rawurlencode($v);
555
-	$testv = (is_array($v) ? count($v) : strlen($v));
556
-	$v_read = null;
557
-	// lire les variables et agir
558
-	foreach ($url as $n => $val) {
559
-		if (preg_match($regexp, urldecode($val), $r)) {
560
-			$r = array_pad($r, 3, null);
561
-			if ($v === null) {
562
-				// c'est un tableau, on memorise les valeurs
563
-				if (substr($r[1], -2) == "[]") {
564
-					if (!$v_read) {
565
-						$v_read = array();
566
-					}
567
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
568
-				} // c'est un scalaire, on retourne direct
569
-				else {
570
-					return $r[2] ? substr($r[2], 1) : '';
571
-				}
572
-			} // suppression
573
-			elseif (!$testv) {
574
-				unset($url[$n]);
575
-			}
576
-			// Ajout. Pour une variable, remplacer au meme endroit,
577
-			// pour un tableau ce sera fait dans la prochaine boucle
578
-			elseif (substr($r[1], -2) != '[]') {
579
-				$url[$n] = $r[1] . '=' . $u;
580
-				unset($ajouts[$r[1]]);
581
-			}
582
-			// Pour les tableaux on laisse tomber les valeurs de
583
-			// départ, on remplira à l'étape suivante
584
-			else {
585
-				unset($url[$n]);
586
-			}
587
-		}
588
-	}
589
-
590
-	// traiter les parametres pas encore trouves
591
-	if ($v === null
592
-		and $args = func_get_args()
593
-		and count($args) == 2
594
-	) {
595
-		return $v_read; // rien trouve ou un tableau
596
-	} elseif ($testv) {
597
-		foreach ($ajouts as $k => $n) {
598
-			if (!is_array($v)) {
599
-				$url[] = $k . '=' . $u;
600
-			} else {
601
-				$id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
602
-				foreach ($v as $w) {
603
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
604
-				}
605
-			}
606
-		}
607
-	}
608
-
609
-	// eliminer les vides
610
-	$url = array_filter($url);
611
-
612
-	// recomposer l'adresse
613
-	if ($url) {
614
-		$a .= '?' . join($sep, $url);
615
-	}
616
-
617
-	return $a . $ancre;
529
+    // requete erronnee : plusieurs variable dans $c et aucun $v
530
+    if (strpos($c, "|") !== false and is_null($v)) {
531
+        return null;
532
+    }
533
+
534
+    // lever l'#ancre
535
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
536
+        $url = $r[1];
537
+        $ancre = $r[2];
538
+    } else {
539
+        $ancre = '';
540
+    }
541
+
542
+    // eclater
543
+    $url = preg_split(',[?]|&amp;|&,', $url);
544
+
545
+    // recuperer la base
546
+    $a = array_shift($url);
547
+    if (!$a) {
548
+        $a = './';
549
+    }
550
+
551
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
552
+    $ajouts = array_flip(explode('|', $c));
553
+    $u = is_array($v) ? $v : rawurlencode($v);
554
+    $testv = (is_array($v) ? count($v) : strlen($v));
555
+    $v_read = null;
556
+    // lire les variables et agir
557
+    foreach ($url as $n => $val) {
558
+        if (preg_match($regexp, urldecode($val), $r)) {
559
+            $r = array_pad($r, 3, null);
560
+            if ($v === null) {
561
+                // c'est un tableau, on memorise les valeurs
562
+                if (substr($r[1], -2) == "[]") {
563
+                    if (!$v_read) {
564
+                        $v_read = array();
565
+                    }
566
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
567
+                } // c'est un scalaire, on retourne direct
568
+                else {
569
+                    return $r[2] ? substr($r[2], 1) : '';
570
+                }
571
+            } // suppression
572
+            elseif (!$testv) {
573
+                unset($url[$n]);
574
+            }
575
+            // Ajout. Pour une variable, remplacer au meme endroit,
576
+            // pour un tableau ce sera fait dans la prochaine boucle
577
+            elseif (substr($r[1], -2) != '[]') {
578
+                $url[$n] = $r[1] . '=' . $u;
579
+                unset($ajouts[$r[1]]);
580
+            }
581
+            // Pour les tableaux on laisse tomber les valeurs de
582
+            // départ, on remplira à l'étape suivante
583
+            else {
584
+                unset($url[$n]);
585
+            }
586
+        }
587
+    }
588
+
589
+    // traiter les parametres pas encore trouves
590
+    if ($v === null
591
+        and $args = func_get_args()
592
+        and count($args) == 2
593
+    ) {
594
+        return $v_read; // rien trouve ou un tableau
595
+    } elseif ($testv) {
596
+        foreach ($ajouts as $k => $n) {
597
+            if (!is_array($v)) {
598
+                $url[] = $k . '=' . $u;
599
+            } else {
600
+                $id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
601
+                foreach ($v as $w) {
602
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
603
+                }
604
+            }
605
+        }
606
+    }
607
+
608
+    // eliminer les vides
609
+    $url = array_filter($url);
610
+
611
+    // recomposer l'adresse
612
+    if ($url) {
613
+        $a .= '?' . join($sep, $url);
614
+    }
615
+
616
+    return $a . $ancre;
618 617
 }
619 618
 
620 619
 /**
@@ -632,21 +631,21 @@  discard block
 block discarded – undo
632 631
  * @return string
633 632
  */
634 633
 function ancre_url($url, $ancre) {
635
-	// lever l'#ancre
636
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
637
-		$url = $r[1];
638
-	}
639
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
640
-		if (!function_exists('translitteration')) {
641
-			include_spip('inc/charsets');
642
-		}
643
-		$ancre = preg_replace(
644
-			array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
645
-			array('', '-'),
646
-			translitteration($ancre)
647
-		);
648
-	}
649
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
634
+    // lever l'#ancre
635
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
636
+        $url = $r[1];
637
+    }
638
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
639
+        if (!function_exists('translitteration')) {
640
+            include_spip('inc/charsets');
641
+        }
642
+        $ancre = preg_replace(
643
+            array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
644
+            array('', '-'),
645
+            translitteration($ancre)
646
+        );
647
+    }
648
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
650 649
 }
651 650
 
652 651
 /**
@@ -656,16 +655,16 @@  discard block
 block discarded – undo
656 655
  * @return string
657 656
  */
658 657
 function nettoyer_uri($reset = null) {
659
-	static $done = false;
660
-	static $propre = '';
661
-	if (!is_null($reset)) {
662
-		return $propre = $reset;
663
-	}
664
-	if ($done) {
665
-		return $propre;
666
-	}
667
-	$done = true;
668
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
658
+    static $done = false;
659
+    static $propre = '';
660
+    if (!is_null($reset)) {
661
+        return $propre = $reset;
662
+    }
663
+    if ($done) {
664
+        return $propre;
665
+    }
666
+    $done = true;
667
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
669 668
 }
670 669
 
671 670
 /**
@@ -677,13 +676,13 @@  discard block
 block discarded – undo
677 676
  * @return string
678 677
  */
679 678
 function nettoyer_uri_var($request_uri) {
680
-	$uri1 = $request_uri;
681
-	do {
682
-		$uri = $uri1;
683
-		$uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
684
-			'\1', $uri);
685
-	} while ($uri <> $uri1);
686
-	return preg_replace(',[?&]$,', '', $uri1);
679
+    $uri1 = $request_uri;
680
+    do {
681
+        $uri = $uri1;
682
+        $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
683
+            '\1', $uri);
684
+    } while ($uri <> $uri1);
685
+    return preg_replace(',[?&]$,', '', $uri1);
687 686
 }
688 687
 
689 688
 
@@ -697,47 +696,47 @@  discard block
 block discarded – undo
697 696
  *    URL vers soi-même
698 697
  **/
699 698
 function self($amp = '&amp;', $root = false) {
700
-	$url = nettoyer_uri();
701
-	if (!$root
702
-		and (
703
-			// si pas de profondeur on peut tronquer
704
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
705
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
706
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
707
-	) {
708
-		$url = preg_replace(',^[^?]*/,', '', $url);
709
-	}
710
-	// ajouter le cas echeant les variables _POST['id_...']
711
-	foreach ($_POST as $v => $c) {
712
-		if (substr($v, 0, 3) == 'id_') {
713
-			$url = parametre_url($url, $v, $c, '&');
714
-		}
715
-	}
716
-
717
-	// supprimer les variables sans interet
718
-	if (test_espace_prive()) {
719
-		$url = preg_replace(',([?&])('
720
-			. 'lang|show_docs|'
721
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
722
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
723
-		$url = preg_replace(',[&]$,', '\1', $url);
724
-	}
725
-
726
-	// eviter les hacks
727
-	include_spip('inc/filtres_mini');
728
-	$url = spip_htmlspecialchars($url);
699
+    $url = nettoyer_uri();
700
+    if (!$root
701
+        and (
702
+            // si pas de profondeur on peut tronquer
703
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
704
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
705
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
706
+    ) {
707
+        $url = preg_replace(',^[^?]*/,', '', $url);
708
+    }
709
+    // ajouter le cas echeant les variables _POST['id_...']
710
+    foreach ($_POST as $v => $c) {
711
+        if (substr($v, 0, 3) == 'id_') {
712
+            $url = parametre_url($url, $v, $c, '&');
713
+        }
714
+    }
715
+
716
+    // supprimer les variables sans interet
717
+    if (test_espace_prive()) {
718
+        $url = preg_replace(',([?&])('
719
+            . 'lang|show_docs|'
720
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
721
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
722
+        $url = preg_replace(',[&]$,', '\1', $url);
723
+    }
724
+
725
+    // eviter les hacks
726
+    include_spip('inc/filtres_mini');
727
+    $url = spip_htmlspecialchars($url);
729 728
 	
730
-	$url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
729
+    $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
731 730
 
732
-	// &amp; ?
733
-	if ($amp != '&amp;') {
734
-		$url = str_replace('&amp;', $amp, $url);
735
-	}
731
+    // &amp; ?
732
+    if ($amp != '&amp;') {
733
+        $url = str_replace('&amp;', $amp, $url);
734
+    }
736 735
 
737
-	// Si ca demarre par ? ou vide, donner './'
738
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
736
+    // Si ca demarre par ? ou vide, donner './'
737
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
739 738
 
740
-	return $url;
739
+    return $url;
741 740
 }
742 741
 
743 742
 
@@ -748,7 +747,7 @@  discard block
 block discarded – undo
748 747
  *     true si c'est le cas, false sinon.
749 748
  */
750 749
 function test_espace_prive() {
751
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
750
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
752 751
 }
753 752
 
754 753
 /**
@@ -758,7 +757,7 @@  discard block
 block discarded – undo
758 757
  * @return bool
759 758
  */
760 759
 function test_plugin_actif($plugin) {
761
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
760
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
762 761
 }
763 762
 
764 763
 /**
@@ -789,51 +788,51 @@  discard block
 block discarded – undo
789 788
  *     Texte
790 789
  */
791 790
 function _T($texte, $args = array(), $options = array()) {
792
-	static $traduire = false;
793
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
794
-	if ($options) {
795
-		// support de l'ancien argument $class
796
-		if (is_string($options)) {
797
-			$options = array('class' => $options);
798
-		}
799
-		$o = array_merge($o, $options);
800
-	}
791
+    static $traduire = false;
792
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
793
+    if ($options) {
794
+        // support de l'ancien argument $class
795
+        if (is_string($options)) {
796
+            $options = array('class' => $options);
797
+        }
798
+        $o = array_merge($o, $options);
799
+    }
801 800
 
802
-	if (!$traduire) {
803
-		$traduire = charger_fonction('traduire', 'inc');
804
-		include_spip('inc/lang');
805
-	}
801
+    if (!$traduire) {
802
+        $traduire = charger_fonction('traduire', 'inc');
803
+        include_spip('inc/lang');
804
+    }
806 805
 
807
-	// On peut passer explicitement la langue dans le tableau
808
-	// On utilise le même nom de variable que la globale
809
-	if (isset($args['spip_lang'])) {
810
-		$lang = $args['spip_lang'];
811
-		// On l'enleve pour ne pas le passer au remplacement
812
-		unset($args['spip_lang']);
813
-	} // Sinon on prend la langue du contexte
814
-	else {
815
-		$lang = $GLOBALS['spip_lang'];
816
-	}
817
-	$text = $traduire($texte, $lang);
806
+    // On peut passer explicitement la langue dans le tableau
807
+    // On utilise le même nom de variable que la globale
808
+    if (isset($args['spip_lang'])) {
809
+        $lang = $args['spip_lang'];
810
+        // On l'enleve pour ne pas le passer au remplacement
811
+        unset($args['spip_lang']);
812
+    } // Sinon on prend la langue du contexte
813
+    else {
814
+        $lang = $GLOBALS['spip_lang'];
815
+    }
816
+    $text = $traduire($texte, $lang);
818 817
 
819
-	if (!strlen($text)) {
820
-		if (!$o['force']) {
821
-			return '';
822
-		}
818
+    if (!strlen($text)) {
819
+        if (!$o['force']) {
820
+            return '';
821
+        }
823 822
 
824
-		$text = $texte;
823
+        $text = $texte;
825 824
 
826
-		// pour les chaines non traduites, assurer un service minimum
827
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
828
-			$text = str_replace('_', ' ',
829
-				(($n = strpos($text, ':')) === false ? $texte :
830
-					substr($texte, $n + 1)));
831
-		}
832
-		$o['class'] = null;
825
+        // pour les chaines non traduites, assurer un service minimum
826
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
827
+            $text = str_replace('_', ' ',
828
+                (($n = strpos($text, ':')) === false ? $texte :
829
+                    substr($texte, $n + 1)));
830
+        }
831
+        $o['class'] = null;
833 832
 
834
-	}
833
+    }
835 834
 
836
-	return _L($text, $args, $o);
835
+    return _L($text, $args, $o);
837 836
 
838 837
 }
839 838
 
@@ -861,53 +860,53 @@  discard block
 block discarded – undo
861 860
  *     Texte
862 861
  */
863 862
 function _L($text, $args = array(), $options = array()) {
864
-	$f = $text;
865
-	$defaut_options = array(
866
-		'class' => null,
867
-		'sanitize' => true,
868
-	);
869
-	// support de l'ancien argument $class
870
-	if ($options and is_string($options)) {
871
-		$options = array('class' => $options);
872
-	}
873
-	if (is_array($options)) {
874
-		$options += $defaut_options;
875
-	} else {
876
-		$options = $defaut_options;
877
-	}
878
-
879
-	if (is_array($args) and count($args)) {
880
-		if (!function_exists('interdire_scripts')) {
881
-			include_spip('inc/texte');
882
-		}
883
-		if (!function_exists('echapper_html_suspect')) {
884
-			include_spip('inc/texte_mini');
885
-		}
886
-		foreach ($args as $name => $value) {
887
-			if (strpos($text, "@$name@") !== false) {
888
-				if ($options['sanitize']) {
889
-					$value = echapper_html_suspect($value);
890
-					$value = interdire_scripts($value, -1);
891
-				}
892
-				if (!empty($options['class'])) {
893
-					$value = "<span class='".$options['class']."'>$value</span>";
894
-				}
895
-				$text = str_replace("@$name@", $value, $text);
896
-				unset($args[$name]);
897
-			}
898
-		}
899
-		// Si des variables n'ont pas ete inserees, le signaler
900
-		// (chaines de langues pas a jour)
901
-		if ($args) {
902
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
903
-		}
904
-	}
905
-
906
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
907
-		return "<span class=debug-traduction-erreur>$text</span>";
908
-	} else {
909
-		return $text;
910
-	}
863
+    $f = $text;
864
+    $defaut_options = array(
865
+        'class' => null,
866
+        'sanitize' => true,
867
+    );
868
+    // support de l'ancien argument $class
869
+    if ($options and is_string($options)) {
870
+        $options = array('class' => $options);
871
+    }
872
+    if (is_array($options)) {
873
+        $options += $defaut_options;
874
+    } else {
875
+        $options = $defaut_options;
876
+    }
877
+
878
+    if (is_array($args) and count($args)) {
879
+        if (!function_exists('interdire_scripts')) {
880
+            include_spip('inc/texte');
881
+        }
882
+        if (!function_exists('echapper_html_suspect')) {
883
+            include_spip('inc/texte_mini');
884
+        }
885
+        foreach ($args as $name => $value) {
886
+            if (strpos($text, "@$name@") !== false) {
887
+                if ($options['sanitize']) {
888
+                    $value = echapper_html_suspect($value);
889
+                    $value = interdire_scripts($value, -1);
890
+                }
891
+                if (!empty($options['class'])) {
892
+                    $value = "<span class='".$options['class']."'>$value</span>";
893
+                }
894
+                $text = str_replace("@$name@", $value, $text);
895
+                unset($args[$name]);
896
+            }
897
+        }
898
+        // Si des variables n'ont pas ete inserees, le signaler
899
+        // (chaines de langues pas a jour)
900
+        if ($args) {
901
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
902
+        }
903
+    }
904
+
905
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
906
+        return "<span class=debug-traduction-erreur>$text</span>";
907
+    } else {
908
+        return $text;
909
+    }
911 910
 }
912 911
 
913 912
 
@@ -921,13 +920,13 @@  discard block
 block discarded – undo
921 920
  * @return string
922 921
  */
923 922
 function joli_repertoire($rep) {
924
-	$a = substr($rep, 0, 1);
925
-	if ($a <> '.' and $a <> '/') {
926
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
927
-	}
928
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
923
+    $a = substr($rep, 0, 1);
924
+    if ($a <> '.' and $a <> '/') {
925
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
926
+    }
927
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
929 928
 
930
-	return $rep;
929
+    return $rep;
931 930
 }
932 931
 
933 932
 
@@ -952,33 +951,33 @@  discard block
 block discarded – undo
952 951
  * @return float|int|string|void
953 952
  */
954 953
 function spip_timer($t = 'rien', $raw = false) {
955
-	static $time;
956
-	$a = time();
957
-	$b = microtime();
958
-	// microtime peut contenir les microsecondes et le temps
959
-	$b = explode(' ', $b);
960
-	if (count($b) == 2) {
961
-		$a = end($b);
962
-	} // plus precis !
963
-	$b = reset($b);
964
-	if (!isset($time[$t])) {
965
-		$time[$t] = $a + $b;
966
-	} else {
967
-		$p = ($a + $b - $time[$t]) * 1000;
968
-		unset($time[$t]);
954
+    static $time;
955
+    $a = time();
956
+    $b = microtime();
957
+    // microtime peut contenir les microsecondes et le temps
958
+    $b = explode(' ', $b);
959
+    if (count($b) == 2) {
960
+        $a = end($b);
961
+    } // plus precis !
962
+    $b = reset($b);
963
+    if (!isset($time[$t])) {
964
+        $time[$t] = $a + $b;
965
+    } else {
966
+        $p = ($a + $b - $time[$t]) * 1000;
967
+        unset($time[$t]);
969 968
 #			echo "'$p'";exit;
970
-		if ($raw) {
971
-			return $p;
972
-		}
973
-		if ($p < 1000) {
974
-			$s = '';
975
-		} else {
976
-			$s = sprintf("%d ", $x = floor($p / 1000));
977
-			$p -= ($x * 1000);
978
-		}
969
+        if ($raw) {
970
+            return $p;
971
+        }
972
+        if ($p < 1000) {
973
+            $s = '';
974
+        } else {
975
+            $s = sprintf("%d ", $x = floor($p / 1000));
976
+            $p -= ($x * 1000);
977
+        }
979 978
 
980
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
981
-	}
979
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
980
+    }
982 981
 }
983 982
 
984 983
 
@@ -986,21 +985,21 @@  discard block
 block discarded – undo
986 985
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
987 986
 // https://code.spip.net/@spip_touch
988 987
 function spip_touch($fichier, $duree = 0, $touch = true) {
989
-	if ($duree) {
990
-		clearstatcache();
991
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
992
-			return false;
993
-		}
994
-	}
995
-	if ($touch !== false) {
996
-		if (!@touch($fichier)) {
997
-			spip_unlink($fichier);
998
-			@touch($fichier);
999
-		};
1000
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1001
-	}
988
+    if ($duree) {
989
+        clearstatcache();
990
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
991
+            return false;
992
+        }
993
+    }
994
+    if ($touch !== false) {
995
+        if (!@touch($fichier)) {
996
+            spip_unlink($fichier);
997
+            @touch($fichier);
998
+        };
999
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1000
+    }
1002 1001
 
1003
-	return true;
1002
+    return true;
1004 1003
 }
1005 1004
 
1006 1005
 
@@ -1012,11 +1011,11 @@  discard block
 block discarded – undo
1012 1011
  * @uses cron()
1013 1012
  **/
1014 1013
 function action_cron() {
1015
-	include_spip('inc/headers');
1016
-	http_status(204); // No Content
1017
-	header("Connection: close");
1018
-	define('_DIRECT_CRON_FORCE', true);
1019
-	cron();
1014
+    include_spip('inc/headers');
1015
+    http_status(204); // No Content
1016
+    header("Connection: close");
1017
+    define('_DIRECT_CRON_FORCE', true);
1018
+    cron();
1020 1019
 }
1021 1020
 
1022 1021
 /**
@@ -1032,26 +1031,26 @@  discard block
 block discarded – undo
1032 1031
  *     True si la tache a pu être effectuée
1033 1032
  */
1034 1033
 function cron($taches = array(), $taches_old = array()) {
1035
-	// si pas en mode cron force, laisser tomber.
1036
-	if (!defined('_DIRECT_CRON_FORCE')) {
1037
-		return false;
1038
-	}
1039
-	if (!is_array($taches)) {
1040
-		$taches = $taches_old;
1041
-	} // compat anciens appels
1042
-	// si taches a inserer en base et base inaccessible, laisser tomber
1043
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1044
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1045
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1046
-	if ($taches and count($taches) and !spip_connect()) {
1047
-		return false;
1048
-	}
1049
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1050
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1051
-		return $genie($taches);
1052
-	}
1053
-
1054
-	return false;
1034
+    // si pas en mode cron force, laisser tomber.
1035
+    if (!defined('_DIRECT_CRON_FORCE')) {
1036
+        return false;
1037
+    }
1038
+    if (!is_array($taches)) {
1039
+        $taches = $taches_old;
1040
+    } // compat anciens appels
1041
+    // si taches a inserer en base et base inaccessible, laisser tomber
1042
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1043
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1044
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1045
+    if ($taches and count($taches) and !spip_connect()) {
1046
+        return false;
1047
+    }
1048
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1049
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1050
+        return $genie($taches);
1051
+    }
1052
+
1053
+    return false;
1055 1054
 }
1056 1055
 
1057 1056
 /**
@@ -1083,17 +1082,17 @@  discard block
 block discarded – undo
1083 1082
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1084 1083
  */
1085 1084
 function job_queue_add(
1086
-	$function,
1087
-	$description,
1088
-	$arguments = array(),
1089
-	$file = '',
1090
-	$no_duplicate = false,
1091
-	$time = 0,
1092
-	$priority = 0
1085
+    $function,
1086
+    $description,
1087
+    $arguments = array(),
1088
+    $file = '',
1089
+    $no_duplicate = false,
1090
+    $time = 0,
1091
+    $priority = 0
1093 1092
 ) {
1094
-	include_spip('inc/queue');
1093
+    include_spip('inc/queue');
1095 1094
 
1096
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1095
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1097 1096
 }
1098 1097
 
1099 1098
 /**
@@ -1104,9 +1103,9 @@  discard block
 block discarded – undo
1104 1103
  * @return bool
1105 1104
  */
1106 1105
 function job_queue_remove($id_job) {
1107
-	include_spip('inc/queue');
1106
+    include_spip('inc/queue');
1108 1107
 
1109
-	return queue_remove_job($id_job);
1108
+    return queue_remove_job($id_job);
1110 1109
 }
1111 1110
 
1112 1111
 /**
@@ -1119,9 +1118,9 @@  discard block
 block discarded – undo
1119 1118
  *     or an array of simple array to link multiples objet in one time
1120 1119
  */
1121 1120
 function job_queue_link($id_job, $objets) {
1122
-	include_spip('inc/queue');
1121
+    include_spip('inc/queue');
1123 1122
 
1124
-	return queue_link_job($id_job, $objets);
1123
+    return queue_link_job($id_job, $objets);
1125 1124
 }
1126 1125
 
1127 1126
 
@@ -1141,36 +1140,36 @@  discard block
 block discarded – undo
1141 1140
  *  - `null` si la queue n'est pas encore initialisée
1142 1141
  */
1143 1142
 function queue_sleep_time_to_next_job($force = null) {
1144
-	static $queue_next_job_time = -1;
1145
-	if ($force === true) {
1146
-		$queue_next_job_time = -1;
1147
-	} elseif ($force) {
1148
-		$queue_next_job_time = $force;
1149
-	}
1150
-
1151
-	if ($queue_next_job_time == -1) {
1152
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1153
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1154
-		}
1155
-		// utiliser un cache memoire si dispo
1156
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1157
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1158
-		} else {
1159
-			$queue_next_job_time = null;
1160
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1161
-				$queue_next_job_time = intval($contenu);
1162
-			}
1163
-		}
1164
-	}
1165
-
1166
-	if (is_null($queue_next_job_time)) {
1167
-		return null;
1168
-	}
1169
-	if (!$_SERVER['REQUEST_TIME']) {
1170
-		$_SERVER['REQUEST_TIME'] = time();
1171
-	}
1172
-
1173
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1143
+    static $queue_next_job_time = -1;
1144
+    if ($force === true) {
1145
+        $queue_next_job_time = -1;
1146
+    } elseif ($force) {
1147
+        $queue_next_job_time = $force;
1148
+    }
1149
+
1150
+    if ($queue_next_job_time == -1) {
1151
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1152
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1153
+        }
1154
+        // utiliser un cache memoire si dispo
1155
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1156
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1157
+        } else {
1158
+            $queue_next_job_time = null;
1159
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1160
+                $queue_next_job_time = intval($contenu);
1161
+            }
1162
+        }
1163
+    }
1164
+
1165
+    if (is_null($queue_next_job_time)) {
1166
+        return null;
1167
+    }
1168
+    if (!$_SERVER['REQUEST_TIME']) {
1169
+        $_SERVER['REQUEST_TIME'] = time();
1170
+    }
1171
+
1172
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1174 1173
 }
1175 1174
 
1176 1175
 
@@ -1182,9 +1181,9 @@  discard block
 block discarded – undo
1182 1181
  * @return string
1183 1182
  */
1184 1183
 function quote_amp($u) {
1185
-	return preg_replace(
1186
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1187
-		"&amp;", $u);
1184
+    return preg_replace(
1185
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1186
+        "&amp;", $u);
1188 1187
 }
1189 1188
 
1190 1189
 
@@ -1207,27 +1206,27 @@  discard block
 block discarded – undo
1207 1206
  *     Balise HTML `<script>` et son contenu
1208 1207
  **/
1209 1208
 function http_script($script, $src = '', $noscript = '') {
1210
-	static $done = array();
1209
+    static $done = array();
1211 1210
 
1212
-	if ($src && !isset($done[$src])) {
1213
-		$done[$src] = true;
1214
-		$src = find_in_path($src, _JAVASCRIPT);
1215
-		$src = " src='$src'";
1216
-	} else {
1217
-		$src = '';
1218
-	}
1219
-	if ($script) {
1220
-		$script = ("/*<![CDATA[*/\n" .
1221
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1222
-			"/*]]>*/");
1223
-	}
1224
-	if ($noscript) {
1225
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1226
-	}
1211
+    if ($src && !isset($done[$src])) {
1212
+        $done[$src] = true;
1213
+        $src = find_in_path($src, _JAVASCRIPT);
1214
+        $src = " src='$src'";
1215
+    } else {
1216
+        $src = '';
1217
+    }
1218
+    if ($script) {
1219
+        $script = ("/*<![CDATA[*/\n" .
1220
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1221
+            "/*]]>*/");
1222
+    }
1223
+    if ($noscript) {
1224
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1225
+    }
1227 1226
 
1228
-	return ($src or $script or $noscript)
1229
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1230
-		: '';
1227
+    return ($src or $script or $noscript)
1228
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1229
+        : '';
1231 1230
 }
1232 1231
 
1233 1232
 
@@ -1262,7 +1261,7 @@  discard block
 block discarded – undo
1262 1261
  *     Texte échappé
1263 1262
  **/
1264 1263
 function texte_script($texte) {
1265
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1264
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1266 1265
 }
1267 1266
 
1268 1267
 
@@ -1299,69 +1298,69 @@  discard block
 block discarded – undo
1299 1298
  *     Liste des chemins, par ordre de priorité.
1300 1299
  **/
1301 1300
 function _chemin($dir_path = null) {
1302
-	static $path_base = null;
1303
-	static $path_full = null;
1304
-	if ($path_base == null) {
1305
-		// Chemin standard depuis l'espace public
1306
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1307
-			_DIR_RACINE . ':' .
1308
-			_DIR_RACINE . 'squelettes-dist/:' .
1309
-			_DIR_RACINE . 'prive/:' .
1310
-			_DIR_RESTREINT;
1311
-		// Ajouter squelettes/
1312
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1313
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1314
-		}
1315
-		foreach (explode(':', $path) as $dir) {
1316
-			if (strlen($dir) and substr($dir, -1) != '/') {
1317
-				$dir .= "/";
1318
-			}
1319
-			$path_base[] = $dir;
1320
-		}
1321
-		$path_full = $path_base;
1322
-		// Et le(s) dossier(s) des squelettes nommes
1323
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1324
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1325
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1326
-			}
1327
-		}
1328
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1329
-	}
1330
-	if ($dir_path === null) {
1331
-		return $path_full;
1332
-	}
1333
-
1334
-	if (strlen($dir_path)) {
1335
-		$tete = "";
1336
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1337
-			$tete = array_shift($path_base);
1338
-		}
1339
-		$dirs = array_reverse(explode(':', $dir_path));
1340
-		foreach ($dirs as $dir_path) {
1341
-			#if ($dir_path{0}!='/')
1342
-			#	$dir_path = $dir_path;
1343
-			if (substr($dir_path, -1) != '/') {
1344
-				$dir_path .= "/";
1345
-			}
1346
-			if (!in_array($dir_path, $path_base)) {
1347
-				array_unshift($path_base, $dir_path);
1348
-			}
1349
-		}
1350
-		if (strlen($tete)) {
1351
-			array_unshift($path_base, $tete);
1352
-		}
1353
-	}
1354
-	$path_full = $path_base;
1355
-	// Et le(s) dossier(s) des squelettes nommes
1356
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1357
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1358
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1359
-		}
1360
-	}
1361
-
1362
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1363
-
1364
-	return $path_full;
1301
+    static $path_base = null;
1302
+    static $path_full = null;
1303
+    if ($path_base == null) {
1304
+        // Chemin standard depuis l'espace public
1305
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1306
+            _DIR_RACINE . ':' .
1307
+            _DIR_RACINE . 'squelettes-dist/:' .
1308
+            _DIR_RACINE . 'prive/:' .
1309
+            _DIR_RESTREINT;
1310
+        // Ajouter squelettes/
1311
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1312
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1313
+        }
1314
+        foreach (explode(':', $path) as $dir) {
1315
+            if (strlen($dir) and substr($dir, -1) != '/') {
1316
+                $dir .= "/";
1317
+            }
1318
+            $path_base[] = $dir;
1319
+        }
1320
+        $path_full = $path_base;
1321
+        // Et le(s) dossier(s) des squelettes nommes
1322
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1323
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1324
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1325
+            }
1326
+        }
1327
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1328
+    }
1329
+    if ($dir_path === null) {
1330
+        return $path_full;
1331
+    }
1332
+
1333
+    if (strlen($dir_path)) {
1334
+        $tete = "";
1335
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1336
+            $tete = array_shift($path_base);
1337
+        }
1338
+        $dirs = array_reverse(explode(':', $dir_path));
1339
+        foreach ($dirs as $dir_path) {
1340
+            #if ($dir_path{0}!='/')
1341
+            #	$dir_path = $dir_path;
1342
+            if (substr($dir_path, -1) != '/') {
1343
+                $dir_path .= "/";
1344
+            }
1345
+            if (!in_array($dir_path, $path_base)) {
1346
+                array_unshift($path_base, $dir_path);
1347
+            }
1348
+        }
1349
+        if (strlen($tete)) {
1350
+            array_unshift($path_base, $tete);
1351
+        }
1352
+    }
1353
+    $path_full = $path_base;
1354
+    // Et le(s) dossier(s) des squelettes nommes
1355
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1356
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1357
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1358
+        }
1359
+    }
1360
+
1361
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1362
+
1363
+    return $path_full;
1365 1364
 }
1366 1365
 
1367 1366
 /**
@@ -1374,76 +1373,76 @@  discard block
 block discarded – undo
1374 1373
  * @return array Liste de chemins
1375 1374
  **/
1376 1375
 function creer_chemin() {
1377
-	$path_a = _chemin();
1378
-	static $c = '';
1376
+    $path_a = _chemin();
1377
+    static $c = '';
1379 1378
 
1380
-	// on calcule le chemin si le dossier skel a change
1381
-	if ($c != $GLOBALS['dossier_squelettes']) {
1382
-		// assurer le non plantage lors de la montee de version :
1383
-		$c = $GLOBALS['dossier_squelettes'];
1384
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1385
-	}
1379
+    // on calcule le chemin si le dossier skel a change
1380
+    if ($c != $GLOBALS['dossier_squelettes']) {
1381
+        // assurer le non plantage lors de la montee de version :
1382
+        $c = $GLOBALS['dossier_squelettes'];
1383
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1384
+    }
1386 1385
 
1387
-	return $path_a;
1386
+    return $path_a;
1388 1387
 }
1389 1388
 
1390 1389
 
1391 1390
 function lister_themes_prives() {
1392
-	static $themes = null;
1393
-	if (is_null($themes)) {
1394
-		// si pas encore definie
1395
-		if (!defined('_SPIP_THEME_PRIVE')) {
1396
-			define('_SPIP_THEME_PRIVE', 'spip');
1397
-		}
1398
-		$themes = array(_SPIP_THEME_PRIVE);
1399
-		// lors d'une installation neuve, prefs n'est pas definie.
1400
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1401
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1402
-		} else {
1403
-			$prefs = array();
1404
-		}
1405
-		if (is_string($prefs)) {
1406
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1407
-		}
1408
-		if (
1409
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1410
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1411
-			and $theme != _SPIP_THEME_PRIVE
1412
-		) {
1413
-			array_unshift($themes, $theme);
1414
-		} // placer le theme choisi en tete
1415
-	}
1416
-
1417
-	return $themes;
1391
+    static $themes = null;
1392
+    if (is_null($themes)) {
1393
+        // si pas encore definie
1394
+        if (!defined('_SPIP_THEME_PRIVE')) {
1395
+            define('_SPIP_THEME_PRIVE', 'spip');
1396
+        }
1397
+        $themes = array(_SPIP_THEME_PRIVE);
1398
+        // lors d'une installation neuve, prefs n'est pas definie.
1399
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1400
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1401
+        } else {
1402
+            $prefs = array();
1403
+        }
1404
+        if (is_string($prefs)) {
1405
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1406
+        }
1407
+        if (
1408
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1409
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1410
+            and $theme != _SPIP_THEME_PRIVE
1411
+        ) {
1412
+            array_unshift($themes, $theme);
1413
+        } // placer le theme choisi en tete
1414
+    }
1415
+
1416
+    return $themes;
1418 1417
 }
1419 1418
 
1420 1419
 function find_in_theme($file, $subdir = '', $include = false) {
1421
-	static $themefiles = array();
1422
-	if (isset($themefiles["$subdir$file"])) {
1423
-		return $themefiles["$subdir$file"];
1424
-	}
1425
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1426
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1427
-	if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1428
-	  and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1429
-		and $f = find_in_theme("$file_svg_generique")) {
1430
-		if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1431
-			return $themefiles["$subdir$file"] = $fsize;
1432
-		}
1433
-		else {
1434
-			return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1435
-		}
1436
-	}
1437
-
1438
-	$themes = lister_themes_prives();
1439
-	foreach ($themes as $theme) {
1440
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1441
-			return $themefiles["$subdir$file"] = $f;
1442
-		}
1443
-	}
1444
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1445
-
1446
-	return $themefiles["$subdir$file"] = "";
1420
+    static $themefiles = array();
1421
+    if (isset($themefiles["$subdir$file"])) {
1422
+        return $themefiles["$subdir$file"];
1423
+    }
1424
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1425
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1426
+    if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1427
+      and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg"
1428
+        and $f = find_in_theme("$file_svg_generique")) {
1429
+        if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) {
1430
+            return $themefiles["$subdir$file"] = $fsize;
1431
+        }
1432
+        else {
1433
+            return $themefiles["$subdir$file"] = "$f?".$m[1]."px";
1434
+        }
1435
+    }
1436
+
1437
+    $themes = lister_themes_prives();
1438
+    foreach ($themes as $theme) {
1439
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1440
+            return $themefiles["$subdir$file"] = $f;
1441
+        }
1442
+    }
1443
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1444
+
1445
+    return $themefiles["$subdir$file"] = "";
1447 1446
 }
1448 1447
 
1449 1448
 
@@ -1467,31 +1466,31 @@  discard block
 block discarded – undo
1467 1466
  *     sinon chaîne vide.
1468 1467
  **/
1469 1468
 function chemin_image($icone) {
1470
-	static $icone_renommer;
1471
-	if ($p = strpos($icone, '?')) {
1472
-		$icone = substr($icone,0, $p);
1473
-	}
1474
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1475
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1476
-		return $icone;
1477
-	}
1478
-
1479
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1480
-	if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1481
-		return $f;
1482
-	}
1483
-	// sinon passer par le module de renommage
1484
-	if (is_null($icone_renommer)) {
1485
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1486
-	}
1487
-	if ($icone_renommer) {
1488
-		list($icone, $fonction) = $icone_renommer($icone, "");
1489
-		if (file_exists($icone)) {
1490
-			return $icone;
1491
-		}
1492
-	}
1493
-
1494
-	return find_in_path($icone, _NOM_IMG_PACK);
1469
+    static $icone_renommer;
1470
+    if ($p = strpos($icone, '?')) {
1471
+        $icone = substr($icone,0, $p);
1472
+    }
1473
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1474
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1475
+        return $icone;
1476
+    }
1477
+
1478
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1479
+    if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1480
+        return $f;
1481
+    }
1482
+    // sinon passer par le module de renommage
1483
+    if (is_null($icone_renommer)) {
1484
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1485
+    }
1486
+    if ($icone_renommer) {
1487
+        list($icone, $fonction) = $icone_renommer($icone, "");
1488
+        if (file_exists($icone)) {
1489
+            return $icone;
1490
+        }
1491
+    }
1492
+
1493
+    return find_in_path($icone, _NOM_IMG_PACK);
1495 1494
 }
1496 1495
 
1497 1496
 //
@@ -1529,127 +1528,127 @@  discard block
 block discarded – undo
1529 1528
  *     - false : fichier introuvable
1530 1529
  **/
1531 1530
 function find_in_path($file, $dirname = '', $include = false) {
1532
-	static $dirs = array();
1533
-	static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1534
-	static $c = '';
1535
-
1536
-	if (!$file and !strlen($file)) {
1537
-		return false;
1538
-	}
1539
-
1540
-	// on calcule le chemin si le dossier skel a change
1541
-	if ($c != $GLOBALS['dossier_squelettes']) {
1542
-		// assurer le non plantage lors de la montee de version :
1543
-		$c = $GLOBALS['dossier_squelettes'];
1544
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1545
-	}
1546
-
1547
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1548
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1549
-			return false;
1550
-		}
1551
-		if ($include and !isset($inc[$dirname][$file])) {
1552
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1553
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1554
-		}
1555
-
1556
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1557
-	}
1558
-
1559
-	$a = strrpos($file, '/');
1560
-	if ($a !== false) {
1561
-		$dirname .= substr($file, 0, ++$a);
1562
-		$file = substr($file, $a);
1563
-	}
1564
-
1565
-	foreach (creer_chemin() as $dir) {
1566
-		if (!isset($dirs[$a = $dir . $dirname])) {
1567
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1568
-		}
1569
-		if ($dirs[$a]) {
1570
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1571
-				if ($include and !isset($inc[$dirname][$file])) {
1572
-					include_once _ROOT_CWD . $a;
1573
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1574
-				}
1575
-				if (!defined('_SAUVER_CHEMIN')) {
1576
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1577
-					if (is_null($GLOBALS['path_files'])) {
1578
-						return $a;
1579
-					}
1580
-					define('_SAUVER_CHEMIN', true);
1581
-				}
1582
-
1583
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1584
-			}
1585
-		}
1586
-	}
1587
-
1588
-	if ($include) {
1589
-		spip_log("include_spip $dirname$file non trouve");
1590
-		if ($include === 'required') {
1591
-			echo '<pre>',
1592
-			"<strong>Erreur Fatale</strong><br />";
1593
-			if (function_exists('debug_print_backtrace')) {
1594
-				echo debug_print_backtrace();
1595
-			}
1596
-			echo '</pre>';
1597
-			die("Erreur interne: ne peut inclure $dirname$file");
1598
-		}
1599
-	}
1600
-
1601
-	if (!defined('_SAUVER_CHEMIN')) {
1602
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1603
-		if (is_null($GLOBALS['path_files'])) {
1604
-			return false;
1605
-		}
1606
-		define('_SAUVER_CHEMIN', true);
1607
-	}
1608
-
1609
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1531
+    static $dirs = array();
1532
+    static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1533
+    static $c = '';
1534
+
1535
+    if (!$file and !strlen($file)) {
1536
+        return false;
1537
+    }
1538
+
1539
+    // on calcule le chemin si le dossier skel a change
1540
+    if ($c != $GLOBALS['dossier_squelettes']) {
1541
+        // assurer le non plantage lors de la montee de version :
1542
+        $c = $GLOBALS['dossier_squelettes'];
1543
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1544
+    }
1545
+
1546
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1547
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1548
+            return false;
1549
+        }
1550
+        if ($include and !isset($inc[$dirname][$file])) {
1551
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1552
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1553
+        }
1554
+
1555
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1556
+    }
1557
+
1558
+    $a = strrpos($file, '/');
1559
+    if ($a !== false) {
1560
+        $dirname .= substr($file, 0, ++$a);
1561
+        $file = substr($file, $a);
1562
+    }
1563
+
1564
+    foreach (creer_chemin() as $dir) {
1565
+        if (!isset($dirs[$a = $dir . $dirname])) {
1566
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1567
+        }
1568
+        if ($dirs[$a]) {
1569
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1570
+                if ($include and !isset($inc[$dirname][$file])) {
1571
+                    include_once _ROOT_CWD . $a;
1572
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1573
+                }
1574
+                if (!defined('_SAUVER_CHEMIN')) {
1575
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1576
+                    if (is_null($GLOBALS['path_files'])) {
1577
+                        return $a;
1578
+                    }
1579
+                    define('_SAUVER_CHEMIN', true);
1580
+                }
1581
+
1582
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1583
+            }
1584
+        }
1585
+    }
1586
+
1587
+    if ($include) {
1588
+        spip_log("include_spip $dirname$file non trouve");
1589
+        if ($include === 'required') {
1590
+            echo '<pre>',
1591
+            "<strong>Erreur Fatale</strong><br />";
1592
+            if (function_exists('debug_print_backtrace')) {
1593
+                echo debug_print_backtrace();
1594
+            }
1595
+            echo '</pre>';
1596
+            die("Erreur interne: ne peut inclure $dirname$file");
1597
+        }
1598
+    }
1599
+
1600
+    if (!defined('_SAUVER_CHEMIN')) {
1601
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1602
+        if (is_null($GLOBALS['path_files'])) {
1603
+            return false;
1604
+        }
1605
+        define('_SAUVER_CHEMIN', true);
1606
+    }
1607
+
1608
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1610 1609
 }
1611 1610
 
1612 1611
 function clear_path_cache() {
1613
-	$GLOBALS['path_files'] = array();
1614
-	spip_unlink(_CACHE_CHEMIN);
1612
+    $GLOBALS['path_files'] = array();
1613
+    spip_unlink(_CACHE_CHEMIN);
1615 1614
 }
1616 1615
 
1617 1616
 function load_path_cache() {
1618
-	// charger le path des plugins
1619
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1620
-		include_once(_CACHE_PLUGINS_PATH);
1621
-	}
1622
-	$GLOBALS['path_files'] = array();
1623
-	// si le visiteur est admin,
1624
-	// on ne recharge pas le cache pour forcer sa mise a jour
1625
-	if (
1626
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1627
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1628
-		// utiliser le cookie est un pis aller qui marche 'en general'
1629
-		// on blinde par un second test au moment de la lecture de la session
1630
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1631
-		// et en ignorant ce cache en cas de recalcul explicite
1632
-	!_request('var_mode')
1633
-	) {
1634
-		// on essaye de lire directement sans verrou pour aller plus vite
1635
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1636
-			// mais si semble corrompu on relit avec un verrou
1637
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1638
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1639
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1640
-					$GLOBALS['path_files'] = array();
1641
-				}
1642
-			}
1643
-		}
1644
-	}
1617
+    // charger le path des plugins
1618
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1619
+        include_once(_CACHE_PLUGINS_PATH);
1620
+    }
1621
+    $GLOBALS['path_files'] = array();
1622
+    // si le visiteur est admin,
1623
+    // on ne recharge pas le cache pour forcer sa mise a jour
1624
+    if (
1625
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1626
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1627
+        // utiliser le cookie est un pis aller qui marche 'en general'
1628
+        // on blinde par un second test au moment de la lecture de la session
1629
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1630
+        // et en ignorant ce cache en cas de recalcul explicite
1631
+    !_request('var_mode')
1632
+    ) {
1633
+        // on essaye de lire directement sans verrou pour aller plus vite
1634
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1635
+            // mais si semble corrompu on relit avec un verrou
1636
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1637
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1638
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1639
+                    $GLOBALS['path_files'] = array();
1640
+                }
1641
+            }
1642
+        }
1643
+    }
1645 1644
 }
1646 1645
 
1647 1646
 function save_path_cache() {
1648
-	if (defined('_SAUVER_CHEMIN')
1649
-		and _SAUVER_CHEMIN
1650
-	) {
1651
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1652
-	}
1647
+    if (defined('_SAUVER_CHEMIN')
1648
+        and _SAUVER_CHEMIN
1649
+    ) {
1650
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1651
+    }
1653 1652
 }
1654 1653
 
1655 1654
 
@@ -1669,33 +1668,33 @@  discard block
 block discarded – undo
1669 1668
  * @return array
1670 1669
  */
1671 1670
 function find_all_in_path($dir, $pattern, $recurs = false) {
1672
-	$liste_fichiers = array();
1673
-	$maxfiles = 10000;
1674
-
1675
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1676
-	// on a pas encore inclus flock.php
1677
-	if (!function_exists('preg_files')) {
1678
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1679
-	}
1680
-
1681
-	// Parcourir le chemin
1682
-	foreach (creer_chemin() as $d) {
1683
-		$f = $d . $dir;
1684
-		if (@is_dir($f)) {
1685
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1686
-			foreach ($liste as $chemin) {
1687
-				$nom = basename($chemin);
1688
-				// ne prendre que les fichiers pas deja trouves
1689
-				// car find_in_path prend le premier qu'il trouve,
1690
-				// les autres sont donc masques
1691
-				if (!isset($liste_fichiers[$nom])) {
1692
-					$liste_fichiers[$nom] = $chemin;
1693
-				}
1694
-			}
1695
-		}
1696
-	}
1697
-
1698
-	return $liste_fichiers;
1671
+    $liste_fichiers = array();
1672
+    $maxfiles = 10000;
1673
+
1674
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1675
+    // on a pas encore inclus flock.php
1676
+    if (!function_exists('preg_files')) {
1677
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1678
+    }
1679
+
1680
+    // Parcourir le chemin
1681
+    foreach (creer_chemin() as $d) {
1682
+        $f = $d . $dir;
1683
+        if (@is_dir($f)) {
1684
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1685
+            foreach ($liste as $chemin) {
1686
+                $nom = basename($chemin);
1687
+                // ne prendre que les fichiers pas deja trouves
1688
+                // car find_in_path prend le premier qu'il trouve,
1689
+                // les autres sont donc masques
1690
+                if (!isset($liste_fichiers[$nom])) {
1691
+                    $liste_fichiers[$nom] = $chemin;
1692
+                }
1693
+            }
1694
+        }
1695
+    }
1696
+
1697
+    return $liste_fichiers;
1699 1698
 }
1700 1699
 
1701 1700
 /**
@@ -1707,17 +1706,17 @@  discard block
 block discarded – undo
1707 1706
  * @return bool
1708 1707
  */
1709 1708
 function autoriser_sans_cookie($nom, $strict = false) {
1710
-	static $autsanscookie = array('install', 'base_repair');
1709
+    static $autsanscookie = array('install', 'base_repair');
1711 1710
 
1712
-	if (in_array($nom, $autsanscookie)) {
1713
-		if (test_espace_prive()){
1714
-			include_spip('base/connect_sql');
1715
-			if (!$strict or !spip_connect()){
1716
-				return true;
1717
-			}
1718
-		}
1719
-	}
1720
-	return false;
1711
+    if (in_array($nom, $autsanscookie)) {
1712
+        if (test_espace_prive()){
1713
+            include_spip('base/connect_sql');
1714
+            if (!$strict or !spip_connect()){
1715
+                return true;
1716
+            }
1717
+        }
1718
+    }
1719
+    return false;
1721 1720
 }
1722 1721
 
1723 1722
 /**
@@ -1743,99 +1742,99 @@  discard block
 block discarded – undo
1743 1742
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1744 1743
  */
1745 1744
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1746
-	if ($public === null) {
1747
-		$public = !test_espace_prive();
1748
-	}
1749
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1750
-
1751
-	if (!$public) {
1752
-		if (!$entite) {
1753
-			return '';
1754
-		}
1755
-		if (!function_exists('generer_url_ecrire_objet')) {
1756
-			include_spip('inc/urls');
1757
-		}
1758
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1759
-	} else {
1760
-		if ($type === null) {
1761
-			$type = (isset($GLOBALS['type_urls']))
1762
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1763
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1764
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1765
-		}
1766
-
1767
-		$f = charger_fonction($type, 'urls', true);
1768
-		// se rabattre sur les urls page si les urls perso non dispo
1769
-		if (!$f) {
1770
-			$f = charger_fonction('page', 'urls', true);
1771
-		}
1772
-
1773
-		// si $entite='', on veut la fonction de passage URL ==> id
1774
-		// sinon on veut effectuer le passage id ==> URL
1775
-		if (!$entite) {
1776
-			return $f;
1777
-		}
1778
-
1779
-		// mais d'abord il faut tester le cas des urls sur une
1780
-		// base distante
1781
-		if (is_string($public)
1782
-			and $g = charger_fonction('connect', 'urls', true)
1783
-		) {
1784
-			$f = $g;
1785
-		}
1786
-
1787
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1788
-
1789
-	}
1790
-	if ($res) {
1791
-		return $res;
1792
-	}
1793
-	// Sinon c'est un raccourci ou compat SPIP < 2
1794
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1795
-		if (!function_exists($f .= '_dist')) {
1796
-			$f = '';
1797
-		}
1798
-	}
1799
-	if ($f) {
1800
-		$url = $f($id, $args, $ancre);
1801
-		if (strlen($args)) {
1802
-			$url .= strstr($url, '?')
1803
-				? '&amp;' . $args
1804
-				: '?' . $args;
1805
-		}
1806
-
1807
-		return $url;
1808
-	}
1809
-	// On a ete gentil mais la ....
1810
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1811
-
1812
-	return '';
1745
+    if ($public === null) {
1746
+        $public = !test_espace_prive();
1747
+    }
1748
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1749
+
1750
+    if (!$public) {
1751
+        if (!$entite) {
1752
+            return '';
1753
+        }
1754
+        if (!function_exists('generer_url_ecrire_objet')) {
1755
+            include_spip('inc/urls');
1756
+        }
1757
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1758
+    } else {
1759
+        if ($type === null) {
1760
+            $type = (isset($GLOBALS['type_urls']))
1761
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1762
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1763
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1764
+        }
1765
+
1766
+        $f = charger_fonction($type, 'urls', true);
1767
+        // se rabattre sur les urls page si les urls perso non dispo
1768
+        if (!$f) {
1769
+            $f = charger_fonction('page', 'urls', true);
1770
+        }
1771
+
1772
+        // si $entite='', on veut la fonction de passage URL ==> id
1773
+        // sinon on veut effectuer le passage id ==> URL
1774
+        if (!$entite) {
1775
+            return $f;
1776
+        }
1777
+
1778
+        // mais d'abord il faut tester le cas des urls sur une
1779
+        // base distante
1780
+        if (is_string($public)
1781
+            and $g = charger_fonction('connect', 'urls', true)
1782
+        ) {
1783
+            $f = $g;
1784
+        }
1785
+
1786
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1787
+
1788
+    }
1789
+    if ($res) {
1790
+        return $res;
1791
+    }
1792
+    // Sinon c'est un raccourci ou compat SPIP < 2
1793
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1794
+        if (!function_exists($f .= '_dist')) {
1795
+            $f = '';
1796
+        }
1797
+    }
1798
+    if ($f) {
1799
+        $url = $f($id, $args, $ancre);
1800
+        if (strlen($args)) {
1801
+            $url .= strstr($url, '?')
1802
+                ? '&amp;' . $args
1803
+                : '?' . $args;
1804
+        }
1805
+
1806
+        return $url;
1807
+    }
1808
+    // On a ete gentil mais la ....
1809
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1810
+
1811
+    return '';
1813 1812
 }
1814 1813
 
1815 1814
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1816
-	$exec = objet_info($entite, 'url_edit');
1817
-	$url = generer_url_ecrire($exec, $args);
1818
-	if (intval($id)) {
1819
-		$url = parametre_url($url, id_table_objet($entite), $id);
1820
-	} else {
1821
-		$url = parametre_url($url, 'new', 'oui');
1822
-	}
1823
-	if ($ancre) {
1824
-		$url = ancre_url($url, $ancre);
1825
-	}
1815
+    $exec = objet_info($entite, 'url_edit');
1816
+    $url = generer_url_ecrire($exec, $args);
1817
+    if (intval($id)) {
1818
+        $url = parametre_url($url, id_table_objet($entite), $id);
1819
+    } else {
1820
+        $url = parametre_url($url, 'new', 'oui');
1821
+    }
1822
+    if ($ancre) {
1823
+        $url = ancre_url($url, $ancre);
1824
+    }
1826 1825
 
1827
-	return $url;
1826
+    return $url;
1828 1827
 }
1829 1828
 
1830 1829
 // https://code.spip.net/@urls_connect_dist
1831 1830
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1832
-	include_spip('base/connect_sql');
1833
-	$id_type = id_table_objet($entite, $public);
1831
+    include_spip('base/connect_sql');
1832
+    $id_type = id_table_objet($entite, $public);
1834 1833
 
1835
-	return _DIR_RACINE . get_spip_script('./')
1836
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1837
-	. (!$args ? '' : "&$args")
1838
-	. (!$ancre ? '' : "#$ancre");
1834
+    return _DIR_RACINE . get_spip_script('./')
1835
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1836
+    . (!$args ? '' : "&$args")
1837
+    . (!$ancre ? '' : "#$ancre");
1839 1838
 }
1840 1839
 
1841 1840
 
@@ -1846,32 +1845,32 @@  discard block
 block discarded – undo
1846 1845
  * @return string
1847 1846
  */
1848 1847
 function urlencode_1738($url) {
1849
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1850
-		$uri = '';
1851
-		for ($i = 0; $i < strlen($url); $i++) {
1852
-			if (ord($a = $url[$i]) > 127) {
1853
-				$a = rawurlencode($a);
1854
-			}
1855
-			$uri .= $a;
1856
-		}
1857
-		$url = $uri;
1858
-	}
1848
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1849
+        $uri = '';
1850
+        for ($i = 0; $i < strlen($url); $i++) {
1851
+            if (ord($a = $url[$i]) > 127) {
1852
+                $a = rawurlencode($a);
1853
+            }
1854
+            $uri .= $a;
1855
+        }
1856
+        $url = $uri;
1857
+    }
1859 1858
 
1860
-	return quote_amp($url);
1859
+    return quote_amp($url);
1861 1860
 }
1862 1861
 
1863 1862
 // https://code.spip.net/@generer_url_entite_absolue
1864 1863
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1865
-	if (!$connect) {
1866
-		$connect = true;
1867
-	}
1868
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1869
-	if (!preg_match(',^\w+:,', $h)) {
1870
-		include_spip('inc/filtres_mini');
1871
-		$h = url_absolue($h);
1872
-	}
1864
+    if (!$connect) {
1865
+        $connect = true;
1866
+    }
1867
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1868
+    if (!preg_match(',^\w+:,', $h)) {
1869
+        include_spip('inc/filtres_mini');
1870
+        $h = url_absolue($h);
1871
+    }
1873 1872
 
1874
-	return $h;
1873
+    return $h;
1875 1874
 }
1876 1875
 
1877 1876
 
@@ -1887,11 +1886,11 @@  discard block
 block discarded – undo
1887 1886
  *     true si la valeur est considérée active ; false sinon.
1888 1887
  **/
1889 1888
 function test_valeur_serveur($truc) {
1890
-	if (!$truc) {
1891
-		return false;
1892
-	}
1889
+    if (!$truc) {
1890
+        return false;
1891
+    }
1893 1892
 
1894
-	return (strtolower($truc) !== 'off');
1893
+    return (strtolower($truc) !== 'off');
1895 1894
 }
1896 1895
 
1897 1896
 //
@@ -1919,80 +1918,80 @@  discard block
 block discarded – undo
1919 1918
  */
1920 1919
 function url_de_base($profondeur = null) {
1921 1920
 
1922
-	static $url = array();
1923
-	if (is_array($profondeur)) {
1924
-		return $url = $profondeur;
1925
-	}
1926
-	if ($profondeur === false) {
1927
-		return $url;
1928
-	}
1929
-
1930
-	if (is_null($profondeur)) {
1931
-		$profondeur = $GLOBALS['profondeur_url'];
1932
-	}
1933
-
1934
-	if (isset($url[$profondeur])) {
1935
-		return $url[$profondeur];
1936
-	}
1937
-
1938
-	$http = 'http';
1939
-
1940
-	if (
1941
-		isset($_SERVER["SCRIPT_URI"])
1942
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1943
-	) {
1944
-		$http = 'https';
1945
-	} elseif (
1946
-		isset($_SERVER['HTTPS'])
1947
-		and test_valeur_serveur($_SERVER['HTTPS'])
1948
-	) {
1949
-		$http = 'https';
1950
-	}
1951
-
1952
-	// note : HTTP_HOST contient le :port si necessaire
1953
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1954
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1955
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1956
-		$host = $GLOBALS['meta']['adresse_site'];
1957
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1958
-			$http = $scheme;
1959
-			$host = str_replace("{$scheme}://", '', $host);
1960
-		}
1961
-	}
1962
-	if (isset($_SERVER['SERVER_PORT'])
1963
-		and $port = $_SERVER['SERVER_PORT']
1964
-		and strpos($host, ":") == false
1965
-	) {
1966
-		if (!defined('_PORT_HTTP_STANDARD')) {
1967
-			define('_PORT_HTTP_STANDARD', '80');
1968
-		}
1969
-		if (!defined('_PORT_HTTPS_STANDARD')) {
1970
-			define('_PORT_HTTPS_STANDARD', '443');
1971
-		}
1972
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1973
-			$host .= ":$port";
1974
-		}
1975
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1976
-			$host .= ":$port";
1977
-		}
1978
-	}
1979
-
1980
-	if (!$GLOBALS['REQUEST_URI']) {
1981
-		if (isset($_SERVER['REQUEST_URI'])) {
1982
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1983
-		} else {
1984
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1985
-			if (!empty($_SERVER['QUERY_STRING'])
1986
-				and !strpos($_SERVER['REQUEST_URI'], '?')
1987
-			) {
1988
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1989
-			}
1990
-		}
1991
-	}
1992
-
1993
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1994
-
1995
-	return $url[$profondeur];
1921
+    static $url = array();
1922
+    if (is_array($profondeur)) {
1923
+        return $url = $profondeur;
1924
+    }
1925
+    if ($profondeur === false) {
1926
+        return $url;
1927
+    }
1928
+
1929
+    if (is_null($profondeur)) {
1930
+        $profondeur = $GLOBALS['profondeur_url'];
1931
+    }
1932
+
1933
+    if (isset($url[$profondeur])) {
1934
+        return $url[$profondeur];
1935
+    }
1936
+
1937
+    $http = 'http';
1938
+
1939
+    if (
1940
+        isset($_SERVER["SCRIPT_URI"])
1941
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1942
+    ) {
1943
+        $http = 'https';
1944
+    } elseif (
1945
+        isset($_SERVER['HTTPS'])
1946
+        and test_valeur_serveur($_SERVER['HTTPS'])
1947
+    ) {
1948
+        $http = 'https';
1949
+    }
1950
+
1951
+    // note : HTTP_HOST contient le :port si necessaire
1952
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1953
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1954
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1955
+        $host = $GLOBALS['meta']['adresse_site'];
1956
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1957
+            $http = $scheme;
1958
+            $host = str_replace("{$scheme}://", '', $host);
1959
+        }
1960
+    }
1961
+    if (isset($_SERVER['SERVER_PORT'])
1962
+        and $port = $_SERVER['SERVER_PORT']
1963
+        and strpos($host, ":") == false
1964
+    ) {
1965
+        if (!defined('_PORT_HTTP_STANDARD')) {
1966
+            define('_PORT_HTTP_STANDARD', '80');
1967
+        }
1968
+        if (!defined('_PORT_HTTPS_STANDARD')) {
1969
+            define('_PORT_HTTPS_STANDARD', '443');
1970
+        }
1971
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1972
+            $host .= ":$port";
1973
+        }
1974
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1975
+            $host .= ":$port";
1976
+        }
1977
+    }
1978
+
1979
+    if (!$GLOBALS['REQUEST_URI']) {
1980
+        if (isset($_SERVER['REQUEST_URI'])) {
1981
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1982
+        } else {
1983
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1984
+            if (!empty($_SERVER['QUERY_STRING'])
1985
+                and !strpos($_SERVER['REQUEST_URI'], '?')
1986
+            ) {
1987
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1988
+            }
1989
+        }
1990
+    }
1991
+
1992
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1993
+
1994
+    return $url[$profondeur];
1996 1995
 }
1997 1996
 
1998 1997
 /**
@@ -2005,26 +2004,26 @@  discard block
 block discarded – undo
2005 2004
  * @return string
2006 2005
  */
2007 2006
 function url_de_($http, $host, $request, $prof = 0) {
2008
-	$prof = max($prof, 0);
2007
+    $prof = max($prof, 0);
2009 2008
 
2010
-	$myself = ltrim($request, '/');
2011
-	# supprimer la chaine de GET
2012
-	list($myself) = explode('?', $myself);
2013
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2014
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2015
-	if (strpos($myself,'://') !== false) {
2016
-		$myself = explode('://',$myself);
2017
-		array_shift($myself);
2018
-		$myself = implode('://',$myself);
2019
-		$myself = explode('/',$myself);
2020
-		array_shift($myself);
2021
-		$myself = implode('/',$myself);
2022
-	}
2023
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2009
+    $myself = ltrim($request, '/');
2010
+    # supprimer la chaine de GET
2011
+    list($myself) = explode('?', $myself);
2012
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2013
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2014
+    if (strpos($myself,'://') !== false) {
2015
+        $myself = explode('://',$myself);
2016
+        array_shift($myself);
2017
+        $myself = implode('://',$myself);
2018
+        $myself = explode('/',$myself);
2019
+        array_shift($myself);
2020
+        $myself = implode('/',$myself);
2021
+    }
2022
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2024 2023
 
2025
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2024
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2026 2025
 
2027
-	return $url;
2026
+    return $url;
2028 2027
 }
2029 2028
 
2030 2029
 
@@ -2059,26 +2058,26 @@  discard block
 block discarded – undo
2059 2058
  * @return string URL
2060 2059
  **/
2061 2060
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
2062
-	if (!$rel) {
2063
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2064
-	} else {
2065
-		if (!is_string($rel)) {
2066
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2067
-				('./' . _SPIP_ECRIRE_SCRIPT);
2068
-		}
2069
-	}
2070
-
2071
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2072
-	if ($script and ($script <> 'accueil' or $rel)) {
2073
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2074
-	} elseif ($args) {
2075
-		$args = "?$args";
2076
-	}
2077
-	if ($ancre) {
2078
-		$args .= "#$ancre";
2079
-	}
2080
-
2081
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2061
+    if (!$rel) {
2062
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2063
+    } else {
2064
+        if (!is_string($rel)) {
2065
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2066
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2067
+        }
2068
+    }
2069
+
2070
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2071
+    if ($script and ($script <> 'accueil' or $rel)) {
2072
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2073
+    } elseif ($args) {
2074
+        $args = "?$args";
2075
+    }
2076
+    if ($ancre) {
2077
+        $args .= "#$ancre";
2078
+    }
2079
+
2080
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2082 2081
 }
2083 2082
 
2084 2083
 //
@@ -2100,12 +2099,12 @@  discard block
 block discarded – undo
2100 2099
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2101 2100
  **/
2102 2101
 function get_spip_script($default = '') {
2103
-	# cas define('_SPIP_SCRIPT', '');
2104
-	if (_SPIP_SCRIPT) {
2105
-		return _SPIP_SCRIPT;
2106
-	} else {
2107
-		return $default;
2108
-	}
2102
+    # cas define('_SPIP_SCRIPT', '');
2103
+    if (_SPIP_SCRIPT) {
2104
+        return _SPIP_SCRIPT;
2105
+    } else {
2106
+        return $default;
2107
+    }
2109 2108
 }
2110 2109
 
2111 2110
 /**
@@ -2134,39 +2133,39 @@  discard block
 block discarded – undo
2134 2133
  * @return string URL
2135 2134
  **/
2136 2135
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2137
-	// si le script est une action (spip_pass, spip_inscription),
2138
-	// standardiser vers la nouvelle API
2139
-
2140
-	if (!$action) {
2141
-		$action = get_spip_script();
2142
-	}
2143
-	if ($script) {
2144
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2145
-	}
2146
-
2147
-	if ($args) {
2148
-		if (is_array($args)) {
2149
-			$r = '';
2150
-			foreach ($args as $k => $v) {
2151
-				$r .= '&' . $k . '=' . $v;
2152
-			}
2153
-			$args = substr($r, 1);
2154
-		}
2155
-		$action .=
2156
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2157
-	}
2158
-	if (!$no_entities) {
2159
-		$action = quote_amp($action);
2160
-	}
2161
-
2162
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2163
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2136
+    // si le script est une action (spip_pass, spip_inscription),
2137
+    // standardiser vers la nouvelle API
2138
+
2139
+    if (!$action) {
2140
+        $action = get_spip_script();
2141
+    }
2142
+    if ($script) {
2143
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2144
+    }
2145
+
2146
+    if ($args) {
2147
+        if (is_array($args)) {
2148
+            $r = '';
2149
+            foreach ($args as $k => $v) {
2150
+                $r .= '&' . $k . '=' . $v;
2151
+            }
2152
+            $args = substr($r, 1);
2153
+        }
2154
+        $action .=
2155
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2156
+    }
2157
+    if (!$no_entities) {
2158
+        $action = quote_amp($action);
2159
+    }
2160
+
2161
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2162
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2164 2163
 }
2165 2164
 
2166 2165
 // https://code.spip.net/@generer_url_prive
2167 2166
 function generer_url_prive($script, $args = "", $no_entities = false) {
2168 2167
 
2169
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2168
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2170 2169
 }
2171 2170
 
2172 2171
 // Pour les formulaires en methode POST,
@@ -2191,19 +2190,19 @@  discard block
 block discarded – undo
2191 2190
  **/
2192 2191
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2193 2192
 
2194
-	$script1 = explode('&', $script);
2195
-	$script1 = reset($script1);
2193
+    $script1 = explode('&', $script);
2194
+    $script1 = reset($script1);
2196 2195
 
2197
-	return "<form action='"
2198
-	. ($script ? generer_url_ecrire($script) : '')
2199
-	. "' "
2200
-	. ($atts ? $atts : " method='post'")
2201
-	. "><div>\n"
2202
-	. "<input type='hidden' name='exec' value='$script1' />"
2203
-	. $corps
2204
-	. (!$submit ? '' :
2205
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2206
-	. "</div></form>\n";
2196
+    return "<form action='"
2197
+    . ($script ? generer_url_ecrire($script) : '')
2198
+    . "' "
2199
+    . ($atts ? $atts : " method='post'")
2200
+    . "><div>\n"
2201
+    . "<input type='hidden' name='exec' value='$script1' />"
2202
+    . $corps
2203
+    . (!$submit ? '' :
2204
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2205
+    . "</div></form>\n";
2207 2206
 }
2208 2207
 
2209 2208
 /**
@@ -2220,22 +2219,22 @@  discard block
 block discarded – undo
2220 2219
  * @return string
2221 2220
  */
2222 2221
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2223
-	// si l'on est dans l'espace prive, on garde dans l'url
2224
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2225
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2226
-	$h = (_DIR_RACINE and !$public)
2227
-		? generer_url_ecrire(_request('exec'))
2228
-		: generer_url_public();
2222
+    // si l'on est dans l'espace prive, on garde dans l'url
2223
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2224
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2225
+    $h = (_DIR_RACINE and !$public)
2226
+        ? generer_url_ecrire(_request('exec'))
2227
+        : generer_url_public();
2229 2228
 
2230
-	return "\n<form action='" .
2231
-	$h .
2232
-	"'" .
2233
-	$atts .
2234
-	">\n" .
2235
-	"<div>" .
2236
-	"\n<input type='hidden' name='action' value='$script' />" .
2237
-	$corps .
2238
-	"</div></form>";
2229
+    return "\n<form action='" .
2230
+    $h .
2231
+    "'" .
2232
+    $atts .
2233
+    ">\n" .
2234
+    "<div>" .
2235
+    "\n<input type='hidden' name='action' value='$script' />" .
2236
+    $corps .
2237
+    "</div></form>";
2239 2238
 }
2240 2239
 
2241 2240
 /**
@@ -2254,22 +2253,22 @@  discard block
 block discarded – undo
2254 2253
  *     URL
2255 2254
  */
2256 2255
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2257
-	// si l'on est dans l'espace prive, on garde dans l'url
2258
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2259
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2260
-	$url = (_DIR_RACINE and !$public)
2261
-		? generer_url_ecrire(_request('exec'))
2262
-		: generer_url_public('', '', false, false);
2263
-	$url = parametre_url($url, 'action', $script);
2264
-	if ($args) {
2265
-		$url .= quote_amp('&' . $args);
2266
-	}
2256
+    // si l'on est dans l'espace prive, on garde dans l'url
2257
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2258
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2259
+    $url = (_DIR_RACINE and !$public)
2260
+        ? generer_url_ecrire(_request('exec'))
2261
+        : generer_url_public('', '', false, false);
2262
+    $url = parametre_url($url, 'action', $script);
2263
+    if ($args) {
2264
+        $url .= quote_amp('&' . $args);
2265
+    }
2267 2266
 
2268
-	if ($no_entities) {
2269
-		$url = str_replace('&amp;', '&', $url);
2270
-	}
2267
+    if ($no_entities) {
2268
+        $url = str_replace('&amp;', '&', $url);
2269
+    }
2271 2270
 
2272
-	return $url;
2271
+    return $url;
2273 2272
 }
2274 2273
 
2275 2274
 
@@ -2282,8 +2281,8 @@  discard block
 block discarded – undo
2282 2281
  * @param string $ta Répertoire temporaire accessible
2283 2282
  */
2284 2283
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2285
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2286
-	spip_initialisation_suite();
2284
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2285
+    spip_initialisation_suite();
2287 2286
 }
2288 2287
 
2289 2288
 /**
@@ -2303,315 +2302,315 @@  discard block
 block discarded – undo
2303 2302
  * @param string $ta Répertoire temporaire accessible
2304 2303
  */
2305 2304
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2306
-	static $too_late = 0;
2307
-	if ($too_late++) {
2308
-		return;
2309
-	}
2310
-
2311
-	// Declaration des repertoires
2312
-
2313
-	// le nom du repertoire plugins/ activables/desactivables
2314
-	if (!defined('_DIR_PLUGINS')) {
2315
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2316
-	}
2317
-
2318
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2319
-	if (!defined('_DIR_PLUGINS_DIST')) {
2320
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2321
-	}
2322
-
2323
-	// le nom du repertoire des librairies
2324
-	if (!defined('_DIR_LIB')) {
2325
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2326
-	}
2327
-
2328
-	if (!defined('_DIR_IMG')) {
2329
-		define('_DIR_IMG', $pa);
2330
-	}
2331
-	if (!defined('_DIR_LOGOS')) {
2332
-		define('_DIR_LOGOS', $pa);
2333
-	}
2334
-	if (!defined('_DIR_IMG_ICONES')) {
2335
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2336
-	}
2337
-
2338
-	if (!defined('_DIR_DUMP')) {
2339
-		define('_DIR_DUMP', $ti . "dump/");
2340
-	}
2341
-	if (!defined('_DIR_SESSIONS')) {
2342
-		define('_DIR_SESSIONS', $ti . "sessions/");
2343
-	}
2344
-	if (!defined('_DIR_TRANSFERT')) {
2345
-		define('_DIR_TRANSFERT', $ti . "upload/");
2346
-	}
2347
-	if (!defined('_DIR_CACHE')) {
2348
-		define('_DIR_CACHE', $ti . "cache/");
2349
-	}
2350
-	if (!defined('_DIR_CACHE_XML')) {
2351
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2352
-	}
2353
-	if (!defined('_DIR_SKELS')) {
2354
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2355
-	}
2356
-	if (!defined('_DIR_AIDE')) {
2357
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2358
-	}
2359
-	if (!defined('_DIR_TMP')) {
2360
-		define('_DIR_TMP', $ti);
2361
-	}
2362
-
2363
-	if (!defined('_DIR_VAR')) {
2364
-		define('_DIR_VAR', $ta);
2365
-	}
2366
-
2367
-	if (!defined('_DIR_ETC')) {
2368
-		define('_DIR_ETC', $pi);
2369
-	}
2370
-	if (!defined('_DIR_CONNECT')) {
2371
-		define('_DIR_CONNECT', $pi);
2372
-	}
2373
-	if (!defined('_DIR_CHMOD')) {
2374
-		define('_DIR_CHMOD', $pi);
2375
-	}
2376
-
2377
-	if (!isset($GLOBALS['test_dirs']))
2378
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2379
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2380
-	{
2381
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2382
-	}
2383
-
2384
-	// Declaration des fichiers
2385
-
2386
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2387
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2388
-	}
2389
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2390
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2391
-	}
2392
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2393
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2394
-	}
2395
-	if (!defined('_CACHE_PIPELINES')) {
2396
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2397
-	}
2398
-	if (!defined('_CACHE_CHEMIN')) {
2399
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2400
-	}
2401
-
2402
-	# attention .php obligatoire pour ecrire_fichier_securise
2403
-	if (!defined('_FILE_META')) {
2404
-		define('_FILE_META', $ti . 'meta_cache.php');
2405
-	}
2406
-	if (!defined('_DIR_LOG')) {
2407
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2408
-	}
2409
-	if (!defined('_FILE_LOG')) {
2410
-		define('_FILE_LOG', 'spip');
2411
-	}
2412
-	if (!defined('_FILE_LOG_SUFFIX')) {
2413
-		define('_FILE_LOG_SUFFIX', '.log');
2414
-	}
2415
-
2416
-	// Le fichier de connexion a la base de donnees
2417
-	// tient compte des anciennes versions (inc_connect...)
2418
-	if (!defined('_FILE_CONNECT_INS')) {
2419
-		define('_FILE_CONNECT_INS', 'connect');
2420
-	}
2421
-	if (!defined('_FILE_CONNECT')) {
2422
-		define('_FILE_CONNECT',
2423
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2424
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2425
-				: false)));
2426
-	}
2427
-
2428
-	// Le fichier de reglages des droits
2429
-	if (!defined('_FILE_CHMOD_INS')) {
2430
-		define('_FILE_CHMOD_INS', 'chmod');
2431
-	}
2432
-	if (!defined('_FILE_CHMOD')) {
2433
-		define('_FILE_CHMOD',
2434
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2435
-			: false));
2436
-	}
2437
-
2438
-	if (!defined('_FILE_LDAP')) {
2439
-		define('_FILE_LDAP', 'ldap.php');
2440
-	}
2441
-
2442
-	if (!defined('_FILE_TMP_SUFFIX')) {
2443
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2444
-	}
2445
-	if (!defined('_FILE_CONNECT_TMP')) {
2446
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2447
-	}
2448
-	if (!defined('_FILE_CHMOD_TMP')) {
2449
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2450
-	}
2451
-
2452
-	// Definition des droits d'acces en ecriture
2453
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2454
-		include_once _FILE_CHMOD;
2455
-	}
2456
-
2457
-	// Se mefier des fichiers mal remplis!
2458
-	if (!defined('_SPIP_CHMOD')) {
2459
-		define('_SPIP_CHMOD', 0777);
2460
-	}
2461
-
2462
-	if (!defined('_DEFAULT_CHARSET')) {
2463
-		/** Le charset par défaut lors de l'installation */
2464
-		define('_DEFAULT_CHARSET', 'utf-8');
2465
-	}
2466
-	if (!defined('_ROOT_PLUGINS')) {
2467
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2468
-	}
2469
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2470
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2471
-	}
2472
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2473
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2474
-	}
2475
-
2476
-	// La taille des Log
2477
-	if (!defined('_MAX_LOG')) {
2478
-		define('_MAX_LOG', 100);
2479
-	}
2480
-
2481
-	// Sommes-nous dans l'empire du Mal ?
2482
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2483
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2484
-		if (!defined('_OS_SERVEUR')) {
2485
-			define('_OS_SERVEUR', 'windows');
2486
-		}
2487
-		if (!defined('_SPIP_LOCK_MODE')) {
2488
-			define('_SPIP_LOCK_MODE', 1);
2489
-		} // utiliser le flock php
2490
-	} else {
2491
-		if (!defined('_OS_SERVEUR')) {
2492
-			define('_OS_SERVEUR', '');
2493
-		}
2494
-		if (!defined('_SPIP_LOCK_MODE')) {
2495
-			define('_SPIP_LOCK_MODE', 1);
2496
-		} // utiliser le flock php
2497
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2498
-	}
2499
-
2500
-	// Langue par defaut
2501
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2502
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2503
-	}
2504
-
2505
-	//
2506
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2507
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2508
-	// pour le rendre surchargeable, on va provoquer un reecriture
2509
-	// systematique du noyau ou une baisse de perfs => a etudier)
2510
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2511
-
2512
-	// charger tout de suite le path et son cache
2513
-	load_path_cache();
2514
-
2515
-	// *********** traiter les variables ************
2516
-
2517
-	//
2518
-	// Securite
2519
-	//
2520
-
2521
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2522
-	if (isset($_REQUEST['GLOBALS'])) {
2523
-		die();
2524
-	}
2525
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2526
-	spip_desinfecte($_GET);
2527
-	spip_desinfecte($_POST);
2528
-	spip_desinfecte($_COOKIE);
2529
-	spip_desinfecte($_REQUEST);
2530
-
2531
-	// appliquer le cookie_prefix
2532
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2533
-		include_spip('inc/cookie');
2534
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2535
-	}
2536
-
2537
-	//
2538
-	// Capacites php (en fonction de la version)
2539
-	//
2540
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2541
-		&& function_exists("ini_get")
2542
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2543
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2544
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2545
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2546
-		(get_cfg_var('upload_max_filesize') > 0));
2547
-
2548
-
2549
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2550
-	if (isset($_SERVER['REQUEST_URI'])) {
2551
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2552
-	} else {
2553
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2554
-		if (!empty($_SERVER['QUERY_STRING'])
2555
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2556
-		) {
2557
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2558
-		}
2559
-	}
2560
-
2561
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2562
-	if (!defined('_RENOUVELLE_ALEA')) {
2563
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2564
-	}
2565
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2566
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2567
-	}
2568
-
2569
-	// charger les meta si possible et renouveller l'alea au besoin
2570
-	// charge aussi effacer_meta et ecrire_meta
2571
-	$inc_meta = charger_fonction('meta', 'inc');
2572
-	$inc_meta();
2573
-
2574
-	// nombre de repertoires depuis la racine
2575
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2576
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2577
-	// le calcul est faux)
2578
-	if (!_DIR_RESTREINT) {
2579
-		$GLOBALS['profondeur_url'] = 1;
2580
-	} else {
2581
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2582
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2583
-		if (!$uri_ref
2584
-			// si on est appele avec un autre ti, on est sans doute en mutu
2585
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2586
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2587
-			// s'en remettre a l'adresse du site. alea jacta est.
2588
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2589
-		) {
2590
-
2591
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2592
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2593
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2594
-			} else {
2595
-				$uri_ref = "";
2596
-			}
2597
-		}
2598
-		if (!$uri or !$uri_ref) {
2599
-			$GLOBALS['profondeur_url'] = 0;
2600
-		} else {
2601
-			$GLOBALS['profondeur_url'] = max(0,
2602
-				substr_count($uri[0], '/')
2603
-				- substr_count($uri_ref, '/'));
2604
-		}
2605
-	}
2606
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2607
-	if (_FILE_CONNECT) {
2608
-		if (verifier_visiteur() == '0minirezo'
2609
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2610
-			and !isset($_COOKIE['spip_admin'])
2611
-		) {
2612
-			clear_path_cache();
2613
-		}
2614
-	}
2305
+    static $too_late = 0;
2306
+    if ($too_late++) {
2307
+        return;
2308
+    }
2309
+
2310
+    // Declaration des repertoires
2311
+
2312
+    // le nom du repertoire plugins/ activables/desactivables
2313
+    if (!defined('_DIR_PLUGINS')) {
2314
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2315
+    }
2316
+
2317
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2318
+    if (!defined('_DIR_PLUGINS_DIST')) {
2319
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2320
+    }
2321
+
2322
+    // le nom du repertoire des librairies
2323
+    if (!defined('_DIR_LIB')) {
2324
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2325
+    }
2326
+
2327
+    if (!defined('_DIR_IMG')) {
2328
+        define('_DIR_IMG', $pa);
2329
+    }
2330
+    if (!defined('_DIR_LOGOS')) {
2331
+        define('_DIR_LOGOS', $pa);
2332
+    }
2333
+    if (!defined('_DIR_IMG_ICONES')) {
2334
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2335
+    }
2336
+
2337
+    if (!defined('_DIR_DUMP')) {
2338
+        define('_DIR_DUMP', $ti . "dump/");
2339
+    }
2340
+    if (!defined('_DIR_SESSIONS')) {
2341
+        define('_DIR_SESSIONS', $ti . "sessions/");
2342
+    }
2343
+    if (!defined('_DIR_TRANSFERT')) {
2344
+        define('_DIR_TRANSFERT', $ti . "upload/");
2345
+    }
2346
+    if (!defined('_DIR_CACHE')) {
2347
+        define('_DIR_CACHE', $ti . "cache/");
2348
+    }
2349
+    if (!defined('_DIR_CACHE_XML')) {
2350
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2351
+    }
2352
+    if (!defined('_DIR_SKELS')) {
2353
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2354
+    }
2355
+    if (!defined('_DIR_AIDE')) {
2356
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2357
+    }
2358
+    if (!defined('_DIR_TMP')) {
2359
+        define('_DIR_TMP', $ti);
2360
+    }
2361
+
2362
+    if (!defined('_DIR_VAR')) {
2363
+        define('_DIR_VAR', $ta);
2364
+    }
2365
+
2366
+    if (!defined('_DIR_ETC')) {
2367
+        define('_DIR_ETC', $pi);
2368
+    }
2369
+    if (!defined('_DIR_CONNECT')) {
2370
+        define('_DIR_CONNECT', $pi);
2371
+    }
2372
+    if (!defined('_DIR_CHMOD')) {
2373
+        define('_DIR_CHMOD', $pi);
2374
+    }
2375
+
2376
+    if (!isset($GLOBALS['test_dirs']))
2377
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2378
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2379
+    {
2380
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2381
+    }
2382
+
2383
+    // Declaration des fichiers
2384
+
2385
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2386
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2387
+    }
2388
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2389
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2390
+    }
2391
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2392
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2393
+    }
2394
+    if (!defined('_CACHE_PIPELINES')) {
2395
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2396
+    }
2397
+    if (!defined('_CACHE_CHEMIN')) {
2398
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2399
+    }
2400
+
2401
+    # attention .php obligatoire pour ecrire_fichier_securise
2402
+    if (!defined('_FILE_META')) {
2403
+        define('_FILE_META', $ti . 'meta_cache.php');
2404
+    }
2405
+    if (!defined('_DIR_LOG')) {
2406
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2407
+    }
2408
+    if (!defined('_FILE_LOG')) {
2409
+        define('_FILE_LOG', 'spip');
2410
+    }
2411
+    if (!defined('_FILE_LOG_SUFFIX')) {
2412
+        define('_FILE_LOG_SUFFIX', '.log');
2413
+    }
2414
+
2415
+    // Le fichier de connexion a la base de donnees
2416
+    // tient compte des anciennes versions (inc_connect...)
2417
+    if (!defined('_FILE_CONNECT_INS')) {
2418
+        define('_FILE_CONNECT_INS', 'connect');
2419
+    }
2420
+    if (!defined('_FILE_CONNECT')) {
2421
+        define('_FILE_CONNECT',
2422
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2423
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2424
+                : false)));
2425
+    }
2426
+
2427
+    // Le fichier de reglages des droits
2428
+    if (!defined('_FILE_CHMOD_INS')) {
2429
+        define('_FILE_CHMOD_INS', 'chmod');
2430
+    }
2431
+    if (!defined('_FILE_CHMOD')) {
2432
+        define('_FILE_CHMOD',
2433
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2434
+            : false));
2435
+    }
2436
+
2437
+    if (!defined('_FILE_LDAP')) {
2438
+        define('_FILE_LDAP', 'ldap.php');
2439
+    }
2440
+
2441
+    if (!defined('_FILE_TMP_SUFFIX')) {
2442
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2443
+    }
2444
+    if (!defined('_FILE_CONNECT_TMP')) {
2445
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2446
+    }
2447
+    if (!defined('_FILE_CHMOD_TMP')) {
2448
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2449
+    }
2450
+
2451
+    // Definition des droits d'acces en ecriture
2452
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2453
+        include_once _FILE_CHMOD;
2454
+    }
2455
+
2456
+    // Se mefier des fichiers mal remplis!
2457
+    if (!defined('_SPIP_CHMOD')) {
2458
+        define('_SPIP_CHMOD', 0777);
2459
+    }
2460
+
2461
+    if (!defined('_DEFAULT_CHARSET')) {
2462
+        /** Le charset par défaut lors de l'installation */
2463
+        define('_DEFAULT_CHARSET', 'utf-8');
2464
+    }
2465
+    if (!defined('_ROOT_PLUGINS')) {
2466
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2467
+    }
2468
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2469
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2470
+    }
2471
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2472
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2473
+    }
2474
+
2475
+    // La taille des Log
2476
+    if (!defined('_MAX_LOG')) {
2477
+        define('_MAX_LOG', 100);
2478
+    }
2479
+
2480
+    // Sommes-nous dans l'empire du Mal ?
2481
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2482
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2483
+        if (!defined('_OS_SERVEUR')) {
2484
+            define('_OS_SERVEUR', 'windows');
2485
+        }
2486
+        if (!defined('_SPIP_LOCK_MODE')) {
2487
+            define('_SPIP_LOCK_MODE', 1);
2488
+        } // utiliser le flock php
2489
+    } else {
2490
+        if (!defined('_OS_SERVEUR')) {
2491
+            define('_OS_SERVEUR', '');
2492
+        }
2493
+        if (!defined('_SPIP_LOCK_MODE')) {
2494
+            define('_SPIP_LOCK_MODE', 1);
2495
+        } // utiliser le flock php
2496
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2497
+    }
2498
+
2499
+    // Langue par defaut
2500
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2501
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2502
+    }
2503
+
2504
+    //
2505
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2506
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2507
+    // pour le rendre surchargeable, on va provoquer un reecriture
2508
+    // systematique du noyau ou une baisse de perfs => a etudier)
2509
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2510
+
2511
+    // charger tout de suite le path et son cache
2512
+    load_path_cache();
2513
+
2514
+    // *********** traiter les variables ************
2515
+
2516
+    //
2517
+    // Securite
2518
+    //
2519
+
2520
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2521
+    if (isset($_REQUEST['GLOBALS'])) {
2522
+        die();
2523
+    }
2524
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2525
+    spip_desinfecte($_GET);
2526
+    spip_desinfecte($_POST);
2527
+    spip_desinfecte($_COOKIE);
2528
+    spip_desinfecte($_REQUEST);
2529
+
2530
+    // appliquer le cookie_prefix
2531
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2532
+        include_spip('inc/cookie');
2533
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2534
+    }
2535
+
2536
+    //
2537
+    // Capacites php (en fonction de la version)
2538
+    //
2539
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2540
+        && function_exists("ini_get")
2541
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2542
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2543
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2544
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2545
+        (get_cfg_var('upload_max_filesize') > 0));
2546
+
2547
+
2548
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2549
+    if (isset($_SERVER['REQUEST_URI'])) {
2550
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2551
+    } else {
2552
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2553
+        if (!empty($_SERVER['QUERY_STRING'])
2554
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2555
+        ) {
2556
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2557
+        }
2558
+    }
2559
+
2560
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2561
+    if (!defined('_RENOUVELLE_ALEA')) {
2562
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2563
+    }
2564
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2565
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2566
+    }
2567
+
2568
+    // charger les meta si possible et renouveller l'alea au besoin
2569
+    // charge aussi effacer_meta et ecrire_meta
2570
+    $inc_meta = charger_fonction('meta', 'inc');
2571
+    $inc_meta();
2572
+
2573
+    // nombre de repertoires depuis la racine
2574
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2575
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2576
+    // le calcul est faux)
2577
+    if (!_DIR_RESTREINT) {
2578
+        $GLOBALS['profondeur_url'] = 1;
2579
+    } else {
2580
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2581
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2582
+        if (!$uri_ref
2583
+            // si on est appele avec un autre ti, on est sans doute en mutu
2584
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2585
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2586
+            // s'en remettre a l'adresse du site. alea jacta est.
2587
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2588
+        ) {
2589
+
2590
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2591
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2592
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2593
+            } else {
2594
+                $uri_ref = "";
2595
+            }
2596
+        }
2597
+        if (!$uri or !$uri_ref) {
2598
+            $GLOBALS['profondeur_url'] = 0;
2599
+        } else {
2600
+            $GLOBALS['profondeur_url'] = max(0,
2601
+                substr_count($uri[0], '/')
2602
+                - substr_count($uri_ref, '/'));
2603
+        }
2604
+    }
2605
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2606
+    if (_FILE_CONNECT) {
2607
+        if (verifier_visiteur() == '0minirezo'
2608
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2609
+            and !isset($_COOKIE['spip_admin'])
2610
+        ) {
2611
+            clear_path_cache();
2612
+        }
2613
+    }
2615 2614
 
2616 2615
 }
2617 2616
 
@@ -2621,174 +2620,174 @@  discard block
 block discarded – undo
2621 2620
  *
2622 2621
  */
2623 2622
 function spip_initialisation_suite() {
2624
-	static $too_late = 0;
2625
-	if ($too_late++) {
2626
-		return;
2627
-	}
2628
-
2629
-	// taille mini des login
2630
-	if (!defined('_LOGIN_TROP_COURT')) {
2631
-		define('_LOGIN_TROP_COURT', 4);
2632
-	}
2633
-
2634
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2635
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2636
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2637
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2638
-
2639
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2640
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2641
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2642
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2643
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2644
-
2645
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2646
-		define('_PASS_LONGUEUR_MINI', 6);
2647
-	}
2648
-
2649
-
2650
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2651
-	if (!defined('_IMG_QUALITE')) {
2652
-		define('_IMG_QUALITE', 85);
2653
-	} # valeur par defaut
2654
-	if (!defined('_IMG_GD_QUALITE')) {
2655
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2656
-	} # surcharge pour la lib GD
2657
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2658
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2659
-	} # surcharge pour imagick en ligne de commande
2660
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2661
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2662
-		define('_IMG_IMAGICK_QUALITE', 75);
2663
-	} # surcharge pour imagick en PHP
2664
-
2665
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2666
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2667
-	} // poids en octet
2668
-
2669
-	// qq chaines standard
2670
-	if (!defined('_ACCESS_FILE_NAME')) {
2671
-		define('_ACCESS_FILE_NAME', '.htaccess');
2672
-	}
2673
-	if (!defined('_AUTH_USER_FILE')) {
2674
-		define('_AUTH_USER_FILE', '.htpasswd');
2675
-	}
2676
-	if (!defined('_SPIP_DUMP')) {
2677
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2678
-	}
2679
-	if (!defined('_CACHE_RUBRIQUES')) {
2680
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2681
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2682
-	}
2683
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2684
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2685
-		define('_CACHE_RUBRIQUES_MAX', 500);
2686
-	}
2687
-
2688
-	if (!defined('_EXTENSION_SQUELETTES')) {
2689
-		define('_EXTENSION_SQUELETTES', 'html');
2690
-	}
2691
-
2692
-	if (!defined('_DOCTYPE_ECRIRE')) {
2693
-		/** Définit le doctype de l’espace privé */
2694
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2695
-	}
2696
-	if (!defined('_DOCTYPE_AIDE')) {
2697
-		/** Définit le doctype de l’aide en ligne */
2698
-		define('_DOCTYPE_AIDE',
2699
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2700
-	}
2701
-
2702
-	if (!defined('_SPIP_SCRIPT')) {
2703
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2704
-		 * le script de l'espace public, alias index.php */
2705
-		define('_SPIP_SCRIPT', 'spip.php');
2706
-	}
2707
-	if (!defined('_SPIP_PAGE')) {
2708
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2709
-		define('_SPIP_PAGE', 'page');
2710
-	}
2711
-
2712
-	// le script de l'espace prive
2713
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2714
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2715
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2716
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2717
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2718
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2719
-		} else {
2720
-			define('_SPIP_ECRIRE_SCRIPT', '');
2721
-		}
2722
-	}
2723
-
2724
-
2725
-	if (!defined('_SPIP_AJAX')) {
2726
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2727
-			? 1
2728
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2729
-	}
2730
-
2731
-	// La requete est-elle en ajax ?
2732
-	if (!defined('_AJAX')) {
2733
-		define('_AJAX',
2734
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2735
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2736
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2737
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2738
-			)
2739
-			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
2740
-		);
2741
-	}
2742
-
2743
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2744
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2745
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2746
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2747
-		define('_IMG_GD_MAX_PIXELS',
2748
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2749
-			? $GLOBALS['meta']['max_taille_vignettes']
2750
-			: 0);
2751
-	}
2752
-
2753
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2754
-		define('_MEMORY_LIMIT_MIN', 16);
2755
-	} // en Mo
2756
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2757
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2758
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2759
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2760
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2761
-			$unit = strtolower(substr($memory, -1));
2762
-			$memory = substr($memory, 0, -1);
2763
-			switch ($unit) {
2764
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2765
-				case 'g':
2766
-					$memory *= 1024;
2767
-				case 'm':
2768
-					$memory *= 1024;
2769
-				case 'k':
2770
-					$memory *= 1024;
2771
-			}
2772
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2773
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2774
-				if (trim(ini_get('memory_limit')) != $m) {
2775
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2776
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2777
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2778
-				}
2779
-			}
2780
-		} else {
2781
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2782
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2783
-			}
2784
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2785
-	}
2786
-	// Protocoles a normaliser dans les chaines de langues
2787
-	if (!defined('_PROTOCOLES_STD')) {
2788
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2789
-	}
2790
-
2791
-	init_var_mode();
2623
+    static $too_late = 0;
2624
+    if ($too_late++) {
2625
+        return;
2626
+    }
2627
+
2628
+    // taille mini des login
2629
+    if (!defined('_LOGIN_TROP_COURT')) {
2630
+        define('_LOGIN_TROP_COURT', 4);
2631
+    }
2632
+
2633
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2634
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2635
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2636
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2637
+
2638
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2639
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2640
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2641
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2642
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2643
+
2644
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2645
+        define('_PASS_LONGUEUR_MINI', 6);
2646
+    }
2647
+
2648
+
2649
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2650
+    if (!defined('_IMG_QUALITE')) {
2651
+        define('_IMG_QUALITE', 85);
2652
+    } # valeur par defaut
2653
+    if (!defined('_IMG_GD_QUALITE')) {
2654
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2655
+    } # surcharge pour la lib GD
2656
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2657
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2658
+    } # surcharge pour imagick en ligne de commande
2659
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2660
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2661
+        define('_IMG_IMAGICK_QUALITE', 75);
2662
+    } # surcharge pour imagick en PHP
2663
+
2664
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2665
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2666
+    } // poids en octet
2667
+
2668
+    // qq chaines standard
2669
+    if (!defined('_ACCESS_FILE_NAME')) {
2670
+        define('_ACCESS_FILE_NAME', '.htaccess');
2671
+    }
2672
+    if (!defined('_AUTH_USER_FILE')) {
2673
+        define('_AUTH_USER_FILE', '.htpasswd');
2674
+    }
2675
+    if (!defined('_SPIP_DUMP')) {
2676
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2677
+    }
2678
+    if (!defined('_CACHE_RUBRIQUES')) {
2679
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2680
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2681
+    }
2682
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2683
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2684
+        define('_CACHE_RUBRIQUES_MAX', 500);
2685
+    }
2686
+
2687
+    if (!defined('_EXTENSION_SQUELETTES')) {
2688
+        define('_EXTENSION_SQUELETTES', 'html');
2689
+    }
2690
+
2691
+    if (!defined('_DOCTYPE_ECRIRE')) {
2692
+        /** Définit le doctype de l’espace privé */
2693
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2694
+    }
2695
+    if (!defined('_DOCTYPE_AIDE')) {
2696
+        /** Définit le doctype de l’aide en ligne */
2697
+        define('_DOCTYPE_AIDE',
2698
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2699
+    }
2700
+
2701
+    if (!defined('_SPIP_SCRIPT')) {
2702
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2703
+         * le script de l'espace public, alias index.php */
2704
+        define('_SPIP_SCRIPT', 'spip.php');
2705
+    }
2706
+    if (!defined('_SPIP_PAGE')) {
2707
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2708
+        define('_SPIP_PAGE', 'page');
2709
+    }
2710
+
2711
+    // le script de l'espace prive
2712
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2713
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2714
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2715
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2716
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2717
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2718
+        } else {
2719
+            define('_SPIP_ECRIRE_SCRIPT', '');
2720
+        }
2721
+    }
2722
+
2723
+
2724
+    if (!defined('_SPIP_AJAX')) {
2725
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2726
+            ? 1
2727
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2728
+    }
2729
+
2730
+    // La requete est-elle en ajax ?
2731
+    if (!defined('_AJAX')) {
2732
+        define('_AJAX',
2733
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2734
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2735
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2736
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2737
+            )
2738
+            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
2739
+        );
2740
+    }
2741
+
2742
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2743
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2744
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2745
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2746
+        define('_IMG_GD_MAX_PIXELS',
2747
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2748
+            ? $GLOBALS['meta']['max_taille_vignettes']
2749
+            : 0);
2750
+    }
2751
+
2752
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2753
+        define('_MEMORY_LIMIT_MIN', 16);
2754
+    } // en Mo
2755
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2756
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2757
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2758
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2759
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2760
+            $unit = strtolower(substr($memory, -1));
2761
+            $memory = substr($memory, 0, -1);
2762
+            switch ($unit) {
2763
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2764
+                case 'g':
2765
+                    $memory *= 1024;
2766
+                case 'm':
2767
+                    $memory *= 1024;
2768
+                case 'k':
2769
+                    $memory *= 1024;
2770
+            }
2771
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2772
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2773
+                if (trim(ini_get('memory_limit')) != $m) {
2774
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2775
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2776
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2777
+                }
2778
+            }
2779
+        } else {
2780
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2781
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2782
+            }
2783
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2784
+    }
2785
+    // Protocoles a normaliser dans les chaines de langues
2786
+    if (!defined('_PROTOCOLES_STD')) {
2787
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2788
+    }
2789
+
2790
+    init_var_mode();
2792 2791
 }
2793 2792
 
2794 2793
 /**
@@ -2822,129 +2821,129 @@  discard block
 block discarded – undo
2822 2821
  * `   var_mode` (calcul ou recalcul).
2823 2822
  */
2824 2823
 function init_var_mode() {
2825
-	static $done = false;
2826
-	if (!$done) {
2827
-
2828
-		if (isset($_GET['var_mode'])) {
2829
-			$var_mode = explode(',', $_GET['var_mode']);
2830
-			// tout le monde peut calcul/recalcul
2831
-			if (!defined('_VAR_MODE')) {
2832
-				if (in_array('recalcul', $var_mode)) {
2833
-					define('_VAR_MODE', 'recalcul');
2834
-				} elseif (in_array('calcul', $var_mode)) {
2835
-					define('_VAR_MODE', 'calcul');
2836
-				}
2837
-			}
2838
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2839
-			if ($var_mode) {
2840
-				include_spip('inc/autoriser');
2841
-				// autoriser preview si preview seulement, et sinon autoriser debug
2842
-				if (autoriser(
2843
-					($_GET['var_mode'] == 'preview')
2844
-						? 'previsualiser'
2845
-						: 'debug'
2846
-				)) {
2847
-					if (in_array('traduction', $var_mode)) {
2848
-						// forcer le calcul pour passer dans traduire
2849
-						if (!defined('_VAR_MODE')) {
2850
-							define('_VAR_MODE', 'calcul');
2851
-						}
2852
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2853
-						if (!defined('_VAR_NOCACHE')) {
2854
-							define('_VAR_NOCACHE', true);
2855
-						}
2856
-						$var_mode = array_diff($var_mode, array('traduction'));
2857
-					}
2858
-					if (in_array('preview', $var_mode)) {
2859
-						// basculer sur les criteres de preview dans les boucles
2860
-						if (!defined('_VAR_PREVIEW')) {
2861
-							define('_VAR_PREVIEW', true);
2862
-						}
2863
-						// forcer le calcul
2864
-						if (!defined('_VAR_MODE')) {
2865
-							define('_VAR_MODE', 'calcul');
2866
-						}
2867
-						// et ne pas enregistrer de cache
2868
-						if (!defined('_VAR_NOCACHE')) {
2869
-							define('_VAR_NOCACHE', true);
2870
-						}
2871
-						$var_mode = array_diff($var_mode, array('preview'));
2872
-					}
2873
-					if (in_array('inclure', $var_mode)) {
2874
-						// forcer le compilo et ignorer les caches existants
2875
-						if (!defined('_VAR_MODE')) {
2876
-							define('_VAR_MODE', 'calcul');
2877
-						}
2878
-						if (!defined('_VAR_INCLURE')) {
2879
-							define('_VAR_INCLURE', true);
2880
-						}
2881
-						// et ne pas enregistrer de cache
2882
-						if (!defined('_VAR_NOCACHE')) {
2883
-							define('_VAR_NOCACHE', true);
2884
-						}
2885
-						$var_mode = array_diff($var_mode, array('inclure'));
2886
-					}
2887
-					if (in_array('urls', $var_mode)) {
2888
-						// forcer le compilo et ignorer les caches existants
2889
-						if (!defined('_VAR_MODE')) {
2890
-							define('_VAR_MODE', 'calcul');
2891
-						}
2892
-						if (!defined('_VAR_URLS')) {
2893
-							define('_VAR_URLS', true);
2894
-						}
2895
-						$var_mode = array_diff($var_mode, array('urls'));
2896
-					}
2897
-					if (in_array('images', $var_mode)) {
2898
-						// forcer le compilo et ignorer les caches existants
2899
-						if (!defined('_VAR_MODE')) {
2900
-							define('_VAR_MODE', 'calcul');
2901
-						}
2902
-						// indiquer qu'on doit recalculer les images
2903
-						if (!defined('_VAR_IMAGES')) {
2904
-							define('_VAR_IMAGES', true);
2905
-						}
2906
-						$var_mode = array_diff($var_mode, array('images'));
2907
-					}
2908
-					if (in_array('debug', $var_mode)) {
2909
-						if (!defined('_VAR_MODE')) {
2910
-							define('_VAR_MODE', 'debug');
2911
-						}
2912
-						// et ne pas enregistrer de cache
2913
-						if (!defined('_VAR_NOCACHE')) {
2914
-							define('_VAR_NOCACHE', true);
2915
-						}
2916
-						$var_mode = array_diff($var_mode, array('debug'));
2917
-					}
2918
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2919
-						define('_VAR_MODE', reset($var_mode));
2920
-					}
2921
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2922
-						spip_log($GLOBALS['visiteur_session']['nom']
2923
-							. " " . _VAR_MODE);
2924
-					}
2925
-				} // pas autorise ?
2926
-				else {
2927
-					// si on n'est pas connecte on se redirige
2928
-					if (!$GLOBALS['visiteur_session']) {
2929
-						include_spip('inc/headers');
2930
-						redirige_par_entete(generer_url_public('login',
2931
-							'url=' . rawurlencode(
2932
-								parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2933
-							), true));
2934
-					}
2935
-					// sinon tant pis
2936
-				}
2937
-			}
2938
-		}
2939
-		if (!defined('_VAR_MODE')) {
2940
-			/**
2941
-			 * Indique le mode de calcul ou d'affichage de la page.
2942
-			 * @see init_var_mode()
2943
-			 */
2944
-			define('_VAR_MODE', false);
2945
-		}
2946
-		$done = true;
2947
-	}
2824
+    static $done = false;
2825
+    if (!$done) {
2826
+
2827
+        if (isset($_GET['var_mode'])) {
2828
+            $var_mode = explode(',', $_GET['var_mode']);
2829
+            // tout le monde peut calcul/recalcul
2830
+            if (!defined('_VAR_MODE')) {
2831
+                if (in_array('recalcul', $var_mode)) {
2832
+                    define('_VAR_MODE', 'recalcul');
2833
+                } elseif (in_array('calcul', $var_mode)) {
2834
+                    define('_VAR_MODE', 'calcul');
2835
+                }
2836
+            }
2837
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2838
+            if ($var_mode) {
2839
+                include_spip('inc/autoriser');
2840
+                // autoriser preview si preview seulement, et sinon autoriser debug
2841
+                if (autoriser(
2842
+                    ($_GET['var_mode'] == 'preview')
2843
+                        ? 'previsualiser'
2844
+                        : 'debug'
2845
+                )) {
2846
+                    if (in_array('traduction', $var_mode)) {
2847
+                        // forcer le calcul pour passer dans traduire
2848
+                        if (!defined('_VAR_MODE')) {
2849
+                            define('_VAR_MODE', 'calcul');
2850
+                        }
2851
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2852
+                        if (!defined('_VAR_NOCACHE')) {
2853
+                            define('_VAR_NOCACHE', true);
2854
+                        }
2855
+                        $var_mode = array_diff($var_mode, array('traduction'));
2856
+                    }
2857
+                    if (in_array('preview', $var_mode)) {
2858
+                        // basculer sur les criteres de preview dans les boucles
2859
+                        if (!defined('_VAR_PREVIEW')) {
2860
+                            define('_VAR_PREVIEW', true);
2861
+                        }
2862
+                        // forcer le calcul
2863
+                        if (!defined('_VAR_MODE')) {
2864
+                            define('_VAR_MODE', 'calcul');
2865
+                        }
2866
+                        // et ne pas enregistrer de cache
2867
+                        if (!defined('_VAR_NOCACHE')) {
2868
+                            define('_VAR_NOCACHE', true);
2869
+                        }
2870
+                        $var_mode = array_diff($var_mode, array('preview'));
2871
+                    }
2872
+                    if (in_array('inclure', $var_mode)) {
2873
+                        // forcer le compilo et ignorer les caches existants
2874
+                        if (!defined('_VAR_MODE')) {
2875
+                            define('_VAR_MODE', 'calcul');
2876
+                        }
2877
+                        if (!defined('_VAR_INCLURE')) {
2878
+                            define('_VAR_INCLURE', true);
2879
+                        }
2880
+                        // et ne pas enregistrer de cache
2881
+                        if (!defined('_VAR_NOCACHE')) {
2882
+                            define('_VAR_NOCACHE', true);
2883
+                        }
2884
+                        $var_mode = array_diff($var_mode, array('inclure'));
2885
+                    }
2886
+                    if (in_array('urls', $var_mode)) {
2887
+                        // forcer le compilo et ignorer les caches existants
2888
+                        if (!defined('_VAR_MODE')) {
2889
+                            define('_VAR_MODE', 'calcul');
2890
+                        }
2891
+                        if (!defined('_VAR_URLS')) {
2892
+                            define('_VAR_URLS', true);
2893
+                        }
2894
+                        $var_mode = array_diff($var_mode, array('urls'));
2895
+                    }
2896
+                    if (in_array('images', $var_mode)) {
2897
+                        // forcer le compilo et ignorer les caches existants
2898
+                        if (!defined('_VAR_MODE')) {
2899
+                            define('_VAR_MODE', 'calcul');
2900
+                        }
2901
+                        // indiquer qu'on doit recalculer les images
2902
+                        if (!defined('_VAR_IMAGES')) {
2903
+                            define('_VAR_IMAGES', true);
2904
+                        }
2905
+                        $var_mode = array_diff($var_mode, array('images'));
2906
+                    }
2907
+                    if (in_array('debug', $var_mode)) {
2908
+                        if (!defined('_VAR_MODE')) {
2909
+                            define('_VAR_MODE', 'debug');
2910
+                        }
2911
+                        // et ne pas enregistrer de cache
2912
+                        if (!defined('_VAR_NOCACHE')) {
2913
+                            define('_VAR_NOCACHE', true);
2914
+                        }
2915
+                        $var_mode = array_diff($var_mode, array('debug'));
2916
+                    }
2917
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2918
+                        define('_VAR_MODE', reset($var_mode));
2919
+                    }
2920
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2921
+                        spip_log($GLOBALS['visiteur_session']['nom']
2922
+                            . " " . _VAR_MODE);
2923
+                    }
2924
+                } // pas autorise ?
2925
+                else {
2926
+                    // si on n'est pas connecte on se redirige
2927
+                    if (!$GLOBALS['visiteur_session']) {
2928
+                        include_spip('inc/headers');
2929
+                        redirige_par_entete(generer_url_public('login',
2930
+                            'url=' . rawurlencode(
2931
+                                parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2932
+                            ), true));
2933
+                    }
2934
+                    // sinon tant pis
2935
+                }
2936
+            }
2937
+        }
2938
+        if (!defined('_VAR_MODE')) {
2939
+            /**
2940
+             * Indique le mode de calcul ou d'affichage de la page.
2941
+             * @see init_var_mode()
2942
+             */
2943
+            define('_VAR_MODE', false);
2944
+        }
2945
+        $done = true;
2946
+    }
2948 2947
 }
2949 2948
 
2950 2949
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2952,85 +2951,85 @@  discard block
 block discarded – undo
2952 2951
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2953 2952
 // https://code.spip.net/@spip_desinfecte
2954 2953
 function spip_desinfecte(&$t, $deep = true) {
2955
-	foreach ($t as $key => $val) {
2956
-		if (is_string($t[$key])) {
2957
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2958
-		} // traiter aussi les "texte_plus" de article_edit
2959
-		else {
2960
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2961
-				spip_desinfecte($t[$key], $deep);
2962
-			}
2963
-		}
2964
-	}
2954
+    foreach ($t as $key => $val) {
2955
+        if (is_string($t[$key])) {
2956
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2957
+        } // traiter aussi les "texte_plus" de article_edit
2958
+        else {
2959
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2960
+                spip_desinfecte($t[$key], $deep);
2961
+            }
2962
+        }
2963
+    }
2965 2964
 }
2966 2965
 
2967 2966
 //  retourne le statut du visiteur s'il s'annonce
2968 2967
 
2969 2968
 // https://code.spip.net/@verifier_visiteur
2970 2969
 function verifier_visiteur() {
2971
-	// Rq: pour que cette fonction marche depuis mes_options
2972
-	// il faut forcer l'init si ce n'est fait
2973
-	// mais on risque de perturber des plugins en initialisant trop tot
2974
-	// certaines constantes
2975
-	@spip_initialisation_core(
2976
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2977
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2978
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2979
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2980
-	);
2981
-
2982
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
2983
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2984
-	// Attention on separe bien session_nom et nom, pour eviter
2985
-	// les melanges entre donnees SQL et variables plus aleatoires
2986
-	$variables_session = array('session_nom', 'session_email');
2987
-	foreach ($variables_session as $var) {
2988
-		if (_request($var) !== null) {
2989
-			$init = true;
2990
-			break;
2991
-		}
2992
-	}
2993
-	if (isset($init)) {
2994
-		#@spip_initialisation_suite();
2995
-		$session = charger_fonction('session', 'inc');
2996
-		$session();
2997
-		include_spip('inc/texte');
2998
-		foreach ($variables_session as $var) {
2999
-			if (($a = _request($var)) !== null) {
3000
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3001
-			}
3002
-		}
3003
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3004
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3005
-		}
3006
-		$session($GLOBALS['visiteur_session']);
3007
-
3008
-		return 0;
3009
-	}
3010
-
3011
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3012
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3013
-
3014
-		$session = charger_fonction('session', 'inc');
3015
-		if ($session()) {
3016
-			return $GLOBALS['visiteur_session']['statut'];
3017
-		}
3018
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3019
-			include_spip('inc/auth');
3020
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3021
-		}
3022
-		if ($h) {
3023
-			$GLOBALS['visiteur_session'] = $h;
3024
-
3025
-			return $GLOBALS['visiteur_session']['statut'];
3026
-		}
3027
-	}
3028
-
3029
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3030
-	include_spip('inc/lang');
3031
-	utiliser_langue_visiteur();
3032
-
3033
-	return false;
2970
+    // Rq: pour que cette fonction marche depuis mes_options
2971
+    // il faut forcer l'init si ce n'est fait
2972
+    // mais on risque de perturber des plugins en initialisant trop tot
2973
+    // certaines constantes
2974
+    @spip_initialisation_core(
2975
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2976
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2977
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2978
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2979
+    );
2980
+
2981
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
2982
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2983
+    // Attention on separe bien session_nom et nom, pour eviter
2984
+    // les melanges entre donnees SQL et variables plus aleatoires
2985
+    $variables_session = array('session_nom', 'session_email');
2986
+    foreach ($variables_session as $var) {
2987
+        if (_request($var) !== null) {
2988
+            $init = true;
2989
+            break;
2990
+        }
2991
+    }
2992
+    if (isset($init)) {
2993
+        #@spip_initialisation_suite();
2994
+        $session = charger_fonction('session', 'inc');
2995
+        $session();
2996
+        include_spip('inc/texte');
2997
+        foreach ($variables_session as $var) {
2998
+            if (($a = _request($var)) !== null) {
2999
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3000
+            }
3001
+        }
3002
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3003
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3004
+        }
3005
+        $session($GLOBALS['visiteur_session']);
3006
+
3007
+        return 0;
3008
+    }
3009
+
3010
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3011
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3012
+
3013
+        $session = charger_fonction('session', 'inc');
3014
+        if ($session()) {
3015
+            return $GLOBALS['visiteur_session']['statut'];
3016
+        }
3017
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3018
+            include_spip('inc/auth');
3019
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3020
+        }
3021
+        if ($h) {
3022
+            $GLOBALS['visiteur_session'] = $h;
3023
+
3024
+            return $GLOBALS['visiteur_session']['statut'];
3025
+        }
3026
+    }
3027
+
3028
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3029
+    include_spip('inc/lang');
3030
+    utiliser_langue_visiteur();
3031
+
3032
+    return false;
3034 3033
 }
3035 3034
 
3036 3035
 
@@ -3053,21 +3052,21 @@  discard block
 block discarded – undo
3053 3052
  *     - string Langue utilisée.
3054 3053
  **/
3055 3054
 function lang_select($lang = null) {
3056
-	static $pile_langues = array();
3057
-	if (!function_exists('changer_langue')) {
3058
-		include_spip('inc/lang');
3059
-	}
3060
-	if ($lang === null) {
3061
-		$lang = array_pop($pile_langues);
3062
-	} else {
3063
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3064
-	}
3065
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3066
-		return $lang;
3067
-	}
3068
-	changer_langue($lang);
3055
+    static $pile_langues = array();
3056
+    if (!function_exists('changer_langue')) {
3057
+        include_spip('inc/lang');
3058
+    }
3059
+    if ($lang === null) {
3060
+        $lang = array_pop($pile_langues);
3061
+    } else {
3062
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3063
+    }
3064
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3065
+        return $lang;
3066
+    }
3067
+    changer_langue($lang);
3069 3068
 
3070
-	return $lang;
3069
+    return $lang;
3071 3070
 }
3072 3071
 
3073 3072
 /**
@@ -3084,19 +3083,19 @@  discard block
 block discarded – undo
3084 3083
  *     Identifiant de la session
3085 3084
  **/
3086 3085
 function spip_session($force = false) {
3087
-	static $session;
3088
-	if ($force or !isset($session)) {
3089
-		$s = pipeline('definir_session',
3090
-			$GLOBALS['visiteur_session']
3091
-				? serialize($GLOBALS['visiteur_session'])
3092
-				. '_' . @$_COOKIE['spip_session']
3093
-				: ''
3094
-		);
3095
-		$session = $s ? substr(md5($s), 0, 8) : '';
3096
-	}
3086
+    static $session;
3087
+    if ($force or !isset($session)) {
3088
+        $s = pipeline('definir_session',
3089
+            $GLOBALS['visiteur_session']
3090
+                ? serialize($GLOBALS['visiteur_session'])
3091
+                . '_' . @$_COOKIE['spip_session']
3092
+                : ''
3093
+        );
3094
+        $session = $s ? substr(md5($s), 0, 8) : '';
3095
+    }
3097 3096
 
3098
-	#spip_log('session: '.$session);
3099
-	return $session;
3097
+    #spip_log('session: '.$session);
3098
+    return $session;
3100 3099
 }
3101 3100
 
3102 3101
 
@@ -3115,9 +3114,9 @@  discard block
 block discarded – undo
3115 3114
  *    Lien sur une icone d'aide
3116 3115
  **/
3117 3116
 function aider($aide = '', $distante = false) {
3118
-	$aider = charger_fonction('aide', 'inc', true);
3117
+    $aider = charger_fonction('aide', 'inc', true);
3119 3118
 
3120
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3119
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3121 3120
 }
3122 3121
 
3123 3122
 /**
@@ -3127,24 +3126,24 @@  discard block
 block discarded – undo
3127 3126
  */
3128 3127
 function exec_info_dist() {
3129 3128
 
3130
-	include_spip('inc/autoriser');
3131
-	if (autoriser('phpinfos')) {
3132
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3133
-		$cookies_backup = [];
3134
-		foreach ($cookies_masques as $k) {
3135
-			if (!empty($_COOKIE[$k])) {
3136
-				$cookies_backup[$k] = $_COOKIE[$k];
3137
-				$_COOKIE[$k] = '******************************';
3138
-			}
3139
-		}
3140
-		phpinfo();
3141
-		foreach ($cookies_backup as $k => $v) {
3142
-			$_COOKIE[$k] = $v;
3143
-		}
3144
-	} else {
3145
-		include_spip('inc/filtres');
3146
-		sinon_interdire_acces();
3147
-	}
3129
+    include_spip('inc/autoriser');
3130
+    if (autoriser('phpinfos')) {
3131
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3132
+        $cookies_backup = [];
3133
+        foreach ($cookies_masques as $k) {
3134
+            if (!empty($_COOKIE[$k])) {
3135
+                $cookies_backup[$k] = $_COOKIE[$k];
3136
+                $_COOKIE[$k] = '******************************';
3137
+            }
3138
+        }
3139
+        phpinfo();
3140
+        foreach ($cookies_backup as $k => $v) {
3141
+            $_COOKIE[$k] = $v;
3142
+        }
3143
+    } else {
3144
+        include_spip('inc/filtres');
3145
+        sinon_interdire_acces();
3146
+    }
3148 3147
 }
3149 3148
 
3150 3149
 /**
@@ -3164,13 +3163,13 @@  discard block
 block discarded – undo
3164 3163
  *     - string si $message à false.
3165 3164
  **/
3166 3165
 function erreur_squelette($message = '', $lieu = '') {
3167
-	$debusquer = charger_fonction('debusquer', 'public');
3168
-	if (is_array($lieu)) {
3169
-		include_spip('public/compiler');
3170
-		$lieu = reconstruire_contexte_compil($lieu);
3171
-	}
3166
+    $debusquer = charger_fonction('debusquer', 'public');
3167
+    if (is_array($lieu)) {
3168
+        include_spip('public/compiler');
3169
+        $lieu = reconstruire_contexte_compil($lieu);
3170
+    }
3172 3171
 
3173
-	return $debusquer($message, $lieu);
3172
+    return $debusquer($message, $lieu);
3174 3173
 }
3175 3174
 
3176 3175
 /**
@@ -3207,109 +3206,109 @@  discard block
 block discarded – undo
3207 3206
  *     - ou tableau d'information sur le squelette.
3208 3207
  */
3209 3208
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3210
-	if (!function_exists('evaluer_fond')) {
3211
-		include_spip('public/assembler');
3212
-	}
3213
-	// assurer la compat avec l'ancienne syntaxe
3214
-	// (trim etait le 3eme argument, par defaut a true)
3215
-	if (!is_array($options)) {
3216
-		$options = array('trim' => $options);
3217
-	}
3218
-	if (!isset($options['trim'])) {
3219
-		$options['trim'] = true;
3220
-	}
3221
-
3222
-	if (isset($contexte['connect'])) {
3223
-		$connect = $contexte['connect'];
3224
-		unset($contexte['connect']);
3225
-	}
3226
-
3227
-	$texte = "";
3228
-	$pages = array();
3229
-	$lang_select = '';
3230
-	if (!isset($options['etoile']) or !$options['etoile']) {
3231
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3232
-		if (!isset($contexte['lang'])) {
3233
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3234
-		}
3235
-
3236
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3237
-			$lang_select = lang_select($contexte['lang']);
3238
-		}
3239
-	}
3240
-
3241
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3242
-		$GLOBALS['_INC_PUBLIC'] = 0;
3243
-	}
3244
-
3245
-	$GLOBALS['_INC_PUBLIC']++;
3246
-
3247
-	// fix #4235
3248
-	$cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3249
-
3250
-
3251
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3209
+    if (!function_exists('evaluer_fond')) {
3210
+        include_spip('public/assembler');
3211
+    }
3212
+    // assurer la compat avec l'ancienne syntaxe
3213
+    // (trim etait le 3eme argument, par defaut a true)
3214
+    if (!is_array($options)) {
3215
+        $options = array('trim' => $options);
3216
+    }
3217
+    if (!isset($options['trim'])) {
3218
+        $options['trim'] = true;
3219
+    }
3220
+
3221
+    if (isset($contexte['connect'])) {
3222
+        $connect = $contexte['connect'];
3223
+        unset($contexte['connect']);
3224
+    }
3225
+
3226
+    $texte = "";
3227
+    $pages = array();
3228
+    $lang_select = '';
3229
+    if (!isset($options['etoile']) or !$options['etoile']) {
3230
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3231
+        if (!isset($contexte['lang'])) {
3232
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3233
+        }
3234
+
3235
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3236
+            $lang_select = lang_select($contexte['lang']);
3237
+        }
3238
+    }
3239
+
3240
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3241
+        $GLOBALS['_INC_PUBLIC'] = 0;
3242
+    }
3243
+
3244
+    $GLOBALS['_INC_PUBLIC']++;
3245
+
3246
+    // fix #4235
3247
+    $cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3248
+
3249
+
3250
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3252 3251
 		
3253
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3254
-
3255
-		$page = evaluer_fond($f, $contexte, $connect);
3256
-		if ($page === '') {
3257
-			$c = isset($options['compil']) ? $options['compil'] : '';
3258
-			$a = array('fichier' => $f);
3259
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3260
-			erreur_squelette($erreur, $c);
3261
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3262
-			$page = array('texte' => '', 'erreur' => $erreur);
3263
-		}
3264
-
3265
-		$page = pipeline('recuperer_fond', array(
3266
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3267
-			'data' => $page
3268
-		));
3269
-		if (isset($options['ajax']) and $options['ajax']) {
3270
-			if (!function_exists('encoder_contexte_ajax')) {
3271
-				include_spip('inc/filtres');
3272
-			}
3273
-			$page['texte'] = encoder_contexte_ajax(
3274
-				array_merge(
3275
-					$contexte,
3276
-					array('fond' => $f),
3277
-					($connect ? array('connect' => $connect) : array())
3278
-				),
3279
-				'',
3280
-				$page['texte'],
3281
-				$options['ajax']
3282
-			);
3283
-		}
3284
-
3285
-		if (isset($options['raw']) and $options['raw']) {
3286
-			$pages[] = $page;
3287
-		} else {
3288
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3289
-		}
3252
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3253
+
3254
+        $page = evaluer_fond($f, $contexte, $connect);
3255
+        if ($page === '') {
3256
+            $c = isset($options['compil']) ? $options['compil'] : '';
3257
+            $a = array('fichier' => $f);
3258
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3259
+            erreur_squelette($erreur, $c);
3260
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3261
+            $page = array('texte' => '', 'erreur' => $erreur);
3262
+        }
3263
+
3264
+        $page = pipeline('recuperer_fond', array(
3265
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3266
+            'data' => $page
3267
+        ));
3268
+        if (isset($options['ajax']) and $options['ajax']) {
3269
+            if (!function_exists('encoder_contexte_ajax')) {
3270
+                include_spip('inc/filtres');
3271
+            }
3272
+            $page['texte'] = encoder_contexte_ajax(
3273
+                array_merge(
3274
+                    $contexte,
3275
+                    array('fond' => $f),
3276
+                    ($connect ? array('connect' => $connect) : array())
3277
+                ),
3278
+                '',
3279
+                $page['texte'],
3280
+                $options['ajax']
3281
+            );
3282
+        }
3283
+
3284
+        if (isset($options['raw']) and $options['raw']) {
3285
+            $pages[] = $page;
3286
+        } else {
3287
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3288
+        }
3290 3289
 		
3291
-		// contamination de la session appelante, pour les inclusions statiques
3292
-		if (isset($page['invalideurs']['session'])){
3293
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3294
-		}
3295
-	}
3290
+        // contamination de la session appelante, pour les inclusions statiques
3291
+        if (isset($page['invalideurs']['session'])){
3292
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3293
+        }
3294
+    }
3296 3295
 
3297
-	// restaurer le sessionnement du contexte appelant, 
3298
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3299
-	if (isset($cache_utilise_session_appelant)) {
3300
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3301
-	}
3296
+    // restaurer le sessionnement du contexte appelant, 
3297
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3298
+    if (isset($cache_utilise_session_appelant)) {
3299
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3300
+    }
3302 3301
 
3303
-	$GLOBALS['_INC_PUBLIC']--;
3302
+    $GLOBALS['_INC_PUBLIC']--;
3304 3303
 
3305
-	if ($lang_select) {
3306
-		lang_select();
3307
-	}
3308
-	if (isset($options['raw']) and $options['raw']) {
3309
-		return is_array($fond) ? $pages : reset($pages);
3310
-	} else {
3311
-		return $options['trim'] ? ltrim($texte) : $texte;
3312
-	}
3304
+    if ($lang_select) {
3305
+        lang_select();
3306
+    }
3307
+    if (isset($options['raw']) and $options['raw']) {
3308
+        return is_array($fond) ? $pages : reset($pages);
3309
+    } else {
3310
+        return $options['trim'] ? ltrim($texte) : $texte;
3311
+    }
3313 3312
 }
3314 3313
 
3315 3314
 /**
@@ -3319,7 +3318,7 @@  discard block
 block discarded – undo
3319 3318
  * @return string
3320 3319
  */
3321 3320
 function trouve_modele($nom) {
3322
-	return trouver_fond($nom, 'modeles/');
3321
+    return trouver_fond($nom, 'modeles/');
3323 3322
 }
3324 3323
 
3325 3324
 /**
@@ -3335,21 +3334,21 @@  discard block
 block discarded – undo
3335 3334
  * @return array|string
3336 3335
  */
3337 3336
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3338
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3339
-	if (!$pathinfo) {
3340
-		return $f;
3341
-	}
3342
-	// renvoyer un tableau detaille si $pathinfo==true
3343
-	$p = pathinfo($f);
3344
-	if (!isset($p['extension']) or !$p['extension']) {
3345
-		$p['extension'] = _EXTENSION_SQUELETTES;
3346
-	}
3347
-	if (!isset($p['extension']) or !$p['filename']) {
3348
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3349
-	}
3350
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3337
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3338
+    if (!$pathinfo) {
3339
+        return $f;
3340
+    }
3341
+    // renvoyer un tableau detaille si $pathinfo==true
3342
+    $p = pathinfo($f);
3343
+    if (!isset($p['extension']) or !$p['extension']) {
3344
+        $p['extension'] = _EXTENSION_SQUELETTES;
3345
+    }
3346
+    if (!isset($p['extension']) or !$p['filename']) {
3347
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3348
+    }
3349
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3351 3350
 
3352
-	return $p;
3351
+    return $p;
3353 3352
 }
3354 3353
 
3355 3354
 /**
@@ -3370,24 +3369,24 @@  discard block
 block discarded – undo
3370 3369
  *     Nom de l'exec, sinon chaîne vide.
3371 3370
  **/
3372 3371
 function tester_url_ecrire($nom) {
3373
-	static $exec = array();
3374
-	if (isset($exec[$nom])) {
3375
-		return $exec[$nom];
3376
-	}
3377
-	// tester si c'est une page en squelette
3378
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3379
-		return $exec[$nom] = 'fond';
3380
-	} // compat skels orthogonaux version precedente
3381
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3382
-		return $exec[$nom] = 'fond_monobloc';
3383
-	} // echafaudage d'un fond !
3384
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3385
-		return $exec[$nom] = 'fond';
3386
-	}
3387
-	// attention, il ne faut pas inclure l'exec ici
3388
-	// car sinon #URL_ECRIRE provoque des inclusions
3389
-	// et des define intrusifs potentiels
3390
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3372
+    static $exec = array();
3373
+    if (isset($exec[$nom])) {
3374
+        return $exec[$nom];
3375
+    }
3376
+    // tester si c'est une page en squelette
3377
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3378
+        return $exec[$nom] = 'fond';
3379
+    } // compat skels orthogonaux version precedente
3380
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3381
+        return $exec[$nom] = 'fond_monobloc';
3382
+    } // echafaudage d'un fond !
3383
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3384
+        return $exec[$nom] = 'fond';
3385
+    }
3386
+    // attention, il ne faut pas inclure l'exec ici
3387
+    // car sinon #URL_ECRIRE provoque des inclusions
3388
+    // et des define intrusifs potentiels
3389
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3391 3390
 }
3392 3391
 
3393 3392
 
@@ -3403,10 +3402,10 @@  discard block
 block discarded – undo
3403 3402
  * @return bool true si le module est chargé
3404 3403
  **/
3405 3404
 function charger_php_extension($module) {
3406
-	if (extension_loaded($module)) {
3407
-		return true;
3408
-	}
3409
-	return false;
3405
+    if (extension_loaded($module)) {
3406
+        return true;
3407
+    }
3408
+    return false;
3410 3409
 }
3411 3410
 
3412 3411
 
@@ -3417,8 +3416,8 @@  discard block
 block discarded – undo
3417 3416
  *     true si et seulement si la configuration autorise le code HTML5 sur le site public
3418 3417
  **/
3419 3418
 function html5_permis() {
3420
-	return (isset($GLOBALS['meta']['version_html_max'])
3421
-		and ('html5' == $GLOBALS['meta']['version_html_max']));
3419
+    return (isset($GLOBALS['meta']['version_html_max'])
3420
+        and ('html5' == $GLOBALS['meta']['version_html_max']));
3422 3421
 }
3423 3422
 
3424 3423
 /**
@@ -3428,17 +3427,17 @@  discard block
 block discarded – undo
3428 3427
  * @return array
3429 3428
  */
3430 3429
 function formats_image_acceptables($gd = false, $svg_allowed = true) {
3431
-	$config = ($gd ? "gd_formats" : "formats_graphiques");
3432
-	$formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3433
-	$formats = explode(',', $formats);
3434
-	$formats = array_filter($formats);
3435
-	$formats = array_map('trim', $formats);
3430
+    $config = ($gd ? "gd_formats" : "formats_graphiques");
3431
+    $formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3432
+    $formats = explode(',', $formats);
3433
+    $formats = array_filter($formats);
3434
+    $formats = array_map('trim', $formats);
3436 3435
 
3437
-	if ($svg_allowed) {
3438
-		$formats[] = 'svg';
3439
-	}
3436
+    if ($svg_allowed) {
3437
+        $formats[] = 'svg';
3438
+    }
3440 3439
 
3441
-	return $formats;
3440
+    return $formats;
3442 3441
 }
3443 3442
 
3444 3443
 /**
@@ -3447,21 +3446,21 @@  discard block
 block discarded – undo
3447 3446
  * @return array|bool
3448 3447
  */
3449 3448
 function spip_getimagesize($fichier) {
3450
-	if (!$imagesize = @getimagesize($fichier)) {
3449
+    if (!$imagesize = @getimagesize($fichier)) {
3451 3450
 
3452
-		include_spip("inc/svg");
3453
-		if ($attrs = svg_lire_attributs($fichier)) {
3454
-			list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3455
-			$imagesize = [
3456
-				$width,
3457
-				$height,
3458
-				IMAGETYPE_SVG,
3459
-				"width=\"{$width}\" height=\"{$height}\"",
3460
-				"mime" => "image/svg+xml"
3461
-			];
3462
-		}
3463
-	}
3464
-	return $imagesize;
3451
+        include_spip("inc/svg");
3452
+        if ($attrs = svg_lire_attributs($fichier)) {
3453
+            list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
3454
+            $imagesize = [
3455
+                $width,
3456
+                $height,
3457
+                IMAGETYPE_SVG,
3458
+                "width=\"{$width}\" height=\"{$height}\"",
3459
+                "mime" => "image/svg+xml"
3460
+            ];
3461
+        }
3462
+    }
3463
+    return $imagesize;
3465 3464
 }
3466 3465
 
3467 3466
 
@@ -3481,7 +3480,7 @@  discard block
 block discarded – undo
3481 3480
  * @return mixed Valeur de la meta.
3482 3481
  **/
3483 3482
 function lire_meta($nom) {
3484
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3483
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3485 3484
 }
3486 3485
 
3487 3486
 
@@ -3503,130 +3502,130 @@  discard block
 block discarded – undo
3503 3502
  * @param string $statut
3504 3503
  */
3505 3504
 function avertir_auteurs($nom, $message, $statut = '') {
3506
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3507
-	if (!$alertes
3508
-		or !is_array($alertes = unserialize($alertes))
3509
-	) {
3510
-		$alertes = array();
3511
-	}
3505
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3506
+    if (!$alertes
3507
+        or !is_array($alertes = unserialize($alertes))
3508
+    ) {
3509
+        $alertes = array();
3510
+    }
3512 3511
 
3513
-	if (!isset($alertes[$statut])) {
3514
-		$alertes[$statut] = array();
3515
-	}
3516
-	$alertes[$statut][$nom] = $message;
3517
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3512
+    if (!isset($alertes[$statut])) {
3513
+        $alertes[$statut] = array();
3514
+    }
3515
+    $alertes[$statut][$nom] = $message;
3516
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3518 3517
 }
3519 3518
 
3520 3519
 if (PHP_VERSION_ID < 50500) {
3521
-	if (!function_exists('array_column')) {
3522
-		/**
3523
-		 * Returns the values from a single column of the input array, identified by
3524
-		 * the $columnKey.
3525
-		 *
3526
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3527
-		 * array by the values from the $indexKey column in the input array.
3528
-		 *
3529
-		 * @link http://php.net/manual/fr/function.array-column.php
3530
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3531
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3532
-		 * @license http://opensource.org/licenses/MIT MIT
3533
-		 *
3534
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3535
-		 *                     a column of values.
3536
-		 * @param mixed $columnKey The column of values to return. This value may be the
3537
-		 *                         integer key of the column you wish to retrieve, or it
3538
-		 *                         may be the string key name for an associative array.
3539
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3540
-		 *                        the returned array. This value may be the integer key
3541
-		 *                        of the column, or it may be the string key name.
3542
-		 * @return array
3543
-		 */
3544
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3545
-		{
3546
-			// Using func_get_args() in order to check for proper number of
3547
-			// parameters and trigger errors exactly as the built-in array_column()
3548
-			// does in PHP 5.5.
3549
-			$argc = func_num_args();
3550
-			$params = func_get_args();
3551
-
3552
-			if ($argc < 2) {
3553
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3554
-				return null;
3555
-			}
3556
-
3557
-			if (!is_array($params[0])) {
3558
-				trigger_error(
3559
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3560
-					E_USER_WARNING
3561
-				);
3562
-				return null;
3563
-			}
3564
-
3565
-			if (!is_int($params[1])
3566
-				&& !is_float($params[1])
3567
-				&& !is_string($params[1])
3568
-				&& $params[1] !== null
3569
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3570
-			) {
3571
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3572
-				return false;
3573
-			}
3574
-
3575
-			if (isset($params[2])
3576
-				&& !is_int($params[2])
3577
-				&& !is_float($params[2])
3578
-				&& !is_string($params[2])
3579
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3580
-			) {
3581
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3582
-				return false;
3583
-			}
3584
-
3585
-			$paramsInput = $params[0];
3586
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3587
-
3588
-			$paramsIndexKey = null;
3589
-			if (isset($params[2])) {
3590
-				if (is_float($params[2]) || is_int($params[2])) {
3591
-					$paramsIndexKey = (int) $params[2];
3592
-				} else {
3593
-					$paramsIndexKey = (string) $params[2];
3594
-				}
3595
-			}
3596
-
3597
-			$resultArray = array();
3598
-
3599
-			foreach ($paramsInput as $row) {
3600
-				$key = $value = null;
3601
-				$keySet = $valueSet = false;
3602
-
3603
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3604
-					$keySet = true;
3605
-					$key = (string) $row[$paramsIndexKey];
3606
-				}
3607
-
3608
-				if ($paramsColumnKey === null) {
3609
-					$valueSet = true;
3610
-					$value = $row;
3611
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3612
-					$valueSet = true;
3613
-					$value = $row[$paramsColumnKey];
3614
-				}
3615
-
3616
-				if ($valueSet) {
3617
-					if ($keySet) {
3618
-						$resultArray[$key] = $value;
3619
-					} else {
3620
-						$resultArray[] = $value;
3621
-					}
3622
-				}
3623
-
3624
-			}
3625
-
3626
-			return $resultArray;
3627
-		}
3628
-
3629
-	}
3520
+    if (!function_exists('array_column')) {
3521
+        /**
3522
+         * Returns the values from a single column of the input array, identified by
3523
+         * the $columnKey.
3524
+         *
3525
+         * Optionally, you may provide an $indexKey to index the values in the returned
3526
+         * array by the values from the $indexKey column in the input array.
3527
+         *
3528
+         * @link http://php.net/manual/fr/function.array-column.php
3529
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3530
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3531
+         * @license http://opensource.org/licenses/MIT MIT
3532
+         *
3533
+         * @param array $input A multi-dimensional array (record set) from which to pull
3534
+         *                     a column of values.
3535
+         * @param mixed $columnKey The column of values to return. This value may be the
3536
+         *                         integer key of the column you wish to retrieve, or it
3537
+         *                         may be the string key name for an associative array.
3538
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3539
+         *                        the returned array. This value may be the integer key
3540
+         *                        of the column, or it may be the string key name.
3541
+         * @return array
3542
+         */
3543
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3544
+        {
3545
+            // Using func_get_args() in order to check for proper number of
3546
+            // parameters and trigger errors exactly as the built-in array_column()
3547
+            // does in PHP 5.5.
3548
+            $argc = func_num_args();
3549
+            $params = func_get_args();
3550
+
3551
+            if ($argc < 2) {
3552
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3553
+                return null;
3554
+            }
3555
+
3556
+            if (!is_array($params[0])) {
3557
+                trigger_error(
3558
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3559
+                    E_USER_WARNING
3560
+                );
3561
+                return null;
3562
+            }
3563
+
3564
+            if (!is_int($params[1])
3565
+                && !is_float($params[1])
3566
+                && !is_string($params[1])
3567
+                && $params[1] !== null
3568
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3569
+            ) {
3570
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3571
+                return false;
3572
+            }
3573
+
3574
+            if (isset($params[2])
3575
+                && !is_int($params[2])
3576
+                && !is_float($params[2])
3577
+                && !is_string($params[2])
3578
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3579
+            ) {
3580
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3581
+                return false;
3582
+            }
3583
+
3584
+            $paramsInput = $params[0];
3585
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3586
+
3587
+            $paramsIndexKey = null;
3588
+            if (isset($params[2])) {
3589
+                if (is_float($params[2]) || is_int($params[2])) {
3590
+                    $paramsIndexKey = (int) $params[2];
3591
+                } else {
3592
+                    $paramsIndexKey = (string) $params[2];
3593
+                }
3594
+            }
3595
+
3596
+            $resultArray = array();
3597
+
3598
+            foreach ($paramsInput as $row) {
3599
+                $key = $value = null;
3600
+                $keySet = $valueSet = false;
3601
+
3602
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3603
+                    $keySet = true;
3604
+                    $key = (string) $row[$paramsIndexKey];
3605
+                }
3606
+
3607
+                if ($paramsColumnKey === null) {
3608
+                    $valueSet = true;
3609
+                    $value = $row;
3610
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3611
+                    $valueSet = true;
3612
+                    $value = $row[$paramsColumnKey];
3613
+                }
3614
+
3615
+                if ($valueSet) {
3616
+                    if ($keySet) {
3617
+                        $resultArray[$key] = $value;
3618
+                    } else {
3619
+                        $resultArray[] = $value;
3620
+                    }
3621
+                }
3622
+
3623
+            }
3624
+
3625
+            return $resultArray;
3626
+        }
3627
+
3628
+    }
3630 3629
 }
3631 3630
 
3632 3631
 /**
@@ -3640,8 +3639,8 @@  discard block
 block discarded – undo
3640 3639
  * @return string|string[]
3641 3640
  */
3642 3641
 function spip_sanitize_classname($classes) {
3643
-	if (is_array($classes)) {
3644
-		return array_map('spip_sanitize_classname', $classes);
3645
-	}
3646
-	return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes);
3642
+    if (is_array($classes)) {
3643
+        return array_map('spip_sanitize_classname', $classes);
3644
+    }
3645
+    return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes);
3647 3646
 }
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 1 patch
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Autorisations
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('base/abstract_sql');
@@ -38,83 +38,83 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 if (!function_exists('autoriser')) {
41
-	/**
42
-	 * Autoriser une action
43
-	 *
44
-	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
-	 * une certaine action. Cette fonction est le point d'entrée de toutes
46
-	 * les autorisations.
47
-	 *
48
-	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
-	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
-	 * dans cet ordre :
51
-	 *
52
-	 * - autoriser_{type}_{faire}, sinon avec _dist
53
-	 * - autoriser_{type}, sinon avec _dist
54
-	 * - autoriser_{faire}, sinon avec _dist
55
-	 * - autoriser_{defaut}, sinon avec _dist
56
-	 *
57
-	 * Seul le premier argument est obligatoire.
58
-	 *
59
-	 * @note
60
-	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
-	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
-	 *     cette valeur.
63
-	 *
64
-	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
-	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
-	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
-	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
-	 *
69
-	 * @note
70
-	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
-	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
-	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
-	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
-	 *     quel serait le type, quel serait l'action ?
75
-	 *
76
-	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
-	 *     la fonction d'autorisation correspondante ne l'aura pas.
78
-	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
-	 *
80
-	 * @api
81
-	 * @see autoriser_dist()
82
-	 *
83
-	 * @param string $faire
84
-	 *   une action ('modifier', 'publier'...)
85
-	 * @param string $type
86
-	 *   type d'objet ou nom de table ('article')
87
-	 * @param int $id
88
-	 *   id de l'objet sur lequel on veut agir
89
-	 * @param null|int|array $qui
90
-	 *   - si null on prend alors visiteur_session
91
-	 *   - un id_auteur (on regarde dans la base)
92
-	 *   - un tableau auteur complet, y compris [restreint]
93
-	 * @param null|array $opt
94
-	 *   options sous forme de tableau associatif
95
-	 * @return bool
96
-	 *   true si la personne peut effectuer l'action
97
-	 */
98
-	function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
-		// Charger les fonctions d'autorisation supplementaires
100
-		static $pipe;
101
-		if (!isset($pipe)) {
102
-			$pipe = 1;
103
-			pipeline('autoriser');
104
-		}
105
-
106
-		$args = func_get_args();
107
-
108
-		return call_user_func_array('autoriser_dist', $args);
109
-	}
41
+    /**
42
+     * Autoriser une action
43
+     *
44
+     * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
+     * une certaine action. Cette fonction est le point d'entrée de toutes
46
+     * les autorisations.
47
+     *
48
+     * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
+     * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
+     * dans cet ordre :
51
+     *
52
+     * - autoriser_{type}_{faire}, sinon avec _dist
53
+     * - autoriser_{type}, sinon avec _dist
54
+     * - autoriser_{faire}, sinon avec _dist
55
+     * - autoriser_{defaut}, sinon avec _dist
56
+     *
57
+     * Seul le premier argument est obligatoire.
58
+     *
59
+     * @note
60
+     *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
+     *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
+     *     cette valeur.
63
+     *
64
+     *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
+     *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
+     *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
+     *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
+     *
69
+     * @note
70
+     *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
+     *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
+     *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
+     *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
+     *     quel serait le type, quel serait l'action ?
75
+     *
76
+     *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
+     *     la fonction d'autorisation correspondante ne l'aura pas.
78
+     *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
+     *
80
+     * @api
81
+     * @see autoriser_dist()
82
+     *
83
+     * @param string $faire
84
+     *   une action ('modifier', 'publier'...)
85
+     * @param string $type
86
+     *   type d'objet ou nom de table ('article')
87
+     * @param int $id
88
+     *   id de l'objet sur lequel on veut agir
89
+     * @param null|int|array $qui
90
+     *   - si null on prend alors visiteur_session
91
+     *   - un id_auteur (on regarde dans la base)
92
+     *   - un tableau auteur complet, y compris [restreint]
93
+     * @param null|array $opt
94
+     *   options sous forme de tableau associatif
95
+     * @return bool
96
+     *   true si la personne peut effectuer l'action
97
+     */
98
+    function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
+        // Charger les fonctions d'autorisation supplementaires
100
+        static $pipe;
101
+        if (!isset($pipe)) {
102
+            $pipe = 1;
103
+            pipeline('autoriser');
104
+        }
105
+
106
+        $args = func_get_args();
107
+
108
+        return call_user_func_array('autoriser_dist', $args);
109
+    }
110 110
 }
111 111
 
112 112
 
113 113
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
114 114
 // mais apres la fonction autoriser()
115 115
 if ($f = find_in_path('mes_fonctions.php')) {
116
-	global $dossier_squelettes;
117
-	include_once(_ROOT_CWD . $f);
116
+    global $dossier_squelettes;
117
+    include_once(_ROOT_CWD . $f);
118 118
 }
119 119
 
120 120
 
@@ -142,72 +142,72 @@  discard block
 block discarded – undo
142 142
  */
143 143
 function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) {
144 144
 
145
-	// Qui ? visiteur_session ?
146
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
-	if ($qui === null or $qui === '') {
148
-		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
-		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
-	} elseif (is_numeric($qui)) {
151
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
-	}
153
-
154
-	// Admins restreints, on construit ici (pas generique mais...)
155
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
-	if (_ADMINS_RESTREINTS and is_array($qui)) {
157
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
-	}
159
-
160
-	spip_log(
161
-		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
-		'autoriser' . _LOG_DEBUG
163
-	);
164
-
165
-	// passer par objet_type pour avoir les alias
166
-	// et supprimer les _
167
-	$type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
-
169
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
170
-	if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171
-		and autoriser_exception($faire, $type, $id, 'verifier')
172
-	) {
173
-		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
-		return true;
175
-	}
176
-
177
-	// Chercher une fonction d'autorisation
178
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
180
-	$fonctions = $type
181
-		? array(
182
-			'autoriser_' . $type . '_' . $faire,
183
-			'autoriser_' . $type . '_' . $faire . '_dist',
184
-			'autoriser_' . $type,
185
-			'autoriser_' . $type . '_dist',
186
-			'autoriser_' . $faire,
187
-			'autoriser_' . $faire . '_dist',
188
-			'autoriser_defaut',
189
-			'autoriser_defaut_dist'
190
-		)
191
-		: array(
192
-			'autoriser_' . $faire,
193
-			'autoriser_' . $faire . '_dist',
194
-			'autoriser_defaut',
195
-			'autoriser_defaut_dist'
196
-		);
197
-
198
-	foreach ($fonctions as $f) {
199
-		if (function_exists($f)) {
200
-			$a = $f($faire, $type, $id, $qui, $opt);
201
-			break;
202
-		}
203
-	}
204
-
205
-	spip_log(
206
-		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
-		'autoriser' . _LOG_DEBUG
208
-	);
209
-
210
-	return $a;
145
+    // Qui ? visiteur_session ?
146
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
+    if ($qui === null or $qui === '') {
148
+        $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
+        $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
+    } elseif (is_numeric($qui)) {
151
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
+    }
153
+
154
+    // Admins restreints, on construit ici (pas generique mais...)
155
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
+    if (_ADMINS_RESTREINTS and is_array($qui)) {
157
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
+    }
159
+
160
+    spip_log(
161
+        "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
+        'autoriser' . _LOG_DEBUG
163
+    );
164
+
165
+    // passer par objet_type pour avoir les alias
166
+    // et supprimer les _
167
+    $type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
+
169
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
170
+    if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171
+        and autoriser_exception($faire, $type, $id, 'verifier')
172
+    ) {
173
+        spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
+        return true;
175
+    }
176
+
177
+    // Chercher une fonction d'autorisation
178
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
180
+    $fonctions = $type
181
+        ? array(
182
+            'autoriser_' . $type . '_' . $faire,
183
+            'autoriser_' . $type . '_' . $faire . '_dist',
184
+            'autoriser_' . $type,
185
+            'autoriser_' . $type . '_dist',
186
+            'autoriser_' . $faire,
187
+            'autoriser_' . $faire . '_dist',
188
+            'autoriser_defaut',
189
+            'autoriser_defaut_dist'
190
+        )
191
+        : array(
192
+            'autoriser_' . $faire,
193
+            'autoriser_' . $faire . '_dist',
194
+            'autoriser_defaut',
195
+            'autoriser_defaut_dist'
196
+        );
197
+
198
+    foreach ($fonctions as $f) {
199
+        if (function_exists($f)) {
200
+            $a = $f($faire, $type, $id, $qui, $opt);
201
+            break;
202
+        }
203
+    }
204
+
205
+    spip_log(
206
+        "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
+        'autoriser' . _LOG_DEBUG
208
+    );
209
+
210
+    return $a;
211 211
 }
212 212
 
213 213
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -225,20 +225,20 @@  discard block
 block discarded – undo
225 225
  * @return bool
226 226
  */
227 227
 function autoriser_exception($faire, $type, $id, $autoriser = true) {
228
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
-	static $autorisation;
230
-	if ($autoriser === 'verifier') {
231
-		return isset($autorisation[$faire][$type][$id]);
232
-	}
233
-	if ($autoriser === true) {
234
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
-	}
236
-	if ($autoriser === false) {
237
-		unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
238
-		unset($autorisation[$faire][$type][$id]);
239
-	}
228
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
+    static $autorisation;
230
+    if ($autoriser === 'verifier') {
231
+        return isset($autorisation[$faire][$type][$id]);
232
+    }
233
+    if ($autoriser === true) {
234
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
+    }
236
+    if ($autoriser === false) {
237
+        unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
238
+        unset($autorisation[$faire][$type][$id]);
239
+    }
240 240
 
241
-	return false;
241
+    return false;
242 242
 }
243 243
 
244 244
 
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
  * @return bool          true s'il a le droit, false sinon
256 256
  **/
257 257
 function autoriser_defaut_dist($faire, $type, $id, $qui, $opt) {
258
-	return
259
-		$qui['statut'] == '0minirezo'
260
-		and !$qui['restreint'];
258
+    return
259
+        $qui['statut'] == '0minirezo'
260
+        and !$qui['restreint'];
261 261
 }
262 262
 
263 263
 /**
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
  * @return bool
274 274
  */
275 275
 function autoriser_loger_dist($faire, $type, $id, $qui, $opt) {
276
-	if ($qui['statut'] == '5poubelle') {
277
-		return false;
278
-	}
279
-	return true;
276
+    if ($qui['statut'] == '5poubelle') {
277
+        return false;
278
+    }
279
+    return true;
280 280
 }
281 281
 
282 282
 /**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
  * @return bool          true s'il a le droit, false sinon
291 291
  **/
292 292
 function autoriser_ecrire_dist($faire, $type, $id, $qui, $opt) {
293
-	return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
293
+    return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
294 294
 }
295 295
 
296 296
 /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
  * @return bool          true s'il a le droit, false sinon
308 308
  **/
309 309
 function autoriser_creer_dist($faire, $type, $id, $qui, $opt) {
310
-	return in_array($qui['statut'], array('0minirezo', '1comite'));
310
+    return in_array($qui['statut'], array('0minirezo', '1comite'));
311 311
 }
312 312
 
313 313
 /**
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
  **/
326 326
 function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
327 327
 
328
-	// Le visiteur a-t-il un statut prevu par la config ?
329
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
330
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331
-	}
328
+    // Le visiteur a-t-il un statut prevu par la config ?
329
+    if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
330
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331
+    }
332 332
 
333
-	// A-t-on un token de prévisualisation valable ?
334
-	include_spip('inc/securiser_action');
335
-	if (decrire_token_previsu()) {
336
-		return true;
337
-	}
333
+    // A-t-on un token de prévisualisation valable ?
334
+    include_spip('inc/securiser_action');
335
+    if (decrire_token_previsu()) {
336
+        return true;
337
+    }
338 338
 
339
-	return false;
339
+    return false;
340 340
 }
341 341
 
342 342
 /**
@@ -364,57 +364,57 @@  discard block
 block discarded – undo
364 364
  */
365 365
 function test_previsualiser_objet_champ($type = null, $id = 0, $qui = array(), $opt = array()) {
366 366
 
367
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
368
-	if (!$type) {
369
-		return true;
370
-	}
371
-
372
-	include_spip('base/objets');
373
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
374
-	if (isset($infos['statut'])) {
375
-		foreach ($infos['statut'] as $c) {
376
-			if (isset($c['publie'])) {
377
-				if (!isset($c['previsu'])) {
378
-					return false;
379
-				} // pas de previsu definie => NIET
380
-				$champ = $c['champ'];
381
-				if (!isset($opt[$champ])) {
382
-					return false;
383
-				} // pas de champ passe a la demande => NIET
384
-				$previsu = explode(',', $c['previsu']);
385
-				// regarder si ce statut est autorise pour l'auteur
386
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
387
-
388
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389
-					// sinon l’auteur en session
390
-					include_spip('inc/securiser_action');
391
-					if ($desc = decrire_token_previsu()) {
392
-						$id_auteur = $desc['id_auteur'];
393
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
394
-						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
395
-					} else {
396
-						$id_auteur = null;
397
-					}
398
-
399
-					if (!$id_auteur) {
400
-						return false;
401
-					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
402
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
403
-					} elseif (!sql_countsel(
404
-						'spip_auteurs_liens',
405
-						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
406
-					)) {
407
-						return false;
408
-					} // pas auteur de cet objet => NIET
409
-				} elseif (!in_array($opt[$champ], $previsu)) {
410
-					// le statut n'est pas dans ceux definis par la previsu => NIET
411
-					return false;
412
-				}
413
-			}
414
-		}
415
-	}
416
-
417
-	return true;
367
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
368
+    if (!$type) {
369
+        return true;
370
+    }
371
+
372
+    include_spip('base/objets');
373
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
374
+    if (isset($infos['statut'])) {
375
+        foreach ($infos['statut'] as $c) {
376
+            if (isset($c['publie'])) {
377
+                if (!isset($c['previsu'])) {
378
+                    return false;
379
+                } // pas de previsu definie => NIET
380
+                $champ = $c['champ'];
381
+                if (!isset($opt[$champ])) {
382
+                    return false;
383
+                } // pas de champ passe a la demande => NIET
384
+                $previsu = explode(',', $c['previsu']);
385
+                // regarder si ce statut est autorise pour l'auteur
386
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
387
+
388
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389
+                    // sinon l’auteur en session
390
+                    include_spip('inc/securiser_action');
391
+                    if ($desc = decrire_token_previsu()) {
392
+                        $id_auteur = $desc['id_auteur'];
393
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
394
+                        $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
395
+                    } else {
396
+                        $id_auteur = null;
397
+                    }
398
+
399
+                    if (!$id_auteur) {
400
+                        return false;
401
+                    } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
402
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
403
+                    } elseif (!sql_countsel(
404
+                        'spip_auteurs_liens',
405
+                        'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
406
+                    )) {
407
+                        return false;
408
+                    } // pas auteur de cet objet => NIET
409
+                } elseif (!in_array($opt[$champ], $previsu)) {
410
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
411
+                    return false;
412
+                }
413
+            }
414
+        }
415
+    }
416
+
417
+    return true;
418 418
 }
419 419
 
420 420
 /**
@@ -428,47 +428,47 @@  discard block
 block discarded – undo
428 428
  * @return bool          true s'il a le droit, false sinon
429 429
  **/
430 430
 function autoriser_changerlangue_dist($faire, $type, $id, $qui, $opt) {
431
-	$multi_objets = explode(',', lire_config('multi_objets'));
432
-	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
433
-	$table = table_objet_sql($type);
434
-	if (in_array($table, $multi_objets)
435
-		or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
436
-		$multi_secteurs = lire_config('multi_secteurs');
437
-		$champs = objet_info($type, 'field');
438
-		if ($multi_secteurs == 'oui'
439
-			and array_key_exists('id_rubrique', $champs)) {
440
-			// multilinguisme par secteur et objet rattaché à une rubrique
441
-			$primary = id_table_objet($type);
442
-			if ($table != 'spip_rubriques') {
443
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
444
-			} else {
445
-				$id_rubrique = $id;
446
-			}
447
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
448
-			if (!$id_secteur > 0) {
449
-				$id_secteur = $id_rubrique;
450
-			}
451
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
453
-			if ($langue_secteur != $langue_objet) {
454
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
455
-				return true;
456
-			}
457
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458
-				return false;
459
-			} else {
460
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
461
-				if ($id_parent != 0) {
462
-					// sous-rubriques : pas de choix de langue
463
-					return false;
464
-				}
465
-			}
466
-		}
467
-	} else {
468
-		return false;
469
-	}
470
-
471
-	return autoriser('modifier', $type, $id, $qui, $opt);
431
+    $multi_objets = explode(',', lire_config('multi_objets'));
432
+    $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
433
+    $table = table_objet_sql($type);
434
+    if (in_array($table, $multi_objets)
435
+        or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
436
+        $multi_secteurs = lire_config('multi_secteurs');
437
+        $champs = objet_info($type, 'field');
438
+        if ($multi_secteurs == 'oui'
439
+            and array_key_exists('id_rubrique', $champs)) {
440
+            // multilinguisme par secteur et objet rattaché à une rubrique
441
+            $primary = id_table_objet($type);
442
+            if ($table != 'spip_rubriques') {
443
+                $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
444
+            } else {
445
+                $id_rubrique = $id;
446
+            }
447
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
448
+            if (!$id_secteur > 0) {
449
+                $id_secteur = $id_rubrique;
450
+            }
451
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
453
+            if ($langue_secteur != $langue_objet) {
454
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
455
+                return true;
456
+            }
457
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458
+                return false;
459
+            } else {
460
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
461
+                if ($id_parent != 0) {
462
+                    // sous-rubriques : pas de choix de langue
463
+                    return false;
464
+                }
465
+            }
466
+        }
467
+    } else {
468
+        return false;
469
+    }
470
+
471
+    return autoriser('modifier', $type, $id, $qui, $opt);
472 472
 }
473 473
 
474 474
 /**
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
  * @return bool          true s'il a le droit, false sinon
483 483
  **/
484 484
 function autoriser_changertraduction_dist($faire, $type, $id, $qui, $opt) {
485
-	return autoriser('modifier', $type, $id, $qui, $opt);
485
+    return autoriser('modifier', $type, $id, $qui, $opt);
486 486
 }
487 487
 
488 488
 /**
@@ -496,41 +496,41 @@  discard block
 block discarded – undo
496 496
  * @return bool          true s'il a le droit, false sinon
497 497
  **/
498 498
 function autoriser_dater_dist($faire, $type, $id, $qui, $opt) {
499
-	$table = table_objet($type);
500
-	$trouver_table = charger_fonction('trouver_table', 'base');
501
-	$desc = $trouver_table($table);
502
-	if (!$desc) {
503
-		return false;
504
-	}
499
+    $table = table_objet($type);
500
+    $trouver_table = charger_fonction('trouver_table', 'base');
501
+    $desc = $trouver_table($table);
502
+    if (!$desc) {
503
+        return false;
504
+    }
505 505
 	
506
-	if (!isset($opt['statut'])) {
507
-		if (isset($desc['field']['statut'])) {
508
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
509
-		} else {
510
-			$statut = 'publie';
511
-		} // pas de statut => publie
512
-	} else {
513
-		$statut = $opt['statut'];
514
-	}
506
+    if (!isset($opt['statut'])) {
507
+        if (isset($desc['field']['statut'])) {
508
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
509
+        } else {
510
+            $statut = 'publie';
511
+        } // pas de statut => publie
512
+    } else {
513
+        $statut = $opt['statut'];
514
+    }
515 515
 	
516
-	// Liste des statuts publiés pour cet objet
517
-	if (isset($desc['statut'][0]['publie'])) {
518
-		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
519
-	}
520
-	// Sinon en dur le statut "publie"
521
-	else {
522
-		$statuts_publies = array('publie');
523
-	}
516
+    // Liste des statuts publiés pour cet objet
517
+    if (isset($desc['statut'][0]['publie'])) {
518
+        $statuts_publies = explode(',', $desc['statut'][0]['publie']);
519
+    }
520
+    // Sinon en dur le statut "publie"
521
+    else {
522
+        $statuts_publies = array('publie');
523
+    }
524 524
 	
525
-	if (
526
-		in_array($statut, $statuts_publies)
527
-		// Ou cas particulier géré en dur ici pour les articles
528
-		or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
529
-	) {
530
-		return autoriser('modifier', $type, $id);
531
-	}
525
+    if (
526
+        in_array($statut, $statuts_publies)
527
+        // Ou cas particulier géré en dur ici pour les articles
528
+        or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
529
+    ) {
530
+        return autoriser('modifier', $type, $id);
531
+    }
532 532
 
533
-	return false;
533
+    return false;
534 534
 }
535 535
 
536 536
 /**
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
  * @return bool          true s'il a le droit, false sinon
548 548
  **/
549 549
 function autoriser_instituer_dist($faire, $type, $id, $qui, $opt) {
550
-	return autoriser('modifier', $type, $id, $qui, $opt);
550
+    return autoriser('modifier', $type, $id, $qui, $opt);
551 551
 }
552 552
 
553 553
 /**
@@ -563,12 +563,12 @@  discard block
 block discarded – undo
563 563
  * @return bool          true s'il a le droit, false sinon
564 564
  **/
565 565
 function autoriser_rubrique_publierdans_dist($faire, $type, $id, $qui, $opt) {
566
-	return
567
-		($qui['statut'] == '0minirezo')
568
-		and (
569
-			!$qui['restreint'] or !$id
570
-			or in_array($id, $qui['restreint'])
571
-		);
566
+    return
567
+        ($qui['statut'] == '0minirezo')
568
+        and (
569
+            !$qui['restreint'] or !$id
570
+            or in_array($id, $qui['restreint'])
571
+        );
572 572
 }
573 573
 
574 574
 /**
@@ -584,10 +584,10 @@  discard block
 block discarded – undo
584 584
  * @return bool          true s'il a le droit, false sinon
585 585
  **/
586 586
 function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) {
587
-	return
588
-		((!$id and autoriser('defaut', null, null, $qui, $opt))
589
-			or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
590
-		);
587
+    return
588
+        ((!$id and autoriser('defaut', null, null, $qui, $opt))
589
+            or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
590
+        );
591 591
 }
592 592
 
593 593
 /**
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
  * @return bool          true s'il a le droit, false sinon
604 604
  **/
605 605
 function autoriser_rubrique_creerrubriquedans_dist($faire, $type, $id, $qui, $opt) {
606
-	return
607
-		($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
608
-		and autoriser('voir', 'rubrique', $id)
609
-		and autoriser('publierdans', 'rubrique', $id);
606
+    return
607
+        ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
608
+        and autoriser('voir', 'rubrique', $id)
609
+        and autoriser('publierdans', 'rubrique', $id);
610 610
 }
611 611
 
612 612
 /**
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
  * @return bool          true s'il a le droit, false sinon
623 623
  **/
624 624
 function autoriser_rubrique_creerarticledans_dist($faire, $type, $id, $qui, $opt) {
625
-	return
626
-		$id
627
-		and autoriser('voir', 'rubrique', $id)
628
-		and autoriser('creer', 'article');
625
+    return
626
+        $id
627
+        and autoriser('voir', 'rubrique', $id)
628
+        and autoriser('creer', 'article');
629 629
 }
630 630
 
631 631
 
@@ -642,8 +642,8 @@  discard block
 block discarded – undo
642 642
  * @return bool          true s'il a le droit, false sinon
643 643
  **/
644 644
 function autoriser_rubrique_modifier_dist($faire, $type, $id, $qui, $opt) {
645
-	return
646
-		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
645
+    return
646
+        autoriser('publierdans', 'rubrique', $id, $qui, $opt);
647 647
 }
648 648
 
649 649
 /**
@@ -659,29 +659,29 @@  discard block
 block discarded – undo
659 659
  * @return bool          true s'il a le droit, false sinon
660 660
  **/
661 661
 function autoriser_rubrique_supprimer_dist($faire, $type, $id, $qui, $opt) {
662
-	if (!$id = intval($id)) {
663
-		return false;
664
-	}
662
+    if (!$id = intval($id)) {
663
+        return false;
664
+    }
665 665
 
666
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
667
-		return false;
668
-	}
666
+    if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
667
+        return false;
668
+    }
669 669
 
670
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
671
-		return false;
672
-	}
670
+    if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
671
+        return false;
672
+    }
673 673
 
674
-	$compte = pipeline(
675
-		'objet_compte_enfants',
676
-		array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
677
-	);
678
-	foreach ($compte as $objet => $n) {
679
-		if ($n) {
680
-			return false;
681
-		}
682
-	}
674
+    $compte = pipeline(
675
+        'objet_compte_enfants',
676
+        array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
677
+    );
678
+    foreach ($compte as $objet => $n) {
679
+        if ($n) {
680
+            return false;
681
+        }
682
+    }
683 683
 
684
-	return autoriser('modifier', 'rubrique', $id);
684
+    return autoriser('modifier', 'rubrique', $id);
685 685
 }
686 686
 
687 687
 
@@ -699,20 +699,20 @@  discard block
 block discarded – undo
699 699
  * @return bool          true s'il a le droit, false sinon
700 700
  **/
701 701
 function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
702
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
702
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
703 703
 
704
-	return
705
-		$r
706
-		and
707
-		(
708
-			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
709
-			or (
710
-				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
711
-				and in_array($qui['statut'], array('0minirezo', '1comite'))
712
-				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
714
-			)
715
-		);
704
+    return
705
+        $r
706
+        and
707
+        (
708
+            autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
709
+            or (
710
+                (!isset($opt['statut']) or $opt['statut'] !== 'publie')
711
+                and in_array($qui['statut'], array('0minirezo', '1comite'))
712
+                and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
+                and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
714
+            )
715
+        );
716 716
 }
717 717
 
718 718
 /**
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
  * @return bool          true s'il a le droit, false sinon
729 729
  **/
730 730
 function autoriser_article_creer_dist($faire, $type, $id, $qui, $opt) {
731
-	return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
731
+    return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
732 732
 }
733 733
 
734 734
 /**
@@ -748,28 +748,28 @@  discard block
 block discarded – undo
748 748
  * @return bool          true s'il a le droit, false sinon
749 749
  */
750 750
 function autoriser_article_voir_dist($faire, $type, $id, $qui, $opt) {
751
-	if ($qui['statut'] == '0minirezo') {
752
-		return true;
753
-	}
754
-	// cas des articles : depend du statut de l'article et de l'auteur
755
-	if (isset($opt['statut'])) {
756
-		$statut = $opt['statut'];
757
-	} else {
758
-		if (!$id) {
759
-			return false;
760
-		}
761
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
762
-	}
763
-
764
-	return
765
-		// si on est pas auteur de l'article,
766
-		// seuls les propose et publies sont visibles
767
-		in_array($statut, array('prop', 'publie'))
768
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
769
-		or
770
-		($id
771
-			and $qui['id_auteur']
772
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
751
+    if ($qui['statut'] == '0minirezo') {
752
+        return true;
753
+    }
754
+    // cas des articles : depend du statut de l'article et de l'auteur
755
+    if (isset($opt['statut'])) {
756
+        $statut = $opt['statut'];
757
+    } else {
758
+        if (!$id) {
759
+            return false;
760
+        }
761
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
762
+    }
763
+
764
+    return
765
+        // si on est pas auteur de l'article,
766
+        // seuls les propose et publies sont visibles
767
+        in_array($statut, array('prop', 'publie'))
768
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
769
+        or
770
+        ($id
771
+            and $qui['id_auteur']
772
+            and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
773 773
 }
774 774
 
775 775
 
@@ -786,22 +786,22 @@  discard block
 block discarded – undo
786 786
  * @return bool          true s'il a le droit, false sinon
787 787
  **/
788 788
 function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
789
-	# securite, mais on aurait pas du arriver ici !
790
-	if (function_exists($f = 'autoriser_' . $type . '_voir')
791
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
792
-		return $f($faire, $type, $id, $qui, $opt);
793
-	}
789
+    # securite, mais on aurait pas du arriver ici !
790
+    if (function_exists($f = 'autoriser_' . $type . '_voir')
791
+        or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
792
+        return $f($faire, $type, $id, $qui, $opt);
793
+    }
794 794
 
795
-	if ($qui['statut'] == '0minirezo') {
796
-		return true;
797
-	}
798
-	// admins et redacteurs peuvent voir un auteur
799
-	if ($type == 'auteur') {
800
-		return in_array($qui['statut'], array('0minirezo', '1comite'));
801
-	}
802
-	// sinon par defaut tout est visible
803
-	// sauf cas particuliers traites separemment (ie article)
804
-	return true;
795
+    if ($qui['statut'] == '0minirezo') {
796
+        return true;
797
+    }
798
+    // admins et redacteurs peuvent voir un auteur
799
+    if ($type == 'auteur') {
800
+        return in_array($qui['statut'], array('0minirezo', '1comite'));
801
+    }
802
+    // sinon par defaut tout est visible
803
+    // sauf cas particuliers traites separemment (ie article)
804
+    return true;
805 805
 }
806 806
 
807 807
 
@@ -822,12 +822,12 @@  discard block
 block discarded – undo
822 822
  * @return bool          true s'il a le droit, false sinon
823 823
  **/
824 824
 function autoriser_webmestre_dist($faire, $type, $id, $qui, $opt) {
825
-	return
826
-		(defined('_ID_WEBMESTRES') ?
827
-			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
828
-			: $qui['webmestre'] == 'oui')
829
-		and $qui['statut'] == '0minirezo'
830
-		and !$qui['restreint'];
825
+    return
826
+        (defined('_ID_WEBMESTRES') ?
827
+            in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
828
+            : $qui['webmestre'] == 'oui')
829
+        and $qui['statut'] == '0minirezo'
830
+        and !$qui['restreint'];
831 831
 }
832 832
 
833 833
 /**
@@ -843,9 +843,9 @@  discard block
 block discarded – undo
843 843
  * @return bool          true s'il a le droit, false sinon
844 844
  **/
845 845
 function autoriser_configurer_dist($faire, $type, $id, $qui, $opt) {
846
-	return
847
-		$qui['statut'] == '0minirezo'
848
-		and !$qui['restreint'];
846
+    return
847
+        $qui['statut'] == '0minirezo'
848
+        and !$qui['restreint'];
849 849
 }
850 850
 
851 851
 /**
@@ -861,8 +861,8 @@  discard block
 block discarded – undo
861 861
  * @return bool          true s'il a le droit, false sinon
862 862
  **/
863 863
 function autoriser_sauvegarder_dist($faire, $type, $id, $qui, $opt) {
864
-	return
865
-		$qui['statut'] == '0minirezo';
864
+    return
865
+        $qui['statut'] == '0minirezo';
866 866
 }
867 867
 
868 868
 /**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
  * @return bool          true s'il a le droit, false sinon
879 879
  **/
880 880
 function autoriser_detruire_dist($faire, $type, $id, $qui, $opt) {
881
-	return
882
-		autoriser('webmestre', null, null, $qui, $opt);
881
+    return
882
+        autoriser('webmestre', null, null, $qui, $opt);
883 883
 }
884 884
 
885 885
 /**
@@ -896,20 +896,20 @@  discard block
 block discarded – undo
896 896
  * @return bool          true s'il a le droit, false sinon
897 897
  **/
898 898
 function autoriser_auteur_previsualiser_dist($faire, $type, $id, $qui, $opt) {
899
-	// les admins peuvent "previsualiser" une page auteur
900
-	if ($qui['statut'] == '0minirezo'
901
-		and !$qui['restreint']
902
-	) {
903
-		return true;
904
-	}
905
-	// "Voir en ligne" si l'auteur a un article publie
906
-	$n = sql_fetsel(
907
-		'A.id_article',
908
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
910
-	);
899
+    // les admins peuvent "previsualiser" une page auteur
900
+    if ($qui['statut'] == '0minirezo'
901
+        and !$qui['restreint']
902
+    ) {
903
+        return true;
904
+    }
905
+    // "Voir en ligne" si l'auteur a un article publie
906
+    $n = sql_fetsel(
907
+        'A.id_article',
908
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
910
+    );
911 911
 
912
-	return $n ? true : false;
912
+    return $n ? true : false;
913 913
 }
914 914
 
915 915
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @return bool          true s'il a le droit, false sinon
938 938
  **/
939 939
 function autoriser_auteur_creer_dist($faire, $type, $id, $qui, $opt) {
940
-	return ($qui['statut'] == '0minirezo');
940
+    return ($qui['statut'] == '0minirezo');
941 941
 }
942 942
 
943 943
 
@@ -957,78 +957,78 @@  discard block
 block discarded – undo
957 957
  **/
958 958
 function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) {
959 959
 
960
-	// Ni admin ni redacteur => non
961
-	if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
962
-		return false;
963
-	}
964
-
965
-	// Un redacteur peut modifier ses propres donnees mais ni son login/email
966
-	// ni son statut (qui sont le cas echeant passes comme option)
967
-	if ($qui['statut'] == '1comite') {
968
-		if (!empty($opt['webmestre'])) {
969
-			return false;
970
-		} elseif (
971
-			!empty($opt['statut'])
972
-			or !empty($opt['restreintes'])
973
-			or !empty($opt['email'])
974
-		) {
975
-			return false;
976
-		} elseif ($id == $qui['id_auteur']) {
977
-			return true;
978
-		} else {
979
-			return false;
980
-		}
981
-	}
982
-
983
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
984
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
985
-	if ($qui['restreint']) {
986
-		if (isset($opt['webmestre']) and $opt['webmestre']) {
987
-			return false;
988
-		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
989
-			or (isset($opt['restreintes']) and $opt['restreintes'])
990
-		) {
991
-			return false;
992
-		} else {
993
-			if ($id == $qui['id_auteur']) {
994
-				if (isset($opt['statut']) and $opt['statut']) {
995
-					return false;
996
-				} else {
997
-					return true;
998
-				}
999
-			} else {
1000
-				if ($id_auteur = intval($id)) {
1001
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1002
-					if ($t and $t['statut'] != '0minirezo') {
1003
-						return true;
1004
-					} else {
1005
-						return false;
1006
-					}
1007
-				} // id = 0 => creation
1008
-				else {
1009
-					return true;
1010
-				}
1011
-			}
1012
-		}
1013
-	}
1014
-
1015
-	// Un admin complet fait ce qu'il veut
1016
-	// sauf se degrader
1017
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1018
-		return false;
1019
-	} elseif (isset($opt['webmestre'])
1020
-				and $opt['webmestre']
1021
-				and (defined('_ID_WEBMESTRES')
1022
-				or !autoriser('webmestre'))) {
1023
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1024
-		// ou si les webmestres sont fixes par constante (securite)
1025
-		return false;
1026
-	} // et modifier un webmestre si il ne l'est pas lui meme
1027
-	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1028
-		return false;
1029
-	} else {
1030
-		return true;
1031
-	}
960
+    // Ni admin ni redacteur => non
961
+    if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
962
+        return false;
963
+    }
964
+
965
+    // Un redacteur peut modifier ses propres donnees mais ni son login/email
966
+    // ni son statut (qui sont le cas echeant passes comme option)
967
+    if ($qui['statut'] == '1comite') {
968
+        if (!empty($opt['webmestre'])) {
969
+            return false;
970
+        } elseif (
971
+            !empty($opt['statut'])
972
+            or !empty($opt['restreintes'])
973
+            or !empty($opt['email'])
974
+        ) {
975
+            return false;
976
+        } elseif ($id == $qui['id_auteur']) {
977
+            return true;
978
+        } else {
979
+            return false;
980
+        }
981
+    }
982
+
983
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
984
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
985
+    if ($qui['restreint']) {
986
+        if (isset($opt['webmestre']) and $opt['webmestre']) {
987
+            return false;
988
+        } elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
989
+            or (isset($opt['restreintes']) and $opt['restreintes'])
990
+        ) {
991
+            return false;
992
+        } else {
993
+            if ($id == $qui['id_auteur']) {
994
+                if (isset($opt['statut']) and $opt['statut']) {
995
+                    return false;
996
+                } else {
997
+                    return true;
998
+                }
999
+            } else {
1000
+                if ($id_auteur = intval($id)) {
1001
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1002
+                    if ($t and $t['statut'] != '0minirezo') {
1003
+                        return true;
1004
+                    } else {
1005
+                        return false;
1006
+                    }
1007
+                } // id = 0 => creation
1008
+                else {
1009
+                    return true;
1010
+                }
1011
+            }
1012
+        }
1013
+    }
1014
+
1015
+    // Un admin complet fait ce qu'il veut
1016
+    // sauf se degrader
1017
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1018
+        return false;
1019
+    } elseif (isset($opt['webmestre'])
1020
+                and $opt['webmestre']
1021
+                and (defined('_ID_WEBMESTRES')
1022
+                or !autoriser('webmestre'))) {
1023
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1024
+        // ou si les webmestres sont fixes par constante (securite)
1025
+        return false;
1026
+    } // et modifier un webmestre si il ne l'est pas lui meme
1027
+    elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1028
+        return false;
1029
+    } else {
1030
+        return true;
1031
+    }
1032 1032
 }
1033 1033
 
1034 1034
 
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
  * @return bool          true s'il a le droit, false sinon
1046 1046
  **/
1047 1047
 function autoriser_associerauteurs_dist($faire, $type, $id, $qui, $opt) {
1048
-	return autoriser('modifier', $type, $id, $qui, $opt);
1048
+    return autoriser('modifier', $type, $id, $qui, $opt);
1049 1049
 }
1050 1050
 
1051 1051
 
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
  * @return bool          true s'il a le droit, false sinon
1063 1063
  **/
1064 1064
 function autoriser_chargerftp_dist($faire, $type, $id, $qui, $opt) {
1065
-	return $qui['statut'] == '0minirezo';
1065
+    return $qui['statut'] == '0minirezo';
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
  * @return bool          true s'il a le droit, false sinon
1079 1079
  **/
1080 1080
 function autoriser_debug_dist($faire, $type, $id, $qui, $opt) {
1081
-	return $qui['statut'] == '0minirezo';
1081
+    return $qui['statut'] == '0minirezo';
1082 1082
 }
1083 1083
 
1084 1084
 /**
@@ -1095,52 +1095,52 @@  discard block
 block discarded – undo
1095 1095
  * @return array          Liste des rubriques
1096 1096
  **/
1097 1097
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1098
-	static $restreint = array();
1099
-
1100
-	if (!$id_auteur = intval($id_auteur)) {
1101
-		return array();
1102
-	}
1103
-	if ($raz) {
1104
-		unset($restreint[$id_auteur]);
1105
-	} elseif (isset($restreint[$id_auteur])) {
1106
-		return $restreint[$id_auteur];
1107
-	}
1108
-
1109
-	$rubriques = array();
1110
-	if ((!isset($GLOBALS['meta']['version_installee'])
1111
-		or $GLOBALS['meta']['version_installee'] > 16428)
1112
-		and $r = sql_allfetsel(
1113
-			'id_objet',
1114
-			'spip_auteurs_liens',
1115
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1116
-		)
1117
-		and count($r)
1118
-	) {
1119
-		$r = array_column($r, 'id_objet');
1120
-
1121
-		// recuperer toute la branche, au format chaine enumeration
1122
-		include_spip('inc/rubriques');
1123
-		$r = calcul_branche_in($r);
1124
-		$r = explode(',', $r);
1125
-
1126
-		// passer les rubriques en index, elimine les doublons
1127
-		$r = array_flip($r);
1128
-		// recuperer les index seuls
1129
-		$r = array_keys($r);
1130
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1131
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1132
-		$rubriques = array_combine($r, $r);
1133
-	}
1134
-
1135
-	// Affecter l'auteur session le cas echeant
1136
-	if (isset($GLOBALS['visiteur_session']['id_auteur'])
1137
-		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1138
-	) {
1139
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1140
-	}
1141
-
1142
-
1143
-	return $restreint[$id_auteur] = $rubriques;
1098
+    static $restreint = array();
1099
+
1100
+    if (!$id_auteur = intval($id_auteur)) {
1101
+        return array();
1102
+    }
1103
+    if ($raz) {
1104
+        unset($restreint[$id_auteur]);
1105
+    } elseif (isset($restreint[$id_auteur])) {
1106
+        return $restreint[$id_auteur];
1107
+    }
1108
+
1109
+    $rubriques = array();
1110
+    if ((!isset($GLOBALS['meta']['version_installee'])
1111
+        or $GLOBALS['meta']['version_installee'] > 16428)
1112
+        and $r = sql_allfetsel(
1113
+            'id_objet',
1114
+            'spip_auteurs_liens',
1115
+            'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1116
+        )
1117
+        and count($r)
1118
+    ) {
1119
+        $r = array_column($r, 'id_objet');
1120
+
1121
+        // recuperer toute la branche, au format chaine enumeration
1122
+        include_spip('inc/rubriques');
1123
+        $r = calcul_branche_in($r);
1124
+        $r = explode(',', $r);
1125
+
1126
+        // passer les rubriques en index, elimine les doublons
1127
+        $r = array_flip($r);
1128
+        // recuperer les index seuls
1129
+        $r = array_keys($r);
1130
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1131
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1132
+        $rubriques = array_combine($r, $r);
1133
+    }
1134
+
1135
+    // Affecter l'auteur session le cas echeant
1136
+    if (isset($GLOBALS['visiteur_session']['id_auteur'])
1137
+        and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1138
+    ) {
1139
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1140
+    }
1141
+
1142
+
1143
+    return $restreint[$id_auteur] = $rubriques;
1144 1144
 }
1145 1145
 
1146 1146
 /**
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
  * @return bool          true s'il a le droit, false sinon
1157 1157
  **/
1158 1158
 function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) {
1159
-	return autoriser('previsualiser');
1159
+    return autoriser('previsualiser');
1160 1160
 }
1161 1161
 
1162 1162
 /**
@@ -1172,7 +1172,7 @@  discard block
 block discarded – undo
1172 1172
  * @return bool          true s'il a le droit, false sinon
1173 1173
  **/
1174 1174
 function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) {
1175
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1175
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1188,8 +1188,8 @@  discard block
 block discarded – undo
1188 1188
  * @return bool          true s'il a le droit, false sinon
1189 1189
  **/
1190 1190
 function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) {
1191
-	return (($id == $qui['id_auteur']) or
1192
-		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1191
+    return (($id == $qui['id_auteur']) or
1192
+        (($qui['statut'] == '0minirezo') and !$qui['restreint']));
1193 1193
 }
1194 1194
 
1195 1195
 /**
@@ -1205,8 +1205,8 @@  discard block
 block discarded – undo
1205 1205
  * @return bool          true s'il a le droit, false sinon
1206 1206
  **/
1207 1207
 function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) {
1208
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1209
-	return autoriser('modifier', $type, $id, $qui, $opt);
1208
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1209
+    return autoriser('modifier', $type, $id, $qui, $opt);
1210 1210
 }
1211 1211
 
1212 1212
 
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
  * @return bool          true
1225 1225
  **/
1226 1226
 function autoriser_ok_dist($faire, $type, $id, $qui, $opt) {
1227
-	return true;
1227
+    return true;
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
  * @return bool          false
1242 1242
  **/
1243 1243
 function autoriser_niet_dist($faire, $type, $id, $qui, $opt) {
1244
-	return false;
1244
+    return false;
1245 1245
 }
1246 1246
 
1247 1247
 /**
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  * @return bool          false
1258 1258
  **/
1259 1259
 function autoriser_base_reparer_dist($faire, $type, $id, $qui, $opt) {
1260
-	if (!autoriser('detruire') or _request('reinstall')) {
1261
-		return false;
1262
-	}
1260
+    if (!autoriser('detruire') or _request('reinstall')) {
1261
+        return false;
1262
+    }
1263 1263
 
1264
-	return true;
1264
+    return true;
1265 1265
 }
1266 1266
 
1267 1267
 /**
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
  * @return bool          true s'il a le droit, false sinon
1278 1278
  **/
1279 1279
 function autoriser_infosperso_dist($faire, $type, $id, $qui, $opt) {
1280
-	return true;
1280
+    return true;
1281 1281
 }
1282 1282
 
1283 1283
 /**
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
  * @return bool          true s'il a le droit, false sinon
1294 1294
  **/
1295 1295
 function autoriser_langage_configurer_dist($faire, $type, $id, $qui, $opt) {
1296
-	return true;
1296
+    return true;
1297 1297
 }
1298 1298
 
1299 1299
 /**
@@ -1309,7 +1309,7 @@  discard block
 block discarded – undo
1309 1309
  * @return bool          true s'il a le droit, false sinon
1310 1310
  **/
1311 1311
 function autoriser_configurerlangage_dist($faire, $type, $id, $qui, $opt) {
1312
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1312
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1313 1313
 }
1314 1314
 
1315 1315
 /**
@@ -1325,7 +1325,7 @@  discard block
 block discarded – undo
1325 1325
  * @return bool          true s'il a le droit, false sinon
1326 1326
  **/
1327 1327
 function autoriser_preferences_configurer_dist($faire, $type, $id, $qui, $opt) {
1328
-	return true;
1328
+    return true;
1329 1329
 }
1330 1330
 
1331 1331
 /**
@@ -1341,7 +1341,7 @@  discard block
 block discarded – undo
1341 1341
  * @return bool          true s'il a le droit, false sinon
1342 1342
  **/
1343 1343
 function autoriser_configurerpreferences_dist($faire, $type, $id, $qui, $opt) {
1344
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1344
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1345 1345
 }
1346 1346
 
1347 1347
 /**
@@ -1357,8 +1357,8 @@  discard block
 block discarded – undo
1357 1357
  * @return bool          true s'il a le droit, false sinon
1358 1358
  **/
1359 1359
 function autoriser_menudeveloppement_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1360
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1361
-		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1360
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1361
+        and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1362 1362
 }
1363 1363
 
1364 1364
 /**
@@ -1375,7 +1375,7 @@  discard block
 block discarded – undo
1375 1375
  * @return bool          true s'il a le droit, false sinon
1376 1376
  **/
1377 1377
 function autoriser_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1378
-	return true;
1378
+    return true;
1379 1379
 }
1380 1380
 
1381 1381
 /**
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
  * @return bool          true s'il a le droit, false sinon
1392 1392
  **/
1393 1393
 function autoriser_auteurs_voir_dist($faire, $type, $id, $qui, $opt) {
1394
-	return true;
1394
+    return true;
1395 1395
 }
1396 1396
 
1397 1397
 /**
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
  * @return bool          true s'il a le droit, false sinon
1408 1408
  **/
1409 1409
 function autoriser_auteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1410
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1410
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1411 1411
 }
1412 1412
 
1413 1413
 /**
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
  * @return bool          true s'il a le droit, false sinon
1424 1424
  **/
1425 1425
 function autoriser_articles_voir_dist($faire, $type, $id, $qui, $opt) {
1426
-	return true;
1426
+    return true;
1427 1427
 }
1428 1428
 
1429 1429
 /**
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
  * @return bool          true s'il a le droit, false sinon
1440 1440
  **/
1441 1441
 function autoriser_articles_menu_dist($faire, $type, $id, $qui, $opt) {
1442
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1442
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1443 1443
 }
1444 1444
 
1445 1445
 /**
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
  * @return bool          true s'il a le droit, false sinon
1456 1456
  **/
1457 1457
 function autoriser_rubriques_voir_dist($faire, $type, $id, $qui, $opt) {
1458
-	return true;
1458
+    return true;
1459 1459
 }
1460 1460
 
1461 1461
 /**
@@ -1471,7 +1471,7 @@  discard block
 block discarded – undo
1471 1471
  * @return bool          true s'il a le droit, false sinon
1472 1472
  **/
1473 1473
 function autoriser_rubriques_menu_dist($faire, $type, $id, $qui, $opt) {
1474
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1474
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1475 1475
 }
1476 1476
 
1477 1477
 /**
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
  * @return bool          true s'il a le droit, false sinon
1488 1488
  **/
1489 1489
 function autoriser_articlecreer_menu_dist($faire, $type, $id, $qui, $opt) {
1490
-	return verifier_table_non_vide();
1490
+    return verifier_table_non_vide();
1491 1491
 }
1492 1492
 
1493 1493
 
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
  * @return bool          true s'il a le droit, false sinon
1507 1507
  **/
1508 1508
 function autoriser_auteurcreer_menu_dist($faire, $type, $id, $qui, $opt) {
1509
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1509
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1510 1510
 }
1511 1511
 
1512 1512
 /**
@@ -1522,13 +1522,13 @@  discard block
 block discarded – undo
1522 1522
  * @return bool          true s'il a le droit, false sinon
1523 1523
  **/
1524 1524
 function autoriser_visiteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1525
-	include_spip('base/abstract_sql');
1526
-	return 
1527
-		$qui['statut'] == '0minirezo' and !$qui['restreint']
1528
-		and (
1529
-			$GLOBALS['meta']["accepter_visiteurs"] != 'non'
1530
-			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1531
-		);
1525
+    include_spip('base/abstract_sql');
1526
+    return 
1527
+        $qui['statut'] == '0minirezo' and !$qui['restreint']
1528
+        and (
1529
+            $GLOBALS['meta']["accepter_visiteurs"] != 'non'
1530
+            or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1531
+        );
1532 1532
 }
1533 1533
 
1534 1534
 /**
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
  * @return bool          true s'il a le droit, false sinon
1545 1545
  **/
1546 1546
 function autoriser_suiviedito_menu_dist($faire, $type, $id, $qui, $opt) {
1547
-	return $qui['statut'] == '0minirezo';
1547
+    return $qui['statut'] == '0minirezo';
1548 1548
 }
1549 1549
 
1550 1550
 /**
@@ -1560,7 +1560,7 @@  discard block
 block discarded – undo
1560 1560
  * @return bool          true s'il a le droit, false sinon
1561 1561
  **/
1562 1562
 function autoriser_synchro_menu_dist($faire, $type, $id, $qui, $opt) {
1563
-	return $qui['statut'] == '0minirezo';
1563
+    return $qui['statut'] == '0minirezo';
1564 1564
 }
1565 1565
 
1566 1566
 /**
@@ -1688,7 +1688,7 @@  discard block
 block discarded – undo
1688 1688
  * @return bool          true s'il a le droit, false sinon
1689 1689
  **/
1690 1690
 function autoriser_queue_purger_dist($faire, $type, $id, $qui, $opt) {
1691
-	return autoriser('webmestre');
1691
+    return autoriser('webmestre');
1692 1692
 }
1693 1693
 
1694 1694
 
@@ -1706,11 +1706,11 @@  discard block
 block discarded – undo
1706 1706
  * @return bool          true s'il a le droit, false sinon
1707 1707
  **/
1708 1708
 function autoriser_echafauder_dist($faire, $type, $id, $qui, $opt) {
1709
-	if (test_espace_prive()) {
1710
-		return intval($qui['id_auteur']) ? true : false;
1711
-	} else {
1712
-		return autoriser('webmestre', '', $id, $qui, $opt);
1713
-	}
1709
+    if (test_espace_prive()) {
1710
+        return intval($qui['id_auteur']) ? true : false;
1711
+    } else {
1712
+        return autoriser('webmestre', '', $id, $qui, $opt);
1713
+    }
1714 1714
 }
1715 1715
 
1716 1716
 
@@ -1725,27 +1725,27 @@  discard block
 block discarded – undo
1725 1725
  *     Identifiants d'auteurs
1726 1726
  */
1727 1727
 function auteurs_objet($objet, $id_objet, $cond = '') {
1728
-	$objet = objet_type($objet);
1729
-	$where = array(
1730
-		'objet=' . sql_quote($objet),
1731
-		'id_objet=' . intval($id_objet)
1732
-	);
1733
-	if (!empty($cond)) {
1734
-		if (is_array($cond)) {
1735
-			$where = array_merge($where, $cond);
1736
-		} else {
1737
-			$where[] = $cond;
1738
-		}
1739
-	}
1740
-	$auteurs = sql_allfetsel(
1741
-		'id_auteur',
1742
-		'spip_auteurs_liens',
1743
-		$where
1744
-	);
1745
-	if (is_array($auteurs)) {
1746
-		return array_column($auteurs, 'id_auteur');
1747
-	}
1748
-	return array();
1728
+    $objet = objet_type($objet);
1729
+    $where = array(
1730
+        'objet=' . sql_quote($objet),
1731
+        'id_objet=' . intval($id_objet)
1732
+    );
1733
+    if (!empty($cond)) {
1734
+        if (is_array($cond)) {
1735
+            $where = array_merge($where, $cond);
1736
+        } else {
1737
+            $where[] = $cond;
1738
+        }
1739
+    }
1740
+    $auteurs = sql_allfetsel(
1741
+        'id_auteur',
1742
+        'spip_auteurs_liens',
1743
+        $where
1744
+    );
1745
+    if (is_array($auteurs)) {
1746
+        return array_column($auteurs, 'id_auteur');
1747
+    }
1748
+    return array();
1749 1749
 }
1750 1750
 
1751 1751
 /**
@@ -1759,11 +1759,11 @@  discard block
 block discarded – undo
1759 1759
  *     - false : serveur SQL indisponible
1760 1760
  */
1761 1761
 function auteurs_article($id_article, $cond = '') {
1762
-	return sql_allfetsel(
1763
-		'id_auteur',
1764
-		'spip_auteurs_liens',
1765
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1766
-	);
1762
+    return sql_allfetsel(
1763
+        'id_auteur',
1764
+        'spip_auteurs_liens',
1765
+        "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1766
+    );
1767 1767
 }
1768 1768
 
1769 1769
 
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
  */
1778 1778
 function acces_restreint_rubrique($id_rubrique) {
1779 1779
 
1780
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1780
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1781 1781
 }
1782 1782
 
1783 1783
 
@@ -1790,12 +1790,12 @@  discard block
 block discarded – undo
1790 1790
  * @return bool             true si un parent existe
1791 1791
  */
1792 1792
 function verifier_table_non_vide($table = 'spip_rubriques') {
1793
-	static $done = array();
1794
-	if (!isset($done[$table])) {
1795
-		$done[$table] = sql_countsel($table) > 0;
1796
-	}
1793
+    static $done = array();
1794
+    if (!isset($done[$table])) {
1795
+        $done[$table] = sql_countsel($table) > 0;
1796
+    }
1797 1797
 
1798
-	return $done[$table];
1798
+    return $done[$table];
1799 1799
 }
1800 1800
 
1801 1801
 /**
@@ -1820,15 +1820,15 @@  discard block
 block discarded – undo
1820 1820
  */
1821 1821
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
1822 1822
 
1823
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1824
-	switch ($s) {
1825
-		case 'info_redacteurs':
1826
-			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1827
-		case 'info_visiteurs':
1828
-			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1829
-	}
1823
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1824
+    switch ($s) {
1825
+        case 'info_redacteurs':
1826
+            return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1827
+        case 'info_visiteurs':
1828
+            return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1829
+    }
1830 1830
 
1831
-	return false;
1831
+    return false;
1832 1832
 }
1833 1833
 
1834 1834
 
@@ -1845,5 +1845,5 @@  discard block
 block discarded – undo
1845 1845
  * @return bool          true s'il a le droit, false sinon
1846 1846
  **/
1847 1847
 function autoriser_phpinfos_dist($faire, $type, $id, $qui, $opt) {
1848
-	return autoriser('webmestre');
1848
+    return autoriser('webmestre');
1849 1849
 }
Please login to merge, or discard this patch.