source: extensions/captcha/register.inc.php @ 13403

Last change on this file since 13403 was 8888, checked in by patdenice, 13 years ago

Add captcha to contactform (if installed).

File size: 1.2 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5include(CAPTCHA_PATH.'recaptchalib.php');
6add_event_handler('loc_end_page_header', 'add_captcha');
7add_event_handler('register_user_check', 'check_captcha');
8
9function 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
23function captcha_prefilter($content, $smarty)
24{
25  $search = '<p class="bottomButtons">';
26  return str_replace($search, '{$CAPTCHA}'."\n".$search, $content);
27}
28
29function 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?>
Note: See TracBrowser for help on using the repository browser.