Completed
Push — master ( ad50fe...1f1b29 )
by cam
01:13
created
ecrire/inc/texte_mini.php 3 patches
Indentation   +519 added lines, -519 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('inc/filtres');
23 23
 include_spip('inc/lang');
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function definir_puce() {
41 41
 
42
-	// Attention au sens, qui n'est pas defini de la meme facon dans
43
-	// l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
-	// celle du texte) et public (spip_lang est la langue du texte)
45
-	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
42
+    // Attention au sens, qui n'est pas defini de la meme facon dans
43
+    // l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
+    // celle du texte) et public (spip_lang est la langue du texte)
45
+    $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
-	if ($dir == 'rtl') {
49
-		$p .= '_rtl';
50
-	}
47
+    $p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
+    if ($dir == 'rtl') {
49
+        $p .= '_rtl';
50
+    }
51 51
 
52
-	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
-	}
52
+    if (!isset($GLOBALS[$p])) {
53
+        $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
+    }
55 55
 
56
-	return $GLOBALS[$p];
56
+    return $GLOBALS[$p];
57 57
 }
58 58
 
59 59
 /**
@@ -67,30 +67,30 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') {
69 69
 
70
-	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
71
-	$class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline');
72
-	if ($langage) {
73
-		$class .= " language-$langage";
74
-	}
75
-	if ($attributs) {
76
-		$attributs = " " . trim($attributs);
77
-	}
78
-	if ($bloc) {
79
-		$html = "<div class=\"precode\">"
80
-		  . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>"
81
-		  . "<code>"
82
-		  . $echap
83
-		  . '</code>'
84
-		  . '</pre>'
85
-		  . '</div>';
86
-	}
87
-	else {
88
-		$echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89
-		$echap = str_replace("  ", " &nbsp;", $echap);
90
-		$html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
91
-	}
92
-
93
-	return $html;
70
+    $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
71
+    $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline');
72
+    if ($langage) {
73
+        $class .= " language-$langage";
74
+    }
75
+    if ($attributs) {
76
+        $attributs = " " . trim($attributs);
77
+    }
78
+    if ($bloc) {
79
+        $html = "<div class=\"precode\">"
80
+            . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>"
81
+            . "<code>"
82
+            . $echap
83
+            . '</code>'
84
+            . '</pre>'
85
+            . '</div>';
86
+    }
87
+    else {
88
+        $echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89
+        $echap = str_replace("  ", " &nbsp;", $echap);
90
+        $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
91
+    }
92
+
93
+    return $html;
94 94
 }
95 95
 
96 96
 
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 // dont on souhaite qu'ils provoquent un saut de paragraphe
99 99
 
100 100
 if (!defined('_BALISES_BLOCS')) {
101
-	define(
102
-		'_BALISES_BLOCS',
103
-		'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
104
-	);
101
+    define(
102
+        '_BALISES_BLOCS',
103
+        'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
104
+    );
105 105
 }
106 106
 
107 107
 if (!defined('_BALISES_BLOCS_REGEXP')) {
108
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
108
+    define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
109 109
 }
110 110
 
111 111
 //
@@ -116,100 +116,100 @@  discard block
 block discarded – undo
116 116
 // une $source differente ; le script detecte automagiquement si ce qu'on
117 117
 // echappe est un div ou un span
118 118
 function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) {
119
-	if (!strlen($rempl)) {
120
-		return '';
121
-	}
122
-
123
-	// Tester si on echappe en span ou en div
124
-	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
125
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
126
-	}
127
-
128
-	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
129
-	$taille = 30000;
130
-	$return = '';
131
-	for ($i = 0; $i < strlen($rempl); $i += $taille) {
132
-		// Convertir en base64 et cacher dans un attribut
133
-		// utiliser les " pour eviter le re-encodage de ' et &#8217
134
-		$base64 = base64_encode(substr($rempl, $i, $taille));
135
-		$return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
136
-	}
137
-
138
-	return $return;
119
+    if (!strlen($rempl)) {
120
+        return '';
121
+    }
122
+
123
+    // Tester si on echappe en span ou en div
124
+    if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
125
+        $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
126
+    }
127
+
128
+    // Decouper en morceaux, base64 a des probleme selon la taille de la pile
129
+    $taille = 30000;
130
+    $return = '';
131
+    for ($i = 0; $i < strlen($rempl); $i += $taille) {
132
+        // Convertir en base64 et cacher dans un attribut
133
+        // utiliser les " pour eviter le re-encodage de ' et &#8217
134
+        $base64 = base64_encode(substr($rempl, $i, $taille));
135
+        $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
136
+    }
137
+
138
+    return $return;
139 139
 }
140 140
 
141 141
 
142 142
 // Echapper les <html>...</ html>
143 143
 function traiter_echap_html_dist($regs, $options = []) {
144
-	return $regs[3];
144
+    return $regs[3];
145 145
 }
146 146
 
147 147
 // Echapper les <pre>...</ pre>
148 148
 function traiter_echap_pre_dist($regs, $options = []) {
149
-	// echapper les <code> dans <pre>
150
-	$pre = $regs[3];
151
-
152
-	// echapper les < dans <code>
153
-	// on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
154
-	if (
155
-		strpos($pre, '<') !== false
156
-		and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
157
-	) {
158
-		foreach ($matches as $m) {
159
-			if ($m[1] === 'code') {
160
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
161
-				$pre = str_replace($m[0], $code, $pre);
162
-			}
163
-		}
164
-	}
165
-	return "<pre>$pre</pre>";
149
+    // echapper les <code> dans <pre>
150
+    $pre = $regs[3];
151
+
152
+    // echapper les < dans <code>
153
+    // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
154
+    if (
155
+        strpos($pre, '<') !== false
156
+        and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
157
+    ) {
158
+        foreach ($matches as $m) {
159
+            if ($m[1] === 'code') {
160
+                $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
161
+                $pre = str_replace($m[0], $code, $pre);
162
+            }
163
+        }
164
+    }
165
+    return "<pre>$pre</pre>";
166 166
 }
167 167
 
168 168
 // Echapper les <code>...</ code>
169 169
 function traiter_echap_code_dist($regs, $options = []) {
170
-	[, , $att, $corps] = $regs;
170
+    [, , $att, $corps] = $regs;
171 171
 
172
-	// ne pas mettre le <div...> s'il n'y a qu'une ligne
173
-	if (strpos($corps, "\n") !== false) {
174
-		// supprimer les sauts de ligne debut/fin
175
-		// (mais pas les espaces => ascii art).
176
-		$corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps);
172
+    // ne pas mettre le <div...> s'il n'y a qu'une ligne
173
+    if (strpos($corps, "\n") !== false) {
174
+        // supprimer les sauts de ligne debut/fin
175
+        // (mais pas les espaces => ascii art).
176
+        $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps);
177 177
 
178
-		$echap = spip_balisage_code($corps, true, $att);
179
-	} else {
180
-		$echap = spip_balisage_code($corps, false, $att);
181
-	}
178
+        $echap = spip_balisage_code($corps, true, $att);
179
+    } else {
180
+        $echap = spip_balisage_code($corps, false, $att);
181
+    }
182 182
 
183
-	return $echap;
183
+    return $echap;
184 184
 }
185 185
 
186 186
 // Echapper les <cadre>...</ cadre> aka <frame>...</ frame>
187 187
 function traiter_echap_cadre_dist($regs, $options = []) {
188
-	$echap = trim(entites_html($regs[3]));
189
-	// compter les lignes un peu plus finement qu'avec les \n
190
-	$lignes = explode("\n", trim($echap));
191
-	$n = 0;
192
-	foreach ($lignes as $l) {
193
-		$n += floor(strlen($l) / 60) + 1;
194
-	}
195
-	$n = max($n, 2);
196
-	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>";
197
-
198
-	return $echap;
188
+    $echap = trim(entites_html($regs[3]));
189
+    // compter les lignes un peu plus finement qu'avec les \n
190
+    $lignes = explode("\n", trim($echap));
191
+    $n = 0;
192
+    foreach ($lignes as $l) {
193
+        $n += floor(strlen($l) / 60) + 1;
194
+    }
195
+    $n = max($n, 2);
196
+    $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>";
197
+
198
+    return $echap;
199 199
 }
200 200
 
201 201
 function traiter_echap_frame_dist($regs, $options = []) {
202
-	return traiter_echap_cadre_dist($regs);
202
+    return traiter_echap_cadre_dist($regs);
203 203
 }
204 204
 
205 205
 function traiter_echap_script_dist($regs, $options = []) {
206
-	// rendre joli (et inactif) si c'est un script language=php
207
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
208
-		return highlight_string($regs[0], true);
209
-	}
206
+    // rendre joli (et inactif) si c'est un script language=php
207
+    if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
208
+        return highlight_string($regs[0], true);
209
+    }
210 210
 
211
-	// Cas normal : le script passe tel quel
212
-	return $regs[0];
211
+    // Cas normal : le script passe tel quel
212
+    return $regs[0];
213 213
 }
214 214
 
215 215
 define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS');
@@ -228,73 +228,73 @@  discard block
 block discarded – undo
228 228
  * @return string|string[]
229 229
  */
