Changeset 26069


Ignore:
Timestamp:
12/21/13 18:37:54 (6 years ago)
Author:
mistic100
Message:

try to simplify integration of captchas

Location:
extensions/EasyCaptcha
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/EasyCaptcha/include/category.inc.php

    r26025 r26069  
    22defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); 
    33 
     4$conf['EasyCaptcha']['template'] = 'comment'; 
    45include(EASYCAPTCHA_PATH.'include/common.inc.php'); 
     6 
    57add_event_handler('loc_begin_index', 'add_easycaptcha'); 
    68add_event_handler('user_comment_check_albums', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
     
    1517{ 
    1618  $search = '{$comment_add.CONTENT}</textarea></p>'; 
    17   return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content); 
     19  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content); 
    1820} 
    1921 
  • extensions/EasyCaptcha/include/common.inc.php

    r26025 r26069  
    2727 
    2828  $conf['EasyCaptcha']['drag']['selected'] = array_rand($conf['EasyCaptcha']['drag']['selection']); 
    29   $conf['EasyCaptcha']['drag']['text']     = l10n($drag_images[ $conf['EasyCaptcha']['drag']['selected'] ]); 
    30   $conf['EasyCaptcha']['key']      = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']); 
     29  $conf['EasyCaptcha']['drag']['text'] = l10n($drag_images[ $conf['EasyCaptcha']['drag']['selected'] ]); 
     30  $conf['EasyCaptcha']['key'] = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']); 
    3131} 
    3232// Tic-tac-toe 
     
    4949 
    5050$template->set_filename('EasyCaptcha', realpath(EASYCAPTCHA_PATH.'template/'.$conf['EasyCaptcha']['template'].'.tpl')); 
    51 $template->assign_var_from_handle('EASYCAPTCHA_CONTENT', 'EasyCaptcha'); 
     51$template->append('EASYCAPTCHA', array('parsed_content' => $template->parse('EasyCaptcha', true)), true); 
    5252 
    5353 
  • extensions/EasyCaptcha/include/contactform.inc.php

    r26068 r26069  
    22defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); 
    33 
     4$conf['EasyCaptcha']['template'] = 'contactform'; 
    45include(EASYCAPTCHA_PATH.'include/common.inc.php'); 
    5 add_event_handler('loc_begin_index', 'add_easycaptcha'); 
     6 
    67add_event_handler('contact_form_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
    7  
    8 function add_easycaptcha() 
    9 { 
    10   global $template; 
    11   $template->set_prefilter('contactform', 'prefilter_easycaptcha'); 
    12 } 
    13  
    14 function prefilter_easycaptcha($content, $smarty) 
    15 { 
    16   $search = '{$contact.content}</textarea></td>'; 
    17   return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content); 
    18 } 
    198 
    209function check_easycaptcha($action, $comment) 
  • extensions/EasyCaptcha/include/guestbook.inc.php

    r26068 r26069  
    22defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); 
    33 
     4$conf['EasyCaptcha']['template'] = 'guestbook'; 
    45include(EASYCAPTCHA_PATH.'include/common.inc.php'); 
    5 add_event_handler('loc_begin_index', 'add_easycaptcha'); 
     6 
    67add_event_handler('user_comment_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
    7  
    8 function add_easycaptcha() 
    9 { 
    10   global $template; 
    11   $template->set_prefilter('guestbook', 'prefilter_easycaptcha'); 
    12 } 
    13  
    14 function 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 } 
    208 
    219function check_easycaptcha($action, $comment) 
  • extensions/EasyCaptcha/include/picture.inc.php

    r26025 r26069  
    22defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); 
    33 
     4$conf['EasyCaptcha']['template'] = 'comment'; 
    45include(EASYCAPTCHA_PATH.'include/common.inc.php'); 
     6 
    57add_event_handler('loc_end_picture', 'add_easycaptcha'); 
    68add_event_handler('user_comment_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 
     
    1517{ 
    1618  $search = '{$comment_add.CONTENT}</textarea></p>'; 
    17   return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content); 
     19  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content); 
    1820} 
    1921 
  • extensions/EasyCaptcha/include/register.inc.php

    r26025 r26069  
    22defined('EASYCAPTCHA_ID') or die('Hacking attempt!'); 
    33 
     4$conf['EasyCaptcha']['template'] = 'register'; 
    45include(EASYCAPTCHA_PATH.'include/common.inc.php'); 
     6 
    57add_event_handler('loc_end_page_header', 'add_easycaptcha'); 
    68add_event_handler('register_user_check', 'check_easycaptcha'); 
     
    1517{ 
    1618  $search = '<input type="checkbox" name="send_password_by_mail" id="send_password_by_mail" value="1" checked="checked">'; 
    17   return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content); 
     19  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content); 
    1820} 
    1921 
  • extensions/EasyCaptcha/main.inc.php

    r26025 r26069  
    3232{ 
    3333  add_event_handler('loc_end_section_init', 'easycaptcha_document_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30); 
     34  add_event_handler('loc_begin_register', 'easycaptcha_register_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30); 
    3435} 
    3536 
     
    5960  } 
    6061 
    61   if (script_basename() == 'register' && $conf['EasyCaptcha']['activate_on']['register']) 
     62  if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture']) 
    6263  { 
    63     $conf['EasyCaptcha']['template'] = 'register'; 
    64     include(EASYCAPTCHA_PATH . 'include/register.inc.php'); 
    65   } 
    66   else if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture']) 
    67   { 
    68     $conf['EasyCaptcha']['template'] = 'comment'; 
    6964    include(EASYCAPTCHA_PATH . 'include/picture.inc.php'); 
    7065  } 
     
    7873      ) 
    7974    { 
    80       $conf['EasyCaptcha']['template'] = 'comment'; 
    8175      include(EASYCAPTCHA_PATH . 'include/category.inc.php'); 
    8276    } 
    8377    else if ($page['section'] == 'contact' && $conf['EasyCaptcha']['activate_on']['contactform']) 
    8478    { 
    85       $conf['EasyCaptcha']['template'] = 'contactform'; 
    8679      include(EASYCAPTCHA_PATH . 'include/contactform.inc.php'); 
    8780    } 
    8881    else if ($page['section'] == 'guestbook' && $conf['EasyCaptcha']['activate_on']['guestbook']) 
    8982    { 
    90       $conf['EasyCaptcha']['template'] = 'guestbook'; 
    9183      include(EASYCAPTCHA_PATH . 'include/guestbook.inc.php'); 
    9284    } 
     85  } 
     86} 
     87function easycaptcha_register_init() 
     88{ 
     89  global $conf; 
     90 
     91  if (!is_a_guest()) 
     92  { 
     93    return; 
     94  } 
     95 
     96  if ($conf['EasyCaptcha']['activate_on']['register']) 
     97  { 
     98    include(EASYCAPTCHA_PATH . 'include/register.inc.php'); 
    9399  } 
    94100} 
  • extensions/EasyCaptcha/template/contactform.tpl

    r26025 r26069  
    1 </tr> 
    21<tr> 
    32  {include file=$EASYCAPTCHA_ABS_PATH|cat:'template/common.inc.tpl'} 
     
    54  {* <!-- DRAG & DROP --> *} 
    65  {if $EASYCAPTCHA.challenge == 'drag'} 
    7   <td class="title">{'To verify you are a human, please place the <b>%s</b> in the most right box bellow.'|translate:$EASYCAPTCHA.drag.text}</td> 
     6  <td class="title"></td> 
     7  <td> 
     8    {'To verify you are a human, please place the <b>%s</b> in the most right box bellow.'|translate:$EASYCAPTCHA.drag.text} 
     9    {$smarty.capture.easycaptcha} 
     10  </td> 
    811 
    912  {footer_script} 
     
    1316 
    1417  {* <!-- TIC TAC TOE --> *} 
    15   {else if $EASYCAPTCHA..challenge == 'tictac'} 
    16   <td class="title">{'You are player X, click on the right case to complete the line.'|translate}</td> 
     18  {else if $EASYCAPTCHA.challenge == 'tictac'} 
     19  <td class="title"></td> 
     20  <td> 
     21    {'You are player X, click on the right case to complete the line.'|translate} 
     22    {$smarty.capture.easycaptcha} 
     23  </td> 
    1724 
    1825  {footer_script} 
     
    2734 
    2835  {/if} 
    29   <td> 
    30     {$smarty.capture.easycaptcha} 
    31   </td> 
     36</tr> 
Note: See TracChangeset for help on using the changeset viewer.