|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* CAPTCHA for text mode |
|
14
|
|
|
* |
|
15
|
|
|
* PHP 5.3 |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xoops\Class\Captcha\Captcha |
|
18
|
|
|
* @package Captcha |
|
19
|
|
|
* @author Taiwen Jiang <[email protected]> |
|
20
|
|
|
* @copyright 2013 XOOPS Project (http://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
22
|
|
|
* @version $Id$ |
|
23
|
|
|
* @link http://xoops.org |
|
24
|
|
|
* @since 2.6.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
class XoopsCaptchaText extends XoopsCaptchaMethod |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* XoopsCaptchaText::render() |
|
30
|
|
|
* |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function render() |
|
34
|
|
|
{ |
|
35
|
1 |
|
$form = $this->loadText() . ' <input type="text" name="' . $this->config['name'] |
|
36
|
1 |
|
. '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] |
|
37
|
1 |
|
. '" maxlength="' . $this->config['num_chars'] . '" value="" />'; |
|
38
|
1 |
|
$form .= '<br />' . XoopsLocale::INPUT_RESULT_FROM_EXPRESSION; |
|
39
|
1 |
View Code Duplication |
if (!empty($this->config['maxattempts'])) { |
|
40
|
|
|
$form .= '<br />' . sprintf(XoopsLocale::F_MAXIMUM_ATTEMPTS, $this->config['maxattempts']); |
|
41
|
|
|
} |
|
42
|
1 |
|
return $form; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* XoopsCaptchaText::loadText() |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public function loadText() |
|
51
|
|
|
{ |
|
52
|
2 |
|
$val_a = mt_rand(0, 9); |
|
53
|
2 |
|
$val_b = mt_rand(0, 9); |
|
54
|
2 |
|
if ($val_a > $val_b) { |
|
55
|
|
|
$expression = "{$val_a} - {$val_b} = ?"; |
|
56
|
|
|
$this->code = $val_a - $val_b; |
|
|
|
|
|
|
57
|
|
|
} else { |
|
58
|
2 |
|
$expression = "{$val_a} + {$val_b} = ?"; |
|
59
|
2 |
|
$this->code = $val_a + $val_b; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
2 |
|
return '<span style="font-style: normal; font-weight: bold; font-size: 100%; font-color: #333; border: 1px solid #333; padding: 1px 5px;">' . $expression . '</span>'; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.