@@ -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 | |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define('_BALISES_BLOCS', |
|
| 65 | - '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' |
|
| 66 | - ); |
|
| 64 | + define('_BALISES_BLOCS', |
|
| 65 | + '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' |
|
| 66 | + ); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | // echappe est un div ou un span |
| 80 | 80 | // https://code.spip.net/@code_echappement |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ""; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ""; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
@@ -106,84 +106,84 @@ discard block |
||
| 106 | 106 | // Echapper les <html>...</ html> |
| 107 | 107 | // https://code.spip.net/@traiter_echap_html_dist |
| 108 | 108 | function traiter_echap_html_dist($regs) { |
| 109 | - return $regs[3]; |
|
| 109 | + return $regs[3]; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Echapper les <pre>...</ pre> |
| 113 | 113 | function traiter_echap_pre_dist($regs) { |
| 114 | - // echapper les <code> dans <pre> |
|
| 115 | - $pre = $regs[3]; |
|
| 116 | - |
|
| 117 | - // echapper les < dans <code> |
|
| 118 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 119 | - if (strpos($pre, "<") !== false |
|
| 120 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)){ |
|
| 121 | - |
|
| 122 | - foreach ($matches as $m){ |
|
| 123 | - if ($m[1]==='code'){ |
|
| 124 | - $code = "<code" . $m[2] . ">" . spip_htmlspecialchars($m[3]) . "</code>"; |
|
| 125 | - $pre = str_replace($m[0], $code, $pre); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return "<pre>$pre</pre>"; |
|
| 114 | + // echapper les <code> dans <pre> |
|
| 115 | + $pre = $regs[3]; |
|
| 116 | + |
|
| 117 | + // echapper les < dans <code> |
|
| 118 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 119 | + if (strpos($pre, "<") !== false |
|
| 120 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)){ |
|
| 121 | + |
|
| 122 | + foreach ($matches as $m){ |
|
| 123 | + if ($m[1]==='code'){ |
|
| 124 | + $code = "<code" . $m[2] . ">" . spip_htmlspecialchars($m[3]) . "</code>"; |
|
| 125 | + $pre = str_replace($m[0], $code, $pre); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return "<pre>$pre</pre>"; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Echapper les <code>...</ code> |
| 133 | 133 | // https://code.spip.net/@traiter_echap_code_dist |
| 134 | 134 | function traiter_echap_code_dist($regs) { |
| 135 | - list(, , $att, $corps) = $regs; |
|
| 136 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 137 | - |
|
| 138 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 139 | - if (is_int(strpos($echap, "\n"))) { |
|
| 140 | - // supprimer les sauts de ligne debut/fin |
|
| 141 | - // (mais pas les espaces => ascii art). |
|
| 142 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 143 | - $echap = nl2br($echap); |
|
| 144 | - $echap = "<div style='text-align: left;' " |
|
| 145 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 146 | - . $echap . "</code></div>"; |
|
| 147 | - } else { |
|
| 148 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $echap = str_replace("\t", " ", $echap); |
|
| 152 | - $echap = str_replace(" ", " ", $echap); |
|
| 153 | - |
|
| 154 | - return $echap; |
|
| 135 | + list(, , $att, $corps) = $regs; |
|
| 136 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 137 | + |
|
| 138 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 139 | + if (is_int(strpos($echap, "\n"))) { |
|
| 140 | + // supprimer les sauts de ligne debut/fin |
|
| 141 | + // (mais pas les espaces => ascii art). |
|
| 142 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap); |
|
| 143 | + $echap = nl2br($echap); |
|
| 144 | + $echap = "<div style='text-align: left;' " |
|
| 145 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 146 | + . $echap . "</code></div>"; |
|
| 147 | + } else { |
|
| 148 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $echap = str_replace("\t", " ", $echap); |
|
| 152 | + $echap = str_replace(" ", " ", $echap); |
|
| 153 | + |
|
| 154 | + return $echap; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 158 | 158 | // https://code.spip.net/@traiter_echap_cadre_dist |
| 159 | 159 | function traiter_echap_cadre_dist($regs) { |
| 160 | - $echap = trim(entites_html($regs[3])); |
|
| 161 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 162 | - $lignes = explode("\n", trim($echap)); |
|
| 163 | - $n = 0; |
|
| 164 | - foreach ($lignes as $l) { |
|
| 165 | - $n += floor(strlen($l) / 60) + 1; |
|
| 166 | - } |
|
| 167 | - $n = max($n, 2); |
|
| 168 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 169 | - |
|
| 170 | - return $echap; |
|
| 160 | + $echap = trim(entites_html($regs[3])); |
|
| 161 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 162 | + $lignes = explode("\n", trim($echap)); |
|
| 163 | + $n = 0; |
|
| 164 | + foreach ($lignes as $l) { |
|
| 165 | + $n += floor(strlen($l) / 60) + 1; |
|
| 166 | + } |
|
| 167 | + $n = max($n, 2); |
|
| 168 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 169 | + |
|
| 170 | + return $echap; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // https://code.spip.net/@traiter_echap_frame_dist |
| 174 | 174 | function traiter_echap_frame_dist($regs) { |
| 175 | - return traiter_echap_cadre_dist($regs); |
|
| 175 | + return traiter_echap_cadre_dist($regs); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // https://code.spip.net/@traiter_echap_script_dist |
| 179 | 179 | function traiter_echap_script_dist($regs) { |
| 180 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 181 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 182 | - return highlight_string($regs[0], true); |
|
| 183 | - } |
|
| 180 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 181 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 182 | + return highlight_string($regs[0], true); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - // Cas normal : le script passe tel quel |
|
| 186 | - return $regs[0]; |
|
| 185 | + // Cas normal : le script passe tel quel |
|
| 186 | + return $regs[0]; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\s[^>]*)?>(.*)</\1>,UimsS'); |
@@ -192,71 +192,71 @@ discard block |
||
| 192 | 192 | // - pour $no_transform voir le filtre post_autobr dans inc/filtres |
| 193 | 193 | // https://code.spip.net/@echappe_html |
| 194 | 194 | function echappe_html( |
| 195 | - $letexte, |
|
| 196 | - $source = '', |
|
| 197 | - $no_transform = false, |
|
| 198 | - $preg = '' |
|
| 195 | + $letexte, |
|
| 196 | + $source = '', |
|
| 197 | + $no_transform = false, |
|
| 198 | + $preg = '' |
|
| 199 | 199 | ) { |
| 200 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 201 | - return $letexte; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // si le texte recu est long PCRE risque d'exploser, on |
|
| 205 | - // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 206 | - if (($len = strlen($letexte)) > 100000) { |
|
| 207 | - if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 208 | - $old = 100000; |
|
| 209 | - } |
|
| 210 | - if ($len > $old) { |
|
| 211 | - $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 212 | - spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (($preg or strpos($letexte, "<") !== false) |
|
| 217 | - and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 218 | - ) { |
|
| 219 | - foreach ($matches as $regs) { |
|
| 220 | - // echappements tels quels ? |
|
| 221 | - if ($no_transform) { |
|
| 222 | - $echap = $regs[0]; |
|
| 223 | - } // sinon les traiter selon le cas |
|
| 224 | - else { |
|
| 225 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 226 | - $echap = $f($regs); |
|
| 227 | - } else { |
|
| 228 | - if (function_exists($f = $f . '_dist')) { |
|
| 229 | - $echap = $f($regs); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $p = strpos($letexte, $regs[0]); |
|
| 235 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - if ($no_transform) { |
|
| 240 | - return $letexte; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 244 | - // seulement si on a echappe les <script> |
|
| 245 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 246 | - // dans une callback autonommee |
|
| 247 | - if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 249 | - $letexte, $matches, PREG_SET_ORDER) |
|
| 250 | - ) { |
|
| 251 | - foreach ($matches as $regs) { |
|
| 252 | - $letexte = str_replace($regs[0], |
|
| 253 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 254 | - $letexte); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $letexte; |
|
| 200 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 201 | + return $letexte; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // si le texte recu est long PCRE risque d'exploser, on |
|
| 205 | + // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 206 | + if (($len = strlen($letexte)) > 100000) { |
|
| 207 | + if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 208 | + $old = 100000; |
|
| 209 | + } |
|
| 210 | + if ($len > $old) { |
|
| 211 | + $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 212 | + spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (($preg or strpos($letexte, "<") !== false) |
|
| 217 | + and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 218 | + ) { |
|
| 219 | + foreach ($matches as $regs) { |
|
| 220 | + // echappements tels quels ? |
|
| 221 | + if ($no_transform) { |
|
| 222 | + $echap = $regs[0]; |
|
| 223 | + } // sinon les traiter selon le cas |
|
| 224 | + else { |
|
| 225 | + if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 226 | + $echap = $f($regs); |
|
| 227 | + } else { |
|
| 228 | + if (function_exists($f = $f . '_dist')) { |
|
| 229 | + $echap = $f($regs); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $p = strpos($letexte, $regs[0]); |
|
| 235 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + if ($no_transform) { |
|
| 240 | + return $letexte; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 244 | + // seulement si on a echappe les <script> |
|
| 245 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 246 | + // dans une callback autonommee |
|
| 247 | + if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | + if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 249 | + $letexte, $matches, PREG_SET_ORDER) |
|
| 250 | + ) { |
|
| 251 | + foreach ($matches as $regs) { |
|
| 252 | + $letexte = str_replace($regs[0], |
|
| 253 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 254 | + $letexte); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $letexte; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // |
@@ -265,52 +265,52 @@ discard block |
||
| 265 | 265 | // par propre() : exemple dans multi et dans typo() |
| 266 | 266 | // https://code.spip.net/@echappe_retour |
| 267 | 267 | function echappe_retour($letexte, $source = '', $filtre = "") { |
| 268 | - if (strpos($letexte, "base64$source")) { |
|
| 269 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 270 | - $max_prof = 5; |
|
| 271 | - while (strpos($letexte, "<") !== false |
|
| 272 | - and |
|
| 273 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 274 | - $letexte, $regs, PREG_SET_ORDER) |
|
| 275 | - and $max_prof--) { |
|
| 276 | - foreach ($regs as $reg) { |
|
| 277 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 278 | - // recherche d'attributs supplementaires |
|
| 279 | - $at = array(); |
|
| 280 | - foreach (array('lang', 'dir') as $attr) { |
|
| 281 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 282 | - $at[$attr] = $a; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - if ($at) { |
|
| 286 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 287 | - foreach ($at as $attr => $a) { |
|
| 288 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if ($filtre) { |
|
| 292 | - $rempl = $filtre($rempl); |
|
| 293 | - } |
|
| 294 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $letexte; |
|
| 268 | + if (strpos($letexte, "base64$source")) { |
|
| 269 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 270 | + $max_prof = 5; |
|
| 271 | + while (strpos($letexte, "<") !== false |
|
| 272 | + and |
|
| 273 | + preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 274 | + $letexte, $regs, PREG_SET_ORDER) |
|
| 275 | + and $max_prof--) { |
|
| 276 | + foreach ($regs as $reg) { |
|
| 277 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 278 | + // recherche d'attributs supplementaires |
|
| 279 | + $at = array(); |
|
| 280 | + foreach (array('lang', 'dir') as $attr) { |
|
| 281 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 282 | + $at[$attr] = $a; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + if ($at) { |
|
| 286 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 287 | + foreach ($at as $attr => $a) { |
|
| 288 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if ($filtre) { |
|
| 292 | + $rempl = $filtre($rempl); |
|
| 293 | + } |
|
| 294 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $letexte; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // Reinserer le javascript de confiance (venant des modeles) |
| 303 | 303 | |
| 304 | 304 | // https://code.spip.net/@echappe_retour_modeles |
| 305 | 305 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 306 | - $letexte = echappe_retour($letexte); |
|
| 306 | + $letexte = echappe_retour($letexte); |
|
| 307 | 307 | |
| 308 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 309 | - if ($interdire_scripts) { |
|
| 310 | - $letexte = interdire_scripts($letexte); |
|
| 311 | - } |
|
| 308 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 309 | + if ($interdire_scripts) { |
|
| 310 | + $letexte = interdire_scripts($letexte); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - return trim($letexte); |
|
| 313 | + return trim($letexte); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
@@ -338,130 +338,130 @@ discard block |
||
| 338 | 338 | * Texte coupé |
| 339 | 339 | **/ |
| 340 | 340 | function couper($texte, $taille = 50, $suite = null) { |
| 341 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 342 | - return ''; |
|
| 343 | - } |
|
| 344 | - $offset = 400 + 2 * $taille; |
|
| 345 | - while ($offset < $length |
|
| 346 | - and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 347 | - $offset = 2 * $offset; |
|
| 348 | - } |
|
| 349 | - if ($offset < $length |
|
| 350 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | - ) { |
|
| 352 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 354 | - $offset = $p_tag_fermant + 1; |
|
| 355 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 356 | - } |
|
| 357 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 358 | - |
|
| 359 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 360 | - include_spip('inc/lien'); |
|
| 361 | - } |
|
| 362 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 363 | - |
|
| 364 | - // balises de sauts de ligne et paragraphe |
|
| 365 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 366 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 367 | - |
|
| 368 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 369 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 370 | - |
|
| 371 | - // supprimer les tags |
|
| 372 | - $texte = supprimer_tags($texte); |
|
| 373 | - $texte = trim(str_replace("\n", " ", $texte)); |
|
| 374 | - $texte .= "\n"; // marquer la fin |
|
| 375 | - |
|
| 376 | - // corriger la longueur de coupe |
|
| 377 | - // en fonction de la presence de caracteres utf |
|
| 378 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 379 | - $long = charset2unicode($texte); |
|
| 380 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 381 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 382 | - $taille += $nbcharutf; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - // couper au mot precedent |
|
| 387 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 388 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 389 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 390 | - if (is_null($suite)) { |
|
| 391 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 392 | - } |
|
| 393 | - $points = $suite; |
|
| 394 | - |
|
| 395 | - // trop court ? ne pas faire de (...) |
|
| 396 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 397 | - $points = ''; |
|
| 398 | - $long = spip_substr($texte, 0, $taille); |
|
| 399 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 400 | - // encore trop court ? couper au caractere |
|
| 401 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 402 | - $texte = $long; |
|
| 403 | - } |
|
| 404 | - } else { |
|
| 405 | - $texte = $court; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 409 | - { |
|
| 410 | - $points = ''; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // remettre les paragraphes |
|
| 414 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 415 | - |
|
| 416 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 417 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 418 | - |
|
| 419 | - return quote_amp(trim($texte)) . $points; |
|
| 341 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 342 | + return ''; |
|
| 343 | + } |
|
| 344 | + $offset = 400 + 2 * $taille; |
|
| 345 | + while ($offset < $length |
|
| 346 | + and strlen(preg_replace(",<(!--|\w|/)[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { |
|
| 347 | + $offset = 2 * $offset; |
|
| 348 | + } |
|
| 349 | + if ($offset < $length |
|
| 350 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 351 | + ) { |
|
| 352 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 353 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 354 | + $offset = $p_tag_fermant + 1; |
|
| 355 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 356 | + } |
|
| 357 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 358 | + |
|
| 359 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 360 | + include_spip('inc/lien'); |
|
| 361 | + } |
|
| 362 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 363 | + |
|
| 364 | + // balises de sauts de ligne et paragraphe |
|
| 365 | + $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 366 | + $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 367 | + |
|
| 368 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 369 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 370 | + |
|
| 371 | + // supprimer les tags |
|
| 372 | + $texte = supprimer_tags($texte); |
|
| 373 | + $texte = trim(str_replace("\n", " ", $texte)); |
|
| 374 | + $texte .= "\n"; // marquer la fin |
|
| 375 | + |
|
| 376 | + // corriger la longueur de coupe |
|
| 377 | + // en fonction de la presence de caracteres utf |
|
| 378 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 379 | + $long = charset2unicode($texte); |
|
| 380 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 381 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 382 | + $taille += $nbcharutf; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + // couper au mot precedent |
|
| 387 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 388 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 389 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 390 | + if (is_null($suite)) { |
|
| 391 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 392 | + } |
|
| 393 | + $points = $suite; |
|
| 394 | + |
|
| 395 | + // trop court ? ne pas faire de (...) |
|
| 396 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 397 | + $points = ''; |
|
| 398 | + $long = spip_substr($texte, 0, $taille); |
|
| 399 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 400 | + // encore trop court ? couper au caractere |
|
| 401 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 402 | + $texte = $long; |
|
| 403 | + } |
|
| 404 | + } else { |
|
| 405 | + $texte = $court; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if (strpos($texte, "\n")) // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 409 | + { |
|
| 410 | + $points = ''; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // remettre les paragraphes |
|
| 414 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 415 | + |
|
| 416 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 417 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 418 | + |
|
| 419 | + return quote_amp(trim($texte)) . $points; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | |
| 423 | 423 | // https://code.spip.net/@protege_js_modeles |
| 424 | 424 | function protege_js_modeles($t) { |
| 425 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 426 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 427 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 428 | - include_spip('inc/acces'); |
|
| 429 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 430 | - } |
|
| 431 | - foreach ($r as $regs) { |
|
| 432 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 436 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 437 | - include_spip('inc/acces'); |
|
| 438 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 439 | - } |
|
| 440 | - foreach ($r as $regs) { |
|
| 441 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $t; |
|
| 425 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 426 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 427 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 428 | + include_spip('inc/acces'); |
|
| 429 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 430 | + } |
|
| 431 | + foreach ($r as $regs) { |
|
| 432 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 436 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 437 | + include_spip('inc/acces'); |
|
| 438 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 439 | + } |
|
| 440 | + foreach ($r as $regs) { |
|
| 441 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $t; |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
| 450 | 450 | function echapper_faux_tags($letexte) { |
| 451 | - if (strpos($letexte, '<') === false) { |
|
| 452 | - return $letexte; |
|
| 453 | - } |
|
| 454 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 455 | - |
|
| 456 | - $letexte = ""; |
|
| 457 | - while (count($textMatches)) { |
|
| 458 | - // un texte a echapper |
|
| 459 | - $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 460 | - // un tag html qui a servit a faite le split |
|
| 461 | - $letexte .= array_shift($textMatches); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return $letexte; |
|
| 451 | + if (strpos($letexte, '<') === false) { |
|
| 452 | + return $letexte; |
|
| 453 | + } |
|
| 454 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE); |
|
| 455 | + |
|
| 456 | + $letexte = ""; |
|
| 457 | + while (count($textMatches)) { |
|
| 458 | + // un texte a echapper |
|
| 459 | + $letexte .= str_replace("<", '<', array_shift($textMatches)); |
|
| 460 | + // un tag html qui a servit a faite le split |
|
| 461 | + $letexte .= array_shift($textMatches); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return $letexte; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -474,44 +474,44 @@ discard block |
||
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | 476 | function echapper_html_suspect($texte, $strict=true) { |
| 477 | - static $echapper_html_suspect; |
|
| 478 | - if (!$texte or !is_string($texte)) { |
|
| 479 | - return $texte; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if (!isset($echapper_html_suspect)) { |
|
| 483 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 484 | - } |
|
| 485 | - // si fonction personalisee, on delegue |
|
| 486 | - if ($echapper_html_suspect) { |
|
| 487 | - return $echapper_html_suspect($texte, $strict); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - if (strpos($texte, '<') === false |
|
| 491 | - or strpos($texte, '=') === false) { |
|
| 492 | - return $texte; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 496 | - // car sinon on declenche sur les modeles ou ressources |
|
| 497 | - if (!$strict and |
|
| 498 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 499 | - ){ |
|
| 500 | - return $texte; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 504 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 505 | - // donc un test d'egalite est trop strict |
|
| 506 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 507 | - $texte = str_replace("<", "<", $texte); |
|
| 508 | - if (!function_exists('attribut_html')) { |
|
| 509 | - include_spip('inc/filtres'); |
|
| 510 | - } |
|
| 511 | - $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - return $texte; |
|
| 477 | + static $echapper_html_suspect; |
|
| 478 | + if (!$texte or !is_string($texte)) { |
|
| 479 | + return $texte; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if (!isset($echapper_html_suspect)) { |
|
| 483 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 484 | + } |
|
| 485 | + // si fonction personalisee, on delegue |
|
| 486 | + if ($echapper_html_suspect) { |
|
| 487 | + return $echapper_html_suspect($texte, $strict); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + if (strpos($texte, '<') === false |
|
| 491 | + or strpos($texte, '=') === false) { |
|
| 492 | + return $texte; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 496 | + // car sinon on declenche sur les modeles ou ressources |
|
| 497 | + if (!$strict and |
|
| 498 | + (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 499 | + ){ |
|
| 500 | + return $texte; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 504 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 505 | + // donc un test d'egalite est trop strict |
|
| 506 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 507 | + $texte = str_replace("<", "<", $texte); |
|
| 508 | + if (!function_exists('attribut_html')) { |
|
| 509 | + include_spip('inc/filtres'); |
|
| 510 | + } |
|
| 511 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + return $texte; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
@@ -532,27 +532,27 @@ discard block |
||
| 532 | 532 | * Texte sécurisé |
| 533 | 533 | **/ |
| 534 | 534 | function safehtml($t) { |
| 535 | - static $safehtml; |
|
| 536 | - |
|
| 537 | - if (!$t or !is_string($t)) { |
|
| 538 | - return $t; |
|
| 539 | - } |
|
| 540 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 541 | - if (strpos($t, '<') === false) { |
|
| 542 | - return str_replace("\x00", '', $t); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - $t = interdire_scripts($t); // jolifier le php |
|
| 546 | - $t = echappe_js($t); |
|
| 547 | - |
|
| 548 | - if (!isset($safehtml)) { |
|
| 549 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 550 | - } |
|
| 551 | - if ($safehtml) { |
|
| 552 | - $t = $safehtml($t); |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 535 | + static $safehtml; |
|
| 536 | + |
|
| 537 | + if (!$t or !is_string($t)) { |
|
| 538 | + return $t; |
|
| 539 | + } |
|
| 540 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 541 | + if (strpos($t, '<') === false) { |
|
| 542 | + return str_replace("\x00", '', $t); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + $t = interdire_scripts($t); // jolifier le php |
|
| 546 | + $t = echappe_js($t); |
|
| 547 | + |
|
| 548 | + if (!isset($safehtml)) { |
|
| 549 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 550 | + } |
|
| 551 | + if ($safehtml) { |
|
| 552 | + $t = $safehtml($t); |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | |
@@ -574,10 +574,10 @@ discard block |
||
| 574 | 574 | * Texte sans les modèles d'image |
| 575 | 575 | **/ |
| 576 | 576 | function supprime_img($letexte, $message = null) { |
| 577 | - if ($message === null) { |
|
| 578 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 579 | - } |
|
| 577 | + if ($message === null) { |
|
| 578 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 582 | - $message, $letexte); |
|
| 581 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 582 | + $message, $letexte); |
|
| 583 | 583 | } |
@@ -44,7 +44,7 @@ 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 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 70 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 70 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // Tester si on echappe en span ou en div |
| 87 | 87 | if (is_null($mode) or !in_array($mode, array('div', 'span'))) { |
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 88 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -117,11 +117,11 @@ discard block |
||
| 117 | 117 | // echapper les < dans <code> |
| 118 | 118 | // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
| 119 | 119 | if (strpos($pre, "<") !== false |
| 120 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)){ |
|
| 120 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)) { |
|
| 121 | 121 | |
| 122 | - foreach ($matches as $m){ |
|
| 123 | - if ($m[1]==='code'){ |
|
| 124 | - $code = "<code" . $m[2] . ">" . spip_htmlspecialchars($m[3]) . "</code>"; |
|
| 122 | + foreach ($matches as $m) { |
|
| 123 | + if ($m[1] === 'code') { |
|
| 124 | + $code = "<code".$m[2].">".spip_htmlspecialchars($m[3])."</code>"; |
|
| 125 | 125 | $pre = str_replace($m[0], $code, $pre); |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | // Echapper les <code>...</ code> |
| 133 | 133 | // https://code.spip.net/@traiter_echap_code_dist |
| 134 | 134 | function traiter_echap_code_dist($regs) { |
| 135 | - list(, , $att, $corps) = $regs; |
|
| 135 | + list(,, $att, $corps) = $regs; |
|
| 136 | 136 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 137 | 137 | |
| 138 | 138 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | $echap = nl2br($echap); |
| 144 | 144 | $echap = "<div style='text-align: left;' " |
| 145 | 145 | . "class='spip_code' dir='ltr'><code$att>" |
| 146 | - . $echap . "</code></div>"; |
|
| 146 | + . $echap."</code></div>"; |
|
| 147 | 147 | } else { |
| 148 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . "</code>"; |
|
| 148 | + $echap = "<code$att class='spip_code' dir='ltr'>".$echap."</code>"; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $echap = str_replace("\t", " ", $echap); |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | $echap = $regs[0]; |
| 223 | 223 | } // sinon les traiter selon le cas |
| 224 | 224 | else { |
| 225 | - if (function_exists($f = 'traiter_echap_' . strtolower($regs[1]))) { |
|
| 225 | + if (function_exists($f = 'traiter_echap_'.strtolower($regs[1]))) { |
|
| 226 | 226 | $echap = $f($regs); |
| 227 | 227 | } else { |
| 228 | - if (function_exists($f = $f . '_dist')) { |
|
| 228 | + if (function_exists($f = $f.'_dist')) { |
|
| 229 | 229 | $echap = $f($regs); |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | // (derogatoire car on ne peut pas faire passer < ? ... ? > |
| 246 | 246 | // dans une callback autonommee |
| 247 | 247 | if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
| 248 | - if (strpos($letexte, "<" . "?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 248 | + if (strpos($letexte, "<"."?") !== false and preg_match_all(',<[?].*($|[?]>),UisS', |
|
| 249 | 249 | $letexte, $matches, PREG_SET_ORDER) |
| 250 | 250 | ) { |
| 251 | 251 | foreach ($matches as $regs) { |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $max_prof = 5; |
| 271 | 271 | while (strpos($letexte, "<") !== false |
| 272 | 272 | and |
| 273 | - preg_match_all(',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 273 | + preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 274 | 274 | $letexte, $regs, PREG_SET_ORDER) |
| 275 | 275 | and $max_prof--) { |
| 276 | 276 | foreach ($regs as $reg) { |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | if ($at) { |
| 286 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 286 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 287 | 287 | foreach ($at as $attr => $a) { |
| 288 | 288 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 289 | 289 | } |
@@ -362,8 +362,8 @@ discard block |
||
| 362 | 362 | $texte = nettoyer_raccourcis_typo($texte); |
| 363 | 363 | |
| 364 | 364 | // balises de sauts de ligne et paragraphe |
| 365 | - $texte = preg_replace("/<p( [^>]*)?" . ">/", "\r", $texte); |
|
| 366 | - $texte = preg_replace("/<br( [^>]*)?" . ">/", "\n", $texte); |
|
| 365 | + $texte = preg_replace("/<p( [^>]*)?".">/", "\r", $texte); |
|
| 366 | + $texte = preg_replace("/<br( [^>]*)?".">/", "\n", $texte); |
|
| 367 | 367 | |
| 368 | 368 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 369 | 369 | $texte = str_replace("\n\n", "\r", $texte); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | // supprimer les tags |
| 372 | 372 | $texte = supprimer_tags($texte); |
| 373 | 373 | $texte = trim(str_replace("\n", " ", $texte)); |
| 374 | - $texte .= "\n"; // marquer la fin |
|
| 374 | + $texte .= "\n"; // marquer la fin |
|
| 375 | 375 | |
| 376 | 376 | // corriger la longueur de coupe |
| 377 | 377 | // en fonction de la presence de caracteres utf |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | // couper au mot precedent |
| 387 | 387 | $long = spip_substr($texte, 0, max($taille - 4, 1)); |
| 388 | 388 | $u = $GLOBALS['meta']['pcre_u']; |
| 389 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 389 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 390 | 390 | if (is_null($suite)) { |
| 391 | 391 | $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
| 392 | 392 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 397 | 397 | $points = ''; |
| 398 | 398 | $long = spip_substr($texte, 0, $taille); |
| 399 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 399 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 400 | 400 | // encore trop court ? couper au caractere |
| 401 | 401 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 402 | 402 | $texte = $long; |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | // supprimer l'eventuelle entite finale mal coupee |
| 417 | 417 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 418 | 418 | |
| 419 | - return quote_amp(trim($texte)) . $points; |
|
| 419 | + return quote_amp(trim($texte)).$points; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | |
@@ -429,16 +429,16 @@ discard block |
||
| 429 | 429 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 430 | 430 | } |
| 431 | 431 | foreach ($r as $regs) { |
| 432 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 432 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 435 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 436 | 436 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 437 | 437 | include_spip('inc/acces'); |
| 438 | 438 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 439 | 439 | } |
| 440 | 440 | foreach ($r as $regs) { |
| 441 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 441 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | * @param bool $strict |
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | -function echapper_html_suspect($texte, $strict=true) { |
|
| 476 | +function echapper_html_suspect($texte, $strict = true) { |
|
| 477 | 477 | static $echapper_html_suspect; |
| 478 | 478 | if (!$texte or !is_string($texte)) { |
| 479 | 479 | return $texte; |
@@ -495,8 +495,8 @@ discard block |
||
| 495 | 495 | // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
| 496 | 496 | // car sinon on declenche sur les modeles ou ressources |
| 497 | 497 | if (!$strict and |
| 498 | - (strpos($texte,'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 499 | - ){ |
|
| 498 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 499 | + ) { |
|
| 500 | 500 | return $texte; |
| 501 | 501 | } |
| 502 | 502 | |
@@ -575,9 +575,9 @@ discard block |
||
| 575 | 575 | **/ |
| 576 | 576 | function supprime_img($letexte, $message = null) { |
| 577 | 577 | if ($message === null) { |
| 578 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 578 | + $message = '('._T('img_indisponible').')'; |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 581 | + return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 582 | 582 | $message, $letexte); |
| 583 | 583 | } |