230 230
 function echappe_html(
231
-	$letexte,
232
-	$source = '',
233
-	$no_transform = false,
234
-	$preg = '',
235
-	$callback_prefix = '',
236
-	$callback_options = []
231
+    $letexte,
232
+    $source = '',
233
+    $no_transform = false,
234
+    $preg = '',
235
+    $callback_prefix = '',
236
+    $callback_options = []
237 237
 ) {
238
-	if (!is_string($letexte) or !strlen($letexte)) {
239
-		return $letexte;
240
-	}
241
-
242
-	if (
243
-		($preg or strpos($letexte, '<') !== false)
244
-		and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
245
-	) {
246
-		foreach ($matches as $regs) {
247
-			// echappements tels quels ?
248
-			if ($no_transform) {
249
-				$echap = $regs[0];
250
-			} // sinon les traiter selon le cas
251
-			else {
252
-				$callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
253
-				if (
254
-					function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
255
-					or function_exists($f = $f . '_dist')
256
-					or ($callback_secure_prefix and (
257
-						function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
258
-						or function_exists($f = $f . '_dist')
259
-					))
260
-				) {
261
-					$echap = $f($regs, $callback_options);
262
-				}
263
-			}
264
-
265
-			$p = strpos($letexte, (string) $regs[0]);
266
-			$letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
267
-		}
268
-	}
269
-
270
-	if ($no_transform) {
271
-		return $letexte;
272
-	}
273
-
274
-	// Echapper le php pour faire joli (ici, c'est pas pour la securite)
275
-	// seulement si on a echappe les <script>
276
-	// (derogatoire car on ne peut pas faire passer < ? ... ? >
277
-	// dans une callback autonommee
278
-	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
279
-		if (
280
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
281
-				',<[?].*($|[?]>),UisS',
282
-				$letexte,
283
-				$matches,
284
-				PREG_SET_ORDER
285
-			)
286
-		) {
287
-			foreach ($matches as $regs) {
288
-				$letexte = str_replace(
289
-					$regs[0],
290
-					code_echappement(highlight_string($regs[0], true), $source),
291
-					$letexte
292
-				);
293
-			}
294
-		}
295
-	}
296
-
297
-	return $letexte;
238
+    if (!is_string($letexte) or !strlen($letexte)) {
239
+        return $letexte;
240
+    }
241
+
242
+    if (
243
+        ($preg or strpos($letexte, '<') !== false)
244
+        and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
245
+    ) {
246
+        foreach ($matches as $regs) {
247
+            // echappements tels quels ?
248
+            if ($no_transform) {
249
+                $echap = $regs[0];
250
+            } // sinon les traiter selon le cas
251
+            else {
252
+                $callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
253
+                if (
254
+                    function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
255
+                    or function_exists($f = $f . '_dist')
256
+                    or ($callback_secure_prefix and (
257
+                        function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
258
+                        or function_exists($f = $f . '_dist')
259
+                    ))
260
+                ) {
261
+                    $echap = $f($regs, $callback_options);
262
+                }
263
+            }
264
+
265
+            $p = strpos($letexte, (string) $regs[0]);
266
+            $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
267
+        }
268
+    }
269
+
270
+    if ($no_transform) {
271
+        return $letexte;
272
+    }
273
+
274
+    // Echapper le php pour faire joli (ici, c'est pas pour la securite)
275
+    // seulement si on a echappe les <script>
276
+    // (derogatoire car on ne peut pas faire passer < ? ... ? >
277
+    // dans une callback autonommee
278
+    if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
279
+        if (
280
+            strpos($letexte, '<' . '?') !== false and preg_match_all(
281
+                ',<[?].*($|[?]>),UisS',
282
+                $letexte,
283
+                $matches,
284
+                PREG_SET_ORDER
285
+            )
286
+        ) {
287
+            foreach ($matches as $regs) {
288
+                $letexte = str_replace(
289
+                    $regs[0],
290
+                    code_echappement(highlight_string($regs[0], true), $source),
291
+                    $letexte
292
+                );
293
+            }
294
+        }
295
+    }
296
+
297
+    return $letexte;
298 298
 }
299 299
 
300 300
 //
@@ -302,57 +302,57 @@  discard block
 block discarded – undo
302 302
 // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
303 303
 // par propre() : exemple dans multi et dans typo()
304 304
 function echappe_retour($letexte, $source = '', $filtre = '') {
305
-	if (strpos($letexte, (string) "base64$source")) {
306
-		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
307
-		$max_prof = 5;
308
-		while (
309
-			strpos($letexte, '<') !== false
310
-			and
311
-			preg_match_all(
312
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
313
-				$letexte,
314
-				$regs,
315
-				PREG_SET_ORDER
316
-			)
317
-			and $max_prof--
318
-		) {
319
-			foreach ($regs as $reg) {
320
-				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
321
-				// recherche d'attributs supplementaires
322
-				$at = [];
323
-				foreach (['lang', 'dir'] as $attr) {
324
-					if ($a = extraire_attribut($reg[0], $attr)) {
325
-						$at[$attr] = $a;
326
-					}
327
-				}
328
-				if ($at) {
329
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
330
-					foreach ($at as $attr => $a) {
331
-						$rempl = inserer_attribut($rempl, $attr, $a);
332
-					}
333
-				}
334
-				if ($filtre) {
335
-					$rempl = $filtre($rempl);
336
-				}
337
-				$letexte = str_replace($reg[0], $rempl, $letexte);
338
-			}
339
-		}
340
-	}
341
-
342
-	return $letexte;
305
+    if (strpos($letexte, (string) "base64$source")) {
306
+        # spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
307
+        $max_prof = 5;
308
+        while (
309
+            strpos($letexte, '<') !== false
310
+            and
311
+            preg_match_all(
312
+                ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
313
+                $letexte,
314
+                $regs,
315
+                PREG_SET_ORDER
316
+            )
317
+            and $max_prof--
318
+        ) {
319
+            foreach ($regs as $reg) {
320
+                $rempl = base64_decode(extraire_attribut($reg[0], 'title'));
321
+                // recherche d'attributs supplementaires
322
+                $at = [];
323
+                foreach (['lang', 'dir'] as $attr) {
324
+                    if ($a = extraire_attribut($reg[0], $attr)) {
325
+                        $at[$attr] = $a;
326
+                    }
327
+                }
328
+                if ($at) {
329
+                    $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
330
+                    foreach ($at as $attr => $a) {
331
+                        $rempl = inserer_attribut($rempl, $attr, $a);
332
+                    }
333
+                }
334
+                if ($filtre) {
335
+                    $rempl = $filtre($rempl);
336
+                }
337
+                $letexte = str_replace($reg[0], $rempl, $letexte);
338
+            }
339
+        }
340
+    }
341
+
342
+    return $letexte;
343 343
 }
344 344
 
345 345
 // Reinserer le javascript de confiance (venant des modeles)
346 346
 
347 347
 function echappe_retour_modeles($letexte, $interdire_scripts = false) {
348
-	$letexte = echappe_retour($letexte);
348
+    $letexte = echappe_retour($letexte);
349 349
 
350
-	// Dans les appels directs hors squelette, securiser aussi ici
351
-	if ($interdire_scripts) {
352
-		$letexte = interdire_scripts($letexte);
353
-	}
350
+    // Dans les appels directs hors squelette, securiser aussi ici
351
+    if ($interdire_scripts) {
352
+        $letexte = interdire_scripts($letexte);
353
+    }
354 354
 
355
-	return trim($letexte);
355
+    return trim($letexte);
356 356
 }
357 357
 
358 358
 
@@ -380,131 +380,131 @@  discard block
 block discarded – undo
380 380
  *     Texte coupé
381 381
  **/
