Completed
Push — master ( 2b3d16...1fc530 )
by cam
04:16
created
ecrire/inc/filtres.php 1 patch
Indentation   +2011 added lines, -2011 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_spip('public/parametrer'); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-
96
-	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
-		// fonction ou name\space\fonction
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
-			return $f;
106
-		}
107
-	}
108
-
109
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+
96
+    include_fichiers_fonctions();
97
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
+        // fonction ou name\space\fonction
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
+            return $f;
106
+        }
107
+    }
108
+
109
+    return $default;
110 110
 }
111 111
 
112 112
 /**
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
  *     Chaîne vide sinon (filtre introuvable).
131 131
  **/
132 132
 function appliquer_filtre($arg, $filtre, $force = null) {
133
-	$f = chercher_filtre($filtre);
134
-	if (!$f) {
135
-		if (!$force) {
136
-			return '';
137
-		} else {
138
-			return $arg;
139
-		}
140
-	}
133
+    $f = chercher_filtre($filtre);
134
+    if (!$f) {
135
+        if (!$force) {
136
+            return '';
137
+        } else {
138
+            return $arg;
139
+        }
140
+    }
141 141
 
142
-	$args = func_get_args();
143
-	array_shift($args); // enlever $arg
144
-	array_shift($args); // enlever $filtre
145
-	array_unshift($args, $arg); // remettre $arg
146
-	return call_user_func_array($f, $args);
142
+    $args = func_get_args();
143
+    array_shift($args); // enlever $arg
144
+    array_shift($args); // enlever $filtre
145
+    array_unshift($args, $arg); // remettre $arg
146
+    return call_user_func_array($f, $args);
147 147
 }
148 148
 
149 149
 /**
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
  *     Version de SPIP
160 160
  **/
161 161
 function spip_version() {
162
-	$version = $GLOBALS['spip_version_affichee'];
163
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
164
-		$version .= " $vcs_version";
165
-	}
162
+    $version = $GLOBALS['spip_version_affichee'];
163
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
164
+        $version .= " $vcs_version";
165
+    }
166 166
 
167
-	return $version;
167
+    return $version;
168 168
 }
169 169
 
170 170
 /**
@@ -177,19 +177,19 @@  discard block
 block discarded – undo
177 177
  *    - string|null si $raw = false
178 178
  */
179 179
 function version_vcs_courante($dir, $raw = false) {
180
-	$desc = decrire_version_git($dir);
181
-	if ($desc === null) {
182
-		$desc = decrire_version_svn($dir);
183
-	}
184
-	if ($desc === null or $raw) {
185
-		return $desc;
186
-	}
187
-	// affichage "GIT [master: abcdef]"
188
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
189
-	if ($desc['branch']) {
190
-		$commit = $desc['branch'] . ': ' . $commit;
191
-	}
192
-	return "{$desc['vcs']} [$commit]";
180
+    $desc = decrire_version_git($dir);
181
+    if ($desc === null) {
182
+        $desc = decrire_version_svn($dir);
183
+    }
184
+    if ($desc === null or $raw) {
185
+        return $desc;
186
+    }
187
+    // affichage "GIT [master: abcdef]"
188
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
189
+    if ($desc['branch']) {
190
+        $commit = $desc['branch'] . ': ' . $commit;
191
+    }
192
+    return "{$desc['vcs']} [$commit]";
193 193
 }
194 194
 
195 195
 /**
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
  *      array ['branch' => xx, 'commit' => yy] sinon.
202 202
  **/
203 203
 function decrire_version_git($dir) {
204
-	if (!$dir) {
205
-		$dir = '.';
206
-	}
204
+    if (!$dir) {
205
+        $dir = '.';
206
+    }
207 207
 
208
-	// version installee par GIT
209
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
210
-		$currentHead = trim(substr($c, 4));
211
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
212
-			return [
213
-				'vcs' => 'GIT',
214
-				'branch' => basename($currentHead),
215
-				'commit' => trim($hash),
216
-				'commit_short' => substr(trim($hash), 0, 8),
217
-			];
218
-		}
219
-	}
208
+    // version installee par GIT
209
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
210
+        $currentHead = trim(substr($c, 4));
211
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
212
+            return [
213
+                'vcs' => 'GIT',
214
+                'branch' => basename($currentHead),
215
+                'commit' => trim($hash),
216
+                'commit_short' => substr(trim($hash), 0, 8),
217
+            ];
218
+        }
219
+    }
220 220
 
221
-	return null;
221
+    return null;
222 222
 }
223 223
 
224 224
 
@@ -231,25 +231,25 @@  discard block
 block discarded – undo
231 231
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
232 232
  **/
233 233
 function decrire_version_svn($dir) {
234
-	if (!$dir) {
235
-		$dir = '.';
236
-	}
237
-	// version installee par SVN
238
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
239
-		$db = new SQLite3($dir . '/.svn/wc.db');
240
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
241
-		if ($result) {
242
-			$row = $result->fetchArray();
243
-			if ($row['changed_revision'] != "") {
244
-				return [
245
-					'vcs' => 'SVN',
246
-					'branch' => '',
247
-					'commit' => $row['changed_revision'],
248
-				];
249
-			}
250
-		}
251
-	}
252
-	return null;
234
+    if (!$dir) {
235
+        $dir = '.';
236
+    }
237
+    // version installee par SVN
238
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
239
+        $db = new SQLite3($dir . '/.svn/wc.db');
240
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
241
+        if ($result) {
242
+            $row = $result->fetchArray();
243
+            if ($row['changed_revision'] != "") {
244
+                return [
245
+                    'vcs' => 'SVN',
246
+                    'branch' => '',
247
+                    'commit' => $row['changed_revision'],
248
+                ];
249
+            }
250
+        }
251
+    }
252
+    return null;
253 253
 }
254 254
 
255 255
 /**
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
  *
268 268
  **/
269 269
 function version_svn_courante($dir) {
270
-	if ($desc = decrire_version_svn($dir)) {
271
-		return -$desc['commit'];
272
-	}
273
-	return 0;
270
+    if ($desc = decrire_version_svn($dir)) {
271
+        return -$desc['commit'];
272
+    }
273
+    return 0;
274 274
 }
275 275
 
276 276
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -314,18 +314,18 @@  discard block
 block discarded – undo
314 314
  *     Code HTML retourné par le filtre
315 315
  **/
316 316
 function filtrer($filtre) {
317
-	$tous = func_get_args();
318
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
319
-		return image_filtrer($tous);
320
-	} elseif ($f = chercher_filtre($filtre)) {
321
-		array_shift($tous);
322
-		return call_user_func_array($f, $tous);
323
-	} else {
324
-		// le filtre n'existe pas, on provoque une erreur
325
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
326
-		erreur_squelette($msg);
327
-		return '';
328
-	}
317
+    $tous = func_get_args();
318
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
319
+        return image_filtrer($tous);
320
+    } elseif ($f = chercher_filtre($filtre)) {
321
+        array_shift($tous);
322
+        return call_user_func_array($f, $tous);
323
+    } else {
324
+        // le filtre n'existe pas, on provoque une erreur
325
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
326
+        erreur_squelette($msg);
327
+        return '';
328
+    }
329 329
 }
330 330
 
331 331
 /**
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
343 343
  */
344 344
 function trouver_filtre_matrice($filtre) {
345
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
346
-		find_in_path($f, '', true);
347
-		$GLOBALS['spip_matrice'][$filtre] = true;
348
-	}
349
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
345
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
346
+        find_in_path($f, '', true);
347
+        $GLOBALS['spip_matrice'][$filtre] = true;
348
+    }
349
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
350 350
 }
351 351
 
352 352
 
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
  * @return mixed
375 375
  */
376 376
 function filtre_set(&$Pile, $val, $key, $continue = null) {
377
-	$Pile['vars'][$key] = $val;
378
-	return $continue ? $val : '';
377
+    $Pile['vars'][$key] = $val;
378
+    return $continue ? $val : '';
379 379
 }
380 380
 
381 381
 /**
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
402 402
  */
403 403
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
404
-	$Pile[0][$key] = $val;
405
-	return $continue ? $val : '';
404
+    $Pile[0][$key] = $val;
405
+    return $continue ? $val : '';
406 406
 }
407 407
 
408 408
 /**
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @return string
412 412
  */
413 413
 function filtre_sanitize_env(&$Pile, $keys) {
414
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
415
-	return '';
414
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
415
+    return '';
416 416
 }
417 417
 
418 418
 
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
  * @return mixed Retourne la valeur (sans la modifier).
436 436
  */
437 437
 function filtre_debug($val, $key = null) {
438
-	$debug = (
439
-		is_null($key) ? '' : (var_export($key, true) . " = ")
440
-		) . var_export($val, true);
438
+    $debug = (
439
+        is_null($key) ? '' : (var_export($key, true) . " = ")
440
+        ) . var_export($val, true);
441 441
 
442
-	include_spip('inc/autoriser');
443
-	if (autoriser('webmestre')) {
444
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
445
-	}
442
+    include_spip('inc/autoriser');
443
+    if (autoriser('webmestre')) {
444
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
445
+    }
446 446
 
447
-	spip_log($debug, 'debug');
447
+    spip_log($debug, 'debug');
448 448
 
449
-	return $val;
449
+    return $val;
450 450
 }
451 451
 
452 452
 
@@ -474,82 +474,82 @@  discard block
 block discarded – undo
474 474
  *     Texte qui a reçu les filtres
475 475
  **/
476 476
 function image_filtrer($args) {
477
-	$filtre = array_shift($args); # enlever $filtre
478
-	$texte = array_shift($args);
479
-	if (!strlen($texte)) {
480
-		return;
481
-	}
482
-	find_in_path('filtres_images_mini.php', 'inc/', true);
483
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
484
-	// Cas du nom de fichier local
485
-	$is_file = trim($texte);
486
-	if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
487
-		  or strpbrk($is_file, "<>\n\r\t") !== false
488
-		  or strpos($is_file, '/') === 0
489
-	) {
490
-		$is_file = false;
491
-	}
492
-	if ($is_file) {
493
-		$is_local_file = function($path) {
494
-			if (strpos($path, "?") !== false) {
495
-				$path = supprimer_timestamp($path);
496
-				// remove ?24px added by find_in_theme on .svg files
497
-				$path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
498
-			}
499
-			return file_exists($path);
500
-		};
501
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
502
-			array_unshift($args, "<img src='$is_file' />");
503
-			$res = call_user_func_array($filtre, $args);
504
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
505
-			return $res;
506
-		}
507
-	}
508
-
509
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
510
-	if (preg_match_all(
511
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
512
-		$texte, $tags, PREG_SET_ORDER)) {
513
-		foreach ($tags as $tag) {
514
-			$class = extraire_attribut($tag[3], 'class');
515
-			if (!$class or
516
-				(strpos($class, 'filtre_inactif') === false
517
-					// compat historique a virer en 3.2
518
-					and strpos($class, 'no_image_filtrer') === false)
519
-			) {
520
-				array_unshift($args, $tag[3]);
521
-				if ($reduit = call_user_func_array($filtre, $args)) {
522
-					// En cas de span spip_documents, modifier le style=...width:
523
-					if ($tag[1]) {
524
-						$w = extraire_attribut($reduit, 'width');
525
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
526
-							$w = $regs[1];
527
-						}
528
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
529
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
530
-							$replace = inserer_attribut($tag[1], 'style', $style);
531
-							$texte = str_replace($tag[1], $replace, $texte);
532
-						}
533
-					}
534
-					// traiter aussi un eventuel mouseover
535
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
536
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
537
-							$srcover = $match[1];
538
-							array_shift($args);
539
-							array_unshift($args, "<img src='" . $match[1] . "' />");
540
-							$srcover_filter = call_user_func_array($filtre, $args);
541
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543
-						}
544
-					}
545
-					$texte = str_replace($tag[3], $reduit, $texte);
546
-				}
547
-				array_shift($args);
548
-			}
549
-		}
550
-	}
551
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
552
-	return $texte;
477
+    $filtre = array_shift($args); # enlever $filtre
478
+    $texte = array_shift($args);
479
+    if (!strlen($texte)) {
480
+        return;
481
+    }
482
+    find_in_path('filtres_images_mini.php', 'inc/', true);
483
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
484
+    // Cas du nom de fichier local
485
+    $is_file = trim($texte);
486
+    if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
487
+          or strpbrk($is_file, "<>\n\r\t") !== false
488
+          or strpos($is_file, '/') === 0
489
+    ) {
490
+        $is_file = false;
491
+    }
492
+    if ($is_file) {
493
+        $is_local_file = function($path) {
494
+            if (strpos($path, "?") !== false) {
495
+                $path = supprimer_timestamp($path);
496
+                // remove ?24px added by find_in_theme on .svg files
497
+                $path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
498
+            }
499
+            return file_exists($path);
500
+        };
501
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
502
+            array_unshift($args, "<img src='$is_file' />");
503
+            $res = call_user_func_array($filtre, $args);
504
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
505
+            return $res;
506
+        }
507
+    }
508
+
509
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
510
+    if (preg_match_all(
511
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
512
+        $texte, $tags, PREG_SET_ORDER)) {
513
+        foreach ($tags as $tag) {
514
+            $class = extraire_attribut($tag[3], 'class');
515
+            if (!$class or
516
+                (strpos($class, 'filtre_inactif') === false
517
+                    // compat historique a virer en 3.2
518
+                    and strpos($class, 'no_image_filtrer') === false)
519
+            ) {
520
+                array_unshift($args, $tag[3]);
521
+                if ($reduit = call_user_func_array($filtre, $args)) {
522
+                    // En cas de span spip_documents, modifier le style=...width:
523
+                    if ($tag[1]) {
524
+                        $w = extraire_attribut($reduit, 'width');
525
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
526
+                            $w = $regs[1];
527
+                        }
528
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
529
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
530
+                            $replace = inserer_attribut($tag[1], 'style', $style);
531
+                            $texte = str_replace($tag[1], $replace, $texte);
532
+                        }
533
+                    }
534
+                    // traiter aussi un eventuel mouseover
535
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
536
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
537
+                            $srcover = $match[1];
538
+                            array_shift($args);
539
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
540
+                            $srcover_filter = call_user_func_array($filtre, $args);
541
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
542
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
543
+                        }
544
+                    }
545
+                    $texte = str_replace($tag[3], $reduit, $texte);
546
+                }
547
+                array_shift($args);
548
+            }
549
+        }
550
+    }
551
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
552
+    return $texte;
553 553
 }
554 554
 
555 555
 /**
@@ -564,65 +564,65 @@  discard block
 block discarded – undo
564 564
  **/
565 565
 function taille_image($img, $force_refresh = false) {
566 566
 
567
-	static $largeur_img = array(), $hauteur_img = array();
568
-	$srcWidth = 0;
569
-	$srcHeight = 0;
570
-
571
-	$src = extraire_attribut($img, 'src');
572
-
573
-	if (!$src) {
574
-		$src = $img;
575
-	} else {
576
-		$srcWidth = extraire_attribut($img, 'width');
577
-		$srcHeight = extraire_attribut($img, 'height');
578
-	}
579
-
580
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
581
-	// la copie locale a toutes les chances d'etre la ou de resservir
582
-	if (tester_url_absolue($src)) {
583
-		include_spip('inc/distant');
584
-		$fichier = copie_locale($src);
585
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
586
-	}
587
-	if (($p = strpos($src, '?')) !== false) {
588
-		$src = substr($src, 0, $p);
589
-	}
590
-
591
-	$srcsize = false;
592
-	if (isset($largeur_img[$src]) and !$force_refresh) {
593
-		$srcWidth = $largeur_img[$src];
594
-	}
595
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
596
-		$srcHeight = $hauteur_img[$src];
597
-	}
598
-	if (!$srcWidth or !$srcHeight) {
599
-
600
-		if (file_exists($src)
601
-			and $srcsize = spip_getimagesize($src)
602
-		) {
603
-			if (!$srcWidth) {
604
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
605
-			}
606
-			if (!$srcHeight) {
607
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
608
-			}
609
-		}
610
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
611
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
612
-		elseif (@file_exists($f = "$src.src")
613
-			and lire_fichier($f, $valeurs)
614
-			and $valeurs = unserialize($valeurs)
615
-		) {
616
-			if (!$srcWidth) {
617
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
618
-			}
619
-			if (!$srcHeight) {
620
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
621
-			}
622
-		}
623
-	}
624
-
625
-	return array($srcHeight, $srcWidth);
567
+    static $largeur_img = array(), $hauteur_img = array();
568
+    $srcWidth = 0;
569
+    $srcHeight = 0;
570
+
571
+    $src = extraire_attribut($img, 'src');
572
+
573
+    if (!$src) {
574
+        $src = $img;
575
+    } else {
576
+        $srcWidth = extraire_attribut($img, 'width');
577
+        $srcHeight = extraire_attribut($img, 'height');
578
+    }
579
+
580
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
581
+    // la copie locale a toutes les chances d'etre la ou de resservir
582
+    if (tester_url_absolue($src)) {
583
+        include_spip('inc/distant');
584
+        $fichier = copie_locale($src);
585
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
586
+    }
587
+    if (($p = strpos($src, '?')) !== false) {
588
+        $src = substr($src, 0, $p);
589
+    }
590
+
591
+    $srcsize = false;
592
+    if (isset($largeur_img[$src]) and !$force_refresh) {
593
+        $srcWidth = $largeur_img[$src];
594
+    }
595
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
596
+        $srcHeight = $hauteur_img[$src];
597
+    }
598
+    if (!$srcWidth or !$srcHeight) {
599
+
600
+        if (file_exists($src)
601
+            and $srcsize = spip_getimagesize($src)
602
+        ) {
603
+            if (!$srcWidth) {
604
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
605
+            }
606
+            if (!$srcHeight) {
607
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
608
+            }
609
+        }
610
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
611
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
612
+        elseif (@file_exists($f = "$src.src")
613
+            and lire_fichier($f, $valeurs)
614
+            and $valeurs = unserialize($valeurs)
615
+        ) {
616
+            if (!$srcWidth) {
617
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
618
+            }
619
+            if (!$srcHeight) {
620
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
621
+            }
622
+        }
623
+    }
624
+
625
+    return array($srcHeight, $srcWidth);
626 626
 }
627 627
 
628 628
 
@@ -640,12 +640,12 @@  discard block
 block discarded – undo
640 640
  *     Largeur en pixels, NULL ou 0 si aucune image.
641 641
  **/
642 642
 function largeur($img) {
643
-	if (!$img) {
644
-		return;
645
-	}
646
-	list($h, $l) = taille_image($img);
643
+    if (!$img) {
644
+        return;
645
+    }
646
+    list($h, $l) = taille_image($img);
647 647
 
648
-	return $l;
648
+    return $l;
649 649
 }
650 650
 
651 651
 /**
@@ -662,12 +662,12 @@  discard block
 block discarded – undo
662 662
  *     Hauteur en pixels, NULL ou 0 si aucune image.
663 663
  **/
664 664
 function hauteur($img) {
665
-	if (!$img) {
666
-		return;
667
-	}
668
-	list($h, $l) = taille_image($img);
665
+    if (!$img) {
666
+        return;
667
+    }
668
+    list($h, $l) = taille_image($img);
669 669
 
670
-	return $h;
670
+    return $h;
671 671
 }
672 672
 
673 673
 
@@ -687,11 +687,11 @@  discard block
 block discarded – undo
687 687
  * @return string
688 688
  **/
689 689
 function corriger_entites_html($texte) {
690
-	if (strpos($texte, '&amp;') === false) {
691
-		return $texte;
692
-	}
690
+    if (strpos($texte, '&amp;') === false) {
691
+        return $texte;
692
+    }
693 693
 
694
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
694
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
695 695
 }
696 696
 
697 697
 /**
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
  * @return string
707 707
  **/
