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\Core\Kernel\Dtype;
13:
14: use Xoops\Core\Kernel\Dtype;
15: use Xoops\Core\Kernel\XoopsObject;
16:
17: /**
18: * DtypeTextBox
19: *
20: * @category Xoops\Core\Kernel\Dtype\DtypeTextBox
21: * @package Xoops\Core\Kernel
22: * @author trabis <lusopoemas@gmail.com>
23: * @copyright 2011-2015 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @link http://xoops.org
26: * @since 2.6.0
27: */
28: class DtypeTextBox extends DtypeAbstract
29: {
30: /**
31: * getVar get variable prepared according to format
32: *
33: * @param XoopsObject $obj object containing variable
34: * @param string $key name of variable
35: * @param string $format Dtype::FORMAT_* constant indicating desired formatting
36: *
37: * @return mixed
38: */
39: public function getVar(XoopsObject $obj, $key, $format)
40: {
41: $value = $obj->vars[$key]['value'];
42: switch (strtolower($format)) {
43: case 's':
44: case Dtype::FORMAT_SHOW:
45: case 'e':
46: case Dtype::FORMAT_EDIT:
47: return $this->ts->htmlSpecialChars($value);
48: case 'p':
49: case Dtype::FORMAT_PREVIEW:
50: case 'f':
51: case Dtype::FORMAT_FORM_PREVIEW:
52: return $this->ts->htmlSpecialChars($value);
53: case 'n':
54: case Dtype::FORMAT_NONE:
55: default:
56: return $value;
57: }
58: }
59:
60: /**
61: * cleanVar prepare variable for persistence
62: *
63: * @param XoopsObject $obj object containing variable
64: * @param string $key name of variable
65: *
66: * @return string
67: */
68: public function cleanVar(XoopsObject $obj, $key)
69: {
70: $value = $obj->vars[$key]['value'];
71: if ($obj->vars[$key]['required'] && $value != '0' && $value == '') {
72: $obj->setErrors(sprintf(\XoopsLocale::F_IS_REQUIRED, $key));
73: return $value;
74: }
75: if (isset($obj->vars[$key]['maxlength']) && mb_strlen($value) > (int)($obj->vars[$key]['maxlength'])) {
76: $obj->setErrors(sprintf(\XoopsLocale::F_MUST_BE_SHORTER_THAN, $key, (int)($obj->vars[$key]['maxlength'])));
77: return $value;
78: }
79:
80: $value = $this->ts->censorString($value);
81:
82: return $value;
83: }
84: }
85: