source: extensions/EasyCaptcha/include/guestbook.inc.php @ 24215

Revision 24215, 895 bytes checked in by mistic100, 6 years ago (diff)

add extension EasyCaptcha

Line 
1<?php
2defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
3
4include(EASYCAPTCHA_PATH.'include/common.inc.php');
5add_event_handler('loc_begin_index', 'add_easycaptcha');
6add_event_handler('user_comment_check_guestbook', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
7
8function add_easycaptcha()
9{
10  global $template;
11  $template->set_prefilter('index', 'prefilter_easycaptcha');
12}
13
14function prefilter_easycaptcha($content, $smarty)
15{
16  $search = '#{\$comment_add\.CONTENT}</textarea>(\s*)</td>(\s*)</tr>#';
17  $replace = '{\$comment_add.CONTENT}</textarea>$1</td>$2</tr>'."\n".'{\$EASYCAPTCHA}';
18  return preg_replace($search, $replace, $content);
19}
20
21function check_easycaptcha($action, $comment)
22{
23  global $conf, $page;
24
25  if (!is_a_guest()) return $action;
26
27  if (!easycaptcha_check())
28  {
29    $page['errors'][] = l10n('Invalid answer');
30    return 'reject';
31  }
32
33  return $action;
34}
Note: See TracBrowser for help on using the repository browser.