Completed
Push — master ( 7791a8...bbaeee )
by cam
05:04
created
ecrire/inc/charsets.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  * @param string $charset
38 38
  *     Charset à charger.
39 39
  *     Par défaut (AUTO), utilise le charset du site
40
- * @return string|bool
40
+ * @return string|false
41 41
  *     - Nom du charset
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
  *
707 707
  * @param int $num
708 708
  *    Numéro de l'entité unicode
709
- * @return char
709
+ * @return string
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
76
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
77 77
 		return $charset;
78 78
 	} else {
79 79
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	static $pcre_ok = 0;
160 160
 
161 161
 	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
162
+		$s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
163 163
 		if (preg_match(',\W...\W,u', $s)) {
164 164
 			$pcre_ok = 1;
165 165
 		} else {
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
 
261 261
 	if (!isset($trans[$charset][$charset_cible])) {
262 262
 		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "€",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "‚",
266
-			$p . chr(131) => "ƒ",
267
-			$p . chr(132) => "„",
268
-			$p . chr(133) => "…",
269
-			$p . chr(134) => "†",
270
-			$p . chr(135) => "‡",
271
-			$p . chr(136) => "ˆ",
272
-			$p . chr(137) => "‰",
273
-			$p . chr(138) => "Š",
274
-			$p . chr(139) => "‹",
275
-			$p . chr(140) => "Œ",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "Ž",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "‘",
281
-			$p . chr(146) => "’",
282
-			$p . chr(147) => "“",
283
-			$p . chr(148) => "”",
284
-			$p . chr(149) => "•",
285
-			$p . chr(150) => "–",
286
-			$p . chr(151) => "—",
287
-			$p . chr(152) => "˜",
288
-			$p . chr(153) => "™",
289
-			$p . chr(154) => "š",
290
-			$p . chr(155) => "›",
291
-			$p . chr(156) => "œ",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "ž",
294
-			$p . chr(159) => "Ÿ",
263
+			$p.chr(128) => "€",
264
+			$p.chr(129) => ' ', # pas affecte
265
+			$p.chr(130) => "‚",
266
+			$p.chr(131) => "ƒ",
267
+			$p.chr(132) => "„",
268
+			$p.chr(133) => "…",
269
+			$p.chr(134) => "†",
270
+			$p.chr(135) => "‡",
271
+			$p.chr(136) => "ˆ",
272
+			$p.chr(137) => "‰",
273
+			$p.chr(138) => "Š",
274
+			$p.chr(139) => "‹",
275
+			$p.chr(140) => "Œ",
276
+			$p.chr(141) => ' ', # pas affecte
277
+			$p.chr(142) => "Ž",
278
+			$p.chr(143) => ' ', # pas affecte
279
+			$p.chr(144) => ' ', # pas affecte
280
+			$p.chr(145) => "‘",
281
+			$p.chr(146) => "’",
282
+			$p.chr(147) => "“",
283
+			$p.chr(148) => "”",
284
+			$p.chr(149) => "•",
285
+			$p.chr(150) => "–",
286
+			$p.chr(151) => "—",
287
+			$p.chr(152) => "˜",
288
+			$p.chr(153) => "™",
289
+			$p.chr(154) => "š",
290
+			$p.chr(155) => "›",
291
+			$p.chr(156) => "œ",
292
+			$p.chr(157) => ' ', # pas affecte
293
+			$p.chr(158) => "ž",
294
+			$p.chr(159) => "Ÿ",
295 295
 		);
296 296
 		if ($charset_cible != 'unicode') {
297 297
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 					and is_array($GLOBALS['CHARSET'][$cset])
422 422
 				) {
423 423
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
424
+						$trans[$charset][chr($key)] = '&#'.$val.';';
425 425
 					}
426 426
 				}
427 427
 			}
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 					$h = dechex($e);
489 489
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490 490
 						$s = $CHARSET_REVERSE[$charset][$e];
491
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
491
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
492
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
493 493
 					} else {
494
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
494
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
495
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
496 496
 					}
497 497
 				}
498 498
 			}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 				and is_array($GLOBALS['CHARSET'][$cset])
537 537
 			) {
538 538
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
539
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
540 540
 				}
541 541
 			}
542 542
 		}
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 				}
644 644
 				$thisPos++;
645 645
 			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
646
+			$encodedLetter = "&#".preg_replace('/^0+/', '', $decimalCode).';';
647 647
 			$encodedString .= $encodedLetter;
648 648
 		}
649 649
 	}
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687 687
 			else {
688 688
 				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
689
+					$texte .= '&#'.$word.';';
690 690
 				}
691 691
 			}
692 692
 		}
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
 		return chr($num);
716 716
 	}
717 717
 	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
718
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
719 719
 	}
720 720
 	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
721
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
722 722
 	}
723 723
 	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
724
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
725 725
 	}
726 726
 
727 727
 	return '';
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778 778
 		$num = $regs[1];
779 779
 		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
780
+		$s = '\u'.sprintf("%04x", $num);
781 781
 		$texte = str_replace($regs[0], $s, $texte);
782 782
 	}
783 783
 
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
796 796
 	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
797
+		$texte = str_replace($regs[0], "&#".hexdec($regs[1]).";", $texte);
798 798
 	}
799 799
 
800 800
 	return $texte;
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 		return $texte;
840 840
 	}
841 841
 
842
-	$table_translit = 'translit' . $complexe;
842
+	$table_translit = 'translit'.$complexe;
843 843
 
844 844
 	// 2. Translitterer grace a la table predefinie
845 845
 	if (!isset($trans[$complexe])) {
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
  *    true s'il a un BOM
931 931
  **/
932 932
 function bom_utf8($texte) {
933
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
934 934
 }
935 935
 
936 936
 /**
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126 1126
 		// (un caractere utf-8 prenant au maximum n bytes)
1127 1127
 		$n = 0;
1128
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1128
+		while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) {
1129 1129
 			;
1130 1130
 		}
1131 1131
 		$c = substr($c, 0, $n * $length);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 
1160 1160
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1161 1161
 
1162
-	return $lettre1 . spip_substr($c, 1);
1162
+	return $lettre1.spip_substr($c, 1);
1163 1163
 }
1164 1164
 
1165 1165
 /**
Please login to merge, or discard this patch.
Indentation   +703 added lines, -703 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = array();
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = array();
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = array();
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = array();
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (function_exists('mb_internal_encoding')
100
-			and function_exists('mb_detect_order')
101
-			and function_exists('mb_substr')
102
-			and function_exists('mb_strlen')
103
-			and function_exists('mb_strtolower')
104
-			and function_exists('mb_strtoupper')
105
-			and function_exists('mb_encode_mimeheader')
106
-			and function_exists('mb_encode_numericentity')
107
-			and function_exists('mb_decode_numericentity')
108
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
-		) {
110
-			mb_internal_encoding('utf-8');
111
-			$mb = 1;
112
-		} else {
113
-			$mb = -1;
114
-		}
115
-	}
116
-
117
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (function_exists('mb_internal_encoding')
100
+            and function_exists('mb_detect_order')
101
+            and function_exists('mb_substr')
102
+            and function_exists('mb_strlen')
103
+            and function_exists('mb_strtolower')
104
+            and function_exists('mb_strtoupper')
105
+            and function_exists('mb_encode_mimeheader')
106
+            and function_exists('mb_encode_numericentity')
107
+            and function_exists('mb_decode_numericentity')
108
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
+        ) {
110
+            mb_internal_encoding('utf-8');
111
+            $mb = 1;
112
+        } else {
113
+            $mb = -1;
114
+        }
115
+    }
116
+
117
+    return ($mb == 1);
118 118
 }
119 119
 
120 120
 /**
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
  *     true si iconv fonctionne correctement
130 130
  **/
131 131
 function test_iconv() {
132
-	static $iconv_ok;
133
-
134
-	if (!$iconv_ok) {
135
-		if (!function_exists('iconv')) {
136
-			$iconv_ok = -1;
137
-		} else {
138
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
-				$iconv_ok = 1;
140
-			} else {
141
-				$iconv_ok = -1;
142
-			}
143
-		}
144
-	}
145
-
146
-	return ($iconv_ok == 1);
132
+    static $iconv_ok;
133
+
134
+    if (!$iconv_ok) {
135
+        if (!function_exists('iconv')) {
136
+            $iconv_ok = -1;
137
+        } else {
138
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
+                $iconv_ok = 1;
140
+            } else {
141
+                $iconv_ok = -1;
142
+            }
143
+        }
144
+    }
145
+
146
+    return ($iconv_ok == 1);
147 147
 }
148 148
 
149 149
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
  *     true si PCRE supporte l'UTF-8 correctement
157 157
  **/
158 158
 function test_pcre_unicode() {
159
-	static $pcre_ok = 0;
160
-
161
-	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
-		if (preg_match(',\W...\W,u', $s)) {
164
-			$pcre_ok = 1;
165
-		} else {
166
-			$pcre_ok = -1;
167
-		}
168
-	}
169
-
170
-	return $pcre_ok == 1;
159
+    static $pcre_ok = 0;
160
+
161
+    if (!$pcre_ok) {
162
+        $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
+        if (preg_match(',\W...\W,u', $s)) {
164
+            $pcre_ok = 1;
165
+        } else {
166
+            $pcre_ok = -1;
167
+        }
168
+    }
169
+
170
+    return $pcre_ok == 1;
171 171
 }
172 172
 
173 173
 /**
@@ -183,22 +183,22 @@  discard block
 block discarded – undo
183 183
  *    Plage de caractères
184 184
  **/
185 185
 function pcre_lettres_unicode() {
186
-	static $plage_unicode;
187
-
188
-	if (!$plage_unicode) {
189
-		if (test_pcre_unicode()) {
190
-			// cf. http://www.unicode.org/charts/
191
-			$plage_unicode = '\w' // iso-latin
192
-				. '\x{100}-\x{24f}' // europeen etendu
193
-				. '\x{300}-\x{1cff}' // des tas de trucs
194
-			;
195
-		} else {
196
-			// fallback a trois sous
197
-			$plage_unicode = '\w';
198
-		}
199
-	}
200
-
201
-	return $plage_unicode;
186
+    static $plage_unicode;
187
+
188
+    if (!$plage_unicode) {
189
+        if (test_pcre_unicode()) {
190
+            // cf. http://www.unicode.org/charts/
191
+            $plage_unicode = '\w' // iso-latin
192
+                . '\x{100}-\x{24f}' // europeen etendu
193
+                . '\x{300}-\x{1cff}' // des tas de trucs
194
+            ;
195
+        } else {
196
+            // fallback a trois sous
197
+            $plage_unicode = '\w';
198
+        }
199
+    }
200
+
201
+    return $plage_unicode;
202 202
 }
203 203
 
204 204
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
  *    Plage de caractères
217 217
  **/
218 218
 function plage_punct_unicode() {
219
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
219
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220 220
 }
221 221
 
222 222
 /**
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
  *     Texte corrigé
237 237
  **/
238 238
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
239
-	static $trans;
240
-
241
-	if (is_array($texte)) {
242
-		return array_map('corriger_caracteres_windows', $texte);
243
-	}
244
-
245
-	if ($charset == 'AUTO') {
246
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
247
-	}
248
-	if ($charset == 'utf-8') {
249
-		$p = chr(194);
250
-		if (strpos($texte, $p) == false) {
251
-			return $texte;
252
-		}
253
-	} else {
254
-		if ($charset == 'iso-8859-1') {
255
-			$p = '';
256
-		} else {
257
-			return $texte;
258
-		}
259
-	}
260
-
261
-	if (!isset($trans[$charset][$charset_cible])) {
262
-		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
295
-		);
296
-		if ($charset_cible != 'unicode') {
297
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
-			}
300
-		}
301
-	}
302
-
303
-	return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
-		array_values($trans[$charset][$charset_cible]), $texte);
239
+    static $trans;
240
+
241
+    if (is_array($texte)) {
242
+        return array_map('corriger_caracteres_windows', $texte);
243
+    }
244
+
245
+    if ($charset == 'AUTO') {
246
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
247
+    }
248
+    if ($charset == 'utf-8') {
249
+        $p = chr(194);
250
+        if (strpos($texte, $p) == false) {
251
+            return $texte;
252
+        }
253
+    } else {
254
+        if ($charset == 'iso-8859-1') {
255
+            $p = '';
256
+        } else {
257
+            return $texte;
258
+        }
259
+    }
260
+
261
+    if (!isset($trans[$charset][$charset_cible])) {
262
+        $trans[$charset][$charset_cible] = array(
263
+            $p . chr(128) => "&#8364;",
264
+            $p . chr(129) => ' ', # pas affecte
265
+            $p . chr(130) => "&#8218;",
266
+            $p . chr(131) => "&#402;",
267
+            $p . chr(132) => "&#8222;",
268
+            $p . chr(133) => "&#8230;",
269
+            $p . chr(134) => "&#8224;",
270
+            $p . chr(135) => "&#8225;",
271
+            $p . chr(136) => "&#710;",
272
+            $p . chr(137) => "&#8240;",
273
+            $p . chr(138) => "&#352;",
274
+            $p . chr(139) => "&#8249;",
275
+            $p . chr(140) => "&#338;",
276
+            $p . chr(141) => ' ', # pas affecte
277
+            $p . chr(142) => "&#381;",
278
+            $p . chr(143) => ' ', # pas affecte
279
+            $p . chr(144) => ' ', # pas affecte
280
+            $p . chr(145) => "&#8216;",
281
+            $p . chr(146) => "&#8217;",
282
+            $p . chr(147) => "&#8220;",
283
+            $p . chr(148) => "&#8221;",
284
+            $p . chr(149) => "&#8226;",
285
+            $p . chr(150) => "&#8211;",
286
+            $p . chr(151) => "&#8212;",
287
+            $p . chr(152) => "&#732;",
288
+            $p . chr(153) => "&#8482;",
289
+            $p . chr(154) => "&#353;",
290
+            $p . chr(155) => "&#8250;",
291
+            $p . chr(156) => "&#339;",
292
+            $p . chr(157) => ' ', # pas affecte
293
+            $p . chr(158) => "&#382;",
294
+            $p . chr(159) => "&#376;",
295
+        );
296
+        if ($charset_cible != 'unicode') {
297
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
+            }
300
+        }
301
+    }
302
+
303
+    return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
+        array_values($trans[$charset][$charset_cible]), $texte);
305 305
 }
306 306
 
307 307
 
@@ -318,24 +318,24 @@  discard block
 block discarded – undo
318 318
  *     Texte converti
319 319
  **/
320 320
 function html2unicode($texte, $secure = false) {
321
-	if (strpos($texte, '&') === false) {
322
-		return $texte;
323
-	}
324
-	static $trans = array();
325
-	if (!$trans) {
326
-		load_charset('html');
327
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
-			$trans["&$key;"] = $val;
329
-		}
330
-	}
331
-
332
-	if ($secure) {
333
-		return str_replace(array_keys($trans), array_values($trans), $texte);
334
-	} else {
335
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
-			str_replace(array_keys($trans), array_values($trans), $texte)
337
-		);
338
-	}
321
+    if (strpos($texte, '&') === false) {
322
+        return $texte;
323
+    }
324
+    static $trans = array();
325
+    if (!$trans) {
326
+        load_charset('html');
327
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
+            $trans["&$key;"] = $val;
329
+        }
330
+    }
331
+
332
+    if ($secure) {
333
+        return str_replace(array_keys($trans), array_values($trans), $texte);
334
+    } else {
335
+        return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
+            str_replace(array_keys($trans), array_values($trans), $texte)
337
+        );
338
+    }
339 339
 }
340 340
 
341 341
 
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
  *     Texte converti
351 351
  **/
352 352
 function mathml2unicode($texte) {
353
-	static $trans;
354
-	if (!$trans) {
355
-		load_charset('mathml');
353
+    static $trans;
354
+    if (!$trans) {
355
+        load_charset('mathml');
356 356
 
357
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
-			$trans["&$key;"] = $val;
359
-		}
360
-	}
357
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
+            $trans["&$key;"] = $val;
359
+        }
360
+    }
361 361
 
362
-	return str_replace(array_keys($trans), array_values($trans), $texte);
362
+    return str_replace(array_keys($trans), array_values($trans), $texte);
363 363
 }
364 364
 
365 365
 
@@ -381,69 +381,69 @@  discard block
 block discarded – undo
381 381
  *     Texte converti en unicode
382 382
  **/
383 383
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
384
-	static $trans;
385
-
386
-	if ($charset == 'AUTO') {
387
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
388
-	}
389
-
390
-	if ($charset == '') {
391
-		$charset = 'iso-8859-1';
392
-	}
393
-	$charset = strtolower($charset);
394
-
395
-	switch ($charset) {
396
-		case 'utf-8':
397
-		case 'utf8':
398
-			return utf_8_to_unicode($texte);
399
-
400
-		case 'iso-8859-1':
401
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
-		// pas de break; ici, on suit sur default:
403
-
404
-		default:
405
-			// mbstring presente ?
406
-			if (init_mb_string()) {
407
-				if ($order = mb_detect_order() # mb_string connait-il $charset?
408
-					and mb_detect_order($charset)
409
-				) {
410
-					$s = mb_convert_encoding($texte, 'utf-8', $charset);
411
-					if ($s && $s != $texte) {
412
-						return utf_8_to_unicode($s);
413
-					}
414
-				}
415
-				mb_detect_order($order); # remettre comme precedemment
416
-			}
417
-
418
-			// Sinon, peut-etre connaissons-nous ce charset ?
419
-			if (!isset($trans[$charset])) {
420
-				if ($cset = load_charset($charset)
421
-					and is_array($GLOBALS['CHARSET'][$cset])
422
-				) {
423
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
425
-					}
426
-				}
427
-			}
428
-			if (count($trans[$charset])) {
429
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
-			}
431
-
432
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
-			// caractere n'appartient pas au charset, mais c'est un probleme
434
-			// surtout en utf-8, gere ci-dessus)
435
-			if (test_iconv()) {
436
-				$s = iconv($charset, 'utf-32le', $texte);
437
-				if ($s) {
438
-					return utf_32_to_unicode($s);
439
-				}
440
-			}
441
-
442
-			// Au pire ne rien faire
443
-			spip_log("erreur charset '$charset' non supporte");
444
-
445
-			return $texte;
446
-	}
384
+    static $trans;
385
+
386
+    if ($charset == 'AUTO') {
387
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
388
+    }
389
+
390
+    if ($charset == '') {
391
+        $charset = 'iso-8859-1';
392
+    }
393
+    $charset = strtolower($charset);
394
+
395
+    switch ($charset) {
396
+        case 'utf-8':
397
+        case 'utf8':
398
+            return utf_8_to_unicode($texte);
399
+
400
+        case 'iso-8859-1':
401
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
+        // pas de break; ici, on suit sur default:
403
+
404
+        default:
405
+            // mbstring presente ?
406
+            if (init_mb_string()) {
407
+                if ($order = mb_detect_order() # mb_string connait-il $charset?
408
+                    and mb_detect_order($charset)
409
+                ) {
410
+                    $s = mb_convert_encoding($texte, 'utf-8', $charset);
411
+                    if ($s && $s != $texte) {
412
+                        return utf_8_to_unicode($s);
413
+                    }
414
+                }
415
+                mb_detect_order($order); # remettre comme precedemment
416
+            }
417
+
418
+            // Sinon, peut-etre connaissons-nous ce charset ?
419
+            if (!isset($trans[$charset])) {
420
+                if ($cset = load_charset($charset)
421
+                    and is_array($GLOBALS['CHARSET'][$cset])
422
+                ) {
423
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
425
+                    }
426
+                }
427
+            }
428
+            if (count($trans[$charset])) {
429
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
+            }
431
+
432
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
+            // caractere n'appartient pas au charset, mais c'est un probleme
434
+            // surtout en utf-8, gere ci-dessus)
435
+            if (test_iconv()) {
436
+                $s = iconv($charset, 'utf-32le', $texte);
437
+                if ($s) {
438
+                    return utf_32_to_unicode($s);
439
+                }
440
+            }
441
+
442
+            // Au pire ne rien faire
443
+            spip_log("erreur charset '$charset' non supporte");
444
+
445
+            return $texte;
446
+    }
447 447
 }
448 448
 
449 449
 
@@ -462,44 +462,44 @@  discard block
 block discarded – undo
462 462
  *     Texte transformé dans le charset souhaité
463 463
  **/
464 464
 function unicode2charset($texte, $charset = 'AUTO') {
465
-	static $CHARSET_REVERSE = array();
466
-	static $trans = array();
467
-
468
-	if ($charset == 'AUTO') {
469
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
470
-	}
471
-
472
-	switch ($charset) {
473
-		case 'utf-8':
474
-			return unicode_to_utf_8($texte);
475
-			break;
476
-
477
-		default:
478
-			$charset = load_charset($charset);
479
-
480
-			if (empty($CHARSET_REVERSE[$charset])) {
481
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
-			}
483
-
484
-			if (!isset($trans[$charset])) {
485
-				$trans[$charset] = array();
486
-				$t = &$trans[$charset];
487
-				for ($e = 128; $e < 255; $e++) {
488
-					$h = dechex($e);
489
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490
-						$s = $CHARSET_REVERSE[$charset][$e];
491
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
493
-					} else {
494
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
496
-					}
497
-				}
498
-			}
499
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
-
501
-			return $texte;
502
-	}
465
+    static $CHARSET_REVERSE = array();
466
+    static $trans = array();
467
+
468
+    if ($charset == 'AUTO') {
469
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
470
+    }
471
+
472
+    switch ($charset) {
473
+        case 'utf-8':
474
+            return unicode_to_utf_8($texte);
475
+            break;
476
+
477
+        default:
478
+            $charset = load_charset($charset);
479
+
480
+            if (empty($CHARSET_REVERSE[$charset])) {
481
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
+            }
483
+
484
+            if (!isset($trans[$charset])) {
485
+                $trans[$charset] = array();
486
+                $t = &$trans[$charset];
487
+                for ($e = 128; $e < 255; $e++) {
488
+                    $h = dechex($e);
489
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490
+                        $s = $CHARSET_REVERSE[$charset][$e];
491
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
493
+                    } else {
494
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
496
+                    }
497
+                }
498
+            }
499
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
+
501
+            return $texte;
502
+    }
503 503
 }
504 504
 
505 505
 
@@ -517,37 +517,37 @@  discard block
 block discarded – undo
517 517
  *     Texte transformé dans le charset site
518 518
  **/
519 519
 function importer_charset($texte, $charset = 'AUTO') {
520
-	static $trans = array();
521
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
-		if (init_mb_string()) {
525
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
526
-				and mb_detect_order($charset)
527
-			) {
528
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
529
-			}
530
-			mb_detect_order($order); # remettre comme precedemment
531
-			return $s;
532
-		}
533
-		// Sinon, peut-etre connaissons-nous ce charset ?
534
-		if (!isset($trans[$charset])) {
535
-			if ($cset = load_charset($charset)
536
-				and is_array($GLOBALS['CHARSET'][$cset])
537
-			) {
538
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
-				}
541
-			}
542
-		}
543
-		if (count($trans[$charset])) {
544
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
-		}
546
-
547
-		return $texte;
548
-	}
549
-
550
-	return unicode2charset(charset2unicode($texte, $charset));
520
+    static $trans = array();
521
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
+        if (init_mb_string()) {
525
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
526
+                and mb_detect_order($charset)
527
+            ) {
528
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
529
+            }
530
+            mb_detect_order($order); # remettre comme precedemment
531
+            return $s;
532
+        }
533
+        // Sinon, peut-etre connaissons-nous ce charset ?
534
+        if (!isset($trans[$charset])) {
535
+            if ($cset = load_charset($charset)
536
+                and is_array($GLOBALS['CHARSET'][$cset])
537
+            ) {
538
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
+                }
541
+            }
542
+        }
543
+        if (count($trans[$charset])) {
544
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
+        }
546
+
547
+        return $texte;
548
+    }
549
+
550
+    return unicode2charset(charset2unicode($texte, $charset));
551 551
 }
552 552
 
553 553
 
@@ -563,92 +563,92 @@  discard block
 block discarded – undo
563 563
  **/
564 564
 function utf_8_to_unicode($source) {
565 565
 
566
-	// mb_string : methode rapide
567
-	if (init_mb_string()) {
568
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
-
570
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
-	}
572
-
573
-	// Sinon methode pas a pas
574
-	static $decrement;
575
-	static $shift;
576
-
577
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
-	if (!is_array($decrement)) {
579
-		// array used to figure what number to decrement from character order value
580
-		// according to number of characters used to map unicode to ascii by utf-8
581
-		$decrement[4] = 240;
582
-		$decrement[3] = 224;
583
-		$decrement[2] = 192;
584
-		$decrement[1] = 0;
585
-		// the number of bits to shift each charNum by
586
-		$shift[1][0] = 0;
587
-		$shift[2][0] = 6;
588
-		$shift[2][1] = 0;
589
-		$shift[3][0] = 12;
590
-		$shift[3][1] = 6;
591
-		$shift[3][2] = 0;
592
-		$shift[4][0] = 18;
593
-		$shift[4][1] = 12;
594
-		$shift[4][2] = 6;
595
-		$shift[4][3] = 0;
596
-	}
597
-
598
-	$pos = 0;
599
-	$len = strlen($source);
600
-	$encodedString = '';
601
-	while ($pos < $len) {
602
-		$char = '';
603
-		$ischar = false;
604
-		$asciiPos = ord(substr($source, $pos, 1));
605
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
-			// 4 chars representing one unicode character
607
-			$thisLetter = substr($source, $pos, 4);
608
-			$pos += 4;
609
-		} else {
610
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
-				// 3 chars representing one unicode character
612
-				$thisLetter = substr($source, $pos, 3);
613
-				$pos += 3;
614
-			} else {
615
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
-					// 2 chars representing one unicode character
617
-					$thisLetter = substr($source, $pos, 2);
618
-					$pos += 2;
619
-				} else {
620
-					// 1 char (lower ascii)
621
-					$thisLetter = substr($source, $pos, 1);
622
-					$pos += 1;
623
-					$char = $thisLetter;
624
-					$ischar = true;
625
-				}
626
-			}
627
-		}
628
-
629
-		if ($ischar) {
630
-			$encodedString .= $char;
631
-		} else {  // process the string representing the letter to a unicode entity
632
-			$thisLen = strlen($thisLetter);
633
-			$thisPos = 0;
634
-			$decimalCode = 0;
635
-			while ($thisPos < $thisLen) {
636
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
-				if ($thisPos == 0) {
638
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
-				} else {
641
-					$charNum = intval($thisCharOrd - 128);
642
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
-				}
644
-				$thisPos++;
645
-			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
-			$encodedString .= $encodedLetter;
648
-		}
649
-	}
650
-
651
-	return $encodedString;
566
+    // mb_string : methode rapide
567
+    if (init_mb_string()) {
568
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
+
570
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
+    }
572
+
573
+    // Sinon methode pas a pas
574
+    static $decrement;
575
+    static $shift;
576
+
577
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
+    if (!is_array($decrement)) {
579
+        // array used to figure what number to decrement from character order value
580
+        // according to number of characters used to map unicode to ascii by utf-8
581
+        $decrement[4] = 240;
582
+        $decrement[3] = 224;
583
+        $decrement[2] = 192;
584
+        $decrement[1] = 0;
585
+        // the number of bits to shift each charNum by
586
+        $shift[1][0] = 0;
587
+        $shift[2][0] = 6;
588
+        $shift[2][1] = 0;
589
+        $shift[3][0] = 12;
590
+        $shift[3][1] = 6;
591
+        $shift[3][2] = 0;
592
+        $shift[4][0] = 18;
593
+        $shift[4][1] = 12;
594
+        $shift[4][2] = 6;
595
+        $shift[4][3] = 0;
596
+    }
597
+
598
+    $pos = 0;
599
+    $len = strlen($source);
600
+    $encodedString = '';
601
+    while ($pos < $len) {
602
+        $char = '';
603
+        $ischar = false;
604
+        $asciiPos = ord(substr($source, $pos, 1));
605
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
+            // 4 chars representing one unicode character
607
+            $thisLetter = substr($source, $pos, 4);
608
+            $pos += 4;
609
+        } else {
610
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
+                // 3 chars representing one unicode character
612
+                $thisLetter = substr($source, $pos, 3);
613
+                $pos += 3;
614
+            } else {
615
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
+                    // 2 chars representing one unicode character
617
+                    $thisLetter = substr($source, $pos, 2);
618
+                    $pos += 2;
619
+                } else {
620
+                    // 1 char (lower ascii)
621
+                    $thisLetter = substr($source, $pos, 1);
622
+                    $pos += 1;
623
+                    $char = $thisLetter;
624
+                    $ischar = true;
625
+                }
626
+            }
627
+        }
628
+
629
+        if ($ischar) {
630
+            $encodedString .= $char;
631
+        } else {  // process the string representing the letter to a unicode entity
632
+            $thisLen = strlen($thisLetter);
633
+            $thisPos = 0;
634
+            $decimalCode = 0;
635
+            while ($thisPos < $thisLen) {
636
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
+                if ($thisPos == 0) {
638
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
+                } else {
641
+                    $charNum = intval($thisCharOrd - 128);
642
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
+                }
644
+                $thisPos++;
645
+            }
646
+            $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
+            $encodedString .= $encodedLetter;
648
+        }
649
+    }
650
+
651
+    return $encodedString;
652 652
 }
653 653
 
654 654
 /**
@@ -667,32 +667,32 @@  discard block
 block discarded – undo
667 667
  **/
668 668
 function utf_32_to_unicode($source) {
669 669
 
670
-	// mb_string : methode rapide
671
-	if (init_mb_string()) {
672
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
-
675
-		return str_replace(chr(0), '', $source);
676
-	}
677
-
678
-	// Sinon methode lente
679
-	$texte = '';
680
-	while ($source) {
681
-		$words = unpack("V*", substr($source, 0, 1024));
682
-		$source = substr($source, 1024);
683
-		foreach ($words as $word) {
684
-			if ($word < 128) {
685
-				$texte .= chr($word);
686
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
-			else {
688
-				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
690
-				}
691
-			}
692
-		}
693
-	}
694
-
695
-	return $texte;
670
+    // mb_string : methode rapide
671
+    if (init_mb_string()) {
672
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
+
675
+        return str_replace(chr(0), '', $source);
676
+    }
677
+
678
+    // Sinon methode lente
679
+    $texte = '';
680
+    while ($source) {
681
+        $words = unpack("V*", substr($source, 0, 1024));
682
+        $source = substr($source, 1024);
683
+        foreach ($words as $word) {
684
+            if ($word < 128) {
685
+                $texte .= chr($word);
686
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
+            else {
688
+                if ($word != 65279) {
689
+                    $texte .= '&#' . $word . ';';
690
+                }
691
+            }
692
+        }
693
+    }
694
+
695
+    return $texte;
696 696
 
697 697
 }
698 698
 
@@ -710,21 +710,21 @@  discard block
 block discarded – undo
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
713
-	$num = intval($num);
714
-	if ($num < 128) {
715
-		return chr($num);
716
-	}
717
-	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
-	}
720
-	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
-	}
723
-	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
-	}
726
-
727
-	return '';
713
+    $num = intval($num);
714
+    if ($num < 128) {
715
+        return chr($num);
716
+    }
717
+    if ($num < 2048) {
718
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
+    }
720
+    if ($num < 65536) {
721
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
+    }
723
+    if ($num < 1114112) {
724
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
+    }
726
+
727
+    return '';
728 728
 }
729 729
 
730 730
 /**
@@ -737,30 +737,30 @@  discard block
 block discarded – undo
737 737
  **/
738 738
 function unicode_to_utf_8($texte) {
739 739
 
740
-	// 1. Entites &#128; et suivantes
741
-	$vu = array();
742
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
-		$texte, $regs, PREG_SET_ORDER)) {
744
-		foreach ($regs as $reg) {
745
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
747
-			}
748
-		}
749
-	}
750
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
-
752
-	// 2. Entites > &#xFF;
753
-	//$vu = array();
754
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
-		$texte, $regs, PREG_SET_ORDER)) {
756
-		foreach ($regs as $reg) {
757
-			if (!isset($vu[$reg[0]])) {
758
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
-			}
760
-		}
761
-	}
762
-
763
-	return str_replace(array_keys($vu), array_values($vu), $texte);
740
+    // 1. Entites &#128; et suivantes
741
+    $vu = array();
742
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
+        $texte, $regs, PREG_SET_ORDER)) {
744
+        foreach ($regs as $reg) {
745
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
747
+            }
748
+        }
749
+    }
750
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
+
752
+    // 2. Entites > &#xFF;
753
+    //$vu = array();
754
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
+        $texte, $regs, PREG_SET_ORDER)) {
756
+        foreach ($regs as $reg) {
757
+            if (!isset($vu[$reg[0]])) {
758
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
+            }
760
+        }
761
+    }
762
+
763
+    return str_replace(array_keys($vu), array_values($vu), $texte);
764 764
 
765 765
 }
766 766
 
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
  *     Texte converti
774 774
  **/
775 775
 function unicode_to_javascript($texte) {
776
-	$vu = array();
777
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
-		$num = $regs[1];
779
-		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
781
-		$texte = str_replace($regs[0], $s, $texte);
782
-	}
783
-
784
-	return $texte;
776
+    $vu = array();
777
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
+        $num = $regs[1];
779
+        $vu[$num] = true;
780
+        $s = '\u' . sprintf("%04x", $num);
781
+        $texte = str_replace($regs[0], $s, $texte);
782
+    }
783
+
784
+    return $texte;
785 785
 }
786 786
 
787 787
 /**
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
  *     Texte converti
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
796
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
798
-	}
796
+    while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
+        $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
798
+    }
799 799
 
800
-	return $texte;
800
+    return $texte;
801 801
 }
802 802
 
803 803
 /**
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
  *     Texte converti
810 810
  **/
811 811
 function javascript_to_binary($texte) {
812
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
-	}
812
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
+    }
815 815
 
816
-	return $texte;
816
+    return $texte;
817 817
 }
818 818
 
819 819
 
@@ -831,26 +831,26 @@  discard block
 block discarded – undo
831 831
  * @return string
832 832
  */
833 833
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
834
-	static $trans = [];
835
-	if ($charset == 'AUTO') {
836
-		$charset = $GLOBALS['meta']['charset'];
837
-	}
838
-	if (!strlen($texte)) {
839
-		return $texte;
840
-	}
841
-
842
-	$table_translit = 'translit' . $complexe;
843
-
844
-	// 2. Translitterer grace a la table predefinie
845
-	if (!isset($trans[$complexe])) {
846
-		$trans[$complexe] = [];
847
-		load_charset($table_translit);
848
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
849
-			$trans[$complexe][caractere_utf_8($key)] = $val;
850
-		}
851
-	}
852
-
853
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
834
+    static $trans = [];
835
+    if ($charset == 'AUTO') {
836
+        $charset = $GLOBALS['meta']['charset'];
837
+    }
838
+    if (!strlen($texte)) {
839
+        return $texte;
840
+    }
841
+
842
+    $table_translit = 'translit' . $complexe;
843
+
844
+    // 2. Translitterer grace a la table predefinie
845
+    if (!isset($trans[$complexe])) {
846
+        $trans[$complexe] = [];
847
+        load_charset($table_translit);
848
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
849
+            $trans[$complexe][caractere_utf_8($key)] = $val;
850
+        }
851
+    }
852
+
853
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
854 854
 }
855 855
 
856 856
 /**
@@ -873,14 +873,14 @@  discard block
 block discarded – undo
873 873
  * @return string
874 874
  */
875 875
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
876
-	// 0. Supprimer les caracteres illegaux
877
-	include_spip('inc/filtres');
878
-	$texte = corriger_caracteres($texte);
876
+    // 0. Supprimer les caracteres illegaux
877
+    include_spip('inc/filtres');
878
+    $texte = corriger_caracteres($texte);
879 879
 
880
-	// 1. Passer le charset et les &eacute en utf-8
881
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
880
+    // 1. Passer le charset et les &eacute en utf-8
881
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
882 882
 
883
-	return translitteration_rapide($texte, $charset, $complexe);
883
+    return translitteration_rapide($texte, $charset, $complexe);
884 884
 }
885 885
 
886 886
 /**
@@ -895,17 +895,17 @@  discard block
 block discarded – undo
895 895
  * @return string
896 896
  */
897 897
 function translitteration_complexe($texte, $chiffres = false) {
898
-	$texte = translitteration($texte, 'AUTO', 'complexe');
898
+    $texte = translitteration($texte, 'AUTO', 'complexe');
899 899
 
900
-	if ($chiffres) {
901
-		$texte = preg_replace_callback(
902
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
903
-			function($m) { return translitteration_chiffree($m[0]); },
904
-			$texte
905
-		);
906
-	}
900
+    if ($chiffres) {
901
+        $texte = preg_replace_callback(
902
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
903
+            function($m) { return translitteration_chiffree($m[0]); },
904
+            $texte
905
+        );
906
+    }
907 907
 
908
-	return $texte;
908
+    return $texte;
909 909
 }
910 910
 
911 911
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  * @return string
918 918
  */
919 919
 function translitteration_chiffree($car) {
920
-	return strtr($car, "'`?~.^+(-", "123456789");
920
+    return strtr($car, "'`?~.^+(-", "123456789");
921 921
 }
922 922
 
923 923
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
  *    true s'il a un BOM
931 931
  **/
932 932
 function bom_utf8($texte) {
933
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
934 934
 }
935 935
 
936 936
 /**
@@ -947,18 +947,18 @@  discard block
 block discarded – undo
947 947
  *     true si c'est le cas
948 948
  **/
949 949
 function is_utf8($string) {
950
-	return !strlen(
951
-		preg_replace(
952
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
953
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
954
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
955
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
956
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
957
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
958
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
959
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
960
-			. ',sS',
961
-			'', $string));
950
+    return !strlen(
951
+        preg_replace(
952
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
953
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
954
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
955
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
956
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
957
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
958
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
959
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
960
+            . ',sS',
961
+            '', $string));
962 962
 }
963 963
 
964 964
 /**
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
  *     true si c'est le cas
971 971
  **/
972 972
 function is_ascii($string) {
973
-	return !strlen(
974
-		preg_replace(
975
-			',[\x09\x0A\x0D\x20-\x7E],sS',
976
-			'', $string));
973
+    return !strlen(
974
+        preg_replace(
975
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
976
+            '', $string));
977 977
 }
978 978
 
979 979
 /**
@@ -992,58 +992,58 @@  discard block
 block discarded – undo
992 992
  **/
993 993
 function transcoder_page($texte, $headers = '') {
994 994
 
995
-	// Si tout est < 128 pas la peine d'aller plus loin
996
-	if (is_ascii($texte)) {
997
-		#spip_log('charset: ascii');
998
-		return $texte;
999
-	}
1000
-
1001
-	// Reconnaitre le BOM utf-8 (0xEFBBBF)
1002
-	if (bom_utf8($texte)) {
1003
-		$charset = 'utf-8';
1004
-		$texte = substr($texte, 3);
1005
-	} // charset precise par le contenu (xml)
1006
-	else {
1007
-		if (preg_match(
1008
-			',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1009
-			$charset = trim(strtolower($regs[1]));
1010
-		} // charset precise par le contenu (html)
1011
-		else {
1012
-			if (preg_match(
1013
-					',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1014
-					$texte, $regs)
1015
-				# eviter #CHARSET des squelettes
1016
-				and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1017
-			) {
1018
-				$charset = $tmp;
1019
-			} // charset de la reponse http
1020
-			else {
1021
-				if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1022
-					$charset = trim(strtolower($regs[1]));
1023
-				} else {
1024
-					$charset = '';
1025
-				}
1026
-			}
1027
-		}
1028
-	}
1029
-	// normaliser les noms du shif-jis japonais
1030
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1031
-		$charset = 'shift-jis';
1032
-	}
1033
-
1034
-	if ($charset) {
1035
-		spip_log("charset: $charset");
1036
-	} else {
1037
-		// valeur par defaut
1038
-		if (is_utf8($texte)) {
1039
-			$charset = 'utf-8';
1040
-		} else {
1041
-			$charset = 'iso-8859-1';
1042
-		}
1043
-		spip_log("charset probable: $charset");
1044
-	}
1045
-
1046
-	return importer_charset($texte, $charset);
995
+    // Si tout est < 128 pas la peine d'aller plus loin
996
+    if (is_ascii($texte)) {
997
+        #spip_log('charset: ascii');
998
+        return $texte;
999
+    }
1000
+
1001
+    // Reconnaitre le BOM utf-8 (0xEFBBBF)
1002
+    if (bom_utf8($texte)) {
1003
+        $charset = 'utf-8';
1004
+        $texte = substr($texte, 3);
1005
+    } // charset precise par le contenu (xml)
1006
+    else {
1007
+        if (preg_match(
1008
+            ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1009
+            $charset = trim(strtolower($regs[1]));
1010
+        } // charset precise par le contenu (html)
1011
+        else {
1012
+            if (preg_match(
1013
+                    ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1014
+                    $texte, $regs)
1015
+                # eviter #CHARSET des squelettes
1016
+                and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1017
+            ) {
1018
+                $charset = $tmp;
1019
+            } // charset de la reponse http
1020
+            else {
1021
+                if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1022
+                    $charset = trim(strtolower($regs[1]));
1023
+                } else {
1024
+                    $charset = '';
1025
+                }
1026
+            }
1027
+        }
1028
+    }
1029
+    // normaliser les noms du shif-jis japonais
1030
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1031
+        $charset = 'shift-jis';
1032
+    }
1033
+
1034
+    if ($charset) {
1035
+        spip_log("charset: $charset");
1036
+    } else {
1037
+        // valeur par defaut
1038
+        if (is_utf8($texte)) {
1039
+            $charset = 'utf-8';
1040
+        } else {
1041
+            $charset = 'iso-8859-1';
1042
+        }
1043
+        spip_log("charset probable: $charset");
1044
+    }
1045
+
1046
+    return importer_charset($texte, $charset);
1047 1047
 }
1048 1048
 
1049 1049
 
@@ -1067,26 +1067,26 @@  discard block
 block discarded – undo
1067 1067
  *     Le texte coupé
1068 1068
  **/
1069 1069
 function spip_substr($c, $start = 0, $length = null) {
1070
-	// Si ce n'est pas utf-8, utiliser substr
1071
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1072
-		if ($length) {
1073
-			return substr($c, $start, $length);
1074
-		} else {
1075
-			substr($c, $start);
1076
-		}
1077
-	}
1078
-
1079
-	// Si utf-8, voir si on dispose de mb_string
1080
-	if (init_mb_string()) {
1081
-		if ($length) {
1082
-			return mb_substr($c, $start, $length);
1083
-		} else {
1084
-			return mb_substr($c, $start);
1085
-		}
1086
-	}
1087
-
1088
-	// Version manuelle (cf. ci-dessous)
1089
-	return spip_substr_manuelle($c, $start, $length);
1070
+    // Si ce n'est pas utf-8, utiliser substr
1071
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1072
+        if ($length) {
1073
+            return substr($c, $start, $length);
1074
+        } else {
1075
+            substr($c, $start);
1076
+        }
1077
+    }
1078
+
1079
+    // Si utf-8, voir si on dispose de mb_string
1080
+    if (init_mb_string()) {
1081
+        if ($length) {
1082
+            return mb_substr($c, $start, $length);
1083
+        } else {
1084
+            return mb_substr($c, $start);
1085
+        }
1086
+    }
1087
+
1088
+    // Version manuelle (cf. ci-dessous)
1089
+    return spip_substr_manuelle($c, $start, $length);
1090 1090
 }
1091 1091
 
1092 1092
 
@@ -1105,40 +1105,40 @@  discard block
 block discarded – undo
1105 1105
  **/
1106 1106
 function spip_substr_manuelle($c, $start, $length = null) {
1107 1107
 
1108
-	// Cas pathologique
1109
-	if ($length === 0) {
1110
-		return '';
1111
-	}
1112
-
1113
-	// S'il y a un demarrage, on se positionne
1114
-	if ($start > 0) {
1115
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1116
-	} elseif ($start < 0) {
1117
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1118
-	}
1119
-
1120
-	if (!$length) {
1121
-		return $c;
1122
-	}
1123
-
1124
-	if ($length > 0) {
1125
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126
-		// (un caractere utf-8 prenant au maximum n bytes)
1127
-		$n = 0;
1128
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1129
-			;
1130
-		}
1131
-		$c = substr($c, 0, $n * $length);
1132
-		// puis, tant qu'on est trop long, on coupe...
1133
-		while (($l = spip_strlen($c)) > $length) {
1134
-			$c = substr($c, 0, $length - $l);
1135
-		}
1136
-
1137
-		return $c;
1138
-	}
1139
-
1140
-	// $length < 0
1141
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1108
+    // Cas pathologique
1109
+    if ($length === 0) {
1110
+        return '';
1111
+    }
1112
+
1113
+    // S'il y a un demarrage, on se positionne
1114
+    if ($start > 0) {
1115
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1116
+    } elseif ($start < 0) {
1117
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1118
+    }
1119
+
1120
+    if (!$length) {
1121
+        return $c;
1122
+    }
1123
+
1124
+    if ($length > 0) {
1125
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126
+        // (un caractere utf-8 prenant au maximum n bytes)
1127
+        $n = 0;
1128
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1129
+            ;
1130
+        }
1131
+        $c = substr($c, 0, $n * $length);
1132
+        // puis, tant qu'on est trop long, on coupe...
1133
+        while (($l = spip_strlen($c)) > $length) {
1134
+            $c = substr($c, 0, $length - $l);
1135
+        }
1136
+
1137
+        return $c;
1138
+    }
1139
+
1140
+    // $length < 0
1141
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1142 1142
 }
1143 1143
 
1144 1144
 /**
@@ -1152,14 +1152,14 @@  discard block
 block discarded – undo
1152 1152
  *     La chaîne avec une majuscule sur le premier mot
1153 1153
  */
1154 1154
 function spip_ucfirst($c) {
1155
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1156
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1157
-		return ucfirst($c);
1158
-	}
1155
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1156
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1157
+        return ucfirst($c);
1158
+    }
1159 1159
 
1160
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1160
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1161 1161
 
1162
-	return $lettre1 . spip_substr($c, 1);
1162
+    return $lettre1 . spip_substr($c, 1);
1163 1163
 }
1164 1164
 
1165 1165
 /**
@@ -1173,12 +1173,12 @@  discard block
 block discarded – undo
1173 1173
  *     La chaîne en minuscules
1174 1174
  */
1175 1175
 function spip_strtolower($c) {
1176
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1177
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1178
-		return strtolower($c);
1179
-	}
1176
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1177
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1178
+        return strtolower($c);
1179
+    }
1180 1180
 
1181
-	return mb_strtolower($c);
1181
+    return mb_strtolower($c);
1182 1182
 }
1183 1183
 
1184 1184
 /**
@@ -1192,23 +1192,23 @@  discard block
 block discarded – undo
1192 1192
  *     Longueur de la chaîne
1193 1193
  */
1194 1194
 function spip_strlen($c) {
1195
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1196
-	$c = str_replace("\r\n", "\n", $c);
1197
-
1198
-	// Si ce n'est pas utf-8, utiliser strlen
1199
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1200
-		return strlen($c);
1201
-	}
1202
-
1203
-	// Sinon, utiliser mb_strlen() si disponible
1204
-	if (init_mb_string()) {
1205
-		return mb_strlen($c);
1206
-	}
1207
-
1208
-	// Methode manuelle : on supprime les bytes 10......,
1209
-	// on compte donc les ascii (0.......) et les demarrages
1210
-	// de caracteres utf-8 (11......)
1211
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1195
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1196
+    $c = str_replace("\r\n", "\n", $c);
1197
+
1198
+    // Si ce n'est pas utf-8, utiliser strlen
1199
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1200
+        return strlen($c);
1201
+    }
1202
+
1203
+    // Sinon, utiliser mb_strlen() si disponible
1204
+    if (init_mb_string()) {
1205
+        return mb_strlen($c);
1206
+    }
1207
+
1208
+    // Methode manuelle : on supprime les bytes 10......,
1209
+    // on compte donc les ascii (0.......) et les demarrages
1210
+    // de caracteres utf-8 (11......)
1211
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1212 1212
 }
1213 1213
 
1214 1214
 // Initialisation
@@ -1218,14 +1218,14 @@  discard block
 block discarded – undo
1218 1218
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1219 1219
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1220 1220
 if (!isset($GLOBALS['meta']['pcre_u'])
1221
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1221
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1222 1222
 ) {
1223
-	include_spip('inc/meta');
1224
-	ecrire_meta('pcre_u',
1225
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1226
-			and test_pcre_unicode())
1227
-			? 'u' : ''
1228
-	);
1223
+    include_spip('inc/meta');
1224
+    ecrire_meta('pcre_u',
1225
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1226
+            and test_pcre_unicode())
1227
+            ? 'u' : ''
1228
+    );
1229 1229
 }
1230 1230
 
1231 1231
 
@@ -1241,17 +1241,17 @@  discard block
 block discarded – undo
1241 1241
  *     en unicode : &#128169;
1242 1242
  */
1243 1243
 function utf8_noplanes($x) {
1244
-	$regexp_utf8_4bytes = '/(
1244
+    $regexp_utf8_4bytes = '/(
1245 1245
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1246 1246
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1247 1247
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1248 1248
 )/xS';
1249
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1250
-		foreach ($z[0] as $k) {
1251
-			$ku = utf_8_to_unicode($k);
1252
-			$x = str_replace($k, $ku, $x);
1253
-		}
1254
-	}
1255
-
1256
-	return $x;
1249
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1250
+        foreach ($z[0] as $k) {
1251
+            $ku = utf_8_to_unicode($k);
1252
+            $x = str_replace($k, $ku, $x);
1253
+        }
1254
+    }
1255
+
1256
+    return $x;
1257 1257
 }
Please login to merge, or discard this patch.
ecrire/inc/cvt_autosave.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 /**
24 24
  * Nettoyer les échappements
25 25
  *
26
- * @param $val
26
+ * @param string $val
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
30
-	return stripslashes(urldecode($val));
30
+    return stripslashes(urldecode($val));
31 31
 }
32 32
 
33 33
 /**
@@ -38,42 +38,42 @@  discard block
 block discarded – undo
38 38
  * @return array
39 39
  */
40 40
 function cvtautosave_formulaire_charger($flux) {
41
-	if (is_array($flux['data'])
42
-		and isset($flux['data']['_autosave_id'])
43
-		and $cle_autosave = $flux['data']['_autosave_id']
44
-	) {
41
+    if (is_array($flux['data'])
42
+        and isset($flux['data']['_autosave_id'])
43
+        and $cle_autosave = $flux['data']['_autosave_id']
44
+    ) {
45 45
 
46
-		$form = $flux['args']['form'];
47
-		$je_suis_poste = $flux['args']['je_suis_poste'];
46
+        $form = $flux['args']['form'];
47
+        $je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49
-		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
49
+        $cle_autosave = serialize($cle_autosave);
50
+        $cle_autosave = $form . "_" . md5($cle_autosave);
51 51
 
52
-		// si on a un backup en session et qu'on est au premier chargement, non poste
53
-		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
-			and !$je_suis_poste
56
-		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
-			foreach ($vars as $key => $val) {
59
-				if (isset($flux['data'][$key])) {
60
-					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
-						$val));
62
-				}
63
-			}
64
-		}
52
+        // si on a un backup en session et qu'on est au premier chargement, non poste
53
+        // on restitue les donnees
54
+        if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
+            and !$je_suis_poste
56
+        ) {
57
+            parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
+            foreach ($vars as $key => $val) {
59
+                if (isset($flux['data'][$key])) {
60
+                    $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
+                        $val));
62
+                }
63
+            }
64
+        }
65 65
 
66
-		/**
67
-		 * Envoyer le input hidden et le bout de js qui l'utilisera
68
-		 */
69
-		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
-			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
66
+        /**
67
+         * Envoyer le input hidden et le bout de js qui l'utilisera
68
+         */
69
+        $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
+            . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71 71
 		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74
-	}
74
+    }
75 75
 
76
-	return $flux;
76
+    return $flux;
77 77
 }
78 78
 
79 79
 /**
@@ -87,33 +87,33 @@  discard block
 block discarded – undo
87 87
  * @return array
88 88
  */
89 89
 function cvtautosave_formulaire_traiter($flux) {
90
-	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
-	// on elimine les donnees de la session
92
-	if ($cle_autosave = _request('autosave')) {
93
-		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
95
-	}
90
+    // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
+    // on elimine les donnees de la session
92
+    if ($cle_autosave = _request('autosave')) {
93
+        include_spip('inc/session');
94
+        session_set('session_autosave_' . $cle_autosave, null);
95
+    }
96 96
 
97
-	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
-		// delai par defaut avant purge d'un backup de form : 72H
99
-		if (!defined('_AUTOSAVE_GB_DELAY')) {
100
-			define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
-		}
102
-		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
-		// purger aussi toutes les vieilles autosave
104
-		$session = $GLOBALS['visiteur_session'];
105
-		foreach ($session as $k => $v) {
106
-			if (strncmp($k, 'session_autosave_', 17) == 0) {
107
-				$timestamp = 0;
108
-				if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
-					$timestamp = intval($m[1]);
110
-				}
111
-				if ($timestamp < $time_too_old) {
112
-					session_set($k, null);
113
-				}
114
-			}
115
-		}
116
-	}
97
+    if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
+        // delai par defaut avant purge d'un backup de form : 72H
99
+        if (!defined('_AUTOSAVE_GB_DELAY')) {
100
+            define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
+        }
102
+        $time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
+        // purger aussi toutes les vieilles autosave
104
+        $session = $GLOBALS['visiteur_session'];
105
+        foreach ($session as $k => $v) {
106
+            if (strncmp($k, 'session_autosave_', 17) == 0) {
107
+                $timestamp = 0;
108
+                if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
+                    $timestamp = intval($m[1]);
110
+                }
111
+                if ($timestamp < $time_too_old) {
112
+                    session_set($k, null);
113
+                }
114
+            }
115
+        }
116
+    }
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 		$je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49 49
 		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
50
+		$cle_autosave = $form."_".md5($cle_autosave);
51 51
 
52 52
 		// si on a un backup en session et qu'on est au premier chargement, non poste
53 53
 		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
54
+		if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
55 55
 			and !$je_suis_poste
56 56
 		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
57
+			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
58 58
 			foreach ($vars as $key => $val) {
59 59
 				if (isset($flux['data'][$key])) {
60 60
 					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 */
69 69
 		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70 70
 			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71
-		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
71
+		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74 74
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	// on elimine les donnees de la session
92 92
 	if ($cle_autosave = _request('autosave')) {
93 93
 		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
94
+		session_set('session_autosave_'.$cle_autosave, null);
95 95
 	}
96 96
 
97 97
 	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
Please login to merge, or discard this patch.
ecrire/inc/distant.php 4 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
  *   permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG)
65 65
  * @param int $taille_max
66 66
  *   taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE
67
- * @return bool|string
67
+ * @return string|false
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible
247 247
  *
248 248
  * @param string $url_idn
249
- * @return array|string
249
+ * @return string|boolean
250 250
  */
251 251
 function url_to_ascii($url_idn) {
252 252
 
@@ -642,13 +642,13 @@  discard block
 block discarded – undo
642 642
  *
643 643
  * @param string $url
644 644
  *     URL de la page à récupérer
645
- * @param bool|null|string $trans
645
+ * @param boolean $trans
646 646
  *     - chaîne longue : c'est un nom de fichier (nom pour sa copie locale)
647 647
  *     - true : demande d'encodage/charset
648 648
  *     - null : ne retourner que les headers
649 649
  * @param string $get
650 650
  *     Type de requête HTTP à faire (HEAD, GET ou POST)
651
- * @param int|bool $taille_max
651
+ * @param integer $taille_max
652 652
  *     Arrêter le contenu au-delà (0 = seulement les entetes ==> requête HEAD).
653 653
  *     Par defaut taille_max = 1Mo.
654 654
  * @param string|array $datas
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  *
775 775
  * @param resource $handle
776 776
  * @param int|bool $if_modified_since
777
- * @return bool|array
777
+ * @return string
778 778
  *   int status
779 779
  *   string headers
780 780
  *   int last_modified
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
  *   donnees postees
1252 1252
  * @param string $vers
1253 1253
  *   version HTTP
1254
- * @param int|string $date
1254
+ * @param string $date
1255 1255
  *   timestamp pour entente If-Modified-Since
1256
- * @return bool|resource
1256
+ * @return string
1257 1257
  *   false|int si echec
1258 1258
  *   resource socket vers l'url demandee
1259 1259
  */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1256,8 +1256,9 @@
 block discarded – undo
1256 1256
 	$http_noproxy = " $http_noproxy ";
1257 1257
 	$domain = $host;
1258 1258
 	// si le domaine exact www.example.org est dans les exceptions
1259
-	if (strpos($http_noproxy, " $domain ") !== false)
1260
-		return '';
1259
+	if (strpos($http_noproxy, " $domain ") !== false) {
1260
+			return '';
1261
+	}
1261 1262
 
1262 1263
 	while (strpos($domain, '.') !== false) {
1263 1264
 		$domain = explode('.', $domain);
Please login to merge, or discard this patch.
Indentation   +1075 added lines, -1075 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,77 +68,77 @@  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
-			array('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
-		// pour une eventuelle indexation
127
-		pipeline(
128
-			'post_edition',
129
-			array(
130
-				'args' => array(
131
-					'operation' => 'copie_locale',
132
-					'source' => $source,
133
-					'fichier' => $local,
134
-					'http_res' => $res['length'],
135
-				),
136
-				'data' => null
137
-			)
138
-		);
139
-	}
140
-
141
-	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
+            array('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
+        // pour une eventuelle indexation
127
+        pipeline(
128
+            'post_edition',
129
+            array(
130
+                'args' => array(
131
+                    'operation' => 'copie_locale',
132
+                    'source' => $source,
133
+                    'fichier' => $local,
134
+                    'http_res' => $res['length'],
135
+                ),
136
+                'data' => null
137
+            )
138
+        );
139
+    }
140
+
141
+    return $local;
142 142
 }
143 143
 
144 144
 /**
@@ -153,88 +153,88 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
157
-		include_spip('inc/filtres_mini');
158
-	}
156
+    if (!function_exists('protocole_verifier')){
157
+        include_spip('inc/filtres_mini');
158
+    }
159 159
 
160
-	if (!protocole_verifier($url, array('http', 'https'))) {
161
-		return false;
162
-	}
160
+    if (!protocole_verifier($url, array('http', 'https'))) {
161
+        return false;
162
+    }
163 163
 	
164
-	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
166
-		return false;
167
-	}
168
-
169
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
-		return false;
171
-	}
172
-
173
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
-		return false;
175
-	}
176
-
177
-	if (!is_array($known_hosts)) {
178
-		$known_hosts = array($known_hosts);
179
-	}
180
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
-	$known_hosts[] = url_de_base();
182
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
-
184
-	$is_known_host = false;
185
-	foreach ($known_hosts as $known_host) {
186
-		$parse_known = parse_url($known_host);
187
-		if ($parse_known
188
-		  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
-			$is_known_host = true;
190
-			break;
191
-		}
192
-	}
193
-
194
-	if (!$is_known_host) {
195
-		$host = trim($parsed_url['host'], '.');
196
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
-			$ip = $host;
198
-		} else {
199
-			$ip = gethostbyname($host);
200
-			if ($ip === $host) {
201
-				// Error condition for gethostbyname()
202
-				$ip = false;
203
-			}
204
-		}
205
-		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
207
-			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
210
-			) {
211
-				return false;
212
-			}
213
-		}
214
-	}
215
-
216
-	if (empty($parsed_url['port'])) {
217
-		return $url;
218
-	}
219
-
220
-	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
222
-		return $url;
223
-	}
224
-
225
-	if ($is_known_host) {
226
-		foreach ($known_hosts as $known_host) {
227
-			$parse_known = parse_url($known_host);
228
-			if ($parse_known
229
-				and !empty($parse_known['port'])
230
-			  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
-			  and $parse_known['port'] == $port) {
232
-				return $url;
233
-			}
234
-		}
235
-	}
236
-
237
-	return false;
164
+    $parsed_url = parse_url($url);
165
+    if (!$parsed_url or empty($parsed_url['host']) ) {
166
+        return false;
167
+    }
168
+
169
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
+        return false;
171
+    }
172
+
173
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
+        return false;
175
+    }
176
+
177
+    if (!is_array($known_hosts)) {
178
+        $known_hosts = array($known_hosts);
179
+    }
180
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
+    $known_hosts[] = url_de_base();
182
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
+
184
+    $is_known_host = false;
185
+    foreach ($known_hosts as $known_host) {
186
+        $parse_known = parse_url($known_host);
187
+        if ($parse_known
188
+          and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
+            $is_known_host = true;
190
+            break;
191
+        }
192
+    }
193
+
194
+    if (!$is_known_host) {
195
+        $host = trim($parsed_url['host'], '.');
196
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
+            $ip = $host;
198
+        } else {
199
+            $ip = gethostbyname($host);
200
+            if ($ip === $host) {
201
+                // Error condition for gethostbyname()
202
+                $ip = false;
203
+            }
204
+        }
205
+        if ($ip) {
206
+            $parts = array_map('intval', explode( '.', $ip ));
207
+            if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
+              or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
+              or ( 192 === $parts[0] && 168 === $parts[1] )
210
+            ) {
211
+                return false;
212
+            }
213
+        }
214
+    }
215
+
216
+    if (empty($parsed_url['port'])) {
217
+        return $url;
218
+    }
219
+
220
+    $port = $parsed_url['port'];
221
+    if ($port === 80  or $port === 443  or $port === 8080) {
222
+        return $url;
223
+    }
224
+
225
+    if ($is_known_host) {
226
+        foreach ($known_hosts as $known_host) {
227
+            $parse_known = parse_url($known_host);
228
+            if ($parse_known
229
+                and !empty($parse_known['port'])
230
+              and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
+              and $parse_known['port'] == $port) {
232
+                return $url;
233
+            }
234
+        }
235
+    }
236
+
237
+    return false;
238 238
 }
239 239
 
240 240
 /**
@@ -253,86 +253,86 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function prepare_donnees_post($donnees, $boundary = '') {
255 255
 
256
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
-	// pour un appel soap par exemple
258
-	// l'entete est separe des donnees par un double retour a la ligne
259
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
-	if (is_string($donnees) && strlen($donnees)) {
261
-		$entete = '';
262
-		// on repasse tous les \r\n et \r en simples \n
263
-		$donnees = str_replace("\r\n", "\n", $donnees);
264
-		$donnees = str_replace("\r", "\n", $donnees);
265
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
-		$p = strpos($donnees, "\n\n");
267
-		if ($p !== false) {
268
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
-			$donnees = substr($donnees, $p + 2);
270
-		}
271
-		$chaine = str_replace("\n", "\r\n", $donnees);
272
-	} else {
273
-		/* boundary automatique */
274
-		// Si on a plus de 500 octects de donnees, on "boundarise"
275
-		if ($boundary === '') {
276
-			$taille = 0;
277
-			foreach ($donnees as $cle => $valeur) {
278
-				if (is_array($valeur)) {
279
-					foreach ($valeur as $val2) {
280
-						$taille += strlen($val2);
281
-					}
282
-				} else {
283
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
284
-					$taille += strlen($valeur);
285
-				}
286
-			}
287
-			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
289
-			}
290
-		}
291
-
292
-		if (is_string($boundary) and strlen($boundary)) {
293
-			// fabrique une chaine HTTP pour un POST avec boundary
294
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
-			$chaine = '';
296
-			if (is_array($donnees)) {
297
-				foreach ($donnees as $cle => $valeur) {
298
-					if (is_array($valeur)) {
299
-						foreach ($valeur as $val2) {
300
-							$chaine .= "\r\n--$boundary\r\n";
301
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
-							$chaine .= "\r\n";
303
-							$chaine .= $val2;
304
-						}
305
-					} else {
306
-						$chaine .= "\r\n--$boundary\r\n";
307
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
-						$chaine .= "\r\n";
309
-						$chaine .= $valeur;
310
-					}
311
-				}
312
-				$chaine .= "\r\n--$boundary\r\n";
313
-			}
314
-		} else {
315
-			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
-			$chaine = array();
318
-			if (is_array($donnees)) {
319
-				foreach ($donnees as $cle => $valeur) {
320
-					if (is_array($valeur)) {
321
-						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
-						}
324
-					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
-					}
327
-				}
328
-				$chaine = implode('&', $chaine);
329
-			} else {
330
-				$chaine = $donnees;
331
-			}
332
-		}
333
-	}
334
-
335
-	return array($entete, $chaine);
256
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
+    // pour un appel soap par exemple
258
+    // l'entete est separe des donnees par un double retour a la ligne
259
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
+    if (is_string($donnees) && strlen($donnees)) {
261
+        $entete = '';
262
+        // on repasse tous les \r\n et \r en simples \n
263
+        $donnees = str_replace("\r\n", "\n", $donnees);
264
+        $donnees = str_replace("\r", "\n", $donnees);
265
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
+        $p = strpos($donnees, "\n\n");
267
+        if ($p !== false) {
268
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
+            $donnees = substr($donnees, $p + 2);
270
+        }
271
+        $chaine = str_replace("\n", "\r\n", $donnees);
272
+    } else {
273
+        /* boundary automatique */
274
+        // Si on a plus de 500 octects de donnees, on "boundarise"
275
+        if ($boundary === '') {
276
+            $taille = 0;
277
+            foreach ($donnees as $cle => $valeur) {
278
+                if (is_array($valeur)) {
279
+                    foreach ($valeur as $val2) {
280
+                        $taille += strlen($val2);
281
+                    }
282
+                } else {
283
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
284
+                    $taille += strlen($valeur);
285
+                }
286
+            }
287
+            if ($taille > 500) {
288
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
289
+            }
290
+        }
291
+
292
+        if (is_string($boundary) and strlen($boundary)) {
293
+            // fabrique une chaine HTTP pour un POST avec boundary
294
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
+            $chaine = '';
296
+            if (is_array($donnees)) {
297
+                foreach ($donnees as $cle => $valeur) {
298
+                    if (is_array($valeur)) {
299
+                        foreach ($valeur as $val2) {
300
+                            $chaine .= "\r\n--$boundary\r\n";
301
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
+                            $chaine .= "\r\n";
303
+                            $chaine .= $val2;
304
+                        }
305
+                    } else {
306
+                        $chaine .= "\r\n--$boundary\r\n";
307
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
+                        $chaine .= "\r\n";
309
+                        $chaine .= $valeur;
310
+                    }
311
+                }
312
+                $chaine .= "\r\n--$boundary\r\n";
313
+            }
314
+        } else {
315
+            // fabrique une chaine HTTP simple pour un POST
316
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
+            $chaine = array();
318
+            if (is_array($donnees)) {
319
+                foreach ($donnees as $cle => $valeur) {
320
+                    if (is_array($valeur)) {
321
+                        foreach ($valeur as $val2) {
322
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
+                        }
324
+                    } else {
325
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
+                    }
327
+                }
328
+                $chaine = implode('&', $chaine);
329
+            } else {
330
+                $chaine = $donnees;
331
+            }
332
+        }
333
+    }
334
+
335
+    return array($entete, $chaine);
336 336
 }
337 337
 
338 338
 /**
@@ -346,18 +346,18 @@  discard block
 block discarded – undo
346 346
  */
347 347
 function url_to_ascii($url_idn) {
348 348
 
349
-	if ($parts = parse_url($url_idn)) {
350
-		$host = $parts['host'];
351
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
-			include_spip('inc/idna_convert.class');
353
-			$IDN = new idna_convert();
354
-			$host_ascii = $IDN->encode($host);
355
-			$url_idn = explode($host, $url_idn, 2);
356
-			$url_idn = implode($host_ascii, $url_idn);
357
-		}
358
-	}
359
-
360
-	return $url_idn;
349
+    if ($parts = parse_url($url_idn)) {
350
+        $host = $parts['host'];
351
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
+            include_spip('inc/idna_convert.class');
353
+            $IDN = new idna_convert();
354
+            $host_ascii = $IDN->encode($host);
355
+            $url_idn = explode($host, $url_idn, 2);
356
+            $url_idn = implode($host_ascii, $url_idn);
357
+        }
358
+    }
359
+
360
+    return $url_idn;
361 361
 }
362 362
 
363 363
 /**
@@ -396,176 +396,176 @@  discard block
 block discarded – undo
396 396
  *     string file : nom du fichier si enregistre dans un fichier
397 397
  */
398 398
 function recuperer_url($url, $options = array()) {
399
-	$default = array(
400
-		'transcoder' => false,
401
-		'methode' => 'GET',
402
-		'taille_max' => null,
403
-		'datas' => '',
404
-		'boundary' => '',
405
-		'refuser_gz' => false,
406
-		'if_modified_since' => '',
407
-		'uri_referer' => '',
408
-		'file' => '',
409
-		'follow_location' => 10,
410
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
411
-	);
412
-	$options = array_merge($default, $options);
413
-	// copier directement dans un fichier ?
414
-	$copy = $options['file'];
415
-
416
-	if ($options['methode'] == 'HEAD') {
417
-		$options['taille_max'] = 0;
418
-	}
419
-	if (is_null($options['taille_max'])) {
420
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
-	}
422
-
423
-	if (!empty($options['datas'])) {
424
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
-		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
427
-		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
429
-		if (strlen($postdata)) {
430
-			$options['methode'] = 'POST';
431
-		}
432
-	}
433
-
434
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
-	$url = preg_replace(',^feed://,i', 'http://', $url);
436
-	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
438
-	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
440
-	}
441
-
442
-	$url = url_to_ascii($url);
443
-
444
-	$result = array(
445
-		'status' => 0,
446
-		'headers' => '',
447
-		'page' => '',
448
-		'length' => 0,
449
-		'last_modified' => '',
450
-		'location' => '',
451
-		'url' => $url
452
-	);
453
-
454
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
-
457
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
458
-	list($handle, $fopen) = init_http(
459
-		$options['methode'],
460
-		$url,
461
-		$refuser_gz,
462
-		$options['uri_referer'],
463
-		$options['datas'],
464
-		$options['version_http'],
465
-		$options['if_modified_since']
466
-	);
467
-	if (!$handle) {
468
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
469
-
470
-		return false;
471
-	}
472
-
473
-	// Sauf en fopen, envoyer le flux d'entree
474
-	// et recuperer les en-tetes de reponses
475
-	if (!$fopen) {
476
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
-		if (!$res) {
478
-			fclose($handle);
479
-			$t = @parse_url($url);
480
-			$host = $t['host'];
481
-			// Chinoisierie inexplicable pour contrer
482
-			// les actions liberticides de l'empire du milieu
483
-			if (!need_proxy($host)
484
-				and $res = @file_get_contents($url)
485
-			) {
486
-				$result['length'] = strlen($res);
487
-				if ($copy) {
488
-					ecrire_fichier($copy, $res);
489
-					$result['file'] = $copy;
490
-				} else {
491
-					$result['page'] = $res;
492
-				}
493
-				$res = array(
494
-					'status' => 200,
495
-				);
496
-			} else {
497
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
498
-				return false;
499
-			}
500
-		} elseif ($res['location'] and $options['follow_location']) {
501
-			$options['follow_location']--;
502
-			fclose($handle);
503
-			include_spip('inc/filtres');
504
-			$url = suivre_lien($url, $res['location']);
505
-			spip_log("recuperer_url recommence sur $url", 'distant');
506
-
507
-			return recuperer_url($url, $options);
508
-		} elseif ($res['status'] !== 200) {
509
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
510
-		}
511
-		$result['status'] = $res['status'];
512
-		if (isset($res['headers'])) {
513
-			$result['headers'] = $res['headers'];
514
-		}
515
-		if (isset($res['last_modified'])) {
516
-			$result['last_modified'] = $res['last_modified'];
517
-		}
518
-		if (isset($res['location'])) {
519
-			$result['location'] = $res['location'];
520
-		}
521
-	}
522
-
523
-	// on ne veut que les entetes
524
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
525
-		return $result;
526
-	}
527
-
528
-
529
-	// s'il faut deballer, le faire via un fichier temporaire
530
-	// sinon la memoire explose pour les gros flux
531
-
532
-	$gz = false;
533
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
534
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
535
-	}
536
-
537
-	// si on a pas deja recuperer le contenu par une methode detournee
538
-	if (!$result['length']) {
539
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
540
-		fclose($handle);
541
-		if ($copy) {
542
-			$result['length'] = $res;
543
-			$result['file'] = $copy;
544
-		} elseif ($res) {
545
-			$result['page'] = &$res;
546
-			$result['length'] = strlen($result['page']);
547
-		}
548
-		if (!$result['status']) {
549
-			$result['status'] = 200; // on a reussi, donc !
550
-		}
551
-	}
552
-	if (!$result['page']) {
553
-		return $result;
554
-	}
555
-
556
-	// Decompresser au besoin
557
-	if ($gz) {
558
-		$result['page'] = implode('', gzfile($gz));
559
-		supprimer_fichier($gz);
560
-	}
561
-
562
-	// Faut-il l'importer dans notre charset local ?
563
-	if ($options['transcoder']) {
564
-		include_spip('inc/charsets');
565
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
566
-	}
567
-
568
-	return $result;
399
+    $default = array(
400
+        'transcoder' => false,
401
+        'methode' => 'GET',
402
+        'taille_max' => null,
403
+        'datas' => '',
404
+        'boundary' => '',
405
+        'refuser_gz' => false,
406
+        'if_modified_since' => '',
407
+        'uri_referer' => '',
408
+        'file' => '',
409
+        'follow_location' => 10,
410
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
411
+    );
412
+    $options = array_merge($default, $options);
413
+    // copier directement dans un fichier ?
414
+    $copy = $options['file'];
415
+
416
+    if ($options['methode'] == 'HEAD') {
417
+        $options['taille_max'] = 0;
418
+    }
419
+    if (is_null($options['taille_max'])) {
420
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
+    }
422
+
423
+    if (!empty($options['datas'])) {
424
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
+        if (stripos($head, 'Content-Length:') === false) {
426
+            $head .= 'Content-Length: ' . strlen($postdata);
427
+        }
428
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
429
+        if (strlen($postdata)) {
430
+            $options['methode'] = 'POST';
431
+        }
432
+    }
433
+
434
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
+    $url = preg_replace(',^feed://,i', 'http://', $url);
436
+    if (!tester_url_absolue($url)) {
437
+        $url = 'http://' . $url;
438
+    } elseif (strncmp($url, '//', 2) == 0) {
439
+        $url = 'http:' . $url;
440
+    }
441
+
442
+    $url = url_to_ascii($url);
443
+
444
+    $result = array(
445
+        'status' => 0,
446
+        'headers' => '',
447
+        'page' => '',
448
+        'length' => 0,
449
+        'last_modified' => '',
450
+        'location' => '',
451
+        'url' => $url
452
+    );
453
+
454
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
+
457
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
458
+    list($handle, $fopen) = init_http(
459
+        $options['methode'],
460
+        $url,
461
+        $refuser_gz,
462
+        $options['uri_referer'],
463
+        $options['datas'],
464
+        $options['version_http'],
465
+        $options['if_modified_since']
466
+    );
467
+    if (!$handle) {
468
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
469
+
470
+        return false;
471
+    }
472
+
473
+    // Sauf en fopen, envoyer le flux d'entree
474
+    // et recuperer les en-tetes de reponses
475
+    if (!$fopen) {
476
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
+        if (!$res) {
478
+            fclose($handle);
479
+            $t = @parse_url($url);
480
+            $host = $t['host'];
481
+            // Chinoisierie inexplicable pour contrer
482
+            // les actions liberticides de l'empire du milieu
483
+            if (!need_proxy($host)
484
+                and $res = @file_get_contents($url)
485
+            ) {
486
+                $result['length'] = strlen($res);
487
+                if ($copy) {
488
+                    ecrire_fichier($copy, $res);
489
+                    $result['file'] = $copy;
490
+                } else {
491
+                    $result['page'] = $res;
492
+                }
493
+                $res = array(
494
+                    'status' => 200,
495
+                );
496
+            } else {
497
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
498
+                return false;
499
+            }
500
+        } elseif ($res['location'] and $options['follow_location']) {
501
+            $options['follow_location']--;
502
+            fclose($handle);
503
+            include_spip('inc/filtres');
504
+            $url = suivre_lien($url, $res['location']);
505
+            spip_log("recuperer_url recommence sur $url", 'distant');
506
+
507
+            return recuperer_url($url, $options);
508
+        } elseif ($res['status'] !== 200) {
509
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
510
+        }
511
+        $result['status'] = $res['status'];
512
+        if (isset($res['headers'])) {
513
+            $result['headers'] = $res['headers'];
514
+        }
515
+        if (isset($res['last_modified'])) {
516
+            $result['last_modified'] = $res['last_modified'];
517
+        }
518
+        if (isset($res['location'])) {
519
+            $result['location'] = $res['location'];
520
+        }
521
+    }
522
+
523
+    // on ne veut que les entetes
524
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
525
+        return $result;
526
+    }
527
+
528
+
529
+    // s'il faut deballer, le faire via un fichier temporaire
530
+    // sinon la memoire explose pour les gros flux
531
+
532
+    $gz = false;
533
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
534
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
535
+    }
536
+
537
+    // si on a pas deja recuperer le contenu par une methode detournee
538
+    if (!$result['length']) {
539
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
540
+        fclose($handle);
541
+        if ($copy) {
542
+            $result['length'] = $res;
543
+            $result['file'] = $copy;
544
+        } elseif ($res) {
545
+            $result['page'] = &$res;
546
+            $result['length'] = strlen($result['page']);
547
+        }
548
+        if (!$result['status']) {
549
+            $result['status'] = 200; // on a reussi, donc !
550
+        }
551
+    }
552
+    if (!$result['page']) {
553
+        return $result;
554
+    }
555
+
556
+    // Decompresser au besoin
557
+    if ($gz) {
558
+        $result['page'] = implode('', gzfile($gz));
559
+        supprimer_fichier($gz);
560
+    }
561
+
562
+    // Faut-il l'importer dans notre charset local ?
563
+    if ($options['transcoder']) {
564
+        include_spip('inc/charsets');
565
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
566
+    }
567
+
568
+    return $result;
569 569
 }
570 570
 
571 571
 /**
@@ -581,72 +581,72 @@  discard block
 block discarded – undo
581 581
  * @return array|bool|mixed
582 582
  */
583 583
 function recuperer_url_cache($url, $options = array()) {
584
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
585
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
586
-	}
587
-	$default = array(
588
-		'transcoder' => false,
589
-		'methode' => 'GET',
590
-		'taille_max' => null,
591
-		'datas' => '',
592
-		'boundary' => '',
593
-		'refuser_gz' => false,
594
-		'if_modified_since' => '',
595
-		'uri_referer' => '',
596
-		'file' => '',
597
-		'follow_location' => 10,
598
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
599
-		'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
600
-	);
601
-	$options = array_merge($default, $options);
602
-
603
-	// cas ou il n'est pas possible de cacher
604
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
605
-		return recuperer_url($url, $options);
606
-	}
607
-
608
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
609
-	static $errors = array();
610
-	if (isset($errors[$url])) {
611
-		return $errors[$url];
612
-	}
613
-
614
-	$sig = $options;
615
-	unset($sig['if_modified_since']);
616
-	unset($sig['delai_cache']);
617
-	$sig['url'] = $url;
618
-
619
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
620
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
621
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
622
-	$cache = "$sub$cache";
623
-
624
-	$res = false;
625
-	$is_cached = file_exists($cache);
626
-	if ($is_cached
627
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
628
-	) {
629
-		lire_fichier($cache, $res);
630
-		if ($res = unserialize($res)) {
631
-			// mettre le last_modified et le status=304 ?
632
-		}
633
-	}
634
-	if (!$res) {
635
-		$res = recuperer_url($url, $options);
636
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
637
-		if (!$res) {
638
-			if ($is_cached) {
639
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
640
-				lire_fichier($cache, $res);
641
-				$res = unserialize($res);
642
-			}
643
-
644
-			return $errors[$url] = $res;
645
-		}
646
-		ecrire_fichier($cache, serialize($res));
647
-	}
648
-
649
-	return $res;
584
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
585
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
586
+    }
587
+    $default = array(
588
+        'transcoder' => false,
589
+        'methode' => 'GET',
590
+        'taille_max' => null,
591
+        'datas' => '',
592
+        'boundary' => '',
593
+        'refuser_gz' => false,
594
+        'if_modified_since' => '',
595
+        'uri_referer' => '',
596
+        'file' => '',
597
+        'follow_location' => 10,
598
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
599
+        'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
600
+    );
601
+    $options = array_merge($default, $options);
602
+
603
+    // cas ou il n'est pas possible de cacher
604
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
605
+        return recuperer_url($url, $options);
606
+    }
607
+
608
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
609
+    static $errors = array();
610
+    if (isset($errors[$url])) {
611
+        return $errors[$url];
612
+    }
613
+
614
+    $sig = $options;
615
+    unset($sig['if_modified_since']);
616
+    unset($sig['delai_cache']);
617
+    $sig['url'] = $url;
618
+
619
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
620
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
621
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
622
+    $cache = "$sub$cache";
623
+
624
+    $res = false;
625
+    $is_cached = file_exists($cache);
626
+    if ($is_cached
627
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
628
+    ) {
629
+        lire_fichier($cache, $res);
630
+        if ($res = unserialize($res)) {
631
+            // mettre le last_modified et le status=304 ?
632
+        }
633
+    }
634
+    if (!$res) {
635
+        $res = recuperer_url($url, $options);
636
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
637
+        if (!$res) {
638
+            if ($is_cached) {
639
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
640
+                lire_fichier($cache, $res);
641
+                $res = unserialize($res);
642
+            }
643
+
644
+            return $errors[$url] = $res;
645
+        }
646
+        ecrire_fichier($cache, serialize($res));
647
+    }
648
+
649
+    return $res;
650 650
 }
651 651
 
652 652
 /**
@@ -684,52 +684,52 @@  discard block
 block discarded – undo
684 684
  *     - false si la page n'a pu être récupérée (status different de 200)
685 685
  **/
686 686
 function recuperer_page(
687
-	$url,
688
-	$trans = false,
689
-	$get_headers = false,
690
-	$taille_max = null,
691
-	$datas = '',
692
-	$boundary = '',
693
-	$refuser_gz = false,
694
-	$date_verif = '',
695
-	$uri_referer = ''
687
+    $url,
688
+    $trans = false,
689
+    $get_headers = false,
690
+    $taille_max = null,
691
+    $datas = '',
692
+    $boundary = '',
693
+    $refuser_gz = false,
694
+    $date_verif = '',
695
+    $uri_referer = ''
696 696
 ) {
697
-	// $copy = copier le fichier ?
698
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
699
-
700
-	if (!is_null($taille_max) and ($taille_max == 0)) {
701
-		$get = 'HEAD';
702
-	} else {
703
-		$get = 'GET';
704
-	}
705
-
706
-	$options = array(
707
-		'transcoder' => $trans === true,
708
-		'methode' => $get,
709
-		'datas' => $datas,
710
-		'boundary' => $boundary,
711
-		'refuser_gz' => $refuser_gz,
712
-		'if_modified_since' => $date_verif,
713
-		'uri_referer' => $uri_referer,
714
-		'file' => $copy ? $trans : '',
715
-		'follow_location' => 10,
716
-	);
717
-	if (!is_null($taille_max)) {
718
-		$options['taille_max'] = $taille_max;
719
-	}
720
-	// dix tentatives maximum en cas d'entetes 301...
721
-	$res = recuperer_url($url, $options);
722
-	if (!$res) {
723
-		return false;
724
-	}
725
-	if ($res['status'] !== 200) {
726
-		return false;
727
-	}
728
-	if ($get_headers) {
729
-		return $res['headers'] . "\n" . $res['page'];
730
-	}
731
-
732
-	return $res['page'];
697
+    // $copy = copier le fichier ?
698
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
699
+
700
+    if (!is_null($taille_max) and ($taille_max == 0)) {
701
+        $get = 'HEAD';
702
+    } else {
703
+        $get = 'GET';
704
+    }
705
+
706
+    $options = array(
707
+        'transcoder' => $trans === true,
708
+        'methode' => $get,
709
+        'datas' => $datas,
710
+        'boundary' => $boundary,
711
+        'refuser_gz' => $refuser_gz,
712
+        'if_modified_since' => $date_verif,
713
+        'uri_referer' => $uri_referer,
714
+        'file' => $copy ? $trans : '',
715
+        'follow_location' => 10,
716
+    );
717
+    if (!is_null($taille_max)) {
718
+        $options['taille_max'] = $taille_max;
719
+    }
720
+    // dix tentatives maximum en cas d'entetes 301...
721
+    $res = recuperer_url($url, $options);
722
+    if (!$res) {
723
+        return false;
724
+    }
725
+    if ($res['status'] !== 200) {
726
+        return false;
727
+    }
728
+    if ($get_headers) {
729
+        return $res['headers'] . "\n" . $res['page'];
730
+    }
731
+
732
+    return $res['page'];
733 733
 }
734 734
 
735 735
 
@@ -766,48 +766,48 @@  discard block
 block discarded – undo
766 766
  *     - false sinon
767 767
  **/
768 768
 function recuperer_lapage(
769
-	$url,
770
-	$trans = false,
771
-	$get = 'GET',
772
-	$taille_max = 1048576,
773
-	$datas = '',
774
-	$refuser_gz = false,
775
-	$date_verif = '',
776
-	$uri_referer = ''
769
+    $url,
770
+    $trans = false,
771
+    $get = 'GET',
772
+    $taille_max = 1048576,
773
+    $datas = '',
774
+    $refuser_gz = false,
775
+    $date_verif = '',
776
+    $uri_referer = ''
777 777
 ) {
778
-	// $copy = copier le fichier ?
779
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
780
-
781
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
782
-	// en memoire refuser gz
783
-	if ($copy) {
784
-		$refuser_gz = true;
785
-	}
786
-
787
-	$options = array(
788
-		'transcoder' => $trans === true,
789
-		'methode' => $get,
790
-		'datas' => $datas,
791
-		'refuser_gz' => $refuser_gz,
792
-		'if_modified_since' => $date_verif,
793
-		'uri_referer' => $uri_referer,
794
-		'file' => $copy ? $trans : '',
795
-		'follow_location' => false,
796
-	);
797
-	if (!is_null($taille_max)) {
798
-		$options['taille_max'] = $taille_max;
799
-	}
800
-	// dix tentatives maximum en cas d'entetes 301...
801
-	$res = recuperer_url($url, $options);
802
-
803
-	if (!$res) {
804
-		return false;
805
-	}
806
-	if ($res['status'] !== 200) {
807
-		return false;
808
-	}
809
-
810
-	return array($res['headers'], $res['page']);
778
+    // $copy = copier le fichier ?
779
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
780
+
781
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
782
+    // en memoire refuser gz
783
+    if ($copy) {
784
+        $refuser_gz = true;
785
+    }
786
+
787
+    $options = array(
788
+        'transcoder' => $trans === true,
789
+        'methode' => $get,
790
+        'datas' => $datas,
791
+        'refuser_gz' => $refuser_gz,
792
+        'if_modified_since' => $date_verif,
793
+        'uri_referer' => $uri_referer,
794
+        'file' => $copy ? $trans : '',
795
+        'follow_location' => false,
796
+    );
797
+    if (!is_null($taille_max)) {
798
+        $options['taille_max'] = $taille_max;
799
+    }
800
+    // dix tentatives maximum en cas d'entetes 301...
801
+    $res = recuperer_url($url, $options);
802
+
803
+    if (!$res) {
804
+        return false;
805
+    }
806
+    if ($res['status'] !== 200) {
807
+        return false;
808
+    }
809
+
810
+    return array($res['headers'], $res['page']);
811 811
 }
812 812
 
813 813
 /**
@@ -825,41 +825,41 @@  discard block
 block discarded – undo
825 825
  *   string contenu de la resource
826 826
  */
827 827
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
828
-	$taille = 0;
829
-	$result = '';
830
-	$fp = false;
831
-	if ($fichier) {
832
-		include_spip('inc/acces');
833
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
834
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
835
-		if (!$fp and file_exists($fichier)) {
836
-			return filesize($fichier);
837
-		}
838
-		if (!$fp) {
839
-			return false;
840
-		}
841
-		$result = 0; // on renvoie la taille du fichier
842
-	}
843
-	while (!feof($handle) and $taille < $taille_max) {
844
-		$res = fread($handle, 16384);
845
-		$taille += strlen($res);
846
-		if ($fp) {
847
-			fwrite($fp, $res);
848
-			$result = $taille;
849
-		} else {
850
-			$result .= $res;
851
-		}
852
-	}
853
-	if ($fp) {
854
-		spip_fclose_unlock($fp);
855
-		spip_unlink($fichier);
856
-		@rename($tmpfile, $fichier);
857
-		if (!file_exists($fichier)) {
858
-			return false;
859
-		}
860
-	}
861
-
862
-	return $result;
828
+    $taille = 0;
829
+    $result = '';
830
+    $fp = false;
831
+    if ($fichier) {
832
+        include_spip('inc/acces');
833
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
834
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
835
+        if (!$fp and file_exists($fichier)) {
836
+            return filesize($fichier);
837
+        }
838
+        if (!$fp) {
839
+            return false;
840
+        }
841
+        $result = 0; // on renvoie la taille du fichier
842
+    }
843
+    while (!feof($handle) and $taille < $taille_max) {
844
+        $res = fread($handle, 16384);
845
+        $taille += strlen($res);
846
+        if ($fp) {
847
+            fwrite($fp, $res);
848
+            $result = $taille;
849
+        } else {
850
+            $result .= $res;
851
+        }
852
+    }
853
+    if ($fp) {
854
+        spip_fclose_unlock($fp);
855
+        spip_unlink($fichier);
856
+        @rename($tmpfile, $fichier);
857
+        if (!file_exists($fichier)) {
858
+            return false;
859
+        }
860
+    }
861
+
862
+    return $result;
863 863
 }
864 864
 
865 865
 /**
@@ -881,34 +881,34 @@  discard block
 block discarded – undo
881 881
  *   string location
882 882
  */
883 883
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
884
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
885
-
886
-	$s = @trim(fgets($handle, 16384));
887
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
888
-		return false;
889
-	}
890
-	$result['status'] = intval($r[1]);
891
-	while ($s = trim(fgets($handle, 16384))) {
892
-		$result['headers'][] = $s . "\n";
893
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
894
-		list(, $d, $v) = $r;
895
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
896
-			$result['location'] = $v;
897
-		} elseif ($d == 'Last-Modified') {
898
-			$result['last_modified'] = strtotime($v);
899
-		}
900
-	}
901
-	if ($if_modified_since
902
-		and $result['last_modified']
903
-		and $if_modified_since > $result['last_modified']
904
-		and $result['status'] == 200
905
-	) {
906
-		$result['status'] = 304;
907
-	}
908
-
909
-	$result['headers'] = implode('', $result['headers']);
910
-
911
-	return $result;
884
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
885
+
886
+    $s = @trim(fgets($handle, 16384));
887
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
888
+        return false;
889
+    }
890
+    $result['status'] = intval($r[1]);
891
+    while ($s = trim(fgets($handle, 16384))) {
892
+        $result['headers'][] = $s . "\n";
893
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
894
+        list(, $d, $v) = $r;
895
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
896
+            $result['location'] = $v;
897
+        } elseif ($d == 'Last-Modified') {
898
+            $result['last_modified'] = strtotime($v);
899
+        }
900
+    }
901
+    if ($if_modified_since
902
+        and $result['last_modified']
903
+        and $if_modified_since > $result['last_modified']
904
+        and $result['status'] == 200
905
+    ) {
906
+        $result['status'] = 304;
907
+    }
908
+
909
+    $result['headers'] = implode('', $result['headers']);
910
+
911
+    return $result;
912 912
 }
913 913
 
914 914
 /**
@@ -930,20 +930,20 @@  discard block
 block discarded – undo
930 930
  *     - le tableau des entetes dans tous les autres cas
931 931
  **/
932 932
 function recuperer_entetes($f, $date_verif = '') {
933
-	//Cas ou la page distante n'a pas bouge depuis
934
-	//la derniere visite
935
-	$res = recuperer_entetes_complets($f, $date_verif);
936
-	if (!$res) {
937
-		return false;
938
-	}
939
-	if ($res['location']) {
940
-		return $res['location'];
941
-	}
942
-	if ($res['status'] != 200) {
943
-		return $res['status'];
944
-	}
945
-
946
-	return explode("\n", $res['headers']);
933
+    //Cas ou la page distante n'a pas bouge depuis
934
+    //la derniere visite
935
+    $res = recuperer_entetes_complets($f, $date_verif);
936
+    if (!$res) {
937
+        return false;
938
+    }
939
+    if ($res['location']) {
940
+        return $res['location'];
941
+    }
942
+    if ($res['status'] != 200) {
943
+        return $res['status'];
944
+    }
945
+
946
+    return explode("\n", $res['headers']);
947 947
 }
948 948
 
949 949
 /**
@@ -965,22 +965,22 @@  discard block
 block discarded – undo
965 965
  *     Nom du fichier pour copie locale
966 966
  **/
967 967
 function nom_fichier_copie_locale($source, $extension) {
968
-	include_spip('inc/documents');
968
+    include_spip('inc/documents');
969 969
 
970
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
971
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
970
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
971
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
972 972
 
973
-	// on se place tout le temps comme si on etait a la racine
974
-	if (_DIR_RACINE) {
975
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
976
-	}
973
+    // on se place tout le temps comme si on etait a la racine
974
+    if (_DIR_RACINE) {
975
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
976
+    }
977 977
 
978
-	$m = md5($source);
978
+    $m = md5($source);
979 979
 
980
-	return $d
981
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
982
-	. substr($m, 0, 4)
983
-	. ".$extension";
980
+    return $d
981
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
982
+    . substr($m, 0, 4)
983
+    . ".$extension";
984 984
 }
985 985
 
986 986
 /**
@@ -998,68 +998,68 @@  discard block
 block discarded – undo
998 998
  *      Nom du fichier calculé
999 999
  **/
1000 1000
 function fichier_copie_locale($source) {
1001
-	// Si c'est deja local pas de souci
1002
-	if (!tester_url_absolue($source)) {
1003
-		if (_DIR_RACINE) {
1004
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1005
-		}
1006
-
1007
-		return $source;
1008
-	}
1009
-
1010
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1011
-	// a deja ete copie en local avec cette extension
1012
-	// dans ce cas elle est fiable, pas la peine de requeter en base
1013
-	$path_parts = pathinfo($source);
1014
-	if (!isset($path_parts['extension'])) {
1015
-		$path_parts['extension'] = '';
1016
-	}
1017
-	$ext = $path_parts ? $path_parts['extension'] : '';
1018
-	if ($ext
1019
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1020
-		and $f = nom_fichier_copie_locale($source, $ext)
1021
-		and file_exists(_DIR_RACINE . $f)
1022
-	) {
1023
-		return $f;
1024
-	}
1025
-
1026
-
1027
-	// Si c'est deja dans la table des documents,
1028
-	// ramener le nom de sa copie potentielle
1029
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1030
-
1031
-	if ($ext) {
1032
-		return nom_fichier_copie_locale($source, $ext);
1033
-	}
1034
-
1035
-	// voir si l'extension indiquee dans le nom du fichier est ok
1036
-	// et si il n'aurait pas deja ete rapatrie
1037
-
1038
-	$ext = $path_parts ? $path_parts['extension'] : '';
1039
-
1040
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1041
-		$f = nom_fichier_copie_locale($source, $ext);
1042
-		if (file_exists(_DIR_RACINE . $f)) {
1043
-			return $f;
1044
-		}
1045
-	}
1046
-
1047
-	// Ping  pour voir si son extension est connue et autorisee
1048
-	// avec mise en cache du resultat du ping
1049
-
1050
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1051
-	if (!@file_exists($cache)
1052
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1053
-		or _request('var_mode') == 'recalcul'
1054
-	) {
1055
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1056
-		ecrire_fichier($cache, serialize($path_parts));
1057
-	}
1058
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1059
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1060
-		return nom_fichier_copie_locale($source, $ext);
1061
-	}
1062
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1001
+    // Si c'est deja local pas de souci
1002
+    if (!tester_url_absolue($source)) {
1003
+        if (_DIR_RACINE) {
1004
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1005
+        }
1006
+
1007
+        return $source;
1008
+    }
1009
+
1010
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1011
+    // a deja ete copie en local avec cette extension
1012
+    // dans ce cas elle est fiable, pas la peine de requeter en base
1013
+    $path_parts = pathinfo($source);
1014
+    if (!isset($path_parts['extension'])) {
1015
+        $path_parts['extension'] = '';
1016
+    }
1017
+    $ext = $path_parts ? $path_parts['extension'] : '';
1018
+    if ($ext
1019
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1020
+        and $f = nom_fichier_copie_locale($source, $ext)
1021
+        and file_exists(_DIR_RACINE . $f)
1022
+    ) {
1023
+        return $f;
1024
+    }
1025
+
1026
+
1027
+    // Si c'est deja dans la table des documents,
1028
+    // ramener le nom de sa copie potentielle
1029
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1030
+
1031
+    if ($ext) {
1032
+        return nom_fichier_copie_locale($source, $ext);
1033
+    }
1034
+
1035
+    // voir si l'extension indiquee dans le nom du fichier est ok
1036
+    // et si il n'aurait pas deja ete rapatrie
1037
+
1038
+    $ext = $path_parts ? $path_parts['extension'] : '';
1039
+
1040
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1041
+        $f = nom_fichier_copie_locale($source, $ext);
1042
+        if (file_exists(_DIR_RACINE . $f)) {
1043
+            return $f;
1044
+        }
1045
+    }
1046
+
1047
+    // Ping  pour voir si son extension est connue et autorisee
1048
+    // avec mise en cache du resultat du ping
1049
+
1050
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1051
+    if (!@file_exists($cache)
1052
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1053
+        or _request('var_mode') == 'recalcul'
1054
+    ) {
1055
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1056
+        ecrire_fichier($cache, serialize($path_parts));
1057
+    }
1058
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1059
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1060
+        return nom_fichier_copie_locale($source, $ext);
1061
+    }
1062
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1063 1063
 }
1064 1064
 
1065 1065
 
@@ -1087,144 +1087,144 @@  discard block
 block discarded – undo
1087 1087
  **/
1088 1088
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1089 1089
 
1090
-	// pas la peine de perdre son temps
1091
-	if (!tester_url_absolue($source)) {
1092
-		return false;
1093
-	}
1094
-
1095
-	# charger les alias des types mime
1096
-	include_spip('base/typedoc');
1097
-
1098
-	$a = array();
1099
-	$mime_type = '';
1100
-	// On va directement charger le debut des images et des fichiers html,
1101
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1102
-	// ca echoue l'utilisateur devra les entrer...
1103
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1104
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1105
-
1106
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1107
-			$mime_type = (trim($regs[1]));
1108
-		} else {
1109
-			$mime_type = '';
1110
-		} // inconnu
1111
-
1112
-		// Appliquer les alias
1113
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1114
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1115
-		}
1116
-
1117
-		// Si on a un mime-type insignifiant
1118
-		// text/plain,application/octet-stream ou vide
1119
-		// c'est peut-etre que le serveur ne sait pas
1120
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1121
-		// ou le Content-Disposition: attachment; filename=...
1122
-		$t = null;
1123
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1124
-			if (!$t
1125
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1126
-			) {
1127
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1128
-			}
1129
-			if (!$t
1130
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1131
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1132
-			) {
1133
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1134
-			}
1135
-		}
1136
-
1137
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1138
-		if (!$t) {
1139
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1140
-		}
1141
-
1142
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1143
-		// On essaie de nouveau avec l'extension
1144
-		if (!$t
1145
-			and $mime_type != 'text/plain'
1146
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1147
-		) {
1148
-			# eviter xxx.3 => 3gp (> SPIP 3)
1149
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1150
-		}
1151
-
1152
-		if ($t) {
1153
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1154
-			$a['extension'] = $t['extension'];
1155
-		} else {
1156
-			# par defaut on retombe sur '.bin' si c'est autorise
1157
-			spip_log("mime-type $mime_type inconnu", 'distant');
1158
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1159
-			if (!$t) {
1160
-				return false;
1161
-			}
1162
-			$a['extension'] = $t['extension'];
1163
-		}
1164
-
1165
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1166
-			$a['taille'] = intval($regs[1]);
1167
-		}
1168
-	}
1169
-
1170
-	// Echec avec HEAD, on tente avec GET
1171
-	if (!$a and !$max) {
1172
-		spip_log("tenter GET $source", 'distant');
1173
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1174
-	}
1175
-
1176
-	// si on a rien trouve pas la peine d'insister
1177
-	if (!$a) {
1178
-		return false;
1179
-	}
1180
-
1181
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1182
-	// recharger le document en GET et recuperer des donnees supplementaires...
1183
-	include_spip('inc/filtres_images_lib_mini');
1184
-	if (strpos($mime_type, "image/") === 0
1185
-	  and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1186
-		if ($max == 0
1187
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1188
-			and in_array($extension, formats_image_acceptables())
1189
-			and $charger_si_petite_image
1190
-		) {
1191
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1192
-		} else {
1193
-			if ($a['body']) {
1194
-				$a['extension'] = $extension;
1195
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1196
-				ecrire_fichier($a['fichier'], $a['body']);
1197
-				$size_image = @spip_getimagesize($a['fichier']);
1198
-				$a['largeur'] = intval($size_image[0]);
1199
-				$a['hauteur'] = intval($size_image[1]);
1200
-				$a['type_image'] = true;
1201
-			}
1202
-		}
1203
-	}
1204
-
1205
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1206
-	// ce sera mieux que 0x0
1207
-	// Flash is dead!
1208
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1209
-		and empty($a['largeur'])
1210
-	) {
1211
-		$a['largeur'] = 425;
1212
-		$a['hauteur'] = 350;
1213
-	}
1214
-
1215
-	if ($mime_type == 'text/html') {
1216
-		include_spip('inc/filtres');
1217
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1218
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1219
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1220
-		}
1221
-		if (!isset($a['taille']) or !$a['taille']) {
1222
-			$a['taille'] = strlen($page); # a peu pres
1223
-		}
1224
-	}
1225
-	$a['mime_type'] = $mime_type;
1226
-
1227
-	return $a;
1090
+    // pas la peine de perdre son temps
1091
+    if (!tester_url_absolue($source)) {
1092
+        return false;
1093
+    }
1094
+
1095
+    # charger les alias des types mime
1096
+    include_spip('base/typedoc');
1097
+
1098
+    $a = array();
1099
+    $mime_type = '';
1100
+    // On va directement charger le debut des images et des fichiers html,
1101
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1102
+    // ca echoue l'utilisateur devra les entrer...
1103
+    if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1104
+        list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1105
+
1106
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1107
+            $mime_type = (trim($regs[1]));
1108
+        } else {
1109
+            $mime_type = '';
1110
+        } // inconnu
1111
+
1112
+        // Appliquer les alias
1113
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1114
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1115
+        }
1116
+
1117
+        // Si on a un mime-type insignifiant
1118
+        // text/plain,application/octet-stream ou vide
1119
+        // c'est peut-etre que le serveur ne sait pas
1120
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1121
+        // ou le Content-Disposition: attachment; filename=...
1122
+        $t = null;
1123
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1124
+            if (!$t
1125
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1126
+            ) {
1127
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1128
+            }
1129
+            if (!$t
1130
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1131
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1132
+            ) {
1133
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1134
+            }
1135
+        }
1136
+
1137
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1138
+        if (!$t) {
1139
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1140
+        }
1141
+
1142
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1143
+        // On essaie de nouveau avec l'extension
1144
+        if (!$t
1145
+            and $mime_type != 'text/plain'
1146
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1147
+        ) {
1148
+            # eviter xxx.3 => 3gp (> SPIP 3)
1149
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1150
+        }
1151
+
1152
+        if ($t) {
1153
+            spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1154
+            $a['extension'] = $t['extension'];
1155
+        } else {
1156
+            # par defaut on retombe sur '.bin' si c'est autorise
1157
+            spip_log("mime-type $mime_type inconnu", 'distant');
1158
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1159
+            if (!$t) {
1160
+                return false;
1161
+            }
1162
+            $a['extension'] = $t['extension'];
1163
+        }
1164
+
1165
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1166
+            $a['taille'] = intval($regs[1]);
1167
+        }
1168
+    }
1169
+
1170
+    // Echec avec HEAD, on tente avec GET
1171
+    if (!$a and !$max) {
1172
+        spip_log("tenter GET $source", 'distant');
1173
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1174
+    }
1175
+
1176
+    // si on a rien trouve pas la peine d'insister
1177
+    if (!$a) {
1178
+        return false;
1179
+    }
1180
+
1181
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1182
+    // recharger le document en GET et recuperer des donnees supplementaires...
1183
+    include_spip('inc/filtres_images_lib_mini');
1184
+    if (strpos($mime_type, "image/") === 0
1185
+      and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1186
+        if ($max == 0
1187
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1188
+            and in_array($extension, formats_image_acceptables())
1189
+            and $charger_si_petite_image
1190
+        ) {
1191
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1192
+        } else {
1193
+            if ($a['body']) {
1194
+                $a['extension'] = $extension;
1195
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1196
+                ecrire_fichier($a['fichier'], $a['body']);
1197
+                $size_image = @spip_getimagesize($a['fichier']);
1198
+                $a['largeur'] = intval($size_image[0]);
1199
+                $a['hauteur'] = intval($size_image[1]);
1200
+                $a['type_image'] = true;
1201
+            }
1202
+        }
1203
+    }
1204
+
1205
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1206
+    // ce sera mieux que 0x0
1207
+    // Flash is dead!
1208
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1209
+        and empty($a['largeur'])
1210
+    ) {
1211
+        $a['largeur'] = 425;
1212
+        $a['hauteur'] = 350;
1213
+    }
1214
+
1215
+    if ($mime_type == 'text/html') {
1216
+        include_spip('inc/filtres');
1217
+        $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1218
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1219
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1220
+        }
1221
+        if (!isset($a['taille']) or !$a['taille']) {
1222
+            $a['taille'] = strlen($page); # a peu pres
1223
+        }
1224
+    }
1225
+    $a['mime_type'] = $mime_type;
1226
+
1227
+    return $a;
1228 1228
 }
1229 1229
 
1230 1230
 
@@ -1240,45 +1240,45 @@  discard block
 block discarded – undo
1240 1240
  * @return string
1241 1241
  */
1242 1242
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1243
-	if (is_null($http_proxy)) {
1244
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1245
-	}
1246
-	// rien a faire si pas de proxy :)
1247
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1248
-		return '';
1249
-	}
1250
-
1251
-	if (is_null($http_noproxy)) {
1252
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1253
-	}
1254
-	// si pas d'exception, on retourne le proxy
1255
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1256
-		return $http_proxy;
1257
-	}
1258
-
1259
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1260
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1261
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1262
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1263
-	$http_noproxy = " $http_noproxy ";
1264
-	$domain = $host;
1265
-	// si le domaine exact www.example.org est dans les exceptions
1266
-	if (strpos($http_noproxy, " $domain ") !== false)
1267
-		return '';
1268
-
1269
-	while (strpos($domain, '.') !== false) {
1270
-		$domain = explode('.', $domain);
1271
-		array_shift($domain);
1272
-		$domain = implode('.', $domain);
1273
-
1274
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1275
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1276
-			return '';
1277
-		}
1278
-	}
1279
-
1280
-	// ok c'est pas une exception
1281
-	return $http_proxy;
1243
+    if (is_null($http_proxy)) {
1244
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1245
+    }
1246
+    // rien a faire si pas de proxy :)
1247
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1248
+        return '';
1249
+    }
1250
+
1251
+    if (is_null($http_noproxy)) {
1252
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1253
+    }
1254
+    // si pas d'exception, on retourne le proxy
1255
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1256
+        return $http_proxy;
1257
+    }
1258
+
1259
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1260
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1261
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1262
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1263
+    $http_noproxy = " $http_noproxy ";
1264
+    $domain = $host;
1265
+    // si le domaine exact www.example.org est dans les exceptions
1266
+    if (strpos($http_noproxy, " $domain ") !== false)
1267
+        return '';
1268
+
1269
+    while (strpos($domain, '.') !== false) {
1270
+        $domain = explode('.', $domain);
1271
+        array_shift($domain);
1272
+        $domain = implode('.', $domain);
1273
+
1274
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1275
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1276
+            return '';
1277
+        }
1278
+    }
1279
+
1280
+    // ok c'est pas une exception
1281
+    return $http_proxy;
1282 1282
 }
1283 1283
 
1284 1284
 
@@ -1301,58 +1301,58 @@  discard block
 block discarded – undo
1301 1301
  * @return array
1302 1302
  */
1303 1303
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1304
-	$user = $via_proxy = $proxy_user = '';
1305
-	$fopen = false;
1306
-
1307
-	$t = @parse_url($url);
1308
-	$host = $t['host'];
1309
-	if ($t['scheme'] == 'http') {
1310
-		$scheme = 'http';
1311
-		$noproxy = '';
1312
-	} elseif ($t['scheme'] == 'https') {
1313
-		$scheme = 'ssl';
1314
-		$noproxy = 'ssl://';
1315
-		if (!isset($t['port']) || !($port = $t['port'])) {
1316
-			$t['port'] = 443;
1317
-		}
1318
-	} else {
1319
-		$scheme = $t['scheme'];
1320
-		$noproxy = $scheme . '://';
1321
-	}
1322
-	if (isset($t['user'])) {
1323
-		$user = array($t['user'], $t['pass']);
1324
-	}
1325
-
1326
-	if (!isset($t['port']) || !($port = $t['port'])) {
1327
-		$port = 80;
1328
-	}
1329
-	if (!isset($t['path']) || !($path = $t['path'])) {
1330
-		$path = '/';
1331
-	}
1332
-
1333
-	if (!empty($t['query'])) {
1334
-		$path .= '?' . $t['query'];
1335
-	}
1336
-
1337
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1338
-	if (!$f or !is_resource($f)) {
1339
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1340
-		// ce qui correspond a $f===110
1341
-		if ($f !== 110
1342
-			and !need_proxy($host)
1343
-			and !_request('tester_proxy')
1344
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1345
-		) {
1346
-			$f = @fopen($url, 'rb');
1347
-			spip_log("connexion vers $url par simple fopen", 'distant');
1348
-			$fopen = true;
1349
-		} else {
1350
-			// echec total
1351
-			$f = false;
1352
-		}
1353
-	}
1354
-
1355
-	return array($f, $fopen);
1304
+    $user = $via_proxy = $proxy_user = '';
1305
+    $fopen = false;
1306
+
1307
+    $t = @parse_url($url);
1308
+    $host = $t['host'];
1309
+    if ($t['scheme'] == 'http') {
1310
+        $scheme = 'http';
1311
+        $noproxy = '';
1312
+    } elseif ($t['scheme'] == 'https') {
1313
+        $scheme = 'ssl';
1314
+        $noproxy = 'ssl://';
1315
+        if (!isset($t['port']) || !($port = $t['port'])) {
1316
+            $t['port'] = 443;
1317
+        }
1318
+    } else {
1319
+        $scheme = $t['scheme'];
1320
+        $noproxy = $scheme . '://';
1321
+    }
1322
+    if (isset($t['user'])) {
1323
+        $user = array($t['user'], $t['pass']);
1324
+    }
1325
+
1326
+    if (!isset($t['port']) || !($port = $t['port'])) {
1327
+        $port = 80;
1328
+    }
1329
+    if (!isset($t['path']) || !($path = $t['path'])) {
1330
+        $path = '/';
1331
+    }
1332
+
1333
+    if (!empty($t['query'])) {
1334
+        $path .= '?' . $t['query'];
1335
+    }
1336
+
1337
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1338
+    if (!$f or !is_resource($f)) {
1339
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1340
+        // ce qui correspond a $f===110
1341
+        if ($f !== 110
1342
+            and !need_proxy($host)
1343
+            and !_request('tester_proxy')
1344
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1345
+        ) {
1346
+            $f = @fopen($url, 'rb');
1347
+            spip_log("connexion vers $url par simple fopen", 'distant');
1348
+            $fopen = true;
1349
+        } else {
1350
+            // echec total
1351
+            $f = false;
1352
+        }
1353
+    }
1354
+
1355
+    return array($f, $fopen);
1356 1356
 }
1357 1357
 
1358 1358
 /**
@@ -1387,127 +1387,127 @@  discard block
 block discarded – undo
1387 1387
  *   resource socket vers l'url demandee
1388 1388
  */
1389 1389
 function lance_requete(
1390
-	$method,
1391
-	$scheme,
1392
-	$user,
1393
-	$host,
1394
-	$path,
1395
-	$port,
1396
-	$noproxy,
1397
-	$refuse_gz = false,
1398
-	$referer = '',
1399
-	$datas = '',
1400
-	$vers = 'HTTP/1.0',
1401
-	$date = ''
1390
+    $method,
1391
+    $scheme,
1392
+    $user,
1393
+    $host,
1394
+    $path,
1395
+    $port,
1396
+    $noproxy,
1397
+    $refuse_gz = false,
1398
+    $referer = '',
1399
+    $datas = '',
1400
+    $vers = 'HTTP/1.0',
1401
+    $date = ''
1402 1402
 ) {
1403 1403
 
1404
-	$proxy_user = '';
1405
-	$http_proxy = need_proxy($host);
1406
-	if ($user) {
1407
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1408
-	}
1409
-
1410
-	$connect = '';
1411
-	if ($http_proxy) {
1412
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1413
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1414
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1415
-				. "Host: $path_host\r\n"
1416
-				. "Proxy-Connection: Keep-Alive\r\n";
1417
-		} else {
1418
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1419
-				. (!$user ? '' : "$user@")
1420
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1421
-		}
1422
-		$t2 = @parse_url($http_proxy);
1423
-		$first_host = $t2['host'];
1424
-		if (!($port = $t2['port'])) {
1425
-			$port = 80;
1426
-		}
1427
-		if ($t2['user']) {
1428
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1429
-		}
1430
-	} else {
1431
-		$first_host = $noproxy . $host;
1432
-	}
1433
-
1434
-	if ($connect) {
1435
-		$streamContext = stream_context_create(array(
1436
-			'ssl' => array(
1437
-				'verify_peer' => false,
1438
-				'allow_self_signed' => true,
1439
-				'SNI_enabled' => true,
1440
-				'peer_name' => $host,
1441
-			)
1442
-		));
1443
-		if (version_compare(phpversion(), '5.6', '<')) {
1444
-			stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1445
-		}
1446
-		$f = @stream_socket_client(
1447
-			"tcp://$first_host:$port",
1448
-			$errno,
1449
-			$errstr,
1450
-			_INC_DISTANT_CONNECT_TIMEOUT,
1451
-			STREAM_CLIENT_CONNECT,
1452
-			$streamContext
1453
-		);
1454
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1455
-		if (!$f) {
1456
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1457
-			return $errno;
1458
-		}
1459
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1460
-
1461
-		fputs($f, $connect);
1462
-		fputs($f, "\r\n");
1463
-		$res = fread($f, 1024);
1464
-		if (!$res
1465
-			or !count($res = explode(' ', $res))
1466
-			or $res[1] !== '200'
1467
-		) {
1468
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1469
-			fclose($f);
1470
-
1471
-			return false;
1472
-		}
1473
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1474
-		stream_set_blocking($f, true);
1475
-		// envoyer le handshake
1476
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1477
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1478
-	} else {
1479
-		$ntry = 3;
1480
-		do {
1481
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1482
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1483
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1484
-		if (!$f) {
1485
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1486
-
1487
-			return $errno;
1488
-		}
1489
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1490
-	}
1491
-
1492
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1493
-
1494
-	$host_port = $host;
1495
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1496
-		$host_port .= ":$port";
1497
-	}
1498
-	$req = "$method $path $vers\r\n"
1499
-		. "Host: $host_port\r\n"
1500
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1501
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1502
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1503
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1504
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1505
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1506
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1404
+    $proxy_user = '';
1405
+    $http_proxy = need_proxy($host);
1406
+    if ($user) {
1407
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1408
+    }
1409
+
1410
+    $connect = '';
1411
+    if ($http_proxy) {
1412
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1413
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1414
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1415
+                . "Host: $path_host\r\n"
1416
+                . "Proxy-Connection: Keep-Alive\r\n";
1417
+        } else {
1418
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1419
+                . (!$user ? '' : "$user@")
1420
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1421
+        }
1422
+        $t2 = @parse_url($http_proxy);
1423
+        $first_host = $t2['host'];
1424
+        if (!($port = $t2['port'])) {
1425
+            $port = 80;
1426
+        }
1427
+        if ($t2['user']) {
1428
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1429
+        }
1430
+    } else {
1431
+        $first_host = $noproxy . $host;
1432
+    }
1433
+
1434
+    if ($connect) {
1435
+        $streamContext = stream_context_create(array(
1436
+            'ssl' => array(
1437
+                'verify_peer' => false,
1438
+                'allow_self_signed' => true,
1439
+                'SNI_enabled' => true,
1440
+                'peer_name' => $host,
1441
+            )
1442
+        ));
1443
+        if (version_compare(phpversion(), '5.6', '<')) {
1444
+            stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1445
+        }
1446
+        $f = @stream_socket_client(
1447
+            "tcp://$first_host:$port",
1448
+            $errno,
1449
+            $errstr,
1450
+            _INC_DISTANT_CONNECT_TIMEOUT,
1451
+            STREAM_CLIENT_CONNECT,
1452
+            $streamContext
1453
+        );
1454
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1455
+        if (!$f) {
1456
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1457
+            return $errno;
1458
+        }
1459
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1460
+
1461
+        fputs($f, $connect);
1462
+        fputs($f, "\r\n");
1463
+        $res = fread($f, 1024);
1464
+        if (!$res
1465
+            or !count($res = explode(' ', $res))
1466
+            or $res[1] !== '200'
1467
+        ) {
1468
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1469
+            fclose($f);
1470
+
1471
+            return false;
1472
+        }
1473
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1474
+        stream_set_blocking($f, true);
1475
+        // envoyer le handshake
1476
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1477
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1478
+    } else {
1479
+        $ntry = 3;
1480
+        do {
1481
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1482
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1483
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1484
+        if (!$f) {
1485
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1486
+
1487
+            return $errno;
1488
+        }
1489
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1490
+    }
1491
+
1492
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1493
+
1494
+    $host_port = $host;
1495
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1496
+        $host_port .= ":$port";
1497
+    }
1498
+    $req = "$method $path $vers\r\n"
1499
+        . "Host: $host_port\r\n"
1500
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1501
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1502
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1503
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1504
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1505
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1506
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1507 1507
 
1508 1508
 #	spip_log("Requete\n$req", 'distant');
1509
-	fputs($f, $req);
1510
-	fputs($f, $datas ? $datas : "\r\n");
1509
+    fputs($f, $req);
1510
+    fputs($f, $datas ? $datas : "\r\n");
1511 1511
 
1512
-	return $f;
1512
+    return $f;
1513 1513
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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
 			array('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
 		// pour une eventuelle indexation
127 127
 		pipeline(
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
156
+	if (!function_exists('protocole_verifier')) {
157 157
 		include_spip('inc/filtres_mini');
158 158
 	}
159 159
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 	
164 164
 	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
165
+	if (!$parsed_url or empty($parsed_url['host'])) {
166 166
 		return false;
167 167
 	}
168 168
 
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 			}
204 204
 		}
205 205
 		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
206
+			$parts = array_map('intval', explode('.', $ip));
207 207
 			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
208
+			  or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1])
209
+			  or (192 === $parts[0] && 168 === $parts[1])
210 210
 			) {
211 211
 				return false;
212 212
 			}
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
221
+	if ($port === 80 or $port === 443 or $port === 8080) {
222 222
 		return $url;
223 223
 	}
224 224
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				}
286 286
 			}
287 287
 			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
288
+				$boundary = substr(md5(rand().'spip'), 0, 8);
289 289
 			}
290 290
 		}
291 291
 
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 			}
314 314
 		} else {
315 315
 			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
316
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
317 317
 			$chaine = array();
318 318
 			if (is_array($donnees)) {
319 319
 				foreach ($donnees as $cle => $valeur) {
320 320
 					if (is_array($valeur)) {
321 321
 						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
322
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
323 323
 						}
324 324
 					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
325
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
326 326
 					}
327 327
 				}
328 328
 				$chaine = implode('&', $chaine);
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	if (!empty($options['datas'])) {
424 424
 		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425 425
 		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
426
+			$head .= 'Content-Length: '.strlen($postdata);
427 427
 		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
428
+		$options['datas'] = $head."\r\n\r\n".$postdata;
429 429
 		if (strlen($postdata)) {
430 430
 			$options['methode'] = 'POST';
431 431
 		}
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435 435
 	$url = preg_replace(',^feed://,i', 'http://', $url);
436 436
 	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
437
+		$url = 'http://'.$url;
438 438
 	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
439
+		$url = 'http:'.$url;
440 440
 	}
441 441
 
442 442
 	$url = url_to_ascii($url);
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		$options['if_modified_since']
466 466
 	);
467 467
 	if (!$handle) {
468
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
468
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
469 469
 
470 470
 		return false;
471 471
 	}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 					'status' => 200,
495 495
 				);
496 496
 			} else {
497
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
497
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
498 498
 				return false;
499 499
 			}
500 500
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 
507 507
 			return recuperer_url($url, $options);
508 508
 		} elseif ($res['status'] !== 200) {
509
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
509
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
510 510
 		}
511 511
 		$result['status'] = $res['status'];
512 512
 		if (isset($res['headers'])) {
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 	$gz = false;
533 533
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
534
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
535 535
 	}
536 536
 
537 537
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 	$sig['url'] = $url;
618 618
 
619 619
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
620
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
621 621
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
622 622
 	$cache = "$sub$cache";
623 623
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		return false;
727 727
 	}
728 728
 	if ($get_headers) {
729
-		return $res['headers'] . "\n" . $res['page'];
729
+		return $res['headers']."\n".$res['page'];
730 730
 	}
731 731
 
732 732
 	return $res['page'];
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 	$fp = false;
831 831
 	if ($fichier) {
832 832
 		include_spip('inc/acces');
833
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
834 834
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
835 835
 		if (!$fp and file_exists($fichier)) {
836 836
 			return filesize($fichier);
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 	}
890 890
 	$result['status'] = intval($r[1]);
891 891
 	while ($s = trim(fgets($handle, 16384))) {
892
-		$result['headers'][] = $s . "\n";
892
+		$result['headers'][] = $s."\n";
893 893
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
894 894
 		list(, $d, $v) = $r;
895 895
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -972,13 +972,13 @@  discard block
 block discarded – undo
972 972
 
973 973
 	// on se place tout le temps comme si on etait a la racine
974 974
 	if (_DIR_RACINE) {
975
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
976 976
 	}
977 977
 
978 978
 	$m = md5($source);
979 979
 
980 980
 	return $d
981
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
982 982
 	. substr($m, 0, 4)
983 983
 	. ".$extension";
984 984
 }
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 	// Si c'est deja local pas de souci
1002 1002
 	if (!tester_url_absolue($source)) {
1003 1003
 		if (_DIR_RACINE) {
1004
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
1005 1005
 		}
1006 1006
 
1007 1007
 		return $source;
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 	if ($ext
1019 1019
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1020 1020
 		and $f = nom_fichier_copie_locale($source, $ext)
1021
-		and file_exists(_DIR_RACINE . $f)
1021
+		and file_exists(_DIR_RACINE.$f)
1022 1022
 	) {
1023 1023
 		return $f;
1024 1024
 	}
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 
1027 1027
 	// Si c'est deja dans la table des documents,
1028 1028
 	// ramener le nom de sa copie potentielle
1029
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
1030 1030
 
1031 1031
 	if ($ext) {
1032 1032
 		return nom_fichier_copie_locale($source, $ext);
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
 
1038 1038
 	$ext = $path_parts ? $path_parts['extension'] : '';
1039 1039
 
1040
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1041 1041
 		$f = nom_fichier_copie_locale($source, $ext);
1042
-		if (file_exists(_DIR_RACINE . $f)) {
1042
+		if (file_exists(_DIR_RACINE.$f)) {
1043 1043
 			return $f;
1044 1044
 		}
1045 1045
 	}
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 	// Ping  pour voir si son extension est connue et autorisee
1048 1048
 	// avec mise en cache du resultat du ping
1049 1049
 
1050
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
1051 1051
 	if (!@file_exists($cache)
1052 1052
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1053 1053
 		or _request('var_mode') == 'recalcul'
@@ -1056,10 +1056,10 @@  discard block
 block discarded – undo
1056 1056
 		ecrire_fichier($cache, serialize($path_parts));
1057 1057
 	}
1058 1058
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1059
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1060 1060
 		return nom_fichier_copie_locale($source, $ext);
1061 1061
 	}
1062
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1062
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
1063 1063
 }
1064 1064
 
1065 1065
 
@@ -1124,19 +1124,19 @@  discard block
 block discarded – undo
1124 1124
 			if (!$t
1125 1125
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1126 1126
 			) {
1127
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1128 1128
 			}
1129 1129
 			if (!$t
1130 1130
 				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1131 1131
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1132 1132
 			) {
1133
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1134 1134
 			}
1135 1135
 		}
1136 1136
 
1137 1137
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1138 1138
 		if (!$t) {
1139
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
+			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1140 1140
 		}
1141 1141
 
1142 1142
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1146,11 +1146,11 @@  discard block
 block discarded – undo
1146 1146
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1147 1147
 		) {
1148 1148
 			# eviter xxx.3 => 3gp (> SPIP 3)
1149
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1150 1150
 		}
1151 1151
 
1152 1152
 		if ($t) {
1153
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1153
+			spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1154 1154
 			$a['extension'] = $t['extension'];
1155 1155
 		} else {
1156 1156
 			# par defaut on retombe sur '.bin' si c'est autorise
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
 		} else {
1193 1193
 			if ($a['body']) {
1194 1194
 				$a['extension'] = $extension;
1195
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1195
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1196 1196
 				ecrire_fichier($a['fichier'], $a['body']);
1197 1197
 				$size_image = @spip_getimagesize($a['fichier']);
1198 1198
 				$a['largeur'] = intval($size_image[0]);
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
 		}
1318 1318
 	} else {
1319 1319
 		$scheme = $t['scheme'];
1320
-		$noproxy = $scheme . '://';
1320
+		$noproxy = $scheme.'://';
1321 1321
 	}
1322 1322
 	if (isset($t['user'])) {
1323 1323
 		$user = array($t['user'], $t['pass']);
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 	}
1332 1332
 
1333 1333
 	if (!empty($t['query'])) {
1334
-		$path .= '?' . $t['query'];
1334
+		$path .= '?'.$t['query'];
1335 1335
 	}
1336 1336
 
1337 1337
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1404,20 +1404,20 @@  discard block
 block discarded – undo
1404 1404
 	$proxy_user = '';
1405 1405
 	$http_proxy = need_proxy($host);
1406 1406
 	if ($user) {
1407
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1407
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1408 1408
 	}
1409 1409
 
1410 1410
 	$connect = '';
1411 1411
 	if ($http_proxy) {
1412
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1413
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1414
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1412
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) {
1413
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1414
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1415 1415
 				. "Host: $path_host\r\n"
1416 1416
 				. "Proxy-Connection: Keep-Alive\r\n";
1417 1417
 		} else {
1418
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1418
+			$path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://")
1419 1419
 				. (!$user ? '' : "$user@")
1420
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1420
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1421 1421
 		}
1422 1422
 		$t2 = @parse_url($http_proxy);
1423 1423
 		$first_host = $t2['host'];
@@ -1425,10 +1425,10 @@  discard block
 block discarded – undo
1425 1425
 			$port = 80;
1426 1426
 		}
1427 1427
 		if ($t2['user']) {
1428
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1428
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1429 1429
 		}
1430 1430
 	} else {
1431
-		$first_host = $noproxy . $host;
1431
+		$first_host = $noproxy.$host;
1432 1432
 	}
1433 1433
 
1434 1434
 	if ($connect) {
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 		);
1454 1454
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1455 1455
 		if (!$f) {
1456
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1456
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1457 1457
 			return $errno;
1458 1458
 		}
1459 1459
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 			or !count($res = explode(' ', $res))
1466 1466
 			or $res[1] !== '200'
1467 1467
 		) {
1468
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1468
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1469 1469
 			fclose($f);
1470 1470
 
1471 1471
 			return false;
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1483 1483
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1484 1484
 		if (!$f) {
1485
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1485
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1486 1486
 
1487 1487
 			return $errno;
1488 1488
 		}
@@ -1492,16 +1492,16 @@  discard block
 block discarded – undo
1492 1492
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1493 1493
 
1494 1494
 	$host_port = $host;
1495
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1495
+	if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) {
1496 1496
 		$host_port .= ":$port";
1497 1497
 	}
1498 1498
 	$req = "$method $path $vers\r\n"
1499 1499
 		. "Host: $host_port\r\n"
1500
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1501
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1500
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1501
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1502 1502
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1503
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1504
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1503
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1504
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1505 1505
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1506 1506
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1507 1507
 
Please login to merge, or discard this patch.
ecrire/inc/editer.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
  * utile pour les textes > 32ko
315 315
  *
316 316
  * @param  string $texte
317
- * @return array
317
+ * @return string[]
318 318
  */
319 319
 function coupe_trop_long($texte) {
320 320
 	$aider = charger_fonction('aider', 'inc');
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
  *
348 348
  * @param string $texte
349 349
  * @param string $att_text
350
- * @return array
350
+ * @return string[]
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353 353
 	if ((strlen($texte) < 29 * 1024)
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 /**
374 374
  * auto-renseigner le titre si il n'existe pas
375 375
  *
376
- * @param $champ_titre
377
- * @param $champs_contenu
376
+ * @param string $champ_titre
377
+ * @param string[] $champs_contenu
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
Please login to merge, or discard this patch.
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = array(),
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = array(),
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = array();
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = array();
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) {
135
-	$erreurs = array();
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = array();
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -198,115 +198,115 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = array(),
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = array(),
208
+    $hidden = ''
209 209
 ) {
210
-	$table_objet = table_objet($type);
211
-	$table_objet_sql = table_objet_sql($type);
212
-	$id_table_objet = id_table_objet($type);
213
-	$new = !is_numeric($id);
214
-	// Appel direct dans un squelette
215
-	if (!$row) {
216
-		if (!$new or $lier_trad) {
217
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
218
-				$row = $select($id, $id_parent, $lier_trad);
219
-			} else {
220
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
221
-			}
222
-			if (!$new) {
223
-				$md5 = controles_md5($row);
224
-			}
225
-		}
226
-		if (!$row) {
227
-			$row = array();
228
-			$trouver_table = charger_fonction('trouver_table', 'base');
229
-			if ($desc = $trouver_table($table_objet)) {
230
-				foreach ($desc['field'] as $k => $v) {
231
-					$row[$k] = '';
232
-				}
233
-			}
234
-		}
235
-	}
236
-
237
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
238
-	// (et donc: pas de lien de traduction)
239
-	$id = ($new or $lier_trad)
240
-		? 'oui'
241
-		: $row[$id_table_objet];
242
-	$row[$id_table_objet] = $id;
243
-
244
-	$contexte = $row;
245
-	if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
246
-		if (!isset($contexte['id_parent'])) {
247
-			unset($contexte['id_rubrique']);
248
-		}
249
-		$contexte['id_parent'] = $id_parent;
250
-	} elseif (!isset($contexte['id_parent'])) {
251
-		// id_rubrique dans id_parent si possible
252
-		if (isset($contexte['id_rubrique'])) {
253
-			$contexte['id_parent'] = $contexte['id_rubrique'];
254
-			unset($contexte['id_rubrique']);
255
-		} else {
256
-			$contexte['id_parent'] = '';
257
-		}
258
-		if (!$contexte['id_parent']
259
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
260
-		) {
261
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
262
-		}
263
-	}
264
-
265
-	$config = array();
266
-	if ($config_fonc) {
267
-		$contexte['config'] = $config = $config_fonc($contexte);
268
-	}
269
-	$config = $config + array(
270
-		'lignes' => 0,
271
-		'langue' => '',
272
-	);
273
-
274
-	$att_text = " class='textarea' "
275
-		. " rows='"
276
-		. ($config['lignes'] + 15)
277
-		. "' cols='40'";
278
-	if (isset($contexte['texte'])) {
279
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
280
-	}
281
-
282
-	// on veut conserver la langue de l'interface ;
283
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
284
-	// voudrait l'exploiter
285
-	if (isset($contexte['lang'])) {
286
-		$contexte['langue'] = $contexte['lang'];
287
-		unset($contexte['lang']);
288
-	}
289
-
290
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
-		(!$lier_trad ? '' :
292
-			("\n<input type='hidden' name='lier_trad' value='" .
293
-				$lier_trad .
294
-				"' />" .
295
-				"\n<input type='hidden' name='changer_lang' value='" .
296
-				$config['langue'] .
297
-				"' />"))
298
-		. $hidden
299
-		. (isset($md5) ? $md5 : '');
300
-
301
-	// preciser que le formulaire doit passer dans un pipeline
302
-	$contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
303
-
304
-	// preciser que le formulaire doit etre securise auteur/action
305
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
306
-	// on le garde pour compat
307
-	$contexte['_action'] = array("editer_$type", $id);
308
-
309
-	return $contexte;
210
+    $table_objet = table_objet($type);
211
+    $table_objet_sql = table_objet_sql($type);
212
+    $id_table_objet = id_table_objet($type);
213
+    $new = !is_numeric($id);
214
+    // Appel direct dans un squelette
215
+    if (!$row) {
216
+        if (!$new or $lier_trad) {
217
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
218
+                $row = $select($id, $id_parent, $lier_trad);
219
+            } else {
220
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
221
+            }
222
+            if (!$new) {
223
+                $md5 = controles_md5($row);
224
+            }
225
+        }
226
+        if (!$row) {
227
+            $row = array();
228
+            $trouver_table = charger_fonction('trouver_table', 'base');
229
+            if ($desc = $trouver_table($table_objet)) {
230
+                foreach ($desc['field'] as $k => $v) {
231
+                    $row[$k] = '';
232
+                }
233
+            }
234
+        }
235
+    }
236
+
237
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
238
+    // (et donc: pas de lien de traduction)
239
+    $id = ($new or $lier_trad)
240
+        ? 'oui'
241
+        : $row[$id_table_objet];
242
+    $row[$id_table_objet] = $id;
243
+
244
+    $contexte = $row;
245
+    if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
246
+        if (!isset($contexte['id_parent'])) {
247
+            unset($contexte['id_rubrique']);
248
+        }
249
+        $contexte['id_parent'] = $id_parent;
250
+    } elseif (!isset($contexte['id_parent'])) {
251
+        // id_rubrique dans id_parent si possible
252
+        if (isset($contexte['id_rubrique'])) {
253
+            $contexte['id_parent'] = $contexte['id_rubrique'];
254
+            unset($contexte['id_rubrique']);
255
+        } else {
256
+            $contexte['id_parent'] = '';
257
+        }
258
+        if (!$contexte['id_parent']
259
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
260
+        ) {
261
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
262
+        }
263
+    }
264
+
265
+    $config = array();
266
+    if ($config_fonc) {
267
+        $contexte['config'] = $config = $config_fonc($contexte);
268
+    }
269
+    $config = $config + array(
270
+        'lignes' => 0,
271
+        'langue' => '',
272
+    );
273
+
274
+    $att_text = " class='textarea' "
275
+        . " rows='"
276
+        . ($config['lignes'] + 15)
277
+        . "' cols='40'";
278
+    if (isset($contexte['texte'])) {
279
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
280
+    }
281
+
282
+    // on veut conserver la langue de l'interface ;
283
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
284
+    // voudrait l'exploiter
285
+    if (isset($contexte['lang'])) {
286
+        $contexte['langue'] = $contexte['lang'];
287
+        unset($contexte['lang']);
288
+    }
289
+
290
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
+        (!$lier_trad ? '' :
292
+            ("\n<input type='hidden' name='lier_trad' value='" .
293
+                $lier_trad .
294
+                "' />" .
295
+                "\n<input type='hidden' name='changer_lang' value='" .
296
+                $config['langue'] .
297
+                "' />"))
298
+        . $hidden
299
+        . (isset($md5) ? $md5 : '');
300
+
301
+    // preciser que le formulaire doit passer dans un pipeline
302
+    $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
303
+
304
+    // preciser que le formulaire doit etre securise auteur/action
305
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
306
+    // on le garde pour compat
307
+    $contexte['_action'] = array("editer_$type", $id);
308
+
309
+    return $contexte;
310 310
 }
311 311
 
312 312
 /**
@@ -317,29 +317,29 @@  discard block
 block discarded – undo
317 317
  * @return array
318 318
  */
319 319
 function coupe_trop_long($texte) {
320
-	$aider = charger_fonction('aider', 'inc');
321
-	if (strlen($texte) > 28 * 1024) {
322
-		$texte = str_replace("\r\n", "\n", $texte);
323
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
324
-		if ($pos > 0 and $pos < 32 * 1024) {
325
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
326
-			$suite = substr($texte, $pos + 2);
327
-		} else {
328
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
329
-			if (!($pos > 0 and $pos < 32 * 1024)) {
330
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
331
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332
-			} else {
333
-				$decalage = 1;
334
-			}
335
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
336
-			$suite = substr($texte, $pos + $decalage);
337
-		}
338
-
339
-		return (array($debut, $suite));
340
-	} else {
341
-		return (array($texte, ''));
342
-	}
320
+    $aider = charger_fonction('aider', 'inc');
321
+    if (strlen($texte) > 28 * 1024) {
322
+        $texte = str_replace("\r\n", "\n", $texte);
323
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
324
+        if ($pos > 0 and $pos < 32 * 1024) {
325
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
326
+            $suite = substr($texte, $pos + 2);
327
+        } else {
328
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
329
+            if (!($pos > 0 and $pos < 32 * 1024)) {
330
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
331
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332
+            } else {
333
+                $decalage = 1;
334
+            }
335
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
336
+            $suite = substr($texte, $pos + $decalage);
337
+        }
338
+
339
+        return (array($debut, $suite));
340
+    } else {
341
+        return (array($texte, ''));
342
+    }
343 343
 }
344 344
 
345 345
 /**
@@ -350,24 +350,24 @@  discard block
 block discarded – undo
350 350
  * @return array
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353
-	if ((strlen($texte) < 29 * 1024)
354
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
355
-	) {
356
-		return array($texte, '');
357
-	}
358
-
359
-	include_spip('inc/barre');
360
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
361
-	$nombre = 0;
362
-
363
-	while (strlen($texte) > 29 * 1024) {
364
-		$nombre++;
365
-		list($texte1, $texte) = coupe_trop_long($texte);
366
-		$textes_supplement .= '<br />' .
367
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368
-	}
369
-
370
-	return array($texte, $textes_supplement);
353
+    if ((strlen($texte) < 29 * 1024)
354
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
355
+    ) {
356
+        return array($texte, '');
357
+    }
358
+
359
+    include_spip('inc/barre');
360
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
361
+    $nombre = 0;
362
+
363
+    while (strlen($texte) > 29 * 1024) {
364
+        $nombre++;
365
+        list($texte1, $texte) = coupe_trop_long($texte);
366
+        $textes_supplement .= '<br />' .
367
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368
+    }
369
+
370
+    return array($texte, $textes_supplement);
371 371
 }
372 372
 
373 373
 /**
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
381
-	if (!_request($champ_titre)) {
382
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
383
-		if (!is_null($longueur)) {
384
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
385
-		} else {
386
-			$t = $titrer_contenu($champs_contenu);
387
-		}
388
-		if ($t) {
389
-			set_request($champ_titre, $t);
390
-		}
391
-	}
381
+    if (!_request($champ_titre)) {
382
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
383
+        if (!is_null($longueur)) {
384
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
385
+        } else {
386
+            $t = $titrer_contenu($champs_contenu);
387
+        }
388
+        if ($t) {
389
+            set_request($champ_titre, $t);
390
+        }
391
+    }
392 392
 }
393 393
 
394 394
 /**
@@ -408,20 +408,20 @@  discard block
 block discarded – undo
408 408
  * @return string
409 409
  */
410 410
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
411
-	// trouver un champ texte non vide
412
-	$t = '';
413
-	foreach ($champs_contenu as $champ) {
414
-		if ($t = _request($champ, $c)) {
415
-			break;
416
-		}
417
-	}
418
-
419
-	if ($t) {
420
-		include_spip('inc/texte_mini');
421
-		$t = couper($t, $longueur, '...');
422
-	}
423
-
424
-	return $t;
411
+    // trouver un champ texte non vide
412
+    $t = '';
413
+    foreach ($champs_contenu as $champ) {
414
+        if ($t = _request($champ, $c)) {
415
+            break;
416
+        }
417
+    }
418
+
419
+    if ($t) {
420
+        include_spip('inc/texte_mini');
421
+        $t = couper($t, $longueur, '...');
422
+    }
423
+
424
+    return $t;
425 425
 }
426 426
 
427 427
 /**
@@ -444,30 +444,30 @@  discard block
 block discarded – undo
444 444
  *      - array sinon couples ('$prefixe$colonne => md5)
445 445
  **/
446 446
 function controles_md5($data, $prefixe = 'ctr_', $format = 'html') {
447
-	if (!is_array($data)) {
448
-		return false;
449
-	}
450
-
451
-	$ctr = array();
452
-	foreach ($data as $key => $val) {
453
-		$m = md5($val);
454
-		$k = $prefixe . $key;
455
-
456
-		switch ($format) {
457
-			case 'html':
458
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
459
-				break;
460
-			default:
461
-				$ctr[$k] = $m;
462
-				break;
463
-		}
464
-	}
465
-
466
-	if ($format == 'html') {
467
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
468
-	} else {
469
-		return $ctr;
470
-	}
447
+    if (!is_array($data)) {
448
+        return false;
449
+    }
450
+
451
+    $ctr = array();
452
+    foreach ($data as $key => $val) {
453
+        $m = md5($val);
454
+        $k = $prefixe . $key;
455
+
456
+        switch ($format) {
457
+            case 'html':
458
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
459
+                break;
460
+            default:
461
+                $ctr[$k] = $m;
462
+                break;
463
+        }
464
+    }
465
+
466
+    if ($format == 'html') {
467
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
468
+    } else {
469
+        return $ctr;
470
+    }
471 471
 }
472 472
 
473 473
 /**
@@ -506,79 +506,79 @@  discard block
 block discarded – undo
506 506
  *     - post : le contenu posté
507 507
  **/
508 508
 function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') {
509
-	include_spip('inc/filtres');
510
-
511
-	$table_objet = table_objet($type);
512
-	$spip_table_objet = table_objet_sql($type);
513
-	$trouver_table = charger_fonction('trouver_table', 'base');
514
-	$desc = $trouver_table($table_objet, $serveur);
515
-
516
-	// Appels incomplets (sans $c)
517
-	if (!is_array($c)) {
518
-		foreach ($desc['field'] as $champ => $ignore) {
519
-			if (_request($champ)) {
520
-				$c[$champ] = _request($champ);
521
-			}
522
-		}
523
-	}
524
-
525
-	// Securite : certaines variables ne sont jamais acceptees ici
526
-	// car elles ne relevent pas de autoriser(article, modifier) ;
527
-	// il faut passer par instituer_XX()
528
-	// TODO: faut-il passer ces variables interdites
529
-	// dans un fichier de description separe ?
530
-	unset($c['statut']);
531
-	unset($c['id_parent']);
532
-	unset($c['id_rubrique']);
533
-	unset($c['id_secteur']);
534
-
535
-	// Gerer les champs non vides
536
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
537
-		foreach ($options['nonvide'] as $champ => $sinon) {
538
-			if ($c[$champ] === '') {
539
-				$c[$champ] = $sinon;
540
-			}
541
-		}
542
-	}
543
-
544
-	// N'accepter que les champs qui existent
545
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
546
-	$champs = array();
547
-	foreach ($desc['field'] as $champ => $ignore) {
548
-		if (isset($c[$champ])) {
549
-			$champs[$champ] = $c[$champ];
550
-		}
551
-	}
552
-
553
-	// Nettoyer les valeurs
554
-	$champs = array_map('corriger_caracteres', $champs);
555
-
556
-	// Envoyer aux plugins
557
-	$champs = pipeline(
558
-		'pre_edition',
559
-		array(
560
-			'args' => array(
561
-				'table' => $spip_table_objet, // compatibilite
562
-				'table_objet' => $table_objet,
563
-				'spip_table_objet' => $spip_table_objet,
564
-				'type' => $type,
565
-				'id_objet' => $id,
566
-				'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
567
-				'action' => 'controler',
568
-				'serveur' => $serveur,
569
-			),
570
-			'data' => $champs
571
-		)
572
-	);
573
-
574
-	if (!$champs) {
575
-		return false;
576
-	}
577
-
578
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
579
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
580
-
581
-	return $conflits;
509
+    include_spip('inc/filtres');
510
+
511
+    $table_objet = table_objet($type);
512
+    $spip_table_objet = table_objet_sql($type);
513
+    $trouver_table = charger_fonction('trouver_table', 'base');
514
+    $desc = $trouver_table($table_objet, $serveur);
515
+
516
+    // Appels incomplets (sans $c)
517
+    if (!is_array($c)) {
518
+        foreach ($desc['field'] as $champ => $ignore) {
519
+            if (_request($champ)) {
520
+                $c[$champ] = _request($champ);
521
+            }
522
+        }
523
+    }
524
+
525
+    // Securite : certaines variables ne sont jamais acceptees ici
526
+    // car elles ne relevent pas de autoriser(article, modifier) ;
527
+    // il faut passer par instituer_XX()
528
+    // TODO: faut-il passer ces variables interdites
529
+    // dans un fichier de description separe ?
530
+    unset($c['statut']);
531
+    unset($c['id_parent']);
532
+    unset($c['id_rubrique']);
533
+    unset($c['id_secteur']);
534
+
535
+    // Gerer les champs non vides
536
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
537
+        foreach ($options['nonvide'] as $champ => $sinon) {
538
+            if ($c[$champ] === '') {
539
+                $c[$champ] = $sinon;
540
+            }
541
+        }
542
+    }
543
+
544
+    // N'accepter que les champs qui existent
545
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
546
+    $champs = array();
547
+    foreach ($desc['field'] as $champ => $ignore) {
548
+        if (isset($c[$champ])) {
549
+            $champs[$champ] = $c[$champ];
550
+        }
551
+    }
552
+
553
+    // Nettoyer les valeurs
554
+    $champs = array_map('corriger_caracteres', $champs);
555
+
556
+    // Envoyer aux plugins
557
+    $champs = pipeline(
558
+        'pre_edition',
559
+        array(
560
+            'args' => array(
561
+                'table' => $spip_table_objet, // compatibilite
562
+                'table_objet' => $table_objet,
563
+                'spip_table_objet' => $spip_table_objet,
564
+                'type' => $type,
565
+                'id_objet' => $id,
566
+                'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
567
+                'action' => 'controler',
568
+                'serveur' => $serveur,
569
+            ),
570
+            'data' => $champs
571
+        )
572
+    );
573
+
574
+    if (!$champs) {
575
+        return false;
576
+    }
577
+
578
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
579
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
580
+
581
+    return $conflits;
582 582
 }
583 583
 
584 584
 
@@ -608,63 +608,63 @@  discard block
 block discarded – undo
608 608
  *     - post : le contenu posté
609 609
  **/
610 610
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
611
-	$spip_table_objet = table_objet_sql($type);
612
-	$id_table_objet = id_table_objet($type);
613
-
614
-	// Controle des MD5 envoyes
615
-	// On elimine les donnees non modifiees par le formulaire (mais
616
-	// potentiellement modifiees entre temps par un autre utilisateur)
617
-	foreach ($champs as $key => $val) {
618
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
619
-			if (is_scalar($val) and $m == md5($val)) {
620
-				unset($champs[$key]);
621
-			}
622
-		}
623
-	}
624
-	if (!$champs) {
625
-		return;
626
-	}
627
-
628
-	// On veut savoir si notre modif va avoir un impact
629
-	// par rapport aux donnees contenues dans la base
630
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
631
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
632
-	$intact = true;
633
-	foreach ($champs as $ch => $val) {
634
-		$intact &= ($s[$ch] == $val);
635
-	}
636
-	if ($intact) {
637
-		return;
638
-	}
639
-
640
-	// Detection de conflits :
641
-	// On verifie si notre modif ne provient pas d'un formulaire
642
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
643
-	// on compare a ce qui est dans la base, et on bloque en cas
644
-	// de conflit.
645
-	$ctrh = $ctrq = $conflits = array();
646
-	foreach (array_keys($champs) as $key) {
647
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
648
-			$ctrh[$key] = $m;
649
-			$ctrq[] = $key;
650
-		}
651
-	}
652
-	if ($ctrq) {
653
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
654
-		foreach ($ctrh as $key => $m) {
655
-			if ($m != md5($ctrq[$key])
656
-				and $champs[$key] !== $ctrq[$key]
657
-			) {
658
-				$conflits[$key] = array(
659
-					'base' => $ctrq[$key],
660
-					'post' => $champs[$key]
661
-				);
662
-				unset($champs[$key]); # stocker quand meme les modifs ?
663
-			}
664
-		}
665
-	}
666
-
667
-	return $conflits;
611
+    $spip_table_objet = table_objet_sql($type);
612
+    $id_table_objet = id_table_objet($type);
613
+
614
+    // Controle des MD5 envoyes
615
+    // On elimine les donnees non modifiees par le formulaire (mais
616
+    // potentiellement modifiees entre temps par un autre utilisateur)
617
+    foreach ($champs as $key => $val) {
618
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
619
+            if (is_scalar($val) and $m == md5($val)) {
620
+                unset($champs[$key]);
621
+            }
622
+        }
623
+    }
624
+    if (!$champs) {
625
+        return;
626
+    }
627
+
628
+    // On veut savoir si notre modif va avoir un impact
629
+    // par rapport aux donnees contenues dans la base
630
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
631
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
632
+    $intact = true;
633
+    foreach ($champs as $ch => $val) {
634
+        $intact &= ($s[$ch] == $val);
635
+    }
636
+    if ($intact) {
637
+        return;
638
+    }
639
+
640
+    // Detection de conflits :
641
+    // On verifie si notre modif ne provient pas d'un formulaire
642
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
643
+    // on compare a ce qui est dans la base, et on bloque en cas
644
+    // de conflit.
645
+    $ctrh = $ctrq = $conflits = array();
646
+    foreach (array_keys($champs) as $key) {
647
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
648
+            $ctrh[$key] = $m;
649
+            $ctrq[] = $key;
650
+        }
651
+    }
652
+    if ($ctrq) {
653
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
654
+        foreach ($ctrh as $key => $m) {
655
+            if ($m != md5($ctrq[$key])
656
+                and $champs[$key] !== $ctrq[$key]
657
+            ) {
658
+                $conflits[$key] = array(
659
+                    'base' => $ctrq[$key],
660
+                    'post' => $champs[$key]
661
+                );
662
+                unset($champs[$key]); # stocker quand meme les modifs ?
663
+            }
664
+        }
665
+    }
666
+
667
+    return $conflits;
668 668
 }
669 669
 
670 670
 /**
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
  * @return string
677 677
  */
678 678
 function display_conflit_champ($x) {
679
-	if (strstr($x, "\n") or strlen($x) > 80) {
680
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
681
-	} else {
682
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
683
-	}
679
+    if (strstr($x, "\n") or strlen($x) > 80) {
680
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
681
+    } else {
682
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
683
+    }
684 684
 }
685 685
 
686 686
 /**
@@ -698,57 +698,57 @@  discard block
 block discarded – undo
698 698
  * @return string
699 699
  */
700 700
 function signaler_conflits_edition($conflits, $redirect = '') {
701
-	include_spip('inc/minipres');
702
-	include_spip('inc/revisions');
703
-	include_spip('afficher_diff/champ');
704
-	include_spip('inc/suivi_versions');
705
-	include_spip('inc/diff');
706
-	$diffs = array();
707
-	foreach ($conflits as $champ => $a) {
708
-		// probleme de stockage ou conflit d'edition ?
709
-		$base = isset($a['save']) ? $a['save'] : $a['base'];
710
-
711
-		$diff = new Diff(new DiffTexte);
712
-		$n = preparer_diff($a['post']);
713
-		$o = preparer_diff($base);
714
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
715
-
716
-		$titre = isset($a['save']) ? _L(
717
-			'Echec lors de l\'enregistrement du champ @champ@',
718
-			array('champ' => $champ)
719
-		) : $champ;
720
-
721
-		$diffs[] = "<h2>$titre</h2>\n"
722
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
725
-			. display_conflit_champ($a['post'])
726
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
727
-			. display_conflit_champ($base);
728
-	}
729
-
730
-	if ($redirect) {
731
-		$id = uniqid(rand());
732
-		$redirect = "<form action='$redirect' method='get'
701
+    include_spip('inc/minipres');
702
+    include_spip('inc/revisions');
703
+    include_spip('afficher_diff/champ');
704
+    include_spip('inc/suivi_versions');
705
+    include_spip('inc/diff');
706
+    $diffs = array();
707
+    foreach ($conflits as $champ => $a) {
708
+        // probleme de stockage ou conflit d'edition ?
709
+        $base = isset($a['save']) ? $a['save'] : $a['base'];
710
+
711
+        $diff = new Diff(new DiffTexte);
712
+        $n = preparer_diff($a['post']);
713
+        $o = preparer_diff($base);
714
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
715
+
716
+        $titre = isset($a['save']) ? _L(
717
+            'Echec lors de l\'enregistrement du champ @champ@',
718
+            array('champ' => $champ)
719
+        ) : $champ;
720
+
721
+        $diffs[] = "<h2>$titre</h2>\n"
722
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
725
+            . display_conflit_champ($a['post'])
726
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
727
+            . display_conflit_champ($base);
728
+    }
729
+
730
+    if ($redirect) {
731
+        $id = uniqid(rand());
732
+        $redirect = "<form action='$redirect' method='get'
733 733
 			id='$id'
734 734
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
735
-			. form_hidden($redirect)
736
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
735
+            . form_hidden($redirect)
736
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
737 737
 		</form>\n";
738 738
 
739
-		// pour les documents, on est probablement en ajax : il faut ajaxer
740
-		if (_AJAX) {
741
-			$redirect .= '<script type="text/javascript">'
742
-				. 'setTimeout(function(){$("#' . $id . '")
739
+        // pour les documents, on est probablement en ajax : il faut ajaxer
740
+        if (_AJAX) {
741
+            $redirect .= '<script type="text/javascript">'
742
+                . 'setTimeout(function(){$("#' . $id . '")
743 743
 			.ajaxForm({target:$("#' . $id . '").parent()});
744 744
 			}, 200);'
745
-				. "</script>\n";
746
-		}
747
-	}
745
+                . "</script>\n";
746
+        }
747
+    }
748 748
 
749
-	echo minipres(
750
-		_T('titre_conflit_edition'),
751
-		'<style>
749
+    echo minipres(
750
+        _T('titre_conflit_edition'),
751
+        '<style>
752 752
 .diff-para-deplace { background: #e8e8ff; }
753 753
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
754 754
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -759,12 +759,12 @@  discard block
 block discarded – undo
759 759
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
760 760
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
761 761
 </style>'
762
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
765
-		. join("\n", $diffs)
766
-		. "</div>\n"
767
-
768
-		. $redirect
769
-	);
762
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
765
+        . join("\n", $diffs)
766
+        . "</div>\n"
767
+
768
+        . $redirect
769
+    );
770 770
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -34 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -214,10 +214,10 @@  discard block
 block discarded – undo
214 214
 	// Appel direct dans un squelette
215 215
 	if (!$row) {
216 216
 		if (!$new or $lier_trad) {
217
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
217
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
218 218
 				$row = $select($id, $id_parent, $lier_trad);
219 219
 			} else {
220
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
220
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
221 221
 			}
222 222
 			if (!$new) {
223 223
 				$md5 = controles_md5($row);
@@ -287,13 +287,12 @@  discard block
 block discarded – undo
287 287
 		unset($contexte['lang']);
288 288
 	}
289 289
 
290
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
291
-		(!$lier_trad ? '' :
292
-			("\n<input type='hidden' name='lier_trad' value='" .
293
-				$lier_trad .
294
-				"' />" .
295
-				"\n<input type='hidden' name='changer_lang' value='" .
296
-				$config['langue'] .
290
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
291
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
292
+				$lier_trad.
293
+				"' />".
294
+				"\n<input type='hidden' name='changer_lang' value='".
295
+				$config['langue'].
297 296
 				"' />"))
298 297
 		. $hidden
299 298
 		. (isset($md5) ? $md5 : '');
@@ -320,14 +319,14 @@  discard block
 block discarded – undo
320 319
 	$aider = charger_fonction('aider', 'inc');
321 320
 	if (strlen($texte) > 28 * 1024) {
322 321
 		$texte = str_replace("\r\n", "\n", $texte);
323
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
322
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
324 323
 		if ($pos > 0 and $pos < 32 * 1024) {
325
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
324
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
326 325
 			$suite = substr($texte, $pos + 2);
327 326
 		} else {
328
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
327
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
329 328
 			if (!($pos > 0 and $pos < 32 * 1024)) {
330
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
329
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
331 330
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
332 331
 			} else {
333 332
 				$decalage = 1;
@@ -357,13 +356,13 @@  discard block
 block discarded – undo
357 356
 	}
358 357
 
359 358
 	include_spip('inc/barre');
360
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
359
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
361 360
 	$nombre = 0;
362 361
 
363 362
 	while (strlen($texte) > 29 * 1024) {
364 363
 		$nombre++;
365 364
 		list($texte1, $texte) = coupe_trop_long($texte);
366
-		$textes_supplement .= '<br />' .
365
+		$textes_supplement .= '<br />'.
367 366
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
368 367
 	}
369 368
 
@@ -451,7 +450,7 @@  discard block
 block discarded – undo
451 450
 	$ctr = array();
452 451
 	foreach ($data as $key => $val) {
453 452
 		$m = md5($val);
454
-		$k = $prefixe . $key;
453
+		$k = $prefixe.$key;
455 454
 
456 455
 		switch ($format) {
457 456
 			case 'html':
@@ -464,7 +463,7 @@  discard block
 block discarded – undo
464 463
 	}
465 464
 
466 465
 	if ($format == 'html') {
467
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
466
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
468 467
 	} else {
469 468
 		return $ctr;
470 469
 	}
@@ -615,7 +614,7 @@  discard block
 block discarded – undo
615 614
 	// On elimine les donnees non modifiees par le formulaire (mais
616 615
 	// potentiellement modifiees entre temps par un autre utilisateur)
617 616
 	foreach ($champs as $key => $val) {
618
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
617
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
619 618
 			if (is_scalar($val) and $m == md5($val)) {
620 619
 				unset($champs[$key]);
621 620
 			}
@@ -644,7 +643,7 @@  discard block
 block discarded – undo
644 643
 	// de conflit.
645 644
 	$ctrh = $ctrq = $conflits = array();
646 645
 	foreach (array_keys($champs) as $key) {
647
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
646
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
648 647
 			$ctrh[$key] = $m;
649 648
 			$ctrq[] = $key;
650 649
 		}
@@ -677,9 +676,9 @@  discard block
 block discarded – undo
677 676
  */
678 677
 function display_conflit_champ($x) {
679 678
 	if (strstr($x, "\n") or strlen($x) > 80) {
680
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
679
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
681 680
 	} else {
682
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
681
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
683 682
 	}
684 683
 }
685 684
 
@@ -719,11 +718,11 @@  discard block
 block discarded – undo
719 718
 		) : $champ;
720 719
 
721 720
 		$diffs[] = "<h2>$titre</h2>\n"
722
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
723
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
724
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
721
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
722
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
723
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
725 724
 			. display_conflit_champ($a['post'])
726
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
725
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
727 726
 			. display_conflit_champ($base);
728 727
 	}
729 728
 
@@ -731,16 +730,16 @@  discard block
 block discarded – undo
731 730
 		$id = uniqid(rand());
732 731
 		$redirect = "<form action='$redirect' method='get'
733 732
 			id='$id'
734
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
733
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
735 734
 			. form_hidden($redirect)
736
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
735
+			. "<input type='submit' value='"._T('icone_retour')."' />
737 736
 		</form>\n";
738 737
 
739 738
 		// pour les documents, on est probablement en ajax : il faut ajaxer
740 739
 		if (_AJAX) {
741 740
 			$redirect .= '<script type="text/javascript">'
742
-				. 'setTimeout(function(){$("#' . $id . '")
743
-			.ajaxForm({target:$("#' . $id . '").parent()});
741
+				. 'setTimeout(function(){$("#'.$id.'")
742
+			.ajaxForm({target:$("#' . $id.'").parent()});
744 743
 			}, 200);'
745 744
 				. "</script>\n";
746 745
 		}
@@ -759,9 +758,9 @@  discard block
 block discarded – undo
759 758
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
760 759
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
761 760
 </style>'
762
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
763
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
764
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
761
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
762
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
763
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
765 764
 		. join("\n", $diffs)
766 765
 		. "</div>\n"
767 766
 
Please login to merge, or discard this patch.
ecrire/inc/envoyer_mail.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -187,7 +187,7 @@
 block discarded – undo
187 187
  * @param string $to
188 188
  * @param string $texte
189 189
  * @param string $parts
190
- * @return array
190
+ * @return string[]
191 191
  */
192 192
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
193 193
 	$charset = $GLOBALS['meta']['charset'];
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136 136
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
137
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')';
138 138
 	}
139 139
 
140 140
 	// nettoyer les &eacute; &#8217, &emdash; etc...
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		if (!_TEST_EMAIL_DEST) {
172 172
 			return false;
173 173
 		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
174
+			$texte = "Dest : $destinataire\r\n".$texte;
175 175
 			$destinataire = _TEST_EMAIL_DEST;
176 176
 		}
177 177
 	}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
196 196
 	if (strpos($headers, 'Content-Type: ') === false) {
197 197
 		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
198
+			"Content-Type: text/plain;charset=\"$charset\";\n".
199 199
 			"Content-Transfer-Encoding: 8bit\n";
200 200
 	} else {
201 201
 		$type = '';
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
 
204 204
 	// calculer un identifiant unique
205 205
 	preg_match('/@\S+/', $from, $domain);
206
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
206
+	$uniq = rand().'_'.md5($to.$texte).$domain[0];
207 207
 
208 208
 	// Si multi-part, s'en servir comme borne ...
209 209
 	if ($parts) {
210
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
210
+		$texte = "--$uniq\n$type\n".$texte."\n";
211 211
 		foreach ($parts as $part) {
212
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
212
+			$n = strlen($part[1]).($part[0] ? "\n" : '');
213 213
 			$e = join("\n", $part[0]);
214
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
215 215
 		}
216 216
 		$texte .= "\n\n--$uniq--\n";
217 217
 		// Si boundary n'est pas entre guillemets,
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 
222 222
 	// .. et s'en servir pour plaire a SpamAssassin
223 223
 
224
-	$mid = 'Message-Id: <' . $uniq . '>';
224
+	$mid = 'Message-Id: <'.$uniq.'>';
225 225
 
226 226
 	// indispensable pour les sites qui collent d'office From: serveur-http
227 227
 	// sauf si deja mis par l'envoyeur
Please login to merge, or discard this patch.
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Mail
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function nettoyer_titre_email($titre) {
35
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
36 36
 }
37 37
 
38 38
 /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function nettoyer_caracteres_mail($t) {
50 50
 
51
-	$t = filtrer_entites($t);
51
+    $t = filtrer_entites($t);
52 52
 
53
-	if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
-		$t = str_replace(
55
-			array('&#8217;', '&#8220;', '&#8221;'),
56
-			array("'", '"', '"'),
57
-			$t
58
-		);
59
-	}
53
+    if ($GLOBALS['meta']['charset'] <> 'utf-8') {
54
+        $t = str_replace(
55
+            array('&#8217;', '&#8220;', '&#8221;'),
56
+            array("'", '"', '"'),
57
+            $t
58
+        );
59
+    }
60 60
 
61
-	$t = str_replace(
62
-		array('&mdash;', '&endash;'),
63
-		array('--', '-'),
64
-		$t
65
-	);
61
+    $t = str_replace(
62
+        array('&mdash;', '&endash;'),
63
+        array('--', '-'),
64
+        $t
65
+    );
66 66
 
67
-	return $t;
67
+    return $t;
68 68
 }
69 69
 
70 70
 /**
@@ -97,86 +97,86 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
99 99
 
100
-	if (!email_valide($destinataire)) {
101
-		return false;
102
-	}
103
-	if ($destinataire == _T('info_mail_fournisseur')) {
104
-		return false;
105
-	} // tres fort
106
-
107
-	// Fournir si possible un Message-Id: conforme au RFC1036,
108
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
-
110
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
111
-	if (!email_valide($email_envoi)) {
112
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
-		$email_envoi = $destinataire;
114
-	}
115
-
116
-	$parts = '';
117
-	if (is_array($corps)) {
118
-		$texte = $corps['texte'];
119
-		$from = (isset($corps['from']) ? $corps['from'] : $from);
120
-		$headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
-		if (is_array($headers)) {
122
-			$headers = implode("\n", $headers);
123
-		}
124
-		if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
-		}
127
-	} else {
128
-		$texte = $corps;
129
-	}
130
-
131
-	if (!$from) {
132
-		$from = $email_envoi;
133
-	}
134
-
135
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
-	}
139
-
140
-	// nettoyer les &eacute; &#8217, &emdash; etc...
141
-	// les 'cliquer ici' etc sont a eviter;  voir:
142
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
-	$texte = nettoyer_caracteres_mail($texte);
144
-	$sujet = nettoyer_caracteres_mail($sujet);
145
-
146
-	// encoder le sujet si possible selon la RFC
147
-	if (init_mb_string()) {
148
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
-		$charset = $GLOBALS['meta']['charset'];
151
-		mb_internal_encoding($charset);
152
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
-		mb_internal_encoding('utf-8');
154
-	}
155
-
156
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
-		$texte = wordwrap($texte);
158
-	}
159
-
160
-	list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
-
162
-	if (_OS_SERVEUR == 'windows') {
163
-		$texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
-		$headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
-	}
167
-
168
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
-	// mode TEST : forcer l'email
170
-	if (defined('_TEST_EMAIL_DEST')) {
171
-		if (!_TEST_EMAIL_DEST) {
172
-			return false;
173
-		} else {
174
-			$texte = "Dest : $destinataire\r\n" . $texte;
175
-			$destinataire = _TEST_EMAIL_DEST;
176
-		}
177
-	}
178
-
179
-	return @mail($destinataire, $sujet, $texte, $headers);
100
+    if (!email_valide($destinataire)) {
101
+        return false;
102
+    }
103
+    if ($destinataire == _T('info_mail_fournisseur')) {
104
+        return false;
105
+    } // tres fort
106
+
107
+    // Fournir si possible un Message-Id: conforme au RFC1036,
108
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
109
+
110
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
111
+    if (!email_valide($email_envoi)) {
112
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
113
+        $email_envoi = $destinataire;
114
+    }
115
+
116
+    $parts = '';
117
+    if (is_array($corps)) {
118
+        $texte = $corps['texte'];
119
+        $from = (isset($corps['from']) ? $corps['from'] : $from);
120
+        $headers = (isset($corps['headers']) ? $corps['headers'] : $headers);
121
+        if (is_array($headers)) {
122
+            $headers = implode("\n", $headers);
123
+        }
124
+        if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) {
125
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
126
+        }
127
+    } else {
128
+        $texte = $corps;
129
+    }
130
+
131
+    if (!$from) {
132
+        $from = $email_envoi;
133
+    }
134
+
135
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
136
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) {
137
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')';
138
+    }
139
+
140
+    // nettoyer les &eacute; &#8217, &emdash; etc...
141
+    // les 'cliquer ici' etc sont a eviter;  voir:
142
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
143
+    $texte = nettoyer_caracteres_mail($texte);
144
+    $sujet = nettoyer_caracteres_mail($sujet);
145
+
146
+    // encoder le sujet si possible selon la RFC
147
+    if (init_mb_string()) {
148
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
149
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
150
+        $charset = $GLOBALS['meta']['charset'];
151
+        mb_internal_encoding($charset);
152
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
153
+        mb_internal_encoding('utf-8');
154
+    }
155
+
156
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) {
157
+        $texte = wordwrap($texte);
158
+    }
159
+
160
+    list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
161
+
162
+    if (_OS_SERVEUR == 'windows') {
163
+        $texte = preg_replace("@\r*\n@", "\r\n", $texte);
164
+        $headers = preg_replace("@\r*\n@", "\r\n", $headers);
165
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
166
+    }
167
+
168
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
169
+    // mode TEST : forcer l'email
170
+    if (defined('_TEST_EMAIL_DEST')) {
171
+        if (!_TEST_EMAIL_DEST) {
172
+            return false;
173
+        } else {
174
+            $texte = "Dest : $destinataire\r\n" . $texte;
175
+            $destinataire = _TEST_EMAIL_DEST;
176
+        }
177
+    }
178
+
179
+    return @mail($destinataire, $sujet, $texte, $headers);
180 180
 }
181 181
 
182 182
 /**
@@ -190,52 +190,52 @@  discard block
 block discarded – undo
190 190
  * @return array
191 191
  */
192 192
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
193
-	$charset = $GLOBALS['meta']['charset'];
194
-
195
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
196
-	if (strpos($headers, 'Content-Type: ') === false) {
197
-		$type =
198
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
199
-			"Content-Transfer-Encoding: 8bit\n";
200
-	} else {
201
-		$type = '';
202
-	}
203
-
204
-	// calculer un identifiant unique
205
-	preg_match('/@\S+/', $from, $domain);
206
-	$uniq = rand() . '_' . md5($to . $texte) . $domain[0];
207
-
208
-	// Si multi-part, s'en servir comme borne ...
209
-	if ($parts) {
210
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
211
-		foreach ($parts as $part) {
212
-			$n = strlen($part[1]) . ($part[0] ? "\n" : '');
213
-			$e = join("\n", $part[0]);
214
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
215
-		}
216
-		$texte .= "\n\n--$uniq--\n";
217
-		// Si boundary n'est pas entre guillemets,
218
-		// elle est comprise mais le charset est ignoree !
219
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
220
-	}
221
-
222
-	// .. et s'en servir pour plaire a SpamAssassin
223
-
224
-	$mid = 'Message-Id: <' . $uniq . '>';
225
-
226
-	// indispensable pour les sites qui collent d'office From: serveur-http
227
-	// sauf si deja mis par l'envoyeur
228
-	$rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
229
-
230
-	// Nettoyer les en-tetes envoyees
231
-	// Ajouter le \n final
232
-	if (strlen($headers = trim($headers))) {
233
-		$headers .= "\n";
234
-	}
235
-
236
-	// Et mentionner l'indeboulonable nomenclature ratee
237
-
238
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
239
-
240
-	return array($headers, $texte);
193
+    $charset = $GLOBALS['meta']['charset'];
194
+
195
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
196
+    if (strpos($headers, 'Content-Type: ') === false) {
197
+        $type =
198
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
199
+            "Content-Transfer-Encoding: 8bit\n";
200
+    } else {
201
+        $type = '';
202
+    }
203
+
204
+    // calculer un identifiant unique
205
+    preg_match('/@\S+/', $from, $domain);
206
+    $uniq = rand() . '_' . md5($to . $texte) . $domain[0];
207
+
208
+    // Si multi-part, s'en servir comme borne ...
209
+    if ($parts) {
210
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
211
+        foreach ($parts as $part) {
212
+            $n = strlen($part[1]) . ($part[0] ? "\n" : '');
213
+            $e = join("\n", $part[0]);
214
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
215
+        }
216
+        $texte .= "\n\n--$uniq--\n";
217
+        // Si boundary n'est pas entre guillemets,
218
+        // elle est comprise mais le charset est ignoree !
219
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
220
+    }
221
+
222
+    // .. et s'en servir pour plaire a SpamAssassin
223
+
224
+    $mid = 'Message-Id: <' . $uniq . '>';
225
+
226
+    // indispensable pour les sites qui collent d'office From: serveur-http
227
+    // sauf si deja mis par l'envoyeur
228
+    $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n";
229
+
230
+    // Nettoyer les en-tetes envoyees
231
+    // Ajouter le \n final
232
+    if (strlen($headers = trim($headers))) {
233
+        $headers .= "\n";
234
+    }
235
+
236
+    // Et mentionner l'indeboulonable nomenclature ratee
237
+
238
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
239
+
240
+    return array($headers, $texte);
241 241
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 4 patches
Doc Comments   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  *
70 70
  * @param string $fonc
71 71
  *     Nom du filtre
72
- * @param null $default
72
+ * @param string $default
73 73
  *     Nom du filtre appliqué par défaut si celui demandé n'est pas trouvé
74 74
  * @return string
75 75
  *     Fonction PHP correspondante du filtre demandé
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
  *
117 117
  * @see filtrer() Assez proche
118 118
  *
119
- * @param mixed $arg
119
+ * @param string $arg
120 120
  *     Texte (le plus souvent) sur lequel appliquer le filtre
121 121
  * @param string $filtre
122 122
  *     Nom du filtre à appliquer
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
  *   corriger toutes les `&amp;xx;` en `&xx;`
674 674
  * @param bool $quote
675 675
  *   Échapper aussi les simples quotes en `&#039;`
676
- * @return mixed|string
676
+ * @return string
677 677
  */
678 678
 function entites_html($texte, $tout = false, $quote = true) {
679 679
 	if (!is_string($texte) or !$texte
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
  *
1311 1311
  * @param mixed $texte
1312 1312
  *     Contenu de reference a tester
1313
- * @param mixed $sinon
1313
+ * @param string|null $sinon
1314 1314
  *     Contenu a retourner si le contenu de reference est vide
1315 1315
  * @return mixed
1316 1316
  *     Retourne $texte, sinon $sinon.
@@ -1568,7 +1568,7 @@  discard block
 block discarded – undo
1568 1568
  * @param string $letexte
1569 1569
  * @param string $lang
1570 1570
  *     Langue à retrouver (si vide, utilise la langue en cours).
1571
- * @param array $options Options {
1571
+ * @param boolean $options Options {
1572 1572
  * @type bool $echappe_span
1573 1573
  *         True pour échapper les balises span (false par défaut)
1574 1574
  * @type string $lang_defaut
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
  * @param string $letexte
1659 1659
  * @param string $lang
1660 1660
  *     Langue à retrouver (si vide, utilise la langue en cours).
1661
- * @param array $options Options {
1661
+ * @param boolean $options Options {
1662 1662
  * @type bool $echappe_span
1663 1663
  *         True pour échapper les balises span (false par défaut)
1664 1664
  * @type string $lang_defaut
@@ -2042,6 +2042,9 @@  discard block
 block discarded – undo
2042 2042
 // Quelques fonctions de calcul arithmetique
2043 2043
 //
2044 2044
 function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
2045
+/**
2046
+ * @param string $f
2047
+ */
2045 2048
 function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
2046 2049
 
2047 2050
 /**
@@ -2184,7 +2187,7 @@  discard block
 block discarded – undo
2184 2187
  *
2185 2188
  * @param string $adresses
2186 2189
  *      Adresse ou liste d'adresse
2187
- * @return bool|string
2190
+ * @return false|string
2188 2191
  *      - false si pas conforme,
2189 2192
  *      - la normalisation de la dernière adresse donnée sinon
2190 2193
  **/
@@ -2518,7 +2521,7 @@  discard block
 block discarded – undo
2518 2521
  * @param int $a
2519 2522
  * @param int $b
2520 2523
  * @param int $c
2521
- * @return int
2524
+ * @return double
2522 2525
  *      Retourne `$a*$b/$c`
2523 2526
  **/
2524 2527
 function regledetrois($a, $b, $c) {
@@ -4551,7 +4554,7 @@  discard block
 block discarded – undo
4551 4554
  *     Nombre d'éléments
4552 4555
  * @param string $objet
4553 4556
  *     Objet
4554
- * @return mixed|string
4557
+ * @return string
4555 4558
  *     Texte traduit du comptage, tel que '3 articles'
4556 4559
  */
4557 4560
 function objet_afficher_nb($nb, $objet) {
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3370,8 +3370,7 @@  discard block
 block discarded – undo
3370 3370
 	}
3371 3371
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3372 3372
 		$img_file = chemin_image($img);
3373
-	}
3374
-	else {
3373
+	} else {
3375 3374
 		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3376 3375
 			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3377 3376
 			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
@@ -3380,8 +3379,7 @@  discard block
 block discarded – undo
3380 3379
 			  and file_exists($variante_svg_generique)) {
3381 3380
 				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3382 3381
 					$img_file = $variante_svg_size;
3383
-				}
3384
-				else {
3382
+				} else {
3385 3383
 					$img_file = $variante_svg_generique;
3386 3384
 				}
3387 3385
 			}
@@ -3501,8 +3499,7 @@  discard block
 block discarded – undo
3501 3499
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3502 3500
 		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3503 3501
 		$balise_svg .= $title;
3504
-	}
3505
-	else {
3502
+	} else {
3506 3503
 		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3507 3504
 	}
3508 3505
 	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
@@ -4683,8 +4680,7 @@  discard block
 block discarded – undo
4683 4680
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4684 4681
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4685 4682
 		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4686
-	}
4687
-	else {
4683
+	} else {
4688 4684
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4689 4685
 		ksort($contexte);
4690 4686
 		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
Please login to merge, or discard this patch.
Indentation   +2040 added lines, -2040 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_spip('public/parametrer'); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-
96
-	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
-		// fonction ou name\space\fonction
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
-			return $f;
106
-		}
107
-	}
108
-
109
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+
96
+    include_fichiers_fonctions();
97
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
+        // fonction ou name\space\fonction
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
+            return $f;
106
+        }
107
+    }
108
+
109
+    return $default;
110 110
 }
111 111
 
112 112
 /**
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
  *     Chaîne vide sinon (filtre introuvable).
131 131
  **/
132 132
 function appliquer_filtre($arg, $filtre, $force = null) {
133
-	$f = chercher_filtre($filtre);
134
-	if (!$f) {
135
-		if (!$force) {
136
-			return '';
137
-		} else {
138
-			return $arg;
139
-		}
140
-	}
133
+    $f = chercher_filtre($filtre);
134
+    if (!$f) {
135
+        if (!$force) {
136
+            return '';
137
+        } else {
138
+            return $arg;
139
+        }
140
+    }
141 141
 
142
-	$args = func_get_args();
143
-	array_shift($args); // enlever $arg
144
-	array_shift($args); // enlever $filtre
145
-	array_unshift($args, $arg); // remettre $arg
146
-	return call_user_func_array($f, $args);
142
+    $args = func_get_args();
143
+    array_shift($args); // enlever $arg
144
+    array_shift($args); // enlever $filtre
145
+    array_unshift($args, $arg); // remettre $arg
146
+    return call_user_func_array($f, $args);
147 147
 }
148 148
 
149 149
 /**
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
  *     Version de SPIP
160 160
  **/
161 161
 function spip_version() {
162
-	$version = $GLOBALS['spip_version_affichee'];
163
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
164
-		$version .= " $vcs_version";
165
-	}
162
+    $version = $GLOBALS['spip_version_affichee'];
163
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
164
+        $version .= " $vcs_version";
165
+    }
166 166
 
167
-	return $version;
167
+    return $version;
168 168
 }
169 169
 
170 170
 /**
@@ -177,19 +177,19 @@  discard block
 block discarded – undo
177 177
  *    - string|null si $raw = false
178 178
  */
179 179
 function version_vcs_courante($dir, $raw = false) {
180
-	$desc = decrire_version_git($dir);
181
-	if ($desc === null) {
182
-		$desc = decrire_version_svn($dir);
183
-	}
184
-	if ($desc === null or $raw) {
185
-		return $desc;
186
-	}
187
-	// affichage "GIT [master: abcdef]"
188
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
189
-	if ($desc['branch']) {
190
-		$commit = $desc['branch'] . ': ' . $commit;
191
-	}
192
-	return "{$desc['vcs']} [$commit]";
180
+    $desc = decrire_version_git($dir);
181
+    if ($desc === null) {
182
+        $desc = decrire_version_svn($dir);
183
+    }
184
+    if ($desc === null or $raw) {
185
+        return $desc;
186
+    }
187
+    // affichage "GIT [master: abcdef]"
188
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
189
+    if ($desc['branch']) {
190
+        $commit = $desc['branch'] . ': ' . $commit;
191
+    }
192
+    return "{$desc['vcs']} [$commit]";
193 193
 }
194 194
 
195 195
 /**
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
  *      array ['branch' => xx, 'commit' => yy] sinon.
202 202
  **/
203 203
 function decrire_version_git($dir) {
204
-	if (!$dir) {
205
-		$dir = '.';
206
-	}
204
+    if (!$dir) {
205
+        $dir = '.';
206
+    }
207 207
 
208
-	// version installee par GIT
209
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
210
-		$currentHead = trim(substr($c, 4));
211
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
212
-			return [
213
-				'vcs' => 'GIT',
214
-				'branch' => basename($currentHead),
215
-				'commit' => trim($hash),
216
-				'commit_short' => substr(trim($hash), 0, 8),
217
-			];
218
-		}
219
-	}
208
+    // version installee par GIT
209
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
210
+        $currentHead = trim(substr($c, 4));
211
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
212
+            return [
213
+                'vcs' => 'GIT',
214
+                'branch' => basename($currentHead),
215
+                'commit' => trim($hash),
216
+                'commit_short' => substr(trim($hash), 0, 8),
217
+            ];
218
+        }
219
+    }
220 220
 
221
-	return null;
221
+    return null;
222 222
 }
223 223
 
224 224
 
@@ -231,25 +231,25 @@  discard block
 block discarded – undo
231 231
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
232 232
  **/
233 233
 function decrire_version_svn($dir) {
234
-	if (!$dir) {
235
-		$dir = '.';
236
-	}
237
-	// version installee par SVN
238
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
239
-		$db = new SQLite3($dir . '/.svn/wc.db');
240
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
241
-		if ($result) {
242
-			$row = $result->fetchArray();
243
-			if ($row['changed_revision'] != "") {
244
-				return [
245
-					'vcs' => 'SVN',
246
-					'branch' => '',
247
-					'commit' => $row['changed_revision'],
248
-				];
249
-			}
250
-		}
251
-	}
252
-	return null;
234
+    if (!$dir) {
235
+        $dir = '.';
236
+    }
237
+    // version installee par SVN
238
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
239
+        $db = new SQLite3($dir . '/.svn/wc.db');
240
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
241
+        if ($result) {
242
+            $row = $result->fetchArray();
243
+            if ($row['changed_revision'] != "") {
244
+                return [
245
+                    'vcs' => 'SVN',
246
+                    'branch' => '',
247
+                    'commit' => $row['changed_revision'],
248
+                ];
249
+            }
250
+        }
251
+    }
252
+    return null;
253 253
 }
254 254
 
255 255
 /**
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
  *
268 268
  **/
269 269
 function version_svn_courante($dir) {
270
-	if ($desc = decrire_version_svn($dir)) {
271
-		return -$desc['commit'];
272
-	}
273
-	return 0;
270
+    if ($desc = decrire_version_svn($dir)) {
271
+        return -$desc['commit'];
272
+    }
273
+    return 0;
274 274
 }
275 275
 
276 276
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -314,18 +314,18 @@  discard block
 block discarded – undo
314 314
  *     Code HTML retourné par le filtre
315 315
  **/
316 316
 function filtrer($filtre) {
317
-	$tous = func_get_args();
318
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
319
-		return image_filtrer($tous);
320
-	} elseif ($f = chercher_filtre($filtre)) {
321
-		array_shift($tous);
322
-		return call_user_func_array($f, $tous);
323
-	} else {
324
-		// le filtre n'existe pas, on provoque une erreur
325
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
326
-		erreur_squelette($msg);
327
-		return '';
328
-	}
317
+    $tous = func_get_args();
318
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
319
+        return image_filtrer($tous);
320
+    } elseif ($f = chercher_filtre($filtre)) {
321
+        array_shift($tous);
322
+        return call_user_func_array($f, $tous);
323
+    } else {
324
+        // le filtre n'existe pas, on provoque une erreur
325
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
326
+        erreur_squelette($msg);
327
+        return '';
328
+    }
329 329
 }
330 330
 
331 331
 /**
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
343 343
  */
344 344
 function trouver_filtre_matrice($filtre) {
345
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
346
-		find_in_path($f, '', true);
347
-		$GLOBALS['spip_matrice'][$filtre] = true;
348
-	}
349
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
345
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
346
+        find_in_path($f, '', true);
347
+        $GLOBALS['spip_matrice'][$filtre] = true;
348
+    }
349
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
350 350
 }
351 351
 
352 352
 
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
  * @return mixed
375 375
  */
376 376
 function filtre_set(&$Pile, $val, $key, $continue = null) {
377
-	$Pile['vars'][$key] = $val;
378
-	return $continue ? $val : '';
377
+    $Pile['vars'][$key] = $val;
378
+    return $continue ? $val : '';
379 379
 }
380 380
 
381 381
 /**
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
402 402
  */
403 403
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
404
-	$Pile[0][$key] = $val;
405
-	return $continue ? $val : '';
404
+    $Pile[0][$key] = $val;
405
+    return $continue ? $val : '';
406 406
 }
407 407
 
408 408
 /**
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @return string
412 412
  */
413 413
 function filtre_sanitize_env(&$Pile, $keys) {
414
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
415
-	return '';
414
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
415
+    return '';
416 416
 }
417 417
 
418 418
 
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
  * @return mixed Retourne la valeur (sans la modifier).
436 436
  */
437 437
 function filtre_debug($val, $key = null) {
438
-	$debug = (
439
-		is_null($key) ? '' : (var_export($key, true) . " = ")
440
-		) . var_export($val, true);
438
+    $debug = (
439
+        is_null($key) ? '' : (var_export($key, true) . " = ")
440
+        ) . var_export($val, true);
441 441
 
442
-	include_spip('inc/autoriser');
443
-	if (autoriser('webmestre')) {
444
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
445
-	}
442
+    include_spip('inc/autoriser');
443
+    if (autoriser('webmestre')) {
444
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
445
+    }
446 446
 
447
-	spip_log($debug, 'debug');
447
+    spip_log($debug, 'debug');
448 448
 
449
-	return $val;
449
+    return $val;
450 450
 }
451 451
 
452 452
 
@@ -474,71 +474,71 @@  discard block
 block discarded – undo
474 474
  *     Texte qui a reçu les filtres
475 475
  **/
476 476
 function image_filtrer($args) {
477
-	$filtre = array_shift($args); # enlever $filtre
478
-	$texte = array_shift($args);
479
-	if (!strlen($texte)) {
480
-		return;
481
-	}
482
-	find_in_path('filtres_images_mini.php', 'inc/', true);
483
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
484
-	// Cas du nom de fichier local
485
-	if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
486
-		and !preg_match(',^/|[<>]|\s,S', $texte)
487
-		and (
488
-			file_exists(preg_replace(',[?].*$,', '', $texte))
489
-			or tester_url_absolue($texte)
490
-		)
491
-	) {
492
-		array_unshift($args, "<img src='$texte' />");
493
-		$res = call_user_func_array($filtre, $args);
494
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
495
-		return $res;
496
-	}
497
-
498
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
499
-	if (preg_match_all(
500
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
501
-		$texte, $tags, PREG_SET_ORDER)) {
502
-		foreach ($tags as $tag) {
503
-			$class = extraire_attribut($tag[3], 'class');
504
-			if (!$class or
505
-				(strpos($class, 'filtre_inactif') === false
506
-					// compat historique a virer en 3.2
507
-					and strpos($class, 'no_image_filtrer') === false)
508
-			) {
509
-				array_unshift($args, $tag[3]);
510
-				if ($reduit = call_user_func_array($filtre, $args)) {
511
-					// En cas de span spip_documents, modifier le style=...width:
512
-					if ($tag[1]) {
513
-						$w = extraire_attribut($reduit, 'width');
514
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
515
-							$w = $regs[1];
516
-						}
517
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
518
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
519
-							$replace = inserer_attribut($tag[1], 'style', $style);
520
-							$texte = str_replace($tag[1], $replace, $texte);
521
-						}
522
-					}
523
-					// traiter aussi un eventuel mouseover
524
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
525
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
526
-							$srcover = $match[1];
527
-							array_shift($args);
528
-							array_unshift($args, "<img src='" . $match[1] . "' />");
529
-							$srcover_filter = call_user_func_array($filtre, $args);
530
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
531
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
532
-						}
533
-					}
534
-					$texte = str_replace($tag[3], $reduit, $texte);
535
-				}
536
-				array_shift($args);
537
-			}
538
-		}
539
-	}
540
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
541
-	return $texte;
477
+    $filtre = array_shift($args); # enlever $filtre
478
+    $texte = array_shift($args);
479
+    if (!strlen($texte)) {
480
+        return;
481
+    }
482
+    find_in_path('filtres_images_mini.php', 'inc/', true);
483
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
484
+    // Cas du nom de fichier local
485
+    if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
486
+        and !preg_match(',^/|[<>]|\s,S', $texte)
487
+        and (
488
+            file_exists(preg_replace(',[?].*$,', '', $texte))
489
+            or tester_url_absolue($texte)
490
+        )
491
+    ) {
492
+        array_unshift($args, "<img src='$texte' />");
493
+        $res = call_user_func_array($filtre, $args);
494
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
495
+        return $res;
496
+    }
497
+
498
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
499
+    if (preg_match_all(
500
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
501
+        $texte, $tags, PREG_SET_ORDER)) {
502
+        foreach ($tags as $tag) {
503
+            $class = extraire_attribut($tag[3], 'class');
504
+            if (!$class or
505
+                (strpos($class, 'filtre_inactif') === false
506
+                    // compat historique a virer en 3.2
507
+                    and strpos($class, 'no_image_filtrer') === false)
508
+            ) {
509
+                array_unshift($args, $tag[3]);
510
+                if ($reduit = call_user_func_array($filtre, $args)) {
511
+                    // En cas de span spip_documents, modifier le style=...width:
512
+                    if ($tag[1]) {
513
+                        $w = extraire_attribut($reduit, 'width');
514
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
515
+                            $w = $regs[1];
516
+                        }
517
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
518
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
519
+                            $replace = inserer_attribut($tag[1], 'style', $style);
520
+                            $texte = str_replace($tag[1], $replace, $texte);
521
+                        }
522
+                    }
523
+                    // traiter aussi un eventuel mouseover
524
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
525
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
526
+                            $srcover = $match[1];
527
+                            array_shift($args);
528
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
529
+                            $srcover_filter = call_user_func_array($filtre, $args);
530
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
531
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
532
+                        }
533
+                    }
534
+                    $texte = str_replace($tag[3], $reduit, $texte);
535
+                }
536
+                array_shift($args);
537
+            }
538
+        }
539
+    }
540
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
541
+    return $texte;
542 542
 }
543 543
 
544 544
 /**
@@ -553,65 +553,65 @@  discard block
 block discarded – undo
553 553
  **/
554 554
 function taille_image($img, $force_refresh = false) {
555 555
 
556
-	static $largeur_img = array(), $hauteur_img = array();
557
-	$srcWidth = 0;
558
-	$srcHeight = 0;
559
-
560
-	$src = extraire_attribut($img, 'src');
561
-
562
-	if (!$src) {
563
-		$src = $img;
564
-	} else {
565
-		$srcWidth = extraire_attribut($img, 'width');
566
-		$srcHeight = extraire_attribut($img, 'height');
567
-	}
568
-
569
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
570
-	// la copie locale a toutes les chances d'etre la ou de resservir
571
-	if (tester_url_absolue($src)) {
572
-		include_spip('inc/distant');
573
-		$fichier = copie_locale($src);
574
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
575
-	}
576
-	if (($p = strpos($src, '?')) !== false) {
577
-		$src = substr($src, 0, $p);
578
-	}
579
-
580
-	$srcsize = false;
581
-	if (isset($largeur_img[$src]) and !$force_refresh) {
582
-		$srcWidth = $largeur_img[$src];
583
-	}
584
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
585
-		$srcHeight = $hauteur_img[$src];
586
-	}
587
-	if (!$srcWidth or !$srcHeight) {
588
-
589
-		if (file_exists($src)
590
-			and $srcsize = spip_getimagesize($src)
591
-		) {
592
-			if (!$srcWidth) {
593
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
594
-			}
595
-			if (!$srcHeight) {
596
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
597
-			}
598
-		}
599
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
600
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
601
-		elseif (@file_exists($f = "$src.src")
602
-			and lire_fichier($f, $valeurs)
603
-			and $valeurs = unserialize($valeurs)
604
-		) {
605
-			if (!$srcWidth) {
606
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
607
-			}
608
-			if (!$srcHeight) {
609
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
610
-			}
611
-		}
612
-	}
613
-
614
-	return array($srcHeight, $srcWidth);
556
+    static $largeur_img = array(), $hauteur_img = array();
557
+    $srcWidth = 0;
558
+    $srcHeight = 0;
559
+
560
+    $src = extraire_attribut($img, 'src');
561
+
562
+    if (!$src) {
563
+        $src = $img;
564
+    } else {
565
+        $srcWidth = extraire_attribut($img, 'width');
566
+        $srcHeight = extraire_attribut($img, 'height');
567
+    }
568
+
569
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
570
+    // la copie locale a toutes les chances d'etre la ou de resservir
571
+    if (tester_url_absolue($src)) {
572
+        include_spip('inc/distant');
573
+        $fichier = copie_locale($src);
574
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
575
+    }
576
+    if (($p = strpos($src, '?')) !== false) {
577
+        $src = substr($src, 0, $p);
578
+    }
579
+
580
+    $srcsize = false;
581
+    if (isset($largeur_img[$src]) and !$force_refresh) {
582
+        $srcWidth = $largeur_img[$src];
583
+    }
584
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
585
+        $srcHeight = $hauteur_img[$src];
586
+    }
587
+    if (!$srcWidth or !$srcHeight) {
588
+
589
+        if (file_exists($src)
590
+            and $srcsize = spip_getimagesize($src)
591
+        ) {
592
+            if (!$srcWidth) {
593
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
594
+            }
595
+            if (!$srcHeight) {
596
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
597
+            }
598
+        }
599
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
600
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
601
+        elseif (@file_exists($f = "$src.src")
602
+            and lire_fichier($f, $valeurs)
603
+            and $valeurs = unserialize($valeurs)
604
+        ) {
605
+            if (!$srcWidth) {
606
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
607
+            }
608
+            if (!$srcHeight) {
609
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
610
+            }
611
+        }
612
+    }
613
+
614
+    return array($srcHeight, $srcWidth);
615 615
 }
616 616
 
617 617
 
@@ -629,12 +629,12 @@  discard block
 block discarded – undo
629 629
  *     Largeur en pixels, NULL ou 0 si aucune image.
630 630
  **/
631 631
 function largeur($img) {
632
-	if (!$img) {
633
-		return;
634
-	}
635
-	list($h, $l) = taille_image($img);
632
+    if (!$img) {
633
+        return;
634
+    }
635
+    list($h, $l) = taille_image($img);
636 636
 
637
-	return $l;
637
+    return $l;
638 638
 }
639 639
 
640 640
 /**
@@ -651,12 +651,12 @@  discard block
 block discarded – undo
651 651
  *     Hauteur en pixels, NULL ou 0 si aucune image.
652 652
  **/
653 653
 function hauteur($img) {
654
-	if (!$img) {
655
-		return;
656
-	}
657
-	list($h, $l) = taille_image($img);
654
+    if (!$img) {
655
+        return;
656
+    }
657
+    list($h, $l) = taille_image($img);
658 658
 
659
-	return $h;
659
+    return $h;
660 660
 }
661 661
 
662 662
 
@@ -676,11 +676,11 @@  discard block
 block discarded – undo
676 676
  * @return string
677 677
  **/
678 678
 function corriger_entites_html($texte) {
679
-	if (strpos($texte, '&amp;') === false) {
680
-		return $texte;
681
-	}
679
+    if (strpos($texte, '&amp;') === false) {
680
+        return $texte;
681
+    }
682 682
 
683
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
683
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
684 684
 }
685 685
 
686 686
 /**
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
  * @return string
696 696
  **/
697 697
 function corriger_toutes_entites_html($texte) {
698
-	if (strpos($texte, '&amp;') === false) {
699
-		return $texte;
700
-	}
698
+    if (strpos($texte, '&amp;') === false) {
699
+        return $texte;
700
+    }
701 701
 
702
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
702
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
703 703
 }
704 704
 
705 705
 /**
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
  * @return string
710 710
  **/
711 711
 function proteger_amp($texte) {
712
-	return str_replace('&', '&amp;', $texte);
712
+    return str_replace('&', '&amp;', $texte);
713 713
 }
714 714
 
715 715
 
@@ -740,20 +740,20 @@  discard block
 block discarded – undo
740 740
  * @return mixed|string
741 741
  */
742 742
 function entites_html($texte, $tout = false, $quote = true) {
743
-	if (!is_string($texte) or !$texte
744
-		or strpbrk($texte, "&\"'<>") == false
745
-	) {
746
-		return $texte;
747
-	}
748
-	include_spip('inc/texte');
749
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
750
-	$flags |= ENT_HTML401;
751
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
752
-	if ($tout) {
753
-		return corriger_toutes_entites_html($texte);
754
-	} else {
755
-		return corriger_entites_html($texte);
756
-	}
743
+    if (!is_string($texte) or !$texte
744
+        or strpbrk($texte, "&\"'<>") == false
745
+    ) {
746
+        return $texte;
747
+    }
748
+    include_spip('inc/texte');
749
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
750
+    $flags |= ENT_HTML401;
751
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
752
+    if ($tout) {
753
+        return corriger_toutes_entites_html($texte);
754
+    } else {
755
+        return corriger_entites_html($texte);
756
+    }
757 757
 }
758 758
 
759 759
 /**
@@ -772,37 +772,37 @@  discard block
 block discarded – undo
772 772
  *     Texte converti
773 773
  **/
774 774
 function filtrer_entites($texte) {
775
-	if (strpos($texte, '&') === false) {
776
-		return $texte;
777
-	}
778
-	// filtrer
779
-	$texte = html2unicode($texte);
780
-	// remettre le tout dans le charset cible
781
-	$texte = unicode2charset($texte);
782
-	// cas particulier des " et ' qu'il faut filtrer aussi
783
-	// (on le faisait deja avec un &quot;)
784
-	if (strpos($texte, "&#") !== false) {
785
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
786
-	}
775
+    if (strpos($texte, '&') === false) {
776
+        return $texte;
777
+    }
778
+    // filtrer
779
+    $texte = html2unicode($texte);
780
+    // remettre le tout dans le charset cible
781
+    $texte = unicode2charset($texte);
782
+    // cas particulier des " et ' qu'il faut filtrer aussi
783
+    // (on le faisait deja avec un &quot;)
784
+    if (strpos($texte, "&#") !== false) {
785
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
786
+    }
787 787
 
788
-	return $texte;
788
+    return $texte;
789 789
 }
790 790
 
791 791
 
792 792
 if (!function_exists('filtre_filtrer_entites_dist')) {
793
-	/**
794
-	 * Version sécurisée de filtrer_entites
795
-	 * 
796
-	 * @uses interdire_scripts()
797
-	 * @uses filtrer_entites()
798
-	 * 
799
-	 * @param string $t
800
-	 * @return string
801
-	 */
802
-	function filtre_filtrer_entites_dist($t) {
803
-		include_spip('inc/texte');
804
-		return interdire_scripts(filtrer_entites($t));
805
-	}
793
+    /**
794
+     * Version sécurisée de filtrer_entites
795
+     * 
796
+     * @uses interdire_scripts()
797
+     * @uses filtrer_entites()
798
+     * 
799
+     * @param string $t
800
+     * @return string
801
+     */
802
+    function filtre_filtrer_entites_dist($t) {
803
+        include_spip('inc/texte');
804
+        return interdire_scripts(filtrer_entites($t));
805
+    }
806 806
 }
807 807
 
808 808
 
@@ -817,18 +817,18 @@  discard block
 block discarded – undo
817 817
  * @return string|array
818 818
  **/
819 819
 function supprimer_caracteres_illegaux($texte) {
820
-	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";
821
-	static $to = null;
820
+    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";
821
+    static $to = null;
822 822
 
823
-	if (is_array($texte)) {
824
-		return array_map('supprimer_caracteres_illegaux', $texte);
825
-	}
823
+    if (is_array($texte)) {
824
+        return array_map('supprimer_caracteres_illegaux', $texte);
825
+    }
826 826
 
827
-	if (!$to) {
828
-		$to = str_repeat('-', strlen($from));
829
-	}
827
+    if (!$to) {
828
+        $to = str_repeat('-', strlen($from));
829
+    }
830 830
 
831
-	return strtr($texte, $from, $to);
831
+    return strtr($texte, $from, $to);
832 832
 }
833 833
 
834 834
 /**
@@ -840,10 +840,10 @@  discard block
 block discarded – undo
840 840
  * @return string|array
841 841
  **/
842 842
 function corriger_caracteres($texte) {
843
-	$texte = corriger_caracteres_windows($texte);
844
-	$texte = supprimer_caracteres_illegaux($texte);
843
+    $texte = corriger_caracteres_windows($texte);
844
+    $texte = supprimer_caracteres_illegaux($texte);
845 845
 
846
-	return $texte;
846
+    return $texte;
847 847
 }
848 848
 
849 849
 /**
@@ -861,40 +861,40 @@  discard block
 block discarded – undo
861 861
  */
862 862
 function texte_backend($texte) {
863 863
 
864
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
864
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
865 865
 
866
-	// si on a des liens ou des images, les passer en absolu
867
-	$texte = liens_absolus($texte);
866
+    // si on a des liens ou des images, les passer en absolu
867
+    $texte = liens_absolus($texte);
868 868
 
869
-	// echapper les tags &gt; &lt;
870
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
869
+    // echapper les tags &gt; &lt;
870
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
871 871
 
872
-	// importer les &eacute;
873
-	$texte = filtrer_entites($texte);
872
+    // importer les &eacute;
873
+    $texte = filtrer_entites($texte);
874 874
 
875
-	// " -> &quot; et tout ce genre de choses
876
-	$u = $GLOBALS['meta']['pcre_u'];
877
-	$texte = str_replace("&nbsp;", " ", $texte);
878
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
879
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
880
-	$texte = entites_html($texte, false, false);
881
-	// mais bien echapper les double quotes !
882
-	$texte = str_replace('"', '&#034;', $texte);
875
+    // " -> &quot; et tout ce genre de choses
876
+    $u = $GLOBALS['meta']['pcre_u'];
877
+    $texte = str_replace("&nbsp;", " ", $texte);
878
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
879
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
880
+    $texte = entites_html($texte, false, false);
881
+    // mais bien echapper les double quotes !
882
+    $texte = str_replace('"', '&#034;', $texte);
883 883
 
884
-	// verifier le charset
885
-	$texte = charset2unicode($texte);
884
+    // verifier le charset
885
+    $texte = charset2unicode($texte);
886 886
 
887
-	// Caracteres problematiques en iso-latin 1
888
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
889
-		$texte = str_replace(chr(156), '&#156;', $texte);
890
-		$texte = str_replace(chr(140), '&#140;', $texte);
891
-		$texte = str_replace(chr(159), '&#159;', $texte);
892
-	}
887
+    // Caracteres problematiques en iso-latin 1
888
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
889
+        $texte = str_replace(chr(156), '&#156;', $texte);
890
+        $texte = str_replace(chr(140), '&#140;', $texte);
891
+        $texte = str_replace(chr(159), '&#159;', $texte);
892
+    }
893 893
 
894
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
895
-	// et le caractere apostrophe alourdit les squelettes avec PHP
896
-	// ==> on les remplace par l'entite HTML
897
-	return str_replace($apostrophe, "'", $texte);
894
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
895
+    // et le caractere apostrophe alourdit les squelettes avec PHP
896
+    // ==> on les remplace par l'entite HTML
897
+    return str_replace($apostrophe, "'", $texte);
898 898
 }
899 899
 
900 900
 /**
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
  *     Texte encodé et quote pour XML
912 912
  */
913 913
 function texte_backendq($texte) {
914
-	return addslashes(texte_backend($texte));
914
+    return addslashes(texte_backend($texte));
915 915
 }
916 916
 
917 917
 
@@ -934,9 +934,9 @@  discard block
 block discarded – undo
934 934
  *     Numéro de titre, sinon chaîne vide
935 935
  **/
936 936
 function supprimer_numero($texte) {
937
-	return preg_replace(
938
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
939
-		"", $texte);
937
+    return preg_replace(
938
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
939
+        "", $texte);
940 940
 }
941 941
 
942 942
 /**
@@ -959,13 +959,13 @@  discard block
 block discarded – undo
959 959
  *     Numéro de titre, sinon chaîne vide
960 960
  **/
961 961
 function recuperer_numero($texte) {
962
-	if (preg_match(
963
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
964
-		$texte, $regs)) {
965
-		return strval($regs[1]);
966
-	} else {
967
-		return '';
968
-	}
962
+    if (preg_match(
963
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
964
+        $texte, $regs)) {
965
+        return strval($regs[1]);
966
+    } else {
967
+        return '';
968
+    }
969 969
 }
970 970
 
971 971
 /**
@@ -992,13 +992,13 @@  discard block
 block discarded – undo
992 992
  *     Texte converti
993 993
  **/
994 994
 function supprimer_tags($texte, $rempl = "") {
995
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
996
-	// ne pas oublier un < final non ferme car coupe
997
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
998
-	// mais qui peut aussi etre un simple signe plus petit que
999
-	$texte = str_replace('<', '&lt;', $texte);
995
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
996
+    // ne pas oublier un < final non ferme car coupe
997
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
998
+    // mais qui peut aussi etre un simple signe plus petit que
999
+    $texte = str_replace('<', '&lt;', $texte);
1000 1000
 
1001
-	return $texte;
1001
+    return $texte;
1002 1002
 }
1003 1003
 
1004 1004
 /**
@@ -1021,9 +1021,9 @@  discard block
 block discarded – undo
1021 1021
  *     Texte converti
1022 1022
  **/
1023 1023
 function echapper_tags($texte, $rempl = "") {
1024
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1024
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1025 1025
 
1026
-	return $texte;
1026
+    return $texte;
1027 1027
 }
1028 1028
 
1029 1029
 /**
@@ -1044,18 +1044,18 @@  discard block
 block discarded – undo
1044 1044
  *     Texte converti
1045 1045
  **/
1046 1046
 function textebrut($texte) {
1047
-	$u = $GLOBALS['meta']['pcre_u'];
1048
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1049
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1050
-	$texte = preg_replace("/^\n+/", "", $texte);
1051
-	$texte = preg_replace("/\n+$/", "", $texte);
1052
-	$texte = preg_replace("/\n +/", "\n", $texte);
1053
-	$texte = supprimer_tags($texte);
1054
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1055
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1056
-	$texte = str_replace("&#8217;", "'", $texte);
1047
+    $u = $GLOBALS['meta']['pcre_u'];
1048
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1049
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1050
+    $texte = preg_replace("/^\n+/", "", $texte);
1051
+    $texte = preg_replace("/\n+$/", "", $texte);
1052
+    $texte = preg_replace("/\n +/", "\n", $texte);
1053
+    $texte = supprimer_tags($texte);
1054
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1055
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1056
+    $texte = str_replace("&#8217;", "'", $texte);
1057 1057
 
1058
-	return $texte;
1058
+    return $texte;
1059 1059
 }
1060 1060
 
1061 1061
 
@@ -1071,17 +1071,17 @@  discard block
 block discarded – undo
1071 1071
  *     Texte avec liens ouvrants
1072 1072
  **/
1073 1073
 function liens_ouvrants($texte) {
1074
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1075
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1076
-		foreach ($liens[0] as $a) {
1077
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1078
-			$ablank = inserer_attribut($a, 'rel', $rel);
1079
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1080
-			$texte = str_replace($a, $ablank, $texte);
1081
-		}
1082
-	}
1074
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1075
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1076
+        foreach ($liens[0] as $a) {
1077
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1078
+            $ablank = inserer_attribut($a, 'rel', $rel);
1079
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1080
+            $texte = str_replace($a, $ablank, $texte);
1081
+        }
1082
+    }
1083 1083
 
1084
-	return $texte;
1084
+    return $texte;
1085 1085
 }
1086 1086
 
1087 1087
 /**
@@ -1091,22 +1091,22 @@  discard block
 block discarded – undo
1091 1091
  * @return string
1092 1092
  */
1093 1093
 function liens_nofollow($texte) {
1094
-	if (stripos($texte, "<a") === false) {
1095
-		return $texte;
1096
-	}
1094
+    if (stripos($texte, "<a") === false) {
1095
+        return $texte;
1096
+    }
1097 1097
 
1098
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1099
-		foreach ($regs[0] as $a) {
1100
-			$rel = extraire_attribut($a, "rel");
1101
-			if (strpos($rel, "nofollow") === false) {
1102
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1103
-				$anofollow = inserer_attribut($a, "rel", $rel);
1104
-				$texte = str_replace($a, $anofollow, $texte);
1105
-			}
1106
-		}
1107
-	}
1098
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1099
+        foreach ($regs[0] as $a) {
1100
+            $rel = extraire_attribut($a, "rel");
1101
+            if (strpos($rel, "nofollow") === false) {
1102
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1103
+                $anofollow = inserer_attribut($a, "rel", $rel);
1104
+                $texte = str_replace($a, $anofollow, $texte);
1105
+            }
1106
+        }
1107
+    }
1108 1108
 
1109
-	return $texte;
1109
+    return $texte;
1110 1110
 }
1111 1111
 
1112 1112
 /**
@@ -1125,12 +1125,12 @@  discard block
 block discarded – undo
1125 1125
  *     Texte sans paraghaphes
1126 1126
  **/
1127 1127
 function PtoBR($texte) {
1128
-	$u = $GLOBALS['meta']['pcre_u'];
1129
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1130
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1131
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1128
+    $u = $GLOBALS['meta']['pcre_u'];
1129
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1130
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1131
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1132 1132
 
1133
-	return $texte;
1133
+    return $texte;
1134 1134
 }
1135 1135
 
1136 1136
 
@@ -1154,14 +1154,14 @@  discard block
 block discarded – undo
1154 1154
  * @return string Texte encadré du style CSS
1155 1155
  */
1156 1156
 function lignes_longues($texte) {
1157
-	if (!strlen(trim($texte))) {
1158
-		return $texte;
1159
-	}
1160
-	include_spip('inc/texte');
1161
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1162
-		'div' : 'span';
1157
+    if (!strlen(trim($texte))) {
1158
+        return $texte;
1159
+    }
1160
+    include_spip('inc/texte');
1161
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1162
+        'div' : 'span';
1163 1163
 
1164
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1164
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1165 1165
 }
1166 1166
 
1167 1167
 /**
@@ -1180,30 +1180,30 @@  discard block
 block discarded – undo
1180 1180
  * @return string Texte en majuscule
1181 1181
  */
1182 1182
 function majuscules($texte) {
1183
-	if (!strlen($texte)) {
1184
-		return '';
1185
-	}
1183
+    if (!strlen($texte)) {
1184
+        return '';
1185
+    }
1186 1186
 
1187
-	// Cas du turc
1188
-	if ($GLOBALS['spip_lang'] == 'tr') {
1189
-		# remplacer hors des tags et des entites
1190
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1191
-			foreach ($regs as $n => $match) {
1192
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1193
-			}
1194
-		}
1187
+    // Cas du turc
1188
+    if ($GLOBALS['spip_lang'] == 'tr') {
1189
+        # remplacer hors des tags et des entites
1190
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1191
+            foreach ($regs as $n => $match) {
1192
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1193
+            }
1194
+        }
1195 1195
 
1196
-		$texte = str_replace('i', '&#304;', $texte);
1196
+        $texte = str_replace('i', '&#304;', $texte);
1197 1197
 
1198
-		if ($regs) {
1199
-			foreach ($regs as $n => $match) {
1200
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1201
-			}
1202
-		}
1203
-	}
1198
+        if ($regs) {
1199
+            foreach ($regs as $n => $match) {
1200
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1201
+            }
1202
+        }
1203
+    }
1204 1204
 
1205
-	// Cas general
1206
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1205
+    // Cas general
1206
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1207 1207
 }
1208 1208
 
1209 1209
 /**
@@ -1221,29 +1221,29 @@  discard block
 block discarded – undo
1221 1221
  * @return string
1222 1222
  **/
1223 1223
 function taille_en_octets($taille) {
1224
-	if (!defined('_KILOBYTE')) {
1225
-		/**
1226
-		 * Définit le nombre d'octets dans un Kilobyte
1227
-		 *
1228
-		 * @var int
1229
-		 **/
1230
-		define('_KILOBYTE', 1024);
1231
-	}
1224
+    if (!defined('_KILOBYTE')) {
1225
+        /**
1226
+         * Définit le nombre d'octets dans un Kilobyte
1227
+         *
1228
+         * @var int
1229
+         **/
1230
+        define('_KILOBYTE', 1024);
1231
+    }
1232 1232
 
1233
-	if ($taille < 1) {
1234
-		return '';
1235
-	}
1236
-	if ($taille < _KILOBYTE) {
1237
-		$taille = _T('taille_octets', array('taille' => $taille));
1238
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1239
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1240
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1241
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1242
-	} else {
1243
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1244
-	}
1233
+    if ($taille < 1) {
1234
+        return '';
1235
+    }
1236
+    if ($taille < _KILOBYTE) {
1237
+        $taille = _T('taille_octets', array('taille' => $taille));
1238
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1239
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1240
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1241
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1242
+    } else {
1243
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1244
+    }
1245 1245
 
1246
-	return $taille;
1246
+    return $taille;
1247 1247
 }
1248 1248
 
1249 1249
 
@@ -1265,15 +1265,15 @@  discard block
 block discarded – undo
1265 1265
  *     Texte prêt pour être utilisé en attribut HTML
1266 1266
  **/
1267 1267
 function attribut_html($texte, $textebrut = true) {
1268
-	$u = $GLOBALS['meta']['pcre_u'];
1269
-	if ($textebrut) {
1270
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1271
-	}
1272
-	$texte = texte_backend($texte);
1273
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1268
+    $u = $GLOBALS['meta']['pcre_u'];
1269
+    if ($textebrut) {
1270
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1271
+    }
1272
+    $texte = texte_backend($texte);
1273
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1274 1274
 
1275
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1276
-		$texte);
1275
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1276
+        $texte);
1277 1277
 }
1278 1278
 
1279 1279
 
@@ -1293,12 +1293,12 @@  discard block
 block discarded – undo
1293 1293
  *     URL ou chaîne vide
1294 1294
  **/
1295 1295
 function vider_url($url, $entites = true) {
1296
-	# un message pour abs_url
1297
-	$GLOBALS['mode_abs_url'] = 'url';
1298
-	$url = trim($url);
1299
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1296
+    # un message pour abs_url
1297
+    $GLOBALS['mode_abs_url'] = 'url';
1298
+    $url = trim($url);
1299
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1300 1300
 
1301
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1301
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1302 1302
 }
1303 1303
 
1304 1304
 
@@ -1313,10 +1313,10 @@  discard block
 block discarded – undo
1313 1313
  * @return string Adresse email maquillée
1314 1314
  **/
1315 1315
 function antispam($texte) {
1316
-	include_spip('inc/acces');
1317
-	$masque = creer_pass_aleatoire(3);
1316
+    include_spip('inc/acces');
1317
+    $masque = creer_pass_aleatoire(3);
1318 1318
 
1319
-	return preg_replace("/@/", " $masque ", $texte);
1319
+    return preg_replace("/@/", " $masque ", $texte);
1320 1320
 }
1321 1321
 
1322 1322
 /**
@@ -1348,12 +1348,12 @@  discard block
 block discarded – undo
1348 1348
  *     True si on a le droit d'accès, false sinon.
1349 1349
  **/
1350 1350
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1351
-	include_spip('inc/acces');
1352
-	if ($op) {
1353
-		$dir .= " $op $args";
1354
-	}
1351
+    include_spip('inc/acces');
1352
+    if ($op) {
1353
+        $dir .= " $op $args";
1354
+    }
1355 1355
 
1356
-	return verifier_low_sec($id_auteur, $cle, $dir);
1356
+    return verifier_low_sec($id_auteur, $cle, $dir);
1357 1357
 }
1358 1358
 
1359 1359
 /**
@@ -1378,11 +1378,11 @@  discard block
 block discarded – undo
1378 1378
  *     Retourne $texte, sinon $sinon.
1379 1379
  **/
1380 1380
 function sinon($texte, $sinon = '') {
1381
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1382
-		return $texte;
1383
-	} else {
1384
-		return $sinon;
1385
-	}
1381
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1382
+        return $texte;
1383
+    } else {
1384
+        return $sinon;
1385
+    }
1386 1386
 }
1387 1387
 
1388 1388
 /**
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
  * @return mixed
1407 1407
  **/
1408 1408
 function choixsivide($a, $vide, $pasvide) {
1409
-	return $a ? $pasvide : $vide;
1409
+    return $a ? $pasvide : $vide;
1410 1410
 }
1411 1411
 
1412 1412
 /**
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
  * @return mixed
1431 1431
  **/
1432 1432
 function choixsiegal($a1, $a2, $v, $f) {
1433
-	return ($a1 == $a2) ? $v : $f;
1433
+    return ($a1 == $a2) ? $v : $f;
1434 1434
 }
1435 1435
 
1436 1436
 //
@@ -1449,13 +1449,13 @@  discard block
 block discarded – undo
1449 1449
  * @return string
1450 1450
  **/
1451 1451
 function filtrer_ical($texte) {
1452
-	#include_spip('inc/charsets');
1453
-	$texte = html2unicode($texte);
1454
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1455
-	$texte = preg_replace("/\n/", " ", $texte);
1456
-	$texte = preg_replace("/,/", "\,", $texte);
1452
+    #include_spip('inc/charsets');
1453
+    $texte = html2unicode($texte);
1454
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1455
+    $texte = preg_replace("/\n/", " ", $texte);
1456
+    $texte = preg_replace("/,/", "\,", $texte);
1457 1457
 
1458
-	return $texte;
1458
+    return $texte;
1459 1459
 }
1460 1460
 
1461 1461
 
@@ -1480,53 +1480,53 @@  discard block
 block discarded – undo
1480 1480
  * @return string
1481 1481
  **/
1482 1482
 function post_autobr($texte, $delim = "\n_ ") {
1483
-	if (!function_exists('echappe_html')) {
1484
-		include_spip('inc/texte_mini');
1485
-	}
1486
-	$texte = str_replace("\r\n", "\r", $texte);
1487
-	$texte = str_replace("\r", "\n", $texte);
1488
-
1489
-	if (preg_match(",\n+$,", $texte, $fin)) {
1490
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1491
-	} else {
1492
-		$fin = '';
1493
-	}
1494
-
1495
-	$texte = echappe_html($texte, '', true);
1496
-
1497
-	// echapper les modeles
1498
-	if (strpos($texte, "<") !== false) {
1499
-		include_spip('inc/lien');
1500
-		if (defined('_PREG_MODELE')) {
1501
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1502
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1503
-		}
1504
-	}
1505
-
1506
-	$debut = '';
1507
-	$suite = $texte;
1508
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1509
-		$debut .= substr($suite, 0, $t - 1);
1510
-		$suite = substr($suite, $t);
1511
-		$car = substr($suite, 0, 1);
1512
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1513
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1514
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1515
-		) {
1516
-			$debut .= $delim;
1517
-		} else {
1518
-			$debut .= "\n";
1519
-		}
1520
-		if (preg_match(",^\n+,", $suite, $regs)) {
1521
-			$debut .= $regs[0];
1522
-			$suite = substr($suite, strlen($regs[0]));
1523
-		}
1524
-	}
1525
-	$texte = $debut . $suite;
1526
-
1527
-	$texte = echappe_retour($texte);
1528
-
1529
-	return $texte . $fin;
1483
+    if (!function_exists('echappe_html')) {
1484
+        include_spip('inc/texte_mini');
1485
+    }
1486
+    $texte = str_replace("\r\n", "\r", $texte);
1487
+    $texte = str_replace("\r", "\n", $texte);
1488
+
1489
+    if (preg_match(",\n+$,", $texte, $fin)) {
1490
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1491
+    } else {
1492
+        $fin = '';
1493
+    }
1494
+
1495
+    $texte = echappe_html($texte, '', true);
1496
+
1497
+    // echapper les modeles
1498
+    if (strpos($texte, "<") !== false) {
1499
+        include_spip('inc/lien');
1500
+        if (defined('_PREG_MODELE')) {
1501
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1502
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1503
+        }
1504
+    }
1505
+
1506
+    $debut = '';
1507
+    $suite = $texte;
1508
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1509
+        $debut .= substr($suite, 0, $t - 1);
1510
+        $suite = substr($suite, $t);
1511
+        $car = substr($suite, 0, 1);
1512
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1513
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1514
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1515
+        ) {
1516
+            $debut .= $delim;
1517
+        } else {
1518
+            $debut .= "\n";
1519
+        }
1520
+        if (preg_match(",^\n+,", $suite, $regs)) {
1521
+            $debut .= $regs[0];
1522
+            $suite = substr($suite, strlen($regs[0]));
1523
+        }
1524
+    }
1525
+    $texte = $debut . $suite;
1526
+
1527
+    $texte = echappe_retour($texte);
1528
+
1529
+    return $texte . $fin;
1530 1530
 }
1531 1531
 
1532 1532
 
@@ -1567,46 +1567,46 @@  discard block
 block discarded – undo
1567 1567
  * @return string
1568 1568
  **/
1569 1569
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1570
-	static $traduire = false;
1571
-	if ($letexte
1572
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1573
-	) {
1574
-		if (!$traduire) {
1575
-			$traduire = charger_fonction('traduire', 'inc');
1576
-			include_spip('inc/lang');
1577
-		}
1578
-		if (!$lang) {
1579
-			$lang = $GLOBALS['spip_lang'];
1580
-		}
1581
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1582
-		if (is_bool($options)) {
1583
-			$options = array('echappe_span' => $options);
1584
-		}
1585
-		if (!isset($options['echappe_span'])) {
1586
-			$options = array_merge($options, array('echappe_span' => false));
1587
-		}
1588
-
1589
-		foreach ($regs as $reg) {
1590
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1591
-			$desc = $traduire($cle, $lang, true);
1592
-			$l = $desc->langue;
1593
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1594
-			if (strlen($desc->texte)) {
1595
-				$trad = code_echappement($desc->texte, 'idiome', false);
1596
-				if ($l !== $lang) {
1597
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1598
-				}
1599
-				if (lang_dir($l) !== lang_dir($lang)) {
1600
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1601
-				}
1602
-				if (!$options['echappe_span']) {
1603
-					$trad = echappe_retour($trad, 'idiome');
1604
-				}
1605
-				$letexte = str_replace($reg[0], $trad, $letexte);
1606
-			}
1607
-		}
1608
-	}
1609
-	return $letexte;
1570
+    static $traduire = false;
1571
+    if ($letexte
1572
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1573
+    ) {
1574
+        if (!$traduire) {
1575
+            $traduire = charger_fonction('traduire', 'inc');
1576
+            include_spip('inc/lang');
1577
+        }
1578
+        if (!$lang) {
1579
+            $lang = $GLOBALS['spip_lang'];
1580
+        }
1581
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1582
+        if (is_bool($options)) {
1583
+            $options = array('echappe_span' => $options);
1584
+        }
1585
+        if (!isset($options['echappe_span'])) {
1586
+            $options = array_merge($options, array('echappe_span' => false));
1587
+        }
1588
+
1589
+        foreach ($regs as $reg) {
1590
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1591
+            $desc = $traduire($cle, $lang, true);
1592
+            $l = $desc->langue;
1593
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1594
+            if (strlen($desc->texte)) {
1595
+                $trad = code_echappement($desc->texte, 'idiome', false);
1596
+                if ($l !== $lang) {
1597
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1598
+                }
1599
+                if (lang_dir($l) !== lang_dir($lang)) {
1600
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1601
+                }
1602
+                if (!$options['echappe_span']) {
1603
+                    $trad = echappe_retour($trad, 'idiome');
1604
+                }
1605
+                $letexte = str_replace($reg[0], $trad, $letexte);
1606
+            }
1607
+        }
1608
+    }
1609
+    return $letexte;
1610 1610
 }
1611 1611
 
1612 1612
 /**
@@ -1658,64 +1658,64 @@  discard block
 block discarded – undo
1658 1658
  **/
1659 1659
 function extraire_multi($letexte, $lang = null, $options = array()) {
1660 1660
 
1661
-	if ($letexte
1662
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1663
-	) {
1664
-		if (!$lang) {
1665
-			$lang = $GLOBALS['spip_lang'];
1666
-		}
1667
-
1668
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1669
-		if (is_bool($options)) {
1670
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1671
-		}
1672
-		if (!isset($options['echappe_span'])) {
1673
-			$options = array_merge($options, array('echappe_span' => false));
1674
-		}
1675
-		if (!isset($options['lang_defaut'])) {
1676
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1677
-		}
1678
-
1679
-		include_spip('inc/lang');
1680
-		foreach ($regs as $reg) {
1681
-			// chercher la version de la langue courante
1682
-			$trads = extraire_trads($reg[1]);
1683
-			if ($l = approcher_langue($trads, $lang)) {
1684
-				$trad = $trads[$l];
1685
-			} else {
1686
-				if ($options['lang_defaut'] == 'aucune') {
1687
-					$trad = '';
1688
-				} else {
1689
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1690
-					// ou la premiere dispo
1691
-					// mais typographier le texte selon les regles de celle-ci
1692
-					// Attention aux blocs multi sur plusieurs lignes
1693
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1694
-						$l = key($trads);
1695
-					}
1696
-					$trad = $trads[$l];
1697
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1698
-					$trad = $typographie($trad);
1699
-					// Tester si on echappe en span ou en div
1700
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1701
-					include_spip('inc/texte');
1702
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1703
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1704
-					$trad = code_echappement($trad, 'multi', false, $mode);
1705
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1706
-					if (lang_dir($l) !== lang_dir($lang)) {
1707
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1708
-					}
1709
-					if (!$options['echappe_span']) {
1710
-						$trad = echappe_retour($trad, 'multi');
1711
-					}
1712
-				}
1713
-			}
1714
-			$letexte = str_replace($reg[0], $trad, $letexte);
1715
-		}
1716
-	}
1717
-
1718
-	return $letexte;
1661
+    if ($letexte
1662
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1663
+    ) {
1664
+        if (!$lang) {
1665
+            $lang = $GLOBALS['spip_lang'];
1666
+        }
1667
+
1668
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1669
+        if (is_bool($options)) {
1670
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1671
+        }
1672
+        if (!isset($options['echappe_span'])) {
1673
+            $options = array_merge($options, array('echappe_span' => false));
1674
+        }
1675
+        if (!isset($options['lang_defaut'])) {
1676
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1677
+        }
1678
+
1679
+        include_spip('inc/lang');
1680
+        foreach ($regs as $reg) {
1681
+            // chercher la version de la langue courante
1682
+            $trads = extraire_trads($reg[1]);
1683
+            if ($l = approcher_langue($trads, $lang)) {
1684
+                $trad = $trads[$l];
1685
+            } else {
1686
+                if ($options['lang_defaut'] == 'aucune') {
1687
+                    $trad = '';
1688
+                } else {
1689
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1690
+                    // ou la premiere dispo
1691
+                    // mais typographier le texte selon les regles de celle-ci
1692
+                    // Attention aux blocs multi sur plusieurs lignes
1693
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1694
+                        $l = key($trads);
1695
+                    }
1696
+                    $trad = $trads[$l];
1697
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1698
+                    $trad = $typographie($trad);
1699
+                    // Tester si on echappe en span ou en div
1700
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1701
+                    include_spip('inc/texte');
1702
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1703
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1704
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1705
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1706
+                    if (lang_dir($l) !== lang_dir($lang)) {
1707
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1708
+                    }
1709
+                    if (!$options['echappe_span']) {
1710
+                        $trad = echappe_retour($trad, 'multi');
1711
+                    }
1712
+                }
1713
+            }
1714
+            $letexte = str_replace($reg[0], $trad, $letexte);
1715
+        }
1716
+    }
1717
+
1718
+    return $letexte;
1719 1719
 }
1720 1720
 
1721 1721
 /**
@@ -1731,20 +1731,20 @@  discard block
 block discarded – undo
1731 1731
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1732 1732
  **/
1733 1733
 function extraire_trads($bloc) {
1734
-	$lang = '';
1734
+    $lang = '';
1735 1735
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1736 1736
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1737
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1738
-		$texte = trim($regs[1]);
1739
-		if ($texte or $lang) {
1740
-			$trads[$lang] = $texte;
1741
-		}
1742
-		$bloc = substr($bloc, strlen($regs[0]));
1743
-		$lang = $regs[2];
1744
-	}
1745
-	$trads[$lang] = $bloc;
1737
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1738
+        $texte = trim($regs[1]);
1739
+        if ($texte or $lang) {
1740
+            $trads[$lang] = $texte;
1741
+        }
1742
+        $bloc = substr($bloc, strlen($regs[0]));
1743
+        $lang = $regs[2];
1744
+    }
1745
+    $trads[$lang] = $bloc;
1746 1746
 
1747
-	return $trads;
1747
+    return $trads;
1748 1748
 }
1749 1749
 
1750 1750
 
@@ -1755,7 +1755,7 @@  discard block
 block discarded – undo
1755 1755
  * @return string L'initiale en majuscule
1756 1756
  */
1757 1757
 function filtre_initiale($nom) {
1758
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1758
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1759 1759
 }
1760 1760
 
1761 1761
 
@@ -1800,33 +1800,33 @@  discard block
 block discarded – undo
1800 1800
  *      - null (interne) : si on empile
1801 1801
  **/
1802 1802
 function unique($donnee, $famille = '', $cpt = false) {
1803
-	static $mem = array();
1804
-	// permettre de vider la pile et de la restaurer
1805
-	// pour le calcul de introduction...
1806
-	if ($famille == '_spip_raz_') {
1807
-		$tmp = $mem;
1808
-		$mem = array();
1809
-
1810
-		return $tmp;
1811
-	} elseif ($famille == '_spip_set_') {
1812
-		$mem = $donnee;
1813
-
1814
-		return;
1815
-	}
1816
-	// eviter une notice
1817
-	if (!isset($mem[$famille])) {
1818
-		$mem[$famille] = array();
1819
-	}
1820
-	if ($cpt) {
1821
-		return count($mem[$famille]);
1822
-	}
1823
-	// eviter une notice
1824
-	if (!isset($mem[$famille][$donnee])) {
1825
-		$mem[$famille][$donnee] = 0;
1826
-	}
1827
-	if (!($mem[$famille][$donnee]++)) {
1828
-		return $donnee;
1829
-	}
1803
+    static $mem = array();
1804
+    // permettre de vider la pile et de la restaurer
1805
+    // pour le calcul de introduction...
1806
+    if ($famille == '_spip_raz_') {
1807
+        $tmp = $mem;
1808
+        $mem = array();
1809
+
1810
+        return $tmp;
1811
+    } elseif ($famille == '_spip_set_') {
1812
+        $mem = $donnee;
1813
+
1814
+        return;
1815
+    }
1816
+    // eviter une notice
1817
+    if (!isset($mem[$famille])) {
1818
+        $mem[$famille] = array();
1819
+    }
1820
+    if ($cpt) {
1821
+        return count($mem[$famille]);
1822
+    }
1823
+    // eviter une notice
1824
+    if (!isset($mem[$famille][$donnee])) {
1825
+        $mem[$famille][$donnee] = 0;
1826
+    }
1827
+    if (!($mem[$famille][$donnee]++)) {
1828
+        return $donnee;
1829
+    }
1830 1830
 }
1831 1831
 
1832 1832
 
@@ -1854,18 +1854,18 @@  discard block
 block discarded – undo
1854 1854
  *     Une des valeurs en fonction du compteur.
1855 1855
  **/
1856 1856
 function alterner($i) {
1857
-	// recuperer les arguments (attention fonctions un peu space)
1858
-	$num = func_num_args();
1859
-	$args = func_get_args();
1857
+    // recuperer les arguments (attention fonctions un peu space)
1858
+    $num = func_num_args();
1859
+    $args = func_get_args();
1860 1860
 
1861
-	if ($num == 2 && is_array($args[1])) {
1862
-		$args = $args[1];
1863
-		array_unshift($args, '');
1864
-		$num = count($args);
1865
-	}
1861
+    if ($num == 2 && is_array($args[1])) {
1862
+        $args = $args[1];
1863
+        array_unshift($args, '');
1864
+        $num = count($args);
1865
+    }
1866 1866
 
1867
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1868
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1867
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1868
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1869 1869
 }
1870 1870
 
1871 1871
 
@@ -1890,46 +1890,46 @@  discard block
 block discarded – undo
1890 1890
  *     - Tableau complet (si 2e argument)
1891 1891
  **/
1892 1892
 function extraire_attribut($balise, $attribut, $complet = false) {
1893
-	if (is_array($balise)) {
1894
-		array_walk(
1895
-			$balise,
1896
-			function(&$a, $key, $t){
1897
-				$a = extraire_attribut($a, $t);
1898
-			},
1899
-			$attribut
1900
-		);
1901
-
1902
-		return $balise;
1903
-	}
1904
-	if (preg_match(
1905
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1906
-		. $attribut
1907
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1908
-
1909
-		$balise, $r)) {
1910
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1911
-			$r[4] = substr($r[3], 1, -1);
1912
-			$r[3] = $r[3][0];
1913
-		} elseif ($r[3] !== '') {
1914
-			$r[4] = $r[3];
1915
-			$r[3] = '';
1916
-		} else {
1917
-			$r[4] = trim($r[2]);
1918
-		}
1919
-		$att = $r[4];
1920
-		if (strpos($att, "&#") !== false) {
1921
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1922
-		}
1923
-		$att = filtrer_entites($att);
1924
-	} else {
1925
-		$att = null;
1926
-	}
1927
-
1928
-	if ($complet) {
1929
-		return array($att, $r);
1930
-	} else {
1931
-		return $att;
1932
-	}
1893
+    if (is_array($balise)) {
1894
+        array_walk(
1895
+            $balise,
1896
+            function(&$a, $key, $t){
1897
+                $a = extraire_attribut($a, $t);
1898
+            },
1899
+            $attribut
1900
+        );
1901
+
1902
+        return $balise;
1903
+    }
1904
+    if (preg_match(
1905
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1906
+        . $attribut
1907
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1908
+
1909
+        $balise, $r)) {
1910
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1911
+            $r[4] = substr($r[3], 1, -1);
1912
+            $r[3] = $r[3][0];
1913
+        } elseif ($r[3] !== '') {
1914
+            $r[4] = $r[3];
1915
+            $r[3] = '';
1916
+        } else {
1917
+            $r[4] = trim($r[2]);
1918
+        }
1919
+        $att = $r[4];
1920
+        if (strpos($att, "&#") !== false) {
1921
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1922
+        }
1923
+        $att = filtrer_entites($att);
1924
+    } else {
1925
+        $att = null;
1926
+    }
1927
+
1928
+    if ($complet) {
1929
+        return array($att, $r);
1930
+    } else {
1931
+        return $att;
1932
+    }
1933 1933
 }
1934 1934
 
1935 1935
 /**
@@ -1961,37 +1961,37 @@  discard block
 block discarded – undo
1961 1961
  *     Code html modifié
1962 1962
  **/
1963 1963
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1964
-	// preparer l'attribut
1965
-	// supprimer les &nbsp; etc mais pas les balises html
1966
-	// qui ont un sens dans un attribut value d'un input
1967
-	if ($proteger) {
1968
-		$val = attribut_html($val, false);
1969
-	}
1970
-
1971
-	// echapper les ' pour eviter tout bug
1972
-	$val = str_replace("'", "&#039;", $val);
1973
-	if ($vider and strlen($val) == 0) {
1974
-		$insert = '';
1975
-	} else {
1976
-		$insert = " $attribut='$val'";
1977
-	}
1978
-
1979
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1980
-
1981
-	if ($old !== null) {
1982
-		// Remplacer l'ancien attribut du meme nom
1983
-		$balise = $r[1] . $insert . $r[5];
1984
-	} else {
1985
-		// preferer une balise " />" (comme <img />)
1986
-		if (preg_match(',/>,', $balise)) {
1987
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1988
-		} // sinon une balise <a ...> ... </a>
1989
-		else {
1990
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1991
-		}
1992
-	}
1993
-
1994
-	return $balise;
1964
+    // preparer l'attribut
1965
+    // supprimer les &nbsp; etc mais pas les balises html
1966
+    // qui ont un sens dans un attribut value d'un input
1967
+    if ($proteger) {
1968
+        $val = attribut_html($val, false);
1969
+    }
1970
+
1971
+    // echapper les ' pour eviter tout bug
1972
+    $val = str_replace("'", "&#039;", $val);
1973
+    if ($vider and strlen($val) == 0) {
1974
+        $insert = '';
1975
+    } else {
1976
+        $insert = " $attribut='$val'";
1977
+    }
1978
+
1979
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1980
+
1981
+    if ($old !== null) {
1982
+        // Remplacer l'ancien attribut du meme nom
1983
+        $balise = $r[1] . $insert . $r[5];
1984
+    } else {
1985
+        // preferer une balise " />" (comme <img />)
1986
+        if (preg_match(',/>,', $balise)) {
1987
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1988
+        } // sinon une balise <a ...> ... </a>
1989
+        else {
1990
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1991
+        }
1992
+    }
1993
+
1994
+    return $balise;
1995 1995
 }
1996 1996
 
1997 1997
 /**
@@ -2009,7 +2009,7 @@  discard block
 block discarded – undo
2009 2009
  * @return string Code HTML sans l'attribut
2010 2010
  **/
2011 2011
 function vider_attribut($balise, $attribut) {
2012
-	return inserer_attribut($balise, $attribut, '', false, true);
2012
+    return inserer_attribut($balise, $attribut, '', false, true);
2013 2013
 }
2014 2014
 
2015 2015
 
@@ -2021,9 +2021,9 @@  discard block
 block discarded – undo
2021 2021
  * @return string
2022 2022
  */
2023 2023
 function tester_config($id, $mode = '') {
2024
-	include_spip('action/inscrire_auteur');
2024
+    include_spip('action/inscrire_auteur');
2025 2025
 
2026
-	return tester_statut_inscription($mode, $id);
2026
+    return tester_statut_inscription($mode, $id);
2027 2027
 }
2028 2028
 
2029 2029
 //
@@ -2048,7 +2048,7 @@  discard block
 block discarded – undo
2048 2048
  * @return int $a+$b
2049 2049
  **/
2050 2050
 function plus($a, $b) {
2051
-	return $a + $b;
2051
+    return $a + $b;
2052 2052
 }
2053 2053
 function strplus($a, $b) {return strize('plus', $a, $b);}
2054 2054
 /**
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
  * @return int $a-$b
2068 2068
  **/
2069 2069
 function moins($a, $b) {
2070
-	return $a - $b;
2070
+    return $a - $b;
2071 2071
 }
2072 2072
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2073 2073
 
@@ -2088,7 +2088,7 @@  discard block
 block discarded – undo
2088 2088
  * @return int $a*$b
2089 2089
  **/
2090 2090
 function mult($a, $b) {
2091
-	return $a * $b;
2091
+    return $a * $b;
2092 2092
 }
2093 2093
 function strmult($a, $b) {return strize('mult', $a, $b);}
2094 2094
 
@@ -2109,7 +2109,7 @@  discard block
 block discarded – undo
2109 2109
  * @return int $a/$b (ou 0 si $b est nul)
2110 2110
  **/
2111 2111
 function div($a, $b) {
2112
-	return $b ? $a / $b : 0;
2112
+    return $b ? $a / $b : 0;
2113 2113
 }
2114 2114
 function strdiv($a, $b) {return strize('div', $a, $b);}
2115 2115
 
@@ -2131,7 +2131,7 @@  discard block
 block discarded – undo
2131 2131
  * @return int ($nb % $mod) + $add
2132 2132
  **/
2133 2133
 function modulo($nb, $mod, $add = 0) {
2134
-	return ($mod ? $nb % $mod : 0) + $add;
2134
+    return ($mod ? $nb % $mod : 0) + $add;
2135 2135
 }
2136 2136
 
2137 2137
 
@@ -2146,24 +2146,24 @@  discard block
 block discarded – undo
2146 2146
  *      - true sinon
2147 2147
  **/
2148 2148
 function nom_acceptable($nom) {
2149
-	if (!is_string($nom)) {
2150
-		return false;
2151
-	}
2152
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2153
-		define('_TAGS_NOM_AUTEUR', '');
2154
-	}
2155
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2156
-	foreach ($tags_acceptes as $tag) {
2157
-		if (strlen($tag)) {
2158
-			$remp1[] = '<' . trim($tag) . '>';
2159
-			$remp1[] = '</' . trim($tag) . '>';
2160
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2161
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2162
-		}
2163
-	}
2164
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2149
+    if (!is_string($nom)) {
2150
+        return false;
2151
+    }
2152
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2153
+        define('_TAGS_NOM_AUTEUR', '');
2154
+    }
2155
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2156
+    foreach ($tags_acceptes as $tag) {
2157
+        if (strlen($tag)) {
2158
+            $remp1[] = '<' . trim($tag) . '>';
2159
+            $remp1[] = '</' . trim($tag) . '>';
2160
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2161
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2162
+        }
2163
+    }
2164
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2165 2165
 
2166
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2166
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2167 2167
 }
2168 2168
 
2169 2169
 
@@ -2177,29 +2177,29 @@  discard block
 block discarded – undo
2177 2177
  *      - la normalisation de la dernière adresse donnée sinon
2178 2178
  **/
2179 2179
 function email_valide($adresses) {
2180
-	// eviter d'injecter n'importe quoi dans preg_match
2181
-	if (!is_string($adresses)) {
2182
-		return false;
2183
-	}
2180
+    // eviter d'injecter n'importe quoi dans preg_match
2181
+    if (!is_string($adresses)) {
2182
+        return false;
2183
+    }
2184 2184
 
2185
-	// Si c'est un spammeur autant arreter tout de suite
2186
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2187
-		spip_log("Tentative d'injection de mail : $adresses");
2185
+    // Si c'est un spammeur autant arreter tout de suite
2186
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2187
+        spip_log("Tentative d'injection de mail : $adresses");
2188 2188
 
2189
-		return false;
2190
-	}
2189
+        return false;
2190
+    }
2191 2191
 
2192
-	foreach (explode(',', $adresses) as $v) {
2193
-		// nettoyer certains formats
2194
-		// "Marie Toto <[email protected]>"
2195
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2196
-		// RFC 822
2197
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2198
-			return false;
2199
-		}
2200
-	}
2192
+    foreach (explode(',', $adresses) as $v) {
2193
+        // nettoyer certains formats
2194
+        // "Marie Toto <[email protected]>"
2195
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2196
+        // RFC 822
2197
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2198
+            return false;
2199
+        }
2200
+    }
2201 2201
 
2202
-	return $adresse;
2202
+    return $adresse;
2203 2203
 }
2204 2204
 
2205 2205
 /**
@@ -2213,20 +2213,20 @@  discard block
 block discarded – undo
2213 2213
  * @return string Texte
2214 2214
  **/
2215 2215
 function afficher_enclosures($tags) {
2216
-	$s = array();
2217
-	foreach (extraire_balises($tags, 'a') as $tag) {
2218
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2219
-			and $t = extraire_attribut($tag, 'href')
2220
-		) {
2221
-			$s[] = preg_replace(',>[^<]+</a>,S',
2222
-				'>'
2223
-				. http_img_pack('attachment-16.png', $t,
2224
-					'title="' . attribut_html($t) . '"')
2225
-				. '</a>', $tag);
2226
-		}
2227
-	}
2216
+    $s = array();
2217
+    foreach (extraire_balises($tags, 'a') as $tag) {
2218
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2219
+            and $t = extraire_attribut($tag, 'href')
2220
+        ) {
2221
+            $s[] = preg_replace(',>[^<]+</a>,S',
2222
+                '>'
2223
+                . http_img_pack('attachment-16.png', $t,
2224
+                    'title="' . attribut_html($t) . '"')
2225
+                . '</a>', $tag);
2226
+        }
2227
+    }
2228 2228
 
2229
-	return join('&nbsp;', $s);
2229
+    return join('&nbsp;', $s);
2230 2230
 }
2231 2231
 
2232 2232
 /**
@@ -2241,15 +2241,15 @@  discard block
 block discarded – undo
2241 2241
  * @return string Liens trouvés
2242 2242
  **/
2243 2243
 function afficher_tags($tags, $rels = 'tag,directory') {
2244
-	$s = array();
2245
-	foreach (extraire_balises($tags, 'a') as $tag) {
2246
-		$rel = extraire_attribut($tag, 'rel');
2247
-		if (strstr(",$rels,", ",$rel,")) {
2248
-			$s[] = $tag;
2249
-		}
2250
-	}
2244
+    $s = array();
2245
+    foreach (extraire_balises($tags, 'a') as $tag) {
2246
+        $rel = extraire_attribut($tag, 'rel');
2247
+        if (strstr(",$rels,", ",$rel,")) {
2248
+            $s[] = $tag;
2249
+        }
2250
+    }
2251 2251
 
2252
-	return join(', ', $s);
2252
+    return join(', ', $s);
2253 2253
 }
2254 2254
 
2255 2255
 
@@ -2271,21 +2271,21 @@  discard block
 block discarded – undo
2271 2271
  * @return string Tag HTML `<a>` avec microformat.
2272 2272
  **/
2273 2273
 function enclosure2microformat($e) {
2274
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2275
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2276
-	}
2277
-	$type = extraire_attribut($e, 'type');
2278
-	if (!$length = extraire_attribut($e, 'length')) {
2279
-		# <media:content : longeur dans fileSize. On tente.
2280
-		$length = extraire_attribut($e, 'fileSize');
2281
-	}
2282
-	$fichier = basename($url);
2274
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2275
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2276
+    }
2277
+    $type = extraire_attribut($e, 'type');
2278
+    if (!$length = extraire_attribut($e, 'length')) {
2279
+        # <media:content : longeur dans fileSize. On tente.
2280
+        $length = extraire_attribut($e, 'fileSize');
2281
+    }
2282
+    $fichier = basename($url);
2283 2283
 
2284
-	return '<a rel="enclosure"'
2285
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2286
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2287
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2288
-	. '>' . $fichier . '</a>';
2284
+    return '<a rel="enclosure"'
2285
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2286
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2287
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2288
+    . '>' . $fichier . '</a>';
2289 2289
 }
2290 2290
 
2291 2291
 /**
@@ -2303,24 +2303,24 @@  discard block
 block discarded – undo
2303 2303
  * @return string Tags RSS `<enclosure>`.
2304 2304
  **/
2305 2305
 function microformat2enclosure($tags) {
2306
-	$enclosures = array();
2307
-	foreach (extraire_balises($tags, 'a') as $e) {
2308
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2309
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2310
-			$type = extraire_attribut($e, 'type');
2311
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2312
-				$length = intval(extraire_attribut($e, 'length'));
2313
-			} # vieux data
2314
-			$fichier = basename($url);
2315
-			$enclosures[] = '<enclosure'
2316
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2317
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2318
-				. ($length ? ' length="' . $length . '"' : '')
2319
-				. ' />';
2320
-		}
2321
-	}
2306
+    $enclosures = array();
2307
+    foreach (extraire_balises($tags, 'a') as $e) {
2308
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2309
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2310
+            $type = extraire_attribut($e, 'type');
2311
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2312
+                $length = intval(extraire_attribut($e, 'length'));
2313
+            } # vieux data
2314
+            $fichier = basename($url);
2315
+            $enclosures[] = '<enclosure'
2316
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2317
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2318
+                . ($length ? ' length="' . $length . '"' : '')
2319
+                . ' />';
2320
+        }
2321
+    }
2322 2322
 
2323
-	return join("\n", $enclosures);
2323
+    return join("\n", $enclosures);
2324 2324
 }
2325 2325
 
2326 2326
 
@@ -2336,16 +2336,16 @@  discard block
 block discarded – undo
2336 2336
  * @return string Tags RSS Atom `<dc:subject>`.
2337 2337
  **/
2338 2338
 function tags2dcsubject($tags) {
2339
-	$subjects = '';
2340
-	foreach (extraire_balises($tags, 'a') as $e) {
2341
-		if (extraire_attribut($e, rel) == 'tag') {
2342
-			$subjects .= '<dc:subject>'
2343
-				. texte_backend(textebrut($e))
2344
-				. '</dc:subject>' . "\n";
2345
-		}
2346
-	}
2339
+    $subjects = '';
2340
+    foreach (extraire_balises($tags, 'a') as $e) {
2341
+        if (extraire_attribut($e, rel) == 'tag') {
2342
+            $subjects .= '<dc:subject>'
2343
+                . texte_backend(textebrut($e))
2344
+                . '</dc:subject>' . "\n";
2345
+        }
2346
+    }
2347 2347
 
2348
-	return $subjects;
2348
+    return $subjects;
2349 2349
 }
2350 2350
 
2351 2351
 /**
@@ -2374,23 +2374,23 @@  discard block
 block discarded – undo
2374 2374
  *     - Tableau de résultats, si tableau en entrée.
2375 2375
  **/
2376 2376
 function extraire_balise($texte, $tag = 'a') {
2377
-	if (is_array($texte)) {
2378
-		array_walk(
2379
-			$texte,
2380
-			function(&$a, $key, $t){
2381
-				$a = extraire_balise($a, $t);
2382
-			},
2383
-			$tag
2384
-		);
2377
+    if (is_array($texte)) {
2378
+        array_walk(
2379
+            $texte,
2380
+            function(&$a, $key, $t){
2381
+                $a = extraire_balise($a, $t);
2382
+            },
2383
+            $tag
2384
+        );
2385 2385
 
2386
-		return $texte;
2387
-	}
2386
+        return $texte;
2387
+    }
2388 2388
 
2389
-	if (preg_match(
2390
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2391
-		$texte, $regs)) {
2392
-		return $regs[0];
2393
-	}
2389
+    if (preg_match(
2390
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2391
+        $texte, $regs)) {
2392
+        return $regs[0];
2393
+    }
2394 2394
 }
2395 2395
 
2396 2396
 /**
@@ -2418,25 +2418,25 @@  discard block
 block discarded – undo
2418 2418
  *     - Tableau de résultats, si tableau en entrée.
2419 2419
  **/
2420 2420
 function extraire_balises($texte, $tag = 'a') {
2421
-	if (is_array($texte)) {
2422
-		array_walk(
2423
-			$texte,
2424
-			function(&$a, $key, $t){
2425
-				$a = extraire_balises($a, $t);
2426
-			},
2427
-			$tag
2428
-		);
2421
+    if (is_array($texte)) {
2422
+        array_walk(
2423
+            $texte,
2424
+            function(&$a, $key, $t){
2425
+                $a = extraire_balises($a, $t);
2426
+            },
2427
+            $tag
2428
+        );
2429 2429
 
2430
-		return $texte;
2431
-	}
2430
+        return $texte;
2431
+    }
2432 2432
 
2433
-	if (preg_match_all(
2434
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2435
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2436
-		return $regs[0];
2437
-	} else {
2438
-		return array();
2439
-	}
2433
+    if (preg_match_all(
2434
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2435
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2436
+        return $regs[0];
2437
+    } else {
2438
+        return array();
2439
+    }
2440 2440
 }
2441 2441
 
2442 2442
 /**
@@ -2465,11 +2465,11 @@  discard block
 block discarded – undo
2465 2465
  *     - `$def` si on n'a pas transmis de tableau
2466 2466
  **/
2467 2467
 function in_any($val, $vals, $def = '') {
2468
-	if (!is_array($vals) and $v = unserialize($vals)) {
2469
-		$vals = $v;
2470
-	}
2468
+    if (!is_array($vals) and $v = unserialize($vals)) {
2469
+        $vals = $v;
2470
+    }
2471 2471
 
2472
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2472
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2473 2473
 }
2474 2474
 
2475 2475
 
@@ -2490,12 +2490,12 @@  discard block
 block discarded – undo
2490 2490
  *     Résultat du calcul
2491 2491
  **/
2492 2492
 function valeur_numerique($expr) {
2493
-	$a = 0;
2494
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2495
-		eval("\$a = $expr;");
2496
-	}
2493
+    $a = 0;
2494
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2495
+        eval("\$a = $expr;");
2496
+    }
2497 2497
 
2498
-	return intval($a);
2498
+    return intval($a);
2499 2499
 }
2500 2500
 
2501 2501
 /**
@@ -2514,7 +2514,7 @@  discard block
 block discarded – undo
2514 2514
  *      Retourne `$a*$b/$c`
2515 2515
  **/
2516 2516
 function regledetrois($a, $b, $c) {
2517
-	return round($a * $b / $c);
2517
+    return round($a * $b / $c);
2518 2518
 }
2519 2519
 
2520 2520
 
@@ -2538,76 +2538,76 @@  discard block
 block discarded – undo
2538 2538
  **/
2539 2539
 function form_hidden($action) {
2540 2540
 
2541
-	$contexte = array();
2542
-	include_spip('inc/urls');
2543
-	if ($p = urls_decoder_url($action, '')
2544
-		and reset($p)
2545
-	) {
2546
-		$fond = array_shift($p);
2547
-		if ($fond != '404') {
2548
-			$contexte = array_shift($p);
2549
-			$contexte['page'] = $fond;
2550
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2551
-		}
2552
-	}
2553
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2554
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2555
-		unset($contexte['type']);
2556
-	}
2557
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2558
-		unset($contexte['type-page']);
2559
-	}
2560
-
2561
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2562
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2563
-	$values = array();
2564
-
2565
-	// d'abord avec celles de l'url
2566
-	if (false !== ($p = strpos($action, '?'))) {
2567
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2568
-			$c = explode('=', $c, 2);
2569
-			$var = array_shift($c);
2570
-			$val = array_shift($c);
2571
-			if ($var) {
2572
-				$val = rawurldecode($val);
2573
-				$var = rawurldecode($var); // decoder les [] eventuels
2574
-				if (preg_match(',\[\]$,S', $var)) {
2575
-					$values[] = array($var, $val);
2576
-				} else {
2577
-					if (!isset($values[$var])) {
2578
-						$values[$var] = array($var, $val);
2579
-					}
2580
-				}
2581
-			}
2582
-		}
2583
-	}
2584
-
2585
-	// ensuite avec celles du contexte, sans doublonner !
2586
-	foreach ($contexte as $var => $val) {
2587
-		if (preg_match(',\[\]$,S', $var)) {
2588
-			$values[] = array($var, $val);
2589
-		} else {
2590
-			if (!isset($values[$var])) {
2591
-				$values[$var] = array($var, $val);
2592
-			}
2593
-		}
2594
-	}
2595
-
2596
-	// puis on rassemble le tout
2597
-	$hidden = array();
2598
-	foreach ($values as $value) {
2599
-		list($var, $val) = $value;
2600
-		$hidden[] = '<input name="'
2601
-			. entites_html($var)
2602
-			. '"'
2603
-			. (is_null($val)
2604
-				? ''
2605
-				: ' value="' . entites_html($val) . '"'
2606
-			)
2607
-			. ' type="hidden"' . "\n/>";
2608
-	}
2609
-
2610
-	return join("", $hidden);
2541
+    $contexte = array();
2542
+    include_spip('inc/urls');
2543
+    if ($p = urls_decoder_url($action, '')
2544
+        and reset($p)
2545
+    ) {
2546
+        $fond = array_shift($p);
2547
+        if ($fond != '404') {
2548
+            $contexte = array_shift($p);
2549
+            $contexte['page'] = $fond;
2550
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2551
+        }
2552
+    }
2553
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2554
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2555
+        unset($contexte['type']);
2556
+    }
2557
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2558
+        unset($contexte['type-page']);
2559
+    }
2560
+
2561
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2562
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2563
+    $values = array();
2564
+
2565
+    // d'abord avec celles de l'url
2566
+    if (false !== ($p = strpos($action, '?'))) {
2567
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2568
+            $c = explode('=', $c, 2);
2569
+            $var = array_shift($c);
2570
+            $val = array_shift($c);
2571
+            if ($var) {
2572
+                $val = rawurldecode($val);
2573
+                $var = rawurldecode($var); // decoder les [] eventuels
2574
+                if (preg_match(',\[\]$,S', $var)) {
2575
+                    $values[] = array($var, $val);
2576
+                } else {
2577
+                    if (!isset($values[$var])) {
2578
+                        $values[$var] = array($var, $val);
2579
+                    }
2580
+                }
2581
+            }
2582
+        }
2583
+    }
2584
+
2585
+    // ensuite avec celles du contexte, sans doublonner !
2586
+    foreach ($contexte as $var => $val) {
2587
+        if (preg_match(',\[\]$,S', $var)) {
2588
+            $values[] = array($var, $val);
2589
+        } else {
2590
+            if (!isset($values[$var])) {
2591
+                $values[$var] = array($var, $val);
2592
+            }
2593
+        }
2594
+    }
2595
+
2596
+    // puis on rassemble le tout
2597
+    $hidden = array();
2598
+    foreach ($values as $value) {
2599
+        list($var, $val) = $value;
2600
+        $hidden[] = '<input name="'
2601
+            . entites_html($var)
2602
+            . '"'
2603
+            . (is_null($val)
2604
+                ? ''
2605
+                : ' value="' . entites_html($val) . '"'
2606
+            )
2607
+            . ' type="hidden"' . "\n/>";
2608
+    }
2609
+
2610
+    return join("", $hidden);
2611 2611
 }
2612 2612
 
2613 2613
 /**
@@ -2625,15 +2625,15 @@  discard block
 block discarded – undo
2625 2625
  *     Liste (première page, dernière page).
2626 2626
  **/
2627 2627
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2628
-	if ($max <= 0 or $max >= $nombre) {
2629
-		return array(1, $nombre);
2630
-	}
2628
+    if ($max <= 0 or $max >= $nombre) {
2629
+        return array(1, $nombre);
2630
+    }
2631 2631
 
2632
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2633
-	$derniere = min($nombre, $premiere + $max - 2);
2634
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2632
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2633
+    $derniere = min($nombre, $premiere + $max - 2);
2634
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2635 2635
 
2636
-	return array($premiere, $derniere);
2636
+    return array($premiere, $derniere);
2637 2637
 }
2638 2638
 
2639 2639
 
@@ -2655,7 +2655,7 @@  discard block
 block discarded – undo
2655 2655
  *    - la première valeur du tableau sinon.
2656 2656
  **/
2657 2657
 function filtre_reset($array) {
2658
-	return !is_array($array) ? null : reset($array);
2658
+    return !is_array($array) ? null : reset($array);
2659 2659
 }
2660 2660
 
2661 2661
 /**
@@ -2676,7 +2676,7 @@  discard block
 block discarded – undo
2676 2676
  *    - la dernière valeur du tableau sinon.
2677 2677
  **/
2678 2678
 function filtre_end($array) {
2679
-	return !is_array($array) ? null : end($array);
2679
+    return !is_array($array) ? null : end($array);
2680 2680
 }
2681 2681
 
2682 2682
 /**
@@ -2696,11 +2696,11 @@  discard block
 block discarded – undo
2696 2696
  *
2697 2697
  **/
2698 2698
 function filtre_push($array, $val) {
2699
-	if (!is_array($array) or !array_push($array, $val)) {
2700
-		return '';
2701
-	}
2699
+    if (!is_array($array) or !array_push($array, $val)) {
2700
+        return '';
2701
+    }
2702 2702
 
2703
-	return $array;
2703
+    return $array;
2704 2704
 }
2705 2705
 
2706 2706
 /**
@@ -2719,7 +2719,7 @@  discard block
 block discarded – undo
2719 2719
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2720 2720
  **/
2721 2721
 function filtre_find($array, $val) {
2722
-	return (is_array($array) and in_array($val, $array));
2722
+    return (is_array($array) and in_array($val, $array));
2723 2723
 }
2724 2724
 
2725 2725
 
@@ -2754,59 +2754,59 @@  discard block
 block discarded – undo
2754 2754
  *     Code HTML de la pagination
2755 2755
  **/
2756 2756
 function filtre_pagination_dist(
2757
-	$total,
2758
-	$nom,
2759
-	$position,
2760
-	$pas,
2761
-	$liste = true,
2762
-	$modele = '',
2763
-	$connect = '',
2764
-	$env = array()
2757
+    $total,
2758
+    $nom,
2759
+    $position,
2760
+    $pas,
2761
+    $liste = true,
2762
+    $modele = '',
2763
+    $connect = '',
2764
+    $env = array()
2765 2765
 ) {
2766
-	static $ancres = array();
2767
-	if ($pas < 1) {
2768
-		return '';
2769
-	}
2770
-	$ancre = 'pagination' . $nom; // #pagination_articles
2771
-	$debut = 'debut' . $nom; // 'debut_articles'
2772
-
2773
-	// n'afficher l'ancre qu'une fois
2774
-	if (!isset($ancres[$ancre])) {
2775
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2776
-	} else {
2777
-		$bloc_ancre = '';
2778
-	}
2779
-	// liste = false : on ne veut que l'ancre
2780
-	if (!$liste) {
2781
-		return $ancres[$ancre];
2782
-	}
2783
-
2784
-	$self = (empty($env['self']) ? self() : $env['self']);
2785
-	$pagination = array(
2786
-		'debut' => $debut,
2787
-		'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2788
-		'total' => $total,
2789
-		'position' => intval($position),
2790
-		'pas' => $pas,
2791
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
2792
-		'page_courante' => floor(intval($position) / $pas) + 1,
2793
-		'ancre' => $ancre,
2794
-		'bloc_ancre' => $bloc_ancre
2795
-	);
2796
-	if (is_array($env)) {
2797
-		$pagination = array_merge($env, $pagination);
2798
-	}
2799
-
2800
-	// Pas de pagination
2801
-	if ($pagination['nombre_pages'] <= 1) {
2802
-		return '';
2803
-	}
2804
-
2805
-	if ($modele) {
2806
-		$modele = '_' . $modele;
2807
-	}
2808
-
2809
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2766
+    static $ancres = array();
2767
+    if ($pas < 1) {
2768
+        return '';
2769
+    }
2770
+    $ancre = 'pagination' . $nom; // #pagination_articles
2771
+    $debut = 'debut' . $nom; // 'debut_articles'
2772
+
2773
+    // n'afficher l'ancre qu'une fois
2774
+    if (!isset($ancres[$ancre])) {
2775
+        $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2776
+    } else {
2777
+        $bloc_ancre = '';
2778
+    }
2779
+    // liste = false : on ne veut que l'ancre
2780
+    if (!$liste) {
2781
+        return $ancres[$ancre];
2782
+    }
2783
+
2784
+    $self = (empty($env['self']) ? self() : $env['self']);
2785
+    $pagination = array(
2786
+        'debut' => $debut,
2787
+        'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel
2788
+        'total' => $total,
2789
+        'position' => intval($position),
2790
+        'pas' => $pas,
2791
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
2792
+        'page_courante' => floor(intval($position) / $pas) + 1,
2793
+        'ancre' => $ancre,
2794
+        'bloc_ancre' => $bloc_ancre
2795
+    );
2796
+    if (is_array($env)) {
2797
+        $pagination = array_merge($env, $pagination);
2798
+    }
2799
+
2800
+    // Pas de pagination
2801
+    if ($pagination['nombre_pages'] <= 1) {
2802
+        return '';
2803
+    }
2804
+
2805
+    if ($modele) {
2806
+        $modele = '_' . $modele;
2807
+    }
2808
+
2809
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2810 2810
 }
2811 2811
 
2812 2812
 
@@ -2823,15 +2823,15 @@  discard block
 block discarded – undo
2823 2823
  *     Contenu avec urls en absolus
2824 2824
  **/
2825 2825
 function urls_absolues_css($contenu, $source) {
2826
-	$path = suivre_lien(url_absolue($source), './');
2826
+    $path = suivre_lien(url_absolue($source), './');
2827 2827
 
2828
-	return preg_replace_callback(
2829
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2830
-		function($x) use ($path) {
2831
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2832
-		},
2833
-		$contenu
2834
-	);
2828
+    return preg_replace_callback(
2829
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2830
+        function($x) use ($path) {
2831
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2832
+        },
2833
+        $contenu
2834
+    );
2835 2835
 }
2836 2836
 
2837 2837
 
@@ -2860,118 +2860,118 @@  discard block
 block discarded – undo
2860 2860
  *     Chemin du fichier CSS inversé
2861 2861
  **/
2862 2862
 function direction_css($css, $voulue = '') {
2863
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2864
-		return $css;
2865
-	}
2866
-
2867
-	// si on a precise le sens voulu en argument, le prendre en compte
2868
-	if ($voulue = strtolower($voulue)) {
2869
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2870
-			$voulue = lang_dir($voulue);
2871
-		}
2872
-	} else {
2873
-		$voulue = lang_dir();
2874
-	}
2875
-
2876
-	$r = count($r) > 1;
2877
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2878
-	$dir = $r ? 'rtl' : 'ltr';
2879
-	$ndir = $r ? 'ltr' : 'rtl';
2880
-
2881
-	if ($voulue == $dir) {
2882
-		return $css;
2883
-	}
2884
-
2885
-	if (
2886
-		// url absolue
2887
-		preg_match(",^https?:,i", $css)
2888
-		// ou qui contient un ?
2889
-		or (($p = strpos($css, '?')) !== false)
2890
-	) {
2891
-		$distant = true;
2892
-		$cssf = parse_url($css);
2893
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2894
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2895
-	} else {
2896
-		$distant = false;
2897
-		$cssf = $css;
2898
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2899
-		//propose (rien a faire dans ce cas)
2900
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2901
-		if (@file_exists($f)) {
2902
-			return $f;
2903
-		}
2904
-	}
2905
-
2906
-	// 2.
2907
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2908
-	$f = $dir_var
2909
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2910
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2911
-
2912
-	// la css peut etre distante (url absolue !)
2913
-	if ($distant) {
2914
-		include_spip('inc/distant');
2915
-		$res = recuperer_url($css);
2916
-		if (!$res or !$contenu = $res['page']) {
2917
-			return $css;
2918
-		}
2919
-	} else {
2920
-		if ((@filemtime($f) > @filemtime($css))
2921
-			and (_VAR_MODE != 'recalcul')
2922
-		) {
2923
-			return $f;
2924
-		}
2925
-		if (!lire_fichier($css, $contenu)) {
2926
-			return $css;
2927
-		}
2928
-	}
2929
-
2930
-
2931
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2932
-	include_spip("lib/csstidy/class.csstidy");
2933
-	$parser = new csstidy();
2934
-	$parser->set_cfg('optimise_shorthands', 0);
2935
-	$parser->set_cfg('reverse_left_and_right', true);
2936
-	$parser->parse($contenu);
2937
-
2938
-	$contenu = $parser->print->plain();
2939
-
2940
-
2941
-	// reperer les @import auxquels il faut propager le direction_css
2942
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2943
-	$src = array();
2944
-	$src_direction_css = array();
2945
-	$src_faux_abs = array();
2946
-	$d = dirname($css);
2947
-	foreach ($regs[1] as $k => $import_css) {
2948
-		$css_direction = direction_css("$d/$import_css", $voulue);
2949
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2950
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2951
-			$css_direction = substr($css_direction, strlen($d) + 1);
2952
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2953
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2954
-			$css_direction = substr($css_direction, strlen($dir_var));
2955
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2956
-			$css_direction = "/@@@@@@/" . $css_direction;
2957
-		}
2958
-		$src[] = $regs[0][$k];
2959
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2960
-	}
2961
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2962
-
2963
-	$contenu = urls_absolues_css($contenu, $css);
2964
-
2965
-	// virer les fausses url absolues que l'on a mis dans les import
2966
-	if (count($src_faux_abs)) {
2967
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2968
-	}
2969
-
2970
-	if (!ecrire_fichier($f, $contenu)) {
2971
-		return $css;
2972
-	}
2973
-
2974
-	return $f;
2863
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2864
+        return $css;
2865
+    }
2866
+
2867
+    // si on a precise le sens voulu en argument, le prendre en compte
2868
+    if ($voulue = strtolower($voulue)) {
2869
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2870
+            $voulue = lang_dir($voulue);
2871
+        }
2872
+    } else {
2873
+        $voulue = lang_dir();
2874
+    }
2875
+
2876
+    $r = count($r) > 1;
2877
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2878
+    $dir = $r ? 'rtl' : 'ltr';
2879
+    $ndir = $r ? 'ltr' : 'rtl';
2880
+
2881
+    if ($voulue == $dir) {
2882
+        return $css;
2883
+    }
2884
+
2885
+    if (
2886
+        // url absolue
2887
+        preg_match(",^https?:,i", $css)
2888
+        // ou qui contient un ?
2889
+        or (($p = strpos($css, '?')) !== false)
2890
+    ) {
2891
+        $distant = true;
2892
+        $cssf = parse_url($css);
2893
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2894
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2895
+    } else {
2896
+        $distant = false;
2897
+        $cssf = $css;
2898
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2899
+        //propose (rien a faire dans ce cas)
2900
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2901
+        if (@file_exists($f)) {
2902
+            return $f;
2903
+        }
2904
+    }
2905
+
2906
+    // 2.
2907
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2908
+    $f = $dir_var
2909
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2910
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2911
+
2912
+    // la css peut etre distante (url absolue !)
2913
+    if ($distant) {
2914
+        include_spip('inc/distant');
2915
+        $res = recuperer_url($css);
2916
+        if (!$res or !$contenu = $res['page']) {
2917
+            return $css;
2918
+        }
2919
+    } else {
2920
+        if ((@filemtime($f) > @filemtime($css))
2921
+            and (_VAR_MODE != 'recalcul')
2922
+        ) {
2923
+            return $f;
2924
+        }
2925
+        if (!lire_fichier($css, $contenu)) {
2926
+            return $css;
2927
+        }
2928
+    }
2929
+
2930
+
2931
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2932
+    include_spip("lib/csstidy/class.csstidy");
2933
+    $parser = new csstidy();
2934
+    $parser->set_cfg('optimise_shorthands', 0);
2935
+    $parser->set_cfg('reverse_left_and_right', true);
2936
+    $parser->parse($contenu);
2937
+
2938
+    $contenu = $parser->print->plain();
2939
+
2940
+
2941
+    // reperer les @import auxquels il faut propager le direction_css
2942
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2943
+    $src = array();
2944
+    $src_direction_css = array();
2945
+    $src_faux_abs = array();
2946
+    $d = dirname($css);
2947
+    foreach ($regs[1] as $k => $import_css) {
2948
+        $css_direction = direction_css("$d/$import_css", $voulue);
2949
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2950
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2951
+            $css_direction = substr($css_direction, strlen($d) + 1);
2952
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2953
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2954
+            $css_direction = substr($css_direction, strlen($dir_var));
2955
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2956
+            $css_direction = "/@@@@@@/" . $css_direction;
2957
+        }
2958
+        $src[] = $regs[0][$k];
2959
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2960
+    }
2961
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2962
+
2963
+    $contenu = urls_absolues_css($contenu, $css);
2964
+
2965
+    // virer les fausses url absolues que l'on a mis dans les import
2966
+    if (count($src_faux_abs)) {
2967
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2968
+    }
2969
+
2970
+    if (!ecrire_fichier($f, $contenu)) {
2971
+        return $css;
2972
+    }
2973
+
2974
+    return $f;
2975 2975
 }
2976 2976
 
2977 2977
 
@@ -2994,43 +2994,43 @@  discard block
 block discarded – undo
2994 2994
  *     - Chemin ou URL du fichier CSS source sinon.
2995 2995
  **/
2996 2996
 function url_absolue_css($css) {
2997
-	if (!preg_match(',\.css$,i', $css, $r)) {
2998
-		return $css;
2999
-	}
2997
+    if (!preg_match(',\.css$,i', $css, $r)) {
2998
+        return $css;
2999
+    }
3000 3000
 
3001
-	$url_absolue_css = url_absolue($css);
3001
+    $url_absolue_css = url_absolue($css);
3002 3002
 
3003
-	$f = basename($css, '.css');
3004
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3005
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3006
-		. '.css';
3003
+    $f = basename($css, '.css');
3004
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3005
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3006
+        . '.css';
3007 3007
 
3008
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3009
-		return $f;
3010
-	}
3008
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3009
+        return $f;
3010
+    }
3011 3011
 
3012
-	if ($url_absolue_css == $css) {
3013
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3014
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3015
-		) {
3016
-			include_spip('inc/distant');
3017
-			if (!$contenu = recuperer_page($css)) {
3018
-				return $css;
3019
-			}
3020
-		}
3021
-	} elseif (!lire_fichier($css, $contenu)) {
3022
-		return $css;
3023
-	}
3012
+    if ($url_absolue_css == $css) {
3013
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3014
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3015
+        ) {
3016
+            include_spip('inc/distant');
3017
+            if (!$contenu = recuperer_page($css)) {
3018
+                return $css;
3019
+            }
3020
+        }
3021
+    } elseif (!lire_fichier($css, $contenu)) {
3022
+        return $css;
3023
+    }
3024 3024
 
3025
-	// passer les url relatives a la css d'origine en url absolues
3026
-	$contenu = urls_absolues_css($contenu, $css);
3025
+    // passer les url relatives a la css d'origine en url absolues
3026
+    $contenu = urls_absolues_css($contenu, $css);
3027 3027
 
3028
-	// ecrire la css
3029
-	if (!ecrire_fichier($f, $contenu)) {
3030
-		return $css;
3031
-	}
3028
+    // ecrire la css
3029
+    if (!ecrire_fichier($f, $contenu)) {
3030
+        return $css;
3031
+    }
3032 3032
 
3033
-	return $f;
3033
+    return $f;
3034 3034
 }
3035 3035
 
3036 3036
 
@@ -3064,24 +3064,24 @@  discard block
 block discarded – undo
3064 3064
  *     Valeur trouvée ou valeur par défaut.
3065 3065
  **/
3066 3066
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3067
-	foreach (explode('/', $cle) as $k) {
3067
+    foreach (explode('/', $cle) as $k) {
3068 3068
 
3069
-		$table = is_string($table) ? @unserialize($table) : $table;
3069
+        $table = is_string($table) ? @unserialize($table) : $table;
3070 3070
 
3071
-		if (is_object($table)) {
3072
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3073
-		} elseif (is_array($table)) {
3074
-			if ($conserver_null) {
3075
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3076
-			} else {
3077
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3078
-			}
3079
-		} else {
3080
-			$table = $defaut;
3081
-		}
3082
-	}
3071
+        if (is_object($table)) {
3072
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3073
+        } elseif (is_array($table)) {
3074
+            if ($conserver_null) {
3075
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3076
+            } else {
3077
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3078
+            }
3079
+        } else {
3080
+            $table = $defaut;
3081
+        }
3082
+    }
3083 3083
 
3084
-	return $table;
3084
+    return $table;
3085 3085
 }
3086 3086
 
3087 3087
 /**
@@ -3114,22 +3114,22 @@  discard block
 block discarded – undo
3114 3114
  *     - string : expression trouvée.
3115 3115
  **/
3116 3116
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3117
-	if (intval($modif) and $capte == 0) {
3118
-		$capte = $modif;
3119
-		$modif = "UimsS";
3120
-	}
3121
-	$expression = str_replace("\/", "/", $expression);
3122
-	$expression = str_replace("/", "\/", $expression);
3117
+    if (intval($modif) and $capte == 0) {
3118
+        $capte = $modif;
3119
+        $modif = "UimsS";
3120
+    }
3121
+    $expression = str_replace("\/", "/", $expression);
3122
+    $expression = str_replace("/", "\/", $expression);
3123 3123
 
3124
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3125
-		if (isset($r[$capte])) {
3126
-			return $r[$capte];
3127
-		} else {
3128
-			return true;
3129
-		}
3130
-	}
3124
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3125
+        if (isset($r[$capte])) {
3126
+            return $r[$capte];
3127
+        } else {
3128
+            return true;
3129
+        }
3130
+    }
3131 3131
 
3132
-	return false;
3132
+    return false;
3133 3133
 }
3134 3134
 
3135 3135
 
@@ -3156,10 +3156,10 @@  discard block
 block discarded – undo
3156 3156
  *     Texte
3157 3157
  **/
3158 3158
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3159
-	$expression = str_replace("\/", "/", $expression);
3160
-	$expression = str_replace("/", "\/", $expression);
3159
+    $expression = str_replace("\/", "/", $expression);
3160
+    $expression = str_replace("/", "\/", $expression);
3161 3161
 
3162
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3162
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3163 3163
 }
3164 3164
 
3165 3165
 
@@ -3177,21 +3177,21 @@  discard block
 block discarded – undo
3177 3177
  **/
3178 3178
 function traiter_doublons_documents(&$doublons, $letexte) {
3179 3179
 
3180
-	// Verifier dans le texte & les notes (pas beau, helas)
3181
-	$t = $letexte . $GLOBALS['les_notes'];
3180
+    // Verifier dans le texte & les notes (pas beau, helas)
3181
+    $t = $letexte . $GLOBALS['les_notes'];
3182 3182
 
3183
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3184
-		and preg_match_all(
3185
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3186
-			$t, $matches, PREG_PATTERN_ORDER)
3187
-	) {
3188
-		if (!isset($doublons['documents'])) {
3189
-			$doublons['documents'] = "";
3190
-		}
3191
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3192
-	}
3183
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3184
+        and preg_match_all(
3185
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3186
+            $t, $matches, PREG_PATTERN_ORDER)
3187
+    ) {
3188
+        if (!isset($doublons['documents'])) {
3189
+            $doublons['documents'] = "";
3190
+        }
3191
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3192
+    }
3193 3193
 
3194
-	return $letexte;
3194
+    return $letexte;
3195 3195
 }
3196 3196
 
3197 3197
 /**
@@ -3205,7 +3205,7 @@  discard block
 block discarded – undo
3205 3205
  * @return string Chaîne vide
3206 3206
  **/
3207 3207
 function vide($texte) {
3208
-	return "";
3208
+    return "";
3209 3209
 }
3210 3210
 
3211 3211
 //
@@ -3234,23 +3234,23 @@  discard block
 block discarded – undo
3234 3234
  *      Code HTML résultant
3235 3235
  **/
3236 3236
 function env_to_params($env, $ignore_params = array()) {
3237
-	$ignore_params = array_merge(
3238
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3239
-		$ignore_params
3240
-	);
3241
-	if (!is_array($env)) {
3242
-		$env = unserialize($env);
3243
-	}
3244
-	$texte = "";
3245
-	if ($env) {
3246
-		foreach ($env as $i => $j) {
3247
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3248
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3249
-			}
3250
-		}
3251
-	}
3252
-
3253
-	return $texte;
3237
+    $ignore_params = array_merge(
3238
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3239
+        $ignore_params
3240
+    );
3241
+    if (!is_array($env)) {
3242
+        $env = unserialize($env);
3243
+    }
3244
+    $texte = "";
3245
+    if ($env) {
3246
+        foreach ($env as $i => $j) {
3247
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3248
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3249
+            }
3250
+        }
3251
+    }
3252
+
3253
+    return $texte;
3254 3254
 }
3255 3255
 
3256 3256
 /**
@@ -3273,23 +3273,23 @@  discard block
 block discarded – undo
3273 3273
  *      Code HTML résultant
3274 3274
  **/
3275 3275
 function env_to_attributs($env, $ignore_params = array()) {
3276
-	$ignore_params = array_merge(
3277
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3278
-		$ignore_params
3279
-	);
3280
-	if (!is_array($env)) {
3281
-		$env = unserialize($env);
3282
-	}
3283
-	$texte = "";
3284
-	if ($env) {
3285
-		foreach ($env as $i => $j) {
3286
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3287
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3288
-			}
3289
-		}
3290
-	}
3276
+    $ignore_params = array_merge(
3277
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3278
+        $ignore_params
3279
+    );
3280
+    if (!is_array($env)) {
3281
+        $env = unserialize($env);
3282
+    }
3283
+    $texte = "";
3284
+    if ($env) {
3285
+        foreach ($env as $i => $j) {
3286
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3287
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3288
+            }
3289
+        }
3290
+    }
3291 3291
 
3292
-	return $texte;
3292
+    return $texte;
3293 3293
 }
3294 3294
 
3295 3295
 
@@ -3306,9 +3306,9 @@  discard block
 block discarded – undo
3306 3306
  * @return string Chaînes concaténés
3307 3307
  **/
3308 3308
 function concat() {
3309
-	$args = func_get_args();
3309
+    $args = func_get_args();
3310 3310
 
3311
-	return join('', $args);
3311
+    return join('', $args);
3312 3312
 }
3313 3313
 
3314 3314
 
@@ -3328,23 +3328,23 @@  discard block
 block discarded – undo
3328 3328
  *     Contenu du ou des fichiers, concaténé
3329 3329
  **/
3330 3330
 function charge_scripts($files, $script = true) {
3331
-	$flux = "";
3332
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3333
-		if (!is_string($file)) {
3334
-			continue;
3335
-		}
3336
-		if ($script) {
3337
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3338
-		}
3339
-		if ($file) {
3340
-			$path = find_in_path($file);
3341
-			if ($path) {
3342
-				$flux .= spip_file_get_contents($path);
3343
-			}
3344
-		}
3345
-	}
3331
+    $flux = "";
3332
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3333
+        if (!is_string($file)) {
3334
+            continue;
3335
+        }
3336
+        if ($script) {
3337
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3338
+        }
3339
+        if ($file) {
3340
+            $path = find_in_path($file);
3341
+            if ($path) {
3342
+                $flux .= spip_file_get_contents($path);
3343
+            }
3344
+        }
3345
+    }
3346 3346
 
3347
-	return $flux;
3347
+    return $flux;
3348 3348
 }
3349 3349
 
3350 3350
 
@@ -3366,55 +3366,55 @@  discard block
 block discarded – undo
3366 3366
  */
3367 3367
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3368 3368
 
3369
-	$img_file = $img;
3370
-	if ($p = strpos($img_file, '?')) {
3371
-		$img_file = substr($img_file,0, $p);
3372
-	}
3373
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3374
-		$img_file = chemin_image($img);
3375
-	}
3376
-	else {
3377
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3378
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3379
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3380
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3381
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3382
-			  and file_exists($variante_svg_generique)) {
3383
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3384
-					$img_file = $variante_svg_size;
3385
-				}
3386
-				else {
3387
-					$img_file = $variante_svg_generique;
3388
-				}
3389
-			}
3390
-		}
3391
-	}
3392
-	if (stripos($atts, 'width') === false) {
3393
-		// utiliser directement l'info de taille presente dans le nom
3394
-		if ((!isset($options['utiliser_suffixe_size'])
3395
-				or $options['utiliser_suffixe_size'] == true
3396
-			  or strpos($img_file, '-xx.svg') !== false)
3397
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3398
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3399
-		) {
3400
-			$largeur = $hauteur = intval($regs[1]);
3401
-		} else {
3402
-			$taille = taille_image($img_file);
3403
-			list($hauteur, $largeur) = $taille;
3404
-			if (!$hauteur or !$largeur) {
3405
-				return "";
3406
-			}
3407
-		}
3408
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3409
-	}
3410
-
3411
-	if (file_exists($img_file)) {
3412
-		$img_file = timestamp($img_file);
3413
-	}
3414
-	return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3415
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3416
-	. " " . ltrim($atts)
3417
-	. " />";
3369
+    $img_file = $img;
3370
+    if ($p = strpos($img_file, '?')) {
3371
+        $img_file = substr($img_file,0, $p);
3372
+    }
3373
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3374
+        $img_file = chemin_image($img);
3375
+    }
3376
+    else {
3377
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3378
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3379
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3380
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3381
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3382
+              and file_exists($variante_svg_generique)) {
3383
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3384
+                    $img_file = $variante_svg_size;
3385
+                }
3386
+                else {
3387
+                    $img_file = $variante_svg_generique;
3388
+                }
3389
+            }
3390
+        }
3391
+    }
3392
+    if (stripos($atts, 'width') === false) {
3393
+        // utiliser directement l'info de taille presente dans le nom
3394
+        if ((!isset($options['utiliser_suffixe_size'])
3395
+                or $options['utiliser_suffixe_size'] == true
3396
+              or strpos($img_file, '-xx.svg') !== false)
3397
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3398
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3399
+        ) {
3400
+            $largeur = $hauteur = intval($regs[1]);
3401
+        } else {
3402
+            $taille = taille_image($img_file);
3403
+            list($hauteur, $largeur) = $taille;
3404
+            if (!$hauteur or !$largeur) {
3405
+                return "";
3406
+            }
3407
+        }
3408
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3409
+    }
3410
+
3411
+    if (file_exists($img_file)) {
3412
+        $img_file = timestamp($img_file);
3413
+    }
3414
+    return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3415
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3416
+    . " " . ltrim($atts)
3417
+    . " />";
3418 3418
 }
3419 3419
 
3420 3420
 /**
@@ -3426,13 +3426,13 @@  discard block
 block discarded – undo
3426 3426
  * @return string
3427 3427
  */
3428 3428
 function http_style_background($img, $att = '', $size=null) {
3429
-	if ($size and is_numeric($size)){
3430
-		$size = trim($size) . "px";
3431
-	}
3432
-	return " style='background" .
3433
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3434
-		. ($size ? "background-size:{$size};" : '')
3435
-		. "'";
3429
+    if ($size and is_numeric($size)){
3430
+        $size = trim($size) . "px";
3431
+    }
3432
+    return " style='background" .
3433
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3434
+        . ($size ? "background-size:{$size};" : '')
3435
+        . "'";
3436 3436
 }
3437 3437
 
3438 3438
 /**
@@ -3448,17 +3448,17 @@  discard block
 block discarded – undo
3448 3448
  *     Code HTML de la balise IMG
3449 3449
  */
3450 3450
 function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3451
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3452
-	// ecriture courte : on donne le width en 2e arg
3453
-	if (empty($width) and is_numeric($alt)) {
3454
-		$width = $alt;
3455
-		$alt = '';
3456
-	}
3457
-	if ($width) {
3458
-		$atts .= " width='{$width}'";
3459
-	}
3460
-	return http_img_pack($img, $alt, $atts, '',
3461
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3451
+    $atts = $class ? " class='" . attribut_html($class) . "'" : '';
3452
+    // ecriture courte : on donne le width en 2e arg
3453
+    if (empty($width) and is_numeric($alt)) {
3454
+        $width = $alt;
3455
+        $alt = '';
3456
+    }
3457
+    if ($width) {
3458
+        $atts .= " width='{$width}'";
3459
+    }
3460
+    return http_img_pack($img, $alt, $atts, '',
3461
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3462 3462
 }
3463 3463
 
3464 3464
 
@@ -3474,42 +3474,42 @@  discard block
 block discarded – undo
3474 3474
  * @return string
3475 3475
  */
3476 3476
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3477
-	$img_file = $img;
3478
-	if ($p = strpos($img_file, '?')) {
3479
-		$img_file = substr($img_file,0, $p);
3480
-	}
3477
+    $img_file = $img;
3478
+    if ($p = strpos($img_file, '?')) {
3479
+        $img_file = substr($img_file,0, $p);
3480
+    }
3481 3481
 
3482
-	if (!$img_file or !$svg = file_get_contents($img_file)) {
3483
-		return '';
3484
-	}
3482
+    if (!$img_file or !$svg = file_get_contents($img_file)) {
3483
+        return '';
3484
+    }
3485 3485
 
3486
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3487
-		return '';
3488
-	}
3489
-	$balise_svg = $match[0];
3490
-	$balise_svg_source = $balise_svg;
3486
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3487
+        return '';
3488
+    }
3489
+    $balise_svg = $match[0];
3490
+    $balise_svg_source = $balise_svg;
3491 3491
 
3492
-	// entete XML à supprimer
3493
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3492
+    // entete XML à supprimer
3493
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3494 3494
 
3495
-	// IE est toujours mon ami
3496
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3497
-	if ($class) {
3498
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3499
-	}
3500
-	if ($alt){
3501
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3502
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3503
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3504
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3505
-		$balise_svg .= $title;
3506
-	}
3507
-	else {
3508
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3509
-	}
3510
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3495
+    // IE est toujours mon ami
3496
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3497
+    if ($class) {
3498
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3499
+    }
3500
+    if ($alt){
3501
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3502
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3503
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3504
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3505
+        $balise_svg .= $title;
3506
+    }
3507
+    else {
3508
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3509
+    }
3510
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3511 3511
 
3512
-	return $svg;
3512
+    return $svg;
3513 3513
 }
3514 3514
 
3515 3515
 
@@ -3532,17 +3532,17 @@  discard block
 block discarded – undo
3532 3532
  *     Code HTML résultant
3533 3533
  **/
3534 3534
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3535
-	$texte = '';
3536
-	if (is_array($tableau)) {
3537
-		foreach ($tableau as $k => $v) {
3538
-			$res = recuperer_fond('modeles/' . $modele,
3539
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3540
-			);
3541
-			$texte .= $res;
3542
-		}
3543
-	}
3535
+    $texte = '';
3536
+    if (is_array($tableau)) {
3537
+        foreach ($tableau as $k => $v) {
3538
+            $res = recuperer_fond('modeles/' . $modele,
3539
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3540
+            );
3541
+            $texte .= $res;
3542
+        }
3543
+    }
3544 3544
 
3545
-	return $texte;
3545
+    return $texte;
3546 3546
 }
3547 3547
 
3548 3548
 
@@ -3567,37 +3567,37 @@  discard block
 block discarded – undo
3567 3567
  *         - tout : retourne toutes les informations du plugin actif
3568 3568
  **/
3569 3569
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3570
-	include_spip('inc/plugin');
3571
-	$plugin = strtoupper($plugin);
3572
-	$plugins_actifs = liste_plugin_actifs();
3573
-
3574
-	if (!$plugin) {
3575
-		return serialize(array_keys($plugins_actifs));
3576
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3577
-		return '';
3578
-	} elseif (($type_info == 'est_actif') and !$reload) {
3579
-		return $plugins_actifs[$plugin] ? 1 : 0;
3580
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3581
-		return $plugins_actifs[$plugin][$type_info];
3582
-	} else {
3583
-		$get_infos = charger_fonction('get_infos', 'plugins');
3584
-		// On prend en compte les extensions
3585
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3586
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3587
-		} else {
3588
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3589
-		}
3590
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3591
-			return '';
3592
-		}
3593
-		if ($type_info == 'tout') {
3594
-			return $infos;
3595
-		} elseif ($type_info == 'est_actif') {
3596
-			return $infos ? 1 : 0;
3597
-		} else {
3598
-			return strval($infos[$type_info]);
3599
-		}
3600
-	}
3570
+    include_spip('inc/plugin');
3571
+    $plugin = strtoupper($plugin);
3572
+    $plugins_actifs = liste_plugin_actifs();
3573
+
3574
+    if (!$plugin) {
3575
+        return serialize(array_keys($plugins_actifs));
3576
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3577
+        return '';
3578
+    } elseif (($type_info == 'est_actif') and !$reload) {
3579
+        return $plugins_actifs[$plugin] ? 1 : 0;
3580
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3581
+        return $plugins_actifs[$plugin][$type_info];
3582
+    } else {
3583
+        $get_infos = charger_fonction('get_infos', 'plugins');
3584
+        // On prend en compte les extensions
3585
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3586
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3587
+        } else {
3588
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3589
+        }
3590
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3591
+            return '';
3592
+        }
3593
+        if ($type_info == 'tout') {
3594
+            return $infos;
3595
+        } elseif ($type_info == 'est_actif') {
3596
+            return $infos ? 1 : 0;
3597
+        } else {
3598
+            return strval($infos[$type_info]);
3599
+        }
3600
+    }
3601 3601
 }
3602 3602
 
3603 3603
 
@@ -3624,9 +3624,9 @@  discard block
 block discarded – undo
3624 3624
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3625 3625
  */
3626 3626
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3627
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3627
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3628 3628
 
3629
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3629
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3630 3630
 }
3631 3631
 
3632 3632
 
@@ -3656,13 +3656,13 @@  discard block
 block discarded – undo
3656 3656
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3657 3657
  */
3658 3658
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3659
-	static $puce_statut = null;
3660
-	if (!$puce_statut) {
3661
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3662
-	}
3659
+    static $puce_statut = null;
3660
+    if (!$puce_statut) {
3661
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3662
+    }
3663 3663
 
3664
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3665
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3664
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3665
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3666 3666
 }
3667 3667
 
3668 3668
 
@@ -3689,100 +3689,100 @@  discard block
 block discarded – undo
3689 3689
  *   hash du contexte
3690 3690
  */
3691 3691
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3692
-	if (is_string($c)
3693
-		and @unserialize($c) !== false
3694
-	) {
3695
-		$c = unserialize($c);
3696
-	}
3697
-
3698
-	// supprimer les parametres debut_x
3699
-	// pour que la pagination ajax ne soit pas plantee
3700
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3701
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3702
-	if (is_array($c)) {
3703
-		foreach ($c as $k => $v) {
3704
-			if (strpos($k, 'debut_') === 0) {
3705
-				unset($c[$k]);
3706
-			}
3707
-		}
3708
-	}
3709
-
3710
-	if (!function_exists('calculer_cle_action')) {
3711
-		include_spip("inc/securiser_action");
3712
-	}
3713
-
3714
-	$c = serialize($c);
3715
-	$cle = calculer_cle_action($form . $c);
3716
-	$c = "$cle:$c";
3717
-
3718
-	// on ne stocke pas les contextes dans des fichiers en cache
3719
-	// par defaut, sauf si cette configuration a été forcée
3720
-	// OU que la longueur de l’argument géneré est plus long
3721
-	// que ce qui est toléré.
3722
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3723
-	if (!$cache_contextes_ajax) {
3724
-		$env = $c;
3725
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3726
-			$env = gzdeflate($env);
3727
-			// https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3728
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3729
-				$cache_contextes_ajax = true;
3730
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3731
-			}
3732
-		}
3733
-		$env = _xor($env);
3734
-		$env = base64_encode($env);
3735
-		$len = strlen($env);
3736
-		// Si l’url est trop longue pour le navigateur
3737
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3738
-		if ($len > $max_len) {
3739
-			$cache_contextes_ajax = true;
3740
-			spip_log("Contextes AJAX forces en fichiers !"
3741
-				. " Cela arrive lorsque la valeur du contexte" 
3742
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3743
-				, _LOG_AVERTISSEMENT);
3744
-		}
3745
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3746
-		elseif (
3747
-			$max_len = @ini_get('suhosin.get.max_value_length')
3748
-			and $max_len < $len
3749
-		) {
3750
-			$cache_contextes_ajax = true;
3751
-			spip_log("Contextes AJAX forces en fichiers !"
3752
-				. " Cela arrive lorsque la valeur du contexte"
3753
-				. " depasse la longueur maximale autorisee par Suhosin"
3754
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3755
-				. " Vous devriez modifier les parametres de Suhosin"
3756
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3757
-		} 
3758
-
3759
-	}
3760
-
3761
-	if ($cache_contextes_ajax) {
3762
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3763
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3764
-		$md5 = md5($c);
3765
-		ecrire_fichier("$dir/c$md5", $c);
3766
-		$env = $md5;
3767
-	}
3768
-
3769
-	if ($emboite === null) {
3770
-		return $env;
3771
-	}
3772
-	if (!trim($emboite)) {
3773
-		return "";
3774
-	}
3775
-	// toujours encoder l'url source dans le bloc ajax
3776
-	$r = self();
3777
-	$r = ' data-origin="' . $r . '"';
3778
-	$class = 'ajaxbloc';
3779
-	if ($ajaxid and is_string($ajaxid)) {
3780
-		// ajaxid est normalement conforme a un nom de classe css
3781
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3782
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3783
-	}
3784
-
3785
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3692
+    if (is_string($c)
3693
+        and @unserialize($c) !== false
3694
+    ) {
3695
+        $c = unserialize($c);
3696
+    }
3697
+
3698
+    // supprimer les parametres debut_x
3699
+    // pour que la pagination ajax ne soit pas plantee
3700
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3701
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3702
+    if (is_array($c)) {
3703
+        foreach ($c as $k => $v) {
3704
+            if (strpos($k, 'debut_') === 0) {
3705
+                unset($c[$k]);
3706
+            }
3707
+        }
3708
+    }
3709
+
3710
+    if (!function_exists('calculer_cle_action')) {
3711
+        include_spip("inc/securiser_action");
3712
+    }
3713
+
3714
+    $c = serialize($c);
3715
+    $cle = calculer_cle_action($form . $c);
3716
+    $c = "$cle:$c";
3717
+
3718
+    // on ne stocke pas les contextes dans des fichiers en cache
3719
+    // par defaut, sauf si cette configuration a été forcée
3720
+    // OU que la longueur de l’argument géneré est plus long
3721
+    // que ce qui est toléré.
3722
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3723
+    if (!$cache_contextes_ajax) {
3724
+        $env = $c;
3725
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3726
+            $env = gzdeflate($env);
3727
+            // https://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3728
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3729
+                $cache_contextes_ajax = true;
3730
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3731
+            }
3732
+        }
3733
+        $env = _xor($env);
3734
+        $env = base64_encode($env);
3735
+        $len = strlen($env);
3736
+        // Si l’url est trop longue pour le navigateur
3737
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3738
+        if ($len > $max_len) {
3739
+            $cache_contextes_ajax = true;
3740
+            spip_log("Contextes AJAX forces en fichiers !"
3741
+                . " Cela arrive lorsque la valeur du contexte" 
3742
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3743
+                , _LOG_AVERTISSEMENT);
3744
+        }
3745
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3746
+        elseif (
3747
+            $max_len = @ini_get('suhosin.get.max_value_length')
3748
+            and $max_len < $len
3749
+        ) {
3750
+            $cache_contextes_ajax = true;
3751
+            spip_log("Contextes AJAX forces en fichiers !"
3752
+                . " Cela arrive lorsque la valeur du contexte"
3753
+                . " depasse la longueur maximale autorisee par Suhosin"
3754
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3755
+                . " Vous devriez modifier les parametres de Suhosin"
3756
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3757
+        } 
3758
+
3759
+    }
3760
+
3761
+    if ($cache_contextes_ajax) {
3762
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3763
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3764
+        $md5 = md5($c);
3765
+        ecrire_fichier("$dir/c$md5", $c);
3766
+        $env = $md5;
3767
+    }
3768
+
3769
+    if ($emboite === null) {
3770
+        return $env;
3771
+    }
3772
+    if (!trim($emboite)) {
3773
+        return "";
3774
+    }
3775
+    // toujours encoder l'url source dans le bloc ajax
3776
+    $r = self();
3777
+    $r = ' data-origin="' . $r . '"';
3778
+    $class = 'ajaxbloc';
3779
+    if ($ajaxid and is_string($ajaxid)) {
3780
+        // ajaxid est normalement conforme a un nom de classe css
3781
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3782
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3783
+    }
3784
+
3785
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3786 3786
 }
3787 3787
 
3788 3788
 /**
@@ -3802,36 +3802,36 @@  discard block
 block discarded – undo
3802 3802
  *   - false : erreur de décodage
3803 3803
  */
3804 3804
 function decoder_contexte_ajax($c, $form = '') {
3805
-	if (!function_exists('calculer_cle_action')) {
3806
-		include_spip("inc/securiser_action");
3807
-	}
3808
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3809
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3810
-		and lire_fichier("$dir/c$c", $contexte)
3811
-	) {
3812
-		$c = $contexte;
3813
-	} else {
3814
-		$c = @base64_decode($c);
3815
-		$c = _xor($c);
3816
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3817
-			$c = @gzinflate($c);
3818
-		}
3819
-	}
3820
-
3821
-	// extraire la signature en debut de contexte
3822
-	// et la verifier avant de deserializer
3823
-	// format : signature:donneesserializees
3824
-	if ($p = strpos($c,":")){
3825
-		$cle = substr($c,0,$p);
3826
-		$c = substr($c,$p+1);
3827
-
3828
-		if ($cle == calculer_cle_action($form . $c)) {
3829
-			$env = @unserialize($c);
3830
-			return $env;
3831
-		}
3832
-	}
3833
-
3834
-	return false;
3805
+    if (!function_exists('calculer_cle_action')) {
3806
+        include_spip("inc/securiser_action");
3807
+    }
3808
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3809
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3810
+        and lire_fichier("$dir/c$c", $contexte)
3811
+    ) {
3812
+        $c = $contexte;
3813
+    } else {
3814
+        $c = @base64_decode($c);
3815
+        $c = _xor($c);
3816
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3817
+            $c = @gzinflate($c);
3818
+        }
3819
+    }
3820
+
3821
+    // extraire la signature en debut de contexte
3822
+    // et la verifier avant de deserializer
3823
+    // format : signature:donneesserializees
3824
+    if ($p = strpos($c,":")){
3825
+        $cle = substr($c,0,$p);
3826
+        $c = substr($c,$p+1);
3827
+
3828
+        if ($cle == calculer_cle_action($form . $c)) {
3829
+            $env = @unserialize($c);
3830
+            return $env;
3831
+        }
3832
+    }
3833
+
3834
+    return false;
3835 3835
 }
3836 3836
 
3837 3837
 
@@ -3849,20 +3849,20 @@  discard block
 block discarded – undo
3849 3849
  *    Message décrypté ou encrypté
3850 3850
  **/
3851 3851
 function _xor($message, $key = null) {
3852
-	if (is_null($key)) {
3853
-		if (!function_exists('calculer_cle_action')) {
3854
-			include_spip("inc/securiser_action");
3855
-		}
3856
-		$key = pack("H*", calculer_cle_action('_xor'));
3857
-	}
3852
+    if (is_null($key)) {
3853
+        if (!function_exists('calculer_cle_action')) {
3854
+            include_spip("inc/securiser_action");
3855
+        }
3856
+        $key = pack("H*", calculer_cle_action('_xor'));
3857
+    }
3858 3858
 
3859
-	$keylen = strlen($key);
3860
-	$messagelen = strlen($message);
3861
-	for ($i = 0; $i < $messagelen; $i++) {
3862
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3863
-	}
3859
+    $keylen = strlen($key);
3860
+    $messagelen = strlen($message);
3861
+    for ($i = 0; $i < $messagelen; $i++) {
3862
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3863
+    }
3864 3864
 
3865
-	return $message;
3865
+    return $message;
3866 3866
 }
3867 3867
 
3868 3868
 /**
@@ -3920,22 +3920,22 @@  discard block
 block discarded – undo
3920 3920
  *   Code HTML
3921 3921
  */
3922 3922
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3923
-	if ($on) {
3924
-		$bal = "strong";
3925
-		$att = "class='on'";
3926
-	} else {
3927
-		$bal = 'a';
3928
-		$att = "href='$url'"
3929
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3930
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3931
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3932
-			. $evt;
3933
-	}
3934
-	if ($libelle === null) {
3935
-		$libelle = $url;
3936
-	}
3923
+    if ($on) {
3924
+        $bal = "strong";
3925
+        $att = "class='on'";
3926
+    } else {
3927
+        $bal = 'a';
3928
+        $att = "href='$url'"
3929
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3930
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3931
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3932
+            . $evt;
3933
+    }
3934
+    if ($libelle === null) {
3935
+        $libelle = $url;
3936
+    }
3937 3937
 
3938
-	return "<$bal $att>$libelle</$bal>";
3938
+    return "<$bal $att>$libelle</$bal>";
3939 3939
 }
3940 3940
 
3941 3941
 
@@ -3952,18 +3952,18 @@  discard block
 block discarded – undo
3952 3952
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3953 3953
  */
3954 3954
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3955
-	if (!is_numeric($nb) or $nb == 0) {
3956
-		return "";
3957
-	}
3958
-	if (!is_array($vars)) {
3959
-		return "";
3960
-	}
3961
-	$vars[$var] = $nb;
3962
-	if ($nb >= 2) {
3963
-		return _T($chaine_plusieurs, $vars);
3964
-	} else {
3965
-		return _T($chaine_un, $vars);
3966
-	}
3955
+    if (!is_numeric($nb) or $nb == 0) {
3956
+        return "";
3957
+    }
3958
+    if (!is_array($vars)) {
3959
+        return "";
3960
+    }
3961
+    $vars[$var] = $nb;
3962
+    if ($nb >= 2) {
3963
+        return _T($chaine_plusieurs, $vars);
3964
+    } else {
3965
+        return _T($chaine_un, $vars);
3966
+    }
3967 3967
 }
3968 3968
 
3969 3969
 
@@ -3988,56 +3988,56 @@  discard block
 block discarded – undo
3988 3988
  * @return string
3989 3989
  */
3990 3990
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3991
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3992
-		$class .= ' danger';
3993
-	} elseif ($fonction == "rien.gif") {
3994
-		$fonction = "";
3995
-	} elseif ($fonction == "delsafe") {
3996
-		$fonction = "del";
3997
-	}
3998
-
3999
-	$fond_origine = $fond;
4000
-	// remappage des icone : article-24.png+new => article-new-24.png
4001
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4002
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4003
-	}
4004
-
4005
-	// ajouter le type d'objet dans la class de l'icone
4006
-	$class .= " " . substr(basename($fond), 0, -4);
4007
-
4008
-	$alt = attribut_html($texte);
4009
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4010
-
4011
-	$ajax = "";
4012
-	if (strpos($class, "ajax") !== false) {
4013
-		$ajax = "ajax";
4014
-		if (strpos($class, "preload") !== false) {
4015
-			$ajax .= " preload";
4016
-		}
4017
-		if (strpos($class, "nocache") !== false) {
4018
-			$ajax .= " nocache";
4019
-		}
4020
-		$ajax = " class='$ajax'";
4021
-	}
4022
-
4023
-	$size = 24;
4024
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4025
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4026
-		$size = $match[1];
4027
-	}
4028
-
4029
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4030
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4031
-
4032
-	if ($type == 'lien') {
4033
-		return "<span class='icone s$size $class'>"
4034
-		. "<a href='$lien'$title$ajax$javascript>"
4035
-		. $icone
4036
-		. "<b>$texte</b>"
4037
-		. "</a></span>\n";
4038
-	} else {
4039
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4040
-	}
3991
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3992
+        $class .= ' danger';
3993
+    } elseif ($fonction == "rien.gif") {
3994
+        $fonction = "";
3995
+    } elseif ($fonction == "delsafe") {
3996
+        $fonction = "del";
3997
+    }
3998
+
3999
+    $fond_origine = $fond;
4000
+    // remappage des icone : article-24.png+new => article-new-24.png
4001
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4002
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4003
+    }
4004
+
4005
+    // ajouter le type d'objet dans la class de l'icone
4006
+    $class .= " " . substr(basename($fond), 0, -4);
4007
+
4008
+    $alt = attribut_html($texte);
4009
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4010
+
4011
+    $ajax = "";
4012
+    if (strpos($class, "ajax") !== false) {
4013
+        $ajax = "ajax";
4014
+        if (strpos($class, "preload") !== false) {
4015
+            $ajax .= " preload";
4016
+        }
4017
+        if (strpos($class, "nocache") !== false) {
4018
+            $ajax .= " nocache";
4019
+        }
4020
+        $ajax = " class='$ajax'";
4021
+    }
4022
+
4023
+    $size = 24;
4024
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4025
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4026
+        $size = $match[1];
4027
+    }
4028
+
4029
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4030
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4031
+
4032
+    if ($type == 'lien') {
4033
+        return "<span class='icone s$size $class'>"
4034
+        . "<a href='$lien'$title$ajax$javascript>"
4035
+        . $icone
4036
+        . "<b>$texte</b>"
4037
+        . "</a></span>\n";
4038
+    } else {
4039
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
4040
+    }
4041 4041
 }
4042 4042
 
4043 4043
 /**
@@ -4061,7 +4061,7 @@  discard block
 block discarded – undo
4061 4061
  *     Code HTML du lien
4062 4062
  **/
4063 4063
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4064
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4064
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4065 4065
 }
4066 4066
 
4067 4067
 /**
@@ -4096,7 +4096,7 @@  discard block
 block discarded – undo
4096 4096
  *     Code HTML du lien
4097 4097
  **/
4098 4098
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4099
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4099
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4100 4100
 }
4101 4101
 
4102 4102
 /**
@@ -4141,7 +4141,7 @@  discard block
 block discarded – undo
4141 4141
  *     Code HTML du lien
4142 4142
  **/
4143 4143
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4144
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4144
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4145 4145
 }
4146 4146
 
4147 4147
 /**
@@ -4172,7 +4172,7 @@  discard block
 block discarded – undo
4172 4172
  *     Code HTML du lien
4173 4173
  **/
4174 4174
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4175
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4175
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4176 4176
 }
4177 4177
 
4178 4178
 /**
@@ -4202,7 +4202,7 @@  discard block
 block discarded – undo
4202 4202
  *     Code HTML du lien
4203 4203
  */
4204 4204
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4205
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4205
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4206 4206
 }
4207 4207
 
4208 4208
 
@@ -4250,26 +4250,26 @@  discard block
 block discarded – undo
4250 4250
  * @return string Code CSS
4251 4251
  */
4252 4252
 function bando_images_background() {
4253
-	include_spip('inc/bandeau');
4254
-	// recuperer tous les boutons et leurs images
4255
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4253
+    include_spip('inc/bandeau');
4254
+    // recuperer tous les boutons et leurs images
4255
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4256 4256
 
4257
-	$res = "";
4258
-	foreach ($boutons as $page => $detail) {
4259
-		if ($detail->icone and strlen(trim($detail->icone))) {
4260
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4261
-		}
4262
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4263
-		if (is_array($detail->sousmenu)) {
4264
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4265
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4266
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4267
-				}
4268
-			}
4269
-		}
4270
-	}
4257
+    $res = "";
4258
+    foreach ($boutons as $page => $detail) {
4259
+        if ($detail->icone and strlen(trim($detail->icone))) {
4260
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4261
+        }
4262
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4263
+        if (is_array($detail->sousmenu)) {
4264
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4265
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4266
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4267
+                }
4268
+            }
4269
+        }
4270
+    }
4271 4271
 
4272
-	return $res;
4272
+    return $res;
4273 4273
 }
4274 4274
 
4275 4275
 /**
@@ -4288,19 +4288,19 @@  discard block
 block discarded – undo
4288 4288
  * @return string
4289 4289
  */
4290 4290
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4291
-	if ($confirm) {
4292
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4293
-		if ($callback) {
4294
-			$callback = "$confirm?($callback):false";
4295
-		} else {
4296
-			$callback = $confirm;
4297
-		}
4298
-	}
4299
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4300
-	$title = $title ? " title='$title'" : "";
4291
+    if ($confirm) {
4292
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4293
+        if ($callback) {
4294
+            $callback = "$confirm?($callback):false";
4295
+        } else {
4296
+            $callback = $confirm;
4297
+        }
4298
+    }
4299
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4300
+    $title = $title ? " title='$title'" : "";
4301 4301
 
4302
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4303
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4302
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4303
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4304 4304
 }
4305 4305
 
4306 4306
 /**
@@ -4321,78 +4321,78 @@  discard block
 block discarded – undo
4321 4321
  * @return string
4322 4322
  */
4323 4323
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4324
-	static $trouver_table = null;
4325
-	static $objets;
4326
-
4327
-	// On verifie qu'on a tout ce qu'il faut
4328
-	$id_objet = intval($id_objet);
4329
-	if (!($id_objet and $type_objet and $info)) {
4330
-		return '';
4331
-	}
4332
-
4333
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4334
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4335
-		return '';
4336
-	}
4337
-
4338
-	// Si on demande l'url, on retourne direct la fonction
4339
-	if ($info == 'url') {
4340
-		return generer_url_entite($id_objet, $type_objet);
4341
-	}
4342
-
4343
-	// Sinon on va tout chercher dans la table et on garde en memoire
4344
-	$demande_titre = ($info == 'titre');
4345
-
4346
-	// 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
4347
-	if (!isset($objets[$type_objet][$id_objet])
4348
-		or
4349
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4350
-	) {
4351
-		if (!$trouver_table) {
4352
-			$trouver_table = charger_fonction('trouver_table', 'base');
4353
-		}
4354
-		$desc = $trouver_table(table_objet_sql($type_objet));
4355
-		if (!$desc) {
4356
-			return $objets[$type_objet] = false;
4357
-		}
4358
-
4359
-		// Si on demande le titre, on le gere en interne
4360
-		$champ_titre = "";
4361
-		if ($demande_titre) {
4362
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4363
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4364
-		}
4365
-		include_spip('base/abstract_sql');
4366
-		include_spip('base/connect_sql');
4367
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4368
-			'*' . $champ_titre,
4369
-			$desc['table_sql'],
4370
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4371
-		);
4372
-	}
4373
-
4374
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4375
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4376
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4377
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4378
-	else {
4379
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4380
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4381
-		} // Sinon on prend directement le champ SQL tel quel
4382
-		else {
4383
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4384
-		}
4385
-	}
4386
-
4387
-	// On va ensuite appliquer les traitements automatiques si besoin
4388
-	if (!$etoile) {
4389
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4390
-		// mais ce fonctionnement est a ameliorer !
4391
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4392
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4393
-	}
4394
-
4395
-	return $info_generee;
4324
+    static $trouver_table = null;
4325
+    static $objets;
4326
+
4327
+    // On verifie qu'on a tout ce qu'il faut
4328
+    $id_objet = intval($id_objet);
4329
+    if (!($id_objet and $type_objet and $info)) {
4330
+        return '';
4331
+    }
4332
+
4333
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4334
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4335
+        return '';
4336
+    }
4337
+
4338
+    // Si on demande l'url, on retourne direct la fonction
4339
+    if ($info == 'url') {
4340
+        return generer_url_entite($id_objet, $type_objet);
4341
+    }
4342
+
4343
+    // Sinon on va tout chercher dans la table et on garde en memoire
4344
+    $demande_titre = ($info == 'titre');
4345
+
4346
+    // 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
4347
+    if (!isset($objets[$type_objet][$id_objet])
4348
+        or
4349
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4350
+    ) {
4351
+        if (!$trouver_table) {
4352
+            $trouver_table = charger_fonction('trouver_table', 'base');
4353
+        }
4354
+        $desc = $trouver_table(table_objet_sql($type_objet));
4355
+        if (!$desc) {
4356
+            return $objets[$type_objet] = false;
4357
+        }
4358
+
4359
+        // Si on demande le titre, on le gere en interne
4360
+        $champ_titre = "";
4361
+        if ($demande_titre) {
4362
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4363
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4364
+        }
4365
+        include_spip('base/abstract_sql');
4366
+        include_spip('base/connect_sql');
4367
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4368
+            '*' . $champ_titre,
4369
+            $desc['table_sql'],
4370
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4371
+        );
4372
+    }
4373
+
4374
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4375
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4376
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4377
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4378
+    else {
4379
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4380
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4381
+        } // Sinon on prend directement le champ SQL tel quel
4382
+        else {
4383
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4384
+        }
4385
+    }
4386
+
4387
+    // On va ensuite appliquer les traitements automatiques si besoin
4388
+    if (!$etoile) {
4389
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4390
+        // mais ce fonctionnement est a ameliorer !
4391
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4392
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4393
+    }
4394
+
4395
+    return $info_generee;
4396 4396
 }
4397 4397
 
4398 4398
 /**
@@ -4406,44 +4406,44 @@  discard block
 block discarded – undo
4406 4406
  * @return string
4407 4407
  */
4408 4408
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4409
-	if (!$champ) {
4410
-		return $texte;
4411
-	}
4409
+    if (!$champ) {
4410
+        return $texte;
4411
+    }
4412 4412
 	
4413
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4414
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4415
-	include_spip('inc/texte');
4413
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4414
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4415
+    include_spip('inc/texte');
4416 4416
 	
4417
-	$champ = strtoupper($champ);
4418
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4419
-	if (!$traitements or !is_array($traitements)) {
4420
-		return $texte;
4421
-	}
4417
+    $champ = strtoupper($champ);
4418
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4419
+    if (!$traitements or !is_array($traitements)) {
4420
+        return $texte;
4421
+    }
4422 4422
 
4423
-	$traitement = '';
4424
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4425
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4426
-		$table_objet = table_objet($table_objet);
4427
-		if (isset($traitements[$table_objet])) {
4428
-			$traitement = $traitements[$table_objet];
4429
-		}
4430
-	}
4431
-	if (!$traitement and isset($traitements[0])) {
4432
-		$traitement = $traitements[0];
4433
-	}
4434
-	// (sinon prendre le premier de la liste par defaut ?)
4423
+    $traitement = '';
4424
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4425
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4426
+        $table_objet = table_objet($table_objet);
4427
+        if (isset($traitements[$table_objet])) {
4428
+            $traitement = $traitements[$table_objet];
4429
+        }
4430
+    }
4431
+    if (!$traitement and isset($traitements[0])) {
4432
+        $traitement = $traitements[0];
4433
+    }
4434
+    // (sinon prendre le premier de la liste par defaut ?)
4435 4435
 
4436
-	if (!$traitement) {
4437
-		return $texte;
4438
-	}
4436
+    if (!$traitement) {
4437
+        return $texte;
4438
+    }
4439 4439
 
4440
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4440
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4441 4441
 
4442
-	// Fournir $connect et $Pile[0] au traitement si besoin
4443
-	$Pile = array(0 => $env);
4444
-	eval("\$texte = $traitement;");
4442
+    // Fournir $connect et $Pile[0] au traitement si besoin
4443
+    $Pile = array(0 => $env);
4444
+    eval("\$texte = $traitement;");
4445 4445
 
4446
-	return $texte;
4446
+    return $texte;
4447 4447
 }
4448 4448
 
4449 4449
 
@@ -4457,21 +4457,21 @@  discard block
 block discarded – undo
4457 4457
  * @return string
4458 4458
  */
4459 4459
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4460
-	include_spip('inc/liens');
4461
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4462
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4463
-	// le raccourcis n'est plus valide
4464
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4465
-	// on essaye avec generer_info_entite ?
4466
-	if (!strlen($titre) and !$connect) {
4467
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4468
-	}
4469
-	if (!strlen($titre)) {
4470
-		$titre = _T('info_sans_titre');
4471
-	}
4472
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4460
+    include_spip('inc/liens');
4461
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4462
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4463
+    // le raccourcis n'est plus valide
4464
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4465
+    // on essaye avec generer_info_entite ?
4466
+    if (!strlen($titre) and !$connect) {
4467
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4468
+    }
4469
+    if (!strlen($titre)) {
4470
+        $titre = _T('info_sans_titre');
4471
+    }
4472
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4473 4473
 
4474
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4474
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4475 4475
 }
4476 4476
 
4477 4477
 
@@ -4488,15 +4488,15 @@  discard block
 block discarded – undo
4488 4488
  * @return string
4489 4489
  */
4490 4490
 function wrap($texte, $wrap) {
4491
-	$balises = extraire_balises($wrap);
4492
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4493
-		$texte = $wrap . $texte;
4494
-		$regs = array_reverse($regs[1]);
4495
-		$wrap = "</" . implode("></", $regs) . ">";
4496
-		$texte = $texte . $wrap;
4497
-	}
4491
+    $balises = extraire_balises($wrap);
4492
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4493
+        $texte = $wrap . $texte;
4494
+        $regs = array_reverse($regs[1]);
4495
+        $wrap = "</" . implode("></", $regs) . ">";
4496
+        $texte = $texte . $wrap;
4497
+    }
4498 4498
 
4499
-	return $texte;
4499
+    return $texte;
4500 4500
 }
4501 4501
 
4502 4502
 
@@ -4516,43 +4516,43 @@  discard block
 block discarded – undo
4516 4516
  * @return array|mixed|string
4517 4517
  */
4518 4518
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4519
-	if (is_string($u)) {
4520
-		$u = typo($u);
4519
+    if (is_string($u)) {
4520
+        $u = typo($u);
4521 4521
 
4522
-		return $u;
4523
-	}
4522
+        return $u;
4523
+    }
4524 4524
 
4525
-	// caster $u en array si besoin
4526
-	if (is_object($u)) {
4527
-		$u = (array)$u;
4528
-	}
4525
+    // caster $u en array si besoin
4526
+    if (is_object($u)) {
4527
+        $u = (array)$u;
4528
+    }
4529 4529
 
4530
-	if (is_array($u)) {
4531
-		$out = "";
4532
-		// toutes les cles sont numeriques ?
4533
-		// et aucun enfant n'est un tableau
4534
-		// liste simple separee par des virgules
4535
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4536
-		$array_values = array_map('is_array', $u);
4537
-		$object_values = array_map('is_object', $u);
4538
-		if (array_sum($numeric_keys) == count($numeric_keys)
4539
-			and !array_sum($array_values)
4540
-			and !array_sum($object_values)
4541
-		) {
4542
-			return join(", ", array_map('filtre_print_dist', $u));
4543
-		}
4530
+    if (is_array($u)) {
4531
+        $out = "";
4532
+        // toutes les cles sont numeriques ?
4533
+        // et aucun enfant n'est un tableau
4534
+        // liste simple separee par des virgules
4535
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4536
+        $array_values = array_map('is_array', $u);
4537
+        $object_values = array_map('is_object', $u);
4538
+        if (array_sum($numeric_keys) == count($numeric_keys)
4539
+            and !array_sum($array_values)
4540
+            and !array_sum($object_values)
4541
+        ) {
4542
+            return join(", ", array_map('filtre_print_dist', $u));
4543
+        }
4544 4544
 
4545
-		// sinon on passe a la ligne et on indente
4546
-		$i_str = str_pad("", $indent, " ");
4547
-		foreach ($u as $k => $v) {
4548
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4549
-		}
4545
+        // sinon on passe a la ligne et on indente
4546
+        $i_str = str_pad("", $indent, " ");
4547
+        foreach ($u as $k => $v) {
4548
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4549
+        }
4550 4550
 
4551
-		return $out;
4552
-	}
4551
+        return $out;
4552
+    }
4553 4553
 
4554
-	// on sait pas quoi faire...
4555
-	return $u;
4554
+    // on sait pas quoi faire...
4555
+    return $u;
4556 4556
 }
4557 4557
 
4558 4558
 
@@ -4565,10 +4565,10 @@  discard block
 block discarded – undo
4565 4565
  * @return string|array
4566 4566
  */
4567 4567
 function objet_info($objet, $info) {
4568
-	$table = table_objet_sql($objet);
4569
-	$infos = lister_tables_objets_sql($table);
4568
+    $table = table_objet_sql($objet);
4569
+    $infos = lister_tables_objets_sql($table);
4570 4570
 
4571
-	return (isset($infos[$info]) ? $infos[$info] : '');
4571
+    return (isset($infos[$info]) ? $infos[$info] : '');
4572 4572
 }
4573 4573
 
4574 4574
 /**
@@ -4583,11 +4583,11 @@  discard block
 block discarded – undo
4583 4583
  *     Texte traduit du comptage, tel que '3 articles'
4584 4584
  */
4585 4585
 function objet_afficher_nb($nb, $objet) {
4586
-	if (!$nb) {
4587
-		return _T(objet_info($objet, 'info_aucun_objet'));
4588
-	} else {
4589
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4590
-	}
4586
+    if (!$nb) {
4587
+        return _T(objet_info($objet, 'info_aucun_objet'));
4588
+    } else {
4589
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4590
+    }
4591 4591
 }
4592 4592
 
4593 4593
 /**
@@ -4599,11 +4599,11 @@  discard block
 block discarded – undo
4599 4599
  * @return string
4600 4600
  */
4601 4601
 function objet_icone($objet, $taille = 24, $class='') {
4602
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4603
-	$icone = chemin_image($icone);
4604
-	$balise_img = charger_filtre('balise_img');
4602
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4603
+    $icone = chemin_image($icone);
4604
+    $balise_img = charger_filtre('balise_img');
4605 4605
 
4606
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4606
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4607 4607
 }
4608 4608
 
4609 4609
 /**
@@ -4624,12 +4624,12 @@  discard block
 block discarded – undo
4624 4624
  * @return string
4625 4625
  */
4626 4626
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4627
-	$chaine = explode(':',$chaine);
4628
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4629
-		return $t;
4630
-	}
4631
-	$chaine = implode(':',$chaine);
4632
-	return _T($chaine, $args, $options);
4627
+    $chaine = explode(':',$chaine);
4628
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4629
+        return $t;
4630
+    }
4631
+    $chaine = implode(':',$chaine);
4632
+    return _T($chaine, $args, $options);
4633 4633
 }
4634 4634
 
4635 4635
 /**
@@ -4643,17 +4643,17 @@  discard block
 block discarded – undo
4643 4643
  * @return string      Code HTML
4644 4644
  */
4645 4645
 function insert_head_css_conditionnel($flux) {
4646
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4647
-		and $p = strpos($flux, '<!-- insert_head -->')
4648
-	) {
4649
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4650
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4651
-			$p = $p1;
4652
-		}
4653
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4654
-	}
4646
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4647
+        and $p = strpos($flux, '<!-- insert_head -->')
4648
+    ) {
4649
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4650
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4651
+            $p = $p1;
4652
+        }
4653
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4654
+    }
4655 4655
 
4656
-	return $flux;
4656
+    return $flux;
4657 4657
 }
4658 4658
 
4659 4659
 /**
@@ -4674,69 +4674,69 @@  discard block
 block discarded – undo
4674 4674
  * @return string
4675 4675
  */
4676 4676
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4677
-	if (isset($contexte['format'])) {
4678
-		$extension = $contexte['format'];
4679
-		unset($contexte['format']);
4680
-	} else {
4681
-		$extension = "html";
4682
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4683
-			$extension = $m[1];
4684
-		}
4685
-	}
4686
-	// recuperer le contenu produit par le squelette
4687
-	$options['raw'] = true;
4688
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4689
-
4690
-	// calculer le nom de la css
4691
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4692
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4693
-	$contexte_implicite = calculer_contexte_implicite();
4694
-
4695
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4696
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4697
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4698
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4699
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4700
-	}
4701
-	else {
4702
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4703
-		ksort($contexte);
4704
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4705
-	}
4706
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4707
-
4708
-	// mettre a jour le fichier si il n'existe pas
4709
-	// ou trop ancien
4710
-	// le dernier fichier produit est toujours suffixe par .last
4711
-	// et recopie sur le fichier cible uniquement si il change
4712
-	if (!file_exists($filename)
4713
-		or !file_exists($filename . ".last")
4714
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4715
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4716
-	) {
4717
-		$contenu = $cache['texte'];
4718
-		// passer les urls en absolu si c'est une css
4719
-		if ($extension == "css") {
4720
-			$contenu = urls_absolues_css($contenu,
4721
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4722
-		}
4723
-
4724
-		$comment = '';
4725
-		// ne pas insérer de commentaire si c'est du json
4726
-		if ($extension != "json") {
4727
-			$comment = "/* #PRODUIRE{fond=$fond";
4728
-			foreach ($contexte as $k => $v) {
4729
-				$comment .= ",$k=$v";
4730
-			}
4731
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4732
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4733
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4734
-		}
4735
-		// et ecrire le fichier si il change
4736
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4737
-	}
4738
-
4739
-	return timestamp($filename);
4677
+    if (isset($contexte['format'])) {
4678
+        $extension = $contexte['format'];
4679
+        unset($contexte['format']);
4680
+    } else {
4681
+        $extension = "html";
4682
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4683
+            $extension = $m[1];
4684
+        }
4685
+    }
4686
+    // recuperer le contenu produit par le squelette
4687
+    $options['raw'] = true;
4688
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4689
+
4690
+    // calculer le nom de la css
4691
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4692
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4693
+    $contexte_implicite = calculer_contexte_implicite();
4694
+
4695
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4696
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4697
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4698
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4699
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4700
+    }
4701
+    else {
4702
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4703
+        ksort($contexte);
4704
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4705
+    }
4706
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4707
+
4708
+    // mettre a jour le fichier si il n'existe pas
4709
+    // ou trop ancien
4710
+    // le dernier fichier produit est toujours suffixe par .last
4711
+    // et recopie sur le fichier cible uniquement si il change
4712
+    if (!file_exists($filename)
4713
+        or !file_exists($filename . ".last")
4714
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4715
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4716
+    ) {
4717
+        $contenu = $cache['texte'];
4718
+        // passer les urls en absolu si c'est une css
4719
+        if ($extension == "css") {
4720
+            $contenu = urls_absolues_css($contenu,
4721
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4722
+        }
4723
+
4724
+        $comment = '';
4725
+        // ne pas insérer de commentaire si c'est du json
4726
+        if ($extension != "json") {
4727
+            $comment = "/* #PRODUIRE{fond=$fond";
4728
+            foreach ($contexte as $k => $v) {
4729
+                $comment .= ",$k=$v";
4730
+            }
4731
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4732
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4733
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4734
+        }
4735
+        // et ecrire le fichier si il change
4736
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4737
+    }
4738
+
4739
+    return timestamp($filename);
4740 4740
 }
4741 4741
 
4742 4742
 /**
@@ -4749,14 +4749,14 @@  discard block
 block discarded – undo
4749 4749
  *    $fichier auquel on a ajouté le timestamp
4750 4750
  */
4751 4751
 function timestamp($fichier) {
4752
-	if (!$fichier
4753
-		or !file_exists($fichier)
4754
-		or !$m = filemtime($fichier)
4755
-	) {
4756
-		return $fichier;
4757
-	}
4752
+    if (!$fichier
4753
+        or !file_exists($fichier)
4754
+        or !$m = filemtime($fichier)
4755
+    ) {
4756
+        return $fichier;
4757
+    }
4758 4758
 
4759
-	return "$fichier?$m";
4759
+    return "$fichier?$m";
4760 4760
 }
4761 4761
 
4762 4762
 /**
@@ -4766,11 +4766,11 @@  discard block
 block discarded – undo
4766 4766
  * @return string
4767 4767
  */
4768 4768
 function supprimer_timestamp($url) {
4769
-	if (strpos($url, "?") === false) {
4770
-		return $url;
4771
-	}
4769
+    if (strpos($url, "?") === false) {
4770
+        return $url;
4771
+    }
4772 4772
 
4773
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4773
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4774 4774
 }
4775 4775
 
4776 4776
 /**
@@ -4785,9 +4785,9 @@  discard block
 block discarded – undo
4785 4785
  * @return string
4786 4786
  */
4787 4787
 function filtre_nettoyer_titre_email_dist($titre) {
4788
-	include_spip('inc/envoyer_mail');
4788
+    include_spip('inc/envoyer_mail');
4789 4789
 
4790
-	return nettoyer_titre_email($titre);
4790
+    return nettoyer_titre_email($titre);
4791 4791
 }
4792 4792
 
4793 4793
 /**
@@ -4809,19 +4809,19 @@  discard block
 block discarded – undo
4809 4809
  * @return string
4810 4810
  */
4811 4811
 function filtre_chercher_rubrique_dist(
4812
-	$titre,
4813
-	$id_objet,
4814
-	$id_parent,
4815
-	$objet,
4816
-	$id_secteur,
4817
-	$restreint,
4818
-	$actionable = false,
4819
-	$retour_sans_cadre = false
4812
+    $titre,
4813
+    $id_objet,
4814
+    $id_parent,
4815
+    $objet,
4816
+    $id_secteur,
4817
+    $restreint,
4818
+    $actionable = false,
4819
+    $retour_sans_cadre = false
4820 4820
 ) {
4821
-	include_spip('inc/filtres_ecrire');
4821
+    include_spip('inc/filtres_ecrire');
4822 4822
 
4823
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4824
-		$retour_sans_cadre);
4823
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4824
+        $retour_sans_cadre);
4825 4825
 }
4826 4826
 
4827 4827
 /**
@@ -4850,56 +4850,56 @@  discard block
 block discarded – undo
4850 4850
  *     Chaîne vide si l'accès est autorisé
4851 4851
  */
4852 4852
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4853
-	if ($ok) {
4854
-		return '';
4855
-	}
4856
-
4857
-	// Vider tous les tampons
4858
-	$level = @ob_get_level();
4859
-	while ($level--) {
4860
-		@ob_end_clean();
4861
-	}
4862
-
4863
-	include_spip('inc/headers');
4864
-
4865
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4866
-	if ($url) {
4867
-		redirige_par_entete($url, '', $statut);
4868
-	}
4869
-
4870
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4871
-	if (!is_numeric($statut) and is_null($message)) {
4872
-		$message = $statut;
4873
-		$statut = 0;
4874
-	}
4875
-	if (!$message) {
4876
-		$message = '';
4877
-	}
4878
-	$statut = intval($statut);
4879
-
4880
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4881
-	if (test_espace_prive()) {
4882
-		if (!$statut or !in_array($statut, array(404, 403))) {
4883
-			$statut = 403;
4884
-		}
4885
-		http_status(403);
4886
-		$echec = charger_fonction('403', 'exec');
4887
-		$echec($message);
4888
-	} else {
4889
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4890
-		if (!$statut) {
4891
-			$statut = 404;
4892
-		}
4893
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4894
-		http_status($statut);
4895
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4896
-		if ($statut >= 400) {
4897
-			echo recuperer_fond("$statut", array('erreur' => $message));
4898
-		}
4899
-	}
4900
-
4901
-
4902
-	exit;
4853
+    if ($ok) {
4854
+        return '';
4855
+    }
4856
+
4857
+    // Vider tous les tampons
4858
+    $level = @ob_get_level();
4859
+    while ($level--) {
4860
+        @ob_end_clean();
4861
+    }
4862
+
4863
+    include_spip('inc/headers');
4864
+
4865
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4866
+    if ($url) {
4867
+        redirige_par_entete($url, '', $statut);
4868
+    }
4869
+
4870
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4871
+    if (!is_numeric($statut) and is_null($message)) {
4872
+        $message = $statut;
4873
+        $statut = 0;
4874
+    }
4875
+    if (!$message) {
4876
+        $message = '';
4877
+    }
4878
+    $statut = intval($statut);
4879
+
4880
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4881
+    if (test_espace_prive()) {
4882
+        if (!$statut or !in_array($statut, array(404, 403))) {
4883
+            $statut = 403;
4884
+        }
4885
+        http_status(403);
4886
+        $echec = charger_fonction('403', 'exec');
4887
+        $echec($message);
4888
+    } else {
4889
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4890
+        if (!$statut) {
4891
+            $statut = 404;
4892
+        }
4893
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4894
+        http_status($statut);
4895
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4896
+        if ($statut >= 400) {
4897
+            echo recuperer_fond("$statut", array('erreur' => $message));
4898
+        }
4899
+    }
4900
+
4901
+
4902
+    exit;
4903 4903
 }
4904 4904
 
4905 4905
 /**
@@ -4910,11 +4910,11 @@  discard block
 block discarded – undo
4910 4910
  * @return string
4911 4911
  */
4912 4912
 function filtre_compacte_dist($source, $format = null) {
4913
-	if (function_exists('compacte')) {
4914
-		return compacte($source, $format);
4915
-	}
4913
+    if (function_exists('compacte')) {
4914
+        return compacte($source, $format);
4915
+    }
4916 4916
 
4917
-	return $source;
4917
+    return $source;
4918 4918
 }
4919 4919
 
4920 4920
 
@@ -4926,29 +4926,29 @@  discard block
 block discarded – undo
4926 4926
  * @return string
4927 4927
  */
4928 4928
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
4929
-	$l = strlen($passe);
4930
-
4931
-	if ($l<=8 or !$afficher_partiellement){
4932
-		if (!$l) {
4933
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4934
-		}
4935
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
4936
-	}
4937
-
4938
-	if (is_null($portion_pourcent)) {
4939
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4940
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4941
-		}
4942
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4943
-	}
4944
-	if ($portion_pourcent >= 100) {
4945
-		return $passe;
4946
-	}
4947
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
4948
-	$e = max($e, 0);
4949
-	$mid = str_pad('',$l-2*$e,'*');
4950
-	if ($e>0 and strlen($mid)>8){
4951
-		$mid = '***...***';
4952
-	}
4953
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4929
+    $l = strlen($passe);
4930
+
4931
+    if ($l<=8 or !$afficher_partiellement){
4932
+        if (!$l) {
4933
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4934
+        }
4935
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
4936
+    }
4937
+
4938
+    if (is_null($portion_pourcent)) {
4939
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
4940
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
4941
+        }
4942
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
4943
+    }
4944
+    if ($portion_pourcent >= 100) {
4945
+        return $passe;
4946
+    }
4947
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
4948
+    $e = max($e, 0);
4949
+    $mid = str_pad('',$l-2*$e,'*');
4950
+    if ($e>0 and strlen($mid)>8){
4951
+        $mid = '***...***';
4952
+    }
4953
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4954 4954
 }
4955 4955
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	}
95 95
 
96 96
 	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
97
+	foreach (array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f) {
98 98
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99 99
 		// fonction ou name\space\fonction
100 100
 		if (is_callable($f)) {
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	// affichage "GIT [master: abcdef]"
188 188
 	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
189 189
 	if ($desc['branch']) {
190
-		$commit = $desc['branch'] . ': ' . $commit;
190
+		$commit = $desc['branch'].': '.$commit;
191 191
 	}
192 192
 	return "{$desc['vcs']} [$commit]";
193 193
 }
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 	}
207 207
 
208 208
 	// version installee par GIT
209
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
209
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
210 210
 		$currentHead = trim(substr($c, 4));
211
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
211
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
212 212
 			return [
213 213
 				'vcs' => 'GIT',
214 214
 				'branch' => basename($currentHead),
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
 		$dir = '.';
236 236
 	}
237 237
 	// version installee par SVN
238
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
239
-		$db = new SQLite3($dir . '/.svn/wc.db');
238
+	if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) {
239
+		$db = new SQLite3($dir.'/.svn/wc.db');
240 240
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
241 241
 		if ($result) {
242 242
 			$row = $result->fetchArray();
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
 
276 276
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
277 277
 // et laisser passer les fonctions personnelles baptisees image_...
278
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
279
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
280
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
281
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
282
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
278
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
279
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
280
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
281
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
282
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
283 283
 
284 284
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
285 285
 $GLOBALS['spip_matrice']['couleur_foncer'] = 'inc/filtres_images_mini.php';
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
  */
437 437
 function filtre_debug($val, $key = null) {
438 438
 	$debug = (
439
-		is_null($key) ? '' : (var_export($key, true) . " = ")
440
-		) . var_export($val, true);
439
+		is_null($key) ? '' : (var_export($key, true)." = ")
440
+		).var_export($val, true);
441 441
 
442 442
 	include_spip('inc/autoriser');
443 443
 	if (autoriser('webmestre')) {
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
526 526
 							$srcover = $match[1];
527 527
 							array_shift($args);
528
-							array_unshift($args, "<img src='" . $match[1] . "' />");
528
+							array_unshift($args, "<img src='".$match[1]."' />");
529 529
 							$srcover_filter = call_user_func_array($filtre, $args);
530 530
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
531 531
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 	// " -> &quot; et tout ce genre de choses
876 876
 	$u = $GLOBALS['meta']['pcre_u'];
877 877
 	$texte = str_replace("&nbsp;", " ", $texte);
878
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
878
+	$texte = preg_replace('/\s{2,}/S'.$u, " ", $texte);
879 879
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
880 880
 	$texte = entites_html($texte, false, false);
881 881
 	// mais bien echapper les double quotes !
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
  **/
936 936
 function supprimer_numero($texte) {
937 937
 	return preg_replace(
938
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
938
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
939 939
 		"", $texte);
940 940
 }
941 941
 
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
  **/
961 961
 function recuperer_numero($texte) {
962 962
 	if (preg_match(
963
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
963
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
964 964
 		$texte, $regs)) {
965 965
 		return strval($regs[1]);
966 966
 	} else {
@@ -1045,8 +1045,8 @@  discard block
 block discarded – undo
1045 1045
  **/
1046 1046
 function textebrut($texte) {
1047 1047
 	$u = $GLOBALS['meta']['pcre_u'];
1048
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1049
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1048
+	$texte = preg_replace('/\s+/S'.$u, " ", $texte);
1049
+	$texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte);
1050 1050
 	$texte = preg_replace("/^\n+/", "", $texte);
1051 1051
 	$texte = preg_replace("/\n+$/", "", $texte);
1052 1052
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1075 1075
 		$texte, $liens, PREG_PATTERN_ORDER)) {
1076 1076
 		foreach ($liens[0] as $a) {
1077
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1077
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1078 1078
 			$ablank = inserer_attribut($a, 'rel', $rel);
1079 1079
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1080 1080
 			$texte = str_replace($a, $ablank, $texte);
@@ -1099,7 +1099,7 @@  discard block
 block discarded – undo
1099 1099
 		foreach ($regs[0] as $a) {
1100 1100
 			$rel = extraire_attribut($a, "rel");
1101 1101
 			if (strpos($rel, "nofollow") === false) {
1102
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1102
+				$rel = "nofollow".($rel ? " $rel" : "");
1103 1103
 				$anofollow = inserer_attribut($a, "rel", $rel);
1104 1104
 				$texte = str_replace($a, $anofollow, $texte);
1105 1105
 			}
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
 	$u = $GLOBALS['meta']['pcre_u'];
1129 1129
 	$texte = preg_replace("@</p>@iS", "\n", $texte);
1130 1130
 	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1131
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1131
+	$texte = preg_replace("@^\s*<br />@S".$u, "", $texte);
1132 1132
 
1133 1133
 	return $texte;
1134 1134
 }
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
 		return $texte;
1159 1159
 	}
1160 1160
 	include_spip('inc/texte');
1161
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1161
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1162 1162
 		'div' : 'span';
1163 1163
 
1164 1164
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
 function attribut_html($texte, $textebrut = true) {
1268 1268
 	$u = $GLOBALS['meta']['pcre_u'];
1269 1269
 	if ($textebrut) {
1270
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1270
+		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS".$u), array(" ", ""), textebrut($texte));
1271 1271
 	}
1272 1272
 	$texte = texte_backend($texte);
1273 1273
 	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
 	# un message pour abs_url
1297 1297
 	$GLOBALS['mode_abs_url'] = 'url';
1298 1298
 	$url = trim($url);
1299
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1299
+	$r = ",^(?:"._PROTOCOLES_STD.'):?/?/?$,iS';
1300 1300
 
1301 1301
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1302 1302
 }
@@ -1498,14 +1498,14 @@  discard block
 block discarded – undo
1498 1498
 	if (strpos($texte, "<") !== false) {
1499 1499
 		include_spip('inc/lien');
1500 1500
 		if (defined('_PREG_MODELE')) {
1501
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1501
+			$preg_modeles = "@"._PREG_MODELE."@imsS";
1502 1502
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1503 1503
 		}
1504 1504
 	}
1505 1505
 
1506 1506
 	$debut = '';
1507 1507
 	$suite = $texte;
1508
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1508
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1509 1509
 		$debut .= substr($suite, 0, $t - 1);
1510 1510
 		$suite = substr($suite, $t);
1511 1511
 		$car = substr($suite, 0, 1);
@@ -1522,11 +1522,11 @@  discard block
 block discarded – undo
1522 1522
 			$suite = substr($suite, strlen($regs[0]));
1523 1523
 		}
1524 1524
 	}
1525
-	$texte = $debut . $suite;
1525
+	$texte = $debut.$suite;
1526 1526
 
1527 1527
 	$texte = echappe_retour($texte);
1528 1528
 
1529
-	return $texte . $fin;
1529
+	return $texte.$fin;
1530 1530
 }
1531 1531
 
1532 1532
 
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
 		}
1588 1588
 
1589 1589
 		foreach ($regs as $reg) {
1590
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1590
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1591 1591
 			$desc = $traduire($cle, $lang, true);
1592 1592
 			$l = $desc->langue;
1593 1593
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1700,7 +1700,7 @@  discard block
 block discarded – undo
1700 1700
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1701 1701
 					include_spip('inc/texte');
1702 1702
 					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1703
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1703
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1704 1704
 					$trad = code_echappement($trad, 'multi', false, $mode);
1705 1705
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1706 1706
 					if (lang_dir($l) !== lang_dir($lang)) {
@@ -1893,7 +1893,7 @@  discard block
 block discarded – undo
1893 1893
 	if (is_array($balise)) {
1894 1894
 		array_walk(
1895 1895
 			$balise,
1896
-			function(&$a, $key, $t){
1896
+			function(&$a, $key, $t) {
1897 1897
 				$a = extraire_attribut($a, $t);
1898 1898
 			},
1899 1899
 			$attribut
@@ -1980,14 +1980,14 @@  discard block
 block discarded – undo
1980 1980
 
1981 1981
 	if ($old !== null) {
1982 1982
 		// Remplacer l'ancien attribut du meme nom
1983
-		$balise = $r[1] . $insert . $r[5];
1983
+		$balise = $r[1].$insert.$r[5];
1984 1984
 	} else {
1985 1985
 		// preferer une balise " />" (comme <img />)
1986 1986
 		if (preg_match(',/>,', $balise)) {
1987
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1987
+			$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1988 1988
 		} // sinon une balise <a ...> ... </a>
1989 1989
 		else {
1990
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1990
+			$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1991 1991
 		}
1992 1992
 	}
1993 1993
 
@@ -2029,8 +2029,8 @@  discard block
 block discarded – undo
2029 2029
 //
2030 2030
 // Quelques fonctions de calcul arithmetique
2031 2031
 //
2032
-function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
2033
-function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
2032
+function floatstr($a) { return str_replace(',', '.', (string) floatval($a)); }
2033
+function strize($f, $a, $b) { return floatstr($f(floatstr($a), floatstr($b))); }
2034 2034
 
2035 2035
 /**
2036 2036
  * Additionne 2 nombres
@@ -2050,7 +2050,7 @@  discard block
 block discarded – undo
2050 2050
 function plus($a, $b) {
2051 2051
 	return $a + $b;
2052 2052
 }
2053
-function strplus($a, $b) {return strize('plus', $a, $b);}
2053
+function strplus($a, $b) {return strize('plus', $a, $b); }
2054 2054
 /**
2055 2055
  * Soustrait 2 nombres
2056 2056
  *
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
 function moins($a, $b) {
2070 2070
 	return $a - $b;
2071 2071
 }
2072
-function strmoins($a, $b) {return strize('moins', $a, $b);}
2072
+function strmoins($a, $b) {return strize('moins', $a, $b); }
2073 2073
 
2074 2074
 /**
2075 2075
  * Multiplie 2 nombres
@@ -2090,7 +2090,7 @@  discard block
 block discarded – undo
2090 2090
 function mult($a, $b) {
2091 2091
 	return $a * $b;
2092 2092
 }
2093
-function strmult($a, $b) {return strize('mult', $a, $b);}
2093
+function strmult($a, $b) {return strize('mult', $a, $b); }
2094 2094
 
2095 2095
 /**
2096 2096
  * Divise 2 nombres
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
 function div($a, $b) {
2112 2112
 	return $b ? $a / $b : 0;
2113 2113
 }
2114
-function strdiv($a, $b) {return strize('div', $a, $b);}
2114
+function strdiv($a, $b) {return strize('div', $a, $b); }
2115 2115
 
2116 2116
 /**
2117 2117
  * Retourne le modulo 2 nombres
@@ -2152,13 +2152,13 @@  discard block
 block discarded – undo
2152 2152
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2153 2153
 		define('_TAGS_NOM_AUTEUR', '');
2154 2154
 	}
2155
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2155
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2156 2156
 	foreach ($tags_acceptes as $tag) {
2157 2157
 		if (strlen($tag)) {
2158
-			$remp1[] = '<' . trim($tag) . '>';
2159
-			$remp1[] = '</' . trim($tag) . '>';
2160
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2161
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2158
+			$remp1[] = '<'.trim($tag).'>';
2159
+			$remp1[] = '</'.trim($tag).'>';
2160
+			$remp2[] = '\x60'.trim($tag).'\x61';
2161
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2162 2162
 		}
2163 2163
 	}
2164 2164
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2221,7 +2221,7 @@  discard block
 block discarded – undo
2221 2221
 			$s[] = preg_replace(',>[^<]+</a>,S',
2222 2222
 				'>'
2223 2223
 				. http_img_pack('attachment-16.png', $t,
2224
-					'title="' . attribut_html($t) . '"')
2224
+					'title="'.attribut_html($t).'"')
2225 2225
 				. '</a>', $tag);
2226 2226
 		}
2227 2227
 	}
@@ -2282,10 +2282,10 @@  discard block
 block discarded – undo
2282 2282
 	$fichier = basename($url);
2283 2283
 
2284 2284
 	return '<a rel="enclosure"'
2285
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2286
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2287
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2288
-	. '>' . $fichier . '</a>';
2285
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2286
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2287
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2288
+	. '>'.$fichier.'</a>';
2289 2289
 }
2290 2290
 
2291 2291
 /**
@@ -2313,9 +2313,9 @@  discard block
 block discarded – undo
2313 2313
 			} # vieux data
2314 2314
 			$fichier = basename($url);
2315 2315
 			$enclosures[] = '<enclosure'
2316
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2317
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2318
-				. ($length ? ' length="' . $length . '"' : '')
2316
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2317
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2318
+				. ($length ? ' length="'.$length.'"' : '')
2319 2319
 				. ' />';
2320 2320
 		}
2321 2321
 	}
@@ -2341,7 +2341,7 @@  discard block
 block discarded – undo
2341 2341
 		if (extraire_attribut($e, rel) == 'tag') {
2342 2342
 			$subjects .= '<dc:subject>'
2343 2343
 				. texte_backend(textebrut($e))
2344
-				. '</dc:subject>' . "\n";
2344
+				. '</dc:subject>'."\n";
2345 2345
 		}
2346 2346
 	}
2347 2347
 
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
 	if (is_array($texte)) {
2378 2378
 		array_walk(
2379 2379
 			$texte,
2380
-			function(&$a, $key, $t){
2380
+			function(&$a, $key, $t) {
2381 2381
 				$a = extraire_balise($a, $t);
2382 2382
 			},
2383 2383
 			$tag
@@ -2421,7 +2421,7 @@  discard block
 block discarded – undo
2421 2421
 	if (is_array($texte)) {
2422 2422
 		array_walk(
2423 2423
 			$texte,
2424
-			function(&$a, $key, $t){
2424
+			function(&$a, $key, $t) {
2425 2425
 				$a = extraire_balises($a, $t);
2426 2426
 			},
2427 2427
 			$tag
@@ -2547,7 +2547,7 @@  discard block
 block discarded – undo
2547 2547
 		if ($fond != '404') {
2548 2548
 			$contexte = array_shift($p);
2549 2549
 			$contexte['page'] = $fond;
2550
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2550
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2551 2551
 		}
2552 2552
 	}
2553 2553
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2602,9 +2602,9 @@  discard block
 block discarded – undo
2602 2602
 			. '"'
2603 2603
 			. (is_null($val)
2604 2604
 				? ''
2605
-				: ' value="' . entites_html($val) . '"'
2605
+				: ' value="'.entites_html($val).'"'
2606 2606
 			)
2607
-			. ' type="hidden"' . "\n/>";
2607
+			. ' type="hidden"'."\n/>";
2608 2608
 	}
2609 2609
 
2610 2610
 	return join("", $hidden);
@@ -2767,12 +2767,12 @@  discard block
 block discarded – undo
2767 2767
 	if ($pas < 1) {
2768 2768
 		return '';
2769 2769
 	}
2770
-	$ancre = 'pagination' . $nom; // #pagination_articles
2771
-	$debut = 'debut' . $nom; // 'debut_articles'
2770
+	$ancre = 'pagination'.$nom; // #pagination_articles
2771
+	$debut = 'debut'.$nom; // 'debut_articles'
2772 2772
 
2773 2773
 	// n'afficher l'ancre qu'une fois
2774 2774
 	if (!isset($ancres[$ancre])) {
2775
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2775
+		$bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2776 2776
 	} else {
2777 2777
 		$bloc_ancre = '';
2778 2778
 	}
@@ -2803,7 +2803,7 @@  discard block
 block discarded – undo
2803 2803
 	}
2804 2804
 
2805 2805
 	if ($modele) {
2806
-		$modele = '_' . $modele;
2806
+		$modele = '_'.$modele;
2807 2807
 	}
2808 2808
 
2809 2809
 	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
@@ -2828,7 +2828,7 @@  discard block
 block discarded – undo
2828 2828
 	return preg_replace_callback(
2829 2829
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2830 2830
 		function($x) use ($path) {
2831
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2831
+			return "url('".suivre_lien($path, $x[1])."')";
2832 2832
 		},
2833 2833
 		$contenu
2834 2834
 	);
@@ -2890,14 +2890,14 @@  discard block
 block discarded – undo
2890 2890
 	) {
2891 2891
 		$distant = true;
2892 2892
 		$cssf = parse_url($css);
2893
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2893
+		$cssf = $cssf['path'].($cssf['query'] ? "?".$cssf['query'] : "");
2894 2894
 		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2895 2895
 	} else {
2896 2896
 		$distant = false;
2897 2897
 		$cssf = $css;
2898 2898
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2899 2899
 		//propose (rien a faire dans ce cas)
2900
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2900
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2901 2901
 		if (@file_exists($f)) {
2902 2902
 			return $f;
2903 2903
 		}
@@ -2907,7 +2907,7 @@  discard block
 block discarded – undo
2907 2907
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2908 2908
 	$f = $dir_var
2909 2909
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2910
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2910
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2911 2911
 
2912 2912
 	// la css peut etre distante (url absolue !)
2913 2913
 	if ($distant) {
@@ -2952,8 +2952,8 @@  discard block
 block discarded – undo
2952 2952
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2953 2953
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2954 2954
 			$css_direction = substr($css_direction, strlen($dir_var));
2955
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2956
-			$css_direction = "/@@@@@@/" . $css_direction;
2955
+			$src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2956
+			$css_direction = "/@@@@@@/".$css_direction;
2957 2957
 		}
2958 2958
 		$src[] = $regs[0][$k];
2959 2959
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3002,7 +3002,7 @@  discard block
 block discarded – undo
3002 3002
 
3003 3003
 	$f = basename($css, '.css');
3004 3004
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3005
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3005
+		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3006 3006
 		. '.css';
3007 3007
 
3008 3008
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3011,7 +3011,7 @@  discard block
 block discarded – undo
3011 3011
 
3012 3012
 	if ($url_absolue_css == $css) {
3013 3013
 		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3014
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3014
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3015 3015
 		) {
3016 3016
 			include_spip('inc/distant');
3017 3017
 			if (!$contenu = recuperer_page($css)) {
@@ -3121,7 +3121,7 @@  discard block
 block discarded – undo
3121 3121
 	$expression = str_replace("\/", "/", $expression);
3122 3122
 	$expression = str_replace("/", "\/", $expression);
3123 3123
 
3124
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3124
+	if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) {
3125 3125
 		if (isset($r[$capte])) {
3126 3126
 			return $r[$capte];
3127 3127
 		} else {
@@ -3159,7 +3159,7 @@  discard block
 block discarded – undo
3159 3159
 	$expression = str_replace("\/", "/", $expression);
3160 3160
 	$expression = str_replace("/", "\/", $expression);
3161 3161
 
3162
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3162
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3163 3163
 }
3164 3164
 
3165 3165
 
@@ -3178,7 +3178,7 @@  discard block
 block discarded – undo
3178 3178
 function traiter_doublons_documents(&$doublons, $letexte) {
3179 3179
 
3180 3180
 	// Verifier dans le texte & les notes (pas beau, helas)
3181
-	$t = $letexte . $GLOBALS['les_notes'];
3181
+	$t = $letexte.$GLOBALS['les_notes'];
3182 3182
 
3183 3183
 	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3184 3184
 		and preg_match_all(
@@ -3188,7 +3188,7 @@  discard block
 block discarded – undo
3188 3188
 		if (!isset($doublons['documents'])) {
3189 3189
 			$doublons['documents'] = "";
3190 3190
 		}
3191
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3191
+		$doublons['documents'] .= ",".join(',', $matches[1]);
3192 3192
 	}
3193 3193
 
3194 3194
 	return $letexte;
@@ -3245,7 +3245,7 @@  discard block
 block discarded – undo
3245 3245
 	if ($env) {
3246 3246
 		foreach ($env as $i => $j) {
3247 3247
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3248
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3248
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3249 3249
 			}
3250 3250
 		}
3251 3251
 	}
@@ -3284,7 +3284,7 @@  discard block
 block discarded – undo
3284 3284
 	if ($env) {
3285 3285
 		foreach ($env as $i => $j) {
3286 3286
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3287
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3287
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3288 3288
 			}
3289 3289
 		}
3290 3290
 	}
@@ -3368,19 +3368,19 @@  discard block
 block discarded – undo
3368 3368
 
3369 3369
 	$img_file = $img;
3370 3370
 	if ($p = strpos($img_file, '?')) {
3371
-		$img_file = substr($img_file,0, $p);
3371
+		$img_file = substr($img_file, 0, $p);
3372 3372
 	}
3373 3373
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3374 3374
 		$img_file = chemin_image($img);
3375 3375
 	}
3376 3376
 	else {
3377
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3377
+		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3378 3378
 			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3379 3379
 			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3380 3380
 			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3381
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3381
+			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0]))."-xx.svg"
3382 3382
 			  and file_exists($variante_svg_generique)) {
3383
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3383
+				if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].".svg" and file_exists($variante_svg_size)) {
3384 3384
 					$img_file = $variante_svg_size;
3385 3385
 				}
3386 3386
 				else {
@@ -3405,15 +3405,15 @@  discard block
 block discarded – undo
3405 3405
 				return "";
3406 3406
 			}
3407 3407
 		}
3408
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3408
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3409 3409
 	}
3410 3410
 
3411 3411
 	if (file_exists($img_file)) {
3412 3412
 		$img_file = timestamp($img_file);
3413 3413
 	}
3414
-	return "<img src='$img_file' alt='" . attribut_html($alt ? $alt : $title) . "'"
3415
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3416
-	. " " . ltrim($atts)
3414
+	return "<img src='$img_file' alt='".attribut_html($alt ? $alt : $title)."'"
3415
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3416
+	. " ".ltrim($atts)
3417 3417
 	. " />";
3418 3418
 }
3419 3419
 
@@ -3425,12 +3425,12 @@  discard block
 block discarded – undo
3425 3425
  * @param string $size
3426 3426
  * @return string
3427 3427
  */
3428
-function http_style_background($img, $att = '', $size=null) {
3429
-	if ($size and is_numeric($size)){
3430
-		$size = trim($size) . "px";
3428
+function http_style_background($img, $att = '', $size = null) {
3429
+	if ($size and is_numeric($size)) {
3430
+		$size = trim($size)."px";
3431 3431
 	}
3432
-	return " style='background" .
3433
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3432
+	return " style='background".
3433
+		($att ? "" : "-image").": url(\"".chemin_image($img)."\")".($att ? (' '.$att) : '').";"
3434 3434
 		. ($size ? "background-size:{$size};" : '')
3435 3435
 		. "'";
3436 3436
 }
@@ -3447,8 +3447,8 @@  discard block
 block discarded – undo
3447 3447
  * @return string
3448 3448
  *     Code HTML de la balise IMG
3449 3449
  */
3450
-function filtre_balise_img_dist($img, $alt = "", $class = "", $width=null) {
3451
-	$atts = $class ? " class='" . attribut_html($class) . "'" : '';
3450
+function filtre_balise_img_dist($img, $alt = "", $class = "", $width = null) {
3451
+	$atts = $class ? " class='".attribut_html($class)."'" : '';
3452 3452
 	// ecriture courte : on donne le width en 2e arg
3453 3453
 	if (empty($width) and is_numeric($alt)) {
3454 3454
 		$width = $alt;
@@ -3476,7 +3476,7 @@  discard block
 block discarded – undo
3476 3476
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3477 3477
 	$img_file = $img;
3478 3478
 	if ($p = strpos($img_file, '?')) {
3479
-		$img_file = substr($img_file,0, $p);
3479
+		$img_file = substr($img_file, 0, $p);
3480 3480
 	}
3481 3481
 
3482 3482
 	if (!$img_file or !$svg = file_get_contents($img_file)) {
@@ -3490,18 +3490,18 @@  discard block
 block discarded – undo
3490 3490
 	$balise_svg_source = $balise_svg;
3491 3491
 
3492 3492
 	// entete XML à supprimer
3493
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3493
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3494 3494
 
3495 3495
 	// IE est toujours mon ami
3496 3496
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3497 3497
 	if ($class) {
3498 3498
 		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3499 3499
 	}
3500
-	if ($alt){
3500
+	if ($alt) {
3501 3501
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3502
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3502
+		$id = "img-svg-title-".substr(md5("$img_file:$svg:$alt"), 0, 4);
3503 3503
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3504
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3504
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3505 3505
 		$balise_svg .= $title;
3506 3506
 	}
3507 3507
 	else {
@@ -3535,7 +3535,7 @@  discard block
 block discarded – undo
3535 3535
 	$texte = '';
3536 3536
 	if (is_array($tableau)) {
3537 3537
 		foreach ($tableau as $k => $v) {
3538
-			$res = recuperer_fond('modeles/' . $modele,
3538
+			$res = recuperer_fond('modeles/'.$modele,
3539 3539
 				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3540 3540
 			);
3541 3541
 			$texte .= $res;
@@ -3712,7 +3712,7 @@  discard block
 block discarded – undo
3712 3712
 	}
3713 3713
 
3714 3714
 	$c = serialize($c);
3715
-	$cle = calculer_cle_action($form . $c);
3715
+	$cle = calculer_cle_action($form.$c);
3716 3716
 	$c = "$cle:$c";
3717 3717
 
3718 3718
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -3774,15 +3774,15 @@  discard block
 block discarded – undo
3774 3774
 	}
3775 3775
 	// toujours encoder l'url source dans le bloc ajax
3776 3776
 	$r = self();
3777
-	$r = ' data-origin="' . $r . '"';
3777
+	$r = ' data-origin="'.$r.'"';
3778 3778
 	$class = 'ajaxbloc';
3779 3779
 	if ($ajaxid and is_string($ajaxid)) {
3780 3780
 		// ajaxid est normalement conforme a un nom de classe css
3781 3781
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3782
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3782
+		$class .= ' ajax-id-'.entites_html($ajaxid);
3783 3783
 	}
3784 3784
 
3785
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3785
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3786 3786
 }
3787 3787
 
3788 3788
 /**
@@ -3821,11 +3821,11 @@  discard block
 block discarded – undo
3821 3821
 	// extraire la signature en debut de contexte
3822 3822
 	// et la verifier avant de deserializer
3823 3823
 	// format : signature:donneesserializees
3824
-	if ($p = strpos($c,":")){
3825
-		$cle = substr($c,0,$p);
3826
-		$c = substr($c,$p+1);
3824
+	if ($p = strpos($c, ":")) {
3825
+		$cle = substr($c, 0, $p);
3826
+		$c = substr($c, $p + 1);
3827 3827
 
3828
-		if ($cle == calculer_cle_action($form . $c)) {
3828
+		if ($cle == calculer_cle_action($form.$c)) {
3829 3829
 			$env = @unserialize($c);
3830 3830
 			return $env;
3831 3831
 		}
@@ -3926,9 +3926,9 @@  discard block
 block discarded – undo
3926 3926
 	} else {
3927 3927
 		$bal = 'a';
3928 3928
 		$att = "href='$url'"
3929
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3930
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3931
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3929
+			. ($title ? " title='".attribut_html($title)."'" : '')
3930
+			. ($class ? " class='".attribut_html($class)."'" : '')
3931
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
3932 3932
 			. $evt;
3933 3933
 	}
3934 3934
 	if ($libelle === null) {
@@ -4003,7 +4003,7 @@  discard block
 block discarded – undo
4003 4003
 	}
4004 4004
 
4005 4005
 	// ajouter le type d'objet dans la class de l'icone
4006
-	$class .= " " . substr(basename($fond), 0, -4);
4006
+	$class .= " ".substr(basename($fond), 0, -4);
4007 4007
 
4008 4008
 	$alt = attribut_html($texte);
4009 4009
 	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
@@ -4027,7 +4027,7 @@  discard block
 block discarded – undo
4027 4027
 	}
4028 4028
 
4029 4029
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4030
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4030
+	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "")."\">$icone</span>";
4031 4031
 
4032 4032
 	if ($type == 'lien') {
4033 4033
 		return "<span class='icone s$size $class'>"
@@ -4257,13 +4257,13 @@  discard block
 block discarded – undo
4257 4257
 	$res = "";
4258 4258
 	foreach ($boutons as $page => $detail) {
4259 4259
 		if ($detail->icone and strlen(trim($detail->icone))) {
4260
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4260
+			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
4261 4261
 		}
4262 4262
 		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4263 4263
 		if (is_array($detail->sousmenu)) {
4264 4264
 			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4265 4265
 				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4266
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4266
+					$res .= "\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
4267 4267
 				}
4268 4268
 			}
4269 4269
 		}
@@ -4289,17 +4289,17 @@  discard block
 block discarded – undo
4289 4289
  */
4290 4290
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4291 4291
 	if ($confirm) {
4292
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4292
+		$confirm = "confirm(\"".attribut_html($confirm)."\")";
4293 4293
 		if ($callback) {
4294 4294
 			$callback = "$confirm?($callback):false";
4295 4295
 		} else {
4296 4296
 			$callback = $confirm;
4297 4297
 		}
4298 4298
 	}
4299
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4299
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : "";
4300 4300
 	$title = $title ? " title='$title'" : "";
4301 4301
 
4302
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4302
+	return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url)
4303 4303
 	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4304 4304
 }
4305 4305
 
@@ -4360,14 +4360,14 @@  discard block
 block discarded – undo
4360 4360
 		$champ_titre = "";
4361 4361
 		if ($demande_titre) {
4362 4362
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4363
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4363
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4364 4364
 		}
4365 4365
 		include_spip('base/abstract_sql');
4366 4366
 		include_spip('base/connect_sql');
4367 4367
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4368
-			'*' . $champ_titre,
4368
+			'*'.$champ_titre,
4369 4369
 			$desc['table_sql'],
4370
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4370
+			id_table_objet($type_objet).' = '.intval($id_objet)
4371 4371
 		);
4372 4372
 	}
4373 4373
 
@@ -4437,7 +4437,7 @@  discard block
 block discarded – undo
4437 4437
 		return $texte;
4438 4438
 	}
4439 4439
 
4440
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4440
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4441 4441
 
4442 4442
 	// Fournir $connect et $Pile[0] au traitement si besoin
4443 4443
 	$Pile = array(0 => $env);
@@ -4471,7 +4471,7 @@  discard block
 block discarded – undo
4471 4471
 	}
4472 4472
 	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4473 4473
 
4474
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4474
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur)."</a>";
4475 4475
 }
4476 4476
 
4477 4477
 
@@ -4490,10 +4490,10 @@  discard block
 block discarded – undo
4490 4490
 function wrap($texte, $wrap) {
4491 4491
 	$balises = extraire_balises($wrap);
4492 4492
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4493
-		$texte = $wrap . $texte;
4493
+		$texte = $wrap.$texte;
4494 4494
 		$regs = array_reverse($regs[1]);
4495
-		$wrap = "</" . implode("></", $regs) . ">";
4496
-		$texte = $texte . $wrap;
4495
+		$wrap = "</".implode("></", $regs).">";
4496
+		$texte = $texte.$wrap;
4497 4497
 	}
4498 4498
 
4499 4499
 	return $texte;
@@ -4524,7 +4524,7 @@  discard block
 block discarded – undo
4524 4524
 
4525 4525
 	// caster $u en array si besoin
4526 4526
 	if (is_object($u)) {
4527
-		$u = (array)$u;
4527
+		$u = (array) $u;
4528 4528
 	}
4529 4529
 
4530 4530
 	if (is_array($u)) {
@@ -4545,7 +4545,7 @@  discard block
 block discarded – undo
4545 4545
 		// sinon on passe a la ligne et on indente
4546 4546
 		$i_str = str_pad("", $indent, " ");
4547 4547
 		foreach ($u as $k => $v) {
4548
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4548
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4549 4549
 		}
4550 4550
 
4551 4551
 		return $out;
@@ -4598,8 +4598,8 @@  discard block
 block discarded – undo
4598 4598
  * @param string $class
4599 4599
  * @return string
4600 4600
  */
4601
-function objet_icone($objet, $taille = 24, $class='') {
4602
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4601
+function objet_icone($objet, $taille = 24, $class = '') {
4602
+	$icone = objet_info($objet, 'icone_objet')."-".$taille.".png";
4603 4603
 	$icone = chemin_image($icone);
4604 4604
 	$balise_img = charger_filtre('balise_img');
4605 4605
 
@@ -4623,12 +4623,12 @@  discard block
 block discarded – undo
4623 4623
  * @param array $options
4624 4624
  * @return string
4625 4625
  */
4626
-function objet_T($objet, $chaine, $args = array(), $options = array()){
4627
-	$chaine = explode(':',$chaine);
4628
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4626
+function objet_T($objet, $chaine, $args = array(), $options = array()) {
4627
+	$chaine = explode(':', $chaine);
4628
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, array('force'=>false)))) {
4629 4629
 		return $t;
4630 4630
 	}
4631
-	$chaine = implode(':',$chaine);
4631
+	$chaine = implode(':', $chaine);
4632 4632
 	return _T($chaine, $args, $options);
4633 4633
 }
4634 4634
 
@@ -4688,7 +4688,7 @@  discard block
 block discarded – undo
4688 4688
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4689 4689
 
4690 4690
 	// calculer le nom de la css
4691
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4691
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
4692 4692
 	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4693 4693
 	$contexte_implicite = calculer_contexte_implicite();
4694 4694
 
@@ -4696,22 +4696,22 @@  discard block
 block discarded – undo
4696 4696
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4697 4697
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4698 4698
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4699
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4699
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
4700 4700
 	}
4701 4701
 	else {
4702 4702
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4703 4703
 		ksort($contexte);
4704
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4704
+		$hash = md5($fond.json_encode($contexte_implicite).json_encode($contexte).$connect);
4705 4705
 	}
4706
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4706
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
4707 4707
 
4708 4708
 	// mettre a jour le fichier si il n'existe pas
4709 4709
 	// ou trop ancien
4710 4710
 	// le dernier fichier produit est toujours suffixe par .last
4711 4711
 	// et recopie sur le fichier cible uniquement si il change
4712 4712
 	if (!file_exists($filename)
4713
-		or !file_exists($filename . ".last")
4714
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4713
+		or !file_exists($filename.".last")
4714
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.".last") < $cache['lastmodified'])
4715 4715
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4716 4716
 	) {
4717 4717
 		$contenu = $cache['texte'];
@@ -4730,10 +4730,10 @@  discard block
 block discarded – undo
4730 4730
 			}
4731 4731
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4732 4732
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4733
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4733
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
4734 4734
 		}
4735 4735
 		// et ecrire le fichier si il change
4736
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4736
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
4737 4737
 	}
4738 4738
 
4739 4739
 	return timestamp($filename);
@@ -4928,11 +4928,11 @@  discard block
 block discarded – undo
4928 4928
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
4929 4929
 	$l = strlen($passe);
4930 4930
 
4931
-	if ($l<=8 or !$afficher_partiellement){
4931
+	if ($l <= 8 or !$afficher_partiellement) {
4932 4932
 		if (!$l) {
4933 4933
 			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
4934 4934
 		}
4935
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
4935
+		return str_pad('', $afficher_partiellement ? $l : 16, '*');
4936 4936
 	}
4937 4937
 
4938 4938
 	if (is_null($portion_pourcent)) {
@@ -4946,9 +4946,9 @@  discard block
 block discarded – undo
4946 4946
 	}
4947 4947
 	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
4948 4948
 	$e = max($e, 0);
4949
-	$mid = str_pad('',$l-2*$e,'*');
4950
-	if ($e>0 and strlen($mid)>8){
4949
+	$mid = str_pad('', $l - 2 * $e, '*');
4950
+	if ($e > 0 and strlen($mid) > 8) {
4951 4951
 		$mid = '***...***';
4952 4952
 	}
4953
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
4953
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
4954 4954
 }
4955 4955
\ No newline at end of file
Please login to merge, or discard this patch.
ecrire/inc/plugin.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -623,11 +623,11 @@
 block discarded – undo
623 623
  * 
624 624
  * @param $liste
625 625
  *    Liste de description des plugins
626
- * @param $nom
626
+ * @param string $nom
627 627
  *    Le plugin donc on cherche la presence
628 628
  * @param $intervalle
629 629
  *    L'éventuelle intervalle de compatibilité de la dépendance. ex: [1.1.0;]
630
- * @param $balise
630
+ * @param string $balise
631 631
  *    Permet de définir si on teste un utilise ou un nécessite
632 632
  * @return string.
633 633
  *    Vide si ok,
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 /** l'adresse du repertoire de telechargement et de decompactage des plugins */
24 24
 if (!defined('_DIR_PLUGINS_AUTO')) {
25
-	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
25
+	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/');
26 26
 }
27 27
 
28 28
 #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins.
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				if ($dir) {
371 371
 					$dir .= "/";
372 372
 				}
373
-				$dir .= "procure:" . $procure['nom'];
373
+				$dir .= "procure:".$procure['nom'];
374 374
 
375 375
 				$procure['etat'] = '?';
376 376
 				$procure['dir_type'] = $resume['dir_type'];
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 		$plug = $resume['dir'];
552 552
 		$k = $infos[$dir_type][$plug];
553 553
 
554
-		$plug = constant($dir_type) . $plug;
554
+		$plug = constant($dir_type).$plug;
555 555
 		if (!isset($msg[$p])) {
556 556
 			if (isset($resume['erreur']) and $resume['erreur']) {
557 557
 				$msg[$p] = array($resume['erreur']);
@@ -594,10 +594,10 @@  discard block
 block discarded – undo
594 594
 		$list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595 595
 	} elseif (!$raw) {
596 596
 		foreach ($list as $plug => $msg) {
597
-			$list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
-				. "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
597
+			$list[$plug] = "<li>"._T('plugin_impossible_activer', array('plugin' => $plug))
598
+				. "<ul><li>".implode("</li><li>", $msg)."</li></ul></li>";
599 599
 		}
600
-		$list = "<ul>" . join("\n", $list) . "</ul>";
600
+		$list = "<ul>".join("\n", $list)."</ul>";
601 601
 	}
602 602
 	if ($raz) {
603 603
 		effacer_meta('plugin_erreur_activation');
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
 			if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709 709
 				return _T("plugin_${balise}_${type}", array(
710 710
 					'plugin' => $nom,
711
-					'version' => ' &ge; ' . $minimum
711
+					'version' => ' &ge; '.$minimum
712 712
 				));
713 713
 			}
714 714
 			if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715 715
 				return _T("plugin_${balise}_${type}", array(
716 716
 					'plugin' => $nom,
717
-					'version' => ' &gt; ' . $minimum
717
+					'version' => ' &gt; '.$minimum
718 718
 				));
719 719
 			}
720 720
 		}
@@ -723,13 +723,13 @@  discard block
 block discarded – undo
723 723
 			if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724 724
 				return _T("plugin_${balise}_${type}", array(
725 725
 					'plugin' => $nom,
726
-					'version' => ' &le; ' . $maximum
726
+					'version' => ' &le; '.$maximum
727 727
 				));
728 728
 			}
729 729
 			if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730 730
 				return _T("plugin_${balise}_plugin", array(
731 731
 					'plugin' => $nom,
732
-					'version' => ' &lt; ' . $maximum
732
+					'version' => ' &lt; '.$maximum
733 733
 				));
734 734
 			}
735 735
 		}
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 		include_spip('inc/charger_plugin');
749 749
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
750 750
 	}*/
751
-	return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
751
+	return _T('plugin_necessite_lib', array('lib' => $lib))." <a href='$url'>$url</a>";
752 752
 }
753 753
 
754 754
 
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	foreach ($plugin_valides as $p => $resume) {
848 848
 		// Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849 849
 		if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
-			$header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
850
+			$header[] = $p.($resume['version'] ? "(".$resume['version'].")" : "");
851 851
 		}
852 852
 		if ($resume['dir']) {
853 853
 			foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
@@ -871,10 +871,10 @@  discard block
 block discarded – undo
871 871
 	ecrire_meta('plugin_attente', serialize($liste));
872 872
 	$header = strtolower(implode(",", $header));
873 873
 	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
-		ecrire_fichier(_DIR_VAR . "config.txt",
875
-			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
874
+		ecrire_fichier(_DIR_VAR."config.txt",
875
+			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP").' '.$GLOBALS['spip_version_affichee']." @ www.spip.net + ".$header);
876 876
 	} else {
877
-		@unlink(_DIR_VAR . "config.txt");
877
+		@unlink(_DIR_VAR."config.txt");
878 878
 	}
879 879
 	// generer charger_plugins_chemin.php
880 880
 	plugins_precompile_chemin($plugin_valides, $ordre);
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 			// definir le plugin, donc le path avant l'include du fichier options
926 926
 			// permet de faire des include_spip pour attraper un inc_ du plugin
927 927
 
928
-			$dir = $dir_type . ".'" . $plug . "/'";
928
+			$dir = $dir_type.".'".$plug."/'";
929 929
 
930 930
 			$prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931 931
 			if (
@@ -945,13 +945,13 @@  discard block
 block discarded – undo
945 945
 							$dir = '';
946 946
 						}
947 947
 						if (strlen($dir)) {
948
-							$dir = rtrim($dir, '/') . '/';
948
+							$dir = rtrim($dir, '/').'/';
949 949
 						}
950 950
 						if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
-							$chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
951
+							$chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
952 952
 						}
953 953
 						if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
-							$chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
954
+							$chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
955 955
 						}
956 956
 					}
957 957
 				}
@@ -959,9 +959,9 @@  discard block
 block discarded – undo
959 959
 		}
960 960
 	}
961 961
 	if (count($chemins)) {
962
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
-				array_reverse($chemins['public'])) . ")));\n"
964
-			. "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
962
+		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',',
963
+				array_reverse($chemins['public'])).")));\n"
964
+			. "else _chemin(implode(':',array(".implode(',', array_reverse($chemins['prive'])).")));\n";
965 965
 	}
966 966
 
967 967
 	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
 					and strpos($dir, ":") === false // exclure le cas des procure:
1010 1010
 					and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011 1011
 				) {
1012
-					if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1012
+					if (is_readable("$dir$plug/".($file = $info['prefix']."_".$charge.".php"))) {
1013 1013
 						$info[$charge] = array($file);
1014 1014
 					}
1015 1015
 				}
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 						) {
1026 1026
 							unset($info[$charge][$k]);
1027 1027
 						} else {
1028
-							$_file = $root_dir_type . ".'$plug/$file'";
1028
+							$_file = $root_dir_type.".'$plug/$file'";
1029 1029
 							$contenu[$charge] .= "include_once_check($_file);\n";
1030 1030
 						}
1031 1031
 					}
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 		}
1036 1036
 	}
1037 1037
 
1038
-	$contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1038
+	$contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options'];
1039 1039
 	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040 1040
 		. plugin_ongletbouton("onglets_plugins", $onglets);
1041 1041
 
@@ -1070,12 +1070,12 @@  discard block
 block discarded – undo
1070 1070
 		define("_UPDATED_$nom", $val);
1071 1071
 		define("_UPDATED_md5_$nom", $md5);
1072 1072
 	}
1073
-	$val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1073
+	$val = "unserialize('".str_replace("'", "\'", $val)."')";
1074 1074
 
1075 1075
 	return
1076 1076
 		"if (!function_exists('$nom')) {\n"
1077 1077
 		. "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
-		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1078
+		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n"
1079 1079
 		. "}\n";
1080 1080
 }
1081 1081
 
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 	if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099 1099
 		include_once(_CACHE_PLUGINS_OPT);
1100 1100
 	} else {
1101
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1101
+		spip_log("pipelines desactives: impossible de produire "._CACHE_PLUGINS_OPT);
1102 1102
 	}
1103 1103
 }
1104 1104
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 			$dir_type = $plugin_valides[$p]['dir_type'];
1136 1136
 			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137 1137
 			$plug = $plugin_valides[$p]['dir'];
1138
-			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1138
+			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix']."_");
1139 1139
 			if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140 1140
 				foreach ($info['pipeline'] as $pipe) {
1141 1141
 					$nom = $pipe['nom'];
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 						}
1166 1166
 						if (isset($pipe['inclure'])) {
1167 1167
 							$GLOBALS['spip_matrice']["$prefix$action"] =
1168
-								"$root_dir_type:$plug/" . $pipe['inclure'];
1168
+								"$root_dir_type:$plug/".$pipe['inclure'];
1169 1169
 						}
1170 1170
 					}
1171 1171
 				}
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
 					$prepend_code['taches_generales_cron'] = "";
1176 1176
 				}
1177 1177
 				foreach ($info['genie'] as $genie) {
1178
-					$nom = $prefix . $genie['nom'];
1178
+					$nom = $prefix.$genie['nom'];
1179 1179
 					$periode = max(60, intval($genie['periode']));
1180 1180
 					if (charger_fonction($nom, "genie", true)) {
1181 1181
 						$prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
@@ -1193,13 +1193,13 @@  discard block
 block discarded – undo
1193 1193
 				}
1194 1194
 				foreach ($info['style'] as $style) {
1195 1195
 					if (isset($style['path']) and $style['path']) {
1196
-						$code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1196
+						$code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) ";
1197 1197
 					} else {
1198
-						$code = "if (\$f='" . addslashes($style['url']) . "') ";
1198
+						$code = "if (\$f='".addslashes($style['url'])."') ";
1199 1199
 					}
1200 1200
 					$code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201 1201
 					if (isset($style['media']) and strlen($style['media'])) {
1202
-						$code .= " media=\"" . addslashes($style['media']) . "\"";
1202
+						$code .= " media=\"".addslashes($style['media'])."\"";
1203 1203
 					}
1204 1204
 					$code .= "/>';\n";
1205 1205
 					if ($style['type'] != 'prive') {
@@ -1219,9 +1219,9 @@  discard block
 block discarded – undo
1219 1219
 			if (isset($info['script']) and count($info['script'])) {
1220 1220
 				foreach ($info['script'] as $script) {
1221 1221
 					if (isset($script['path']) and $script['path']) {
1222
-						$code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1222
+						$code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) ";
1223 1223
 					} else {
1224
-						$code = "if (\$f='" . addslashes($script['url']) . "') ";
1224
+						$code = "if (\$f='".addslashes($script['url'])."') ";
1225 1225
 					}
1226 1226
 					$code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227 1227
 					if ($script['type'] != 'prive') {
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 		// Eclater le pipeline en filtres et appliquer chaque filtre
1287 1287
 		foreach ($pipe as $fonc) {
1288 1288
 			$fonc = trim($fonc);
1289
-			$s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1289
+			$s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n";
1290 1290
 			if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291 1291
 				$file = $GLOBALS['spip_matrice'][$fonc];
1292 1292
 				$file = "'$file'";
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
 					if (defined($root_dir)) {
1298 1298
 						$dir = $root_dir;
1299 1299
 					}
1300
-					$file = str_replace($regs[0], "'." . $dir . ".'", $file);
1300
+					$file = str_replace($regs[0], "'.".$dir.".'", $file);
1301 1301
 					$file = str_replace("''.", "", $file);
1302 1302
 					$file = str_replace(constant($dir), '', $file);
1303 1303
 				}
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		$content .= "// Pipeline $action \n"
1311 1311
 			. "function execute_pipeline_$action(&\$val){\n"
1312 1312
 			. $s_inc
1313
-			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1313
+			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '')
1314 1314
 			. $s_call
1315 1315
 			. "return \$val;\n}\n";
1316 1316
 	}
@@ -1394,18 +1394,18 @@  discard block
 block discarded – undo
1394 1394
 		$GLOBALS['fichier_php_compile_recent'] = 0;
1395 1395
 	}
1396 1396
 
1397
-	$contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1397
+	$contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>';
1398 1398
 	// si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399 1399
 	// si pas de modif on ne touche pas au fichier initial
1400 1400
 	if (file_exists($nom)) {
1401 1401
 		if (substr($nom, -4) == '.php') {
1402
-			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1402
+			$fichier_tmp = substr($nom, 0, -4).'.tmp.php';
1403 1403
 		}
1404 1404
 		else {
1405
-			$fichier_tmp = $nom . '.tmp';
1405
+			$fichier_tmp = $nom.'.tmp';
1406 1406
 		}
1407 1407
 		file_put_contents($fichier_tmp, $contenu);
1408
-		if(md5_file($nom) == md5_file($fichier_tmp)) {
1408
+		if (md5_file($nom) == md5_file($fichier_tmp)) {
1409 1409
 			$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410 1410
 			@unlink($fichier_tmp);
1411 1411
 			return;
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -555,11 +555,9 @@  discard block
 block discarded – undo
555 555
 		if (!isset($msg[$p])) {
556 556
 			if (isset($resume['erreur']) and $resume['erreur']) {
557 557
 				$msg[$p] = array($resume['erreur']);
558
-			}
559
-			elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
558
+			} elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560 559
 				$msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
-			}
562
-			elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
560
+			} elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563 561
 				$msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564 562
 			}
565 563
 		} else {
@@ -1154,10 +1152,12 @@  discard block
 block discarded – undo
1154 1152
 					}
1155 1153
 					$nom = $nomlower;
1156 1154
 					// une action vide est une declaration qui ne doit pas etre compilee !
1157
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1155
+					if (!isset($GLOBALS['spip_pipeline'][$nom])) {
1156
+					    // creer le pipeline eventuel
1158 1157
 					{
1159 1158
 						$GLOBALS['spip_pipeline'][$nom] = "";
1160 1159
 					}
1160
+					}
1161 1161
 					if ($action) {
1162 1162
 						if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163 1163
 							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
@@ -1400,8 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	if (file_exists($nom)) {
1401 1401
 		if (substr($nom, -4) == '.php') {
1402 1402
 			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
-		}
1404
-		else {
1403
+		} else {
1405 1404
 			$fichier_tmp = $nom . '.tmp';
1406 1405
 		}
1407 1406
 		file_put_contents($fichier_tmp, $contenu);
Please login to merge, or discard this patch.
Indentation   +913 added lines, -913 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /** l'adresse du repertoire de telechargement et de decompactage des plugins */
24 24
 if (!defined('_DIR_PLUGINS_AUTO')) {
25
-	define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
25
+    define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/');
26 26
 }
27 27
 
28 28
 #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins.
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
  * @return array
48 48
 **/
49 49
 function liste_plugin_files($dir_plugins = null) {
50
-	static $plugin_files = array();
51
-	if (is_null($dir_plugins)) {
52
-		$dir_plugins = _DIR_PLUGINS;
53
-	}
54
-	if (!isset($plugin_files[$dir_plugins])
55
-		or count($plugin_files[$dir_plugins]) == 0
56
-	) {
57
-		$plugin_files[$dir_plugins] = array();
58
-		foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
59
-			$plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins));
60
-		}
61
-
62
-		sort($plugin_files[$dir_plugins]);
63
-		// et on lit le XML de tous les plugins pour le mettre en cache
64
-		// et en profiter pour nettoyer ceux qui n'existent plus du cache
65
-		$get_infos = charger_fonction('get_infos', 'plugins');
66
-		$get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true);
67
-	}
68
-
69
-	return $plugin_files[$dir_plugins];
50
+    static $plugin_files = array();
51
+    if (is_null($dir_plugins)) {
52
+        $dir_plugins = _DIR_PLUGINS;
53
+    }
54
+    if (!isset($plugin_files[$dir_plugins])
55
+        or count($plugin_files[$dir_plugins]) == 0
56
+    ) {
57
+        $plugin_files[$dir_plugins] = array();
58
+        foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
59
+            $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins));
60
+        }
61
+
62
+        sort($plugin_files[$dir_plugins]);
63
+        // et on lit le XML de tous les plugins pour le mettre en cache
64
+        // et en profiter pour nettoyer ceux qui n'existent plus du cache
65
+        $get_infos = charger_fonction('get_infos', 'plugins');
66
+        $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true);
67
+    }
68
+
69
+    return $plugin_files[$dir_plugins];
70 70
 }
71 71
 
72 72
 /**
@@ -82,44 +82,44 @@  discard block
 block discarded – undo
82 82
  *     Liste complète des répeertoires
83 83
 **/
84 84
 function fast_find_plugin_dirs($dir, $max_prof = 100) {
85
-	$fichiers = array();
86
-	// revenir au repertoire racine si on a recu dossier/truc
87
-	// pour regarder dossier/truc/ ne pas oublier le / final
88
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
89
-	if ($dir == '') {
90
-		$dir = '.';
91
-	}
92
-
93
-	if (!is_dir($dir)) {
94
-		return $fichiers;
95
-	}
96
-	if (is_plugin_dir($dir, '')) {
97
-		$fichiers[] = $dir;
98
-
99
-		return $fichiers;
100
-	}
101
-	if ($max_prof <= 0) {
102
-		return $fichiers;
103
-	}
104
-
105
-	$subdirs = array();
106
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
107
-		while (($f = readdir($d)) !== false) {
108
-			if ($f[0] != '.' # ignorer . .. .svn etc
109
-				and $f != 'CVS'
110
-				and is_dir($f = "$dir/$f")
111
-			) {
112
-				$subdirs[] = $f;
113
-			}
114
-		}
115
-		closedir($d);
116
-	}
117
-
118
-	foreach ($subdirs as $d) {
119
-		$fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1));
120
-	}
121
-
122
-	return $fichiers;
85
+    $fichiers = array();
86
+    // revenir au repertoire racine si on a recu dossier/truc
87
+    // pour regarder dossier/truc/ ne pas oublier le / final
88
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
89
+    if ($dir == '') {
90
+        $dir = '.';
91
+    }
92
+
93
+    if (!is_dir($dir)) {
94
+        return $fichiers;
95
+    }
96
+    if (is_plugin_dir($dir, '')) {
97
+        $fichiers[] = $dir;
98
+
99
+        return $fichiers;
100
+    }
101
+    if ($max_prof <= 0) {
102
+        return $fichiers;
103
+    }
104
+
105
+    $subdirs = array();
106
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
107
+        while (($f = readdir($d)) !== false) {
108
+            if ($f[0] != '.' # ignorer . .. .svn etc
109
+                and $f != 'CVS'
110
+                and is_dir($f = "$dir/$f")
111
+            ) {
112
+                $subdirs[] = $f;
113
+            }
114
+        }
115
+        closedir($d);
116
+    }
117
+
118
+    foreach ($subdirs as $d) {
119
+        $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1));
120
+    }
121
+
122
+    return $fichiers;
123 123
 }
124 124
 
125 125
 /**
@@ -140,27 +140,27 @@  discard block
 block discarded – undo
140 140
 **/
141 141
 function is_plugin_dir($dir, $dir_plugins = null) {
142 142
 
143
-	if (is_array($dir)) {
144
-		foreach ($dir as $k => $d) {
145
-			if (!is_plugin_dir($d, $dir_plugins)) {
146
-				unset($dir[$k]);
147
-			}
148
-		}
149
-
150
-		return $dir;
151
-	}
152
-	if (is_null($dir_plugins)) {
153
-		$dir_plugins = _DIR_PLUGINS;
154
-	}
155
-	$search = array("$dir_plugins$dir/paquet.xml");
156
-
157
-	foreach ($search as $s) {
158
-		if (file_exists($s)) {
159
-			return $dir;
160
-		}
161
-	}
162
-
163
-	return '';
143
+    if (is_array($dir)) {
144
+        foreach ($dir as $k => $d) {
145
+            if (!is_plugin_dir($d, $dir_plugins)) {
146
+                unset($dir[$k]);
147
+            }
148
+        }
149
+
150
+        return $dir;
151
+    }
152
+    if (is_null($dir_plugins)) {
153
+        $dir_plugins = _DIR_PLUGINS;
154
+    }
155
+    $search = array("$dir_plugins$dir/paquet.xml");
156
+
157
+    foreach ($search as $s) {
158
+        if (file_exists($s)) {
159
+            return $dir;
160
+        }
161
+    }
162
+
163
+    return '';
164 164
 }
165 165
 
166 166
 /** Regexp d'extraction des informations d'un intervalle de compatibilité */
@@ -187,51 +187,51 @@  discard block
 block discarded – undo
187 187
  **/
188 188
 function plugin_version_compatible($intervalle, $version, $avec_quoi = '') {
189 189
 
190
-	if (!strlen($intervalle)) {
191
-		return true;
192
-	}
193
-	if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
194
-		return false;
195
-	}
196
-	// Extraction des bornes et traitement de * pour la borne sup :
197
-	// -- on autorise uniquement les ecritures 3.0.*, 3.*
198
-	$minimum = $regs[1];
199
-	$maximum = $regs[2];
200
-
201
-	//  si une version SPIP de compatibilité a été définie (dans
202
-	//  mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0');
203
-	//  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
204
-	//  avec la version de SPIP (ne nuit donc pas aux tests de necessite
205
-	//  entre plugins)
206
-	if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) {
207
-		if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) {
208
-			return true;
209
-		}
210
-		// si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version
211
-		// cas du plugin qui n'est compatible qu'avec cette nouvelle version
212
-	}
213
-
214
-	$minimum_inc = $intervalle[0] == "[";
215
-	$maximum_inc = substr($intervalle, -1) == "]";
216
-
217
-	if (strlen($minimum)) {
218
-		if ($minimum_inc and spip_version_compare($version, $minimum, '<')) {
219
-			return false;
220
-		}
221
-		if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) {
222
-			return false;
223
-		}
224
-	}
225
-	if (strlen($maximum)) {
226
-		if ($maximum_inc and spip_version_compare($version, $maximum, '>')) {
227
-			return false;
228
-		}
229
-		if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) {
230
-			return false;
231
-		}
232
-	}
233
-
234
-	return true;
190
+    if (!strlen($intervalle)) {
191
+        return true;
192
+    }
193
+    if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
194
+        return false;
195
+    }
196
+    // Extraction des bornes et traitement de * pour la borne sup :
197
+    // -- on autorise uniquement les ecritures 3.0.*, 3.*
198
+    $minimum = $regs[1];
199
+    $maximum = $regs[2];
200
+
201
+    //  si une version SPIP de compatibilité a été définie (dans
202
+    //  mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0');
203
+    //  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
204
+    //  avec la version de SPIP (ne nuit donc pas aux tests de necessite
205
+    //  entre plugins)
206
+    if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) {
207
+        if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) {
208
+            return true;
209
+        }
210
+        // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version
211
+        // cas du plugin qui n'est compatible qu'avec cette nouvelle version
212
+    }
213
+
214
+    $minimum_inc = $intervalle[0] == "[";
215
+    $maximum_inc = substr($intervalle, -1) == "]";
216
+
217
+    if (strlen($minimum)) {
218
+        if ($minimum_inc and spip_version_compare($version, $minimum, '<')) {
219
+            return false;
220
+        }
221
+        if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) {
222
+            return false;
223
+        }
224
+    }
225
+    if (strlen($maximum)) {
226
+        if ($maximum_inc and spip_version_compare($version, $maximum, '>')) {
227
+            return false;
228
+        }
229
+        if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) {
230
+            return false;
231
+        }
232
+    }
233
+
234
+    return true;
235 235
 }
236 236
 
237 237
 /**
@@ -248,62 +248,62 @@  discard block
 block discarded – undo
248 248
  * @return array
249 249
  */
250 250
 function liste_plugin_valides($liste_plug, $force = false) {
251
-	$liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
252
-	$get_infos = charger_fonction('get_infos', 'plugins');
253
-	$infos = array(
254
-		// lister les extensions qui sont automatiquement actives
255
-		'_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
256
-		'_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
257
-	);
258
-
259
-	// creer une premiere liste non ordonnee mais qui ne retient
260
-	// que les plugins valides, et dans leur derniere version en cas de doublon
261
-	$infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
262
-	$infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
263
-	$infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
264
-	$liste_non_classee = array(
265
-		'SPIP' => array(
266
-			'nom' => 'SPIP',
267
-			'etat' => 'stable',
268
-			'version' => $GLOBALS['spip_version_branche'],
269
-			'dir_type' => '_DIR_RESTREINT',
270
-			'dir' => '',
271
-		)
272
-	);
273
-
274
-	$invalides = array();
275
-	foreach ($liste_ext as $plug) {
276
-		if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) {
277
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
278
-		}
279
-	}
280
-	foreach ($liste_plug as $plug) {
281
-		if (isset($infos['_DIR_PLUGINS'][$plug])) {
282
-			$r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
283
-			if (is_array($r)) {
284
-				$invalides = array_merge($invalides, $r);
285
-			}
286
-		}
287
-	}
288
-
289
-	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) {
290
-		$infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
291
-		foreach ($liste_plug as $plug) {
292
-			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) {
293
-				$r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
294
-				if (is_array($r)) {
295
-					$invalides = array_merge($invalides, $r);
296
-				}
297
-			}
298
-		}
299
-	}
300
-
301
-	plugin_fixer_procure($liste_non_classee, $infos);
302
-
303
-	// les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide)
304
-	$invalides = array_diff_key($invalides, $liste_non_classee);
305
-
306
-	return array($infos, $liste_non_classee, $invalides);
251
+    $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
252
+    $get_infos = charger_fonction('get_infos', 'plugins');
253
+    $infos = array(
254
+        // lister les extensions qui sont automatiquement actives
255
+        '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
256
+        '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
257
+    );
258
+
259
+    // creer une premiere liste non ordonnee mais qui ne retient
260
+    // que les plugins valides, et dans leur derniere version en cas de doublon
261
+    $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
262
+    $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
263
+    $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
264
+    $liste_non_classee = array(
265
+        'SPIP' => array(
266
+            'nom' => 'SPIP',
267
+            'etat' => 'stable',
268
+            'version' => $GLOBALS['spip_version_branche'],
269
+            'dir_type' => '_DIR_RESTREINT',
270
+            'dir' => '',
271
+        )
272
+    );
273
+
274
+    $invalides = array();
275
+    foreach ($liste_ext as $plug) {
276
+        if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) {
277
+            plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
278
+        }
279
+    }
280
+    foreach ($liste_plug as $plug) {
281
+        if (isset($infos['_DIR_PLUGINS'][$plug])) {
282
+            $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
283
+            if (is_array($r)) {
284
+                $invalides = array_merge($invalides, $r);
285
+            }
286
+        }
287
+    }
288
+
289
+    if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) {
290
+        $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
291
+        foreach ($liste_plug as $plug) {
292
+            if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) {
293
+                $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
294
+                if (is_array($r)) {
295
+                    $invalides = array_merge($invalides, $r);
296
+                }
297
+            }
298
+        }
299
+    }
300
+
301
+    plugin_fixer_procure($liste_non_classee, $infos);
302
+
303
+    // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide)
304
+    $invalides = array_diff_key($invalides, $liste_non_classee);
305
+
306
+    return array($infos, $liste_non_classee, $invalides);
307 307
 }
308 308
 
309 309
 /**
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
  *   array description short si on ne le retient pas (pour memorisation dans une table des erreurs)
324 324
  */
325 325
 function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) {
326
-	$i = $infos[$dir_type][$plug];
327
-	$p = strtoupper($i['prefix']);
328
-	$short_desc = array(
329
-		'nom' => $i['nom'],
330
-		'etat' => $i['etat'],
331
-		'version' => $i['version'],
332
-		'dir' => $plug,
333
-		'dir_type' => $dir_type
334
-	);
335
-	if (isset($i['erreur']) and $i['erreur']) {
336
-		$short_desc['erreur'] = $i['erreur'];
337
-		return array($p=>$short_desc);
338
-	}
339
-	if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
340
-		return array($p=>$short_desc);
341
-	}
342
-	if (!isset($liste[$p])
343
-		or spip_version_compare($i['version'], $liste[$p]['version'], '>')
344
-	) {
345
-		$liste[$p] = $short_desc;
346
-	}
347
-	// ok le plugin etait deja dans la liste ou on a choisi une version plus recente
348
-	return $p;
326
+    $i = $infos[$dir_type][$plug];
327
+    $p = strtoupper($i['prefix']);
328
+    $short_desc = array(
329
+        'nom' => $i['nom'],
330
+        'etat' => $i['etat'],
331
+        'version' => $i['version'],
332
+        'dir' => $plug,
333
+        'dir_type' => $dir_type
334
+    );
335
+    if (isset($i['erreur']) and $i['erreur']) {
336
+        $short_desc['erreur'] = $i['erreur'];
337
+        return array($p=>$short_desc);
338
+    }
339
+    if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
340
+        return array($p=>$short_desc);
341
+    }
342
+    if (!isset($liste[$p])
343
+        or spip_version_compare($i['version'], $liste[$p]['version'], '>')
344
+    ) {
345
+        $liste[$p] = $short_desc;
346
+    }
347
+    // ok le plugin etait deja dans la liste ou on a choisi une version plus recente
348
+    return $p;
349 349
 }
350 350
 
351 351
 /**
@@ -361,46 +361,46 @@  discard block
 block discarded – undo
361 361
  * @param array $infos
362 362
  */
363 363
 function plugin_fixer_procure(&$liste, &$infos) {
364
-	foreach ($liste as $p => $resume) {
365
-		$i = $infos[$resume['dir_type']][$resume['dir']];
366
-		if (isset($i['procure']) and $i['procure']) {
367
-			foreach ($i['procure'] as $procure) {
368
-				$p = strtoupper($procure['nom']);
369
-				$dir = $resume['dir'];
370
-				if ($dir) {
371
-					$dir .= "/";
372
-				}
373
-				$dir .= "procure:" . $procure['nom'];
374
-
375
-				$procure['etat'] = '?';
376
-				$procure['dir_type'] = $resume['dir_type'];
377
-				$procure['dir'] = $dir;
378
-
379
-				// si ce plugin n'est pas deja procure, ou dans une version plus ancienne
380
-				// on ajoute cette version a la liste
381
-				if (!isset($liste[$p])
382
-					or spip_version_compare($procure['version'], $liste[$p]['version'], '>')
383
-				) {
384
-					$liste[$p] = $procure;
385
-
386
-					// on fournit une information minimale pour ne pas perturber la compilation
387
-					$infos[$resume['dir_type']][$dir] = array(
388
-						'prefix' => $procure['nom'],
389
-						'nom' => $procure['nom'],
390
-						'etat' => $procure['etat'],
391
-						'version' => $procure['version'],
392
-						'chemin' => array(),
393
-						'necessite' => array(),
394
-						'utilise' => array(),
395
-						'lib' => array(),
396
-						'menu' => array(),
397
-						'onglet' => array(),
398
-						'procure' => array(),
399
-					);
400
-				}
401
-			}
402
-		}
403
-	}
364
+    foreach ($liste as $p => $resume) {
365
+        $i = $infos[$resume['dir_type']][$resume['dir']];
366
+        if (isset($i['procure']) and $i['procure']) {
367
+            foreach ($i['procure'] as $procure) {
368
+                $p = strtoupper($procure['nom']);
369
+                $dir = $resume['dir'];
370
+                if ($dir) {
371
+                    $dir .= "/";
372
+                }
373
+                $dir .= "procure:" . $procure['nom'];
374
+
375
+                $procure['etat'] = '?';
376
+                $procure['dir_type'] = $resume['dir_type'];
377
+                $procure['dir'] = $dir;
378
+
379
+                // si ce plugin n'est pas deja procure, ou dans une version plus ancienne
380
+                // on ajoute cette version a la liste
381
+                if (!isset($liste[$p])
382
+                    or spip_version_compare($procure['version'], $liste[$p]['version'], '>')
383
+                ) {
384
+                    $liste[$p] = $procure;
385
+
386
+                    // on fournit une information minimale pour ne pas perturber la compilation
387
+                    $infos[$resume['dir_type']][$dir] = array(
388
+                        'prefix' => $procure['nom'],
389
+                        'nom' => $procure['nom'],
390
+                        'etat' => $procure['etat'],
391
+                        'version' => $procure['version'],
392
+                        'chemin' => array(),
393
+                        'necessite' => array(),
394
+                        'utilise' => array(),
395
+                        'lib' => array(),
396
+                        'menu' => array(),
397
+                        'onglet' => array(),
398
+                        'procure' => array(),
399
+                    );
400
+                }
401
+            }
402
+        }
403
+    }
404 404
 }
405 405
 
406 406
 /**
@@ -414,19 +414,19 @@  discard block
 block discarded – undo
414 414
  * @return array
415 415
  */
416 416
 function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) {
417
-	foreach ($liste as $prefix => $infos) {
418
-		if (!$dir_plugins
419
-			or (
420
-				defined($infos['dir_type'])
421
-				and constant($infos['dir_type']) == $dir_plugins)
422
-		) {
423
-			$liste[$prefix] = $infos['dir'];
424
-		} else {
425
-			unset($liste[$prefix]);
426
-		}
427
-	}
428
-
429
-	return $liste;
417
+    foreach ($liste as $prefix => $infos) {
418
+        if (!$dir_plugins
419
+            or (
420
+                defined($infos['dir_type'])
421
+                and constant($infos['dir_type']) == $dir_plugins)
422
+        ) {
423
+            $liste[$prefix] = $infos['dir'];
424
+        } else {
425
+            unset($liste[$prefix]);
426
+        }
427
+    }
428
+
429
+    return $liste;
430 430
 }
431 431
 
432 432
 /**
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
  * @return array
442 442
  */
443 443
 function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) {
444
-	include_spip('plugins/installer');
444
+    include_spip('plugins/installer');
445 445
 
446
-	return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
446
+    return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
447 447
 }
448 448
 
449 449
 /**
@@ -474,53 +474,53 @@  discard block
 block discarded – undo
474 474
  *                qui n'ont pas satisfait leurs dépendances
475 475
 **/
476 476
 function plugin_trier($infos, $liste_non_classee) {
477
-	$toute_la_liste = $liste_non_classee;
478
-	$liste = $ordre = array();
479
-	$count = 0;
480
-
481
-	while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
482
-		#echo "tour::";var_dump($liste_non_classee);
483
-		$count = $c;
484
-		foreach ($liste_non_classee as $p => $resume) {
485
-			$plug = $resume['dir'];
486
-			$dir_type = $resume['dir_type'];
487
-			$info1 = $infos[$dir_type][$plug];
488
-			// si des plugins sont necessaires,
489
-			// on ne peut inserer qu'apres eux
490
-			foreach ($info1['necessite'] as $need) {
491
-				$nom = strtoupper($need['nom']);
492
-				$compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
493
-				if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) {
494
-					$info1 = false;
495
-					break;
496
-				}
497
-			}
498
-			if (!$info1) {
499
-				continue;
500
-			}
501
-			// idem si des plugins sont utiles,
502
-			// sauf si ils sont de toute facon absents de la liste
503
-			foreach ($info1['utilise'] as $need) {
504
-				$nom = strtoupper($need['nom']);
505
-				$compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
506
-				if (isset($toute_la_liste[$nom])) {
507
-					if (!isset($liste[$nom]) or
508
-						!plugin_version_compatible($compat, $liste[$nom]['version'])
509
-					) {
510
-						$info1 = false;
511
-						break;
512
-					}
513
-				}
514
-			}
515
-			if ($info1) {
516
-				$ordre[$p] = $info1;
517
-				$liste[$p] = $liste_non_classee[$p];
518
-				unset($liste_non_classee[$p]);
519
-			}
520
-		}
521
-	}
522
-
523
-	return array($liste, $ordre, $liste_non_classee);
477
+    $toute_la_liste = $liste_non_classee;
478
+    $liste = $ordre = array();
479
+    $count = 0;
480
+
481
+    while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
482
+        #echo "tour::";var_dump($liste_non_classee);
483
+        $count = $c;
484
+        foreach ($liste_non_classee as $p => $resume) {
485
+            $plug = $resume['dir'];
486
+            $dir_type = $resume['dir_type'];
487
+            $info1 = $infos[$dir_type][$plug];
488
+            // si des plugins sont necessaires,
489
+            // on ne peut inserer qu'apres eux
490
+            foreach ($info1['necessite'] as $need) {
491
+                $nom = strtoupper($need['nom']);
492
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
493
+                if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) {
494
+                    $info1 = false;
495
+                    break;
496
+                }
497
+            }
498
+            if (!$info1) {
499
+                continue;
500
+            }
501
+            // idem si des plugins sont utiles,
502
+            // sauf si ils sont de toute facon absents de la liste
503
+            foreach ($info1['utilise'] as $need) {
504
+                $nom = strtoupper($need['nom']);
505
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
506
+                if (isset($toute_la_liste[$nom])) {
507
+                    if (!isset($liste[$nom]) or
508
+                        !plugin_version_compatible($compat, $liste[$nom]['version'])
509
+                    ) {
510
+                        $info1 = false;
511
+                        break;
512
+                    }
513
+                }
514
+            }
515
+            if ($info1) {
516
+                $ordre[$p] = $info1;
517
+                $liste[$p] = $liste_non_classee[$p];
518
+                unset($liste_non_classee[$p]);
519
+            }
520
+        }
521
+    }
522
+
523
+    return array($liste, $ordre, $liste_non_classee);
524 524
 }
525 525
 
526 526
 /**
@@ -537,40 +537,40 @@  discard block
 block discarded – undo
537 537
  *     Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent
538 538
 **/
539 539
 function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array()) {
540
-	static $erreurs = array();
541
-
542
-	if (!is_array($liste)) {
543
-		$liste = array();
544
-	}
545
-
546
-	// les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste
547
-	$liste = array_diff_key($liste, $liste_non_classee);
548
-
549
-	foreach ($liste_non_classee as $p => $resume) {
550
-		$dir_type = $resume['dir_type'];
551
-		$plug = $resume['dir'];
552
-		$k = $infos[$dir_type][$plug];
553
-
554
-		$plug = constant($dir_type) . $plug;
555
-		if (!isset($msg[$p])) {
556
-			if (isset($resume['erreur']) and $resume['erreur']) {
557
-				$msg[$p] = array($resume['erreur']);
558
-			}
559
-			elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560
-				$msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
-			}
562
-			elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563
-				$msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564
-			}
565
-		} else {
566
-			foreach ($msg[$p] as $c => $l) {
567
-				$msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
568
-			}
569
-		}
570
-		$erreurs[$plug] = $msg[$p];
571
-	}
572
-
573
-	ecrire_meta('plugin_erreur_activation', serialize($erreurs));
540
+    static $erreurs = array();
541
+
542
+    if (!is_array($liste)) {
543
+        $liste = array();
544
+    }
545
+
546
+    // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste
547
+    $liste = array_diff_key($liste, $liste_non_classee);
548
+
549
+    foreach ($liste_non_classee as $p => $resume) {
550
+        $dir_type = $resume['dir_type'];
551
+        $plug = $resume['dir'];
552
+        $k = $infos[$dir_type][$plug];
553
+
554
+        $plug = constant($dir_type) . $plug;
555
+        if (!isset($msg[$p])) {
556
+            if (isset($resume['erreur']) and $resume['erreur']) {
557
+                $msg[$p] = array($resume['erreur']);
558
+            }
559
+            elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
560
+                $msg[$p] = array(plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite'));
561
+            }
562
+            elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) {
563
+                $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise');
564
+            }
565
+        } else {
566
+            foreach ($msg[$p] as $c => $l) {
567
+                $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
568
+            }
569
+        }
570
+        $erreurs[$plug] = $msg[$p];
571
+    }
572
+
573
+    ecrire_meta('plugin_erreur_activation', serialize($erreurs));
574 574
 }
575 575
 
576 576
 /**
@@ -585,25 +585,25 @@  discard block
 block discarded – undo
585 585
  *     - Liste des erreurs ou code HTML des erreurs
586 586
 **/
587 587
 function plugin_donne_erreurs($raw = false, $raz = true) {
588
-	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) {
589
-		return $raw ? array() : '';
590
-	}
591
-	$list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
592
-	// Compat ancienne version
593
-	if (!$list) {
594
-		$list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595
-	} elseif (!$raw) {
596
-		foreach ($list as $plug => $msg) {
597
-			$list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
-				. "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
599
-		}
600
-		$list = "<ul>" . join("\n", $list) . "</ul>";
601
-	}
602
-	if ($raz) {
603
-		effacer_meta('plugin_erreur_activation');
604
-	}
605
-
606
-	return $list;
588
+    if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) {
589
+        return $raw ? array() : '';
590
+    }
591
+    $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
592
+    // Compat ancienne version
593
+    if (!$list) {
594
+        $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
595
+    } elseif (!$raw) {
596
+        foreach ($list as $plug => $msg) {
597
+            $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
598
+                . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
599
+        }
600
+        $list = "<ul>" . join("\n", $list) . "</ul>";
601
+    }
602
+    if ($raz) {
603
+        effacer_meta('plugin_erreur_activation');
604
+    }
605
+
606
+    return $list;
607 607
 }
608 608
 
609 609
 /**
@@ -623,21 +623,21 @@  discard block
 block discarded – undo
623 623
  *
624 624
  **/
625 625
 function plugin_necessite($n, $liste, $balise = 'necessite') {
626
-	$msg = array();
627
-	foreach ($n as $need) {
628
-		$id = strtoupper($need['nom']);
629
-		$r = plugin_controler_necessite(
630
-			$liste, 
631
-			$id, 
632
-			isset($need['compatibilite']) ? $need['compatibilite'] : '', 
633
-			$balise
634
-		);
635
-		if ($r) {
636
-			$msg[] = $r;
637
-		}
638
-	}
639
-
640
-	return $msg;
626
+    $msg = array();
627
+    foreach ($n as $need) {
628
+        $id = strtoupper($need['nom']);
629
+        $r = plugin_controler_necessite(
630
+            $liste, 
631
+            $id, 
632
+            isset($need['compatibilite']) ? $need['compatibilite'] : '', 
633
+            $balise
634
+        );
635
+        if ($r) {
636
+            $msg[] = $r;
637
+        }
638
+    }
639
+
640
+    return $msg;
641 641
 }
642 642
 
643 643
 /**
@@ -659,16 +659,16 @@  discard block
 block discarded – undo
659 659
  *    Message d'erreur lorsque la dépendance est absente.
660 660
  **/
661 661
 function plugin_controler_necessite($liste, $nom, $intervalle, $balise) {
662
-	if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) {
663
-		return '';
664
-	}
665
-
666
-	return plugin_message_incompatibilite(
667
-		$intervalle, 
668
-		(isset($liste[$nom]) ? $liste[$nom]['version'] : ""), 
669
-		$nom, 
670
-		$balise
671
-	);
662
+    if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) {
663
+        return '';
664
+    }
665
+
666
+    return plugin_message_incompatibilite(
667
+        $intervalle, 
668
+        (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), 
669
+        $nom, 
670
+        $balise
671
+    );
672 672
 }
673 673
 
674 674
 /**
@@ -685,70 +685,70 @@  discard block
 block discarded – undo
685 685
  */
686 686
 function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) {
687 687
 
688
-	// prendre en compte les erreurs de dépendances à PHP
689
-	// ou à une extension PHP avec des messages d'erreurs dédiés.
690
-	$type = 'plugin';
691
-	if ($nom === 'SPIP') {
692
-		$type = 'spip';
693
-	} elseif ($nom === 'PHP') {
694
-		$type = 'php';
695
-	} elseif (strncmp($nom, 'PHP:', 4) === 0) {
696
-		$type = 'extension_php';
697
-		list(,$nom) = explode(':', $nom, 2);
698
-	}
699
-
700
-	if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
701
-		$minimum = $regs[1];
702
-		$maximum = $regs[2];
703
-
704
-		$minimum_inclus = $intervalle[0] == "[";
705
-		$maximum_inclus = substr($intervalle, -1) == "]";
706
-
707
-		if (strlen($minimum)) {
708
-			if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709
-				return _T("plugin_${balise}_${type}", array(
710
-					'plugin' => $nom,
711
-					'version' => ' &ge; ' . $minimum
712
-				));
713
-			}
714
-			if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715
-				return _T("plugin_${balise}_${type}", array(
716
-					'plugin' => $nom,
717
-					'version' => ' &gt; ' . $minimum
718
-				));
719
-			}
720
-		}
721
-
722
-		if (strlen($maximum)) {
723
-			if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724
-				return _T("plugin_${balise}_${type}", array(
725
-					'plugin' => $nom,
726
-					'version' => ' &le; ' . $maximum
727
-				));
728
-			}
729
-			if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730
-				return _T("plugin_${balise}_plugin", array(
731
-					'plugin' => $nom,
732
-					'version' => ' &lt; ' . $maximum
733
-				));
734
-			}
735
-		}
736
-	}
737
-
738
-	// note : il ne peut pas y avoir d'erreur sur
739
-	// - un 'utilise' sans version.
740
-	// - un 'php' sans version.
741
-	return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom));
688
+    // prendre en compte les erreurs de dépendances à PHP
689
+    // ou à une extension PHP avec des messages d'erreurs dédiés.
690
+    $type = 'plugin';
691
+    if ($nom === 'SPIP') {
692
+        $type = 'spip';
693
+    } elseif ($nom === 'PHP') {
694
+        $type = 'php';
695
+    } elseif (strncmp($nom, 'PHP:', 4) === 0) {
696
+        $type = 'extension_php';
697
+        list(,$nom) = explode(':', $nom, 2);
698
+    }
699
+
700
+    if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) {
701
+        $minimum = $regs[1];
702
+        $maximum = $regs[2];
703
+
704
+        $minimum_inclus = $intervalle[0] == "[";
705
+        $maximum_inclus = substr($intervalle, -1) == "]";
706
+
707
+        if (strlen($minimum)) {
708
+            if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) {
709
+                return _T("plugin_${balise}_${type}", array(
710
+                    'plugin' => $nom,
711
+                    'version' => ' &ge; ' . $minimum
712
+                ));
713
+            }
714
+            if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) {
715
+                return _T("plugin_${balise}_${type}", array(
716
+                    'plugin' => $nom,
717
+                    'version' => ' &gt; ' . $minimum
718
+                ));
719
+            }
720
+        }
721
+
722
+        if (strlen($maximum)) {
723
+            if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) {
724
+                return _T("plugin_${balise}_${type}", array(
725
+                    'plugin' => $nom,
726
+                    'version' => ' &le; ' . $maximum
727
+                ));
728
+            }
729
+            if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) {
730
+                return _T("plugin_${balise}_plugin", array(
731
+                    'plugin' => $nom,
732
+                    'version' => ' &lt; ' . $maximum
733
+                ));
734
+            }
735
+        }
736
+    }
737
+
738
+    // note : il ne peut pas y avoir d'erreur sur
739
+    // - un 'utilise' sans version.
740
+    // - un 'php' sans version.
741
+    return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom));
742 742
 }
743 743
 
744 744
 
745 745
 function plugin_controler_lib($lib, $url) {
746
-	/* Feature sortie du core, voir STP
746
+    /* Feature sortie du core, voir STP
747 747
 	 * if ($url) {
748 748
 		include_spip('inc/charger_plugin');
749 749
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
750 750
 	}*/
751
-	return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
751
+    return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>";
752 752
 }
753 753
 
754 754
 
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
  *     true si il y a eu des modifications sur la liste des plugins actifs, false sinon
764 764
  **/
765 765
 function actualise_plugins_actifs($pipe_recherche = false) {
766
-	return ecrire_plugin_actifs('', $pipe_recherche, 'force');
766
+    return ecrire_plugin_actifs('', $pipe_recherche, 'force');
767 767
 }
768 768
 
769 769
 
@@ -790,113 +790,113 @@  discard block
 block discarded – undo
790 790
  **/
791 791
 function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') {
792 792
 
793
-	// creer le repertoire cache/ si necessaire ! (installation notamment)
794
-	$cache = sous_repertoire(_DIR_CACHE, '', false, true);
795
-
796
-	// Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore.
797
-	if (!$cache and !spip_connect()) {
798
-		return false;
799
-	}
800
-
801
-	if ($operation != 'raz') {
802
-		$plugin_valides = liste_chemin_plugin_actifs();
803
-		$plugin_valides = is_plugin_dir($plugin_valides);
804
-		if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
805
-			$plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
806
-			$plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL);
807
-			$plugin_valides = array_merge($plugin_valides, $plugin_valides_supp);
808
-		}
809
-		// si des plugins sont en attentes (coches mais impossible a activer)
810
-		// on les reinjecte ici
811
-		if (isset($GLOBALS['meta']['plugin_attente'])
812
-			and $a = unserialize($GLOBALS['meta']['plugin_attente'])
813
-		) {
814
-			$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
815
-		}
816
-
817
-		if ($operation == 'ajoute') {
818
-			$plugin = array_merge($plugin_valides, $plugin);
819
-		} elseif ($operation == 'enleve') {
820
-			$plugin = array_diff($plugin_valides, $plugin);
821
-		} else {
822
-			$plugin = $plugin_valides;
823
-		}
824
-	}
825
-	$actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : '';
826
-
827
-	// si une fonction de gestion de dependances existe, l'appeler ici
828
-	if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) {
829
-		$plugin = $ajouter_dependances($plugin);
830
-	}
831
-
832
-	// recharger le xml des plugins a activer
833
-	// on force le reload ici, meme si le fichier xml n'a pas change
834
-	// pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
835
-	// pourra etre evite quand on ne supportera plus les plugin.xml
836
-	// en deplacant la detection de ces fichiers dans la compilation ci dessous
837
-	list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true);
838
-	// trouver l'ordre d'activation
839
-	list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste);
840
-	if ($invalides or $reste) {
841
-		plugins_erreurs(array_merge($invalides, $reste), $liste, $infos);
842
-	}
843
-
844
-	// Ignorer les plugins necessitant une lib absente
845
-	// et preparer la meta d'entete Http
846
-	$err = $msg = $header = array();
847
-	foreach ($plugin_valides as $p => $resume) {
848
-		// Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849
-		if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
-			$header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
851
-		}
852
-		if ($resume['dir']) {
853
-			foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
854
-				if (!find_in_path($l['nom'], 'lib/')) {
855
-					$err[$p] = $resume;
856
-					$msg[$p][] = $l;
857
-					unset($plugin_valides[$p]);
858
-				}
859
-			}
860
-		}
861
-	}
862
-	if ($err) {
863
-		plugins_erreurs($err, '', $infos, $msg);
864
-	}
865
-
866
-	if (isset($GLOBALS['meta']['message_crash_plugins'])) {
867
-		effacer_meta('message_crash_plugins');
868
-	}
869
-	ecrire_meta('plugin', serialize($plugin_valides));
870
-	$liste = array_diff_key($liste, $plugin_valides);
871
-	ecrire_meta('plugin_attente', serialize($liste));
872
-	$header = strtolower(implode(",", $header));
873
-	if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
-		ecrire_fichier(_DIR_VAR . "config.txt",
875
-			(defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
876
-	} else {
877
-		@unlink(_DIR_VAR . "config.txt");
878
-	}
879
-	// generer charger_plugins_chemin.php
880
-	plugins_precompile_chemin($plugin_valides, $ordre);
881
-	// generer les fichiers
882
-	// - charger_plugins_options.php
883
-	// - charger_plugins_fonctions.php
884
-	plugins_precompile_xxxtions($plugin_valides, $ordre);
885
-	// charger les chemins des plugins et les fichiers d'options 
886
-	// (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins)
887
-	plugins_amorcer_plugins_actifs();
888
-	// mise a jour de la matrice des pipelines
889
-	$prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
890
-	// generer le fichier _CACHE_PIPELINE
891
-	pipeline_precompile($prepend_code);
892
-
893
-	if (spip_connect()) {
894
-		// lancer et initialiser les nouveaux crons !
895
-		include_spip('inc/genie');
896
-		genie_queue_watch_dist();
897
-	}
898
-
899
-	return ($GLOBALS['meta']['plugin'] != $actifs_avant);
793
+    // creer le repertoire cache/ si necessaire ! (installation notamment)
794
+    $cache = sous_repertoire(_DIR_CACHE, '', false, true);
795
+
796
+    // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore.
797
+    if (!$cache and !spip_connect()) {
798
+        return false;
799
+    }
800
+
801
+    if ($operation != 'raz') {
802
+        $plugin_valides = liste_chemin_plugin_actifs();
803
+        $plugin_valides = is_plugin_dir($plugin_valides);
804
+        if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
805
+            $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
806
+            $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL);
807
+            $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp);
808
+        }
809
+        // si des plugins sont en attentes (coches mais impossible a activer)
810
+        // on les reinjecte ici
811
+        if (isset($GLOBALS['meta']['plugin_attente'])
812
+            and $a = unserialize($GLOBALS['meta']['plugin_attente'])
813
+        ) {
814
+            $plugin_valides = $plugin_valides + liste_chemin_plugin($a);
815
+        }
816
+
817
+        if ($operation == 'ajoute') {
818
+            $plugin = array_merge($plugin_valides, $plugin);
819
+        } elseif ($operation == 'enleve') {
820
+            $plugin = array_diff($plugin_valides, $plugin);
821
+        } else {
822
+            $plugin = $plugin_valides;
823
+        }
824
+    }
825
+    $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : '';
826
+
827
+    // si une fonction de gestion de dependances existe, l'appeler ici
828
+    if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) {
829
+        $plugin = $ajouter_dependances($plugin);
830
+    }
831
+
832
+    // recharger le xml des plugins a activer
833
+    // on force le reload ici, meme si le fichier xml n'a pas change
834
+    // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
835
+    // pourra etre evite quand on ne supportera plus les plugin.xml
836
+    // en deplacant la detection de ces fichiers dans la compilation ci dessous
837
+    list($infos, $liste, $invalides) = liste_plugin_valides($plugin, true);
838
+    // trouver l'ordre d'activation
839
+    list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste);
840
+    if ($invalides or $reste) {
841
+        plugins_erreurs(array_merge($invalides, $reste), $liste, $infos);
842
+    }
843
+
844
+    // Ignorer les plugins necessitant une lib absente
845
+    // et preparer la meta d'entete Http
846
+    $err = $msg = $header = array();
847
+    foreach ($plugin_valides as $p => $resume) {
848
+        // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP
849
+        if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') {
850
+            $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : "");
851
+        }
852
+        if ($resume['dir']) {
853
+            foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
854
+                if (!find_in_path($l['nom'], 'lib/')) {
855
+                    $err[$p] = $resume;
856
+                    $msg[$p][] = $l;
857
+                    unset($plugin_valides[$p]);
858
+                }
859
+            }
860
+        }
861
+    }
862
+    if ($err) {
863
+        plugins_erreurs($err, '', $infos, $msg);
864
+    }
865
+
866
+    if (isset($GLOBALS['meta']['message_crash_plugins'])) {
867
+        effacer_meta('message_crash_plugins');
868
+    }
869
+    ecrire_meta('plugin', serialize($plugin_valides));
870
+    $liste = array_diff_key($liste, $plugin_valides);
871
+    ecrire_meta('plugin_attente', serialize($liste));
872
+    $header = strtolower(implode(",", $header));
873
+    if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) {
874
+        ecrire_fichier(_DIR_VAR . "config.txt",
875
+            (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
876
+    } else {
877
+        @unlink(_DIR_VAR . "config.txt");
878
+    }
879
+    // generer charger_plugins_chemin.php
880
+    plugins_precompile_chemin($plugin_valides, $ordre);
881
+    // generer les fichiers
882
+    // - charger_plugins_options.php
883
+    // - charger_plugins_fonctions.php
884
+    plugins_precompile_xxxtions($plugin_valides, $ordre);
885
+    // charger les chemins des plugins et les fichiers d'options 
886
+    // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins)
887
+    plugins_amorcer_plugins_actifs();
888
+    // mise a jour de la matrice des pipelines
889
+    $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
890
+    // generer le fichier _CACHE_PIPELINE
891
+    pipeline_precompile($prepend_code);
892
+
893
+    if (spip_connect()) {
894
+        // lancer et initialiser les nouveaux crons !
895
+        include_spip('inc/genie');
896
+        genie_queue_watch_dist();
897
+    }
898
+
899
+    return ($GLOBALS['meta']['plugin'] != $actifs_avant);
900 900
 }
901 901
 
902 902
 /**
@@ -915,56 +915,56 @@  discard block
 block discarded – undo
915 915
  *     Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances
916 916
 **/
917 917
 function plugins_precompile_chemin($plugin_valides, $ordre) {
918
-	$chemins = array();
919
-	$contenu = "";
920
-	foreach ($ordre as $p => $info) {
921
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
922
-		if (isset($plugin_valides[$p])) {
923
-			$dir_type = $plugin_valides[$p]['dir_type'];
924
-			$plug = $plugin_valides[$p]['dir'];
925
-			// definir le plugin, donc le path avant l'include du fichier options
926
-			// permet de faire des include_spip pour attraper un inc_ du plugin
927
-
928
-			$dir = $dir_type . ".'" . $plug . "/'";
929
-
930
-			$prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931
-			if (
932
-				$prefix !== "SPIP"
933
-				and strpos($dir, ":") === false // exclure le cas des procure:
934
-			) {
935
-				$contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
936
-				foreach ($info['chemin'] as $chemin) {
937
-					if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'],
938
-							$GLOBALS['spip_version_branche'], 'spip')
939
-					) {
940
-						$dir = $chemin['path'];
941
-						if (strlen($dir) and $dir[0] == "/") {
942
-							$dir = substr($dir, 1);
943
-						}
944
-						if (strlen($dir) and $dir == "./") {
945
-							$dir = '';
946
-						}
947
-						if (strlen($dir)) {
948
-							$dir = rtrim($dir, '/') . '/';
949
-						}
950
-						if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
-							$chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
952
-						}
953
-						if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
-							$chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
955
-						}
956
-					}
957
-				}
958
-			}
959
-		}
960
-	}
961
-	if (count($chemins)) {
962
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
-				array_reverse($chemins['public'])) . ")));\n"
964
-			. "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
965
-	}
966
-
967
-	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
918
+    $chemins = array();
919
+    $contenu = "";
920
+    foreach ($ordre as $p => $info) {
921
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
922
+        if (isset($plugin_valides[$p])) {
923
+            $dir_type = $plugin_valides[$p]['dir_type'];
924
+            $plug = $plugin_valides[$p]['dir'];
925
+            // definir le plugin, donc le path avant l'include du fichier options
926
+            // permet de faire des include_spip pour attraper un inc_ du plugin
927
+
928
+            $dir = $dir_type . ".'" . $plug . "/'";
929
+
930
+            $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
931
+            if (
932
+                $prefix !== "SPIP"
933
+                and strpos($dir, ":") === false // exclure le cas des procure:
934
+            ) {
935
+                $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
936
+                foreach ($info['chemin'] as $chemin) {
937
+                    if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'],
938
+                            $GLOBALS['spip_version_branche'], 'spip')
939
+                    ) {
940
+                        $dir = $chemin['path'];
941
+                        if (strlen($dir) and $dir[0] == "/") {
942
+                            $dir = substr($dir, 1);
943
+                        }
944
+                        if (strlen($dir) and $dir == "./") {
945
+                            $dir = '';
946
+                        }
947
+                        if (strlen($dir)) {
948
+                            $dir = rtrim($dir, '/') . '/';
949
+                        }
950
+                        if (!isset($chemin['type']) or $chemin['type'] == 'public') {
951
+                            $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
952
+                        }
953
+                        if (!isset($chemin['type']) or $chemin['type'] == 'prive') {
954
+                            $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : "");
955
+                        }
956
+                    }
957
+                }
958
+            }
959
+        }
960
+    }
961
+    if (count($chemins)) {
962
+        $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',',
963
+                array_reverse($chemins['public'])) . ")));\n"
964
+            . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n";
965
+    }
966
+
967
+    ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
968 968
 }
969 969
 
970 970
 /**
@@ -982,65 +982,65 @@  discard block
 block discarded – undo
982 982
  *     Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances
983 983
 **/
984 984
 function plugins_precompile_xxxtions($plugin_valides, $ordre) {
985
-	$contenu = array('options' => '', 'fonctions' => '');
986
-	$boutons = array();
987
-	$onglets = array();
988
-	$sign = "";
989
-
990
-	foreach ($ordre as $p => $info) {
991
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
992
-		if (isset($plugin_valides[$p])) {
993
-			$dir_type = $plugin_valides[$p]['dir_type'];
994
-			$plug = $plugin_valides[$p]['dir'];
995
-			$dir = constant($dir_type);
996
-			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
997
-			if ($info['menu']) {
998
-				$boutons = array_merge($boutons, $info['menu']);
999
-			}
1000
-			if ($info['onglet']) {
1001
-				$onglets = array_merge($onglets, $info['onglet']);
1002
-			}
1003
-			foreach ($contenu as $charge => $v) {
1004
-				// si pas declare/detecte a la lecture du paquet.xml,
1005
-				// detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
1006
-				// donc ni sa relecture, ni sa detection
1007
-				if (!isset($info[$charge])
1008
-					and $dir // exclure le cas du plugin "SPIP"
1009
-					and strpos($dir, ":") === false // exclure le cas des procure:
1010
-					and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011
-				) {
1012
-					if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1013
-						$info[$charge] = array($file);
1014
-					}
1015
-				}
1016
-				if (isset($info[$charge])) {
1017
-					$files = $info[$charge];
1018
-					foreach ($files as $k => $file) {
1019
-						// on genere un if file_exists devant chaque include
1020
-						// pour pouvoir garder le meme niveau d'erreur general
1021
-						$file = trim($file);
1022
-						if (!is_readable("$dir$plug/$file")
1023
-							// uniquement pour les paquet.xml
1024
-							and file_exists("$dir$plug/paquet.xml")
1025
-						) {
1026
-							unset($info[$charge][$k]);
1027
-						} else {
1028
-							$_file = $root_dir_type . ".'$plug/$file'";
1029
-							$contenu[$charge] .= "include_once_check($_file);\n";
1030
-						}
1031
-					}
1032
-				}
1033
-			}
1034
-			$sign .= md5(serialize($info));
1035
-		}
1036
-	}
1037
-
1038
-	$contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1039
-	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040
-		. plugin_ongletbouton("onglets_plugins", $onglets);
1041
-
1042
-	ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
1043
-	ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
985
+    $contenu = array('options' => '', 'fonctions' => '');
986
+    $boutons = array();
987
+    $onglets = array();
988
+    $sign = "";
989
+
990
+    foreach ($ordre as $p => $info) {
991
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
992
+        if (isset($plugin_valides[$p])) {
993
+            $dir_type = $plugin_valides[$p]['dir_type'];
994
+            $plug = $plugin_valides[$p]['dir'];
995
+            $dir = constant($dir_type);
996
+            $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
997
+            if ($info['menu']) {
998
+                $boutons = array_merge($boutons, $info['menu']);
999
+            }
1000
+            if ($info['onglet']) {
1001
+                $onglets = array_merge($onglets, $info['onglet']);
1002
+            }
1003
+            foreach ($contenu as $charge => $v) {
1004
+                // si pas declare/detecte a la lecture du paquet.xml,
1005
+                // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
1006
+                // donc ni sa relecture, ni sa detection
1007
+                if (!isset($info[$charge])
1008
+                    and $dir // exclure le cas du plugin "SPIP"
1009
+                    and strpos($dir, ":") === false // exclure le cas des procure:
1010
+                    and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
1011
+                ) {
1012
+                    if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) {
1013
+                        $info[$charge] = array($file);
1014
+                    }
1015
+                }
1016
+                if (isset($info[$charge])) {
1017
+                    $files = $info[$charge];
1018
+                    foreach ($files as $k => $file) {
1019
+                        // on genere un if file_exists devant chaque include
1020
+                        // pour pouvoir garder le meme niveau d'erreur general
1021
+                        $file = trim($file);
1022
+                        if (!is_readable("$dir$plug/$file")
1023
+                            // uniquement pour les paquet.xml
1024
+                            and file_exists("$dir$plug/paquet.xml")
1025
+                        ) {
1026
+                            unset($info[$charge][$k]);
1027
+                        } else {
1028
+                            $_file = $root_dir_type . ".'$plug/$file'";
1029
+                            $contenu[$charge] .= "include_once_check($_file);\n";
1030
+                        }
1031
+                    }
1032
+                }
1033
+            }
1034
+            $sign .= md5(serialize($info));
1035
+        }
1036
+    }
1037
+
1038
+    $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options'];
1039
+    $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
1040
+        . plugin_ongletbouton("onglets_plugins", $onglets);
1041
+
1042
+    ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
1043
+    ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
1044 1044
 }
1045 1045
 
1046 1046
 /**
@@ -1059,24 +1059,24 @@  discard block
 block discarded – undo
1059 1059
  * @return string Code php
1060 1060
  */
1061 1061
 function plugin_ongletbouton($nom, $val) {
1062
-	if (!$val) {
1063
-		$val = array();
1064
-	}
1065
-
1066
-	$val = serialize($val);
1067
-	$md5 = md5($val);
1068
-
1069
-	if (!defined("_UPDATED_$nom")) {
1070
-		define("_UPDATED_$nom", $val);
1071
-		define("_UPDATED_md5_$nom", $md5);
1072
-	}
1073
-	$val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1074
-
1075
-	return
1076
-		"if (!function_exists('$nom')) {\n"
1077
-		. "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
-		. "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1079
-		. "}\n";
1062
+    if (!$val) {
1063
+        $val = array();
1064
+    }
1065
+
1066
+    $val = serialize($val);
1067
+    $md5 = md5($val);
1068
+
1069
+    if (!defined("_UPDATED_$nom")) {
1070
+        define("_UPDATED_$nom", $val);
1071
+        define("_UPDATED_md5_$nom", $md5);
1072
+    }
1073
+    $val = "unserialize('" . str_replace("'", "\'", $val) . "')";
1074
+
1075
+    return
1076
+        "if (!function_exists('$nom')) {\n"
1077
+        . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
1078
+        . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n"
1079
+        . "}\n";
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1091,15 +1091,15 @@  discard block
 block discarded – undo
1091 1091
 **/
1092 1092
 function plugins_amorcer_plugins_actifs() {
1093 1093
 
1094
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1095
-		include_once(_CACHE_PLUGINS_PATH);
1096
-	} 
1094
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1095
+        include_once(_CACHE_PLUGINS_PATH);
1096
+    } 
1097 1097
 
1098
-	if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099
-		include_once(_CACHE_PLUGINS_OPT);
1100
-	} else {
1101
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1102
-	}
1098
+    if (@is_readable(_CACHE_PLUGINS_OPT)) {
1099
+        include_once(_CACHE_PLUGINS_OPT);
1100
+    } else {
1101
+        spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
1102
+    }
1103 1103
 }
1104 1104
 
1105 1105
 /**
@@ -1122,136 +1122,136 @@  discard block
 block discarded – undo
1122 1122
  *     Couples (nom du pipeline => Code PHP à insérer au début du pipeline)
1123 1123
 **/
1124 1124
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) {
1125
-	static $liste_pipe_manquants = array();
1126
-	if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) {
1127
-		$liste_pipe_manquants[] = $pipe_recherche;
1128
-	}
1129
-
1130
-	$prepend_code = array();
1131
-
1132
-	foreach ($ordre as $p => $info) {
1133
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
1134
-		if (isset($plugin_valides[$p])) {
1135
-			$dir_type = $plugin_valides[$p]['dir_type'];
1136
-			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137
-			$plug = $plugin_valides[$p]['dir'];
1138
-			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1139
-			if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140
-				foreach ($info['pipeline'] as $pipe) {
1141
-					$nom = $pipe['nom'];
1142
-					if (isset($pipe['action'])) {
1143
-						$action = $pipe['action'];
1144
-					} else {
1145
-						$action = $nom;
1146
-					}
1147
-					$nomlower = strtolower($nom);
1148
-					if ($nomlower != $nom
1149
-						and isset($GLOBALS['spip_pipeline'][$nom])
1150
-						and !isset($GLOBALS['spip_pipeline'][$nomlower])
1151
-					) {
1152
-						$GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
1153
-						unset($GLOBALS['spip_pipeline'][$nom]);
1154
-					}
1155
-					$nom = $nomlower;
1156
-					// une action vide est une declaration qui ne doit pas etre compilee !
1157
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1158
-					{
1159
-						$GLOBALS['spip_pipeline'][$nom] = "";
1160
-					}
1161
-					if ($action) {
1162
-						if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163
-							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
1164
-								$GLOBALS['spip_pipeline'][$nom], 1);
1165
-						}
1166
-						if (isset($pipe['inclure'])) {
1167
-							$GLOBALS['spip_matrice']["$prefix$action"] =
1168
-								"$root_dir_type:$plug/" . $pipe['inclure'];
1169
-						}
1170
-					}
1171
-				}
1172
-			}
1173
-			if (isset($info['genie']) and count($info['genie'])) {
1174
-				if (!isset($prepend_code['taches_generales_cron'])) {
1175
-					$prepend_code['taches_generales_cron'] = "";
1176
-				}
1177
-				foreach ($info['genie'] as $genie) {
1178
-					$nom = $prefix . $genie['nom'];
1179
-					$periode = max(60, intval($genie['periode']));
1180
-					if (charger_fonction($nom, "genie", true)) {
1181
-						$prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
1182
-					} else {
1183
-						spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR);
1184
-					}
1185
-				}
1186
-			}
1187
-			if (isset($info['style']) and count($info['style'])) {
1188
-				if (!isset($prepend_code['insert_head_css'])) {
1189
-					$prepend_code['insert_head_css'] = "";
1190
-				}
1191
-				if (!isset($prepend_code['header_prive_css'])) {
1192
-					$prepend_code['header_prive_css'] = "";
1193
-				}
1194
-				foreach ($info['style'] as $style) {
1195
-					if (isset($style['path']) and $style['path']) {
1196
-						$code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1197
-					} else {
1198
-						$code = "if (\$f='" . addslashes($style['url']) . "') ";
1199
-					}
1200
-					$code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201
-					if (isset($style['media']) and strlen($style['media'])) {
1202
-						$code .= " media=\"" . addslashes($style['media']) . "\"";
1203
-					}
1204
-					$code .= "/>';\n";
1205
-					if ($style['type'] != 'prive') {
1206
-						$prepend_code['insert_head_css'] .= $code;
1207
-					}
1208
-					if ($style['type'] != 'public') {
1209
-						$prepend_code['header_prive_css'] .= $code;
1210
-					}
1211
-				}
1212
-			}
1213
-			if (!isset($prepend_code['insert_head'])) {
1214
-				$prepend_code['insert_head'] = "";
1215
-			}
1216
-			if (!isset($prepend_code['header_prive'])) {
1217
-				$prepend_code['header_prive'] = "";
1218
-			}
1219
-			if (isset($info['script']) and count($info['script'])) {
1220
-				foreach ($info['script'] as $script) {
1221
-					if (isset($script['path']) and $script['path']) {
1222
-						$code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1223
-					} else {
1224
-						$code = "if (\$f='" . addslashes($script['url']) . "') ";
1225
-					}
1226
-					$code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227
-					if ($script['type'] != 'prive') {
1228
-						$prepend_code['insert_head'] .= $code;
1229
-					}
1230
-					if ($script['type'] != 'public') {
1231
-						$prepend_code['header_prive'] .= $code;
1232
-					}
1233
-				}
1234
-			}
1235
-		}
1236
-	}
1237
-
1238
-	$prepend_code['insert_head'] =
1239
-		"include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n"
1240
-		. "\$val = minipipe('f_jQuery', \$val);\n"
1241
-		. $prepend_code['insert_head'];
1242
-	$prepend_code['header_prive'] =
1243
-		"include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n"
1244
-		. "\$val = minipipe('f_jQuery_prive', \$val);\n"
1245
-		. $prepend_code['header_prive'];
1246
-
1247
-	// on ajoute les pipe qui ont ete recenses manquants
1248
-	foreach ($liste_pipe_manquants as $add_pipe) {
1249
-		if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) {
1250
-			$GLOBALS['spip_pipeline'][$add_pipe] = '';
1251
-		}
1252
-	}
1253
-
1254
-	return $prepend_code;
1125
+    static $liste_pipe_manquants = array();
1126
+    if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) {
1127
+        $liste_pipe_manquants[] = $pipe_recherche;
1128
+    }
1129
+
1130
+    $prepend_code = array();
1131
+
1132
+    foreach ($ordre as $p => $info) {
1133
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
1134
+        if (isset($plugin_valides[$p])) {
1135
+            $dir_type = $plugin_valides[$p]['dir_type'];
1136
+            $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
1137
+            $plug = $plugin_valides[$p]['dir'];
1138
+            $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_");
1139
+            if (isset($info['pipeline']) and is_array($info['pipeline'])) {
1140
+                foreach ($info['pipeline'] as $pipe) {
1141
+                    $nom = $pipe['nom'];
1142
+                    if (isset($pipe['action'])) {
1143
+                        $action = $pipe['action'];
1144
+                    } else {
1145
+                        $action = $nom;
1146
+                    }
1147
+                    $nomlower = strtolower($nom);
1148
+                    if ($nomlower != $nom
1149
+                        and isset($GLOBALS['spip_pipeline'][$nom])
1150
+                        and !isset($GLOBALS['spip_pipeline'][$nomlower])
1151
+                    ) {
1152
+                        $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
1153
+                        unset($GLOBALS['spip_pipeline'][$nom]);
1154
+                    }
1155
+                    $nom = $nomlower;
1156
+                    // une action vide est une declaration qui ne doit pas etre compilee !
1157
+                    if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
1158
+                    {
1159
+                        $GLOBALS['spip_pipeline'][$nom] = "";
1160
+                    }
1161
+                    if ($action) {
1162
+                        if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) {
1163
+                            $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1",
1164
+                                $GLOBALS['spip_pipeline'][$nom], 1);
1165
+                        }
1166
+                        if (isset($pipe['inclure'])) {
1167
+                            $GLOBALS['spip_matrice']["$prefix$action"] =
1168
+                                "$root_dir_type:$plug/" . $pipe['inclure'];
1169
+                        }
1170
+                    }
1171
+                }
1172
+            }
1173
+            if (isset($info['genie']) and count($info['genie'])) {
1174
+                if (!isset($prepend_code['taches_generales_cron'])) {
1175
+                    $prepend_code['taches_generales_cron'] = "";
1176
+                }
1177
+                foreach ($info['genie'] as $genie) {
1178
+                    $nom = $prefix . $genie['nom'];
1179
+                    $periode = max(60, intval($genie['periode']));
1180
+                    if (charger_fonction($nom, "genie", true)) {
1181
+                        $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n";
1182
+                    } else {
1183
+                        spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR);
1184
+                    }
1185
+                }
1186
+            }
1187
+            if (isset($info['style']) and count($info['style'])) {
1188
+                if (!isset($prepend_code['insert_head_css'])) {
1189
+                    $prepend_code['insert_head_css'] = "";
1190
+                }
1191
+                if (!isset($prepend_code['header_prive_css'])) {
1192
+                    $prepend_code['header_prive_css'] = "";
1193
+                }
1194
+                foreach ($info['style'] as $style) {
1195
+                    if (isset($style['path']) and $style['path']) {
1196
+                        $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) ";
1197
+                    } else {
1198
+                        $code = "if (\$f='" . addslashes($style['url']) . "') ";
1199
+                    }
1200
+                    $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\"";
1201
+                    if (isset($style['media']) and strlen($style['media'])) {
1202
+                        $code .= " media=\"" . addslashes($style['media']) . "\"";
1203
+                    }
1204
+                    $code .= "/>';\n";
1205
+                    if ($style['type'] != 'prive') {
1206
+                        $prepend_code['insert_head_css'] .= $code;
1207
+                    }
1208
+                    if ($style['type'] != 'public') {
1209
+                        $prepend_code['header_prive_css'] .= $code;
1210
+                    }
1211
+                }
1212
+            }
1213
+            if (!isset($prepend_code['insert_head'])) {
1214
+                $prepend_code['insert_head'] = "";
1215
+            }
1216
+            if (!isset($prepend_code['header_prive'])) {
1217
+                $prepend_code['header_prive'] = "";
1218
+            }
1219
+            if (isset($info['script']) and count($info['script'])) {
1220
+                foreach ($info['script'] as $script) {
1221
+                    if (isset($script['path']) and $script['path']) {
1222
+                        $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) ";
1223
+                    } else {
1224
+                        $code = "if (\$f='" . addslashes($script['url']) . "') ";
1225
+                    }
1226
+                    $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n";
1227
+                    if ($script['type'] != 'prive') {
1228
+                        $prepend_code['insert_head'] .= $code;
1229
+                    }
1230
+                    if ($script['type'] != 'public') {
1231
+                        $prepend_code['header_prive'] .= $code;
1232
+                    }
1233
+                }
1234
+            }
1235
+        }
1236
+    }
1237
+
1238
+    $prepend_code['insert_head'] =
1239
+        "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n"
1240
+        . "\$val = minipipe('f_jQuery', \$val);\n"
1241
+        . $prepend_code['insert_head'];
1242
+    $prepend_code['header_prive'] =
1243
+        "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n"
1244
+        . "\$val = minipipe('f_jQuery_prive', \$val);\n"
1245
+        . $prepend_code['header_prive'];
1246
+
1247
+    // on ajoute les pipe qui ont ete recenses manquants
1248
+    foreach ($liste_pipe_manquants as $add_pipe) {
1249
+        if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) {
1250
+            $GLOBALS['spip_pipeline'][$add_pipe] = '';
1251
+        }
1252
+    }
1253
+
1254
+    return $prepend_code;
1255 1255
 }
1256 1256
 
1257 1257
 /**
@@ -1278,44 +1278,44 @@  discard block
 block discarded – undo
1278 1278
 **/
1279 1279
 function pipeline_precompile($prepend_code = array()) {
1280 1280
 
1281
-	$content = "";
1282
-	foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) {
1283
-		$s_inc = "";
1284
-		$s_call = "";
1285
-		$pipe = array_filter(explode('|', $pipeline));
1286
-		// Eclater le pipeline en filtres et appliquer chaque filtre
1287
-		foreach ($pipe as $fonc) {
1288
-			$fonc = trim($fonc);
1289
-			$s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1290
-			if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291
-				$file = $GLOBALS['spip_matrice'][$fonc];
1292
-				$file = "'$file'";
1293
-				// si un _DIR_XXX: est dans la chaine, on extrait la constante
1294
-				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) {
1295
-					$dir = $regs[1];
1296
-					$root_dir = str_replace('_DIR_', '_ROOT_', $dir);
1297
-					if (defined($root_dir)) {
1298
-						$dir = $root_dir;
1299
-					}
1300
-					$file = str_replace($regs[0], "'." . $dir . ".'", $file);
1301
-					$file = str_replace("''.", "", $file);
1302
-					$file = str_replace(constant($dir), '', $file);
1303
-				}
1304
-				$s_inc .= "include_once_check($file);\n";
1305
-			}
1306
-		}
1307
-		if (strlen($s_inc)) {
1308
-			$s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
1309
-		}
1310
-		$content .= "// Pipeline $action \n"
1311
-			. "function execute_pipeline_$action(&\$val){\n"
1312
-			. $s_inc
1313
-			. ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1314
-			. $s_call
1315
-			. "return \$val;\n}\n";
1316
-	}
1317
-	ecrire_fichier_php(_CACHE_PIPELINES, $content);
1318
-	clear_path_cache();
1281
+    $content = "";
1282
+    foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) {
1283
+        $s_inc = "";
1284
+        $s_call = "";
1285
+        $pipe = array_filter(explode('|', $pipeline));
1286
+        // Eclater le pipeline en filtres et appliquer chaque filtre
1287
+        foreach ($pipe as $fonc) {
1288
+            $fonc = trim($fonc);
1289
+            $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n";
1290
+            if (isset($GLOBALS['spip_matrice'][$fonc])) {
1291
+                $file = $GLOBALS['spip_matrice'][$fonc];
1292
+                $file = "'$file'";
1293
+                // si un _DIR_XXX: est dans la chaine, on extrait la constante
1294
+                if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) {
1295
+                    $dir = $regs[1];
1296
+                    $root_dir = str_replace('_DIR_', '_ROOT_', $dir);
1297
+                    if (defined($root_dir)) {
1298
+                        $dir = $root_dir;
1299
+                    }
1300
+                    $file = str_replace($regs[0], "'." . $dir . ".'", $file);
1301
+                    $file = str_replace("''.", "", $file);
1302
+                    $file = str_replace(constant($dir), '', $file);
1303
+                }
1304
+                $s_inc .= "include_once_check($file);\n";
1305
+            }
1306
+        }
1307
+        if (strlen($s_inc)) {
1308
+            $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
1309
+        }
1310
+        $content .= "// Pipeline $action \n"
1311
+            . "function execute_pipeline_$action(&\$val){\n"
1312
+            . $s_inc
1313
+            . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '')
1314
+            . $s_call
1315
+            . "return \$val;\n}\n";
1316
+    }
1317
+    ecrire_fichier_php(_CACHE_PIPELINES, $content);
1318
+    clear_path_cache();
1319 1319
 }
1320 1320
 
1321 1321
 
@@ -1328,12 +1328,12 @@  discard block
 block discarded – undo
1328 1328
  *     true si le plugin est actif, false sinon
1329 1329
 **/
1330 1330
 function plugin_est_installe($plug_path) {
1331
-	$plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array();
1332
-	if (!$plugin_installes) {
1333
-		return false;
1334
-	}
1331
+    $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array();
1332
+    if (!$plugin_installes) {
1333
+        return false;
1334
+    }
1335 1335
 
1336
-	return in_array($plug_path, $plugin_installes);
1336
+    return in_array($plug_path, $plugin_installes);
1337 1337
 }
1338 1338
 
1339 1339
 
@@ -1346,37 +1346,37 @@  discard block
 block discarded – undo
1346 1346
  * @uses plugins_installer_dist()
1347 1347
  **/
1348 1348
 function plugin_installes_meta() {
1349
-	if (isset($GLOBALS['fichier_php_compile_recent'])) {
1350
-		// attendre eventuellement l'invalidation du cache opcode
1351
-		spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
1352
-	}
1353
-
1354
-	$installer_plugins = charger_fonction('installer', 'plugins');
1355
-	$meta_plug_installes = array();
1356
-	foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) {
1357
-		if ($plug = $resume['dir']) {
1358
-			$infos = $installer_plugins($plug, 'install', $resume['dir_type']);
1359
-			if ($infos) {
1360
-				if (!is_array($infos) or $infos['install_test'][0]) {
1361
-					$meta_plug_installes[] = $plug;
1362
-				}
1363
-				if (is_array($infos)) {
1364
-					list($ok, $trace) = $infos['install_test'];
1365
-					include_spip('inc/filtres_boites');
1366
-					echo "<div class='install-plugins svp_retour'>"
1367
-						. boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))),
1368
-							($ok ? 'success' : 'error'))
1369
-						. $trace
1370
-						. "<div class='result'>"
1371
-						. ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
1372
-						. "</div>"
1373
-						. boite_fermer()
1374
-						. "</div>";
1375
-				}
1376
-			}
1377
-		}
1378
-	}
1379
-	ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non');
1349
+    if (isset($GLOBALS['fichier_php_compile_recent'])) {
1350
+        // attendre eventuellement l'invalidation du cache opcode
1351
+        spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']);
1352
+    }
1353
+
1354
+    $installer_plugins = charger_fonction('installer', 'plugins');
1355
+    $meta_plug_installes = array();
1356
+    foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) {
1357
+        if ($plug = $resume['dir']) {
1358
+            $infos = $installer_plugins($plug, 'install', $resume['dir_type']);
1359
+            if ($infos) {
1360
+                if (!is_array($infos) or $infos['install_test'][0]) {
1361
+                    $meta_plug_installes[] = $plug;
1362
+                }
1363
+                if (is_array($infos)) {
1364
+                    list($ok, $trace) = $infos['install_test'];
1365
+                    include_spip('inc/filtres_boites');
1366
+                    echo "<div class='install-plugins svp_retour'>"
1367
+                        . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))),
1368
+                            ($ok ? 'success' : 'error'))
1369
+                        . $trace
1370
+                        . "<div class='result'>"
1371
+                        . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
1372
+                        . "</div>"
1373
+                        . boite_fermer()
1374
+                        . "</div>";
1375
+                }
1376
+            }
1377
+        }
1378
+    }
1379
+    ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non');
1380 1380
 }
1381 1381
 
1382 1382
 /**
@@ -1390,29 +1390,29 @@  discard block
 block discarded – undo
1390 1390
  *     Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante
1391 1391
 **/
1392 1392
 function ecrire_fichier_php($nom, $contenu, $comment = '') {
1393
-	if (!isset($GLOBALS['fichier_php_compile_recent'])) {
1394
-		$GLOBALS['fichier_php_compile_recent'] = 0;
1395
-	}
1396
-
1397
-	$contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1398
-	// si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399
-	// si pas de modif on ne touche pas au fichier initial
1400
-	if (file_exists($nom)) {
1401
-		if (substr($nom, -4) == '.php') {
1402
-			$fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
-		}
1404
-		else {
1405
-			$fichier_tmp = $nom . '.tmp';
1406
-		}
1407
-		file_put_contents($fichier_tmp, $contenu);
1408
-		if(md5_file($nom) == md5_file($fichier_tmp)) {
1409
-			$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410
-			@unlink($fichier_tmp);
1411
-			return;
1412
-		}
1413
-		@unlink($fichier_tmp);
1414
-	}
1415
-	ecrire_fichier($nom, $contenu);
1416
-	$GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1417
-	spip_clear_opcode_cache(realpath($nom));
1393
+    if (!isset($GLOBALS['fichier_php_compile_recent'])) {
1394
+        $GLOBALS['fichier_php_compile_recent'] = 0;
1395
+    }
1396
+
1397
+    $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>';
1398
+    // si un fichier existe deja on verifie que son contenu change avant de l'ecraser
1399
+    // si pas de modif on ne touche pas au fichier initial
1400
+    if (file_exists($nom)) {
1401
+        if (substr($nom, -4) == '.php') {
1402
+            $fichier_tmp = substr($nom, 0, -4) . '.tmp.php';
1403
+        }
1404
+        else {
1405
+            $fichier_tmp = $nom . '.tmp';
1406
+        }
1407
+        file_put_contents($fichier_tmp, $contenu);
1408
+        if(md5_file($nom) == md5_file($fichier_tmp)) {
1409
+            $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1410
+            @unlink($fichier_tmp);
1411
+            return;
1412
+        }
1413
+        @unlink($fichier_tmp);
1414
+    }
1415
+    ecrire_fichier($nom, $contenu);
1416
+    $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom));
1417
+    spip_clear_opcode_cache(realpath($nom));
1418 1418
 }
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -165,7 +165,7 @@
 block discarded – undo
165 165
  * @param string $primary
166 166
  * @param array $rows
167 167
  * @param string $serveur
168
- * @return array
168
+ * @return string[]
169 169
  */
170 170
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
171 171
 	# calculer le {id_article IN()} et le {... as points}
Please login to merge, or discard this patch.
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,111 +49,111 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = array(),
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = array(),
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = array();
60
-	$delai_fraicheur = min(_DELAI_CACHE_resultats,
61
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
-
63
-	// si recherche n'est pas dans le contexte, on va prendre en globals
64
-	// ca permet de faire des inclure simple.
65
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
-		$recherche = $GLOBALS['recherche'];
67
-	}
68
-
69
-	// traiter le cas {recherche?}
70
-	if ($cond and !strlen($recherche)) {
71
-		return array(
72
-			"0 as points" /* as points */, /* where */
73
-			''
74
-		);
75
-	}
76
-
77
-
78
-	$rechercher = false;
79
-
80
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
-	if (!isset($cache[$serveur][$table][$recherche])) {
82
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
-		$hash = substr(md5($recherche . $table), 0, 16);
84
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
-		$row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
-			$where . " AND $where_resultat_recent", '', '', '0,1');
87
-		if (!$row
88
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
-		) {
90
-			$rechercher = true;
91
-		}
92
-	}
93
-
94
-	// si on n'a pas encore traite les donnees dans une boucle precedente
95
-	if ($rechercher) {
96
-		//$tables = liste_des_champs();
97
-		$x = objet_type($table);
98
-		$points = recherche_en_base($recherche,
99
-			$x,
100
-			array(
101
-				'score' => true,
102
-				'toutvoir' => true,
103
-				'jointures' => true
104
-			),
105
-			$serveur);
106
-		// pas de résultat, pas de point
107
-		$points = isset($points[$x]) ? $points[$x] : array();
108
-
109
-		// permettre aux plugins de modifier le resultat
110
-		$points = pipeline('prepare_recherche', array(
111
-			'args' => array(
112
-				'type' => $x,
113
-				'recherche' => $recherche,
114
-				'serveur' => $serveur,
115
-				'modificateurs' => $modificateurs
116
-			),
117
-			'data' => $points
118
-		));
119
-
120
-		// supprimer les anciens resultats de cette recherche
121
-		// et les resultats trop vieux avec une marge
122
-		// pas de AS resultats dans un delete (mysql)
123
-		$whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
-			array("recherche", "table_objet", "serveur"), $where);
125
-
126
-		sql_delete('spip_resultats',
127
-			"NOT($where_resultat_recent) OR ($whered)");
128
-
129
-		// inserer les resultats dans la table de cache des resultats
130
-		if (count($points)) {
131
-			$tab_couples = array();
132
-			foreach ($points as $id => $p) {
133
-				$tab_couples[] = array(
134
-					'recherche' => $hash,
135
-					'id' => $id,
136
-					'points' => $p['score'],
137
-					'table_objet' => $table,
138
-					'serveur' => $hash_serv,
139
-				);
140
-			}
141
-			sql_insertq_multi('spip_resultats', $tab_couples, array());
142
-		}
143
-	}
144
-
145
-	if (!isset($cache[$serveur][$table][$recherche])) {
146
-		if (!$serveur) {
147
-			$cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
-		} else {
149
-			if (sql_countsel('spip_resultats as resultats', $where)) {
150
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
-			}
152
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
-		}
154
-	}
155
-
156
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = array();
60
+    $delai_fraicheur = min(_DELAI_CACHE_resultats,
61
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0));
62
+
63
+    // si recherche n'est pas dans le contexte, on va prendre en globals
64
+    // ca permet de faire des inclure simple.
65
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
66
+        $recherche = $GLOBALS['recherche'];
67
+    }
68
+
69
+    // traiter le cas {recherche?}
70
+    if ($cond and !strlen($recherche)) {
71
+        return array(
72
+            "0 as points" /* as points */, /* where */
73
+            ''
74
+        );
75
+    }
76
+
77
+
78
+    $rechercher = false;
79
+
80
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81
+    if (!isset($cache[$serveur][$table][$recherche])) {
82
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
+        $hash = substr(md5($recherche . $table), 0, 16);
84
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
+        $row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
+            $where . " AND $where_resultat_recent", '', '', '0,1');
87
+        if (!$row
88
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89
+        ) {
90
+            $rechercher = true;
91
+        }
92
+    }
93
+
94
+    // si on n'a pas encore traite les donnees dans une boucle precedente
95
+    if ($rechercher) {
96
+        //$tables = liste_des_champs();
97
+        $x = objet_type($table);
98
+        $points = recherche_en_base($recherche,
99
+            $x,
100
+            array(
101
+                'score' => true,
102
+                'toutvoir' => true,
103
+                'jointures' => true
104
+            ),
105
+            $serveur);
106
+        // pas de résultat, pas de point
107
+        $points = isset($points[$x]) ? $points[$x] : array();
108
+
109
+        // permettre aux plugins de modifier le resultat
110
+        $points = pipeline('prepare_recherche', array(
111
+            'args' => array(
112
+                'type' => $x,
113
+                'recherche' => $recherche,
114
+                'serveur' => $serveur,
115
+                'modificateurs' => $modificateurs
116
+            ),
117
+            'data' => $points
118
+        ));
119
+
120
+        // supprimer les anciens resultats de cette recherche
121
+        // et les resultats trop vieux avec une marge
122
+        // pas de AS resultats dans un delete (mysql)
123
+        $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"),
124
+            array("recherche", "table_objet", "serveur"), $where);
125
+
126
+        sql_delete('spip_resultats',
127
+            "NOT($where_resultat_recent) OR ($whered)");
128
+
129
+        // inserer les resultats dans la table de cache des resultats
130
+        if (count($points)) {
131
+            $tab_couples = array();
132
+            foreach ($points as $id => $p) {
133
+                $tab_couples[] = array(
134
+                    'recherche' => $hash,
135
+                    'id' => $id,
136
+                    'points' => $p['score'],
137
+                    'table_objet' => $table,
138
+                    'serveur' => $hash_serv,
139
+                );
140
+            }
141
+            sql_insertq_multi('spip_resultats', $tab_couples, array());
142
+        }
143
+    }
144
+
145
+    if (!isset($cache[$serveur][$table][$recherche])) {
146
+        if (!$serveur) {
147
+            $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where);
148
+        } else {
149
+            if (sql_countsel('spip_resultats as resultats', $where)) {
150
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
151
+            }
152
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
153
+        }
154
+    }
155
+
156
+    return $cache[$serveur][$table][$recherche];
157 157
 }
158 158
 
159 159
 
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
  * @return array
170 170
  */
171 171
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
172
-	# calculer le {id_article IN()} et le {... as points}
173
-	if (!count($rows)) {
174
-		return array("''", "0=1");
175
-	} else {
176
-		$listes_ids = array();
177
-		$select = '0';
178
-		foreach ($rows as $r) {
179
-			$listes_ids[$r['points']][] = $r['id'];
180
-		}
181
-
182
-		foreach ($listes_ids as $p => $ids) {
183
-			$select .= "+$p*(" .
184
-				sql_in("$table.$primary", $ids, '', $serveur)
185
-				. ") ";
186
-		}
187
-
188
-		return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
-	}
172
+    # calculer le {id_article IN()} et le {... as points}
173
+    if (!count($rows)) {
174
+        return array("''", "0=1");
175
+    } else {
176
+        $listes_ids = array();
177
+        $select = '0';
178
+        foreach ($rows as $r) {
179
+            $listes_ids[$r['points']][] = $r['id'];
180
+        }
181
+
182
+        foreach ($listes_ids as $p => $ids) {
183
+            $select .= "+$p*(" .
184
+                sql_in("$table.$primary", $ids, '', $serveur)
185
+                . ") ";
186
+        }
187
+
188
+        return array("$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur));
189
+    }
190 190
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND");
81 81
 	if (!isset($cache[$serveur][$table][$recherche])) {
82 82
 		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
83
-		$hash = substr(md5($recherche . $table), 0, 16);
84
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
83
+		$hash = substr(md5($recherche.$table), 0, 16);
84
+		$where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')";
85 85
 		$row = sql_fetsel('recherche', 'spip_resultats AS resultats',
86
-			$where . " AND $where_resultat_recent", '', '', '0,1');
86
+			$where." AND $where_resultat_recent", '', '', '0,1');
87 87
 		if (!$row
88 88
 			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
89 89
 		) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		}
181 181
 
182 182
 		foreach ($listes_ids as $p => $ids) {
183
-			$select .= "+$p*(" .
183
+			$select .= "+$p*(".
184 184
 				sql_in("$table.$primary", $ids, '', $serveur)
185 185
 				. ") ";
186 186
 		}
Please login to merge, or discard this patch.
ecrire/inc/puce_statut.php 3 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -415,6 +415,13 @@
 block discarded – undo
415 415
 }
416 416
 
417 417
 
418
+/**
419
+ * @param integer $id
420
+ * @param string $type
421
+ * @param double $n
422
+ * @param string|null $img
423
+ * @param string $titre
424
+ */
418 425
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
419 426
 	$h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
420 427
 	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
Please login to merge, or discard this patch.
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 if (!defined('_ACTIVER_PUCE_RAPIDE')) {
25
-	/**
26
-	 * Activer le changement rapide de statut sur les listes d'objets ?
27
-	 *
28
-	 * Peut ralentir un site sur des listes très longues.
29
-	 *
30
-	 * @var bool
31
-	 **/
32
-	define('_ACTIVER_PUCE_RAPIDE', true);
25
+    /**
26
+     * Activer le changement rapide de statut sur les listes d'objets ?
27
+     *
28
+     * Peut ralentir un site sur des listes très longues.
29
+     *
30
+     * @var bool
31
+     **/
32
+    define('_ACTIVER_PUCE_RAPIDE', true);
33 33
 }
34 34
 
35 35
 /**
@@ -57,31 +57,31 @@  discard block
 block discarded – undo
57 57
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
58 58
  */
59 59
 function inc_puce_statut_dist(
60
-	$id_objet,
61
-	$statut,
62
-	$id_parent,
63
-	$type,
64
-	$ajax = false,
65
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
60
+    $id_objet,
61
+    $statut,
62
+    $id_parent,
63
+    $type,
64
+    $ajax = false,
65
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
66 66
 ) {
67
-	static $f_puce_statut = array();
68
-	$type = objet_type($type);
69
-	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
70
-	if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
71
-		$f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
72
-	}
73
-	if ($f_puce_statut[$type]) {
74
-		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
75
-	}
76
-
77
-	// si statut_image trouve quelque chose (et '' est quelque chose)
78
-	// composer une puce, avec si possible changement rapide
79
-	elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
80
-		return $puce;
81
-	} // sinon fausse puce avec le type de l'image
82
-	else {
83
-		return http_img_pack("$type-16.png", '');
84
-	}
67
+    static $f_puce_statut = array();
68
+    $type = objet_type($type);
69
+    // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
70
+    if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) {
71
+        $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
72
+    }
73
+    if ($f_puce_statut[$type]) {
74
+        return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
75
+    }
76
+
77
+    // si statut_image trouve quelque chose (et '' est quelque chose)
78
+    // composer une puce, avec si possible changement rapide
79
+    elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
80
+        return $puce;
81
+    } // sinon fausse puce avec le type de l'image
82
+    else {
83
+        return http_img_pack("$type-16.png", '');
84
+    }
85 85
 }
86 86
 
87 87
 /**
@@ -110,41 +110,41 @@  discard block
 block discarded – undo
110 110
  *   null si pas capable de déterminer l'image
111 111
  */
112 112
 function statut_image($objet, $statut) {
113
-	$src = null;
114
-	$table = table_objet_sql($objet);
115
-	$desc = lister_tables_objets_sql($table);
116
-	if (isset($desc['statut_images'])) {
117
-		// si une declaration statut_images
118
-		// mais rien pour le statut demande, ne rien afficher
119
-		$src = '';
120
-		if (isset($desc['statut_images'][$statut])) {
121
-			$src = $desc['statut_images'][$statut];
122
-		} // sinon image par defaut ?
123
-		elseif (isset($desc['statut_images'][0])) {
124
-			$src = $desc['statut_images'][0];
125
-		}
126
-	} else {
127
-		switch ($statut) {
128
-			case 'prepa':
129
-				$src = 'puce-preparer-8.png';
130
-				break;
131
-			case 'prop':
132
-				$src = 'puce-proposer-8.png';
133
-				break;
134
-			case 'publie':
135
-				$src = 'puce-publier-8.png';
136
-				break;
137
-			case 'refuse':
138
-				$src = 'puce-refuser-8.png';
139
-				break;
140
-			case 'poubelle':
141
-			case 'poub':
142
-				$src = 'puce-supprimer-8.png';
143
-				break;
144
-		}
145
-	}
146
-
147
-	return $src;
113
+    $src = null;
114
+    $table = table_objet_sql($objet);
115
+    $desc = lister_tables_objets_sql($table);
116
+    if (isset($desc['statut_images'])) {
117
+        // si une declaration statut_images
118
+        // mais rien pour le statut demande, ne rien afficher
119
+        $src = '';
120
+        if (isset($desc['statut_images'][$statut])) {
121
+            $src = $desc['statut_images'][$statut];
122
+        } // sinon image par defaut ?
123
+        elseif (isset($desc['statut_images'][0])) {
124
+            $src = $desc['statut_images'][0];
125
+        }
126
+    } else {
127
+        switch ($statut) {
128
+            case 'prepa':
129
+                $src = 'puce-preparer-8.png';
130
+                break;
131
+            case 'prop':
132
+                $src = 'puce-proposer-8.png';
133
+                break;
134
+            case 'publie':
135
+                $src = 'puce-publier-8.png';
136
+                break;
137
+            case 'refuse':
138
+                $src = 'puce-refuser-8.png';
139
+                break;
140
+            case 'poubelle':
141
+            case 'poub':
142
+                $src = 'puce-supprimer-8.png';
143
+                break;
144
+        }
145
+    }
146
+
147
+    return $src;
148 148
 }
149 149
 
150 150
 /**
@@ -172,40 +172,40 @@  discard block
 block discarded – undo
172 172
  * @return string
173 173
  */
174 174
 function statut_titre($objet, $statut) {
175
-	$titre = '';
176
-	$table = table_objet_sql($objet);
177
-	$desc = lister_tables_objets_sql($table);
178
-	if (isset($desc['statut_titres'])) {
179
-		// si une declaration statut_titres
180
-		// mais rien pour le statut demande, ne rien afficher
181
-		if (isset($desc['statut_titres'][$statut])) {
182
-			$titre = $desc['statut_titres'][$statut];
183
-		} // sinon image par defaut ?
184
-		elseif (isset($desc['statut_titres'][0])) {
185
-			$titre = $desc['statut_titres'][0];
186
-		}
187
-	} else {
188
-		switch ($statut) {
189
-			case 'prepa':
190
-				$titre = 'texte_statut_en_cours_redaction';
191
-				break;
192
-			case 'prop':
193
-				$titre = 'texte_statut_propose_evaluation';
194
-				break;
195
-			case 'publie':
196
-				$titre = 'texte_statut_publie';
197
-				break;
198
-			case 'refuse':
199
-				$titre = 'texte_statut_refuse';
200
-				break;
201
-			case 'poubelle':
202
-			case 'poub':
203
-				$titre = 'texte_statut_poubelle';
204
-				break;
205
-		}
206
-	}
207
-
208
-	return $titre ? _T($titre) : '';
175
+    $titre = '';
176
+    $table = table_objet_sql($objet);
177
+    $desc = lister_tables_objets_sql($table);
178
+    if (isset($desc['statut_titres'])) {
179
+        // si une declaration statut_titres
180
+        // mais rien pour le statut demande, ne rien afficher
181
+        if (isset($desc['statut_titres'][$statut])) {
182
+            $titre = $desc['statut_titres'][$statut];
183
+        } // sinon image par defaut ?
184
+        elseif (isset($desc['statut_titres'][0])) {
185
+            $titre = $desc['statut_titres'][0];
186
+        }
187
+    } else {
188
+        switch ($statut) {
189
+            case 'prepa':
190
+                $titre = 'texte_statut_en_cours_redaction';
191
+                break;
192
+            case 'prop':
193
+                $titre = 'texte_statut_propose_evaluation';
194
+                break;
195
+            case 'publie':
196
+                $titre = 'texte_statut_publie';
197
+                break;
198
+            case 'refuse':
199
+                $titre = 'texte_statut_refuse';
200
+                break;
201
+            case 'poubelle':
202
+            case 'poub':
203
+                $titre = 'texte_statut_poubelle';
204
+                break;
205
+        }
206
+    }
207
+
208
+    return $titre ? _T($titre) : '';
209 209
 }
210 210
 
211 211
 
@@ -225,37 +225,37 @@  discard block
 block discarded – undo
225 225
  * @return string
226 226
  */
227 227
 function statut_texte_instituer($objet, $statut) {
228
-	$texte = '';
229
-	$table = table_objet_sql($objet);
230
-	$desc = lister_tables_objets_sql($table);
231
-	if (isset($desc['statut_textes_instituer'])) {
232
-		// si une declaration statut_titres
233
-		// mais rien pour le statut demande, ne rien afficher
234
-		if (isset($desc['statut_textes_instituer'][$statut])) {
235
-			$texte = $desc['statut_textes_instituer'][$statut];
236
-		}
237
-	} else {
238
-		switch ($statut) {
239
-			case 'prepa':
240
-				$texte = 'texte_statut_en_cours_redaction';
241
-				break;
242
-			case 'prop':
243
-				$texte = 'texte_statut_propose_evaluation';
244
-				break;
245
-			case 'publie':
246
-				$texte = 'texte_statut_publie';
247
-				break;
248
-			case 'refuse':
249
-				$texte = 'texte_statut_refuse';
250
-				break;
251
-			case 'poubelle':
252
-			case 'poub':
253
-				$texte = 'texte_statut_poubelle';
254
-				break;
255
-		}
256
-	}
257
-
258
-	return $texte ? _T($texte) : '';
228
+    $texte = '';
229
+    $table = table_objet_sql($objet);
230
+    $desc = lister_tables_objets_sql($table);
231
+    if (isset($desc['statut_textes_instituer'])) {
232
+        // si une declaration statut_titres
233
+        // mais rien pour le statut demande, ne rien afficher
234
+        if (isset($desc['statut_textes_instituer'][$statut])) {
235
+            $texte = $desc['statut_textes_instituer'][$statut];
236
+        }
237
+    } else {
238
+        switch ($statut) {
239
+            case 'prepa':
240
+                $texte = 'texte_statut_en_cours_redaction';
241
+                break;
242
+            case 'prop':
243
+                $texte = 'texte_statut_propose_evaluation';
244
+                break;
245
+            case 'publie':
246
+                $texte = 'texte_statut_publie';
247
+                break;
248
+            case 'refuse':
249
+                $texte = 'texte_statut_refuse';
250
+                break;
251
+            case 'poubelle':
252
+            case 'poub':
253
+                $texte = 'texte_statut_poubelle';
254
+                break;
255
+        }
256
+    }
257
+
258
+    return $texte ? _T($texte) : '';
259 259
 }
260 260
 
261 261
 
@@ -275,16 +275,16 @@  discard block
 block discarded – undo
275 275
  * @return string
276 276
  */
277 277
 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
278
-	$img = statut_image('auteur', $statut);
279
-	if (!$img) {
280
-		return '';
281
-	}
282
-	$alt = statut_titre('auteur', $statut);
278
+    $img = statut_image('auteur', $statut);
279
+    if (!$img) {
280
+        return '';
281
+    }
282
+    $alt = statut_titre('auteur', $statut);
283 283
 
284
-	$fond = '';
285
-	$titre = '';
284
+    $fond = '';
285
+    $titre = '';
286 286
 
287
-	/*
287
+    /*
288 288
 	if ($type != 'auteur') {
289 289
 	  $img2 = chemin_image('del-16.png');
290 290
 	  $titre = _T('titre_image_redacteur');
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
 	}
295 295
 	*/
296 296
 
297
-	return http_img_pack($img, $alt, $fond, $alt);
297
+    return http_img_pack($img, $alt, $fond, $alt);
298 298
 }
299 299
 
300 300
 
301 301
 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
302
-	return http_img_pack('rubrique-16.png', '');
302
+    return http_img_pack('rubrique-16.png', '');
303 303
 }
304 304
 
305 305
 /**
@@ -323,114 +323,114 @@  discard block
 block discarded – undo
323 323
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
324 324
  **/
325 325
 function puce_statut_changement_rapide(
326
-	$id,
327
-	$statut,
328
-	$id_rubrique,
329
-	$type = 'article',
330
-	$ajax = false,
331
-	$menu_rapide = _ACTIVER_PUCE_RAPIDE
326
+    $id,
327
+    $statut,
328
+    $id_rubrique,
329
+    $type = 'article',
330
+    $ajax = false,
331
+    $menu_rapide = _ACTIVER_PUCE_RAPIDE
332 332
 ) {
333
-	$src = statut_image($type, $statut);
334
-	if (!$src) {
335
-		return $src;
336
-	}
337
-
338
-	if (!$id
339
-		or !_SPIP_AJAX
340
-		or !$menu_rapide
341
-	) {
342
-		$ajax_node = '';
343
-	} else {
344
-		$ajax_node = " class='imgstatut$type$id'";
345
-	}
346
-
347
-
348
-	$t = statut_titre($type, $statut);
349
-	$inser_puce = http_img_pack($src, $t, $ajax_node, $t);
350
-
351
-	if (!$ajax_node) {
352
-		return $inser_puce;
353
-	}
354
-
355
-	$table = table_objet_sql($type);
356
-	$desc = lister_tables_objets_sql($table);
357
-	if (!isset($desc['statut_textes_instituer'])) {
358
-		return $inser_puce;
359
-	}
360
-
361
-	if (!function_exists('autoriser')) {
362
-		include_spip('inc/autoriser');
363
-	}
364
-
365
-	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
366
-	if ($id_rubrique) {
367
-		if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
368
-			return $inser_puce;
369
-		}
370
-	} // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
371
-	else {
372
-		if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) {
373
-			return $inser_puce;
374
-		}
375
-	}
376
-
377
-	$coord = array_flip(array_keys($desc['statut_textes_instituer']));
378
-	if (!isset($coord[$statut])) {
379
-		return $inser_puce;
380
-	}
381
-
382
-	$unit = 8/*widh de img*/ + 4/*padding*/
383
-	;
384
-	$margin = 4; /* marge a gauche + droite */
385
-	$zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/
386
-	;
387
-	$clip = $zero + ($unit * $coord[$statut]);
388
-
389
-	if ($ajax) {
390
-		$width = $unit * count($desc['statut_textes_instituer']) + $margin;
391
-		$out = "<span class='puce_objet_fixe $type'>"
392
-			. $inser_puce
393
-			. "</span>"
394
-			. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
395
-		$i = 0;
396
-		foreach ($desc['statut_textes_instituer'] as $s => $t) {
397
-			$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
398
-		}
399
-		$out .= "</span>";
400
-
401
-		return $out;
402
-	} else {
403
-
404
-		$nom = "puce_statut_";
405
-		$action = generer_url_ecrire('puce_statut', "", true);
406
-		$action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
407
-		$over = " onmouseover=\"$action\"";
408
-
409
-		$lang_dir = lang_dir(lang_typo());
410
-
411
-		return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
412
-		. $inser_puce
413
-		. '</span>';
414
-	}
333
+    $src = statut_image($type, $statut);
334
+    if (!$src) {
335
+        return $src;
336
+    }
337
+
338
+    if (!$id
339
+        or !_SPIP_AJAX
340
+        or !$menu_rapide
341
+    ) {
342
+        $ajax_node = '';
343
+    } else {
344
+        $ajax_node = " class='imgstatut$type$id'";
345
+    }
346
+
347
+
348
+    $t = statut_titre($type, $statut);
349
+    $inser_puce = http_img_pack($src, $t, $ajax_node, $t);
350
+
351
+    if (!$ajax_node) {
352
+        return $inser_puce;
353
+    }
354
+
355
+    $table = table_objet_sql($type);
356
+    $desc = lister_tables_objets_sql($table);
357
+    if (!isset($desc['statut_textes_instituer'])) {
358
+        return $inser_puce;
359
+    }
360
+
361
+    if (!function_exists('autoriser')) {
362
+        include_spip('inc/autoriser');
363
+    }
364
+
365
+    // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
366
+    if ($id_rubrique) {
367
+        if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
368
+            return $inser_puce;
369
+        }
370
+    } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
371
+    else {
372
+        if (!autoriser('instituer', $type, $id, null, array('statut' => 'publie'))) {
373
+            return $inser_puce;
374
+        }
375
+    }
376
+
377
+    $coord = array_flip(array_keys($desc['statut_textes_instituer']));
378
+    if (!isset($coord[$statut])) {
379
+        return $inser_puce;
380
+    }
381
+
382
+    $unit = 8/*widh de img*/ + 4/*padding*/
383
+    ;
384
+    $margin = 4; /* marge a gauche + droite */
385
+    $zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/
386
+    ;
387
+    $clip = $zero + ($unit * $coord[$statut]);
388
+
389
+    if ($ajax) {
390
+        $width = $unit * count($desc['statut_textes_instituer']) + $margin;
391
+        $out = "<span class='puce_objet_fixe $type'>"
392
+            . $inser_puce
393
+            . "</span>"
394
+            . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
395
+        $i = 0;
396
+        foreach ($desc['statut_textes_instituer'] as $s => $t) {
397
+            $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
398
+        }
399
+        $out .= "</span>";
400
+
401
+        return $out;
402
+    } else {
403
+
404
+        $nom = "puce_statut_";
405
+        $action = generer_url_ecrire('puce_statut', "", true);
406
+        $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
407
+        $over = " onmouseover=\"$action\"";
408
+
409
+        $lang_dir = lang_dir(lang_typo());
410
+
411
+        return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
412
+        . $inser_puce
413
+        . '</span>';
414
+    }
415 415
 }
416 416
 
417 417
 
418 418
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
419
-	$h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
420
-	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
421
-	$t = supprimer_tags($titre);
419
+    $h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
420
+    $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
421
+    $t = supprimer_tags($titre);
422 422
 
423
-	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>";
423
+    return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>";
424 424
 }
425 425
 
426 426
 // compat
427 427
 // La couleur du statut
428 428
 
429 429
 function puce_statut($statut, $atts = '') {
430
-	$src = statut_image('article', $statut);
431
-	if (!$src) {
432
-		return '';
433
-	}
430
+    $src = statut_image('article', $statut);
431
+    if (!$src) {
432
+        return '';
433
+    }
434 434
 
435
-	return http_img_pack($src, statut_titre('article', $statut), $atts);
435
+    return http_img_pack($src, statut_titre('article', $statut), $atts);
436 436
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -420,7 +420,7 @@
 block discarded – undo
420 420
 	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
421 421
 	$t = supprimer_tags($titre);
422 422
 
423
-	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . "</a>";
423
+	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t)."</a>";
424 424
 }
425 425
 
426 426
 // compat
Please login to merge, or discard this patch.