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

Revision 26069, 2.3 KB 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
4include_once(EASYCAPTCHA_PATH . 'drag/functions_drag.inc.php');
5
6global $template;
7
8// choose random challenge
9if ($conf['EasyCaptcha']['challenge'] == 'random')
10{
11  $challenges = array('tictac', 'drag');
12  $conf['EasyCaptcha']['challenge'] = $challenges[ rand(0,1) ];
13}
14
15// Drag & drop
16if ($conf['EasyCaptcha']['challenge'] == 'drag')
17{
18  load_language($conf['EasyCaptcha']['drag']['theme'].'.lang', EASYCAPTCHA_PATH);
19
20  $drag_images = include(EASYCAPTCHA_PATH.'drag/'.$conf['EasyCaptcha']['drag']['theme'].'/conf.inc.php');
21  $conf['EasyCaptcha']['drag']['nb'] = min($conf['EasyCaptcha']['drag']['nb'], count($drag_images));
22
23  foreach (array_rand($drag_images, $conf['EasyCaptcha']['drag']['nb']) as $row)
24  {
25    $conf['EasyCaptcha']['drag']['selection'][ $row ] = easycaptcha_encode_image_url($row);
26  }
27
28  $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']);
31}
32// Tic-tac-toe
33else if ($conf['EasyCaptcha']['challenge'] == 'tictac')
34{
35  $conf['EasyCaptcha']['key'] = $conf['EasyCaptcha']['challenge'] .'-0';
36}
37else
38{
39  return;
40}
41
42load_language('plugin.lang', EASYCAPTCHA_PATH);
43
44$template->assign(array(
45  'EASYCAPTCHA' => $conf['EasyCaptcha'],
46  'EASYCAPTCHA_PATH' => EASYCAPTCHA_PATH,
47  'EASYCAPTCHA_ABS_PATH' => realpath(EASYCAPTCHA_PATH).'/',
48  ));
49
50$template->set_filename('EasyCaptcha', realpath(EASYCAPTCHA_PATH.'template/'.$conf['EasyCaptcha']['template'].'.tpl'));
51$template->append('EASYCAPTCHA', array('parsed_content' => $template->parse('EasyCaptcha', true)), true);
52
53
54function easycaptcha_check()
55{
56  global $conf;
57
58  if (empty($_POST['easycaptcha_key']) || empty($_POST['easycaptcha']))
59  {
60    return false;
61  }
62
63  list($challenge, $key) = explode('-', $_POST['easycaptcha_key']);
64
65  if ($challenge == 'drag')
66  {
67    $check = easycaptcha_decode_image_url($_POST['easycaptcha']);
68    return pwg_password_verify($conf['secret_key'] . $check, $key);
69  }
70  else if ($challenge == 'tictac')
71  {
72    return $_POST['easycaptcha'] == pwg_get_session_var('easycaptcha', '33');
73  }
74  else
75  {
76    return false;
77  }
78}
Note: See TracBrowser for help on using the repository browser.