source: extensions/captcha/main.inc.php @ 8038

Last change on this file since 8038 was 8034, checked in by patdenice, 13 years ago

Display corrected in IE8.
Add theme interface select in admin pannel.

File size: 2.2 KB
Line 
1<?php
2/*
3Plugin Name: Captcha
4Version: auto
5Description: Add captcha to registration form
6Plugin URI: auto
7Author: P@t
8Author URI: http://piwigo.org
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12define('CAPTCHA_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
13
14global $conf;
15
16if (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}
24elseif (script_basename() == 'admin')
25{
26  add_event_handler('get_admin_plugin_menu_links', 'captcha_plugin_admin_menu' );
27}
28
29function 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
43function captcha_prefilter($content, $smarty)
44{
45  $search = '<p class="bottomButtons">';
46  return str_replace($search, '{$CAPTCHA}'."\n".$search, $content);
47}
48
49function 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
70function 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?>
Note: See TracBrowser for help on using the repository browser.