1: <?php
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: $plugin_is_filter = 5 | CLASS_PLUGIN;
29: $plugin_description = gettext("Google reCaptcha handler.");
30: $plugin_author = "Stephen Billard (sbillard)";
31: $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) : '';
32:
33: $option_interface = 'reCaptcha';
34:
35: require_once(dirname(__FILE__) . '/reCaptcha/recaptchalib.php');
36:
37: class reCaptcha extends _zp_captcha {
38:
39: var $name = 'reCaptcha';
40:
41: 42: 43: 44: 45:
46: function __construct() {
47: setOptionDefault('reCaptcha_theme', 'red');
48: }
49:
50: 51: 52: 53: 54:
55: function getOptionsSupported() {
56: $themes = array(gettext('Red') => 'red', gettext('White') => 'white', gettext('Black Glass') => 'blackglass', gettext('Clean') => 'clean');
57: $custom = getPluginFiles('*', 'reCaptcha', false);
58: foreach ($custom as $theme => $path) {
59: if (is_dir($path)) {
60: $themes[$theme = basename($theme)] = $theme;
61: }
62: }
63:
64: return array(
65: gettext('Public key') => array('key' => 'reCaptcha_public_key', 'type' => OPTION_TYPE_TEXTBOX,
66: 'order' => 1,
67: 'desc' => gettext('Enter your <em>reCaptcha</em> public key. You can obtain this key from the Google <a href="http://www.google.com/recaptcha">reCaptcha</a> site')),
68: gettext('Private key') => array('key' => 'reCaptcha_private_key', 'type' => OPTION_TYPE_TEXTBOX,
69: 'order' => 2,
70: 'desc' => gettext('Enter your <em>reCaptcha</em> private key.')),
71: gettext('Theme') => array('key' => 'reCaptcha_theme', 'type' => OPTION_TYPE_SELECTOR,
72: 'order' => 3,
73: 'selections' => $themes,
74: 'desc' => gettext('Select the <em>reCaptcha</em> theme.')),
75: '' => array('key' => 'reCcaptcha_image', 'type' => OPTION_TYPE_CUSTOM,
76: 'order' => 4,
77: 'desc' => gettext('Sample CAPTCHA image'))
78: );
79: }
80:
81: function handleOption($key, $cv) {
82: $captcha = $this->getCaptcha(NULL);
83: ?>
84: <span id="zenphoto_captcha_image_loc"><?php echo $captcha['input']; ?></span>
85: <?php
86: }
87:
88: 89: 90: 91: 92:
93: function checkCaptcha($s1, $s2) {
94: $resp = recaptcha_check_answer(getOption('reCaptcha_private_key'), @$_SERVER["REMOTE_ADDR"], @$_POST["recaptcha_challenge_field"], @$_POST["recaptcha_response_field"]);
95: return $resp->is_valid;
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105: 106:
107: function getCaptcha($prompt) {
108: $theme = getOption('reCaptcha_theme');
109: $publicKey = getOption('reCaptcha_public_key');
110: $lang = strtolower(substr(ZENPHOTO_LOCALE, 0, 2));
111:
112: if (!getOption('reCaptcha_public_key')) {
113: return array('input' => '', 'html' => '<p class="errorbox">' . gettext('reCAPTCHA is not properly configured.') . '</p>', 'hidden' => '');
114: } else {
115:
116: $source = getPlugin('reCaptcha/' . $theme . '/reCaptcha.html');
117: if ($source) {
118: $webpath = dirname(getplugin('reCaptcha/' . $theme . '/reCaptcha.html', false, true));
119: $tr = array('__GETHELP__' => gettext("Help"),
120: '__GETIMAGE__' => gettext("Get a visual challenge"),
121: '__GETAUDIO__' => gettext("Get an audio challenge"),
122: '__RELOAD__' => gettext("Get another challenge"),
123: '__WORDS__' => gettext("Type the two words"),
124: '__NUMBERS__' => gettext("Type what you hear"),
125: '__ERROR__' => gettext("Incorrect please try again"),
126: '__SOURCEWEBPATH__' => $webpath);
127: $html = strtr(file_get_contents($source), $tr);
128: $theme = 'custom';
129: } else {
130: $html = '';
131: }
132: $themejs = '<script type="text/javascript">' . "\n" .
133: " var RecaptchaOptions = {\n";
134: if (!in_array($lang, array('de', 'en', 'es', 'fr', 'nl', 'ru', 'pt', 'tr'))) {
135: $themejs .= " custom_translations : {\n" .
136: " instructions_visual : 'Type the two words',\n" .
137: " instructions_audio : 'Type what you hear',\n" .
138: " play_again : 'Play sound again',\n" .
139: " cant_hear_this : 'Download the sound as MP3',\n" .
140: " visual_challenge : 'Get a visual challenge',\n" .
141: " audio_challenge : 'Get an audio challenge',\n" .
142: " refresh_btn : 'Get another challenge',\n" .
143: " help_btn : 'Help',\n" .
144: " incorrect_try_again : 'Incorrect please try again',\n" .
145: " },\n";
146: }
147: $themejs .= " lang : '$lang',\n" .
148: " theme : '$theme'\n" .
149: " };\n" .
150: "</script>\n";
151: $html .= recaptcha_get_html($publicKey, NULL, secureServer());
152: return array('html' => '<label class="captcha_label">' . $prompt . '</label>', 'input' => $themejs . $html);
153: }
154: }
155:
156: }
157:
158: if ($plugin_disable) {
159: enableExtension('reCaptcha', 0);
160: } else {
161: $_zp_captcha = new reCaptcha();
162: }
163: ?>
164: