Welcome to Joel Lipman .Com

Preparing Content...


Loading...

Our Website Development Notes

We hope this helps!

Articles // Web Development // Joomla

ReCaptcha alternative: Integrate PlayThru in JComments 2.3 for Joomla 2.5

Sunday, 27th April 2014
54,395 Reads
Applies to: What?
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:
  1. Signup and you will be redirected to a dashboard.
  2. On the dashboard, note the Publisher's key (eg. "c518c95f01312c9ac97ace9ace199ace0c38d9d")
  3. On the dashboard, note the Scoring key (eg. "64d6d442b7e846acfaacef642e1ad173b35503")
  4. 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)
  1. Extract the ZIP file to a folder (should be about 4 php files)
  2. Modify the file ayah_config.php to match the publisher and scoring key given to you. > Save
  3. 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.
  1. Open the file \administrator\components\com_jcomments\admin.jcomments.php (line 1066)
  2. Replace the line
    1. $captcha[] = JCommentsHTML::makeOption('kcaptcha', 'KCAPTCHA');
  3. With this
    1. $captcha[] = JCommentsHTML::makeOption('kcaptcha', 'KCAPTCHA');  
    2. $captcha[] = JCommentsHTML::makeOption('playthru', 'PLAYTHRU');

STEP #4: Set to PlayThru in admin setting
We've made the change, now login and set it to PlayThru
  1. Login to your Joomla Administration panel
  2. Components > JComments > Settings > Layout > CAPTCHA > PLAYTHRU
  3. 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)
  1. Open the file \components\com_jcomments\tpl\default\tpl_form.php (line 114)
  2. Replace the code
    1. <?php  
    2. }  
    3. if ($this->getVar('comments-form-captcha', 0) == 1) {  
    4. $html = $this->getVar('comments-form-captcha-html');  
    5. if ($html != '') {  
    6. echo $html;  
    7. } else {  
    8. $link = JCommentsFactory::getLink('captcha');  
    9. ?>  
    10. <p>  
    11. <span>  
    12. <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 />  
    13. <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br />  
    14. <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br />  
    15. </span>  
    16. </p>  
    17. <?php  
    18. }  
    19. }  
    20. ?>
  3. With this
    1. <?php  
    2. }  
    3. if ($this->getVar('comments-form-captcha', 0) == 1) {  
    4. $html = $this->getVar('comments-form-captcha-html','kcaptcha');  
    5. if ($html == 'kcaptcha') {  
    6. $link = JCommentsFactory::getLink('captcha');  
    7. ?>  
    8. <p>  
    9. <span>  
    10. <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 />  
    11. <span class="captcha" onclick="jcomments.clear('captcha');"><?php echo JText::_('FORM_CAPTCHA_REFRESH'); ?></span><br />  
    12. <input class="captcha" id="comments-form-captcha" type="text" name="captcha_refid" value="" size="5" tabindex="6" /><br />  
    13. </span>  
    14. </p>  
    15. <?php  
    16. } else {  
    17. JPluginHelper::importPlugin('captcha');  
    18. require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php');  
    19. $ayah = new AYAH();  
    20. echo $ayah->getPublisherHTML();  
    21. }  
    22. }  
    23. ?>

STEP #6: Process submitted PlayThru
  1. Open the file \components\com_jcomments\jcomments.ajax.php (line 275)
  2. Replace the code
    1. if ($acl->check('enable_captcha') == 1) {  
    2. $captchaEngine = $config->get('captcha_engine', 'kcaptcha');  
    3. if ($captchaEngine == 'kcaptcha') {  
    4. require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' );  
    5. if (!JCommentsCaptcha::check($values['captcha_refid'])) {  
    6. self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');  
    7. JCommentsCaptcha::destroy();  
    8. $response->addScript("jcomments.clear('captcha');");  
    9. return $response;  
    10. }  
    11. } else {  
    12. $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response));  
    13. // if all plugins returns false  
    14. if (!in_array(true, $result, true)) {  
    15. self::showErrorMessage(JText::_('ERROR_CAPTCHA'));  
    16. return $response;  
    17. }  
    18. }  
    19. }
  3. With this
    1. if ($acl->check('enable_captcha') == 1) {  
    2. $captchaEngine = $config->get('captcha_engine', 'playthru');  
    3.  
    4. if ($captchaEngine == 'kcaptcha') {  
    5. require_once( JCOMMENTS_BASE.DS.'jcomments.captcha.php' );  
    6. if (!JCommentsCaptcha::check($values['captcha_refid'])) {  
    7. self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');  
    8. JCommentsCaptcha::destroy();  
    9. $response->addScript("jcomments.clear('captcha');");  
    10. return $response;  
    11. }  
    12. } elseif ($captchaEngine == 'playthru') {  
    13. $post = JRequest::get('post');  
    14. JPluginHelper::importPlugin('captcha');  
    15. $dispatcher = JDispatcher::getInstance();  
    16. $score=false;  
    17.  
    18. // AreYouAHuman stuff  
    19. require_once(JCOMMENTS_BASE.DS.'libraries/ayah/'.'ayah.php');  
    20. $ayah = new AYAH();  
    21. $score = $ayah->scoreResult();  
    22. if ($score===false){  
    23. self::showErrorMessage('Sorry, but we were not able to verify you as human. Please refresh the page and play the game below.');  
    24. return $response;  
    25. }  
    26. } else {  
    27. $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response));  
    28. // if all plugins returns false  
    29. if (!in_array(true, $result, true)) {  
    30. self::showErrorMessage(JText::_('ERROR_CAPTCHA'));  
    31. return $response;  
    32. }  
    33. }  
    34. }

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.


Article Comments (3)

Sunday, 3rd July 2016
1 Vote
Gravatar for W.
W.
Vamos testar agora, certo?

Sunday, 27th April 2014
2 Votes
Gravatar for Joel
Joel
Hi Larry,

I've adapted the instructions for a JComments 3.0 for Joomla 3.2.3 site and copied these into the article http://www.joellipman.com/articles/web-development/joomla-cms/3rd-party-joomla/711-recaptcha-alternative-integrate-playthru-in-jcomments-3-0-for-joomla-3-2.html

Hope it helps!

Friday, 25th April 2014
4 Votes
Gravatar for Larry
Larry
trying to edit this in the latest version of JComments, but the filenames have changed. A grep search of all php files is not showing these variables anywhere. Please advise.


Recent Comments

Gravatar for Art
Oracle: order by subquery missing right parenthesis
Hello, what if I would like to add rownum to that code, but in my case it's all is subquery? How can I do this ?

20 Jan


Gravatar for Robert
CharIndex Reverse - find occurrence starting from end of string in TSQL
Very helpful thanks! This worked for me as well, and is a little shorter. Not sure if there are drawbacks. SELECT RIGHT(@Haystack,CHARINDEX(@Delimiter,REVERSE(@Haystack))-LEN(@Delimiter))

29 Dec


Gravatar for Translation

27 Dec


Gravatar for Tibbe
JComments 2.3.0 with ReCaptcha in Joomla 2.5.x
Hi there, This looks like a great solution to get rid of spam comments. How to integrate this in Joomla 3.x? Step 2 I did in settings.xml, but no result in frontend. Kind Regards, Tibbe

16 Dec


Gravatar for sach|n
SSRS Repeat Headers in PDF Report
Yes its working for me..thnx Joel.

7 Oct