Completed
Push — master ( 891627...7497d6 )
by cam
05:58
created
ecrire/inc/filtres.php 1 patch
Indentation   +2026 added lines, -2026 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_spip('public/parametrer'); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,36 +75,36 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
-		// fonction ou name\space\fonction
98
-		if (is_callable($f)) {
99
-			return $f;
100
-		}
101
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
-			return $f;
104
-		}
105
-	}
106
-
107
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
+        // fonction ou name\space\fonction
98
+        if (is_callable($f)) {
99
+            return $f;
100
+        }
101
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
+            return $f;
104
+        }
105
+    }
106
+
107
+    return $default;
108 108
 }
109 109
 
110 110
 /**
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
  *     Chaîne vide sinon (filtre introuvable).
129 129
  **/
130 130
 function appliquer_filtre($arg, $filtre, $force = null) {
131
-	$f = chercher_filtre($filtre);
132
-	if (!$f) {
133
-		if (!$force) {
134
-			return '';
135
-		} else {
136
-			return $arg;
137
-		}
138
-	}
131
+    $f = chercher_filtre($filtre);
132
+    if (!$f) {
133
+        if (!$force) {
134
+            return '';
135
+        } else {
136
+            return $arg;
137
+        }
138
+    }
139 139
 
140
-	$args = func_get_args();
141
-	array_shift($args); // enlever $arg
142
-	array_shift($args); // enlever $filtre
143
-	array_unshift($args, $arg); // remettre $arg
144
-	return call_user_func_array($f, $args);
140
+    $args = func_get_args();
141
+    array_shift($args); // enlever $arg
142
+    array_shift($args); // enlever $filtre
143
+    array_unshift($args, $arg); // remettre $arg
144
+    return call_user_func_array($f, $args);
145 145
 }
146 146
 
147 147
 /**
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
  *     Version de SPIP
158 158
  **/
159 159
 function spip_version() {
160
-	$version = $GLOBALS['spip_version_affichee'];
161
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
162
-		$version .= " $vcs_version";
163
-	}
160
+    $version = $GLOBALS['spip_version_affichee'];
161
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
162
+        $version .= " $vcs_version";
163
+    }
164 164
 
165
-	return $version;
165
+    return $version;
166 166
 }
167 167
 
168 168
 /**
@@ -175,19 +175,19 @@  discard block
 block discarded – undo
175 175
  *    - string|null si $raw = false
176 176
  */
177 177
 function version_vcs_courante($dir, $raw = false) {
178
-	$desc = decrire_version_git($dir);
179
-	if ($desc === null) {
180
-		$desc = decrire_version_svn($dir);
181
-	}
182
-	if ($desc === null or $raw) {
183
-		return $desc;
184
-	}
185
-	// affichage "GIT [master: abcdef]"
186
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
187
-	if ($desc['branch']) {
188
-		$commit = $desc['branch'] . ': ' . $commit;
189
-	}
190
-	return "{$desc['vcs']} [$commit]";
178
+    $desc = decrire_version_git($dir);
179
+    if ($desc === null) {
180
+        $desc = decrire_version_svn($dir);
181
+    }
182
+    if ($desc === null or $raw) {
183
+        return $desc;
184
+    }
185
+    // affichage "GIT [master: abcdef]"
186
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
187
+    if ($desc['branch']) {
188
+        $commit = $desc['branch'] . ': ' . $commit;
189
+    }
190
+    return "{$desc['vcs']} [$commit]";
191 191
 }
192 192
 
193 193
 /**
@@ -199,24 +199,24 @@  discard block
 block discarded – undo
199 199
  *      array ['branch' => xx, 'commit' => yy] sinon.
200 200
  **/
201 201
 function decrire_version_git($dir) {
202
-	if (!$dir) {
203
-		$dir = '.';
204
-	}
202
+    if (!$dir) {
203
+        $dir = '.';
204
+    }
205 205
 
206
-	// version installee par GIT
207
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
208
-		$currentHead = trim(substr($c, 4));
209
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
210
-			return [
211
-				'vcs' => 'GIT',
212
-				'branch' => basename($currentHead),
213
-				'commit' => trim($hash),
214
-				'commit_short' => substr(trim($hash), 0, 8),
215
-			];
216
-		}
217
-	}
206
+    // version installee par GIT
207
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
208
+        $currentHead = trim(substr($c, 4));
209
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
210
+            return [
211
+                'vcs' => 'GIT',
212
+                'branch' => basename($currentHead),
213
+                'commit' => trim($hash),
214
+                'commit_short' => substr(trim($hash), 0, 8),
215
+            ];
216
+        }
217
+    }
218 218
 
219
-	return null;
219
+    return null;
220 220
 }
221 221
 
222 222
 
@@ -229,25 +229,25 @@  discard block
 block discarded – undo
229 229
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
230 230
  **/
231 231
 function decrire_version_svn($dir) {
232
-	if (!$dir) {
233
-		$dir = '.';
234
-	}
235
-	// version installee par SVN
236
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
237
-		$db = new SQLite3($dir . '/.svn/wc.db');
238
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
239
-		if ($result) {
240
-			$row = $result->fetchArray();
241
-			if ($row['changed_revision'] != "") {
242
-				return [
243
-					'vcs' => 'SVN',
244
-					'branch' => '',
245
-					'commit' => $row['changed_revision'],
246
-				];
247
-			}
248
-		}
249
-	}
250
-	return null;
232
+    if (!$dir) {
233
+        $dir = '.';
234
+    }
235
+    // version installee par SVN
236
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
237
+        $db = new SQLite3($dir . '/.svn/wc.db');
238
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
239
+        if ($result) {
240
+            $row = $result->fetchArray();
241
+            if ($row['changed_revision'] != "") {
242
+                return [
243
+                    'vcs' => 'SVN',
244
+                    'branch' => '',
245
+                    'commit' => $row['changed_revision'],
246
+                ];
247
+            }
248
+        }
249
+    }
250
+    return null;
251 251
 }
252 252
 
253 253
 /**
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
  *
266 266
  **/
267 267
 function version_svn_courante($dir) {
268
-	if ($desc = decrire_version_svn($dir)) {
269
-		return -$desc['commit'];
270
-	}
271
-	return 0;
268
+    if ($desc = decrire_version_svn($dir)) {
269
+        return -$desc['commit'];
270
+    }
271
+    return 0;
272 272
 }
273 273
 
274 274
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -312,18 +312,18 @@  discard block
 block discarded – undo
312 312
  *     Code HTML retourné par le filtre
313 313
  **/
314 314
 function filtrer($filtre) {
315
-	$tous = func_get_args();
316
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
317
-		return image_filtrer($tous);
318
-	} elseif ($f = chercher_filtre($filtre)) {
319
-		array_shift($tous);
320
-		return call_user_func_array($f, $tous);
321
-	} else {
322
-		// le filtre n'existe pas, on provoque une erreur
323
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
324
-		erreur_squelette($msg);
325
-		return '';
326
-	}
315
+    $tous = func_get_args();
316
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
317
+        return image_filtrer($tous);
318
+    } elseif ($f = chercher_filtre($filtre)) {
319
+        array_shift($tous);
320
+        return call_user_func_array($f, $tous);
321
+    } else {
322
+        // le filtre n'existe pas, on provoque une erreur
323
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
324
+        erreur_squelette($msg);
325
+        return '';
326
+    }
327 327
 }
328 328
 
329 329
 /**
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
341 341
  */
342 342
 function trouver_filtre_matrice($filtre) {
343
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
344
-		find_in_path($f, '', true);
345
-		$GLOBALS['spip_matrice'][$filtre] = true;
346
-	}
347
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
343
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
344
+        find_in_path($f, '', true);
345
+        $GLOBALS['spip_matrice'][$filtre] = true;
346
+    }
347
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
348 348
 }
349 349
 
350 350
 
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
  * @return mixed
373 373
  */
374 374
 function filtre_set(&$Pile, $val, $key, $continue = null) {
375
-	$Pile['vars'][$key] = $val;
376
-	return $continue ? $val : '';
375
+    $Pile['vars'][$key] = $val;
376
+    return $continue ? $val : '';
377 377
 }
378 378
 
379 379
 /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
400 400
  */
401 401
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
402
-	$Pile[0][$key] = $val;
403
-	return $continue ? $val : '';
402
+    $Pile[0][$key] = $val;
403
+    return $continue ? $val : '';
404 404
 }
405 405
 
406 406
 /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
  * @return string
410 410
  */
411 411
 function filtre_sanitize_env(&$Pile, $keys) {
412
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
413
-	return '';
412
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
413
+    return '';
414 414
 }
415 415
 
416 416
 
@@ -433,18 +433,18 @@  discard block
 block discarded – undo
433 433
  * @return mixed Retourne la valeur (sans la modifier).
434 434
  */
435 435
 function filtre_debug($val, $key = null) {
436
-	$debug = (
437
-		is_null($key) ? '' : (var_export($key, true) . " = ")
438
-		) . var_export($val, true);
436
+    $debug = (
437
+        is_null($key) ? '' : (var_export($key, true) . " = ")
438
+        ) . var_export($val, true);
439 439
 
440
-	include_spip('inc/autoriser');
441
-	if (autoriser('webmestre')) {
442
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
443
-	}
440
+    include_spip('inc/autoriser');
441
+    if (autoriser('webmestre')) {
442
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
443
+    }
444 444
 
445
-	spip_log($debug, 'debug');
445
+    spip_log($debug, 'debug');
446 446
 
447
-	return $val;
447
+    return $val;
448 448
 }
449 449
 
450 450
 
@@ -472,71 +472,71 @@  discard block
 block discarded – undo
472 472
  *     Texte qui a reçu les filtres
473 473
  **/
474 474
 function image_filtrer($args) {
475
-	$filtre = array_shift($args); # enlever $filtre
476
-	$texte = array_shift($args);
477
-	if (!strlen($texte)) {
478
-		return;
479
-	}
480
-	find_in_path('filtres_images_mini.php', 'inc/', true);
481
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
482
-	// Cas du nom de fichier local
483
-	if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
484
-		and !preg_match(',^/|[<>]|\s,S', $texte)
485
-		and (
486
-			file_exists(preg_replace(',[?].*$,', '', $texte))
487
-			or tester_url_absolue($texte)
488
-		)
489
-	) {
490
-		array_unshift($args, "<img src='$texte' />");
491
-		$res = call_user_func_array($filtre, $args);
492
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
493
-		return $res;
494
-	}
495
-
496
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
497
-	if (preg_match_all(
498
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
499
-		$texte, $tags, PREG_SET_ORDER)) {
500
-		foreach ($tags as $tag) {
501
-			$class = extraire_attribut($tag[3], 'class');
502
-			if (!$class or
503
-				(strpos($class, 'filtre_inactif') === false
504
-					// compat historique a virer en 3.2
505
-					and strpos($class, 'no_image_filtrer') === false)
506
-			) {
507
-				array_unshift($args, $tag[3]);
508
-				if ($reduit = call_user_func_array($filtre, $args)) {
509
-					// En cas de span spip_documents, modifier le style=...width:
510
-					if ($tag[1]) {
511
-						$w = extraire_attribut($reduit, 'width');
512
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
513
-							$w = $regs[1];
514
-						}
515
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
516
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
517
-							$replace = inserer_attribut($tag[1], 'style', $style);
518
-							$texte = str_replace($tag[1], $replace, $texte);
519
-						}
520
-					}
521
-					// traiter aussi un eventuel mouseover
522
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
523
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
524
-							$srcover = $match[1];
525
-							array_shift($args);
526
-							array_unshift($args, "<img src='" . $match[1] . "' />");
527
-							$srcover_filter = call_user_func_array($filtre, $args);
528
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
529
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
530
-						}
531
-					}
532
-					$texte = str_replace($tag[3], $reduit, $texte);
533
-				}
534
-				array_shift($args);
535
-			}
536
-		}
537
-	}
538
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
539
-	return $texte;
475
+    $filtre = array_shift($args); # enlever $filtre
476
+    $texte = array_shift($args);
477
+    if (!strlen($texte)) {
478
+        return;
479
+    }
480
+    find_in_path('filtres_images_mini.php', 'inc/', true);
481
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
482
+    // Cas du nom de fichier local
483
+    if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
484
+        and !preg_match(',^/|[<>]|\s,S', $texte)
485
+        and (
486
+            file_exists(preg_replace(',[?].*$,', '', $texte))
487
+            or tester_url_absolue($texte)
488
+        )
489
+    ) {
490
+        array_unshift($args, "<img src='$texte' />");
491
+        $res = call_user_func_array($filtre, $args);
492
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
493
+        return $res;
494
+    }
495
+
496
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
497
+    if (preg_match_all(
498
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
499
+        $texte, $tags, PREG_SET_ORDER)) {
500
+        foreach ($tags as $tag) {
501
+            $class = extraire_attribut($tag[3], 'class');
502
+            if (!$class or
503
+                (strpos($class, 'filtre_inactif') === false
504
+                    // compat historique a virer en 3.2
505
+                    and strpos($class, 'no_image_filtrer') === false)
506
+            ) {
507
+                array_unshift($args, $tag[3]);
508
+                if ($reduit = call_user_func_array($filtre, $args)) {
509
+                    // En cas de span spip_documents, modifier le style=...width:
510
+                    if ($tag[1]) {
511
+                        $w = extraire_attribut($reduit, 'width');
512
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
513
+                            $w = $regs[1];
514
+                        }
515
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
516
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
517
+                            $replace = inserer_attribut($tag[1], 'style', $style);
518
+                            $texte = str_replace($tag[1], $replace, $texte);
519
+                        }
520
+                    }
521
+                    // traiter aussi un eventuel mouseover
522
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
523
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
524
+                            $srcover = $match[1];
525
+                            array_shift($args);
526
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
527
+                            $srcover_filter = call_user_func_array($filtre, $args);
528
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
529
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
530
+                        }
531
+                    }
532
+                    $texte = str_replace($tag[3], $reduit, $texte);
533
+                }
534
+                array_shift($args);
535
+            }
536
+        }
537
+    }
538
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
539
+    return $texte;
540 540
 }
541 541
 
542 542
 /**
@@ -551,65 +551,65 @@  discard block
 block discarded – undo
551 551
  **/
552 552
 function taille_image($img) {
553 553
 
554
-	static $largeur_img = array(), $hauteur_img = array();
555
-	$srcWidth = 0;
556
-	$srcHeight = 0;
557
-
558
-	$src = extraire_attribut($img, 'src');
559
-
560
-	if (!$src) {
561
-		$src = $img;
562
-	} else {
563
-		$srcWidth = extraire_attribut($img, 'width');
564
-		$srcHeight = extraire_attribut($img, 'height');
565
-	}
566
-
567
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
568
-	// la copie locale a toutes les chances d'etre la ou de resservir
569
-	if (tester_url_absolue($src)) {
570
-		include_spip('inc/distant');
571
-		$fichier = copie_locale($src);
572
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
573
-	}
574
-	if (($p = strpos($src, '?')) !== false) {
575
-		$src = substr($src, 0, $p);
576
-	}
577
-
578
-	$srcsize = false;
579
-	if (isset($largeur_img[$src])) {
580
-		$srcWidth = $largeur_img[$src];
581
-	}
582
-	if (isset($hauteur_img[$src])) {
583
-		$srcHeight = $hauteur_img[$src];
584
-	}
585
-	if (!$srcWidth or !$srcHeight) {
586
-
587
-		if (file_exists($src)
588
-			and $srcsize = spip_getimagesize($src)
589
-		) {
590
-			if (!$srcWidth) {
591
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
592
-			}
593
-			if (!$srcHeight) {
594
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
595
-			}
596
-		}
597
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
598
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
599
-		elseif (@file_exists($f = "$src.src")
600
-			and lire_fichier($f, $valeurs)
601
-			and $valeurs = unserialize($valeurs)
602
-		) {
603
-			if (!$srcWidth) {
604
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
605
-			}
606
-			if (!$srcHeight) {
607
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
608
-			}
609
-		}
610
-	}
611
-
612
-	return array($srcHeight, $srcWidth);
554
+    static $largeur_img = array(), $hauteur_img = array();
555
+    $srcWidth = 0;
556
+    $srcHeight = 0;
557
+
558
+    $src = extraire_attribut($img, 'src');
559
+
560
+    if (!$src) {
561
+        $src = $img;
562
+    } else {
563
+        $srcWidth = extraire_attribut($img, 'width');
564
+        $srcHeight = extraire_attribut($img, 'height');
565
+    }
566
+
567
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
568
+    // la copie locale a toutes les chances d'etre la ou de resservir
569
+    if (tester_url_absolue($src)) {
570
+        include_spip('inc/distant');
571
+        $fichier = copie_locale($src);
572
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
573
+    }
574
+    if (($p = strpos($src, '?')) !== false) {
575
+        $src = substr($src, 0, $p);
576
+    }
577
+
578
+    $srcsize = false;
579
+    if (isset($largeur_img[$src])) {
580
+        $srcWidth = $largeur_img[$src];
581
+    }
582
+    if (isset($hauteur_img[$src])) {
583
+        $srcHeight = $hauteur_img[$src];
584
+    }
585
+    if (!$srcWidth or !$srcHeight) {
586
+
587
+        if (file_exists($src)
588
+            and $srcsize = spip_getimagesize($src)
589
+        ) {
590
+            if (!$srcWidth) {
591
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
592
+            }
593
+            if (!$srcHeight) {
594
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
595
+            }
596
+        }
597
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
598
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
599
+        elseif (@file_exists($f = "$src.src")
600
+            and lire_fichier($f, $valeurs)
601
+            and $valeurs = unserialize($valeurs)
602
+        ) {
603
+            if (!$srcWidth) {
604
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
605
+            }
606
+            if (!$srcHeight) {
607
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
608
+            }
609
+        }
610
+    }
611
+
612
+    return array($srcHeight, $srcWidth);
613 613
 }
614 614
 
615 615
 
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
  *     Largeur en pixels, NULL ou 0 si aucune image.
628 628
  **/
629 629
 function largeur($img) {
630
-	if (!$img) {
631
-		return;
632
-	}
633
-	list($h, $l) = taille_image($img);
630
+    if (!$img) {
631
+        return;
632
+    }
633
+    list($h, $l) = taille_image($img);
634 634
 
635
-	return $l;
635
+    return $l;
636 636
 }
637 637
 
638 638
 /**
@@ -649,12 +649,12 @@  discard block
 block discarded – undo
649 649
  *     Hauteur en pixels, NULL ou 0 si aucune image.
650 650
  **/
651 651
 function hauteur($img) {
652
-	if (!$img) {
653
-		return;
654
-	}
655
-	list($h, $l) = taille_image($img);
652
+    if (!$img) {
653
+        return;
654
+    }
655
+    list($h, $l) = taille_image($img);
656 656
 
657
-	return $h;
657
+    return $h;
658 658
 }
659 659
 
660 660
 
@@ -674,11 +674,11 @@  discard block
 block discarded – undo
674 674
  * @return string
675 675
  **/
676 676
 function corriger_entites_html($texte) {
677
-	if (strpos($texte, '&amp;') === false) {
678
-		return $texte;
679
-	}
677
+    if (strpos($texte, '&amp;') === false) {
678
+        return $texte;
679
+    }
680 680
 
681
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
681
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
682 682
 }
683 683
 
684 684
 /**
@@ -693,11 +693,11 @@  discard block
 block discarded – undo
693 693
  * @return string
694 694
  **/
695 695
 function corriger_toutes_entites_html($texte) {
696
-	if (strpos($texte, '&amp;') === false) {
697
-		return $texte;
698
-	}
696
+    if (strpos($texte, '&amp;') === false) {
697
+        return $texte;
698
+    }
699 699
 
700
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
700
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
701 701
 }
702 702
 
703 703
 /**
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
  * @return string
708 708
  **/
709 709
 function proteger_amp($texte) {
710
-	return str_replace('&', '&amp;', $texte);
710
+    return str_replace('&', '&amp;', $texte);
711 711
 }
712 712
 
713 713
 
@@ -738,20 +738,20 @@  discard block
 block discarded – undo
