debuggable

 
Contact Us
 

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']));
  }

}

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;

You can skip to the end and add a comment.

Mark Story said on Sep 01, 2008:

Felix: In the past I've implemented such external service connections as models. I'm guessing you feel it is more appropriate as a datasource, as you've presented it as such here. Would care to explain why you've made it into a datasource instead of a model?

One question about the datasource it wasn't clear where you are providing the initial configuration i.e. API key. I'm assuming you did this in app/config/database.php but it isn't clear.

Felix Geisendörfer said on Sep 01, 2008:

Mark Story: Check out the debuggable scraps repo, it has the full instructions ; ). About the model vs datasource thingy: I'll do a post on that soon.

Andreas  said on Sep 01, 2008:

I'm looking forward to that post on datasource vs. model.

I always have problems to decide if I should do something as a model, a datasource, behaviour, component...

I guess i would have done this spam-filter as a component.
Your solution looks really nice. Never thought it could be simple as that.

leo  said on Sep 01, 2008:

That was exactly my thougt Andreas - "wow, didn't know this could be solved in such a nice way". Really, very elegant!

Thanks for keeping up the challenge Felix ;)

Steve Oliveira said on Sep 01, 2008:

I too look forward to reading your post on datasource vs model.

Jonathan Snook said on Sep 02, 2008:

My first instinct would have been to try and build this as a Behavior and then have notSpam available as a validate function (saving having to declare it manually as it is here). And then you could define configuration options at the model level, allowing for different Akismet configurations or different field mappings.

So, while you explain Model vs DataSource, I'd be interested in DataSource vs Behavior. :)

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.