diff --git a/auth/email/auth.php b/auth/email/auth.php
index 82e0ba29a6c..461e198e44f 100644
--- a/auth/email/auth.php
+++ b/auth/email/auth.php
@@ -206,6 +206,15 @@ class auth_plugin_email extends auth_plugin_base {
set_config('recaptcha', $config->recaptcha, 'auth/email');
return true;
}
+
+ /**
+ * Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
+ * @abstract Implement in child classes
+ * @return bool
+ */
+ function is_captcha_enabled() {
+ return false;
+ }
}
diff --git a/lang/en_utf8/auth.php b/lang/en_utf8/auth.php
index 90c0b133d22..ccaf4db7d77 100644
--- a/lang/en_utf8/auth.php
+++ b/lang/en_utf8/auth.php
@@ -378,8 +378,8 @@ $string['unlocked'] = 'Unlocked';
$string['unlockedifempty'] = 'Unlocked if empty';
$string['locked'] = 'Locked';
$string['incorrectpleasetryagain'] = 'Incorrect. Please try again.';
-$string['enterthewordsabove'] = 'Enter the words above:';
-$string['enterthenumbersyouhear'] = 'Enter the numbers you hear:';
+$string['enterthewordsabove'] = 'Enter the words above';
+$string['enterthenumbersyouhear'] = 'Enter the numbers you hear';
$string['getanothercaptcha'] = 'Get another CAPTCHA';
$string['getanaudiocaptcha'] = 'Get an audio CAPTCHA';
$string['getanimagecaptcha'] = 'Get an image CAPTCHA';
diff --git a/lib/authlib.php b/lib/authlib.php
index 242d2cd3a4f..2cbdda31d13 100644
--- a/lib/authlib.php
+++ b/lib/authlib.php
@@ -342,6 +342,17 @@ class auth_plugin_base {
}
return $authdescription;
}
+
+ /**
+ * Returns whether or not the captcha element is enabled, and the admin settings fulfil its requirements.
+ * @abstract Implement in child classes
+ * @return bool
+ */
+ function is_captcha_enabled() {
+ return false;
+ }
+
+
}
?>
diff --git a/lib/form/recaptcha.php b/lib/form/recaptcha.php
index 71f3c10e799..f3c4ad703b2 100644
--- a/lib/form/recaptcha.php
+++ b/lib/form/recaptcha.php
@@ -75,11 +75,11 @@ class MoodleQuickForm_recaptcha extends HTML_QuickForm_input {
' . $strincorrectpleasetryagain . '
-' . $strenterthewordsabove . '
-' . $strenterthenumbersyouhear . '
+
+
-
+
diff --git a/lib/recaptchalib.php b/lib/recaptchalib.php
index c980a6673ca..65f46a211bc 100644
--- a/lib/recaptchalib.php
+++ b/lib/recaptchalib.php
@@ -66,22 +66,20 @@ function _recaptcha_qsencode ($data) {
*/
function _recaptcha_http_post($host, $path, $data, $port = 80) {
global $CFG;
- require_once $CFG->libdir . '/snoopy/Snoopy.class.inc';
+ require_once $CFG->libdir . '/filelib.php';
- $snoopy = new Snoopy();
- $snoopy->proxy_host = $CFG->proxyhost;
- $snoopy->proxy_port = $CFG->proxyport;
+ $req = _recaptcha_qsencode ($data);
- if (!empty($CFG->proxyuser) and !empty($CFG->proxypassword)) {
- // this will probably fail, but let's try it anyway
- $snoopy->proxy_user = $CFG->proxyuser;
- $snoopy->proxy_password = $CFG->proxypassword;
- }
+ $headers = array();
+ $headers['Host'] = $host;
+ $headers['Content-Type'] = 'application/x-www-form-urlencoded';
+ $headers['Content-Length'] = strlen($req);
+ $headers['User-Agent'] = 'reCAPTCHA/PHP';
- $submit = $snoopy->submit('http://' . $host . $path, $data);
+ $results = download_file_content('http://' . $host . $path, $headers, $data);
- if ($submit) {
- return array(1 => $snoopy->results);
+ if ($results) {
+ return array(1 => $results);
} else {
return false;
}
@@ -99,8 +97,11 @@ function _recaptcha_http_post($host, $path, $data, $port = 80) {
* @return string - The HTML to be embedded in the user's form.
*/
-function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
-{
+function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false) {
+ global $CFG;
+
+ $recaptchatype = optional_param('recaptcha', 'image', PARAM_TEXT);
+
if ($pubkey == null || $pubkey == '') {
die ("To use reCAPTCHA you must get an API key from http://recaptcha.net/api/getkey");
}
@@ -115,13 +116,53 @@ function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
if ($error) {
$errorpart = "&error=" . $error;
}
- return '
+ require_once $CFG->libdir . '/filelib.php';
+ $html = download_file_content($server . '/noscript?k=' . $pubkey . $errorpart);
+ preg_match('/image\?c\=([A-Za-z0-9\-\_]*)\"/', $html, $matches);
+ $challenge_hash = $matches[1];
+ $image_url = $server . '/image?c=' . $challenge_hash;
+
+ $strincorrectpleasetryagain = get_string('incorrectpleasetryagain', 'auth');
+ $strenterthewordsabove = get_string('enterthewordsabove', 'auth');
+ $strenterthenumbersyouhear = get_string('enterthenumbersyouhear', 'auth');
+ $strgetanothercaptcha = get_string('getanothercaptcha', 'auth');
+ $strgetanaudiocaptcha = get_string('getanaudiocaptcha', 'auth');
+ $strgetanimagecaptcha = get_string('getanimagecaptcha', 'auth');
+
+ $return = '
';
+
+ return $return;
}