From 1874bb29db64f594c13f39352be5c87430af172f Mon Sep 17 00:00:00 2001 From: Cerdic <cedric@yterium.com> Date: Fri, 29 Sep 2017 14:57:02 +0000 Subject: [PATCH] Suite de r23719 : les fonctions _T et _L prennent une option sanitize qui par defaut vaut true pour dire qu'on veut nettoyer le html suspect des arguments des chaines de langue passer cette option a false permet de debrayer ce nettoyage pour les cas ou ils poserait probleme (exceptions) --- ecrire/inc/utils.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php index e2ac3d1e3f..9f86eb6767 100644 --- a/ecrire/inc/utils.php +++ b/ecrire/inc/utils.php @@ -744,12 +744,13 @@ function test_plugin_actif($plugin) { * @param array $options * - string class : nom d'une classe a ajouter sur un span pour encapsuler la chaine * - bool force : forcer un retour meme si la chaine n'a pas de traduction + * - bool sanitize : nettoyer le html suspect dans les arguments * @return string * Texte */ function _T($texte, $args = array(), $options = array()) { static $traduire = false; - $o = array('class' => '', 'force' => true); + $o = array('class' => '', 'force' => true, 'sanitize' => true); if ($options) { // support de l'ancien argument $class if (is_string($options)) { @@ -792,7 +793,7 @@ function _T($texte, $args = array(), $options = array()) { } - return _L($text, $args, $o['class']); + return _L($text, $args, $o); } @@ -813,13 +814,18 @@ function _T($texte, $args = array(), $options = array()) { * Texte * @param array $args * Couples (variable => valeur) Ã transformer dans le texte - * @param string|null $class - * Encapsule les valeurs dans un span avec cette classe si transmis. + * @param array $options + * - string class : nom d'une classe a ajouter sur un span pour encapsuler la chaine + * - bool sanitize : nettoyer le html suspect dans les arguments * @return string * Texte */ -function _L($text, $args = array(), $class = null) { +function _L($text, $args = array(), $options = array()) { $f = $text; + if ($options and is_string($options)) { + // support de l'ancien argument $class + $options = array('class' => $options); + } if (is_array($args)) { if (!function_exists('interdire_scripts')) { include_spip('inc/texte'); @@ -828,10 +834,12 @@ function _L($text, $args = array(), $class = null) { include_spip('inc/texte_mini'); } foreach ($args as $name => $value) { - $value = echapper_html_suspect($value); - $value = interdire_scripts($value, -1); - if ($class) { - $value = "<span class='$class'>$value</span>"; + if (!isset($options['sanitize']) or $options['sanitize']) { + $value = echapper_html_suspect($value); + $value = interdire_scripts($value, -1); + } + if (isset($options['class']) and $options['class']) { + $value = "<span class='".$options['class']."'>$value</span>"; } $t = str_replace("@$name@", $value, $text); if ($text !== $t) { @@ -846,7 +854,7 @@ function _L($text, $args = array(), $class = null) { } } - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and $class === null) { + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and (!isset($options['class']) or !$options['class'])) { return "<span class=debug-traduction-erreur>$text</span>"; } else { return $text; -- GitLab