Completed
Push — master ( b141e8...cdf6f6 )
by cam
04:43
created
ecrire/inc/filtres.php 1 patch
Indentation   +2003 added lines, -2003 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,77 +474,77 @@  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
-		and (
494
-			file_exists(supprimer_timestamp($is_file))
495
-			or tester_url_absolue($is_file)
496
-		)
497
-	) {
498
-		array_unshift($args, "<img src='$is_file' />");
499
-		$res = call_user_func_array($filtre, $args);
500
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
501
-		return $res;
502
-	}
503
-
504
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
505
-	if (preg_match_all(
506
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
507
-		$texte, $tags, PREG_SET_ORDER)) {
508
-		foreach ($tags as $tag) {
509
-			$class = extraire_attribut($tag[3], 'class');
510
-			if (!$class or
511
-				(strpos($class, 'filtre_inactif') === false
512
-					// compat historique a virer en 3.2
513
-					and strpos($class, 'no_image_filtrer') === false)
514
-			) {
515
-				array_unshift($args, $tag[3]);
516
-				if ($reduit = call_user_func_array($filtre, $args)) {
517
-					// En cas de span spip_documents, modifier le style=...width:
518
-					if ($tag[1]) {
519
-						$w = extraire_attribut($reduit, 'width');
520
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
521
-							$w = $regs[1];
522
-						}
523
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
524
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
525
-							$replace = inserer_attribut($tag[1], 'style', $style);
526
-							$texte = str_replace($tag[1], $replace, $texte);
527
-						}
528
-					}
529
-					// traiter aussi un eventuel mouseover
530
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
531
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
532
-							$srcover = $match[1];
533
-							array_shift($args);
534
-							array_unshift($args, "<img src='" . $match[1] . "' />");
535
-							$srcover_filter = call_user_func_array($filtre, $args);
536
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
537
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
538
-						}
539
-					}
540
-					$texte = str_replace($tag[3], $reduit, $texte);
541
-				}
542
-				array_shift($args);
543
-			}
544
-		}
545
-	}
546
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
547
-	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
+        and (
494
+            file_exists(supprimer_timestamp($is_file))
495
+            or tester_url_absolue($is_file)
496
+        )
497
+    ) {
498
+        array_unshift($args, "<img src='$is_file' />");
499
+        $res = call_user_func_array($filtre, $args);
500
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
501
+        return $res;
502
+    }
503
+
504
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
505
+    if (preg_match_all(
506
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
507
+        $texte, $tags, PREG_SET_ORDER)) {
508
+        foreach ($tags as $tag) {
509
+            $class = extraire_attribut($tag[3], 'class');
510
+            if (!$class or
511
+                (strpos($class, 'filtre_inactif') === false
512
+                    // compat historique a virer en 3.2
513
+                    and strpos($class, 'no_image_filtrer') === false)
514
+            ) {
515
+                array_unshift($args, $tag[3]);
516
+                if ($reduit = call_user_func_array($filtre, $args)) {
517
+                    // En cas de span spip_documents, modifier le style=...width:
518
+                    if ($tag[1]) {
519
+                        $w = extraire_attribut($reduit, 'width');
520
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
521
+                            $w = $regs[1];
522
+                        }
523
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
524
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
525
+                            $replace = inserer_attribut($tag[1], 'style', $style);
526
+                            $texte = str_replace($tag[1], $replace, $texte);
527
+                        }
528
+                    }
529
+                    // traiter aussi un eventuel mouseover
530
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
531
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
532
+                            $srcover = $match[1];
533
+                            array_shift($args);
534
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
535
+                            $srcover_filter = call_user_func_array($filtre, $args);
536
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
537
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
538
+                        }
539
+                    }
540
+                    $texte = str_replace($tag[3], $reduit, $texte);
541
+                }
542
+                array_shift($args);
543
+            }
544
+        }
545
+    }
546
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
547
+    return $texte;
548 548
 }
549 549
 
550 550
 /**
@@ -559,65 +559,65 @@  discard block
 block discarded – undo
559 559
  **/
560 560
 function taille_image($img, $force_refresh = false) {
561 561
 
562
-	static $largeur_img = array(), $hauteur_img = array();
563
-	$srcWidth = 0;
564
-	$srcHeight = 0;
565
-
566
-	$src = extraire_attribut($img, 'src');
567
-
568
-	if (!$src) {
569
-		$src = $img;
570
-	} else {
571
-		$srcWidth = extraire_attribut($img, 'width');
572
-		$srcHeight = extraire_attribut($img, 'height');
573
-	}
574
-
575
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
576
-	// la copie locale a toutes les chances d'etre la ou de resservir
577
-	if (tester_url_absolue($src)) {
578
-		include_spip('inc/distant');
579
-		$fichier = copie_locale($src);
580
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
581
-	}
582
-	if (($p = strpos($src, '?')) !== false) {
583
-		$src = substr($src, 0, $p);
584
-	}
585
-
586
-	$srcsize = false;
587
-	if (isset($largeur_img[$src]) and !$force_refresh) {
588
-		$srcWidth = $largeur_img[$src];
589
-	}
590
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
591
-		$srcHeight = $hauteur_img[$src];
592
-	}
593
-	if (!$srcWidth or !$srcHeight) {
594
-
595
-		if (file_exists($src)
596
-			and $srcsize = spip_getimagesize($src)
597
-		) {
598
-			if (!$srcWidth) {
599
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
600
-			}
601
-			if (!$srcHeight) {
602
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
603
-			}
604
-		}
605
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
606
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
607
-		elseif (@file_exists($f = "$src.src")
608
-			and lire_fichier($f, $valeurs)
609
-			and $valeurs = unserialize($valeurs)
610
-		) {
611
-			if (!$srcWidth) {
612
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
613
-			}
614
-			if (!$srcHeight) {
615
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
616
-			}
617
-		}
618
-	}
619
-
620
-	return array($srcHeight, $srcWidth);
562
+    static $largeur_img = array(), $hauteur_img = array();
563
+    $srcWidth = 0;
564
+    $srcHeight = 0;
565
+
566
+    $src = extraire_attribut($img, 'src');
567
+
568
+    if (!$src) {
569
+        $src = $img;
570
+    } else {
571
+        $srcWidth = extraire_attribut($img, 'width');
572
+        $srcHeight = extraire_attribut($img, 'height');
573
+    }
574
+
575
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
576
+    // la copie locale a toutes les chances d'etre la ou de resservir
577
+    if (tester_url_absolue($src)) {
578
+        include_spip('inc/distant');
579
+        $fichier = copie_locale($src);
580
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
581
+    }
582
+    if (($p = strpos($src, '?')) !== false) {
583
+        $src = substr($src, 0, $p);
584
+    }
585
+
586
+    $srcsize = false;
587
+    if (isset($largeur_img[$src]) and !$force_refresh) {
588
+        $srcWidth = $largeur_img[$src];
589
+    }
590
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
591
+        $srcHeight = $hauteur_img[$src];
592
+    }
593
+    if (!$srcWidth or !$srcHeight) {
594
+
595
+        if (file_exists($src)
596
+            and $srcsize = spip_getimagesize($src)
597
+        ) {
598
+            if (!$srcWidth) {
599
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
600
+            }
601
+            if (!$srcHeight) {
602
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
603
+            }
604
+        }
605
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
606
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
607
+        elseif (@file_exists($f = "$src.src")
608
+            and lire_fichier($f, $valeurs)
609
+            and $valeurs = unserialize($valeurs)
610
+        ) {
611
+            if (!$srcWidth) {
612
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
613
+            }
614
+            if (!$srcHeight) {
615
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
616
+            }
617
+        }
618
+    }
619
+
620
+    return array($srcHeight, $srcWidth);
621 621
 }
622 622
 
623 623
 
@@ -635,12 +635,12 @@  discard block
 block discarded – undo
635 635
  *     Largeur en pixels, NULL ou 0 si aucune image.
636 636
  **/
637 637
 function largeur($img) {
638
-	if (!$img) {
639
-		return;
640
-	}
641
-	list($h, $l) = taille_image($img);
638
+    if (!$img) {
639
+        return;
640
+    }
641
+    list($h, $l) = taille_image($img);
642 642
 
643
-	return $l;
643
+    return $l;
644 644
 }
645 645
 
646 646
 /**
@@ -657,12 +657,12 @@  discard block
 block discarded – undo
657 657
  *     Hauteur en pixels, NULL ou 0 si aucune image.
658 658
  **/
659 659
 function hauteur($img) {
660
-	if (!$img) {
661
-		return;
662
-	}
663
-	list($h, $l) = taille_image($img);
660
+    if (!$img) {
661
+        return;
662
+    }
663
+    list($h, $l) = taille_image($img);
664 664
 
665
-	return $h;
665
+    return $h;
666 666
 }
667 667
 
668 668
 
@@ -682,11 +682,11 @@  discard block
 block discarded – undo
682 682
  * @return string
683 683
  **/
684 684
 function corriger_entites_html($texte) {
685
-	if (strpos($texte, '&amp;') === false) {
686
-		return $texte;
687
-	}
685
+    if (strpos($texte, '&amp;') === false) {
686
+        return $texte;
687
+    }
688 688
 
689
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
689
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
690 690
 }
691 691
 
692 692
 /**
@@ -701,11 +701,11 @@  discard block
 block discarded – undo
701 701
  * @return string
702 702
  **/
703 703
 function corriger_toutes_entites_html($texte) {
704
-	if (strpos($texte, '&amp;') === false) {
705
-		return $texte;
706
-	}
704
+    if (strpos($texte, '&amp;') === false) {
705
+        return $texte;
706
+    }
707 707
 
708
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
708
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
709 709
 }
710 710
 
711 711
 /**
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
  * @return string
716 716
  **/
717 717
 function proteger_amp($texte) {
718
-	return str_replace('&', '&amp;', $texte);
718
+    return str_replace('&', '&amp;', $texte);
719 719
 }
720 720
 
721 721
 
@@ -746,20 +746,20 @@  discard block
 block discarded – undo
746 746
  * @return mixed|string
747 747
  */
748 748
 function entites_html($texte, $tout = false, $quote = true) {
749
-	if (!is_string($texte) or !$texte
750
-		or strpbrk($texte, "&\"'<>") == false
751
-	) {
752
-		return $texte;
753
-	}
754
-	include_spip('inc/texte');
755
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
756
-	$flags |= ENT_HTML401;
757
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
758
-	if ($tout) {
759
-		return corriger_toutes_entites_html($texte);
760
-	} else {
761
-		return corriger_entites_html($texte);
762
-	}
749
+    if (!is_string($texte) or !$texte
750
+        or strpbrk($texte, "&\"'<>") == false
751
+    ) {
752
+        return $texte;
753
+    }
754
+    include_spip('inc/texte');
755
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
756
+    $flags |= ENT_HTML401;
757
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
758
+    if ($tout) {
759
+        return corriger_toutes_entites_html($texte);
760
+    } else {
761
+        return corriger_entites_html($texte);
762
+    }
763 763
 }
764 764
 
765 765
 /**
@@ -778,37 +778,37 @@  discard block
 block discarded – undo
778 778
  *     Texte converti
779 779
  **/
780 780
 function filtrer_entites($texte) {
781
-	if (strpos($texte, '&') === false) {
782
-		return $texte;
783
-	}
784
-	// filtrer
785
-	$texte = html2unicode($texte);
786
-	// remettre le tout dans le charset cible
787
-	$texte = unicode2charset($texte);
788
-	// cas particulier des " et ' qu'il faut filtrer aussi
789
-	// (on le faisait deja avec un &quot;)
790
-	if (strpos($texte, "&#") !== false) {
791
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
792
-	}
781
+    if (strpos($texte, '&') === false) {
782
+        return $texte;
783
+    }
784
+    // filtrer
785
+    $texte = html2unicode($texte);
786
+    // remettre le tout dans le charset cible
787
+    $texte = unicode2charset($texte);
788
+    // cas particulier des " et ' qu'il faut filtrer aussi
789
+    // (on le faisait deja avec un &quot;)
790
+    if (strpos($texte, "&#") !== false) {
791
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
792
+    }
793 793
 
794
-	return $texte;
794
+    return $texte;
795 795
 }
796 796
 
797 797
 
798 798
 if (!function_exists('filtre_filtrer_entites_dist')) {
799
-	/**
800
-	 * Version sécurisée de filtrer_entites
801
-	 * 
802
-	 * @uses interdire_scripts()
803
-	 * @uses filtrer_entites()
804
-	 * 
805
-	 * @param string $t
806
-	 * @return string
807
-	 */
808
-	function filtre_filtrer_entites_dist($t) {
809
-		include_spip('inc/texte');
810
-		return interdire_scripts(filtrer_entites($t));
811
-	}
799
+    /**
800
+     * Version sécurisée de filtrer_entites
801
+     * 
802
+     * @uses interdire_scripts()
803
+     * @uses filtrer_entites()
804
+     * 
805
+     * @param string $t
806
+     * @return string
807
+     */
808
+    function filtre_filtrer_entites_dist($t) {
809
+        include_spip('inc/texte');
810
+        return interdire_scripts(filtrer_entites($t));
811
+    }
812 812
 }
813 813
 
814 814
 
@@ -823,18 +823,18 @@  discard block
 block discarded – undo
823 823
  * @return string|array
824 824
  **/
825 825
 function supprimer_caracteres_illegaux($texte) {
826
-	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";
827
-	static $to = null;
826
+    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";
827
+    static $to = null;
828 828
 
829
-	if (is_array($texte)) {
830
-		return array_map('supprimer_caracteres_illegaux', $texte);
831
-	}
829
+    if (is_array($texte)) {
830
+        return array_map('supprimer_caracteres_illegaux', $texte);
831
+    }
832 832
 
833
-	if (!$to) {
834
-		$to = str_repeat('-', strlen($from));
835
-	}
833
+    if (!$to) {
834
+        $to = str_repeat('-', strlen($from));
835
+    }
836 836
 
837
-	return strtr($texte, $from, $to);
837
+    return strtr($texte, $from, $to);
838 838
 }
839 839
 
840 840
 /**
@@ -846,10 +846,10 @@  discard block
 block discarded – undo
846 846
  * @return string|array
847 847
  **/
848 848
 function corriger_caracteres($texte) {
849
-	$texte = corriger_caracteres_windows($texte);
850
-	$texte = supprimer_caracteres_illegaux($texte);
849
+    $texte = corriger_caracteres_windows($texte);
850
+    $texte = supprimer_caracteres_illegaux($texte);
851 851
 
852
-	return $texte;
852
+    return $texte;
853 853
 }
854 854
 
855 855
 /**
@@ -867,40 +867,40 @@  discard block
 block discarded – undo
867 867
  */
868 868
 function texte_backend($texte) {
869 869
 
870
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
870
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
871 871
 
872
-	// si on a des liens ou des images, les passer en absolu
873
-	$texte = liens_absolus($texte);
872
+    // si on a des liens ou des images, les passer en absolu
873
+    $texte = liens_absolus($texte);
874 874
 
875
-	// echapper les tags &gt; &lt;
876
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
875
+    // echapper les tags &gt; &lt;
876
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
877 877
 
878
-	// importer les &eacute;
879
-	$texte = filtrer_entites($texte);
878
+    // importer les &eacute;
879
+    $texte = filtrer_entites($texte);
880 880
 
881
-	// " -> &quot; et tout ce genre de choses
882
-	$u = $GLOBALS['meta']['pcre_u'];
883
-	$texte = str_replace("&nbsp;", " ", $texte);
884
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
885
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
886
-	$texte = entites_html($texte, false, false);
887
-	// mais bien echapper les double quotes !
888
-	$texte = str_replace('"', '&#034;', $texte);
881
+    // " -> &quot; et tout ce genre de choses
882
+    $u = $GLOBALS['meta']['pcre_u'];
883
+    $texte = str_replace("&nbsp;", " ", $texte);
884
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
885
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
886
+    $texte = entites_html($texte, false, false);
887
+    // mais bien echapper les double quotes !
888
+    $texte = str_replace('"', '&#034;', $texte);
889 889
 
890
-	// verifier le charset
891
-	$texte = charset2unicode($texte);
890
+    // verifier le charset
891
+    $texte = charset2unicode($texte);
892 892
 
893
-	// Caracteres problematiques en iso-latin 1
894
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
895
-		$texte = str_replace(chr(156), '&#156;', $texte);
896
-		$texte = str_replace(chr(140), '&#140;', $texte);
897
-		$texte = str_replace(chr(159), '&#159;', $texte);
898
-	}
893
+    // Caracteres problematiques en iso-latin 1
894
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
895
+        $texte = str_replace(chr(156), '&#156;', $texte);
896
+        $texte = str_replace(chr(140), '&#140;', $texte);
897
+        $texte = str_replace(chr(159), '&#159;', $texte);
898
+    }
899 899
 
900
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
901
-	// et le caractere apostrophe alourdit les squelettes avec PHP
902
-	// ==> on les remplace par l'entite HTML
903
-	return str_replace($apostrophe, "'", $texte);
900
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
901
+    // et le caractere apostrophe alourdit les squelettes avec PHP
902
+    // ==> on les remplace par l'entite HTML
903
+    return str_replace($apostrophe, "'", $texte);
904 904
 }
905 905
 
906 906
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  *     Texte encodé et quote pour XML
918 918
  */
919 919
 function texte_backendq($texte) {
920
-	return addslashes(texte_backend($texte));
920
+    return addslashes(texte_backend($texte));
921 921
 }
922 922
 
923 923
 
@@ -940,9 +940,9 @@  discard block
 block discarded – undo
940 940
  *     Numéro de titre, sinon chaîne vide
941 941
  **/
942 942
 function supprimer_numero($texte) {
943
-	return preg_replace(
944
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
945
-		"", $texte);
943
+    return preg_replace(
944
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
945
+        "", $texte);
946 946
 }
947 947
 
948 948
 /**
@@ -965,13 +965,13 @@  discard block
 block discarded – undo
965 965
  *     Numéro de titre, sinon chaîne vide
966 966
  **/
967 967
 function recuperer_numero($texte) {
968
-	if (preg_match(
969
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
970
-		$texte, $regs)) {
971
-		return strval($regs[1]);
972
-	} else {
973
-		return '';
974
-	}
968
+    if (preg_match(
969
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
970
+        $texte, $regs)) {
971
+        return strval($regs[1]);
972
+    } else {
973
+        return '';
974
+    }
975 975
 }
976 976
 
977 977
 /**
@@ -998,13 +998,13 @@  discard block
 block discarded – undo
998 998
  *     Texte converti
999 999
  **/
