Format code

ofaj
jmontoyaa 9 years ago
parent ecf24659ef
commit 81b59fb98c
  1. 44
      main/inc/lib/security.lib.php

@ -396,24 +396,26 @@ class Security
/**
*
* Filter content
* @param string content to be filter
* @param string $text to be filter
* @return string
*/
static function filter_terms($text)
public static function filter_terms($text)
{
static $bad_terms = array();
if (empty($bad_terms)) {
$list = api_get_setting('filter_terms');
$list = explode("\n", $list);
$list = array_filter($list);
if (!empty($list)) {
foreach ($list as $term) {
$term = str_replace(array("\r\n", "\r", "\n", "\t"), '', $term);
$html_entities_value = api_htmlentities($term, ENT_QUOTES, api_get_system_encoding());
$bad_terms[] = $term;
if ($term != $html_entities_value) {
$bad_terms[] = $html_entities_value;
$list = explode("\n", $list);
$list = array_filter($list);
if (!empty($list)) {
foreach ($list as $term) {
$term = str_replace(array("\r\n", "\r", "\n", "\t"), '', $term);
$html_entities_value = api_htmlentities($term, ENT_QUOTES, api_get_system_encoding());
$bad_terms[] = $term;
if ($term != $html_entities_value) {
$bad_terms[] = $html_entities_value;
}
}
}
$bad_terms = array_filter($bad_terms);
@ -421,30 +423,12 @@ class Security
}
$replace = '***';
if (!empty($bad_terms)) {
//Fast way
// Fast way
$new_text = str_ireplace($bad_terms, $replace, $text, $count);
//We need statistics
/*
if (strlen($new_text) != strlen($text)) {
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_FILTERED_TERMS);
$attributes = array();
$attributes['user_id'] =
$attributes['course_id'] =
$attributes['session_id'] =
$attributes['tool_id'] =
$attributes['term'] =
$attributes['created_at'] = api_get_utc_datetime();
$sql = Database::insert($table, $attributes);
}
*/
$text = $new_text;
}
return $text;
}

Loading…
Cancel
Save