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