Ok this is my take on adding the recaptcha.
It is pure alpha, nothing tested, simply written by the instructions of
ReCaptcha for PHP. All operations are done in /class/captcha/ and all needed things are in the link above.
-1- download the Recaptcha and extract recaptchalib.php
-2- register and obtain an API key
-3- modify config.php and fill in your private key
return $config = array(
"disabled" => false, // Disable CAPTCHA
"mode" => 'recaptcha', // default mode image, text or recaptcha
"name" => 'xoopscaptcha', // captcha name
"skipmember" => true, // Skip CAPTCHA check for members
"maxattempt" => 10, // Maximum attempts for each session
"num_chars" => 4, // Maximum characters
"rule_text" => _CAPTCHA_RULE_TEXT,
"maxattempt_text" => _CAPTCHA_MAXATTEMPTS,
"private_key" => 'myAPIkey'
);
?>
-4- add config.recaptcha.php and fill in your public key
return $config = array(
"public_key" => 'myAPIkey'
);
?>
-5- add recaptcha.php
class XoopsCaptchaRecaptcha extends XoopsCaptchaMethod
{
function __construct($handler = null)
{
parent::__construct($handler);
parent::loadConfig('recaptcha');
}
function XoopsCaptchaImage($handler = null)
{
$this->__construct($handler);
}
function isActive()
{
return true;
}
function render()
{
$image = $this->loadImage();
return $image . '
';
}
function loadImage()
{
require_once(XOOPS_ROOT_PATH . '/class/captcha/'.'recaptchalib.php');
$publickey = $this->config["public_key"]; // you got this from the signup page see config.captcha.php
$ret = recaptcha_get_html($publickey);
return $ret;
}
}
?>
-6- insert
// Verify the ReCaptcha code
} elseif ($this->config["mode"] == 'recaptcha') {
require_once(XOOPS_ROOT_PATH . '/class/captcha/'.'recaptchalib.php');
$privatekey = $this->config["private_key"] ;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$this->message[] = $resp->error;
}
else {
$is_valid = true;
}
// Verify the code Captcha
before
} elseif (!empty($_SESSION["{$sessionName}_code"])) {
$func = !empty($this->config["casesensitive"]) ? "strcmp" : "strcasecmp";
$is_valid = ! $func( trim(@$_POST[$sessionName]), $_SESSION["{$sessionName}_code"] );
}
in xoopscaptcha.php
You need also to change:
$this->path_plugin = XOOPS_ROOT_PATH . "/Frameworks/captcha";
to
$this->path_plugin = XOOPS_ROOT_PATH . '/class/captcha';
in xoopscaptcha.php
-7- test
Edit: corrected include path and made it clearer for public and private keys.
- Added correction for Frameworks relic