Placed in: Home arrow Programming arrow Joomla arrow Enable Akismet support in !JoomlaComment viagra australia
viagra online
viagra sale
cialis online
cialis australia
Enable Akismet support in !JoomlaComment

!JoomlaComment is one of the leading free commenting components for Joomla!. I've been using the component since the beginning of my website.

As I said before, !JoomlaComment isn't perfect (yet). It's still missing some features that make others (Like JomComment) more attractive, like the support for trackback. On the other hand, !JoomlaComment does allow threaded / nested comments which is a big positive point.

Enable Akismet support in !JoomlaComment

Another downside of the component is the lack of using the Akismet service. Akismet (which is often used together with WordPress) is a service that helps you preventing others of placing automated spam messages in your comments. !JoomlaComments current solution for preventing spam messages was by enabling CAPTCHA: A technique not many users like.

Download source files Akismet support in !JoomlaComment

We're now going to disable the CAPTCHA and enable Akismet support in !JoomlaComment. How? By "hacking" in the !JoomlaComment core.

So let's edit the PHP code from !JoomlaComment and add Akismet support! This tutorial is written for the latest release of !JoomlaComment at this moment: 3.26.

Before you start, I strongly suggest that you backup your files before changing. In case something goes wrong, you can just put everything back as it should be.

Resources

First things first, you'll need to have the following before we can start:

The setup

UnZIP the archive that contains the PHP5 class for Akismet that you downloaded in the previous step. Grab the class file (Akismet.class.php) and upload it to the following folder on your FTP:

/components/com_comment/joscomment/

While you're still there, grab the class file from !JoomlaComment to change (comment.class.php). Open that file with your PHP editor.

Dig in te code

First, we'll need to make a reference to the Akismet class. From line 25 till 28, you'll see a couple of PHP includes. Add another one on line 29:

 
require_once($mosConfig_absolute_path.'/components/
                   com_comment/joscomment/Akismet.class.php');

Now search for the function that inserts new comments to the database (function insertNewPost around line 995). Inside that function, there is will be a query prepared to write to the database ($database->SetQuery arund line 1022). Now add the following code before that query.

 
// START Marcofolio.net Akismet
$WordPressAPIKey = 'XXXXXX'; // Insert WordPress API Key
$MyBlogURL = 'http://www.XXX.com'; // Insert your own blog URL (Don't end with '/')
$akismet = new Akismet($MyBlogURL ,$WordPressAPIKey);
$akismet->setCommentAuthor($this->_tname);
$akismet->setCommentAuthorEmail($this->_temail);
$akismet->setCommentAuthorURL($this->_twebsite);
$akismet->setCommentContent($this->_tcomment);
 
// For Joomla! 1.0.x
$akismet->setPermalink($MyBlogURL.'/index.php?option=com_content&
                                    task=view&id='.$this->_content_id);
 
// For Joomla! 1.5.x
$akismet->setPermalink($MyBlogURL.'/index.php?option=com_content&
                                    view=article&id='.$this->_content_id);
 
if($akismet->isCommentSpam())
{
  // store the comment but mark it as spam (in case of a mis-diagnosis)
  $published = 0;
}
// END Marcofolio.net Akismet

Make sure you change the $WordPressAPIKey into the API Key that you found in your WordPress registration mail. Also, change the $MyBlogURL value to the place where you have your blog. Don't end with a slash ("www.marcofolio.net" is a good value, "www.marcofolio.net/" is not).

Akismet needs the permalink where the comment has been submitted. In Joomla!, the way of viewing articles is different from Joomla! 1.0.x and 1.5.x . Check which version of Joomla! you're running and remove that line that doesn't belong to your version. Also, make sure that the variable is on one line (had to do it on multiple lines here because of fitting on the page).

That's it! Save the file and upload it back to the server.

Testing

Everything should be working fine now. First, disable CAPTCHA from the component settings in the admin panel. Now go to your blog and try to make a comment like you would normally do. Everything should be working fine now.

To test if it actually worked, use the following username: viagra-test-123. When now trying to submit, the comment will be caught as spam by Akismet and will not be directly published. The comment will be stored in the database in case of mis-diagnosis. You can still view and approve comments from the admin panel.

Conclusion and Download

Although also Akismet isn't perfect (it doesn't catch all spam, especially when humans enter a spammy comment instead of an automated script), this is a better solution than CAPTCHA. Also, you'll need to check yourself every time of a comment is caught as spam, but isn't.

Another thing is that Akismet would normally learn from spam comments. The Akismet class does provide the functionality to help the system by telling which comments where spam and which were ham, but that would require changing the admin panel. Feel free to do so if you want!

Download source files Akismet support in !JoomlaComment

Hope this helped and maybe it gets included in one of the next released of !JoomlaComment.


Tags:  joomlacomment customize akismet joomla

Interested in this topic? You might enjoy another article I've written called

 
Next >
Subscribe

Subscribe to Marcofolio