source: extensions/CryptograPHP/include/contactform.inc.php @ 11316

Last change on this file since 11316 was 11316, checked in by mistic100, 13 years ago

activate captcha on comment form

File size: 1.3 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5$cryptinstall = CRYPTO_PATH.'cryptographp/cryptographp.fct.php';
6include($cryptinstall);
7
8add_event_handler('display_contactform', 'add_captcha');
9add_event_handler('check_contactform_params', 'check_captcha');
10
11function add_captcha()
12{
13  global $template, $conf;
14
15  if (!is_a_guest()) return;
16
17  $template->set_prefilter('cf_form', 'captcha_prefilter');
18  $template->assign('CAPTCHA', dsp_crypt($conf['cryptographp_theme'][0].'.cfg.php',1));
19}
20
21function captcha_prefilter($content, $smarty)
22{
23  $search = '
24      <tr>
25        <td class="contact-form-left">&nbsp;</td>
26        <td class="contact-form-right"><input class="submit" type="submit" value="{\'cf_submit\'|@translate}"></td>
27      </tr>';
28  $replace = '
29    <tr>
30      <td class="contact-form-left" style="vertical-align:top;">{\'Antibot test\'|@translate}</td>
31      <td class="contact-form-right"><input type="text" name="code"> <span style="vertical-align:top;">{$CAPTCHA}</span></td>
32    </tr>'
33  ."\n".$search;
34 
35  return str_replace($search, $replace, $content);
36}
37
38function check_captcha($infos)
39{
40  if (!is_a_guest()) return $infos;
41
42  if (!chk_crypt($_POST['code']))
43  {
44    load_language('plugin.lang', CRYPTO_PATH);
45    array_push($infos['errors'], l10n('Invalid Captcha'));
46  }
47
48  return $infos;
49}
50
51?>
Note: See TracBrowser for help on using the repository browser.