source: extensions/EasyCaptcha/include/category.inc.php @ 26069

Revision 26069, 1001 bytes checked in by mistic100, 6 years ago (diff)

try to simplify integration of captchas

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