1000 1000
 function supprimer_tags($texte, $rempl = "") {
1001
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1002
-	// ne pas oublier un < final non ferme car coupe
1003
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1004
-	// mais qui peut aussi etre un simple signe plus petit que
1005
-	$texte = str_replace('<', '&lt;', $texte);
1001
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1002
+    // ne pas oublier un < final non ferme car coupe
1003
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1004
+    // mais qui peut aussi etre un simple signe plus petit que
1005
+    $texte = str_replace('<', '&lt;', $texte);
1006 1006
 
1007
-	return $texte;
1007
+    return $texte;
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1027,9 +1027,9 @@  discard block
 block discarded – undo
1027 1027
  *     Texte converti
1028 1028
  **/
1029 1029
 function echapper_tags($texte, $rempl = "") {
1030
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1030
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1031 1031
 
1032
-	return $texte;
1032
+    return $texte;
1033 1033
 }
1034 1034
 
1035 1035
 /**
@@ -1050,18 +1050,18 @@  discard block
 block discarded – undo
1050 1050
  *     Texte converti
1051 1051
  **/
1052 1052
 function textebrut($texte) {
1053
-	$u = $GLOBALS['meta']['pcre_u'];
1054
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1055
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1056
-	$texte = preg_replace("/^\n+/", "", $texte);
1057
-	$texte = preg_replace("/\n+$/", "", $texte);
1058
-	$texte = preg_replace("/\n +/", "\n", $texte);
1059
-	$texte = supprimer_tags($texte);
1060
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1061
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1062
-	$texte = str_replace("&#8217;", "'", $texte);
1053
+    $u = $GLOBALS['meta']['pcre_u'];
1054
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1055
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1056
+    $texte = preg_replace("/^\n+/", "", $texte);
1057
+    $texte = preg_replace("/\n+$/", "", $texte);
1058
+    $texte = preg_replace("/\n +/", "\n", $texte);
1059
+    $texte = supprimer_tags($texte);
1060
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1061
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1062
+    $texte = str_replace("&#8217;", "'", $texte);
1063 1063
 
1064
-	return $texte;
1064
+    return $texte;
1065 1065
 }
1066 1066
 
1067 1067
 
@@ -1077,17 +1077,17 @@  discard block
 block discarded – undo
1077 1077
  *     Texte avec liens ouvrants
1078 1078
  **/
1079 1079
 function liens_ouvrants($texte) {
1080
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1081
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1082
-		foreach ($liens[0] as $a) {
1083
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1084
-			$ablank = inserer_attribut($a, 'rel', $rel);
1085
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1086
-			$texte = str_replace($a, $ablank, $texte);
1087
-		}
1088
-	}
1080
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1081
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1082
+        foreach ($liens[0] as $a) {
1083
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1084
+            $ablank = inserer_attribut($a, 'rel', $rel);
1085
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1086
+            $texte = str_replace($a, $ablank, $texte);
1087
+        }
1088
+    }
1089 1089
 
1090
-	return $texte;
1090
+    return $texte;
1091 1091
 }
1092 1092
 
1093 1093
 /**
@@ -1097,22 +1097,22 @@  discard block
 block discarded – undo
1097 1097
  * @return string
1098 1098
  */
1099 1099
 function liens_nofollow($texte) {
1100
-	if (stripos($texte, "<a") === false) {
1101
-		return $texte;
1102
-	}
1100
+    if (stripos($texte, "<a") === false) {
1101
+        return $texte;
1102
+    }
1103 1103
 
1104
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1105
-		foreach ($regs[0] as $a) {
1106
-			$rel = extraire_attribut($a, "rel");
1107
-			if (strpos($rel, "nofollow") === false) {
1108
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1109
-				$anofollow = inserer_attribut($a, "rel", $rel);
1110
-				$texte = str_replace($a, $anofollow, $texte);
1111
-			}
1112
-		}
1113
-	}
1104
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1105
+        foreach ($regs[0] as $a) {
1106
+            $rel = extraire_attribut($a, "rel");
1107
+            if (strpos($rel, "nofollow") === false) {
1108
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1109
+                $anofollow = inserer_attribut($a, "rel", $rel);
1110
+                $texte = str_replace($a, $anofollow, $texte);
1111
+            }
1112
+        }
1113
+    }
1114 1114
 
1115
-	return $texte;
1115
+    return $texte;
1116 1116
 }
1117 1117
 
1118 1118
 /**
@@ -1131,12 +1131,12 @@  discard block
 block discarded – undo
1131 1131
  *     Texte sans paraghaphes
1132 1132
  **/
1133 1133
 function PtoBR($texte) {
1134
-	$u = $GLOBALS['meta']['pcre_u'];
1135
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1136
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1137
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1134
+    $u = $GLOBALS['meta']['pcre_u'];
1135
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1136
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1137
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1138 1138
 
1139
-	return $texte;
1139
+    return $texte;
1140 1140
 }
1141 1141
 
1142 1142
 
@@ -1160,14 +1160,14 @@  discard block
 block discarded – undo
1160 1160
  * @return string Texte encadré du style CSS
1161 1161
  */
1162 1162
 function lignes_longues($texte) {
1163
-	if (!strlen(trim($texte))) {
1164
-		return $texte;
1165
-	}
1166
-	include_spip('inc/texte');
1167
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1168
-		'div' : 'span';
1163
+    if (!strlen(trim($texte))) {
1164
+        return $texte;
1165
+    }
1166
+    include_spip('inc/texte');
1167
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1168
+        'div' : 'span';
1169 1169
 
1170
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1170
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1171 1171
 }
1172 1172
 
1173 1173
 /**
@@ -1186,30 +1186,30 @@  discard block
 block discarded – undo
1186 1186
  * @return string Texte en majuscule
1187 1187
  */
1188 1188
 function majuscules($texte) {
1189
-	if (!strlen($texte)) {
1190
-		return '';
1191
-	}
1189
+    if (!strlen($texte)) {
1190
+        return '';
1191
+    }
1192 1192
 
1193
-	// Cas du turc
1194
-	if ($GLOBALS['spip_lang'] == 'tr') {
1195
-		# remplacer hors des tags et des entites
1196
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1197
-			foreach ($regs as $n => $match) {
1198
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1199
-			}
1200
-		}
1193
+    // Cas du turc
1194
+    if ($GLOBALS['spip_lang'] == 'tr') {
1195
+        # remplacer hors des tags et des entites
1196
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1197
+            foreach ($regs as $n => $match) {
1198
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1199
+            }
1200
+        }
1201 1201
 
1202
-		$texte = str_replace('i', '&#304;', $texte);
1202
+        $texte = str_replace('i', '&#304;', $texte);
1203 1203
 
1204
-		if ($regs) {
1205
-			foreach ($regs as $n => $match) {
1206
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1207
-			}
1208
-		}
1209
-	}
1204
+        if ($regs) {
1205
+            foreach ($regs as $n => $match) {
1206
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1207
+            }
1208
+        }
1209
+    }
1210 1210
 
1211
-	// Cas general
1212
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1211
+    // Cas general
1212
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1213 1213
 }
1214 1214
 
1215 1215
 /**
@@ -1227,29 +1227,29 @@  discard block
 block discarded – undo
1227 1227
  * @return string
1228 1228
  **/
1229 1229
 function taille_en_octets($taille) {
1230
-	if (!defined('_KILOBYTE')) {
1231
-		/**
1232
-		 * Définit le nombre d'octets dans un Kilobyte
1233
-		 *
1234
-		 * @var int
1235
-		 **/
1236
-		define('_KILOBYTE', 1024);
1237
-	}
1230
+    if (!defined('_KILOBYTE')) {
1231
+        /**
1232
+         * Définit le nombre d'octets dans un Kilobyte
1233
+         *
1234
+         * @var int
1235
+         **/
1236
+        define('_KILOBYTE', 1024);
1237
+    }
1238 1238
 
1239
-	if ($taille < 1) {
1240
-		return '';
1241
-	}
1242
-	if ($taille < _KILOBYTE) {
1243
-		$taille = _T('taille_octets', array('taille' => $taille));
1244
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1245
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1246
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1247
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1248
-	} else {
1249
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1250
-	}
1239
+    if ($taille < 1) {
1240
+        return '';
1241
+    }
1242
+    if ($taille < _KILOBYTE) {
1243
+        $taille = _T('taille_octets', array('taille' => $taille));
1244
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1245
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1246
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1247
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1248
+    } else {
1249
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1250
+    }
1251 1251
 
1252
-	return $taille;
1252
+    return $taille;
1253 1253
 }
1254 1254
 
1255 1255
 
@@ -1271,15 +1271,15 @@  discard block
 block discarded – undo
1271 1271
  *     Texte prêt pour être utilisé en attribut HTML
1272 1272
  **/
1273 1273
 function attribut_html($texte, $textebrut = true) {
1274
-	$u = $GLOBALS['meta']['pcre_u'];
1275
-	if ($textebrut) {
1276
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1277
-	}
1278
-	$texte = texte_backend($texte);
1279
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1274
+    $u = $GLOBALS['meta']['pcre_u'];
1275
+    if ($textebrut) {
1276
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1277
+    }
1278
+    $texte = texte_backend($texte);
1279
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1280 1280
 
1281
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1282
-		$texte);
1281
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1282
+        $texte);
1283 1283
 }
1284 1284
 
1285 1285
 
@@ -1299,12 +1299,12 @@  discard block
 block discarded – undo
1299 1299
  *     URL ou chaîne vide
1300 1300
  **/
1301 1301
 function vider_url($url, $entites = true) {
1302
-	# un message pour abs_url
1303
-	$GLOBALS['mode_abs_url'] = 'url';
1304
-	$url = trim($url);
1305
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1302
+    # un message pour abs_url
1303
+    $GLOBALS['mode_abs_url'] = 'url';
1304
+    $url = trim($url);
1305
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1306 1306
 
1307
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1307
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1308 1308
 }
1309 1309
 
1310 1310
 
@@ -1319,10 +1319,10 @@  discard block
 block discarded – undo
1319 1319
  * @return string Adresse email maquillée
1320 1320
  **/
1321 1321
 function antispam($texte) {
1322
-	include_spip('inc/acces');
1323
-	$masque = creer_pass_aleatoire(3);
1322
+    include_spip('inc/acces');
1323
+    $masque = creer_pass_aleatoire(3);
1324 1324
 
1325
-	return preg_replace("/@/", " $masque ", $texte);
1325
+    return preg_replace("/@/", " $masque ", $texte);
1326 1326
 }
1327 1327
 
1328 1328
 /**
@@ -1354,12 +1354,12 @@  discard block
 block discarded – undo
1354 1354
  *     True si on a le droit d'accès, false sinon.
1355 1355
  **/
1356 1356
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1357
-	include_spip('inc/acces');
1358
-	if ($op) {
1359
-		$dir .= " $op $args";
1360
-	}
1357
+    include_spip('inc/acces');
1358
+    if ($op) {
1359
+        $dir .= " $op $args";
1360
+    }
1361 1361
 
1362
-	return verifier_low_sec($id_auteur, $cle, $dir);
1362
+    return verifier_low_sec($id_auteur, $cle, $dir);
1363 1363
 }
1364 1364
 
1365 1365
 /**
@@ -1384,11 +1384,11 @@  discard block
 block discarded – undo
1384 1384
  *     Retourne $texte, sinon $sinon.
1385 1385
  **/
1386 1386
 function sinon($texte, $sinon = '') {
1387
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1388
-		return $texte;
1389
-	} else {
1390
-		return $sinon;
1391
-	}
1387
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1388
+        return $texte;
1389
+    } else {
1390
+        return $sinon;
1391
+    }
1392 1392
 }
1393 1393
 
1394 1394
 /**
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
  * @return mixed
1413 1413
  **/
1414 1414
 function choixsivide($a, $vide, $pasvide) {
1415
-	return $a ? $pasvide : $vide;
1415
+    return $a ? $pasvide : $vide;
1416 1416
 }
1417 1417
 
1418 1418
 /**
@@ -1436,7 +1436,7 @@  discard block
 block discarded – undo
1436 1436
  * @return mixed
1437 1437
  **/
1438 1438
 function choixsiegal($a1, $a2, $v, $f) {
1439
-	return ($a1 == $a2) ? $v : $f;
1439
+    return ($a1 == $a2) ? $v : $f;
1440 1440
 }
1441 1441
 
1442 1442
 //
@@ -1455,13 +1455,13 @@  discard block
 block discarded – undo
1455 1455
  * @return string
1456 1456
  **/
1457 1457
 function filtrer_ical($texte) {
1458
-	#include_spip('inc/charsets');
1459
-	$texte = html2unicode($texte);
1460
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1461
-	$texte = preg_replace("/\n/", " ", $texte);
1462
-	$texte = preg_replace("/,/", "\,", $texte);
1458
+    #include_spip('inc/charsets');
1459
+    $texte = html2unicode($texte);
1460
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1461
+    $texte = preg_replace("/\n/", " ", $texte);
1462
+    $texte = preg_replace("/,/", "\,", $texte);
1463 1463
 
1464
-	return $texte;
1464
+    return $texte;
1465 1465
 }
1466 1466
 
1467 1467
 
@@ -1486,53 +1486,53 @@  discard block
 block discarded – undo
1486 1486
  * @return string
1487 1487
  **/
1488 1488
 function post_autobr($texte, $delim = "\n_ ") {
1489
-	if (!function_exists('echappe_html')) {
1490
-		include_spip('inc/texte_mini');
1491
-	}
1492
-	$texte = str_replace("\r\n", "\r", $texte);
1493
-	$texte = str_replace("\r", "\n", $texte);
1494
-
1495
-	if (preg_match(",\n+$,", $texte, $fin)) {
1496
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1497
-	} else {
1498
-		$fin = '';
1499
-	}
1500
-
1501
-	$texte = echappe_html($texte, '', true);
1502
-
1503
-	// echapper les modeles
1504
-	if (strpos($texte, "<") !== false) {
1505
-		include_spip('inc/lien');
1506
-		if (defined('_PREG_MODELE')) {
1507
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1508
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1509
-		}
1510
-	}
1511
-
1512
-	$debut = '';
1513
-	$suite = $texte;
1514
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1515
-		$debut .= substr($suite, 0, $t - 1);
1516
-		$suite = substr($suite, $t);
1517
-		$car = substr($suite, 0, 1);
1518
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1519
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1520
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1521
-		) {
1522
-			$debut .= $delim;
1523
-		} else {
1524
-			$debut .= "\n";
1525
-		}
1526
-		if (preg_match(",^\n+,", $suite, $regs)) {
1527
-			$debut .= $regs[0];
1528
-			$suite = substr($suite, strlen($regs[0]));
1529
-		}
1530
-	}
1531
-	$texte = $debut . $suite;
1532
-
1533
-	$texte = echappe_retour($texte);
1534
-
1535
-	return $texte . $fin;
1489
+    if (!function_exists('echappe_html')) {
1490
+        include_spip('inc/texte_mini');
1491
+    }
1492
+    $texte = str_replace("\r\n", "\r", $texte);
1493
+    $texte = str_replace("\r", "\n", $texte);
1494
+
1495
+    if (preg_match(",\n+$,", $texte, $fin)) {
1496
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1497
+    } else {
1498
+        $fin = '';
1499
+    }
1500
+
1501
+    $texte = echappe_html($texte, '', true);
1502
+
1503
+    // echapper les modeles
1504
+    if (strpos($texte, "<") !== false) {
1505
+        include_spip('inc/lien');
1506
+        if (defined('_PREG_MODELE')) {
1507
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1508
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1509
+        }
1510
+    }
1511
+
1512
+    $debut = '';
1513
+    $suite = $texte;
1514
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1515
+        $debut .= substr($suite, 0, $t - 1);
1516
+        $suite = substr($suite, $t);
1517
+        $car = substr($suite, 0, 1);
1518
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1519
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1520
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1521
+        ) {
1522
+            $debut .= $delim;
1523
+        } else {
1524
+            $debut .= "\n";
1525
+        }
1526
+        if (preg_match(",^\n+,", $suite, $regs)) {
1527
+            $debut .= $regs[0];
1528
+            $suite = substr($suite, strlen($regs[0]));
1529
+        }
1530
+    }
1531
+    $texte = $debut . $suite;
1532
+
1533
+    $texte = echappe_retour($texte);
1534
+
1535
+    return $texte . $fin;
1536 1536
 }
1537 1537
 
1538 1538
 
@@ -1573,46 +1573,46 @@  discard block
 block discarded – undo
1573 1573
  * @return string
1574 1574
  **/
1575 1575
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1576
-	static $traduire = false;
1577
-	if ($letexte
1578
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1579
-	) {
1580
-		if (!$traduire) {
1581
-			$traduire = charger_fonction('traduire', 'inc');
1582
-			include_spip('inc/lang');
1583
-		}
1584
-		if (!$lang) {
1585
-			$lang = $GLOBALS['spip_lang'];
1586
-		}
1587
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1588
-		if (is_bool($options)) {
1589
-			$options = array('echappe_span' => $options);
1590
-		}
1591
-		if (!isset($options['echappe_span'])) {
1592
-			$options = array_merge($options, array('echappe_span' => false));
1593
-		}
1594
-
1595
-		foreach ($regs as $reg) {
1596
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1597
-			$desc = $traduire($cle, $lang, true);
1598
-			$l = $desc->langue;
1599
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1600
-			if (strlen($desc->texte)) {
1601
-				$trad = code_echappement($desc->texte, 'idiome', false);
1602
-				if ($l !== $lang) {
1603
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1604
-				}
1605
-				if (lang_dir($l) !== lang_dir($lang)) {
1606
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1607
-				}
1608
-				if (!$options['echappe_span']) {
1609
-					$trad = echappe_retour($trad, 'idiome');
1610
-				}
1611
-				$letexte = str_replace($reg[0], $trad, $letexte);
1612
-			}
1613
-		}
1614
-	}
1615
-	return $letexte;
1576
+    static $traduire = false;
1577
+    if ($letexte
1578
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1579
+    ) {
1580
+        if (!$traduire) {
1581
+            $traduire = charger_fonction('traduire', 'inc');
1582
+            include_spip('inc/lang');
1583
+        }
1584
+        if (!$lang) {
1585
+            $lang = $GLOBALS['spip_lang'];
1586
+        }
1587
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1588
+        if (is_bool($options)) {
1589
+            $options = array('echappe_span' => $options);
1590
+        }
1591
+        if (!isset($options['echappe_span'])) {
1592
+            $options = array_merge($options, array('echappe_span' => false));
1593
+        }
1594
+
1595
+        foreach ($regs as $reg) {
1596
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1597
+            $desc = $traduire($cle, $lang, true);
1598
+            $l = $desc->langue;
1599
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1600
+            if (strlen($desc->texte)) {
1601
+                $trad = code_echappement($desc->texte, 'idiome', false);
1602
+                if ($l !== $lang) {
1603
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1604
+                }
1605
+                if (lang_dir($l) !== lang_dir($lang)) {
1606
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1607
+                }
1608
+                if (!$options['echappe_span']) {
1609
+                    $trad = echappe_retour($trad, 'idiome');
1610
+                }
1611
+                $letexte = str_replace($reg[0], $trad, $letexte);
1612
+            }
1613
+        }
1614
+    }
1615
+    return $letexte;
1616 1616
 }
