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