Project

General

Profile

1 596 thorn
<?php
2
3
// $Id$
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
/* CAPTCHA - How to use:
27
 * use
28
 *	require_once(WB_PATH.'/include/captcha/captcha.php');
29
 * and put
30
 *	<?php call_captcha(); ?>
31
 * into your form.
32
 *
33
 * captcha-code is in $_SESSION['captcha']
34
 * user input in $_POST['captcha']
35
 */
36
37
// Must include code to stop this file being accessed directly
38
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
39
40
if(!isset($admin)) {
41
	require_once(WB_PATH.'/framework/class.wb.php');
42
	$admin = new wb;
43
}
44
45
// check if module language file exists for the language set by the user (e.g. DE, EN)
46
global $MOD_CAPTCHA;
47
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
48
	// no module language file exists for the language set by the user, include default module language file EN.php
49
	require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
50
} else {
51
	// a module language file exists for the language defined by the user, load it
52
	require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
53
}
54
55
// output-handler for image-captchas to determine size of image
56
if(!function_exists('captcha_header')) {
57
	function captcha_header() {
58
		header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
59
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
60
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
61
		header("Cache-Control: post-check=0, pre-check=0", false); // MS made there own headers :-(
62
		header("Pragma: no-cache");
63
		header("Content-type: image/png");
64
		return;
65
	}
66
}
67
68
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
69
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
70
	$useable_captchas = array(
71
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
72
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
73
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
74
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE']
75
	);
76
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
77
	$useable_captchas = array(
78
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
79
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
80
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE']
81
	);
82
} else {
83
	$useable_captchas = array(
84
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT']
85
	);
86
}
87
88
if(!function_exists('call_captcha')) {
89
	function call_captcha() {
90
		global $MOD_CAPTCHA;
91
92
		switch(CAPTCHA_TYPE) {
93
			// two special cases
94
			case 'calc_text': // calculation as text
95
				?>
96
				<?php include(WB_PATH.'/include/captcha/captchas/calc_text.php'); ?> =
97
				<input type="text" name="captcha" maxlength="5"  style="width:20px" />&nbsp;&nbsp;<?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></font>
98
				<?php
99
				break;
100
			case 'calc_image': // calculation with image (old captcha)
101
				?>
102
				<img src="<?php echo WB_URL.'/include/captcha/captchas/calc_image.php?t='.time(); ?>" align="middle" alt="Captcha" /> =
103
				<input type="text" name="captcha" maxlength="5" style="width:20px" />&nbsp;&nbsp;<?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></font>
104
				<?php
105
				break;
106
			// normal images
107
			case 'ttf_image': // captcha with varying background and ttf-font
108
			case 'old_image': // old captcha
109
				?>
110
				<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php?t='.time(); ?>" align="middle" alt="Captcha" />
111
				<input type="text" name="captcha" maxlength="5" style="width:50px" />&nbsp;&nbsp;<?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></font>
112
				<?php
113
				break;
114
		}
115
	}
116
}
117
?>