@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // traite les modeles (dans la fonction typo), en remplacant |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | // mais on renvoie les params (pour l'indexation par le moteur de recherche) |
| 23 | 23 | |
| 24 | 24 | define( |
| 25 | - '_PREG_MODELE', |
|
| 26 | - '(<([a-z_-]{3,})' # <modele |
|
| 27 | - . '\s*([0-9]*)\s*' # id |
|
| 28 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 29 | - . '\s*/?' . '>)' # fin du modele > |
|
| 25 | + '_PREG_MODELE', |
|
| 26 | + '(<([a-z_-]{3,})' # <modele |
|
| 27 | + . '\s*([0-9]*)\s*' # id |
|
| 28 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 29 | + . '\s*/?' . '>)' # fin du modele > |
|
| 30 | 30 | ); |
| 31 | 31 | |
| 32 | 32 | define( |
| 33 | - '_RACCOURCI_MODELE', |
|
| 34 | - _PREG_MODELE |
|
| 35 | - . '\s*(<\/a>)?' # eventuel </a> |
|
| 33 | + '_RACCOURCI_MODELE', |
|
| 34 | + _PREG_MODELE |
|
| 35 | + . '\s*(<\/a>)?' # eventuel </a> |
|
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
@@ -46,63 +46,63 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function modeles_collecter($texte, bool $collecter_liens = true) { |
| 48 | 48 | |
| 49 | - $modeles = []; |
|
| 50 | - // detecter les modeles (rapide) |
|
| 51 | - if ( |
|
| 52 | - strpos($texte, '<') !== false |
|
| 53 | - and preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 54 | - ) { |
|
| 55 | - $pos = 0; |
|
| 56 | - // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 57 | - foreach ($matches as $match) { |
|
| 58 | - $a = strpos($texte, (string)$match[0], $pos); |
|
| 59 | - |
|
| 60 | - if (preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs)) { |
|
| 61 | - // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 62 | - while (count($regs) < 6) { |
|
| 63 | - $regs[] = ''; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - [, $mod, $type, $id, $params, $fermeture_lien] = $regs; |
|
| 67 | - |
|
| 68 | - if ( |
|
| 69 | - $collecter_liens |
|
| 70 | - and $fermeture_lien |
|
| 71 | - and $before = substr($texte, $pos, $a - $pos) |
|
| 72 | - and stripos($before, '<a') !== false |
|
| 73 | - and preg_match('/<a\s[^<>]*>\s*$/i', $before, $r) |
|
| 74 | - ) { |
|
| 75 | - $lien = [ |
|
| 76 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 77 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 78 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 79 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 80 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 81 | - ]; |
|
| 82 | - $n = strlen($r[0]); |
|
| 83 | - $a -= $n; |
|
| 84 | - $longueur = $n + strlen($regs[0]); |
|
| 85 | - } else { |
|
| 86 | - $lien = false; |
|
| 87 | - $longueur = strlen($mod); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $modele = [ |
|
| 91 | - 'modele' => $mod, |
|
| 92 | - 'pos' => $a, |
|
| 93 | - 'length' => $longueur, |
|
| 94 | - 'type' => $type, |
|
| 95 | - 'id' => $id, |
|
| 96 | - 'params' => $params, |
|
| 97 | - 'lien' => $lien, |
|
| 98 | - ]; |
|
| 99 | - |
|
| 100 | - $modeles[] = $modele; |
|
| 101 | - } |
|
| 102 | - $pos = $a + strlen((string)$match[0]); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return $modeles; |
|
| 49 | + $modeles = []; |
|
| 50 | + // detecter les modeles (rapide) |
|
| 51 | + if ( |
|
| 52 | + strpos($texte, '<') !== false |
|
| 53 | + and preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 54 | + ) { |
|
| 55 | + $pos = 0; |
|
| 56 | + // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 57 | + foreach ($matches as $match) { |
|
| 58 | + $a = strpos($texte, (string)$match[0], $pos); |
|
| 59 | + |
|
| 60 | + if (preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs)) { |
|
| 61 | + // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 62 | + while (count($regs) < 6) { |
|
| 63 | + $regs[] = ''; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + [, $mod, $type, $id, $params, $fermeture_lien] = $regs; |
|
| 67 | + |
|
| 68 | + if ( |
|
| 69 | + $collecter_liens |
|
| 70 | + and $fermeture_lien |
|
| 71 | + and $before = substr($texte, $pos, $a - $pos) |
|
| 72 | + and stripos($before, '<a') !== false |
|
| 73 | + and preg_match('/<a\s[^<>]*>\s*$/i', $before, $r) |
|
| 74 | + ) { |
|
| 75 | + $lien = [ |
|
| 76 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 77 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 78 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 79 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 80 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 81 | + ]; |
|
| 82 | + $n = strlen($r[0]); |
|
| 83 | + $a -= $n; |
|
| 84 | + $longueur = $n + strlen($regs[0]); |
|
| 85 | + } else { |
|
| 86 | + $lien = false; |
|
| 87 | + $longueur = strlen($mod); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $modele = [ |
|
| 91 | + 'modele' => $mod, |
|
| 92 | + 'pos' => $a, |
|
| 93 | + 'length' => $longueur, |
|
| 94 | + 'type' => $type, |
|
| 95 | + 'id' => $id, |
|
| 96 | + 'params' => $params, |
|
| 97 | + 'lien' => $lien, |
|
| 98 | + ]; |
|
| 99 | + |
|
| 100 | + $modeles[] = $modele; |
|
| 101 | + } |
|
| 102 | + $pos = $a + strlen((string)$match[0]); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return $modeles; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -116,24 +116,24 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | function modeles_echapper_raccourcis($texte, bool $collecter_liens = false) { |
| 118 | 118 | |
| 119 | - $modeles = modeles_collecter($texte, $collecter_liens); |
|
| 120 | - $markid = ''; |
|
| 121 | - if (!empty($modeles)) { |
|
| 122 | - // generer un marqueur qui n'est pas dans le texte |
|
| 123 | - do { |
|
| 124 | - $markid = substr(md5(creer_uniqid()), 0, 7); |
|
| 125 | - $markid = "@|MODELE$markid|"; |
|
| 126 | - } while (strpos($texte, $markid) !== false); |
|
| 127 | - |
|
| 128 | - $offset_pos = 0; |
|
| 129 | - foreach ($modeles as $m) { |
|
| 130 | - $rempl = $markid . base64_encode($m['modele']) . '|@'; |
|
| 131 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 132 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return [$texte, $markid]; |
|
| 119 | + $modeles = modeles_collecter($texte, $collecter_liens); |
|
| 120 | + $markid = ''; |
|
| 121 | + if (!empty($modeles)) { |
|
| 122 | + // generer un marqueur qui n'est pas dans le texte |
|
| 123 | + do { |
|
| 124 | + $markid = substr(md5(creer_uniqid()), 0, 7); |
|
| 125 | + $markid = "@|MODELE$markid|"; |
|
| 126 | + } while (strpos($texte, $markid) !== false); |
|
| 127 | + |
|
| 128 | + $offset_pos = 0; |
|
| 129 | + foreach ($modeles as $m) { |
|
| 130 | + $rempl = $markid . base64_encode($m['modele']) . '|@'; |
|
| 131 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 132 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return [$texte, $markid]; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -146,24 +146,24 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | function modele_retablir_raccourcis_echappes(string $texte, string $markid) { |
| 148 | 148 | |
| 149 | - if ($markid) { |
|
| 150 | - $pos = 0; |
|
| 151 | - while ( |
|
| 152 | - ($p = strpos($texte, $markid, $pos)) !== false |
|
| 153 | - and $end = strpos($texte, '|@', $p + 16) |
|
| 154 | - ) { |
|
| 155 | - $base64 = substr($texte, $p + 16, $end - ($p + 16)); |
|
| 156 | - if ($modele = base64_decode($base64, true)) { |
|
| 157 | - $texte = substr_replace($texte, $modele, $p, $end + 2 - $p); |
|
| 158 | - $pos = $p + strlen($modele); |
|
| 159 | - } |
|
| 160 | - else { |
|
| 161 | - $pos = $end; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return $texte; |
|
| 149 | + if ($markid) { |
|
| 150 | + $pos = 0; |
|
| 151 | + while ( |
|
| 152 | + ($p = strpos($texte, $markid, $pos)) !== false |
|
| 153 | + and $end = strpos($texte, '|@', $p + 16) |
|
| 154 | + ) { |
|
| 155 | + $base64 = substr($texte, $p + 16, $end - ($p + 16)); |
|
| 156 | + if ($modele = base64_decode($base64, true)) { |
|
| 157 | + $texte = substr_replace($texte, $modele, $p, $end + 2 - $p); |
|
| 158 | + $pos = $p + strlen($modele); |
|
| 159 | + } |
|
| 160 | + else { |
|
| 161 | + $pos = $end; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return $texte; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -178,82 +178,82 @@ discard block |
||
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | 180 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
| 181 | - // preserver la compatibilite : true = recherche des documents |
|
| 182 | - if ($doublons === true) { |
|
| 183 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $modeles = modeles_collecter($texte, true); |
|
| 187 | - if (!empty($modeles)) { |
|
| 188 | - include_spip('public/assembler'); |
|
| 189 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 190 | - |
|
| 191 | - $offset_pos = 0; |
|
| 192 | - foreach ($modeles as $m) { |
|
| 193 | - // calculer le modele |
|
| 194 | - # hack indexation |
|
| 195 | - if ($doublons) { |
|
| 196 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 197 | - } # version normale |
|
| 198 | - else { |
|
| 199 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 200 | - // dans les parametres, plutot que les liens echappes |
|
| 201 | - $params = $m['params']; |
|
| 202 | - if (!is_null($liens)) { |
|
| 203 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 207 | - |
|
| 208 | - // en cas d'echec, |
|
| 209 | - // si l'objet demande a une url, |
|
| 210 | - // creer un petit encadre vers elle |
|
| 211 | - if ($modele === false) { |
|
| 212 | - $modele = $m['modele']; |
|
| 213 | - |
|
| 214 | - if (!is_null($liens)) { |
|
| 215 | - $modele = str_replace($liens[0], $liens[1], $modele); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 219 | - |
|
| 220 | - if (!empty($m['lien'])) { |
|
| 221 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 222 | - $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 223 | - $contexte['lien_class'] = $m['lien']['class']; |
|
| 224 | - $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 225 | - $contexte['lien_title'] = $m['lien']['title']; |
|
| 226 | - $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // le remplacer dans le texte |
|
| 233 | - if ($modele !== false) { |
|
| 234 | - $modele = protege_js_modeles($modele); |
|
| 235 | - |
|
| 236 | - if ($wrap_embed_html) { |
|
| 237 | - $modele = $wrap_embed_html($m['modele'], $modele); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $rempl = code_echappement($modele, $echap); |
|
| 241 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 242 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // hack pour tout l'espace prive |
|
| 247 | - if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 248 | - $type = strtolower($m['type']); |
|
| 249 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 250 | - if (in_array($type, $modeles)) { |
|
| 251 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte; |
|
| 181 | + // preserver la compatibilite : true = recherche des documents |
|
| 182 | + if ($doublons === true) { |
|
| 183 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $modeles = modeles_collecter($texte, true); |
|
| 187 | + if (!empty($modeles)) { |
|
| 188 | + include_spip('public/assembler'); |
|
| 189 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 190 | + |
|
| 191 | + $offset_pos = 0; |
|
| 192 | + foreach ($modeles as $m) { |
|
| 193 | + // calculer le modele |
|
| 194 | + # hack indexation |
|
| 195 | + if ($doublons) { |
|
| 196 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 197 | + } # version normale |
|
| 198 | + else { |
|
| 199 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 200 | + // dans les parametres, plutot que les liens echappes |
|
| 201 | + $params = $m['params']; |
|
| 202 | + if (!is_null($liens)) { |
|
| 203 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 207 | + |
|
| 208 | + // en cas d'echec, |
|
| 209 | + // si l'objet demande a une url, |
|
| 210 | + // creer un petit encadre vers elle |
|
| 211 | + if ($modele === false) { |
|
| 212 | + $modele = $m['modele']; |
|
| 213 | + |
|
| 214 | + if (!is_null($liens)) { |
|
| 215 | + $modele = str_replace($liens[0], $liens[1], $modele); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 219 | + |
|
| 220 | + if (!empty($m['lien'])) { |
|
| 221 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 222 | + $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 223 | + $contexte['lien_class'] = $m['lien']['class']; |
|
| 224 | + $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 225 | + $contexte['lien_title'] = $m['lien']['title']; |
|
| 226 | + $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // le remplacer dans le texte |
|
| 233 | + if ($modele !== false) { |
|
| 234 | + $modele = protege_js_modeles($modele); |
|
| 235 | + |
|
| 236 | + if ($wrap_embed_html) { |
|
| 237 | + $modele = $wrap_embed_html($m['modele'], $modele); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $rempl = code_echappement($modele, $echap); |
|
| 241 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 242 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // hack pour tout l'espace prive |
|
| 247 | + if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 248 | + $type = strtolower($m['type']); |
|
| 249 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 250 | + if (in_array($type, $modeles)) { |
|
| 251 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte; |
|
| 259 | 259 | } |
@@ -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,14 +61,14 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define( |
|
| 65 | - '_BALISES_BLOCS', |
|
| 66 | - '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' |
|
| 67 | - ); |
|
| 64 | + define( |
|
| 65 | + '_BALISES_BLOCS', |
|
| 66 | + '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' |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 71 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -79,106 +79,106 @@ discard block |
||
| 79 | 79 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 80 | 80 | // echappe est un div ou un span |
| 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, ['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, ['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 | |
| 105 | 105 | // Echapper les <html>...</ html> |
| 106 | 106 | function traiter_echap_html_dist($regs, $options = []) { |
| 107 | - return $regs[3]; |
|
| 107 | + return $regs[3]; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Echapper les <pre>...</ pre> |
| 111 | 111 | function traiter_echap_pre_dist($regs, $options = []) { |
| 112 | - // echapper les <code> dans <pre> |
|
| 113 | - $pre = $regs[3]; |
|
| 114 | - |
|
| 115 | - // echapper les < dans <code> |
|
| 116 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | - if ( |
|
| 118 | - strpos($pre, '<') !== false |
|
| 119 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | - ) { |
|
| 121 | - foreach ($matches as $m) { |
|
| 122 | - if ($m[1] === 'code') { |
|
| 123 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | - $pre = str_replace($m[0], $code, $pre); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return "<pre>$pre</pre>"; |
|
| 112 | + // echapper les <code> dans <pre> |
|
| 113 | + $pre = $regs[3]; |
|
| 114 | + |
|
| 115 | + // echapper les < dans <code> |
|
| 116 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | + if ( |
|
| 118 | + strpos($pre, '<') !== false |
|
| 119 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | + ) { |
|
| 121 | + foreach ($matches as $m) { |
|
| 122 | + if ($m[1] === 'code') { |
|
| 123 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | + $pre = str_replace($m[0], $code, $pre); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return "<pre>$pre</pre>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Echapper les <code>...</ code> |
| 132 | 132 | function traiter_echap_code_dist($regs, $options = []) { |
| 133 | - [, , $att, $corps] = $regs; |
|
| 134 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | - |
|
| 136 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | - if (is_int(strpos($echap, "\n"))) { |
|
| 138 | - // supprimer les sauts de ligne debut/fin |
|
| 139 | - // (mais pas les espaces => ascii art). |
|
| 140 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | - $echap = nl2br($echap); |
|
| 142 | - $echap = "<div style='text-align: left;' " |
|
| 143 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | - . $echap . '</code></div>'; |
|
| 145 | - } else { |
|
| 146 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $echap = str_replace("\t", ' ', $echap); |
|
| 150 | - $echap = str_replace(' ', ' ', $echap); |
|
| 151 | - |
|
| 152 | - return $echap; |
|
| 133 | + [, , $att, $corps] = $regs; |
|
| 134 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | + |
|
| 136 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | + if (is_int(strpos($echap, "\n"))) { |
|
| 138 | + // supprimer les sauts de ligne debut/fin |
|
| 139 | + // (mais pas les espaces => ascii art). |
|
| 140 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | + $echap = nl2br($echap); |
|
| 142 | + $echap = "<div style='text-align: left;' " |
|
| 143 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | + . $echap . '</code></div>'; |
|
| 145 | + } else { |
|
| 146 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $echap = str_replace("\t", ' ', $echap); |
|
| 150 | + $echap = str_replace(' ', ' ', $echap); |
|
| 151 | + |
|
| 152 | + return $echap; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 156 | 156 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 157 | - $echap = trim(entites_html($regs[3])); |
|
| 158 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | - $lignes = explode("\n", trim($echap)); |
|
| 160 | - $n = 0; |
|
| 161 | - foreach ($lignes as $l) { |
|
| 162 | - $n += floor(strlen($l) / 60) + 1; |
|
| 163 | - } |
|
| 164 | - $n = max($n, 2); |
|
| 165 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | - |
|
| 167 | - return $echap; |
|
| 157 | + $echap = trim(entites_html($regs[3])); |
|
| 158 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | + $lignes = explode("\n", trim($echap)); |
|
| 160 | + $n = 0; |
|
| 161 | + foreach ($lignes as $l) { |
|
| 162 | + $n += floor(strlen($l) / 60) + 1; |
|
| 163 | + } |
|
| 164 | + $n = max($n, 2); |
|
| 165 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | + |
|
| 167 | + return $echap; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function traiter_echap_frame_dist($regs, $options = []) { |
| 171 | - return traiter_echap_cadre_dist($regs); |
|
| 171 | + return traiter_echap_cadre_dist($regs); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function traiter_echap_script_dist($regs, $options = []) { |
| 175 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | - return highlight_string($regs[0], true); |
|
| 178 | - } |
|
| 175 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | + return highlight_string($regs[0], true); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // Cas normal : le script passe tel quel |
|
| 181 | - return $regs[0]; |
|
| 180 | + // Cas normal : le script passe tel quel |
|
| 181 | + return $regs[0]; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -197,73 +197,73 @@ discard block |
||
| 197 | 197 | * @return string|string[] |
| 198 | 198 | */ |
| 199 | 199 | function echappe_html( |
| 200 | - $letexte, |
|
| 201 | - $source = '', |
|
| 202 | - $no_transform = false, |
|
| 203 | - $preg = '', |
|
| 204 | - $callback_prefix = '', |
|
| 205 | - $callback_options = [] |
|
| 200 | + $letexte, |
|
| 201 | + $source = '', |
|
| 202 | + $no_transform = false, |
|
| 203 | + $preg = '', |
|
| 204 | + $callback_prefix = '', |
|
| 205 | + $callback_options = [] |
|
| 206 | 206 | ) { |
| 207 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 208 | - return $letexte; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ( |
|
| 212 | - ($preg or strpos($letexte, '<') !== false) |
|
| 213 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 214 | - ) { |
|
| 215 | - foreach ($matches as $regs) { |
|
| 216 | - // echappements tels quels ? |
|
| 217 | - if ($no_transform) { |
|
| 218 | - $echap = $regs[0]; |
|
| 219 | - } // sinon les traiter selon le cas |
|
| 220 | - else { |
|
| 221 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 222 | - if ( |
|
| 223 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 224 | - or function_exists($f = $f . '_dist') |
|
| 225 | - or ($callback_secure_prefix and ( |
|
| 226 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 227 | - or function_exists($f = $f . '_dist') |
|
| 228 | - )) |
|
| 229 | - ) { |
|
| 230 | - $echap = $f($regs, $callback_options); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $p = strpos($letexte, (string) $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 ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | - if ( |
|
| 249 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 250 | - ',<[?].*($|[?]>),UisS', |
|
| 251 | - $letexte, |
|
| 252 | - $matches, |
|
| 253 | - PREG_SET_ORDER |
|
| 254 | - ) |
|
| 255 | - ) { |
|
| 256 | - foreach ($matches as $regs) { |
|
| 257 | - $letexte = str_replace( |
|
| 258 | - $regs[0], |
|
| 259 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 260 | - $letexte |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $letexte; |
|
| 207 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 208 | + return $letexte; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ( |
|
| 212 | + ($preg or strpos($letexte, '<') !== false) |
|
| 213 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 214 | + ) { |
|
| 215 | + foreach ($matches as $regs) { |
|
| 216 | + // echappements tels quels ? |
|
| 217 | + if ($no_transform) { |
|
| 218 | + $echap = $regs[0]; |
|
| 219 | + } // sinon les traiter selon le cas |
|
| 220 | + else { |
|
| 221 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 222 | + if ( |
|
| 223 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 224 | + or function_exists($f = $f . '_dist') |
|
| 225 | + or ($callback_secure_prefix and ( |
|
| 226 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 227 | + or function_exists($f = $f . '_dist') |
|
| 228 | + )) |
|
| 229 | + ) { |
|
| 230 | + $echap = $f($regs, $callback_options); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $p = strpos($letexte, (string) $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 ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | + if ( |
|
| 249 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 250 | + ',<[?].*($|[?]>),UisS', |
|
| 251 | + $letexte, |
|
| 252 | + $matches, |
|
| 253 | + PREG_SET_ORDER |
|
| 254 | + ) |
|
| 255 | + ) { |
|
| 256 | + foreach ($matches as $regs) { |
|
| 257 | + $letexte = str_replace( |
|
| 258 | + $regs[0], |
|
| 259 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 260 | + $letexte |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $letexte; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // |
@@ -271,57 +271,57 @@ discard block |
||
| 271 | 271 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 272 | 272 | // par propre() : exemple dans multi et dans typo() |
| 273 | 273 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 274 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 275 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 276 | - $max_prof = 5; |
|
| 277 | - while ( |
|
| 278 | - strpos($letexte, '<') !== false |
|
| 279 | - and |
|
| 280 | - preg_match_all( |
|
| 281 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 282 | - $letexte, |
|
| 283 | - $regs, |
|
| 284 | - PREG_SET_ORDER |
|
| 285 | - ) |
|
| 286 | - and $max_prof-- |
|
| 287 | - ) { |
|
| 288 | - foreach ($regs as $reg) { |
|
| 289 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 290 | - // recherche d'attributs supplementaires |
|
| 291 | - $at = []; |
|
| 292 | - foreach (['lang', 'dir'] as $attr) { |
|
| 293 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 294 | - $at[$attr] = $a; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($at) { |
|
| 298 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 299 | - foreach ($at as $attr => $a) { |
|
| 300 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if ($filtre) { |
|
| 304 | - $rempl = $filtre($rempl); |
|
| 305 | - } |
|
| 306 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return $letexte; |
|
| 274 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 275 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 276 | + $max_prof = 5; |
|
| 277 | + while ( |
|
| 278 | + strpos($letexte, '<') !== false |
|
| 279 | + and |
|
| 280 | + preg_match_all( |
|
| 281 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 282 | + $letexte, |
|
| 283 | + $regs, |
|
| 284 | + PREG_SET_ORDER |
|
| 285 | + ) |
|
| 286 | + and $max_prof-- |
|
| 287 | + ) { |
|
| 288 | + foreach ($regs as $reg) { |
|
| 289 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 290 | + // recherche d'attributs supplementaires |
|
| 291 | + $at = []; |
|
| 292 | + foreach (['lang', 'dir'] as $attr) { |
|
| 293 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 294 | + $at[$attr] = $a; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($at) { |
|
| 298 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 299 | + foreach ($at as $attr => $a) { |
|
| 300 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if ($filtre) { |
|
| 304 | + $rempl = $filtre($rempl); |
|
| 305 | + } |
|
| 306 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return $letexte; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Reinserer le javascript de confiance (venant des modeles) |
| 315 | 315 | |
| 316 | 316 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 317 | - $letexte = echappe_retour($letexte); |
|
| 317 | + $letexte = echappe_retour($letexte); |
|
| 318 | 318 | |
| 319 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 320 | - if ($interdire_scripts) { |
|
| 321 | - $letexte = interdire_scripts($letexte); |
|
| 322 | - } |
|
| 319 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 320 | + if ($interdire_scripts) { |
|
| 321 | + $letexte = interdire_scripts($letexte); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - return trim($letexte); |
|
| 324 | + return trim($letexte); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -349,131 +349,131 @@ discard block |
||
| 349 | 349 | * Texte coupé |
| 350 | 350 | **/ |
| 351 | 351 | function couper($texte, $taille = 50, $suite = null) { |
| 352 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 353 | - return ''; |
|
| 354 | - } |
|
| 355 | - $offset = 400 + 2 * $taille; |
|
| 356 | - while ( |
|
| 357 | - $offset < $length |
|
| 358 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 359 | - ) { |
|
| 360 | - $offset = 2 * $offset; |
|
| 361 | - } |
|
| 362 | - if ( |
|
| 363 | - $offset < $length |
|
| 364 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 365 | - ) { |
|
| 366 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 367 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 368 | - $offset = $p_tag_fermant + 1; |
|
| 369 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 370 | - } |
|
| 371 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 372 | - |
|
| 373 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 374 | - include_spip('inc/lien'); |
|
| 375 | - } |
|
| 376 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 377 | - |
|
| 378 | - // balises de sauts de ligne et paragraphe |
|
| 379 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 380 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 381 | - |
|
| 382 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 383 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 384 | - |
|
| 385 | - // supprimer les tags |
|
| 386 | - $texte = supprimer_tags($texte); |
|
| 387 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 388 | - $texte .= "\n"; // marquer la fin |
|
| 389 | - |
|
| 390 | - // corriger la longueur de coupe |
|
| 391 | - // en fonction de la presence de caracteres utf |
|
| 392 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 393 | - $long = charset2unicode($texte); |
|
| 394 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 395 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 396 | - $taille += $nbcharutf; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - // couper au mot precedent |
|
| 401 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 402 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 403 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 404 | - if (is_null($suite)) { |
|
| 405 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 406 | - } |
|
| 407 | - $points = $suite; |
|
| 408 | - |
|
| 409 | - // trop court ? ne pas faire de (...) |
|
| 410 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 411 | - $points = ''; |
|
| 412 | - $long = spip_substr($texte, 0, $taille); |
|
| 413 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 414 | - // encore trop court ? couper au caractere |
|
| 415 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 416 | - $texte = $long; |
|
| 417 | - } |
|
| 418 | - } else { |
|
| 419 | - $texte = $court; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 423 | - $points = ''; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // remettre les paragraphes |
|
| 427 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 428 | - |
|
| 429 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 430 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 431 | - |
|
| 432 | - return quote_amp(trim($texte)) . $points; |
|
| 352 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 353 | + return ''; |
|
| 354 | + } |
|
| 355 | + $offset = 400 + 2 * $taille; |
|
| 356 | + while ( |
|
| 357 | + $offset < $length |
|
| 358 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 359 | + ) { |
|
| 360 | + $offset = 2 * $offset; |
|
| 361 | + } |
|
| 362 | + if ( |
|
| 363 | + $offset < $length |
|
| 364 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 365 | + ) { |
|
| 366 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 367 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 368 | + $offset = $p_tag_fermant + 1; |
|
| 369 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 370 | + } |
|
| 371 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 372 | + |
|
| 373 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 374 | + include_spip('inc/lien'); |
|
| 375 | + } |
|
| 376 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 377 | + |
|
| 378 | + // balises de sauts de ligne et paragraphe |
|
| 379 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 380 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 381 | + |
|
| 382 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 383 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 384 | + |
|
| 385 | + // supprimer les tags |
|
| 386 | + $texte = supprimer_tags($texte); |
|
| 387 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 388 | + $texte .= "\n"; // marquer la fin |
|
| 389 | + |
|
| 390 | + // corriger la longueur de coupe |
|
| 391 | + // en fonction de la presence de caracteres utf |
|
| 392 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 393 | + $long = charset2unicode($texte); |
|
| 394 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 395 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 396 | + $taille += $nbcharutf; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + // couper au mot precedent |
|
| 401 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 402 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 403 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 404 | + if (is_null($suite)) { |
|
| 405 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 406 | + } |
|
| 407 | + $points = $suite; |
|
| 408 | + |
|
| 409 | + // trop court ? ne pas faire de (...) |
|
| 410 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 411 | + $points = ''; |
|
| 412 | + $long = spip_substr($texte, 0, $taille); |
|
| 413 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 414 | + // encore trop court ? couper au caractere |
|
| 415 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 416 | + $texte = $long; |
|
| 417 | + } |
|
| 418 | + } else { |
|
| 419 | + $texte = $court; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 423 | + $points = ''; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // remettre les paragraphes |
|
| 427 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 428 | + |
|
| 429 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 430 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 431 | + |
|
| 432 | + return quote_amp(trim($texte)) . $points; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
| 436 | 436 | function protege_js_modeles($t) { |
| 437 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 438 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 439 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 440 | - include_spip('inc/acces'); |
|
| 441 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 442 | - } |
|
| 443 | - foreach ($r as $regs) { |
|
| 444 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 448 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 449 | - include_spip('inc/acces'); |
|
| 450 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 451 | - } |
|
| 452 | - foreach ($r as $regs) { |
|
| 453 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return $t; |
|
| 437 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 438 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 439 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 440 | + include_spip('inc/acces'); |
|
| 441 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 442 | + } |
|
| 443 | + foreach ($r as $regs) { |
|
| 444 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 448 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 449 | + include_spip('inc/acces'); |
|
| 450 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 451 | + } |
|
| 452 | + foreach ($r as $regs) { |
|
| 453 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $t; |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
| 462 | 462 | function echapper_faux_tags($letexte) { |
| 463 | - if (strpos($letexte, '<') === false) { |
|
| 464 | - return $letexte; |
|
| 465 | - } |
|
| 466 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 467 | - |
|
| 468 | - $letexte = ''; |
|
| 469 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 470 | - // un texte a echapper |
|
| 471 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 472 | - // un tag html qui a servit a faite le split |
|
| 473 | - $letexte .= array_shift($textMatches); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - return $letexte; |
|
| 463 | + if (strpos($letexte, '<') === false) { |
|
| 464 | + return $letexte; |
|
| 465 | + } |
|
| 466 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 467 | + |
|
| 468 | + $letexte = ''; |
|
| 469 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 470 | + // un texte a echapper |
|
| 471 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 472 | + // un tag html qui a servit a faite le split |
|
| 473 | + $letexte .= array_shift($textMatches); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + return $letexte; |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -493,100 +493,100 @@ discard block |
||
| 493 | 493 | * @return string |
| 494 | 494 | */ |
| 495 | 495 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 496 | - static $echapper_html_suspect; |
|
| 497 | - if (!$texte or !is_string($texte)) { |
|
| 498 | - return $texte; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - if (!isset($echapper_html_suspect)) { |
|
| 502 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 503 | - } |
|
| 504 | - // si fonction personalisee, on delegue |
|
| 505 | - if ($echapper_html_suspect) { |
|
| 506 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 507 | - $args = [$texte, $options]; |
|
| 508 | - if ($connect or !empty($env)) { |
|
| 509 | - $args[] = $connect; |
|
| 510 | - } |
|
| 511 | - if (!empty($env)) { |
|
| 512 | - $args[] = $env; |
|
| 513 | - } |
|
| 514 | - return $echapper_html_suspect(...$args); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if (is_bool($options)) { |
|
| 518 | - $options = ['strict' => $options]; |
|
| 519 | - } |
|
| 520 | - $strict = $options['strict'] ?? true; |
|
| 521 | - |
|
| 522 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 523 | - if ( |
|
| 524 | - strpos($texte, '<') === false |
|
| 525 | - or strpos($texte, '=') === false |
|
| 526 | - ) { |
|
| 527 | - return $texte; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 531 | - if (!isset($env['espace_prive'])) { |
|
| 532 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 533 | - $env['espace_prive'] = test_espace_prive(); |
|
| 534 | - } |
|
| 535 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 536 | - |
|
| 537 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 538 | - // car sinon on declenche sur les modeles ou ressources |
|
| 539 | - if ( |
|
| 540 | - !$strict and |
|
| 541 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 542 | - ) { |
|
| 543 | - return $texte; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - [$texte, $markid] = modeles_echapper_raccourcis($texte, false); |
|
| 547 | - $texte = echappe_js($texte); |
|
| 548 | - |
|
| 549 | - $texte_to_check = $texte; |
|
| 550 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 551 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 552 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 553 | - if (!empty($options['expanser_liens'])) { |
|
| 554 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 555 | - } |
|
| 556 | - if (!is_html_safe($texte_to_check)) { |
|
| 557 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 558 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 559 | - $texte = str_replace('<', '<', $texte); |
|
| 560 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 561 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 562 | - if (!function_exists('attribut_html')) { |
|
| 563 | - include_spip('inc/filtres'); |
|
| 564 | - } |
|
| 565 | - if (!empty($options['wrap_suspect'])) { |
|
| 566 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 567 | - } |
|
| 568 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 569 | - } |
|
| 570 | - $texte = modele_retablir_raccourcis_echappes($texte, $markid); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // si on est là dans le public c'est le mode parano |
|
| 574 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 575 | - else { |
|
| 576 | - $markid = null; |
|
| 577 | - if (!empty($options['expanser_liens'])) { |
|
| 578 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 579 | - } |
|
| 580 | - else { |
|
| 581 | - [$texte, $markid] = modeles_echapper_raccourcis($texte, false); |
|
| 582 | - } |
|
| 583 | - $texte = safehtml($texte); |
|
| 584 | - if ($markid) { |
|
| 585 | - $texte = modele_retablir_raccourcis_echappes($texte, $markid); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $texte; |
|
| 496 | + static $echapper_html_suspect; |
|
| 497 | + if (!$texte or !is_string($texte)) { |
|
| 498 | + return $texte; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + if (!isset($echapper_html_suspect)) { |
|
| 502 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 503 | + } |
|
| 504 | + // si fonction personalisee, on delegue |
|
| 505 | + if ($echapper_html_suspect) { |
|
| 506 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 507 | + $args = [$texte, $options]; |
|
| 508 | + if ($connect or !empty($env)) { |
|
| 509 | + $args[] = $connect; |
|
| 510 | + } |
|
| 511 | + if (!empty($env)) { |
|
| 512 | + $args[] = $env; |
|
| 513 | + } |
|
| 514 | + return $echapper_html_suspect(...$args); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if (is_bool($options)) { |
|
| 518 | + $options = ['strict' => $options]; |
|
| 519 | + } |
|
| 520 | + $strict = $options['strict'] ?? true; |
|
| 521 | + |
|
| 522 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 523 | + if ( |
|
| 524 | + strpos($texte, '<') === false |
|
| 525 | + or strpos($texte, '=') === false |
|
| 526 | + ) { |
|
| 527 | + return $texte; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 531 | + if (!isset($env['espace_prive'])) { |
|
| 532 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 533 | + $env['espace_prive'] = test_espace_prive(); |
|
| 534 | + } |
|
| 535 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 536 | + |
|
| 537 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 538 | + // car sinon on declenche sur les modeles ou ressources |
|
| 539 | + if ( |
|
| 540 | + !$strict and |
|
| 541 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 542 | + ) { |
|
| 543 | + return $texte; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + [$texte, $markid] = modeles_echapper_raccourcis($texte, false); |
|
| 547 | + $texte = echappe_js($texte); |
|
| 548 | + |
|
| 549 | + $texte_to_check = $texte; |
|
| 550 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 551 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 552 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 553 | + if (!empty($options['expanser_liens'])) { |
|
| 554 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 555 | + } |
|
| 556 | + if (!is_html_safe($texte_to_check)) { |
|
| 557 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 558 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 559 | + $texte = str_replace('<', '<', $texte); |
|
| 560 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 561 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 562 | + if (!function_exists('attribut_html')) { |
|
| 563 | + include_spip('inc/filtres'); |
|
| 564 | + } |
|
| 565 | + if (!empty($options['wrap_suspect'])) { |
|
| 566 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 567 | + } |
|
| 568 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 569 | + } |
|
| 570 | + $texte = modele_retablir_raccourcis_echappes($texte, $markid); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // si on est là dans le public c'est le mode parano |
|
| 574 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 575 | + else { |
|
| 576 | + $markid = null; |
|
| 577 | + if (!empty($options['expanser_liens'])) { |
|
| 578 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 579 | + } |
|
| 580 | + else { |
|
| 581 | + [$texte, $markid] = modeles_echapper_raccourcis($texte, false); |
|
| 582 | + } |
|
| 583 | + $texte = safehtml($texte); |
|
| 584 | + if ($markid) { |
|
| 585 | + $texte = modele_retablir_raccourcis_echappes($texte, $markid); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $texte; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -607,30 +607,30 @@ discard block |
||
| 607 | 607 | * Texte sécurisé |
| 608 | 608 | **/ |
| 609 | 609 | function safehtml($t) { |
| 610 | - static $safehtml; |
|
| 611 | - |
|
| 612 | - if (!$t or !is_string($t)) { |
|
| 613 | - return $t; |
|
| 614 | - } |
|
| 615 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 616 | - if (strpos($t, '<') === false) { |
|
| 617 | - return str_replace("\x00", '', $t); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - if (!function_exists('interdire_scripts')) { |
|
| 621 | - include_spip('inc/texte'); |
|
| 622 | - } |
|
| 623 | - $t = interdire_scripts($t); // jolifier le php |
|
| 624 | - $t = echappe_js($t); |
|
| 625 | - |
|
| 626 | - if (!isset($safehtml)) { |
|
| 627 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 628 | - } |
|
| 629 | - if ($safehtml) { |
|
| 630 | - $t = $safehtml($t); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 610 | + static $safehtml; |
|
| 611 | + |
|
| 612 | + if (!$t or !is_string($t)) { |
|
| 613 | + return $t; |
|
| 614 | + } |
|
| 615 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 616 | + if (strpos($t, '<') === false) { |
|
| 617 | + return str_replace("\x00", '', $t); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + if (!function_exists('interdire_scripts')) { |
|
| 621 | + include_spip('inc/texte'); |
|
| 622 | + } |
|
| 623 | + $t = interdire_scripts($t); // jolifier le php |
|
| 624 | + $t = echappe_js($t); |
|
| 625 | + |
|
| 626 | + if (!isset($safehtml)) { |
|
| 627 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 628 | + } |
|
| 629 | + if ($safehtml) { |
|
| 630 | + $t = $safehtml($t); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
@@ -638,20 +638,20 @@ discard block |
||
| 638 | 638 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 639 | 639 | */ |
| 640 | 640 | function is_html_safe(string $texte): bool { |
| 641 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 642 | - return $is_html_safe($texte); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 646 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 647 | - // safehtml reduit aussi potentiellement les |
|
| 648 | - $texte = str_replace(" ", " ", $texte); |
|
| 649 | - $texte_safe = safehtml($texte); |
|
| 650 | - |
|
| 651 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 652 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 653 | - // donc un test d'egalite est trop strict |
|
| 654 | - return strlen($texte_safe) === strlen($texte); |
|
| 641 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 642 | + return $is_html_safe($texte); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 646 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 647 | + // safehtml reduit aussi potentiellement les |
|
| 648 | + $texte = str_replace(" ", " ", $texte); |
|
| 649 | + $texte_safe = safehtml($texte); |
|
| 650 | + |
|
| 651 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 652 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 653 | + // donc un test d'egalite est trop strict |
|
| 654 | + return strlen($texte_safe) === strlen($texte); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -672,13 +672,13 @@ discard block |
||
| 672 | 672 | * Texte sans les modèles d'image |
| 673 | 673 | **/ |
| 674 | 674 | function supprime_img($letexte, $message = null) { |
| 675 | - if ($message === null) { |
|
| 676 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return preg_replace( |
|
| 680 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 681 | - $message, |
|
| 682 | - $letexte |
|
| 683 | - ); |
|
| 675 | + if ($message === null) { |
|
| 676 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return preg_replace( |
|
| 680 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 681 | + $message, |
|
| 682 | + $letexte |
|
| 683 | + ); |
|
| 684 | 684 | } |
@@ -576,8 +576,7 @@ |
||
| 576 | 576 | $markid = null; |
| 577 | 577 | if (!empty($options['expanser_liens'])) { |
| 578 | 578 | $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
| 579 | - } |
|
| 580 | - else { |
|
| 579 | + } else { |
|
| 581 | 580 | [$texte, $markid] = modeles_echapper_raccourcis($texte, false); |
| 582 | 581 | } |
| 583 | 582 | $texte = safehtml($texte); |