1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Adding CAPTCHA |
4
|
|
|
* |
5
|
|
|
* Currently there are two types of CAPTCHA forms, text and image |
6
|
|
|
* The default mode is "text", it can be changed in the priority: |
7
|
|
|
* 1 If mode is set through XoopsFormCaptcha::setMode(), take it |
8
|
|
|
* 2 Elseif mode is set though captcha/config.php, take it |
9
|
|
|
* 3 Else, take "text" |
10
|
|
|
* |
11
|
|
|
* D.J. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
15
|
|
|
|
16
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsform/formelement.php'; |
17
|
|
|
|
18
|
|
|
/* |
19
|
|
|
* Usage |
20
|
|
|
* |
21
|
|
|
* For form creation: |
22
|
|
|
* 1 Add [require_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php";] to class/xoopsformloader.php, OR add to the file that uses CAPTCHA before calling XoopsFormCaptcha |
23
|
|
|
* 2 Add form element where proper: $xoopsform->addElement(new \XoopsFormCaptcha($caption, $name, $skipmember, ...); |
24
|
|
|
* |
25
|
|
|
* For verification: |
26
|
|
|
* if (@require_once XOOPS_ROOT_PATH."/class/captcha/xoopscaptcha.php") { |
27
|
|
|
* $xoopsCaptcha = XoopsCaptcha::getInstance(); |
28
|
|
|
* if (! $xoopsCaptcha->verify() ) { |
29
|
|
|
* echo $xoopsCaptcha->getMessage(); |
30
|
|
|
* ... |
31
|
|
|
* } |
32
|
|
|
* } |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Class XoopsFormCaptcha |
38
|
|
|
*/ |
39
|
|
|
class XoopsFormCaptcha extends \XoopsFormElement |
40
|
|
|
{ |
41
|
|
|
public $_captchaHandler; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $caption Caption of the form element, default value is defined in captcha/language/ |
45
|
|
|
* @param string $name Name for the input box |
46
|
|
|
* @param boolean $skipmember Skip CAPTCHA check for members |
47
|
|
|
* @param int $numchar Number of characters in image mode, and input box size for text mode |
48
|
|
|
* @param int $minfontsize Minimum font-size of characters in image mode |
49
|
|
|
* @param int $maxfontsize Maximum font-size of characters in image mode |
50
|
|
|
* @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
51
|
|
|
* @param int $backgroundnum Number of background images in image mode |
52
|
|
|
* |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
$caption = '', |
56
|
|
|
$name = 'xoopscaptcha', |
57
|
|
|
$skipmember = null, |
58
|
|
|
$numchar = null, |
59
|
|
|
$minfontsize = null, |
60
|
|
|
$maxfontsize = null, |
61
|
|
|
$backgroundtype = null, |
62
|
|
|
$backgroundnum = null |
63
|
|
|
) { |
64
|
|
|
if (!class_exists('XoopsCaptcaha')) { |
65
|
|
|
require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->_captchaHandler = XoopsCaptcha::getInstance(); |
69
|
|
|
$this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
|
|
|
70
|
|
|
if (!$this->_captchaHandler->active) { |
71
|
|
|
$this->setHidden(); |
72
|
|
|
} else { |
73
|
|
|
$caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
74
|
|
|
$this->setCaption($caption); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $name |
80
|
|
|
* @param $val |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function setConfig($name, $val) |
84
|
|
|
{ |
85
|
|
|
return $this->_captchaHandler->setConfig($name, $val); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return mixed|string |
90
|
|
|
*/ |
91
|
|
|
public function render() |
92
|
|
|
{ |
93
|
|
|
if (!$this->isHidden()) { |
94
|
|
|
return $this->_captchaHandler->render(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.