Changeset 8888 for extensions/captcha


Ignore:
Timestamp:
01/25/11 16:42:40 (9 years ago)
Author:
patdenice
Message:

Add captcha to contactform (if installed).

Location:
extensions/captcha
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/captcha/main.inc.php

    r8034 r8888  
    1414global $conf; 
    1515 
    16 if (script_basename() == 'register' 
    17   and !empty($conf['captcha_publickey']) 
    18   and !empty($conf['captcha_privatekey'])) 
     16if (!empty($conf['captcha_publickey']) and !empty($conf['captcha_privatekey'])) 
    1917{ 
    20   include(CAPTCHA_PATH.'recaptchalib.php'); 
    21   add_event_handler('loc_end_page_header', 'add_captcha'); 
    22   add_event_handler('register_user_check', 'check_captcha'); 
    23 } 
    24 elseif (script_basename() == 'admin') 
    25 { 
    26   add_event_handler('get_admin_plugin_menu_links', 'captcha_plugin_admin_menu' ); 
     18  if (script_basename() == 'register') include('register.inc.php'); 
     19  elseif (isset($_GET['/contact'])) include('contactform.inc.php'); 
    2720} 
    2821 
    29 function add_captcha() 
    30 { 
    31   global $template, $conf; 
    32  
    33   $template->set_prefilter('register', 'captcha_prefilter'); 
    34   $template->set_filename('captcha', realpath(CAPTCHA_PATH.'captcha.tpl')); 
    35   $template->assign(array( 
    36     'CAPTCHA_HTML'  => recaptcha_get_html($conf['captcha_publickey'], get_plugin_data('captcha')), 
    37     'CAPTCHA_THEME' => $conf['captcha_theme'], 
    38     ) 
    39   ); 
    40   $template->assign_var_from_handle('CAPTCHA', 'captcha'); 
    41 } 
    42  
    43 function captcha_prefilter($content, $smarty) 
    44 { 
    45   $search = '<p class="bottomButtons">'; 
    46   return str_replace($search, '{$CAPTCHA}'."\n".$search, $content); 
    47 } 
    48  
    49 function check_captcha($errors) 
    50 { 
    51   global $conf; 
    52  
    53   $resp = recaptcha_check_answer( 
    54     $conf['captcha_privatekey'], 
    55     $_SERVER["REMOTE_ADDR"], 
    56     $_POST["recaptcha_challenge_field"], 
    57     $_POST["recaptcha_response_field"] 
    58   ); 
    59  
    60   if (!$resp->is_valid) 
    61   { 
    62     load_language('plugin.lang', CAPTCHA_PATH); 
    63     array_push($errors, l10n('Invalid Captcha')); 
    64     set_plugin_data('captcha', $resp->error); 
    65   } 
    66  
    67   return $errors; 
    68 } 
     22if (script_basename() == 'admin') 
     23  add_event_handler('get_admin_plugin_menu_links', 'captcha_plugin_admin_menu' ); 
    6924 
    7025function captcha_plugin_admin_menu($menu) 
Note: See TracChangeset for help on using the changeset viewer.