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: use \Xoops\Core\Text\Sanitizer;
17:
18: /**
19: * DtypeAbstract
20: *
21: * @category Xoops\Core\Kernel\Dtype\DtypeAbstract
22: * @package Xoops\Core\Kernel
23: * @author trabis <lusopoemas@gmail.com>
24: * @copyright 2011-2013 XOOPS Project (http://xoops.org)
25: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26: * @link http://xoops.org
27: */
28: abstract class DtypeAbstract
29: {
30: /**
31: * @var \Xoops\Core\Database\Connection
32: */
33: protected $db;
34:
35: /**
36: * @var Sanitizer
37: */
38: protected $ts;
39:
40: /**
41: * Sets database and sanitizer for easy access
42: */
43: public function __construct()
44: {
45: //$this->db = \Xoops::getInstance()->db();
46: $this->ts = Sanitizer::getInstance();
47: }
48:
49: /**
50: * cleanVar prepare variable for persistence
51: *
52: * @param XoopsObject $obj object containing variable
53: * @param string $key name of variable
54: *
55: * @return mixed
56: */
57: public function cleanVar(XoopsObject $obj, $key)
58: {
59: $value = $obj->vars[$key]['value'];
60: return $value;
61: }
62:
63: /**
64: * getVar get variable prepared according to format
65: *
66: * @param XoopsObject $obj object containing variable
67: * @param string $key name of variable
68: * @param string $format Dtype::FORMAT_* constant indicating desired formatting
69: *
70: * @return mixed
71: */
72: public function getVar(XoopsObject $obj, $key, $format)
73: {
74: $value = $obj->vars[$key]['value'];
75: if ($obj->vars[$key]['options'] != '' && $value != '') {
76: switch (strtolower($format)) {
77: case 's':
78: case Dtype::FORMAT_SHOW:
79: $selected = explode('|', $value);
80: $options = explode('|', $obj->vars[$key]['options']);
81: $i = 1;
82: $ret = array();
83: foreach ($options as $op) {
84: if (in_array($i, $selected)) {
85: $ret[] = $op;
86: }
87: ++$i;
88: }
89: return implode(', ', $ret);
90: case 'e':
91: case Dtype::FORMAT_EDIT:
92: return explode('|', $value);
93: default:
94: }
95: }
96: return $value;
97: }
98: }
99: