Project

General

Profile

1 624 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') == false) { exit("Cannot access this file directly"); }
28
29 628 thorn
global $admin;
30 624 thorn
$name = 'text';
31 639 thorn
$file = WB_PATH."/temp/.captcha_$name.php";
32 624 thorn
33
srand((double)microtime()*100000);
34
$_SESSION['captcha'] = rand(0,99999);
35
36
// get questions and answers
37
$qa = array();
38
@$content = file($file);
39
if($content===FALSE) {
40
	echo '<b>Error</b>: Can not read text! Enter <b>0</b> to solve this captcha';
41
	$_SESSION['captcha'] = '0';
42 630 thorn
	return;
43 624 thorn
}
44
reset($content);
45
while($s = current($content)) {
46
	// get question
47
	$s=trim(rtrim(rtrim($s,"\n"),"\r")); // remove newline
48 628 thorn
	$s=$admin->strip_slashes($s);
49 624 thorn
	if($s=='' OR $s{0}!='?') {
50
		next($content);
51
		continue;
52
	}
53
	if(isset($s{3}) && $s{3}==':') {
54
		$lang=substr($s,1,2);
55
		$q=substr($s,4);
56
	}	else {
57
		$lang='XX';
58
		$q=substr($s,1);
59
	}
60
	// get answer
61
	$s=next($content);
62
	$s=trim(rtrim(rtrim($s,"\n"),"\r")); // remove newline
63 628 thorn
	$s=$admin->strip_slashes($s);
64 639 thorn
	if(isset($s{0}) && $s{0}=='!') {
65
		$a=substr($s,1);
66
		$qa[$lang][$q]=$a;
67
		next($content);
68
	}
69 624 thorn
}
70
if($qa == array()) {
71
	echo '<b>Error</b>: no text defined! Enter <b>0</b> to solve this captcha';
72
	$_SESSION['captcha'] = '0';
73 630 thorn
	return;
74 624 thorn
}
75
76
// choose language to use
77
if(defined('LANGUAGE') && isset($qa[LANGUAGE]))
78
	$lang = LANGUAGE;
79
else
80
	$lang = 'XX';
81
if(!isset($qa[$lang])) {
82
	echo '<b>Error</b>: no text defined! Enter <b>0</b> to solve this captcha';
83
	$_SESSION['captcha'] = '0';
84 630 thorn
	return;
85 624 thorn
}
86
87
// choose random question
88
$k = array_rand($qa[$lang]);
89
90
$_SESSION['captcha'] = $qa[$lang][$k];
91
92
echo $k;
93
94 628 thorn
?>