382 382
 function couper($texte, $taille = 50, $suite = null) {
383
-	if (!($length = strlen($texte)) or $taille <= 0) {
384
-		return '';
385
-	}
386
-	$offset = 400 + 2 * $taille;
387
-	while (
388
-		$offset < $length
389
-		and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
390
-	) {
391
-		$offset = 2 * $offset;
392
-	}
393
-	if (
394
-		$offset < $length
395
-		&& ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
396
-	) {
397
-		$p_tag_fermant = strpos($texte, '>', $offset);
398
-		if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
399
-			$offset = $p_tag_fermant + 1;
400
-		} // prolonger la coupe jusqu'au tag fermant suivant eventuel
401
-	}
402
-	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
403
-
404
-	if (!function_exists('nettoyer_raccourcis_typo')) {
405
-		include_spip('inc/lien');
406
-	}
407
-	$texte = nettoyer_raccourcis_typo($texte);
408
-
409
-	// balises de sauts de ligne et paragraphe
410
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
411
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
412
-
413
-	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
414
-	$texte = str_replace("\n\n", "\r", $texte);
415
-
416
-	// supprimer les tags
417
-	$texte = supprimer_tags($texte);
418
-	$texte = trim(str_replace("\n", ' ', $texte));
419
-	$texte .= "\n";  // marquer la fin
420
-
421
-	// corriger la longueur de coupe
422
-	// en fonction de la presence de caracteres utf
423
-	if ($GLOBALS['meta']['charset'] == 'utf-8') {
424
-		$long = charset2unicode($texte);
425
-		$long = spip_substr($long, 0, max($taille, 1));
426
-		$nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
427
-		$taille += $nbcharutf;
428
-	}
429
-
430
-
431
-	// couper au mot precedent
432
-	$long = spip_substr($texte, 0, max($taille - 4, 1));
433
-	$u = $GLOBALS['meta']['pcre_u'];
434
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
435
-	if (is_null($suite)) {
436
-		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
437
-	}
438
-	$points = $suite;
439
-
440
-	// trop court ? ne pas faire de (...)
441
-	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
442
-		$points = '';
443
-		$long = spip_substr($texte, 0, $taille);
444
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
445
-		// encore trop court ? couper au caractere
446
-		if (spip_strlen($texte) < 0.75 * $taille) {
447
-			$texte = $long;
448
-		}
449
-	} else {
450
-		$texte = $court;
451
-	}
452
-
453
-	if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
454
-	$points = '';
455
-	}
456
-
457
-	// remettre les paragraphes
458
-	$texte = preg_replace("/\r+/", "\n\n", $texte);
459
-
460
-	// supprimer l'eventuelle entite finale mal coupee
461
-	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
462
-
463
-	return quote_amp(trim($texte)) . $points;
383
+    if (!($length = strlen($texte)) or $taille <= 0) {
384
+        return '';
385
+    }
386
+    $offset = 400 + 2 * $taille;
387
+    while (
388
+        $offset < $length
389
+        and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
390
+    ) {
391
+        $offset = 2 * $offset;
392
+    }
393
+    if (
394
+        $offset < $length
395
+        && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
396
+    ) {
397
+        $p_tag_fermant = strpos($texte, '>', $offset);
398
+        if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
399
+            $offset = $p_tag_fermant + 1;
400
+        } // prolonger la coupe jusqu'au tag fermant suivant eventuel
401
+    }
402
+    $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
403
+
404
+    if (!function_exists('nettoyer_raccourcis_typo')) {
405
+        include_spip('inc/lien');
406
+    }
407
+    $texte = nettoyer_raccourcis_typo($texte);
408
+
409
+    // balises de sauts de ligne et paragraphe
410
+    $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
411
+    $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
412
+
413
+    // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
414
+    $texte = str_replace("\n\n", "\r", $texte);
415
+
416
+    // supprimer les tags
417
+    $texte = supprimer_tags($texte);
418
+    $texte = trim(str_replace("\n", ' ', $texte));
419
+    $texte .= "\n";  // marquer la fin
420
+
421
+    // corriger la longueur de coupe
422
+    // en fonction de la presence de caracteres utf
423
+    if ($GLOBALS['meta']['charset'] == 'utf-8') {
424
+        $long = charset2unicode($texte);
425
+        $long = spip_substr($long, 0, max($taille, 1));
426
+        $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
427
+        $taille += $nbcharutf;
428
+    }
429
+
430
+
431
+    // couper au mot precedent
432
+    $long = spip_substr($texte, 0, max($taille - 4, 1));
433
+    $u = $GLOBALS['meta']['pcre_u'];
434
+    $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
435
+    if (is_null($suite)) {
436
+        $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
437
+    }
438
+    $points = $suite;
439
+
440
+    // trop court ? ne pas faire de (...)
441
+    if (spip_strlen($court) < max(0.75 * $taille, 2)) {
442
+        $points = '';
443
+        $long = spip_substr($texte, 0, $taille);
444
+        $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
445
+        // encore trop court ? couper au caractere
446
+        if (spip_strlen($texte) < 0.75 * $taille) {
447
+            $texte = $long;
448
+        }
449
+    } else {
450
+        $texte = $court;
451
+    }
452
+
453
+    if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
454
+    $points = '';
455
+    }
456
+
457
+    // remettre les paragraphes
458
+    $texte = preg_replace("/\r+/", "\n\n", $texte);
459
+
460
+    // supprimer l'eventuelle entite finale mal coupee
461
+    $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
462
+
463
+    return quote_amp(trim($texte)) . $points;
464 464
 }
465 465
 
466 466
 
