In the evening when I get home from time to time, I write on wordpress to share the little knowledge I have about web development and today I decided to share with you my discovery of the day with
Symfony3.
Akismet the ultimate tool against SPAM
Akismet is THE web service that will allow you to stop the comment spam on your blog and in your emails. Basically it was developed for wordpress (finish the robots that offer blue pills...
yes if you are a client this article might not arrange your business ;) but for others it is just a source of irritation and then we will put up this wonderful tool that is Akismet web service on our website.
I have a comment module called CommentBundle and in its controller save a comment after submitting a form. So I want to add a check via Akismet before publishing the comment. I will not be recording the comment if it is spam.
Integrating an external PHP class in my Symfony3 Bundle
By doing some research, there is a class that does it perfectly, you will find it here
php5-akismet. You need to add it to your bundle...here's how to do it :
I create a folder in my bundle which i name "Helper" (you can put the name you wants as long as you put the good namespace behind the "use").
I copy my file Akismet.php in it and i add a namespace at the beginning of the file :
namespace CommentBundle\Helper;
//...end of the file
How to use my class
I let you discover the code of my class which is very well commented and very simple to understand. I give you here an example of validation for my comment with Akismet :
$WordPressAPIKey = 'xxxxxxxxxx';
$MyBlogURL = 'http://www.monsite.com/';
$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet->setCommentAuthorEmail($user->getEmail());
$akismet->setCommentContent($comment->getContent());
if(!$akismet->isCommentSpam()){
// on enregistre notre commentaire
}
I hope it can help,
See you soon
Pierre.