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

Last change on this file since 26069 was 26069, checked in by mistic100, 10 years ago

try to simplify integration of captchas

File size: 982 bytes
RevLine 
[24215]1<?php
2defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
3
[26069]4$conf['EasyCaptcha']['template'] = 'comment';
[24215]5include(EASYCAPTCHA_PATH.'include/common.inc.php');
[26069]6
[24215]7add_event_handler('loc_end_picture', 'add_easycaptcha');
8add_event_handler('user_comment_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
9
10function add_easycaptcha()
11{
12  global $template;
13  $template->set_prefilter('picture', 'prefilter_easycaptcha');
14}
15
16function prefilter_easycaptcha($content, $smarty)
17{
18  $search = '{$comment_add.CONTENT}</textarea></p>';
[26069]19  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content);
[24215]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.