467 467
 function protege_js_modeles($t) {
468
-	if (isset($GLOBALS['visiteur_session'])) {
469
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
470
-			if (!defined('_PROTEGE_JS_MODELES')) {
471
-				include_spip('inc/acces');
472
-				define('_PROTEGE_JS_MODELES', creer_uniqid());
473
-			}
474
-			foreach ($r as $regs) {
475
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
476
-			}
477
-		}
478
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
479
-			if (!defined('_PROTEGE_PHP_MODELES')) {
480
-				include_spip('inc/acces');
481
-				define('_PROTEGE_PHP_MODELES', creer_uniqid());
482
-			}
483
-			foreach ($r as $regs) {
484
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
485
-			}
486
-		}
487
-	}
488
-
489
-	return $t;
468
+    if (isset($GLOBALS['visiteur_session'])) {
469
+        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
470
+            if (!defined('_PROTEGE_JS_MODELES')) {
471
+                include_spip('inc/acces');
472
+                define('_PROTEGE_JS_MODELES', creer_uniqid());
473
+            }
474
+            foreach ($r as $regs) {
475
+                $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
476
+            }
477
+        }
478
+        if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
479
+            if (!defined('_PROTEGE_PHP_MODELES')) {
480
+                include_spip('inc/acces');
481
+                define('_PROTEGE_PHP_MODELES', creer_uniqid());
482
+            }
483
+            foreach ($r as $regs) {
484
+                $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
485
+            }
486
+        }
487
+    }
488
+
489
+    return $t;
490 490
 }
491 491
 
492 492
 
493 493
 function echapper_faux_tags($letexte) {
494
-	if (strpos($letexte, '<') === false) {
495
-		return $letexte;
496
-	}
497
-	$textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
498
-
499
-	$letexte = '';
500
-	while (is_countable($textMatches) ? count($textMatches) : 0) {
501
-		// un texte a echapper
502
-		$letexte .= str_replace('<', '&lt;', array_shift($textMatches));
503
-		// un tag html qui a servit a faite le split
504
-		$letexte .= array_shift($textMatches);
505
-	}
506
-
507
-	return $letexte;
494
+    if (strpos($letexte, '<') === false) {
495
+        return $letexte;
496
+    }
497
+    $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
498
+
499
+    $letexte = '';
500
+    while (is_countable($textMatches) ? count($textMatches) : 0) {
501
+        // un texte a echapper
502
+        $letexte .= str_replace('<', '&lt;', array_shift($textMatches));
503
+        // un tag html qui a servit a faite le split
504
+        $letexte .= array_shift($textMatches);
505
+    }
506
+
507
+    return $letexte;
508 508
 }
509 509
 
510 510
 /**
@@ -524,115 +524,115 @@  discard block
 block discarded – undo
524 524
  * @return string
525 525
  */
