* Filtering for XSS is very easily done by using the htmlentities() function.
* This kind of filtering prevents JavaScript snippets to be understood as such.
* @param mixed The variable to filter for XSS, this params can be a string or an array (example : array(x,y))
* @param integer The user status,constant allowed (STUDENT, COURSEMANAGER, ANONYMOUS, COURSEMANAGERLOWSECURITY)
* @param string The variable to filter for XSS, this params can be a string or an array (example : array(x,y))
* @param int The user status,constant allowed (STUDENT, COURSEMANAGER, ANONYMOUS, COURSEMANAGERLOWSECURITY)
* @param bool $filter_terms
* @return mixed Filtered string or array
*/
public static function remove_XSS($var, $user_status = ANONYMOUS, $filter_terms = false)
public static function remove_XSS($var, $user_status = null, $filter_terms = false)
{
if ($filter_terms) {
$var = self::filter_terms($var);
}
if (empty($user_status)) {
if (api_is_anonymous()) {
$user_status = ANONYMOUS;
} else {
if (api_is_allowed_to_edit()) {
$user_status = COURSEMANAGER;
} else {
$user_status = STUDENT;
}
}
}
if ($user_status == COURSEMANAGERLOWSECURITY) {
return $var; // No filtering.
}
static $purifier = array();
if (!isset($purifier[$user_status])) {
if (!class_exists('HTMLPurifier')) {
@ -309,7 +323,6 @@ class Security
mkdir($cache_dir, 0777);
}
$config = HTMLPurifier_Config::createDefault();
//$config->set('Cache.DefinitionImpl', null); // Enable this line for testing purposes, for turning off caching. Don't forget to disable this line later!