1617 1617
 
1618 1618
 /**
@@ -1664,64 +1664,64 @@  discard block
 block discarded – undo
1664 1664
  **/
1665 1665
 function extraire_multi($letexte, $lang = null, $options = array()) {
1666 1666
 
1667
-	if ($letexte
1668
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1669
-	) {
1670
-		if (!$lang) {
1671
-			$lang = $GLOBALS['spip_lang'];
1672
-		}
1673
-
1674
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1675
-		if (is_bool($options)) {
1676
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1677
-		}
1678
-		if (!isset($options['echappe_span'])) {
1679
-			$options = array_merge($options, array('echappe_span' => false));
1680
-		}
1681
-		if (!isset($options['lang_defaut'])) {
1682
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1683
-		}
1684
-
1685
-		include_spip('inc/lang');
1686
-		foreach ($regs as $reg) {
1687
-			// chercher la version de la langue courante
1688
-			$trads = extraire_trads($reg[1]);
1689
-			if ($l = approcher_langue($trads, $lang)) {
1690
-				$trad = $trads[$l];
1691
-			} else {
1692
-				if ($options['lang_defaut'] == 'aucune') {
1693
-					$trad = '';
1694
-				} else {
1695
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1696
-					// ou la premiere dispo
1697
-					// mais typographier le texte selon les regles de celle-ci
1698
-					// Attention aux blocs multi sur plusieurs lignes
1699
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1700
-						$l = key($trads);
1701
-					}
1702
-					$trad = $trads[$l];
1703
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1704
-					$trad = $typographie($trad);
1705
-					// Tester si on echappe en span ou en div
1706
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1707
-					include_spip('inc/texte');
1708
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1709
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1710
-					$trad = code_echappement($trad, 'multi', false, $mode);
1711
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1712
-					if (lang_dir($l) !== lang_dir($lang)) {
1713
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1714
-					}
1715
-					if (!$options['echappe_span']) {
1716
-						$trad = echappe_retour($trad, 'multi');
1717
-					}
1718
-				}
1719
-			}
1720
-			$letexte = str_replace($reg[0], $trad, $letexte);
1721
-		}
1722
-	}
1723
-
1724
-	return $letexte;
1667
+    if ($letexte
1668
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1669
+    ) {
1670
+        if (!$lang) {
1671
+            $lang = $GLOBALS['spip_lang'];
1672
+        }
1673
+
1674
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1675
+        if (is_bool($options)) {
1676
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1677
+        }
1678
+        if (!isset($options['echappe_span'])) {
1679
+            $options = array_merge($options, array('echappe_span' => false));
1680
+        }
1681
+        if (!isset($options['lang_defaut'])) {
1682
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1683
+        }
1684
+
1685
+        include_spip('inc/lang');
1686
+        foreach ($regs as $reg) {
1687
+            // chercher la version de la langue courante
1688
+            $trads = extraire_trads($reg[1]);
1689
+            if ($l = approcher_langue($trads, $lang)) {
1690
+                $trad = $trads[$l];
1691
+            } else {
1692
+                if ($options['lang_defaut'] == 'aucune') {
1693
+                    $trad = '';
1694
+                } else {
1695
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1696
+                    // ou la premiere dispo
1697
+                    // mais typographier le texte selon les regles de celle-ci
1698
+                    // Attention aux blocs multi sur plusieurs lignes
1699
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1700
+                        $l = key($trads);
1701
+                    }
1702
+                    $trad = $trads[$l];
1703
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1704
+                    $trad = $typographie($trad);
1705
+                    // Tester si on echappe en span ou en div
1706
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1707
+                    include_spip('inc/texte');
1708
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1709
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1710
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1711
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1712
+                    if (lang_dir($l) !== lang_dir($lang)) {
1713
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1714
+                    }
1715
+                    if (!$options['echappe_span']) {
1716
+                        $trad = echappe_retour($trad, 'multi');
1717
+                    }
1718
+                }
1719
+            }
1720
+            $letexte = str_replace($reg[0], $trad, $letexte);
1721
+        }
1722
+    }
1723
+
1724
+    return $letexte;
1725 1725
 }
1726 1726
 
1727 1727
 /**
@@ -1737,20 +1737,20 @@  discard block
 block discarded – undo
1737 1737
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1738 1738
  **/
1739 1739
 function extraire_trads($bloc) {
1740
-	$lang = '';
1740
+    $lang = '';
1741 1741
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1742 1742
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1743
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1744
-		$texte = trim($regs[1]);
1745
-		if ($texte or $lang) {
1746
-			$trads[$lang] = $texte;
1747
-		}
1748
-		$bloc = substr($bloc, strlen($regs[0]));
1749
-		$lang = $regs[2];
1750
-	}
1751
-	$trads[$lang] = $bloc;
1743
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1744
+        $texte = trim($regs[1]);
1745
+        if ($texte or $lang) {
1746
+            $trads[$lang] = $texte;
1747
+        }
1748
+        $bloc = substr($bloc, strlen($regs[0]));
1749
+        $lang = $regs[2];
1750
+    }
1751
+    $trads[$lang] = $bloc;
1752 1752
 
1753
-	return $trads;
1753
+    return $trads;
1754 1754
 }
1755 1755
 
1756 1756
 
@@ -1761,7 +1761,7 @@  discard block
 block discarded – undo
1761 1761
  * @return string L'initiale en majuscule
1762 1762
  */
1763 1763
 function filtre_initiale($nom) {
1764
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1764
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1765 1765
 }
1766 1766
 
1767 1767
 
@@ -1806,33 +1806,33 @@  discard block
 block discarded – undo
1806 1806
  *      - null (interne) : si on empile
1807 1807
  **/
1808 1808
 function unique($donnee, $famille = '', $cpt = false) {
1809
-	static $mem = array();
1810
-	// permettre de vider la pile et de la restaurer
1811
-	// pour le calcul de introduction...
1812
-	if ($famille == '_spip_raz_') {
1813
-		$tmp = $mem;
1814
-		$mem = array();
1815
-
1816
-		return $tmp;
1817
-	} elseif ($famille == '_spip_set_') {
1818
-		$mem = $donnee;
1819
-
1820
-		return;
1821
-	}
1822
-	// eviter une notice
1823
-	if (!isset($mem[$famille])) {
1824
-		$mem[$famille] = array();
1825
-	}
1826
-	if ($cpt) {
1827
-		return count($mem[$famille]);
1828
-	}
1829
-	// eviter une notice
1830
-	if (!isset($mem[$famille][$donnee])) {
1831
-		$mem[$famille][$donnee] = 0;
1832
-	}
1833
-	if (!($mem[$famille][$donnee]++)) {
1834
-		return $donnee;
1835
-	}
1809
+    static $mem = array();
1810
+    // permettre de vider la pile et de la restaurer
1811
+    // pour le calcul de introduction...
1812
+    if ($famille == '_spip_raz_') {
1813
+        $tmp = $mem;
1814
+        $mem = array();
1815
+
1816
+        return $tmp;
1817
+    } elseif ($famille == '_spip_set_') {
1818
+        $mem = $donnee;
1819
+
1820
+        return;
1821
+    }
1822
+    // eviter une notice
1823
+    if (!isset($mem[$famille])) {
1824
+        $mem[$famille] = array();
1825
+    }
1826
+    if ($cpt) {
1827
+        return count($mem[$famille]);
1828
+    }
1829
+    // eviter une notice
1830
+    if (!isset($mem[$famille][$donnee])) {
1831
+        $mem[$famille][$donnee] = 0;
1832
+    }
1833
+    if (!($mem[$famille][$donnee]++)) {
1834
+        return $donnee;
1835
+    }
1836 1836
 }
1837 1837
 
1838 1838
 
@@ -1860,18 +1860,18 @@  discard block
 block discarded – undo
1860 1860
  *     Une des valeurs en fonction du compteur.
1861 1861
  **/
1862 1862
 function alterner($i) {
1863
-	// recuperer les arguments (attention fonctions un peu space)
1864
-	$num = func_num_args();
1865
-	$args = func_get_args();
1863
+    // recuperer les arguments (attention fonctions un peu space)
1864
+    $num = func_num_args();
1865
+    $args = func_get_args();
1866 1866
 
1867
-	if ($num == 2 && is_array($args[1])) {
1868
-		$args = $args[1];
1869
-		array_unshift($args, '');
1870
-		$num = count($args);
1871
-	}
1867
+    if ($num == 2 && is_array($args[1])) {
1868
+        $args = $args[1];
1869
+        array_unshift($args, '');
1870
+        $num = count($args);
1871
+    }
1872 1872
 
1873
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1874
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1873
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1874
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1875 1875
 }
1876 1876
 
1877 1877
 
@@ -1896,46 +1896,46 @@  discard block
 block discarded – undo
1896 1896
  *     - Tableau complet (si 2e argument)
1897 1897
  **/
1898 1898
 function extraire_attribut($balise, $attribut, $complet = false) {
1899
-	if (is_array($balise)) {
1900
-		array_walk(
1901
-			$balise,
1902
-			function(&$a, $key, $t){
1903
-				$a = extraire_attribut($a, $t);
1904
-			},
1905
-			$attribut
1906
-		);
1907
-
1908
-		return $balise;
1909
-	}
1910
-	if (preg_match(
1911
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1912
-		. $attribut
1913
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1914
-
1915
-		$balise, $r)) {
1916
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1917
-			$r[4] = substr($r[3], 1, -1);
1918
-			$r[3] = $r[3][0];
1919
-		} elseif ($r[3] !== '') {
1920
-			$r[4] = $r[3];
1921
-			$r[3] = '';
1922
-		} else {
1923
-			$r[4] = trim($r[2]);
1924
-		}
1925
-		$att = $r[4];
1926
-		if (strpos($att, "&#") !== false) {
1927
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1928
-		}
1929
-		$att = filtrer_entites($att);
1930
-	} else {
1931
-		$att = null;
1932
-	}
1933
-
1934
-	if ($complet) {
1935
-		return array($att, $r);
1936
-	} else {
1937
-		return $att;
1938
-	}
1899
+    if (is_array($balise)) {
1900
+        array_walk(
1901
+            $balise,
1902
+            function(&$a, $key, $t){
1903
+                $a = extraire_attribut($a, $t);
1904
+            },
1905
+            $attribut
1906
+        );
1907
+
1908
+        return $balise;
1909
+    }
1910
+    if (preg_match(
1911
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1912
+        . $attribut
1913
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1914
+
1915
+        $balise, $r)) {
1916
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1917
+            $r[4] = substr($r[3], 1, -1);
1918
+            $r[3] = $r[3][0];
1919
+        } elseif ($r[3] !== '') {
1920
+            $r[4] = $r[3];
1921
+            $r[3] = '';
1922
+        } else {
1923
+            $r[4] = trim($r[2]);
1924
+        }
1925
+        $att = $r[4];
1926
+        if (strpos($att, "&#") !== false) {
1927
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1928
+        }
1929
+        $att = filtrer_entites($att);
1930
+    } else {
1931
+        $att = null;
1932
+    }
1933
+
1934
+    if ($complet) {
1935
+        return array($att, $r);
1936
+    } else {
1937
+        return $att;
1938
+    }
1939 1939
 }
1940 1940
 
1941 1941
 /**
@@ -1967,37 +1967,37 @@  discard block
 block discarded – undo
1967 1967
  *     Code html modifié
1968 1968
  **/
1969 1969
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1970
-	// preparer l'attribut
1971
-	// supprimer les &nbsp; etc mais pas les balises html
1972
-	// qui ont un sens dans un attribut value d'un input
1973
-	if ($proteger) {
1974
-		$val = attribut_html($val, false);
1975
-	}
1976
-
1977
-	// echapper les ' pour eviter tout bug
1978
-	$val = str_replace("'", "&#039;", $val);
1979
-	if ($vider and strlen($val) == 0) {
1980
-		$insert = '';
1981
-	} else {
1982
-		$insert = " $attribut='$val'";
1983
-	}
1984
-
1985
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1986
-
1987
-	if ($old !== null) {
1988
-		// Remplacer l'ancien attribut du meme nom
1989
-		$balise = $r[1] . $insert . $r[5];
1990
-	} else {
1991
-		// preferer une balise " />" (comme <img />)
1992
-		if (preg_match(',/>,', $balise)) {
1993
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1994
-		} // sinon une balise <a ...> ... </a>
1995
-		else {
1996
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1997
-		}
1998
-	}
1999
-
2000
-	return $balise;
1970
+    // preparer l'attribut
1971
+    // supprimer les &nbsp; etc mais pas les balises html
1972
+    // qui ont un sens dans un attribut value d'un input
1973
+    if ($proteger) {
1974
+        $val = attribut_html($val, false);
1975
+    }
1976
+
1977
+    // echapper les ' pour eviter tout bug
1978
+    $val = str_replace("'", "&#039;", $val);
1979
+    if ($vider and strlen($val) == 0) {
1980
+        $insert = '';
1981
+    } else {
1982
+        $insert = " $attribut='$val'";
1983
+    }
1984
+
1985
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1986
+
1987
+    if ($old !== null) {
1988
+        // Remplacer l'ancien attribut du meme nom
1989
+        $balise = $r[1] . $insert . $r[5];
1990
+    } else {
1991
+        // preferer une balise " />" (comme <img />)
1992
+        if (preg_match(',/>,', $balise)) {
1993
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1994
+        } // sinon une balise <a ...> ... </a>
1995
+        else {
1996
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1997
+        }
1998
+    }
1999
+
2000
+    return $balise;
2001 2001
 }
2002 2002
 
2003 2003
 /**
@@ -2015,7 +2015,7 @@  discard block
 block discarded – undo
2015 2015
  * @return string Code HTML sans l'attribut
2016 2016
  **/
2017 2017
 function vider_attribut($balise, $attribut) {
2018
-	return inserer_attribut($balise, $attribut, '', false, true);
2018
+    return inserer_attribut($balise, $attribut, '', false, true);
2019 2019
 }
2020 2020
 
2021 2021
 
@@ -2027,9 +2027,9 @@  discard block
 block discarded – undo
2027 2027
  * @return string
2028 2028
  */
2029 2029
 function tester_config($id, $mode = '') {
2030
-	include_spip('action/inscrire_auteur');
2030
+    include_spip('action/inscrire_auteur');
2031 2031
 
2032
-	return tester_statut_inscription($mode, $id);
2032
+    return tester_statut_inscription($mode, $id);
2033 2033
 }
2034 2034
 
2035 2035
 //
@@ -2054,7 +2054,7 @@  discard block
 block discarded – undo
2054 2054
  * @return int $a+$b
2055 2055
  **/
2056 2056
 function plus($a, $b) {
2057
-	return $a + $b;
2057
+    return $a + $b;
2058 2058
 }
2059 2059
 function strplus($a, $b) {return strize('plus', $a, $b);}
2060 2060
 /**
@@ -2073,7 +2073,7 @@  discard block
 block discarded – undo
2073 2073
  * @return int $a-$b
2074 2074
  **/
2075 2075
 function moins($a, $b) {
2076
-	return $a - $b;
2076
+    return $a - $b;
2077 2077
 }
2078 2078
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2079 2079
 
@@ -2094,7 +2094,7 @@  discard block
 block discarded – undo
2094 2094
  * @return int $a*$b
2095 2095
  **/
2096 2096
 function mult($a, $b) {
2097
-	return $a * $b;
2097
+    return $a * $b;
2098 2098
 }
2099 2099
 function strmult($a, $b) {return strize('mult', $a, $b);}
2100 2100
 
@@ -2115,7 +2115,7 @@  discard block
 block discarded – undo
2115 2115
  * @return int $a/$b (ou 0 si $b est nul)
2116 2116
  **/
2117 2117
 function div($a, $b) {
2118
-	return $b ? $a / $b : 0;
2118
+    return $b ? $a / $b : 0;
2119 2119
 }
2120 2120
 function strdiv($a, $b) {return strize('div', $a, $b);}
2121 2121
 
@@ -2137,7 +2137,7 @@  discard block
 block discarded – undo
2137 2137
  * @return int ($nb % $mod) + $add
2138 2138
  **/
2139 2139
 function modulo($nb, $mod, $add = 0) {
2140
-	return ($mod ? $nb % $mod : 0) + $add;
2140
+    return ($mod ? $nb % $mod : 0) + $add;
2141 2141
 }
2142 2142
 
2143 2143
 
@@ -2152,24 +2152,24 @@  discard block
 block discarded – undo
2152 2152
  *      - true sinon
2153 2153
  **/
2154 2154
 function nom_acceptable($nom) {
2155
-	if (!is_string($nom)) {
2156
-		return false;
2157
-	}
2158
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2159
-		define('_TAGS_NOM_AUTEUR', '');
2160
-	}
2161
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2162
-	foreach ($tags_acceptes as $tag) {
2163
-		if (strlen($tag)) {
2164
-			$remp1[] = '<' . trim($tag) . '>';
2165
-			$remp1[] = '</' . trim($tag) . '>';
2166
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2167
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2168
-		}
2169
-	}
2170
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2155
+    if (!is_string($nom)) {
2156
+        return false;
2157
+    }
2158
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2159
+        define('_TAGS_NOM_AUTEUR', '');
2160
+    }
2161
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2162
+    foreach ($tags_acceptes as $tag) {
2163
+        if (strlen($tag)) {
2164
+            $remp1[] = '<' . trim($tag) . '>';
2165
+            $remp1[] = '</' . trim($tag) . '>';
2166
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2167
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2168
+        }
2169
+    }
2170
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2171 2171
 
2172
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2172
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2173 2173
 }
2174 2174
 
2175 2175
 
@@ -2183,29 +2183,29 @@  discard block
 block discarded – undo
2183 2183
  *      - la normalisation de la dernière adresse donnée sinon
2184 2184
  **/
2185 2185
 function email_valide($adresses) {
2186
-	// eviter d'injecter n'importe quoi dans preg_match
2187
-	if (!is_string($adresses)) {
2188
-		return false;
2189
-	}
2186
+    // eviter d'injecter n'importe quoi dans preg_match
2187
+    if (!is_string($adresses)) {
2188
+        return false;
2189
+    }
2190 2190
 
2191
-	// Si c'est un spammeur autant arreter tout de suite
2192
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2193
-		spip_log("Tentative d'injection de mail : $adresses");
2191
+    // Si c'est un spammeur autant arreter tout de suite
2192
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2193
+        spip_log("Tentative d'injection de mail : $adresses");
2194 2194
 
2195
-		return false;
2196
-	}
2195
+        return false;
2196
+    }
2197 2197
 
2198
-	foreach (explode(',', $adresses) as $v) {
2199
-		// nettoyer certains formats
2200
-		// "Marie Toto <[email protected]>"
2201
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2202
-		// RFC 822
2203
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2204
-			return false;
2205
-		}
2206
-	}
2198
+    foreach (explode(',', $adresses) as $v) {
2199
+        // nettoyer certains formats
2200
+        // "Marie Toto <[email protected]>"
2201
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2202
+        // RFC 822
2203
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2204
+            return false;
2205
+        }
2206
+    }
2207 2207
 
2208
-	return $adresse;
2208
+    return $adresse;
2209 2209
 }
2210 2210
 
2211 2211
 /**
@@ -2219,20 +2219,20 @@  discard block
 block discarded – undo
2219 2219
  * @return string Texte
2220 2220
  **/
2221 2221
 function afficher_enclosures($tags) {
2222
-	$s = array();
2223
-	foreach (extraire_balises($tags, 'a') as $tag) {
2224
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2225
-			and $t = extraire_attribut($tag, 'href')
2226
-		) {
2227
-			$s[] = preg_replace(',>[^<]+</a>,S',
2228
-				'>'
2229
-				. http_img_pack('attachment-16.png', $t,
2230
-					'title="' . attribut_html($t) . '"')
2231
-				. '</a>', $tag);
2232
-		}
2233
-	}
2222
+    $s = array();
2223
+    foreach (extraire_balises($tags, 'a') as $tag) {
2224
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2225
+            and $t = extraire_attribut($tag, 'href')
2226
+        ) {
2227
+            $s[] = preg_replace(',>[^<]+</a>,S',
2228
+                '>'
2229
+                . http_img_pack('attachment-16.png', $t,
2230
+                    'title="' . attribut_html($t) . '"')
2231
+                . '</a>', $tag);
2232
+        }
2233
+    }
2234 2234
 
2235
-	return join('&nbsp;', $s);
2235
+    return join('&nbsp;', $s);
2236 2236
 }
2237 2237
 
2238 2238
 /**
@@ -2247,15 +2247,15 @@  discard block
 block discarded – undo
2247 2247
  * @return string Liens trouvés
2248 2248
  **/
2249 2249
 function afficher_tags($tags, $rels = 'tag,directory') {
2250
-	$s = array();
2251
-	foreach (extraire_balises($tags, 'a') as $tag) {
2252
-		$rel = extraire_attribut($tag, 'rel');
2253
-		if (strstr(",$rels,", ",$rel,")) {
2254
-			$s[] = $tag;
2255
-		}
2256
-	}
2250
+    $s = array();
2251
+    foreach (extraire_balises($tags, 'a') as $tag) {
2252
+        $rel = extraire_attribut($tag, 'rel');
2253
+        if (strstr(",$rels,", ",$rel,")) {
2254
+            $s[] = $tag;
2255
+        }
2256
+    }
2257 2257
 
2258
-	return join(', ', $s);
2258
+    return join(', ', $s);
2259 2259
 }
2260 2260
 
2261 2261
 
@@ -2277,21 +2277,21 @@  discard block
 block discarded – undo
2277 2277
  * @return string Tag HTML `<a>` avec microformat.
2278 2278
  **/
2279 2279
 function enclosure2microformat($e) {
2280
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2281
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2282
-	}
2283
-	$type = extraire_attribut($e, 'type');
2284
-	if (!$length = extraire_attribut($e, 'length')) {
2285
-		# <media:content : longeur dans fileSize. On tente.
2286
-		$length = extraire_attribut($e, 'fileSize');
2287
-	}
2288
-	$fichier = basename($url);
2280
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2281
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2282
+    }
2283
+    $type = extraire_attribut($e, 'type');
2284
+    if (!$length = extraire_attribut($e, 'length')) {
2285
+        # <media:content : longeur dans fileSize. On tente.
2286
+        $length = extraire_attribut($e, 'fileSize');
2287
+    }
2288
+    $fichier = basename($url);
2289 2289
 
2290
-	return '<a rel="enclosure"'
2291
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2292
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2293
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2294
-	. '>' . $fichier . '</a>';
2290
+    return '<a rel="enclosure"'
2291
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2292
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2293
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2294
+    . '>' . $fichier . '</a>';
2295 2295
 }
2296 2296
 
2297 2297
 /**
@@ -2309,24 +2309,24 @@  discard block
 block discarded – undo
2309 2309
  * @return string Tags RSS `<enclosure>`.
2310 2310
  **/
2311 2311
 function microformat2enclosure($tags) {
2312
-	$enclosures = array();
2313
-	foreach (extraire_balises($tags, 'a') as $e) {
2314
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2315
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2316
-			$type = extraire_attribut($e, 'type');
2317
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2318
-				$length = intval(extraire_attribut($e, 'length'));
2319
-			} # vieux data
2320
-			$fichier = basename($url);
2321
-			$enclosures[] = '<enclosure'
2322
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2323
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2324
-				. ($length ? ' length="' . $length . '"' : '')
2325
-				. ' />';
2326
-		}
2327
-	}
2312
+    $enclosures = array();
2313
+    foreach (extraire_balises($tags, 'a') as $e) {
2314
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2315
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2316
+            $type = extraire_attribut($e, 'type');
2317
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2318
+                $length = intval(extraire_attribut($e, 'length'));
2319
+            } # vieux data
2320
+            $fichier = basename($url);
2321
+            $enclosures[] = '<enclosure'
2322
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2323
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2324
+                . ($length ? ' length="' . $length . '"' : '')
2325
+                . ' />';
2326
+        }
2327
+    }
2328 2328
 
2329
-	return join("\n", $enclosures);
2329
+    return join("\n", $enclosures);
2330 2330
 }
2331 2331
 
2332 2332
 
@@ -2342,16 +2342,16 @@  discard block
 block discarded – undo
2342 2342
  * @return string Tags RSS Atom `<dc:subject>`.
2343 2343
  **/
2344 2344
 function tags2dcsubject($tags) {
2345
-	$subjects = '';
2346
-	foreach (extraire_balises($tags, 'a') as $e) {
2347
-		if (extraire_attribut($e, rel) == 'tag') {
2348
-			$subjects .= '<dc:subject>'
2349
-				. texte_backend(textebrut($e))
2350
-				. '</dc:subject>' . "\n";
2351
-		}
2352
-	}
2345
+    $subjects = '';
2346
+    foreach (extraire_balises($tags, 'a') as $e) {
2347
+        if (extraire_attribut($e, rel) == 'tag') {
2348
+            $subjects .= '<dc:subject>'
2349
+                . texte_backend(textebrut($e))
2350
+                . '</dc:subject>' . "\n";
2351
+        }
2352
+    }
2353 2353
 
2354
-	return $subjects;
2354
+    return $subjects;
2355 2355
 }
2356 2356
 
2357 2357
 /**
@@ -2380,23 +2380,23 @@  discard block
 block discarded – undo
2380 2380
  *     - Tableau de résultats, si tableau en entrée.
2381 2381
  **/
2382 2382
 function extraire_balise($texte, $tag = 'a') {
2383
-	if (is_array($texte)) {
2384
-		array_walk(
2385
-			$texte,
2386
-			function(&$a, $key, $t){
2387
-				$a = extraire_balise($a, $t);
2388
-			},
2389
-			$tag
2390
-		);
2383
+    if (is_array($texte)) {
2384
+        array_walk(
2385
+            $texte,
2386
+            function(&$a, $key, $t){
2387
+                $a = extraire_balise($a, $t);
2388
+            },
2389
+            $tag
2390
+        );
2391 2391
 
2392
-		return $texte;
2393
-	}
2392
+        return $texte;
2393
+    }
2394 2394
 
2395
-	if (preg_match(
2396
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2397
-		$texte, $regs)) {
2398
-		return $regs[0];
2399
-	}
2395
+    if (preg_match(
2396
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2397
+        $texte, $regs)) {
2398
+        return $regs[0];
2399
+    }
2400 2400
 }
2401 2401
 
2402 2402
 /**
@@ -2424,25 +2424,25 @@  discard block
 block discarded – undo
2424 2424
  *     - Tableau de résultats, si tableau en entrée.
2425 2425
  **/
2426 2426
 function extraire_balises($texte, $tag = 'a') {
2427
-	if (is_array($texte)) {
2428
-		array_walk(
2429
-			$texte,
2430
-			function(&$a, $key, $t){
2431
-				$a = extraire_balises($a, $t);
2432
-			},
2433
-			$tag
2434
-		);
2427
+    if (is_array($texte)) {
2428
+        array_walk(
2429
+            $texte,
2430
+            function(&$a, $key, $t){
2431
+                $a = extraire_balises($a, $t);
2432
+            },
2433
+            $tag
2434
+        );
2435 2435
 
2436
-		return $texte;
2437
-	}
2436
+        return $texte;
2437
+    }
2438 2438
 
2439
-	if (preg_match_all(
2440
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2441
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2442
-		return $regs[0];
2443
-	} else {
2444
-		return array();
2445
-	}
2439
+    if (preg_match_all(
2440
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2441
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2442
+        return $regs[0];
2443
+    } else {
2444
+        return array();
2445
+    }
2446 2446
 }
2447 2447
 
2448 2448
 /**
@@ -2471,11 +2471,11 @@  discard block
 block discarded – undo
2471 2471
  *     - `$def` si on n'a pas transmis de tableau
2472 2472
  **/
2473 2473
 function in_any($val, $vals, $def = '') {
2474
-	if (!is_array($vals) and $v = unserialize($vals)) {
2475
-		$vals = $v;
2476
-	}
2474
+    if (!is_array($vals) and $v = unserialize($vals)) {
2475
+        $vals = $v;
2476
+    }
2477 2477
 
2478
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2478
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2479 2479
 }
2480 2480
 
2481 2481
 
@@ -2496,12 +2496,12 @@  discard block
 block discarded – undo
2496 2496
  *     Résultat du calcul
2497 2497
  **/
2498 2498
 function valeur_numerique($expr) {
2499
-	$a = 0;
2500
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2501
-		eval("\$a = $expr;");
2502
-	}
2499
+    $a = 0;
2500
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2501
+        eval("\$a = $expr;");
2502
+    }
2503 2503
 
2504
-	return intval($a);
2504
+    return intval($a);
2505 2505
 }
2506 2506
 
2507 2507
 /**
@@ -2520,7 +2520,7 @@  discard block
 block discarded – undo
2520 2520
  *      Retourne `$a*$b/$c`
2521 2521
  **/
2522 2522
 function regledetrois($a, $b, $c) {
2523
-	return round($a * $b / $c);
2523
+    return round($a * $b / $c);
2524 2524
 }
2525 2525
 
2526 2526
 
@@ -2544,76 +2544,76 @@  discard block
 block discarded – undo
2544 2544
  **/
2545 2545
 function form_hidden($action) {
2546 2546
 
2547
-	$contexte = array();
2548
-	include_spip('inc/urls');
2549
-	if ($p = urls_decoder_url($action, '')
2550
-		and reset($p)
2551
-	) {
2552
-		$fond = array_shift($p);
2553
-		if ($fond != '404') {
2554
-			$contexte = array_shift($p);
2555
-			$contexte['page'] = $fond;
2556
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2557
-		}
2558
-	}
2559
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2560
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2561
-		unset($contexte['type']);
2562
-	}
2563
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2564
-		unset($contexte['type-page']);
2565
-	}
2566
-
2567
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2568
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2569
-	$values = array();
2570
-
2571
-	// d'abord avec celles de l'url
2572
-	if (false !== ($p = strpos($action, '?'))) {
2573
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2574
-			$c = explode('=', $c, 2);
2575
-			$var = array_shift($c);
2576
-			$val = array_shift($c);
2577
-			if ($var) {
2578
-				$val = rawurldecode($val);
2579
-				$var = rawurldecode($var); // decoder les [] eventuels
2580
-				if (preg_match(',\[\]$,S', $var)) {
2581
-					$values[] = array($var, $val);
2582
-				} else {
2583
-					if (!isset($values[$var])) {
2584
-						$values[$var] = array($var, $val);
2585
-					}
2586
-				}
2587
-			}
2588
-		}
2589
-	}
2590
-
2591
-	// ensuite avec celles du contexte, sans doublonner !
2592
-	foreach ($contexte as $var => $val) {
2593
-		if (preg_match(',\[\]$,S', $var)) {
2594
-			$values[] = array($var, $val);
2595
-		} else {
2596
-			if (!isset($values[$var])) {
2597
-				$values[$var] = array($var, $val);
2598
-			}
2599
-		}
2600
-	}
2601
-
2602
-	// puis on rassemble le tout
2603
-	$hidden = array();
2604
-	foreach ($values as $value) {
2605
-		list($var, $val) = $value;
2606
-		$hidden[] = '<input name="'
2607
-			. entites_html($var)
2608
-			. '"'
2609
-			. (is_null($val)
2610
-				? ''
2611
-				: ' value="' . entites_html($val) . '"'
2612
-			)
2613
-			. ' type="hidden"' . "\n/>";
2614
-	}
2615
-
2616
-	return join("", $hidden);
2547
+    $contexte = array();
2548
+    include_spip('inc/urls');
2549
+    if ($p = urls_decoder_url($action, '')
2550
+        and reset($p)
2551
+    ) {
2552
+        $fond = array_shift($p);
2553
+        if ($fond != '404') {
2554
+            $contexte = array_shift($p);
2555
+            $contexte['page'] = $fond;
2556
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2557
+        }
2558
+    }
2559
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2560
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2561
+        unset($contexte['type']);
2562
+    }
2563
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2564
+        unset($contexte['type-page']);
2565
+    }
2566
+
2567
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2568
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2569
+    $values = array();
2570
+
2571
+    // d'abord avec celles de l'url
2572
+    if (false !== ($p = strpos($action, '?'))) {
2573
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2574
+            $c = explode('=', $c, 2);
2575
+            $var = array_shift($c);
2576
+            $val = array_shift($c);
2577
+            if ($var) {
2578
+                $val = rawurldecode($val);
2579
+                $var = rawurldecode($var); // decoder les [] eventuels
2580
+                if (preg_match(',\[\]$,S', $var)) {
2581
+                    $values[] = array($var, $val);
2582
+                } else {
2583
+                    if (!isset($values[$var])) {
2584
+                        $values[$var] = array($var, $val);
2585
+                    }
2586
+                }
2587
+            }
2588
+        }
2589
+    }
2590
+
2591
+    // ensuite avec celles du contexte, sans doublonner !
2592
+    foreach ($contexte as $var => $val) {
2593
+        if (preg_match(',\[\]$,S', $var)) {
2594
+            $values[] = array($var, $val);
2595
+        } else {
2596
+            if (!isset($values[$var])) {
2597
+                $values[$var] = array($var, $val);
2598
+            }
2599
+        }
2600
+    }
2601
+
2602
+    // puis on rassemble le tout
2603
+    $hidden = array();
2604
+    foreach ($values as $value) {
2605
+        list($var, $val) = $value;
2606
+        $hidden[] = '<input name="'
2607
+            . entites_html($var)
2608
+            . '"'
2609
+            . (is_null($val)
2610
+                ? ''
2611
+                : ' value="' . entites_html($val) . '"'
2612
+            )
2613
+            . ' type="hidden"' . "\n/>";
2614
+    }
2615
+
2616
+    return join("", $hidden);
2617 2617
 }
2618 2618
 
2619 2619
 /**
@@ -2631,15 +2631,15 @@  discard block
 block discarded – undo
2631 2631
  *     Liste (première page, dernière page).
2632 2632
  **/
2633 2633
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2634
-	if ($max <= 0 or $max >= $nombre) {
2635
-		return array(1, $nombre);
2636
-	}
2634
+    if ($max <= 0 or $max >= $nombre) {
2635
+        return array(1, $nombre);
2636
+    }
2637 2637
 
2638
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2639
-	$derniere = min($nombre, $premiere + $max - 2);
2640
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2638
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2639
+    $derniere = min($nombre, $premiere + $max - 2);
2640
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2641 2641
 
2642
-	return array($premiere, $derniere);
2642
+    return array($premiere, $derniere);
2643 2643
 }
2644 2644
 
2645 2645
 
@@ -2661,7 +2661,7 @@  discard block
 block discarded – undo
2661 2661
  *    - la première valeur du tableau sinon.
2662 2662
  **/
2663 2663
 function filtre_reset($array) {
2664
-	return !is_array($array) ? null : reset($array);
2664
+    return !is_array($array) ? null : reset($array);
2665 2665
 }
2666 2666
 
2667 2667
 /**
@@ -2682,7 +2682,7 @@  discard block
 block discarded – undo
2682 2682
  *    - la dernière valeur du tableau sinon.
2683 2683
  **/
2684 2684
 function filtre_end($array) {
2685
-	return !is_array($array) ? null : end($array);
2685
+    return !is_array($array) ? null : end($array);
2686 2686
 }
2687 2687
 
2688 2688
 /**
@@ -2702,11 +2702,11 @@  discard block
 block discarded – undo
2702 2702
  *
2703 2703
  **/
2704 2704
 function filtre_push($array, $val) {
2705
-	if (!is_array($array) or !array_push($array, $val)) {
2706
-		return '';
2707
-	}
2705
+    if (!is_array($array) or !array_push($array, $val)) {
2706
+        return '';
2707
+    }
2708 2708
 
2709
-	return $array;
2709
+    return $array;
2710 2710
 }
2711 2711
 
2712 2712
 /**
@@ -2725,7 +2725,7 @@  discard block
 block discarded – undo
2725 2725
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2726 2726
  **/
2727 2727
 function filtre_find($array, $val) {
2728
-	return (is_array($array) and in_array($val, $array));
2728
+    return (is_array($array) and in_array($val, $array));
2729 2729
 }
2730 2730
 
2731 2731
 
@@ -2742,15 +2742,15 @@  discard block
 block discarded – undo
2742 2742
  *     Contenu avec urls en absolus
2743 2743
  **/
2744 2744
 function urls_absolues_css($contenu, $source) {
2745
-	$path = suivre_lien(url_absolue($source), './');
2745
+    $path = suivre_lien(url_absolue($source), './');
2746 2746
 
2747
-	return preg_replace_callback(
2748
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2749
-		function($x) use ($path) {
2750
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2751
-		},
2752
-		$contenu
2753
-	);
2747
+    return preg_replace_callback(
2748
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2749
+        function($x) use ($path) {
2750
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2751
+        },
2752
+        $contenu
2753
+    );
2754 2754
 }
2755 2755
 
2756 2756
 
@@ -2779,118 +2779,118 @@  discard block
 block discarded – undo
2779 2779
  *     Chemin du fichier CSS inversé
2780 2780
  **/
2781 2781
 function direction_css($css, $voulue = '') {
2782
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2783
-		return $css;
2784
-	}
2785
-
2786
-	// si on a precise le sens voulu en argument, le prendre en compte
2787
-	if ($voulue = strtolower($voulue)) {
2788
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2789
-			$voulue = lang_dir($voulue);
2790
-		}
2791
-	} else {
2792
-		$voulue = lang_dir();
2793
-	}
2794
-
2795
-	$r = count($r) > 1;
2796
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2797
-	$dir = $r ? 'rtl' : 'ltr';
2798
-	$ndir = $r ? 'ltr' : 'rtl';
2799
-
2800
-	if ($voulue == $dir) {
2801
-		return $css;
2802
-	}
2803
-
2804
-	if (
2805
-		// url absolue
2806
-		preg_match(",^https?:,i", $css)
2807
-		// ou qui contient un ?
2808
-		or (($p = strpos($css, '?')) !== false)
2809
-	) {
2810
-		$distant = true;
2811
-		$cssf = parse_url($css);
2812
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2813
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2814
-	} else {
2815
-		$distant = false;
2816
-		$cssf = $css;
2817
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2818
-		//propose (rien a faire dans ce cas)
2819
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2820
-		if (@file_exists($f)) {
2821
-			return $f;
2822
-		}
2823
-	}
2824
-
2825
-	// 2.
2826
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2827
-	$f = $dir_var
2828
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2829
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2830
-
2831
-	// la css peut etre distante (url absolue !)
2832
-	if ($distant) {
2833
-		include_spip('inc/distant');
2834
-		$res = recuperer_url($css);
2835
-		if (!$res or !$contenu = $res['page']) {
2836
-			return $css;
2837
-		}
2838
-	} else {
2839
-		if ((@filemtime($f) > @filemtime($css))
2840
-			and (_VAR_MODE != 'recalcul')
2841
-		) {
2842
-			return $f;
2843
-		}
2844
-		if (!lire_fichier($css, $contenu)) {
2845
-			return $css;
2846
-		}
2847
-	}
2848
-
2849
-
2850
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2851
-	include_spip("lib/csstidy/class.csstidy");
2852
-	$parser = new csstidy();
2853
-	$parser->set_cfg('optimise_shorthands', 0);
2854
-	$parser->set_cfg('reverse_left_and_right', true);
2855
-	$parser->parse($contenu);
2856
-
2857
-	$contenu = $parser->print->plain();
2858
-
2859
-
2860
-	// reperer les @import auxquels il faut propager le direction_css
2861
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2862
-	$src = array();
2863
-	$src_direction_css = array();
2864
-	$src_faux_abs = array();
2865
-	$d = dirname($css);
2866
-	foreach ($regs[1] as $k => $import_css) {
2867
-		$css_direction = direction_css("$d/$import_css", $voulue);
2868
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2869
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2870
-			$css_direction = substr($css_direction, strlen($d) + 1);
2871
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2872
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2873
-			$css_direction = substr($css_direction, strlen($dir_var));
2874
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2875
-			$css_direction = "/@@@@@@/" . $css_direction;
2876
-		}
2877
-		$src[] = $regs[0][$k];
2878
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2879
-	}
2880
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2881
-
2882
-	$contenu = urls_absolues_css($contenu, $css);
2883
-
2884
-	// virer les fausses url absolues que l'on a mis dans les import
2885
-	if (count($src_faux_abs)) {
2886
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2887
-	}
2888
-
2889
-	if (!ecrire_fichier($f, $contenu)) {
2890
-		return $css;
2891
-	}
2892
-
2893
-	return $f;
2782
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2783
+        return $css;
2784
+    }
2785
+
2786
+    // si on a precise le sens voulu en argument, le prendre en compte
2787
+    if ($voulue = strtolower($voulue)) {
2788
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2789
+            $voulue = lang_dir($voulue);
2790
+        }
2791
+    } else {
2792
+        $voulue = lang_dir();
2793
+    }
2794
+
2795
+    $r = count($r) > 1;
2796
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2797
+    $dir = $r ? 'rtl' : 'ltr';
2798
+    $ndir = $r ? 'ltr' : 'rtl';
2799
+
2800
+    if ($voulue == $dir) {
2801
+        return $css;
2802
+    }
2803
+
2804
+    if (
2805
+        // url absolue
2806
+        preg_match(",^https?:,i", $css)
2807
+        // ou qui contient un ?
2808
+        or (($p = strpos($css, '?')) !== false)
2809
+    ) {
2810
+        $distant = true;
2811
+        $cssf = parse_url($css);
2812
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2813
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2814
+    } else {
2815
+        $distant = false;
2816
+        $cssf = $css;
2817
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2818
+        //propose (rien a faire dans ce cas)
2819
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2820
+        if (@file_exists($f)) {
2821
+            return $f;
2822
+        }
2823
+    }
2824
+
2825
+    // 2.
2826
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2827
+    $f = $dir_var
2828
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2829
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2830
+
2831
+    // la css peut etre distante (url absolue !)
2832
+    if ($distant) {
2833
+        include_spip('inc/distant');
2834
+        $res = recuperer_url($css);
2835
+        if (!$res or !$contenu = $res['page']) {
2836
+            return $css;
2837
+        }
2838
+    } else {
2839
+        if ((@filemtime($f) > @filemtime($css))
2840
+            and (_VAR_MODE != 'recalcul')
2841
+        ) {
2842
+            return $f;
2843
+        }
2844
+        if (!lire_fichier($css, $contenu)) {
2845
+            return $css;
2846
+        }
2847
+    }
2848
+
2849
+
2850
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2851
+    include_spip("lib/csstidy/class.csstidy");
2852
+    $parser = new csstidy();
2853
+    $parser->set_cfg('optimise_shorthands', 0);
2854
+    $parser->set_cfg('reverse_left_and_right', true);
2855
+    $parser->parse($contenu);
2856
+
2857
+    $contenu = $parser->print->plain();
2858
+
2859
+
2860
+    // reperer les @import auxquels il faut propager le direction_css
2861
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2862
+    $src = array();
2863
+    $src_direction_css = array();
2864
+    $src_faux_abs = array();
2865
+    $d = dirname($css);
2866
+    foreach ($regs[1] as $k => $import_css) {
2867
+        $css_direction = direction_css("$d/$import_css", $voulue);
2868
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2869
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2870
+            $css_direction = substr($css_direction, strlen($d) + 1);
2871
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2872
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2873
+            $css_direction = substr($css_direction, strlen($dir_var));
2874
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2875
+            $css_direction = "/@@@@@@/" . $css_direction;
2876
+        }
2877
+        $src[] = $regs[0][$k];
2878
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2879
+    }
2880
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2881
+
2882
+    $contenu = urls_absolues_css($contenu, $css);
2883
+
2884
+    // virer les fausses url absolues que l'on a mis dans les import
2885
+    if (count($src_faux_abs)) {
2886
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2887
+    }
2888
+
2889
+    if (!ecrire_fichier($f, $contenu)) {
2890
+        return $css;
2891
+    }
2892
+
2893
+    return $f;
2894 2894
 }
2895 2895
 
2896 2896
 
@@ -2913,43 +2913,43 @@  discard block
 block discarded – undo
2913 2913
  *     - Chemin ou URL du fichier CSS source sinon.
2914 2914
  **/
2915 2915
 function url_absolue_css($css) {
2916
-	if (!preg_match(',\.css$,i', $css, $r)) {
2917
-		return $css;
2918
-	}
2916
+    if (!preg_match(',\.css$,i', $css, $r)) {
2917
+        return $css;
2918
+    }
2919 2919
 
2920
-	$url_absolue_css = url_absolue($css);
2920
+    $url_absolue_css = url_absolue($css);
2921 2921
 
2922
-	$f = basename($css, '.css');
2923
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2924
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2925
-		. '.css';
2922
+    $f = basename($css, '.css');
2923
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2924
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2925
+        . '.css';
2926 2926
 
2927
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2928
-		return $f;
2929
-	}
2927
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2928
+        return $f;
2929
+    }
2930 2930
 
2931
-	if ($url_absolue_css == $css) {
2932
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2933
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2934
-		) {
2935
-			include_spip('inc/distant');
2936
-			if (!$contenu = recuperer_page($css)) {
2937
-				return $css;
2938
-			}
2939
-		}
2940
-	} elseif (!lire_fichier($css, $contenu)) {
2941
-		return $css;
2942
-	}
2931
+    if ($url_absolue_css == $css) {
2932
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2933
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2934
+        ) {
2935
+            include_spip('inc/distant');
2936
+            if (!$contenu = recuperer_page($css)) {
2937
+                return $css;
2938
+            }
2939
+        }
2940
+    } elseif (!lire_fichier($css, $contenu)) {
2941
+        return $css;
2942
+    }
2943 2943
 
2944
-	// passer les url relatives a la css d'origine en url absolues
2945
-	$contenu = urls_absolues_css($contenu, $css);
2944
+    // passer les url relatives a la css d'origine en url absolues
2945
+    $contenu = urls_absolues_css($contenu, $css);
2946 2946
 
2947
-	// ecrire la css
2948
-	if (!ecrire_fichier($f, $contenu)) {
2949
-		return $css;
2950
-	}
2947
+    // ecrire la css
2948
+    if (!ecrire_fichier($f, $contenu)) {
2949
+        return $css;
2950
+    }
2951 2951
 
2952
-	return $f;
2952
+    return $f;
2953 2953
 }
2954 2954
 
2955 2955
 
@@ -2983,24 +2983,24 @@  discard block
 block discarded – undo
2983 2983
  *     Valeur trouvée ou valeur par défaut.
2984 2984
  **/
2985 2985
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
2986
-	foreach (explode('/', $cle) as $k) {
2986
+    foreach (explode('/', $cle) as $k) {
2987 2987
 
2988
-		$table = is_string($table) ? @unserialize($table) : $table;
2988
+        $table = is_string($table) ? @unserialize($table) : $table;
2989 2989
 
2990
-		if (is_object($table)) {
2991
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2992
-		} elseif (is_array($table)) {
2993
-			if ($conserver_null) {
2994
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2995
-			} else {
2996
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
2997
-			}
2998
-		} else {
2999
-			$table = $defaut;
3000
-		}
3001
-	}
2990
+        if (is_object($table)) {
2991
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2992
+        } elseif (is_array($table)) {
2993
+            if ($conserver_null) {
2994
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2995
+            } else {
2996
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
2997
+            }
2998
+        } else {
2999
+            $table = $defaut;
3000
+        }
3001
+    }
3002 3002
 
3003
-	return $table;
3003
+    return $table;
3004 3004
 }
3005 3005
 
3006 3006
 /**
@@ -3033,22 +3033,22 @@  discard block
 block discarded – undo
3033 3033
  *     - string : expression trouvée.
3034 3034
  **/
3035 3035
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3036
-	if (intval($modif) and $capte == 0) {
3037
-		$capte = $modif;
3038
-		$modif = "UimsS";
3039
-	}
3040
-	$expression = str_replace("\/", "/", $expression);
3041
-	$expression = str_replace("/", "\/", $expression);
3036
+    if (intval($modif) and $capte == 0) {
3037
+        $capte = $modif;
3038
+        $modif = "UimsS";
3039
+    }
3040
+    $expression = str_replace("\/", "/", $expression);
3041
+    $expression = str_replace("/", "\/", $expression);
3042 3042
 
3043
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3044
-		if (isset($r[$capte])) {
3045
-			return $r[$capte];
3046
-		} else {
3047
-			return true;
3048
-		}
3049
-	}
3043
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3044
+        if (isset($r[$capte])) {
3045
+            return $r[$capte];
3046
+        } else {
3047
+            return true;
3048
+        }
3049
+    }
3050 3050
 
3051
-	return false;
3051
+    return false;
3052 3052
 }
3053 3053
 
3054 3054
 
@@ -3075,10 +3075,10 @@  discard block
 block discarded – undo
3075 3075
  *     Texte
3076 3076
  **/
3077 3077
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3078
-	$expression = str_replace("\/", "/", $expression);
3079
-	$expression = str_replace("/", "\/", $expression);
3078
+    $expression = str_replace("\/", "/", $expression);
3079
+    $expression = str_replace("/", "\/", $expression);
3080 3080
 
3081
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3081
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3082 3082
 }
3083 3083
 
3084 3084
 
@@ -3096,21 +3096,21 @@  discard block
 block discarded – undo
3096 3096
  **/
3097 3097
 function traiter_doublons_documents(&$doublons, $letexte) {
3098 3098
 
3099
-	// Verifier dans le texte & les notes (pas beau, helas)
3100
-	$t = $letexte . $GLOBALS['les_notes'];
3099
+    // Verifier dans le texte & les notes (pas beau, helas)
3100
+    $t = $letexte . $GLOBALS['les_notes'];
3101 3101
 
3102
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3103
-		and preg_match_all(
3104
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3105
-			$t, $matches, PREG_PATTERN_ORDER)
3106
-	) {
3107
-		if (!isset($doublons['documents'])) {
3108
-			$doublons['documents'] = "";
3109
-		}
3110
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3111
-	}
3102
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3103
+        and preg_match_all(
3104
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3105
+            $t, $matches, PREG_PATTERN_ORDER)
3106
+    ) {
3107
+        if (!isset($doublons['documents'])) {
3108
+            $doublons['documents'] = "";
3109
+        }
3110
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3111
+    }
3112 3112
 
3113
-	return $letexte;
3113
+    return $letexte;
3114 3114
 }
3115 3115
 
3116 3116
 /**
@@ -3124,7 +3124,7 @@  discard block
 block discarded – undo
3124 3124
  * @return string Chaîne vide
3125 3125
  **/
3126 3126
 function vide($texte) {
3127
-	return "";
3127
+    return "";
3128 3128
 }
3129 3129
 
3130 3130
 //
@@ -3153,23 +3153,23 @@  discard block
 block discarded – undo
3153 3153
  *      Code HTML résultant
3154 3154
  **/
3155 3155
 function env_to_params($env, $ignore_params = array()) {
3156
-	$ignore_params = array_merge(
3157
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3158
-		$ignore_params
3159
-	);
3160
-	if (!is_array($env)) {
3161
-		$env = unserialize($env);
3162
-	}
3163
-	$texte = "";
3164
-	if ($env) {
3165
-		foreach ($env as $i => $j) {
3166
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3167
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3168
-			}
3169
-		}
3170
-	}
3171
-
3172
-	return $texte;
3156
+    $ignore_params = array_merge(
3157
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3158
+        $ignore_params
3159
+    );
3160
+    if (!is_array($env)) {
3161
+        $env = unserialize($env);
3162
+    }
3163
+    $texte = "";
3164
+    if ($env) {
3165
+        foreach ($env as $i => $j) {
3166
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3167
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3168
+            }
3169
+        }
3170
+    }
3171
+
3172
+    return $texte;
3173 3173
 }
3174 3174
 
3175 3175
 /**
@@ -3192,23 +3192,23 @@  discard block
 block discarded – undo
3192 3192
  *      Code HTML résultant
3193 3193
  **/
3194 3194
 function env_to_attributs($env, $ignore_params = array()) {
3195
-	$ignore_params = array_merge(
3196
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3197
-		$ignore_params
3198
-	);
3199
-	if (!is_array($env)) {
3200
-		$env = unserialize($env);
3201
-	}
3202
-	$texte = "";
3203
-	if ($env) {
3204
-		foreach ($env as $i => $j) {
3205
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3206
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3207
-			}
3208
-		}
3209
-	}
3195
+    $ignore_params = array_merge(
3196
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3197
+        $ignore_params
3198
+    );
3199
+    if (!is_array($env)) {
3200
+        $env = unserialize($env);
3201
+    }
3202
+    $texte = "";
3203
+    if ($env) {
3204
+        foreach ($env as $i => $j) {
3205
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3206
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3207
+            }
3208
+        }
3209
+    }
3210 3210
 
3211
-	return $texte;
3211
+    return $texte;
3212 3212
 }
3213 3213
 
3214 3214
 
@@ -3225,9 +3225,9 @@  discard block
 block discarded – undo
3225 3225
  * @return string Chaînes concaténés
3226 3226
  **/
3227 3227
 function concat() {
3228
-	$args = func_get_args();
3228
+    $args = func_get_args();
3229 3229
 
3230
-	return join('', $args);
3230
+    return join('', $args);
3231 3231
 }
3232 3232
 
3233 3233
 
@@ -3247,23 +3247,23 @@  discard block
 block discarded – undo
3247 3247
  *     Contenu du ou des fichiers, concaténé
3248 3248
  **/
3249 3249
 function charge_scripts($files, $script = true) {
3250
-	$flux = "";
3251
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3252
-		if (!is_string($file)) {
3253
-			continue;
3254
-		}
3255
-		if ($script) {
3256
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3257
-		}
3258
-		if ($file) {
3259
-			$path = find_in_path($file);
3260
-			if ($path) {
3261
-				$flux .= spip_file_get_contents($path);
3262
-			}
3263
-		}
3264
-	}
3250
+    $flux = "";
3251
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3252
+        if (!is_string($file)) {
3253
+            continue;
3254
+        }
3255
+        if ($script) {
3256
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3257
+        }
3258
+        if ($file) {
3259
+            $path = find_in_path($file);
3260
+            if ($path) {
3261
+                $flux .= spip_file_get_contents($path);
3262
+            }
3263
+        }
3264
+    }
3265 3265
 
3266
-	return $flux;
3266
+    return $flux;
3267 3267
 }
3268 3268
 
3269 3269
 
@@ -3285,64 +3285,64 @@  discard block
 block discarded – undo
3285 3285
  */
3286 3286
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3287 3287
 
