@@ -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,66 +46,66 @@ 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 | - if ($fermeture_lien) { |
|
| 87 | - $mod = rtrim(substr($mod, 0, -strlen($fermeture_lien))); |
|
| 88 | - } |
|
| 89 | - $lien = false; |
|
| 90 | - $longueur = strlen($mod); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $modele = [ |
|
| 94 | - 'modele' => $mod, |
|
| 95 | - 'pos' => $a, |
|
| 96 | - 'length' => $longueur, |
|
| 97 | - 'type' => $type, |
|
| 98 | - 'id' => $id, |
|
| 99 | - 'params' => $params, |
|
| 100 | - 'lien' => $lien, |
|
| 101 | - ]; |
|
| 102 | - |
|
| 103 | - $modeles[] = $modele; |
|
| 104 | - } |
|
| 105 | - $pos = $a + strlen((string)$match[0]); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - 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 | + if ($fermeture_lien) { |
|
| 87 | + $mod = rtrim(substr($mod, 0, -strlen($fermeture_lien))); |
|
| 88 | + } |
|
| 89 | + $lien = false; |
|
| 90 | + $longueur = strlen($mod); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $modele = [ |
|
| 94 | + 'modele' => $mod, |
|
| 95 | + 'pos' => $a, |
|
| 96 | + 'length' => $longueur, |
|
| 97 | + 'type' => $type, |
|
| 98 | + 'id' => $id, |
|
| 99 | + 'params' => $params, |
|
| 100 | + 'lien' => $lien, |
|
| 101 | + ]; |
|
| 102 | + |
|
| 103 | + $modeles[] = $modele; |
|
| 104 | + } |
|
| 105 | + $pos = $a + strlen((string)$match[0]); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + return $modeles; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -119,24 +119,24 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | function modeles_echapper_raccourcis($texte, bool $collecter_liens = false) { |
| 121 | 121 | |
| 122 | - $modeles = modeles_collecter($texte, $collecter_liens); |
|
| 123 | - $markid = ''; |
|
| 124 | - if (!empty($modeles)) { |
|
| 125 | - // generer un marqueur qui n'est pas dans le texte |
|
| 126 | - do { |
|
| 127 | - $markid = substr(md5(creer_uniqid()), 0, 7); |
|
| 128 | - $markid = "@|MODELE$markid|"; |
|
| 129 | - } while (strpos($texte, $markid) !== false); |
|
| 130 | - |
|
| 131 | - $offset_pos = 0; |
|
| 132 | - foreach ($modeles as $m) { |
|
| 133 | - $rempl = $markid . base64_encode($m['modele']) . '|@'; |
|
| 134 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 135 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return [$texte, $markid]; |
|
| 122 | + $modeles = modeles_collecter($texte, $collecter_liens); |
|
| 123 | + $markid = ''; |
|
| 124 | + if (!empty($modeles)) { |
|
| 125 | + // generer un marqueur qui n'est pas dans le texte |
|
| 126 | + do { |
|
| 127 | + $markid = substr(md5(creer_uniqid()), 0, 7); |
|
| 128 | + $markid = "@|MODELE$markid|"; |
|
| 129 | + } while (strpos($texte, $markid) !== false); |
|
| 130 | + |
|
| 131 | + $offset_pos = 0; |
|
| 132 | + foreach ($modeles as $m) { |
|
| 133 | + $rempl = $markid . base64_encode($m['modele']) . '|@'; |
|
| 134 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 135 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return [$texte, $markid]; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -149,24 +149,24 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function modele_retablir_raccourcis_echappes(string $texte, string $markid) { |
| 151 | 151 | |
| 152 | - if ($markid) { |
|
| 153 | - $pos = 0; |
|
| 154 | - while ( |
|
| 155 | - ($p = strpos($texte, $markid, $pos)) !== false |
|
| 156 | - and $end = strpos($texte, '|@', $p + 16) |
|
| 157 | - ) { |
|
| 158 | - $base64 = substr($texte, $p + 16, $end - ($p + 16)); |
|
| 159 | - if ($modele = base64_decode($base64, true)) { |
|
| 160 | - $texte = substr_replace($texte, $modele, $p, $end + 2 - $p); |
|
| 161 | - $pos = $p + strlen($modele); |
|
| 162 | - } |
|
| 163 | - else { |
|
| 164 | - $pos = $end; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return $texte; |
|
| 152 | + if ($markid) { |
|
| 153 | + $pos = 0; |
|
| 154 | + while ( |
|
| 155 | + ($p = strpos($texte, $markid, $pos)) !== false |
|
| 156 | + and $end = strpos($texte, '|@', $p + 16) |
|
| 157 | + ) { |
|
| 158 | + $base64 = substr($texte, $p + 16, $end - ($p + 16)); |
|
| 159 | + if ($modele = base64_decode($base64, true)) { |
|
| 160 | + $texte = substr_replace($texte, $modele, $p, $end + 2 - $p); |
|
| 161 | + $pos = $p + strlen($modele); |
|
| 162 | + } |
|
| 163 | + else { |
|
| 164 | + $pos = $end; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return $texte; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -181,82 +181,82 @@ discard block |
||
| 181 | 181 | * @return string |
| 182 | 182 | */ |
| 183 | 183 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
| 184 | - // preserver la compatibilite : true = recherche des documents |
|
| 185 | - if ($doublons === true) { |
|
| 186 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $modeles = modeles_collecter($texte, true); |
|
| 190 | - if (!empty($modeles)) { |
|
| 191 | - include_spip('public/assembler'); |
|
| 192 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 193 | - |
|
| 194 | - $offset_pos = 0; |
|
| 195 | - foreach ($modeles as $m) { |
|
| 196 | - // calculer le modele |
|
| 197 | - # hack indexation |
|
| 198 | - if ($doublons) { |
|
| 199 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 200 | - } # version normale |
|
| 201 | - else { |
|
| 202 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 203 | - // dans les parametres, plutot que les liens echappes |
|
| 204 | - $params = $m['params']; |
|
| 205 | - if (!is_null($liens)) { |
|
| 206 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 210 | - |
|
| 211 | - // en cas d'echec, |
|
| 212 | - // si l'objet demande a une url, |
|
| 213 | - // creer un petit encadre vers elle |
|
| 214 | - if ($modele === false) { |
|
| 215 | - $modele = $m['modele']; |
|
| 216 | - |
|
| 217 | - if (!is_null($liens)) { |
|
| 218 | - $modele = str_replace($liens[0], $liens[1], $modele); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 222 | - |
|
| 223 | - if (!empty($m['lien'])) { |
|
| 224 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 225 | - $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 226 | - $contexte['lien_class'] = $m['lien']['class']; |
|
| 227 | - $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 228 | - $contexte['lien_title'] = $m['lien']['title']; |
|
| 229 | - $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - // le remplacer dans le texte |
|
| 236 | - if ($modele !== false) { |
|
| 237 | - $modele = protege_js_modeles($modele); |
|
| 238 | - |
|
| 239 | - if ($wrap_embed_html) { |
|
| 240 | - $modele = $wrap_embed_html($m['modele'], $modele); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $rempl = code_echappement($modele, $echap); |
|
| 244 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 245 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // hack pour tout l'espace prive |
|
| 250 | - if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 251 | - $type = strtolower($m['type']); |
|
| 252 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 253 | - if (in_array($type, $modeles)) { |
|
| 254 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return $texte; |
|
| 184 | + // preserver la compatibilite : true = recherche des documents |
|
| 185 | + if ($doublons === true) { |
|
| 186 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $modeles = modeles_collecter($texte, true); |
|
| 190 | + if (!empty($modeles)) { |
|
| 191 | + include_spip('public/assembler'); |
|
| 192 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 193 | + |
|
| 194 | + $offset_pos = 0; |
|
| 195 | + foreach ($modeles as $m) { |
|
| 196 | + // calculer le modele |
|
| 197 | + # hack indexation |
|
| 198 | + if ($doublons) { |
|
| 199 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 200 | + } # version normale |
|
| 201 | + else { |
|
| 202 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 203 | + // dans les parametres, plutot que les liens echappes |
|
| 204 | + $params = $m['params']; |
|
| 205 | + if (!is_null($liens)) { |
|
| 206 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 210 | + |
|
| 211 | + // en cas d'echec, |
|
| 212 | + // si l'objet demande a une url, |
|
| 213 | + // creer un petit encadre vers elle |
|
| 214 | + if ($modele === false) { |
|
| 215 | + $modele = $m['modele']; |
|
| 216 | + |
|
| 217 | + if (!is_null($liens)) { |
|
| 218 | + $modele = str_replace($liens[0], $liens[1], $modele); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 222 | + |
|
| 223 | + if (!empty($m['lien'])) { |
|
| 224 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 225 | + $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 226 | + $contexte['lien_class'] = $m['lien']['class']; |
|
| 227 | + $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 228 | + $contexte['lien_title'] = $m['lien']['title']; |
|
| 229 | + $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + // le remplacer dans le texte |
|
| 236 | + if ($modele !== false) { |
|
| 237 | + $modele = protege_js_modeles($modele); |
|
| 238 | + |
|
| 239 | + if ($wrap_embed_html) { |
|
| 240 | + $modele = $wrap_embed_html($m['modele'], $modele); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $rempl = code_echappement($modele, $echap); |
|
| 244 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 245 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // hack pour tout l'espace prive |
|
| 250 | + if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 251 | + $type = strtolower($m['type']); |
|
| 252 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 253 | + if (in_array($type, $modeles)) { |
|
| 254 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return $texte; |
|
| 262 | 262 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | '(<([a-z_-]{3,})' # <modele |
| 27 | 27 | . '\s*([0-9]*)\s*' # id |
| 28 | 28 | . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
| 29 | - . '\s*/?' . '>)' # fin du modele > |
|
| 29 | + . '\s*/?'.'>)' # fin du modele > |
|
| 30 | 30 | ); |
| 31 | 31 | |
| 32 | 32 | define( |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | . '\s*(<\/a>)?' # eventuel </a> |
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | -define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
|
| 38 | +define('_RACCOURCI_MODELE_DEBUT', '@^'._RACCOURCI_MODELE.'@isS'); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Detecter et collecter les modeles d'un texte dans un tableau descriptif |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $pos = 0; |
| 56 | 56 | // Recuperer l'appel complet (y compris un eventuel lien) |
| 57 | 57 | foreach ($matches as $match) { |
| 58 | - $a = strpos($texte, (string)$match[0], $pos); |
|
| 58 | + $a = strpos($texte, (string) $match[0], $pos); |
|
| 59 | 59 | |
| 60 | 60 | if (preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs)) { |
| 61 | 61 | // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $modeles[] = $modele; |
| 104 | 104 | } |
| 105 | - $pos = $a + strlen((string)$match[0]); |
|
| 105 | + $pos = $a + strlen((string) $match[0]); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | return $modeles; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | $offset_pos = 0; |
| 132 | 132 | foreach ($modeles as $m) { |
| 133 | - $rempl = $markid . base64_encode($m['modele']) . '|@'; |
|
| 133 | + $rempl = $markid.base64_encode($m['modele']).'|@'; |
|
| 134 | 134 | $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
| 135 | 135 | $offset_pos += strlen($rempl) - $m['length']; |
| 136 | 136 | } |
@@ -159,8 +159,7 @@ |
||
| 159 | 159 | if ($modele = base64_decode($base64, true)) { |
| 160 | 160 | $texte = substr_replace($texte, $modele, $p, $end + 2 - $p); |
| 161 | 161 | $pos = $p + strlen($modele); |
| 162 | - } |
|
| 163 | - else { |
|
| 162 | + } else { |
|
| 164 | 163 | $pos = $end; |
| 165 | 164 | } |
| 166 | 165 | } |
@@ -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 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect ?? '', null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte, [], $connect, $env); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,40 +415,40 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - $env['espace_prive'] = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$t) { |
|
| 432 | - return strval($t); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | - // avant echappement des balises <html> |
|
| 437 | - // https://core.spip.net/issues/3371 |
|
| 438 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | - // https://core.spip.net/issues/4166 |
|
| 440 | - if ( |
|
| 441 | - $interdire_script |
|
| 442 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | - or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | - ) { |
|
| 446 | - $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | - } |
|
| 448 | - $t = echappe_html($t); |
|
| 449 | - $t = expanser_liens($t, $connect, $env); |
|
| 450 | - $t = traiter_raccourcis($t); |
|
| 451 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | - |
|
| 453 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + $env['espace_prive'] = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$t) { |
|
| 432 | + return strval($t); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 436 | + // avant echappement des balises <html> |
|
| 437 | + // https://core.spip.net/issues/3371 |
|
| 438 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 439 | + // https://core.spip.net/issues/4166 |
|
| 440 | + if ( |
|
| 441 | + $interdire_script |
|
| 442 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 443 | + or (!empty($env['espace_prive']) and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + or (!empty($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 445 | + ) { |
|
| 446 | + $t = echapper_html_suspect($t, ['strict' => false], $connect, $env); |
|
| 447 | + } |
|
| 448 | + $t = echappe_html($t); |
|
| 449 | + $t = expanser_liens($t, $connect, $env); |
|
| 450 | + $t = traiter_raccourcis($t); |
|
| 451 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 452 | + |
|
| 453 | + return $t; |
|
| 454 | 454 | } |
@@ -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 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | // celle du texte) et public (spip_lang est la langue du texte) |
| 45 | 45 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 48 | 48 | if ($dir == 'rtl') { |
| 49 | 49 | $p .= '_rtl'; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | if (!isset($GLOBALS[$p])) { |
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $GLOBALS[$p]; |
@@ -68,7 +68,7 @@ discard block |
||
| 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 | // |
@@ -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, ['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 |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | ) { |
| 121 | 121 | foreach ($matches as $m) { |
| 122 | 122 | if ($m[1] === 'code') { |
| 123 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 123 | + $code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>'; |
|
| 124 | 124 | $pre = str_replace($m[0], $code, $pre); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | // Echapper les <code>...</ code> |
| 132 | 132 | function traiter_echap_code_dist($regs, $options = []) { |
| 133 | - [, , $att, $corps] = $regs; |
|
| 133 | + [,, $att, $corps] = $regs; |
|
| 134 | 134 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 135 | 135 | |
| 136 | 136 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | $echap = nl2br($echap); |
| 142 | 142 | $echap = "<div style='text-align: left;' " |
| 143 | 143 | . "class='spip_code' dir='ltr'><code$att>" |
| 144 | - . $echap . '</code></div>'; |
|
| 144 | + . $echap.'</code></div>'; |
|
| 145 | 145 | } else { |
| 146 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 146 | + $echap = "<code$att class='spip_code' dir='ltr'>".$echap.'</code>'; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | $echap = str_replace("\t", ' ', $echap); |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | else { |
| 221 | 221 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 222 | 222 | if ( |
| 223 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 224 | - or function_exists($f = $f . '_dist') |
|
| 223 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 224 | + or function_exists($f = $f.'_dist') |
|
| 225 | 225 | or ($callback_secure_prefix and ( |
| 226 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 227 | - or function_exists($f = $f . '_dist') |
|
| 226 | + function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 227 | + or function_exists($f = $f.'_dist') |
|
| 228 | 228 | )) |
| 229 | 229 | ) { |
| 230 | 230 | $echap = $f($regs, $callback_options); |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | // dans une callback autonommee |
| 247 | 247 | if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
| 248 | 248 | if ( |
| 249 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 249 | + strpos($letexte, '<'.'?') !== false and preg_match_all( |
|
| 250 | 250 | ',<[?].*($|[?]>),UisS', |
| 251 | 251 | $letexte, |
| 252 | 252 | $matches, |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | strpos($letexte, '<') !== false |
| 279 | 279 | and |
| 280 | 280 | preg_match_all( |
| 281 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 281 | + ',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 282 | 282 | $letexte, |
| 283 | 283 | $regs, |
| 284 | 284 | PREG_SET_ORDER |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | if ($at) { |
| 298 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 298 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 299 | 299 | foreach ($at as $attr => $a) { |
| 300 | 300 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 301 | 301 | } |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | $texte = nettoyer_raccourcis_typo($texte); |
| 377 | 377 | |
| 378 | 378 | // balises de sauts de ligne et paragraphe |
| 379 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 380 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 379 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r", $texte); |
|
| 380 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 381 | 381 | |
| 382 | 382 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 383 | 383 | $texte = str_replace("\n\n", "\r", $texte); |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | // supprimer les tags |
| 386 | 386 | $texte = supprimer_tags($texte); |
| 387 | 387 | $texte = trim(str_replace("\n", ' ', $texte)); |
| 388 | - $texte .= "\n"; // marquer la fin |
|
| 388 | + $texte .= "\n"; // marquer la fin |
|
| 389 | 389 | |
| 390 | 390 | // corriger la longueur de coupe |
| 391 | 391 | // en fonction de la presence de caracteres utf |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | // couper au mot precedent |
| 401 | 401 | $long = spip_substr($texte, 0, max($taille - 4, 1)); |
| 402 | 402 | $u = $GLOBALS['meta']['pcre_u']; |
| 403 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 403 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 404 | 404 | if (is_null($suite)) { |
| 405 | 405 | $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
| 406 | 406 | } |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 411 | 411 | $points = ''; |
| 412 | 412 | $long = spip_substr($texte, 0, $taille); |
| 413 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 413 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 414 | 414 | // encore trop court ? couper au caractere |
| 415 | 415 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 416 | 416 | $texte = $long; |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | // supprimer l'eventuelle entite finale mal coupee |
| 430 | 430 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 431 | 431 | |
| 432 | - return quote_amp(trim($texte)) . $points; |
|
| 432 | + return quote_amp(trim($texte)).$points; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -441,16 +441,16 @@ discard block |
||
| 441 | 441 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 442 | 442 | } |
| 443 | 443 | foreach ($r as $regs) { |
| 444 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 444 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 447 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 448 | 448 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 449 | 449 | include_spip('inc/acces'); |
| 450 | 450 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 451 | 451 | } |
| 452 | 452 | foreach ($r as $regs) { |
| 453 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 453 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | 456 | } |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | if (!empty($options['wrap_suspect'])) { |
| 566 | 566 | $texte = wrap($texte, $options['wrap_suspect']); |
| 567 | 567 | } |
| 568 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 568 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 569 | 569 | } |
| 570 | 570 | $texte = modele_retablir_raccourcis_echappes($texte, $markid); |
| 571 | 571 | } |
@@ -673,11 +673,11 @@ discard block |
||
| 673 | 673 | **/ |
| 674 | 674 | function supprime_img($letexte, $message = null) { |
| 675 | 675 | if ($message === null) { |
| 676 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 676 | + $message = '('._T('img_indisponible').')'; |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | return preg_replace( |
| 680 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 680 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 681 | 681 | $message, |
| 682 | 682 | $letexte |
| 683 | 683 | ); |
@@ -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); |
@@ -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 | include_spip('base/abstract_sql'); |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | 38 | function inc_lien_dist( |
| 39 | - $lien, |
|
| 40 | - $texte = '', |
|
| 41 | - $class = '', |
|
| 42 | - $title = '', |
|
| 43 | - $hlang = '', |
|
| 44 | - $rel = '', |
|
| 45 | - string $connect = '', |
|
| 46 | - $env = [] |
|
| 39 | + $lien, |
|
| 40 | + $texte = '', |
|
| 41 | + $class = '', |
|
| 42 | + $title = '', |
|
| 43 | + $hlang = '', |
|
| 44 | + $rel = '', |
|
| 45 | + string $connect = '', |
|
| 46 | + $env = [] |
|
| 47 | 47 | ) { |
| 48 | - return $lien; |
|
| 48 | + return $lien; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
@@ -56,28 +56,28 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | function expanser_liens($t, string $connect = '', $env = []) { |
| 58 | 58 | |
| 59 | - $t = pipeline('pre_liens', $t); |
|
| 59 | + $t = pipeline('pre_liens', $t); |
|
| 60 | 60 | |
| 61 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 62 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 63 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 61 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 62 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 63 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 64 | 64 | |
| 65 | - return $t; |
|
| 65 | + return $t; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Meme analyse mais pour eliminer les liens |
| 69 | 69 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 70 | 70 | function nettoyer_raccourcis_typo($texte, string $connect = '') { |
| 71 | - return $texte; |
|
| 71 | + return $texte; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 75 | 75 | // la langue et la bulle eventuelles |
| 76 | 76 | function traiter_raccourci_lien_atts($texte) { |
| 77 | - $bulle = ''; |
|
| 78 | - $hlang = ''; |
|
| 77 | + $bulle = ''; |
|
| 78 | + $hlang = ''; |
|
| 79 | 79 | |
| 80 | - return [trim($texte), $bulle, $hlang]; |
|
| 80 | + return [trim($texte), $bulle, $hlang]; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * @return string |
| 94 | 94 | */ |
| 95 | 95 | function virtuel_redirige($virtuel, $url = false) { |
| 96 | - return $virtuel; |
|
| 96 | + return $virtuel; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Cherche un lien du type [->raccourci 123] |
@@ -106,62 +106,62 @@ discard block |
||
| 106 | 106 | // 'url': seulement U (i.e. generer_url_RACCOURCI) |
| 107 | 107 | |
| 108 | 108 | function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 109 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 109 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 110 | 110 | |
| 111 | - return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 111 | + return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 115 | 115 | |
| 116 | 116 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 117 | - if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 118 | - return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $lien = entites_html(trim($ref)); |
|
| 122 | - |
|
| 123 | - // Liens explicites |
|
| 124 | - if (!$texte) { |
|
| 125 | - $texte = str_replace('"', '', $lien); |
|
| 126 | - // evite l'affichage de trops longues urls. |
|
| 127 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 128 | - $texte = $lien_court($texte); |
|
| 129 | - if ($echappe_typo) { |
|
| 130 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // petites corrections d'URL |
|
| 135 | - if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 136 | - $lien = 'http://' . $lien; |
|
| 137 | - } else { |
|
| 138 | - if (strpos($lien, '@') && email_valide($lien)) { |
|
| 139 | - if (!$texte) { |
|
| 140 | - $texte = $lien; |
|
| 141 | - } |
|
| 142 | - $lien = 'mailto:' . $lien; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ($pour == 'url') { |
|
| 147 | - return $lien; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - if ($pour == 'titre') { |
|
| 151 | - return $texte; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return ['url' => $lien, 'titre' => $texte]; |
|
| 117 | + if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 118 | + return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $lien = entites_html(trim($ref)); |
|
| 122 | + |
|
| 123 | + // Liens explicites |
|
| 124 | + if (!$texte) { |
|
| 125 | + $texte = str_replace('"', '', $lien); |
|
| 126 | + // evite l'affichage de trops longues urls. |
|
| 127 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 128 | + $texte = $lien_court($texte); |
|
| 129 | + if ($echappe_typo) { |
|
| 130 | + $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // petites corrections d'URL |
|
| 135 | + if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 136 | + $lien = 'http://' . $lien; |
|
| 137 | + } else { |
|
| 138 | + if (strpos($lien, '@') && email_valide($lien)) { |
|
| 139 | + if (!$texte) { |
|
| 140 | + $texte = $lien; |
|
| 141 | + } |
|
| 142 | + $lien = 'mailto:' . $lien; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ($pour == 'url') { |
|
| 147 | + return $lien; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + if ($pour == 'titre') { |
|
| 151 | + return $texte; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return ['url' => $lien, 'titre' => $texte]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 158 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 159 | - $url = $f($texte, $id); |
|
| 160 | - } else { |
|
| 161 | - $url = glossaire_std($texte); |
|
| 162 | - } |
|
| 158 | + if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 159 | + $url = $f($texte, $id); |
|
| 160 | + } else { |
|
| 161 | + $url = glossaire_std($texte); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $url; |
|
| 164 | + return $url; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -183,74 +183,74 @@ discard block |
||
| 183 | 183 | * @return array|bool|string |
| 184 | 184 | */ |
| 185 | 185 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') { |
| 186 | - $cible = $GLOBALS['lien_implicite_cible_public'] ?? null; |
|
| 187 | - if (!($match = typer_raccourci($ref))) { |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 192 | - |
|
| 193 | - # attention dans le cas des sites le lien doit pointer non pas sur |
|
| 194 | - # la page locale du site, mais directement sur le site lui-meme |
|
| 195 | - $url = ''; |
|
| 196 | - if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 197 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (!$url) { |
|
| 201 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if (!$url) { |
|
| 205 | - return false; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (is_array($url)) { |
|
| 209 | - [$type, $id] = array_pad($url, 2, null); |
|
| 210 | - $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($pour === 'url') { |
|
| 214 | - return $url; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 218 | - if ($r) { |
|
| 219 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if ($texte = trim($texte)) { |
|
| 223 | - $r['titre'] = $texte; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if (!@$r['titre']) { |
|
| 227 | - $r['titre'] = _T($type) . " $id"; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ($pour == 'titre') { |
|
| 231 | - return $r['titre']; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $r['url'] = $url; |
|
| 235 | - |
|
| 236 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 237 | - if ( |
|
| 238 | - $type == 'document' |
|
| 239 | - and $mime = sql_getfetsel( |
|
| 240 | - 'mime_type', |
|
| 241 | - 'spip_types_documents', |
|
| 242 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 243 | - '', |
|
| 244 | - '', |
|
| 245 | - '', |
|
| 246 | - '', |
|
| 247 | - $connect |
|
| 248 | - ) |
|
| 249 | - ) { |
|
| 250 | - $r['mime'] = $mime; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - return $r; |
|
| 186 | + $cible = $GLOBALS['lien_implicite_cible_public'] ?? null; |
|
| 187 | + if (!($match = typer_raccourci($ref))) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 192 | + |
|
| 193 | + # attention dans le cas des sites le lien doit pointer non pas sur |
|
| 194 | + # la page locale du site, mais directement sur le site lui-meme |
|
| 195 | + $url = ''; |
|
| 196 | + if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 197 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (!$url) { |
|
| 201 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if (!$url) { |
|
| 205 | + return false; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (is_array($url)) { |
|
| 209 | + [$type, $id] = array_pad($url, 2, null); |
|
| 210 | + $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? ''); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($pour === 'url') { |
|
| 214 | + return $url; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 218 | + if ($r) { |
|
| 219 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if ($texte = trim($texte)) { |
|
| 223 | + $r['titre'] = $texte; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if (!@$r['titre']) { |
|
| 227 | + $r['titre'] = _T($type) . " $id"; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ($pour == 'titre') { |
|
| 231 | + return $r['titre']; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $r['url'] = $url; |
|
| 235 | + |
|
| 236 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 237 | + if ( |
|
| 238 | + $type == 'document' |
|
| 239 | + and $mime = sql_getfetsel( |
|
| 240 | + 'mime_type', |
|
| 241 | + 'spip_types_documents', |
|
| 242 | + 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 243 | + '', |
|
| 244 | + '', |
|
| 245 | + '', |
|
| 246 | + '', |
|
| 247 | + $connect |
|
| 248 | + ) |
|
| 249 | + ) { |
|
| 250 | + $r['mime'] = $mime; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + return $r; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -258,43 +258,43 @@ discard block |
||
| 258 | 258 | define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S'); |
| 259 | 259 | |
| 260 | 260 | function typer_raccourci($lien) { |
| 261 | - if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 262 | - return []; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $f = $match[1]; |
|
| 266 | - // valeur par defaut et alias historiques |
|
| 267 | - if (!$f) { |
|
| 268 | - $f = 'article'; |
|
| 269 | - } else { |
|
| 270 | - if ($f == 'art') { |
|
| 271 | - $f = 'article'; |
|
| 272 | - } else { |
|
| 273 | - if ($f == 'br') { |
|
| 274 | - $f = 'breve'; |
|
| 275 | - } else { |
|
| 276 | - if ($f == 'rub') { |
|
| 277 | - $f = 'rubrique'; |
|
| 278 | - } else { |
|
| 279 | - if ($f == 'aut') { |
|
| 280 | - $f = 'auteur'; |
|
| 281 | - } else { |
|
| 282 | - if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 283 | - $f = 'document'; |
|
| 284 | - } else { |
|
| 285 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 286 | - $f = 'breve'; # accents :( |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $match[0] = $f; |
|
| 296 | - |
|
| 297 | - return $match; |
|
| 261 | + if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 262 | + return []; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $f = $match[1]; |
|
| 266 | + // valeur par defaut et alias historiques |
|
| 267 | + if (!$f) { |
|
| 268 | + $f = 'article'; |
|
| 269 | + } else { |
|
| 270 | + if ($f == 'art') { |
|
| 271 | + $f = 'article'; |
|
| 272 | + } else { |
|
| 273 | + if ($f == 'br') { |
|
| 274 | + $f = 'breve'; |
|
| 275 | + } else { |
|
| 276 | + if ($f == 'rub') { |
|
| 277 | + $f = 'rubrique'; |
|
| 278 | + } else { |
|
| 279 | + if ($f == 'aut') { |
|
| 280 | + $f = 'auteur'; |
|
| 281 | + } else { |
|
| 282 | + if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 283 | + $f = 'document'; |
|
| 284 | + } else { |
|
| 285 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 286 | + $f = 'breve'; # accents :( |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $match[0] = $f; |
|
| 296 | + |
|
| 297 | + return $match; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -309,44 +309,44 @@ discard block |
||
| 309 | 309 | * } |
| 310 | 310 | **/ |
| 311 | 311 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 312 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 313 | - $desc = $trouver_table(table_objet($type)); |
|
| 312 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 313 | + $desc = $trouver_table(table_objet($type)); |
|
| 314 | 314 | |
| 315 | - if (!($desc and $s = $desc['titre'])) { |
|
| 316 | - return []; |
|
| 317 | - } |
|
| 315 | + if (!($desc and $s = $desc['titre'])) { |
|
| 316 | + return []; |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 320 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 319 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 320 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 321 | 321 | |
| 322 | - if (!$r) { |
|
| 323 | - return []; |
|
| 324 | - } |
|
| 322 | + if (!$r) { |
|
| 323 | + return []; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 326 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 327 | 327 | |
| 328 | - if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 329 | - $r['titre'] = $r['surnom']; |
|
| 330 | - } |
|
| 328 | + if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 329 | + $r['titre'] = $r['surnom']; |
|
| 330 | + } |
|
| 331 | 331 | |
| 332 | - if (!isset($r['lang'])) { |
|
| 333 | - $r['lang'] = ''; |
|
| 334 | - } |
|
| 332 | + if (!isset($r['lang'])) { |
|
| 333 | + $r['lang'] = ''; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - return $r; |
|
| 336 | + return $r; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // |
| 340 | 340 | // Raccourcis ancre [#ancre<-] |
| 341 | 341 | // |
| 342 | 342 | function traiter_raccourci_ancre($letexte) { |
| 343 | - return $letexte; |
|
| 343 | + return $letexte; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | function traiter_raccourci_glossaire($texte) { |
| 347 | - return $texte; |
|
| 347 | + return $texte; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | function glossaire_std($terme) { |
| 351 | - return $terme; |
|
| 351 | + return $terme; |
|
| 352 | 352 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
|
| 114 | +define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS'); |
|
| 115 | 115 | |
| 116 | 116 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 117 | 117 | if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
@@ -127,19 +127,19 @@ discard block |
||
| 127 | 127 | $lien_court = charger_fonction('lien_court', 'inc'); |
| 128 | 128 | $texte = $lien_court($texte); |
| 129 | 129 | if ($echappe_typo) { |
| 130 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 130 | + $texte = '<html>'.quote_amp($texte).'</html>'; |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // petites corrections d'URL |
| 135 | 135 | if (preg_match('/^www\.[^@]+$/S', $lien)) { |
| 136 | - $lien = 'http://' . $lien; |
|
| 136 | + $lien = 'http://'.$lien; |
|
| 137 | 137 | } else { |
| 138 | 138 | if (strpos($lien, '@') && email_valide($lien)) { |
| 139 | 139 | if (!$texte) { |
| 140 | 140 | $texte = $lien; |
| 141 | 141 | } |
| 142 | - $lien = 'mailto:' . $lien; |
|
| 142 | + $lien = 'mailto:'.$lien; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 158 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 158 | + if (function_exists($f = 'glossaire_'.$ancre)) { |
|
| 159 | 159 | $url = $f($texte, $id); |
| 160 | 160 | } else { |
| 161 | 161 | $url = glossaire_std($texte); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | return false; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 191 | + [$type,, $id,, $args,, $ancre] = array_pad($match, 7, null); |
|
| 192 | 192 | |
| 193 | 193 | # attention dans le cas des sites le lien doit pointer non pas sur |
| 194 | 194 | # la page locale du site, mais directement sur le site lui-meme |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | if (!@$r['titre']) { |
| 227 | - $r['titre'] = _T($type) . " $id"; |
|
| 227 | + $r['titre'] = _T($type)." $id"; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | if ($pour == 'titre') { |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | and $mime = sql_getfetsel( |
| 240 | 240 | 'mime_type', |
| 241 | 241 | 'spip_types_documents', |
| 242 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 242 | + 'extension IN ('.sql_get_select('extension', 'spip_documents', 'id_document='.sql_quote($id)).')', |
|
| 243 | 243 | '', |
| 244 | 244 | '', |
| 245 | 245 | '', |