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

Last change on this file since 26068 was 26068, checked in by mistic100, 11 years ago

compatibility with contactform and guestbook

File size: 897 bytes
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', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
7
8function add_easycaptcha()
9{
10  global $template;
11  $template->set_prefilter('guestbook', '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_CONTENT}';
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.