3288
-	$img_file = $img;
3289
-	if ($p = strpos($img_file, '?')) {
3290
-		$img_file = substr($img_file,0, $p);
3291
-	}
3292
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3293
-		$img_file = chemin_image($img);
3294
-	}
3295
-	else {
3296
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3297
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3298
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3299
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3300
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3301
-			  and file_exists($variante_svg_generique)) {
3302
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3303
-					$img_file = $variante_svg_size;
3304
-				}
3305
-				else {
3306
-					$img_file = $variante_svg_generique;
3307
-				}
3308
-			}
3309
-		}
3310
-	}
3311
-	if (stripos($atts, 'width') === false) {
3312
-		// utiliser directement l'info de taille presente dans le nom
3313
-		if ((!isset($options['utiliser_suffixe_size'])
3314
-				or $options['utiliser_suffixe_size'] == true
3315
-			  or strpos($img_file, '-xx.svg') !== false)
3316
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3317
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3318
-		) {
3319
-			$largeur = $hauteur = intval($regs[1]);
3320
-		} else {
3321
-			$taille = taille_image($img_file);
3322
-			list($hauteur, $largeur) = $taille;
3323
-			if (!$hauteur or !$largeur) {
3324
-				return "";
3325
-			}
3326
-		}
3327
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3328
-	}
3329
-
3330
-	if (file_exists($img_file)) {
3331
-		$img_file = timestamp($img_file);
3332
-	}
3333
-	if ($alt === false) {
3334
-		$alt = '';
3335
-	}
3336
-	elseif($alt or $alt==='') {
3337
-		$alt = " alt='".attribut_html($alt)."'";
3338
-	}
3339
-	else {
3340
-		$alt = " alt='".attribut_html($title)."'";
3341
-	}
3342
-	return "<img src='$img_file'$alt"
3343
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3344
-	. " " . ltrim($atts)
3345
-	. " />";
3288
+    $img_file = $img;
3289
+    if ($p = strpos($img_file, '?')) {
3290
+        $img_file = substr($img_file,0, $p);
3291
+    }
3292
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3293
+        $img_file = chemin_image($img);
3294
+    }
3295
+    else {
3296
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3297
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3298
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3299
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3300
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3301
+              and file_exists($variante_svg_generique)) {
3302
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3303
+                    $img_file = $variante_svg_size;
3304
+                }
3305
+                else {
3306
+                    $img_file = $variante_svg_generique;
3307
+                }
3308
+            }
3309
+        }
3310
+    }
3311
+    if (stripos($atts, 'width') === false) {
3312
+        // utiliser directement l'info de taille presente dans le nom
3313
+        if ((!isset($options['utiliser_suffixe_size'])
3314
+                or $options['utiliser_suffixe_size'] == true
3315
+              or strpos($img_file, '-xx.svg') !== false)
3316
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3317
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3318
+        ) {
3319
+            $largeur = $hauteur = intval($regs[1]);
3320
+        } else {
3321
+            $taille = taille_image($img_file);
3322
+            list($hauteur, $largeur) = $taille;
3323
+            if (!$hauteur or !$largeur) {
3324
+                return "";
3325
+            }
3326
+        }
3327
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3328
+    }
3329
+
3330
+    if (file_exists($img_file)) {
3331
+        $img_file = timestamp($img_file);
3332
+    }
3333
+    if ($alt === false) {
3334
+        $alt = '';
3335
+    }
3336
+    elseif($alt or $alt==='') {
3337
+        $alt = " alt='".attribut_html($alt)."'";
3338
+    }
3339
+    else {
3340
+        $alt = " alt='".attribut_html($title)."'";
3341
+    }
3342
+    return "<img src='$img_file'$alt"
3343
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3344
+    . " " . ltrim($atts)
3345
+    . " />";
3346 3346
 }
3347 3347
 
3348 3348
 /**
@@ -3354,13 +3354,13 @@  discard block
 block discarded – undo
3354 3354
  * @return string
3355 3355
  */
3356 3356
 function http_style_background($img, $att = '', $size=null) {
3357
-	if ($size and is_numeric($size)){
3358
-		$size = trim($size) . "px";
3359
-	}
3360
-	return " style='background" .
3361
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3362
-		. ($size ? "background-size:{$size};" : '')
3363
-		. "'";
3357
+    if ($size and is_numeric($size)){
3358
+        $size = trim($size) . "px";
3359
+    }
3360
+    return " style='background" .
3361
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3362
+        . ($size ? "background-size:{$size};" : '')
3363
+        . "'";
3364 3364
 }
3365 3365
 
3366 3366
 /**
@@ -3376,17 +3376,17 @@  discard block
 block discarded – undo
3376 3376
  *     Code HTML de la balise IMG
3377 3377
  */
3378 3378
 function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3379
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3380
-	// ecriture courte : on donne le width en 2e arg
3381
-	if (empty($width) and is_numeric($alt)) {
3382
-		$width = $alt;
3383
-		$alt = '';
3384
-	}
3385
-	if ($width) {
3386
-		$atts .= " width='{$width}'";
3387
-	}
3388
-	return http_img_pack($img, $alt, $atts, '',
3389
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3379
+    $atts = $class ? " class='" . attribut_html($class) . "'" : '';
3380
+    // ecriture courte : on donne le width en 2e arg
3381
+    if (empty($width) and is_numeric($alt)) {
3382
+        $width = $alt;
3383
+        $alt = '';
3384
+    }
3385
+    if ($width) {
3386
+        $atts .= " width='{$width}'";
3387
+    }
3388
+    return http_img_pack($img, $alt, $atts, '',
3389
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3390 3390
 }
3391 3391
 
3392 3392
 
@@ -3402,42 +3402,42 @@  discard block
 block discarded – undo
3402 3402
  * @return string
3403 3403
  */
3404 3404
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3405
-	$img_file = $img;
3406
-	if ($p = strpos($img_file, '?')) {
3407
-		$img_file = substr($img_file,0, $p);
3408
-	}
3405
+    $img_file = $img;
3406
+    if ($p = strpos($img_file, '?')) {
3407
+        $img_file = substr($img_file,0, $p);
3408
+    }
3409 3409
 
3410
-	if (!$img_file or !$svg = file_get_contents($img_file)) {
3411
-		return '';
3412
-	}
3410
+    if (!$img_file or !$svg = file_get_contents($img_file)) {
3411
+        return '';
3412
+    }
3413 3413
 
3414
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3415
-		return '';
3416
-	}
3417
-	$balise_svg = $match[0];
3418
-	$balise_svg_source = $balise_svg;
3414
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3415
+        return '';
3416
+    }
3417
+    $balise_svg = $match[0];
3418
+    $balise_svg_source = $balise_svg;
3419 3419
 
3420
-	// entete XML à supprimer
3421
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3420
+    // entete XML à supprimer
3421
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3422 3422
 
3423
-	// IE est toujours mon ami
3424
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3425
-	if ($class) {
3426
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3427
-	}
3428
-	if ($alt){
3429
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3430
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3431
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3432
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3433
-		$balise_svg .= $title;
3434
-	}
3435
-	else {
3436
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3437
-	}
3438
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3423
+    // IE est toujours mon ami
3424
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3425
+    if ($class) {
3426
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3427
+    }
3428
+    if ($alt){
3429
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3430
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3431
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3432
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3433
+        $balise_svg .= $title;
3434
+    }
3435
+    else {
3436
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3437
+    }
3438
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3439 3439
 
3440
-	return $svg;
3440
+    return $svg;
3441 3441
 }
3442 3442
 
3443 3443
 
@@ -3460,17 +3460,17 @@  discard block
 block discarded – undo
3460 3460
  *     Code HTML résultant
3461 3461
  **/
3462 3462
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3463
-	$texte = '';
3464
-	if (is_array($tableau)) {
3465
-		foreach ($tableau as $k => $v) {
3466
-			$res = recuperer_fond('modeles/' . $modele,
3467
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3468
-			);
3469
-			$texte .= $res;
3470
-		}
3471
-	}
3463
+    $texte = '';
3464
+    if (is_array($tableau)) {
3465
+        foreach ($tableau as $k => $v) {
3466
+            $res = recuperer_fond('modeles/' . $modele,
3467
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3468
+            );
3469
+            $texte .= $res;
3470
+        }
3471
+    }
3472 3472
 
3473
-	return $texte;
3473
+    return $texte;
3474 3474
 }
3475 3475
 
3476 3476
 
@@ -3495,37 +3495,37 @@  discard block
 block discarded – undo
3495 3495
  *         - tout : retourne toutes les informations du plugin actif
3496 3496
  **/
3497 3497
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3498
-	include_spip('inc/plugin');
3499
-	$plugin = strtoupper($plugin);
3500
-	$plugins_actifs = liste_plugin_actifs();
3501
-
3502
-	if (!$plugin) {
3503
-		return serialize(array_keys($plugins_actifs));
3504
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3505
-		return '';
3506
-	} elseif (($type_info == 'est_actif') and !$reload) {
3507
-		return $plugins_actifs[$plugin] ? 1 : 0;
3508
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3509
-		return $plugins_actifs[$plugin][$type_info];
3510
-	} else {
3511
-		$get_infos = charger_fonction('get_infos', 'plugins');
3512
-		// On prend en compte les extensions
3513
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3514
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3515
-		} else {
3516
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3517
-		}
3518
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3519
-			return '';
3520
-		}
3521
-		if ($type_info == 'tout') {
3522
-			return $infos;
3523
-		} elseif ($type_info == 'est_actif') {
3524
-			return $infos ? 1 : 0;
3525
-		} else {
3526
-			return strval($infos[$type_info]);
3527
-		}
3528
-	}
3498
+    include_spip('inc/plugin');
3499
+    $plugin = strtoupper($plugin);
3500
+    $plugins_actifs = liste_plugin_actifs();
3501
+
3502
+    if (!$plugin) {
3503
+        return serialize(array_keys($plugins_actifs));
3504
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3505
+        return '';
3506
+    } elseif (($type_info == 'est_actif') and !$reload) {
3507
+        return $plugins_actifs[$plugin] ? 1 : 0;
3508
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3509
+        return $plugins_actifs[$plugin][$type_info];
3510
+    } else {
3511
+        $get_infos = charger_fonction('get_infos', 'plugins');
3512
+        // On prend en compte les extensions
3513
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3514
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3515
+        } else {
3516
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3517
+        }
3518
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3519
+            return '';
3520
+        }
3521
+        if ($type_info == 'tout') {
3522
+            return $infos;
3523
+        } elseif ($type_info == 'est_actif') {
3524
+            return $infos ? 1 : 0;
3525
+        } else {
3526
+            return strval($infos[$type_info]);
3527
+        }
3528
+    }
3529 3529
 }
3530 3530
 
3531 3531
 
@@ -3552,9 +3552,9 @@  discard block
 block discarded – undo
3552 3552
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3553 3553
  */
3554 3554
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3555
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3555
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3556 3556
 
3557
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3557
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3558 3558
 }
3559 3559
 
3560 3560
 
@@ -3584,13 +3584,13 @@  discard block
 block discarded – undo
3584 3584
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3585 3585
  */
3586 3586
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3587
-	static $puce_statut = null;
3588
-	if (!$puce_statut) {
3589
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3590
-	}
3587
+    static $puce_statut = null;
3588
+    if (!$puce_statut) {
3589
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3590
+    }
3591 3591
 
3592
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3593
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3592
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3593
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3594 3594
 }
3595 3595
 
3596 3596
 
@@ -3617,100 +3617,100 @@  discard block
 block discarded – undo
3617 3617
  *   hash du contexte
3618 3618
  */
3619 3619
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3620
-	if (is_string($c)
3621
-		and @unserialize($c) !== false
3622
-	) {
3623
-		$c = unserialize($c);
3624
-	}
3625
-
3626
-	// supprimer les parametres debut_x
3627
-	// pour que la pagination ajax ne soit pas plantee
3628
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3629
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3630
-	if (is_array($c)) {
3631
-		foreach ($c as $k => $v) {
3632
-			if (strpos($k, 'debut_') === 0) {
3633
-				unset($c[$k]);
3634
-			}
3635
-		}
3636
-	}
3637
-
3638
-	if (!function_exists('calculer_cle_action')) {
3639
-		include_spip("inc/securiser_action");
3640
-	}
3641
-
3642
-	$c = serialize($c);
3643
-	$cle = calculer_cle_action($form . $c);
3644
-	$c = "$cle:$c";
3645
-
3646
-	// on ne stocke pas les contextes dans des fichiers en cache
3647
-	// par defaut, sauf si cette configuration a été forcée
3648
-	// OU que la longueur de l’argument géneré est plus long
3649
-	// que ce qui est toléré.
3650
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3651
-	if (!$cache_contextes_ajax) {
3652
-		$env = $c;
3653
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3654
-			$env = gzdeflate($env);
3655
-			// https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3656
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3657
-				$cache_contextes_ajax = true;
3658
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3659
-			}
3660
-		}
3661
-		$env = _xor($env);
3662
-		$env = base64_encode($env);
3663
-		$len = strlen($env);
3664
-		// Si l’url est trop longue pour le navigateur
3665
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3666
-		if ($len > $max_len) {
3667
-			$cache_contextes_ajax = true;
3668
-			spip_log("Contextes AJAX forces en fichiers !"
3669
-				. " Cela arrive lorsque la valeur du contexte" 
3670
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3671
-				, _LOG_AVERTISSEMENT);
3672
-		}
3673
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3674
-		elseif (
3675
-			$max_len = @ini_get('suhosin.get.max_value_length')
3676
-			and $max_len < $len
3677
-		) {
3678
-			$cache_contextes_ajax = true;
3679
-			spip_log("Contextes AJAX forces en fichiers !"
3680
-				. " Cela arrive lorsque la valeur du contexte"
3681
-				. " depasse la longueur maximale autorisee par Suhosin"
3682
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3683
-				. " Vous devriez modifier les parametres de Suhosin"
3684
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3685
-		} 
3686
-
3687
-	}
3688
-
3689
-	if ($cache_contextes_ajax) {
3690
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3691
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3692
-		$md5 = md5($c);
3693
-		ecrire_fichier("$dir/c$md5", $c);
3694
-		$env = $md5;
3695
-	}
3696
-
3697
-	if ($emboite === null) {
3698
-		return $env;
3699
-	}
3700
-	if (!trim($emboite)) {
3701
-		return "";
3702
-	}
3703
-	// toujours encoder l'url source dans le bloc ajax
3704
-	$r = self();
3705
-	$r = ' data-origin="' . $r . '"';
3706
-	$class = 'ajaxbloc';
3707
-	if ($ajaxid and is_string($ajaxid)) {
3708
-		// ajaxid est normalement conforme a un nom de classe css
3709
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3710
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3711
-	}
3712
-
3713
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3620
+    if (is_string($c)
3621
+        and @unserialize($c) !== false
3622
+    ) {
3623
+        $c = unserialize($c);
3624
+    }
3625
+
3626
+    // supprimer les parametres debut_x
3627
+    // pour que la pagination ajax ne soit pas plantee
3628
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3629
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3630
+    if (is_array($c)) {
3631
+        foreach ($c as $k => $v) {
3632
+            if (strpos($k, 'debut_') === 0) {
3633
+                unset($c[$k]);
3634
+            }
3635
+        }
3636
+    }
3637
+
3638
+    if (!function_exists('calculer_cle_action')) {
3639
+        include_spip("inc/securiser_action");
3640
+    }
3641
+
3642
+    $c = serialize($c);
3643
+    $cle = calculer_cle_action($form . $c);
3644
+    $c = "$cle:$c";
3645
+
3646
+    // on ne stocke pas les contextes dans des fichiers en cache
3647
+    // par defaut, sauf si cette configuration a été forcée
3648
+    // OU que la longueur de l’argument géneré est plus long
3649
+    // que ce qui est toléré.
3650
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3651
+    if (!$cache_contextes_ajax) {
3652
+        $env = $c;
3653
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3654
+            $env = gzdeflate($env);
3655
+            // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3656
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3657
+                $cache_contextes_ajax = true;
3658
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3659
+            }
3660
+        }
3661
+        $env = _xor($env);
3662
+        $env = base64_encode($env);
3663
+        $len = strlen($env);
3664
+        // Si l’url est trop longue pour le navigateur
3665
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3666
+        if ($len > $max_len) {
3667
+            $cache_contextes_ajax = true;
3668
+            spip_log("Contextes AJAX forces en fichiers !"
3669
+                . " Cela arrive lorsque la valeur du contexte" 
3670
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3671
+                , _LOG_AVERTISSEMENT);
3672
+        }
3673
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3674
+        elseif (
3675
+            $max_len = @ini_get('suhosin.get.max_value_length')
3676
+            and $max_len < $len
3677
+        ) {
3678
+            $cache_contextes_ajax = true;
3679
+            spip_log("Contextes AJAX forces en fichiers !"
3680
+                . " Cela arrive lorsque la valeur du contexte"
3681
+                . " depasse la longueur maximale autorisee par Suhosin"
3682
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3683
+                . " Vous devriez modifier les parametres de Suhosin"
3684
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3685
+        } 
3686
+
3687
+    }
3688
+
3689
+    if ($cache_contextes_ajax) {
3690
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3691
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3692
+        $md5 = md5($c);
3693
+        ecrire_fichier("$dir/c$md5", $c);
3694
+        $env = $md5;
3695
+    }
3696
+
3697
+    if ($emboite === null) {
3698
+        return $env;
3699
+    }
3700
+    if (!trim($emboite)) {
3701
+        return "";
3702
+    }
3703
+    // toujours encoder l'url source dans le bloc ajax
3704
+    $r = self();
3705
+    $r = ' data-origin="' . $r . '"';
3706
+    $class = 'ajaxbloc';
3707
+    if ($ajaxid and is_string($ajaxid)) {
3708
+        // ajaxid est normalement conforme a un nom de classe css
3709
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3710
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3711
+    }
3712
+
3713
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3714 3714
 }
3715 3715
 
3716 3716
 /**
@@ -3730,36 +3730,36 @@  discard block
 block discarded – undo
3730 3730
  *   - false : erreur de décodage
3731 3731
  */
3732 3732
 function decoder_contexte_ajax($c, $form = '') {
3733
-	if (!function_exists('calculer_cle_action')) {
3734
-		include_spip("inc/securiser_action");
3735
-	}
3736
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3737
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3738
-		and lire_fichier("$dir/c$c", $contexte)
3739
-	) {
3740
-		$c = $contexte;
3741
-	} else {
3742
-		$c = @base64_decode($c);
3743
-		$c = _xor($c);
3744
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3745
-			$c = @gzinflate($c);
3746
-		}
3747
-	}
3748
-
3749
-	// extraire la signature en debut de contexte
3750
-	// et la verifier avant de deserializer
3751
-	// format : signature:donneesserializees
3752
-	if ($p = strpos($c,":")){
3753
-		$cle = substr($c,0,$p);
3754
-		$c = substr($c,$p+1);
3755
-
3756
-		if ($cle == calculer_cle_action($form . $c)) {
3757
-			$env = @unserialize($c);
3758
-			return $env;
3759
-		}
3760
-	}
3761
-
3762
-	return false;
3733
+    if (!function_exists('calculer_cle_action')) {
3734
+        include_spip("inc/securiser_action");
3735
+    }
3736
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3737
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3738
+        and lire_fichier("$dir/c$c", $contexte)
3739
+    ) {
3740
+        $c = $contexte;
3741
+    } else {
3742
+        $c = @base64_decode($c);
3743
+        $c = _xor($c);
3744
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3745
+            $c = @gzinflate($c);
3746
+        }
3747
+    }
3748
+
3749
+    // extraire la signature en debut de contexte
3750
+    // et la verifier avant de deserializer
3751
+    // format : signature:donneesserializees
3752
+    if ($p = strpos($c,":")){
3753
+        $cle = substr($c,0,$p);
3754
+        $c = substr($c,$p+1);
3755
+
3756
+        if ($cle == calculer_cle_action($form . $c)) {
3757
+            $env = @unserialize($c);
3758
+            return $env;
3759
+        }
3760
+    }
3761
+
3762
+    return false;
3763 3763
 }
3764 3764
 
3765 3765
 
@@ -3777,20 +3777,20 @@  discard block
 block discarded – undo
3777 3777
  *    Message décrypté ou encrypté
3778 3778
  **/
3779 3779
 function _xor($message, $key = null) {
3780
-	if (is_null($key)) {
3781
-		if (!function_exists('calculer_cle_action')) {
3782
-			include_spip("inc/securiser_action");
3783
-		}
3784
-		$key = pack("H*", calculer_cle_action('_xor'));
3785
-	}
3780
+    if (is_null($key)) {
3781
+        if (!function_exists('calculer_cle_action')) {
3782
+            include_spip("inc/securiser_action");
3783
+        }
3784
+        $key = pack("H*", calculer_cle_action('_xor'));
3785
+    }
3786 3786
 
3787
-	$keylen = strlen($key);
3788
-	$messagelen = strlen($message);
3789
-	for ($i = 0; $i < $messagelen; $i++) {
3790
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3791
-	}
3787
+    $keylen = strlen($key);
3788
+    $messagelen = strlen($message);
3789
+    for ($i = 0; $i < $messagelen; $i++) {
3790
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3791
+    }
3792 3792
 
3793
-	return $message;
3793
+    return $message;
3794 3794
 }
3795 3795
 
3796 3796
 /**
@@ -3848,22 +3848,22 @@  discard block
 block discarded – undo
3848 3848
  *   Code HTML
3849 3849
  */
3850 3850
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3851
-	if ($on) {
3852
-		$bal = "strong";
3853
-		$att = "class='on'";
3854
-	} else {
3855
-		$bal = 'a';
3856
-		$att = "href='$url'"
3857
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3858
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3859
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3860
-			. $evt;
3861
-	}
3862
-	if ($libelle === null) {
3863
-		$libelle = $url;
3864
-	}
3851
+    if ($on) {
3852
+        $bal = "strong";
3853
+        $att = "class='on'";
3854
+    } else {
3855
+        $bal = 'a';
3856
+        $att = "href='$url'"
3857
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3858
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3859
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3860
+            . $evt;
3861
+    }
3862
+    if ($libelle === null) {
3863
+        $libelle = $url;
3864
+    }
3865 3865
 
3866
-	return "<$bal $att>$libelle</$bal>";
3866
+    return "<$bal $att>$libelle</$bal>";
3867 3867
 }
3868 3868
 
3869 3869
 
@@ -3880,18 +3880,18 @@  discard block
 block discarded – undo
3880 3880
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3881 3881
  */
3882 3882
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3883
-	if (!is_numeric($nb) or $nb == 0) {
3884
-		return "";
3885
-	}
3886
-	if (!is_array($vars)) {
3887
-		return "";
3888
-	}
3889
-	$vars[$var] = $nb;
3890
-	if ($nb >= 2) {
3891
-		return _T($chaine_plusieurs, $vars);
3892
-	} else {
3893
-		return _T($chaine_un, $vars);
3894
-	}
3883
+    if (!is_numeric($nb) or $nb == 0) {
3884
+        return "";
3885
+    }
3886
+    if (!is_array($vars)) {
3887
+        return "";
3888
+    }
3889
+    $vars[$var] = $nb;
3890
+    if ($nb >= 2) {
3891
+        return _T($chaine_plusieurs, $vars);
3892
+    } else {
3893
+        return _T($chaine_un, $vars);
3894
+    }
3895 3895
 }
3896 3896
 
3897 3897
 
@@ -3916,56 +3916,56 @@  discard block
 block discarded – undo
3916 3916
  * @return string
3917 3917
  */
3918 3918
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3919
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3920
-		$class .= ' danger';
3921
-	} elseif ($fonction == "rien.gif") {
3922
-		$fonction = "";
3923
-	} elseif ($fonction == "delsafe") {
3924
-		$fonction = "del";
3925
-	}
3926
-
3927
-	$fond_origine = $fond;
3928
-	// remappage des icone : article-24.png+new => article-new-24.png
3929
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3930
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
3931
-	}
3932
-
3933
-	// ajouter le type d'objet dans la class de l'icone
3934
-	$class .= " " . substr(basename($fond), 0, -4);
3935
-
3936
-	$alt = attribut_html($texte);
3937
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3938
-
3939
-	$ajax = "";
3940
-	if (strpos($class, "ajax") !== false) {
3941
-		$ajax = "ajax";
3942
-		if (strpos($class, "preload") !== false) {
3943
-			$ajax .= " preload";
3944
-		}
3945
-		if (strpos($class, "nocache") !== false) {
3946
-			$ajax .= " nocache";
3947
-		}
3948
-		$ajax = " class='$ajax'";
3949
-	}
3950
-
3951
-	$size = 24;
3952
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3953
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3954
-		$size = $match[1];
3955
-	}
3956
-
3957
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3958
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3959
-
3960
-	if ($type == 'lien') {
3961
-		return "<span class='icone s$size $class'>"
3962
-		. "<a href='$lien'$title$ajax$javascript>"
3963
-		. $icone
3964
-		. "<b>$texte</b>"
3965
-		. "</a></span>\n";
3966
-	} else {
3967
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3968
-	}
3919
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3920
+        $class .= ' danger';
3921
+    } elseif ($fonction == "rien.gif") {
3922
+        $fonction = "";
3923
+    } elseif ($fonction == "delsafe") {
3924
+        $fonction = "del";
3925
+    }
3926
+
3927
+    $fond_origine = $fond;
3928
+    // remappage des icone : article-24.png+new => article-new-24.png
3929
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3930
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
3931
+    }
3932
+
3933
+    // ajouter le type d'objet dans la class de l'icone
3934
+    $class .= " " . substr(basename($fond), 0, -4);
3935
+
3936
+    $alt = attribut_html($texte);
3937
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3938
+
3939
+    $ajax = "";
3940
+    if (strpos($class, "ajax") !== false) {
3941
+        $ajax = "ajax";
3942
+        if (strpos($class, "preload") !== false) {
3943
+            $ajax .= " preload";
3944
+        }
3945
+        if (strpos($class, "nocache") !== false) {
3946
+            $ajax .= " nocache";
3947
+        }
3948
+        $ajax = " class='$ajax'";
3949
+    }
3950
+
3951
+    $size = 24;
3952
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
3953
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
3954
+        $size = $match[1];
3955
+    }
3956
+
3957
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3958
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
3959
+
3960
+    if ($type == 'lien') {
3961
+        return "<span class='icone s$size $class'>"
3962
+        . "<a href='$lien'$title$ajax$javascript>"
3963
+        . $icone
3964
+        . "<b>$texte</b>"
3965
+        . "</a></span>\n";
3966
+    } else {
3967
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3968
+    }
3969 3969
 }
3970 3970
 
3971 3971
 /**
@@ -3989,7 +3989,7 @@  discard block
 block discarded – undo
3989 3989
  *     Code HTML du lien
3990 3990
  **/
3991 3991
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3992
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3992
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3993 3993
 }
3994 3994
 
3995 3995
 /**
@@ -4024,7 +4024,7 @@  discard block
 block discarded – undo
4024 4024
  *     Code HTML du lien
4025 4025
  **/
4026 4026
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4027
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4027
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4028 4028
 }
4029 4029
 
4030 4030
 /**
@@ -4069,7 +4069,7 @@  discard block
 block discarded – undo
4069 4069
  *     Code HTML du lien
4070 4070
  **/
4071 4071
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4072
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4072
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4073 4073
 }
4074 4074
 
4075 4075
 /**
@@ -4100,7 +4100,7 @@  discard block
 block discarded – undo
4100 4100
  *     Code HTML du lien
4101 4101
  **/
4102 4102
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4103
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4103
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4104 4104
 }
4105 4105
 
4106 4106
 /**
@@ -4130,7 +4130,7 @@  discard block
 block discarded – undo
4130 4130
  *     Code HTML du lien
4131 4131
  */
4132 4132
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4133
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4133
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4134 4134
 }
4135 4135
 
4136 4136
 
@@ -4178,26 +4178,26 @@  discard block
 block discarded – undo
4178 4178
  * @return string Code CSS
4179 4179
  */
4180 4180
 function bando_images_background() {
4181
-	include_spip('inc/bandeau');
4182
-	// recuperer tous les boutons et leurs images
4183
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4181
+    include_spip('inc/bandeau');
4182
+    // recuperer tous les boutons et leurs images
4183
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4184 4184
 
4185
-	$res = "";
4186
-	foreach ($boutons as $page => $detail) {
4187
-		if ($detail->icone and strlen(trim($detail->icone))) {
4188
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4189
-		}
4190
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4191
-		if (is_array($detail->sousmenu)) {
4192
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4193
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4194
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4195
-				}
4196
-			}
4197
-		}
4198
-	}
4185
+    $res = "";
4186
+    foreach ($boutons as $page => $detail) {
4187
+        if ($detail->icone and strlen(trim($detail->icone))) {
4188
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4189
+        }
4190
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4191
+        if (is_array($detail->sousmenu)) {
4192
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4193
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4194
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4195
+                }
4196
+            }
4197
+        }
4198
+    }
4199 4199
 
4200
-	return $res;
4200
+    return $res;
4201 4201
 }
4202 4202
 
4203 4203
 /**
@@ -4216,19 +4216,19 @@  discard block
 block discarded – undo
4216 4216
  * @return string
4217 4217
  */
4218 4218
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4219
-	if ($confirm) {
4220
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4221
-		if ($callback) {
4222
-			$callback = "$confirm?($callback):false";
4223
-		} else {
4224
-			$callback = $confirm;
4225
-		}
4226
-	}
4227
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4228
-	$title = $title ? " title='$title'" : "";
4219
+    if ($confirm) {
4220
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4221
+        if ($callback) {
4222
+            $callback = "$confirm?($callback):false";
4223
+        } else {
4224
+            $callback = $confirm;
4225
+        }
4226
+    }
4227
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4228
+    $title = $title ? " title='$title'" : "";
4229 4229
 
4230
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4231
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4230
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4231
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4232 4232
 }
4233 4233
 
4234 4234
 /**
@@ -4249,78 +4249,78 @@  discard block
 block discarded – undo
4249 4249
  * @return string
4250 4250
  */
4251 4251
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4252
-	static $trouver_table = null;
4253
-	static $objets;
4254
-
4255
-	// On verifie qu'on a tout ce qu'il faut
4256
-	$id_objet = intval($id_objet);
4257
-	if (!($id_objet and $type_objet and $info)) {
4258
-		return '';
4259
-	}
4260
-
4261
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4262
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4263
-		return '';
4264
-	}
4265
-
4266
-	// Si on demande l'url, on retourne direct la fonction
4267
-	if ($info == 'url') {
4268
-		return generer_url_entite($id_objet, $type_objet);
4269
-	}
4270
-
4271
-	// Sinon on va tout chercher dans la table et on garde en memoire
4272
-	$demande_titre = ($info == 'titre');
4273
-
4274
-	// 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
4275
-	if (!isset($objets[$type_objet][$id_objet])
4276
-		or
4277
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4278
-	) {
4279
-		if (!$trouver_table) {
4280
-			$trouver_table = charger_fonction('trouver_table', 'base');
4281
-		}
4282
-		$desc = $trouver_table(table_objet_sql($type_objet));
4283
-		if (!$desc) {
4284
-			return $objets[$type_objet] = false;
4285
-		}
4286
-
4287
-		// Si on demande le titre, on le gere en interne
4288
-		$champ_titre = "";
4289
-		if ($demande_titre) {
4290
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4291
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4292
-		}
4293
-		include_spip('base/abstract_sql');
4294
-		include_spip('base/connect_sql');
4295
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4296
-			'*' . $champ_titre,
4297
-			$desc['table_sql'],
4298
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4299
-		);
4300
-	}
4301
-
4302
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4303
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4304
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4305
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4306
-	else {
4307
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4308
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4309
-		} // Sinon on prend directement le champ SQL tel quel
4310
-		else {
4311
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4312
-		}
4313
-	}
4314
-
4315
-	// On va ensuite appliquer les traitements automatiques si besoin
4316
-	if (!$etoile) {
4317
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4318
-		// mais ce fonctionnement est a ameliorer !
4319
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4320
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4321
-	}
4322
-
4323
-	return $info_generee;
4252
+    static $trouver_table = null;
4253
+    static $objets;
4254
+
4255
+    // On verifie qu'on a tout ce qu'il faut
4256
+    $id_objet = intval($id_objet);
4257
+    if (!($id_objet and $type_objet and $info)) {
4258
+        return '';
4259
+    }
4260
+
4261
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4262
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4263
+        return '';
4264
+    }
4265
+
4266
+    // Si on demande l'url, on retourne direct la fonction
4267
+    if ($info == 'url') {
4268
+        return generer_url_entite($id_objet, $type_objet);
4269
+    }
4270
+
4271
+    // Sinon on va tout chercher dans la table et on garde en memoire
4272
+    $demande_titre = ($info == 'titre');
4273
+
4274
+    // 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
4275
+    if (!isset($objets[$type_objet][$id_objet])
4276
+        or
4277
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4278
+    ) {
4279
+        if (!$trouver_table) {
4280
+            $trouver_table = charger_fonction('trouver_table', 'base');
4281
+        }
4282
+        $desc = $trouver_table(table_objet_sql($type_objet));
4283
+        if (!$desc) {
4284
+            return $objets[$type_objet] = false;
4285
+        }
4286
+
4287
+        // Si on demande le titre, on le gere en interne
4288
+        $champ_titre = "";
4289
+        if ($demande_titre) {
4290
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4291
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4292
+        }
4293
+        include_spip('base/abstract_sql');
4294
+        include_spip('base/connect_sql');
4295
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4296
+            '*' . $champ_titre,
4297
+            $desc['table_sql'],
4298
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4299
+        );
4300
+    }
4301
+
4302
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4303
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4304
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4305
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4306
+    else {
4307
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4308
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4309
+        } // Sinon on prend directement le champ SQL tel quel
4310
+        else {
4311
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4312
+        }
4313
+    }
4314
+
4315
+    // On va ensuite appliquer les traitements automatiques si besoin
4316
+    if (!$etoile) {
4317
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4318
+        // mais ce fonctionnement est a ameliorer !
4319
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4320
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4321
+    }
4322
+
4323
+    return $info_generee;
4324 4324
 }
4325 4325
 
4326 4326
 /**
@@ -4334,44 +4334,44 @@  discard block
 block discarded – undo
4334 4334
  * @return string
4335 4335
  */
4336 4336
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4337
-	if (!$champ) {
4338
-		return $texte;
4339
-	}
4337
+    if (!$champ) {
4338
+        return $texte;
4339
+    }
4340 4340
 	
4341
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4342
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4343
-	include_spip('inc/texte');
4341
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4342
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4343
+    include_spip('inc/texte');
4344 4344
 	
4345
-	$champ = strtoupper($champ);
4346
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4347
-	if (!$traitements or !is_array($traitements)) {
4348
-		return $texte;
4349
-	}
4345
+    $champ = strtoupper($champ);
4346
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4347
+    if (!$traitements or !is_array($traitements)) {
4348
+        return $texte;
4349
+    }
4350 4350
 
4351
-	$traitement = '';
4352
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4353
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4354
-		$table_objet = table_objet($table_objet);
4355
-		if (isset($traitements[$table_objet])) {
4356
-			$traitement = $traitements[$table_objet];
4357
-		}
4358
-	}
4359
-	if (!$traitement and isset($traitements[0])) {
4360
-		$traitement = $traitements[0];
4361
-	}
4362
-	// (sinon prendre le premier de la liste par defaut ?)
4351
+    $traitement = '';
4352
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4353
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4354
+        $table_objet = table_objet($table_objet);
4355
+        if (isset($traitements[$table_objet])) {
4356
+            $traitement = $traitements[$table_objet];
4357
+        }
4358
+    }
4359
+    if (!$traitement and isset($traitements[0])) {
4360
+        $traitement = $traitements[0];
4361
+    }
4362
+    // (sinon prendre le premier de la liste par defaut ?)
4363 4363
 
4364
-	if (!$traitement) {
4365
-		return $texte;
4366
-	}
4364
+    if (!$traitement) {
4365
+        return $texte;
4366
+    }
4367 4367
 
4368
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4368
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4369 4369
 
4370
-	// Fournir $connect et $Pile[0] au traitement si besoin
4371
-	$Pile = array(0 => $env);
4372
-	eval("\$texte = $traitement;");
4370
+    // Fournir $connect et $Pile[0] au traitement si besoin
4371
+    $Pile = array(0 => $env);
4372
+    eval("\$texte = $traitement;");
4373 4373
 
4374
-	return $texte;
4374
+    return $texte;
4375 4375
 }
4376 4376
 
4377 4377
 
@@ -4385,21 +4385,21 @@  discard block
 block discarded – undo
4385 4385
  * @return string
4386 4386
  */
4387 4387
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4388
-	include_spip('inc/liens');
4389
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4390
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4391
-	// le raccourcis n'est plus valide
4392
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4393
-	// on essaye avec generer_info_entite ?
4394
-	if (!strlen($titre) and !$connect) {
4395
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4396
-	}
4397
-	if (!strlen($titre)) {
4398
-		$titre = _T('info_sans_titre');
4399
-	}
4400
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4388
+    include_spip('inc/liens');
4389
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4390
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4391
+    // le raccourcis n'est plus valide
4392
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4393
+    // on essaye avec generer_info_entite ?
4394
+    if (!strlen($titre) and !$connect) {
4395
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4396
+    }
4397
+    if (!strlen($titre)) {
4398
+        $titre = _T('info_sans_titre');
4399
+    }
4400
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4401 4401
 
4402
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4402
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4403 4403
 }
4404 4404
 
4405 4405
 
@@ -4416,15 +4416,15 @@  discard block
 block discarded – undo
4416 4416
  * @return string
4417 4417
  */
4418 4418
 function wrap($texte, $wrap) {
4419
-	$balises = extraire_balises($wrap);
4420
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4421
-		$texte = $wrap . $texte;
4422
-		$regs = array_reverse($regs[1]);
4423
-		$wrap = "</" . implode("></", $regs) . ">";
4424
-		$texte = $texte . $wrap;
4425
-	}
4419
+    $balises = extraire_balises($wrap);
4420
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4421
+        $texte = $wrap . $texte;
4422
+        $regs = array_reverse($regs[1]);
4423
+        $wrap = "</" . implode("></", $regs) . ">";
4424
+        $texte = $texte . $wrap;
4425
+    }
4426 4426
 
4427
-	return $texte;
4427
+    return $texte;
4428 4428
 }
4429 4429
 
4430 4430
 
@@ -4444,43 +4444,43 @@  discard block
 block discarded – undo
4444 4444
  * @return array|mixed|string
4445 4445
  */
4446 4446
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4447
-	if (is_string($u)) {
4448
-		$u = typo($u);
4447
+    if (is_string($u)) {
4448
+        $u = typo($u);
4449 4449
 
4450
-		return $u;
4451
-	}
4450
+        return $u;
4451
+    }
4452 4452
 
4453
-	// caster $u en array si besoin
4454
-	if (is_object($u)) {
4455
-		$u = (array)$u;
4456
-	}
4453
+    // caster $u en array si besoin
4454
+    if (is_object($u)) {
4455
+        $u = (array)$u;
4456
+    }
4457 4457
 
4458
-	if (is_array($u)) {
4459
-		$out = "";
4460
-		// toutes les cles sont numeriques ?
4461
-		// et aucun enfant n'est un tableau
4462
-		// liste simple separee par des virgules
4463
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4464
-		$array_values = array_map('is_array', $u);
4465
-		$object_values = array_map('is_object', $u);
4466
-		if (array_sum($numeric_keys) == count($numeric_keys)
4467
-			and !array_sum($array_values)
4468
-			and !array_sum($object_values)
4469
-		) {
4470
-			return join(", ", array_map('filtre_print_dist', $u));
4471
-		}
4458
+    if (is_array($u)) {
4459
+        $out = "";
4460
+        // toutes les cles sont numeriques ?
4461
+        // et aucun enfant n'est un tableau
4462
+        // liste simple separee par des virgules
4463
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4464
+        $array_values = array_map('is_array', $u);
4465
+        $object_values = array_map('is_object', $u);
4466
+        if (array_sum($numeric_keys) == count($numeric_keys)
4467
+            and !array_sum($array_values)
4468
+            and !array_sum($object_values)
4469
+        ) {
4470
+            return join(", ", array_map('filtre_print_dist', $u));
4471
+        }
4472 4472
 
4473
-		// sinon on passe a la ligne et on indente
4474
-		$i_str = str_pad("", $indent, " ");
4475
-		foreach ($u as $k => $v) {
4476
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4477
-		}
4473
+        // sinon on passe a la ligne et on indente
4474
+        $i_str = str_pad("", $indent, " ");
4475
+        foreach ($u as $k => $v) {
4476
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4477
+        }
4478 4478
 
4479
-		return $out;
4480
-	}
4479
+        return $out;
4480
+    }
4481 4481
 
4482
-	// on sait pas quoi faire...
4483
-	return $u;
4482
+    // on sait pas quoi faire...
4483
+    return $u;
4484 4484
 }
4485 4485
 
4486 4486
 
@@ -4493,10 +4493,10 @@  discard block
 block discarded – undo
4493 4493
  * @return string|array
4494 4494
  */
4495 4495
 function objet_info($objet, $info) {
4496
-	$table = table_objet_sql($objet);
4497
-	$infos = lister_tables_objets_sql($table);
4496
+    $table = table_objet_sql($objet);
4497
+    $infos = lister_tables_objets_sql($table);
4498 4498
 
4499
-	return (isset($infos[$info]) ? $infos[$info] : '');
4499
+    return (isset($infos[$info]) ? $infos[$info] : '');
4500 4500
 }
4501 4501
 
4502 4502
 /**
@@ -4511,11 +4511,11 @@  discard block
 block discarded – undo
4511 4511
  *     Texte traduit du comptage, tel que '3 articles'
4512 4512
  */
4513 4513
 function objet_afficher_nb($nb, $objet) {
4514
-	if (!$nb) {
4515
-		return _T(objet_info($objet, 'info_aucun_objet'));
4516
-	} else {
4517
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4518
-	}
4514
+    if (!$nb) {
4515
+        return _T(objet_info($objet, 'info_aucun_objet'));
4516
+    } else {
4517
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4518
+    }
4519 4519
 }
4520 4520
 
4521 4521
 /**
@@ -4527,11 +4527,11 @@  discard block
 block discarded – undo
4527 4527
  * @return string
4528 4528
  */
4529 4529
 function objet_icone($objet, $taille = 24, $class='') {
4530
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4531
-	$icone = chemin_image($icone);
4532
-	$balise_img = charger_filtre('balise_img');
4530
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4531
+    $icone = chemin_image($icone);
4532
+    $balise_img = charger_filtre('balise_img');
4533 4533
 
4534
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4534
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4535 4535
 }
4536 4536
 
4537 4537
 /**
@@ -4552,12 +4552,12 @@  discard block
 block discarded – undo
4552 4552
  * @return string
4553 4553
  */
4554 4554
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4555
-	$chaine = explode(':',$chaine);
4556
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4557
-		return $t;
4558
-	}
4559
-	$chaine = implode(':',$chaine);
4560
-	return _T($chaine, $args, $options);
4555
+    $chaine = explode(':',$chaine);
4556
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4557
+        return $t;
4558
+    }
4559
+    $chaine = implode(':',$chaine);
4560
+    return _T($chaine, $args, $options);
4561 4561
 }
4562 4562
 
4563 4563
 /**
@@ -4571,17 +4571,17 @@  discard block
 block discarded – undo
4571 4571
  * @return string      Code HTML
4572 4572
  */
4573 4573
 function insert_head_css_conditionnel($flux) {
4574
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4575
-		and $p = strpos($flux, '<!-- insert_head -->')
4576
-	) {
4577
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4578
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4579
-			$p = $p1;
4580
-		}
4581
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4582
-	}
4574
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4575
+        and $p = strpos($flux, '<!-- insert_head -->')
4576
+    ) {
4577
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4578
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4579
+            $p = $p1;
4580
+        }
4581
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4582
+    }
4583 4583
 
4584
-	return $flux;
4584
+    return $flux;
4585 4585
 }
4586 4586
 
4587 4587
 /**
@@ -4602,69 +4602,69 @@  discard block
 block discarded – undo
4602 4602
  * @return string
4603 4603
  */
4604 4604
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4605
-	if (isset($contexte['format'])) {
4606
-		$extension = $contexte['format'];
4607
-		unset($contexte['format']);
4608
-	} else {
4609
-		$extension = "html";
4610
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4611
-			$extension = $m[1];
4612
-		}
4613
-	}
4614
-	// recuperer le contenu produit par le squelette
4615
-	$options['raw'] = true;
4616
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4617
-
4618
-	// calculer le nom de la css
4619
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4620
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4621
-	$contexte_implicite = calculer_contexte_implicite();
4622
-
4623
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4624
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4625
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4626
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4627
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4628
-	}
4629
-	else {
4630
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4631
-		ksort($contexte);
4632
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4633
-	}
4634
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4635
-
4636
-	// mettre a jour le fichier si il n'existe pas
4637
-	// ou trop ancien
4638
-	// le dernier fichier produit est toujours suffixe par .last
4639
-	// et recopie sur le fichier cible uniquement si il change
4640
-	if (!file_exists($filename)
4641
-		or !file_exists($filename . ".last")
4642
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4643
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4644
-	) {
4645
-		$contenu = $cache['texte'];
4646
-		// passer les urls en absolu si c'est une css
4647
-		if ($extension == "css") {
4648
-			$contenu = urls_absolues_css($contenu,
4649
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4650
-		}
4651
-
4652
-		$comment = '';
4653
-		// ne pas insérer de commentaire si c'est du json
4654
-		if ($extension != "json") {
4655
-			$comment = "/* #PRODUIRE{fond=$fond";
4656
-			foreach ($contexte as $k => $v) {
4657
-				$comment .= ",$k=$v";
4658
-			}
4659
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4660
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4661
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4662
-		}
4663
-		// et ecrire le fichier si il change
4664
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4665
-	}
4666
-
4667
-	return timestamp($filename);
4605
+    if (isset($contexte['format'])) {
4606
+        $extension = $contexte['format'];
4607
+        unset($contexte['format']);
4608
+    } else {
4609
+        $extension = "html";
4610
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4611
+            $extension = $m[1];
4612
+        }
4613
+    }
4614
+    // recuperer le contenu produit par le squelette
4615
+    $options['raw'] = true;
4616
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4617
+
4618
+    // calculer le nom de la css
4619
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4620
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4621
+    $contexte_implicite = calculer_contexte_implicite();
4622
+
4623
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4624
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4625
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4626
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4627
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4628
+    }
4629
+    else {
4630
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4631
+        ksort($contexte);
4632
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4633
+    }
4634
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4635
+
4636
+    // mettre a jour le fichier si il n'existe pas
4637
+    // ou trop ancien
4638
+    // le dernier fichier produit est toujours suffixe par .last
4639
+    // et recopie sur le fichier cible uniquement si il change
4640
+    if (!file_exists($filename)
4641
+        or !file_exists($filename . ".last")
4642
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4643
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4644
+    ) {
4645
+        $contenu = $cache['texte'];
4646
+        // passer les urls en absolu si c'est une css
4647
+        if ($extension == "css") {
4648
+            $contenu = urls_absolues_css($contenu,
4649
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4650
+        }
4651
+
4652
+        $comment = '';
4653
+        // ne pas insérer de commentaire si c'est du json
4654
+        if ($extension != "json") {
4655
+            $comment = "/* #PRODUIRE{fond=$fond";
4656
+            foreach ($contexte as $k => $v) {
4657
+                $comment .= ",$k=$v";
4658
+            }
4659
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4660
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4661
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4662
+        }
4663
+        // et ecrire le fichier si il change
4664
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4665
+    }
4666
+
4667
+    return timestamp($filename);
4668 4668
 }
4669 4669
 
4670 4670
 /**
@@ -4677,14 +4677,14 @@  discard block
 block discarded – undo
4677 4677
  *    $fichier auquel on a ajouté le timestamp
4678 4678
  */
4679 4679
 function timestamp($fichier) {
4680
-	if (!$fichier
4681
-		or !file_exists($fichier)
4682
-		or !$m = filemtime($fichier)
4683
-	) {
4684
-		return $fichier;
4685
-	}
4680
+    if (!$fichier
4681
+        or !file_exists($fichier)
4682
+        or !$m = filemtime($fichier)
4683
+    ) {
4684
+        return $fichier;
4685
+    }
4686 4686
 
4687
-	return "$fichier?$m";
4687
+    return "$fichier?$m";
4688 4688
 }
4689 4689
 
4690 4690
 /**
@@ -4694,11 +4694,11 @@  discard block
 block discarded – undo
4694 4694
  * @return string
4695 4695
  */
4696 4696
 function supprimer_timestamp($url) {
4697
-	if (strpos($url, "?") === false) {
4698
-		return $url;
4699
-	}
4697
+    if (strpos($url, "?") === false) {
4698
+        return $url;
4699
+    }
4700 4700
 
4701
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4701
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4702 4702
 }
4703 4703
 
4704 4704
 /**
@@ -4713,9 +4713,9 @@  discard block
 block discarded – undo
4713 4713
  * @return string
4714 4714
  */
4715 4715
 function filtre_nettoyer_titre_email_dist($titre) {
4716
-	include_spip('inc/envoyer_mail');
4716
+    include_spip('inc/envoyer_mail');
4717 4717
 
4718
-	return nettoyer_titre_email($titre);
4718
+    return nettoyer_titre_email($titre);
4719 4719
 }
4720 4720
 
4721 4721
 /**
@@ -4737,19 +4737,19 @@  discard block
 block discarded – undo
4737 4737
  * @return string
4738 4738
  */
4739 4739
 function filtre_chercher_rubrique_dist(
4740
-	$titre,
4741
-	$id_objet,
4742
-	$id_parent,
4743
-	$objet,
4744
-	$id_secteur,
4745
-	$restreint,
4746
-	$actionable = false,
4747
-	$retour_sans_cadre = false
4740
+    $titre,
4741
+    $id_objet,
4742
+    $id_parent,
4743
+    $objet,
4744
+    $id_secteur,
4745
+    $restreint,
4746
+    $actionable = false,
4747
+    $retour_sans_cadre = false
4748 4748
 ) {
4749
-	include_spip('inc/filtres_ecrire');
4749
+    include_spip('inc/filtres_ecrire');
4750 4750
 
4751
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4752
-		$retour_sans_cadre);
4751
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4752
+        $retour_sans_cadre);
4753 4753
 }
4754 4754
 
4755 4755
 /**
@@ -4778,56 +4778,56 @@  discard block
 block discarded – undo
4778 4778
  *     Chaîne vide si l'accès est autorisé
4779 4779
  */
4780 4780
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4781
-	if ($ok) {
4782
-		return '';
4783
-	}
4784
-
4785
-	// Vider tous les tampons
4786
-	$level = @ob_get_level();
4787
-	while ($level--) {
4788
-		@ob_end_clean();
4789
-	}
4790
-
4791
-	include_spip('inc/headers');
4792
-
4793
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4794
-	if ($url) {
4795
-		redirige_par_entete($url, '', $statut);
4796
-	}
4797
-
4798
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4799
-	if (!is_numeric($statut) and is_null($message)) {
4800
-		$message = $statut;
4801
-		$statut = 0;
4802
-	}
4803
-	if (!$message) {
4804
-		$message = '';
4805
-	}
4806
-	$statut = intval($statut);
4807
-
4808
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4809
-	if (test_espace_prive()) {
4810
-		if (!$statut or !in_array($statut, array(404, 403))) {
4811
-			$statut = 403;
4812
-		}
4813
-		http_status(403);
4814
-		$echec = charger_fonction('403', 'exec');
4815
-		$echec($message);
4816
-	} else {
4817
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4818
-		if (!$statut) {
4819
-			$statut = 404;
4820
-		}
4821
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4822
-		http_status($statut);
4823
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4824
-		if ($statut >= 400) {
4825
-			echo recuperer_fond("$statut", array('erreur' => $message));
4826
-		}
4827
-	}
4828
-
4829
-
4830
-	exit;
4781
+    if ($ok) {
4782
+        return '';
4783
+    }
4784
+
4785
+    // Vider tous les tampons
4786
+    $level = @ob_get_level();
4787
+    while ($level--) {
4788
+        @ob_end_clean();
4789
+    }
4790
+
4791
+    include_spip('inc/headers');
4792
+
4793
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4794
+    if ($url) {
4795
+        redirige_par_entete($url, '', $statut);
4796
+    }
4797
+
4798
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4799
+    if (!is_numeric($statut) and is_null($message)) {
4800
+        $message = $statut;
4801
+        $statut = 0;
4802
+    }
4803
+    if (!$message) {
4804
+        $message = '';
4805
+    }
4806
+    $statut = intval($statut);
4807
+
4808
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4809
+    if (test_espace_prive()) {
4810
+        if (!$statut or !in_array($statut, array(404, 403))) {
4811
+            $statut = 403;
4812
+        }
4813
+        http_status(403);
4814
+        $echec = charger_fonction('403', 'exec');
4815
+        $echec($message);
4816
+    } else {
4817
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4818
+        if (!$statut) {
4819
+            $statut = 404;
4820
+        }
4821
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4822
+        http_status($statut);
4823
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4824
+        if ($statut >= 400) {
4825
+            echo recuperer_fond("$statut", array('erreur' => $message));
4826
+        }
4827
+    }
4828
+
4829
+
4830
+    exit;
4831 4831
 }
4832 4832
 
4833 4833
 /**
@@ -4838,11 +4838,11 @@  discard block
 block discarded – undo
4838 4838
  * @return string
4839 4839
  */
4840 4840
 function filtre_compacte_dist($source, $format = null) {
4841
-	if (function_exists('compacte')) {
4842
-		return compacte($source, $format);
4843
-	}
4841
+    if (function_exists('compacte')) {
4842
+        return compacte($source, $format);
4843
+    }
4844 4844
 
4845
-	return $source;
4845
+    return $source;
4846 4846
 }
4847 4847
 
4848 4848
 
@@ -4854,29 +4854,29 @@  discard block
 block discarded – undo
4854 4854
  * @return string
4855 4855
  */
4856 4856
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
4857
-	$l = strlen($passe);
4858
-
4859
-	if ($l<=8 or !$afficher_partiellement){
4860
-		if (!$l) {
4861
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4862
-		}
4863
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
4864
-	}
4865
-
4866
-	if (is_null($portion_pourcent)) {
4867
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4868
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4869
-		}
4870
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4871
-	}
4872
-	if ($portion_pourcent >= 100) {
4873
-		return $passe;
4874
-	}
4875
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
4876
-	$e = max($e, 0);
4877
-	$mid = str_pad('',$l-2*$e,'*');
4878
-	if ($e>0 and strlen($mid)>8){
4879
-		$mid = '***...***';
4880
-	}
4881
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4857
+    $l = strlen($passe);
4858
+
4859
+    if ($l<=8 or !$afficher_partiellement){
4860
+        if (!$l) {
4861
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4862
+        }
4863
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
4864
+    }
4865
+
4866
+    if (is_null($portion_pourcent)) {
4867
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4868
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4869
+        }
4870
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4871
+    }
4872
+    if ($portion_pourcent >= 100) {
4873
+        return $passe;
4874
+    }
4875
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
4876
+    $e = max($e, 0);
4877
+    $mid = str_pad('',$l-2*$e,'*');
4878
+    if ($e>0 and strlen($mid)>8){
4879
+        $mid = '***...***';
4880
+    }
4881
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4882 4882
 }
4883 4883
\ No newline at end of file
Please login to merge, or discard this patch.