drAkismetPlugin
This plugin is a library on top of the Akismet API. It is a spam detection tool leveraged by a web service. Read their online documentation for more information on the available calls.
Installation and configuration
- Download the plugin and copy it to your project's plugins directory.
- Enable the plugin in your
ProjectConfiguration class (/config/ProjectConfiguration.class.php).
- Create a configuration file
akismet.yml
- Enter your API key(s): signup
Usage
API calls
The 1.1 API supports four methods:
Use a drAkismetApi instance to call theses methods:
$api = new drAkismetApi();
$verifyKey = $api->verifyKey() // or: new drAkismetApiVerifyKey();
->setBlogUri('http://www.symfony-project.org/blog/');
$api->call($verifyKey); // returns a drAkismetApiReponse
// or alternatively you can directly do:
$api->verifyKey()->setBlogUri('http://www.symfony-project.org/blog/')
->isValid($api); // returns TRUE / FALSE
Or use the drAkismetApiComment helper class - which can be extended by your own comment class:
$api = new drAkismetApi();
$comment = new drAkismetApiComment();
$comment->setAuthor('viagra-test-123')
->setAuthorEmail('foo@bar.net')
->setCommentContent('test');
$checkComment->setBlogUri('http://www.symfony-project.org/blog/')
->isSpam($api, $comment);
Response
Calls to an API method return an instance of drAkismetApiReponse. The four provided methods return a subclass of said response class:
verifyKeyResponse has a method isValid (returned by verify-key)
checkCommentResponse has a method isSpam (returned by comment-check)
It is possible to create your own connection class (socket connection by default) or to override the
request parameters (e.g. for testing purposes):
class myConnection implements drAkismetConnectionInterface
{
/* ... */
}
$api = new drAkismetApi();
$api->setConnection(new myConnection());
$api->setHost('akismet-test.yourhost.com');
$api->setPort(8080);
Validator
Use drAkismetValidatorSpam to validate comments directly from your forms. Of course, like any sfValidator, you can also use it outside your forms:
new drAkismetValidatorSpam(array(
'blog' => 'http://www.symfony-project.org/blog/',
'user_ip' => $_SERVER['REMOTE_ADDR'],
'comment_author' => 'viagra-test-123',
'comment_author_email' => 'foo@bar.net',
'comment_content' => 'test'
));
Configuration
User agent
The defaults in the config directory of this plugin should suffice, but your are free to alter them.
API keys
For each host you can configure different API keys. You can also override the hostname that will be used when communicating with the Akismet service:
akismet:
api_keys:
www.yourhost.com: 123abc456def # the API key for said host
mydev.local:
host: www.yourhost.com # the hostname to use (instead of mydev.local)
key: 123abc456def
Deny calls
You can limit the available API methods by using the allow_calls key:
akismet:
allow_calls: [check-comment] # one or more of: verify-key, check-comment, submit-spam, submit-ham