1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | add_event_handler('loc_end_picture', 'add_crypto'); |
---|
5 | add_event_handler('user_comment_check', 'check_crypto', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
6 | |
---|
7 | function add_crypto() |
---|
8 | { |
---|
9 | global $template; |
---|
10 | |
---|
11 | if (!is_a_guest()) return; |
---|
12 | |
---|
13 | $template->set_prefilter('picture', 'prefilter_crypto'); |
---|
14 | } |
---|
15 | |
---|
16 | function prefilter_crypto($content, $smarty) |
---|
17 | { |
---|
18 | global $conf; |
---|
19 | |
---|
20 | $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#'; |
---|
21 | $replace = '<input type="hidden" name="key" value="{$comment_add.KEY}"$1>'.' |
---|
22 | <label> |
---|
23 | <img id="captcha" src="'.CRYPTO_PATH.'securimage/securimage_show.php" alt="CAPTCHA Image"> |
---|
24 | <a href="#" onclick="document.getElementById(\'captcha\').src = \''.CRYPTO_PATH.'securimage/securimage_show.php?\' + Math.random(); return false"> |
---|
25 | <img src="'.CRYPTO_PATH.'template/refresh.png"></a> |
---|
26 | <br>{\''.($conf['cryptographp']['captcha_type']=='string'?'Enter code':'Solve equation').'\'|@translate} : |
---|
27 | <input type="text" name="captcha_code" size="'.($conf['cryptographp']['code_length']+1).'" maxlength="'.$conf['cryptographp']['code_length'].'" /> |
---|
28 | |
---|
29 | </label>'; |
---|
30 | |
---|
31 | return preg_replace($search, $replace, $content); |
---|
32 | } |
---|
33 | |
---|
34 | function check_crypto($action, $comment) |
---|
35 | { |
---|
36 | global $conf; |
---|
37 | |
---|
38 | include_once(CRYPTO_PATH.'securimage/securimage.php'); |
---|
39 | $securimage = new Securimage(); |
---|
40 | |
---|
41 | if ( $action == 'reject' or $action == $conf['cryptographp']['comments_action'] or !is_a_guest() ) |
---|
42 | { |
---|
43 | return $action; |
---|
44 | } |
---|
45 | |
---|
46 | if ($securimage->check($_POST['captcha_code']) == false) |
---|
47 | { |
---|
48 | return $conf['cryptographp']['comments_action']; |
---|
49 | } |
---|
50 | |
---|
51 | return $action; |
---|
52 | } |
---|
53 | |
---|
54 | ?> |
---|