/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2012 *
+ * Copyright (c) 2001-2014 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
// http://doc.spip.org/@traiter_echap_code_dist
function traiter_echap_code_dist($regs) {
list(,,$att,$corps) = $regs;
- $echap = htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
+ $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
// ne pas mettre le <div...> s'il n'y a qu'une ligne
if (is_int(strpos($echap,"\n"))) {
return $regs[0];
}
-define('_PROTEGE_BLOCS', ',<(html|code|cadre|frame|script)(\s[^>]*)?>(.*)</\1>,UimsS');
+/**
+ * Traiter les blocs <math></math> echappes par echappe_html
+ * @param $regs
+ * @return string
+ */
+function traiter_echap_math_dist($regs) {
+ // Gestion du TeX
+ if (!function_exists('traiter_math'))
+ include_spip('inc/math');
+
+ $t = traiter_math($regs[0], '');
+ return $t;
+}
+
+define('_PROTEGE_BLOCS', ',<(html|code|cadre|frame|script|math)(\s[^>]*)?>(.*)</\1>,UimsS');
// - pour $source voir commentaire infra (echappe_retour)
// - pour $no_transform voir le filtre post_autobr dans inc/filtres
}
if (($preg OR strpos($letexte,"<")!==false)
- AND preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER))
+ AND preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)) {
foreach ($matches as $regs) {
// echappements tels quels ?
if ($no_transform) {
$p = strpos($letexte,$regs[0]);
$letexte = substr_replace($letexte,code_echappement($echap, $source, $no_transform),$p,strlen($regs[0]));
}
+ }
if ($no_transform)
return $letexte;
// Gestion du TeX
- if (strpos($letexte, "<math>") !== false) {
- include_spip('inc/math');
- $letexte = traiter_math($letexte, $source);
+ // code mort sauf si on a personalise _PROTEGE_BLOCS sans y mettre <math>
+ // eviter la rupture de compat en branche 3.0
+ // a supprimer en branche 3.1
+ if (strpos($preg ? $preg : _PROTEGE_BLOCS,'code')!==false){
+ if (strpos($letexte, "<math>") !== false) {
+ include_spip('inc/math');
+ $letexte = traiter_math($letexte, $source);
+ }
}
// Echapper le php pour faire joli (ici, c'est pas pour la securite)
- if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
- $letexte, $matches, PREG_SET_ORDER))
- foreach ($matches as $regs) {
- $letexte = str_replace($regs[0],
- code_echappement(highlight_string($regs[0],true), $source),
- $letexte);
+ // seulement si on a echappe les <script>
+ // (derogatoire car on ne peut pas faire passer < ? ... ? >
+ // dans une callback autonommee
+ if (strpos($preg ? $preg : _PROTEGE_BLOCS,'script')!==false){
+ if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
+ $letexte, $matches, PREG_SET_ORDER))
+ foreach ($matches as $regs) {
+ $letexte = str_replace($regs[0],
+ code_echappement(highlight_string($regs[0],true), $source),
+ $letexte);
+ }
}
return $letexte;
// http://doc.spip.org/@echappe_retour
function echappe_retour($letexte, $source='', $filtre = "") {
if (strpos($letexte,"base64$source")) {
- # spip_log(htmlspecialchars($letexte)); ## pour les curieux
- if (strpos($letexte,"<")!==false AND
+ # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux
+ $max_prof = 5;
+ while (strpos($letexte,"<")!==false
+ AND
preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
- $letexte, $regs, PREG_SET_ORDER)) {
+ $letexte, $regs, PREG_SET_ORDER)
+ AND $max_prof--) {
foreach ($regs as $reg) {
$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
// recherche d'attributs supplementaires