Skip to content

Commit

Permalink
Merge pull request #4 from Elgg/content_filtering
Browse files Browse the repository at this point in the history
feature(blacklist): all content is now always checked agains blacklisted terms
  • Loading branch information
mrclay committed Jan 28, 2016
2 parents 05afad6 + c3ded9f commit 9bf4226
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
36 changes: 23 additions & 13 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions views/default/plugins/community_spam_tools/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
'name' => 'params[profile_blacklist]',
'value' => $blacklist,
));
echo '<span class="elgg-text-help">' . elgg_echo('community_spam_tools:blacklist:desc') . '</span>';
echo '</div>';

0 comments on commit 9bf4226

Please sign in to comment.