From: Chuck Hagenbuch Date: Sat, 30 May 2009 15:37:06 +0000 (-0400) Subject: remove the special escape callback and just implement escape() as an additional helper X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b357fff3dc39bff90c0663c239c6df610dd28112;p=horde.git remove the special escape callback and just implement escape() as an additional helper --- diff --git a/framework/View/lib/Horde/View/Base.php b/framework/View/lib/Horde/View/Base.php index efe60c831..6b09e8f6e 100644 --- a/framework/View/lib/Horde/View/Base.php +++ b/framework/View/lib/Horde/View/Base.php @@ -41,13 +41,6 @@ abstract class Horde_View_Base private $_helpers = array(); /** - * Callback for escaping. - * - * @var string - */ - private $_escape = 'htmlspecialchars'; - - /** * Encoding to use in escaping mechanisms; defaults to UTF-8. * @var string */ @@ -72,11 +65,6 @@ abstract class Horde_View_Base */ public function __construct($config = array()) { - // user-defined escaping callback - if (!empty($config['escape'])) { - $this->setEscape($config['escape']); - } - // encoding if (!empty($config['encoding'])) { $this->setEncoding($config['encoding']); @@ -218,16 +206,6 @@ abstract class Horde_View_Base } /** - * Sets the escape() callback. - * - * @param mixed $spec The callback for escape() to use. - */ - public function setEscape($spec) - { - $this->_escape = $spec; - } - - /** * Assigns multiple variables to the view. * * The array keys are used as names, each assigned their @@ -336,26 +314,7 @@ abstract class Horde_View_Base } /** - * Escapes a value for output in a template. - * - * If escaping mechanism is one of htmlspecialchars or htmlentities, uses - * {@link $_encoding} setting. - * - * @param mixed $var The output to escape. - * - * @return mixed The escaped value. - */ - public function escape($var) - { - if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) { - return call_user_func($this->_escape, $var, ENT_QUOTES, $this->_encoding); - } - - return call_user_func($this->_escape, $var); - } - - /** - * Set encoding to use with htmlentities() and htmlspecialchars() + * Set encoding * * @param string $encoding */ @@ -365,7 +324,7 @@ abstract class Horde_View_Base } /** - * Return current escape encoding + * Return current encoding * * @return string */ diff --git a/framework/View/lib/Horde/View/Helper/Tag.php b/framework/View/lib/Horde/View/Helper/Tag.php index 7365286bd..12f708bc3 100644 --- a/framework/View/lib/Horde/View/Helper/Tag.php +++ b/framework/View/lib/Horde/View/Helper/Tag.php @@ -102,6 +102,21 @@ class Horde_View_Helper_Tag extends Horde_View_Helper_Base } /** + * Escapes a value for output in a view template. + * + * + *

h($this->templateVar) ?>

+ *
+ * + * @param mixed $var The output to escape. + * @return mixed The escaped value. + */ + public function escape($var) + { + return htmlspecialchars($var, ENT_QUOTES, $this->_view->getEncoding()); + } + + /** * Returns the escaped $html without affecting existing escaped entities. * * $this->escapeOnce("1 > 2 & 3") diff --git a/framework/View/lib/Horde/View/Interface.php b/framework/View/lib/Horde/View/Interface.php index dd6a7396e..ee73e79d4 100644 --- a/framework/View/lib/Horde/View/Interface.php +++ b/framework/View/lib/Horde/View/Interface.php @@ -55,13 +55,6 @@ interface Horde_View_Interface public function addHelper($helper); /** - * Sets the escape() callback. - * - * @param mixed $spec The callback for escape() to use. - */ - public function setEscape($spec); - - /** * Assigns multiple variables to the view. * * The array keys are used as names, each assigned their @@ -83,26 +76,14 @@ interface Horde_View_Interface public function render($name); /** - * Escapes a value for output in a template. - * - * If escaping mechanism is one of htmlspecialchars or htmlentities, uses - * {@link $_encoding} setting. - * - * @param mixed $var The output to escape. - * - * @return mixed The escaped value. - */ - public function escape($var); - - /** - * Set encoding to use with htmlentities() and htmlspecialchars() + * Set encoding * * @param string $encoding */ public function setEncoding($encoding); /** - * Return current escape encoding + * Return current encoding * * @return string */