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