|
Revision 11316, 1.3 KB
(checked in by mistic100, 2 years ago)
|
|
activate captcha on comment form
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
|---|
| 4 | |
|---|
| 5 | $cryptinstall = CRYPTO_PATH.'cryptographp/cryptographp.fct.php'; |
|---|
| 6 | include($cryptinstall); |
|---|
| 7 | |
|---|
| 8 | add_event_handler('display_contactform', 'add_captcha'); |
|---|
| 9 | add_event_handler('check_contactform_params', 'check_captcha'); |
|---|
| 10 | |
|---|
| 11 | function 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 | |
|---|
| 21 | function captcha_prefilter($content, $smarty) |
|---|
| 22 | { |
|---|
| 23 | $search = ' |
|---|
| 24 | <tr> |
|---|
| 25 | <td class="contact-form-left"> </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 | |
|---|
| 38 | function 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 | ?> |
|---|