source: extensions/CryptograPHP/include/contactform.inc.php @ 17484

Last change on this file since 17484 was 17484, checked in by mistic100, 12 years ago

update for the new Contact Form

File size: 2.0 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4load_language('plugin.lang', CRYPTO_PATH);
5add_event_handler('loc_begin_index', 'add_crypto');
6add_event_handler('contact_form_check', 'check_crypto', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
7
8function add_crypto()
9{
10  global $template;
11
12  if (!is_a_guest()) return;
13
14  $template->set_prefilter('index', 'prefilter_crypto');
15}
16
17function prefilter_crypto($content, $smarty)
18{
19  global $conf;
20 
21  $search = '{$contact.content}</textarea></td>';
22  $replace = $search.'
23      </tr>     
24      <tr>
25        <td class="title">
26          {\''.($conf['cryptographp']['captcha_type']=='string'?'Enter code':'Solve equation').'\'|@translate}
27        </td>
28        <td>
29          <input type="text" name="captcha_code" id="captcha_code" size="'.($conf['cryptographp']['code_length']+1).'" maxlength="'.$conf['cryptographp']['code_length'].'" />
30          <img id="captcha" src="{$ROOT_URL}'.CRYPTO_PATH.'securimage/securimage_show.php" alt="CAPTCHA Image" style="vertical-align:top;">
31          <a href="#" id="captcha_refresh" onclick="document.getElementById(\'captcha\').src = \'{$ROOT_URL}'.CRYPTO_PATH.'securimage/securimage_show.php?\' + Math.random(); return false">
32            <img src="{$ROOT_URL}'.CRYPTO_PATH.'template/refresh.png" style="vertical-align:bottom;"></a>
33        </td>
34       
35{footer_script}
36var captcha_code = new LiveValidation("captcha_code", {ldelim} onlyOnSubmit: true, insertAfterWhatNode: "captcha_refresh" });
37captcha_code.add(Validate.Presence, {ldelim} failureMessage: "{\'Invalid Captcha\'|@translate}" });
38{/footer_script}';
39 
40  return str_replace($search, $replace, $content);
41}
42
43function check_crypto($action, $comment)
44{
45  global $conf, $page;
46 
47  include_once(CRYPTO_PATH.'securimage/securimage.php');
48  $securimage = new Securimage();
49
50  if (!is_a_guest()) return $action;
51
52  if ($securimage->check($_POST['captcha_code']) == false)
53  {
54    array_push($page['errors'], l10n('Invalid Captcha'));
55    return 'reject';
56  }
57
58  return $action;
59}
60
61?>
Note: See TracBrowser for help on using the repository browser.