526 526
 function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) {
527
-	static $echapper_html_suspect;
528
-	if (!$texte or !is_string($texte)) {
529
-		return $texte;
530
-	}
531
-
532
-	if (!isset($echapper_html_suspect)) {
533
-		$echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
534
-	}
535
-	// si fonction personalisee, on delegue
536
-	if ($echapper_html_suspect) {
537
-		// on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
538
-		$args = [$texte, $options];
539
-		if ($connect or !empty($env)) {
540
-			$args[] = $connect;
541
-		}
542
-		if (!empty($env)) {
543
-			$args[] = $env;
544
-		}
545
-		return $echapper_html_suspect(...$args);
546
-	}
547
-
548
-	if (is_bool($options)) {
549
-		$options = ['strict' => $options];
550
-	}
551
-	$strict = $options['strict'] ?? true;
552
-
553
-	// pas de balise html ou pas d'attribut sur les balises ? c'est OK
554
-	if (
555
-		strpos($texte, '<') === false
556
-		or strpos($texte, '=') === false
557
-	) {
558
-		return $texte;
559
-	}
560
-
561
-	// dans le prive, on veut afficher tout echappé pour la moderation
562
-	if (!isset($env['espace_prive'])) {
563
-		// conserver le comportement historique en cas d'appel court sans env
564
-		$env['espace_prive'] = test_espace_prive();
565
-	}
566
-	if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
567
-
568
-		// quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
569
-		// car sinon on declenche sur les modeles ou ressources
570
-		if (
571
-			!$strict and
572
-			(strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
573
-		) {
574
-			return $texte;
575
-		}
576
-
577
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
578
-		include_spip("src/Texte/Collecteur/Modeles");
579
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
580
-		$texte = $collecteurModeles->echapper($texte);
581
-		$texte = echappe_js($texte);
582
-
583
-		$texte_to_check = $texte;
584
-		// si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
585
-		// car un raccourci peut etre utilisé pour faire un lien malin
586
-		// et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
587
-		if (!empty($options['expanser_liens'])) {
588
-			$texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
589
-		}
590
-		if (!is_html_safe($texte_to_check)) {
591
-			$texte = $options['texte_source_affiche'] ?? $texte;
592
-			$texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
593
-			$texte = str_replace('<', '&lt;', $texte);
594
-			$texte = str_replace('&lt;tt>', '<tt>', $texte);
595
-			$texte = str_replace('&lt;/tt>', '</tt>', $texte);
596
-			if (!function_exists('attribut_html')) {
597
-				include_spip('inc/filtres');
598
-			}
599
-			if (!empty($options['wrap_suspect'])) {
600
-				$texte = wrap($texte, $options['wrap_suspect']);
601
-			}
602
-			$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
603
-		}
604
-
605
-		$texte = $collecteurModeles->retablir($texte);
606
-	}
607
-
608
-	// si on est là dans le public c'est le mode parano
609
-	// on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
610
-	else {
611
-		$collecteurLiens = $collecteurModeles = null;
612
-		if (!empty($options['expanser_liens'])) {
613
-			$texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
614
-		}
615
-		else {
616
-			include_spip("src/Texte/Collecteur/AbstractCollecteur");
617
-			include_spip("src/Texte/Collecteur/Liens");
618
-			include_spip("src/Texte/Collecteur/Modeles");
619
-
620
-			$collecteurLiens = new Spip\Texte\Collecteur\Liens();
621
-			$texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']);
622
-
623
-			$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
624
-			$texte = $collecteurModeles->echapper($texte);
625
-		}
626
-		$texte = safehtml($texte);
627
-		if ($collecteurModeles) {
628
-			$texte = $collecteurModeles->retablir($texte);
629
-		}
630
-		if ($collecteurLiens) {
631
-			$texte = $collecteurLiens->retablir($texte);
632
-		}
633
-	}
634
-
635
-	return $texte;
527
+    static $echapper_html_suspect;
528
+    if (!$texte or !is_string($texte)) {
529
+        return $texte;
530
+    }
531
+
532
+    if (!isset($echapper_html_suspect)) {
533
+        $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
534
+    }
535
+    // si fonction personalisee, on delegue
536
+    if ($echapper_html_suspect) {
537
+        // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
538
+        $args = [$texte, $options];
539
+        if ($connect or !empty($env)) {
540
+            $args[] = $connect;
541
+        }
542
+        if (!empty($env)) {
543
+            $args[] = $env;
544
+        }
545
+        return $echapper_html_suspect(...$args);
546
+    }
547
+
548
+    if (is_bool($options)) {
549
+        $options = ['strict' => $options];
550
+    }
551
+    $strict = $options['strict'] ?? true;
552
+
553
+    // pas de balise html ou pas d'attribut sur les balises ? c'est OK
554
+    if (
555
+        strpos($texte, '<') === false
556
+        or strpos($texte, '=') === false
557
+    ) {
558
+        return $texte;
559
+    }
560
+
561
+    // dans le prive, on veut afficher tout echappé pour la moderation
562
+    if (!isset($env['espace_prive'])) {
563
+        // conserver le comportement historique en cas d'appel court sans env
564
+        $env['espace_prive'] = test_espace_prive();
565
+    }
566
+    if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
567
+
568
+        // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
569
+        // car sinon on declenche sur les modeles ou ressources
570
+        if (
571
+            !$strict and
572
+            (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
573
+        ) {
574
+            return $texte;
575
+        }
576
+
577
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
578
+        include_spip("src/Texte/Collecteur/Modeles");
579
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
580
+        $texte = $collecteurModeles->echapper($texte);
581
+        $texte = echappe_js($texte);
582
+
583
+        $texte_to_check = $texte;
584
+        // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
585
+        // car un raccourci peut etre utilisé pour faire un lien malin
586
+        // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
587
+        if (!empty($options['expanser_liens'])) {
588
+            $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
589
+        }
590
+        if (!is_html_safe($texte_to_check)) {
591
+            $texte = $options['texte_source_affiche'] ?? $texte;
592
+            $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
593
+            $texte = str_replace('<', '&lt;', $texte);
594
+            $texte = str_replace('&lt;tt>', '<tt>', $texte);
595
+            $texte = str_replace('&lt;/tt>', '</tt>', $texte);
596
+            if (!function_exists('attribut_html')) {
597
+                include_spip('inc/filtres');
598
+            }
599
+            if (!empty($options['wrap_suspect'])) {
600
+                $texte = wrap($texte, $options['wrap_suspect']);
601
+            }
602
+            $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
603
+        }
604
+
605
+        $texte = $collecteurModeles->retablir($texte);
606
+    }
607
+
608
+    // si on est là dans le public c'est le mode parano
609
+    // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
610
+    else {
611
+        $collecteurLiens = $collecteurModeles = null;
612
+        if (!empty($options['expanser_liens'])) {
613
+            $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
614
+        }
615
+        else {
616
+            include_spip("src/Texte/Collecteur/AbstractCollecteur");
617
+            include_spip("src/Texte/Collecteur/Liens");
618
+            include_spip("src/Texte/Collecteur/Modeles");
619
+
620
+            $collecteurLiens = new Spip\Texte\Collecteur\Liens();
621
+            $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']);
622
+
623
+            $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
624
+            $texte = $collecteurModeles->echapper($texte);
625
+        }
626
+        $texte = safehtml($texte);
627
+        if ($collecteurModeles) {
628
+            $texte = $collecteurModeles->retablir($texte);
629
+        }
630
+        if ($collecteurLiens) {
631
+            $texte = $collecteurLiens->retablir($texte);
632
+        }
633
+    }
634
+
635
+    return $texte;
636 636
 }
637 637
 
638 638
 
@@ -653,52 +653,52 @@  discard block
 block discarded – undo
653 653
  *      Texte sécurisé
654 654
  **/
655 655
 function safehtml($t) {
656
-	static $safehtml;
657
-
658
-	if (!$t or !is_string($t)) {
659
-		return $t;
660
-	}
661
-	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
662
-	if (strpos($t, '<') === false) {
663
-		return str_replace("\x00", '', $t);
664
-	}
665
-
666
-	$collecteurIdiomes = null;
667
-	if (stripos($t, '<:') !== false) {
668
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
669
-		include_spip("src/Texte/Collecteur/Idiomes");
670
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
671
-		$t = $collecteurIdiomes->echapper($t);
672
-	}
673
-	$collecteurMultis = null;
674
-	if (stripos($t, '<multi') !== false) {
675
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
676
-		include_spip("src/Texte/Collecteur/Multis");
677
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
678
-		$t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']);
679
-	}
680
-
681
-	if (!function_exists('interdire_scripts')) {
682
-		include_spip('inc/texte');
683
-	}
684
-	$t = interdire_scripts($t); // jolifier le php
685
-	$t = echappe_js($t);
686
-
687
-	if (!isset($safehtml)) {
688
-		$safehtml = charger_fonction('safehtml', 'inc', true);
689
-	}
690
-	if ($safehtml) {
691
-		$t = $safehtml($t);
692
-	}
693
-
694
-	if ($collecteurMultis) {
695
-		$t = $collecteurMultis->retablir($t);
696
-	}
697
-	if ($collecteurIdiomes) {
698
-		$t = $collecteurIdiomes->retablir($t);
699
-	}
700
-
701
-	return interdire_scripts($t); // interdire le php (2 precautions)
656
+    static $safehtml;
657
+
658
+    if (!$t or !is_string($t)) {
659
+        return $t;
660
+    }
661
+    # attention safehtml nettoie deux ou trois caracteres de plus. A voir
662
+    if (strpos($t, '<') === false) {
663
+        return str_replace("\x00", '', $t);
664
+    }
665
+
666
+    $collecteurIdiomes = null;
667
+    if (stripos($t, '<:') !== false) {
668
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
669
+        include_spip("src/Texte/Collecteur/Idiomes");
670
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
671
+        $t = $collecteurIdiomes->echapper($t);
672
+    }
673
+    $collecteurMultis = null;
674
+    if (stripos($t, '<multi') !== false) {
675
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
676
+        include_spip("src/Texte/Collecteur/Multis");
677
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
678
+        $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']);
679
+    }
680
+
681
+    if (!function_exists('interdire_scripts')) {
682
+        include_spip('inc/texte');
683
+    }
684
+    $t = interdire_scripts($t); // jolifier le php
685
+    $t = echappe_js($t);
686
+
687
+    if (!isset($safehtml)) {
688
+        $safehtml = charger_fonction('safehtml', 'inc', true);
689
+    }
690
+    if ($safehtml) {
691
+        $t = $safehtml($t);
692
+    }
693
+
694
+    if ($collecteurMultis) {
695
+        $t = $collecteurMultis->retablir($t);
696
+    }
697
+    if ($collecteurIdiomes) {
698
+        $t = $collecteurIdiomes->retablir($t);
699
+    }
700
+
701
+    return interdire_scripts($t); // interdire le php (2 precautions)
702 702
 }
