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
// Must include code to stop this file being accessed directly
27
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
28
29
if(!isset($admin)) {
30
	require_once(WB_PATH.'/framework/class.wb.php');
31
	$admin = new wb;
32
}
33
34
// check if module language file exists for the language set by the user (e.g. DE, EN)
35
global $MOD_CAPTCHA;
36
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
37
	// no module language file exists for the language set by the user, include default module language file EN.php
38
	require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
39
} else {
40
	// a module language file exists for the language defined by the user, load it
41
	require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
42
}
43
44
// output-handler for image-captchas to determine size of image
45
if(!function_exists('captcha_header')) {
46
	function captcha_header() {
47
		header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
48
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
49
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
50
		header("Cache-Control: post-check=0, pre-check=0", false); // MS made there own headers :-(
51
		header("Pragma: no-cache");
52
		header("Content-type: image/png");
53
		return;
54
	}
55
}
56
57
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
58
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
59
	$useable_captchas = array(
60
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
61
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
62 615 thorn
		'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
63 596 thorn
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
64 624 thorn
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
65
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
66 596 thorn
	);
67
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
68
	$useable_captchas = array(
69
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
70
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
71 624 thorn
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
72
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
73 596 thorn
	);
74
} else {
75
	$useable_captchas = array(
76 624 thorn
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
77
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
78 596 thorn
	);
79
}
80
81
if(!function_exists('call_captcha')) {
82 756 thorn
	function call_captcha($action='all', $style='') {
83 596 thorn
		global $MOD_CAPTCHA;
84 609 thorn
		$t = time();
85
		$_SESSION['captcha_time'] = $t;
86 747 thorn
87
		if($action=='all') {
88
			switch(CAPTCHA_TYPE) {
89
				// one special case
90
				case 'text': // text-captcha
91
					?><table class="captcha_table"><tr>
92
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?></td>
93 756 thorn
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
94 747 thorn
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
95
					</tr></table><?php
96
					break;
97
				// two special cases
98
				case 'calc_text': // calculation as text
99
					?><table class="captcha_table"><tr>
100
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>&nbsp;=&nbsp;</td>
101 756 thorn
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px;" /></td>
102 747 thorn
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
103
					</tr></table><?php
104
					break;
105
				case 'calc_image': // calculation with image (old captcha)
106
				case 'calc_ttf_image': // calculation with varying background and ttf-font
107
					?><table class="captcha_table"><tr>
108
					<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>
109 756 thorn
					<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
110 747 thorn
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
111
					</tr></table><?php
112
					break;
113
				// normal images
114
				case 'ttf_image': // captcha with varying background and ttf-font
115
				case 'old_image': // old captcha
116
					?><table class="captcha_table"><tr>
117
					<td class="image_captcha"><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td>
118 756 thorn
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
119 747 thorn
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
120
					</tr></table><?php
121
					break;
122
			}
123
		} elseif($action=='image') {
124
			switch(CAPTCHA_TYPE) {
125
				case 'text': // text-captcha
126
				case 'calc_text': // calculation as text
127 756 thorn
					echo ($style?"<span $style>":'');
128 747 thorn
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
129 756 thorn
					echo ($style?'</span>':'');
130 747 thorn
					break;
131
				case 'calc_image': // calculation with image (old captcha)
132
				case 'calc_ttf_image': // calculation with varying background and ttf-font
133
				case 'ttf_image': // captcha with varying background and ttf-font
134
				case 'old_image': // old captcha
135 756 thorn
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
136 747 thorn
					break;
137
			}
138
		} elseif($action=='input') {
139
			switch(CAPTCHA_TYPE) {
140
				case 'text': // text-captcha
141 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
142 747 thorn
					break;
143
				case 'calc_text': // calculation as text
144
				case 'calc_image': // calculation with image (old captcha)
145
				case 'calc_ttf_image': // calculation with varying background and ttf-font
146 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
147 747 thorn
					break;
148
				case 'ttf_image': // captcha with varying background and ttf-font
149
				case 'old_image': // old captcha
150 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
151 747 thorn
					break;
152
			}
153
		} elseif($action=='text') {
154 756 thorn
			echo ($style?"<span $style>":'');
155 747 thorn
			switch(CAPTCHA_TYPE) {
156
				case 'text': // text-captcha
157
					echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
158
					break;
159
				case 'calc_text': // calculation as text
160
				case 'calc_image': // calculation with image (old captcha)
161
				case 'calc_ttf_image': // calculation with varying background and ttf-font
162
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
163
					break;
164
				case 'ttf_image': // captcha with varying background and ttf-font
165
				case 'old_image': // old captcha
166
					echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
167
					break;
168
			}
169 756 thorn
			echo ($style?'</span>':'');
170 596 thorn
		}
171
	}
172
}
173 615 thorn
?>