738 738
  * @return mixed|string
739 739
  */
740 740
 function entites_html($texte, $tout = false, $quote = true) {
741
-	if (!is_string($texte) or !$texte
742
-		or strpbrk($texte, "&\"'<>") == false
743
-	) {
744
-		return $texte;
745
-	}
746
-	include_spip('inc/texte');
747
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
748
-	$flags |= ENT_HTML401;
749
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
750
-	if ($tout) {
751
-		return corriger_toutes_entites_html($texte);
752
-	} else {
753
-		return corriger_entites_html($texte);
754
-	}
741
+    if (!is_string($texte) or !$texte
742
+        or strpbrk($texte, "&\"'<>") == false
743
+    ) {
744
+        return $texte;
745
+    }
746
+    include_spip('inc/texte');
747
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
748
+    $flags |= ENT_HTML401;
749
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
750
+    if ($tout) {
751
+        return corriger_toutes_entites_html($texte);
752
+    } else {
753
+        return corriger_entites_html($texte);
754
+    }
755 755
 }
756 756
 
757 757
 /**
@@ -770,37 +770,37 @@  discard block
 block discarded – undo
770 770
  *     Texte converti
771 771
  **/
772 772
 function filtrer_entites($texte) {
773
-	if (strpos($texte, '&') === false) {
774
-		return $texte;
775
-	}
776
-	// filtrer
777
-	$texte = html2unicode($texte);
778
-	// remettre le tout dans le charset cible
779
-	$texte = unicode2charset($texte);
780
-	// cas particulier des " et ' qu'il faut filtrer aussi
781
-	// (on le faisait deja avec un &quot;)
782
-	if (strpos($texte, "&#") !== false) {
783
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
784
-	}
773
+    if (strpos($texte, '&') === false) {
774
+        return $texte;
775
+    }
776
+    // filtrer
777
+    $texte = html2unicode($texte);
778
+    // remettre le tout dans le charset cible
779
+    $texte = unicode2charset($texte);
780
+    // cas particulier des " et ' qu'il faut filtrer aussi
781
+    // (on le faisait deja avec un &quot;)
782
+    if (strpos($texte, "&#") !== false) {
783
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
784
+    }
785 785
 
786
-	return $texte;
786
+    return $texte;
787 787
 }
788 788
 
789 789
 
790 790
 if (!function_exists('filtre_filtrer_entites_dist')) {
791
-	/**
792
-	 * Version sécurisée de filtrer_entites
793
-	 * 
794
-	 * @uses interdire_scripts()
795
-	 * @uses filtrer_entites()
796
-	 * 
797
-	 * @param string $t
798
-	 * @return string
799
-	 */
800
-	function filtre_filtrer_entites_dist($t) {
801
-		include_spip('inc/texte');
802
-		return interdire_scripts(filtrer_entites($t));
803
-	}
791
+    /**
792
+     * Version sécurisée de filtrer_entites
793
+     * 
794
+     * @uses interdire_scripts()
795
+     * @uses filtrer_entites()
796
+     * 
797
+     * @param string $t
798
+     * @return string
799
+     */
800
+    function filtre_filtrer_entites_dist($t) {
801
+        include_spip('inc/texte');
802
+        return interdire_scripts(filtrer_entites($t));
803
+    }
804 804
 }
805 805
 
806 806
 
@@ -815,18 +815,18 @@  discard block
 block discarded – undo
815 815
  * @return string|array
816 816
  **/
817 817
 function supprimer_caracteres_illegaux($texte) {
818
-	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";
819
-	static $to = null;
818
+    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";
819
+    static $to = null;
820 820
 
821
-	if (is_array($texte)) {
822
-		return array_map('supprimer_caracteres_illegaux', $texte);
823
-	}
821
+    if (is_array($texte)) {
822
+        return array_map('supprimer_caracteres_illegaux', $texte);
823
+    }
824 824
 
825
-	if (!$to) {
826
-		$to = str_repeat('-', strlen($from));
827
-	}
825
+    if (!$to) {
826
+        $to = str_repeat('-', strlen($from));
827
+    }
828 828
 
829
-	return strtr($texte, $from, $to);
829
+    return strtr($texte, $from, $to);
830 830
 }
831 831
 
832 832
 /**
@@ -838,10 +838,10 @@  discard block
 block discarded – undo
838 838
  * @return string|array
839 839
  **/
840 840
 function corriger_caracteres($texte) {
841
-	$texte = corriger_caracteres_windows($texte);
842
-	$texte = supprimer_caracteres_illegaux($texte);
841
+    $texte = corriger_caracteres_windows($texte);
842
+    $texte = supprimer_caracteres_illegaux($texte);
843 843
 
844
-	return $texte;
844
+    return $texte;
845 845
 }
846 846
 
847 847
 /**
@@ -859,40 +859,40 @@  discard block
 block discarded – undo
859 859
  */
860 860
 function texte_backend($texte) {
861 861
 
862
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
862
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
863 863
 
864
-	// si on a des liens ou des images, les passer en absolu
865
-	$texte = liens_absolus($texte);
864
+    // si on a des liens ou des images, les passer en absolu
865
+    $texte = liens_absolus($texte);
866 866
 
867
-	// echapper les tags &gt; &lt;
868
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
867
+    // echapper les tags &gt; &lt;
868
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
869 869
 
870
-	// importer les &eacute;
871
-	$texte = filtrer_entites($texte);
870
+    // importer les &eacute;
871
+    $texte = filtrer_entites($texte);
872 872
 
873
-	// " -> &quot; et tout ce genre de choses
874
-	$u = $GLOBALS['meta']['pcre_u'];
875
-	$texte = str_replace("&nbsp;", " ", $texte);
876
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
877
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
878
-	$texte = entites_html($texte, false, false);
879
-	// mais bien echapper les double quotes !
880
-	$texte = str_replace('"', '&#034;', $texte);
873
+    // " -> &quot; et tout ce genre de choses
874
+    $u = $GLOBALS['meta']['pcre_u'];
875
+    $texte = str_replace("&nbsp;", " ", $texte);
876
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
877
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
878
+    $texte = entites_html($texte, false, false);
879
+    // mais bien echapper les double quotes !
880
+    $texte = str_replace('"', '&#034;', $texte);
881 881
 
882
-	// verifier le charset
883
-	$texte = charset2unicode($texte);
882
+    // verifier le charset
883
+    $texte = charset2unicode($texte);
884 884
 
885
-	// Caracteres problematiques en iso-latin 1
886
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
887
-		$texte = str_replace(chr(156), '&#156;', $texte);
888
-		$texte = str_replace(chr(140), '&#140;', $texte);
889
-		$texte = str_replace(chr(159), '&#159;', $texte);
890
-	}
885
+    // Caracteres problematiques en iso-latin 1
886
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
887
+        $texte = str_replace(chr(156), '&#156;', $texte);
888
+        $texte = str_replace(chr(140), '&#140;', $texte);
889
+        $texte = str_replace(chr(159), '&#159;', $texte);
890
+    }
891 891
 
892
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
893
-	// et le caractere apostrophe alourdit les squelettes avec PHP
894
-	// ==> on les remplace par l'entite HTML
895
-	return str_replace($apostrophe, "'", $texte);
892
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
893
+    // et le caractere apostrophe alourdit les squelettes avec PHP
894
+    // ==> on les remplace par l'entite HTML
895
+    return str_replace($apostrophe, "'", $texte);
896 896
 }
897 897
 
898 898
 /**
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
  *     Texte encodé et quote pour XML
910 910
  */
911 911
 function texte_backendq($texte) {
912
-	return addslashes(texte_backend($texte));
912
+    return addslashes(texte_backend($texte));
913 913
 }
914 914
 
915 915
 
@@ -932,9 +932,9 @@  discard block
 block discarded – undo
932 932
  *     Numéro de titre, sinon chaîne vide
933 933
  **/
934 934
 function supprimer_numero($texte) {
935
-	return preg_replace(
936
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
937
-		"", $texte);
935
+    return preg_replace(
936
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
937
+        "", $texte);
938 938
 }
939 939
 
940 940
 /**
@@ -957,13 +957,13 @@  discard block
 block discarded – undo
957 957
  *     Numéro de titre, sinon chaîne vide
958 958
  **/
959 959
 function recuperer_numero($texte) {
960
-	if (preg_match(
961
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
962
-		$texte, $regs)) {
963
-		return strval($regs[1]);
964
-	} else {
965
-		return '';
966
-	}
960
+    if (preg_match(
961
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
962
+        $texte, $regs)) {
963
+        return strval($regs[1]);
964
+    } else {
965
+        return '';
966
+    }
967 967
 }
968 968
 
969 969
 /**
@@ -990,13 +990,13 @@  discard block
 block discarded – undo
990 990
  *     Texte converti
991 991
  **/
992 992
 function supprimer_tags($texte, $rempl = "") {
993
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
994
-	// ne pas oublier un < final non ferme car coupe
995
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
996
-	// mais qui peut aussi etre un simple signe plus petit que
997
-	$texte = str_replace('<', '&lt;', $texte);
993
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
994
+    // ne pas oublier un < final non ferme car coupe
995
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
996
+    // mais qui peut aussi etre un simple signe plus petit que
997
+    $texte = str_replace('<', '&lt;', $texte);
998 998
 
999
-	return $texte;
999
+    return $texte;
1000 1000
 }
1001 1001
 
1002 1002
 /**
@@ -1019,9 +1019,9 @@  discard block
 block discarded – undo
1019 1019
  *     Texte converti
1020 1020
  **/
1021 1021
 function echapper_tags($texte, $rempl = "") {
1022
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1022
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1023 1023
 
1024
-	return $texte;
1024
+    return $texte;
1025 1025
 }
1026 1026
 
1027 1027
 /**
@@ -1042,18 +1042,18 @@  discard block
 block discarded – undo
1042 1042
  *     Texte converti
1043 1043
  **/
1044 1044
 function textebrut($texte) {
1045
-	$u = $GLOBALS['meta']['pcre_u'];
1046
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1047
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1048
-	$texte = preg_replace("/^\n+/", "", $texte);
1049
-	$texte = preg_replace("/\n+$/", "", $texte);
1050
-	$texte = preg_replace("/\n +/", "\n", $texte);
1051
-	$texte = supprimer_tags($texte);
1052
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1053
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1054
-	$texte = str_replace("&#8217;", "'", $texte);
1045
+    $u = $GLOBALS['meta']['pcre_u'];
1046
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1047
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1048
+    $texte = preg_replace("/^\n+/", "", $texte);
1049
+    $texte = preg_replace("/\n+$/", "", $texte);
1050
+    $texte = preg_replace("/\n +/", "\n", $texte);
1051
+    $texte = supprimer_tags($texte);
1052
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1053
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1054
+    $texte = str_replace("&#8217;", "'", $texte);
1055 1055
 
1056
-	return $texte;
1056
+    return $texte;
1057 1057
 }
1058 1058
 
1059 1059
 
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
  *     Texte avec liens ouvrants
1070 1070
  **/
1071 1071
 function liens_ouvrants($texte) {
1072
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1073
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1074
-		foreach ($liens[0] as $a) {
1075
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1076
-			$ablank = inserer_attribut($a, 'rel', $rel);
1077
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1078
-			$texte = str_replace($a, $ablank, $texte);
1079
-		}
1080
-	}
1072
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1073
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1074
+        foreach ($liens[0] as $a) {
1075
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1076
+            $ablank = inserer_attribut($a, 'rel', $rel);
1077
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1078
+            $texte = str_replace($a, $ablank, $texte);
1079
+        }
1080
+    }
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1089,22 +1089,22 @@  discard block
 block discarded – undo
1089 1089
  * @return string
1090 1090
  */
1091 1091
 function liens_nofollow($texte) {
1092
-	if (stripos($texte, "<a") === false) {
1093
-		return $texte;
1094
-	}
1092
+    if (stripos($texte, "<a") === false) {
1093
+        return $texte;
1094
+    }
1095 1095
 
1096
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1097
-		foreach ($regs[0] as $a) {
1098
-			$rel = extraire_attribut($a, "rel");
1099
-			if (strpos($rel, "nofollow") === false) {
1100
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1101
-				$anofollow = inserer_attribut($a, "rel", $rel);
1102
-				$texte = str_replace($a, $anofollow, $texte);
1103
-			}
1104
-		}
1105
-	}
1096
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1097
+        foreach ($regs[0] as $a) {
1098
+            $rel = extraire_attribut($a, "rel");
1099
+            if (strpos($rel, "nofollow") === false) {
1100
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1101
+                $anofollow = inserer_attribut($a, "rel", $rel);
1102
+                $texte = str_replace($a, $anofollow, $texte);
1103
+            }
1104
+        }
1105
+    }
1106 1106
 
1107
-	return $texte;
1107
+    return $texte;
1108 1108
 }
1109 1109
 
1110 1110
 /**
@@ -1123,12 +1123,12 @@  discard block
 block discarded – undo
1123 1123
  *     Texte sans paraghaphes
1124 1124
  **/
1125 1125
 function PtoBR($texte) {
1126
-	$u = $GLOBALS['meta']['pcre_u'];
1127
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1128
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1129
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1126
+    $u = $GLOBALS['meta']['pcre_u'];
1127
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1128
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1129
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1130 1130
 
1131
-	return $texte;
1131
+    return $texte;
1132 1132
 }
1133 1133
 
1134 1134
 
@@ -1152,14 +1152,14 @@  discard block
 block discarded – undo
1152 1152
  * @return string Texte encadré du style CSS
1153 1153
  */
1154 1154
 function lignes_longues($texte) {
1155
-	if (!strlen(trim($texte))) {
1156
-		return $texte;
1157
-	}
1158
-	include_spip('inc/texte');
1159
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1160
-		'div' : 'span';
1155
+    if (!strlen(trim($texte))) {
1156
+        return $texte;
1157
+    }
1158
+    include_spip('inc/texte');
1159
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1160
+        'div' : 'span';
1161 1161
 
1162
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1162
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1163 1163
 }
1164 1164
 
1165 1165
 /**
@@ -1178,30 +1178,30 @@  discard block
 block discarded – undo
1178 1178
  * @return string Texte en majuscule
1179 1179
  */
1180 1180
 function majuscules($texte) {
1181
-	if (!strlen($texte)) {
1182
-		return '';
1183
-	}
1181
+    if (!strlen($texte)) {
1182
+        return '';
1183
+    }
1184 1184
 
1185
-	// Cas du turc
1186
-	if ($GLOBALS['spip_lang'] == 'tr') {
1187
-		# remplacer hors des tags et des entites
1188
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1189
-			foreach ($regs as $n => $match) {
1190
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1191
-			}
1192
-		}
1185
+    // Cas du turc
1186
+    if ($GLOBALS['spip_lang'] == 'tr') {
1187
+        # remplacer hors des tags et des entites
1188
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1189
+            foreach ($regs as $n => $match) {
1190
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1191
+            }
1192
+        }
1193 1193
 
1194
-		$texte = str_replace('i', '&#304;', $texte);
1194
+        $texte = str_replace('i', '&#304;', $texte);
1195 1195
 
1196
-		if ($regs) {
1197
-			foreach ($regs as $n => $match) {
1198
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1199
-			}
1200
-		}
1201
-	}
1196
+        if ($regs) {
1197
+            foreach ($regs as $n => $match) {
1198
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1199
+            }
1200
+        }
1201
+    }
1202 1202
 
1203
-	// Cas general
1204
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1203
+    // Cas general
1204
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1205 1205
 }
1206 1206
 
1207 1207
 /**
@@ -1219,29 +1219,29 @@  discard block
 block discarded – undo
1219 1219
  * @return string
1220 1220
  **/
1221 1221
 function taille_en_octets($taille) {
1222
-	if (!defined('_KILOBYTE')) {
1223
-		/**
1224
-		 * Définit le nombre d'octets dans un Kilobyte
1225
-		 *
1226
-		 * @var int
1227
-		 **/
1228
-		define('_KILOBYTE', 1024);
1229
-	}
1222
+    if (!defined('_KILOBYTE')) {
1223
+        /**
1224
+         * Définit le nombre d'octets dans un Kilobyte
1225
+         *
1226
+         * @var int
1227
+         **/
1228
+        define('_KILOBYTE', 1024);
1229
+    }
1230 1230
 
1231
-	if ($taille < 1) {
1232
-		return '';
1233
-	}
1234
-	if ($taille < _KILOBYTE) {
1235
-		$taille = _T('taille_octets', array('taille' => $taille));
1236
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1237
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1238
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1239
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1240
-	} else {
1241
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1242
-	}
1231
+    if ($taille < 1) {
1232
+        return '';
1233
+    }
1234
+    if ($taille < _KILOBYTE) {
1235
+        $taille = _T('taille_octets', array('taille' => $taille));
1236
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1237
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1238
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1239
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1240
+    } else {
1241
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1242
+    }
1243 1243
 
1244
-	return $taille;
1244
+    return $taille;
1245 1245
 }
1246 1246
 
1247 1247
 
@@ -1263,15 +1263,15 @@  discard block
 block discarded – undo
1263 1263
  *     Texte prêt pour être utilisé en attribut HTML
1264 1264
  **/
1265 1265
 function attribut_html($texte, $textebrut = true) {
1266
-	$u = $GLOBALS['meta']['pcre_u'];
1267
-	if ($textebrut) {
1268
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1269
-	}
1270
-	$texte = texte_backend($texte);
1271
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1266
+    $u = $GLOBALS['meta']['pcre_u'];
1267
+    if ($textebrut) {
1268
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1269
+    }
1270
+    $texte = texte_backend($texte);
1271
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1272 1272
 
1273
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1274
-		$texte);
1273
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1274
+        $texte);
1275 1275
 }
1276 1276
 
1277 1277
 
@@ -1291,12 +1291,12 @@  discard block
 block discarded – undo
1291 1291
  *     URL ou chaîne vide
1292 1292
  **/
1293 1293
 function vider_url($url, $entites = true) {
1294
-	# un message pour abs_url
1295
-	$GLOBALS['mode_abs_url'] = 'url';
1296
-	$url = trim($url);
1297
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1294
+    # un message pour abs_url
1295
+    $GLOBALS['mode_abs_url'] = 'url';
1296
+    $url = trim($url);
1297
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1298 1298
 
1299
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1299
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1300 1300
 }
1301 1301
 
1302 1302
 
@@ -1311,10 +1311,10 @@  discard block
 block discarded – undo
1311 1311
  * @return string Adresse email maquillée
1312 1312
  **/
1313 1313
 function antispam($texte) {
1314
-	include_spip('inc/acces');
1315
-	$masque = creer_pass_aleatoire(3);
1314
+    include_spip('inc/acces');
1315
+    $masque = creer_pass_aleatoire(3);
1316 1316
 
1317
-	return preg_replace("/@/", " $masque ", $texte);
1317
+    return preg_replace("/@/", " $masque ", $texte);
1318 1318
 }
1319 1319
 
1320 1320
 /**
@@ -1346,12 +1346,12 @@  discard block
 block discarded – undo
1346 1346
  *     True si on a le droit d'accès, false sinon.
1347 1347
  **/
1348 1348
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1349
-	include_spip('inc/acces');
1350
-	if ($op) {
1351
-		$dir .= " $op $args";
1352
-	}
1349
+    include_spip('inc/acces');
1350
+    if ($op) {
1351
+        $dir .= " $op $args";
1352
+    }
1353 1353
 
1354
-	return verifier_low_sec($id_auteur, $cle, $dir);
1354
+    return verifier_low_sec($id_auteur, $cle, $dir);
1355 1355
 }
1356 1356
 
1357 1357
 /**
@@ -1376,11 +1376,11 @@  discard block
 block discarded – undo
1376 1376
  *     Retourne $texte, sinon $sinon.
1377 1377
  **/
1378 1378
 function sinon($texte, $sinon = '') {
1379
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1380
-		return $texte;
1381
-	} else {
1382
-		return $sinon;
1383
-	}
1379
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1380
+        return $texte;
1381
+    } else {
1382
+        return $sinon;
1383
+    }
1384 1384
 }
1385 1385
 
1386 1386
 /**
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
  * @return mixed
1405 1405
  **/
1406 1406
 function choixsivide($a, $vide, $pasvide) {
1407
-	return $a ? $pasvide : $vide;
1407
+    return $a ? $pasvide : $vide;
1408 1408
 }
1409 1409
 
1410 1410
 /**
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
  * @return mixed
1429 1429
  **/
1430 1430
 function choixsiegal($a1, $a2, $v, $f) {
1431
-	return ($a1 == $a2) ? $v : $f;
1431
+    return ($a1 == $a2) ? $v : $f;
1432 1432
 }
1433 1433
 
1434 1434
 //
@@ -1447,13 +1447,13 @@  discard block
 block discarded – undo
1447 1447
  * @return string
1448 1448
  **/
1449 1449
 function filtrer_ical($texte) {
1450
-	#include_spip('inc/charsets');
1451
-	$texte = html2unicode($texte);
1452
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1453
-	$texte = preg_replace("/\n/", " ", $texte);
1454
-	$texte = preg_replace("/,/", "\,", $texte);
1450
+    #include_spip('inc/charsets');
1451
+    $texte = html2unicode($texte);
1452
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1453
+    $texte = preg_replace("/\n/", " ", $texte);
1454
+    $texte = preg_replace("/,/", "\,", $texte);
1455 1455
 
1456
-	return $texte;
1456
+    return $texte;
1457 1457
 }
1458 1458
 
1459 1459
 
@@ -1478,53 +1478,53 @@  discard block
 block discarded – undo
1478 1478
  * @return string
1479 1479
  **/
1480 1480
 function post_autobr($texte, $delim = "\n_ ") {
1481
-	if (!function_exists('echappe_html')) {
1482
-		include_spip('inc/texte_mini');
1483
-	}
1484
-	$texte = str_replace("\r\n", "\r", $texte);
1485
-	$texte = str_replace("\r", "\n", $texte);
1486
-
1487
-	if (preg_match(",\n+$,", $texte, $fin)) {
1488
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1489
-	} else {
1490
-		$fin = '';
1491
-	}
1492
-
1493
-	$texte = echappe_html($texte, '', true);
1494
-
1495
-	// echapper les modeles
1496
-	if (strpos($texte, "<") !== false) {
1497
-		include_spip('inc/lien');
1498
-		if (defined('_PREG_MODELE')) {
1499
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1500
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1501
-		}
1502
-	}
1503
-
1504
-	$debut = '';
1505
-	$suite = $texte;
1506
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1507
-		$debut .= substr($suite, 0, $t - 1);
1508
-		$suite = substr($suite, $t);
1509
-		$car = substr($suite, 0, 1);
1510
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1511
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1512
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1513
-		) {
1514
-			$debut .= $delim;
1515
-		} else {
1516
-			$debut .= "\n";
1517
-		}
1518
-		if (preg_match(",^\n+,", $suite, $regs)) {
1519
-			$debut .= $regs[0];
1520
-			$suite = substr($suite, strlen($regs[0]));
1521
-		}
1522
-	}
1523
-	$texte = $debut . $suite;
1524
-
1525
-	$texte = echappe_retour($texte);
1526
-
1527
-	return $texte . $fin;
1481
+    if (!function_exists('echappe_html')) {
1482
+        include_spip('inc/texte_mini');
1483
+    }
1484
+    $texte = str_replace("\r\n", "\r", $texte);
1485
+    $texte = str_replace("\r", "\n", $texte);
1486
+
1487
+    if (preg_match(",\n+$,", $texte, $fin)) {
1488
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1489
+    } else {
1490
+        $fin = '';
1491
+    }
1492
+
1493
+    $texte = echappe_html($texte, '', true);
1494
+
1495
+    // echapper les modeles
1496
+    if (strpos($texte, "<") !== false) {
1497
+        include_spip('inc/lien');
1498
+        if (defined('_PREG_MODELE')) {
1499
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1500
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1501
+        }
1502
+    }
1503
+
1504
+    $debut = '';
1505
+    $suite = $texte;
1506
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1507
+        $debut .= substr($suite, 0, $t - 1);
1508
+        $suite = substr($suite, $t);
1509
+        $car = substr($suite, 0, 1);
1510
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1511
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1512
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1513
+        ) {
1514
+            $debut .= $delim;
1515
+        } else {
1516
+            $debut .= "\n";
1517
+        }
1518
+        if (preg_match(",^\n+,", $suite, $regs)) {
1519
+            $debut .= $regs[0];
1520
+            $suite = substr($suite, strlen($regs[0]));
1521
+        }
1522
+    }
1523
+    $texte = $debut . $suite;
1524
+
1525
+    $texte = echappe_retour($texte);
1526
+
1527
+    return $texte . $fin;
1528 1528
 }
1529 1529
 
1530 1530
 
@@ -1565,46 +1565,46 @@  discard block
 block discarded – undo
1565 1565
  * @return string
1566 1566
  **/
1567 1567
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1568
-	static $traduire = false;
1569
-	if ($letexte
1570
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1571
-	) {
1572
-		if (!$traduire) {
1573
-			$traduire = charger_fonction('traduire', 'inc');
1574
-			include_spip('inc/lang');
1575
-		}
1576
-		if (!$lang) {
1577
-			$lang = $GLOBALS['spip_lang'];
1578
-		}
1579
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1580
-		if (is_bool($options)) {
1581
-			$options = array('echappe_span' => $options);
1582
-		}
1583
-		if (!isset($options['echappe_span'])) {
1584
-			$options = array_merge($options, array('echappe_span' => false));
1585
-		}
1586
-
1587
-		foreach ($regs as $reg) {
1588
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1589
-			$desc = $traduire($cle, $lang, true);
1590
-			$l = $desc->langue;
1591
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1592
-			if (strlen($desc->texte)) {
1593
-				$trad = code_echappement($desc->texte, 'idiome', false);
1594
-				if ($l !== $lang) {
1595
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1596
-				}
1597
-				if (lang_dir($l) !== lang_dir($lang)) {
1598
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1599
-				}
1600
-				if (!$options['echappe_span']) {
1601
-					$trad = echappe_retour($trad, 'idiome');
1602
-				}
1603
-				$letexte = str_replace($reg[0], $trad, $letexte);
1604
-			}
1605
-		}
1606
-	}
1607
-	return $letexte;
1568
+    static $traduire = false;
1569
+    if ($letexte
1570
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1571
+    ) {
1572
+        if (!$traduire) {
1573
+            $traduire = charger_fonction('traduire', 'inc');
1574
+            include_spip('inc/lang');
1575
+        }
1576
+        if (!$lang) {
1577
+            $lang = $GLOBALS['spip_lang'];
1578
+        }
1579
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1580
+        if (is_bool($options)) {
1581
+            $options = array('echappe_span' => $options);
1582
+        }
1583
+        if (!isset($options['echappe_span'])) {
1584
+            $options = array_merge($options, array('echappe_span' => false));
1585
+        }
1586
+
1587
+        foreach ($regs as $reg) {
1588
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1589
+            $desc = $traduire($cle, $lang, true);
1590
+            $l = $desc->langue;
1591
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1592
+            if (strlen($desc->texte)) {
1593
+                $trad = code_echappement($desc->texte, 'idiome', false);
1594
+                if ($l !== $lang) {
1595
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1596
+                }
1597
+                if (lang_dir($l) !== lang_dir($lang)) {
1598
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1599
+                }
1600
+                if (!$options['echappe_span']) {
1601
+                    $trad = echappe_retour($trad, 'idiome');
1602
+                }
1603
+                $letexte = str_replace($reg[0], $trad, $letexte);
1604
+            }
1605
+        }
1606
+    }
1607
+    return $letexte;
1608 1608
 }
1609 1609
 
1610 1610
 /**
@@ -1656,64 +1656,64 @@  discard block
 block discarded – undo
1656 1656
  **/
1657 1657
 function extraire_multi($letexte, $lang = null, $options = array()) {
1658 1658
 
1659
-	if ($letexte
1660
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1661
-	) {
1662
-		if (!$lang) {
1663
-			$lang = $GLOBALS['spip_lang'];
1664
-		}
1665
-
1666
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
-		if (is_bool($options)) {
1668
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1669
-		}
1670
-		if (!isset($options['echappe_span'])) {
1671
-			$options = array_merge($options, array('echappe_span' => false));
1672
-		}
1673
-		if (!isset($options['lang_defaut'])) {
1674
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1675
-		}
1676
-
1677
-		include_spip('inc/lang');
1678
-		foreach ($regs as $reg) {
1679
-			// chercher la version de la langue courante
1680
-			$trads = extraire_trads($reg[1]);
1681
-			if ($l = approcher_langue($trads, $lang)) {
1682
-				$trad = $trads[$l];
1683
-			} else {
1684
-				if ($options['lang_defaut'] == 'aucune') {
1685
-					$trad = '';
1686
-				} else {
1687
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1688
-					// ou la premiere dispo
1689
-					// mais typographier le texte selon les regles de celle-ci
1690
-					// Attention aux blocs multi sur plusieurs lignes
1691
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1692
-						$l = key($trads);
1693
-					}
1694
-					$trad = $trads[$l];
1695
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1696
-					$trad = $typographie($trad);
1697
-					// Tester si on echappe en span ou en div
1698
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1699
-					include_spip('inc/texte');
1700
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1701
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1702
-					$trad = code_echappement($trad, 'multi', false, $mode);
1703
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1704
-					if (lang_dir($l) !== lang_dir($lang)) {
1705
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1706
-					}
1707
-					if (!$options['echappe_span']) {
1708
-						$trad = echappe_retour($trad, 'multi');
1709
-					}
1710
-				}
1711
-			}
1712
-			$letexte = str_replace($reg[0], $trad, $letexte);
1713
-		}
1714
-	}
1715
-
1716
-	return $letexte;
1659
+    if ($letexte
1660
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1661
+    ) {
1662
+        if (!$lang) {
1663
+            $lang = $GLOBALS['spip_lang'];
1664
+        }
1665
+
1666
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
+        if (is_bool($options)) {
1668
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1669
+        }
1670
+        if (!isset($options['echappe_span'])) {
1671
+            $options = array_merge($options, array('echappe_span' => false));
1672
+        }
1673
+        if (!isset($options['lang_defaut'])) {
1674
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1675
+        }
1676
+
1677
+        include_spip('inc/lang');
1678
+        foreach ($regs as $reg) {
1679
+            // chercher la version de la langue courante
1680
+            $trads = extraire_trads($reg[1]);
1681
+            if ($l = approcher_langue($trads, $lang)) {
1682
+                $trad = $trads[$l];
1683
+            } else {
1684
+                if ($options['lang_defaut'] == 'aucune') {
1685
+                    $trad = '';
1686
+                } else {
1687
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1688
+                    // ou la premiere dispo
1689
+                    // mais typographier le texte selon les regles de celle-ci
1690
+                    // Attention aux blocs multi sur plusieurs lignes
1691
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1692
+                        $l = key($trads);
1693
+                    }
1694
+                    $trad = $trads[$l];
1695
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1696
+                    $trad = $typographie($trad);
1697
+                    // Tester si on echappe en span ou en div
1698
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1699
+                    include_spip('inc/texte');
1700
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1701
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1702
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1703
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1704
+                    if (lang_dir($l) !== lang_dir($lang)) {
1705
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1706
+                    }
1707
+                    if (!$options['echappe_span']) {
1708
+                        $trad = echappe_retour($trad, 'multi');
1709
+                    }
1710
+                }
1711
+            }
1712
+            $letexte = str_replace($reg[0], $trad, $letexte);
1713
+        }
1714
+    }
1715
+
1716
+    return $letexte;
1717 1717
 }
1718 1718
 
1719 1719
 /**
@@ -1729,20 +1729,20 @@  discard block
 block discarded – undo
1729 1729
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1730 1730
  **/
1731 1731
 function extraire_trads($bloc) {
1732
-	$lang = '';
1732
+    $lang = '';
1733 1733
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1734 1734
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1735
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1736
-		$texte = trim($regs[1]);
1737
-		if ($texte or $lang) {
1738
-			$trads[$lang] = $texte;
1739
-		}
1740
-		$bloc = substr($bloc, strlen($regs[0]));
1741
-		$lang = $regs[2];
1742
-	}
1743
-	$trads[$lang] = $bloc;
1735
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1736
+        $texte = trim($regs[1]);
1737
+        if ($texte or $lang) {
1738
+            $trads[$lang] = $texte;
1739
+        }
1740
+        $bloc = substr($bloc, strlen($regs[0]));
1741
+        $lang = $regs[2];
1742
+    }
1743
+    $trads[$lang] = $bloc;
1744 1744
 
1745
-	return $trads;
1745
+    return $trads;
1746 1746
 }
1747 1747
 
1748 1748
 
@@ -1753,7 +1753,7 @@  discard block
 block discarded – undo
1753 1753
  * @return string L'initiale en majuscule
1754 1754
  */
1755 1755
 function filtre_initiale($nom) {
1756
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1756
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1757 1757
 }
1758 1758
 
1759 1759
 
@@ -1798,33 +1798,33 @@  discard block
 block discarded – undo
1798 1798
  *      - null (interne) : si on empile
1799 1799
  **/
1800 1800
 function unique($donnee, $famille = '', $cpt = false) {
1801
-	static $mem = array();
1802
-	// permettre de vider la pile et de la restaurer
1803
-	// pour le calcul de introduction...
1804
-	if ($famille == '_spip_raz_') {
1805
-		$tmp = $mem;
1806
-		$mem = array();
1807
-
1808
-		return $tmp;
1809
-	} elseif ($famille == '_spip_set_') {
1810
-		$mem = $donnee;
1811
-
1812
-		return;
1813
-	}
1814
-	// eviter une notice
1815
-	if (!isset($mem[$famille])) {
1816
-		$mem[$famille] = array();
1817
-	}
1818
-	if ($cpt) {
1819
-		return count($mem[$famille]);
1820
-	}
1821
-	// eviter une notice
1822
-	if (!isset($mem[$famille][$donnee])) {
1823
-		$mem[$famille][$donnee] = 0;
1824
-	}
1825
-	if (!($mem[$famille][$donnee]++)) {
1826
-		return $donnee;
1827
-	}
1801
+    static $mem = array();
1802
+    // permettre de vider la pile et de la restaurer
1803
+    // pour le calcul de introduction...
1804
+    if ($famille == '_spip_raz_') {
1805
+        $tmp = $mem;
1806
+        $mem = array();
1807
+
1808
+        return $tmp;
1809
+    } elseif ($famille == '_spip_set_') {
1810
+        $mem = $donnee;
1811
+
1812
+        return;
1813
+    }
1814
+    // eviter une notice
1815
+    if (!isset($mem[$famille])) {
1816
+        $mem[$famille] = array();
1817
+    }
1818
+    if ($cpt) {
1819
+        return count($mem[$famille]);
1820
+    }
1821
+    // eviter une notice
1822
+    if (!isset($mem[$famille][$donnee])) {
1823
+        $mem[$famille][$donnee] = 0;
1824
+    }
1825
+    if (!($mem[$famille][$donnee]++)) {
1826
+        return $donnee;
1827
+    }
1828 1828
 }
1829 1829
 
1830 1830
 
@@ -1852,18 +1852,18 @@  discard block
 block discarded – undo
1852 1852
  *     Une des valeurs en fonction du compteur.
1853 1853
  **/
1854 1854
 function alterner($i) {
1855
-	// recuperer les arguments (attention fonctions un peu space)
1856
-	$num = func_num_args();
1857
-	$args = func_get_args();
1855
+    // recuperer les arguments (attention fonctions un peu space)
1856
+    $num = func_num_args();
1857
+    $args = func_get_args();
1858 1858
 
1859
-	if ($num == 2 && is_array($args[1])) {
1860
-		$args = $args[1];
1861
-		array_unshift($args, '');
1862
-		$num = count($args);
1863
-	}
1859
+    if ($num == 2 && is_array($args[1])) {
1860
+        $args = $args[1];
1861
+        array_unshift($args, '');
1862
+        $num = count($args);
1863
+    }
1864 1864
 
1865
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1866
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1865
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1866
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1867 1867
 }
1868 1868
 
1869 1869
 
@@ -1888,46 +1888,46 @@  discard block
 block discarded – undo
1888 1888
  *     - Tableau complet (si 2e argument)
1889 1889
  **/
1890 1890
 function extraire_attribut($balise, $attribut, $complet = false) {
1891
-	if (is_array($balise)) {
1892
-		array_walk(
1893
-			$balise,
1894
-			function(&$a, $key, $t){
1895
-				$a = extraire_attribut($a, $t);
1896
-			},
1897
-			$attribut
1898
-		);
1899
-
1900
-		return $balise;
1901
-	}
1902
-	if (preg_match(
1903
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1904
-		. $attribut
1905
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1906
-
1907
-		$balise, $r)) {
1908
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1909
-			$r[4] = substr($r[3], 1, -1);
1910
-			$r[3] = $r[3][0];
1911
-		} elseif ($r[3] !== '') {
1912
-			$r[4] = $r[3];
1913
-			$r[3] = '';
1914
-		} else {
1915
-			$r[4] = trim($r[2]);
1916
-		}
1917
-		$att = $r[4];
1918
-		if (strpos($att, "&#") !== false) {
1919
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1920
-		}
1921
-		$att = filtrer_entites($att);
1922
-	} else {
1923
-		$att = null;
1924
-	}
1925
-
1926
-	if ($complet) {
1927
-		return array($att, $r);
1928
-	} else {
1929
-		return $att;
1930
-	}
1891
+    if (is_array($balise)) {
1892
+        array_walk(
1893
+            $balise,
1894
+            function(&$a, $key, $t){
1895
+                $a = extraire_attribut($a, $t);
1896
+            },
1897
+            $attribut
1898
+        );
1899
+
1900
+        return $balise;
1901
+    }
1902
+    if (preg_match(
1903
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1904
+        . $attribut
1905
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1906
+
1907
+        $balise, $r)) {
1908
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1909
+            $r[4] = substr($r[3], 1, -1);
1910
+            $r[3] = $r[3][0];
1911
+        } elseif ($r[3] !== '') {
1912
+            $r[4] = $r[3];
1913
+            $r[3] = '';
1914
+        } else {
1915
+            $r[4] = trim($r[2]);
1916
+        }
1917
+        $att = $r[4];
1918
+        if (strpos($att, "&#") !== false) {
1919
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1920
+        }
1921
+        $att = filtrer_entites($att);
1922
+    } else {
1923
+        $att = null;
1924
+    }
1925
+
1926
+    if ($complet) {
1927
+        return array($att, $r);
1928
+    } else {
1929
+        return $att;
1930
+    }
1931 1931
 }
1932 1932
 
1933 1933
 /**
@@ -1959,37 +1959,37 @@  discard block
 block discarded – undo
1959 1959
  *     Code html modifié
1960 1960
  **/
1961 1961
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1962
-	// preparer l'attribut
1963
-	// supprimer les &nbsp; etc mais pas les balises html
1964
-	// qui ont un sens dans un attribut value d'un input
1965
-	if ($proteger) {
1966
-		$val = attribut_html($val, false);
1967
-	}
1968
-
1969
-	// echapper les ' pour eviter tout bug
1970
-	$val = str_replace("'", "&#039;", $val);
1971
-	if ($vider and strlen($val) == 0) {
1972
-		$insert = '';
1973
-	} else {
1974
-		$insert = " $attribut='$val'";
1975
-	}
1976
-
1977
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1978
-
1979
-	if ($old !== null) {
1980
-		// Remplacer l'ancien attribut du meme nom
1981
-		$balise = $r[1] . $insert . $r[5];
1982
-	} else {
1983
-		// preferer une balise " />" (comme <img />)
1984
-		if (preg_match(',/>,', $balise)) {
1985
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1986
-		} // sinon une balise <a ...> ... </a>
1987
-		else {
1988
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1989
-		}
1990
-	}
1991
-
1992
-	return $balise;
1962
+    // preparer l'attribut
1963
+    // supprimer les &nbsp; etc mais pas les balises html
1964
+    // qui ont un sens dans un attribut value d'un input
1965
+    if ($proteger) {
1966
+        $val = attribut_html($val, false);
1967
+    }
1968
+
1969
+    // echapper les ' pour eviter tout bug
1970
+    $val = str_replace("'", "&#039;", $val);
1971
+    if ($vider and strlen($val) == 0) {
1972
+        $insert = '';
1973
+    } else {
1974
+        $insert = " $attribut='$val'";
1975
+    }
1976
+
1977
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1978
+
1979
+    if ($old !== null) {
1980
+        // Remplacer l'ancien attribut du meme nom
1981
+        $balise = $r[1] . $insert . $r[5];
1982
+    } else {
1983
+        // preferer une balise " />" (comme <img />)
1984
+        if (preg_match(',/>,', $balise)) {
1985
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1986
+        } // sinon une balise <a ...> ... </a>
1987
+        else {
1988
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1989
+        }
1990
+    }
1991
+
1992
+    return $balise;
1993 1993
 }
1994 1994
 
1995 1995
 /**
@@ -2007,7 +2007,7 @@  discard block
 block discarded – undo
2007 2007
  * @return string Code HTML sans l'attribut
2008 2008
  **/
2009 2009
 function vider_attribut($balise, $attribut) {
2010
-	return inserer_attribut($balise, $attribut, '', false, true);
2010
+    return inserer_attribut($balise, $attribut, '', false, true);
2011 2011
 }
2012 2012
 
2013 2013
 
@@ -2019,9 +2019,9 @@  discard block
 block discarded – undo
2019 2019
  * @return string
2020 2020
  */
2021 2021
 function tester_config($id, $mode = '') {
2022
-	include_spip('action/inscrire_auteur');
2022
+    include_spip('action/inscrire_auteur');
2023 2023
 
2024
-	return tester_statut_inscription($mode, $id);
2024
+    return tester_statut_inscription($mode, $id);
2025 2025
 }
2026 2026
 
2027 2027
 //
@@ -2046,7 +2046,7 @@  discard block
 block discarded – undo
2046 2046
  * @return int $a+$b
2047 2047
  **/
2048 2048
 function plus($a, $b) {
2049
-	return $a + $b;
2049
+    return $a + $b;
2050 2050
 }
2051 2051
 function strplus($a, $b) {return strize('plus', $a, $b);}
2052 2052
 /**
@@ -2065,7 +2065,7 @@  discard block
 block discarded – undo
2065 2065
  * @return int $a-$b
2066 2066
  **/
2067 2067
 function moins($a, $b) {
2068
-	return $a - $b;
2068
+    return $a - $b;
2069 2069
 }
2070 2070
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2071 2071
 
@@ -2086,7 +2086,7 @@  discard block
 block discarded – undo
2086 2086
  * @return int $a*$b
2087 2087
  **/
2088 2088
 function mult($a, $b) {
2089
-	return $a * $b;
2089
+    return $a * $b;
2090 2090
 }
2091 2091
 function strmult($a, $b) {return strize('mult', $a, $b);}
2092 2092
 
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
  * @return int $a/$b (ou 0 si $b est nul)
2108 2108
  **/
2109 2109
 function div($a, $b) {
2110
-	return $b ? $a / $b : 0;
2110
+    return $b ? $a / $b : 0;
2111 2111
 }
2112 2112
 function strdiv($a, $b) {return strize('div', $a, $b);}
2113 2113
 
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
  * @return int ($nb % $mod) + $add
2130 2130
  **/
2131 2131
 function modulo($nb, $mod, $add = 0) {
2132
-	return ($mod ? $nb % $mod : 0) + $add;
2132
+    return ($mod ? $nb % $mod : 0) + $add;
2133 2133
 }
2134 2134
 
2135 2135
 
@@ -2144,24 +2144,24 @@  discard block
 block discarded – undo
2144 2144
  *      - true sinon
2145 2145
  **/
2146 2146
 function nom_acceptable($nom) {
2147
-	if (!is_string($nom)) {
2148
-		return false;
2149
-	}
2150
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2151
-		define('_TAGS_NOM_AUTEUR', '');
2152
-	}
2153
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2154
-	foreach ($tags_acceptes as $tag) {
2155
-		if (strlen($tag)) {
2156
-			$remp1[] = '<' . trim($tag) . '>';
2157
-			$remp1[] = '</' . trim($tag) . '>';
2158
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2159
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2160
-		}
2161
-	}
2162
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2147
+    if (!is_string($nom)) {
2148
+        return false;
2149
+    }
2150
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2151
+        define('_TAGS_NOM_AUTEUR', '');
2152
+    }
2153
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2154
+    foreach ($tags_acceptes as $tag) {
2155
+        if (strlen($tag)) {
2156
+            $remp1[] = '<' . trim($tag) . '>';
2157
+            $remp1[] = '</' . trim($tag) . '>';
2158
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2159
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2160
+        }
2161
+    }
2162
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2163 2163
 
2164
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2164
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2165 2165
 }
2166 2166
 
2167 2167
 
@@ -2175,29 +2175,29 @@  discard block
 block discarded – undo
2175 2175
  *      - la normalisation de la dernière adresse donnée sinon
2176 2176
  **/
2177 2177
 function email_valide($adresses) {
2178
-	// eviter d'injecter n'importe quoi dans preg_match
2179
-	if (!is_string($adresses)) {
2180
-		return false;
2181
-	}
2178
+    // eviter d'injecter n'importe quoi dans preg_match
2179
+    if (!is_string($adresses)) {
2180
+        return false;
2181
+    }
2182 2182
 
2183
-	// Si c'est un spammeur autant arreter tout de suite
2184
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2185
-		spip_log("Tentative d'injection de mail : $adresses");
2183
+    // Si c'est un spammeur autant arreter tout de suite
2184
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2185
+        spip_log("Tentative d'injection de mail : $adresses");
2186 2186
 
2187
-		return false;
2188
-	}
2187
+        return false;
2188
+    }
2189 2189
 
2190
-	foreach (explode(',', $adresses) as $v) {
2191
-		// nettoyer certains formats
2192
-		// "Marie Toto <[email protected]>"
2193
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2194
-		// RFC 822
2195
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2196
-			return false;
2197
-		}
2198
-	}
2190
+    foreach (explode(',', $adresses) as $v) {
2191
+        // nettoyer certains formats
2192
+        // "Marie Toto <[email protected]>"
2193
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2194
+        // RFC 822
2195
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2196
+            return false;
2197
+        }
2198
+    }
2199 2199
 
2200
-	return $adresse;
2200
+    return $adresse;
2201 2201
 }
2202 2202
 
2203 2203
 /**
@@ -2211,20 +2211,20 @@  discard block
 block discarded – undo
2211 2211
  * @return string Texte
2212 2212
  **/
2213 2213
 function afficher_enclosures($tags) {
2214
-	$s = array();
2215
-	foreach (extraire_balises($tags, 'a') as $tag) {
2216
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2217
-			and $t = extraire_attribut($tag, 'href')
2218
-		) {
2219
-			$s[] = preg_replace(',>[^<]+</a>,S',
2220
-				'>'
2221
-				. http_img_pack('attachment-16.png', $t,
2222
-					'title="' . attribut_html($t) . '"')
2223
-				. '</a>', $tag);
2224
-		}
2225
-	}
2214
+    $s = array();
2215
+    foreach (extraire_balises($tags, 'a') as $tag) {
2216
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2217
+            and $t = extraire_attribut($tag, 'href')
2218
+        ) {
2219
+            $s[] = preg_replace(',>[^<]+</a>,S',
2220
+                '>'
2221
+                . http_img_pack('attachment-16.png', $t,
2222
+                    'title="' . attribut_html($t) . '"')
2223
+                . '</a>', $tag);
2224
+        }
2225
+    }
2226 2226
 
2227
-	return join('&nbsp;', $s);
2227
+    return join('&nbsp;', $s);
2228 2228
 }
2229 2229
 
2230 2230
 /**
@@ -2239,15 +2239,15 @@  discard block
 block discarded – undo
2239 2239
  * @return string Liens trouvés
2240 2240
  **/
2241 2241
 function afficher_tags($tags, $rels = 'tag,directory') {
2242
-	$s = array();
2243
-	foreach (extraire_balises($tags, 'a') as $tag) {
2244
-		$rel = extraire_attribut($tag, 'rel');
2245
-		if (strstr(",$rels,", ",$rel,")) {
2246
-			$s[] = $tag;
2247
-		}
2248
-	}
2242
+    $s = array();
2243
+    foreach (extraire_balises($tags, 'a') as $tag) {
2244
+        $rel = extraire_attribut($tag, 'rel');
2245
+        if (strstr(",$rels,", ",$rel,")) {
2246
+            $s[] = $tag;
2247
+        }
2248
+    }
2249 2249
 
2250
-	return join(', ', $s);
2250
+    return join(', ', $s);
2251 2251
 }
2252 2252
 
2253 2253
 
@@ -2269,21 +2269,21 @@  discard block
 block discarded – undo
2269 2269
  * @return string Tag HTML `<a>` avec microformat.
2270 2270
  **/
2271 2271
 function enclosure2microformat($e) {
2272
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2273
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2274
-	}
2275
-	$type = extraire_attribut($e, 'type');
2276
-	if (!$length = extraire_attribut($e, 'length')) {
2277
-		# <media:content : longeur dans fileSize. On tente.
2278
-		$length = extraire_attribut($e, 'fileSize');
2279
-	}
2280
-	$fichier = basename($url);
2272
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2273
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2274
+    }
2275
+    $type = extraire_attribut($e, 'type');
2276
+    if (!$length = extraire_attribut($e, 'length')) {
2277
+        # <media:content : longeur dans fileSize. On tente.
2278
+        $length = extraire_attribut($e, 'fileSize');
2279
+    }
2280
+    $fichier = basename($url);
2281 2281
 
2282
-	return '<a rel="enclosure"'
2283
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2284
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2285
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2286
-	. '>' . $fichier . '</a>';
2282
+    return '<a rel="enclosure"'
2283
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2284
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2285
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2286
+    . '>' . $fichier . '</a>';
2287 2287
 }
2288 2288
 
2289 2289
 /**
@@ -2301,24 +2301,24 @@  discard block
 block discarded – undo
2301 2301
  * @return string Tags RSS `<enclosure>`.
2302 2302
  **/
2303 2303
 function microformat2enclosure($tags) {
2304
-	$enclosures = array();
2305
-	foreach (extraire_balises($tags, 'a') as $e) {
2306
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2307
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2308
-			$type = extraire_attribut($e, 'type');
2309
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2310
-				$length = intval(extraire_attribut($e, 'length'));
2311
-			} # vieux data
2312
-			$fichier = basename($url);
2313
-			$enclosures[] = '<enclosure'
2314
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2315
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2316
-				. ($length ? ' length="' . $length . '"' : '')
2317
-				. ' />';
2318
-		}
2319
-	}
2304
+    $enclosures = array();
2305
+    foreach (extraire_balises($tags, 'a') as $e) {
2306
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2307
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2308
+            $type = extraire_attribut($e, 'type');
2309
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2310
+                $length = intval(extraire_attribut($e, 'length'));
2311
+            } # vieux data
2312
+            $fichier = basename($url);
2313
+            $enclosures[] = '<enclosure'
2314
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2315
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2316
+                . ($length ? ' length="' . $length . '"' : '')
2317
+                . ' />';
2318
+        }
2319
+    }
2320 2320
 
2321
-	return join("\n", $enclosures);
2321
+    return join("\n", $enclosures);
2322 2322
 }
2323 2323
 
2324 2324
 
@@ -2334,16 +2334,16 @@  discard block
 block discarded – undo
2334 2334
  * @return string Tags RSS Atom `<dc:subject>`.
2335 2335
  **/
2336 2336
 function tags2dcsubject($tags) {
2337
-	$subjects = '';
2338
-	foreach (extraire_balises($tags, 'a') as $e) {
2339
-		if (extraire_attribut($e, rel) == 'tag') {
2340
-			$subjects .= '<dc:subject>'
2341
-				. texte_backend(textebrut($e))
2342
-				. '</dc:subject>' . "\n";
2343
-		}
2344
-	}
2337
+    $subjects = '';
2338
+    foreach (extraire_balises($tags, 'a') as $e) {
2339
+        if (extraire_attribut($e, rel) == 'tag') {
2340
+            $subjects .= '<dc:subject>'
2341
+                . texte_backend(textebrut($e))
2342
+                . '</dc:subject>' . "\n";
2343
+        }
2344
+    }
2345 2345
 
2346
-	return $subjects;
2346
+    return $subjects;
2347 2347
 }
2348 2348
 
2349 2349
 /**
@@ -2372,23 +2372,23 @@  discard block
 block discarded – undo
2372 2372
  *     - Tableau de résultats, si tableau en entrée.
2373 2373
  **/
2374 2374
 function extraire_balise($texte, $tag = 'a') {
2375
-	if (is_array($texte)) {
2376
-		array_walk(
2377
-			$texte,
2378
-			function(&$a, $key, $t){
2379
-				$a = extraire_balise($a, $t);
2380
-			},
2381
-			$tag
2382
-		);
2375
+    if (is_array($texte)) {
2376
+        array_walk(
2377
+            $texte,
2378
+            function(&$a, $key, $t){
2379
+                $a = extraire_balise($a, $t);
2380
+            },
2381
+            $tag
2382
+        );
2383 2383
 
2384
-		return $texte;
2385
-	}
2384
+        return $texte;
2385
+    }
2386 2386
 
2387
-	if (preg_match(
2388
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2389
-		$texte, $regs)) {
2390
-		return $regs[0];
2391
-	}
2387
+    if (preg_match(
2388
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2389
+        $texte, $regs)) {
2390
+        return $regs[0];
2391
+    }
2392 2392
 }
2393 2393
 
2394 2394
 /**
@@ -2416,25 +2416,25 @@  discard block
 block discarded – undo
2416 2416
  *     - Tableau de résultats, si tableau en entrée.
2417 2417
  **/
2418 2418
 function extraire_balises($texte, $tag = 'a') {
2419
-	if (is_array($texte)) {
2420
-		array_walk(
2421
-			$texte,
2422
-			function(&$a, $key, $t){
2423
-				$a = extraire_balises($a, $t);
2424
-			},
2425
-			$tag
2426
-		);
2419
+    if (is_array($texte)) {
2420
+        array_walk(
2421
+            $texte,
2422
+            function(&$a, $key, $t){
2423
+                $a = extraire_balises($a, $t);
2424
+            },
2425
+            $tag
2426
+        );
2427 2427
 
2428
-		return $texte;
2429
-	}
2428
+        return $texte;
2429
+    }
2430 2430
 
2431
-	if (preg_match_all(
2432
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2433
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2434
-		return $regs[0];
2435
-	} else {
2436
-		return array();
2437
-	}
2431
+    if (preg_match_all(
2432
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2433
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2434
+        return $regs[0];
2435
+    } else {
2436
+        return array();
2437
+    }
2438 2438
 }
2439 2439
 
2440 2440
 /**
@@ -2463,11 +2463,11 @@  discard block
 block discarded – undo
2463 2463
  *     - `$def` si on n'a pas transmis de tableau
2464 2464
  **/
2465 2465
 function in_any($val, $vals, $def = '') {
2466
-	if (!is_array($vals) and $v = unserialize($vals)) {
2467
-		$vals = $v;
2468
-	}
2466
+    if (!is_array($vals) and $v = unserialize($vals)) {
2467
+        $vals = $v;
2468
+    }
2469 2469
 
2470
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2470
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2471 2471
 }
2472 2472
 
2473 2473
 
@@ -2488,12 +2488,12 @@  discard block
 block discarded – undo
2488 2488
  *     Résultat du calcul
2489 2489
  **/
2490 2490
 function valeur_numerique($expr) {
2491
-	$a = 0;
2492
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2493
-		eval("\$a = $expr;");
2494
-	}
2491
+    $a = 0;
2492
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2493
+        eval("\$a = $expr;");
2494
+    }
2495 2495
 
2496
-	return intval($a);
2496
+    return intval($a);
2497 2497
 }
2498 2498
 
2499 2499
 /**
@@ -2512,7 +2512,7 @@  discard block
 block discarded – undo
2512 2512
  *      Retourne `$a*$b/$c`
2513 2513
  **/
2514 2514
 function regledetrois($a, $b, $c) {
2515
-	return round($a * $b / $c);
2515
+    return round($a * $b / $c);
2516 2516
 }
2517 2517
 
2518 2518
 
@@ -2536,76 +2536,76 @@  discard block
 block discarded – undo
2536 2536
  **/
2537 2537
 function form_hidden($action) {
2538 2538
 
2539
-	$contexte = array();
2540
-	include_spip('inc/urls');
2541
-	if ($p = urls_decoder_url($action, '')
2542
-		and reset($p)
2543
-	) {
2544
-		$fond = array_shift($p);
2545
-		if ($fond != '404') {
2546
-			$contexte = array_shift($p);
2547
-			$contexte['page'] = $fond;
2548
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2549
-		}
2550
-	}
2551
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2552
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2553
-		unset($contexte['type']);
2554
-	}
2555
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2556
-		unset($contexte['type-page']);
2557
-	}
2558
-
2559
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2560
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2561
-	$values = array();
2562
-
2563
-	// d'abord avec celles de l'url
2564
-	if (false !== ($p = strpos($action, '?'))) {
2565
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2566
-			$c = explode('=', $c, 2);
2567
-			$var = array_shift($c);
2568
-			$val = array_shift($c);
2569
-			if ($var) {
2570
-				$val = rawurldecode($val);
2571
-				$var = rawurldecode($var); // decoder les [] eventuels
2572
-				if (preg_match(',\[\]$,S', $var)) {
2573
-					$values[] = array($var, $val);
2574
-				} else {
2575
-					if (!isset($values[$var])) {
2576
-						$values[$var] = array($var, $val);
2577
-					}
2578
-				}
2579
-			}
2580
-		}
2581
-	}
2582
-
2583
-	// ensuite avec celles du contexte, sans doublonner !
2584
-	foreach ($contexte as $var => $val) {
2585
-		if (preg_match(',\[\]$,S', $var)) {
2586
-			$values[] = array($var, $val);
2587
-		} else {
2588
-			if (!isset($values[$var])) {
2589
-				$values[$var] = array($var, $val);
2590
-			}
2591
-		}
2592
-	}
2593
-
2594
-	// puis on rassemble le tout
2595
-	$hidden = array();
2596
-	foreach ($values as $value) {
2597
-		list($var, $val) = $value;
2598
-		$hidden[] = '<input name="'
2599
-			. entites_html($var)
2600
-			. '"'
2601
-			. (is_null($val)
2602
-				? ''
2603
-				: ' value="' . entites_html($val) . '"'
2604
-			)
2605
-			. ' type="hidden"' . "\n/>";
2606
-	}
2607
-
2608
-	return join("", $hidden);
2539
+    $contexte = array();
2540
+    include_spip('inc/urls');
2541
+    if ($p = urls_decoder_url($action, '')
2542
+        and reset($p)
2543
+    ) {
2544
+        $fond = array_shift($p);
2545
+        if ($fond != '404') {
2546
+            $contexte = array_shift($p);
2547
+            $contexte['page'] = $fond;
2548
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2549
+        }
2550
+    }
2551
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2552
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2553
+        unset($contexte['type']);
2554
+    }
2555
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2556
+        unset($contexte['type-page']);
2557
+    }
2558
+
2559
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2560
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2561
+    $values = array();
2562
+
2563
+    // d'abord avec celles de l'url
2564
+    if (false !== ($p = strpos($action, '?'))) {
2565
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2566
+            $c = explode('=', $c, 2);
2567
+            $var = array_shift($c);
2568
+            $val = array_shift($c);
2569
+            if ($var) {
2570
+                $val = rawurldecode($val);
2571
+                $var = rawurldecode($var); // decoder les [] eventuels
2572
+                if (preg_match(',\[\]$,S', $var)) {
2573
+                    $values[] = array($var, $val);
2574
+                } else {
2575
+                    if (!isset($values[$var])) {
2576
+                        $values[$var] = array($var, $val);
2577
+                    }
2578
+                }
2579
+            }
2580
+        }
2581
+    }
2582
+
2583
+    // ensuite avec celles du contexte, sans doublonner !
2584
+    foreach ($contexte as $var => $val) {
2585
+        if (preg_match(',\[\]$,S', $var)) {
2586
+            $values[] = array($var, $val);
2587
+        } else {
2588
+            if (!isset($values[$var])) {
2589
+                $values[$var] = array($var, $val);
2590
+            }
2591
+        }
2592
+    }
2593
+
2594
+    // puis on rassemble le tout
2595
+    $hidden = array();
2596
+    foreach ($values as $value) {
2597
+        list($var, $val) = $value;
2598
+        $hidden[] = '<input name="'
2599
+            . entites_html($var)
2600
+            . '"'
2601
+            . (is_null($val)
2602
+                ? ''
2603
+                : ' value="' . entites_html($val) . '"'
2604
+            )
2605
+            . ' type="hidden"' . "\n/>";
2606
+    }
2607
+
2608
+    return join("", $hidden);
2609 2609
 }
2610 2610
 
2611 2611
 /**
@@ -2623,15 +2623,15 @@  discard block
 block discarded – undo
2623 2623
  *     Liste (première page, dernière page).
2624 2624
  **/
2625 2625
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2626
-	if ($max <= 0 or $max >= $nombre) {
2627
-		return array(1, $nombre);
2628
-	}
2626
+    if ($max <= 0 or $max >= $nombre) {
2627
+        return array(1, $nombre);
2628
+    }
2629 2629
 
2630
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2631
-	$derniere = min($nombre, $premiere + $max - 2);
2632
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2630
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2631
+    $derniere = min($nombre, $premiere + $max - 2);
2632
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2633 2633
 
2634
-	return array($premiere, $derniere);
2634
+    return array($premiere, $derniere);
2635 2635
 }
2636 2636
 
2637 2637
 
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
  *    - la première valeur du tableau sinon.
2654 2654
  **/
2655 2655
 function filtre_reset($array) {
2656
-	return !is_array($array) ? null : reset($array);
2656
+    return !is_array($array) ? null : reset($array);
2657 2657
 }
2658 2658
 
2659 2659
 /**
@@ -2674,7 +2674,7 @@  discard block
 block discarded – undo
2674 2674
  *    - la dernière valeur du tableau sinon.
2675 2675
  **/
2676 2676
 function filtre_end($array) {
2677
-	return !is_array($array) ? null : end($array);
2677
+    return !is_array($array) ? null : end($array);
2678 2678
 }
2679 2679
 
2680 2680
 /**
@@ -2694,11 +2694,11 @@  discard block
 block discarded – undo
2694 2694
  *
2695 2695
  **/
2696 2696
 function filtre_push($array, $val) {
2697
-	if (!is_array($array) or !array_push($array, $val)) {
2698
-		return '';
2699
-	}
2697
+    if (!is_array($array) or !array_push($array, $val)) {
2698
+        return '';
2699
+    }
2700 2700
 
2701
-	return $array;
2701
+    return $array;
2702 2702
 }
2703 2703
 
2704 2704
 /**
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2718 2718
  **/
2719 2719
 function filtre_find($array, $val) {
2720
-	return (is_array($array) and in_array($val, $array));
2720
+    return (is_array($array) and in_array($val, $array));
2721 2721
 }
2722 2722
 
2723 2723
 
@@ -2752,59 +2752,59 @@  discard block
 block discarded – undo
2752 2752
  *     Code HTML de la pagination
2753 2753
  **/
2754 2754
 function filtre_pagination_dist(
2755
-	$total,
2756
-	$nom,
2757
-	$position,
2758
-	$pas,
2759
-	$liste = true,
2760
-	$modele = '',
2761
-	$connect = '',
2762
-	$env = array()
2755
+    $total,
2756
+    $nom,
2757
+    $position,
2758
+    $pas,
2759
+    $liste = true,
2760
+    $modele = '',
2761
+    $connect = '',
2762
+    $env = array()
2763 2763
 ) {
2764
-	static $ancres = array();
2765
-	if ($pas < 1) {
2766
-		return '';
2767
-	}
2768
-	$ancre = 'pagination' . $nom; // #pagination_articles
2769
-	$debut = 'debut' . $nom; // 'debut_articles'
2770
-
2771
-	// n'afficher l'ancre qu'une fois
2772
-	if (!isset($ancres[$ancre])) {
2773
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2774
-	} else {
2775
-		$bloc_ancre = '';
2776
-	}
2777
-	// liste = false : on ne veut que l'ancre
2778
-	if (!$liste) {
2779
-		return $ancres[$ancre];
2780
-	}
2781
-
2782
-	$self = (empty($env['self']) ? self() : $env['self']);
2783
-	$pagination = array(
2784
-		'debut' => $debut,
2785
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2786
-		'total' => $total,
2787
-		'position' => intval($position),
2788
-		'pas' => $pas,
2789
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
2790
-		'page_courante' => floor(intval($position) / $pas) + 1,
2791
-		'ancre' => $ancre,
2792
-		'bloc_ancre' => $bloc_ancre
2793
-	);
2794
-	if (is_array($env)) {
2795
-		$pagination = array_merge($env, $pagination);
2796
-	}
2797
-
2798
-	// Pas de pagination
2799
-	if ($pagination['nombre_pages'] <= 1) {
2800
-		return '';
2801
-	}
2802
-
2803
-	if ($modele) {
2804
-		$modele = '_' . $modele;
2805
-	}
2806
-
2807
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2764
+    static $ancres = array();
2765
+    if ($pas < 1) {
2766
+        return '';
2767
+    }
2768
+    $ancre = 'pagination' . $nom; // #pagination_articles
2769
+    $debut = 'debut' . $nom; // 'debut_articles'
2770
+
2771
+    // n'afficher l'ancre qu'une fois
2772
+    if (!isset($ancres[$ancre])) {
2773
+        $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2774
+    } else {
2775
+        $bloc_ancre = '';
2776
+    }
2777
+    // liste = false : on ne veut que l'ancre
2778
+    if (!$liste) {
2779
+        return $ancres[$ancre];
2780
+    }
2781
+
2782
+    $self = (empty($env['self']) ? self() : $env['self']);
2783
+    $pagination = array(
2784
+        'debut' => $debut,
2785
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2786
+        'total' => $total,
2787
+        'position' => intval($position),
2788
+        'pas' => $pas,
2789
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
2790
+        'page_courante' => floor(intval($position) / $pas) + 1,
2791
+        'ancre' => $ancre,
2792
+        'bloc_ancre' => $bloc_ancre
2793
+    );
2794
+    if (is_array($env)) {
2795
+        $pagination = array_merge($env, $pagination);
2796
+    }
2797
+
2798
+    // Pas de pagination
2799
+    if ($pagination['nombre_pages'] <= 1) {
2800
+        return '';
2801
+    }
2802
+
2803
+    if ($modele) {
2804
+        $modele = '_' . $modele;
2805
+    }
2806
+
2807
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2808 2808
 }
2809 2809
 
2810 2810
 
@@ -2821,15 +2821,15 @@  discard block
 block discarded – undo
2821 2821
  *     Contenu avec urls en absolus
2822 2822
  **/
2823 2823
 function urls_absolues_css($contenu, $source) {
2824
-	$path = suivre_lien(url_absolue($source), './');
2824
+    $path = suivre_lien(url_absolue($source), './');
2825 2825
 
2826
-	return preg_replace_callback(
2827
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2828
-		function($x) use ($path) {
2829
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2830
-		},
2831
-		$contenu
2832
-	);
2826
+    return preg_replace_callback(
2827
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2828
+        function($x) use ($path) {
2829
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2830
+        },
2831
+        $contenu
2832
+    );
2833 2833
 }
2834 2834
 
2835 2835
 
@@ -2858,118 +2858,118 @@  discard block
 block discarded – undo
2858 2858
  *     Chemin du fichier CSS inversé
2859 2859
  **/
2860 2860
 function direction_css($css, $voulue = '') {
2861
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2862
-		return $css;
2863
-	}
2864
-
2865
-	// si on a precise le sens voulu en argument, le prendre en compte
2866
-	if ($voulue = strtolower($voulue)) {
2867
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2868
-			$voulue = lang_dir($voulue);
2869
-		}
2870
-	} else {
2871
-		$voulue = lang_dir();
2872
-	}
2873
-
2874
-	$r = count($r) > 1;
2875
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2876
-	$dir = $r ? 'rtl' : 'ltr';
2877
-	$ndir = $r ? 'ltr' : 'rtl';
2878
-
2879
-	if ($voulue == $dir) {
2880
-		return $css;
2881
-	}
2882
-
2883
-	if (
2884
-		// url absolue
2885
-		preg_match(",^https?:,i", $css)
2886
-		// ou qui contient un ?
2887
-		or (($p = strpos($css, '?')) !== false)
2888
-	) {
2889
-		$distant = true;
2890
-		$cssf = parse_url($css);
2891
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2892
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2893
-	} else {
2894
-		$distant = false;
2895
-		$cssf = $css;
2896
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2897
-		//propose (rien a faire dans ce cas)
2898
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2899
-		if (@file_exists($f)) {
2900
-			return $f;
2901
-		}
2902
-	}
2903
-
2904
-	// 2.
2905
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2906
-	$f = $dir_var
2907
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2908
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2909
-
2910
-	// la css peut etre distante (url absolue !)
2911
-	if ($distant) {
2912
-		include_spip('inc/distant');
2913
-		$res = recuperer_url($css);
2914
-		if (!$res or !$contenu = $res['page']) {
2915
-			return $css;
2916
-		}
2917
-	} else {
2918
-		if ((@filemtime($f) > @filemtime($css))
2919
-			and (_VAR_MODE != 'recalcul')
2920
-		) {
2921
-			return $f;
2922
-		}
2923
-		if (!lire_fichier($css, $contenu)) {
2924
-			return $css;
2925
-		}
2926
-	}
2927
-
2928
-
2929
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2930
-	include_spip("lib/csstidy/class.csstidy");
2931
-	$parser = new csstidy();
2932
-	$parser->set_cfg('optimise_shorthands', 0);
2933
-	$parser->set_cfg('reverse_left_and_right', true);
2934
-	$parser->parse($contenu);
2935
-
2936
-	$contenu = $parser->print->plain();
2937
-
2938
-
2939
-	// reperer les @import auxquels il faut propager le direction_css
2940
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2941
-	$src = array();
2942
-	$src_direction_css = array();
2943
-	$src_faux_abs = array();
2944
-	$d = dirname($css);
2945
-	foreach ($regs[1] as $k => $import_css) {
2946
-		$css_direction = direction_css("$d/$import_css", $voulue);
2947
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2948
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2949
-			$css_direction = substr($css_direction, strlen($d) + 1);
2950
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2951
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2952
-			$css_direction = substr($css_direction, strlen($dir_var));
2953
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2954
-			$css_direction = "/@@@@@@/" . $css_direction;
2955
-		}
2956
-		$src[] = $regs[0][$k];
2957
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2958
-	}
2959
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2960
-
2961
-	$contenu = urls_absolues_css($contenu, $css);
2962
-
2963
-	// virer les fausses url absolues que l'on a mis dans les import
2964
-	if (count($src_faux_abs)) {
2965
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2966
-	}
2967
-
2968
-	if (!ecrire_fichier($f, $contenu)) {
2969
-		return $css;
2970
-	}
2971
-
2972
-	return $f;
2861
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2862
+        return $css;
2863
+    }
2864
+
2865
+    // si on a precise le sens voulu en argument, le prendre en compte
2866
+    if ($voulue = strtolower($voulue)) {
2867
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2868
+            $voulue = lang_dir($voulue);
2869
+        }
2870
+    } else {
2871
+        $voulue = lang_dir();
2872
+    }
2873
+
2874
+    $r = count($r) > 1;
2875
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2876
+    $dir = $r ? 'rtl' : 'ltr';
2877
+    $ndir = $r ? 'ltr' : 'rtl';
2878
+
2879
+    if ($voulue == $dir) {
2880
+        return $css;
2881
+    }
2882
+
2883
+    if (
2884
+        // url absolue
2885
+        preg_match(",^https?:,i", $css)
2886
+        // ou qui contient un ?
2887
+        or (($p = strpos($css, '?')) !== false)
2888
+    ) {
2889
+        $distant = true;
2890
+        $cssf = parse_url($css);
2891
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2892
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2893
+    } else {
2894
+        $distant = false;
2895
+        $cssf = $css;
2896
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2897
+        //propose (rien a faire dans ce cas)
2898
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2899
+        if (@file_exists($f)) {
2900
+            return $f;
2901
+        }
2902
+    }
2903
+
2904
+    // 2.
2905
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2906
+    $f = $dir_var
2907
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2908
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2909
+
2910
+    // la css peut etre distante (url absolue !)
2911
+    if ($distant) {
2912
+        include_spip('inc/distant');
2913
+        $res = recuperer_url($css);
2914
+        if (!$res or !$contenu = $res['page']) {
2915
+            return $css;
2916
+        }
2917
+    } else {
2918
+        if ((@filemtime($f) > @filemtime($css))
2919
+            and (_VAR_MODE != 'recalcul')
2920
+        ) {
2921
+            return $f;
2922
+        }
2923
+        if (!lire_fichier($css, $contenu)) {
2924
+            return $css;
2925
+        }
2926
+    }
2927
+
2928
+
2929
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2930
+    include_spip("lib/csstidy/class.csstidy");
2931
+    $parser = new csstidy();
2932
+    $parser->set_cfg('optimise_shorthands', 0);
2933
+    $parser->set_cfg('reverse_left_and_right', true);
2934
+    $parser->parse($contenu);
2935
+
2936
+    $contenu = $parser->print->plain();
2937
+
2938
+
2939
+    // reperer les @import auxquels il faut propager le direction_css
2940
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2941
+    $src = array();
2942
+    $src_direction_css = array();
2943
+    $src_faux_abs = array();
2944
+    $d = dirname($css);
2945
+    foreach ($regs[1] as $k => $import_css) {
2946
+        $css_direction = direction_css("$d/$import_css", $voulue);
2947
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2948
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2949
+            $css_direction = substr($css_direction, strlen($d) + 1);
2950
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2951
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2952
+            $css_direction = substr($css_direction, strlen($dir_var));
2953
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2954
+            $css_direction = "/@@@@@@/" . $css_direction;
2955
+        }
2956
+        $src[] = $regs[0][$k];
2957
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2958
+    }
2959
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2960
+
2961
+    $contenu = urls_absolues_css($contenu, $css);
2962
+
2963
+    // virer les fausses url absolues que l'on a mis dans les import
2964
+    if (count($src_faux_abs)) {
2965
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2966
+    }
2967
+
2968
+    if (!ecrire_fichier($f, $contenu)) {
2969
+        return $css;
2970
+    }
2971
+
2972
+    return $f;
2973 2973
 }
2974 2974
 
2975 2975
 
@@ -2992,43 +2992,43 @@  discard block
 block discarded – undo
2992 2992
  *     - Chemin ou URL du fichier CSS source sinon.
2993 2993
  **/
2994 2994
 function url_absolue_css($css) {
2995
-	if (!preg_match(',\.css$,i', $css, $r)) {
2996
-		return $css;
2997
-	}
2995
+    if (!preg_match(',\.css$,i', $css, $r)) {
2996
+        return $css;
2997
+    }
2998 2998
 
2999
-	$url_absolue_css = url_absolue($css);
2999
+    $url_absolue_css = url_absolue($css);
3000 3000
 
3001
-	$f = basename($css, '.css');
3002
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3003
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3004
-		. '.css';
3001
+    $f = basename($css, '.css');
3002
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3003
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3004
+        . '.css';
3005 3005
 
3006
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3007
-		return $f;
3008
-	}
3006
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3007
+        return $f;
3008
+    }
3009 3009
 
3010
-	if ($url_absolue_css == $css) {
3011
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3012
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3013
-		) {
3014
-			include_spip('inc/distant');
3015
-			if (!$contenu = recuperer_page($css)) {
3016
-				return $css;
3017
-			}
3018
-		}
3019
-	} elseif (!lire_fichier($css, $contenu)) {
3020
-		return $css;
3021
-	}
3010
+    if ($url_absolue_css == $css) {
3011
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3012
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3013
+        ) {
3014
+            include_spip('inc/distant');
3015
+            if (!$contenu = recuperer_page($css)) {
3016
+                return $css;
3017
+            }
3018
+        }
3019
+    } elseif (!lire_fichier($css, $contenu)) {
3020
+        return $css;
3021
+    }
3022 3022
 
3023
-	// passer les url relatives a la css d'origine en url absolues
3024
-	$contenu = urls_absolues_css($contenu, $css);
3023
+    // passer les url relatives a la css d'origine en url absolues
3024
+    $contenu = urls_absolues_css($contenu, $css);
3025 3025
 
3026
-	// ecrire la css
3027
-	if (!ecrire_fichier($f, $contenu)) {
3028
-		return $css;
3029
-	}
3026
+    // ecrire la css
3027
+    if (!ecrire_fichier($f, $contenu)) {
3028
+        return $css;
3029
+    }
3030 3030
 
3031
-	return $f;
3031
+    return $f;
3032 3032
 }
3033 3033
 
3034 3034
 
@@ -3062,24 +3062,24 @@  discard block
 block discarded – undo
3062 3062
  *     Valeur trouvée ou valeur par défaut.
3063 3063
  **/
3064 3064
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3065
-	foreach (explode('/', $cle) as $k) {
3065
+    foreach (explode('/', $cle) as $k) {
3066 3066
 
3067
-		$table = is_string($table) ? @unserialize($table) : $table;
3067
+        $table = is_string($table) ? @unserialize($table) : $table;
3068 3068
 
3069
-		if (is_object($table)) {
3070
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3071
-		} elseif (is_array($table)) {
3072
-			if ($conserver_null) {
3073
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3074
-			} else {
3075
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3076
-			}
3077
-		} else {
3078
-			$table = $defaut;
3079
-		}
3080
-	}
3069
+        if (is_object($table)) {
3070
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3071
+        } elseif (is_array($table)) {
3072
+            if ($conserver_null) {
3073
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3074
+            } else {
3075
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3076
+            }
3077
+        } else {
3078
+            $table = $defaut;
3079
+        }
3080
+    }
3081 3081
 
3082
-	return $table;
3082
+    return $table;
3083 3083
 }
3084 3084
 
3085 3085
 /**
@@ -3112,22 +3112,22 @@  discard block
 block discarded – undo
3112 3112
  *     - string : expression trouvée.
3113 3113
  **/
3114 3114
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3115
-	if (intval($modif) and $capte == 0) {
3116
-		$capte = $modif;
3117
-		$modif = "UimsS";
3118
-	}
3119
-	$expression = str_replace("\/", "/", $expression);
3120
-	$expression = str_replace("/", "\/", $expression);
3115
+    if (intval($modif) and $capte == 0) {
3116
+        $capte = $modif;
3117
+        $modif = "UimsS";
3118
+    }
3119
+    $expression = str_replace("\/", "/", $expression);
3120
+    $expression = str_replace("/", "\/", $expression);
3121 3121
 
3122
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3123
-		if (isset($r[$capte])) {
3124
-			return $r[$capte];
3125
-		} else {
3126
-			return true;
3127
-		}
3128
-	}
3122
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3123
+        if (isset($r[$capte])) {
3124
+            return $r[$capte];
3125
+        } else {
3126
+            return true;
3127
+        }
3128
+    }
3129 3129
 
3130
-	return false;
3130
+    return false;
3131 3131
 }
3132 3132
 
3133 3133
 
@@ -3154,10 +3154,10 @@  discard block
 block discarded – undo
3154 3154
  *     Texte
3155 3155
  **/
3156 3156
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3157
-	$expression = str_replace("\/", "/", $expression);
3158
-	$expression = str_replace("/", "\/", $expression);
3157
+    $expression = str_replace("\/", "/", $expression);
3158
+    $expression = str_replace("/", "\/", $expression);
3159 3159
 
3160
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3160
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3161 3161
 }
3162 3162
 
3163 3163
 
@@ -3175,21 +3175,21 @@  discard block
 block discarded – undo
3175 3175
  **/
3176 3176
 function traiter_doublons_documents(&$doublons, $letexte) {
3177 3177
 
3178
-	// Verifier dans le texte & les notes (pas beau, helas)
3179
-	$t = $letexte . $GLOBALS['les_notes'];
3178
+    // Verifier dans le texte & les notes (pas beau, helas)
3179
+    $t = $letexte . $GLOBALS['les_notes'];
3180 3180
 
3181
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3182
-		and preg_match_all(
3183
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3184
-			$t, $matches, PREG_PATTERN_ORDER)
3185
-	) {
3186
-		if (!isset($doublons['documents'])) {
3187
-			$doublons['documents'] = "";
3188
-		}
3189
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3190
-	}
3181
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3182
+        and preg_match_all(
3183
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3184
+            $t, $matches, PREG_PATTERN_ORDER)
3185
+    ) {
3186
+        if (!isset($doublons['documents'])) {
3187
+            $doublons['documents'] = "";
3188
+        }
3189
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3190
+    }
3191 3191
 
3192
-	return $letexte;
3192
+    return $letexte;
3193 3193
 }
3194 3194
 
3195 3195
 /**
@@ -3203,7 +3203,7 @@  discard block
 block discarded – undo
3203 3203
  * @return string Chaîne vide
3204 3204
  **/
3205 3205
 function vide($texte) {
3206
-	return "";
3206
+    return "";
3207 3207
 }
3208 3208
 
3209 3209
 //
@@ -3232,23 +3232,23 @@  discard block
 block discarded – undo
3232 3232
  *      Code HTML résultant
3233 3233
  **/
3234 3234
 function env_to_params($env, $ignore_params = array()) {
3235
-	$ignore_params = array_merge(
3236
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3237
-		$ignore_params
3238
-	);
3239
-	if (!is_array($env)) {
3240
-		$env = unserialize($env);
3241
-	}
3242
-	$texte = "";
3243
-	if ($env) {
3244
-		foreach ($env as $i => $j) {
3245
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3246
-				$texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3247
-			}
3248
-		}
3249
-	}
3250
-
3251
-	return $texte;
3235
+    $ignore_params = array_merge(
3236
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3237
+        $ignore_params
3238
+    );
3239
+    if (!is_array($env)) {
3240
+        $env = unserialize($env);
3241
+    }
3242
+    $texte = "";
3243
+    if ($env) {
3244
+        foreach ($env as $i => $j) {
3245
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3246
+                $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3247
+            }
3248
+        }
3249
+    }
3250
+
3251
+    return $texte;
3252 3252
 }
3253 3253
 
3254 3254
 /**
@@ -3271,23 +3271,23 @@  discard block
 block discarded – undo
3271 3271
  *      Code HTML résultant
3272 3272
  **/
3273 3273
 function env_to_attributs($env, $ignore_params = array()) {
3274
-	$ignore_params = array_merge(
3275
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3276
-		$ignore_params
3277
-	);
3278
-	if (!is_array($env)) {
3279
-		$env = unserialize($env);
3280
-	}
3281
-	$texte = "";
3282
-	if ($env) {
3283
-		foreach ($env as $i => $j) {
3284
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3285
-				$texte .= $i . "='" . $j . "' ";
3286
-			}
3287
-		}
3288
-	}
3274
+    $ignore_params = array_merge(
3275
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3276
+        $ignore_params
3277
+    );
3278
+    if (!is_array($env)) {
3279
+        $env = unserialize($env);
3280
+    }
3281
+    $texte = "";
3282
+    if ($env) {
3283
+        foreach ($env as $i => $j) {
3284
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3285
+                $texte .= $i . "='" . $j . "' ";
3286
+            }
3287
+        }
3288
+    }
3289 3289
 
3290
-	return $texte;
3290
+    return $texte;
3291 3291
 }
3292 3292
 
3293 3293
 
@@ -3304,9 +3304,9 @@  discard block
 block discarded – undo
3304 3304
  * @return string Chaînes concaténés
3305 3305
  **/
3306 3306
 function concat() {
3307
-	$args = func_get_args();
3307
+    $args = func_get_args();
3308 3308
 
3309
-	return join('', $args);
3309
+    return join('', $args);
3310 3310
 }
3311 3311
 
3312 3312
 
@@ -3326,23 +3326,23 @@  discard block
 block discarded – undo
3326 3326
  *     Contenu du ou des fichiers, concaténé
3327 3327
  **/
3328 3328
 function charge_scripts($files, $script = true) {
3329
-	$flux = "";
3330
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3331
-		if (!is_string($file)) {
3332
-			continue;
3333
-		}
3334
-		if ($script) {
3335
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3336
-		}
3337
-		if ($file) {
3338
-			$path = find_in_path($file);
3339
-			if ($path) {
3340
-				$flux .= spip_file_get_contents($path);
3341
-			}
3342
-		}
3343
-	}
3329
+    $flux = "";
3330
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3331
+        if (!is_string($file)) {
3332
+            continue;
3333
+        }
3334
+        if ($script) {
3335
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3336
+        }
3337
+        if ($file) {
3338
+            $path = find_in_path($file);
3339
+            if ($path) {
3340
+                $flux .= spip_file_get_contents($path);
3341
+            }
3342
+        }
3343
+    }
3344 3344
 
3345
-	return $flux;
3345
+    return $flux;
3346 3346
 }
3347 3347
 
3348 3348
 
@@ -3364,55 +3364,55 @@  discard block
 block discarded – undo
3364 3364
  */
3365 3365
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3366 3366
 
3367
-	$img_file = $img;
3368
-	if ($p = strpos($img_file, '?')) {
3369
-		$img_file = substr($img_file,0, $p);
3370
-	}
3371
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3372
-		$img_file = chemin_image($img);
3373
-	}
3374
-	else {
3375
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3376
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3377
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3378
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3379
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3380
-			  and file_exists($variante_svg_generique)) {
3381
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3382
-					$img_file = $variante_svg_size;
3383
-				}
3384
-				else {
3385
-					$img_file = $variante_svg_generique;
3386
-				}
3387
-			}
3388
-		}
3389
-	}
3390
-	if (stripos($atts, 'width') === false) {
3391
-		// utiliser directement l'info de taille presente dans le nom
3392
-		if ((!isset($options['utiliser_suffixe_size'])
3393
-				or $options['utiliser_suffixe_size'] == true
3394
-			  or strpos($img_file, '-xx.svg') !== false)
3395
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3396
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3397
-		) {
3398
-			$largeur = $hauteur = intval($regs[1]);
3399
-		} else {
3400
-			$taille = taille_image($img_file);
3401
-			list($hauteur, $largeur) = $taille;
3402
-			if (!$hauteur or !$largeur) {
3403
-				return "";
3404
-			}
3405
-		}
3406
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3407
-	}
3408
-
3409
-	if (file_exists($img_file)) {
3410
-		$img_file = timestamp($img_file);
3411
-	}
3412
-	return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3413
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3414
-	. " " . ltrim($atts)
3415
-	. " />";
3367
+    $img_file = $img;
3368
+    if ($p = strpos($img_file, '?')) {
3369
+        $img_file = substr($img_file,0, $p);
3370
+    }
3371
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3372
+        $img_file = chemin_image($img);
3373
+    }
3374
+    else {
3375
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3376
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3377
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3378
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3379
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3380
+              and file_exists($variante_svg_generique)) {
3381
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3382
+                    $img_file = $variante_svg_size;
3383
+                }
3384
+                else {
3385
+                    $img_file = $variante_svg_generique;
3386
+                }
3387
+            }
3388
+        }
3389
+    }
3390
+    if (stripos($atts, 'width') === false) {
3391
+        // utiliser directement l'info de taille presente dans le nom
3392
+        if ((!isset($options['utiliser_suffixe_size'])
3393
+                or $options['utiliser_suffixe_size'] == true
3394
+              or strpos($img_file, '-xx.svg') !== false)
3395
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3396
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3397
+        ) {
3398
+            $largeur = $hauteur = intval($regs[1]);
3399
+        } else {
3400
+            $taille = taille_image($img_file);
3401
+            list($hauteur, $largeur) = $taille;
3402
+            if (!$hauteur or !$largeur) {
3403
+                return "";
3404
+            }
3405
+        }
3406
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3407
+    }
3408
+
3409
+    if (file_exists($img_file)) {
3410
+        $img_file = timestamp($img_file);
3411
+    }
3412
+    return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3413
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3414
+    . " " . ltrim($atts)
3415
+    . " />";
3416 3416
 }
3417 3417
 
3418 3418
 /**
@@ -3424,13 +3424,13 @@  discard block
 block discarded – undo
3424 3424
  * @return string
3425 3425
  */
3426 3426
 function http_style_background($img, $att = '', $size=null) {
3427
-	if ($size and is_numeric($size)){
3428
-		$size = trim($size) . "px";
3429
-	}
3430
-	return " style='background" .
3431
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3432
-		. ($size ? "background-size:{$size};" : '')
3433
-		. "'";
3427
+    if ($size and is_numeric($size)){
3428
+        $size = trim($size) . "px";
3429
+    }
3430
+    return " style='background" .
3431
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3432
+        . ($size ? "background-size:{$size};" : '')
3433
+        . "'";
3434 3434
 }
3435 3435
 
3436 3436
 /**
@@ -3446,17 +3446,17 @@  discard block
 block discarded – undo
3446 3446
  *     Code HTML de la balise IMG
3447 3447
  */
3448 3448
 function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3449
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3450
-	// ecriture courte : on donne le width en 2e arg
3451
-	if (empty($width) and is_numeric($alt)) {
3452
-		$width = $alt;
3453
-		$alt = '';
3454
-	}
3455
-	if ($width) {
3456
-		$atts .= " width='{$width}'";
3457
-	}
3458
-	return http_img_pack($img, $alt, $atts, '',
3459
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3449
+    $atts = $class ? " class='" . attribut_html($class) . "'" : '';
3450
+    // ecriture courte : on donne le width en 2e arg
3451
+    if (empty($width) and is_numeric($alt)) {
3452
+        $width = $alt;
3453
+        $alt = '';
3454
+    }
3455
+    if ($width) {
3456
+        $atts .= " width='{$width}'";
3457
+    }
3458
+    return http_img_pack($img, $alt, $atts, '',
3459
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3460 3460
 }
3461 3461
 
3462 3462
 
@@ -3472,42 +3472,42 @@  discard block
 block discarded – undo
3472 3472
  * @return string
3473 3473
  */
3474 3474
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3475
-	$img_file = $img;
3476
-	if ($p = strpos($img_file, '?')) {
3477
-		$img_file = substr($img_file,0, $p);
3478
-	}
3475
+    $img_file = $img;
3476
+    if ($p = strpos($img_file, '?')) {
3477
+        $img_file = substr($img_file,0, $p);
3478
+    }
3479 3479
 
3480
-	if (!$img_file or !$svg = file_get_contents($img_file)) {
3481
-		return '';
3482
-	}
3480
+    if (!$img_file or !$svg = file_get_contents($img_file)) {
3481
+        return '';
3482
+    }
3483 3483
 
3484
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3485
-		return '';
3486
-	}
3487
-	$balise_svg = $match[0];
3488
-	$balise_svg_source = $balise_svg;
3484
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3485
+        return '';
3486
+    }
3487
+    $balise_svg = $match[0];
3488
+    $balise_svg_source = $balise_svg;
3489 3489
 
3490
-	// entete XML à supprimer
3491
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3490
+    // entete XML à supprimer
3491
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3492 3492
 
3493
-	// IE est toujours mon ami
3494
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3495
-	if ($class) {
3496
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3497
-	}
3498
-	if ($alt){
3499
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3500
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3501
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3502
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3503
-		$balise_svg .= $title;
3504
-	}
3505
-	else {
3506
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3507
-	}
3508
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3493
+    // IE est toujours mon ami
3494
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3495
+    if ($class) {
3496
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3497
+    }
3498
+    if ($alt){
3499
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3500
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3501
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3502
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3503
+        $balise_svg .= $title;
3504
+    }
3505
+    else {
3506
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3507
+    }
3508
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3509 3509
 
3510
-	return $svg;
3510
+    return $svg;
3511 3511
 }
3512 3512
 
3513 3513
 
@@ -3530,17 +3530,17 @@  discard block
 block discarded – undo
3530 3530
  *     Code HTML résultant
3531 3531
  **/
3532 3532
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3533
-	$texte = '';
3534
-	if (is_array($tableau)) {
3535
-		foreach ($tableau as $k => $v) {
3536
-			$res = recuperer_fond('modeles/' . $modele,
3537
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3538
-			);
3539
-			$texte .= $res;
3540
-		}
3541
-	}
3533
+    $texte = '';
3534
+    if (is_array($tableau)) {
3535
+        foreach ($tableau as $k => $v) {
3536
+            $res = recuperer_fond('modeles/' . $modele,
3537
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3538
+            );
3539
+            $texte .= $res;
3540
+        }
3541
+    }
3542 3542
 
3543
-	return $texte;
3543
+    return $texte;
3544 3544
 }
3545 3545
 
3546 3546
 
@@ -3565,37 +3565,37 @@  discard block
 block discarded – undo
3565 3565
  *         - tout : retourne toutes les informations du plugin actif
3566 3566
  **/
3567 3567
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3568
-	include_spip('inc/plugin');
3569
-	$plugin = strtoupper($plugin);
3570
-	$plugins_actifs = liste_plugin_actifs();
3571
-
3572
-	if (!$plugin) {
3573
-		return serialize(array_keys($plugins_actifs));
3574
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3575
-		return '';
3576
-	} elseif (($type_info == 'est_actif') and !$reload) {
3577
-		return $plugins_actifs[$plugin] ? 1 : 0;
3578
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3579
-		return $plugins_actifs[$plugin][$type_info];
3580
-	} else {
3581
-		$get_infos = charger_fonction('get_infos', 'plugins');
3582
-		// On prend en compte les extensions
3583
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3584
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3585
-		} else {
3586
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3587
-		}
3588
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3589
-			return '';
3590
-		}
3591
-		if ($type_info == 'tout') {
3592
-			return $infos;
3593
-		} elseif ($type_info == 'est_actif') {
3594
-			return $infos ? 1 : 0;
3595
-		} else {
3596
-			return strval($infos[$type_info]);
3597
-		}
3598
-	}
3568
+    include_spip('inc/plugin');
3569
+    $plugin = strtoupper($plugin);
3570
+    $plugins_actifs = liste_plugin_actifs();
3571
+
3572
+    if (!$plugin) {
3573
+        return serialize(array_keys($plugins_actifs));
3574
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3575
+        return '';
3576
+    } elseif (($type_info == 'est_actif') and !$reload) {
3577
+        return $plugins_actifs[$plugin] ? 1 : 0;
3578
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3579
+        return $plugins_actifs[$plugin][$type_info];
3580
+    } else {
3581
+        $get_infos = charger_fonction('get_infos', 'plugins');
3582
+        // On prend en compte les extensions
3583
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3584
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3585
+        } else {
3586
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3587
+        }
3588
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3589
+            return '';
3590
+        }
3591
+        if ($type_info == 'tout') {
3592
+            return $infos;
3593
+        } elseif ($type_info == 'est_actif') {
3594
+            return $infos ? 1 : 0;
3595
+        } else {
3596
+            return strval($infos[$type_info]);
3597
+        }
3598
+    }
3599 3599
 }
3600 3600
 
3601 3601
 
@@ -3622,9 +3622,9 @@  discard block
 block discarded – undo
3622 3622
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3623 3623
  */
3624 3624
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3625
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3625
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3626 3626
 
3627
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3627
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3628 3628
 }
3629 3629
 
3630 3630
 
@@ -3654,13 +3654,13 @@  discard block
 block discarded – undo
3654 3654
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3655 3655
  */
3656 3656
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3657
-	static $puce_statut = null;
3658
-	if (!$puce_statut) {
3659
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3660
-	}
3657
+    static $puce_statut = null;
3658
+    if (!$puce_statut) {
3659
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3660
+    }
3661 3661
 
3662
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3663
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3662
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3663
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3664 3664
 }
3665 3665
 
3666 3666
 
@@ -3687,88 +3687,88 @@  discard block
 block discarded – undo
3687 3687
  *   hash du contexte
3688 3688
  */
3689 3689
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3690
-	if (is_string($c)
3691
-		and @unserialize($c) !== false
3692
-	) {
3693
-		$c = unserialize($c);
3694
-	}
3695
-
3696
-	// supprimer les parametres debut_x
3697
-	// pour que la pagination ajax ne soit pas plantee
3698
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3699
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3700
-	if (is_array($c)) {
3701
-		foreach ($c as $k => $v) {
3702
-			if (strpos($k, 'debut_') === 0) {
3703
-				unset($c[$k]);
3704
-			}
3705
-		}
3706
-	}
3707
-
3708
-	if (!function_exists('calculer_cle_action')) {
3709
-		include_spip("inc/securiser_action");
3710
-	}
3711
-
3712
-	$c = serialize($c);
3713
-	$cle = calculer_cle_action($form . $c);
3714
-	$c = "$cle:$c";
3715
-
3716
-	// on ne stocke pas les contextes dans des fichiers caches
3717
-	// par defaut, sauf si cette configuration a ete forcee
3718
-	// OU que la longueur de l''argument generee est plus long
3719
-	// que ce que telere Suhosin.
3720
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3721
-	if (!$cache_contextes_ajax) {
3722
-		$env = $c;
3723
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3724
-			$env = gzdeflate($env);
3725
-			// https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3726
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3727
-				$cache_contextes_ajax = true;
3728
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3729
-			}
3730
-		}
3731
-		$env = _xor($env);
3732
-		$env = base64_encode($env);
3733
-		// tester Suhosin et la valeur maximale des variables en GET...
3734
-		if ($max_len = @ini_get('suhosin.get.max_value_length')
3735
-			and $max_len < ($len = strlen($env))
3736
-		) {
3737
-			$cache_contextes_ajax = true;
3738
-			spip_log("Contextes AJAX forces en fichiers !"
3739
-				. " Cela arrive lorsque la valeur du contexte"
3740
-				. " depasse la longueur maximale autorisee par Suhosin"
3741
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3742
-				. " Vous devriez modifier les parametres de Suhosin"
3743
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3744
-		}
3745
-	}
3746
-
3747
-	if ($cache_contextes_ajax) {
3748
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3749
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3750
-		$md5 = md5($c);
3751
-		ecrire_fichier("$dir/c$md5", $c);
3752
-		$env = $md5;
3753
-	}
3754
-
3755
-	if ($emboite === null) {
3756
-		return $env;
3757
-	}
3758
-	if (!trim($emboite)) {
3759
-		return "";
3760
-	}
3761
-	// toujours encoder l'url source dans le bloc ajax
3762
-	$r = self();
3763
-	$r = ' data-origin="' . $r . '"';
3764
-	$class = 'ajaxbloc';
3765
-	if ($ajaxid and is_string($ajaxid)) {
3766
-		// ajaxid est normalement conforme a un nom de classe css
3767
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3768
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3769
-	}
3770
-
3771
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3690
+    if (is_string($c)
3691
+        and @unserialize($c) !== false
3692
+    ) {
3693
+        $c = unserialize($c);
3694
+    }
3695
+
3696
+    // supprimer les parametres debut_x
3697
+    // pour que la pagination ajax ne soit pas plantee
3698
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3699
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3700
+    if (is_array($c)) {
3701
+        foreach ($c as $k => $v) {
3702
+            if (strpos($k, 'debut_') === 0) {
3703
+                unset($c[$k]);
3704
+            }
3705
+        }
3706
+    }
3707
+
3708
+    if (!function_exists('calculer_cle_action')) {
3709
+        include_spip("inc/securiser_action");
3710
+    }
3711
+
3712
+    $c = serialize($c);
3713
+    $cle = calculer_cle_action($form . $c);
3714
+    $c = "$cle:$c";
3715
+
3716
+    // on ne stocke pas les contextes dans des fichiers caches
3717
+    // par defaut, sauf si cette configuration a ete forcee
3718
+    // OU que la longueur de l''argument generee est plus long
3719
+    // que ce que telere Suhosin.
3720
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3721
+    if (!$cache_contextes_ajax) {
3722
+        $env = $c;
3723
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3724
+            $env = gzdeflate($env);
3725
+            // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3726
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3727
+                $cache_contextes_ajax = true;
3728
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3729
+            }
3730
+        }
3731
+        $env = _xor($env);
3732
+        $env = base64_encode($env);
3733
+        // tester Suhosin et la valeur maximale des variables en GET...
3734
+        if ($max_len = @ini_get('suhosin.get.max_value_length')
3735
+            and $max_len < ($len = strlen($env))
3736
+        ) {
3737
+            $cache_contextes_ajax = true;
3738
+            spip_log("Contextes AJAX forces en fichiers !"
3739
+                . " Cela arrive lorsque la valeur du contexte"
3740
+                . " depasse la longueur maximale autorisee par Suhosin"
3741
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3742
+                . " Vous devriez modifier les parametres de Suhosin"
3743
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3744
+        }
3745
+    }
3746
+
3747
+    if ($cache_contextes_ajax) {
3748
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3749
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3750
+        $md5 = md5($c);
3751
+        ecrire_fichier("$dir/c$md5", $c);
3752
+        $env = $md5;
3753
+    }
3754
+
3755
+    if ($emboite === null) {
3756
+        return $env;
3757
+    }
3758
+    if (!trim($emboite)) {
3759
+        return "";
3760
+    }
3761
+    // toujours encoder l'url source dans le bloc ajax
3762
+    $r = self();
3763
+    $r = ' data-origin="' . $r . '"';
3764
+    $class = 'ajaxbloc';
3765
+    if ($ajaxid and is_string($ajaxid)) {
3766
+        // ajaxid est normalement conforme a un nom de classe css
3767
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3768
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3769
+    }
3770
+
3771
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3772 3772
 }
3773 3773
 
3774 3774
 /**
@@ -3788,36 +3788,36 @@  discard block
 block discarded – undo
3788 3788
  *   - false : erreur de décodage
3789 3789
  */
3790 3790
 function decoder_contexte_ajax($c, $form = '') {
3791
-	if (!function_exists('calculer_cle_action')) {
3792
-		include_spip("inc/securiser_action");
3793
-	}
3794
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3795
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3796
-		and lire_fichier("$dir/c$c", $contexte)
3797
-	) {
3798
-		$c = $contexte;
3799
-	} else {
3800
-		$c = @base64_decode($c);
3801
-		$c = _xor($c);
3802
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3803
-			$c = @gzinflate($c);
3804
-		}
3805
-	}
3806
-
3807
-	// extraire la signature en debut de contexte
3808
-	// et la verifier avant de deserializer
3809
-	// format : signature:donneesserializees
3810
-	if ($p = strpos($c,":")){
3811
-		$cle = substr($c,0,$p);
3812
-		$c = substr($c,$p+1);
3813
-
3814
-		if ($cle == calculer_cle_action($form . $c)) {
3815
-			$env = @unserialize($c);
3816
-			return $env;
3817
-		}
3818
-	}
3819
-
3820
-	return false;
3791
+    if (!function_exists('calculer_cle_action')) {
3792
+        include_spip("inc/securiser_action");
3793
+    }
3794
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3795
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3796
+        and lire_fichier("$dir/c$c", $contexte)
3797
+    ) {
3798
+        $c = $contexte;
3799
+    } else {
3800
+        $c = @base64_decode($c);
3801
+        $c = _xor($c);
3802
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3803
+            $c = @gzinflate($c);
3804
+        }
3805
+    }
3806
+
3807
+    // extraire la signature en debut de contexte
3808
+    // et la verifier avant de deserializer
3809
+    // format : signature:donneesserializees
3810
+    if ($p = strpos($c,":")){
3811
+        $cle = substr($c,0,$p);
3812
+        $c = substr($c,$p+1);
3813
+
3814
+        if ($cle == calculer_cle_action($form . $c)) {
3815
+            $env = @unserialize($c);
3816
+            return $env;
3817
+        }
3818
+    }
3819
+
3820
+    return false;
3821 3821
 }
3822 3822
 
3823 3823
 
@@ -3835,20 +3835,20 @@  discard block
 block discarded – undo
3835 3835
  *    Message décrypté ou encrypté
3836 3836
  **/
3837 3837
 function _xor($message, $key = null) {
3838
-	if (is_null($key)) {
3839
-		if (!function_exists('calculer_cle_action')) {
3840
-			include_spip("inc/securiser_action");
3841
-		}
3842
-		$key = pack("H*", calculer_cle_action('_xor'));
3843
-	}
3838
+    if (is_null($key)) {
3839
+        if (!function_exists('calculer_cle_action')) {
3840
+            include_spip("inc/securiser_action");
3841
+        }
3842
+        $key = pack("H*", calculer_cle_action('_xor'));
3843
+    }
3844 3844
 
3845
-	$keylen = strlen($key);
3846
-	$messagelen = strlen($message);
3847
-	for ($i = 0; $i < $messagelen; $i++) {
3848
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3849
-	}
3845
+    $keylen = strlen($key);
3846
+    $messagelen = strlen($message);
3847
+    for ($i = 0; $i < $messagelen; $i++) {
3848
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3849
+    }
3850 3850
 
3851
-	return $message;
3851
+    return $message;
3852 3852
 }
3853 3853
 
3854 3854
 /**
@@ -3906,22 +3906,22 @@  discard block
 block discarded – undo
3906 3906
  *   Code HTML
3907 3907
  */
3908 3908
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3909
-	if ($on) {
3910
-		$bal = "strong";
3911
-		$att = "class='on'";
3912
-	} else {
3913
-		$bal = 'a';
3914
-		$att = "href='$url'"
3915
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3916
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3917
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3918
-			. $evt;
3919
-	}
3920
-	if ($libelle === null) {
3921
-		$libelle = $url;
3922
-	}
3909
+    if ($on) {
3910
+        $bal = "strong";
3911
+        $att = "class='on'";
3912
+    } else {
3913
+        $bal = 'a';
3914
+        $att = "href='$url'"
3915
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3916
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3917
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3918
+            . $evt;
3919
+    }
3920
+    if ($libelle === null) {
3921
+        $libelle = $url;
3922
+    }
3923 3923
 
3924
-	return "<$bal $att>$libelle</$bal>";
3924
+    return "<$bal $att>$libelle</$bal>";
3925 3925
 }
3926 3926
 
3927 3927
 
@@ -3938,18 +3938,18 @@  discard block
 block discarded – undo
3938 3938
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3939 3939
  */
3940 3940
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3941
-	if (!is_numeric($nb) or $nb == 0) {
3942
-		return "";
3943
-	}
3944
-	if (!is_array($vars)) {
3945
-		return "";
3946
-	}
3947
-	$vars[$var] = $nb;
3948
-	if ($nb >= 2) {
3949
-		return _T($chaine_plusieurs, $vars);
3950
-	} else {
3951
-		return _T($chaine_un, $vars);
3952
-	}
3941
+    if (!is_numeric($nb) or $nb == 0) {
3942
+        return "";
3943
+    }
3944
+    if (!is_array($vars)) {
3945
+        return "";
3946
+    }
3947
+    $vars[$var] = $nb;
3948
+    if ($nb >= 2) {
3949
+        return _T($chaine_plusieurs, $vars);
3950
+    } else {
3951
+        return _T($chaine_un, $vars);
3952
+    }
3953 3953
 }
3954 3954
 
3955 3955
 
@@ -3974,56 +3974,56 @@  discard block
 block discarded – undo
3974 3974
  * @return string
3975 3975
  */
3976 3976
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3977
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3978
-		$class .= ' danger';
3979
-	} elseif ($fonction == "rien.gif") {
3980
-		$fonction = "";
3981
-	} elseif ($fonction == "delsafe") {
3982
-		$fonction = "del";
3983
-	}
3984
-
3985
-	$fond_origine = $fond;
3986
-	// remappage des icone : article-24.png+new => article-new-24.png
3987
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3988
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
3989
-	}
3990
-
3991
-	// ajouter le type d'objet dans la class de l'icone
3992
-	$class .= " " . substr(basename($fond), 0, -4);
3993
-
3994
-	$alt = attribut_html($texte);
3995
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3996
-
3997
-	$ajax = "";
3998
-	if (strpos($class, "ajax") !== false) {
3999
-		$ajax = "ajax";
4000
-		if (strpos($class, "preload") !== false) {
4001
-			$ajax .= " preload";
4002
-		}
4003
-		if (strpos($class, "nocache") !== false) {
4004
-			$ajax .= " nocache";
4005
-		}
4006
-		$ajax = " class='$ajax'";
4007
-	}
4008
-
4009
-	$size = 24;
4010
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4011
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4012
-		$size = $match[1];
4013
-	}
4014
-
4015
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4016
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4017
-
4018
-	if ($type == 'lien') {
4019
-		return "<span class='icone s$size $class'>"
4020
-		. "<a href='$lien'$title$ajax$javascript>"
4021
-		. $icone
4022
-		. "<b>$texte</b>"
4023
-		. "</a></span>\n";
4024
-	} else {
4025
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4026
-	}
3977
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3978
+        $class .= ' danger';
3979
+    } elseif ($fonction == "rien.gif") {
3980
+        $fonction = "";
3981
+    } elseif ($fonction == "delsafe") {
3982
+        $fonction = "del";
3983
+    }
3984
+
3985
+    $fond_origine = $fond;
3986
+    // remappage des icone : article-24.png+new => article-new-24.png
3987
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3988
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
3989
+    }
3990
+
3991
+    // ajouter le type d'objet dans la class de l'icone
3992
+    $class .= " " . substr(basename($fond), 0, -4);
3993
+
3994
+    $alt = attribut_html($texte);
3995
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3996
+
3997
+    $ajax = "";
3998
+    if (strpos($class, "ajax") !== false) {
3999
+        $ajax = "ajax";
4000
+        if (strpos($class, "preload") !== false) {
4001
+            $ajax .= " preload";
4002
+        }
4003
+        if (strpos($class, "nocache") !== false) {
4004
+            $ajax .= " nocache";
4005
+        }
4006
+        $ajax = " class='$ajax'";
4007
+    }
4008
+
4009
+    $size = 24;
4010
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4011
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4012
+        $size = $match[1];
4013
+    }
4014
+
4015
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4016
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4017
+
4018
+    if ($type == 'lien') {
4019
+        return "<span class='icone s$size $class'>"
4020
+        . "<a href='$lien'$title$ajax$javascript>"
4021
+        . $icone
4022
+        . "<b>$texte</b>"
4023
+        . "</a></span>\n";
4024
+    } else {
4025
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4026
+    }
4027 4027
 }
4028 4028
 
4029 4029
 /**
@@ -4047,7 +4047,7 @@  discard block
 block discarded – undo
4047 4047
  *     Code HTML du lien
4048 4048
  **/
4049 4049
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4050
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4050
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4051 4051
 }
4052 4052
 
4053 4053
 /**
@@ -4082,7 +4082,7 @@  discard block
 block discarded – undo
4082 4082
  *     Code HTML du lien
4083 4083
  **/
4084 4084
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4085
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4085
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4086 4086
 }
4087 4087
 
4088 4088
 /**
@@ -4127,7 +4127,7 @@  discard block
 block discarded – undo
4127 4127
  *     Code HTML du lien
4128 4128
  **/
4129 4129
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4130
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4130
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4131 4131
 }
4132 4132
 
4133 4133
 /**
@@ -4158,7 +4158,7 @@  discard block
 block discarded – undo
4158 4158
  *     Code HTML du lien
4159 4159
  **/
4160 4160
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4161
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4161
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4162 4162
 }
4163 4163
 
4164 4164
 /**
@@ -4188,7 +4188,7 @@  discard block
 block discarded – undo
4188 4188
  *     Code HTML du lien
4189 4189
  */
4190 4190
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4191
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4191
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4192 4192
 }
4193 4193
 
4194 4194
 
@@ -4236,26 +4236,26 @@  discard block
 block discarded – undo
4236 4236
  * @return string Code CSS
4237 4237
  */
4238 4238
 function bando_images_background() {
4239
-	include_spip('inc/bandeau');
4240
-	// recuperer tous les boutons et leurs images
4241
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4239
+    include_spip('inc/bandeau');
4240
+    // recuperer tous les boutons et leurs images
4241
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4242 4242
 
4243
-	$res = "";
4244
-	foreach ($boutons as $page => $detail) {
4245
-		if ($detail->icone and strlen(trim($detail->icone))) {
4246
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4247
-		}
4248
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4249
-		if (is_array($detail->sousmenu)) {
4250
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4251
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4252
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4253
-				}
4254
-			}
4255
-		}
4256
-	}
4243
+    $res = "";
4244
+    foreach ($boutons as $page => $detail) {
4245
+        if ($detail->icone and strlen(trim($detail->icone))) {
4246
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4247
+        }
4248
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4249
+        if (is_array($detail->sousmenu)) {
4250
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4251
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4252
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4253
+                }
4254
+            }
4255
+        }
4256
+    }
4257 4257
 
4258
-	return $res;
4258
+    return $res;
4259 4259
 }
4260 4260
 
4261 4261
 /**
@@ -4274,19 +4274,19 @@  discard block
 block discarded – undo
4274 4274
  * @return string
4275 4275
  */
4276 4276
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4277
-	if ($confirm) {
4278
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4279
-		if ($callback) {
4280
-			$callback = "$confirm?($callback):false";
4281
-		} else {
4282
-			$callback = $confirm;
4283
-		}
4284
-	}
4285
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4286
-	$title = $title ? " title='$title'" : "";
4277
+    if ($confirm) {
4278
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4279
+        if ($callback) {
4280
+            $callback = "$confirm?($callback):false";
4281
+        } else {
4282
+            $callback = $confirm;
4283
+        }
4284
+    }
4285
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4286
+    $title = $title ? " title='$title'" : "";
4287 4287
 
4288
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4289
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4288
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4289
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4290 4290
 }
4291 4291
 
4292 4292
 /**
@@ -4307,78 +4307,78 @@  discard block
 block discarded – undo
4307 4307
  * @return string
4308 4308
  */
4309 4309
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4310
-	static $trouver_table = null;
4311
-	static $objets;
4312
-
4313
-	// On verifie qu'on a tout ce qu'il faut
4314
-	$id_objet = intval($id_objet);
4315
-	if (!($id_objet and $type_objet and $info)) {
4316
-		return '';
4317
-	}
4318
-
4319
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4320
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4321
-		return '';
4322
-	}
4323
-
4324
-	// Si on demande l'url, on retourne direct la fonction
4325
-	if ($info == 'url') {
4326
-		return generer_url_entite($id_objet, $type_objet);
4327
-	}
4328
-
4329
-	// Sinon on va tout chercher dans la table et on garde en memoire
4330
-	$demande_titre = ($info == 'titre');
4331
-
4332
-	// 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
4333
-	if (!isset($objets[$type_objet][$id_objet])
4334
-		or
4335
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4336
-	) {
4337
-		if (!$trouver_table) {
4338
-			$trouver_table = charger_fonction('trouver_table', 'base');
4339
-		}
4340
-		$desc = $trouver_table(table_objet_sql($type_objet));
4341
-		if (!$desc) {
4342
-			return $objets[$type_objet] = false;
4343
-		}
4344
-
4345
-		// Si on demande le titre, on le gere en interne
4346
-		$champ_titre = "";
4347
-		if ($demande_titre) {
4348
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4349
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4350
-		}
4351
-		include_spip('base/abstract_sql');
4352
-		include_spip('base/connect_sql');
4353
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4354
-			'*' . $champ_titre,
4355
-			$desc['table_sql'],
4356
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4357
-		);
4358
-	}
4359
-
4360
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4361
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4362
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4363
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4364
-	else {
4365
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4366
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4367
-		} // Sinon on prend directement le champ SQL tel quel
4368
-		else {
4369
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4370
-		}
4371
-	}
4372
-
4373
-	// On va ensuite appliquer les traitements automatiques si besoin
4374
-	if (!$etoile) {
4375
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4376
-		// mais ce fonctionnement est a ameliorer !
4377
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4378
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4379
-	}
4380
-
4381
-	return $info_generee;
4310
+    static $trouver_table = null;
4311
+    static $objets;
4312
+
4313
+    // On verifie qu'on a tout ce qu'il faut
4314
+    $id_objet = intval($id_objet);
4315
+    if (!($id_objet and $type_objet and $info)) {
4316
+        return '';
4317
+    }
4318
+
4319
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4320
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4321
+        return '';
4322
+    }
4323
+
4324
+    // Si on demande l'url, on retourne direct la fonction
4325
+    if ($info == 'url') {
4326
+        return generer_url_entite($id_objet, $type_objet);
4327
+    }
4328
+
4329
+    // Sinon on va tout chercher dans la table et on garde en memoire
4330
+    $demande_titre = ($info == 'titre');
4331
+
4332
+    // 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
4333
+    if (!isset($objets[$type_objet][$id_objet])
4334
+        or
4335
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4336
+    ) {
4337
+        if (!$trouver_table) {
4338
+            $trouver_table = charger_fonction('trouver_table', 'base');
4339
+        }
4340
+        $desc = $trouver_table(table_objet_sql($type_objet));
4341
+        if (!$desc) {
4342
+            return $objets[$type_objet] = false;
4343
+        }
4344
+
4345
+        // Si on demande le titre, on le gere en interne
4346
+        $champ_titre = "";
4347
+        if ($demande_titre) {
4348
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4349
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4350
+        }
4351
+        include_spip('base/abstract_sql');
4352
+        include_spip('base/connect_sql');
4353
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4354
+            '*' . $champ_titre,
4355
+            $desc['table_sql'],
4356
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4357
+        );
4358
+    }
4359
+
4360
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4361
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4362
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4363
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4364
+    else {
4365
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4366
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4367
+        } // Sinon on prend directement le champ SQL tel quel
4368
+        else {
4369
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4370
+        }
4371
+    }
4372
+
4373
+    // On va ensuite appliquer les traitements automatiques si besoin
4374
+    if (!$etoile) {
4375
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4376
+        // mais ce fonctionnement est a ameliorer !
4377
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4378
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4379
+    }
4380
+
4381
+    return $info_generee;
4382 4382
 }
4383 4383
 
4384 4384
 /**
@@ -4392,44 +4392,44 @@  discard block
 block discarded – undo
4392 4392
  * @return string
4393 4393
  */
4394 4394
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4395
-	if (!$champ) {
4396
-		return $texte;
4397
-	}
4395
+    if (!$champ) {
4396
+        return $texte;
4397
+    }
4398 4398
 	
4399
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4400
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4401
-	include_spip('inc/texte');
4399
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4400
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4401
+    include_spip('inc/texte');
4402 4402
 	
4403
-	$champ = strtoupper($champ);
4404
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4405
-	if (!$traitements or !is_array($traitements)) {
4406
-		return $texte;
4407
-	}
4403
+    $champ = strtoupper($champ);
4404
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4405
+    if (!$traitements or !is_array($traitements)) {
4406
+        return $texte;
4407
+    }
4408 4408
 
4409
-	$traitement = '';
4410
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4411
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4412
-		$table_objet = table_objet($table_objet);
4413
-		if (isset($traitements[$table_objet])) {
4414
-			$traitement = $traitements[$table_objet];
4415
-		}
4416
-	}
4417
-	if (!$traitement and isset($traitements[0])) {
4418
-		$traitement = $traitements[0];
4419
-	}
4420
-	// (sinon prendre le premier de la liste par defaut ?)
4409
+    $traitement = '';
4410
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4411
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4412
+        $table_objet = table_objet($table_objet);
4413
+        if (isset($traitements[$table_objet])) {
4414
+            $traitement = $traitements[$table_objet];
4415
+        }
4416
+    }
4417
+    if (!$traitement and isset($traitements[0])) {
4418
+        $traitement = $traitements[0];
4419
+    }
4420
+    // (sinon prendre le premier de la liste par defaut ?)
4421 4421
 
4422
-	if (!$traitement) {
4423
-		return $texte;
4424
-	}
4422
+    if (!$traitement) {
4423
+        return $texte;
4424
+    }
4425 4425
 
4426
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4426
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4427 4427
 
4428
-	// Fournir $connect et $Pile[0] au traitement si besoin
4429
-	$Pile = array(0 => $env);
4430
-	eval("\$texte = $traitement;");
4428
+    // Fournir $connect et $Pile[0] au traitement si besoin
4429
+    $Pile = array(0 => $env);
4430
+    eval("\$texte = $traitement;");
4431 4431
 
4432
-	return $texte;
4432
+    return $texte;
4433 4433
 }
4434 4434
 
4435 4435
 
@@ -4443,21 +4443,21 @@  discard block
 block discarded – undo
4443 4443
  * @return string
4444 4444
  */
4445 4445
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4446
-	include_spip('inc/liens');
4447
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4448
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4449
-	// le raccourcis n'est plus valide
4450
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4451
-	// on essaye avec generer_info_entite ?
4452
-	if (!strlen($titre) and !$connect) {
4453
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4454
-	}
4455
-	if (!strlen($titre)) {
4456
-		$titre = _T('info_sans_titre');
4457
-	}
4458
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4446
+    include_spip('inc/liens');
4447
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4448
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4449
+    // le raccourcis n'est plus valide
4450
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4451
+    // on essaye avec generer_info_entite ?
4452
+    if (!strlen($titre) and !$connect) {
4453
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4454
+    }
4455
+    if (!strlen($titre)) {
4456
+        $titre = _T('info_sans_titre');
4457
+    }
4458
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4459 4459
 
4460
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4460
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4461 4461
 }
4462 4462
 
4463 4463
 
@@ -4474,15 +4474,15 @@  discard block
 block discarded – undo
4474 4474
  * @return string
4475 4475
  */
4476 4476
 function wrap($texte, $wrap) {
4477
-	$balises = extraire_balises($wrap);
4478
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4479
-		$texte = $wrap . $texte;
4480
-		$regs = array_reverse($regs[1]);
4481
-		$wrap = "</" . implode("></", $regs) . ">";
4482
-		$texte = $texte . $wrap;
4483
-	}
4477
+    $balises = extraire_balises($wrap);
4478
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4479
+        $texte = $wrap . $texte;
4480
+        $regs = array_reverse($regs[1]);
4481
+        $wrap = "</" . implode("></", $regs) . ">";
4482
+        $texte = $texte . $wrap;
4483
+    }
4484 4484
 
4485
-	return $texte;
4485
+    return $texte;
4486 4486
 }
4487 4487
 
4488 4488
 
@@ -4502,43 +4502,43 @@  discard block
 block discarded – undo
4502 4502
  * @return array|mixed|string
4503 4503
  */
4504 4504
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4505
-	if (is_string($u)) {
4506
-		$u = typo($u);
4505
+    if (is_string($u)) {
4506
+        $u = typo($u);
4507 4507
 
4508
-		return $u;
4509
-	}
4508
+        return $u;
4509
+    }
4510 4510
 
4511
-	// caster $u en array si besoin
4512
-	if (is_object($u)) {
4513
-		$u = (array)$u;
4514
-	}
4511
+    // caster $u en array si besoin
4512
+    if (is_object($u)) {
4513
+        $u = (array)$u;
4514
+    }
4515 4515
 
4516
-	if (is_array($u)) {
4517
-		$out = "";
4518
-		// toutes les cles sont numeriques ?
4519
-		// et aucun enfant n'est un tableau
4520
-		// liste simple separee par des virgules
4521
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4522
-		$array_values = array_map('is_array', $u);
4523
-		$object_values = array_map('is_object', $u);
4524
-		if (array_sum($numeric_keys) == count($numeric_keys)
4525
-			and !array_sum($array_values)
4526
-			and !array_sum($object_values)
4527
-		) {
4528
-			return join(", ", array_map('filtre_print_dist', $u));
4529
-		}
4516
+    if (is_array($u)) {
4517
+        $out = "";
4518
+        // toutes les cles sont numeriques ?
4519
+        // et aucun enfant n'est un tableau
4520
+        // liste simple separee par des virgules
4521
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4522
+        $array_values = array_map('is_array', $u);
4523
+        $object_values = array_map('is_object', $u);
4524
+        if (array_sum($numeric_keys) == count($numeric_keys)
4525
+            and !array_sum($array_values)
4526
+            and !array_sum($object_values)
4527
+        ) {
4528
+            return join(", ", array_map('filtre_print_dist', $u));
4529
+        }
4530 4530
 
4531
-		// sinon on passe a la ligne et on indente
4532
-		$i_str = str_pad("", $indent, " ");
4533
-		foreach ($u as $k => $v) {
4534
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4535
-		}
4531
+        // sinon on passe a la ligne et on indente
4532
+        $i_str = str_pad("", $indent, " ");
4533
+        foreach ($u as $k => $v) {
4534
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4535
+        }
4536 4536
 
4537
-		return $out;
4538
-	}
4537
+        return $out;
4538
+    }
4539 4539
 
4540
-	// on sait pas quoi faire...
4541
-	return $u;
4540
+    // on sait pas quoi faire...
4541
+    return $u;
4542 4542
 }
4543 4543
 
4544 4544
 
@@ -4551,10 +4551,10 @@  discard block
 block discarded – undo
4551 4551
  * @return string|array
4552 4552
  */
4553 4553
 function objet_info($objet, $info) {
4554
-	$table = table_objet_sql($objet);
4555
-	$infos = lister_tables_objets_sql($table);
4554
+    $table = table_objet_sql($objet);
4555
+    $infos = lister_tables_objets_sql($table);
4556 4556
 
4557
-	return (isset($infos[$info]) ? $infos[$info] : '');
4557
+    return (isset($infos[$info]) ? $infos[$info] : '');
4558 4558
 }
4559 4559
 
4560 4560
 /**
@@ -4569,11 +4569,11 @@  discard block
 block discarded – undo
4569 4569
  *     Texte traduit du comptage, tel que '3 articles'
4570 4570
  */
4571 4571
 function objet_afficher_nb($nb, $objet) {
4572
-	if (!$nb) {
4573
-		return _T(objet_info($objet, 'info_aucun_objet'));
4574
-	} else {
4575
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4576
-	}
4572
+    if (!$nb) {
4573
+        return _T(objet_info($objet, 'info_aucun_objet'));
4574
+    } else {
4575
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4576
+    }
4577 4577
 }
4578 4578
 
4579 4579
 /**
@@ -4585,11 +4585,11 @@  discard block
 block discarded – undo
4585 4585
  * @return string
4586 4586
  */
4587 4587
 function objet_icone($objet, $taille = 24, $class='') {
4588
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4589
-	$icone = chemin_image($icone);
4590
-	$balise_img = charger_filtre('balise_img');
4588
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4589
+    $icone = chemin_image($icone);
4590
+    $balise_img = charger_filtre('balise_img');
4591 4591
 
4592
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4592
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4593 4593
 }
4594 4594
 
4595 4595
 /**
@@ -4610,12 +4610,12 @@  discard block
 block discarded – undo
4610 4610
  * @return string
4611 4611
  */
4612 4612
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4613
-	$chaine = explode(':',$chaine);
4614
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4615
-		return $t;
4616
-	}
4617
-	$chaine = implode(':',$chaine);
4618
-	return _T($chaine, $args, $options);
4613
+    $chaine = explode(':',$chaine);
4614
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4615
+        return $t;
4616
+    }
4617
+    $chaine = implode(':',$chaine);
4618
+    return _T($chaine, $args, $options);
4619 4619
 }
4620 4620
 
4621 4621
 /**
@@ -4629,17 +4629,17 @@  discard block
 block discarded – undo
4629 4629
  * @return string      Code HTML
4630 4630
  */
4631 4631
 function insert_head_css_conditionnel($flux) {
4632
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4633
-		and $p = strpos($flux, '<!-- insert_head -->')
4634
-	) {
4635
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4636
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4637
-			$p = $p1;
4638
-		}
4639
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4640
-	}
4632
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4633
+        and $p = strpos($flux, '<!-- insert_head -->')
4634
+    ) {
4635
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4636
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4637
+            $p = $p1;
4638
+        }
4639
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4640
+    }
4641 4641
 
4642
-	return $flux;
4642
+    return $flux;
4643 4643
 }
4644 4644
 
4645 4645
 /**
@@ -4660,69 +4660,69 @@  discard block
 block discarded – undo
4660 4660
  * @return string
4661 4661
  */
4662 4662
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4663
-	if (isset($contexte['format'])) {
4664
-		$extension = $contexte['format'];
4665
-		unset($contexte['format']);
4666
-	} else {
4667
-		$extension = "html";
4668
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4669
-			$extension = $m[1];
4670
-		}
4671
-	}
4672
-	// recuperer le contenu produit par le squelette
4673
-	$options['raw'] = true;
4674
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4675
-
4676
-	// calculer le nom de la css
4677
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4678
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4679
-	$contexte_implicite = calculer_contexte_implicite();
4680
-
4681
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4682
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4683
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4684
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4685
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4686
-	}
4687
-	else {
4688
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4689
-		ksort($contexte);
4690
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4691
-	}
4692
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4693
-
4694
-	// mettre a jour le fichier si il n'existe pas
4695
-	// ou trop ancien
4696
-	// le dernier fichier produit est toujours suffixe par .last
4697
-	// et recopie sur le fichier cible uniquement si il change
4698
-	if (!file_exists($filename)
4699
-		or !file_exists($filename . ".last")
4700
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4701
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4702
-	) {
4703
-		$contenu = $cache['texte'];
4704
-		// passer les urls en absolu si c'est une css
4705
-		if ($extension == "css") {
4706
-			$contenu = urls_absolues_css($contenu,
4707
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4708
-		}
4709
-
4710
-		$comment = '';
4711
-		// ne pas insérer de commentaire si c'est du json
4712
-		if ($extension != "json") {
4713
-			$comment = "/* #PRODUIRE{fond=$fond";
4714
-			foreach ($contexte as $k => $v) {
4715
-				$comment .= ",$k=$v";
4716
-			}
4717
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4718
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4719
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4720
-		}
4721
-		// et ecrire le fichier si il change
4722
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4723
-	}
4724
-
4725
-	return timestamp($filename);
4663
+    if (isset($contexte['format'])) {
4664
+        $extension = $contexte['format'];
4665
+        unset($contexte['format']);
4666
+    } else {
4667
+        $extension = "html";
4668
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4669
+            $extension = $m[1];
4670
+        }
4671
+    }
4672
+    // recuperer le contenu produit par le squelette
4673
+    $options['raw'] = true;
4674
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4675
+
4676
+    // calculer le nom de la css
4677
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4678
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4679
+    $contexte_implicite = calculer_contexte_implicite();
4680
+
4681
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4682
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4683
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4684
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4685
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4686
+    }
4687
+    else {
4688
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4689
+        ksort($contexte);
4690
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4691
+    }
4692
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4693
+
4694
+    // mettre a jour le fichier si il n'existe pas
4695
+    // ou trop ancien
4696
+    // le dernier fichier produit est toujours suffixe par .last
4697
+    // et recopie sur le fichier cible uniquement si il change
4698
+    if (!file_exists($filename)
4699
+        or !file_exists($filename . ".last")
4700
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4701
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4702
+    ) {
4703
+        $contenu = $cache['texte'];
4704
+        // passer les urls en absolu si c'est une css
4705
+        if ($extension == "css") {
4706
+            $contenu = urls_absolues_css($contenu,
4707
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4708
+        }
4709
+
4710
+        $comment = '';
4711
+        // ne pas insérer de commentaire si c'est du json
4712
+        if ($extension != "json") {
4713
+            $comment = "/* #PRODUIRE{fond=$fond";
4714
+            foreach ($contexte as $k => $v) {
4715
+                $comment .= ",$k=$v";
4716
+            }
4717
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4718
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4719
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4720
+        }
4721
+        // et ecrire le fichier si il change
4722
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4723
+    }
4724
+
4725
+    return timestamp($filename);
4726 4726
 }
4727 4727
 
4728 4728
 /**
@@ -4735,14 +4735,14 @@  discard block
 block discarded – undo
4735 4735
  *    $fichier auquel on a ajouté le timestamp
4736 4736
  */
4737 4737
 function timestamp($fichier) {
4738
-	if (!$fichier
4739
-		or !file_exists($fichier)
4740
-		or !$m = filemtime($fichier)
4741
-	) {
4742
-		return $fichier;
4743
-	}
4738
+    if (!$fichier
4739
+        or !file_exists($fichier)
4740
+        or !$m = filemtime($fichier)
4741
+    ) {
4742
+        return $fichier;
4743
+    }
4744 4744
 
4745
-	return "$fichier?$m";
4745
+    return "$fichier?$m";
4746 4746
 }
4747 4747
 
4748 4748
 /**
@@ -4752,11 +4752,11 @@  discard block
 block discarded – undo
4752 4752
  * @return string
4753 4753
  */
4754 4754
 function supprimer_timestamp($url) {
4755
-	if (strpos($url, "?") === false) {
4756
-		return $url;
4757
-	}
4755
+    if (strpos($url, "?") === false) {
4756
+        return $url;
4757
+    }
4758 4758
 
4759
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4759
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4760 4760
 }
4761 4761
 
4762 4762
 /**
@@ -4771,9 +4771,9 @@  discard block
 block discarded – undo
4771 4771
  * @return string
4772 4772
  */
4773 4773
 function filtre_nettoyer_titre_email_dist($titre) {
4774
-	include_spip('inc/envoyer_mail');
4774
+    include_spip('inc/envoyer_mail');
4775 4775
 
4776
-	return nettoyer_titre_email($titre);
4776
+    return nettoyer_titre_email($titre);
4777 4777
 }
4778 4778
 
4779 4779
 /**
@@ -4795,19 +4795,19 @@  discard block
 block discarded – undo
4795 4795
  * @return string
4796 4796
  */
4797 4797
 function filtre_chercher_rubrique_dist(
4798
-	$titre,
4799
-	$id_objet,
4800
-	$id_parent,
4801
-	$objet,
4802
-	$id_secteur,
4803
-	$restreint,
4804
-	$actionable = false,
4805
-	$retour_sans_cadre = false
4798
+    $titre,
4799
+    $id_objet,
4800
+    $id_parent,
4801
+    $objet,
4802
+    $id_secteur,
4803
+    $restreint,
4804
+    $actionable = false,
4805
+    $retour_sans_cadre = false
4806 4806
 ) {
4807
-	include_spip('inc/filtres_ecrire');
4807
+    include_spip('inc/filtres_ecrire');
4808 4808
 
4809
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4810
-		$retour_sans_cadre);
4809
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4810
+        $retour_sans_cadre);
4811 4811
 }
4812 4812
 
4813 4813
 /**
@@ -4836,56 +4836,56 @@  discard block
 block discarded – undo
4836 4836
  *     Chaîne vide si l'accès est autorisé
4837 4837
  */
4838 4838
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4839
-	if ($ok) {
4840
-		return '';
4841
-	}
4842
-
4843
-	// Vider tous les tampons
4844
-	$level = @ob_get_level();
4845
-	while ($level--) {
4846
-		@ob_end_clean();
4847
-	}
4848
-
4849
-	include_spip('inc/headers');
4850
-
4851
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4852
-	if ($url) {
4853
-		redirige_par_entete($url, '', $statut);
4854
-	}
4855
-
4856
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4857
-	if (!is_numeric($statut) and is_null($message)) {
4858
-		$message = $statut;
4859
-		$statut = 0;
4860
-	}
4861
-	if (!$message) {
4862
-		$message = '';
4863
-	}
4864
-	$statut = intval($statut);
4865
-
4866
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4867
-	if (test_espace_prive()) {
4868
-		if (!$statut or !in_array($statut, array(404, 403))) {
4869
-			$statut = 403;
4870
-		}
4871
-		http_status(403);
4872
-		$echec = charger_fonction('403', 'exec');
4873
-		$echec($message);
4874
-	} else {
4875
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4876
-		if (!$statut) {
4877
-			$statut = 404;
4878
-		}
4879
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4880
-		http_status($statut);
4881
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4882
-		if ($statut >= 400) {
4883
-			echo recuperer_fond("$statut", array('erreur' => $message));
4884
-		}
4885
-	}
4886
-
4887
-
4888
-	exit;
4839
+    if ($ok) {
4840
+        return '';
4841
+    }
4842
+
4843
+    // Vider tous les tampons
4844
+    $level = @ob_get_level();
4845
+    while ($level--) {
4846
+        @ob_end_clean();
4847
+    }
4848
+
4849
+    include_spip('inc/headers');
4850
+
4851
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4852
+    if ($url) {
4853
+        redirige_par_entete($url, '', $statut);
4854
+    }
4855
+
4856
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4857
+    if (!is_numeric($statut) and is_null($message)) {
4858
+        $message = $statut;
4859
+        $statut = 0;
4860
+    }
4861
+    if (!$message) {
4862
+        $message = '';
4863
+    }
4864
+    $statut = intval($statut);
4865
+
4866
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4867
+    if (test_espace_prive()) {
4868
+        if (!$statut or !in_array($statut, array(404, 403))) {
4869
+            $statut = 403;
4870
+        }
4871
+        http_status(403);
4872
+        $echec = charger_fonction('403', 'exec');
4873
+        $echec($message);
4874
+    } else {
4875
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4876
+        if (!$statut) {
4877
+            $statut = 404;
4878
+        }
4879
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4880
+        http_status($statut);
4881
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4882
+        if ($statut >= 400) {
4883
+            echo recuperer_fond("$statut", array('erreur' => $message));
4884
+        }
4885
+    }
4886
+
4887
+
4888
+    exit;
4889 4889
 }
4890 4890
 
4891 4891
 /**
@@ -4896,11 +4896,11 @@  discard block
 block discarded – undo
4896 4896
  * @return string
4897 4897
  */
4898 4898
 function filtre_compacte_dist($source, $format = null) {
4899
-	if (function_exists('compacte')) {
4900
-		return compacte($source, $format);
4901
-	}
4899
+    if (function_exists('compacte')) {
4900
+        return compacte($source, $format);
4901
+    }
4902 4902
 
4903
-	return $source;
4903
+    return $source;
4904 4904
 }
4905 4905
 
4906 4906
 
@@ -4912,29 +4912,29 @@  discard block
 block discarded – undo
4912 4912
  * @return string
4913 4913
  */
4914 4914
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
4915
-	$l = strlen($passe);
4916
-
4917
-	if ($l<=8 or !$afficher_partiellement){
4918
-		if (!$l) {
4919
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4920
-		}
4921
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
4922
-	}
4923
-
4924
-	if (is_null($portion_pourcent)) {
4925
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4926
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4927
-		}
4928
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4929
-	}
4930
-	if ($portion_pourcent >= 100) {
4931
-		return $passe;
4932
-	}
4933
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
4934
-	$e = max($e, 0);
4935
-	$mid = str_pad('',$l-2*$e,'*');
4936
-	if ($e>0 and strlen($mid)>8){
4937
-		$mid = '***...***';
4938
-	}
4939
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4915
+    $l = strlen($passe);
4916
+
4917
+    if ($l<=8 or !$afficher_partiellement){
4918
+        if (!$l) {
4919
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4920
+        }
4921
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
4922
+    }
4923
+
4924
+    if (is_null($portion_pourcent)) {
4925
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4926
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4927
+        }
4928
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4929
+    }
4930
+    if ($portion_pourcent >= 100) {
4931
+        return $passe;
4932
+    }
4933
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
4934
+    $e = max($e, 0);
4935
+    $mid = str_pad('',$l-2*$e,'*');
4936
+    if ($e>0 and strlen($mid)>8){
4937
+        $mid = '***...***';
4938
+    }
4939
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4940 4940
 }
4941 4941
\ No newline at end of file
Please login to merge, or discard this patch.