708 708
 function corriger_toutes_entites_html($texte) {
709
-	if (strpos($texte, '&amp;') === false) {
710
-		return $texte;
711
-	}
709
+    if (strpos($texte, '&amp;') === false) {
710
+        return $texte;
711
+    }
712 712
 
713
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
713
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
714 714
 }
715 715
 
716 716
 /**
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
  * @return string
721 721
  **/
722 722
 function proteger_amp($texte) {
723
-	return str_replace('&', '&amp;', $texte);
723
+    return str_replace('&', '&amp;', $texte);
724 724
 }
725 725
 
726 726
 
@@ -751,20 +751,20 @@  discard block
 block discarded – undo
751 751
  * @return mixed|string
752 752
  */
753 753
 function entites_html($texte, $tout = false, $quote = true) {
754
-	if (!is_string($texte) or !$texte
755
-		or strpbrk($texte, "&\"'<>") == false
756
-	) {
757
-		return $texte;
758
-	}
759
-	include_spip('inc/texte');
760
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
761
-	$flags |= ENT_HTML401;
762
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
763
-	if ($tout) {
764
-		return corriger_toutes_entites_html($texte);
765
-	} else {
766
-		return corriger_entites_html($texte);
767
-	}
754
+    if (!is_string($texte) or !$texte
755
+        or strpbrk($texte, "&\"'<>") == false
756
+    ) {
757
+        return $texte;
758
+    }
759
+    include_spip('inc/texte');
760
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
761
+    $flags |= ENT_HTML401;
762
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
763
+    if ($tout) {
764
+        return corriger_toutes_entites_html($texte);
765
+    } else {
766
+        return corriger_entites_html($texte);
767
+    }
768 768
 }
769 769
 
770 770
 /**
@@ -783,37 +783,37 @@  discard block
 block discarded – undo
783 783
  *     Texte converti
784 784
  **/
785 785
 function filtrer_entites($texte) {
786
-	if (strpos($texte, '&') === false) {
787
-		return $texte;
788
-	}
789
-	// filtrer
790
-	$texte = html2unicode($texte);
791
-	// remettre le tout dans le charset cible
792
-	$texte = unicode2charset($texte);
793
-	// cas particulier des " et ' qu'il faut filtrer aussi
794
-	// (on le faisait deja avec un &quot;)
795
-	if (strpos($texte, "&#") !== false) {
796
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
797
-	}
786
+    if (strpos($texte, '&') === false) {
787
+        return $texte;
788
+    }
789
+    // filtrer
790
+    $texte = html2unicode($texte);
791
+    // remettre le tout dans le charset cible
792
+    $texte = unicode2charset($texte);
793
+    // cas particulier des " et ' qu'il faut filtrer aussi
794
+    // (on le faisait deja avec un &quot;)
795
+    if (strpos($texte, "&#") !== false) {
796
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
797
+    }
798 798
 
799
-	return $texte;
799
+    return $texte;
800 800
 }
801 801
 
802 802
 
803 803
 if (!function_exists('filtre_filtrer_entites_dist')) {
804
-	/**
805
-	 * Version sécurisée de filtrer_entites
806
-	 * 
807
-	 * @uses interdire_scripts()
808
-	 * @uses filtrer_entites()
809
-	 * 
810
-	 * @param string $t
811
-	 * @return string
812
-	 */
813
-	function filtre_filtrer_entites_dist($t) {
814
-		include_spip('inc/texte');
815
-		return interdire_scripts(filtrer_entites($t));
816
-	}
804
+    /**
805
+     * Version sécurisée de filtrer_entites
806
+     * 
807
+     * @uses interdire_scripts()
808
+     * @uses filtrer_entites()
809
+     * 
810
+     * @param string $t
811
+     * @return string
812
+     */
813
+    function filtre_filtrer_entites_dist($t) {
814
+        include_spip('inc/texte');
815
+        return interdire_scripts(filtrer_entites($t));
816
+    }
817 817
 }
818 818
 
819 819
 
@@ -828,18 +828,18 @@  discard block
 block discarded – undo
828 828
  * @return string|array
829 829
  **/
830 830
 function supprimer_caracteres_illegaux($texte) {
831
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
832
-	static $to = null;
831
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
832
+    static $to = null;
833 833
 
834
-	if (is_array($texte)) {
835
-		return array_map('supprimer_caracteres_illegaux', $texte);
836
-	}
834
+    if (is_array($texte)) {
835
+        return array_map('supprimer_caracteres_illegaux', $texte);
836
+    }
837 837
 
838
-	if (!$to) {
839
-		$to = str_repeat('-', strlen($from));
840
-	}
838
+    if (!$to) {
839
+        $to = str_repeat('-', strlen($from));
840
+    }
841 841
 
842
-	return strtr($texte, $from, $to);
842
+    return strtr($texte, $from, $to);
843 843
 }
844 844
 
845 845
 /**
@@ -851,10 +851,10 @@  discard block
 block discarded – undo
851 851
  * @return string|array
852 852
  **/
853 853
 function corriger_caracteres($texte) {
854
-	$texte = corriger_caracteres_windows($texte);
855
-	$texte = supprimer_caracteres_illegaux($texte);
854
+    $texte = corriger_caracteres_windows($texte);
855
+    $texte = supprimer_caracteres_illegaux($texte);
856 856
 
857
-	return $texte;
857
+    return $texte;
858 858
 }
859 859
 
860 860
 /**
@@ -872,40 +872,40 @@  discard block
 block discarded – undo
872 872
  */
873 873
 function texte_backend($texte) {
874 874
 
875
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
875
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
876 876
 
877
-	// si on a des liens ou des images, les passer en absolu
878
-	$texte = liens_absolus($texte);
877
+    // si on a des liens ou des images, les passer en absolu
878
+    $texte = liens_absolus($texte);
879 879
 
880
-	// echapper les tags &gt; &lt;
881
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
880
+    // echapper les tags &gt; &lt;
881
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
882 882
 
883
-	// importer les &eacute;
884
-	$texte = filtrer_entites($texte);
883
+    // importer les &eacute;
884
+    $texte = filtrer_entites($texte);
885 885
 
886
-	// " -> &quot; et tout ce genre de choses
887
-	$u = $GLOBALS['meta']['pcre_u'];
888
-	$texte = str_replace("&nbsp;", " ", $texte);
889
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
890
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
891
-	$texte = entites_html($texte, false, false);
892
-	// mais bien echapper les double quotes !
893
-	$texte = str_replace('"', '&#034;', $texte);
886
+    // " -> &quot; et tout ce genre de choses
887
+    $u = $GLOBALS['meta']['pcre_u'];
888
+    $texte = str_replace("&nbsp;", " ", $texte);
889
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
890
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
891
+    $texte = entites_html($texte, false, false);
892
+    // mais bien echapper les double quotes !
893
+    $texte = str_replace('"', '&#034;', $texte);
894 894
 
895
-	// verifier le charset
896
-	$texte = charset2unicode($texte);
895
+    // verifier le charset
896
+    $texte = charset2unicode($texte);
897 897
 
898
-	// Caracteres problematiques en iso-latin 1
899
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
900
-		$texte = str_replace(chr(156), '&#156;', $texte);
901
-		$texte = str_replace(chr(140), '&#140;', $texte);
902
-		$texte = str_replace(chr(159), '&#159;', $texte);
903
-	}
898
+    // Caracteres problematiques en iso-latin 1
899
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
900
+        $texte = str_replace(chr(156), '&#156;', $texte);
901
+        $texte = str_replace(chr(140), '&#140;', $texte);
902
+        $texte = str_replace(chr(159), '&#159;', $texte);
903
+    }
904 904
 
905
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
906
-	// et le caractere apostrophe alourdit les squelettes avec PHP
907
-	// ==> on les remplace par l'entite HTML
908
-	return str_replace($apostrophe, "'", $texte);
905
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
906
+    // et le caractere apostrophe alourdit les squelettes avec PHP
907
+    // ==> on les remplace par l'entite HTML
908
+    return str_replace($apostrophe, "'", $texte);
909 909
 }
910 910
 
911 911
 /**
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
  *     Texte encodé et quote pour XML
923 923
  */
924 924
 function texte_backendq($texte) {
925
-	return addslashes(texte_backend($texte));
925
+    return addslashes(texte_backend($texte));
926 926
 }
927 927
 
928 928
 
@@ -945,9 +945,9 @@  discard block
 block discarded – undo
945 945
  *     Numéro de titre, sinon chaîne vide
946 946
  **/
947 947
 function supprimer_numero($texte) {
948
-	return preg_replace(
949
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
950
-		"", $texte);
948
+    return preg_replace(
949
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
950
+        "", $texte);
951 951
 }
952 952
 
953 953
 /**
@@ -970,13 +970,13 @@  discard block
 block discarded – undo
970 970
  *     Numéro de titre, sinon chaîne vide
971 971
  **/
972 972
 function recuperer_numero($texte) {
973
-	if (preg_match(
974
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
975
-		$texte, $regs)) {
976
-		return strval($regs[1]);
977
-	} else {
978
-		return '';
979
-	}
973
+    if (preg_match(
974
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
975
+        $texte, $regs)) {
976
+        return strval($regs[1]);
977
+    } else {
978
+        return '';
979
+    }
980 980
 }
981 981
 
982 982
 /**
@@ -1003,13 +1003,13 @@  discard block
 block discarded – undo
1003 1003
  *     Texte converti
1004 1004
  **/
1005 1005
 function supprimer_tags($texte, $rempl = "") {
1006
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1007
-	// ne pas oublier un < final non ferme car coupe
1008
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1009
-	// mais qui peut aussi etre un simple signe plus petit que
1010
-	$texte = str_replace('<', '&lt;', $texte);
1006
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1007
+    // ne pas oublier un < final non ferme car coupe
1008
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1009
+    // mais qui peut aussi etre un simple signe plus petit que
1010
+    $texte = str_replace('<', '&lt;', $texte);
1011 1011
 
1012
-	return $texte;
1012
+    return $texte;
1013 1013
 }
1014 1014
 
1015 1015
 /**
@@ -1032,9 +1032,9 @@  discard block
 block discarded – undo
1032 1032
  *     Texte converti
1033 1033
  **/
1034 1034
 function echapper_tags($texte, $rempl = "") {
1035
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1035
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1036 1036
 
1037
-	return $texte;
1037
+    return $texte;
1038 1038
 }
1039 1039
 
1040 1040
 /**
@@ -1055,18 +1055,18 @@  discard block
 block discarded – undo
1055 1055
  *     Texte converti
1056 1056
  **/
1057 1057
 function textebrut($texte) {
1058
-	$u = $GLOBALS['meta']['pcre_u'];
1059
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1060
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1061
-	$texte = preg_replace("/^\n+/", "", $texte);
1062
-	$texte = preg_replace("/\n+$/", "", $texte);
1063
-	$texte = preg_replace("/\n +/", "\n", $texte);
1064
-	$texte = supprimer_tags($texte);
1065
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1066
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1067
-	$texte = str_replace("&#8217;", "'", $texte);
1058
+    $u = $GLOBALS['meta']['pcre_u'];
1059
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1060
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1061
+    $texte = preg_replace("/^\n+/", "", $texte);
1062
+    $texte = preg_replace("/\n+$/", "", $texte);
1063
+    $texte = preg_replace("/\n +/", "\n", $texte);
1064
+    $texte = supprimer_tags($texte);
1065
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1066
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1067
+    $texte = str_replace("&#8217;", "'", $texte);
1068 1068
 
1069
-	return $texte;
1069
+    return $texte;
1070 1070
 }
1071 1071
 
1072 1072
 
@@ -1082,17 +1082,17 @@  discard block
 block discarded – undo
1082 1082
  *     Texte avec liens ouvrants
1083 1083
  **/
1084 1084
 function liens_ouvrants($texte) {
1085
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1086
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1087
-		foreach ($liens[0] as $a) {
1088
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1089
-			$ablank = inserer_attribut($a, 'rel', $rel);
1090
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1091
-			$texte = str_replace($a, $ablank, $texte);
1092
-		}
1093
-	}
1085
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1086
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1087
+        foreach ($liens[0] as $a) {
1088
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1089
+            $ablank = inserer_attribut($a, 'rel', $rel);
1090
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1091
+            $texte = str_replace($a, $ablank, $texte);
1092
+        }
1093
+    }
1094 1094
 
1095
-	return $texte;
1095
+    return $texte;
1096 1096
 }
1097 1097
 
1098 1098
 /**
@@ -1102,22 +1102,22 @@  discard block
 block discarded – undo
1102 1102
  * @return string
1103 1103
  */
1104 1104
 function liens_nofollow($texte) {
1105
-	if (stripos($texte, "<a") === false) {
1106
-		return $texte;
1107
-	}
1105
+    if (stripos($texte, "<a") === false) {
1106
+        return $texte;
1107
+    }
1108 1108
 
1109
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1110
-		foreach ($regs[0] as $a) {
1111
-			$rel = extraire_attribut($a, "rel");
1112
-			if (strpos($rel, "nofollow") === false) {
1113
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1114
-				$anofollow = inserer_attribut($a, "rel", $rel);
1115
-				$texte = str_replace($a, $anofollow, $texte);
1116
-			}
1117
-		}
1118
-	}
1109
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1110
+        foreach ($regs[0] as $a) {
1111
+            $rel = extraire_attribut($a, "rel");
1112
+            if (strpos($rel, "nofollow") === false) {
1113
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1114
+                $anofollow = inserer_attribut($a, "rel", $rel);
1115
+                $texte = str_replace($a, $anofollow, $texte);
1116
+            }
1117
+        }
1118
+    }
1119 1119
 
1120
-	return $texte;
1120
+    return $texte;
1121 1121
 }
1122 1122
 
1123 1123
 /**
@@ -1136,12 +1136,12 @@  discard block
 block discarded – undo
1136 1136
  *     Texte sans paraghaphes
1137 1137
  **/
1138 1138
 function PtoBR($texte) {
1139
-	$u = $GLOBALS['meta']['pcre_u'];
1140
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1141
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1142
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1139
+    $u = $GLOBALS['meta']['pcre_u'];
1140
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1141
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1142
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1143 1143
 
1144
-	return $texte;
1144
+    return $texte;
1145 1145
 }
1146 1146
 
1147 1147
 
@@ -1165,14 +1165,14 @@  discard block
 block discarded – undo
1165 1165
  * @return string Texte encadré du style CSS
1166 1166
  */
1167 1167
 function lignes_longues($texte) {
1168
-	if (!strlen(trim($texte))) {
1169
-		return $texte;
1170
-	}
1171
-	include_spip('inc/texte');
1172
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1173
-		'div' : 'span';
1168
+    if (!strlen(trim($texte))) {
1169
+        return $texte;
1170
+    }
1171
+    include_spip('inc/texte');
1172
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1173
+        'div' : 'span';
1174 1174
 
1175
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1175
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1191,30 +1191,30 @@  discard block
 block discarded – undo
1191 1191
  * @return string Texte en majuscule
1192 1192
  */
1193 1193
 function majuscules($texte) {
1194
-	if (!strlen($texte)) {
1195
-		return '';
1196
-	}
1194
+    if (!strlen($texte)) {
1195
+        return '';
1196
+    }
1197 1197
 
1198
-	// Cas du turc
1199
-	if ($GLOBALS['spip_lang'] == 'tr') {
1200
-		# remplacer hors des tags et des entites
1201
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1202
-			foreach ($regs as $n => $match) {
1203
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1204
-			}
1205
-		}
1198
+    // Cas du turc
1199
+    if ($GLOBALS['spip_lang'] == 'tr') {
1200
+        # remplacer hors des tags et des entites
1201
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1202
+            foreach ($regs as $n => $match) {
1203
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1204
+            }
1205
+        }
1206 1206
 
1207
-		$texte = str_replace('i', '&#304;', $texte);
1207
+        $texte = str_replace('i', '&#304;', $texte);
1208 1208
 
1209
-		if ($regs) {
1210
-			foreach ($regs as $n => $match) {
1211
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1212
-			}
1213
-		}
1214
-	}
1209
+        if ($regs) {
1210
+            foreach ($regs as $n => $match) {
1211
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1212
+            }
1213
+        }
1214
+    }
1215 1215
 
1216
-	// Cas general
1217
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1216
+    // Cas general
1217
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1218 1218
 }
1219 1219
 
1220 1220
 /**
@@ -1232,29 +1232,29 @@  discard block
 block discarded – undo
1232 1232
  * @return string
1233 1233
  **/
1234 1234
 function taille_en_octets($taille) {
1235
-	if (!defined('_KILOBYTE')) {
1236
-		/**
1237
-		 * Définit le nombre d'octets dans un Kilobyte
1238
-		 *
1239
-		 * @var int
1240
-		 **/
1241
-		define('_KILOBYTE', 1024);
1242
-	}
1235
+    if (!defined('_KILOBYTE')) {
1236
+        /**
1237
+         * Définit le nombre d'octets dans un Kilobyte
1238
+         *
1239
+         * @var int
1240
+         **/
1241
+        define('_KILOBYTE', 1024);
1242
+    }
1243 1243
 
1244
-	if ($taille < 1) {
1245
-		return '';
1246
-	}
1247
-	if ($taille < _KILOBYTE) {
1248
-		$taille = _T('taille_octets', array('taille' => $taille));
1249
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1250
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1251
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1252
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1253
-	} else {
1254
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1255
-	}
1244
+    if ($taille < 1) {
1245
+        return '';
1246
+    }
1247
+    if ($taille < _KILOBYTE) {
1248
+        $taille = _T('taille_octets', array('taille' => $taille));
1249
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1250
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1251
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1252
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1253
+    } else {
1254
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1255
+    }
1256 1256
 
1257
-	return $taille;
1257
+    return $taille;
1258 1258
 }
1259 1259
 
1260 1260
 
@@ -1276,15 +1276,15 @@  discard block
 block discarded – undo
1276 1276
  *     Texte prêt pour être utilisé en attribut HTML
1277 1277
  **/
1278 1278
 function attribut_html($texte, $textebrut = true) {
1279
-	$u = $GLOBALS['meta']['pcre_u'];
1280
-	if ($textebrut) {
1281
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1282
-	}
1283
-	$texte = texte_backend($texte);
1284
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1279
+    $u = $GLOBALS['meta']['pcre_u'];
1280
+    if ($textebrut) {
1281
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1282
+    }
1283
+    $texte = texte_backend($texte);
1284
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1285 1285
 
1286
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1287
-		$texte);
1286
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1287
+        $texte);
1288 1288
 }
1289 1289
 
1290 1290
 
@@ -1304,12 +1304,12 @@  discard block
 block discarded – undo
1304 1304
  *     URL ou chaîne vide
1305 1305
  **/
1306 1306
 function vider_url($url, $entites = true) {
1307
-	# un message pour abs_url
1308
-	$GLOBALS['mode_abs_url'] = 'url';
1309
-	$url = trim($url);
1310
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1307
+    # un message pour abs_url
1308
+    $GLOBALS['mode_abs_url'] = 'url';
1309
+    $url = trim($url);
1310
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1311 1311
 
1312
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1312
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1313 1313
 }
1314 1314
 
1315 1315
 
@@ -1324,10 +1324,10 @@  discard block
 block discarded – undo
1324 1324
  * @return string Adresse email maquillée
1325 1325
  **/
1326 1326
 function antispam($texte) {
1327
-	include_spip('inc/acces');
1328
-	$masque = creer_pass_aleatoire(3);
1327
+    include_spip('inc/acces');
1328
+    $masque = creer_pass_aleatoire(3);
1329 1329
 
1330
-	return preg_replace("/@/", " $masque ", $texte);
1330
+    return preg_replace("/@/", " $masque ", $texte);
1331 1331
 }
1332 1332
 
1333 1333
 /**
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
  *     True si on a le droit d'accès, false sinon.
1360 1360
  **/
1361 1361
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1362
-	include_spip('inc/acces');
1363
-	if ($op) {
1364
-		$dir .= " $op $args";
1365
-	}
1362
+    include_spip('inc/acces');
1363
+    if ($op) {
1364
+        $dir .= " $op $args";
1365
+    }
1366 1366
 
