1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: |
|
19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
20: |
|
21: | |
22: | |
23: |
|
24: | class XoopsCaptchaText extends XoopsCaptchaMethod
|
25: | {
|
26: |
|
27: |
|
28: | protected $outputText = '';
|
29: | |
30: | |
31: | |
32: | |
33: |
|
34: | public function __construct($handler = null)
|
35: | {
|
36: | parent::__construct($handler);
|
37: | $this->buildQuestion();
|
38: | }
|
39: |
|
40: | |
41: | |
42: | |
43: | |
44: |
|
45: | public function render()
|
46: | {
|
47: | $form = $this->loadText() . ' <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: | |
58: | |
59: | |
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: | |