703 703
 
704 704
 
@@ -706,25 +706,25 @@  discard block
 block discarded – undo
706 706
  * Detecter si un texte est "safe" ie non modifie significativement par safehtml()
707 707
  */
708 708
 function is_html_safe(string $texte): bool {
709
-	if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
710
-		return $is_html_safe($texte);
711
-	}
712
-
713
-	// simplifier les retour ligne pour etre certain de ce que l'on compare
714
-	$texte = str_replace("\r\n", "\n", $texte);
715
-	// safehtml reduit aussi potentiellement les &nbsp;
716
-	$texte = str_replace("&nbsp;", " ", $texte);
717
-	// safehtml remplace les entités numériques
718
-	if (strpos($texte, '&#') !== false) {
719
-		$texte = unicode2charset($texte);
720
-	}
721
-
722
-	$texte_safe = safehtml($texte);
723
-
724
-	// on teste sur strlen car safehtml supprime le contenu dangereux
725
-	// mais il peut aussi changer des ' en " sur les attributs html,
726
-	// donc un test d'egalite est trop strict
727
-	return strlen($texte_safe) === strlen($texte);
709
+    if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
710
+        return $is_html_safe($texte);
711
+    }
712
+
713
+    // simplifier les retour ligne pour etre certain de ce que l'on compare
714
+    $texte = str_replace("\r\n", "\n", $texte);
715
+    // safehtml reduit aussi potentiellement les &nbsp;
716
+    $texte = str_replace("&nbsp;", " ", $texte);
717
+    // safehtml remplace les entités numériques
718
+    if (strpos($texte, '&#') !== false) {
719
+        $texte = unicode2charset($texte);
720
+    }
721
+
722
+    $texte_safe = safehtml($texte);
723
+
724
+    // on teste sur strlen car safehtml supprime le contenu dangereux
725
+    // mais il peut aussi changer des ' en " sur les attributs html,
726
+    // donc un test d'egalite est trop strict
727
+    return strlen($texte_safe) === strlen($texte);
728 728
 }
729 729
 
730 730
 /**
@@ -745,13 +745,13 @@  discard block
 block discarded – undo
745 745
  *     Texte sans les modèles d'image
746 746
  **/
747 747
 function supprime_img($letexte, $message = null) {
748
-	if ($message === null) {
749
-		$message = '(' . _T('img_indisponible') . ')';
750
-	}
751
-
752
-	return preg_replace(
753
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
754
-		$message,
755
-		$letexte
756
-	);
748
+    if ($message === null) {
749
+        $message = '(' . _T('img_indisponible') . ')';
750
+    }
751
+
752
+    return preg_replace(
753
+        ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
754
+        $message,
755
+        $letexte
756
+    );
757 757
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	// celle du texte) et public (spip_lang est la langue du texte)
45 45
 	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
47
+	$p = 'puce'.(test_espace_prive() ? '_prive' : '');
48 48
 	if ($dir == 'rtl') {
49 49
 		$p .= '_rtl';
50 50
 	}
51 51
 
52 52
 	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
53
+		$GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>';
54 54
 	}
55 55
 
56 56
 	return $GLOBALS[$p];
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') {
69 69
 
70 70
 	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
71
-	$class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline');
71
+	$class = "spip_code ".($bloc ? 'spip_code_block' : 'spip_code_inline');
72 72
 	if ($langage) {
73 73
 		$class .= " language-$langage";
74 74
 	}
75 75
 	if ($attributs) {
76
-		$attributs = " " . trim($attributs);
76
+		$attributs = " ".trim($attributs);
77 77
 	}
78 78
 	if ($bloc) {
79 79
 		$html = "<div class=\"precode\">"
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	else {
88 88
 		$echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89 89
 		$echap = str_replace("  ", " &nbsp;", $echap);
90
-		$html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
90
+		$html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>';
91 91
 	}
92 92
 
93 93
 	return $html;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 }
106 106
 
107 107
 if (!defined('_BALISES_BLOCS_REGEXP')) {
108
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
108
+	define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS');
109 109
 }
110 110
 
111 111
 //
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 
123 123
 	// Tester si on echappe en span ou en div
124 124
 	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
125
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
125
+		$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
126 126
 	}
127 127
 
