- Joomla CMS v2.5.11 (Joomla.org)
- jComments v2.3.0 (JoomlaTune.com)
- PlayThru v1.1.8 (AreYouAHuman.com)
This article is a follow-up of my article JComments 2.3.0 with Google ReCaptcha (Joomla 2.5.x) but instead of using ReCaptcha, we're going to use an alternative called PlayThru by AreYouAHuman.Com.
Why?
The kCaptcha used by the jComments extension is easily automated and no longer blocks spam comments.
How?
So I have come up with what I consider a pretty stable solution. I adapted it from various legacy solutions when using Google's ReCaptcha.
Note: There is a Joomla plugin for AYAH and this works for the user registration form. I installed it but the below details how to integrate the AYAH library with jComments. I will look at a solution using the installed plugin later.
STEP #1: Signup at AYAH
You need to have a publisher and scoring key, sign up for FREE at AreYouAHuman.Com: Basic Signup:
- Signup and you will be redirected to a dashboard.
- On the dashboard, note the Publisher's key (eg. "c518c95f01312c9ac97ace9ace199ace0c38d9d")
- On the dashboard, note the Scoring key (eg. "64d6d442b7e846acfaacef642e1ad173b35503")
- On the dashboard, check the site URL matches the domain you are trying this on (eg. if you are testing on "http://test.mycompany.com" then the site specified in the AYAH dashboard should be "test.mycompany.com" and not "www.mycompany.com")
STEP #2: Download AYAH files
Download the latest files from https://portal.areyouahuman.com/installation/php (If you want my cached download - v1.1.8: click here)
- Extract the ZIP file to a folder (should be about 4 php files)
- Modify the file ayah_config.php to match the publisher and scoring key given to you. > Save
- Upload the files to \components\com_jcomments\libraries\ayah
STEP #3: Enable admin option dropdown
This is a code change to allow the admin to select PlayThru.
- Open the file \administrator\components\com_jcomments\admin.jcomments.php (line 1066)
- Replace the line
- With this
STEP #4: Set to PlayThru in admin setting
We've made the change, now login and set it to PlayThru
- Login to your Joomla Administration panel
- Components > JComments > Settings > Layout > CAPTCHA > PLAYTHRU
- Save the change.
STEP #5: Display PlayThru in comment form
This step displays the PlayThru on the form (note this code may need to be reverted if the admin does not want to use PlayThru anymore)
- Open the file \components\com_jcomments\tpl\default\tpl_form.php (line 114)
- Replace the code copyraw
<?php } if ($this->getVar('comments-form-captcha', 0) == 1) { $html = $this->getVar('comments-form-captcha-html'); if ($html != '') { echo $html; } else { $link = JCommentsFactory::getLink('captcha'); ?> <p> <span> <img class="captcha" onclick="jcomments.clear('captcha');" id="comments-form-captcha-image" src="/<?php echo $link; ?>" width="121" height="60" alt="<?php echo JText::_('FORM_CAPTCHA'); ?>" /><br /> <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br /> <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br /> </span> </p> <?php } } ?>
- <?php
- }
- if ($this->getVar('comments-form-captcha', 0) == 1) {
- $html = $this->getVar('comments-form-captcha-html');
- if ($html != '') {
- echo $html;
- } else {
- $link = JCommentsFactory::getLink('captcha');
- ?>
- <p>
- <span>
- <img class="captcha" onclick="jcomments.clear('captcha');" id="comments-form-captcha-image" src="/<?php echo $link; ?>" width="121" height="60" alt="<?php echo JText::_('FORM_CAPTCHA'); ?>" /><br />
- <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br />
- <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br />
- </span>
- </p>
- <?php
- }
- }
- ?>
- With this copyraw
<?php } if ($this->getVar('comments-form-captcha', 0) == 1) { $html = $this->getVar('comments-form-captcha-html','kcaptcha'); if ($html == 'kcaptcha') { $link = JCommentsFactory::getLink('captcha'); ?> <p> <span> <img class="captcha" onclick="jcomments.clear('captcha');" id="comments-form-captcha-image" src="/<?php echo $link; ?>" width="121" height="60" alt="<?php echo JText::_('FORM_CAPTCHA'); ?>" /><br /> <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br /> <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br /> </span> </p> <?php } else { JPluginHelper::importPlugin('captcha'); require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php'); $ayah = new AYAH(); echo $ayah->getPublisherHTML(); } } ?>
- <?php
- }
- if ($this->getVar('comments-form-captcha', 0) == 1) {
- $html = $this->getVar('comments-form-captcha-html','kcaptcha');
- if ($html == 'kcaptcha') {
- $link = JCommentsFactory::getLink('captcha');
- ?>
- <p>
- <span>
- <img class="captcha" onclick="jcomments.clear('captcha');" id="comments-form-captcha-image" src="/<?php echo $link; ?>" width="121" height="60" alt="<?php echo JText::_('FORM_CAPTCHA'); ?>" /><br />
- <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br />
- <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br />
- </span>
- </p>
- <?php
- } else {
- JPluginHelper::importPlugin('captcha');
- require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php');
- $ayah = new AYAH();
- echo $ayah->getPublisherHTML();
- }
- }
- ?>
STEP #6: Process submitted PlayThru
- Open the file \components\com_jcomments\jcomments.ajax.php (line 275)
- Replace the code copyraw
if ($acl->check('enable_captcha') == 1) { $captchaEngine = $config->get('captcha_engine', 'kcaptcha'); if ($captchaEngine == 'kcaptcha') { require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' ); if (!JCommentsCaptcha::check($values['captcha_refid'])) { self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha'); JCommentsCaptcha::destroy(); $response->addScript("jcomments.clear('captcha');"); return $response; } } else { $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response)); // if all plugins returns false if (!in_array(true, $result, true)) { self::showErrorMessage(JText::_('ERROR_CAPTCHA')); return $response; } } }
- if ($acl->check('enable_captcha') == 1) {
- $captchaEngine = $config->get('captcha_engine', 'kcaptcha');
- if ($captchaEngine == 'kcaptcha') {
- require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' );
- if (!JCommentsCaptcha::check($values['captcha_refid'])) {
- self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');
- JCommentsCaptcha::destroy();
- $response->addScript("jcomments.clear('captcha');");
- return $response;
- }
- } else {
- $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response));
- // if all plugins returns false
- if (!in_array(true, $result, true)) {
- self::showErrorMessage(JText::_('ERROR_CAPTCHA'));
- return $response;
- }
- }
- }
- With this copyraw
if ($acl->check('enable_captcha') == 1) { $captchaEngine = $config->get('captcha_engine', 'playthru'); if ($captchaEngine == 'kcaptcha') { require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' ); if (!JCommentsCaptcha::check($values['captcha_refid'])) { self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha'); JCommentsCaptcha::destroy(); $response->addScript("jcomments.clear('captcha');"); return $response; } } elseif ($captchaEngine == 'playthru') { $post = JRequest::get('post'); JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $score=false; // AreYouAHuman stuff require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php'); $ayah = new AYAH(); $score = $ayah->scoreResult(); if ($score===false){ self::showErrorMessage('Sorry, but we were not able to verify you as human. Please refresh the page and play the game below.'); return $response; } } else { $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response)); // if all plugins returns false if (!in_array(true, $result, true)) { self::showErrorMessage(JText::_('ERROR_CAPTCHA')); return $response; } } }
- if ($acl->check('enable_captcha') == 1) {
- $captchaEngine = $config->get('captcha_engine', 'playthru');
- if ($captchaEngine == 'kcaptcha') {
- require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' );
- if (!JCommentsCaptcha::check($values['captcha_refid'])) {
- self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');
- JCommentsCaptcha::destroy();
- $response->addScript("jcomments.clear('captcha');");
- return $response;
- }
- } elseif ($captchaEngine == 'playthru') {
- $post = JRequest::get('post');
- JPluginHelper::importPlugin('captcha');
- $dispatcher = JDispatcher::getInstance();
- $score=false;
- // AreYouAHuman stuff
- require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php');
- $ayah = new AYAH();
- $score = $ayah->scoreResult();
- if ($score===false){
- self::showErrorMessage('Sorry, but we were not able to verify you as human. Please refresh the page and play the game below.');
- return $response;
- }
- } else {
- $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response));
- // if all plugins returns false
- if (!in_array(true, $result, true)) {
- self::showErrorMessage(JText::_('ERROR_CAPTCHA'));
- return $response;
- }
- }
- }
Additional:
- Need to look at a more integrated solution using the AYAH plugin
- BUG: If a user attempts to submit the form without playing the game, and then attempts to complete the game, it will not register. The user needs to refresh the page, play the game and then re-submit the form.