Akismet datasource
Posted on 1/9/08 by Felix Geisendörfer
Hey folks,
this is post #13 of my 30 day challenge.
For our blog here at debuggable we use the excellent Akismet service to protect ourselves from spam. Thanks to CakePHP, our implementation for it is as simple as this:
class Comment extends AppModel{
var $validate = array(
'text' => array(
array(
'rule' => array('notSpam'),
'message' => 'This comment appears to be spam. Please contact us if the problem persists.',
'required' => true,
),
),
);
function notSpam($fields) {
$akismet = ConnectionManager::getDataSource('akismet');
return !$akismet->isSpam($this->data['Comment'], Post::url($this->data['Comment']['post_id']));
}
}
var $validate = array(
'text' => array(
array(
'rule' => array('notSpam'),
'message' => 'This comment appears to be spam. Please contact us if the problem persists.',
'required' => true,
),
),
);
function notSpam($fields) {
$akismet = ConnectionManager::getDataSource('akismet');
return !$akismet->isSpam($this->data['Comment'], Post::url($this->data['Comment']['post_id']));
}
}
So if you are coding up a little blog or something else that needs (Comment) spam protection, we released our Akismet API datasource for you.
Get it while its hot: Akismet Datasource at the Debuggable Scraps repository.
Alright, hope this helps some of you out there. Please Comment with suggestions and criticism ; ).
-- Felix Geisendörfer aka the_undefined
&nsbp;