128 128
 	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	) {
158 158
 		foreach ($matches as $m) {
159 159
 			if ($m[1] === 'code') {
160
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
160
+				$code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>';
161 161
 				$pre = str_replace($m[0], $code, $pre);
162 162
 			}
163 163
 		}
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 // Echapper les <code>...</ code>
169 169
 function traiter_echap_code_dist($regs, $options = []) {
170
-	[, , $att, $corps] = $regs;
170
+	[,, $att, $corps] = $regs;
171 171
 
172 172
 	// ne pas mettre le <div...> s'il n'y a qu'une ligne
173 173
 	if (strpos($corps, "\n") !== false) {
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
 			else {
252 252
 				$callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
253 253
 				if (
254
-					function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
255
-					or function_exists($f = $f . '_dist')
254
+					function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1]))
255
+					or function_exists($f = $f.'_dist')
256 256
 					or ($callback_secure_prefix and (
257
-						function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
258
-						or function_exists($f = $f . '_dist')
257
+						function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1]))
258
+						or function_exists($f = $f.'_dist')
259 259
 					))
260 260
 				) {
261 261
 					$echap = $f($regs, $callback_options);
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	// dans une callback autonommee
278 278
 	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
279 279
 		if (
280
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
280
+			strpos($letexte, '<'.'?') !== false and preg_match_all(
281 281
 				',<[?].*($|[?]>),UisS',
282 282
 				$letexte,
283 283
 				$matches,
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 			strpos($letexte, '<') !== false
310 310
 			and
311 311
 			preg_match_all(
312
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
312
+				',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
313 313
 				$letexte,
314 314
 				$regs,
315 315
 				PREG_SET_ORDER
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 					}
327 327
 				}
328 328
 				if ($at) {
329
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
329
+					$rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
330 330
 					foreach ($at as $attr => $a) {
331 331
 						$rempl = inserer_attribut($rempl, $attr, $a);
332 332
 					}
@@ -407,8 +407,8 @@  discard block
 block discarded – undo
407 407
 	$texte = nettoyer_raccourcis_typo($texte);
408 408
 
409 409
 	// balises de sauts de ligne et paragraphe
410
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
411
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
410
+	$texte = preg_replace('/<p( [^>]*)?'.'>/', "\r", $texte);
411
+	$texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte);
412 412
 
413 413
 	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
414 414
 	$texte = str_replace("\n\n", "\r", $texte);
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	// supprimer les tags
417 417
 	$texte = supprimer_tags($texte);
418 418
 	$texte = trim(str_replace("\n", ' ', $texte));
419
-	$texte .= "\n";  // marquer la fin
419
+	$texte .= "\n"; // marquer la fin
420 420
 
421 421
 	// corriger la longueur de coupe
422 422
 	// en fonction de la presence de caracteres utf
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	// couper au mot precedent
432 432
 	$long = spip_substr($texte, 0, max($taille - 4, 1));
433 433
 	$u = $GLOBALS['meta']['pcre_u'];
434
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
434
+	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
435 435
 	if (is_null($suite)) {
436 436
 		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
437 437
 	}
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
 	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
442 442
 		$points = '';
443 443
 		$long = spip_substr($texte, 0, $taille);
444
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
444
+		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
445 445
 		// encore trop court ? couper au caractere
446 446
 		if (spip_strlen($texte) < 0.75 * $taille) {
447 447
 			$texte = $long;
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 	// supprimer l'eventuelle entite finale mal coupee
461 461
 	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
462 462
 
463
-	return quote_amp(trim($texte)) . $points;
463
+	return quote_amp(trim($texte)).$points;
464 464
 }
465 465
 
466 466
 
@@ -472,16 +472,16 @@  discard block
 block discarded – undo
472 472
 				define('_PROTEGE_JS_MODELES', creer_uniqid());
473 473
 			}
474 474
 			foreach ($r as $regs) {
475
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
475
+				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t);
476 476
 			}
477 477
 		}
478
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
478
+		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) {
479 479
 			if (!defined('_PROTEGE_PHP_MODELES')) {
480 480
 				include_spip('inc/acces');
481 481
 				define('_PROTEGE_PHP_MODELES', creer_uniqid());
482 482
 			}
483 483
 			foreach ($r as $regs) {
484
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
484
+				$t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t);
485 485
 			}
486 486
 		}
487 487
 	}
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 			if (!empty($options['wrap_suspect'])) {
600 600
 				$texte = wrap($texte, $options['wrap_suspect']);
601 601
 			}
602
-			$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
602
+			$texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte;
603 603
 		}
604 604
 
605 605
 		$texte = $collecteurModeles->retablir($texte);
@@ -746,11 +746,11 @@  discard block
 block discarded – undo
746 746
  **/
747 747
 function supprime_img($letexte, $message = null) {
748 748
 	if ($message === null) {
749
-		$message = '(' . _T('img_indisponible') . ')';
749
+		$message = '('._T('img_indisponible').')';
750 750
 	}
751 751
 
752 752
 	return preg_replace(
753
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
753
+		',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
754 754
 		$message,
755 755
 		$letexte
756 756
 	);
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
 		  . '</code>'
84 84
 		  . '</pre>'
85 85
 		  . '</div>';
86
-	}
87
-	else {
86
+	} else {
88 87
 		$echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89 88
 		$echap = str_replace("  ", " &nbsp;", $echap);
90 89
 		$html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
@@ -611,8 +610,7 @@  discard block
 block discarded – undo
611 610
 		$collecteurLiens = $collecteurModeles = null;
612 611
 		if (!empty($options['expanser_liens'])) {
613 612
 			$texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
614
-		}
615
-		else {
613
+		} else {
616 614
 			include_spip("src/Texte/Collecteur/AbstractCollecteur");
617 615
 			include_spip("src/Texte/Collecteur/Liens");
618 616
 			include_spip("src/Texte/Collecteur/Modeles");
Please login to merge, or discard this patch.