1: <?php
2: /**
3: * CAPTCHA for text mode
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @package class
15: * @subpackage CAPTCHA
16: * @since 2.3.0
17: * @author Taiwen Jiang <phppp@users.sourceforge.net>
18: */
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: /**
22: * Class XoopsCaptchaText
23: */
24: class XoopsCaptchaText extends XoopsCaptchaMethod
25: {
26:
27: /** @var string */
28: protected $outputText = '';
29: /**
30: * XoopsCaptchaMethod::__construct()
31: *
32: * @param mixed $handler
33: */
34: public function __construct($handler = null)
35: {
36: parent::__construct($handler);
37: $this->buildQuestion();
38: }
39:
40: /**
41: * XoopsCaptchaText::render()
42: *
43: * @return string|void
44: */
45: public function render()
46: {
47: $form = $this->loadText() . '&nbsp;&nbsp; <input type="text" name="' . $this->config['name'] . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] . '" maxlength="' . $this->config['num_chars'] . '" value="" />';
48: $form .= '<br>' . _CAPTCHA_RULE_TEXT;
49: if (!empty($this->config['maxattempts'])) {
50: $form .= '<br>' . sprintf(_CAPTCHA_MAXATTEMPTS, $this->config['maxattempts']);
51: }
52:
53: return $form;
54: }
55:
56: /**
57: * XoopsCaptchaText::loadText()
58: *
59: * @return string
60: */
61: public function loadText()
62: {
63: return '<span class="captchatext">' . $this->outputText . '</span>';
64: }
65:
66: protected function buildQuestion()
67: {
68: $val_a = mt_rand(0, 9);
69: $val_b = mt_rand(0, 9);
70: if ($val_a > $val_b) {
71: $expression = "{$val_a} - {$val_b} = ?";
72: $this->code = $val_a - $val_b;
73: } else {
74: $expression = "{$val_a} + {$val_b} = ?";
75: $this->code = $val_a + $val_b;
76: }
77:
78: $this->outputText = $expression;
79: }
80: }
81: