remove the special escape callback and just implement escape() as an additional helper
authorChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:37:06 +0000 (11:37 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 30 May 2009 15:37:06 +0000 (11:37 -0400)
framework/View/lib/Horde/View/Base.php
framework/View/lib/Horde/View/Helper/Tag.php
framework/View/lib/Horde/View/Interface.php

index efe60c8..6b09e8f 100644 (file)
@@ -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
      */
index 7365286..12f708b 100644 (file)
@@ -102,6 +102,21 @@ class Horde_View_Helper_Tag extends Horde_View_Helper_Base
     }
 
     /**
+     * Escapes a value for output in a view template.
+     *
+     * <code>
+     *   <p><?= $this->h($this->templateVar) ?></p>
+     * </code>
+     *
+     * @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 &amp; 3")
index dd6a739..ee73e79 100644 (file)
@@ -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
      */