Allow Xss filter to return a DOMDocument object.
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jul 2010 16:08:17 +0000 (10:08 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jul 2010 16:08:17 +0000 (10:08 -0600)
framework/Text_Filter/lib/Horde/Text/Filter/Xss.php

index 0e48997..52c715b 100644 (file)
@@ -15,6 +15,9 @@
  *                     the document.
  *                     DEFAULT: false (returns the contents contained inside
  *                              the BODY tag)
+ * 'return_dom' - (boolean) If true, return a DOMDocument object instead of
+ *                HTML text (overrides return_document).
+ *                DEFAULT: false
  * 'strip_styles' - (boolean) Strip style tags?
  *                  DEFAULT: true
  * 'strip_style_attributes' - (boolean) Strip style attributes in all tags?
@@ -43,6 +46,7 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base
         'charset' => 'UTF-8',
         'noprefetch' => false,
         'return_document' => false,
+        'return_dom' => false,
         'strip_styles' => true,
         'strip_style_attributes' => true
     );
@@ -88,7 +92,8 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base
      *
      * @param string $text  The text after the filtering.
      *
-     * @return string  The modified text.
+     * @return string|DOMDocument  The modified text or a DOMDocument object
+     *                             if the 'return_dom' parameter is set.
      */
     public function postProcess($text)
     {
@@ -121,6 +126,10 @@ class Horde_Text_Filter_Xss extends Horde_Text_Filter_Base
             }
         }
 
+        if ($this->_params['return_dom']) {
+            return $doc;
+        }
+
         $text = '';
         if ($this->_params['return_document']) {
             $text = $doc->saveHTML();