1367
-	return verifier_low_sec($id_auteur, $cle, $dir);
1367
+    return verifier_low_sec($id_auteur, $cle, $dir);
1368 1368
 }
1369 1369
 
1370 1370
 /**
@@ -1389,11 +1389,11 @@  discard block
 block discarded – undo
1389 1389
  *     Retourne $texte, sinon $sinon.
1390 1390
  **/
1391 1391
 function sinon($texte, $sinon = '') {
1392
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1393
-		return $texte;
1394
-	} else {
1395
-		return $sinon;
1396
-	}
1392
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1393
+        return $texte;
1394
+    } else {
1395
+        return $sinon;
1396
+    }
1397 1397
 }
1398 1398
 
1399 1399
 /**
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
  * @return mixed
1418 1418
  **/
1419 1419
 function choixsivide($a, $vide, $pasvide) {
1420
-	return $a ? $pasvide : $vide;
1420
+    return $a ? $pasvide : $vide;
1421 1421
 }
1422 1422
 
1423 1423
 /**
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
  * @return mixed
1442 1442
  **/
1443 1443
 function choixsiegal($a1, $a2, $v, $f) {
1444
-	return ($a1 == $a2) ? $v : $f;
1444
+    return ($a1 == $a2) ? $v : $f;
1445 1445
 }
1446 1446
 
1447 1447
 //
@@ -1460,13 +1460,13 @@  discard block
 block discarded – undo
1460 1460
  * @return string
1461 1461
  **/
1462 1462
 function filtrer_ical($texte) {
1463
-	#include_spip('inc/charsets');
1464
-	$texte = html2unicode($texte);
1465
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1466
-	$texte = preg_replace("/\n/", " ", $texte);
1467
-	$texte = preg_replace("/,/", "\,", $texte);
1463
+    #include_spip('inc/charsets');
1464
+    $texte = html2unicode($texte);
1465
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1466
+    $texte = preg_replace("/\n/", " ", $texte);
1467
+    $texte = preg_replace("/,/", "\,", $texte);
1468 1468
 
1469
-	return $texte;
1469
+    return $texte;
1470 1470
 }
1471 1471
 
1472 1472
 
@@ -1491,53 +1491,53 @@  discard block
 block discarded – undo
1491 1491
  * @return string
1492 1492
  **/
1493 1493
 function post_autobr($texte, $delim = "\n_ ") {
1494
-	if (!function_exists('echappe_html')) {
1495
-		include_spip('inc/texte_mini');
1496
-	}
1497
-	$texte = str_replace("\r\n", "\r", $texte);
1498
-	$texte = str_replace("\r", "\n", $texte);
1499
-
1500
-	if (preg_match(",\n+$,", $texte, $fin)) {
1501
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1502
-	} else {
1503
-		$fin = '';
1504
-	}
1505
-
1506
-	$texte = echappe_html($texte, '', true);
1507
-
1508
-	// echapper les modeles
1509
-	if (strpos($texte, "<") !== false) {
1510
-		include_spip('inc/lien');
1511
-		if (defined('_PREG_MODELE')) {
1512
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1513
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1514
-		}
1515
-	}
1516
-
1517
-	$debut = '';
1518
-	$suite = $texte;
1519
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1520
-		$debut .= substr($suite, 0, $t - 1);
1521
-		$suite = substr($suite, $t);
1522
-		$car = substr($suite, 0, 1);
1523
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1524
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1525
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1526
-		) {
1527
-			$debut .= $delim;
1528
-		} else {
1529
-			$debut .= "\n";
1530
-		}
1531
-		if (preg_match(",^\n+,", $suite, $regs)) {
1532
-			$debut .= $regs[0];
1533
-			$suite = substr($suite, strlen($regs[0]));
1534
-		}
1535
-	}
1536
-	$texte = $debut . $suite;
1537
-
1538
-	$texte = echappe_retour($texte);
1539
-
1540
-	return $texte . $fin;
1494
+    if (!function_exists('echappe_html')) {
1495
+        include_spip('inc/texte_mini');
1496
+    }
1497
+    $texte = str_replace("\r\n", "\r", $texte);
1498
+    $texte = str_replace("\r", "\n", $texte);
1499
+
1500
+    if (preg_match(",\n+$,", $texte, $fin)) {
1501
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1502
+    } else {
1503
+        $fin = '';
1504
+    }
1505
+
1506
+    $texte = echappe_html($texte, '', true);
1507
+
1508
+    // echapper les modeles
1509
+    if (strpos($texte, "<") !== false) {
1510
+        include_spip('inc/lien');
1511
+        if (defined('_PREG_MODELE')) {
1512
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1513
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1514
+        }
1515
+    }
1516
+
1517
+    $debut = '';
1518
+    $suite = $texte;
1519
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1520
+        $debut .= substr($suite, 0, $t - 1);
1521
+        $suite = substr($suite, $t);
1522
+        $car = substr($suite, 0, 1);
1523
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1524
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1525
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1526
+        ) {
1527
+            $debut .= $delim;
1528
+        } else {
1529
+            $debut .= "\n";
1530
+        }
1531
+        if (preg_match(",^\n+,", $suite, $regs)) {
1532
+            $debut .= $regs[0];
1533
+            $suite = substr($suite, strlen($regs[0]));
1534
+        }
1535
+    }
1536
+    $texte = $debut . $suite;
1537
+
1538
+    $texte = echappe_retour($texte);
1539
+
1540
+    return $texte . $fin;
1541 1541
 }
1542 1542
 
1543 1543
 
@@ -1578,46 +1578,46 @@  discard block
 block discarded – undo
1578 1578
  * @return string
1579 1579
  **/
1580 1580
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1581
-	static $traduire = false;
1582
-	if ($letexte
1583
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1584
-	) {
1585
-		if (!$traduire) {
1586
-			$traduire = charger_fonction('traduire', 'inc');
1587
-			include_spip('inc/lang');
1588
-		}
1589
-		if (!$lang) {
1590
-			$lang = $GLOBALS['spip_lang'];
1591
-		}
1592
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1593
-		if (is_bool($options)) {
1594
-			$options = array('echappe_span' => $options);
1595
-		}
1596
-		if (!isset($options['echappe_span'])) {
1597
-			$options = array_merge($options, array('echappe_span' => false));
1598
-		}
1599
-
1600
-		foreach ($regs as $reg) {
1601
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1602
-			$desc = $traduire($cle, $lang, true);
1603
-			$l = $desc->langue;
1604
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1605
-			if (strlen($desc->texte)) {
1606
-				$trad = code_echappement($desc->texte, 'idiome', false);
1607
-				if ($l !== $lang) {
1608
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1609
-				}
1610
-				if (lang_dir($l) !== lang_dir($lang)) {
1611
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1612
-				}
1613
-				if (!$options['echappe_span']) {
1614
-					$trad = echappe_retour($trad, 'idiome');
1615
-				}
1616
-				$letexte = str_replace($reg[0], $trad, $letexte);
1617
-			}
1618
-		}
1619
-	}
1620
-	return $letexte;
1581
+    static $traduire = false;
1582
+    if ($letexte
1583
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1584
+    ) {
1585
+        if (!$traduire) {
1586
+            $traduire = charger_fonction('traduire', 'inc');
1587
+            include_spip('inc/lang');
1588
+        }
1589
+        if (!$lang) {
1590
+            $lang = $GLOBALS['spip_lang'];
1591
+        }
1592
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1593
+        if (is_bool($options)) {
1594
+            $options = array('echappe_span' => $options);
1595
+        }
1596
+        if (!isset($options['echappe_span'])) {
1597
+            $options = array_merge($options, array('echappe_span' => false));
1598
+        }
1599
+
1600
+        foreach ($regs as $reg) {
1601
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1602
+            $desc = $traduire($cle, $lang, true);
1603
+            $l = $desc->langue;
1604
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1605
+            if (strlen($desc->texte)) {
1606
+                $trad = code_echappement($desc->texte, 'idiome', false);
1607
+                if ($l !== $lang) {
1608
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1609
+                }
1610
+                if (lang_dir($l) !== lang_dir($lang)) {
1611
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1612
+                }
1613
+                if (!$options['echappe_span']) {
1614
+                    $trad = echappe_retour($trad, 'idiome');
1615
+                }
1616
+                $letexte = str_replace($reg[0], $trad, $letexte);
1617
+            }
1618
+        }
1619
+    }
1620
+    return $letexte;
1621 1621
 }
1622 1622
 
1623 1623
 /**
@@ -1669,64 +1669,64 @@  discard block
 block discarded – undo
1669 1669
  **/
1670 1670
 function extraire_multi($letexte, $lang = null, $options = array()) {
1671 1671
 
1672
-	if ($letexte
1673
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1674
-	) {
1675
-		if (!$lang) {
1676
-			$lang = $GLOBALS['spip_lang'];
1677
-		}
1678
-
1679
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1680
-		if (is_bool($options)) {
1681
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1682
-		}
1683
-		if (!isset($options['echappe_span'])) {
1684
-			$options = array_merge($options, array('echappe_span' => false));
1685
-		}
1686
-		if (!isset($options['lang_defaut'])) {
1687
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1688
-		}
1689
-
1690
-		include_spip('inc/lang');
1691
-		foreach ($regs as $reg) {
1692
-			// chercher la version de la langue courante
1693
-			$trads = extraire_trads($reg[1]);
1694
-			if ($l = approcher_langue($trads, $lang)) {
1695
-				$trad = $trads[$l];
1696
-			} else {
1697
-				if ($options['lang_defaut'] == 'aucune') {
1698
-					$trad = '';
1699
-				} else {
1700
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1701
-					// ou la premiere dispo
1702
-					// mais typographier le texte selon les regles de celle-ci
1703
-					// Attention aux blocs multi sur plusieurs lignes
1704
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1705
-						$l = key($trads);
1706
-					}
1707
-					$trad = $trads[$l];
1708
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1709
-					$trad = $typographie($trad);
1710
-					// Tester si on echappe en span ou en div
1711
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1712
-					include_spip('inc/texte');
1713
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1714
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1715
-					$trad = code_echappement($trad, 'multi', false, $mode);
1716
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1717
-					if (lang_dir($l) !== lang_dir($lang)) {
1718
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1719
-					}
1720
-					if (!$options['echappe_span']) {
1721
-						$trad = echappe_retour($trad, 'multi');
1722
-					}
1723
-				}
1724
-			}
1725
-			$letexte = str_replace($reg[0], $trad, $letexte);
1726
-		}
1727
-	}
1728
-
1729
-	return $letexte;
1672
+    if ($letexte
1673
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1674
+    ) {
1675
+        if (!$lang) {
1676
+            $lang = $GLOBALS['spip_lang'];
1677
+        }
1678
+
1679
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1680
+        if (is_bool($options)) {
1681
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1682
+        }
1683
+        if (!isset($options['echappe_span'])) {
1684
+            $options = array_merge($options, array('echappe_span' => false));
1685
+        }
1686
+        if (!isset($options['lang_defaut'])) {
1687
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1688
+        }
1689
+
1690
+        include_spip('inc/lang');
1691
+        foreach ($regs as $reg) {
1692
+            // chercher la version de la langue courante
1693
+            $trads = extraire_trads($reg[1]);
1694
+            if ($l = approcher_langue($trads, $lang)) {
1695
+                $trad = $trads[$l];
1696
+            } else {
1697
+                if ($options['lang_defaut'] == 'aucune') {
1698
+                    $trad = '';
1699
+                } else {
1700
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1701
+                    // ou la premiere dispo
1702
+                    // mais typographier le texte selon les regles de celle-ci
1703
+                    // Attention aux blocs multi sur plusieurs lignes
1704
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1705
+                        $l = key($trads);
1706
+                    }
1707
+                    $trad = $trads[$l];
1708
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1709
+                    $trad = $typographie($trad);
1710
+                    // Tester si on echappe en span ou en div
1711
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1712
+                    include_spip('inc/texte');
1713
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1714
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1715
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1716
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1717
+                    if (lang_dir($l) !== lang_dir($lang)) {
1718
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1719
+                    }
1720
+                    if (!$options['echappe_span']) {
1721
+                        $trad = echappe_retour($trad, 'multi');
1722
+                    }
1723
+                }
1724
+            }
1725
+            $letexte = str_replace($reg[0], $trad, $letexte);
1726
+        }
1727
+    }
1728
+
1729
+    return $letexte;
1730 1730
 }
1731 1731
 
1732 1732
 /**
@@ -1742,20 +1742,20 @@  discard block
 block discarded – undo
1742 1742
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1743 1743
  **/
1744 1744
 function extraire_trads($bloc) {
1745
-	$lang = '';
1745
+    $lang = '';
1746 1746
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1747 1747
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1748
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1749
-		$texte = trim($regs[1]);
1750
-		if ($texte or $lang) {
1751
-			$trads[$lang] = $texte;
1752
-		}
1753
-		$bloc = substr($bloc, strlen($regs[0]));
1754
-		$lang = $regs[2];
1755
-	}
1756
-	$trads[$lang] = $bloc;
1748
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1749
+        $texte = trim($regs[1]);
1750
+        if ($texte or $lang) {
1751
+            $trads[$lang] = $texte;
1752
+        }
1753
+        $bloc = substr($bloc, strlen($regs[0]));
1754
+        $lang = $regs[2];
1755
+    }
1756
+    $trads[$lang] = $bloc;
1757 1757
 
1758
-	return $trads;
1758
+    return $trads;
1759 1759
 }
1760 1760
 
1761 1761
 
@@ -1766,7 +1766,7 @@  discard block
 block discarded – undo
1766 1766
  * @return string L'initiale en majuscule
1767 1767
  */
1768 1768
 function filtre_initiale($nom) {
1769
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1769
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1770 1770
 }
1771 1771
 
1772 1772
 
@@ -1811,33 +1811,33 @@  discard block
 block discarded – undo
1811 1811
  *      - null (interne) : si on empile
1812 1812
  **/
1813 1813
 function unique($donnee, $famille = '', $cpt = false) {
1814
-	static $mem = array();
1815
-	// permettre de vider la pile et de la restaurer
1816
-	// pour le calcul de introduction...
1817
-	if ($famille == '_spip_raz_') {
1818
-		$tmp = $mem;
1819
-		$mem = array();
1820
-
1821
-		return $tmp;
1822
-	} elseif ($famille == '_spip_set_') {
1823
-		$mem = $donnee;
1824
-
1825
-		return;
1826
-	}
1827
-	// eviter une notice
1828
-	if (!isset($mem[$famille])) {
1829
-		$mem[$famille] = array();
1830
-	}
1831
-	if ($cpt) {
1832
-		return count($mem[$famille]);
1833
-	}
1834
-	// eviter une notice
1835
-	if (!isset($mem[$famille][$donnee])) {
1836
-		$mem[$famille][$donnee] = 0;
1837
-	}
1838
-	if (!($mem[$famille][$donnee]++)) {
1839
-		return $donnee;
1840
-	}
1814
+    static $mem = array();
1815
+    // permettre de vider la pile et de la restaurer
1816
+    // pour le calcul de introduction...
1817
+    if ($famille == '_spip_raz_') {
1818
+        $tmp = $mem;
1819
+        $mem = array();
1820
+
1821
+        return $tmp;
1822
+    } elseif ($famille == '_spip_set_') {
1823
+        $mem = $donnee;
1824
+
1825
+        return;
1826
+    }
1827
+    // eviter une notice
1828
+    if (!isset($mem[$famille])) {
1829
+        $mem[$famille] = array();
1830
+    }
1831
+    if ($cpt) {
1832
+        return count($mem[$famille]);
1833
+    }
1834
+    // eviter une notice
1835
+    if (!isset($mem[$famille][$donnee])) {
1836
+        $mem[$famille][$donnee] = 0;
1837
+    }
1838
+    if (!($mem[$famille][$donnee]++)) {
1839
+        return $donnee;
1840
+    }
1841 1841
 }
1842 1842
 
1843 1843
 
@@ -1865,18 +1865,18 @@  discard block
 block discarded – undo
1865 1865
  *     Une des valeurs en fonction du compteur.
1866 1866
  **/
1867 1867
 function alterner($i) {
1868
-	// recuperer les arguments (attention fonctions un peu space)
1869
-	$num = func_num_args();
1870
-	$args = func_get_args();
1868
+    // recuperer les arguments (attention fonctions un peu space)
1869
+    $num = func_num_args();
1870
+    $args = func_get_args();
1871 1871
 
1872
-	if ($num == 2 && is_array($args[1])) {
1873
-		$args = $args[1];
1874
-		array_unshift($args, '');
1875
-		$num = count($args);
1876
-	}
1872
+    if ($num == 2 && is_array($args[1])) {
1873
+        $args = $args[1];
1874
+        array_unshift($args, '');
1875
+        $num = count($args);
1876
+    }
1877 1877
 
1878
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1879
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1878
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1879
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1880 1880
 }
1881 1881
 
1882 1882
 
@@ -1901,46 +1901,46 @@  discard block
 block discarded – undo
1901 1901
  *     - Tableau complet (si 2e argument)
1902 1902
  **/
1903 1903
 function extraire_attribut($balise, $attribut, $complet = false) {
1904
-	if (is_array($balise)) {
1905
-		array_walk(
1906
-			$balise,
1907
-			function(&$a, $key, $t){
1908
-				$a = extraire_attribut($a, $t);
1909
-			},
1910
-			$attribut
1911
-		);
1912
-
1913
-		return $balise;
1914
-	}
1915
-	if (preg_match(
1916
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1917
-		. $attribut
1918
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1919
-
1920
-		$balise, $r)) {
1921
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1922
-			$r[4] = substr($r[3], 1, -1);
1923
-			$r[3] = $r[3][0];
1924
-		} elseif ($r[3] !== '') {
1925
-			$r[4] = $r[3];
1926
-			$r[3] = '';
1927
-		} else {
1928
-			$r[4] = trim($r[2]);
1929
-		}
1930
-		$att = $r[4];
1931
-		if (strpos($att, "&#") !== false) {
1932
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1933
-		}
1934
-		$att = filtrer_entites($att);
1935
-	} else {
1936
-		$att = null;
1937
-	}
1938
-
1939
-	if ($complet) {
1940
-		return array($att, $r);
1941
-	} else {
1942
-		return $att;
1943
-	}
1904
+    if (is_array($balise)) {
1905
+        array_walk(
1906
+            $balise,
1907
+            function(&$a, $key, $t){
1908
+                $a = extraire_attribut($a, $t);
1909
+            },
1910
+            $attribut
1911
+        );
1912
+
1913
+        return $balise;
1914
+    }
1915
+    if (preg_match(
1916
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1917
+        . $attribut
1918
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1919
+
1920
+        $balise, $r)) {
1921
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1922
+            $r[4] = substr($r[3], 1, -1);
1923
+            $r[3] = $r[3][0];
1924
+        } elseif ($r[3] !== '') {
1925
+            $r[4] = $r[3];
1926
+            $r[3] = '';
1927
+        } else {
1928
+            $r[4] = trim($r[2]);
1929
+        }
1930
+        $att = $r[4];
1931
+        if (strpos($att, "&#") !== false) {
1932
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1933
+        }
1934
+        $att = filtrer_entites($att);
1935
+    } else {
1936
+        $att = null;
1937
+    }
1938
+
1939
+    if ($complet) {
1940
+        return array($att, $r);
1941
+    } else {
1942
+        return $att;
1943
+    }
1944 1944
 }
1945 1945
 
1946 1946
 /**
@@ -1972,37 +1972,37 @@  discard block
 block discarded – undo
1972 1972
  *     Code html modifié
1973 1973
  **/
