diff --git a/languages/en.php b/languages/en.php index 6a8a58d..e5a2b46 100755 --- a/languages/en.php +++ b/languages/en.php @@ -10,6 +10,7 @@ 'community_spam_tools:msg_limit' => 'Maximum number of sent messages over 5 minutes', 'community_spam_tools:msg_limit:new_user' => 'Maximum number of sent messages for new users', 'community_spam_tools:blacklist' => 'Comma-separated list of spam words or phrases', + 'community_spam_tools:blacklist:desc' => 'All user profile fields and the description field of all content types will be checked for these terms. If two or more terms are found, the user gets banned.', ); add_translation('en', $english); diff --git a/start.php b/start.php index 558bbdf..6b099c3 100755 --- a/start.php +++ b/start.php @@ -13,7 +13,8 @@ function community_spam_init() { if (!elgg_is_admin_logged_in()) { elgg_register_event_handler('create', 'object', 'community_spam_messages_throttle'); } - elgg_register_event_handler('create', 'object', 'community_spam_messages_filter'); + elgg_register_event_handler('create', 'object', 'community_spam_content_filter'); + elgg_register_event_handler('update', 'object', 'community_spam_content_filter'); // profile spam elgg_register_plugin_hook_handler('action', 'profile/edit', 'community_spam_profile_blacklist'); @@ -181,25 +182,34 @@ function community_spam_stop_add() { } /** - * Filter based on common spam terms + * Filter content based on common spam terms and ban spammers */ -function community_spam_messages_filter($event, $type, $object) { - if ($object->getSubtype() !== 'messages') { - return; - } - +function community_spam_content_filter($event, $type, $object) { if (!community_spam_is_new_user()) { return; } - $terms = array('yahoo', 'hotmail', 'miss', 'love', 'email address', 'dear', 'picture', 'profile', 'interest'); - $count = 0; - foreach ($terms as $term) { + $blacklist = elgg_get_plugin_setting('profile_blacklist', 'community_spam_tools'); + $blacklist = explode(",", $blacklist); + $blacklist = array_map('trim', $blacklist); + + $terms = array(); + foreach ($blacklist as $term) { if (stripos($object->description, $term) !== false) { - $count++; + $terms[] = $term; } } - if ($count > 3) { - return false; + + if (count($terms) < 2) { + // Allow the content to be created + return; } + + $spammer = elgg_get_logged_in_user_entity(); + $spammer->annotate('banned', 1); // this integrates with ban plugin + + $terms = implode(', ', $terms); + $spammer->ban("Used the following blacklisted terms: $terms"); + + return false; } diff --git a/views/default/plugins/community_spam_tools/settings.php b/views/default/plugins/community_spam_tools/settings.php index 55aafa8..bebadf0 100755 --- a/views/default/plugins/community_spam_tools/settings.php +++ b/views/default/plugins/community_spam_tools/settings.php @@ -32,4 +32,5 @@ 'name' => 'params[profile_blacklist]', 'value' => $blacklist, )); +echo '' . elgg_echo('community_spam_tools:blacklist:desc') . ''; echo '';