1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173:
<?php
$plugin_is_filter = 5 | CLASS_PLUGIN;
$plugin_description = gettext("Google reCaptcha v2 handler.");
$plugin_author = "Ben Feather (Epsilon), Stephen Billard (sbillard), Malte Müller (acrylian)";
$plugin_disable = ($_zp_captcha->name && $_zp_captcha->name != 'reCaptcha') ? sprintf(gettext('Only one Captcha handler plugin may be enabled. <a href="#%1$s"><code>%1$s</code></a> is already enabled.'), $_zp_captcha->name) : '';
$plugin_notice = array(
gettext('Google account and reCaptcha key required.'),
gettext('Privacy note: This plugin uses external third party sources')
);
$option_interface = 'reCaptcha';
$plugin_category = gettext('Spam');
class reCaptcha extends _zp_captcha {
var $name = 'reCaptcha';
function __construct() {
setOptionDefault('reCaptcha_theme', 'light');
setOptionDefault('reCaptcha_type', 'image');
setOptionDefault('reCaptcha_size', 'normal');
}
function getOptionsSupported() {
return array(
gettext('Public key') => array(
'key' => 'reCaptcha_public_key',
'type' => OPTION_TYPE_TEXTBOX,
'order' => 1,
'desc' => gettext('Enter your <em>reCaptcha v2</em> public key. You can obtain this key from the Google <a href="http://www.google.com/recaptcha">reCaptcha</a> site')),
gettext('Private key') => array(
'key' => 'reCaptcha_private_key',
'type' => OPTION_TYPE_TEXTBOX,
'order' => 2,
'desc' => gettext('Enter your <em>reCaptcha v2</em> private key.')),
gettext('Widget Theme:') => array(
'key' => 'reCaptcha_theme',
'type' => OPTION_TYPE_SELECTOR,
'order' => 3,
'selections' => array(
gettext('Light') => 'light',
gettext('Dark') => 'dark'
),
'desc' => gettext('Choose the theme for your reCaptcha.')
),
gettext('Widget Type:') => array(
'key' => 'reCaptcha_type',
'type' => OPTION_TYPE_SELECTOR,
'order' => 4,
'selections' => array(
gettext('Audio') => 'audio',
gettext('Image') => 'image'
),
'desc' => gettext('Choose the secondary verification method you would like to use.')
),
gettext('Widget Size:') => array(
'key' => 'reCaptcha_size',
'type' => OPTION_TYPE_SELECTOR,
'order' => 5,
'selections' => array(
gettext('Normal') => 'normal',
gettext('Compact') => 'compact'
),
'desc' => gettext('Choose the size of the reCaptcha widget.')
)
);
}
function getCaptchaHTML($publicKey, $theme, $type, $size) {
return '<div class="g-recaptcha" data-sitekey="' . $publicKey . '" data-theme="' . $theme . '" data-type="' . $type . '" data-size="' . $size . '"></div>
<script src="https://www.google.com/recaptcha/api.js"></script>';
}
function checkCaptcha($s1, $s2) {
$secretKey = getOption('reCaptcha_private_key');
$captcha = '';
if(isset($_POST['g-recaptcha-response'])) {
$captcha = sanitize($_POST['g-recaptcha-response']);
}
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretKey . '&response=' . $captcha . '&remoteip=' . sanitize($_SERVER['REMOTE_ADDR']));
if (strpos($response, 'true') == true) {
$valid = true;
} else {
$valid = false;
}
return $valid;
}
function getCaptcha($prompt) {
$publicKey = getOption('reCaptcha_public_key');
$theme = getOption('reCaptcha_theme');
if (!in_array($theme, array('light', 'dark'))) {
$theme = 'light';
}
$type = getOption('reCaptcha_type');
$size = getOption('reCaptcha_size');
if (!getOption('reCaptcha_public_key') || !getOption('reCaptcha_private_key')) {
return array(
'input' => '',
'html' => '<div class="errorbox"><p>' . gettext('reCAPTCHA v2 keys are not configured properly. Visit <a href="https://www.google.com/recaptcha/intro/index.html">this link</a> to retrieve your reCaptcha keys.') . '</p></div>',
'hidden' => ''
);
} else {
$html = $this->getCaptchaHTML($publicKey, $theme, $type, $size);
return array(
'html' => '<label class="captcha-label">' . $prompt . '</label>',
'input' => $html
);
}
}
}
if ($plugin_disable) {
enableExtension('reCaptcha', 0);
} else {
$_zp_captcha = new reCaptcha(getOption('reCaptcha_private_key'));
}