1974 1974
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1975
-	// preparer l'attribut
1976
-	// supprimer les &nbsp; etc mais pas les balises html
1977
-	// qui ont un sens dans un attribut value d'un input
1978
-	if ($proteger) {
1979
-		$val = attribut_html($val, false);
1980
-	}
1981
-
1982
-	// echapper les ' pour eviter tout bug
1983
-	$val = str_replace("'", "&#039;", $val);
1984
-	if ($vider and strlen($val) == 0) {
1985
-		$insert = '';
1986
-	} else {
1987
-		$insert = " $attribut='$val'";
1988
-	}
1989
-
1990
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1991
-
1992
-	if ($old !== null) {
1993
-		// Remplacer l'ancien attribut du meme nom
1994
-		$balise = $r[1] . $insert . $r[5];
1995
-	} else {
1996
-		// preferer une balise " />" (comme <img />)
1997
-		if (preg_match(',/>,', $balise)) {
1998
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1999
-		} // sinon une balise <a ...> ... </a>
2000
-		else {
2001
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2002
-		}
2003
-	}
2004
-
2005
-	return $balise;
1975
+    // preparer l'attribut
1976
+    // supprimer les &nbsp; etc mais pas les balises html
1977
+    // qui ont un sens dans un attribut value d'un input
1978
+    if ($proteger) {
1979
+        $val = attribut_html($val, false);
1980
+    }
1981
+
1982
+    // echapper les ' pour eviter tout bug
1983
+    $val = str_replace("'", "&#039;", $val);
1984
+    if ($vider and strlen($val) == 0) {
1985
+        $insert = '';
1986
+    } else {
1987
+        $insert = " $attribut='$val'";
1988
+    }
1989
+
1990
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1991
+
1992
+    if ($old !== null) {
1993
+        // Remplacer l'ancien attribut du meme nom
1994
+        $balise = $r[1] . $insert . $r[5];
1995
+    } else {
1996
+        // preferer une balise " />" (comme <img />)
1997
+        if (preg_match(',/>,', $balise)) {
1998
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1999
+        } // sinon une balise <a ...> ... </a>
2000
+        else {
2001
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2002
+        }
2003
+    }
2004
+
2005
+    return $balise;
2006 2006
 }
2007 2007
 
2008 2008
 /**
@@ -2020,7 +2020,7 @@  discard block
 block discarded – undo
2020 2020
  * @return string Code HTML sans l'attribut
2021 2021
  **/
2022 2022
 function vider_attribut($balise, $attribut) {
2023
-	return inserer_attribut($balise, $attribut, '', false, true);
2023
+    return inserer_attribut($balise, $attribut, '', false, true);
2024 2024
 }
2025 2025
 
2026 2026
 
@@ -2032,9 +2032,9 @@  discard block
 block discarded – undo
2032 2032
  * @return string
2033 2033
  */
2034 2034
 function tester_config($id, $mode = '') {
2035
-	include_spip('action/inscrire_auteur');
2035
+    include_spip('action/inscrire_auteur');
2036 2036
 
2037
-	return tester_statut_inscription($mode, $id);
2037
+    return tester_statut_inscription($mode, $id);
2038 2038
 }
2039 2039
 
2040 2040
 //
@@ -2059,7 +2059,7 @@  discard block
 block discarded – undo
2059 2059
  * @return int $a+$b
2060 2060
  **/
2061 2061
 function plus($a, $b) {
2062
-	return $a + $b;
2062
+    return $a + $b;
2063 2063
 }
2064 2064
 function strplus($a, $b) {return strize('plus', $a, $b);}
2065 2065
 /**
@@ -2078,7 +2078,7 @@  discard block
 block discarded – undo
2078 2078
  * @return int $a-$b
2079 2079
  **/
2080 2080
 function moins($a, $b) {
2081
-	return $a - $b;
2081
+    return $a - $b;
2082 2082
 }
2083 2083
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2084 2084
 
@@ -2099,7 +2099,7 @@  discard block
 block discarded – undo
2099 2099
  * @return int $a*$b
2100 2100
  **/
2101 2101
 function mult($a, $b) {
2102
-	return $a * $b;
2102
+    return $a * $b;
2103 2103
 }
2104 2104
 function strmult($a, $b) {return strize('mult', $a, $b);}
2105 2105
 
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
  * @return int $a/$b (ou 0 si $b est nul)
2121 2121
  **/
2122 2122
 function div($a, $b) {
2123
-	return $b ? $a / $b : 0;
2123
+    return $b ? $a / $b : 0;
2124 2124
 }
2125 2125
 function strdiv($a, $b) {return strize('div', $a, $b);}
2126 2126
 
@@ -2142,7 +2142,7 @@  discard block
 block discarded – undo
2142 2142
  * @return int ($nb % $mod) + $add
2143 2143
  **/
2144 2144
 function modulo($nb, $mod, $add = 0) {
2145
-	return ($mod ? $nb % $mod : 0) + $add;
2145
+    return ($mod ? $nb % $mod : 0) + $add;
2146 2146
 }
2147 2147
 
2148 2148
 
@@ -2157,24 +2157,24 @@  discard block
 block discarded – undo
2157 2157
  *      - true sinon
2158 2158
  **/
2159 2159
 function nom_acceptable($nom) {
2160
-	if (!is_string($nom)) {
2161
-		return false;
2162
-	}
2163
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2164
-		define('_TAGS_NOM_AUTEUR', '');
2165
-	}
2166
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2167
-	foreach ($tags_acceptes as $tag) {
2168
-		if (strlen($tag)) {
2169
-			$remp1[] = '<' . trim($tag) . '>';
2170
-			$remp1[] = '</' . trim($tag) . '>';
2171
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2172
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2173
-		}
2174
-	}
2175
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2160
+    if (!is_string($nom)) {
2161
+        return false;
2162
+    }
2163
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2164
+        define('_TAGS_NOM_AUTEUR', '');
2165
+    }
2166
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2167
+    foreach ($tags_acceptes as $tag) {
2168
+        if (strlen($tag)) {
2169
+            $remp1[] = '<' . trim($tag) . '>';
2170
+            $remp1[] = '</' . trim($tag) . '>';
2171
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2172
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2173
+        }
2174
+    }
2175
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2176 2176
 
2177
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2177
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2178 2178
 }
2179 2179
 
2180 2180
 
@@ -2190,14 +2190,14 @@  discard block
 block discarded – undo
2190 2190
  *      - renvoie un tableau si l'entree est un tableau
2191 2191
  **/
2192 2192
 function email_valide($adresses) {
2193
-	if (is_array($adresses)) {
2194
-		$adresses = array_map('email_valide', $adresses);
2195
-		$adresses = array_filter($adresses);
2196
-		return $adresses;
2197
-	}
2193
+    if (is_array($adresses)) {
2194
+        $adresses = array_map('email_valide', $adresses);
2195
+        $adresses = array_filter($adresses);
2196
+        return $adresses;
2197
+    }
2198 2198
 
2199
-	$email_valide = charger_fonction('email_valide', 'inc');
2200
-	return $email_valide($adresses);
2199
+    $email_valide = charger_fonction('email_valide', 'inc');
2200
+    return $email_valide($adresses);
2201 2201
 }
2202 2202
 
2203 2203
 /**
@@ -2211,20 +2211,20 @@  discard block
 block discarded – undo
2211 2211
  * @return string Texte
2212 2212
  **/
2213 2213
 function afficher_enclosures($tags) {
2214
-	$s = array();
2215
-	foreach (extraire_balises($tags, 'a') as $tag) {
2216
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2217
-			and $t = extraire_attribut($tag, 'href')
2218
-		) {
2219
-			$s[] = preg_replace(',>[^<]+</a>,S',
2220
-				'>'
2221
-				. http_img_pack('attachment-16.png', $t,
2222
-					'title="' . attribut_html($t) . '"')
2223
-				. '</a>', $tag);
2224
-		}
2225
-	}
2214
+    $s = array();
2215
+    foreach (extraire_balises($tags, 'a') as $tag) {
2216
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2217
+            and $t = extraire_attribut($tag, 'href')
2218
+        ) {
2219
+            $s[] = preg_replace(',>[^<]+</a>,S',
2220
+                '>'
2221
+                . http_img_pack('attachment-16.png', $t,
2222
+                    'title="' . attribut_html($t) . '"')
2223
+                . '</a>', $tag);
2224
+        }
2225
+    }
2226 2226
 
2227
-	return join('&nbsp;', $s);
2227
+    return join('&nbsp;', $s);
2228 2228
 }
2229 2229
 
2230 2230
 /**
@@ -2239,15 +2239,15 @@  discard block
 block discarded – undo
2239 2239
  * @return string Liens trouvés
2240 2240
  **/
2241 2241
 function afficher_tags($tags, $rels = 'tag,directory') {
2242
-	$s = array();
2243
-	foreach (extraire_balises($tags, 'a') as $tag) {
2244
-		$rel = extraire_attribut($tag, 'rel');
2245
-		if (strstr(",$rels,", ",$rel,")) {
2246
-			$s[] = $tag;
2247
-		}
2248
-	}
2242
+    $s = array();
2243
+    foreach (extraire_balises($tags, 'a') as $tag) {
2244
+        $rel = extraire_attribut($tag, 'rel');
2245
+        if (strstr(",$rels,", ",$rel,")) {
2246
+            $s[] = $tag;
2247
+        }
2248
+    }
2249 2249
 
2250
-	return join(', ', $s);
2250
+    return join(', ', $s);
2251 2251
 }
2252 2252
 
2253 2253
 
@@ -2269,21 +2269,21 @@  discard block
 block discarded – undo
2269 2269
  * @return string Tag HTML `<a>` avec microformat.
2270 2270
  **/
2271 2271
 function enclosure2microformat($e) {
2272
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2273
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2274
-	}
2275
-	$type = extraire_attribut($e, 'type');
2276
-	if (!$length = extraire_attribut($e, 'length')) {
2277
-		# <media:content : longeur dans fileSize. On tente.
2278
-		$length = extraire_attribut($e, 'fileSize');
2279
-	}
2280
-	$fichier = basename($url);
2272
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2273
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2274
+    }
2275
+    $type = extraire_attribut($e, 'type');
2276
+    if (!$length = extraire_attribut($e, 'length')) {
2277
+        # <media:content : longeur dans fileSize. On tente.
2278
+        $length = extraire_attribut($e, 'fileSize');
2279
+    }
2280
+    $fichier = basename($url);
2281 2281
 
2282
-	return '<a rel="enclosure"'
2283
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2284
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2285
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2286
-	. '>' . $fichier . '</a>';
2282
+    return '<a rel="enclosure"'
2283
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2284
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2285
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2286
+    . '>' . $fichier . '</a>';
2287 2287
 }
2288 2288
 
2289 2289
 /**
@@ -2301,24 +2301,24 @@  discard block
 block discarded – undo
2301 2301
  * @return string Tags RSS `<enclosure>`.
2302 2302
  **/
2303 2303
 function microformat2enclosure($tags) {
2304
-	$enclosures = array();
2305
-	foreach (extraire_balises($tags, 'a') as $e) {
2306
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2307
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2308
-			$type = extraire_attribut($e, 'type');
2309
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2310
-				$length = intval(extraire_attribut($e, 'length'));
2311
-			} # vieux data
2312
-			$fichier = basename($url);
2313
-			$enclosures[] = '<enclosure'
2314
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2315
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2316
-				. ($length ? ' length="' . $length . '"' : '')
2317
-				. ' />';
2318
-		}
2319
-	}
2304
+    $enclosures = array();
2305
+    foreach (extraire_balises($tags, 'a') as $e) {
2306
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2307
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2308
+            $type = extraire_attribut($e, 'type');
2309
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2310
+                $length = intval(extraire_attribut($e, 'length'));
2311
+            } # vieux data
2312
+            $fichier = basename($url);
2313
+            $enclosures[] = '<enclosure'
2314
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2315
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2316
+                . ($length ? ' length="' . $length . '"' : '')
2317
+                . ' />';
2318
+        }
2319
+    }
2320 2320
 
2321
-	return join("\n", $enclosures);
2321
+    return join("\n", $enclosures);
2322 2322
 }
2323 2323
 
2324 2324
 
@@ -2334,16 +2334,16 @@  discard block
 block discarded – undo
2334 2334
  * @return string Tags RSS Atom `<dc:subject>`.
2335 2335
  **/
2336 2336
 function tags2dcsubject($tags) {
2337
-	$subjects = '';
2338
-	foreach (extraire_balises($tags, 'a') as $e) {
2339
-		if (extraire_attribut($e, rel) == 'tag') {
2340
-			$subjects .= '<dc:subject>'
2341
-				. texte_backend(textebrut($e))
2342
-				. '</dc:subject>' . "\n";
2343
-		}
2344
-	}
2337
+    $subjects = '';
2338
+    foreach (extraire_balises($tags, 'a') as $e) {
2339
+        if (extraire_attribut($e, rel) == 'tag') {
2340
+            $subjects .= '<dc:subject>'
2341
+                . texte_backend(textebrut($e))
2342
+                . '</dc:subject>' . "\n";
2343
+        }
2344
+    }
2345 2345
 
2346
-	return $subjects;
2346
+    return $subjects;
2347 2347
 }
2348 2348
 
2349 2349
 /**
@@ -2372,23 +2372,23 @@  discard block
 block discarded – undo
2372 2372
  *     - Tableau de résultats, si tableau en entrée.
2373 2373
  **/
2374 2374
 function extraire_balise($texte, $tag = 'a') {
2375
-	if (is_array($texte)) {
2376
-		array_walk(
2377
-			$texte,
2378
-			function(&$a, $key, $t){
2379
-				$a = extraire_balise($a, $t);
2380
-			},
2381
-			$tag
2382
-		);
2375
+    if (is_array($texte)) {
2376
+        array_walk(
2377
+            $texte,
2378
+            function(&$a, $key, $t){
2379
+                $a = extraire_balise($a, $t);
2380
+            },
2381
+            $tag
2382
+        );
2383 2383
 
2384
-		return $texte;
2385
-	}
2384
+        return $texte;
2385
+    }
2386 2386
 
2387
-	if (preg_match(
2388
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2389
-		$texte, $regs)) {
2390
-		return $regs[0];
2391
-	}
2387
+    if (preg_match(
2388
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2389
+        $texte, $regs)) {
2390
+        return $regs[0];
2391
+    }
2392 2392
 }
2393 2393
 
2394 2394
 /**
@@ -2416,25 +2416,25 @@  discard block
 block discarded – undo
2416 2416
  *     - Tableau de résultats, si tableau en entrée.
2417 2417
  **/
2418 2418
 function extraire_balises($texte, $tag = 'a') {
2419
-	if (is_array($texte)) {
2420
-		array_walk(
2421
-			$texte,
2422
-			function(&$a, $key, $t){
2423
-				$a = extraire_balises($a, $t);
2424
-			},
2425
-			$tag
2426
-		);
2419
+    if (is_array($texte)) {
2420
+        array_walk(
2421
+            $texte,
2422
+            function(&$a, $key, $t){
2423
+                $a = extraire_balises($a, $t);
2424
+            },
2425
+            $tag
2426
+        );
2427 2427
 
2428
-		return $texte;
2429
-	}
2428
+        return $texte;
2429
+    }
2430 2430
 
2431
-	if (preg_match_all(
2432
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2433
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2434
-		return $regs[0];
2435
-	} else {
2436
-		return array();
2437
-	}
2431
+    if (preg_match_all(
2432
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2433
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2434
+        return $regs[0];
2435
+    } else {
2436
+        return array();
2437
+    }
2438 2438
 }
2439 2439
 
2440 2440
 /**
@@ -2463,11 +2463,11 @@  discard block
 block discarded – undo
2463 2463
  *     - `$def` si on n'a pas transmis de tableau
2464 2464
  **/
2465 2465
 function in_any($val, $vals, $def = '') {
2466
-	if (!is_array($vals) and $v = unserialize($vals)) {
2467
-		$vals = $v;
2468
-	}
2466
+    if (!is_array($vals) and $v = unserialize($vals)) {
2467
+        $vals = $v;
2468
+    }
2469 2469
 
2470
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2470
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2471 2471
 }
2472 2472
 
2473 2473
 
@@ -2488,12 +2488,12 @@  discard block
 block discarded – undo
2488 2488
  *     Résultat du calcul
2489 2489
  **/
2490 2490
 function valeur_numerique($expr) {
2491
-	$a = 0;
2492
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2493
-		eval("\$a = $expr;");
2494
-	}
2491
+    $a = 0;
2492
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2493
+        eval("\$a = $expr;");
2494
+    }
2495 2495
 
2496
-	return intval($a);
2496
+    return intval($a);
2497 2497
 }
2498 2498
 
2499 2499
 /**
@@ -2512,7 +2512,7 @@  discard block
 block discarded – undo
2512 2512
  *      Retourne `$a*$b/$c`
2513 2513
  **/
2514 2514
 function regledetrois($a, $b, $c) {
2515
-	return round($a * $b / $c);
2515
+    return round($a * $b / $c);
2516 2516
 }
2517 2517
 
2518 2518
 
@@ -2536,76 +2536,76 @@  discard block
 block discarded – undo
2536 2536
  **/
2537 2537
 function form_hidden($action) {
2538 2538
 
2539
-	$contexte = array();
2540
-	include_spip('inc/urls');
2541
-	if ($p = urls_decoder_url($action, '')
2542
-		and reset($p)
2543
-	) {
2544
-		$fond = array_shift($p);
2545
-		if ($fond != '404') {
2546
-			$contexte = array_shift($p);
2547
-			$contexte['page'] = $fond;
2548
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2549
-		}
2550
-	}
2551
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2552
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2553
-		unset($contexte['type']);
2554
-	}
2555
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2556
-		unset($contexte['type-page']);
2557
-	}
2558
-
2559
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2560
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2561
-	$values = array();
2562
-
2563
-	// d'abord avec celles de l'url
2564
-	if (false !== ($p = strpos($action, '?'))) {
2565
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2566
-			$c = explode('=', $c, 2);
2567
-			$var = array_shift($c);
2568
-			$val = array_shift($c);
2569
-			if ($var) {
2570
-				$val = rawurldecode($val);
2571
-				$var = rawurldecode($var); // decoder les [] eventuels
2572
-				if (preg_match(',\[\]$,S', $var)) {
2573
-					$values[] = array($var, $val);
2574
-				} else {
2575
-					if (!isset($values[$var])) {
2576
-						$values[$var] = array($var, $val);
2577
-					}
2578
-				}
2579
-			}
2580
-		}
2581
-	}
2582
-
2583
-	// ensuite avec celles du contexte, sans doublonner !
2584
-	foreach ($contexte as $var => $val) {
2585
-		if (preg_match(',\[\]$,S', $var)) {
2586
-			$values[] = array($var, $val);
2587
-		} else {
2588
-			if (!isset($values[$var])) {
2589
-				$values[$var] = array($var, $val);
2590
-			}
2591
-		}
2592
-	}
2593
-
2594
-	// puis on rassemble le tout
2595
-	$hidden = array();
2596
-	foreach ($values as $value) {
2597
-		list($var, $val) = $value;
2598
-		$hidden[] = '<input name="'
2599
-			. entites_html($var)
2600
-			. '"'
2601
-			. (is_null($val)
2602
-				? ''
2603
-				: ' value="' . entites_html($val) . '"'
2604
-			)
2605
-			. ' type="hidden"' . "\n/>";
2606
-	}
2607
-
2608
-	return join("", $hidden);
2539
+    $contexte = array();
2540
+    include_spip('inc/urls');
2541
+    if ($p = urls_decoder_url($action, '')
2542
+        and reset($p)
2543
+    ) {
2544
+        $fond = array_shift($p);
2545
+        if ($fond != '404') {
2546
+            $contexte = array_shift($p);
2547
+            $contexte['page'] = $fond;
2548
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2549
+        }
2550
+    }
2551
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2552
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2553
+        unset($contexte['type']);
2554
+    }
2555
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2556
+        unset($contexte['type-page']);
2557
+    }
2558
+
2559
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2560
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2561
+    $values = array();
2562
+
2563
+    // d'abord avec celles de l'url
2564
+    if (false !== ($p = strpos($action, '?'))) {
2565
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2566
+            $c = explode('=', $c, 2);
2567
+            $var = array_shift($c);
2568
+            $val = array_shift($c);
2569
+            if ($var) {
2570
+                $val = rawurldecode($val);
2571
+                $var = rawurldecode($var); // decoder les [] eventuels
2572
+                if (preg_match(',\[\]$,S', $var)) {
2573
+                    $values[] = array($var, $val);
2574
+                } else {
2575
+                    if (!isset($values[$var])) {
2576
+                        $values[$var] = array($var, $val);
2577
+                    }
2578
+                }
2579
+            }
2580
+        }
2581
+    }
2582
+
2583
+    // ensuite avec celles du contexte, sans doublonner !
2584
+    foreach ($contexte as $var => $val) {
2585
+        if (preg_match(',\[\]$,S', $var)) {
2586
+            $values[] = array($var, $val);
2587
+        } else {
2588
+            if (!isset($values[$var])) {
2589
+                $values[$var] = array($var, $val);
2590
+            }
2591
+        }
2592
+    }
2593
+
2594
+    // puis on rassemble le tout
2595
+    $hidden = array();
2596
+    foreach ($values as $value) {
2597
+        list($var, $val) = $value;
2598
+        $hidden[] = '<input name="'
2599
+            . entites_html($var)
2600
+            . '"'
2601
+            . (is_null($val)
2602
+                ? ''
2603
+                : ' value="' . entites_html($val) . '"'
2604
+            )
2605
+            . ' type="hidden"' . "\n/>";
2606
+    }
2607
+
2608
+    return join("", $hidden);
2609 2609
 }
