XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
config.php
1<?php
16
17if (!defined('XOOPS_ROOT_PATH')) {
18 exit();
19}
20
21require_once XOOPS_ROOT_PATH.'/kernel/configoption.php';
22require_once XOOPS_ROOT_PATH.'/kernel/configitem.php';
23
24
26{
27
34 public $_cHandler;
35
42 public $_oHandler;
43
51 public $_cachedConfigs = [];
52
58 public function __construct(&$db)
59 {
60 $this->_cHandler =new XoopsConfigItemHandler($db);
61 $this->_oHandler =new XoopsConfigOptionHandler($db);
62 }
63
70 public function &createConfig()
71 {
72 $ret =& $this->_cHandler->create();
73 return $ret;
74 }
75
83 public function &getConfig($id, $withoptions = false)
84 {
85 $config =& $this->_cHandler->get($id);
86 if (true == $withoptions) {
87 $config->setConfOptions($this->getConfigOptions(new Criteria('conf_id', $id)));
88 }
89 return $config;
90 }
91
98 public function insertConfig(&$config)
99 {
100 if (!$this->_cHandler->insert($config)) {
101 return false;
102 }
103 $options =& $config->getConfOptions();
104 $count = is_countable($options) ? count($options) : 0;
105 $conf_id = $config->getVar('conf_id');
106 for ($i = 0; $i < $count; $i++) {
107 $options[$i]->setVar('conf_id', $conf_id);
108 if (!$this->_oHandler->insert($options[$i])) {
109 echo $options[$i]->getErrors();
110 }
111 }
112 if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
113 unset($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
114 }
115 return true;
116 }
117
124 public function deleteConfig(&$config)
125 {
126 if (!$this->_cHandler->delete($config)) {
127 return false;
128 }
129 $options =& $config->getConfOptions();
130 $count = is_countable($options) ? count($options) : 0;
131 if (0 == $count) {
132 $options =& $this->getConfigOptions(new Criteria('conf_id', $config->getVar('conf_id')));
133 $count = count($options);
134 }
135 if (is_array($options) && $count > 0) {
136 for ($i = 0; $i < $count; $i++) {
137 $this->_oHandler->delete($options[$i]);
138 }
139 }
140 if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
141 unset($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
142 }
143 return true;
144 }
145
155 public function &getConfigs($criteria = null, $id_as_key = false, $with_options = false)
156 {
157 $config =& $this->_cHandler->getObjects($criteria, $id_as_key);
158 return $config;
159 }
160
167 public function getConfigCount($criteria = null)
168 {
169 return $this->_cHandler->getCount($criteria);
170 }
171
181 public function &getConfigsByCat($category, $module = 0)
182 {
183 static $_cachedConfigs= [];
184 if (!empty($_cachedConfigs[$module][$category])) {
185 return $_cachedConfigs[$module][$category];
186 } else {
187 $ret = [];
188 $criteria = new CriteriaCompo(new Criteria('conf_modid', (int)$module));
189 if (!empty($category)) {
190 $criteria->add(new Criteria('conf_catid', (int)$category));
191 }
192
193 // get config values
194 $configs = [];
195 $db = $this->_cHandler->db;
196 $result = $db->query('SELECT conf_name,conf_value,conf_valuetype FROM '.$db->prefix('config').' '.$criteria->renderWhere().' ORDER BY conf_order ASC');
197 if ($result) {
198 while ([$name, $value, $type] = $db->fetchRow($result)) {
199 switch ($type) {
200 case 'array':
201 $ret[$name] = unserialize($value);
202 break;
203 case 'encrypt':
204 $ret[$name] = XCube_Utils::decrypt($value);
205 break;
206 default:
207 $ret[$name] = $value;
208 }
209 }
210 $_cachedConfigs[$module][$category] =& $ret;
211 }
212 return $ret;
213 }
214 }
215
223 public function &getConfigsByDirname($dirname, $category = 0)
224 {
225 $ret = null;
226 ;
227 $handler = xoops_gethandler('module');
228 ;
229 $module =& $handler->getByDirname($dirname);
230 if (!is_object($module)) {
231 return $ret;
232 }
233
234 $ret =& $this->getConfigsByCat($category, $module->get('mid'));
235
236 return $ret;
237 }
238
244 public function &createConfigOption()
245 {
246 $ret =& $this->_oHandler->create();
247 return $ret;
248 }
249
257 public function &getConfigOption($id)
258 {
259 $ret =& $this->_oHandler->get($id);
260 return $ret;
261 }
262
271 public function &getConfigOptions($criteria = null, $id_as_key = false)
272 {
273 $ret =& $this->_oHandler->getObjects($criteria, $id_as_key);
274 return $ret;
275 }
276
284 public function getConfigOptionsCount($criteria = null)
285 {
286 return $this->_oHandler->getCount($criteria);
287 }
288
297 public function &getConfigList($conf_modid, $conf_catid = 0)
298 {
299 if (!empty($this->_cachedConfigs[$conf_modid][$conf_catid])) {
300 return $this->_cachedConfigs[$conf_modid][$conf_catid];
301 } else {
302 $criteria = new CriteriaCompo(new Criteria('conf_modid', $conf_modid));
303 if (empty($conf_catid)) {
304 $criteria->add(new Criteria('conf_catid', $conf_catid));
305 }
306 $configs =& $this->_cHandler->getObjects($criteria);
307 $confcount = is_countable($configs) ? count($configs) : 0;
308 $ret = [];
309 for ($i = 0; $i < $confcount; $i++) {
310 $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
311 }
312 $this->_cachedConfigs[$conf_modid][$conf_catid] =& $ret;
313 return $ret;
314 }
315 }
316}
static decrypt(string $crypt_text, string $key=null)
[Static] To decrypt strings by "DES-ECB".
& getConfigList($conf_modid, $conf_catid=0)
Definition config.php:297
getConfigOptionsCount($criteria=null)
Definition config.php:284
& getConfigsByCat($category, $module=0)
Definition config.php:181
& getConfig($id, $withoptions=false)
Definition config.php:83
getConfigCount($criteria=null)
Definition config.php:167
& getConfigOption($id)
Definition config.php:257
& getConfigOptions($criteria=null, $id_as_key=false)
Definition config.php:271
& getConfigsByDirname($dirname, $category=0)
Definition config.php:223
insertConfig(&$config)
Definition config.php:98
deleteConfig(&$config)
Definition config.php:124
& getConfigs($criteria=null, $id_as_key=false, $with_options=false)
Definition config.php:155