Project

General

Profile

1
<?php
2

    
3
// $Id: captcha.php 820 2008-04-13 11:56:10Z thorn $
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
// Must include code to stop this file being accessed directly
27
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
28

    
29
// check if module language file exists for the language set by the user (e.g. DE, EN)
30
global $MOD_CAPTCHA;
31
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
32
	// no module language file exists for the language set by the user, include default module language file EN.php
33
	require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
34
} else {
35
	// a module language file exists for the language defined by the user, load it
36
	require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
37
}
38

    
39
// output-handler for image-captchas to determine size of image
40
if(!function_exists('captcha_header')) {
41
	function captcha_header() {
42
		header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
43
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
44
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
45
		header("Cache-Control: post-check=0, pre-check=0", false); // MS made there own headers :-(
46
		header("Pragma: no-cache");
47
		header("Content-type: image/png");
48
		return;
49
	}
50
}
51

    
52
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
53
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
54
	$useable_captchas = array(
55
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
56
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
57
		'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
58
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
59
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
60
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
61
	);
62
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
63
	$useable_captchas = array(
64
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
65
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
66
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
67
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
68
	);
69
} else {
70
	$useable_captchas = array(
71
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
72
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
73
	);
74
}
75

    
76
if(!function_exists('call_captcha')) {
77
	function call_captcha($action='all', $style='') {
78
		global $MOD_CAPTCHA;
79
		$t = time();
80
		$_SESSION['captcha_time'] = $t;
81
		
82
		if($action=='all') {
83
			switch(CAPTCHA_TYPE) {
84
				// one special case
85
				case 'text': // text-captcha
86
					?><table class="captcha_table"><tr>
87
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?></td>
88
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
89
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
90
					</tr></table><?php
91
					break;
92
				// two special cases
93
				case 'calc_text': // calculation as text
94
					?><table class="captcha_table"><tr>
95
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>&nbsp;=&nbsp;</td>
96
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px;" /></td>
97
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
98
					</tr></table><?php
99
					break;
100
				case 'calc_image': // calculation with image (old captcha)
101
				case 'calc_ttf_image': // calculation with varying background and ttf-font
102
					?><table class="captcha_table"><tr>
103
					<td class="image_captcha"><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td><td>&nbsp;=&nbsp;</td>
104
					<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
105
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
106
					</tr></table><?php
107
					break;
108
				// normal images
109
				case 'ttf_image': // captcha with varying background and ttf-font
110
				case 'old_image': // old captcha
111
					?><table class="captcha_table"><tr>
112
					<td class="image_captcha"><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td>
113
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
114
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
115
					</tr></table><?php
116
					break;
117
			}
118
		} elseif($action=='image') {
119
			switch(CAPTCHA_TYPE) {
120
				case 'text': // text-captcha
121
				case 'calc_text': // calculation as text
122
					echo ($style?"<span $style>":'');
123
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
124
					echo ($style?'</span>':'');
125
					break;
126
				case 'calc_image': // calculation with image (old captcha)
127
				case 'calc_ttf_image': // calculation with varying background and ttf-font
128
				case 'ttf_image': // captcha with varying background and ttf-font
129
				case 'old_image': // old captcha
130
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
131
					break;
132
			}
133
		} elseif($action=='input') {
134
			switch(CAPTCHA_TYPE) {
135
				case 'text': // text-captcha
136
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
137
					break;
138
				case 'calc_text': // calculation as text
139
				case 'calc_image': // calculation with image (old captcha)
140
				case 'calc_ttf_image': // calculation with varying background and ttf-font
141
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
142
					break;
143
				case 'ttf_image': // captcha with varying background and ttf-font
144
				case 'old_image': // old captcha
145
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
146
					break;
147
			}
148
		} elseif($action=='text') {
149
			echo ($style?"<span $style>":'');
150
			switch(CAPTCHA_TYPE) {
151
				case 'text': // text-captcha
152
					echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
153
					break;
154
				case 'calc_text': // calculation as text
155
				case 'calc_image': // calculation with image (old captcha)
156
				case 'calc_ttf_image': // calculation with varying background and ttf-font
157
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
158
					break;
159
				case 'ttf_image': // captcha with varying background and ttf-font
160
				case 'old_image': // old captcha
161
					echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
162
					break;
163
			}
164
			echo ($style?'</span>':'');
165
		}
166
	}
167
}
168
?>
(1-1/3)