2610 2610
 
2611 2611
 /**
@@ -2623,15 +2623,15 @@  discard block
 block discarded – undo
2623 2623
  *     Liste (première page, dernière page).
2624 2624
  **/
2625 2625
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2626
-	if ($max <= 0 or $max >= $nombre) {
2627
-		return array(1, $nombre);
2628
-	}
2626
+    if ($max <= 0 or $max >= $nombre) {
2627
+        return array(1, $nombre);
2628
+    }
2629 2629
 
2630
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2631
-	$derniere = min($nombre, $premiere + $max - 2);
2632
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2630
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2631
+    $derniere = min($nombre, $premiere + $max - 2);
2632
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2633 2633
 
2634
-	return array($premiere, $derniere);
2634
+    return array($premiere, $derniere);
2635 2635
 }
2636 2636
 
2637 2637
 
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
  *    - la première valeur du tableau sinon.
2654 2654
  **/
2655 2655
 function filtre_reset($array) {
2656
-	return !is_array($array) ? null : reset($array);
2656
+    return !is_array($array) ? null : reset($array);
2657 2657
 }
2658 2658
 
2659 2659
 /**
@@ -2674,7 +2674,7 @@  discard block
 block discarded – undo
2674 2674
  *    - la dernière valeur du tableau sinon.
2675 2675
  **/
2676 2676
 function filtre_end($array) {
2677
-	return !is_array($array) ? null : end($array);
2677
+    return !is_array($array) ? null : end($array);
2678 2678
 }
2679 2679
 
2680 2680
 /**
@@ -2694,11 +2694,11 @@  discard block
 block discarded – undo
2694 2694
  *
2695 2695
  **/
2696 2696
 function filtre_push($array, $val) {
2697
-	if (!is_array($array) or !array_push($array, $val)) {
2698
-		return '';
2699
-	}
2697
+    if (!is_array($array) or !array_push($array, $val)) {
2698
+        return '';
2699
+    }
2700 2700
 
2701
-	return $array;
2701
+    return $array;
2702 2702
 }
2703 2703
 
2704 2704
 /**
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2718 2718
  **/
2719 2719
 function filtre_find($array, $val) {
2720
-	return (is_array($array) and in_array($val, $array));
2720
+    return (is_array($array) and in_array($val, $array));
2721 2721
 }
2722 2722
 
2723 2723
 
@@ -2734,15 +2734,15 @@  discard block
 block discarded – undo
2734 2734
  *     Contenu avec urls en absolus
2735 2735
  **/
2736 2736
 function urls_absolues_css($contenu, $source) {
2737
-	$path = suivre_lien(url_absolue($source), './');
2737
+    $path = suivre_lien(url_absolue($source), './');
2738 2738
 
2739
-	return preg_replace_callback(
2740
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2741
-		function($x) use ($path) {
2742
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2743
-		},
2744
-		$contenu
2745
-	);
2739
+    return preg_replace_callback(
2740
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2741
+        function($x) use ($path) {
2742
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2743
+        },
2744
+        $contenu
2745
+    );
2746 2746
 }
2747 2747
 
2748 2748
 
@@ -2771,118 +2771,118 @@  discard block
 block discarded – undo
2771 2771
  *     Chemin du fichier CSS inversé
2772 2772
  **/
2773 2773
 function direction_css($css, $voulue = '') {
2774
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2775
-		return $css;
2776
-	}
2777
-
2778
-	// si on a precise le sens voulu en argument, le prendre en compte
2779
-	if ($voulue = strtolower($voulue)) {
2780
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2781
-			$voulue = lang_dir($voulue);
2782
-		}
2783
-	} else {
2784
-		$voulue = lang_dir();
2785
-	}
2786
-
2787
-	$r = count($r) > 1;
2788
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2789
-	$dir = $r ? 'rtl' : 'ltr';
2790
-	$ndir = $r ? 'ltr' : 'rtl';
2791
-
2792
-	if ($voulue == $dir) {
2793
-		return $css;
2794
-	}
2795
-
2796
-	if (
2797
-		// url absolue
2798
-		preg_match(",^https?:,i", $css)
2799
-		// ou qui contient un ?
2800
-		or (($p = strpos($css, '?')) !== false)
2801
-	) {
2802
-		$distant = true;
2803
-		$cssf = parse_url($css);
2804
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2805
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2806
-	} else {
2807
-		$distant = false;
2808
-		$cssf = $css;
2809
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2810
-		//propose (rien a faire dans ce cas)
2811
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2812
-		if (@file_exists($f)) {
2813
-			return $f;
2814
-		}
2815
-	}
2816
-
2817
-	// 2.
2818
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2819
-	$f = $dir_var
2820
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2821
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2822
-
2823
-	// la css peut etre distante (url absolue !)
2824
-	if ($distant) {
2825
-		include_spip('inc/distant');
2826
-		$res = recuperer_url($css);
2827
-		if (!$res or !$contenu = $res['page']) {
2828
-			return $css;
2829
-		}
2830
-	} else {
2831
-		if ((@filemtime($f) > @filemtime($css))
2832
-			and (_VAR_MODE != 'recalcul')
2833
-		) {
2834
-			return $f;
2835
-		}
2836
-		if (!lire_fichier($css, $contenu)) {
2837
-			return $css;
2838
-		}
2839
-	}
2840
-
2841
-
2842
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2843
-	include_spip("lib/csstidy/class.csstidy");
2844
-	$parser = new csstidy();
2845
-	$parser->set_cfg('optimise_shorthands', 0);
2846
-	$parser->set_cfg('reverse_left_and_right', true);
2847
-	$parser->parse($contenu);
2848
-
2849
-	$contenu = $parser->print->plain();
2850
-
2851
-
2852
-	// reperer les @import auxquels il faut propager le direction_css
2853
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2854
-	$src = array();
2855
-	$src_direction_css = array();
2856
-	$src_faux_abs = array();
2857
-	$d = dirname($css);
2858
-	foreach ($regs[1] as $k => $import_css) {
2859
-		$css_direction = direction_css("$d/$import_css", $voulue);
2860
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2861
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2862
-			$css_direction = substr($css_direction, strlen($d) + 1);
2863
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2864
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2865
-			$css_direction = substr($css_direction, strlen($dir_var));
2866
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2867
-			$css_direction = "/@@@@@@/" . $css_direction;
2868
-		}
2869
-		$src[] = $regs[0][$k];
2870
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2871
-	}
2872
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2873
-
2874
-	$contenu = urls_absolues_css($contenu, $css);
2875
-
2876
-	// virer les fausses url absolues que l'on a mis dans les import
2877
-	if (count($src_faux_abs)) {
2878
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2879
-	}
2880
-
2881
-	if (!ecrire_fichier($f, $contenu)) {
2882
-		return $css;
2883
-	}
2884
-
2885
-	return $f;
2774
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2775
+        return $css;
2776
+    }
2777
+
2778
+    // si on a precise le sens voulu en argument, le prendre en compte
2779
+    if ($voulue = strtolower($voulue)) {
2780
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2781
+            $voulue = lang_dir($voulue);
2782
+        }
2783
+    } else {
2784
+        $voulue = lang_dir();
2785
+    }
2786
+
2787
+    $r = count($r) > 1;
2788
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2789
+    $dir = $r ? 'rtl' : 'ltr';
2790
+    $ndir = $r ? 'ltr' : 'rtl';
2791
+
2792
+    if ($voulue == $dir) {
2793
+        return $css;
2794
+    }
2795
+
2796
+    if (
2797
+        // url absolue
2798
+        preg_match(",^https?:,i", $css)
2799
+        // ou qui contient un ?
2800
+        or (($p = strpos($css, '?')) !== false)
2801
+    ) {
2802
+        $distant = true;
2803
+        $cssf = parse_url($css);
2804
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2805
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2806
+    } else {
2807
+        $distant = false;
2808
+        $cssf = $css;
2809
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2810
+        //propose (rien a faire dans ce cas)
2811
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2812
+        if (@file_exists($f)) {
2813
+            return $f;
2814
+        }
2815
+    }
2816
+
2817
+    // 2.
2818
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2819
+    $f = $dir_var
2820
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2821
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2822
+
2823
+    // la css peut etre distante (url absolue !)
2824
+    if ($distant) {
2825
+        include_spip('inc/distant');
2826
+        $res = recuperer_url($css);
2827
+        if (!$res or !$contenu = $res['page']) {
2828
+            return $css;
2829
+        }
2830
+    } else {
2831
+        if ((@filemtime($f) > @filemtime($css))
2832
+            and (_VAR_MODE != 'recalcul')
2833
+        ) {
2834
+            return $f;
2835
+        }
2836
+        if (!lire_fichier($css, $contenu)) {
2837
+            return $css;
2838
+        }
2839
+    }
2840
+
2841
+
2842
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2843
+    include_spip("lib/csstidy/class.csstidy");
2844
+    $parser = new csstidy();
2845
+    $parser->set_cfg('optimise_shorthands', 0);
2846
+    $parser->set_cfg('reverse_left_and_right', true);
2847
+    $parser->parse($contenu);
2848
+
2849
+    $contenu = $parser->print->plain();
2850
+
2851
+
2852
+    // reperer les @import auxquels il faut propager le direction_css
2853
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2854
+    $src = array();
2855
+    $src_direction_css = array();
2856
+    $src_faux_abs = array();
2857
+    $d = dirname($css);
2858
+    foreach ($regs[1] as $k => $import_css) {
2859
+        $css_direction = direction_css("$d/$import_css", $voulue);
2860
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2861
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2862
+            $css_direction = substr($css_direction, strlen($d) + 1);
2863
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2864
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2865
+            $css_direction = substr($css_direction, strlen($dir_var));
2866
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2867
+            $css_direction = "/@@@@@@/" . $css_direction;
2868
+        }
2869
+        $src[] = $regs[0][$k];
2870
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2871
+    }
2872
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2873
+
2874
+    $contenu = urls_absolues_css($contenu, $css);
2875
+
2876
+    // virer les fausses url absolues que l'on a mis dans les import
2877
+    if (count($src_faux_abs)) {
2878
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2879
+    }
2880
+
2881
+    if (!ecrire_fichier($f, $contenu)) {
2882
+        return $css;
2883
+    }
2884
+
2885
+    return $f;
2886 2886
 }
2887 2887
 
2888 2888
 
@@ -2905,43 +2905,43 @@  discard block
 block discarded – undo
2905 2905
  *     - Chemin ou URL du fichier CSS source sinon.
2906 2906
  **/
2907 2907
 function url_absolue_css($css) {
2908
-	if (!preg_match(',\.css$,i', $css, $r)) {
2909
-		return $css;
2910
-	}
2908
+    if (!preg_match(',\.css$,i', $css, $r)) {
2909
+        return $css;
2910
+    }
2911 2911
 
2912
-	$url_absolue_css = url_absolue($css);
2912
+    $url_absolue_css = url_absolue($css);
2913 2913
 
2914
-	$f = basename($css, '.css');
2915
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2916
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2917
-		. '.css';
2914
+    $f = basename($css, '.css');
2915
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2916
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2917
+        . '.css';
2918 2918
 
2919
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2920
-		return $f;
2921
-	}
2919
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2920
+        return $f;
2921
+    }
2922 2922
 
2923
-	if ($url_absolue_css == $css) {
2924
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2925
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2926
-		) {
2927
-			include_spip('inc/distant');
2928
-			if (!$contenu = recuperer_page($css)) {
2929
-				return $css;
2930
-			}
2931
-		}
2932
-	} elseif (!lire_fichier($css, $contenu)) {
2933
-		return $css;
2934
-	}
2923
+    if ($url_absolue_css == $css) {
2924
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2925
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2926
+        ) {
2927
+            include_spip('inc/distant');
2928
+            if (!$contenu = recuperer_page($css)) {
2929
+                return $css;
2930
+            }
2931
+        }
2932
+    } elseif (!lire_fichier($css, $contenu)) {
2933
+        return $css;
2934
+    }
2935 2935
 
2936
-	// passer les url relatives a la css d'origine en url absolues
2937
-	$contenu = urls_absolues_css($contenu, $css);
2936
+    // passer les url relatives a la css d'origine en url absolues
2937
+    $contenu = urls_absolues_css($contenu, $css);
2938 2938
 
2939
-	// ecrire la css
2940
-	if (!ecrire_fichier($f, $contenu)) {
2941
-		return $css;
2942
-	}
2939
+    // ecrire la css
2940
+    if (!ecrire_fichier($f, $contenu)) {
2941
+        return $css;
2942
+    }
2943 2943
 
2944
-	return $f;
2944
+    return $f;
2945 2945
 }
2946 2946
 
2947 2947
 
@@ -2975,24 +2975,24 @@  discard block
 block discarded – undo
2975 2975
  *     Valeur trouvée ou valeur par défaut.
2976 2976
  **/
2977 2977
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
2978
-	foreach (explode('/', $cle) as $k) {
2978
+    foreach (explode('/', $cle) as $k) {
2979 2979
 
2980
-		$table = is_string($table) ? @unserialize($table) : $table;
2980
+        $table = is_string($table) ? @unserialize($table) : $table;
2981 2981
 
2982
-		if (is_object($table)) {
2983
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2984
-		} elseif (is_array($table)) {
2985
-			if ($conserver_null) {
2986
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2987
-			} else {
2988
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
2989
-			}
2990
-		} else {
2991
-			$table = $defaut;
2992
-		}
2993
-	}
2982
+        if (is_object($table)) {
2983
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2984
+        } elseif (is_array($table)) {
2985
+            if ($conserver_null) {
2986
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2987
+            } else {
2988
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
2989
+            }
2990
+        } else {
2991
+            $table = $defaut;
2992
+        }
2993
+    }
2994 2994
 
2995
-	return $table;
2995
+    return $table;
2996 2996
 }
2997 2997
 
2998 2998
 /**
@@ -3025,22 +3025,22 @@  discard block
 block discarded – undo
3025 3025
  *     - string : expression trouvée.
3026 3026
  **/
3027 3027
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3028
-	if (intval($modif) and $capte == 0) {
3029
-		$capte = $modif;
3030
-		$modif = "UimsS";
3031
-	}
3032
-	$expression = str_replace("\/", "/", $expression);
3033
-	$expression = str_replace("/", "\/", $expression);
3028
+    if (intval($modif) and $capte == 0) {
3029
+        $capte = $modif;
3030
+        $modif = "UimsS";
3031
+    }
3032
+    $expression = str_replace("\/", "/", $expression);
3033
+    $expression = str_replace("/", "\/", $expression);
3034 3034
 
3035
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3036
-		if (isset($r[$capte])) {
3037
-			return $r[$capte];
3038
-		} else {
3039
-			return true;
3040
-		}
3041
-	}
3035
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3036
+        if (isset($r[$capte])) {
3037
+            return $r[$capte];
3038
+        } else {
3039
+            return true;
3040
+        }
3041
+    }
3042 3042
 
3043
-	return false;
3043
+    return false;
3044 3044
 }
3045 3045
 
3046 3046
 
@@ -3067,10 +3067,10 @@  discard block
 block discarded – undo
3067 3067
  *     Texte
3068 3068
  **/
3069 3069
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3070
-	$expression = str_replace("\/", "/", $expression);
3071
-	$expression = str_replace("/", "\/", $expression);
3070
+    $expression = str_replace("\/", "/", $expression);
3071
+    $expression = str_replace("/", "\/", $expression);
3072 3072
 
3073
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3073
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3074 3074
 }
3075 3075
 
3076 3076
 
@@ -3088,21 +3088,21 @@  discard block
 block discarded – undo
3088 3088
  **/
3089 3089
 function traiter_doublons_documents(&$doublons, $letexte) {
3090 3090
 
3091
-	// Verifier dans le texte & les notes (pas beau, helas)
3092
-	$t = $letexte . $GLOBALS['les_notes'];
3091
+    // Verifier dans le texte & les notes (pas beau, helas)
3092
+    $t = $letexte . $GLOBALS['les_notes'];
3093 3093
 
3094
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3095
-		and preg_match_all(
3096
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3097
-			$t, $matches, PREG_PATTERN_ORDER)
3098
-	) {
3099
-		if (!isset($doublons['documents'])) {
3100
-			$doublons['documents'] = "";
3101
-		}
3102
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3103
-	}
3094
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3095
+        and preg_match_all(
3096
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3097
+            $t, $matches, PREG_PATTERN_ORDER)
3098
+    ) {
3099
+        if (!isset($doublons['documents'])) {
3100
+            $doublons['documents'] = "";
3101
+        }
3102
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3103
+    }
3104 3104
 
3105
-	return $letexte;
3105
+    return $letexte;
3106 3106
 }
3107 3107
 
3108 3108
 /**
@@ -3116,7 +3116,7 @@  discard block
 block discarded – undo
3116 3116
  * @return string Chaîne vide
3117 3117
  **/
3118 3118
 function vide($texte) {
3119
-	return "";
3119
+    return "";
3120 3120
 }
3121 3121
 
3122 3122
 //
@@ -3145,23 +3145,23 @@  discard block
 block discarded – undo
3145 3145
  *      Code HTML résultant
3146 3146
  **/
3147 3147
 function env_to_params($env, $ignore_params = array()) {
3148
-	$ignore_params = array_merge(
3149
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3150
-		$ignore_params
3151
-	);
3152
-	if (!is_array($env)) {
3153
-		$env = unserialize($env);
3154
-	}
3155
-	$texte = "";
3156
-	if ($env) {
3157
-		foreach ($env as $i => $j) {
3158
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3159
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3160
-			}
3161
-		}
3162
-	}
3163
-
3164
-	return $texte;
3148
+    $ignore_params = array_merge(
3149
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3150
+        $ignore_params
3151
+    );
3152
+    if (!is_array($env)) {
3153
+        $env = unserialize($env);
3154
+    }
3155
+    $texte = "";
3156
+    if ($env) {
3157
+        foreach ($env as $i => $j) {
3158
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3159
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3160
+            }
3161
+        }
3162
+    }
3163
+
3164
+    return $texte;
3165 3165
 }
3166 3166
 
3167 3167
 /**
@@ -3184,23 +3184,23 @@  discard block
 block discarded – undo
3184 3184
  *      Code HTML résultant
3185 3185
  **/
