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