From 17f4b82821695fba5317cb98dc86a692ccc11015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 19 Aug 2011 10:35:00 +0200 Subject: [PATCH] Factor out code escaping from echo --- libraries/js_escape.lib.php | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/libraries/js_escape.lib.php b/libraries/js_escape.lib.php index 656794f819..25fb5bfbc7 100644 --- a/libraries/js_escape.lib.php +++ b/libraries/js_escape.lib.php @@ -57,24 +57,41 @@ function PMA_escapeJsString($string) } /** - * Prints an javascript assignment with proper escaping of a value + * Formats an javascript assignment with proper escaping of a value * and support for assigning array of strings. * * @param string $key Name of value to set * @param mixed $value Value to set, can be either string or array of strings + * + * @return string Javascript code. */ -function PMA_printJsValue($key, $value) +function PMA_getJsValue($key, $value) { - echo $key . ' = '; + $result = $key . ' = '; if (is_array($value)) { - echo '['; + $result .= '['; foreach ($value as $id => $val) { - echo "'" . PMA_escapeJsString($val) . "',"; + $result .= "'" . PMA_escapeJsString($val) . "',"; } - echo "];\n"; + $result .= "];\n"; } else { - echo "'" . PMA_escapeJsString($value) . "';\n"; + $result .= "'" . PMA_escapeJsString($value) . "';\n"; } + return $result; +} + +/** + * Prints an javascript assignment with proper escaping of a value + * and support for assigning array of strings. + * + * @param string $key Name of value to set + * @param mixed $value Value to set, can be either string or array of strings + * + * @return nothing + */ +function PMA_printJsValue($key, $value) +{ + echo PMA_getJsValue($key, $value); } ?> -- 2.11.4.GIT