3186 3186
 function env_to_attributs($env, $ignore_params = array()) {
3187
-	$ignore_params = array_merge(
3188
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3189
-		$ignore_params
3190
-	);
3191
-	if (!is_array($env)) {
3192
-		$env = unserialize($env);
3193
-	}
3194
-	$texte = "";
3195
-	if ($env) {
3196
-		foreach ($env as $i => $j) {
3197
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3198
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3199
-			}
3200
-		}
3201
-	}
3187
+    $ignore_params = array_merge(
3188
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3189
+        $ignore_params
3190
+    );
3191
+    if (!is_array($env)) {
3192
+        $env = unserialize($env);
3193
+    }
3194
+    $texte = "";
3195
+    if ($env) {
3196
+        foreach ($env as $i => $j) {
3197
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3198
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3199
+            }
3200
+        }
3201
+    }
3202 3202
 
3203
-	return $texte;
3203
+    return $texte;
3204 3204
 }
3205 3205
 
3206 3206
 
@@ -3217,9 +3217,9 @@  discard block
 block discarded – undo
3217 3217
  * @return string Chaînes concaténés
3218 3218
  **/
3219 3219
 function concat() {
3220
-	$args = func_get_args();
3220
+    $args = func_get_args();
3221 3221
 
3222
-	return join('', $args);
3222
+    return join('', $args);
3223 3223
 }
3224 3224
 
3225 3225
 
@@ -3239,23 +3239,23 @@  discard block
 block discarded – undo
3239 3239
  *     Contenu du ou des fichiers, concaténé
3240 3240
  **/
3241 3241
 function charge_scripts($files, $script = true) {
3242
-	$flux = "";
3243
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3244
-		if (!is_string($file)) {
3245
-			continue;
3246
-		}
3247
-		if ($script) {
3248
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3249
-		}
3250
-		if ($file) {
3251
-			$path = find_in_path($file);
3252
-			if ($path) {
3253
-				$flux .= spip_file_get_contents($path);
3254
-			}
3255
-		}
3256
-	}
3242
+    $flux = "";
3243
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3244
+        if (!is_string($file)) {
3245
+            continue;
3246
+        }
3247
+        if ($script) {
3248
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3249
+        }
3250
+        if ($file) {
3251
+            $path = find_in_path($file);
3252
+            if ($path) {
3253
+                $flux .= spip_file_get_contents($path);
3254
+            }
3255
+        }
3256
+    }
3257 3257
 
3258
-	return $flux;
3258
+    return $flux;
3259 3259
 }
3260 3260
 
3261 3261
 
@@ -3277,64 +3277,64 @@  discard block
 block discarded – undo
3277 3277
  */
3278 3278
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3279 3279
 
3280
-	$img_file = $img;
3281
-	if ($p = strpos($img_file, '?')) {
3282
-		$img_file = substr($img_file,0, $p);
3283
-	}
3284
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3285
-		$img_file = chemin_image($img);
3286
-	}
3287
-	else {
3288
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3289
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3290
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3291
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3292
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3293
-			  and file_exists($variante_svg_generique)) {
3294
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3295
-					$img_file = $variante_svg_size;
3296
-				}
3297
-				else {
3298
-					$img_file = $variante_svg_generique;
3299
-				}
3300
-			}
3301
-		}
3302
-	}
3303
-	if (stripos($atts, 'width') === false) {
3304
-		// utiliser directement l'info de taille presente dans le nom
3305
-		if ((!isset($options['utiliser_suffixe_size'])
3306
-				or $options['utiliser_suffixe_size'] == true
3307
-			  or strpos($img_file, '-xx.svg') !== false)
3308
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3309
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3310
-		) {
3311
-			$largeur = $hauteur = intval($regs[1]);
3312
-		} else {
3313
-			$taille = taille_image($img_file);
3314
-			list($hauteur, $largeur) = $taille;
3315
-			if (!$hauteur or !$largeur) {
3316
-				return "";
3317
-			}
3318
-		}
3319
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3320
-	}
3321
-
3322
-	if (file_exists($img_file)) {
3323
-		$img_file = timestamp($img_file);
3324
-	}
3325
-	if ($alt === false) {
3326
-		$alt = '';
3327
-	}
3328
-	elseif($alt or $alt==='') {
3329
-		$alt = " alt='".attribut_html($alt)."'";
3330
-	}
3331
-	else {
3332
-		$alt = " alt='".attribut_html($title)."'";
3333
-	}
3334
-	return "<img src='$img_file'$alt"
3335
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3336
-	. " " . ltrim($atts)
3337
-	. " />";
3280
+    $img_file = $img;
3281
+    if ($p = strpos($img_file, '?')) {
3282
+        $img_file = substr($img_file,0, $p);
3283
+    }
3284
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3285
+        $img_file = chemin_image($img);
3286
+    }
3287
+    else {
3288
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3289
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3290
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3291
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3292
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3293
+              and file_exists($variante_svg_generique)) {
3294
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3295
+                    $img_file = $variante_svg_size;
3296
+                }
3297
+                else {
3298
+                    $img_file = $variante_svg_generique;
3299
+                }
3300
+            }
3301
+        }
3302
+    }
3303
+    if (stripos($atts, 'width') === false) {
3304
+        // utiliser directement l'info de taille presente dans le nom
3305
+        if ((!isset($options['utiliser_suffixe_size'])
3306
+                or $options['utiliser_suffixe_size'] == true
3307
+              or strpos($img_file, '-xx.svg') !== false)
3308
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3309
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3310
+        ) {
3311
+            $largeur = $hauteur = intval($regs[1]);
3312
+        } else {
3313
+            $taille = taille_image($img_file);
3314
+            list($hauteur, $largeur) = $taille;
3315
+            if (!$hauteur or !$largeur) {
3316
+                return "";
3317
+            }
3318
+        }
3319
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3320
+    }
3321
+
3322
+    if (file_exists($img_file)) {
3323
+        $img_file = timestamp($img_file);
3324
+    }
3325
+    if ($alt === false) {
3326
+        $alt = '';
3327
+    }
3328
+    elseif($alt or $alt==='') {
3329
+        $alt = " alt='".attribut_html($alt)."'";
3330
+    }
3331
+    else {
3332
+        $alt = " alt='".attribut_html($title)."'";
3333
+    }
3334
+    return "<img src='$img_file'$alt"
3335
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3336
+    . " " . ltrim($atts)
3337
+    . " />";
3338 3338
 }
3339 3339
 
3340 3340
 /**
@@ -3346,13 +3346,13 @@  discard block
 block discarded – undo
3346 3346
  * @return string
3347 3347
  */
3348 3348
 function http_style_background($img, $att = '', $size=null) {
3349
-	if ($size and is_numeric($size)){
3350
-		$size = trim($size) . "px";
3351
-	}
3352
-	return " style='background" .
3353
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3354
-		. ($size ? "background-size:{$size};" : '')
3355
-		. "'";
3349
+    if ($size and is_numeric($size)){
3350
+        $size = trim($size) . "px";
3351
+    }
3352
+    return " style='background" .
3353
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3354
+        . ($size ? "background-size:{$size};" : '')
3355
+        . "'";
3356 3356
 }
3357 3357
 
3358 3358
 /**
@@ -3368,17 +3368,17 @@  discard block
 block discarded – undo
3368 3368
  *     Code HTML de la balise IMG
3369 3369
  */
3370 3370
 function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3371
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3372
-	// ecriture courte : on donne le width en 2e arg
3373
-	if (empty($width) and is_numeric($alt)) {
3374
-		$width = $alt;
3375
-		$alt = '';
3376
-	}
3377
-	if ($width) {
3378
-		$atts .= " width='{$width}'";
3379
-	}
3380
-	return http_img_pack($img, $alt, $atts, '',
3381
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3371
+    $atts = $class ? " class='" . attribut_html($class) . "'" : '';
3372
+    // ecriture courte : on donne le width en 2e arg
3373
+    if (empty($width) and is_numeric($alt)) {
3374
+        $width = $alt;
3375
+        $alt = '';
3376
+    }
3377
+    if ($width) {
3378
+        $atts .= " width='{$width}'";
3379
+    }
3380
+    return http_img_pack($img, $alt, $atts, '',
3381
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3382 3382
 }
3383 3383
 
3384 3384
 
@@ -3394,42 +3394,42 @@  discard block
 block discarded – undo
3394 3394
  * @return string
3395 3395
  */
3396 3396
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3397
-	$img_file = $img;
3398
-	if ($p = strpos($img_file, '?')) {
3399
-		$img_file = substr($img_file,0, $p);
3400
-	}
3397
+    $img_file = $img;
3398
+    if ($p = strpos($img_file, '?')) {
3399
+        $img_file = substr($img_file,0, $p);
3400
+    }
3401 3401
 
3402
-	if (!$img_file or !$svg = file_get_contents($img_file)) {
3403
-		return '';
3404
-	}
3402
+    if (!$img_file or !$svg = file_get_contents($img_file)) {
3403
+        return '';
3404
+    }
3405 3405
 
3406
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3407
-		return '';
3408
-	}
3409
-	$balise_svg = $match[0];
3410
-	$balise_svg_source = $balise_svg;
3406
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3407
+        return '';
3408
+    }
3409
+    $balise_svg = $match[0];
3410
+    $balise_svg_source = $balise_svg;
3411 3411
 
3412
-	// entete XML à supprimer
3413
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3412
+    // entete XML à supprimer
3413
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3414 3414
 
3415
-	// IE est toujours mon ami
3416
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3417
-	if ($class) {
3418
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3419
-	}
3420
-	if ($alt){
3421
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3422
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3423
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3424
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3425
-		$balise_svg .= $title;
3426
-	}
3427
-	else {
3428
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3429
-	}
3430
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3415
+    // IE est toujours mon ami
3416
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3417
+    if ($class) {
3418
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3419
+    }
3420
+    if ($alt){
3421
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3422
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3423
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3424
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3425
+        $balise_svg .= $title;
3426
+    }
3427
+    else {
3428
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3429
+    }
3430
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3431 3431
 
3432
-	return $svg;
3432
+    return $svg;
3433 3433
 }
3434 3434
 
3435 3435
 
@@ -3452,17 +3452,17 @@  discard block
 block discarded – undo
3452 3452
  *     Code HTML résultant
3453 3453
  **/
3454 3454
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3455
-	$texte = '';
3456
-	if (is_array($tableau)) {
3457
-		foreach ($tableau as $k => $v) {
3458
-			$res = recuperer_fond('modeles/' . $modele,
3459
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3460
-			);
3461
-			$texte .= $res;
3462
-		}
3463
-	}
3455
+    $texte = '';
3456
+    if (is_array($tableau)) {
3457
+        foreach ($tableau as $k => $v) {
3458
+            $res = recuperer_fond('modeles/' . $modele,
3459
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3460
+            );
3461
+            $texte .= $res;
3462
+        }
3463
+    }
3464 3464
 
3465
-	return $texte;
3465
+    return $texte;
3466 3466
 }
3467 3467
 
3468 3468
 
@@ -3487,37 +3487,37 @@  discard block
 block discarded – undo
3487 3487
  *         - tout : retourne toutes les informations du plugin actif
3488 3488
  **/
3489 3489
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3490
-	include_spip('inc/plugin');
3491
-	$plugin = strtoupper($plugin);
3492
-	$plugins_actifs = liste_plugin_actifs();
3493
-
3494
-	if (!$plugin) {
3495
-		return serialize(array_keys($plugins_actifs));
3496
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3497
-		return '';
3498
-	} elseif (($type_info == 'est_actif') and !$reload) {
3499
-		return $plugins_actifs[$plugin] ? 1 : 0;
3500
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3501
-		return $plugins_actifs[$plugin][$type_info];
3502
-	} else {
3503
-		$get_infos = charger_fonction('get_infos', 'plugins');
3504
-		// On prend en compte les extensions
3505
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3506
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3507
-		} else {
3508
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3509
-		}
3510
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3511
-			return '';
3512
-		}
3513
-		if ($type_info == 'tout') {
3514
-			return $infos;
3515
-		} elseif ($type_info == 'est_actif') {
3516
-			return $infos ? 1 : 0;
3517
-		} else {
3518
-			return strval($infos[$type_info]);
3519
-		}
3520
-	}
3490
+    include_spip('inc/plugin');
3491
+    $plugin = strtoupper($plugin);
3492
+    $plugins_actifs = liste_plugin_actifs();
3493
+
3494
+    if (!$plugin) {
3495
+        return serialize(array_keys($plugins_actifs));
3496
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3497
+        return '';
3498
+    } elseif (($type_info == 'est_actif') and !$reload) {
3499
+        return $plugins_actifs[$plugin] ? 1 : 0;
3500
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3501
+        return $plugins_actifs[$plugin][$type_info];
3502
+    } else {
3503
+        $get_infos = charger_fonction('get_infos', 'plugins');
3504
+        // On prend en compte les extensions
3505
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3506
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3507
+        } else {
3508
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3509
+        }
3510
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3511
+            return '';
3512
+        }
3513
+        if ($type_info == 'tout') {
3514
+            return $infos;
3515
+        } elseif ($type_info == 'est_actif') {
3516
+            return $infos ? 1 : 0;
3517
+        } else {
3518
+            return strval($infos[$type_info]);
3519
+        }
3520
+    }
3521 3521
 }
3522 3522
 
3523 3523
 
@@ -3544,9 +3544,9 @@  discard block
 block discarded – undo
3544 3544
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3545 3545
  */
3546 3546
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3547
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3547
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3548 3548
 
3549
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3549
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3550 3550
 }
3551 3551
 
3552 3552
 
@@ -3576,13 +3576,13 @@  discard block
 block discarded – undo
3576 3576
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3577 3577
  */
3578 3578
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3579
-	static $puce_statut = null;
3580
-	if (!$puce_statut) {
3581
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3582
-	}
3579
+    static $puce_statut = null;
3580
+    if (!$puce_statut) {
3581
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3582
+    }
3583 3583
 
3584
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3585
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3584
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3585
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3586 3586
 }
3587 3587
 
3588 3588
 
@@ -3609,100 +3609,100 @@  discard block
 block discarded – undo
3609 3609
  *   hash du contexte
3610 3610
  */
3611 3611
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3612
-	if (is_string($c)
3613
-		and @unserialize($c) !== false
3614
-	) {
3615
-		$c = unserialize($c);
3616
-	}
3617
-
3618
-	// supprimer les parametres debut_x
3619
-	// pour que la pagination ajax ne soit pas plantee
3620
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3621
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3622
-	if (is_array($c)) {
3623
-		foreach ($c as $k => $v) {
3624
-			if (strpos($k, 'debut_') === 0) {
3625
-				unset($c[$k]);
3626
-			}
3627
-		}
3628
-	}
3629
-
3630
-	if (!function_exists('calculer_cle_action')) {
3631
-		include_spip("inc/securiser_action");
3632
-	}
3633
-
3634
-	$c = serialize($c);
3635
-	$cle = calculer_cle_action($form . $c);
3636
-	$c = "$cle:$c";
3637
-
3638
-	// on ne stocke pas les contextes dans des fichiers en cache
3639
-	// par defaut, sauf si cette configuration a été forcée
3640
-	// OU que la longueur de l’argument géneré est plus long
3641
-	// que ce qui est toléré.
3642
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3643
-	if (!$cache_contextes_ajax) {
3644
-		$env = $c;
3645
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3646
-			$env = gzdeflate($env);
3647
-			// https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3648
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3649
-				$cache_contextes_ajax = true;
3650
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3651
-			}
3652
-		}
3653
-		$env = _xor($env);
3654
-		$env = base64_encode($env);
3655
-		$len = strlen($env);
3656
-		// Si l’url est trop longue pour le navigateur
3657
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3658
-		if ($len > $max_len) {
3659
-			$cache_contextes_ajax = true;
3660
-			spip_log("Contextes AJAX forces en fichiers !"
3661
-				. " Cela arrive lorsque la valeur du contexte" 
3662
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3663
-				, _LOG_AVERTISSEMENT);
3664
-		}
3665
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3666
-		elseif (
3667
-			$max_len = @ini_get('suhosin.get.max_value_length')
3668
-			and $max_len < $len
3669
-		) {
3670
-			$cache_contextes_ajax = true;
3671
-			spip_log("Contextes AJAX forces en fichiers !"
3672
-				. " Cela arrive lorsque la valeur du contexte"
3673
-				. " depasse la longueur maximale autorisee par Suhosin"
3674
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3675
-				. " Vous devriez modifier les parametres de Suhosin"
3676
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3677
-		} 
3678
-
3679
-	}
3680
-
3681
-	if ($cache_contextes_ajax) {
3682
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3683
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3684
-		$md5 = md5($c);
3685
-		ecrire_fichier("$dir/c$md5", $c);
3686
-		$env = $md5;
3687
-	}
3688
-
3689
-	if ($emboite === null) {
3690
-		return $env;
3691
-	}
3692
-	if (!trim($emboite)) {
3693
-		return "";
3694
-	}
3695
-	// toujours encoder l'url source dans le bloc ajax
3696
-	$r = self();
3697
-	$r = ' data-origin="' . $r . '"';
3698
-	$class = 'ajaxbloc';
3699
-	if ($ajaxid and is_string($ajaxid)) {
3700
-		// ajaxid est normalement conforme a un nom de classe css
3701
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3702
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3703
-	}
3704
-
3705
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3612
+    if (is_string($c)
3613
+        and @unserialize($c) !== false
3614
+    ) {
3615
+        $c = unserialize($c);
3616
+    }
3617
+
3618
+    // supprimer les parametres debut_x
3619
+    // pour que la pagination ajax ne soit pas plantee
3620
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3621
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3622
+    if (is_array($c)) {
3623
+        foreach ($c as $k => $v) {
3624
+            if (strpos($k, 'debut_') === 0) {
3625
+                unset($c[$k]);
3626
+            }
3627
+        }
3628
+    }
3629
+
3630
+    if (!function_exists('calculer_cle_action')) {
3631
+        include_spip("inc/securiser_action");
3632
+    }
3633
+
3634
+    $c = serialize($c);
3635
+    $cle = calculer_cle_action($form . $c);
3636
+    $c = "$cle:$c";
3637
+
3638
+    // on ne stocke pas les contextes dans des fichiers en cache
3639
+    // par defaut, sauf si cette configuration a été forcée
3640
+    // OU que la longueur de l’argument géneré est plus long
3641
+    // que ce qui est toléré.
3642
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3643
+    if (!$cache_contextes_ajax) {
3644
+        $env = $c;
3645
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3646
+            $env = gzdeflate($env);
3647
+            // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3648
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3649
+                $cache_contextes_ajax = true;
3650
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3651
+            }
3652
+        }
3653
+        $env = _xor($env);
3654
+        $env = base64_encode($env);
3655
+        $len = strlen($env);
3656
+        // Si l’url est trop longue pour le navigateur
3657
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3658
+        if ($len > $max_len) {
3659
+            $cache_contextes_ajax = true;
3660
+            spip_log("Contextes AJAX forces en fichiers !"
3661
+                . " Cela arrive lorsque la valeur du contexte" 
3662
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3663
+                , _LOG_AVERTISSEMENT);
3664
+        }
3665
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3666
+        elseif (
3667
+            $max_len = @ini_get('suhosin.get.max_value_length')
3668
+            and $max_len < $len
3669
+        ) {
3670
+            $cache_contextes_ajax = true;
3671
+            spip_log("Contextes AJAX forces en fichiers !"
3672
+                . " Cela arrive lorsque la valeur du contexte"
3673
+                . " depasse la longueur maximale autorisee par Suhosin"
3674
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3675
+                . " Vous devriez modifier les parametres de Suhosin"
3676
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3677
+        } 
3678
+
3679
+    }
3680
+
3681
+    if ($cache_contextes_ajax) {
3682
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3683
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3684
+        $md5 = md5($c);
3685
+        ecrire_fichier("$dir/c$md5", $c);
3686
+        $env = $md5;
3687
+    }
3688
+
3689
+    if ($emboite === null) {
3690
+        return $env;
3691
+    }
3692
+    if (!trim($emboite)) {
3693
+        return "";
3694
+    }
3695
+    // toujours encoder l'url source dans le bloc ajax
3696
+    $r = self();
3697
+    $r = ' data-origin="' . $r . '"';
3698
+    $class = 'ajaxbloc';
3699
+    if ($ajaxid and is_string($ajaxid)) {
3700
+        // ajaxid est normalement conforme a un nom de classe css
3701
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3702
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3703
+    }
3704
+
3705
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3706 3706
 }
3707 3707
 
3708 3708
 /**
@@ -3722,36 +3722,36 @@  discard block
 block discarded – undo
3722 3722
  *   - false : erreur de décodage
3723 3723
  */
3724 3724
 function decoder_contexte_ajax($c, $form = '') {
3725
-	if (!function_exists('calculer_cle_action')) {
3726
-		include_spip("inc/securiser_action");
3727
-	}
3728
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3729
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3730
-		and lire_fichier("$dir/c$c", $contexte)
3731
-	) {
3732
-		$c = $contexte;
3733
-	} else {
3734
-		$c = @base64_decode($c);
3735
-		$c = _xor($c);
3736
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3737
-			$c = @gzinflate($c);
3738
-		}
3739
-	}
3740
-
3741
-	// extraire la signature en debut de contexte
3742
-	// et la verifier avant de deserializer
3743
-	// format : signature:donneesserializees
3744
-	if ($p = strpos($c,":")){
3745
-		$cle = substr($c,0,$p);
3746
-		$c = substr($c,$p+1);
3747
-
3748
-		if ($cle == calculer_cle_action($form . $c)) {
3749
-			$env = @unserialize($c);
3750
-			return $env;
3751
-		}
3752
-	}
3753
-
3754
-	return false;
3725
+    if (!function_exists('calculer_cle_action')) {
3726
+        include_spip("inc/securiser_action");
3727
+    }
3728
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3729
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3730
+        and lire_fichier("$dir/c$c", $contexte)
3731
+    ) {
3732
+        $c = $contexte;
3733
+    } else {
3734
+        $c = @base64_decode($c);
3735
+        $c = _xor($c);
3736
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3737
+            $c = @gzinflate($c);
3738
+        }
3739
+    }
3740
+
3741
+    // extraire la signature en debut de contexte
3742
+    // et la verifier avant de deserializer
3743
+    // format : signature:donneesserializees
3744
+    if ($p = strpos($c,":")){
3745
+        $cle = substr($c,0,$p);
3746
+        $c = substr($c,$p+1);
3747
+
3748
+        if ($cle == calculer_cle_action($form . $c)) {
3749
+            $env = @unserialize($c);
3750
+            return $env;
3751
+        }
3752
+    }
3753
+
3754
+    return false;
3755 3755
 }
3756 3756
 
3757 3757
 
@@ -3769,20 +3769,20 @@  discard block
 block discarded – undo
3769 3769
  *    Message décrypté ou encrypté
3770 3770
  **/
3771 3771
 function _xor($message, $key = null) {
3772
-	if (is_null($key)) {
3773
-		if (!function_exists('calculer_cle_action')) {
3774
-			include_spip("inc/securiser_action");
3775
-		}
3776
-		$key = pack("H*", calculer_cle_action('_xor'));
3777
-	}
3772
+    if (is_null($key)) {
3773
+        if (!function_exists('calculer_cle_action')) {
3774
+            include_spip("inc/securiser_action");
3775
+        }
3776
+        $key = pack("H*", calculer_cle_action('_xor'));
3777
+    }
3778 3778
 
3779
-	$keylen = strlen($key);
3780
-	$messagelen = strlen($message);
3781
-	for ($i = 0; $i < $messagelen; $i++) {
3782
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3783
-	}
3779
+    $keylen = strlen($key);
3780
+    $messagelen = strlen($message);
3781
+    for ($i = 0; $i < $messagelen; $i++) {
3782
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3783
+    }
3784 3784
 
3785
-	return $message;
3785
+    return $message;
3786 3786
 }
3787 3787
 
3788 3788
 /**
@@ -3840,22 +3840,22 @@  discard block
 block discarded – undo
3840 3840
  *   Code HTML
3841 3841
  */
3842 3842
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3843
-	if ($on) {
3844
-		$bal = "strong";
3845
-		$att = "class='on'";
3846
-	} else {
3847
-		$bal = 'a';
3848
-		$att = "href='$url'"
3849
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3850
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3851
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3852
-			. $evt;
3853
-	}
3854
-	if ($libelle === null) {
3855
-		$libelle = $url;
3856
-	}
3843
+    if ($on) {
3844
+        $bal = "strong";
3845
+        $att = "class='on'";
3846
+    } else {
3847
+        $bal = 'a';
3848
+        $att = "href='$url'"
3849
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3850
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3851
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3852
+            . $evt;
3853
+    }
3854
+    if ($libelle === null) {
3855
+        $libelle = $url;
3856
+    }
3857 3857
 
3858
-	return "<$bal $att>$libelle</$bal>";
3858
+    return "<$bal $att>$libelle</$bal>";
3859 3859
 }
3860 3860
 
3861 3861
 
@@ -3872,37 +3872,37 @@  discard block
 block discarded – undo
3872 3872
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3873 3873
  */
3874 3874
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3875
-	static $local_singulier_ou_pluriel = array();
3875
+    static $local_singulier_ou_pluriel = array();
3876 3876
 
3877
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
3878
-	if (!is_numeric($nb) or $nb == 0) {
3879
-		return "";
3880
-	}
3881
-	if (!is_array($vars)) {
3882
-		return "";
3883
-	}
3877
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
3878
+    if (!is_numeric($nb) or $nb == 0) {
3879
+        return "";
3880
+    }
3881
+    if (!is_array($vars)) {
3882
+        return "";
3883
+    }
3884 3884
 
3885
-	$langue = $GLOBALS['spip_lang'];
3886
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
3887
-		$local_singulier_ou_pluriel[$langue] = false;
3888
-		if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
3889
-		  or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
3890
-			$local_singulier_ou_pluriel[$langue] = $f;
3891
-		}
3892
-	}
3885
+    $langue = $GLOBALS['spip_lang'];
3886
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
3887
+        $local_singulier_ou_pluriel[$langue] = false;
3888
+        if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
3889
+          or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
3890
+            $local_singulier_ou_pluriel[$langue] = $f;
3891
+        }
3892
+    }
3893 3893
 
3894
-	// si on a une surcharge on l'utilise
3895
-	if ($local_singulier_ou_pluriel[$langue]) {
3896
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
3897
-	}
3894
+    // si on a une surcharge on l'utilise
3895
+    if ($local_singulier_ou_pluriel[$langue]) {
3896
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
3897
+    }
3898 3898
 
3899
-	// sinon traitement par defaut
3900
-	$vars[$var] = $nb;
3901
-	if ($nb >= 2) {
3902
-		return _T($chaine_plusieurs, $vars);
3903
-	} else {
3904
-		return _T($chaine_un, $vars);
3905
-	}
3899
+    // sinon traitement par defaut
3900
+    $vars[$var] = $nb;
3901
+    if ($nb >= 2) {
3902
+        return _T($chaine_plusieurs, $vars);
3903
+    } else {
3904
+        return _T($chaine_un, $vars);
3905
+    }
3906 3906
 }
3907 3907
 
3908 3908
 
@@ -3927,56 +3927,56 @@  discard block
 block discarded – undo
3927 3927
  * @return string
3928 3928
  */
3929 3929
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3930
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3931
-		$class .= ' danger';
3932
-	} elseif ($fonction == "rien.gif") {
3933
-		$fonction = "";
3934
-	} elseif ($fonction == "delsafe") {
3935
-		$fonction = "del";
3936
-	}
3937
-
3938
-	$fond_origine = $fond;
3939
-	// remappage des icone : article-24.png+new => article-new-24.png
3940
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3941
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
3942
-	}
3943
-
3944
-	// ajouter le type d'objet dans la class de l'icone
3945
-	$class .= " " . substr(basename($fond), 0, -4);
3946
-
3947
-	$alt = attribut_html($texte);
3948
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3949
-
3950
-	$ajax = "";
3951
-	if (strpos($class, "ajax") !== false) {
3952
-		$ajax = "ajax";
3953
-		if (strpos($class, "preload") !== false) {
3954
-			$ajax .= " preload";
3955
-		}
3956
-		if (strpos($class, "nocache") !== false) {
3957
-			$ajax .= " nocache";
3958
-		}
3959
-		$ajax = " class='$ajax'";
3960
-	}
3961
-
3962
-	$size = 24;
3963
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3964
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3965
-		$size = $match[1];
3966
-	}
3967
-
3968
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3969
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3970
-
3971
-	if ($type == 'lien') {
3972
-		return "<span class='icone s$size $class'>"
3973
-		. "<a href='$lien'$title$ajax$javascript>"
3974
-		. $icone
3975
-		. "<b>$texte</b>"
3976
-		. "</a></span>\n";
3977
-	} else {
3978
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3979
-	}
3930
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3931
+        $class .= ' danger';
3932
+    } elseif ($fonction == "rien.gif") {
3933
+        $fonction = "";
3934
+    } elseif ($fonction == "delsafe") {
3935
+        $fonction = "del";
3936
+    }
3937
+
3938
+    $fond_origine = $fond;
3939
+    // remappage des icone : article-24.png+new => article-new-24.png
3940
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3941
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
3942
+    }
3943
+
3944
+    // ajouter le type d'objet dans la class de l'icone
3945
+    $class .= " " . substr(basename($fond), 0, -4);
3946
+
3947
+    $alt = attribut_html($texte);
3948
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3949
+
3950
+    $ajax = "";
3951
+    if (strpos($class, "ajax") !== false) {
3952
+        $ajax = "ajax";
3953
+        if (strpos($class, "preload") !== false) {
3954
+            $ajax .= " preload";
3955
+        }
3956
+        if (strpos($class, "nocache") !== false) {
3957
+            $ajax .= " nocache";
3958
+        }
3959
+        $ajax = " class='$ajax'";
3960
+    }
3961
+
3962
+    $size = 24;
3963
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3964
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3965
+        $size = $match[1];
3966
+    }
3967
+
3968
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3969
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3970
+
3971
+    if ($type == 'lien') {
3972
+        return "<span class='icone s$size $class'>"
3973
+        . "<a href='$lien'$title$ajax$javascript>"
3974
+        . $icone
3975
+        . "<b>$texte</b>"
3976
+        . "</a></span>\n";
3977
+    } else {
3978
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3979
+    }
3980 3980
 }
3981 3981
 
3982 3982
 /**
@@ -4000,7 +4000,7 @@  discard block
 block discarded – undo
4000 4000
  *     Code HTML du lien
4001 4001
  **/
4002 4002
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4003
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4003
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4004 4004
 }
4005 4005
 
4006 4006
 /**
@@ -4035,7 +4035,7 @@  discard block
 block discarded – undo
4035 4035
  *     Code HTML du lien
4036 4036
  **/
4037 4037
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4038
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4038
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4039 4039
 }
4040 4040
 
4041 4041
 /**
@@ -4080,7 +4080,7 @@  discard block
 block discarded – undo
4080 4080
  *     Code HTML du lien
4081 4081
  **/
4082 4082
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4083
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4083
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4084 4084
 }
4085 4085
 
4086 4086
 /**
@@ -4111,7 +4111,7 @@  discard block
 block discarded – undo
4111 4111
  *     Code HTML du lien
4112 4112
  **/
4113 4113
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4114
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4114
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4115 4115
 }
4116 4116
 
4117 4117
 /**
@@ -4141,7 +4141,7 @@  discard block
 block discarded – undo
4141 4141
  *     Code HTML du lien
4142 4142
  */
4143 4143
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4144
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4144
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4145 4145
 }
4146 4146
 
4147 4147
 
@@ -4189,26 +4189,26 @@  discard block
 block discarded – undo
4189 4189
  * @return string Code CSS
4190 4190
  */
4191 4191
 function bando_images_background() {
4192
-	include_spip('inc/bandeau');
4193
-	// recuperer tous les boutons et leurs images
4194
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4192
+    include_spip('inc/bandeau');
4193
+    // recuperer tous les boutons et leurs images
4194
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4195 4195
 
4196
-	$res = "";
4197
-	foreach ($boutons as $page => $detail) {
4198
-		if ($detail->icone and strlen(trim($detail->icone))) {
4199
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4200
-		}
4201
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4202
-		if (is_array($detail->sousmenu)) {
4203
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4204
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4205
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4206
-				}
4207
-			}
4208
-		}
4209
-	}
4196
+    $res = "";
4197
+    foreach ($boutons as $page => $detail) {
4198
+        if ($detail->icone and strlen(trim($detail->icone))) {
4199
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4200
+        }
4201
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4202
+        if (is_array($detail->sousmenu)) {
4203
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4204
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4205
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4206
+                }
4207
+            }
4208
+        }
4209
+    }
4210 4210
 
4211
-	return $res;
4211
+    return $res;
4212 4212
 }
4213 4213
 
4214 4214
 /**
@@ -4227,19 +4227,19 @@  discard block
 block discarded – undo
4227 4227
  * @return string
4228 4228
  */
4229 4229
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4230
-	if ($confirm) {
4231
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4232
-		if ($callback) {
4233
-			$callback = "$confirm?($callback):false";
4234
-		} else {
4235
-			$callback = $confirm;
4236
-		}
4237
-	}
4238
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4239
-	$title = $title ? " title='$title'" : "";
4230
+    if ($confirm) {
4231
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4232
+        if ($callback) {
4233
+            $callback = "$confirm?($callback):false";
4234
+        } else {
4235
+            $callback = $confirm;
4236
+        }
4237
+    }
4238
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4239
+    $title = $title ? " title='$title'" : "";
4240 4240
 
4241
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4242
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4241
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4242
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4243 4243
 }
4244 4244
 
4245 4245
 /**
@@ -4260,78 +4260,78 @@  discard block
 block discarded – undo
4260 4260
  * @return string
4261 4261
  */
4262 4262
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4263
-	static $trouver_table = null;
4264
-	static $objets;
4265
-
4266
-	// On verifie qu'on a tout ce qu'il faut
4267
-	$id_objet = intval($id_objet);
4268
-	if (!($id_objet and $type_objet and $info)) {
4269
-		return '';
4270
-	}
4271
-
4272
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4273
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4274
-		return '';
4275
-	}
4276
-
4277
-	// Si on demande l'url, on retourne direct la fonction
4278
-	if ($info == 'url') {
4279
-		return generer_url_entite($id_objet, $type_objet);
4280
-	}
4281
-
4282
-	// Sinon on va tout chercher dans la table et on garde en memoire
4283
-	$demande_titre = ($info == 'titre');
4284
-
4285
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4286
-	if (!isset($objets[$type_objet][$id_objet])
4287
-		or
4288
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4289
-	) {
4290
-		if (!$trouver_table) {
4291
-			$trouver_table = charger_fonction('trouver_table', 'base');
4292
-		}
4293
-		$desc = $trouver_table(table_objet_sql($type_objet));
4294
-		if (!$desc) {
4295
-			return $objets[$type_objet] = false;
4296
-		}
4297
-
4298
-		// Si on demande le titre, on le gere en interne
4299
-		$champ_titre = "";
4300
-		if ($demande_titre) {
4301
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4302
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4303
-		}
4304
-		include_spip('base/abstract_sql');
4305
-		include_spip('base/connect_sql');
4306
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4307
-			'*' . $champ_titre,
4308
-			$desc['table_sql'],
4309
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4310
-		);
4311
-	}
4312
-
4313
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4314
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4315
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4316
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4317
-	else {
4318
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4319
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4320
-		} // Sinon on prend directement le champ SQL tel quel
4321
-		else {
4322
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4323
-		}
4324
-	}
4325
-
4326
-	// On va ensuite appliquer les traitements automatiques si besoin
4327
-	if (!$etoile) {
4328
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4329
-		// mais ce fonctionnement est a ameliorer !
4330
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4331
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4332
-	}
4333
-
4334
-	return $info_generee;
4263
+    static $trouver_table = null;
4264
+    static $objets;
4265
+
4266
+    // On verifie qu'on a tout ce qu'il faut
4267
+    $id_objet = intval($id_objet);
4268
+    if (!($id_objet and $type_objet and $info)) {
4269
+        return '';
4270
+    }
4271
+
4272
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4273
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4274
+        return '';
4275
+    }
4276
+
4277
+    // Si on demande l'url, on retourne direct la fonction
4278
+    if ($info == 'url') {
4279
+        return generer_url_entite($id_objet, $type_objet);
4280
+    }
4281
+
4282
+    // Sinon on va tout chercher dans la table et on garde en memoire
4283
+    $demande_titre = ($info == 'titre');
4284
+
4285
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4286
+    if (!isset($objets[$type_objet][$id_objet])
4287
+        or
4288
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4289
+    ) {
4290
+        if (!$trouver_table) {
4291
+            $trouver_table = charger_fonction('trouver_table', 'base');
4292
+        }
4293
+        $desc = $trouver_table(table_objet_sql($type_objet));
4294
+        if (!$desc) {
4295
+            return $objets[$type_objet] = false;
4296
+        }
4297
+
4298
+        // Si on demande le titre, on le gere en interne
4299
+        $champ_titre = "";
4300
+        if ($demande_titre) {
4301
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4302
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4303
+        }
4304
+        include_spip('base/abstract_sql');
4305
+        include_spip('base/connect_sql');
4306
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4307
+            '*' . $champ_titre,
4308
+            $desc['table_sql'],
4309
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4310
+        );
4311
+    }
4312
+
4313
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4314
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4315
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4316
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4317
+    else {
4318
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4319
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4320
+        } // Sinon on prend directement le champ SQL tel quel
4321
+        else {
4322
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4323
+        }
4324
+    }
4325
+
4326
+    // On va ensuite appliquer les traitements automatiques si besoin
4327
+    if (!$etoile) {
4328
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4329
+        // mais ce fonctionnement est a ameliorer !
4330
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4331
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4332
+    }
4333
+
4334
+    return $info_generee;
4335 4335
 }
4336 4336
 
4337 4337
 /**
@@ -4345,44 +4345,44 @@  discard block
 block discarded – undo
4345 4345
  * @return string
4346 4346
  */
4347 4347
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4348
-	if (!$champ) {
4349
-		return $texte;
4350
-	}
4348
+    if (!$champ) {
4349
+        return $texte;
4350
+    }
4351 4351
 	
4352
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4353
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4354
-	include_spip('inc/texte');
4352
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4353
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4354
+    include_spip('inc/texte');
4355 4355
 	
4356
-	$champ = strtoupper($champ);
4357
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4358
-	if (!$traitements or !is_array($traitements)) {
4359
-		return $texte;
4360
-	}
4356
+    $champ = strtoupper($champ);
4357
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4358
+    if (!$traitements or !is_array($traitements)) {
4359
+        return $texte;
4360
+    }
4361 4361
 
4362
-	$traitement = '';
4363
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4364
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4365
-		$table_objet = table_objet($table_objet);
4366
-		if (isset($traitements[$table_objet])) {
4367
-			$traitement = $traitements[$table_objet];
4368
-		}
4369
-	}
4370
-	if (!$traitement and isset($traitements[0])) {
4371
-		$traitement = $traitements[0];
4372
-	}
4373
-	// (sinon prendre le premier de la liste par defaut ?)
4362
+    $traitement = '';
4363
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4364
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4365
+        $table_objet = table_objet($table_objet);
4366
+        if (isset($traitements[$table_objet])) {
4367
+            $traitement = $traitements[$table_objet];
4368
+        }
4369
+    }
4370
+    if (!$traitement and isset($traitements[0])) {
4371
+        $traitement = $traitements[0];
4372
+    }
4373
+    // (sinon prendre le premier de la liste par defaut ?)
4374 4374
 
4375
-	if (!$traitement) {
4376
-		return $texte;
4377
-	}
4375
+    if (!$traitement) {
4376
+        return $texte;
4377
+    }
4378 4378
 
4379
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4379
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4380 4380
 
4381
-	// Fournir $connect et $Pile[0] au traitement si besoin
4382
-	$Pile = array(0 => $env);
4383
-	eval("\$texte = $traitement;");
4381
+    // Fournir $connect et $Pile[0] au traitement si besoin
4382
+    $Pile = array(0 => $env);
4383
+    eval("\$texte = $traitement;");
4384 4384
 
4385
-	return $texte;
4385
+    return $texte;
4386 4386
 }
4387 4387
 
4388 4388
 
@@ -4396,21 +4396,21 @@  discard block
 block discarded – undo
4396 4396
  * @return string
4397 4397
  */
4398 4398
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4399
-	include_spip('inc/liens');
4400
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4401
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4402
-	// le raccourcis n'est plus valide
4403
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4404
-	// on essaye avec generer_info_entite ?
4405
-	if (!strlen($titre) and !$connect) {
4406
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4407
-	}
4408
-	if (!strlen($titre)) {
4409
-		$titre = _T('info_sans_titre');
4410
-	}
4411
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4399
+    include_spip('inc/liens');
4400
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4401
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4402
+    // le raccourcis n'est plus valide
4403
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4404
+    // on essaye avec generer_info_entite ?
4405
+    if (!strlen($titre) and !$connect) {
4406
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4407
+    }
4408
+    if (!strlen($titre)) {
4409
+        $titre = _T('info_sans_titre');
4410
+    }
4411
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4412 4412
 
4413
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4413
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4414 4414
 }
4415 4415
 
4416 4416
 
@@ -4427,15 +4427,15 @@  discard block
 block discarded – undo
4427 4427
  * @return string
4428 4428
  */
4429 4429
 function wrap($texte, $wrap) {
4430
-	$balises = extraire_balises($wrap);
4431
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4432
-		$texte = $wrap . $texte;
4433
-		$regs = array_reverse($regs[1]);
4434
-		$wrap = "</" . implode("></", $regs) . ">";
4435
-		$texte = $texte . $wrap;
4436
-	}
4430
+    $balises = extraire_balises($wrap);
4431
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4432
+        $texte = $wrap . $texte;
4433
+        $regs = array_reverse($regs[1]);
4434
+        $wrap = "</" . implode("></", $regs) . ">";
4435
+        $texte = $texte . $wrap;
4436
+    }
4437 4437
 
4438
-	return $texte;
4438
+    return $texte;
4439 4439
 }
4440 4440
 
4441 4441
 
@@ -4455,43 +4455,43 @@  discard block
 block discarded – undo
4455 4455
  * @return array|mixed|string
4456 4456
  */
4457 4457
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4458
-	if (is_string($u)) {
4459
-		$u = typo($u);
4458
+    if (is_string($u)) {
4459
+        $u = typo($u);
4460 4460
 
4461
-		return $u;
4462
-	}
4461
+        return $u;
4462
+    }
4463 4463
 
4464
-	// caster $u en array si besoin
4465
-	if (is_object($u)) {
4466
-		$u = (array)$u;
4467
-	}
4464
+    // caster $u en array si besoin
4465
+    if (is_object($u)) {
4466
+        $u = (array)$u;
4467
+    }
4468 4468
 
4469
-	if (is_array($u)) {
4470
-		$out = "";
4471
-		// toutes les cles sont numeriques ?
4472
-		// et aucun enfant n'est un tableau
4473
-		// liste simple separee par des virgules
4474
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4475
-		$array_values = array_map('is_array', $u);
4476
-		$object_values = array_map('is_object', $u);
4477
-		if (array_sum($numeric_keys) == count($numeric_keys)
4478
-			and !array_sum($array_values)
4479
-			and !array_sum($object_values)
4480
-		) {
4481
-			return join(", ", array_map('filtre_print_dist', $u));
4482
-		}
4469
+    if (is_array($u)) {
4470
+        $out = "";
4471
+        // toutes les cles sont numeriques ?
4472
+        // et aucun enfant n'est un tableau
4473
+        // liste simple separee par des virgules
4474
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4475
+        $array_values = array_map('is_array', $u);
4476
+        $object_values = array_map('is_object', $u);
4477
+        if (array_sum($numeric_keys) == count($numeric_keys)
4478
+            and !array_sum($array_values)
4479
+            and !array_sum($object_values)
4480
+        ) {
4481
+            return join(", ", array_map('filtre_print_dist', $u));
4482
+        }
4483 4483
 
4484
-		// sinon on passe a la ligne et on indente
4485
-		$i_str = str_pad("", $indent, " ");
4486
-		foreach ($u as $k => $v) {
4487
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4488
-		}
4484
+        // sinon on passe a la ligne et on indente
4485
+        $i_str = str_pad("", $indent, " ");
4486
+        foreach ($u as $k => $v) {
4487
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4488
+        }
4489 4489
 
4490
-		return $out;
4491
-	}
4490
+        return $out;
4491
+    }
4492 4492
 
4493
-	// on sait pas quoi faire...
4494
-	return $u;
4493
+    // on sait pas quoi faire...
4494
+    return $u;
4495 4495
 }
4496 4496
 
4497 4497
 
@@ -4504,10 +4504,10 @@  discard block
 block discarded – undo
4504 4504
  * @return string|array
4505 4505
  */
4506 4506
 function objet_info($objet, $info) {
4507
-	$table = table_objet_sql($objet);
4508
-	$infos = lister_tables_objets_sql($table);
4507
+    $table = table_objet_sql($objet);
4508
+    $infos = lister_tables_objets_sql($table);
4509 4509
 
4510
-	return (isset($infos[$info]) ? $infos[$info] : '');
4510
+    return (isset($infos[$info]) ? $infos[$info] : '');
4511 4511
 }
4512 4512
 
4513 4513
 /**
@@ -4522,11 +4522,11 @@  discard block
 block discarded – undo
4522 4522
  *     Texte traduit du comptage, tel que '3 articles'
4523 4523
  */
4524 4524
 function objet_afficher_nb($nb, $objet) {
4525
-	if (!$nb) {
4526
-		return _T(objet_info($objet, 'info_aucun_objet'));
4527
-	} else {
4528
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4529
-	}
4525
+    if (!$nb) {
4526
+        return _T(objet_info($objet, 'info_aucun_objet'));
4527
+    } else {
4528
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4529
+    }
4530 4530
 }
4531 4531
 
4532 4532
 /**
@@ -4538,11 +4538,11 @@  discard block
 block discarded – undo
4538 4538
  * @return string
4539 4539
  */
4540 4540
 function objet_icone($objet, $taille = 24, $class='') {
4541
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4542
-	$icone = chemin_image($icone);
4543
-	$balise_img = charger_filtre('balise_img');
4541
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4542
+    $icone = chemin_image($icone);
4543
+    $balise_img = charger_filtre('balise_img');
4544 4544
 
4545
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4545
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4546 4546
 }
4547 4547
 
4548 4548
 /**
@@ -4563,12 +4563,12 @@  discard block
 block discarded – undo
4563 4563
  * @return string
4564 4564
  */
4565 4565
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4566
-	$chaine = explode(':',$chaine);
4567
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4568
-		return $t;
4569
-	}
4570
-	$chaine = implode(':',$chaine);
4571
-	return _T($chaine, $args, $options);
4566
+    $chaine = explode(':',$chaine);
4567
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4568
+        return $t;
4569
+    }
4570
+    $chaine = implode(':',$chaine);
4571
+    return _T($chaine, $args, $options);
4572 4572
 }
4573 4573
 
4574 4574
 /**
@@ -4582,17 +4582,17 @@  discard block
 block discarded – undo
4582 4582
  * @return string      Code HTML
4583 4583
  */
4584 4584
 function insert_head_css_conditionnel($flux) {
4585
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4586
-		and $p = strpos($flux, '<!-- insert_head -->')
4587
-	) {
4588
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4589
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4590
-			$p = $p1;
4591
-		}
4592
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4593
-	}
4585
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4586
+        and $p = strpos($flux, '<!-- insert_head -->')
4587
+    ) {
4588
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4589
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4590
+            $p = $p1;
4591
+        }
4592
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4593
+    }
4594 4594
 
4595
-	return $flux;
4595
+    return $flux;
4596 4596
 }
4597 4597
 
4598 4598
 /**
@@ -4613,69 +4613,69 @@  discard block
 block discarded – undo
4613 4613
  * @return string
4614 4614
  */
4615 4615
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4616
-	if (isset($contexte['format'])) {
4617
-		$extension = $contexte['format'];
4618
-		unset($contexte['format']);
4619
-	} else {
4620
-		$extension = "html";
4621
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4622
-			$extension = $m[1];
4623
-		}
4624
-	}
4625
-	// recuperer le contenu produit par le squelette
4626
-	$options['raw'] = true;
4627
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4628
-
4629
-	// calculer le nom de la css
4630
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4631
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4632
-	$contexte_implicite = calculer_contexte_implicite();
4633
-
4634
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4635
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4636
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4637
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4638
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4639
-	}
4640
-	else {
4641
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4642
-		ksort($contexte);
4643
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4644
-	}
4645
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4646
-
4647
-	// mettre a jour le fichier si il n'existe pas
4648
-	// ou trop ancien
4649
-	// le dernier fichier produit est toujours suffixe par .last
4650
-	// et recopie sur le fichier cible uniquement si il change
4651
-	if (!file_exists($filename)
4652
-		or !file_exists($filename . ".last")
4653
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4654
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4655
-	) {
4656
-		$contenu = $cache['texte'];
4657
-		// passer les urls en absolu si c'est une css
4658
-		if ($extension == "css") {
4659
-			$contenu = urls_absolues_css($contenu,
4660
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4661
-		}
4662
-
4663
-		$comment = '';
4664
-		// ne pas insérer de commentaire si c'est du json
4665
-		if ($extension != "json") {
4666
-			$comment = "/* #PRODUIRE{fond=$fond";
4667
-			foreach ($contexte as $k => $v) {
4668
-				$comment .= ",$k=$v";
4669
-			}
4670
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4671
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4672
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4673
-		}
4674
-		// et ecrire le fichier si il change
4675
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4676
-	}
4677
-
4678
-	return timestamp($filename);
4616
+    if (isset($contexte['format'])) {
4617
+        $extension = $contexte['format'];
4618
+        unset($contexte['format']);
4619
+    } else {
4620
+        $extension = "html";
4621
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4622
+            $extension = $m[1];
4623
+        }
4624
+    }
4625
+    // recuperer le contenu produit par le squelette
4626
+    $options['raw'] = true;
4627
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4628
+
4629
+    // calculer le nom de la css
4630
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4631
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4632
+    $contexte_implicite = calculer_contexte_implicite();
4633
+
4634
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4635
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4636
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4637
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4638
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4639
+    }
4640
+    else {
4641
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4642
+        ksort($contexte);
4643
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4644
+    }
4645
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4646
+
4647
+    // mettre a jour le fichier si il n'existe pas
4648
+    // ou trop ancien
4649
+    // le dernier fichier produit est toujours suffixe par .last
4650
+    // et recopie sur le fichier cible uniquement si il change
4651
+    if (!file_exists($filename)
4652
+        or !file_exists($filename . ".last")
4653
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4654
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4655
+    ) {
4656
+        $contenu = $cache['texte'];
4657
+        // passer les urls en absolu si c'est une css
4658
+        if ($extension == "css") {
4659
+            $contenu = urls_absolues_css($contenu,
4660
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4661
+        }
4662
+
4663
+        $comment = '';
4664
+        // ne pas insérer de commentaire si c'est du json
4665
+        if ($extension != "json") {
4666
+            $comment = "/* #PRODUIRE{fond=$fond";
4667
+            foreach ($contexte as $k => $v) {
4668
+                $comment .= ",$k=$v";
4669
+            }
4670
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4671
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4672
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4673
+        }
4674
+        // et ecrire le fichier si il change
4675
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4676
+    }
4677
+
4678
+    return timestamp($filename);
4679 4679
 }
4680 4680
 
4681 4681
 /**
@@ -4688,14 +4688,14 @@  discard block
 block discarded – undo
4688 4688
  *    $fichier auquel on a ajouté le timestamp
4689 4689
  */
4690 4690
 function timestamp($fichier) {
4691
-	if (!$fichier
4692
-		or !file_exists($fichier)
4693
-		or !$m = filemtime($fichier)
4694
-	) {
4695
-		return $fichier;
4696
-	}
4691
+    if (!$fichier
4692
+        or !file_exists($fichier)
4693
+        or !$m = filemtime($fichier)
4694
+    ) {
4695
+        return $fichier;
4696
+    }
4697 4697
 
4698
-	return "$fichier?$m";
4698
+    return "$fichier?$m";
4699 4699
 }
4700 4700
 
4701 4701
 /**
@@ -4705,11 +4705,11 @@  discard block
 block discarded – undo
4705 4705
  * @return string
4706 4706
  */
4707 4707
 function supprimer_timestamp($url) {
4708
-	if (strpos($url, "?") === false) {
4709
-		return $url;
4710
-	}
4708
+    if (strpos($url, "?") === false) {
4709
+        return $url;
4710
+    }
4711 4711
 
4712
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4712
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4713 4713
 }
4714 4714
 
4715 4715
 /**
@@ -4724,9 +4724,9 @@  discard block
 block discarded – undo
4724 4724
  * @return string
4725 4725
  */
4726 4726
 function filtre_nettoyer_titre_email_dist($titre) {
4727
-	include_spip('inc/envoyer_mail');
4727
+    include_spip('inc/envoyer_mail');
4728 4728
 
4729
-	return nettoyer_titre_email($titre);
4729
+    return nettoyer_titre_email($titre);
4730 4730
 }
4731 4731
 
4732 4732
 /**
@@ -4748,19 +4748,19 @@  discard block
 block discarded – undo
4748 4748
  * @return string
4749 4749
  */
4750 4750
 function filtre_chercher_rubrique_dist(
4751
-	$titre,
4752
-	$id_objet,
4753
-	$id_parent,
4754
-	$objet,
4755
-	$id_secteur,
4756
-	$restreint,
4757
-	$actionable = false,
4758
-	$retour_sans_cadre = false
4751
+    $titre,
4752
+    $id_objet,
4753
+    $id_parent,
4754
+    $objet,
4755
+    $id_secteur,
4756
+    $restreint,
4757
+    $actionable = false,
4758
+    $retour_sans_cadre = false
4759 4759
 ) {
4760
-	include_spip('inc/filtres_ecrire');
4760
+    include_spip('inc/filtres_ecrire');
4761 4761
 
4762
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4763
-		$retour_sans_cadre);
4762
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4763
+        $retour_sans_cadre);
4764 4764
 }
4765 4765
 
4766 4766
 /**
@@ -4789,56 +4789,56 @@  discard block
 block discarded – undo
4789 4789
  *     Chaîne vide si l'accès est autorisé
4790 4790
  */
4791 4791
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4792
-	if ($ok) {
4793
-		return '';
4794
-	}
4795
-
4796
-	// Vider tous les tampons
4797
-	$level = @ob_get_level();
4798
-	while ($level--) {
4799
-		@ob_end_clean();
4800
-	}
4801
-
4802
-	include_spip('inc/headers');
4803
-
4804
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4805
-	if ($url) {
4806
-		redirige_par_entete($url, '', $statut);
4807
-	}
4808
-
4809
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4810
-	if (!is_numeric($statut) and is_null($message)) {
4811
-		$message = $statut;
4812
-		$statut = 0;
4813
-	}
4814
-	if (!$message) {
4815
-		$message = '';
4816
-	}
4817
-	$statut = intval($statut);
4818
-
4819
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4820
-	if (test_espace_prive()) {
4821
-		if (!$statut or !in_array($statut, array(404, 403))) {
4822
-			$statut = 403;
4823
-		}
4824
-		http_status(403);
4825
-		$echec = charger_fonction('403', 'exec');
4826
-		$echec($message);
4827
-	} else {
4828
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4829
-		if (!$statut) {
4830
-			$statut = 404;
4831
-		}
4832
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4833
-		http_status($statut);
4834
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4835
-		if ($statut >= 400) {
4836
-			echo recuperer_fond("$statut", array('erreur' => $message));
4837
-		}
4838
-	}
4839
-
4840
-
4841
-	exit;
4792
+    if ($ok) {
4793
+        return '';
4794
+    }
4795
+
4796
+    // Vider tous les tampons
4797
+    $level = @ob_get_level();
4798
+    while ($level--) {
4799
+        @ob_end_clean();
4800
+    }
4801
+
4802
+    include_spip('inc/headers');
4803
+
4804
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4805
+    if ($url) {
4806
+        redirige_par_entete($url, '', $statut);
4807
+    }
4808
+
4809
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4810
+    if (!is_numeric($statut) and is_null($message)) {
4811
+        $message = $statut;
4812
+        $statut = 0;
4813
+    }
4814
+    if (!$message) {
4815
+        $message = '';
4816
+    }
4817
+    $statut = intval($statut);
4818
+
4819
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4820
+    if (test_espace_prive()) {
4821
+        if (!$statut or !in_array($statut, array(404, 403))) {
4822
+            $statut = 403;
4823
+        }
4824
+        http_status(403);
4825
+        $echec = charger_fonction('403', 'exec');
4826
+        $echec($message);
4827
+    } else {
4828
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4829
+        if (!$statut) {
4830
+            $statut = 404;
4831
+        }
4832
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4833
+        http_status($statut);
4834
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4835
+        if ($statut >= 400) {
4836
+            echo recuperer_fond("$statut", array('erreur' => $message));
4837
+        }
4838
+    }
4839
+
4840
+
4841
+    exit;
4842 4842
 }
4843 4843
 
4844 4844
 /**
@@ -4849,11 +4849,11 @@  discard block
 block discarded – undo
4849 4849
  * @return string
4850 4850
  */
4851 4851
 function filtre_compacte_dist($source, $format = null) {
4852
-	if (function_exists('compacte')) {
4853
-		return compacte($source, $format);
4854
-	}
4852
+    if (function_exists('compacte')) {
4853
+        return compacte($source, $format);
4854
+    }
4855 4855
 
4856
-	return $source;
4856
+    return $source;
4857 4857
 }
4858 4858
 
4859 4859
 
@@ -4865,29 +4865,29 @@  discard block
 block discarded – undo
4865 4865
  * @return string
4866 4866
  */
4867 4867
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
4868
-	$l = strlen($passe);
4869
-
4870
-	if ($l<=8 or !$afficher_partiellement){
4871
-		if (!$l) {
4872
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4873
-		}
4874
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
4875
-	}
4876
-
4877
-	if (is_null($portion_pourcent)) {
4878
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4879
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4880
-		}
4881
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4882
-	}
4883
-	if ($portion_pourcent >= 100) {
4884
-		return $passe;
4885
-	}
4886
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
4887
-	$e = max($e, 0);
4888
-	$mid = str_pad('',$l-2*$e,'*');
4889
-	if ($e>0 and strlen($mid)>8){
4890
-		$mid = '***...***';
4891
-	}
4892
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4868
+    $l = strlen($passe);
4869
+
4870
+    if ($l<=8 or !$afficher_partiellement){
4871
+        if (!$l) {
4872
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4873
+        }
4874
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
4875
+    }
4876
+
4877
+    if (is_null($portion_pourcent)) {
4878
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4879
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4880
+        }
4881
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4882
+    }
4883
+    if ($portion_pourcent >= 100) {
4884
+        return $passe;
4885
+    }
4886
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
4887
+    $e = max($e, 0);
4888
+    $mid = str_pad('',$l-2*$e,'*');
4889
+    if ($e>0 and strlen($mid)>8){
4890
+        $mid = '***...***';
4891
+    }
4892
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4893 4893
 }
4894 4894
\ No newline at end of file
Please login to merge, or discard this patch.