|
Revision 11316, 1.2 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('loc_begin_index', 'add_captcha'); |
|---|
| 9 | add_event_handler('user_comment_check', 'check_captcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
|---|
| 10 | |
|---|
| 11 | function add_captcha() |
|---|
| 12 | { |
|---|
| 13 | global $template, $conf; |
|---|
| 14 | |
|---|
| 15 | if (!is_a_guest()) return; |
|---|
| 16 | |
|---|
| 17 | $template->set_prefilter('comments_on_albums', '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 | load_language('plugin.lang', CRYPTO_PATH); |
|---|
| 24 | |
|---|
| 25 | $search = '<input type="hidden" name="key" value="{$comment_add.KEY}">'; |
|---|
| 26 | $replace = $search.' |
|---|
| 27 | <label>{$CAPTCHA}<input type="text" name="code"></label>'; |
|---|
| 28 | |
|---|
| 29 | return str_replace($search, $replace, $content); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function check_captcha($action, $comment) |
|---|
| 33 | { |
|---|
| 34 | global $conf, $user; |
|---|
| 35 | |
|---|
| 36 | $my_action = ($conf['cryptographp_theme'][1] == 'reject') ? 'reject':'moderate'; |
|---|
| 37 | |
|---|
| 38 | if ($action == 'reject' OR $action == $my_action OR !is_a_guest()) |
|---|
| 39 | { |
|---|
| 40 | return $action; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | if (!chk_crypt($_POST['code'])) |
|---|
| 44 | { |
|---|
| 45 | return $my_action; |
|---|
| 46 | } |
|---|
| 47 | else |
|---|
| 48 | { |
|---|
| 49 | return $action; |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | ?> |
|---|