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
// 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 615 thorn
		'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
58 596 thorn
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
59 624 thorn
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
60
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
61 596 thorn
	);
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 624 thorn
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
67
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
68 596 thorn
	);
69
} else {
70
	$useable_captchas = array(
71 624 thorn
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
72
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
73 596 thorn
	);
74
}
75
76
if(!function_exists('call_captcha')) {
77 756 thorn
	function call_captcha($action='all', $style='') {
78 596 thorn
		global $MOD_CAPTCHA;
79 609 thorn
		$t = time();
80
		$_SESSION['captcha_time'] = $t;
81 747 thorn
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 756 thorn
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
89 747 thorn
					<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 756 thorn
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px;" /></td>
97 747 thorn
					<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 756 thorn
					<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
105 747 thorn
					<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 756 thorn
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
114 747 thorn
					<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 756 thorn
					echo ($style?"<span $style>":'');
123 747 thorn
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
124 756 thorn
					echo ($style?'</span>':'');
125 747 thorn
					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 756 thorn
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
131 747 thorn
					break;
132
			}
133
		} elseif($action=='input') {
134
			switch(CAPTCHA_TYPE) {
135
				case 'text': // text-captcha
136 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
137 747 thorn
					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 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
142 747 thorn
					break;
143
				case 'ttf_image': // captcha with varying background and ttf-font
144
				case 'old_image': // old captcha
145 756 thorn
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
146 747 thorn
					break;
147
			}
148
		} elseif($action=='text') {
149 756 thorn
			echo ($style?"<span $style>":'');
150 747 thorn
			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 756 thorn
			echo ($style?'</span>':'');
165 596 thorn
		}
166
	}
167
}
168 615 thorn
?>