]> source.dussan.org Git - nextcloud-server.git/commitdiff
backport of sanitizeHTML() function
authorBjoern Schiessle <schiessle@owncloud.com>
Wed, 20 Jun 2012 14:43:31 +0000 (16:43 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Wed, 20 Jun 2012 14:43:31 +0000 (16:43 +0200)
lib/public/util.php
lib/util.php

index bffe07da3f8b732c707623c16af4536be6a65dfe..08394da575eb50ebce07ddfb219fb6303ab48822 100644 (file)
@@ -266,6 +266,17 @@ class Util {
                return(\OC_Util::callCheck());
        }
 
+       /**\r
+        * @brief Used to sanitize HTML\r
+        *\r
+        * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page.\r
+        *\r
+        * @param string or array of strings\r
+        * @return array with sanitized strings or a single sinitized string, depends on the input parameter.\r
+        */\r
+       public static function sanitizeHTML( $value ){\r
+               return(\OC_Util::sanitizeHTML($value));\r
+       }
 }
 
 ?>
index 1dd11e7b5c88eda6f60364f2afdad374938499d0..1eeb70aca695ebdea1acb1629794152f7048db4a 100644 (file)
@@ -348,7 +348,7 @@ class OC_Util {
                $_SESSION['requesttoken-'.$token]=time();
 
                // cleanup old tokens garbage collector
-               // only run every 20th time so we donยดt waste cpu cycles
+               // only run every 20th time so we don't waste cpu cycles
                if(rand(0,20)==0) {  
                        foreach($_SESSION as $key=>$value) {
                                // search all tokens in the session
@@ -403,5 +403,19 @@ class OC_Util {
                        exit;
                }
        }
+       
+       /**\r
+        * @brief Public function to sanitize HTML\r
+        *\r
+        * This function is used to sanitize HTML and should be applied on any string or array of strings before displaying it on a web page.\r
+        *\r
+        * @param string or array of strings\r
+        * @return array with sanitized strings or a single sinitized string, depends on the input parameter.\r
+        */\r
+       public static function sanitizeHTML( &$value ){\r
+               if (is_array($value) || is_object($value)) array_walk_recursive($value,'OC_Util::sanitizeHTML');\r
+               else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4\r
+               return $value;\r
+       }
 }