Issues (3083)

htdocs/class/xoopsform/formcaptcha.php (1 issue)

1
<?php
2
/**
3
 * XOOPS form element of CAPTCHA
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             kernel
15
 * @subpackage          form
16
 * @since               2.3.0
17
 * @author              Taiwen Jiang <[email protected]>
18
 */
19
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20
21
xoops_load('XoopsFormElement');
22
23
/**
24
 * Usage of XoopsFormCaptcha
25
 *
26
 * For form creation:
27
 * Add form element where proper: <code>$xoopsform->addElement(new XoopsFormCaptcha($caption, $name, $skipmember, $configs));</code>
28
 *
29
 * For verification:
30
 * <code>
31
 *               xoops_load('xoopscaptcha');
32
 *               $xoopsCaptcha = XoopsCaptcha::getInstance();
33
 *               if (! $xoopsCaptcha->verify() ) {
34
 *                   echo $xoopsCaptcha->getMessage();
35
 *                   ...
36
 *               }
37
 * </code>
38
 */
39
40
/**
41
 * Xoops Form Captcha
42
 *
43
 * @author             Taiwen Jiang <[email protected]>
44
 * @package            kernel
45
 * @subpackage         form
46
 */
47
class XoopsFormCaptcha extends XoopsFormElement
48
{
49
    public $captchaHandler;
50
51
    /**
52
     * Constructor
53
     * @param string  $caption    Caption of the form element, default value is defined in captcha/language/
54
     * @param string  $name       Name for the input box
55
     * @param boolean $skipmember Skip CAPTCHA check for members deprecated
56
     * @param array   $configs									 deprecated
57
     */
58
    public function __construct($caption = '', $name = 'xoopscaptcha', $skipmember = '', $configs = array())
59
    {
60
        xoops_load('XoopsCaptcha');
61
        $this->captchaHandler  = XoopsCaptcha::getInstance();
62
		if($skipmember !== '' || !empty($configs)){
63
			$GLOBALS['xoopsLogger']->addDeprecated("In the class 'XoopsFormCaptcha' The settings 'skipmember' and 'configs' are deprecated since XOOPS 2.5.11");
64
		}
65
		$config['name'] = $name;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.
Loading history...
66
		$this->captchaHandler->setConfigs($config);
67
        
68
        if (!$this->captchaHandler->isActive()) {
69
            $this->setHidden();
70
        } else {
71
            $caption = !empty($caption) ? $caption : $this->captchaHandler->getCaption();
72
            $this->setCaption($caption);
73
            $this->setName($name);
74
        }
75
    }
76
77
    /**
78
     * @param $name
79
     * @param $val
80
     *
81
     * @return mixed
82
     */
83
    public function setConfig($name, $val)
84
    {
85
        return $this->captchaHandler->setConfig($name, $val);
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91
    public function render()
92
    {
93
        // if (!$this->isHidden()) {
94
        return $this->captchaHandler->render();
95
        // }
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public function renderValidationJS()
102
    {
103
        return $this->captchaHandler->renderValidationJS();
104
    }
105
}
106