1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Form;
13:
14: /**
15: * Token - a security token form element
16: *
17: * @category Xoops\Form\Token
18: * @package Xoops\Form
19: * @author Kazumi Ono <onokazu@xoops.org>
20: * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class Token extends Hidden
25: {
26: /**
27: * Constructor
28: *
29: * @param string|array $name name attribute or array of all attributes
30: * @param integer $timeout timeout in seconds for generated token
31: */
32: public function __construct($name = 'XOOPS_TOKEN', $timeout = 0)
33: {
34: if (is_array($name)) {
35: parent::__construct($name);
36: } else {
37: parent::__construct([]);
38: $this->set('name', $name);
39: $this->set(':timeout', $timeout);
40: }
41: $name = $this->get('name', 'XOOPS_TOKEN');
42: if (substr($name, -8) !== '_REQUEST') {
43: $this->set('name', $name.'_REQUEST');
44: }
45: $this->set('value', \Xoops::getInstance()->security()->createToken($this->get(':timeout', 0), $name));
46: }
47: }
48: