Completed
Push — master ( 4ccf90...a418a7 )
by cam
01:11
created
ecrire/inc/filtres.php 1 patch
Indentation   +2408 added lines, -2408 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_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,38 +77,38 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if (!strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if (!strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	list($h, $l) = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    list($h, $l) = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	list($h, $l) = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    list($h, $l) = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	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";
871
-	static $to = null;
870
+    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";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -911,40 +911,40 @@  discard block
 block discarded – undo
911 911
  */
912 912
 function texte_backend($texte) {
913 913
 
914
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
914
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
915 915
 
916
-	// si on a des liens ou des images, les passer en absolu
917
-	$texte = liens_absolus($texte);
916
+    // si on a des liens ou des images, les passer en absolu
917
+    $texte = liens_absolus($texte);
918 918
 
919
-	// echapper les tags &gt; &lt;
920
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
919
+    // echapper les tags &gt; &lt;
920
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
921 921
 
922
-	// importer les &eacute;
923
-	$texte = filtrer_entites($texte);
922
+    // importer les &eacute;
923
+    $texte = filtrer_entites($texte);
924 924
 
925
-	// " -> &quot; et tout ce genre de choses
926
-	$u = $GLOBALS['meta']['pcre_u'];
927
-	$texte = str_replace('&nbsp;', ' ', $texte);
928
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
-	$texte = entites_html($texte, false, false);
931
-	// mais bien echapper les double quotes !
932
-	$texte = str_replace('"', '&#034;', $texte);
925
+    // " -> &quot; et tout ce genre de choses
926
+    $u = $GLOBALS['meta']['pcre_u'];
927
+    $texte = str_replace('&nbsp;', ' ', $texte);
928
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
929
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
930
+    $texte = entites_html($texte, false, false);
931
+    // mais bien echapper les double quotes !
932
+    $texte = str_replace('"', '&#034;', $texte);
933 933
 
934
-	// verifier le charset
935
-	$texte = charset2unicode($texte);
934
+    // verifier le charset
935
+    $texte = charset2unicode($texte);
936 936
 
937
-	// Caracteres problematiques en iso-latin 1
938
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
-		$texte = str_replace(chr(156), '&#156;', $texte);
940
-		$texte = str_replace(chr(140), '&#140;', $texte);
941
-		$texte = str_replace(chr(159), '&#159;', $texte);
942
-	}
937
+    // Caracteres problematiques en iso-latin 1
938
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
939
+        $texte = str_replace(chr(156), '&#156;', $texte);
940
+        $texte = str_replace(chr(140), '&#140;', $texte);
941
+        $texte = str_replace(chr(159), '&#159;', $texte);
942
+    }
943 943
 
944
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
945
-	// et le caractere apostrophe alourdit les squelettes avec PHP
946
-	// ==> on les remplace par l'entite HTML
947
-	return str_replace($apostrophe, "'", $texte);
944
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
945
+    // et le caractere apostrophe alourdit les squelettes avec PHP
946
+    // ==> on les remplace par l'entite HTML
947
+    return str_replace($apostrophe, "'", $texte);
948 948
 }
949 949
 
950 950
 /**
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
  *     Texte encodé et quote pour XML
962 962
  */
963 963
 function texte_backendq($texte) {
964
-	return addslashes(texte_backend($texte));
964
+    return addslashes(texte_backend($texte));
965 965
 }
966 966
 
967 967
 
@@ -984,11 +984,11 @@  discard block
 block discarded – undo
984 984
  *     Numéro de titre, sinon chaîne vide
985 985
  **/
986 986
 function supprimer_numero($texte) {
987
-	return preg_replace(
988
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
-		'',
990
-		$texte
991
-	);
987
+    return preg_replace(
988
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
989
+        '',
990
+        $texte
991
+    );
992 992
 }
993 993
 
994 994
 /**
@@ -1011,17 +1011,17 @@  discard block
 block discarded – undo
1011 1011
  *     Numéro de titre, sinon chaîne vide
1012 1012
  **/
1013 1013
 function recuperer_numero($texte) {
1014
-	if (
1015
-		preg_match(
1016
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
-			$texte,
1018
-			$regs
1019
-		)
1020
-	) {
1021
-		return strval($regs[1]);
1022
-	} else {
1023
-		return '';
1024
-	}
1014
+    if (
1015
+        preg_match(
1016
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1017
+            $texte,
1018
+            $regs
1019
+        )
1020
+    ) {
1021
+        return strval($regs[1]);
1022
+    } else {
1023
+        return '';
1024
+    }
1025 1025
 }
1026 1026
 
1027 1027
 /**
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
  *     Texte converti
1049 1049
  **/
1050 1050
 function supprimer_tags($texte, $rempl = '') {
1051
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
-	// ne pas oublier un < final non ferme car coupe
1053
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
-	// mais qui peut aussi etre un simple signe plus petit que
1055
-	$texte = str_replace('<', '&lt;', $texte);
1051
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1052
+    // ne pas oublier un < final non ferme car coupe
1053
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1054
+    // mais qui peut aussi etre un simple signe plus petit que
1055
+    $texte = str_replace('<', '&lt;', $texte);
1056 1056
 
1057
-	return $texte;
1057
+    return $texte;
1058 1058
 }
1059 1059
 
1060 1060
 /**
@@ -1077,9 +1077,9 @@  discard block
 block discarded – undo
1077 1077
  *     Texte converti
1078 1078
  **/
1079 1079
 function echapper_tags($texte, $rempl = '') {
1080
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1080
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1100,18 +1100,18 @@  discard block
 block discarded – undo
1100 1100
  *     Texte converti
1101 1101
  **/
1102 1102
 function textebrut($texte) {
1103
-	$u = $GLOBALS['meta']['pcre_u'];
1104
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
-	$texte = preg_replace("/^\n+/", '', $texte);
1107
-	$texte = preg_replace("/\n+$/", '', $texte);
1108
-	$texte = preg_replace("/\n +/", "\n", $texte);
1109
-	$texte = supprimer_tags($texte);
1110
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
-	$texte = str_replace('&#8217;', "'", $texte);
1103
+    $u = $GLOBALS['meta']['pcre_u'];
1104
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1105
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1106
+    $texte = preg_replace("/^\n+/", '', $texte);
1107
+    $texte = preg_replace("/\n+$/", '', $texte);
1108
+    $texte = preg_replace("/\n +/", "\n", $texte);
1109
+    $texte = supprimer_tags($texte);
1110
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1111
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1112
+    $texte = str_replace('&#8217;', "'", $texte);
1113 1113
 
1114
-	return $texte;
1114
+    return $texte;
1115 1115
 }
1116 1116
 
1117 1117
 
@@ -1127,23 +1127,23 @@  discard block
 block discarded – undo
1127 1127
  *     Texte avec liens ouvrants
1128 1128
  **/
1129 1129
 function liens_ouvrants($texte) {
1130
-	if (
1131
-		preg_match_all(
1132
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
-			$texte,
1134
-			$liens,
1135
-			PREG_PATTERN_ORDER
1136
-		)
1137
-	) {
1138
-		foreach ($liens[0] as $a) {
1139
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
-			$ablank = inserer_attribut($a, 'rel', $rel);
1141
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1142
-			$texte = str_replace($a, $ablank, $texte);
1143
-		}
1144
-	}
1145
-
1146
-	return $texte;
1130
+    if (
1131
+        preg_match_all(
1132
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1133
+            $texte,
1134
+            $liens,
1135
+            PREG_PATTERN_ORDER
1136
+        )
1137
+    ) {
1138
+        foreach ($liens[0] as $a) {
1139
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1140
+            $ablank = inserer_attribut($a, 'rel', $rel);
1141
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1142
+            $texte = str_replace($a, $ablank, $texte);
1143
+        }
1144
+    }
1145
+
1146
+    return $texte;
1147 1147
 }
1148 1148
 
1149 1149
 /**
@@ -1153,22 +1153,22 @@  discard block
 block discarded – undo
1153 1153
  * @return string
1154 1154
  */
1155 1155
 function liens_nofollow($texte) {
1156
-	if (stripos($texte, '<a') === false) {
1157
-		return $texte;
1158
-	}
1156
+    if (stripos($texte, '<a') === false) {
1157
+        return $texte;
1158
+    }
1159 1159
 
1160
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
-		foreach ($regs[0] as $a) {
1162
-			$rel = extraire_attribut($a, 'rel');
1163
-			if (strpos($rel, 'nofollow') === false) {
1164
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1165
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1166
-				$texte = str_replace($a, $anofollow, $texte);
1167
-			}
1168
-		}
1169
-	}
1160
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1161
+        foreach ($regs[0] as $a) {
1162
+            $rel = extraire_attribut($a, 'rel');
1163
+            if (strpos($rel, 'nofollow') === false) {
1164
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1165
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1166
+                $texte = str_replace($a, $anofollow, $texte);
1167
+            }
1168
+        }
1169
+    }
1170 1170
 
1171
-	return $texte;
1171
+    return $texte;
1172 1172
 }
1173 1173
 
1174 1174
 /**
@@ -1187,12 +1187,12 @@  discard block
 block discarded – undo
1187 1187
  *     Texte sans paraghaphes
1188 1188
  **/
1189 1189
 function PtoBR($texte) {
1190
-	$u = $GLOBALS['meta']['pcre_u'];
1191
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1192
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1190
+    $u = $GLOBALS['meta']['pcre_u'];
1191
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1192
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1193
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1194 1194
 
1195
-	return $texte;
1195
+    return $texte;
1196 1196
 }
1197 1197
 
1198 1198
 
@@ -1217,14 +1217,14 @@  discard block
 block discarded – undo
1217 1217
  * @return string Texte encadré du style CSS
1218 1218
  */
1219 1219
 function lignes_longues($texte) {
1220
-	if (!strlen(trim($texte))) {
1221
-		return $texte;
1222
-	}
1223
-	include_spip('inc/texte');
1224
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
-		'div' : 'span';
1220
+    if (!strlen(trim($texte))) {
1221
+        return $texte;
1222
+    }
1223
+    include_spip('inc/texte');
1224
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1225
+        'div' : 'span';
1226 1226
 
1227
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1227
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1243,30 +1243,30 @@  discard block
 block discarded – undo
1243 1243
  * @return string Texte en majuscule
1244 1244
  */
1245 1245
 function majuscules($texte) {
1246
-	if (!strlen($texte)) {
1247
-		return '';
1248
-	}
1246
+    if (!strlen($texte)) {
1247
+        return '';
1248
+    }
1249 1249
 
1250
-	// Cas du turc
1251
-	if ($GLOBALS['spip_lang'] == 'tr') {
1252
-		# remplacer hors des tags et des entites
1253
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
-			foreach ($regs as $n => $match) {
1255
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
-			}
1257
-		}
1250
+    // Cas du turc
1251
+    if ($GLOBALS['spip_lang'] == 'tr') {
1252
+        # remplacer hors des tags et des entites
1253
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1254
+            foreach ($regs as $n => $match) {
1255
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1256
+            }
1257
+        }
1258 1258
 
1259
-		$texte = str_replace('i', '&#304;', $texte);
1259
+        $texte = str_replace('i', '&#304;', $texte);
1260 1260
 
1261
-		if ($regs) {
1262
-			foreach ($regs as $n => $match) {
1263
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
-			}
1265
-		}
1266
-	}
1261
+        if ($regs) {
1262
+            foreach ($regs as $n => $match) {
1263
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1264
+            }
1265
+        }
1266
+    }
1267 1267
 
1268
-	// Cas general
1269
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1268
+    // Cas general
1269
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1270 1270
 }
1271 1271
 
1272 1272
 /**
@@ -1284,29 +1284,29 @@  discard block
 block discarded – undo
1284 1284
  * @return string
1285 1285
  **/
1286 1286
 function taille_en_octets($taille) {
1287
-	if (!defined('_KILOBYTE')) {
1288
-		/**
1289
-		 * Définit le nombre d'octets dans un Kilobyte
1290
-		 *
1291
-		 * @var int
1292
-		 **/
1293
-		define('_KILOBYTE', 1024);
1294
-	}
1287
+    if (!defined('_KILOBYTE')) {
1288
+        /**
1289
+         * Définit le nombre d'octets dans un Kilobyte
1290
+         *
1291
+         * @var int
1292
+         **/
1293
+        define('_KILOBYTE', 1024);
1294
+    }
1295 1295
 
1296
-	if ($taille < 1) {
1297
-		return '';
1298
-	}
1299
-	if ($taille < _KILOBYTE) {
1300
-		$taille = _T('taille_octets', ['taille' => $taille]);
1301
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
-	} else {
1306
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
-	}
1296
+    if ($taille < 1) {
1297
+        return '';
1298
+    }
1299
+    if ($taille < _KILOBYTE) {
1300
+        $taille = _T('taille_octets', ['taille' => $taille]);
1301
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1302
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1303
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1304
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1305
+    } else {
1306
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1307
+    }
1308 1308
 
1309
-	return $taille;
1309
+    return $taille;
1310 1310
 }
1311 1311
 
1312 1312
 
@@ -1328,18 +1328,18 @@  discard block
 block discarded – undo
1328 1328
  *     Texte prêt pour être utilisé en attribut HTML
1329 1329
  **/
1330 1330
 function attribut_html($texte, $textebrut = true) {
1331
-	$u = $GLOBALS['meta']['pcre_u'];
1332
-	if ($textebrut) {
1333
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
-	}
1335
-	$texte = texte_backend($texte);
1336
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1331
+    $u = $GLOBALS['meta']['pcre_u'];
1332
+    if ($textebrut) {
1333
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1334
+    }
1335
+    $texte = texte_backend($texte);
1336
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337 1337
 
1338
-	return preg_replace(
1339
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
-		['&', '&#38;'],
1341
-		$texte
1342
-	);
1338
+    return preg_replace(
1339
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1340
+        ['&', '&#38;'],
1341
+        $texte
1342
+    );
1343 1343
 }
1344 1344
 
1345 1345
 
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
  *     URL ou chaîne vide
1360 1360
  **/
1361 1361
 function vider_url($url, $entites = true) {
1362
-	# un message pour abs_url
1363
-	$GLOBALS['mode_abs_url'] = 'url';
1364
-	$url = trim($url);
1365
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1362
+    # un message pour abs_url
1363
+    $GLOBALS['mode_abs_url'] = 'url';
1364
+    $url = trim($url);
1365
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1366 1366
 
1367
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1367
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1368 1368
 }
1369 1369
 
1370 1370
 
@@ -1379,10 +1379,10 @@  discard block
 block discarded – undo
1379 1379
  * @return string Adresse email maquillée
1380 1380
  **/
1381 1381
 function antispam($texte) {
1382
-	include_spip('inc/acces');
1383
-	$masque = creer_pass_aleatoire(3);
1382
+    include_spip('inc/acces');
1383
+    $masque = creer_pass_aleatoire(3);
1384 1384
 
1385
-	return preg_replace('/@/', " $masque ", $texte);
1385
+    return preg_replace('/@/', " $masque ", $texte);
1386 1386
 }
1387 1387
 
1388 1388
 /**
@@ -1414,12 +1414,12 @@  discard block
 block discarded – undo
1414 1414
  *     True si on a le droit d'accès, false sinon.
1415 1415
  **/
1416 1416
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1417
-	include_spip('inc/acces');
1418
-	if ($op) {
1419
-		$dir .= " $op $args";
1420
-	}
1417
+    include_spip('inc/acces');
1418
+    if ($op) {
1419
+        $dir .= " $op $args";
1420
+    }
1421 1421
 
1422
-	return verifier_low_sec($id_auteur, $cle, $dir);
1422
+    return verifier_low_sec($id_auteur, $cle, $dir);
1423 1423
 }
1424 1424
 
1425 1425
 /**
@@ -1444,11 +1444,11 @@  discard block
 block discarded – undo
1444 1444
  *     Retourne $texte, sinon $sinon.
1445 1445
  **/
1446 1446
 function sinon($texte, $sinon = '') {
1447
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1448
-		return $texte;
1449
-	} else {
1450
-		return $sinon;
1451
-	}
1447
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1448
+        return $texte;
1449
+    } else {
1450
+        return $sinon;
1451
+    }
1452 1452
 }
1453 1453
 
1454 1454
 /**
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
  * @return mixed
1473 1473
  **/
1474 1474
 function choixsivide($a, $vide, $pasvide) {
1475
-	return $a ? $pasvide : $vide;
1475
+    return $a ? $pasvide : $vide;
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
  * @return mixed
1497 1497
  **/
1498 1498
 function choixsiegal($a1, $a2, $v, $f) {
1499
-	return ($a1 == $a2) ? $v : $f;
1499
+    return ($a1 == $a2) ? $v : $f;
1500 1500
 }
1501 1501
 
1502 1502
 //
@@ -1515,13 +1515,13 @@  discard block
 block discarded – undo
1515 1515
  * @return string
1516 1516
  **/
1517 1517
 function filtrer_ical($texte) {
1518
-	#include_spip('inc/charsets');
1519
-	$texte = html2unicode($texte);
1520
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
-	$texte = preg_replace("/\n/", ' ', $texte);
1522
-	$texte = preg_replace('/,/', '\,', $texte);
1518
+    #include_spip('inc/charsets');
1519
+    $texte = html2unicode($texte);
1520
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1521
+    $texte = preg_replace("/\n/", ' ', $texte);
1522
+    $texte = preg_replace('/,/', '\,', $texte);
1523 1523
 
1524
-	return $texte;
1524
+    return $texte;
1525 1525
 }
1526 1526
 
1527 1527
 
@@ -1546,54 +1546,54 @@  discard block
 block discarded – undo
1546 1546
  * @return string
1547 1547
  **/
1548 1548
 function post_autobr($texte, $delim = "\n_ ") {
1549
-	if (!function_exists('echappe_html')) {
1550
-		include_spip('inc/texte_mini');
1551
-	}
1552
-	$texte = str_replace("\r\n", "\r", $texte);
1553
-	$texte = str_replace("\r", "\n", $texte);
1554
-
1555
-	if (preg_match(",\n+$,", $texte, $fin)) {
1556
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
-	} else {
1558
-		$fin = '';
1559
-	}
1560
-
1561
-	$texte = echappe_html($texte, '', true);
1562
-
1563
-	// echapper les modeles
1564
-	if (strpos($texte, '<') !== false) {
1565
-		include_spip('inc/lien');
1566
-		if (defined('_PREG_MODELE')) {
1567
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1569
-		}
1570
-	}
1571
-
1572
-	$debut = '';
1573
-	$suite = $texte;
1574
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1575
-		$debut .= substr($suite, 0, $t - 1);
1576
-		$suite = substr($suite, $t);
1577
-		$car = substr($suite, 0, 1);
1578
-		if (
1579
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
-		) {
1583
-			$debut .= $delim;
1584
-		} else {
1585
-			$debut .= "\n";
1586
-		}
1587
-		if (preg_match(",^\n+,", $suite, $regs)) {
1588
-			$debut .= $regs[0];
1589
-			$suite = substr($suite, strlen($regs[0]));
1590
-		}
1591
-	}
1592
-	$texte = $debut . $suite;
1593
-
1594
-	$texte = echappe_retour($texte);
1595
-
1596
-	return $texte . $fin;
1549
+    if (!function_exists('echappe_html')) {
1550
+        include_spip('inc/texte_mini');
1551
+    }
1552
+    $texte = str_replace("\r\n", "\r", $texte);
1553
+    $texte = str_replace("\r", "\n", $texte);
1554
+
1555
+    if (preg_match(",\n+$,", $texte, $fin)) {
1556
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1557
+    } else {
1558
+        $fin = '';
1559
+    }
1560
+
1561
+    $texte = echappe_html($texte, '', true);
1562
+
1563
+    // echapper les modeles
1564
+    if (strpos($texte, '<') !== false) {
1565
+        include_spip('inc/lien');
1566
+        if (defined('_PREG_MODELE')) {
1567
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1568
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1569
+        }
1570
+    }
1571
+
1572
+    $debut = '';
1573
+    $suite = $texte;
1574
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1575
+        $debut .= substr($suite, 0, $t - 1);
1576
+        $suite = substr($suite, $t);
1577
+        $car = substr($suite, 0, 1);
1578
+        if (
1579
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1580
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1581
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1582
+        ) {
1583
+            $debut .= $delim;
1584
+        } else {
1585
+            $debut .= "\n";
1586
+        }
1587
+        if (preg_match(",^\n+,", $suite, $regs)) {
1588
+            $debut .= $regs[0];
1589
+            $suite = substr($suite, strlen($regs[0]));
1590
+        }
1591
+    }
1592
+    $texte = $debut . $suite;
1593
+
1594
+    $texte = echappe_retour($texte);
1595
+
1596
+    return $texte . $fin;
1597 1597
 }
1598 1598
 
1599 1599
 
@@ -1634,47 +1634,47 @@  discard block
 block discarded – undo
1634 1634
  * @return string
1635 1635
  **/
1636 1636
 function extraire_idiome($letexte, $lang = null, $options = []) {
1637
-	static $traduire = false;
1638
-	if (
1639
-		$letexte
1640
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
-	) {
1642
-		if (!$traduire) {
1643
-			$traduire = charger_fonction('traduire', 'inc');
1644
-			include_spip('inc/lang');
1645
-		}
1646
-		if (!$lang) {
1647
-			$lang = $GLOBALS['spip_lang'];
1648
-		}
1649
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
-		if (is_bool($options)) {
1651
-			$options = ['echappe_span' => $options];
1652
-		}
1653
-		if (!isset($options['echappe_span'])) {
1654
-			$options = array_merge($options, ['echappe_span' => false]);
1655
-		}
1656
-
1657
-		foreach ($regs as $reg) {
1658
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
-			$desc = $traduire($cle, $lang, true);
1660
-			$l = $desc->langue;
1661
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
-			if (strlen($desc->texte)) {
1663
-				$trad = code_echappement($desc->texte, 'idiome', false);
1664
-				if ($l !== $lang) {
1665
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
-				}
1667
-				if (lang_dir($l) !== lang_dir($lang)) {
1668
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
-				}
1670
-				if (!$options['echappe_span']) {
1671
-					$trad = echappe_retour($trad, 'idiome');
1672
-				}
1673
-				$letexte = str_replace($reg[0], $trad, $letexte);
1674
-			}
1675
-		}
1676
-	}
1677
-	return $letexte;
1637
+    static $traduire = false;
1638
+    if (
1639
+        $letexte
1640
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1641
+    ) {
1642
+        if (!$traduire) {
1643
+            $traduire = charger_fonction('traduire', 'inc');
1644
+            include_spip('inc/lang');
1645
+        }
1646
+        if (!$lang) {
1647
+            $lang = $GLOBALS['spip_lang'];
1648
+        }
1649
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1650
+        if (is_bool($options)) {
1651
+            $options = ['echappe_span' => $options];
1652
+        }
1653
+        if (!isset($options['echappe_span'])) {
1654
+            $options = array_merge($options, ['echappe_span' => false]);
1655
+        }
1656
+
1657
+        foreach ($regs as $reg) {
1658
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1659
+            $desc = $traduire($cle, $lang, true);
1660
+            $l = $desc->langue;
1661
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1662
+            if (strlen($desc->texte)) {
1663
+                $trad = code_echappement($desc->texte, 'idiome', false);
1664
+                if ($l !== $lang) {
1665
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1666
+                }
1667
+                if (lang_dir($l) !== lang_dir($lang)) {
1668
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1669
+                }
1670
+                if (!$options['echappe_span']) {
1671
+                    $trad = echappe_retour($trad, 'idiome');
1672
+                }
1673
+                $letexte = str_replace($reg[0], $trad, $letexte);
1674
+            }
1675
+        }
1676
+    }
1677
+    return $letexte;
1678 1678
 }
1679 1679
 
1680 1680
 /**
@@ -1726,68 +1726,68 @@  discard block
 block discarded – undo
1726 1726
  **/
1727 1727
 function extraire_multi($letexte, $lang = null, $options = []) {
1728 1728
 
1729
-	if (
1730
-		$letexte
1731
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
-	) {
1733
-		if (!$lang) {
1734
-			$lang = $GLOBALS['spip_lang'];
1735
-		}
1736
-
1737
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
-		if (is_bool($options)) {
1739
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
-		}
1741
-		if (!isset($options['echappe_span'])) {
1742
-			$options = array_merge($options, ['echappe_span' => false]);
1743
-		}
1744
-		if (!isset($options['lang_defaut'])) {
1745
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
-		}
1747
-
1748
-		include_spip('inc/lang');
1749
-		foreach ($regs as $reg) {
1750
-			// chercher la version de la langue courante
1751
-			$trads = extraire_trads($reg[1]);
1752
-			if ($l = approcher_langue($trads, $lang)) {
1753
-				$trad = $trads[$l];
1754
-			} else {
1755
-				if ($options['lang_defaut'] == 'aucune') {
1756
-					$trad = '';
1757
-				} else {
1758
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
-					// ou la premiere dispo
1760
-					// mais typographier le texte selon les regles de celle-ci
1761
-					// Attention aux blocs multi sur plusieurs lignes
1762
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
-						$l = key($trads);
1764
-					}
1765
-					$trad = $trads[$l];
1766
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1767
-					$trad = $typographie($trad);
1768
-					// Tester si on echappe en span ou en div
1769
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1770
-					include_spip('inc/texte');
1771
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
-					if ($mode === 'div') {
1774
-						$trad = rtrim($trad) . "\n\n";
1775
-					}
1776
-					$trad = code_echappement($trad, 'multi', false, $mode);
1777
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
-					if (lang_dir($l) !== lang_dir($lang)) {
1779
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
-					}
1781
-					if (!$options['echappe_span']) {
1782
-						$trad = echappe_retour($trad, 'multi');
1783
-					}
1784
-				}
1785
-			}
1786
-			$letexte = str_replace($reg[0], $trad, $letexte);
1787
-		}
1788
-	}
1789
-
1790
-	return $letexte;
1729
+    if (
1730
+        $letexte
1731
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1732
+    ) {
1733
+        if (!$lang) {
1734
+            $lang = $GLOBALS['spip_lang'];
1735
+        }
1736
+
1737
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1738
+        if (is_bool($options)) {
1739
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1740
+        }
1741
+        if (!isset($options['echappe_span'])) {
1742
+            $options = array_merge($options, ['echappe_span' => false]);
1743
+        }
1744
+        if (!isset($options['lang_defaut'])) {
1745
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1746
+        }
1747
+
1748
+        include_spip('inc/lang');
1749
+        foreach ($regs as $reg) {
1750
+            // chercher la version de la langue courante
1751
+            $trads = extraire_trads($reg[1]);
1752
+            if ($l = approcher_langue($trads, $lang)) {
1753
+                $trad = $trads[$l];
1754
+            } else {
1755
+                if ($options['lang_defaut'] == 'aucune') {
1756
+                    $trad = '';
1757
+                } else {
1758
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1759
+                    // ou la premiere dispo
1760
+                    // mais typographier le texte selon les regles de celle-ci
1761
+                    // Attention aux blocs multi sur plusieurs lignes
1762
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1763
+                        $l = key($trads);
1764
+                    }
1765
+                    $trad = $trads[$l];
1766
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1767
+                    $trad = $typographie($trad);
1768
+                    // Tester si on echappe en span ou en div
1769
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1770
+                    include_spip('inc/texte');
1771
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1772
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1773
+                    if ($mode === 'div') {
1774
+                        $trad = rtrim($trad) . "\n\n";
1775
+                    }
1776
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1777
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1778
+                    if (lang_dir($l) !== lang_dir($lang)) {
1779
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1780
+                    }
1781
+                    if (!$options['echappe_span']) {
1782
+                        $trad = echappe_retour($trad, 'multi');
1783
+                    }
1784
+                }
1785
+            }
1786
+            $letexte = str_replace($reg[0], $trad, $letexte);
1787
+        }
1788
+    }
1789
+
1790
+    return $letexte;
1791 1791
 }
1792 1792
 
1793 1793
 /**
@@ -1803,20 +1803,20 @@  discard block
 block discarded – undo
1803 1803
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1804 1804
  **/
1805 1805
 function extraire_trads($bloc) {
1806
-	$lang = '';
1806
+    $lang = '';
1807 1807
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1808 1808
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1809
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
-		$texte = trim($regs[1]);
1811
-		if ($texte or $lang) {
1812
-			$trads[$lang] = $texte;
1813
-		}
1814
-		$bloc = substr($bloc, strlen($regs[0]));
1815
-		$lang = $regs[2];
1816
-	}
1817
-	$trads[$lang] = $bloc;
1809
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1810
+        $texte = trim($regs[1]);
1811
+        if ($texte or $lang) {
1812
+            $trads[$lang] = $texte;
1813
+        }
1814
+        $bloc = substr($bloc, strlen($regs[0]));
1815
+        $lang = $regs[2];
1816
+    }
1817
+    $trads[$lang] = $bloc;
1818 1818
 
1819
-	return $trads;
1819
+    return $trads;
1820 1820
 }
1821 1821
 
1822 1822
 
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
  * @return string L'initiale en majuscule
1828 1828
  */
1829 1829
 function filtre_initiale($nom) {
1830
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1830
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1831 1831
 }
1832 1832
 
1833 1833
 
@@ -1872,33 +1872,33 @@  discard block
 block discarded – undo
1872 1872
  *      - null (interne) : si on empile
1873 1873
  **/
1874 1874
 function unique($donnee, $famille = '', $cpt = false) {
1875
-	static $mem = [];
1876
-	// permettre de vider la pile et de la restaurer
1877
-	// pour le calcul de introduction...
1878
-	if ($famille == '_spip_raz_') {
1879
-		$tmp = $mem;
1880
-		$mem = [];
1881
-
1882
-		return $tmp;
1883
-	} elseif ($famille == '_spip_set_') {
1884
-		$mem = $donnee;
1885
-
1886
-		return;
1887
-	}
1888
-	// eviter une notice
1889
-	if (!isset($mem[$famille])) {
1890
-		$mem[$famille] = [];
1891
-	}
1892
-	if ($cpt) {
1893
-		return count($mem[$famille]);
1894
-	}
1895
-	// eviter une notice
1896
-	if (!isset($mem[$famille][$donnee])) {
1897
-		$mem[$famille][$donnee] = 0;
1898
-	}
1899
-	if (!($mem[$famille][$donnee]++)) {
1900
-		return $donnee;
1901
-	}
1875
+    static $mem = [];
1876
+    // permettre de vider la pile et de la restaurer
1877
+    // pour le calcul de introduction...
1878
+    if ($famille == '_spip_raz_') {
1879
+        $tmp = $mem;
1880
+        $mem = [];
1881
+
1882
+        return $tmp;
1883
+    } elseif ($famille == '_spip_set_') {
1884
+        $mem = $donnee;
1885
+
1886
+        return;
1887
+    }
1888
+    // eviter une notice
1889
+    if (!isset($mem[$famille])) {
1890
+        $mem[$famille] = [];
1891
+    }
1892
+    if ($cpt) {
1893
+        return count($mem[$famille]);
1894
+    }
1895
+    // eviter une notice
1896
+    if (!isset($mem[$famille][$donnee])) {
1897
+        $mem[$famille][$donnee] = 0;
1898
+    }
1899
+    if (!($mem[$famille][$donnee]++)) {
1900
+        return $donnee;
1901
+    }
1902 1902
 }
1903 1903
 
1904 1904
 
@@ -1928,16 +1928,16 @@  discard block
 block discarded – undo
1928 1928
  *     Une des valeurs en fonction du compteur.
1929 1929
  **/
1930 1930
 function alterner($i, ...$args) {
1931
-	// recuperer les arguments (attention fonctions un peu space)
1932
-	$num = count($args);
1931
+    // recuperer les arguments (attention fonctions un peu space)
1932
+    $num = count($args);
1933 1933
 
1934
-	if ($num === 1 && is_array($args[0])) {
1935
-		$args = $args[0];
1936
-		$num = count($args);
1937
-	}
1934
+    if ($num === 1 && is_array($args[0])) {
1935
+        $args = $args[0];
1936
+        $num = count($args);
1937
+    }
1938 1938
 
1939
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
-	return $args[(intval($i) - 1) % $num];
1939
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1940
+    return $args[(intval($i) - 1) % $num];
1941 1941
 }
1942 1942
 
1943 1943
 
@@ -1962,49 +1962,49 @@  discard block
 block discarded – undo
1962 1962
  *     - Tableau complet (si 2e argument)
1963 1963
  **/
1964 1964
 function extraire_attribut($balise, $attribut, $complet = false) {
1965
-	if (is_array($balise)) {
1966
-		array_walk(
1967
-			$balise,
1968
-			function (&$a, $key, $t) {
1969
-				$a = extraire_attribut($a, $t);
1970
-			},
1971
-			$attribut
1972
-		);
1973
-
1974
-		return $balise;
1975
-	}
1976
-	if (
1977
-		preg_match(
1978
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
-			. $attribut
1980
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
-			$balise,
1982
-			$r
1983
-		)
1984
-	) {
1985
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
-			$r[4] = substr($r[3], 1, -1);
1987
-			$r[3] = $r[3][0];
1988
-		} elseif ($r[3] !== '') {
1989
-			$r[4] = $r[3];
1990
-			$r[3] = '';
1991
-		} else {
1992
-			$r[4] = trim($r[2]);
1993
-		}
1994
-		$att = $r[4];
1995
-		if (strpos($att, '&#') !== false) {
1996
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
-		}
1998
-		$att = filtrer_entites($att);
1999
-	} else {
2000
-		$att = null;
2001
-	}
2002
-
2003
-	if ($complet) {
2004
-		return [$att, $r];
2005
-	} else {
2006
-		return $att;
2007
-	}
1965
+    if (is_array($balise)) {
1966
+        array_walk(
1967
+            $balise,
1968
+            function (&$a, $key, $t) {
1969
+                $a = extraire_attribut($a, $t);
1970
+            },
1971
+            $attribut
1972
+        );
1973
+
1974
+        return $balise;
1975
+    }
1976
+    if (
1977
+        preg_match(
1978
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1979
+            . $attribut
1980
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1981
+            $balise,
1982
+            $r
1983
+        )
1984
+    ) {
1985
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1986
+            $r[4] = substr($r[3], 1, -1);
1987
+            $r[3] = $r[3][0];
1988
+        } elseif ($r[3] !== '') {
1989
+            $r[4] = $r[3];
1990
+            $r[3] = '';
1991
+        } else {
1992
+            $r[4] = trim($r[2]);
1993
+        }
1994
+        $att = $r[4];
1995
+        if (strpos($att, '&#') !== false) {
1996
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1997
+        }
1998
+        $att = filtrer_entites($att);
1999
+    } else {
2000
+        $att = null;
2001
+    }
2002
+
2003
+    if ($complet) {
2004
+        return [$att, $r];
2005
+    } else {
2006
+        return $att;
2007
+    }
2008 2008
 }
2009 2009
 
2010 2010
 /**
@@ -2036,37 +2036,37 @@  discard block
 block discarded – undo
2036 2036
  *     Code html modifié
2037 2037
  **/
2038 2038
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2039
-	// preparer l'attribut
2040
-	// supprimer les &nbsp; etc mais pas les balises html
2041
-	// qui ont un sens dans un attribut value d'un input
2042
-	if ($proteger) {
2043
-		$val = attribut_html($val, false);
2044
-	}
2045
-
2046
-	// echapper les ' pour eviter tout bug
2047
-	$val = str_replace("'", '&#039;', $val);
2048
-	if ($vider and strlen($val) == 0) {
2049
-		$insert = '';
2050
-	} else {
2051
-		$insert = " $attribut='$val'";
2052
-	}
2053
-
2054
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
-
2056
-	if ($old !== null) {
2057
-		// Remplacer l'ancien attribut du meme nom
2058
-		$balise = $r[1] . $insert . $r[5];
2059
-	} else {
2060
-		// preferer une balise " />" (comme <img />)
2061
-		if (preg_match(',/>,', $balise)) {
2062
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
-		} // sinon une balise <a ...> ... </a>
2064
-		else {
2065
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
-		}
2067
-	}
2068
-
2069
-	return $balise;
2039
+    // preparer l'attribut
2040
+    // supprimer les &nbsp; etc mais pas les balises html
2041
+    // qui ont un sens dans un attribut value d'un input
2042
+    if ($proteger) {
2043
+        $val = attribut_html($val, false);
2044
+    }
2045
+
2046
+    // echapper les ' pour eviter tout bug
2047
+    $val = str_replace("'", '&#039;', $val);
2048
+    if ($vider and strlen($val) == 0) {
2049
+        $insert = '';
2050
+    } else {
2051
+        $insert = " $attribut='$val'";
2052
+    }
2053
+
2054
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2055
+
2056
+    if ($old !== null) {
2057
+        // Remplacer l'ancien attribut du meme nom
2058
+        $balise = $r[1] . $insert . $r[5];
2059
+    } else {
2060
+        // preferer une balise " />" (comme <img />)
2061
+        if (preg_match(',/>,', $balise)) {
2062
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2063
+        } // sinon une balise <a ...> ... </a>
2064
+        else {
2065
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2066
+        }
2067
+    }
2068
+
2069
+    return $balise;
2070 2070
 }
2071 2071
 
2072 2072
 /**
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
  * @return string Code HTML sans l'attribut
2085 2085
  **/
2086 2086
 function vider_attribut($balise, $attribut) {
2087
-	return inserer_attribut($balise, $attribut, '', false, true);
2087
+    return inserer_attribut($balise, $attribut, '', false, true);
2088 2088
 }
2089 2089
 
2090 2090
 /**
@@ -2096,56 +2096,56 @@  discard block
 block discarded – undo
2096 2096
  * @return string
2097 2097
  */
2098 2098
 function modifier_class($balise, $class, $operation = 'ajouter') {
2099
-	if (is_string($class)) {
2100
-		$class = explode(' ', trim($class));
2101
-	}
2102
-	$class = array_filter($class);
2103
-
2104
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2105
-	if (preg_match(',[^\w-],', implode('', $class))) {
2106
-		return $balise;
2107
-	}
2108
-
2109
-	if ($class) {
2110
-		$class = array_unique($class);
2111
-		$class_courante = extraire_attribut($balise, 'class');
2112
-
2113
-		$class_new = $class_courante;
2114
-		foreach ($class as $c) {
2115
-			if ($c) {
2116
-				$is_class_presente = false;
2117
-				if (
2118
-					strpos($class_courante, $c) !== false
2119
-					and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
-				) {
2121
-					$is_class_presente = true;
2122
-				}
2123
-				if (
2124
-					in_array($operation, ['ajouter', 'commuter'])
2125
-					and !$is_class_presente
2126
-				) {
2127
-					$class_new = rtrim($class_new) . ' ' . $c;
2128
-				}
2129
-				elseif (
2130
-					in_array($operation, ['supprimer', 'commuter'])
2131
-					and $is_class_presente
2132
-				) {
2133
-					$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
-				}
2135
-			}
2136
-		}
2137
-
2138
-		if ($class_new !== $class_courante) {
2139
-			if (strlen($class_new)) {
2140
-				$balise = inserer_attribut($balise, 'class', $class_new);
2141
-			}
2142
-			elseif ($class_courante) {
2143
-				$balise = vider_attribut($balise, 'class');
2144
-			}
2145
-		}
2146
-	}
2147
-
2148
-	return $balise;
2099
+    if (is_string($class)) {
2100
+        $class = explode(' ', trim($class));
2101
+    }
2102
+    $class = array_filter($class);
2103
+
2104
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2105
+    if (preg_match(',[^\w-],', implode('', $class))) {
2106
+        return $balise;
2107
+    }
2108
+
2109
+    if ($class) {
2110
+        $class = array_unique($class);
2111
+        $class_courante = extraire_attribut($balise, 'class');
2112
+
2113
+        $class_new = $class_courante;
2114
+        foreach ($class as $c) {
2115
+            if ($c) {
2116
+                $is_class_presente = false;
2117
+                if (
2118
+                    strpos($class_courante, $c) !== false
2119
+                    and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2120
+                ) {
2121
+                    $is_class_presente = true;
2122
+                }
2123
+                if (
2124
+                    in_array($operation, ['ajouter', 'commuter'])
2125
+                    and !$is_class_presente
2126
+                ) {
2127
+                    $class_new = rtrim($class_new) . ' ' . $c;
2128
+                }
2129
+                elseif (
2130
+                    in_array($operation, ['supprimer', 'commuter'])
2131
+                    and $is_class_presente
2132
+                ) {
2133
+                    $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2134
+                }
2135
+            }
2136
+        }
2137
+
2138
+        if ($class_new !== $class_courante) {
2139
+            if (strlen($class_new)) {
2140
+                $balise = inserer_attribut($balise, 'class', $class_new);
2141
+            }
2142
+            elseif ($class_courante) {
2143
+                $balise = vider_attribut($balise, 'class');
2144
+            }
2145
+        }
2146
+    }
2147
+
2148
+    return $balise;
2149 2149
 }
2150 2150
 
2151 2151
 /**
@@ -2155,7 +2155,7 @@  discard block
 block discarded – undo
2155 2155
  * @return string
2156 2156
  */
2157 2157
 function ajouter_class($balise, $class) {
2158
-	return modifier_class($balise, $class, 'ajouter');
2158
+    return modifier_class($balise, $class, 'ajouter');
2159 2159
 }
2160 2160
 
2161 2161
 /**
@@ -2165,7 +2165,7 @@  discard block
 block discarded – undo
2165 2165
  * @return string
2166 2166
  */
2167 2167
 function supprimer_class($balise, $class) {
2168
-	return modifier_class($balise, $class, 'supprimer');
2168
+    return modifier_class($balise, $class, 'supprimer');
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
  * @return string
2177 2177
  */
2178 2178
 function commuter_class($balise, $class) {
2179
-	return modifier_class($balise, $class, 'commuter');
2179
+    return modifier_class($balise, $class, 'commuter');
2180 2180
 }
2181 2181
 
2182 2182
 /**
@@ -2187,19 +2187,19 @@  discard block
 block discarded – undo
2187 2187
  * @return string
2188 2188
  */
2189 2189
 function tester_config($id, $mode = '') {
2190
-	include_spip('action/inscrire_auteur');
2190
+    include_spip('action/inscrire_auteur');
2191 2191
 
2192
-	return tester_statut_inscription($mode, $id);
2192
+    return tester_statut_inscription($mode, $id);
2193 2193
 }
2194 2194
 
2195 2195
 //
2196 2196
 // Quelques fonctions de calcul arithmetique
2197 2197
 //
2198 2198
 function floatstr($a) {
2199
- return str_replace(',', '.', (string)floatval($a));
2199
+    return str_replace(',', '.', (string)floatval($a));
2200 2200
 }
2201 2201
 function strize($f, $a, $b) {
2202
- return floatstr($f(floatstr($a), floatstr($b)));
2202
+    return floatstr($f(floatstr($a), floatstr($b)));
2203 2203
 }
2204 2204
 
2205 2205
 /**
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
  * @return int $a+$b
2219 2219
  **/
2220 2220
 function plus($a, $b) {
2221
-	return $a + $b;
2221
+    return $a + $b;
2222 2222
 }
2223 2223
 function strplus($a, $b) {
2224 2224
 return strize('plus', $a, $b);
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
  * @return int $a-$b
2240 2240
  **/
2241 2241
 function moins($a, $b) {
2242
-	return $a - $b;
2242
+    return $a - $b;
2243 2243
 }
2244 2244
 function strmoins($a, $b) {
2245 2245
 return strize('moins', $a, $b);
@@ -2262,7 +2262,7 @@  discard block
 block discarded – undo
2262 2262
  * @return int $a*$b
2263 2263
  **/
2264 2264
 function mult($a, $b) {
2265
-	return $a * $b;
2265
+    return $a * $b;
2266 2266
 }
2267 2267
 function strmult($a, $b) {
2268 2268
 return strize('mult', $a, $b);
@@ -2285,7 +2285,7 @@  discard block
 block discarded – undo
2285 2285
  * @return int $a/$b (ou 0 si $b est nul)
2286 2286
  **/
2287 2287
 function div($a, $b) {
2288
-	return $b ? $a / $b : 0;
2288
+    return $b ? $a / $b : 0;
2289 2289
 }
2290 2290
 function strdiv($a, $b) {
2291 2291
 return strize('div', $a, $b);
@@ -2309,7 +2309,7 @@  discard block
 block discarded – undo
2309 2309
  * @return int ($nb % $mod) + $add
2310 2310
  **/
2311 2311
 function modulo($nb, $mod, $add = 0) {
2312
-	return ($mod ? $nb % $mod : 0) + $add;
2312
+    return ($mod ? $nb % $mod : 0) + $add;
2313 2313
 }
2314 2314
 
2315 2315
 
@@ -2324,24 +2324,24 @@  discard block
 block discarded – undo
2324 2324
  *      - true sinon
2325 2325
  **/
2326 2326
 function nom_acceptable($nom) {
2327
-	if (!is_string($nom)) {
2328
-		return false;
2329
-	}
2330
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2331
-		define('_TAGS_NOM_AUTEUR', '');
2332
-	}
2333
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
-	foreach ($tags_acceptes as $tag) {
2335
-		if (strlen($tag)) {
2336
-			$remp1[] = '<' . trim($tag) . '>';
2337
-			$remp1[] = '</' . trim($tag) . '>';
2338
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2339
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2340
-		}
2341
-	}
2342
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2327
+    if (!is_string($nom)) {
2328
+        return false;
2329
+    }
2330
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2331
+        define('_TAGS_NOM_AUTEUR', '');
2332
+    }
2333
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2334
+    foreach ($tags_acceptes as $tag) {
2335
+        if (strlen($tag)) {
2336
+            $remp1[] = '<' . trim($tag) . '>';
2337
+            $remp1[] = '</' . trim($tag) . '>';
2338
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2339
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2340
+        }
2341
+    }
2342
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2343 2343
 
2344
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2344
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2345 2345
 }
2346 2346
 
2347 2347
 
@@ -2357,14 +2357,14 @@  discard block
 block discarded – undo
2357 2357
  *      - renvoie un tableau si l'entree est un tableau
2358 2358
  **/
2359 2359
 function email_valide($adresses) {
2360
-	if (is_array($adresses)) {
2361
-		$adresses = array_map('email_valide', $adresses);
2362
-		$adresses = array_filter($adresses);
2363
-		return $adresses;
2364
-	}
2360
+    if (is_array($adresses)) {
2361
+        $adresses = array_map('email_valide', $adresses);
2362
+        $adresses = array_filter($adresses);
2363
+        return $adresses;
2364
+    }
2365 2365
 
2366
-	$email_valide = charger_fonction('email_valide', 'inc');
2367
-	return $email_valide($adresses);
2366
+    $email_valide = charger_fonction('email_valide', 'inc');
2367
+    return $email_valide($adresses);
2368 2368
 }
2369 2369
 
2370 2370
 /**
@@ -2378,27 +2378,27 @@  discard block
 block discarded – undo
2378 2378
  * @return string Texte
2379 2379
  **/
2380 2380
 function afficher_enclosures($tags) {
2381
-	$s = [];
2382
-	foreach (extraire_balises($tags, 'a') as $tag) {
2383
-		if (
2384
-			extraire_attribut($tag, 'rel') == 'enclosure'
2385
-			and $t = extraire_attribut($tag, 'href')
2386
-		) {
2387
-			$s[] = preg_replace(
2388
-				',>[^<]+</a>,S',
2389
-				'>'
2390
-				. http_img_pack(
2391
-					'attachment-16.png',
2392
-					$t,
2393
-					'title="' . attribut_html($t) . '"'
2394
-				)
2395
-				. '</a>',
2396
-				$tag
2397
-			);
2398
-		}
2399
-	}
2400
-
2401
-	return join('&nbsp;', $s);
2381
+    $s = [];
2382
+    foreach (extraire_balises($tags, 'a') as $tag) {
2383
+        if (
2384
+            extraire_attribut($tag, 'rel') == 'enclosure'
2385
+            and $t = extraire_attribut($tag, 'href')
2386
+        ) {
2387
+            $s[] = preg_replace(
2388
+                ',>[^<]+</a>,S',
2389
+                '>'
2390
+                . http_img_pack(
2391
+                    'attachment-16.png',
2392
+                    $t,
2393
+                    'title="' . attribut_html($t) . '"'
2394
+                )
2395
+                . '</a>',
2396
+                $tag
2397
+            );
2398
+        }
2399
+    }
2400
+
2401
+    return join('&nbsp;', $s);
2402 2402
 }
2403 2403
 
2404 2404
 /**
@@ -2413,15 +2413,15 @@  discard block
 block discarded – undo
2413 2413
  * @return string Liens trouvés
2414 2414
  **/
2415 2415
 function afficher_tags($tags, $rels = 'tag,directory') {
2416
-	$s = [];
2417
-	foreach (extraire_balises($tags, 'a') as $tag) {
2418
-		$rel = extraire_attribut($tag, 'rel');
2419
-		if (strstr(",$rels,", ",$rel,")) {
2420
-			$s[] = $tag;
2421
-		}
2422
-	}
2416
+    $s = [];
2417
+    foreach (extraire_balises($tags, 'a') as $tag) {
2418
+        $rel = extraire_attribut($tag, 'rel');
2419
+        if (strstr(",$rels,", ",$rel,")) {
2420
+            $s[] = $tag;
2421
+        }
2422
+    }
2423 2423
 
2424
-	return join(', ', $s);
2424
+    return join(', ', $s);
2425 2425
 }
2426 2426
 
2427 2427
 
@@ -2443,21 +2443,21 @@  discard block
 block discarded – undo
2443 2443
  * @return string Tag HTML `<a>` avec microformat.
2444 2444
  **/
2445 2445
 function enclosure2microformat($e) {
2446
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2448
-	}
2449
-	$type = extraire_attribut($e, 'type');
2450
-	if (!$length = extraire_attribut($e, 'length')) {
2451
-		# <media:content : longeur dans fileSize. On tente.
2452
-		$length = extraire_attribut($e, 'fileSize');
2453
-	}
2454
-	$fichier = basename($url);
2446
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2447
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2448
+    }
2449
+    $type = extraire_attribut($e, 'type');
2450
+    if (!$length = extraire_attribut($e, 'length')) {
2451
+        # <media:content : longeur dans fileSize. On tente.
2452
+        $length = extraire_attribut($e, 'fileSize');
2453
+    }
2454
+    $fichier = basename($url);
2455 2455
 
2456
-	return '<a rel="enclosure"'
2457
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
-	. '>' . $fichier . '</a>';
2456
+    return '<a rel="enclosure"'
2457
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2458
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2459
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2460
+    . '>' . $fichier . '</a>';
2461 2461
 }
2462 2462
 
2463 2463
 /**
@@ -2475,24 +2475,24 @@  discard block
 block discarded – undo
2475 2475
  * @return string Tags RSS `<enclosure>`.
2476 2476
  **/
2477 2477
 function microformat2enclosure($tags) {
2478
-	$enclosures = [];
2479
-	foreach (extraire_balises($tags, 'a') as $e) {
2480
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2482
-			$type = extraire_attribut($e, 'type');
2483
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
-				$length = intval(extraire_attribut($e, 'length'));
2485
-			} # vieux data
2486
-			$fichier = basename($url);
2487
-			$enclosures[] = '<enclosure'
2488
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
-				. ($length ? ' length="' . $length . '"' : '')
2491
-				. ' />';
2492
-		}
2493
-	}
2478
+    $enclosures = [];
2479
+    foreach (extraire_balises($tags, 'a') as $e) {
2480
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2481
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2482
+            $type = extraire_attribut($e, 'type');
2483
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2484
+                $length = intval(extraire_attribut($e, 'length'));
2485
+            } # vieux data
2486
+            $fichier = basename($url);
2487
+            $enclosures[] = '<enclosure'
2488
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2489
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2490
+                . ($length ? ' length="' . $length . '"' : '')
2491
+                . ' />';
2492
+        }
2493
+    }
2494 2494
 
2495
-	return join("\n", $enclosures);
2495
+    return join("\n", $enclosures);
2496 2496
 }
2497 2497
 
2498 2498
 
@@ -2508,16 +2508,16 @@  discard block
 block discarded – undo
2508 2508
  * @return string Tags RSS Atom `<dc:subject>`.
2509 2509
  **/
2510 2510
 function tags2dcsubject($tags) {
2511
-	$subjects = '';
2512
-	foreach (extraire_balises($tags, 'a') as $e) {
2513
-		if (extraire_attribut($e, 'rel') == 'tag') {
2514
-			$subjects .= '<dc:subject>'
2515
-				. texte_backend(textebrut($e))
2516
-				. '</dc:subject>' . "\n";
2517
-		}
2518
-	}
2511
+    $subjects = '';
2512
+    foreach (extraire_balises($tags, 'a') as $e) {
2513
+        if (extraire_attribut($e, 'rel') == 'tag') {
2514
+            $subjects .= '<dc:subject>'
2515
+                . texte_backend(textebrut($e))
2516
+                . '</dc:subject>' . "\n";
2517
+        }
2518
+    }
2519 2519
 
2520
-	return $subjects;
2520
+    return $subjects;
2521 2521
 }
2522 2522
 
2523 2523
 /**
@@ -2546,27 +2546,27 @@  discard block
 block discarded – undo
2546 2546
  *     - Tableau de résultats, si tableau en entrée.
2547 2547
  **/
2548 2548
 function extraire_balise($texte, $tag = 'a') {
2549
-	if (is_array($texte)) {
2550
-		array_walk(
2551
-			$texte,
2552
-			function (&$a, $key, $t) {
2553
-				$a = extraire_balise($a, $t);
2554
-			},
2555
-			$tag
2556
-		);
2557
-
2558
-		return $texte;
2559
-	}
2560
-
2561
-	if (
2562
-		preg_match(
2563
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
-			$texte,
2565
-			$regs
2566
-		)
2567
-	) {
2568
-		return $regs[0];
2569
-	}
2549
+    if (is_array($texte)) {
2550
+        array_walk(
2551
+            $texte,
2552
+            function (&$a, $key, $t) {
2553
+                $a = extraire_balise($a, $t);
2554
+            },
2555
+            $tag
2556
+        );
2557
+
2558
+        return $texte;
2559
+    }
2560
+
2561
+    if (
2562
+        preg_match(
2563
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2564
+            $texte,
2565
+            $regs
2566
+        )
2567
+    ) {
2568
+        return $regs[0];
2569
+    }
2570 2570
 }
2571 2571
 
2572 2572
 /**
@@ -2594,30 +2594,30 @@  discard block
 block discarded – undo
2594 2594
  *     - Tableau de résultats, si tableau en entrée.
2595 2595
  **/
2596 2596
 function extraire_balises($texte, $tag = 'a') {
2597
-	if (is_array($texte)) {
2598
-		array_walk(
2599
-			$texte,
2600
-			function (&$a, $key, $t) {
2601
-				$a = extraire_balises($a, $t);
2602
-			},
2603
-			$tag
2604
-		);
2605
-
2606
-		return $texte;
2607
-	}
2608
-
2609
-	if (
2610
-		preg_match_all(
2611
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
-			$texte,
2613
-			$regs,
2614
-			PREG_PATTERN_ORDER
2615
-		)
2616
-	) {
2617
-		return $regs[0];
2618
-	} else {
2619
-		return [];
2620
-	}
2597
+    if (is_array($texte)) {
2598
+        array_walk(
2599
+            $texte,
2600
+            function (&$a, $key, $t) {
2601
+                $a = extraire_balises($a, $t);
2602
+            },
2603
+            $tag
2604
+        );
2605
+
2606
+        return $texte;
2607
+    }
2608
+
2609
+    if (
2610
+        preg_match_all(
2611
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2612
+            $texte,
2613
+            $regs,
2614
+            PREG_PATTERN_ORDER
2615
+        )
2616
+    ) {
2617
+        return $regs[0];
2618
+    } else {
2619
+        return [];
2620
+    }
2621 2621
 }
2622 2622
 
2623 2623
 /**
@@ -2646,11 +2646,11 @@  discard block
 block discarded – undo
2646 2646
  *     - `$def` si on n'a pas transmis de tableau
2647 2647
  **/
2648 2648
 function in_any($val, $vals, $def = '') {
2649
-	if (!is_array($vals) and $v = unserialize($vals)) {
2650
-		$vals = $v;
2651
-	}
2649
+    if (!is_array($vals) and $v = unserialize($vals)) {
2650
+        $vals = $v;
2651
+    }
2652 2652
 
2653
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2653
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2654 2654
 }
2655 2655
 
2656 2656
 
@@ -2671,12 +2671,12 @@  discard block
 block discarded – undo
2671 2671
  *     Résultat du calcul
2672 2672
  **/
2673 2673
 function valeur_numerique($expr) {
2674
-	$a = 0;
2675
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
-		eval("\$a = $expr;");
2677
-	}
2674
+    $a = 0;
2675
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2676
+        eval("\$a = $expr;");
2677
+    }
2678 2678
 
2679
-	return intval($a);
2679
+    return intval($a);
2680 2680
 }
2681 2681
 
2682 2682
 /**
@@ -2695,7 +2695,7 @@  discard block
 block discarded – undo
2695 2695
  *      Retourne `$a*$b/$c`
2696 2696
  **/
2697 2697
 function regledetrois($a, $b, $c) {
2698
-	return round($a * $b / $c);
2698
+    return round($a * $b / $c);
2699 2699
 }
2700 2700
 
2701 2701
 
@@ -2719,77 +2719,77 @@  discard block
 block discarded – undo
2719 2719
  **/
2720 2720
 function form_hidden($action) {
2721 2721
 
2722
-	$contexte = [];
2723
-	include_spip('inc/urls');
2724
-	if (
2725
-		$p = urls_decoder_url($action, '')
2726
-		and reset($p)
2727
-	) {
2728
-		$fond = array_shift($p);
2729
-		if ($fond != '404') {
2730
-			$contexte = array_shift($p);
2731
-			$contexte['page'] = $fond;
2732
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
-		}
2734
-	}
2735
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
-		unset($contexte['type']);
2738
-	}
2739
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
-		unset($contexte['type-page']);
2741
-	}
2742
-
2743
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2745
-	$values = [];
2746
-
2747
-	// d'abord avec celles de l'url
2748
-	if (false !== ($p = strpos($action, '?'))) {
2749
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
-			$c = explode('=', $c, 2);
2751
-			$var = array_shift($c);
2752
-			$val = array_shift($c);
2753
-			if ($var) {
2754
-				$val = rawurldecode($val);
2755
-				$var = rawurldecode($var); // decoder les [] eventuels
2756
-				if (preg_match(',\[\]$,S', $var)) {
2757
-					$values[] = [$var, $val];
2758
-				} else {
2759
-					if (!isset($values[$var])) {
2760
-						$values[$var] = [$var, $val];
2761
-					}
2762
-				}
2763
-			}
2764
-		}
2765
-	}
2766
-
2767
-	// ensuite avec celles du contexte, sans doublonner !
2768
-	foreach ($contexte as $var => $val) {
2769
-		if (preg_match(',\[\]$,S', $var)) {
2770
-			$values[] = [$var, $val];
2771
-		} else {
2772
-			if (!isset($values[$var])) {
2773
-				$values[$var] = [$var, $val];
2774
-			}
2775
-		}
2776
-	}
2777
-
2778
-	// puis on rassemble le tout
2779
-	$hidden = [];
2780
-	foreach ($values as $value) {
2781
-		list($var, $val) = $value;
2782
-		$hidden[] = '<input name="'
2783
-			. entites_html($var)
2784
-			. '"'
2785
-			. (is_null($val)
2786
-				? ''
2787
-				: ' value="' . entites_html($val) . '"'
2788
-			)
2789
-			. ' type="hidden"' . "\n/>";
2790
-	}
2791
-
2792
-	return join('', $hidden);
2722
+    $contexte = [];
2723
+    include_spip('inc/urls');
2724
+    if (
2725
+        $p = urls_decoder_url($action, '')
2726
+        and reset($p)
2727
+    ) {
2728
+        $fond = array_shift($p);
2729
+        if ($fond != '404') {
2730
+            $contexte = array_shift($p);
2731
+            $contexte['page'] = $fond;
2732
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2733
+        }
2734
+    }
2735
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2736
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2737
+        unset($contexte['type']);
2738
+    }
2739
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2740
+        unset($contexte['type-page']);
2741
+    }
2742
+
2743
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2744
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2745
+    $values = [];
2746
+
2747
+    // d'abord avec celles de l'url
2748
+    if (false !== ($p = strpos($action, '?'))) {
2749
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2750
+            $c = explode('=', $c, 2);
2751
+            $var = array_shift($c);
2752
+            $val = array_shift($c);
2753
+            if ($var) {
2754
+                $val = rawurldecode($val);
2755
+                $var = rawurldecode($var); // decoder les [] eventuels
2756
+                if (preg_match(',\[\]$,S', $var)) {
2757
+                    $values[] = [$var, $val];
2758
+                } else {
2759
+                    if (!isset($values[$var])) {
2760
+                        $values[$var] = [$var, $val];
2761
+                    }
2762
+                }
2763
+            }
2764
+        }
2765
+    }
2766
+
2767
+    // ensuite avec celles du contexte, sans doublonner !
2768
+    foreach ($contexte as $var => $val) {
2769
+        if (preg_match(',\[\]$,S', $var)) {
2770
+            $values[] = [$var, $val];
2771
+        } else {
2772
+            if (!isset($values[$var])) {
2773
+                $values[$var] = [$var, $val];
2774
+            }
2775
+        }
2776
+    }
2777
+
2778
+    // puis on rassemble le tout
2779
+    $hidden = [];
2780
+    foreach ($values as $value) {
2781
+        list($var, $val) = $value;
2782
+        $hidden[] = '<input name="'
2783
+            . entites_html($var)
2784
+            . '"'
2785
+            . (is_null($val)
2786
+                ? ''
2787
+                : ' value="' . entites_html($val) . '"'
2788
+            )
2789
+            . ' type="hidden"' . "\n/>";
2790
+    }
2791
+
2792
+    return join('', $hidden);
2793 2793
 }
2794 2794
 
2795 2795
 
@@ -2811,7 +2811,7 @@  discard block
 block discarded – undo
2811 2811
  *    - la première valeur du tableau sinon.
2812 2812
  **/
2813 2813
 function filtre_reset($array) {
2814
-	return !is_array($array) ? null : reset($array);
2814
+    return !is_array($array) ? null : reset($array);
2815 2815
 }
2816 2816
 
2817 2817
 /**
@@ -2832,7 +2832,7 @@  discard block
 block discarded – undo
2832 2832
  *    - la dernière valeur du tableau sinon.
2833 2833
  **/
2834 2834
 function filtre_end($array) {
2835
-	return !is_array($array) ? null : end($array);
2835
+    return !is_array($array) ? null : end($array);
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2852,11 +2852,11 @@  discard block
 block discarded – undo
2852 2852
  *
2853 2853
  **/
2854 2854
 function filtre_push($array, $val) {
2855
-	if (!is_array($array) or !array_push($array, $val)) {
2856
-		return '';
2857
-	}
2855
+    if (!is_array($array) or !array_push($array, $val)) {
2856
+        return '';
2857
+    }
2858 2858
 
2859
-	return $array;
2859
+    return $array;
2860 2860
 }
2861 2861
 
2862 2862
 /**
@@ -2875,7 +2875,7 @@  discard block
 block discarded – undo
2875 2875
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2876 2876
  **/
2877 2877
 function filtre_find($array, $val) {
2878
-	return (is_array($array) and in_array($val, $array));
2878
+    return (is_array($array) and in_array($val, $array));
2879 2879
 }
2880 2880
 
2881 2881
 
@@ -2892,15 +2892,15 @@  discard block
 block discarded – undo
2892 2892
  *     Contenu avec urls en absolus
2893 2893
  **/
2894 2894
 function urls_absolues_css($contenu, $source) {
2895
-	$path = suivre_lien(url_absolue($source), './');
2895
+    $path = suivre_lien(url_absolue($source), './');
2896 2896
 
2897
-	return preg_replace_callback(
2898
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
-		function ($x) use ($path) {
2900
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2901
-		},
2902
-		$contenu
2903
-	);
2897
+    return preg_replace_callback(
2898
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2899
+        function ($x) use ($path) {
2900
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2901
+        },
2902
+        $contenu
2903
+    );
2904 2904
 }
2905 2905
 
2906 2906
 
@@ -2929,119 +2929,119 @@  discard block
 block discarded – undo
2929 2929
  *     Chemin du fichier CSS inversé
2930 2930
  **/
2931 2931
 function direction_css($css, $voulue = '') {
2932
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
-		return $css;
2934
-	}
2935
-	include_spip('inc/lang');
2936
-	// si on a precise le sens voulu en argument, le prendre en compte
2937
-	if ($voulue = strtolower($voulue)) {
2938
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
-			$voulue = lang_dir($voulue);
2940
-		}
2941
-	} else {
2942
-		$voulue = lang_dir();
2943
-	}
2944
-
2945
-	$r = count($r) > 1;
2946
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
-	$dir = $r ? 'rtl' : 'ltr';
2948
-	$ndir = $r ? 'ltr' : 'rtl';
2949
-
2950
-	if ($voulue == $dir) {
2951
-		return $css;
2952
-	}
2953
-
2954
-	if (
2955
-		// url absolue
2956
-		preg_match(',^https?:,i', $css)
2957
-		// ou qui contient un ?
2958
-		or (($p = strpos($css, '?')) !== false)
2959
-	) {
2960
-		$distant = true;
2961
-		$cssf = parse_url($css);
2962
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
-	} else {
2965
-		$distant = false;
2966
-		$cssf = $css;
2967
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
-		//propose (rien a faire dans ce cas)
2969
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
-		if (@file_exists($f)) {
2971
-			return $f;
2972
-		}
2973
-	}
2974
-
2975
-	// 2.
2976
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
-	$f = $dir_var
2978
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
-
2981
-	// la css peut etre distante (url absolue !)
2982
-	if ($distant) {
2983
-		include_spip('inc/distant');
2984
-		$res = recuperer_url($css);
2985
-		if (!$res or !$contenu = $res['page']) {
2986
-			return $css;
2987
-		}
2988
-	} else {
2989
-		if (
2990
-			(@filemtime($f) > @filemtime($css))
2991
-			and (_VAR_MODE != 'recalcul')
2992
-		) {
2993
-			return $f;
2994
-		}
2995
-		if (!lire_fichier($css, $contenu)) {
2996
-			return $css;
2997
-		}
2998
-	}
2999
-
3000
-
3001
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
-	include_spip('lib/csstidy/class.csstidy');
3003
-	$parser = new csstidy();
3004
-	$parser->set_cfg('optimise_shorthands', 0);
3005
-	$parser->set_cfg('reverse_left_and_right', true);
3006
-	$parser->parse($contenu);
3007
-
3008
-	$contenu = $parser->print->plain();
3009
-
3010
-
3011
-	// reperer les @import auxquels il faut propager le direction_css
3012
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
-	$src = [];
3014
-	$src_direction_css = [];
3015
-	$src_faux_abs = [];
3016
-	$d = dirname($css);
3017
-	foreach ($regs[1] as $k => $import_css) {
3018
-		$css_direction = direction_css("$d/$import_css", $voulue);
3019
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
-			$css_direction = substr($css_direction, strlen($d) + 1);
3022
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
-			$css_direction = substr($css_direction, strlen($dir_var));
3025
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
-			$css_direction = '/@@@@@@/' . $css_direction;
3027
-		}
3028
-		$src[] = $regs[0][$k];
3029
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
-	}
3031
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3032
-
3033
-	$contenu = urls_absolues_css($contenu, $css);
3034
-
3035
-	// virer les fausses url absolues que l'on a mis dans les import
3036
-	if (count($src_faux_abs)) {
3037
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
-	}
3039
-
3040
-	if (!ecrire_fichier($f, $contenu)) {
3041
-		return $css;
3042
-	}
3043
-
3044
-	return $f;
2932
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2933
+        return $css;
2934
+    }
2935
+    include_spip('inc/lang');
2936
+    // si on a precise le sens voulu en argument, le prendre en compte
2937
+    if ($voulue = strtolower($voulue)) {
2938
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2939
+            $voulue = lang_dir($voulue);
2940
+        }
2941
+    } else {
2942
+        $voulue = lang_dir();
2943
+    }
2944
+
2945
+    $r = count($r) > 1;
2946
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2947
+    $dir = $r ? 'rtl' : 'ltr';
2948
+    $ndir = $r ? 'ltr' : 'rtl';
2949
+
2950
+    if ($voulue == $dir) {
2951
+        return $css;
2952
+    }
2953
+
2954
+    if (
2955
+        // url absolue
2956
+        preg_match(',^https?:,i', $css)
2957
+        // ou qui contient un ?
2958
+        or (($p = strpos($css, '?')) !== false)
2959
+    ) {
2960
+        $distant = true;
2961
+        $cssf = parse_url($css);
2962
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2963
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2964
+    } else {
2965
+        $distant = false;
2966
+        $cssf = $css;
2967
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2968
+        //propose (rien a faire dans ce cas)
2969
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2970
+        if (@file_exists($f)) {
2971
+            return $f;
2972
+        }
2973
+    }
2974
+
2975
+    // 2.
2976
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2977
+    $f = $dir_var
2978
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2979
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2980
+
2981
+    // la css peut etre distante (url absolue !)
2982
+    if ($distant) {
2983
+        include_spip('inc/distant');
2984
+        $res = recuperer_url($css);
2985
+        if (!$res or !$contenu = $res['page']) {
2986
+            return $css;
2987
+        }
2988
+    } else {
2989
+        if (
2990
+            (@filemtime($f) > @filemtime($css))
2991
+            and (_VAR_MODE != 'recalcul')
2992
+        ) {
2993
+            return $f;
2994
+        }
2995
+        if (!lire_fichier($css, $contenu)) {
2996
+            return $css;
2997
+        }
2998
+    }
2999
+
3000
+
3001
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3002
+    include_spip('lib/csstidy/class.csstidy');
3003
+    $parser = new csstidy();
3004
+    $parser->set_cfg('optimise_shorthands', 0);
3005
+    $parser->set_cfg('reverse_left_and_right', true);
3006
+    $parser->parse($contenu);
3007
+
3008
+    $contenu = $parser->print->plain();
3009
+
3010
+
3011
+    // reperer les @import auxquels il faut propager le direction_css
3012
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3013
+    $src = [];
3014
+    $src_direction_css = [];
3015
+    $src_faux_abs = [];
3016
+    $d = dirname($css);
3017
+    foreach ($regs[1] as $k => $import_css) {
3018
+        $css_direction = direction_css("$d/$import_css", $voulue);
3019
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3020
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3021
+            $css_direction = substr($css_direction, strlen($d) + 1);
3022
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3023
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3024
+            $css_direction = substr($css_direction, strlen($dir_var));
3025
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3026
+            $css_direction = '/@@@@@@/' . $css_direction;
3027
+        }
3028
+        $src[] = $regs[0][$k];
3029
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3030
+    }
3031
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3032
+
3033
+    $contenu = urls_absolues_css($contenu, $css);
3034
+
3035
+    // virer les fausses url absolues que l'on a mis dans les import
3036
+    if (count($src_faux_abs)) {
3037
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3038
+    }
3039
+
3040
+    if (!ecrire_fichier($f, $contenu)) {
3041
+        return $css;
3042
+    }
3043
+
3044
+    return $f;
3045 3045
 }
3046 3046
 
3047 3047
 
@@ -3064,46 +3064,46 @@  discard block
 block discarded – undo
3064 3064
  *     - Chemin ou URL du fichier CSS source sinon.
3065 3065
  **/
3066 3066
 function url_absolue_css($css) {
3067
-	if (!preg_match(',\.css$,i', $css, $r)) {
3068
-		return $css;
3069
-	}
3067
+    if (!preg_match(',\.css$,i', $css, $r)) {
3068
+        return $css;
3069
+    }
3070 3070
 
3071
-	$url_absolue_css = url_absolue($css);
3071
+    $url_absolue_css = url_absolue($css);
3072 3072
 
3073
-	$f = basename($css, '.css');
3074
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
-		. '.css';
3073
+    $f = basename($css, '.css');
3074
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3075
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3076
+        . '.css';
3077 3077
 
3078
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
-		return $f;
3080
-	}
3078
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3079
+        return $f;
3080
+    }
3081 3081
 
3082
-	if ($url_absolue_css == $css) {
3083
-		if (
3084
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
-		) {
3087
-			include_spip('inc/distant');
3088
-			$contenu = recuperer_url($css);
3089
-			$contenu = $contenu['page'] ?? '';
3090
-			if (!$contenu) {
3091
-				return $css;
3092
-			}
3093
-		}
3094
-	} elseif (!lire_fichier($css, $contenu)) {
3095
-		return $css;
3096
-	}
3082
+    if ($url_absolue_css == $css) {
3083
+        if (
3084
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3085
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3086
+        ) {
3087
+            include_spip('inc/distant');
3088
+            $contenu = recuperer_url($css);
3089
+            $contenu = $contenu['page'] ?? '';
3090
+            if (!$contenu) {
3091
+                return $css;
3092
+            }
3093
+        }
3094
+    } elseif (!lire_fichier($css, $contenu)) {
3095
+        return $css;
3096
+    }
3097 3097
 
3098
-	// passer les url relatives a la css d'origine en url absolues
3099
-	$contenu = urls_absolues_css($contenu, $css);
3098
+    // passer les url relatives a la css d'origine en url absolues
3099
+    $contenu = urls_absolues_css($contenu, $css);
3100 3100
 
3101
-	// ecrire la css
3102
-	if (!ecrire_fichier($f, $contenu)) {
3103
-		return $css;
3104
-	}
3101
+    // ecrire la css
3102
+    if (!ecrire_fichier($f, $contenu)) {
3103
+        return $css;
3104
+    }
3105 3105
 
3106
-	return $f;
3106
+    return $f;
3107 3107
 }
3108 3108
 
3109 3109
 
@@ -3137,24 +3137,24 @@  discard block
 block discarded – undo
3137 3137
  *     Valeur trouvée ou valeur par défaut.
3138 3138
  **/
3139 3139
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3140
-	foreach (explode('/', $cle) as $k) {
3141
-		$table = (is_string($table) ? @unserialize($table) : $table);
3140
+    foreach (explode('/', $cle) as $k) {
3141
+        $table = (is_string($table) ? @unserialize($table) : $table);
3142 3142
 
3143
-		if (is_object($table)) {
3144
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
-		} elseif (is_array($table)) {
3146
-			if ($conserver_null) {
3147
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
-			} else {
3149
-				$table = ($table[$k] ?? $defaut);
3150
-			}
3151
-		} else {
3152
-			$table = $defaut;
3153
-			break;
3154
-		}
3155
-	}
3143
+        if (is_object($table)) {
3144
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3145
+        } elseif (is_array($table)) {
3146
+            if ($conserver_null) {
3147
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3148
+            } else {
3149
+                $table = ($table[$k] ?? $defaut);
3150
+            }
3151
+        } else {
3152
+            $table = $defaut;
3153
+            break;
3154
+        }
3155
+    }
3156 3156
 
3157
-	return $table;
3157
+    return $table;
3158 3158
 }
3159 3159
 
3160 3160
 /**
@@ -3187,22 +3187,22 @@  discard block
 block discarded – undo
3187 3187
  *     - string : expression trouvée.
3188 3188
  **/
3189 3189
 function filtre_match_dist($texte, $expression, $modif = 'UimsS', $capte = 0) {
3190
-	if (intval($modif) and $capte == 0) {
3191
-		$capte = $modif;
3192
-		$modif = 'UimsS';
3193
-	}
3194
-	$expression = str_replace('\/', '/', $expression);
3195
-	$expression = str_replace('/', '\/', $expression);
3190
+    if (intval($modif) and $capte == 0) {
3191
+        $capte = $modif;
3192
+        $modif = 'UimsS';
3193
+    }
3194
+    $expression = str_replace('\/', '/', $expression);
3195
+    $expression = str_replace('/', '\/', $expression);
3196 3196
 
3197
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
-		if (isset($r[$capte])) {
3199
-			return $r[$capte];
3200
-		} else {
3201
-			return true;
3202
-		}
3203
-	}
3197
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3198
+        if (isset($r[$capte])) {
3199
+            return $r[$capte];
3200
+        } else {
3201
+            return true;
3202
+        }
3203
+    }
3204 3204
 
3205
-	return false;
3205
+    return false;
3206 3206
 }
3207 3207
 
3208 3208
 
@@ -3229,10 +3229,10 @@  discard block
 block discarded – undo
3229 3229
  *     Texte
3230 3230
  **/
3231 3231
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3232
-	$expression = str_replace('\/', '/', $expression);
3233
-	$expression = str_replace('/', '\/', $expression);
3232
+    $expression = str_replace('\/', '/', $expression);
3233
+    $expression = str_replace('/', '\/', $expression);
3234 3234
 
3235
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3235
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3236 3236
 }
3237 3237
 
3238 3238
 
@@ -3250,25 +3250,25 @@  discard block
 block discarded – undo
3250 3250
  **/
3251 3251
 function traiter_doublons_documents(&$doublons, $letexte) {
3252 3252
 
3253
-	// Verifier dans le texte & les notes (pas beau, helas)
3254
-	$t = $letexte . $GLOBALS['les_notes'];
3253
+    // Verifier dans le texte & les notes (pas beau, helas)
3254
+    $t = $letexte . $GLOBALS['les_notes'];
3255 3255
 
3256
-	if (
3257
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
-		and preg_match_all(
3259
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
-			$t,
3261
-			$matches,
3262
-			PREG_PATTERN_ORDER
3263
-		)
3264
-	) {
3265
-		if (!isset($doublons['documents'])) {
3266
-			$doublons['documents'] = '';
3267
-		}
3268
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3269
-	}
3256
+    if (
3257
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3258
+        and preg_match_all(
3259
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3260
+            $t,
3261
+            $matches,
3262
+            PREG_PATTERN_ORDER
3263
+        )
3264
+    ) {
3265
+        if (!isset($doublons['documents'])) {
3266
+            $doublons['documents'] = '';
3267
+        }
3268
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3269
+    }
3270 3270
 
3271
-	return $letexte;
3271
+    return $letexte;
3272 3272
 }
3273 3273
 
3274 3274
 /**
@@ -3282,7 +3282,7 @@  discard block
 block discarded – undo
3282 3282
  * @return string Chaîne vide
3283 3283
  **/
3284 3284
 function vide($texte) {
3285
-	return '';
3285
+    return '';
3286 3286
 }
3287 3287
 
3288 3288
 //
@@ -3311,23 +3311,23 @@  discard block
 block discarded – undo
3311 3311
  *      Code HTML résultant
3312 3312
  **/
3313 3313
 function env_to_params($env, $ignore_params = []) {
3314
-	$ignore_params = array_merge(
3315
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
-		$ignore_params
3317
-	);
3318
-	if (!is_array($env)) {
3319
-		$env = unserialize($env);
3320
-	}
3321
-	$texte = '';
3322
-	if ($env) {
3323
-		foreach ($env as $i => $j) {
3324
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
-			}
3327
-		}
3328
-	}
3329
-
3330
-	return $texte;
3314
+    $ignore_params = array_merge(
3315
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
+        $ignore_params
3317
+    );
3318
+    if (!is_array($env)) {
3319
+        $env = unserialize($env);
3320
+    }
3321
+    $texte = '';
3322
+    if ($env) {
3323
+        foreach ($env as $i => $j) {
3324
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3325
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3326
+            }
3327
+        }
3328
+    }
3329
+
3330
+    return $texte;
3331 3331
 }
3332 3332
 
3333 3333
 /**
@@ -3350,23 +3350,23 @@  discard block
 block discarded – undo
3350 3350
  *      Code HTML résultant
3351 3351
  **/
3352 3352
 function env_to_attributs($env, $ignore_params = []) {
3353
-	$ignore_params = array_merge(
3354
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
-		$ignore_params
3356
-	);
3357
-	if (!is_array($env)) {
3358
-		$env = unserialize($env);
3359
-	}
3360
-	$texte = '';
3361
-	if ($env) {
3362
-		foreach ($env as $i => $j) {
3363
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3364
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
-			}
3366
-		}
3367
-	}
3353
+    $ignore_params = array_merge(
3354
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3355
+        $ignore_params
3356
+    );
3357
+    if (!is_array($env)) {
3358
+        $env = unserialize($env);
3359
+    }
3360
+    $texte = '';
3361
+    if ($env) {
3362
+        foreach ($env as $i => $j) {
3363
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3364
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3365
+            }
3366
+        }
3367
+    }
3368 3368
 
3369
-	return $texte;
3369
+    return $texte;
3370 3370
 }
3371 3371
 
3372 3372
 
@@ -3384,7 +3384,7 @@  discard block
 block discarded – undo
3384 3384
  * @return string Chaînes concaténés
3385 3385
  **/
3386 3386
 function concat(...$args): string {
3387
-	return join('', $args);
3387
+    return join('', $args);
3388 3388
 }
3389 3389
 
3390 3390
 
@@ -3404,23 +3404,23 @@  discard block
 block discarded – undo
3404 3404
  *     Contenu du ou des fichiers, concaténé
3405 3405
  **/
3406 3406
 function charge_scripts($files, $script = true) {
3407
-	$flux = '';
3408
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
-		if (!is_string($file)) {
3410
-			continue;
3411
-		}
3412
-		if ($script) {
3413
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
-		}
3415
-		if ($file) {
3416
-			$path = find_in_path($file);
3417
-			if ($path) {
3418
-				$flux .= spip_file_get_contents($path);
3419
-			}
3420
-		}
3421
-	}
3422
-
3423
-	return $flux;
3407
+    $flux = '';
3408
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3409
+        if (!is_string($file)) {
3410
+            continue;
3411
+        }
3412
+        if ($script) {
3413
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3414
+        }
3415
+        if ($file) {
3416
+            $path = find_in_path($file);
3417
+            if ($path) {
3418
+                $flux .= spip_file_get_contents($path);
3419
+            }
3420
+        }
3421
+    }
3422
+
3423
+    return $flux;
3424 3424
 }
3425 3425
 
3426 3426
 /**
@@ -3431,22 +3431,22 @@  discard block
 block discarded – undo
3431 3431
  * @return string
3432 3432
  */
3433 3433
 function http_img_variante_svg_si_possible($img_file) {
3434
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
-	if (
3437
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
-		and file_exists($variante_svg_generique)
3440
-	) {
3441
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
-			$img_file = $variante_svg_size;
3443
-		}
3444
-		else {
3445
-			$img_file = $variante_svg_generique;
3446
-		}
3447
-	}
3434
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3435
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3436
+    if (
3437
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3438
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3439
+        and file_exists($variante_svg_generique)
3440
+    ) {
3441
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3442
+            $img_file = $variante_svg_size;
3443
+        }
3444
+        else {
3445
+            $img_file = $variante_svg_generique;
3446
+        }
3447
+    }
3448 3448
 
3449
-	return $img_file;
3449
+    return $img_file;
3450 3450
 }
3451 3451
 
3452 3452
 /**
@@ -3467,54 +3467,54 @@  discard block
 block discarded – undo
3467 3467
  */
3468 3468
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3469 3469
 
3470
-	$img_file = $img;
3471
-	if ($p = strpos($img_file, '?')) {
3472
-		$img_file = substr($img_file, 0, $p);
3473
-	}
3474
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
-		$img_file = chemin_image($img);
3476
-	}
3477
-	else {
3478
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
-			$img_file = http_img_variante_svg_si_possible($img_file);
3480
-		}
3481
-	}
3482
-	if (stripos($atts, 'width') === false) {
3483
-		// utiliser directement l'info de taille presente dans le nom
3484
-		if (
3485
-			(!isset($options['utiliser_suffixe_size'])
3486
-				or $options['utiliser_suffixe_size'] == true
3487
-			  or strpos($img_file, '-xx.svg') !== false)
3488
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
-		) {
3491
-			$largeur = $hauteur = intval($regs[1]);
3492
-		} else {
3493
-			$taille = taille_image($img_file);
3494
-			list($hauteur, $largeur) = $taille;
3495
-			if (!$hauteur or !$largeur) {
3496
-				return '';
3497
-			}
3498
-		}
3499
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
-	}
3501
-
3502
-	if (file_exists($img_file)) {
3503
-		$img_file = timestamp($img_file);
3504
-	}
3505
-	if ($alt === false) {
3506
-		$alt = '';
3507
-	}
3508
-	elseif ($alt or $alt === '') {
3509
-		$alt = " alt='" . attribut_html($alt) . "'";
3510
-	}
3511
-	else {
3512
-		$alt = " alt='" . attribut_html($title) . "'";
3513
-	}
3514
-	return "<img src='$img_file'$alt"
3515
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
-	. ' ' . ltrim($atts)
3517
-	. ' />';
3470
+    $img_file = $img;
3471
+    if ($p = strpos($img_file, '?')) {
3472
+        $img_file = substr($img_file, 0, $p);
3473
+    }
3474
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3475
+        $img_file = chemin_image($img);
3476
+    }
3477
+    else {
3478
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3479
+            $img_file = http_img_variante_svg_si_possible($img_file);
3480
+        }
3481
+    }
3482
+    if (stripos($atts, 'width') === false) {
3483
+        // utiliser directement l'info de taille presente dans le nom
3484
+        if (
3485
+            (!isset($options['utiliser_suffixe_size'])
3486
+                or $options['utiliser_suffixe_size'] == true
3487
+              or strpos($img_file, '-xx.svg') !== false)
3488
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3489
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3490
+        ) {
3491
+            $largeur = $hauteur = intval($regs[1]);
3492
+        } else {
3493
+            $taille = taille_image($img_file);
3494
+            list($hauteur, $largeur) = $taille;
3495
+            if (!$hauteur or !$largeur) {
3496
+                return '';
3497
+            }
3498
+        }
3499
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3500
+    }
3501
+
3502
+    if (file_exists($img_file)) {
3503
+        $img_file = timestamp($img_file);
3504
+    }
3505
+    if ($alt === false) {
3506
+        $alt = '';
3507
+    }
3508
+    elseif ($alt or $alt === '') {
3509
+        $alt = " alt='" . attribut_html($alt) . "'";
3510
+    }
3511
+    else {
3512
+        $alt = " alt='" . attribut_html($title) . "'";
3513
+    }
3514
+    return "<img src='$img_file'$alt"
3515
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3516
+    . ' ' . ltrim($atts)
3517
+    . ' />';
3518 3518
 }
3519 3519
 
3520 3520
 /**
@@ -3526,70 +3526,70 @@  discard block
 block discarded – undo
3526 3526
  * @return string
3527 3527
  */
3528 3528
 function http_style_background($img, $att = '', $size = null) {
3529
-	if ($size and is_numeric($size)) {
3530
-		$size = trim($size) . 'px';
3531
-	}
3532
-	return " style='background" .
3533
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
-		. ($size ? "background-size:{$size};" : '')
3535
-		. "'";
3529
+    if ($size and is_numeric($size)) {
3530
+        $size = trim($size) . 'px';
3531
+    }
3532
+    return " style='background" .
3533
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3534
+        . ($size ? "background-size:{$size};" : '')
3535
+        . "'";
3536 3536
 }
3537 3537
 
3538 3538
 
3539 3539
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3540
-	$args = [$alt_or_size, $class_or_size, $size];
3541
-	while (is_null(end($args)) and count($args)) {
3542
-		array_pop($args);
3543
-	}
3544
-	if (!count($args)) {
3545
-		return [null, null, null];
3546
-	}
3547
-	if (count($args) < 3) {
3548
-		$maybe_size = array_pop($args);
3549
-		// @2x
3550
-		// @1.5x
3551
-		// 512
3552
-		// 512x*
3553
-		// 512x300
3554
-		if (
3555
-			!strlen($maybe_size)
3556
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
-		) {
3558
-			$args[] = $maybe_size;
3559
-			$maybe_size = null;
3560
-		}
3561
-		while (count($args) < 2) {
3562
-			$args[] = null; // default alt or class
3563
-		}
3564
-		$args[] = $maybe_size;
3565
-	}
3566
-	return $args;
3540
+    $args = [$alt_or_size, $class_or_size, $size];
3541
+    while (is_null(end($args)) and count($args)) {
3542
+        array_pop($args);
3543
+    }
3544
+    if (!count($args)) {
3545
+        return [null, null, null];
3546
+    }
3547
+    if (count($args) < 3) {
3548
+        $maybe_size = array_pop($args);
3549
+        // @2x
3550
+        // @1.5x
3551
+        // 512
3552
+        // 512x*
3553
+        // 512x300
3554
+        if (
3555
+            !strlen($maybe_size)
3556
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3557
+        ) {
3558
+            $args[] = $maybe_size;
3559
+            $maybe_size = null;
3560
+        }
3561
+        while (count($args) < 2) {
3562
+            $args[] = null; // default alt or class
3563
+        }
3564
+        $args[] = $maybe_size;
3565
+    }
3566
+    return $args;
3567 3567
 }
3568 3568
 
3569 3569
 function helper_filtre_balise_img_svg_size($img, $size) {
3570
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
-		$coef = floatval(substr($size, 1, -1));
3573
-		list($h, $w) = taille_image($img);
3574
-		$height = intval(round($h / $coef));
3575
-		$width = intval(round($w / $coef));
3576
-	}
3577
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
-	else {
3579
-		$size = explode('x', $size, 2);
3580
-		$size = array_map('trim', $size);
3581
-		$height = $width = intval(array_shift($size));
3582
-
3583
-		if (count($size) and reset($size)) {
3584
-			$height = array_shift($size);
3585
-			if ($height === '*') {
3586
-				list($h, $w) = taille_image($img);
3587
-				$height = intval(round($h * $width / $w));
3588
-			}
3589
-		}
3590
-	}
3591
-
3592
-	return [$width, $height];
3570
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3571
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3572
+        $coef = floatval(substr($size, 1, -1));
3573
+        list($h, $w) = taille_image($img);
3574
+        $height = intval(round($h / $coef));
3575
+        $width = intval(round($w / $coef));
3576
+    }
3577
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3578
+    else {
3579
+        $size = explode('x', $size, 2);
3580
+        $size = array_map('trim', $size);
3581
+        $height = $width = intval(array_shift($size));
3582
+
3583
+        if (count($size) and reset($size)) {
3584
+            $height = array_shift($size);
3585
+            if ($height === '*') {
3586
+                list($h, $w) = taille_image($img);
3587
+                $height = intval(round($h * $width / $w));
3588
+            }
3589
+        }
3590
+    }
3591
+
3592
+    return [$width, $height];
3593 3593
 }
3594 3594
 
3595 3595
 /**
@@ -3625,43 +3625,43 @@  discard block
 block discarded – undo
3625 3625
  */
3626 3626
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3627 3627
 
3628
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
-
3630
-	$img = trim($img);
3631
-	if (strpos($img, '<img') === 0) {
3632
-		if (!is_null($alt)) {
3633
-			$img = inserer_attribut($img, 'alt', $alt);
3634
-		}
3635
-		if (!is_null($class)) {
3636
-			if (strlen($class)) {
3637
-				$img = inserer_attribut($img, 'class', $class);
3638
-			}
3639
-			else {
3640
-				$img = vider_attribut($img, 'class');
3641
-			}
3642
-		}
3643
-	}
3644
-	else {
3645
-		$img = http_img_pack(
3646
-			$img,
3647
-			$alt,
3648
-			$class ? " class='" . attribut_html($class) . "'" : '',
3649
-			'',
3650
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
-		);
3652
-		if (is_null($alt)) {
3653
-			$img = vider_attribut($img, 'alt');
3654
-		}
3655
-	}
3656
-
3657
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
-
3660
-		$img = inserer_attribut($img, 'width', $width);
3661
-		$img = inserer_attribut($img, 'height', $height);
3662
-	}
3663
-
3664
-	return $img;
3628
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3629
+
3630
+    $img = trim($img);
3631
+    if (strpos($img, '<img') === 0) {
3632
+        if (!is_null($alt)) {
3633
+            $img = inserer_attribut($img, 'alt', $alt);
3634
+        }
3635
+        if (!is_null($class)) {
3636
+            if (strlen($class)) {
3637
+                $img = inserer_attribut($img, 'class', $class);
3638
+            }
3639
+            else {
3640
+                $img = vider_attribut($img, 'class');
3641
+            }
3642
+        }
3643
+    }
3644
+    else {
3645
+        $img = http_img_pack(
3646
+            $img,
3647
+            $alt,
3648
+            $class ? " class='" . attribut_html($class) . "'" : '',
3649
+            '',
3650
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3651
+        );
3652
+        if (is_null($alt)) {
3653
+            $img = vider_attribut($img, 'alt');
3654
+        }
3655
+    }
3656
+
3657
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3658
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3659
+
3660
+        $img = inserer_attribut($img, 'width', $width);
3661
+        $img = inserer_attribut($img, 'height', $height);
3662
+    }
3663
+
3664
+    return $img;
3665 3665
 }
3666 3666
 
3667 3667
 
@@ -3695,77 +3695,77 @@  discard block
 block discarded – undo
3695 3695
  */
3696 3696
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3697 3697
 
3698
-	$img = trim($img);
3699
-	$img_file = $img;
3700
-	if (strpos($img, '<svg') === false) {
3701
-		if ($p = strpos($img_file, '?')) {
3702
-			$img_file = substr($img_file, 0, $p);
3703
-		}
3698
+    $img = trim($img);
3699
+    $img_file = $img;
3700
+    if (strpos($img, '<svg') === false) {
3701
+        if ($p = strpos($img_file, '?')) {
3702
+            $img_file = substr($img_file, 0, $p);
3703
+        }
3704 3704
 
3705
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3706
-		// la copie locale a toutes les chances d'etre la ou de resservir
3707
-		if (tester_url_absolue($img_file)) {
3708
-			include_spip('inc/distant');
3709
-			$fichier = copie_locale($img_file);
3710
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3711
-		}
3705
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3706
+        // la copie locale a toutes les chances d'etre la ou de resservir
3707
+        if (tester_url_absolue($img_file)) {
3708
+            include_spip('inc/distant');
3709
+            $fichier = copie_locale($img_file);
3710
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3711
+        }
3712 3712
 
3713
-		if (!$img_file
3714
-			or !file_exists($img_file)
3715
-			or !$svg = file_get_contents($img_file)) {
3716
-			return '';
3717
-		}
3718
-	}
3713
+        if (!$img_file
3714
+            or !file_exists($img_file)
3715
+            or !$svg = file_get_contents($img_file)) {
3716
+            return '';
3717
+        }
3718
+    }
3719 3719
 
3720
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3721
-		return '';
3722
-	}
3720
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3721
+        return '';
3722
+    }
3723 3723
 
3724
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3724
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3725 3725
 
3726
-	$balise_svg = $match[0];
3727
-	$balise_svg_source = $balise_svg;
3726
+    $balise_svg = $match[0];
3727
+    $balise_svg_source = $balise_svg;
3728 3728
 
3729
-	// entete XML à supprimer
3730
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3729
+    // entete XML à supprimer
3730
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3731 3731
 
3732
-	// IE est toujours mon ami
3733
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3732
+    // IE est toujours mon ami
3733
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3734 3734
 
3735
-	// regler la classe
3736
-	if (!is_null($class)) {
3737
-		if (strlen($class)) {
3738
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3739
-		}
3740
-		else {
3741
-			$balise_svg = vider_attribut($balise_svg, 'class');
3742
-		}
3743
-	}
3735
+    // regler la classe
3736
+    if (!is_null($class)) {
3737
+        if (strlen($class)) {
3738
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3739
+        }
3740
+        else {
3741
+            $balise_svg = vider_attribut($balise_svg, 'class');
3742
+        }
3743
+    }
3744 3744
 
3745
-	// regler le alt
3746
-	if ($alt) {
3747
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3748
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3749
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3750
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3751
-		$balise_svg .= $title;
3752
-	}
3753
-	else {
3754
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3755
-	}
3745
+    // regler le alt
3746
+    if ($alt) {
3747
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3748
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3749
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3750
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3751
+        $balise_svg .= $title;
3752
+    }
3753
+    else {
3754
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3755
+    }
3756 3756
 
3757
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3757
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3758 3758
 
3759
-	if (!is_null($size) and strlen($size = trim($size))) {
3760
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3759
+    if (!is_null($size) and strlen($size = trim($size))) {
3760
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3761 3761
 
3762
-		if (!function_exists('svg_redimensionner')) {
3763
-			include_spip('inc/svg');
3764
-		}
3765
-		$svg = svg_redimensionner($svg, $width, $height);
3766
-	}
3762
+        if (!function_exists('svg_redimensionner')) {
3763
+            include_spip('inc/svg');
3764
+        }
3765
+        $svg = svg_redimensionner($svg, $width, $height);
3766
+    }
3767 3767
 
3768
-	return $svg;
3768
+    return $svg;
3769 3769
 }
3770 3770
 
3771 3771
 
@@ -3791,18 +3791,18 @@  discard block
 block discarded – undo
3791 3791
  *     Code HTML résultant
3792 3792
  **/
3793 3793
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3794
-	$texte = '';
3795
-	if (is_array($tableau)) {
3796
-		foreach ($tableau as $k => $v) {
3797
-			$res = recuperer_fond(
3798
-				'modeles/' . $modele,
3799
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3800
-			);
3801
-			$texte .= $res;
3802
-		}
3803
-	}
3794
+    $texte = '';
3795
+    if (is_array($tableau)) {
3796
+        foreach ($tableau as $k => $v) {
3797
+            $res = recuperer_fond(
3798
+                'modeles/' . $modele,
3799
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3800
+            );
3801
+            $texte .= $res;
3802
+        }
3803
+    }
3804 3804
 
3805
-	return $texte;
3805
+    return $texte;
3806 3806
 }
3807 3807
 
3808 3808
 
@@ -3827,37 +3827,37 @@  discard block
 block discarded – undo
3827 3827
  *         - tout : retourne toutes les informations du plugin actif
3828 3828
  **/
3829 3829
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3830
-	include_spip('inc/plugin');
3831
-	$plugin = strtoupper($plugin);
3832
-	$plugins_actifs = liste_plugin_actifs();
3833
-
3834
-	if (!$plugin) {
3835
-		return serialize(array_keys($plugins_actifs));
3836
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3837
-		return '';
3838
-	} elseif (($type_info == 'est_actif') and !$reload) {
3839
-		return $plugins_actifs[$plugin] ? 1 : 0;
3840
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3841
-		return $plugins_actifs[$plugin][$type_info];
3842
-	} else {
3843
-		$get_infos = charger_fonction('get_infos', 'plugins');
3844
-		// On prend en compte les extensions
3845
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3846
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3847
-		} else {
3848
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3849
-		}
3850
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3851
-			return '';
3852
-		}
3853
-		if ($type_info == 'tout') {
3854
-			return $infos;
3855
-		} elseif ($type_info == 'est_actif') {
3856
-			return $infos ? 1 : 0;
3857
-		} else {
3858
-			return strval($infos[$type_info]);
3859
-		}
3860
-	}
3830
+    include_spip('inc/plugin');
3831
+    $plugin = strtoupper($plugin);
3832
+    $plugins_actifs = liste_plugin_actifs();
3833
+
3834
+    if (!$plugin) {
3835
+        return serialize(array_keys($plugins_actifs));
3836
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3837
+        return '';
3838
+    } elseif (($type_info == 'est_actif') and !$reload) {
3839
+        return $plugins_actifs[$plugin] ? 1 : 0;
3840
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3841
+        return $plugins_actifs[$plugin][$type_info];
3842
+    } else {
3843
+        $get_infos = charger_fonction('get_infos', 'plugins');
3844
+        // On prend en compte les extensions
3845
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3846
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3847
+        } else {
3848
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3849
+        }
3850
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3851
+            return '';
3852
+        }
3853
+        if ($type_info == 'tout') {
3854
+            return $infos;
3855
+        } elseif ($type_info == 'est_actif') {
3856
+            return $infos ? 1 : 0;
3857
+        } else {
3858
+            return strval($infos[$type_info]);
3859
+        }
3860
+    }
3861 3861
 }
3862 3862
 
3863 3863
 
@@ -3884,9 +3884,9 @@  discard block
 block discarded – undo
3884 3884
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3885 3885
  */
3886 3886
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3887
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3887
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3888 3888
 
3889
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3889
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3890 3890
 }
3891 3891
 
3892 3892
 
@@ -3916,19 +3916,19 @@  discard block
 block discarded – undo
3916 3916
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3917 3917
  */
3918 3918
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3919
-	static $puce_statut = null;
3920
-	if (!$puce_statut) {
3921
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3922
-	}
3919
+    static $puce_statut = null;
3920
+    if (!$puce_statut) {
3921
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3922
+    }
3923 3923
 
3924
-	return $puce_statut(
3925
-		$id_objet,
3926
-		$statut,
3927
-		$id_parent,
3928
-		$objet,
3929
-		false,
3930
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3931
-	);
3924
+    return $puce_statut(
3925
+        $id_objet,
3926
+        $statut,
3927
+        $id_parent,
3928
+        $objet,
3929
+        false,
3930
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3931
+    );
3932 3932
 }
3933 3933
 
3934 3934
 
@@ -3955,97 +3955,97 @@  discard block
 block discarded – undo
3955 3955
  *   hash du contexte
3956 3956
  */
3957 3957
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3958
-	if (
3959
-		is_string($c)
3960
-		and @unserialize($c) !== false
3961
-	) {
3962
-		$c = unserialize($c);
3963
-	}
3964
-
3965
-	// supprimer les parametres debut_x
3966
-	// pour que la pagination ajax ne soit pas plantee
3967
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3968
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3969
-	if (is_array($c)) {
3970
-		foreach ($c as $k => $v) {
3971
-			if (strpos($k, 'debut_') === 0) {
3972
-				unset($c[$k]);
3973
-			}
3974
-		}
3975
-	}
3976
-
3977
-	if (!function_exists('calculer_cle_action')) {
3978
-		include_spip('inc/securiser_action');
3979
-	}
3980
-
3981
-	$c = serialize($c);
3982
-	$cle = calculer_cle_action($form . $c);
3983
-	$c = "$cle:$c";
3984
-
3985
-	// on ne stocke pas les contextes dans des fichiers en cache
3986
-	// par defaut, sauf si cette configuration a été forcée
3987
-	// OU que la longueur de l’argument géneré est plus long
3988
-	// que ce qui est toléré.
3989
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3990
-	if (!$cache_contextes_ajax) {
3991
-		$env = $c;
3992
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3993
-			$env = gzdeflate($env);
3994
-		}
3995
-		$env = _xor($env);
3996
-		$env = base64_encode($env);
3997
-		$len = strlen($env);
3998
-		// Si l’url est trop longue pour le navigateur
3999
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4000
-		if ($len > $max_len) {
4001
-			$cache_contextes_ajax = true;
4002
-			spip_log(
4003
-				'Contextes AJAX forces en fichiers !'
4004
-				. ' Cela arrive lorsque la valeur du contexte'
4005
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4006
-				_LOG_AVERTISSEMENT
4007
-			);
4008
-		}
4009
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4010
-		elseif (
4011
-			$max_len = @ini_get('suhosin.get.max_value_length')
4012
-			and $max_len < $len
4013
-		) {
4014
-			$cache_contextes_ajax = true;
4015
-			spip_log('Contextes AJAX forces en fichiers !'
4016
-				. ' Cela arrive lorsque la valeur du contexte'
4017
-				. ' depasse la longueur maximale autorisee par Suhosin'
4018
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4019
-				. ' Vous devriez modifier les parametres de Suhosin'
4020
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4021
-		}
4022
-	}
4023
-
4024
-	if ($cache_contextes_ajax) {
4025
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4026
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4027
-		$md5 = md5($c);
4028
-		ecrire_fichier("$dir/c$md5", $c);
4029
-		$env = $md5;
4030
-	}
4031
-
4032
-	if ($emboite === null) {
4033
-		return $env;
4034
-	}
4035
-	if (!trim($emboite)) {
4036
-		return '';
4037
-	}
4038
-	// toujours encoder l'url source dans le bloc ajax
4039
-	$r = self();
4040
-	$r = ' data-origin="' . $r . '"';
4041
-	$class = 'ajaxbloc';
4042
-	if ($ajaxid and is_string($ajaxid)) {
4043
-		// ajaxid est normalement conforme a un nom de classe css
4044
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4045
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4046
-	}
4047
-
4048
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3958
+    if (
3959
+        is_string($c)
3960
+        and @unserialize($c) !== false
3961
+    ) {
3962
+        $c = unserialize($c);
3963
+    }
3964
+
3965
+    // supprimer les parametres debut_x
3966
+    // pour que la pagination ajax ne soit pas plantee
3967
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3968
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3969
+    if (is_array($c)) {
3970
+        foreach ($c as $k => $v) {
3971
+            if (strpos($k, 'debut_') === 0) {
3972
+                unset($c[$k]);
3973
+            }
3974
+        }
3975
+    }
3976
+
3977
+    if (!function_exists('calculer_cle_action')) {
3978
+        include_spip('inc/securiser_action');
3979
+    }
3980
+
3981
+    $c = serialize($c);
3982
+    $cle = calculer_cle_action($form . $c);
3983
+    $c = "$cle:$c";
3984
+
3985
+    // on ne stocke pas les contextes dans des fichiers en cache
3986
+    // par defaut, sauf si cette configuration a été forcée
3987
+    // OU que la longueur de l’argument géneré est plus long
3988
+    // que ce qui est toléré.
3989
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3990
+    if (!$cache_contextes_ajax) {
3991
+        $env = $c;
3992
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3993
+            $env = gzdeflate($env);
3994
+        }
3995
+        $env = _xor($env);
3996
+        $env = base64_encode($env);
3997
+        $len = strlen($env);
3998
+        // Si l’url est trop longue pour le navigateur
3999
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4000
+        if ($len > $max_len) {
4001
+            $cache_contextes_ajax = true;
4002
+            spip_log(
4003
+                'Contextes AJAX forces en fichiers !'
4004
+                . ' Cela arrive lorsque la valeur du contexte'
4005
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4006
+                _LOG_AVERTISSEMENT
4007
+            );
4008
+        }
4009
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4010
+        elseif (
4011
+            $max_len = @ini_get('suhosin.get.max_value_length')
4012
+            and $max_len < $len
4013
+        ) {
4014
+            $cache_contextes_ajax = true;
4015
+            spip_log('Contextes AJAX forces en fichiers !'
4016
+                . ' Cela arrive lorsque la valeur du contexte'
4017
+                . ' depasse la longueur maximale autorisee par Suhosin'
4018
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4019
+                . ' Vous devriez modifier les parametres de Suhosin'
4020
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4021
+        }
4022
+    }
4023
+
4024
+    if ($cache_contextes_ajax) {
4025
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4026
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4027
+        $md5 = md5($c);
4028
+        ecrire_fichier("$dir/c$md5", $c);
4029
+        $env = $md5;
4030
+    }
4031
+
4032
+    if ($emboite === null) {
4033
+        return $env;
4034
+    }
4035
+    if (!trim($emboite)) {
4036
+        return '';
4037
+    }
4038
+    // toujours encoder l'url source dans le bloc ajax
4039
+    $r = self();
4040
+    $r = ' data-origin="' . $r . '"';
4041
+    $class = 'ajaxbloc';
4042
+    if ($ajaxid and is_string($ajaxid)) {
4043
+        // ajaxid est normalement conforme a un nom de classe css
4044
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4045
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4046
+    }
4047
+
4048
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4049 4049
 }
4050 4050
 
4051 4051
 /**
@@ -4065,37 +4065,37 @@  discard block
 block discarded – undo
4065 4065
  *   - false : erreur de décodage
4066 4066
  */
4067 4067
 function decoder_contexte_ajax($c, $form = '') {
4068
-	if (!function_exists('calculer_cle_action')) {
4069
-		include_spip('inc/securiser_action');
4070
-	}
4071
-	if (
4072
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4073
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4074
-		and lire_fichier("$dir/c$c", $contexte)
4075
-	) {
4076
-		$c = $contexte;
4077
-	} else {
4078
-		$c = @base64_decode($c);
4079
-		$c = _xor($c);
4080
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4081
-			$c = @gzinflate($c);
4082
-		}
4083
-	}
4084
-
4085
-	// extraire la signature en debut de contexte
4086
-	// et la verifier avant de deserializer
4087
-	// format : signature:donneesserializees
4088
-	if ($p = strpos($c, ':')) {
4089
-		$cle = substr($c, 0, $p);
4090
-		$c = substr($c, $p + 1);
4091
-
4092
-		if ($cle == calculer_cle_action($form . $c)) {
4093
-			$env = @unserialize($c);
4094
-			return $env;
4095
-		}
4096
-	}
4097
-
4098
-	return false;
4068
+    if (!function_exists('calculer_cle_action')) {
4069
+        include_spip('inc/securiser_action');
4070
+    }
4071
+    if (
4072
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4073
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4074
+        and lire_fichier("$dir/c$c", $contexte)
4075
+    ) {
4076
+        $c = $contexte;
4077
+    } else {
4078
+        $c = @base64_decode($c);
4079
+        $c = _xor($c);
4080
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4081
+            $c = @gzinflate($c);
4082
+        }
4083
+    }
4084
+
4085
+    // extraire la signature en debut de contexte
4086
+    // et la verifier avant de deserializer
4087
+    // format : signature:donneesserializees
4088
+    if ($p = strpos($c, ':')) {
4089
+        $cle = substr($c, 0, $p);
4090
+        $c = substr($c, $p + 1);
4091
+
4092
+        if ($cle == calculer_cle_action($form . $c)) {
4093
+            $env = @unserialize($c);
4094
+            return $env;
4095
+        }
4096
+    }
4097
+
4098
+    return false;
4099 4099
 }
4100 4100
 
4101 4101
 
@@ -4113,20 +4113,20 @@  discard block
 block discarded – undo
4113 4113
  *    Message décrypté ou encrypté
4114 4114
  **/
4115 4115
 function _xor($message, $key = null) {
4116
-	if (is_null($key)) {
4117
-		if (!function_exists('calculer_cle_action')) {
4118
-			include_spip('inc/securiser_action');
4119
-		}
4120
-		$key = pack('H*', calculer_cle_action('_xor'));
4121
-	}
4116
+    if (is_null($key)) {
4117
+        if (!function_exists('calculer_cle_action')) {
4118
+            include_spip('inc/securiser_action');
4119
+        }
4120
+        $key = pack('H*', calculer_cle_action('_xor'));
4121
+    }
4122 4122
 
4123
-	$keylen = strlen($key);
4124
-	$messagelen = strlen($message);
4125
-	for ($i = 0; $i < $messagelen; $i++) {
4126
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4127
-	}
4123
+    $keylen = strlen($key);
4124
+    $messagelen = strlen($message);
4125
+    for ($i = 0; $i < $messagelen; $i++) {
4126
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4127
+    }
4128 4128
 
4129
-	return $message;
4129
+    return $message;
4130 4130
 }
4131 4131
 
4132 4132
 /**
@@ -4140,7 +4140,7 @@  discard block
 block discarded – undo
4140 4140
  * @return string
4141 4141
  */
4142 4142
 function url_reponse_forum($texte) {
4143
- return $texte;
4143
+    return $texte;
4144 4144
 }
4145 4145
 
4146 4146
 /**
@@ -4154,7 +4154,7 @@  discard block
 block discarded – undo
4154 4154
  * @return string
4155 4155
  */
4156 4156
 function url_rss_forum($texte) {
4157
- return $texte;
4157
+    return $texte;
4158 4158
 }
4159 4159
 
4160 4160
 
@@ -4193,37 +4193,37 @@  discard block
 block discarded – undo
4193 4193
  *   Code HTML
4194 4194
  */
4195 4195
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4196
-	if ($on) {
4197
-		$bal = 'strong';
4198
-		$class = '';
4199
-		$att = '';
4200
-		// si $on passe la balise et optionnelement une ou ++classe
4201
-		// a.active span.selected.active etc....
4202
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4203
-			$on = explode('.', $on);
4204
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4205
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4206
-				$bal = array_shift($on);
4207
-				$class = implode(' ', $on);
4208
-				if ($bal == 'a') {
4209
-					$att = 'href="#" ';
4210
-				}
4211
-			}
4212
-		}
4213
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4214
-	} else {
4215
-		$bal = 'a';
4216
-		$att = "href='$url'"
4217
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4218
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4219
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4220
-			. $evt;
4221
-	}
4222
-	if ($libelle === null) {
4223
-		$libelle = $url;
4224
-	}
4225
-
4226
-	return "<$bal $att>$libelle</$bal>";
4196
+    if ($on) {
4197
+        $bal = 'strong';
4198
+        $class = '';
4199
+        $att = '';
4200
+        // si $on passe la balise et optionnelement une ou ++classe
4201
+        // a.active span.selected.active etc....
4202
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4203
+            $on = explode('.', $on);
4204
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4205
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4206
+                $bal = array_shift($on);
4207
+                $class = implode(' ', $on);
4208
+                if ($bal == 'a') {
4209
+                    $att = 'href="#" ';
4210
+                }
4211
+            }
4212
+        }
4213
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4214
+    } else {
4215
+        $bal = 'a';
4216
+        $att = "href='$url'"
4217
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4218
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4219
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4220
+            . $evt;
4221
+    }
4222
+    if ($libelle === null) {
4223
+        $libelle = $url;
4224
+    }
4225
+
4226
+    return "<$bal $att>$libelle</$bal>";
4227 4227
 }
4228 4228
 
4229 4229
 
@@ -4240,39 +4240,39 @@  discard block
 block discarded – undo
4240 4240
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4241 4241
  */
4242 4242
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4243
-	static $local_singulier_ou_pluriel = [];
4244
-
4245
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4246
-	if (!is_numeric($nb) or $nb == 0) {
4247
-		return '';
4248
-	}
4249
-	if (!is_array($vars)) {
4250
-		return '';
4251
-	}
4252
-
4253
-	$langue = $GLOBALS['spip_lang'];
4254
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4255
-		$local_singulier_ou_pluriel[$langue] = false;
4256
-		if (
4257
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4258
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4259
-		) {
4260
-			$local_singulier_ou_pluriel[$langue] = $f;
4261
-		}
4262
-	}
4263
-
4264
-	// si on a une surcharge on l'utilise
4265
-	if ($local_singulier_ou_pluriel[$langue]) {
4266
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4267
-	}
4268
-
4269
-	// sinon traitement par defaut
4270
-	$vars[$var] = $nb;
4271
-	if ($nb >= 2) {
4272
-		return _T($chaine_plusieurs, $vars);
4273
-	} else {
4274
-		return _T($chaine_un, $vars);
4275
-	}
4243
+    static $local_singulier_ou_pluriel = [];
4244
+
4245
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4246
+    if (!is_numeric($nb) or $nb == 0) {
4247
+        return '';
4248
+    }
4249
+    if (!is_array($vars)) {
4250
+        return '';
4251
+    }
4252
+
4253
+    $langue = $GLOBALS['spip_lang'];
4254
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4255
+        $local_singulier_ou_pluriel[$langue] = false;
4256
+        if (
4257
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4258
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4259
+        ) {
4260
+            $local_singulier_ou_pluriel[$langue] = $f;
4261
+        }
4262
+    }
4263
+
4264
+    // si on a une surcharge on l'utilise
4265
+    if ($local_singulier_ou_pluriel[$langue]) {
4266
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4267
+    }
4268
+
4269
+    // sinon traitement par defaut
4270
+    $vars[$var] = $nb;
4271
+    if ($nb >= 2) {
4272
+        return _T($chaine_plusieurs, $vars);
4273
+    } else {
4274
+        return _T($chaine_un, $vars);
4275
+    }
4276 4276
 }
4277 4277
 
4278 4278
 
@@ -4300,73 +4300,73 @@  discard block
 block discarded – undo
4300 4300
  */
4301 4301
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4302 4302
 
4303
-	$class_lien = $class_bouton = $class;
4304
-
4305
-	// Normaliser la fonction et compléter la classe en fonction
4306
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4307
-		$class_lien .= ' danger';
4308
-		$class_bouton .= ' btn_danger';
4309
-	} elseif ($fonction == 'rien.gif') {
4310
-		$fonction = '';
4311
-	} elseif ($fonction == 'delsafe') {
4312
-		$fonction = 'del';
4313
-	}
4314
-
4315
-	$fond_origine = $fond;
4316
-	// Remappage des icone : article-24.png+new => article-new-24.png
4317
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4318
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4319
-	}
4320
-
4321
-	// Ajouter le type d'objet dans la classe
4322
-	$objet_type = substr(basename($fond), 0, -4);
4323
-	$class_lien .= " $objet_type";
4324
-	$class_bouton .= " $objet_type";
4325
-
4326
-	// Texte
4327
-	$alt = attribut_html($texte);
4328
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4329
-
4330
-	// Liens : préparer les classes ajax
4331
-	$ajax = '';
4332
-	if ($type === 'lien') {
4333
-		if (strpos($class_lien, 'ajax') !== false) {
4334
-			$ajax = 'ajax';
4335
-			if (strpos($class_lien, 'preload') !== false) {
4336
-				$ajax .= ' preload';
4337
-			}
4338
-			if (strpos($class_lien, 'nocache') !== false) {
4339
-				$ajax .= ' nocache';
4340
-			}
4341
-			$ajax = " class='$ajax'";
4342
-		}
4343
-	}
4344
-
4345
-	// Repérer la taille et l'ajouter dans la classe
4346
-	$size = 24;
4347
-	if (
4348
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4349
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4350
-	) {
4351
-		$size = $match[1];
4352
-	}
4353
-	$class_lien .= " s$size";
4354
-	$class_bouton .= " s$size";
4355
-
4356
-	// Icône
4357
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4358
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4359
-
4360
-	// Markup final
4361
-	if ($type == 'lien') {
4362
-		return "<span class='icone $class_lien'>"
4363
-		. "<a href='$lien'$title$ajax$javascript>"
4364
-		. $icone
4365
-		. "<b>$texte</b>"
4366
-		. "</a></span>\n";
4367
-	} else {
4368
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4369
-	}
4303
+    $class_lien = $class_bouton = $class;
4304
+
4305
+    // Normaliser la fonction et compléter la classe en fonction
4306
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4307
+        $class_lien .= ' danger';
4308
+        $class_bouton .= ' btn_danger';
4309
+    } elseif ($fonction == 'rien.gif') {
4310
+        $fonction = '';
4311
+    } elseif ($fonction == 'delsafe') {
4312
+        $fonction = 'del';
4313
+    }
4314
+
4315
+    $fond_origine = $fond;
4316
+    // Remappage des icone : article-24.png+new => article-new-24.png
4317
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4318
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4319
+    }
4320
+
4321
+    // Ajouter le type d'objet dans la classe
4322
+    $objet_type = substr(basename($fond), 0, -4);
4323
+    $class_lien .= " $objet_type";
4324
+    $class_bouton .= " $objet_type";
4325
+
4326
+    // Texte
4327
+    $alt = attribut_html($texte);
4328
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4329
+
4330
+    // Liens : préparer les classes ajax
4331
+    $ajax = '';
4332
+    if ($type === 'lien') {
4333
+        if (strpos($class_lien, 'ajax') !== false) {
4334
+            $ajax = 'ajax';
4335
+            if (strpos($class_lien, 'preload') !== false) {
4336
+                $ajax .= ' preload';
4337
+            }
4338
+            if (strpos($class_lien, 'nocache') !== false) {
4339
+                $ajax .= ' nocache';
4340
+            }
4341
+            $ajax = " class='$ajax'";
4342
+        }
4343
+    }
4344
+
4345
+    // Repérer la taille et l'ajouter dans la classe
4346
+    $size = 24;
4347
+    if (
4348
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4349
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4350
+    ) {
4351
+        $size = $match[1];
4352
+    }
4353
+    $class_lien .= " s$size";
4354
+    $class_bouton .= " s$size";
4355
+
4356
+    // Icône
4357
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4358
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4359
+
4360
+    // Markup final
4361
+    if ($type == 'lien') {
4362
+        return "<span class='icone $class_lien'>"
4363
+        . "<a href='$lien'$title$ajax$javascript>"
4364
+        . $icone
4365
+        . "<b>$texte</b>"
4366
+        . "</a></span>\n";
4367
+    } else {
4368
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4369
+    }
4370 4370
 }
4371 4371
 
4372 4372
 /**
@@ -4390,7 +4390,7 @@  discard block
 block discarded – undo
4390 4390
  *     Code HTML du lien
4391 4391
  **/
4392 4392
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4393
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4393
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4394 4394
 }
4395 4395
 
4396 4396
 /**
@@ -4425,7 +4425,7 @@  discard block
 block discarded – undo
4425 4425
  *     Code HTML du lien
4426 4426
  **/
4427 4427
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4428
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4428
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4429 4429
 }
4430 4430
 
4431 4431
 /**
@@ -4470,7 +4470,7 @@  discard block
 block discarded – undo
4470 4470
  *     Code HTML du lien
4471 4471
  **/
4472 4472
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4473
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4473
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4474 4474
 }
4475 4475
 
4476 4476
 /**
@@ -4501,7 +4501,7 @@  discard block
 block discarded – undo
4501 4501
  *     Code HTML du lien
4502 4502
  **/
4503 4503
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4504
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4504
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4505 4505
 }
4506 4506
 
4507 4507
 /**
@@ -4532,7 +4532,7 @@  discard block
 block discarded – undo
4532 4532
  *     Code HTML du lien
4533 4533
  */
4534 4534
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4535
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4535
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4536 4536
 }
4537 4537
 
4538 4538
 
@@ -4554,7 +4554,7 @@  discard block
 block discarded – undo
4554 4554
  * @return array Liste des éléments
4555 4555
  */
4556 4556
 function filtre_explode_dist($a, $b) {
4557
- return explode($b, $a);
4557
+    return explode($b, $a);
4558 4558
 }
4559 4559
 
4560 4560
 /**
@@ -4575,7 +4575,7 @@  discard block
 block discarded – undo
4575 4575
  * @return string Texte
4576 4576
  */
4577 4577
 function filtre_implode_dist($a, $b) {
4578
- return is_array($a) ? implode($b, $a) : $a;
4578
+    return is_array($a) ? implode($b, $a) : $a;
4579 4579
 }
4580 4580
 
4581 4581
 /**
@@ -4584,24 +4584,24 @@  discard block
 block discarded – undo
4584 4584
  * @return string Code CSS
4585 4585
  */
4586 4586
 function bando_images_background() {
4587
-	include_spip('inc/bandeau');
4588
-	// recuperer tous les boutons et leurs images
4589
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4587
+    include_spip('inc/bandeau');
4588
+    // recuperer tous les boutons et leurs images
4589
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4590 4590
 
4591
-	$res = '';
4592
-	foreach ($boutons as $page => $detail) {
4593
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4594
-		if (is_array($detail->sousmenu)) {
4595
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4596
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4597
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4598
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4599
-				}
4600
-			}
4601
-		}
4602
-	}
4591
+    $res = '';
4592
+    foreach ($boutons as $page => $detail) {
4593
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4594
+        if (is_array($detail->sousmenu)) {
4595
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4596
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4597
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4598
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4599
+                }
4600
+            }
4601
+        }
4602
+    }
4603 4603
 
4604
-	return $res;
4604
+    return $res;
4605 4605
 }
4606 4606
 
4607 4607
 /**
@@ -4626,27 +4626,27 @@  discard block
 block discarded – undo
4626 4626
  */
4627 4627
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4628 4628
 
4629
-	// Classes : dispatcher `ajax` sur le formulaire
4630
-	$class_form = '';
4631
-	if (strpos($class, 'ajax') !== false) {
4632
-		$class_form = 'ajax';
4633
-		$class = str_replace('ajax', '', $class);
4634
-	}
4635
-	$class_btn = 'submit ' . trim($class);
4629
+    // Classes : dispatcher `ajax` sur le formulaire
4630
+    $class_form = '';
4631
+    if (strpos($class, 'ajax') !== false) {
4632
+        $class_form = 'ajax';
4633
+        $class = str_replace('ajax', '', $class);
4634
+    }
4635
+    $class_btn = 'submit ' . trim($class);
4636 4636
 
4637
-	if ($confirm) {
4638
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4639
-		if ($callback) {
4640
-			$callback = "$confirm?($callback):false";
4641
-		} else {
4642
-			$callback = $confirm;
4643
-		}
4644
-	}
4645
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4646
-	$title = $title ? " title='$title'" : '';
4637
+    if ($confirm) {
4638
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4639
+        if ($callback) {
4640
+            $callback = "$confirm?($callback):false";
4641
+        } else {
4642
+            $callback = $confirm;
4643
+        }
4644
+    }
4645
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4646
+    $title = $title ? " title='$title'" : '';
4647 4647
 
4648
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4649
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4648
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4649
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4650 4650
 }
4651 4651
 
4652 4652
 /**
@@ -4669,94 +4669,94 @@  discard block
 block discarded – undo
4669 4669
  * @return string
4670 4670
  */
4671 4671
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4672
-	static $trouver_table = null;
4673
-	static $objets;
4674
-
4675
-	// On verifie qu'on a tout ce qu'il faut
4676
-	$id_objet = intval($id_objet);
4677
-	if (!($id_objet and $type_objet and $info)) {
4678
-		return '';
4679
-	}
4680
-
4681
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4682
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4683
-		return '';
4684
-	}
4685
-
4686
-	// Si on demande l'url, on retourne direct la fonction
4687
-	if ($info == 'url') {
4688
-		return generer_url_entite($id_objet, $type_objet, ...$params);
4689
-	}
4690
-
4691
-	// Sinon on va tout chercher dans la table et on garde en memoire
4692
-	$demande_titre = ($info === 'titre');
4693
-	$demande_introduction = ($info === 'introduction');
4694
-
4695
-	// 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
4696
-	if (
4697
-		!isset($objets[$type_objet][$id_objet])
4698
-		or
4699
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4700
-	) {
4701
-		if (!$trouver_table) {
4702
-			$trouver_table = charger_fonction('trouver_table', 'base');
4703
-		}
4704
-		$desc = $trouver_table(table_objet_sql($type_objet));
4705
-		if (!$desc) {
4706
-			return $objets[$type_objet] = false;
4707
-		}
4708
-
4709
-		// Si on demande le titre, on le gere en interne
4710
-		$champ_titre = '';
4711
-		if ($demande_titre) {
4712
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4713
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4714
-		}
4715
-		include_spip('base/abstract_sql');
4716
-		include_spip('base/connect_sql');
4717
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4718
-			'*' . $champ_titre,
4719
-			$desc['table_sql'],
4720
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4721
-		);
4722
-
4723
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4724
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4725
-	}
4726
-
4727
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4728
-	// ajouter la longueur au début des params supplémentaires
4729
-	if ($demande_introduction) {
4730
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4731
-		array_unshift($params, $introduction_longueur);
4732
-	}
4733
-
4734
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4735
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4736
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4737
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4738
-	else {
4739
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4740
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4741
-		} // Sinon on prend directement le champ SQL tel quel
4742
-		else {
4743
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4744
-		}
4745
-	}
4746
-
4747
-	// On va ensuite appliquer les traitements automatiques si besoin
4748
-	if (!$etoile) {
4749
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4750
-		// mais ce fonctionnement est a ameliorer !
4751
-		$info_generee = appliquer_traitement_champ(
4752
-			$info_generee,
4753
-			$info,
4754
-			table_objet($type_objet),
4755
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4756
-		);
4757
-	}
4758
-
4759
-	return $info_generee;
4672
+    static $trouver_table = null;
4673
+    static $objets;
4674
+
4675
+    // On verifie qu'on a tout ce qu'il faut
4676
+    $id_objet = intval($id_objet);
4677
+    if (!($id_objet and $type_objet and $info)) {
4678
+        return '';
4679
+    }
4680
+
4681
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4682
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4683
+        return '';
4684
+    }
4685
+
4686
+    // Si on demande l'url, on retourne direct la fonction
4687
+    if ($info == 'url') {
4688
+        return generer_url_entite($id_objet, $type_objet, ...$params);
4689
+    }
4690
+
4691
+    // Sinon on va tout chercher dans la table et on garde en memoire
4692
+    $demande_titre = ($info === 'titre');
4693
+    $demande_introduction = ($info === 'introduction');
4694
+
4695
+    // 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
4696
+    if (
4697
+        !isset($objets[$type_objet][$id_objet])
4698
+        or
4699
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4700
+    ) {
4701
+        if (!$trouver_table) {
4702
+            $trouver_table = charger_fonction('trouver_table', 'base');
4703
+        }
4704
+        $desc = $trouver_table(table_objet_sql($type_objet));
4705
+        if (!$desc) {
4706
+            return $objets[$type_objet] = false;
4707
+        }
4708
+
4709
+        // Si on demande le titre, on le gere en interne
4710
+        $champ_titre = '';
4711
+        if ($demande_titre) {
4712
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4713
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4714
+        }
4715
+        include_spip('base/abstract_sql');
4716
+        include_spip('base/connect_sql');
4717
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4718
+            '*' . $champ_titre,
4719
+            $desc['table_sql'],
4720
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4721
+        );
4722
+
4723
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4724
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4725
+    }
4726
+
4727
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4728
+    // ajouter la longueur au début des params supplémentaires
4729
+    if ($demande_introduction) {
4730
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4731
+        array_unshift($params, $introduction_longueur);
4732
+    }
4733
+
4734
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4735
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4736
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4737
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4738
+    else {
4739
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4740
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4741
+        } // Sinon on prend directement le champ SQL tel quel
4742
+        else {
4743
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4744
+        }
4745
+    }
4746
+
4747
+    // On va ensuite appliquer les traitements automatiques si besoin
4748
+    if (!$etoile) {
4749
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4750
+        // mais ce fonctionnement est a ameliorer !
4751
+        $info_generee = appliquer_traitement_champ(
4752
+            $info_generee,
4753
+            $info,
4754
+            table_objet($type_objet),
4755
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4756
+        );
4757
+    }
4758
+
4759
+    return $info_generee;
4760 4760
 }
4761 4761
 
4762 4762
 /**
@@ -4789,36 +4789,36 @@  discard block
 block discarded – undo
4789 4789
  */
4790 4790
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, $connect = '') {
4791 4791
 
4792
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4793
-	$texte = $ligne_sql['texte'] ?? '';
4794
-	// En absence de descriptif, on se rabat sur chapo + texte
4795
-	if (isset($ligne_sql['chapo'])) {
4796
-		$chapo = $ligne_sql['chapo'];
4797
-		$texte = strlen($descriptif) ?
4798
-			'' :
4799
-			"$chapo \n\n $texte";
4800
-	}
4792
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4793
+    $texte = $ligne_sql['texte'] ?? '';
4794
+    // En absence de descriptif, on se rabat sur chapo + texte
4795
+    if (isset($ligne_sql['chapo'])) {
4796
+        $chapo = $ligne_sql['chapo'];
4797
+        $texte = strlen($descriptif) ?
4798
+            '' :
4799
+            "$chapo \n\n $texte";
4800
+    }
4801 4801
 
4802
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4803
-	if (!intval($longueur_ou_suite)) {
4804
-		$longueur = intval($introduction_longueur ?: 600);
4805
-	} else {
4806
-		$longueur = intval($longueur_ou_suite);
4807
-	}
4802
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4803
+    if (!intval($longueur_ou_suite)) {
4804
+        $longueur = intval($introduction_longueur ?: 600);
4805
+    } else {
4806
+        $longueur = intval($longueur_ou_suite);
4807
+    }
4808 4808
 
4809
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4810
-	// Ex : #INTRODUCTION{...}
4811
-	if (
4812
-		is_null($suite)
4813
-		and !intval($longueur_ou_suite)
4814
-	) {
4815
-		$suite = $longueur_ou_suite;
4816
-	}
4809
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4810
+    // Ex : #INTRODUCTION{...}
4811
+    if (
4812
+        is_null($suite)
4813
+        and !intval($longueur_ou_suite)
4814
+    ) {
4815
+        $suite = $longueur_ou_suite;
4816
+    }
4817 4817
 
4818
-	$f = chercher_filtre('introduction');
4819
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4818
+    $f = chercher_filtre('introduction');
4819
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4820 4820
 
4821
-	return $introduction;
4821
+    return $introduction;
4822 4822
 }
4823 4823
 
4824 4824
 /**
@@ -4832,44 +4832,44 @@  discard block
 block discarded – undo
4832 4832
  * @return string
4833 4833
  */
4834 4834
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], $connect = '') {
4835
-	if (!$champ) {
4836
-		return $texte;
4837
-	}
4835
+    if (!$champ) {
4836
+        return $texte;
4837
+    }
4838 4838
 
4839
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4840
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4841
-	include_fichiers_fonctions();
4839
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4840
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4841
+    include_fichiers_fonctions();
4842 4842
 
4843
-	$champ = strtoupper($champ);
4844
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4845
-	if (!$traitements or !is_array($traitements)) {
4846
-		return $texte;
4847
-	}
4843
+    $champ = strtoupper($champ);
4844
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4845
+    if (!$traitements or !is_array($traitements)) {
4846
+        return $texte;
4847
+    }
4848 4848
 
4849
-	$traitement = '';
4850
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4851
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4852
-		$table_objet = table_objet($table_objet);
4853
-		if (isset($traitements[$table_objet])) {
4854
-			$traitement = $traitements[$table_objet];
4855
-		}
4856
-	}
4857
-	if (!$traitement and isset($traitements[0])) {
4858
-		$traitement = $traitements[0];
4859
-	}
4860
-	// (sinon prendre le premier de la liste par defaut ?)
4849
+    $traitement = '';
4850
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4851
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4852
+        $table_objet = table_objet($table_objet);
4853
+        if (isset($traitements[$table_objet])) {
4854
+            $traitement = $traitements[$table_objet];
4855
+        }
4856
+    }
4857
+    if (!$traitement and isset($traitements[0])) {
4858
+        $traitement = $traitements[0];
4859
+    }
4860
+    // (sinon prendre le premier de la liste par defaut ?)
4861 4861
 
4862
-	if (!$traitement) {
4863
-		return $texte;
4864
-	}
4862
+    if (!$traitement) {
4863
+        return $texte;
4864
+    }
4865 4865
 
4866
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4866
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4867 4867
 
4868
-	// Fournir $connect et $Pile[0] au traitement si besoin
4869
-	$Pile = [0 => $env];
4870
-	eval("\$texte = $traitement;");
4868
+    // Fournir $connect et $Pile[0] au traitement si besoin
4869
+    $Pile = [0 => $env];
4870
+    eval("\$texte = $traitement;");
4871 4871
 
4872
-	return $texte;
4872
+    return $texte;
4873 4873
 }
4874 4874
 
4875 4875
 
@@ -4883,21 +4883,21 @@  discard block
 block discarded – undo
4883 4883
  * @return string
4884 4884
  */
4885 4885
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4886
-	include_spip('inc/liens');
4887
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4888
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4889
-	// le raccourcis n'est plus valide
4890
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4891
-	// on essaye avec generer_info_entite ?
4892
-	if (!strlen($titre) and !$connect) {
4893
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4894
-	}
4895
-	if (!strlen($titre)) {
4896
-		$titre = _T('info_sans_titre');
4897
-	}
4898
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4886
+    include_spip('inc/liens');
4887
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4888
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4889
+    // le raccourcis n'est plus valide
4890
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4891
+    // on essaye avec generer_info_entite ?
4892
+    if (!strlen($titre) and !$connect) {
4893
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4894
+    }
4895
+    if (!strlen($titre)) {
4896
+        $titre = _T('info_sans_titre');
4897
+    }
4898
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4899 4899
 
4900
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4900
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4901 4901
 }
4902 4902
 
4903 4903
 
@@ -4914,15 +4914,15 @@  discard block
 block discarded – undo
4914 4914
  * @return string
4915 4915
  */
4916 4916
 function wrap($texte, $wrap) {
4917
-	$balises = extraire_balises($wrap);
4918
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4919
-		$texte = $wrap . $texte;
4920
-		$regs = array_reverse($regs[1]);
4921
-		$wrap = '</' . implode('></', $regs) . '>';
4922
-		$texte = $texte . $wrap;
4923
-	}
4917
+    $balises = extraire_balises($wrap);
4918
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4919
+        $texte = $wrap . $texte;
4920
+        $regs = array_reverse($regs[1]);
4921
+        $wrap = '</' . implode('></', $regs) . '>';
4922
+        $texte = $texte . $wrap;
4923
+    }
4924 4924
 
4925
-	return $texte;
4925
+    return $texte;
4926 4926
 }
4927 4927
 
4928 4928
 
@@ -4942,44 +4942,44 @@  discard block
 block discarded – undo
4942 4942
  * @return array|mixed|string
4943 4943
  */
4944 4944
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4945
-	if (is_string($u)) {
4946
-		$u = typo($u);
4945
+    if (is_string($u)) {
4946
+        $u = typo($u);
4947 4947
 
4948
-		return $u;
4949
-	}
4948
+        return $u;
4949
+    }
4950 4950
 
4951
-	// caster $u en array si besoin
4952
-	if (is_object($u)) {
4953
-		$u = (array)$u;
4954
-	}
4951
+    // caster $u en array si besoin
4952
+    if (is_object($u)) {
4953
+        $u = (array)$u;
4954
+    }
4955 4955
 
4956
-	if (is_array($u)) {
4957
-		$out = '';
4958
-		// toutes les cles sont numeriques ?
4959
-		// et aucun enfant n'est un tableau
4960
-		// liste simple separee par des virgules
4961
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4962
-		$array_values = array_map('is_array', $u);
4963
-		$object_values = array_map('is_object', $u);
4964
-		if (
4965
-			array_sum($numeric_keys) == count($numeric_keys)
4966
-			and !array_sum($array_values)
4967
-			and !array_sum($object_values)
4968
-		) {
4969
-			return join(', ', array_map('filtre_print_dist', $u));
4970
-		}
4956
+    if (is_array($u)) {
4957
+        $out = '';
4958
+        // toutes les cles sont numeriques ?
4959
+        // et aucun enfant n'est un tableau
4960
+        // liste simple separee par des virgules
4961
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4962
+        $array_values = array_map('is_array', $u);
4963
+        $object_values = array_map('is_object', $u);
4964
+        if (
4965
+            array_sum($numeric_keys) == count($numeric_keys)
4966
+            and !array_sum($array_values)
4967
+            and !array_sum($object_values)
4968
+        ) {
4969
+            return join(', ', array_map('filtre_print_dist', $u));
4970
+        }
4971 4971
 
4972
-		// sinon on passe a la ligne et on indente
4973
-		$i_str = str_pad('', $indent, ' ');
4974
-		foreach ($u as $k => $v) {
4975
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4976
-		}
4972
+        // sinon on passe a la ligne et on indente
4973
+        $i_str = str_pad('', $indent, ' ');
4974
+        foreach ($u as $k => $v) {
4975
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4976
+        }
4977 4977
 
4978
-		return $out;
4979
-	}
4978
+        return $out;
4979
+    }
4980 4980
 
4981
-	// on sait pas quoi faire...
4982
-	return $u;
4981
+    // on sait pas quoi faire...
4982
+    return $u;
4983 4983
 }
4984 4984
 
4985 4985
 
@@ -4992,10 +4992,10 @@  discard block
 block discarded – undo
4992 4992
  * @return string|array
4993 4993
  */
4994 4994
 function objet_info($objet, $info) {
4995
-	$table = table_objet_sql($objet);
4996
-	$infos = lister_tables_objets_sql($table);
4995
+    $table = table_objet_sql($objet);
4996
+    $infos = lister_tables_objets_sql($table);
4997 4997
 
4998
-	return (isset($infos[$info]) ? $infos[$info] : '');
4998
+    return (isset($infos[$info]) ? $infos[$info] : '');
4999 4999
 }
5000 5000
 
5001 5001
 /**
@@ -5010,11 +5010,11 @@  discard block
 block discarded – undo
5010 5010
  *     Texte traduit du comptage, tel que '3 articles'
5011 5011
  */
5012 5012
 function objet_afficher_nb($nb, $objet) {
5013
-	if (!$nb) {
5014
-		return _T(objet_info($objet, 'info_aucun_objet'));
5015
-	} else {
5016
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5017
-	}
5013
+    if (!$nb) {
5014
+        return _T(objet_info($objet, 'info_aucun_objet'));
5015
+    } else {
5016
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5017
+    }
5018 5018
 }
5019 5019
 
5020 5020
 /**
@@ -5026,11 +5026,11 @@  discard block
 block discarded – undo
5026 5026
  * @return string
5027 5027
  */
5028 5028
 function objet_icone($objet, $taille = 24, $class = '') {
5029
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5030
-	$icone = chemin_image($icone);
5031
-	$balise_img = charger_filtre('balise_img');
5029
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5030
+    $icone = chemin_image($icone);
5031
+    $balise_img = charger_filtre('balise_img');
5032 5032
 
5033
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5033
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5034 5034
 }
5035 5035
 
5036 5036
 /**
@@ -5051,12 +5051,12 @@  discard block
 block discarded – undo
5051 5051
  * @return string
5052 5052
  */
5053 5053
 function objet_T($objet, $chaine, $args = [], $options = []) {
5054
-	$chaine = explode(':', $chaine);
5055
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5056
-		return $t;
5057
-	}
5058
-	$chaine = implode(':', $chaine);
5059
-	return _T($chaine, $args, $options);
5054
+    $chaine = explode(':', $chaine);
5055
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5056
+        return $t;
5057
+    }
5058
+    $chaine = implode(':', $chaine);
5059
+    return _T($chaine, $args, $options);
5060 5060
 }
5061 5061
 
5062 5062
 /**
@@ -5070,18 +5070,18 @@  discard block
 block discarded – undo
5070 5070
  * @return string      Code HTML
5071 5071
  */
5072 5072
 function insert_head_css_conditionnel($flux) {
5073
-	if (
5074
-		strpos($flux, '<!-- insert_head_css -->') === false
5075
-		and $p = strpos($flux, '<!-- insert_head -->')
5076
-	) {
5077
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5078
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5079
-			$p = $p1;
5080
-		}
5081
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5082
-	}
5073
+    if (
5074
+        strpos($flux, '<!-- insert_head_css -->') === false
5075
+        and $p = strpos($flux, '<!-- insert_head -->')
5076
+    ) {
5077
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5078
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5079
+            $p = $p1;
5080
+        }
5081
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5082
+    }
5083 5083
 
5084
-	return $flux;
5084
+    return $flux;
5085 5085
 }
5086 5086
 
5087 5087
 /**
@@ -5104,72 +5104,72 @@  discard block
 block discarded – undo
5104 5104
  * @return string
5105 5105
  */
5106 5106
 function produire_fond_statique($fond, $contexte = [], $options = [], $connect = '') {
5107
-	if (isset($contexte['format'])) {
5108
-		$extension = $contexte['format'];
5109
-		unset($contexte['format']);
5110
-	} else {
5111
-		$extension = 'html';
5112
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5113
-			$extension = $m[1];
5114
-		}
5115
-	}
5116
-	// recuperer le contenu produit par le squelette
5117
-	$options['raw'] = true;
5118
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5119
-
5120
-	// calculer le nom de la css
5121
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5122
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5123
-	$contexte_implicite = calculer_contexte_implicite();
5124
-
5125
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5126
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5127
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5128
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5129
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5130
-	}
5131
-	else {
5132
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5133
-		ksort($contexte);
5134
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5135
-	}
5136
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5137
-
5138
-	// mettre a jour le fichier si il n'existe pas
5139
-	// ou trop ancien
5140
-	// le dernier fichier produit est toujours suffixe par .last
5141
-	// et recopie sur le fichier cible uniquement si il change
5142
-	if (
5143
-		!file_exists($filename)
5144
-		or !file_exists($filename . '.last')
5145
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5146
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5147
-	) {
5148
-		$contenu = $cache['texte'];
5149
-		// passer les urls en absolu si c'est une css
5150
-		if ($extension == 'css') {
5151
-			$contenu = urls_absolues_css(
5152
-				$contenu,
5153
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5154
-			);
5155
-		}
5156
-
5157
-		$comment = '';
5158
-		// ne pas insérer de commentaire sur certains formats
5159
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5160
-			$comment = "/* #PRODUIRE{fond=$fond";
5161
-			foreach ($contexte as $k => $v) {
5162
-				$comment .= ",$k=$v";
5163
-			}
5164
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5165
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5166
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5167
-		}
5168
-		// et ecrire le fichier si il change
5169
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5170
-	}
5171
-
5172
-	return timestamp($filename);
5107
+    if (isset($contexte['format'])) {
5108
+        $extension = $contexte['format'];
5109
+        unset($contexte['format']);
5110
+    } else {
5111
+        $extension = 'html';
5112
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5113
+            $extension = $m[1];
5114
+        }
5115
+    }
5116
+    // recuperer le contenu produit par le squelette
5117
+    $options['raw'] = true;
5118
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5119
+
5120
+    // calculer le nom de la css
5121
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5122
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5123
+    $contexte_implicite = calculer_contexte_implicite();
5124
+
5125
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5126
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5127
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5128
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5129
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5130
+    }
5131
+    else {
5132
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5133
+        ksort($contexte);
5134
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5135
+    }
5136
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5137
+
5138
+    // mettre a jour le fichier si il n'existe pas
5139
+    // ou trop ancien
5140
+    // le dernier fichier produit est toujours suffixe par .last
5141
+    // et recopie sur le fichier cible uniquement si il change
5142
+    if (
5143
+        !file_exists($filename)
5144
+        or !file_exists($filename . '.last')
5145
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5146
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5147
+    ) {
5148
+        $contenu = $cache['texte'];
5149
+        // passer les urls en absolu si c'est une css
5150
+        if ($extension == 'css') {
5151
+            $contenu = urls_absolues_css(
5152
+                $contenu,
5153
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5154
+            );
5155
+        }
5156
+
5157
+        $comment = '';
5158
+        // ne pas insérer de commentaire sur certains formats
5159
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5160
+            $comment = "/* #PRODUIRE{fond=$fond";
5161
+            foreach ($contexte as $k => $v) {
5162
+                $comment .= ",$k=$v";
5163
+            }
5164
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5165
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5166
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5167
+        }
5168
+        // et ecrire le fichier si il change
5169
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5170
+    }
5171
+
5172
+    return timestamp($filename);
5173 5173
 }
5174 5174
 
5175 5175
 /**
@@ -5182,15 +5182,15 @@  discard block
 block discarded – undo
5182 5182
  *    $fichier auquel on a ajouté le timestamp
5183 5183
  */
5184 5184
 function timestamp($fichier) {
5185
-	if (
5186
-		!$fichier
5187
-		or !file_exists($fichier)
5188
-		or !$m = filemtime($fichier)
5189
-	) {
5190
-		return $fichier;
5191
-	}
5185
+    if (
5186
+        !$fichier
5187
+        or !file_exists($fichier)
5188
+        or !$m = filemtime($fichier)
5189
+    ) {
5190
+        return $fichier;
5191
+    }
5192 5192
 
5193
-	return "$fichier?$m";
5193
+    return "$fichier?$m";
5194 5194
 }
5195 5195
 
5196 5196
 /**
@@ -5200,11 +5200,11 @@  discard block
 block discarded – undo
5200 5200
  * @return string
5201 5201
  */
5202 5202
 function supprimer_timestamp($url) {
5203
-	if (strpos($url, '?') === false) {
5204
-		return $url;
5205
-	}
5203
+    if (strpos($url, '?') === false) {
5204
+        return $url;
5205
+    }
5206 5206
 
5207
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5207
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5208 5208
 }
5209 5209
 
5210 5210
 /**
@@ -5219,9 +5219,9 @@  discard block
 block discarded – undo
5219 5219
  * @return string
5220 5220
  */
5221 5221
 function filtre_nettoyer_titre_email_dist($titre) {
5222
-	include_spip('inc/envoyer_mail');
5222
+    include_spip('inc/envoyer_mail');
5223 5223
 
5224
-	return nettoyer_titre_email($titre);
5224
+    return nettoyer_titre_email($titre);
5225 5225
 }
5226 5226
 
5227 5227
 /**
@@ -5243,27 +5243,27 @@  discard block
 block discarded – undo
5243 5243
  * @return string
5244 5244
  */
5245 5245
 function filtre_chercher_rubrique_dist(
5246
-	$titre,
5247
-	$id_objet,
5248
-	$id_parent,
5249
-	$objet,
5250
-	$id_secteur,
5251
-	$restreint,
5252
-	$actionable = false,
5253
-	$retour_sans_cadre = false
5246
+    $titre,
5247
+    $id_objet,
5248
+    $id_parent,
5249
+    $objet,
5250
+    $id_secteur,
5251
+    $restreint,
5252
+    $actionable = false,
5253
+    $retour_sans_cadre = false
5254 5254
 ) {
5255
-	include_spip('inc/filtres_ecrire');
5255
+    include_spip('inc/filtres_ecrire');
5256 5256
 
5257
-	return chercher_rubrique(
5258
-		$titre,
5259
-		$id_objet,
5260
-		$id_parent,
5261
-		$objet,
5262
-		$id_secteur,
5263
-		$restreint,
5264
-		$actionable,
5265
-		$retour_sans_cadre
5266
-	);
5257
+    return chercher_rubrique(
5258
+        $titre,
5259
+        $id_objet,
5260
+        $id_parent,
5261
+        $objet,
5262
+        $id_secteur,
5263
+        $restreint,
5264
+        $actionable,
5265
+        $retour_sans_cadre
5266
+    );
5267 5267
 }
5268 5268
 
5269 5269
 /**
@@ -5292,56 +5292,56 @@  discard block
 block discarded – undo
5292 5292
  *     Chaîne vide si l'accès est autorisé
5293 5293
  */
5294 5294
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5295
-	if ($ok) {
5296
-		return '';
5297
-	}
5298
-
5299
-	// Vider tous les tampons
5300
-	$level = @ob_get_level();
5301
-	while ($level--) {
5302
-		@ob_end_clean();
5303
-	}
5304
-
5305
-	include_spip('inc/headers');
5306
-
5307
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5308
-	if ($url) {
5309
-		redirige_par_entete($url, '', $statut);
5310
-	}
5311
-
5312
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5313
-	if (!is_numeric($statut) and is_null($message)) {
5314
-		$message = $statut;
5315
-		$statut = 0;
5316
-	}
5317
-	if (!$message) {
5318
-		$message = '';
5319
-	}
5320
-	$statut = intval($statut);
5321
-
5322
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5323
-	if (test_espace_prive()) {
5324
-		if (!$statut or !in_array($statut, [404, 403])) {
5325
-			$statut = 403;
5326
-		}
5327
-		http_response_code(403);
5328
-		$echec = charger_fonction('403', 'exec');
5329
-		$echec($message);
5330
-	} else {
5331
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5332
-		if (!$statut) {
5333
-			$statut = 404;
5334
-		}
5335
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5336
-		http_response_code($statut);
5337
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5338
-		if ($statut >= 400) {
5339
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5340
-		}
5341
-	}
5342
-
5343
-
5344
-	exit;
5295
+    if ($ok) {
5296
+        return '';
5297
+    }
5298
+
5299
+    // Vider tous les tampons
5300
+    $level = @ob_get_level();
5301
+    while ($level--) {
5302
+        @ob_end_clean();
5303
+    }
5304
+
5305
+    include_spip('inc/headers');
5306
+
5307
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5308
+    if ($url) {
5309
+        redirige_par_entete($url, '', $statut);
5310
+    }
5311
+
5312
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5313
+    if (!is_numeric($statut) and is_null($message)) {
5314
+        $message = $statut;
5315
+        $statut = 0;
5316
+    }
5317
+    if (!$message) {
5318
+        $message = '';
5319
+    }
5320
+    $statut = intval($statut);
5321
+
5322
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5323
+    if (test_espace_prive()) {
5324
+        if (!$statut or !in_array($statut, [404, 403])) {
5325
+            $statut = 403;
5326
+        }
5327
+        http_response_code(403);
5328
+        $echec = charger_fonction('403', 'exec');
5329
+        $echec($message);
5330
+    } else {
5331
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5332
+        if (!$statut) {
5333
+            $statut = 404;
5334
+        }
5335
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5336
+        http_response_code($statut);
5337
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5338
+        if ($statut >= 400) {
5339
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5340
+        }
5341
+    }
5342
+
5343
+
5344
+    exit;
5345 5345
 }
5346 5346
 
5347 5347
 /**
@@ -5352,11 +5352,11 @@  discard block
 block discarded – undo
5352 5352
  * @return string
5353 5353
  */
5354 5354
 function filtre_compacte_dist($source, $format = null) {
5355
-	if (function_exists('compacte')) {
5356
-		return compacte($source, $format);
5357
-	}
5355
+    if (function_exists('compacte')) {
5356
+        return compacte($source, $format);
5357
+    }
5358 5358
 
5359
-	return $source;
5359
+    return $source;
5360 5360
 }
5361 5361
 
5362 5362
 
@@ -5368,31 +5368,31 @@  discard block
 block discarded – undo
5368 5368
  * @return string
5369 5369
  */
5370 5370
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5371
-	$l = strlen($passe);
5372
-
5373
-	if ($l <= 8 or !$afficher_partiellement) {
5374
-		if (!$l) {
5375
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5376
-		}
5377
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5378
-	}
5379
-
5380
-	if (is_null($portion_pourcent)) {
5381
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5382
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5383
-		}
5384
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5385
-	}
5386
-	if ($portion_pourcent >= 100) {
5387
-		return $passe;
5388
-	}
5389
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5390
-	$e = max($e, 0);
5391
-	$mid = str_pad('', $l - 2 * $e, '*');
5392
-	if ($e > 0 and strlen($mid) > 8) {
5393
-		$mid = '***...***';
5394
-	}
5395
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5371
+    $l = strlen($passe);
5372
+
5373
+    if ($l <= 8 or !$afficher_partiellement) {
5374
+        if (!$l) {
5375
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5376
+        }
5377
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5378
+    }
5379
+
5380
+    if (is_null($portion_pourcent)) {
5381
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5382
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5383
+        }
5384
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5385
+    }
5386
+    if ($portion_pourcent >= 100) {
5387
+        return $passe;
5388
+    }
5389
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5390
+    $e = max($e, 0);
5391
+    $mid = str_pad('', $l - 2 * $e, '*');
5392
+    if ($e > 0 and strlen($mid) > 8) {
5393
+        $mid = '***...***';
5394
+    }
5395
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5396 5396
 }
5397 5397
 
5398 5398
 
@@ -5413,64 +5413,64 @@  discard block
 block discarded – undo
5413 5413
  */
5414 5414
 function identifiant_slug($texte, $type = '', $options = []) {
5415 5415
 
5416
-	$original = $texte;
5417
-	$separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5418
-	$longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5419
-	$longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5416
+    $original = $texte;
5417
+    $separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5418
+    $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5419
+    $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5420 5420
 
5421
-	if (!function_exists('translitteration')) {
5422
-		include_spip('inc/charsets');
5423
-	}
5421
+    if (!function_exists('translitteration')) {
5422
+        include_spip('inc/charsets');
5423
+    }
5424 5424
 
5425
-	// pas de balise html
5426
-	if (strpos($texte, '<') !== false) {
5427
-		$texte = strip_tags($texte);
5428
-	}
5429
-	if (strpos($texte, '&') !== false) {
5430
-		$texte = unicode2charset($texte);
5431
-	}
5432
-	// On enlève les espaces indésirables
5433
-	$texte = trim($texte);
5425
+    // pas de balise html
5426
+    if (strpos($texte, '<') !== false) {
5427
+        $texte = strip_tags($texte);
5428
+    }
5429
+    if (strpos($texte, '&') !== false) {
5430
+        $texte = unicode2charset($texte);
5431
+    }
5432
+    // On enlève les espaces indésirables
5433
+    $texte = trim($texte);
5434 5434
 
5435
-	// On enlève les accents et cie
5436
-	$texte = translitteration($texte);
5435
+    // On enlève les accents et cie
5436
+    $texte = translitteration($texte);
5437 5437
 
5438
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5439
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5438
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5439
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5440 5440
 
5441
-	// nettoyer les doubles occurences du separateur si besoin
5442
-	while (strpos($texte, "$separateur$separateur") !== false) {
5443
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5444
-	}
5441
+    // nettoyer les doubles occurences du separateur si besoin
5442
+    while (strpos($texte, "$separateur$separateur") !== false) {
5443
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5444
+    }
5445 5445
 
5446
-	// pas de separateur au debut ni a la fin
5447
-	$texte = trim($texte, $separateur);
5446
+    // pas de separateur au debut ni a la fin
5447
+    $texte = trim($texte, $separateur);
5448 5448
 
5449
-	// en minuscules
5450
-	$texte = strtolower($texte);
5449
+    // en minuscules
5450
+    $texte = strtolower($texte);
5451 5451
 
5452
-	switch ($type) {
5453
-		case 'class':
5454
-		case 'id':
5455
-		case 'anchor':
5456
-			if (preg_match(',^\d,', $texte)) {
5457
-				$texte = substr($type, 0, 1) . $texte;
5458
-			}
5459
-	}
5452
+    switch ($type) {
5453
+        case 'class':
5454
+        case 'id':
5455
+        case 'anchor':
5456
+            if (preg_match(',^\d,', $texte)) {
5457
+                $texte = substr($type, 0, 1) . $texte;
5458
+            }
5459
+    }
5460 5460
 
5461
-	if (strlen($texte) > $longueur_maxi) {
5462
-		$texte = substr($texte, 0, $longueur_maxi);
5463
-	}
5461
+    if (strlen($texte) > $longueur_maxi) {
5462
+        $texte = substr($texte, 0, $longueur_maxi);
5463
+    }
5464 5464
 
5465
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5466
-		if (preg_match(',^\d,', $texte)) {
5467
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5468
-		}
5469
-		$texte .= $separateur . md5($original);
5470
-		$texte = substr($texte, 0, $longueur_mini);
5471
-	}
5465
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5466
+        if (preg_match(',^\d,', $texte)) {
5467
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5468
+        }
5469
+        $texte .= $separateur . md5($original);
5470
+        $texte = substr($texte, 0, $longueur_mini);
5471
+    }
5472 5472
 
5473
-	return $texte;
5473
+    return $texte;
5474 5474
 }
5475 5475
 
5476 5476
 
@@ -5491,11 +5491,11 @@  discard block
 block discarded – undo
5491 5491
  * @exemple `<:info_maximum|label_nettoyer:>`
5492 5492
  */
5493 5493
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5494
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5495
-	if ($ucfirst) {
5496
-		$label = spip_ucfirst($label);
5497
-	}
5498
-	return $label;
5494
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5495
+    if ($ucfirst) {
5496
+        $label = spip_ucfirst($label);
5497
+    }
5498
+    return $label;
5499 5499
 }
5500 5500
 
5501 5501
 /**
@@ -5508,8 +5508,8 @@  discard block
 block discarded – undo
5508 5508
  * @exemple `<:info_maximum|label_ponctuer:>`
5509 5509
  */
5510 5510
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5511
-	$label = label_nettoyer($text, $ucfirst);
5512
-	return _T('label_ponctuer', ['label' => $label]);
5511
+    $label = label_nettoyer($text, $ucfirst);
5512
+    return _T('label_ponctuer', ['label' => $label]);
5513 5513
 }
5514 5514
 
5515 5515
 
@@ -5522,19 +5522,19 @@  discard block
 block discarded – undo
5522 5522
  * @return array
5523 5523
  */
5524 5524
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5525
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5526
-		return [];
5527
-	}
5525
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5526
+        return [];
5527
+    }
5528 5528
 
5529
-	// compatibilite signature inversee
5530
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5531
-		list($objet, $id_objet) = [$id_objet, $objet];
5532
-	}
5529
+    // compatibilite signature inversee
5530
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5531
+        list($objet, $id_objet) = [$id_objet, $objet];
5532
+    }
5533 5533
 
5534
-	if (!function_exists($fonction)) {
5535
-		include_spip('base/objets');
5536
-	}
5537
-	return $fonction($objet, $id_objet);
5534
+    if (!function_exists($fonction)) {
5535
+        include_spip('base/objets');
5536
+    }
5537
+    return $fonction($objet, $id_objet);
5538 5538
 }
5539 5539
 
5540 5540
 
@@ -5549,7 +5549,7 @@  discard block
 block discarded – undo
5549 5549
  * @return array
5550 5550
  */
5551 5551
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5552
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5552
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5553 5553
 }
5554 5554
 
5555 5555
 /**
@@ -5563,7 +5563,7 @@  discard block
 block discarded – undo
5563 5563
  * @return array
5564 5564
  */
5565 5565
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5566
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5566
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5567 5567
 }
5568 5568
 
5569 5569
 /**
@@ -5577,7 +5577,7 @@  discard block
 block discarded – undo
5577 5577
  * @return array
5578 5578
  */
5579 5579
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5580
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5580
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5581 5581
 }
5582 5582
 
5583 5583
 /**
@@ -5591,5 +5591,5 @@  discard block
 block discarded – undo
5591 5591
  * @return array
5592 5592
  */
5593 5593
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5594
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5594
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5595 5595
 }
Please login to merge, or discard this patch.
ecrire/inc/distant.php 2 patches
Indentation   +1033 added lines, -1033 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2097152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2097152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		(isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,85 +68,85 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode == 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode == 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local == $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode == 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
-		}
120
-		if (!$res['length']) {
121
-			// si $t c'est sans doute juste un not-modified-since
122
-			return $t ? $local : false;
123
-		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
-
126
-		// si on retrouve l'extension
127
-		if (!empty($res['headers'])
128
-		  and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])) {
129
-			if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
130
-				$sanitizer($localrac);
131
-			}
132
-		}
133
-
134
-		// pour une eventuelle indexation
135
-		pipeline(
136
-			'post_edition',
137
-			[
138
-				'args' => [
139
-					'operation' => 'copie_locale',
140
-					'source' => $source,
141
-					'fichier' => $local,
142
-					'http_res' => $res['length'],
143
-				],
144
-				'data' => null
145
-			]
146
-		);
147
-	}
148
-
149
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode == 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode == 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local == $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode == 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            ['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
+        }
120
+        if (!$res['length']) {
121
+            // si $t c'est sans doute juste un not-modified-since
122
+            return $t ? $local : false;
123
+        }
124
+        spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
+
126
+        // si on retrouve l'extension
127
+        if (!empty($res['headers'])
128
+          and $extension = distant_trouver_extension_selon_headers($source, $res['headers'])) {
129
+            if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
130
+                $sanitizer($localrac);
131
+            }
132
+        }
133
+
134
+        // pour une eventuelle indexation
135
+        pipeline(
136
+            'post_edition',
137
+            [
138
+                'args' => [
139
+                    'operation' => 'copie_locale',
140
+                    'source' => $source,
141
+                    'fichier' => $local,
142
+                    'http_res' => $res['length'],
143
+                ],
144
+                'data' => null
145
+            ]
146
+        );
147
+    }
148
+
149
+    return $local;
150 150
 }
151 151
 
152 152
 /**
@@ -161,93 +161,93 @@  discard block
 block discarded – undo
161 161
  *   url ou false en cas d'echec
162 162
  */
163 163
 function valider_url_distante($url, $known_hosts = []) {
164
-	if (!function_exists('protocole_verifier')) {
165
-		include_spip('inc/filtres_mini');
166
-	}
167
-
168
-	if (!protocole_verifier($url, ['http', 'https'])) {
169
-		return false;
170
-	}
171
-
172
-	$parsed_url = parse_url($url);
173
-	if (!$parsed_url or empty($parsed_url['host'])) {
174
-		return false;
175
-	}
176
-
177
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
178
-		return false;
179
-	}
180
-
181
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
182
-		return false;
183
-	}
184
-
185
-	if (!is_array($known_hosts)) {
186
-		$known_hosts = [$known_hosts];
187
-	}
188
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
189
-	$known_hosts[] = url_de_base();
190
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
191
-
192
-	$is_known_host = false;
193
-	foreach ($known_hosts as $known_host) {
194
-		$parse_known = parse_url($known_host);
195
-		if (
196
-			$parse_known
197
-			and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
198
-		) {
199
-			$is_known_host = true;
200
-			break;
201
-		}
202
-	}
203
-
204
-	if (!$is_known_host) {
205
-		$host = trim($parsed_url['host'], '.');
206
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
207
-			$ip = $host;
208
-		} else {
209
-			$ip = gethostbyname($host);
210
-			if ($ip === $host) {
211
-				// Error condition for gethostbyname()
212
-				$ip = false;
213
-			}
214
-		}
215
-		if ($ip) {
216
-			$parts = array_map('intval', explode('.', $ip));
217
-			if (
218
-				127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
219
-				or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
220
-				or ( 192 === $parts[0] && 168 === $parts[1] )
221
-			) {
222
-				return false;
223
-			}
224
-		}
225
-	}
226
-
227
-	if (empty($parsed_url['port'])) {
228
-		return $url;
229
-	}
230
-
231
-	$port = $parsed_url['port'];
232
-	if ($port === 80  or $port === 443  or $port === 8080) {
233
-		return $url;
234
-	}
235
-
236
-	if ($is_known_host) {
237
-		foreach ($known_hosts as $known_host) {
238
-			$parse_known = parse_url($known_host);
239
-			if (
240
-				$parse_known
241
-				and !empty($parse_known['port'])
242
-				and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
243
-				and $parse_known['port'] == $port
244
-			) {
245
-				return $url;
246
-			}
247
-		}
248
-	}
249
-
250
-	return false;
164
+    if (!function_exists('protocole_verifier')) {
165
+        include_spip('inc/filtres_mini');
166
+    }
167
+
168
+    if (!protocole_verifier($url, ['http', 'https'])) {
169
+        return false;
170
+    }
171
+
172
+    $parsed_url = parse_url($url);
173
+    if (!$parsed_url or empty($parsed_url['host'])) {
174
+        return false;
175
+    }
176
+
177
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
178
+        return false;
179
+    }
180
+
181
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
182
+        return false;
183
+    }
184
+
185
+    if (!is_array($known_hosts)) {
186
+        $known_hosts = [$known_hosts];
187
+    }
188
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
189
+    $known_hosts[] = url_de_base();
190
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
191
+
192
+    $is_known_host = false;
193
+    foreach ($known_hosts as $known_host) {
194
+        $parse_known = parse_url($known_host);
195
+        if (
196
+            $parse_known
197
+            and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
198
+        ) {
199
+            $is_known_host = true;
200
+            break;
201
+        }
202
+    }
203
+
204
+    if (!$is_known_host) {
205
+        $host = trim($parsed_url['host'], '.');
206
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
207
+            $ip = $host;
208
+        } else {
209
+            $ip = gethostbyname($host);
210
+            if ($ip === $host) {
211
+                // Error condition for gethostbyname()
212
+                $ip = false;
213
+            }
214
+        }
215
+        if ($ip) {
216
+            $parts = array_map('intval', explode('.', $ip));
217
+            if (
218
+                127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
219
+                or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
220
+                or ( 192 === $parts[0] && 168 === $parts[1] )
221
+            ) {
222
+                return false;
223
+            }
224
+        }
225
+    }
226
+
227
+    if (empty($parsed_url['port'])) {
228
+        return $url;
229
+    }
230
+
231
+    $port = $parsed_url['port'];
232
+    if ($port === 80  or $port === 443  or $port === 8080) {
233
+        return $url;
234
+    }
235
+
236
+    if ($is_known_host) {
237
+        foreach ($known_hosts as $known_host) {
238
+            $parse_known = parse_url($known_host);
239
+            if (
240
+                $parse_known
241
+                and !empty($parse_known['port'])
242
+                and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
243
+                and $parse_known['port'] == $port
244
+            ) {
245
+                return $url;
246
+            }
247
+        }
248
+    }
249
+
250
+    return false;
251 251
 }
252 252
 
253 253
 /**
@@ -267,86 +267,86 @@  discard block
 block discarded – undo
267 267
  */
268 268
 function prepare_donnees_post($donnees, $boundary = '') {
269 269
 
270
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
271
-	// pour un appel soap par exemple
272
-	// l'entete est separe des donnees par un double retour a la ligne
273
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
274
-	if (is_string($donnees) && strlen($donnees)) {
275
-		$entete = '';
276
-		// on repasse tous les \r\n et \r en simples \n
277
-		$donnees = str_replace("\r\n", "\n", $donnees);
278
-		$donnees = str_replace("\r", "\n", $donnees);
279
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
280
-		$p = strpos($donnees, "\n\n");
281
-		if ($p !== false) {
282
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
283
-			$donnees = substr($donnees, $p + 2);
284
-		}
285
-		$chaine = str_replace("\n", "\r\n", $donnees);
286
-	} else {
287
-		/* boundary automatique */
288
-		// Si on a plus de 500 octects de donnees, on "boundarise"
289
-		if ($boundary === '') {
290
-			$taille = 0;
291
-			foreach ($donnees as $cle => $valeur) {
292
-				if (is_array($valeur)) {
293
-					foreach ($valeur as $val2) {
294
-						$taille += strlen($val2);
295
-					}
296
-				} else {
297
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
298
-					$taille += strlen($valeur);
299
-				}
300
-			}
301
-			if ($taille > 500) {
302
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
303
-			}
304
-		}
305
-
306
-		if (is_string($boundary) and strlen($boundary)) {
307
-			// fabrique une chaine HTTP pour un POST avec boundary
308
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
309
-			$chaine = '';
310
-			if (is_array($donnees)) {
311
-				foreach ($donnees as $cle => $valeur) {
312
-					if (is_array($valeur)) {
313
-						foreach ($valeur as $val2) {
314
-							$chaine .= "\r\n--$boundary\r\n";
315
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
316
-							$chaine .= "\r\n";
317
-							$chaine .= $val2;
318
-						}
319
-					} else {
320
-						$chaine .= "\r\n--$boundary\r\n";
321
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
322
-						$chaine .= "\r\n";
323
-						$chaine .= $valeur;
324
-					}
325
-				}
326
-				$chaine .= "\r\n--$boundary\r\n";
327
-			}
328
-		} else {
329
-			// fabrique une chaine HTTP simple pour un POST
330
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
331
-			$chaine = [];
332
-			if (is_array($donnees)) {
333
-				foreach ($donnees as $cle => $valeur) {
334
-					if (is_array($valeur)) {
335
-						foreach ($valeur as $val2) {
336
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
337
-						}
338
-					} else {
339
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
340
-					}
341
-				}
342
-				$chaine = implode('&', $chaine);
343
-			} else {
344
-				$chaine = $donnees;
345
-			}
346
-		}
347
-	}
348
-
349
-	return [$entete, $chaine];
270
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
271
+    // pour un appel soap par exemple
272
+    // l'entete est separe des donnees par un double retour a la ligne
273
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
274
+    if (is_string($donnees) && strlen($donnees)) {
275
+        $entete = '';
276
+        // on repasse tous les \r\n et \r en simples \n
277
+        $donnees = str_replace("\r\n", "\n", $donnees);
278
+        $donnees = str_replace("\r", "\n", $donnees);
279
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
280
+        $p = strpos($donnees, "\n\n");
281
+        if ($p !== false) {
282
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
283
+            $donnees = substr($donnees, $p + 2);
284
+        }
285
+        $chaine = str_replace("\n", "\r\n", $donnees);
286
+    } else {
287
+        /* boundary automatique */
288
+        // Si on a plus de 500 octects de donnees, on "boundarise"
289
+        if ($boundary === '') {
290
+            $taille = 0;
291
+            foreach ($donnees as $cle => $valeur) {
292
+                if (is_array($valeur)) {
293
+                    foreach ($valeur as $val2) {
294
+                        $taille += strlen($val2);
295
+                    }
296
+                } else {
297
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
298
+                    $taille += strlen($valeur);
299
+                }
300
+            }
301
+            if ($taille > 500) {
302
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
303
+            }
304
+        }
305
+
306
+        if (is_string($boundary) and strlen($boundary)) {
307
+            // fabrique une chaine HTTP pour un POST avec boundary
308
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
309
+            $chaine = '';
310
+            if (is_array($donnees)) {
311
+                foreach ($donnees as $cle => $valeur) {
312
+                    if (is_array($valeur)) {
313
+                        foreach ($valeur as $val2) {
314
+                            $chaine .= "\r\n--$boundary\r\n";
315
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
316
+                            $chaine .= "\r\n";
317
+                            $chaine .= $val2;
318
+                        }
319
+                    } else {
320
+                        $chaine .= "\r\n--$boundary\r\n";
321
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
322
+                        $chaine .= "\r\n";
323
+                        $chaine .= $valeur;
324
+                    }
325
+                }
326
+                $chaine .= "\r\n--$boundary\r\n";
327
+            }
328
+        } else {
329
+            // fabrique une chaine HTTP simple pour un POST
330
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
331
+            $chaine = [];
332
+            if (is_array($donnees)) {
333
+                foreach ($donnees as $cle => $valeur) {
334
+                    if (is_array($valeur)) {
335
+                        foreach ($valeur as $val2) {
336
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
337
+                        }
338
+                    } else {
339
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
340
+                    }
341
+                }
342
+                $chaine = implode('&', $chaine);
343
+            } else {
344
+                $chaine = $donnees;
345
+            }
346
+        }
347
+    }
348
+
349
+    return [$entete, $chaine];
350 350
 }
351 351
 
352 352
 /**
@@ -360,22 +360,22 @@  discard block
 block discarded – undo
360 360
  */
361 361
 function url_to_ascii($url_idn) {
362 362
 
363
-	if ($parts = parse_url($url_idn)) {
364
-		$host = $parts['host'];
365
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
366
-			include_spip('inc/idna_convert.class');
367
-			$IDN = new idna_convert();
368
-			$host_ascii = $IDN->encode($host);
369
-			$url_idn = explode($host, $url_idn, 2);
370
-			$url_idn = implode($host_ascii, $url_idn);
371
-		}
372
-		// et on urlencode les char utf si besoin dans le path
373
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) {
374
- return urlencode($match[0]);
375
-		}, $url_idn);
376
-	}
377
-
378
-	return $url_idn;
363
+    if ($parts = parse_url($url_idn)) {
364
+        $host = $parts['host'];
365
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
366
+            include_spip('inc/idna_convert.class');
367
+            $IDN = new idna_convert();
368
+            $host_ascii = $IDN->encode($host);
369
+            $url_idn = explode($host, $url_idn, 2);
370
+            $url_idn = implode($host_ascii, $url_idn);
371
+        }
372
+        // et on urlencode les char utf si besoin dans le path
373
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) {
374
+    return urlencode($match[0]);
375
+        }, $url_idn);
376
+    }
377
+
378
+    return $url_idn;
379 379
 }
380 380
 
381 381
 /**
@@ -416,197 +416,197 @@  discard block
 block discarded – undo
416 416
  *     string file : nom du fichier si enregistre dans un fichier
417 417
  */
418 418
 function recuperer_url($url, $options = []) {
419
-	// Conserve la mémoire de la méthode fournit éventuellement
420
-	$methode_demandee = $options['methode'] ?? '';
421
-	$default = [
422
-		'transcoder' => false,
423
-		'methode' => 'GET',
424
-		'taille_max' => null,
425
-		'headers' => [],
426
-		'datas' => '',
427
-		'boundary' => '',
428
-		'refuser_gz' => false,
429
-		'if_modified_since' => '',
430
-		'uri_referer' => '',
431
-		'file' => '',
432
-		'follow_location' => 10,
433
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
434
-	];
435
-	$options = array_merge($default, $options);
436
-	// copier directement dans un fichier ?
437
-	$copy = $options['file'];
438
-
439
-	if ($options['methode'] == 'HEAD') {
440
-		$options['taille_max'] = 0;
441
-	}
442
-	if (is_null($options['taille_max'])) {
443
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
444
-	}
445
-
446
-
447
-	// Ajout des en-têtes spécifiques si besoin
448
-	$head_add = '';
449
-	if (!empty($options['headers'])) {
450
-		foreach ($options['headers'] as $champ => $valeur) {
451
-			$head_add .= $champ . ': ' . $valeur . "\r\n";
452
-		}
453
-		// ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas
454
-		unset($options['headers']);
455
-	}
456
-
457
-	if (!empty($options['datas'])) {
458
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
459
-		$head .= $head_add;
460
-		if (stripos($head, 'Content-Length:') === false) {
461
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
462
-		}
463
-		$options['datas'] = $head . "\r\n" . $postdata;
464
-		if (
465
-			strlen($postdata)
466
-			and !$methode_demandee
467
-		) {
468
-			$options['methode'] = 'POST';
469
-		}
470
-	} elseif ($head_add) {
471
-		$options['datas'] = $head_add . "\r\n";
472
-	}
473
-
474
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
475
-	$url = preg_replace(',^feed://,i', 'http://', $url);
476
-	if (!tester_url_absolue($url)) {
477
-		$url = 'http://' . $url;
478
-	} elseif (strncmp($url, '//', 2) == 0) {
479
-		$url = 'http:' . $url;
480
-	}
481
-
482
-	$url = url_to_ascii($url);
483
-
484
-	$result = [
485
-		'status' => 0,
486
-		'headers' => '',
487
-		'page' => '',
488
-		'length' => 0,
489
-		'last_modified' => '',
490
-		'location' => '',
491
-		'url' => $url
492
-	];
493
-
494
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
495
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
496
-
497
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
498
-	list($handle, $fopen) = init_http(
499
-		$options['methode'],
500
-		$url,
501
-		$refuser_gz,
502
-		$options['uri_referer'],
503
-		$options['datas'],
504
-		$options['version_http'],
505
-		$options['if_modified_since']
506
-	);
507
-	if (!$handle) {
508
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
509
-
510
-		return false;
511
-	}
512
-
513
-	// Sauf en fopen, envoyer le flux d'entree
514
-	// et recuperer les en-tetes de reponses
515
-	if (!$fopen) {
516
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
517
-		if (!$res) {
518
-			fclose($handle);
519
-			$t = @parse_url($url);
520
-			$host = $t['host'];
521
-			// Chinoisierie inexplicable pour contrer
522
-			// les actions liberticides de l'empire du milieu
523
-			if (
524
-				!need_proxy($host)
525
-				and $res = @file_get_contents($url)
526
-			) {
527
-				$result['length'] = strlen($res);
528
-				if ($copy) {
529
-					ecrire_fichier($copy, $res);
530
-					$result['file'] = $copy;
531
-				} else {
532
-					$result['page'] = $res;
533
-				}
534
-				$res = [
535
-					'status' => 200,
536
-				];
537
-			} else {
538
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
539
-				return false;
540
-			}
541
-		} elseif ($res['location'] and $options['follow_location']) {
542
-			$options['follow_location']--;
543
-			fclose($handle);
544
-			include_spip('inc/filtres');
545
-			$url = suivre_lien($url, $res['location']);
546
-			spip_log("recuperer_url recommence sur $url", 'distant');
547
-
548
-			return recuperer_url($url, $options);
549
-		} elseif ($res['status'] !== 200) {
550
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
551
-		}
552
-		$result['status'] = $res['status'];
553
-		if (isset($res['headers'])) {
554
-			$result['headers'] = $res['headers'];
555
-		}
556
-		if (isset($res['last_modified'])) {
557
-			$result['last_modified'] = $res['last_modified'];
558
-		}
559
-		if (isset($res['location'])) {
560
-			$result['location'] = $res['location'];
561
-		}
562
-	}
563
-
564
-	// on ne veut que les entetes
565
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
566
-		return $result;
567
-	}
568
-
569
-
570
-	// s'il faut deballer, le faire via un fichier temporaire
571
-	// sinon la memoire explose pour les gros flux
572
-
573
-	$gz = false;
574
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
575
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
576
-	}
577
-
578
-	// si on a pas deja recuperer le contenu par une methode detournee
579
-	if (!$result['length']) {
580
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
581
-		fclose($handle);
582
-		if ($copy) {
583
-			$result['length'] = $res;
584
-			$result['file'] = $copy;
585
-		} elseif ($res) {
586
-			$result['page'] = &$res;
587
-			$result['length'] = strlen($result['page']);
588
-		}
589
-		if (!$result['status']) {
590
-			$result['status'] = 200; // on a reussi, donc !
591
-		}
592
-	}
593
-	if (!$result['page']) {
594
-		return $result;
595
-	}
596
-
597
-	// Decompresser au besoin
598
-	if ($gz) {
599
-		$result['page'] = implode('', gzfile($gz));
600
-		supprimer_fichier($gz);
601
-	}
602
-
603
-	// Faut-il l'importer dans notre charset local ?
604
-	if ($options['transcoder']) {
605
-		include_spip('inc/charsets');
606
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
607
-	}
608
-
609
-	return $result;
419
+    // Conserve la mémoire de la méthode fournit éventuellement
420
+    $methode_demandee = $options['methode'] ?? '';
421
+    $default = [
422
+        'transcoder' => false,
423
+        'methode' => 'GET',
424
+        'taille_max' => null,
425
+        'headers' => [],
426
+        'datas' => '',
427
+        'boundary' => '',
428
+        'refuser_gz' => false,
429
+        'if_modified_since' => '',
430
+        'uri_referer' => '',
431
+        'file' => '',
432
+        'follow_location' => 10,
433
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
434
+    ];
435
+    $options = array_merge($default, $options);
436
+    // copier directement dans un fichier ?
437
+    $copy = $options['file'];
438
+
439
+    if ($options['methode'] == 'HEAD') {
440
+        $options['taille_max'] = 0;
441
+    }
442
+    if (is_null($options['taille_max'])) {
443
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
444
+    }
445
+
446
+
447
+    // Ajout des en-têtes spécifiques si besoin
448
+    $head_add = '';
449
+    if (!empty($options['headers'])) {
450
+        foreach ($options['headers'] as $champ => $valeur) {
451
+            $head_add .= $champ . ': ' . $valeur . "\r\n";
452
+        }
453
+        // ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas
454
+        unset($options['headers']);
455
+    }
456
+
457
+    if (!empty($options['datas'])) {
458
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
459
+        $head .= $head_add;
460
+        if (stripos($head, 'Content-Length:') === false) {
461
+            $head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
462
+        }
463
+        $options['datas'] = $head . "\r\n" . $postdata;
464
+        if (
465
+            strlen($postdata)
466
+            and !$methode_demandee
467
+        ) {
468
+            $options['methode'] = 'POST';
469
+        }
470
+    } elseif ($head_add) {
471
+        $options['datas'] = $head_add . "\r\n";
472
+    }
473
+
474
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
475
+    $url = preg_replace(',^feed://,i', 'http://', $url);
476
+    if (!tester_url_absolue($url)) {
477
+        $url = 'http://' . $url;
478
+    } elseif (strncmp($url, '//', 2) == 0) {
479
+        $url = 'http:' . $url;
480
+    }
481
+
482
+    $url = url_to_ascii($url);
483
+
484
+    $result = [
485
+        'status' => 0,
486
+        'headers' => '',
487
+        'page' => '',
488
+        'length' => 0,
489
+        'last_modified' => '',
490
+        'location' => '',
491
+        'url' => $url
492
+    ];
493
+
494
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
495
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
496
+
497
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
498
+    list($handle, $fopen) = init_http(
499
+        $options['methode'],
500
+        $url,
501
+        $refuser_gz,
502
+        $options['uri_referer'],
503
+        $options['datas'],
504
+        $options['version_http'],
505
+        $options['if_modified_since']
506
+    );
507
+    if (!$handle) {
508
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
509
+
510
+        return false;
511
+    }
512
+
513
+    // Sauf en fopen, envoyer le flux d'entree
514
+    // et recuperer les en-tetes de reponses
515
+    if (!$fopen) {
516
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
517
+        if (!$res) {
518
+            fclose($handle);
519
+            $t = @parse_url($url);
520
+            $host = $t['host'];
521
+            // Chinoisierie inexplicable pour contrer
522
+            // les actions liberticides de l'empire du milieu
523
+            if (
524
+                !need_proxy($host)
525
+                and $res = @file_get_contents($url)
526
+            ) {
527
+                $result['length'] = strlen($res);
528
+                if ($copy) {
529
+                    ecrire_fichier($copy, $res);
530
+                    $result['file'] = $copy;
531
+                } else {
532
+                    $result['page'] = $res;
533
+                }
534
+                $res = [
535
+                    'status' => 200,
536
+                ];
537
+            } else {
538
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
539
+                return false;
540
+            }
541
+        } elseif ($res['location'] and $options['follow_location']) {
542
+            $options['follow_location']--;
543
+            fclose($handle);
544
+            include_spip('inc/filtres');
545
+            $url = suivre_lien($url, $res['location']);
546
+            spip_log("recuperer_url recommence sur $url", 'distant');
547
+
548
+            return recuperer_url($url, $options);
549
+        } elseif ($res['status'] !== 200) {
550
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
551
+        }
552
+        $result['status'] = $res['status'];
553
+        if (isset($res['headers'])) {
554
+            $result['headers'] = $res['headers'];
555
+        }
556
+        if (isset($res['last_modified'])) {
557
+            $result['last_modified'] = $res['last_modified'];
558
+        }
559
+        if (isset($res['location'])) {
560
+            $result['location'] = $res['location'];
561
+        }
562
+    }
563
+
564
+    // on ne veut que les entetes
565
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
566
+        return $result;
567
+    }
568
+
569
+
570
+    // s'il faut deballer, le faire via un fichier temporaire
571
+    // sinon la memoire explose pour les gros flux
572
+
573
+    $gz = false;
574
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
575
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
576
+    }
577
+
578
+    // si on a pas deja recuperer le contenu par une methode detournee
579
+    if (!$result['length']) {
580
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
581
+        fclose($handle);
582
+        if ($copy) {
583
+            $result['length'] = $res;
584
+            $result['file'] = $copy;
585
+        } elseif ($res) {
586
+            $result['page'] = &$res;
587
+            $result['length'] = strlen($result['page']);
588
+        }
589
+        if (!$result['status']) {
590
+            $result['status'] = 200; // on a reussi, donc !
591
+        }
592
+    }
593
+    if (!$result['page']) {
594
+        return $result;
595
+    }
596
+
597
+    // Decompresser au besoin
598
+    if ($gz) {
599
+        $result['page'] = implode('', gzfile($gz));
600
+        supprimer_fichier($gz);
601
+    }
602
+
603
+    // Faut-il l'importer dans notre charset local ?
604
+    if ($options['transcoder']) {
605
+        include_spip('inc/charsets');
606
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
607
+    }
608
+
609
+    return $result;
610 610
 }
611 611
 
612 612
 /**
@@ -622,73 +622,73 @@  discard block
 block discarded – undo
622 622
  * @return array|bool|mixed
623 623
  */
624 624
 function recuperer_url_cache($url, $options = []) {
625
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
626
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
627
-	}
628
-	$default = [
629
-		'transcoder' => false,
630
-		'methode' => 'GET',
631
-		'taille_max' => null,
632
-		'datas' => '',
633
-		'boundary' => '',
634
-		'refuser_gz' => false,
635
-		'if_modified_since' => '',
636
-		'uri_referer' => '',
637
-		'file' => '',
638
-		'follow_location' => 10,
639
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
640
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
641
-	];
642
-	$options = array_merge($default, $options);
643
-
644
-	// cas ou il n'est pas possible de cacher
645
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
646
-		return recuperer_url($url, $options);
647
-	}
648
-
649
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
650
-	static $errors = [];
651
-	if (isset($errors[$url])) {
652
-		return $errors[$url];
653
-	}
654
-
655
-	$sig = $options;
656
-	unset($sig['if_modified_since']);
657
-	unset($sig['delai_cache']);
658
-	$sig['url'] = $url;
659
-
660
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
661
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
662
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
663
-	$cache = "$sub$cache";
664
-
665
-	$res = false;
666
-	$is_cached = file_exists($cache);
667
-	if (
668
-		$is_cached
669
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
670
-	) {
671
-		lire_fichier($cache, $res);
672
-		if ($res = unserialize($res)) {
673
-			// mettre le last_modified et le status=304 ?
674
-		}
675
-	}
676
-	if (!$res) {
677
-		$res = recuperer_url($url, $options);
678
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
679
-		if (!$res) {
680
-			if ($is_cached) {
681
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
682
-				lire_fichier($cache, $res);
683
-				$res = unserialize($res);
684
-			}
685
-
686
-			return $errors[$url] = $res;
687
-		}
688
-		ecrire_fichier($cache, serialize($res));
689
-	}
690
-
691
-	return $res;
625
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
626
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
627
+    }
628
+    $default = [
629
+        'transcoder' => false,
630
+        'methode' => 'GET',
631
+        'taille_max' => null,
632
+        'datas' => '',
633
+        'boundary' => '',
634
+        'refuser_gz' => false,
635
+        'if_modified_since' => '',
636
+        'uri_referer' => '',
637
+        'file' => '',
638
+        'follow_location' => 10,
639
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
640
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
641
+    ];
642
+    $options = array_merge($default, $options);
643
+
644
+    // cas ou il n'est pas possible de cacher
645
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
646
+        return recuperer_url($url, $options);
647
+    }
648
+
649
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
650
+    static $errors = [];
651
+    if (isset($errors[$url])) {
652
+        return $errors[$url];
653
+    }
654
+
655
+    $sig = $options;
656
+    unset($sig['if_modified_since']);
657
+    unset($sig['delai_cache']);
658
+    $sig['url'] = $url;
659
+
660
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
661
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
662
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
663
+    $cache = "$sub$cache";
664
+
665
+    $res = false;
666
+    $is_cached = file_exists($cache);
667
+    if (
668
+        $is_cached
669
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
670
+    ) {
671
+        lire_fichier($cache, $res);
672
+        if ($res = unserialize($res)) {
673
+            // mettre le last_modified et le status=304 ?
674
+        }
675
+    }
676
+    if (!$res) {
677
+        $res = recuperer_url($url, $options);
678
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
679
+        if (!$res) {
680
+            if ($is_cached) {
681
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
682
+                lire_fichier($cache, $res);
683
+                $res = unserialize($res);
684
+            }
685
+
686
+            return $errors[$url] = $res;
687
+        }
688
+        ecrire_fichier($cache, serialize($res));
689
+    }
690
+
691
+    return $res;
692 692
 }
693 693
 
694 694
 /**
@@ -706,41 +706,41 @@  discard block
 block discarded – undo
706 706
  *   string contenu de la resource
707 707
  */
708 708
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
709
-	$taille = 0;
710
-	$result = '';
711
-	$fp = false;
712
-	if ($fichier) {
713
-		include_spip('inc/acces');
714
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
715
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
716
-		if (!$fp and file_exists($fichier)) {
717
-			return filesize($fichier);
718
-		}
719
-		if (!$fp) {
720
-			return false;
721
-		}
722
-		$result = 0; // on renvoie la taille du fichier
723
-	}
724
-	while (!feof($handle) and $taille < $taille_max) {
725
-		$res = fread($handle, 16384);
726
-		$taille += strlen($res);
727
-		if ($fp) {
728
-			fwrite($fp, $res);
729
-			$result = $taille;
730
-		} else {
731
-			$result .= $res;
732
-		}
733
-	}
734
-	if ($fp) {
735
-		spip_fclose_unlock($fp);
736
-		spip_unlink($fichier);
737
-		@rename($tmpfile, $fichier);
738
-		if (!file_exists($fichier)) {
739
-			return false;
740
-		}
741
-	}
742
-
743
-	return $result;
709
+    $taille = 0;
710
+    $result = '';
711
+    $fp = false;
712
+    if ($fichier) {
713
+        include_spip('inc/acces');
714
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
715
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
716
+        if (!$fp and file_exists($fichier)) {
717
+            return filesize($fichier);
718
+        }
719
+        if (!$fp) {
720
+            return false;
721
+        }
722
+        $result = 0; // on renvoie la taille du fichier
723
+    }
724
+    while (!feof($handle) and $taille < $taille_max) {
725
+        $res = fread($handle, 16384);
726
+        $taille += strlen($res);
727
+        if ($fp) {
728
+            fwrite($fp, $res);
729
+            $result = $taille;
730
+        } else {
731
+            $result .= $res;
732
+        }
733
+    }
734
+    if ($fp) {
735
+        spip_fclose_unlock($fp);
736
+        spip_unlink($fichier);
737
+        @rename($tmpfile, $fichier);
738
+        if (!file_exists($fichier)) {
739
+            return false;
740
+        }
741
+    }
742
+
743
+    return $result;
744 744
 }
745 745
 
746 746
 /**
@@ -762,35 +762,35 @@  discard block
 block discarded – undo
762 762
  *   string location
763 763
  */
764 764
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
765
-	$result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
766
-
767
-	$s = @trim(fgets($handle, 16384));
768
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
769
-		return false;
770
-	}
771
-	$result['status'] = intval($r[1]);
772
-	while ($s = trim(fgets($handle, 16384))) {
773
-		$result['headers'][] = $s . "\n";
774
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
775
-		list(, $d, $v) = $r;
776
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
777
-			$result['location'] = $v;
778
-		} elseif ($d == 'Last-Modified') {
779
-			$result['last_modified'] = strtotime($v);
780
-		}
781
-	}
782
-	if (
783
-		$if_modified_since
784
-		and $result['last_modified']
785
-		and $if_modified_since > $result['last_modified']
786
-		and $result['status'] == 200
787
-	) {
788
-		$result['status'] = 304;
789
-	}
790
-
791
-	$result['headers'] = implode('', $result['headers']);
792
-
793
-	return $result;
765
+    $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => ''];
766
+
767
+    $s = @trim(fgets($handle, 16384));
768
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
769
+        return false;
770
+    }
771
+    $result['status'] = intval($r[1]);
772
+    while ($s = trim(fgets($handle, 16384))) {
773
+        $result['headers'][] = $s . "\n";
774
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
775
+        list(, $d, $v) = $r;
776
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
777
+            $result['location'] = $v;
778
+        } elseif ($d == 'Last-Modified') {
779
+            $result['last_modified'] = strtotime($v);
780
+        }
781
+    }
782
+    if (
783
+        $if_modified_since
784
+        and $result['last_modified']
785
+        and $if_modified_since > $result['last_modified']
786
+        and $result['status'] == 200
787
+    ) {
788
+        $result['status'] = 304;
789
+    }
790
+
791
+    $result['headers'] = implode('', $result['headers']);
792
+
793
+    return $result;
794 794
 }
795 795
 
796 796
 /**
@@ -812,22 +812,22 @@  discard block
 block discarded – undo
812 812
  *     Nom du fichier pour copie locale
813 813
  **/
814 814
 function nom_fichier_copie_locale($source, $extension) {
815
-	include_spip('inc/documents');
815
+    include_spip('inc/documents');
816 816
 
817
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
818
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
817
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
818
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
819 819
 
820
-	// on se place tout le temps comme si on etait a la racine
821
-	if (_DIR_RACINE) {
822
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
823
-	}
820
+    // on se place tout le temps comme si on etait a la racine
821
+    if (_DIR_RACINE) {
822
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
823
+    }
824 824
 
825
-	$m = md5($source);
825
+    $m = md5($source);
826 826
 
827
-	return $d
828
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
829
-	. substr($m, 0, 4)
830
-	. ".$extension";
827
+    return $d
828
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
829
+    . substr($m, 0, 4)
830
+    . ".$extension";
831 831
 }
832 832
 
833 833
 /**
@@ -845,70 +845,70 @@  discard block
 block discarded – undo
845 845
  *      Nom du fichier calculé
846 846
  **/
847 847
 function fichier_copie_locale($source) {
848
-	// Si c'est deja local pas de souci
849
-	if (!tester_url_absolue($source)) {
850
-		if (_DIR_RACINE) {
851
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
852
-		}
853
-
854
-		return $source;
855
-	}
856
-
857
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
858
-	// a deja ete copie en local avec cette extension
859
-	// dans ce cas elle est fiable, pas la peine de requeter en base
860
-	$path_parts = pathinfo($source);
861
-	if (!isset($path_parts['extension'])) {
862
-		$path_parts['extension'] = '';
863
-	}
864
-	$ext = $path_parts ? $path_parts['extension'] : '';
865
-	if (
866
-		$ext
867
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
868
-		and $f = nom_fichier_copie_locale($source, $ext)
869
-		and file_exists(_DIR_RACINE . $f)
870
-	) {
871
-		return $f;
872
-	}
873
-
874
-
875
-	// Si c'est deja dans la table des documents,
876
-	// ramener le nom de sa copie potentielle
877
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
878
-
879
-	if ($ext) {
880
-		return nom_fichier_copie_locale($source, $ext);
881
-	}
882
-
883
-	// voir si l'extension indiquee dans le nom du fichier est ok
884
-	// et si il n'aurait pas deja ete rapatrie
885
-
886
-	$ext = $path_parts ? $path_parts['extension'] : '';
887
-
888
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
889
-		$f = nom_fichier_copie_locale($source, $ext);
890
-		if (file_exists(_DIR_RACINE . $f)) {
891
-			return $f;
892
-		}
893
-	}
894
-
895
-	// Ping  pour voir si son extension est connue et autorisee
896
-	// avec mise en cache du resultat du ping
897
-
898
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
899
-	if (
900
-		!@file_exists($cache)
901
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
902
-		or _request('var_mode') == 'recalcul'
903
-	) {
904
-		$path_parts = recuperer_infos_distantes($source, 0, false);
905
-		ecrire_fichier($cache, serialize($path_parts));
906
-	}
907
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
908
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
909
-		return nom_fichier_copie_locale($source, $ext);
910
-	}
911
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
848
+    // Si c'est deja local pas de souci
849
+    if (!tester_url_absolue($source)) {
850
+        if (_DIR_RACINE) {
851
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
852
+        }
853
+
854
+        return $source;
855
+    }
856
+
857
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
858
+    // a deja ete copie en local avec cette extension
859
+    // dans ce cas elle est fiable, pas la peine de requeter en base
860
+    $path_parts = pathinfo($source);
861
+    if (!isset($path_parts['extension'])) {
862
+        $path_parts['extension'] = '';
863
+    }
864
+    $ext = $path_parts ? $path_parts['extension'] : '';
865
+    if (
866
+        $ext
867
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
868
+        and $f = nom_fichier_copie_locale($source, $ext)
869
+        and file_exists(_DIR_RACINE . $f)
870
+    ) {
871
+        return $f;
872
+    }
873
+
874
+
875
+    // Si c'est deja dans la table des documents,
876
+    // ramener le nom de sa copie potentielle
877
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
878
+
879
+    if ($ext) {
880
+        return nom_fichier_copie_locale($source, $ext);
881
+    }
882
+
883
+    // voir si l'extension indiquee dans le nom du fichier est ok
884
+    // et si il n'aurait pas deja ete rapatrie
885
+
886
+    $ext = $path_parts ? $path_parts['extension'] : '';
887
+
888
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
889
+        $f = nom_fichier_copie_locale($source, $ext);
890
+        if (file_exists(_DIR_RACINE . $f)) {
891
+            return $f;
892
+        }
893
+    }
894
+
895
+    // Ping  pour voir si son extension est connue et autorisee
896
+    // avec mise en cache du resultat du ping
897
+
898
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
899
+    if (
900
+        !@file_exists($cache)
901
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
902
+        or _request('var_mode') == 'recalcul'
903
+    ) {
904
+        $path_parts = recuperer_infos_distantes($source, 0, false);
905
+        ecrire_fichier($cache, serialize($path_parts));
906
+    }
907
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
908
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
909
+        return nom_fichier_copie_locale($source, $ext);
910
+    }
911
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
912 912
 }
913 913
 
914 914
 
@@ -936,97 +936,97 @@  discard block
 block discarded – undo
936 936
  **/
937 937
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
938 938
 
939
-	// pas la peine de perdre son temps
940
-	if (!tester_url_absolue($source)) {
941
-		return false;
942
-	}
943
-
944
-	# charger les alias des types mime
945
-	include_spip('base/typedoc');
946
-
947
-	$a = [];
948
-	$mime_type = '';
949
-	// On va directement charger le debut des images et des fichiers html,
950
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
951
-	// ca echoue l'utilisateur devra les entrer...
952
-	$reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
953
-	$headers = $reponse['headers'] ?? '';
954
-	$a['body'] = $reponse['page'] ?? '';
955
-	if ($headers) {
956
-		if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
957
-			return false;
958
-		}
959
-
960
-		$a['extension'] = $extension;
961
-
962
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
963
-			$a['taille'] = intval($regs[1]);
964
-		}
965
-	}
966
-
967
-	// Echec avec HEAD, on tente avec GET
968
-	if (!$a and !$max) {
969
-		spip_log("tenter GET $source", 'distant');
970
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
971
-	}
972
-
973
-	// si on a rien trouve pas la peine d'insister
974
-	if (!$a) {
975
-		return false;
976
-	}
977
-
978
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
979
-	// recharger le document en GET et recuperer des donnees supplementaires...
980
-	include_spip('inc/filtres_images_lib_mini');
981
-	if (
982
-		strpos($mime_type, 'image/') === 0
983
-		and $extension = _image_trouver_extension_depuis_mime($mime_type)
984
-	) {
985
-		if (
986
-			$max == 0
987
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
988
-			and in_array($extension, formats_image_acceptables())
989
-			and $charger_si_petite_image
990
-		) {
991
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
992
-		} else {
993
-			if ($a['body']) {
994
-				$a['extension'] = $extension;
995
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
996
-				ecrire_fichier($a['fichier'], $a['body']);
997
-				$size_image = @spip_getimagesize($a['fichier']);
998
-				$a['largeur'] = intval($size_image[0]);
999
-				$a['hauteur'] = intval($size_image[1]);
1000
-				$a['type_image'] = true;
1001
-			}
1002
-		}
1003
-	}
1004
-
1005
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1006
-	// ce sera mieux que 0x0
1007
-	// Flash is dead!
1008
-	if (
1009
-		$a and isset($a['extension']) and $a['extension'] == 'swf'
1010
-		and empty($a['largeur'])
1011
-	) {
1012
-		$a['largeur'] = 425;
1013
-		$a['hauteur'] = 350;
1014
-	}
1015
-
1016
-	if ($mime_type == 'text/html') {
1017
-		include_spip('inc/filtres');
1018
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1019
-		$page = $page['page'] ?? '';
1020
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1021
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1022
-		}
1023
-		if (!isset($a['taille']) or !$a['taille']) {
1024
-			$a['taille'] = strlen($page); # a peu pres
1025
-		}
1026
-	}
1027
-	$a['mime_type'] = $mime_type;
1028
-
1029
-	return $a;
939
+    // pas la peine de perdre son temps
940
+    if (!tester_url_absolue($source)) {
941
+        return false;
942
+    }
943
+
944
+    # charger les alias des types mime
945
+    include_spip('base/typedoc');
946
+
947
+    $a = [];
948
+    $mime_type = '';
949
+    // On va directement charger le debut des images et des fichiers html,
950
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
951
+    // ca echoue l'utilisateur devra les entrer...
952
+    $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
953
+    $headers = $reponse['headers'] ?? '';
954
+    $a['body'] = $reponse['page'] ?? '';
955
+    if ($headers) {
956
+        if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) {
957
+            return false;
958
+        }
959
+
960
+        $a['extension'] = $extension;
961
+
962
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
963
+            $a['taille'] = intval($regs[1]);
964
+        }
965
+    }
966
+
967
+    // Echec avec HEAD, on tente avec GET
968
+    if (!$a and !$max) {
969
+        spip_log("tenter GET $source", 'distant');
970
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
971
+    }
972
+
973
+    // si on a rien trouve pas la peine d'insister
974
+    if (!$a) {
975
+        return false;
976
+    }
977
+
978
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
979
+    // recharger le document en GET et recuperer des donnees supplementaires...
980
+    include_spip('inc/filtres_images_lib_mini');
981
+    if (
982
+        strpos($mime_type, 'image/') === 0
983
+        and $extension = _image_trouver_extension_depuis_mime($mime_type)
984
+    ) {
985
+        if (
986
+            $max == 0
987
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
988
+            and in_array($extension, formats_image_acceptables())
989
+            and $charger_si_petite_image
990
+        ) {
991
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
992
+        } else {
993
+            if ($a['body']) {
994
+                $a['extension'] = $extension;
995
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
996
+                ecrire_fichier($a['fichier'], $a['body']);
997
+                $size_image = @spip_getimagesize($a['fichier']);
998
+                $a['largeur'] = intval($size_image[0]);
999
+                $a['hauteur'] = intval($size_image[1]);
1000
+                $a['type_image'] = true;
1001
+            }
1002
+        }
1003
+    }
1004
+
1005
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1006
+    // ce sera mieux que 0x0
1007
+    // Flash is dead!
1008
+    if (
1009
+        $a and isset($a['extension']) and $a['extension'] == 'swf'
1010
+        and empty($a['largeur'])
1011
+    ) {
1012
+        $a['largeur'] = 425;
1013
+        $a['hauteur'] = 350;
1014
+    }
1015
+
1016
+    if ($mime_type == 'text/html') {
1017
+        include_spip('inc/filtres');
1018
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1019
+        $page = $page['page'] ?? '';
1020
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1021
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1022
+        }
1023
+        if (!isset($a['taille']) or !$a['taille']) {
1024
+            $a['taille'] = strlen($page); # a peu pres
1025
+        }
1026
+    }
1027
+    $a['mime_type'] = $mime_type;
1028
+
1029
+    return $a;
1030 1030
 }
1031 1031
 
