The mod should allow you to replace the ISC Captcha system for reviews and replace it with the Recaptcha service. Naturally you will need to get your API keys before you do anything and I'm not going to reinvent the wheel telling you how to do that... Find out yourself
![Arrow :arrow:](./images/smilies/icon_arrow.gif)
Note: This modification assumes that you have decided to force captcha to be used on reviews regardless of your Captcha settings in ISC Admin.
Right.. modification is as follows:
Create a folder structure like this one: /modules/custom/recaptcha (ie: add "custom" inside modules, and then a "recaptcha" inside that)
Download the reCaptcha PHP library from here
Place the recaptchalib.php file in your newly created folder ie: in /modules/custom/recaptcha
Open recaptchalib.php
Find:
Code: Select all
/**
* The reCAPTCHA server URL's
*/
Code: Select all
$recaptcha_private_key = 'Your_Private_API_key_for_this_site';
$recaptcha_public_key = 'Your_Public_API_key_for_this_site';
Open /includes/classes/class.review.php
Find:
Code: Select all
$captcha = '';
if(isset($_POST['captcha'])) {
$captcha = $_POST['captcha'];
}
$captcha_check = true;
// Should reviews be approved automatically?
if(GetConfig('AutoApproveReviews')) {
$status = 1;
}
else {
$status = 0;
}
// Do we need to check captcha?
if(GetConfig('CaptchaEnabled') && isc_strtolower($captcha) != isc_strtolower($GLOBALS['ISC_CLASS_CAPTCHA']->LoadSecret())) {
$_SESSION['productReviewData'] = $reviewPostData;
FlashMessage(GetLang('ReviewBadCaptcha'), MSG_ERROR, $prodReviewsLink, 'reviews');
exit;
}
Code: Select all
//***************************************
// MOD Use ReCaptcha instead of ISC system
require_once(dirname(__FILE__).'/../../modules/custom/recaptcha/recaptchalib.php');
if(isset($recaptcha_private_key) && isset($recaptcha_public_key)) {
$resp = recaptcha_check_answer ($recaptcha_private_key,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
// Invalid recaptcha so do as per normal ISC system
if (!$resp->is_valid) {
$_SESSION['productReviewData'] = $reviewPostData;
FlashMessage(GetLang('ReviewBadCaptcha'), MSG_ERROR, $prodReviewsLink, 'reviews');
exit;
}
}
/*
* If the recaptcha key isn't set we gracefully degrade
* back to the ISC system rather than leave it wide open
*/
else {
$captcha = '';
if(isset($_POST['captcha'])) {
$captcha = $_POST['captcha'];
}
$captcha_check = true;
// Should reviews be approved automatically?
if(GetConfig('AutoApproveReviews')) {
$status = 1;
}
else {
$status = 0;
}
//***************************************
// MOD Force Capcha for reviews
// Do we need to check captcha?
//if(GetConfig('CaptchaEnabled') && isc_strtolower($captcha) != isc_strtolower($GLOBALS['ISC_CLASS_CAPTCHA']->LoadSecret())) {
if(isc_strtolower($captcha) != isc_strtolower($GLOBALS['ISC_CLASS_CAPTCHA']->LoadSecret())) {
$_SESSION['productReviewData'] = $reviewPostData;
FlashMessage(GetLang('ReviewBadCaptcha'), MSG_ERROR, $prodReviewsLink, 'reviews');
exit;
}
// MOD END Force Captcha for reviews
//***************************************
}
// MOD END Use ReCaptcha instead of ISC system
//***************************************
Open: /modules/comments/builtincomments/module.builtincomments.php
Find:
Code: Select all
// Is captcha enabled?
if (GetConfig('CaptchaEnabled') == false) {
$GLOBALS['HideReviewCaptcha'] = "none";
}
else {
// Generate the captcha image
$GLOBALS['ISC_CLASS_CAPTCHA'] = GetClass('ISC_CAPTCHA');
$GLOBALS['ISC_CLASS_CAPTCHA']->CreateSecret();
$GLOBALS['CaptchaImage'] = $GLOBALS['ISC_CLASS_CAPTCHA']->ShowCaptcha();
}
Code: Select all
//***************************************
// MOD Force Capcha for reviews
/*
// Is captcha enabled?
if (GetConfig('CaptchaEnabled') == false) {
$GLOBALS['HideReviewCaptcha'] = "none";
}
else {
// Generate the captcha image
$GLOBALS['ISC_CLASS_CAPTCHA'] = GetClass('ISC_CAPTCHA');
$GLOBALS['ISC_CLASS_CAPTCHA']->CreateSecret();
$GLOBALS['CaptchaImage'] = $GLOBALS['ISC_CLASS_CAPTCHA']->ShowCaptcha();
}
*/
//***************************************
// MOD Use ReCaptcha instead of ISC system
require_once(dirname(__FILE__).'/../../custom/recaptcha/recaptchalib.php');
if(isset($recaptcha_private_key) && isset($recaptcha_public_key)) {
$GLOBALS['CaptchaImage'] = recaptcha_get_html($recaptcha_public_key);
$GLOBALS['CaptchaImage'] .= "
<script type=\"text/javascript\">
\$(function(){
$('#captcha').hide();
$('#captcha').val('true');
});
</script>
";
}
/*
* If the recaptcha key isn't set we gracefully degrade
* back to the ISC system rather than leave it wide open
*/
else {
// Generate the captcha image
$GLOBALS['ISC_CLASS_CAPTCHA'] = GetClass('ISC_CAPTCHA');
$GLOBALS['ISC_CLASS_CAPTCHA']->CreateSecret();
$GLOBALS['CaptchaImage'] = $GLOBALS['ISC_CLASS_CAPTCHA']->ShowCaptcha();
}
// MOD END Force Captcha for reviews
//***************************************
That's about it... This is a "free" mod but once again I would appreciate it if you would donate to the next charity bucket or sponsored form you see by way of passing it forward... Especially if you intend to resell this on to clients...