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 (http://www.gnu.org/licenses/gpl-2.0.html)
14: * @package kernel
15: * @subpackage form
16: * @since 2.3.0
17: * @author Taiwen Jiang <phppp@users.sourceforge.net>
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 <phppp@users.sourceforge.net>
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
56: * @param array $configs
57: */
58: public function __construct($caption = '', $name = 'xoopscaptcha', $skipmember = true, $configs = array())
59: {
60: xoops_load('XoopsCaptcha');
61: $this->captchaHandler = XoopsCaptcha::getInstance();
62: $configs['name'] = $name;
63: $configs['skipmember'] = $skipmember;
64: $this->captchaHandler->setConfigs($configs);
65: if (!$this->captchaHandler->isActive()) {
66: $this->setHidden();
67: } else {
68: $caption = !empty($caption) ? $caption : $this->captchaHandler->getCaption();
69: $this->setCaption($caption);
70: $this->setName($name);
71: }
72: }
73:
74: /**
75: * @param $name
76: * @param $val
77: *
78: * @return mixed
79: */
80: public function setConfig($name, $val)
81: {
82: return $this->captchaHandler->setConfig($name, $val);
83: }
84:
85: /**
86: * @return mixed
87: */
88: public function render()
89: {
90: // if (!$this->isHidden()) {
91: return $this->captchaHandler->render();
92: // }
93: }
94:
95: /**
96: * @return mixed
97: */
98: public function renderValidationJS()
99: {
100: return $this->captchaHandler->renderValidationJS();
101: }
102: }
103: