Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        captcha
5
 * @package         include
6
 * @subpackage
7
 * @author          Ryan Djurovich,WebsiteBaker Project
8
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
9
 * @link            http://www.websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: captcha.php 2070 2014-01-03 01:21:42Z darkviper $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/include/captcha/captcha.php $
15
 * @lastmodified    $Date: 2014-01-03 02:21:42 +0100 (Fri, 03 Jan 2014) $
16
 *
17
 */
18

    
19
// displays the image or text inside an <iframe>
20
if(!function_exists('display_captcha_real')) {
21
	function display_captcha_real($kind='image') {
22
		$t = time();
23
		$output  = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ";
24
		$output .= "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
25
		$output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"";
26
		$output .= strtolower(LANGUAGE)."\" lang=\"".strtolower(LANGUAGE)."\">\n";
27
		$output .= "\t<head>\n\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n";
28
		$output .= "\t\t<title>captcha</title>\n\t</head>\n\t<body>\n";
29
		$_SESSION['captcha_time'] = $t;
30
		if($kind=='image') {
31
			$output .= "\t\t<a title=\"reload\" href=\"".WB_URL."/include/captcha/captcha.php?display_captcha_X986E21=2\">";
32
			$output .= "<img style=\"border: none;\" src=\"".WB_URL."/include/captcha/captchas/";
33
			$output .= CAPTCHA_TYPE.".php?t=".$t."\" alt=\"Captcha\" /></a>\n";
34
		} else {
35
			$output .= "\t\t<h2>error</h2>";
36
		}
37
		$output .= "\t</body>\n</html>";
38
		echo $output;
39
	}
40
}
41

    
42
// called from an <iframe>
43
if(isset($_GET['display_captcha_X986E21'])) {
44
	require('../../config.php');
45
	switch(CAPTCHA_TYPE) {
46
	case 'calc_image':
47
	case 'calc_ttf_image':
48
	case 'ttf_image':
49
	case 'old_image':
50
		display_captcha_real('image');
51
		break;
52
	}
53
	exit(0);
54
}
55

    
56

    
57
// Make sure page cannot be accessed directly
58
if(!defined('WB_PATH')) { exit("Cannot access this file directly"); }
59

    
60
// check if module language file exists for the language set by the user (e.g. DE, EN)
61
global $MOD_CAPTCHA;
62
if(!file_exists(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php')) {
63
	// no module language file exists for the language set by the user, include default module language file EN.php
64
	require_once(WB_PATH.'/modules/captcha_control/languages/EN.php');
65
} else {
66
	// a module language file exists for the language defined by the user, load it
67
	require_once(WB_PATH.'/modules/captcha_control/languages/'.LANGUAGE .'.php');
68
}
69

    
70
// output-handler for image-captchas to determine size of image
71
if(!function_exists('captcha_header')) {
72
	function captcha_header() {
73
		header("Expires: Mon, 1 Jan 1990 05:00:00 GMT");
74
		header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
75
		header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
76
		header("Pragma: no-cache");
77
		header("Content-type: image/png");
78
		return;
79
	}
80
}
81

    
82
// get list of available CAPTCHAS for the dropdown-listbox in admin-tools
83
if(extension_loaded('gd') && function_exists('imagepng') && function_exists('imagettftext')) {
84
	$useable_captchas = array(
85
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
86
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
87
		'calc_ttf_image'=>$MOD_CAPTCHA_CONTROL['CALC_TTF_IMAGE'],
88
		'ttf_image'=>$MOD_CAPTCHA_CONTROL['TTF_IMAGE'],
89
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
90
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
91
	);
92
} elseif(extension_loaded('gd') && function_exists('imagepng')) {
93
	$useable_captchas = array(
94
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
95
		'calc_image'=>$MOD_CAPTCHA_CONTROL['CALC_IMAGE'],
96
		'old_image'=>$MOD_CAPTCHA_CONTROL['OLD_IMAGE'],
97
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
98
	);
99
} else {
100
	$useable_captchas = array(
101
		'calc_text'=>$MOD_CAPTCHA_CONTROL['CALC_TEXT'],
102
		'text'=>$MOD_CAPTCHA_CONTROL['TEXT']
103
	);
104
}
105

    
106
if(!function_exists('call_captcha')) {
107
	function call_captcha($action='all', $style='', $sec_id='') {
108
		global $MOD_CAPTCHA;
109
		$t = time();
110
		$_SESSION['captcha_time'] = $t;
111

    
112
		// get width and height of captcha image for use in <iframe>
113
		switch(CAPTCHA_TYPE) {
114
		case 'calc_image':
115
			$captcha_width = 160;
116
			$captcha_height = 55;
117
			break;
118
		case 'calc_ttf_image':
119
			$captcha_width = 175;
120
			$captcha_height = 55;
121
			break;
122
		case 'ttf_image':
123
			$captcha_width = 175;
124
			$captcha_height = 55;
125
			break;
126
		case 'old_image':
127
			$captcha_width = 160;
128
			$captcha_height = 55;
129
			break;
130
		default:
131
			$captcha_width = 250;
132
			$captcha_height = 100;
133
		}
134

    
135
		if($action=='all') {
136
			switch(CAPTCHA_TYPE) {
137
				case 'text': // text-captcha
138
					?><table class="captcha_table"><tr>
139
					<td class="text_captcha">
140
						<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
141
					</td>
142
					<td></td>
143
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
144
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
145
					</tr></table><?php
146
					break;
147
				case 'calc_text': // calculation as text
148
					?><table class="captcha_table"><tr>
149
					<td class="text_captcha">
150
						<?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>
151
					</td>
152
					<td>&nbsp;=&nbsp;</td>
153
					<td><input type="text" name="captcha" maxlength="10"  style="width:30px;" /></td>
154
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
155
					</tr></table><?php
156
					break;
157
				case 'calc_image': // calculation with image (old captcha)
158
				case 'calc_ttf_image': // calculation with varying background and ttf-font
159
				  ?><table class="captcha_table" style="font-size: 100%;"><tr>
160
					<td class="image_captcha">
161
						<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\" style=\"overflow:hidden;border: 1px solid #999;\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?>">
162
						<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id"; ?>" alt="Captcha" style="margin: 0;padding:  0;" />
163
						</iframe>
164
					</td>
165
					<td>&nbsp;=&nbsp;</td>
166
					<td><input type="text" name="captcha" maxlength="10" style="width:30px;" /></td>
167
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
168
					</tr></table><?php
169
					break;
170
				// normal images
171
				case 'ttf_image': // captcha with varying background and ttf-font
172
				case 'old_image': // old captcha
173
					?><table class="captcha_table"><tr>
174
					<td class="image_captcha">
175
						<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\"  style=\"overflow:hidden;border: 1px solid #999;\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?> " >
176
						<img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id"; ?>" alt="Captcha" style="margin: 0;padding:  0;" />
177
						</iframe>
178
					</td>
179
					<td></td>
180
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
181
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
182
					</tr></table><?php
183
					break;
184
			}
185
		} elseif($action=='image') {
186
			switch(CAPTCHA_TYPE) {
187
				case 'text': // text-captcha
188
				case 'calc_text': // calculation as text
189
					echo ($style?"<span $style>":'');
190
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
191
					echo ($style?'</span>':'');
192
					break;
193
				case 'calc_image': // calculation with image (old captcha)
194
				case 'calc_ttf_image': // calculation with varying background and ttf-font
195
				case 'ttf_image': // captcha with varying background and ttf-font
196
				case 'old_image': // old captcha
197
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t&amp;s=$sec_id\" />";
198
					break;
199
			}
200
		} elseif($action=='image_iframe') {
201
			switch(CAPTCHA_TYPE) {
202
				case 'text': // text-captcha
203
					echo ($style?"<span $style>":'');
204
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
205
					echo ($style?'</span>':'');
206
					break;
207
				case 'calc_text': // calculation as text
208
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
209
					break;
210
				case 'calc_image': // calculation with image (old captcha)
211
				case 'calc_ttf_image': // calculation with varying background and ttf-font
212
				case 'ttf_image': // captcha with varying background and ttf-font
213
				case 'old_image': // old captcha
214
					?>
215
					<?php echo "<iframe class=\"captcha_iframe\" width=\"$captcha_width\" height=\"$captcha_height\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" name=\"captcha_iframe_$sec_id\" src=\"". WB_URL ."/include/captcha/captcha.php?display_captcha_X986E21=1&amp;s=$sec_id"; ?>">
216
					<?php
217
					echo "<img $style alt=\"Captcha\" src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
218
					?></iframe><?php
219
					break;
220
			}
221
		} elseif($action=='input') {
222
			switch(CAPTCHA_TYPE) {
223
				case 'text': // text-captcha
224
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
225
					break;
226
				case 'calc_text': // calculation as text
227
				case 'calc_image': // calculation with image (old captcha)
228
				case 'calc_ttf_image': // calculation with varying background and ttf-font
229
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
230
					break;
231
				case 'ttf_image': // captcha with varying background and ttf-font
232
				case 'old_image': // old captcha
233
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
234
					break;
235
			}
236
		} elseif($action=='text') {
237
			echo ($style?"<span $style>":'');
238
			switch(CAPTCHA_TYPE) {
239
				case 'text': // text-captcha
240
					echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
241
					break;
242
				case 'calc_text': // calculation as text
243
				case 'calc_image': // calculation with image (old captcha)
244
				case 'calc_ttf_image': // calculation with varying background and ttf-font
245
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
246
					break;
247
				case 'ttf_image': // captcha with varying background and ttf-font
248
				case 'old_image': // old captcha
249
					echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
250
					break;
251
			}
252
			echo ($style?'</span>':'');
253
		}
254
	}
255
}
(1-1/5)