1032 1032
 /**
@@ -1035,67 +1035,67 @@  discard block
 block discarded – undo
1035 1035
  * @return false|mixed
1036 1036
  */
1037 1037
 function distant_trouver_extension_selon_headers($source, $headers) {
1038
-	if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1039
-		$mime_type = (trim($regs[1]));
1040
-	} else {
1041
-		$mime_type = '';
1042
-	} // inconnu
1043
-
1044
-	// Appliquer les alias
1045
-	while (isset($GLOBALS['mime_alias'][$mime_type])) {
1046
-		$mime_type = $GLOBALS['mime_alias'][$mime_type];
1047
-	}
1048
-
1049
-	// Si on a un mime-type insignifiant
1050
-	// text/plain,application/octet-stream ou vide
1051
-	// c'est peut-etre que le serveur ne sait pas
1052
-	// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1053
-	// ou le Content-Disposition: attachment; filename=...
1054
-	$t = null;
1055
-	if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1056
-		if (
1057
-			!$t
1058
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1059
-		) {
1060
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1061
-		}
1062
-		if (
1063
-			!$t
1064
-			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1065
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1066
-		) {
1067
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1068
-		}
1069
-	}
1070
-
1071
-	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1072
-	if (!$t) {
1073
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1074
-	}
1075
-
1076
-	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1077
-	// On essaie de nouveau avec l'extension
1078
-	if (
1079
-		!$t
1080
-		and $mime_type != 'text/plain'
1081
-		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1082
-	) {
1083
-		# eviter xxx.3 => 3gp (> SPIP 3)
1084
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1085
-	}
1086
-
1087
-	if ($t) {
1088
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1089
-		return $t['extension'];
1090
-	} else {
1091
-		# par defaut on retombe sur '.bin' si c'est autorise
1092
-		spip_log("mime-type $mime_type inconnu", 'distant');
1093
-		$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1094
-		if (!$t) {
1095
-			return false;
1096
-		}
1097
-		return $t['extension'];
1098
-	}
1038
+    if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1039
+        $mime_type = (trim($regs[1]));
1040
+    } else {
1041
+        $mime_type = '';
1042
+    } // inconnu
1043
+
1044
+    // Appliquer les alias
1045
+    while (isset($GLOBALS['mime_alias'][$mime_type])) {
1046
+        $mime_type = $GLOBALS['mime_alias'][$mime_type];
1047
+    }
1048
+
1049
+    // Si on a un mime-type insignifiant
1050
+    // text/plain,application/octet-stream ou vide
1051
+    // c'est peut-etre que le serveur ne sait pas
1052
+    // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1053
+    // ou le Content-Disposition: attachment; filename=...
1054
+    $t = null;
1055
+    if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) {
1056
+        if (
1057
+            !$t
1058
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1059
+        ) {
1060
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1061
+        }
1062
+        if (
1063
+            !$t
1064
+            and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1065
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1066
+        ) {
1067
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1068
+        }
1069
+    }
1070
+
1071
+    // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1072
+    if (!$t) {
1073
+        $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1074
+    }
1075
+
1076
+    // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1077
+    // On essaie de nouveau avec l'extension
1078
+    if (
1079
+        !$t
1080
+        and $mime_type != 'text/plain'
1081
+        and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1082
+    ) {
1083
+        # eviter xxx.3 => 3gp (> SPIP 3)
1084
+        $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1085
+    }
1086
+
1087
+    if ($t) {
1088
+        spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1089
+        return $t['extension'];
1090
+    } else {
1091
+        # par defaut on retombe sur '.bin' si c'est autorise
1092
+        spip_log("mime-type $mime_type inconnu", 'distant');
1093
+        $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1094
+        if (!$t) {
1095
+            return false;
1096
+        }
1097
+        return $t['extension'];
1098
+    }
1099 1099
 }
1100 1100
 
1101 1101
 /**
@@ -1110,46 +1110,46 @@  discard block
 block discarded – undo
1110 1110
  * @return string
1111 1111
  */
1112 1112
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1113
-	if (is_null($http_proxy)) {
1114
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1115
-	}
1116
-	// rien a faire si pas de proxy :)
1117
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1118
-		return '';
1119
-	}
1120
-
1121
-	if (is_null($http_noproxy)) {
1122
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1123
-	}
1124
-	// si pas d'exception, on retourne le proxy
1125
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1126
-		return $http_proxy;
1127
-	}
1128
-
1129
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1130
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1131
-	$http_noproxy = str_replace("\n", ' ', $http_noproxy);
1132
-	$http_noproxy = str_replace("\r", ' ', $http_noproxy);
1133
-	$http_noproxy = " $http_noproxy ";
1134
-	$domain = $host;
1135
-	// si le domaine exact www.example.org est dans les exceptions
1136
-	if (strpos($http_noproxy, " $domain ") !== false) {
1137
-		return '';
1138
-	}
1139
-
1140
-	while (strpos($domain, '.') !== false) {
1141
-		$domain = explode('.', $domain);
1142
-		array_shift($domain);
1143
-		$domain = implode('.', $domain);
1144
-
1145
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1146
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1147
-			return '';
1148
-		}
1149
-	}
1150
-
1151
-	// ok c'est pas une exception
1152
-	return $http_proxy;
1113
+    if (is_null($http_proxy)) {
1114
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1115
+    }
1116
+    // rien a faire si pas de proxy :)
1117
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1118
+        return '';
1119
+    }
1120
+
1121
+    if (is_null($http_noproxy)) {
1122
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1123
+    }
1124
+    // si pas d'exception, on retourne le proxy
1125
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1126
+        return $http_proxy;
1127
+    }
1128
+
1129
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1130
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1131
+    $http_noproxy = str_replace("\n", ' ', $http_noproxy);
1132
+    $http_noproxy = str_replace("\r", ' ', $http_noproxy);
1133
+    $http_noproxy = " $http_noproxy ";
1134
+    $domain = $host;
1135
+    // si le domaine exact www.example.org est dans les exceptions
1136
+    if (strpos($http_noproxy, " $domain ") !== false) {
1137
+        return '';
1138
+    }
1139
+
1140
+    while (strpos($domain, '.') !== false) {
1141
+        $domain = explode('.', $domain);
1142
+        array_shift($domain);
1143
+        $domain = implode('.', $domain);
1144
+
1145
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1146
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1147
+            return '';
1148
+        }
1149
+    }
1150
+
1151
+    // ok c'est pas une exception
1152
+    return $http_proxy;
1153 1153
 }
1154 1154
 
1155 1155
 
@@ -1172,59 +1172,59 @@  discard block
 block discarded – undo
1172 1172
  * @return array
1173 1173
  */
1174 1174
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1175
-	$user = $via_proxy = $proxy_user = '';
1176
-	$fopen = false;
1177
-
1178
-	$t = @parse_url($url);
1179
-	$host = $t['host'];
1180
-	if ($t['scheme'] == 'http') {
1181
-		$scheme = 'http';
1182
-		$noproxy = '';
1183
-	} elseif ($t['scheme'] == 'https') {
1184
-		$scheme = 'ssl';
1185
-		$noproxy = 'ssl://';
1186
-		if (!isset($t['port']) || !($port = $t['port'])) {
1187
-			$t['port'] = 443;
1188
-		}
1189
-	} else {
1190
-		$scheme = $t['scheme'];
1191
-		$noproxy = $scheme . '://';
1192
-	}
1193
-	if (isset($t['user'])) {
1194
-		$user = [$t['user'], $t['pass']];
1195
-	}
1196
-
1197
-	if (!isset($t['port']) || !($port = $t['port'])) {
1198
-		$port = 80;
1199
-	}
1200
-	if (!isset($t['path']) || !($path = $t['path'])) {
1201
-		$path = '/';
1202
-	}
1203
-
1204
-	if (!empty($t['query'])) {
1205
-		$path .= '?' . $t['query'];
1206
-	}
1207
-
1208
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1209
-	if (!$f or !is_resource($f)) {
1210
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1211
-		// ce qui correspond a $f===110
1212
-		if (
1213
-			$f !== 110
1214
-			and !need_proxy($host)
1215
-			and !_request('tester_proxy')
1216
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1217
-		) {
1218
-			$f = @fopen($url, 'rb');
1219
-			spip_log("connexion vers $url par simple fopen", 'distant');
1220
-			$fopen = true;
1221
-		} else {
1222
-			// echec total
1223
-			$f = false;
1224
-		}
1225
-	}
1226
-
1227
-	return [$f, $fopen];
1175
+    $user = $via_proxy = $proxy_user = '';
1176
+    $fopen = false;
1177
+
1178
+    $t = @parse_url($url);
1179
+    $host = $t['host'];
1180
+    if ($t['scheme'] == 'http') {
1181
+        $scheme = 'http';
1182
+        $noproxy = '';
1183
+    } elseif ($t['scheme'] == 'https') {
1184
+        $scheme = 'ssl';
1185
+        $noproxy = 'ssl://';
1186
+        if (!isset($t['port']) || !($port = $t['port'])) {
1187
+            $t['port'] = 443;
1188
+        }
1189
+    } else {
1190
+        $scheme = $t['scheme'];
1191
+        $noproxy = $scheme . '://';
1192
+    }
1193
+    if (isset($t['user'])) {
1194
+        $user = [$t['user'], $t['pass']];
1195
+    }
1196
+
1197
+    if (!isset($t['port']) || !($port = $t['port'])) {
1198
+        $port = 80;
1199
+    }
1200
+    if (!isset($t['path']) || !($path = $t['path'])) {
1201
+        $path = '/';
1202
+    }
1203
+
1204
+    if (!empty($t['query'])) {
1205
+        $path .= '?' . $t['query'];
1206
+    }
1207
+
1208
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1209
+    if (!$f or !is_resource($f)) {
1210
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1211
+        // ce qui correspond a $f===110
1212
+        if (
1213
+            $f !== 110
1214
+            and !need_proxy($host)
1215
+            and !_request('tester_proxy')
1216
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1217
+        ) {
1218
+            $f = @fopen($url, 'rb');
1219
+            spip_log("connexion vers $url par simple fopen", 'distant');
1220
+            $fopen = true;
1221
+        } else {
1222
+            // echec total
1223
+            $f = false;
1224
+        }
1225
+    }
1226
+
1227
+    return [$f, $fopen];
1228 1228
 }
1229 1229
 
1230 1230
 /**
@@ -1259,125 +1259,125 @@  discard block
 block discarded – undo
1259 1259
  *   resource socket vers l'url demandee
1260 1260
  */
1261 1261
 function lance_requete(
1262
-	$method,
1263
-	$scheme,
1264
-	$user,
1265
-	$host,
1266
-	$path,
1267
-	$port,
1268
-	$noproxy,
1269
-	$refuse_gz = false,
1270
-	$referer = '',
1271
-	$datas = '',
1272
-	$vers = 'HTTP/1.0',
1273
-	$date = ''
1262
+    $method,
1263
+    $scheme,
1264
+    $user,
1265
+    $host,
1266
+    $path,
1267
+    $port,
1268
+    $noproxy,
1269
+    $refuse_gz = false,
1270
+    $referer = '',
1271
+    $datas = '',
1272
+    $vers = 'HTTP/1.0',
1273
+    $date = ''
1274 1274
 ) {
1275 1275
 
1276
-	$proxy_user = '';
1277
-	$http_proxy = need_proxy($host);
1278
-	if ($user) {
1279
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1280
-	}
1281
-
1282
-	$connect = '';
1283
-	if ($http_proxy) {
1284
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1285
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1286
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1287
-				. "Host: $path_host\r\n"
1288
-				. "Proxy-Connection: Keep-Alive\r\n";
1289
-		} else {
1290
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1291
-				. (!$user ? '' : "$user@")
1292
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1293
-		}
1294
-		$t2 = @parse_url($http_proxy);
1295
-		$first_host = $t2['host'];
1296
-		if (!($port = $t2['port'])) {
1297
-			$port = 80;
1298
-		}
1299
-		if ($t2['user']) {
1300
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1301
-		}
1302
-	} else {
1303
-		$first_host = $noproxy . $host;
1304
-	}
1305
-
1306
-	if ($connect) {
1307
-		$streamContext = stream_context_create([
1308
-			'ssl' => [
1309
-				'verify_peer' => false,
1310
-				'allow_self_signed' => true,
1311
-				'SNI_enabled' => true,
1312
-				'peer_name' => $host,
1313
-			]
1314
-		]);
1315
-		$f = @stream_socket_client(
1316
-			"tcp://$first_host:$port",
1317
-			$errno,
1318
-			$errstr,
1319
-			_INC_DISTANT_CONNECT_TIMEOUT,
1320
-			STREAM_CLIENT_CONNECT,
1321
-			$streamContext
1322
-		);
1323
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1324
-		if (!$f) {
1325
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1326
-			return $errno;
1327
-		}
1328
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1329
-
1330
-		fputs($f, $connect);
1331
-		fputs($f, "\r\n");
1332
-		$res = fread($f, 1024);
1333
-		if (
1334
-			!$res
1335
-			or !count($res = explode(' ', $res))
1336
-			or $res[1] !== '200'
1337
-		) {
1338
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1339
-			fclose($f);
1340
-
1341
-			return false;
1342
-		}
1343
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1344
-		stream_set_blocking($f, true);
1345
-		// envoyer le handshake
1346
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1347
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1348
-	} else {
1349
-		$ntry = 3;
1350
-		do {
1351
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1352
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1353
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1354
-		if (!$f) {
1355
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1356
-
1357
-			return $errno;
1358
-		}
1359
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1360
-	}
1361
-
1362
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1363
-
1364
-	$host_port = $host;
1365
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1366
-		$host_port .= ":$port";
1367
-	}
1368
-	$req = "$method $path $vers\r\n"
1369
-		. "Host: $host_port\r\n"
1370
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1371
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1372
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1373
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1374
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1375
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1376
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1276
+    $proxy_user = '';
1277
+    $http_proxy = need_proxy($host);
1278
+    if ($user) {
1279
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1280
+    }
1281
+
1282
+    $connect = '';
1283
+    if ($http_proxy) {
1284
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1285
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1286
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1287
+                . "Host: $path_host\r\n"
1288
+                . "Proxy-Connection: Keep-Alive\r\n";
1289
+        } else {
1290
+            $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1291
+                . (!$user ? '' : "$user@")
1292
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1293
+        }
1294
+        $t2 = @parse_url($http_proxy);
1295
+        $first_host = $t2['host'];
1296
+        if (!($port = $t2['port'])) {
1297
+            $port = 80;
1298
+        }
1299
+        if ($t2['user']) {
1300
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1301
+        }
1302
+    } else {
1303
+        $first_host = $noproxy . $host;
1304
+    }
1305
+
1306
+    if ($connect) {
1307
+        $streamContext = stream_context_create([
1308
+            'ssl' => [
1309
+                'verify_peer' => false,
1310
+                'allow_self_signed' => true,
1311
+                'SNI_enabled' => true,
1312
+                'peer_name' => $host,
1313
+            ]
1314
+        ]);
1315
+        $f = @stream_socket_client(
1316
+            "tcp://$first_host:$port",
1317
+            $errno,
1318
+            $errstr,
1319
+            _INC_DISTANT_CONNECT_TIMEOUT,
1320
+            STREAM_CLIENT_CONNECT,
1321
+            $streamContext
1322
+        );
1323
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1324
+        if (!$f) {
1325
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1326
+            return $errno;
1327
+        }
1328
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1329
+
1330
+        fputs($f, $connect);
1331
+        fputs($f, "\r\n");
1332
+        $res = fread($f, 1024);
1333
+        if (
1334
+            !$res
1335
+            or !count($res = explode(' ', $res))
1336
+            or $res[1] !== '200'
1337
+        ) {
1338
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1339
+            fclose($f);
1340
+
1341
+            return false;
1342
+        }
1343
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1344
+        stream_set_blocking($f, true);
1345
+        // envoyer le handshake
1346
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1347
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1348
+    } else {
1349
+        $ntry = 3;
1350
+        do {
1351
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1352
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1353
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1354
+        if (!$f) {
1355
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1356
+
1357
+            return $errno;
1358
+        }
1359
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1360
+    }
1361
+
1362
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1363
+
1364
+    $host_port = $host;
1365
+    if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1366
+        $host_port .= ":$port";
1367
+    }
1368
+    $req = "$method $path $vers\r\n"
1369
+        . "Host: $host_port\r\n"
1370
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1371
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1372
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1373
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1374
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1375
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1376
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1377 1377
 
1378 1378
 #	spip_log("Requete\n$req", 'distant');
1379
-	fputs($f, $req);
1380
-	fputs($f, $datas ? $datas : "\r\n");
1379
+    fputs($f, $req);
1380
+    fputs($f, $datas ? $datas : "\r\n");
1381 1381
 
1382
-	return $f;
1382
+    return $f;
1383 1383
 }
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32 32
 	define('_INC_DISTANT_MAX_SIZE', 2097152);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38
-define('_REGEXP_COPIE_LOCALE', ',' 	.
38
+define('_REGEXP_COPIE_LOCALE', ','.
39 39
 	preg_replace(
40 40
 		'@^https?:@',
41 41
 		'https?:',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// si c'est la protection de soi-meme, retourner le path
72 72
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
73
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
74 74
 
75 75
 		return @file_exists($source) ? $source : false;
76 76
 	}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		return false;
91 91
 	}
92 92
 
93
-	$localrac = _DIR_RACINE . $local;
93
+	$localrac = _DIR_RACINE.$local;
94 94
 	$t = ($mode == 'force') ? false : @file_exists($localrac);
95 95
 
96 96
 	// test d'existence du fichier
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 			['file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '']
116 116
 		);
117 117
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE);
119 119
 		}
120 120
 		if (!$res['length']) {
121 121
 			// si $t c'est sans doute juste un not-modified-since
122 122
 			return $t ? $local : false;
123 123
 		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
124
+		spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant');
125 125
 
126 126
 		// si on retrouve l'extension
127 127
 		if (!empty($res['headers'])
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 			$parts = array_map('intval', explode('.', $ip));
217 217
 			if (
218 218
 				127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
219
-				or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
220
-				or ( 192 === $parts[0] && 168 === $parts[1] )
219
+				or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1])
220
+				or (192 === $parts[0] && 168 === $parts[1])
221 221
 			) {
222 222
 				return false;
223 223
 			}
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	}
230 230
 
231 231
 	$port = $parsed_url['port'];
232
-	if ($port === 80  or $port === 443  or $port === 8080) {
232
+	if ($port === 80 or $port === 443 or $port === 8080) {
233 233
 		return $url;
234 234
 	}
235 235
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 				}
300 300
 			}
301 301
 			if ($taille > 500) {
302
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
302
+				$boundary = substr(md5(rand().'spip'), 0, 8);
303 303
 			}
304 304
 		}
305 305
 
@@ -327,16 +327,16 @@  discard block
 block discarded – undo
327 327
 			}
328 328
 		} else {
329 329
 			// fabrique une chaine HTTP simple pour un POST
330
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
330
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
331 331
 			$chaine = [];
332 332
 			if (is_array($donnees)) {
333 333
 				foreach ($donnees as $cle => $valeur) {
334 334
 					if (is_array($valeur)) {
335 335
 						foreach ($valeur as $val2) {
336
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
336
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
337 337
 						}
338 338
 					} else {
339
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
339
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
340 340
 					}
341 341
 				}
342 342
 				$chaine = implode('&', $chaine);
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 			$url_idn = implode($host_ascii, $url_idn);
371 371
 		}
372 372
 		// et on urlencode les char utf si besoin dans le path
373
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function ($match) {
373
+		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) {
374 374
  return urlencode($match[0]);
375 375
 		}, $url_idn);
376 376
 	}
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 	$head_add = '';
449 449
 	if (!empty($options['headers'])) {
450 450
 		foreach ($options['headers'] as $champ => $valeur) {
451
-			$head_add .= $champ . ': ' . $valeur . "\r\n";
451
+			$head_add .= $champ.': '.$valeur."\r\n";
452 452
 		}
453 453
 		// ne pas le repasser a recuperer_url si on follow un location, car ils seront dans datas
454 454
 		unset($options['headers']);
@@ -458,9 +458,9 @@  discard block
 block discarded – undo
458 458
 		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
459 459
 		$head .= $head_add;
460 460
 		if (stripos($head, 'Content-Length:') === false) {
461
-			$head .= 'Content-Length: ' . strlen($postdata) . "\r\n";
461
+			$head .= 'Content-Length: '.strlen($postdata)."\r\n";
462 462
 		}
463
-		$options['datas'] = $head . "\r\n" . $postdata;
463
+		$options['datas'] = $head."\r\n".$postdata;
464 464
 		if (
465 465
 			strlen($postdata)
466 466
 			and !$methode_demandee
@@ -468,15 +468,15 @@  discard block
 block discarded – undo
468 468
 			$options['methode'] = 'POST';
469 469
 		}
470 470
 	} elseif ($head_add) {
471
-		$options['datas'] = $head_add . "\r\n";
471
+		$options['datas'] = $head_add."\r\n";
472 472
 	}
473 473
 
474 474
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
475 475
 	$url = preg_replace(',^feed://,i', 'http://', $url);
476 476
 	if (!tester_url_absolue($url)) {
477
-		$url = 'http://' . $url;
477
+		$url = 'http://'.$url;
478 478
 	} elseif (strncmp($url, '//', 2) == 0) {
479
-		$url = 'http:' . $url;
479
+		$url = 'http:'.$url;
480 480
 	}
481 481
 
482 482
 	$url = url_to_ascii($url);
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 		$options['if_modified_since']
506 506
 	);
507 507
 	if (!$handle) {
508
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
508
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
509 509
 
510 510
 		return false;
511 511
 	}
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 					'status' => 200,
536 536
 				];
537 537
 			} else {
538
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
538
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
539 539
 				return false;
540 540
 			}
541 541
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 
548 548
 			return recuperer_url($url, $options);
549 549
 		} elseif ($res['status'] !== 200) {
550
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
550
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
551 551
 		}
552 552
 		$result['status'] = $res['status'];
553 553
 		if (isset($res['headers'])) {
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 
573 573
 	$gz = false;
574 574
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
575
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
575
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
576 576
 	}
577 577
 
578 578
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 	$sig['url'] = $url;
659 659
 
660 660
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
661
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
661
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
662 662
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
663 663
 	$cache = "$sub$cache";
664 664
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	$fp = false;
712 712
 	if ($fichier) {
713 713
 		include_spip('inc/acces');
714
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
714
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
715 715
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
716 716
 		if (!$fp and file_exists($fichier)) {
717 717
 			return filesize($fichier);
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 	}
771 771
 	$result['status'] = intval($r[1]);
772 772
 	while ($s = trim(fgets($handle, 16384))) {
773
-		$result['headers'][] = $s . "\n";
773
+		$result['headers'][] = $s."\n";
774 774
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
775 775
 		list(, $d, $v) = $r;
776 776
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -819,13 +819,13 @@  discard block
 block discarded – undo
819 819
 
820 820
 	// on se place tout le temps comme si on etait a la racine
821 821
 	if (_DIR_RACINE) {
822
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
822
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
823 823
 	}
824 824
 
825 825
 	$m = md5($source);
826 826
 
827 827
 	return $d
828
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
828
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
829 829
 	. substr($m, 0, 4)
830 830
 	. ".$extension";
831 831
 }
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	// Si c'est deja local pas de souci
849 849
 	if (!tester_url_absolue($source)) {
850 850
 		if (_DIR_RACINE) {
851
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
851
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
852 852
 		}
853 853
 
854 854
 		return $source;
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 		$ext
867 867
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
868 868
 		and $f = nom_fichier_copie_locale($source, $ext)
869
-		and file_exists(_DIR_RACINE . $f)
869
+		and file_exists(_DIR_RACINE.$f)
870 870
 	) {
871 871
 		return $f;
872 872
 	}
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 
875 875
 	// Si c'est deja dans la table des documents,
876 876
 	// ramener le nom de sa copie potentielle
877
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
877
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
878 878
 
879 879
 	if ($ext) {
880 880
 		return nom_fichier_copie_locale($source, $ext);
@@ -885,9 +885,9 @@  discard block
 block discarded – undo
885 885
 
886 886
 	$ext = $path_parts ? $path_parts['extension'] : '';
887 887
 
888
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
888
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
889 889
 		$f = nom_fichier_copie_locale($source, $ext);
890
-		if (file_exists(_DIR_RACINE . $f)) {
890
+		if (file_exists(_DIR_RACINE.$f)) {
891 891
 			return $f;
892 892
 		}
893 893
 	}
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 	// Ping  pour voir si son extension est connue et autorisee
896 896
 	// avec mise en cache du resultat du ping
897 897
 
898
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
898
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
899 899
 	if (
900 900
 		!@file_exists($cache)
901 901
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
@@ -905,10 +905,10 @@  discard block
 block discarded – undo
905 905
 		ecrire_fichier($cache, serialize($path_parts));
906 906
 	}
907 907
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
908
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
908
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
909 909
 		return nom_fichier_copie_locale($source, $ext);
910 910
 	}
911
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
911
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
912 912
 }
913 913
 
914 914
 
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 		} else {
993 993
 			if ($a['body']) {
994 994
 				$a['extension'] = $extension;
995
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
995
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
996 996
 				ecrire_fichier($a['fichier'], $a['body']);
997 997
 				$size_image = @spip_getimagesize($a['fichier']);
998 998
 				$a['largeur'] = intval($size_image[0]);
@@ -1057,20 +1057,20 @@  discard block
 block discarded – undo
1057 1057
 			!$t
1058 1058
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1059 1059
 		) {
1060
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1060
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1061 1061
 		}
1062 1062
 		if (
1063 1063
 			!$t
1064 1064
 			and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1065 1065
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1066 1066
 		) {
1067
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1067
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1068 1068
 		}
1069 1069
 	}
1070 1070
 
1071 1071
 	// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1072 1072
 	if (!$t) {
1073
-		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1073
+		$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1074 1074
 	}
1075 1075
 
1076 1076
 	// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1081,11 +1081,11 @@  discard block
 block discarded – undo
1081 1081
 		and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1082 1082
 	) {
1083 1083
 		# eviter xxx.3 => 3gp (> SPIP 3)
1084
-		$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1084
+		$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1085 1085
 	}
1086 1086
 
1087 1087
 	if ($t) {
1088
-		spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1088
+		spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1089 1089
 		return $t['extension'];
1090 1090
 	} else {
1091 1091
 		# par defaut on retombe sur '.bin' si c'est autorise
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 		}
1189 1189
 	} else {
1190 1190
 		$scheme = $t['scheme'];
1191
-		$noproxy = $scheme . '://';
1191
+		$noproxy = $scheme.'://';
1192 1192
 	}
1193 1193
 	if (isset($t['user'])) {
1194 1194
 		$user = [$t['user'], $t['pass']];
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
 	}
1203 1203
 
1204 1204
 	if (!empty($t['query'])) {
1205
-		$path .= '?' . $t['query'];
1205
+		$path .= '?'.$t['query'];
1206 1206
 	}
1207 1207
 
1208 1208
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1276,20 +1276,20 @@  discard block
 block discarded – undo
1276 1276
 	$proxy_user = '';
1277 1277
 	$http_proxy = need_proxy($host);
1278 1278
 	if ($user) {
1279
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1279
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1280 1280
 	}
1281 1281
 
1282 1282
 	$connect = '';
1283 1283
 	if ($http_proxy) {
1284
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) {
1285
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1286
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1284
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) {
1285
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1286
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1287 1287
 				. "Host: $path_host\r\n"
1288 1288
 				. "Proxy-Connection: Keep-Alive\r\n";
1289 1289
 		} else {
1290
-			$path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://")
1290
+			$path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://")
1291 1291
 				. (!$user ? '' : "$user@")
1292
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1292
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1293 1293
 		}
1294 1294
 		$t2 = @parse_url($http_proxy);
1295 1295
 		$first_host = $t2['host'];
@@ -1297,10 +1297,10 @@  discard block
 block discarded – undo
1297 1297
 			$port = 80;
1298 1298
 		}
1299 1299
 		if ($t2['user']) {
1300
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1300
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1301 1301
 		}
1302 1302
 	} else {
1303
-		$first_host = $noproxy . $host;
1303
+		$first_host = $noproxy.$host;
1304 1304
 	}
1305 1305
 
1306 1306
 	if ($connect) {
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
 		);
1323 1323
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1324 1324
 		if (!$f) {
1325
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1325
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1326 1326
 			return $errno;
1327 1327
 		}
1328 1328
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 			or !count($res = explode(' ', $res))
1336 1336
 			or $res[1] !== '200'
1337 1337
 		) {
1338
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1338
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1339 1339
 			fclose($f);
1340 1340
 
1341 1341
 			return false;
@@ -1352,7 +1352,7 @@  discard block
 block discarded – undo
1352 1352
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1353 1353
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1354 1354
 		if (!$f) {
1355
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1355
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1356 1356
 
1357 1357
 			return $errno;
1358 1358
 		}
@@ -1362,16 +1362,16 @@  discard block
 block discarded – undo
1362 1362
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1363 1363
 
1364 1364
 	$host_port = $host;
1365
-	if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) {
1365
+	if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) {
1366 1366
 		$host_port .= ":$port";
1367 1367
 	}
1368 1368
 	$req = "$method $path $vers\r\n"
1369 1369
 		. "Host: $host_port\r\n"
1370
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1371
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1370
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1371
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1372 1372
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1373
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1374
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1373
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1374
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1375 1375
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1376 1376
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1377 1377
 
Please login to merge, or discard this patch.