function profanity_list_execute in Profanity 7
Helper function for use in replacing or validating.
7 calls to profanity_list_execute()
- profanity_entity_prepare_view in ./
profanity.module - Implements hook_entity_load().
- profanity_entity_property_getter in ./
profanity.module - Get the label property for a passed entity filtered for profanity.
- profanity_rules_match_lists in ./
profanity.rules.inc - Run the lists against the text.
- profanity_tokens in ./
profanity.module - Implements hook_tokens().
- profanity_user_register_validate in ./
profanity.module - Form validation callback.
File
- ./
profanity.module, line 334 - Main {profanity} file.
Code
function profanity_list_execute($list_name, $text, $return_text = TRUE) {
$list = profanity_list_load($list_name);
if (!$list) {
return $return_text ? $text : FALSE;
}
$words = trim($list->words, ',');
$words = explode(',', $words);
if (empty($words)) {
return $return_text ? $text : FALSE;
}
$count = 0;
// Match partials, for example the word "christ" would match in
// "christmas" and be potentially changed to "******mas".
if ($list->match_partial) {
// Character replacement.
if ($list->replacement_mode == 0) {
// This following method won out when tracking time to execute.
$replacements = profanity_list_get_replacements($list);
if ($list->case_sensitive) {
$text = str_replace($words, $replacements, $text, $count);
}
else {
$text = str_ireplace($words, $replacements, $text, $count);
}
}
elseif ($list->replacement_mode == 1) {
if ($list->case_sensitive) {
$text = str_replace($words, $list->replacement_phrase, $text, $count);
}
else {
$text = str_ireplace($words, $list->replacement_phrase, $text, $count);
}
}
}
else {
$wordlist = implode('|', array_map('preg_quote', $words));
$modifiers = $list->case_sensitive ? NULL : "/i";
// Character replacement.
if ($list->replacement_mode == 0) {
$replace = new ProfanityPregCallback($wordlist, $modifiers, $list->replacement_character);
$text = $replace
->execute($text);
$count = $replace
->get_count();
}
elseif ($list->replacement_mode == 1) {
$text = preg_replace("/\\b({$wordlist})\\b{$modifiers}", $list->replacement_phrase, $text, -1, $count);
}
}
$found = $count > 0;
return $return_text ? $text : $found;
}