1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | include(CAPTCHA_PATH.'recaptchalib.php'); |
---|
6 | add_event_handler('loc_end_page_header', 'add_captcha'); |
---|
7 | add_event_handler('register_user_check', 'check_captcha'); |
---|
8 | |
---|
9 | function add_captcha() |
---|
10 | { |
---|
11 | global $template, $conf; |
---|
12 | |
---|
13 | $template->set_prefilter('register', 'captcha_prefilter'); |
---|
14 | $template->set_filename('captcha', realpath(CAPTCHA_PATH.'captcha.tpl')); |
---|
15 | $template->assign(array( |
---|
16 | 'CAPTCHA_HTML' => recaptcha_get_html($conf['captcha_publickey'], get_plugin_data('captcha')), |
---|
17 | 'CAPTCHA_THEME' => $conf['captcha_theme'], |
---|
18 | ) |
---|
19 | ); |
---|
20 | $template->assign_var_from_handle('CAPTCHA', 'captcha'); |
---|
21 | } |
---|
22 | |
---|
23 | function captcha_prefilter($content, $smarty) |
---|
24 | { |
---|
25 | $search = '<p class="bottomButtons">'; |
---|
26 | return str_replace($search, '{$CAPTCHA}'."\n".$search, $content); |
---|
27 | } |
---|
28 | |
---|
29 | function check_captcha($errors) |
---|
30 | { |
---|
31 | global $conf; |
---|
32 | |
---|
33 | $resp = recaptcha_check_answer( |
---|
34 | $conf['captcha_privatekey'], |
---|
35 | $_SERVER["REMOTE_ADDR"], |
---|
36 | $_POST["recaptcha_challenge_field"], |
---|
37 | $_POST["recaptcha_response_field"] |
---|
38 | ); |
---|
39 | |
---|
40 | if (!$resp->is_valid) |
---|
41 | { |
---|
42 | load_language('plugin.lang', CAPTCHA_PATH); |
---|
43 | array_push($errors, l10n('Invalid Captcha')); |
---|
44 | set_plugin_data('captcha', $resp->error); |
---|
45 | } |
---|
46 | |
---|
47 | return $errors; |
---|
48 | } |
---|
49 | |
---|
50 | ?> |
---|