Skip to content

Commit

Permalink
add support for Comments plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Apr 2, 2016
1 parent 7cd4ff3 commit c028d12
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions SpamGuardPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ public function init()
}
});
}

#
# Support for Comments
if ($this->getSettings()->getAttribute('enableCommentsSupport'))
{
craft()->on('comments.onBeforeSaveComment', function(Event $event)
{
$spam = spamGuard()->detectCommentsSpam($event->params['comment']);

if ($spam)
{
$event->performAction = false;
}
});
}
}

/**
Expand Down Expand Up @@ -137,6 +152,7 @@ public function defineSettings()
'enableContactFormSupport' => array(AttributeType::Bool, 'default' => true),
'enableGuestEntriesSupport' => array(AttributeType::Bool, 'default' => true),
'enableSproutFormsSupport' => array(AttributeType::Bool, 'default' => true),
'enableCommentsSupport' => array(AttributeType::Bool, 'default' => true),
'logSubmissions' => array(AttributeType::Bool, 'default' => false),
'enableCpTab' => array(AttributeType::Bool, 'default' => true),
'pluginAlias' => AttributeType::String,
Expand Down
20 changes: 20 additions & 0 deletions services/SpamGuardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ public function detectDynamicFormSpam(BaseModel $model)
return $this->isSpam($data);
}

/**
* Comments onBeforeSaveComment()
*
* Allows you to use spamguard alongside the Comments plugin
*
* @since 0.6.0
* @param array $form
* @return boolean
*/
public function detectCommentsSpam(BaseModel $comment)
{
$data = array(
'content' => $comment->comment,
'author' => $comment->author->fullName,
'email' => $comment->author->email,
);

return $this->isSpam($data);
}

/**
* Deletes a log by id
*
Expand Down
10 changes: 10 additions & 0 deletions templates/_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ <h3 class="glyph thirdparty">Integration Settings</h3>
errors: ""
})
}}
{{
forms.checkboxField({
id: "enableCommentsSupport",
name: "enableCommentsSupport",
label: "Enable Comments Support?"|t,
checked: settings.enableCommentsSupport,
instructions: "This features requires [Comments 0.4.0](https://github.com/engram-design/Comments) or above"|t,
errors: ""
})
}}
</div>

<div class="spamguardSection">
Expand Down

0 comments on commit c028d12

Please sign in to comment.