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 | |
---|
25 | if (script_basename() == 'admin') |
---|
26 | { |
---|
27 | add_event_handler('get_admin_plugin_menu_links', 'captcha_plugin_admin_menu' ); |
---|
28 | } |
---|
29 | |
---|
30 | function add_captcha() |
---|
31 | { |
---|
32 | global $template, $conf; |
---|
33 | |
---|
34 | $template->set_prefilter('register', 'captcha_prefilter'); |
---|
35 | $template->set_filename('captcha', realpath(CAPTCHA_PATH.'captcha.tpl')); |
---|
36 | $template->assign('CAPTCHA_HTML', recaptcha_get_html($conf['captcha_publickey'], get_plugin_data('captcha'))); |
---|
37 | $template->assign_var_from_handle('CAPTCHA', 'captcha'); |
---|
38 | } |
---|
39 | |
---|
40 | function captcha_prefilter($content, $smarty) |
---|
41 | { |
---|
42 | $search = '<p class="bottomButtons">'; |
---|
43 | $captcha = '{$CAPTCHA}'; |
---|
44 | |
---|
45 | return str_replace($search, $captcha."\n".$search, $content); |
---|
46 | } |
---|
47 | |
---|
48 | function check_captcha($errors) |
---|
49 | { |
---|
50 | global $conf; |
---|
51 | |
---|
52 | $resp = recaptcha_check_answer( |
---|
53 | $conf['captcha_privatekey'], |
---|
54 | $_SERVER["REMOTE_ADDR"], |
---|
55 | $_POST["recaptcha_challenge_field"], |
---|
56 | $_POST["recaptcha_response_field"] |
---|
57 | ); |
---|
58 | |
---|
59 | if (!$resp->is_valid) |
---|
60 | { |
---|
61 | load_language('plugin.lang', CAPTCHA_PATH); |
---|
62 | array_push($errors, l10n('Invalid Captcha')); |
---|
63 | set_plugin_data('captcha', $resp->error); |
---|
64 | } |
---|
65 | |
---|
66 | return $errors; |
---|
67 | } |
---|
68 | |
---|
69 | function captcha_plugin_admin_menu($menu) |
---|
70 | { |
---|
71 | global $page,$conf; |
---|
72 | |
---|
73 | if ( (empty($conf['captcha_publickey']) or empty($conf['captcha_publickey'])) |
---|
74 | and in_array($page['page'], array('intro','plugins_list')) ) |
---|
75 | { |
---|
76 | load_language('plugin.lang', CAPTCHA_PATH); |
---|
77 | $page['errors'][] = l10n('You need to define Captcha keys'); |
---|
78 | } |
---|
79 | |
---|
80 | array_push($menu, |
---|
81 | array( |
---|
82 | 'NAME' => 'Captcha', |
---|
83 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin.php') |
---|
84 | ) |
---|
85 | ); |
---|
86 | return $menu; |
---|
87 | } |
---|
88 | |
---|
89 | ?> |
---|