Permalink
Browse files

Merge pull request #6 from brettp/1.7

Thanks, Brett!
  • Loading branch information...
2 parents 8d10a6f + 572e0c2 commit ded718e677894e62ff932b12990577c01cf7bec4 @ewinslow committed Jun 19, 2011
Showing with 55 additions and 11 deletions.
  1. +0 −4 activate.php
  2. +0 −2 deactivate.php
  3. +2 −0 languages/en.php
  4. +44 −5 start.php
  5. +9 −0 views/default/settings/akismet/edit.php
View
@@ -1,4 +0,0 @@
-<?php
-if (!elgg_get_plugin_setting('api_key', 'akismet')) {
- elgg_add_admin_notice('akismet_key', "You need to fill in your API key for Akismet before it can start working!");
-}
View
@@ -1,2 +0,0 @@
-<?php
-elgg_delete_admin_notice('akismet_key');
View
@@ -3,6 +3,8 @@
add_translation("en", array(
'akismet:noapikey' => 'API key not defined, please configure Akismet in your admin tools',
'akismet:api_key' => 'API key',
+ 'akismet:ban_max_days' => 'Only auto-ban users if their account is younger than this many days',
'akismet:spam' => 'You have been banned for spam! Please get in contact with an administrator if you feel this is in error.',
+ 'akismet:spam_no_ban' => 'Your content has been rejected because we think it is spam. Please get in contact with an administrator if you feel this is in error.',
'akismet:ham' => 'Message passed Akismet spam check',
));
View
@@ -7,6 +7,7 @@ function akismet_init() {
require dirname(__FILE__) . "/vendors/akismet/PHP5Akismet.0.4/Akismet.class.php";
// Only filter if the plugin has been set up and we're not an admin user
+
if (get_plugin_setting('api_key', 'akismet') && !isadminloggedin()) {
register_elgg_event_handler('create', 'object', 'akismet_object_handler');
register_elgg_event_handler('update', 'user', 'akismet_user_handler');
@@ -17,8 +18,18 @@ function akismet_init() {
function akismet_user_handler($event, $type, ElggUser $user) {
$fields = array($user->briefdescription, $user->description);
- foreach ($fields as $field) {
- akismet_filter($user, $field, $user);
+ // we need to check if we're in an action because of updates to last_login, etc
+ // akismet doesn't care about that.
+ $action = get_input('action');
+ $ignored_actions = array(
+ 'login',
+ 'logout'
+ );
+
+ if (!in_array($action, $ignored_actions)) {
+ foreach ($fields as $field) {
+ akismet_filter($user, $field, $user);
+ }
}
}
@@ -32,9 +43,30 @@ function akismet_annotation_handler($event, $type, ElggAnnotation $annotation) {
function akismet_filter($object, $content, $owner) {
if (akismet_scan($content, $owner->name, $owner->email, $owner->website, $object->getURL())) {
- register_error(elgg_echo('akismet:spam'));
- $object->disable('spam');
- $owner->ban('spam');
+ if ($object instanceof ElggEntity) {
+ $object->disable('spam');
+ } elseif ($object instanceof ElggAnnotation) {
+ akismet_disable_annotation($object);
+ } else {
+ // don't know how to deal with this type.
+ return;
+ }
+
+ // only disable the user if older than X days
+ $ban_max_days = $plugin->ban_max_days;
+
+ if (!$ban_max_days) {
+ $ban_max_days = 7;
+ }
+
+ $too_old = strtotime("-$ban_max_days days") - $owner->time_created > 0;
+
+ if (!$too_old) {
+ register_error(elgg_echo('akismet:spam'));
+ $owner->ban('spam');
+ } else {
+ register_error(elgg_echo('akismet:spam_no_ban'));
+ }
//bail on the current action + return to previous page seems to make the most sense here...
forward(REFERER);
@@ -70,4 +102,11 @@ function akismet_scan($comment, $author = "", $author_email = "", $author_url =
return $akismet->isCommentSpam();
}
+function akismet_disable_annotation($annotation) {
+ $db_prefix = get_config('dbprefix');
+
+ $q = "UPDATE {$db_prefix}annotations SET enabled = 'no' WHERE id = '$annotation->id'";
+ return update_data($q);
+}
+
register_elgg_event_handler('init', 'system', 'akismet_init');
@@ -1,10 +1,19 @@
<?php
$plugin = $vars['entity'];
+$ban_max_days = $plugin->ban_max_days;
+if (!$ban_max_days) {
+ $ban_max_days = 7;
+}
?>
<div>
<label><?php echo elgg_echo('akismet:api_key'); ?>:</label>
<?php echo elgg_view('input/text', array('internalname' => 'params[api_key]', 'value' => $plugin->api_key)); ?>
</div>
+
+<div>
+ <label><?php echo elgg_echo('akismet:ban_max_days'); ?>:</label>
+ <?php echo elgg_view('input/text', array('internalname' => 'params[ban_max_days]', 'value' => $ban_max_days)); ?>
+</div>

0 comments on commit ded718e

Please sign in to comment.