1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Captcha |
---|
4 | Version: auto |
---|
5 | Description: Add captcha to registration form |
---|
6 | Plugin URI: auto |
---|
7 | Author: P@t |
---|
8 | Author URI: http://piwigo.org |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | define('CAPTCHA_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
13 | |
---|
14 | global $conf; |
---|
15 | |
---|
16 | if (script_basename() == 'register' |
---|
17 | and !empty($conf['captcha_publickey']) |
---|
18 | and !empty($conf['captcha_privatekey'])) |
---|
19 | { |
---|
20 | include(CAPTCHA_PATH.'recaptchalib.php'); |
---|
21 | add_event_handler('loc_end_page_header', 'add_captcha'); |
---|
22 | add_event_handler('register_user_check', 'check_captcha'); |
---|
23 | } |
---|
24 | elseif (script_basename() == 'admin') |
---|
25 | { |
---|
26 | add_event_handler('get_admin_plugin_menu_links', 'captcha_plugin_admin_menu' ); |
---|
27 | } |
---|
28 | |
---|
29 | function add_captcha() |
---|
30 | { |
---|
31 | global $template, $conf; |
---|
32 | |
---|
33 | $template->set_prefilter('register', 'captcha_prefilter'); |
---|
34 | $template->set_filename('captcha', realpath(CAPTCHA_PATH.'captcha.tpl')); |
---|
35 | $template->assign(array( |
---|
36 | 'CAPTCHA_HTML' => recaptcha_get_html($conf['captcha_publickey'], get_plugin_data('captcha')), |
---|
37 | 'CAPTCHA_THEME' => $conf['captcha_theme'], |
---|
38 | ) |
---|
39 | ); |
---|
40 | $template->assign_var_from_handle('CAPTCHA', 'captcha'); |
---|
41 | } |
---|
42 | |
---|
43 | function captcha_prefilter($content, $smarty) |
---|
44 | { |
---|
45 | $search = '<p class="bottomButtons">'; |
---|
46 | return str_replace($search, '{$CAPTCHA}'."\n".$search, $content); |
---|
47 | } |
---|
48 | |
---|
49 | function check_captcha($errors) |
---|
50 | { |
---|
51 | global $conf; |
---|
52 | |
---|
53 | $resp = recaptcha_check_answer( |
---|
54 | $conf['captcha_privatekey'], |
---|
55 | $_SERVER["REMOTE_ADDR"], |
---|
56 | $_POST["recaptcha_challenge_field"], |
---|
57 | $_POST["recaptcha_response_field"] |
---|
58 | ); |
---|
59 | |
---|
60 | if (!$resp->is_valid) |
---|
61 | { |
---|
62 | load_language('plugin.lang', CAPTCHA_PATH); |
---|
63 | array_push($errors, l10n('Invalid Captcha')); |
---|
64 | set_plugin_data('captcha', $resp->error); |
---|
65 | } |
---|
66 | |
---|
67 | return $errors; |
---|
68 | } |
---|
69 | |
---|
70 | function captcha_plugin_admin_menu($menu) |
---|
71 | { |
---|
72 | global $page,$conf; |
---|
73 | |
---|
74 | if ( (empty($conf['captcha_publickey']) or empty($conf['captcha_publickey'])) |
---|
75 | and in_array($page['page'], array('intro','plugins_list')) ) |
---|
76 | { |
---|
77 | load_language('plugin.lang', CAPTCHA_PATH); |
---|
78 | $page['errors'][] = l10n('You need to define Captcha keys'); |
---|
79 | } |
---|
80 | |
---|
81 | array_push($menu, |
---|
82 | array( |
---|
83 | 'NAME' => 'Captcha', |
---|
84 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php') |
---|
85 | ) |
---|
86 | ); |
---|
87 | return $menu; |
---|
88 | } |
---|
89 | |
---|
90 | ?> |
---|