1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
19: |
|
20: | |
21: | |
22: |
|
23: | define('XOOPS_CONF', 1);
|
24: | define('XOOPS_CONF_USER', 2);
|
25: | define('XOOPS_CONF_METAFOOTER', 3);
|
26: | define('XOOPS_CONF_CENSOR', 4);
|
27: | define('XOOPS_CONF_SEARCH', 5);
|
28: | define('XOOPS_CONF_MAILER', 6);
|
29: | define('XOOPS_CONF_AUTH', 7);
|
30: |
|
31: |
|
32: | |
33: | |
34: | |
35: | |
36: | |
37: |
|
38: | class XoopsConfigItem extends XoopsObject
|
39: | {
|
40: | |
41: | |
42: | |
43: | |
44: | |
45: |
|
46: | public $_confOptions = array();
|
47: |
|
48: | public $conf_id;
|
49: | public $conf_modid;
|
50: | public $conf_catid;
|
51: | public $conf_name;
|
52: | public $conf_title;
|
53: | public $conf_value;
|
54: | public $conf_desc;
|
55: | public $conf_formtype;
|
56: | public $conf_valuetype;
|
57: | public $conf_order;
|
58: |
|
59: | |
60: | |
61: |
|
62: | public function __construct()
|
63: | {
|
64: | $this->initVar('conf_id', XOBJ_DTYPE_INT, null, false);
|
65: | $this->initVar('conf_modid', XOBJ_DTYPE_INT, null, false);
|
66: | $this->initVar('conf_catid', XOBJ_DTYPE_INT, null, false);
|
67: | $this->initVar('conf_name', XOBJ_DTYPE_OTHER);
|
68: | $this->initVar('conf_title', XOBJ_DTYPE_TXTBOX);
|
69: | $this->initVar('conf_value', XOBJ_DTYPE_TXTAREA);
|
70: | $this->initVar('conf_desc', XOBJ_DTYPE_OTHER);
|
71: | $this->initVar('conf_formtype', XOBJ_DTYPE_OTHER);
|
72: | $this->initVar('conf_valuetype', XOBJ_DTYPE_OTHER);
|
73: | $this->initVar('conf_order', XOBJ_DTYPE_INT);
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function id($format = 'N')
|
82: | {
|
83: | return $this->getVar('conf_id', $format);
|
84: | }
|
85: |
|
86: | |
87: | |
88: | |
89: | |
90: |
|
91: | public function conf_id($format = '')
|
92: | {
|
93: | return $this->getVar('conf_id', $format);
|
94: | }
|
95: |
|
96: | |
97: | |
98: | |
99: | |
100: |
|
101: | public function conf_modid($format = '')
|
102: | {
|
103: | return $this->getVar('conf_modid', $format);
|
104: | }
|
105: |
|
106: | |
107: | |
108: | |
109: | |
110: |
|
111: | public function conf_catid($format = '')
|
112: | {
|
113: | return $this->getVar('conf_catid', $format);
|
114: | }
|
115: |
|
116: | |
117: | |
118: | |
119: | |
120: |
|
121: | public function conf_name($format = '')
|
122: | {
|
123: | return $this->getVar('conf_name', $format);
|
124: | }
|
125: |
|
126: | |
127: | |
128: | |
129: | |
130: |
|
131: | public function conf_title($format = '')
|
132: | {
|
133: | return $this->getVar('conf_title', $format);
|
134: | }
|
135: |
|
136: | |
137: | |
138: | |
139: | |
140: |
|
141: | public function conf_value($format = '')
|
142: | {
|
143: | return $this->getVar('conf_value', $format);
|
144: | }
|
145: |
|
146: | |
147: | |
148: | |
149: | |
150: |
|
151: | public function conf_desc($format = '')
|
152: | {
|
153: | return $this->getVar('conf_desc', $format);
|
154: | }
|
155: |
|
156: | |
157: | |
158: | |
159: | |
160: |
|
161: | public function conf_formtype($format = '')
|
162: | {
|
163: | return $this->getVar('conf_formtype', $format);
|
164: | }
|
165: |
|
166: | |
167: | |
168: | |
169: | |
170: |
|
171: | public function conf_valuetype($format = '')
|
172: | {
|
173: | return $this->getVar('conf_valuetype', $format);
|
174: | }
|
175: |
|
176: | |
177: | |
178: | |
179: | |
180: |
|
181: | public function conf_order($format = '')
|
182: | {
|
183: | return $this->getVar('conf_order', $format);
|
184: | }
|
185: |
|
186: | |
187: | |
188: | |
189: | |
190: |
|
191: | public function getConfValueForOutput()
|
192: | {
|
193: | switch ($this->getVar('conf_valuetype')) {
|
194: | case 'int':
|
195: | return (int)$this->getVar('conf_value', 'N');
|
196: | break;
|
197: | case 'array':
|
198: | $value = @unserialize($this->getVar('conf_value', 'N'));
|
199: |
|
200: | return $value ?: array();
|
201: | case 'float':
|
202: | $value = $this->getVar('conf_value', 'N');
|
203: |
|
204: | return (float)$value;
|
205: | break;
|
206: | case 'textarea':
|
207: | return $this->getVar('conf_value');
|
208: | default:
|
209: | return $this->getVar('conf_value', 'N');
|
210: | break;
|
211: | }
|
212: | }
|
213: |
|
214: | |
215: | |
216: | |
217: | |
218: | |
219: |
|
220: | public function setConfValueForInput(&$value, $force_slash = false)
|
221: | {
|
222: | switch ($this->getVar('conf_valuetype')) {
|
223: | case 'array':
|
224: | if (!is_array($value)) {
|
225: | $value = explode('|', trim((string)$value));
|
226: | }
|
227: | $this->setVar('conf_value', serialize($value), $force_slash);
|
228: | break;
|
229: | case 'text':
|
230: | $this->setVar('conf_value', trim((string)$value), $force_slash);
|
231: | break;
|
232: | default:
|
233: | $this->setVar('conf_value', $value, $force_slash);
|
234: | break;
|
235: | }
|
236: | }
|
237: |
|
238: | |
239: | |
240: | |
241: | |
242: |
|
243: | public function setConfOptions($option)
|
244: | {
|
245: | if (is_array($option)) {
|
246: | $count = count($option);
|
247: | for ($i = 0; $i < $count; ++$i) {
|
248: | $this->setConfOptions($option[$i]);
|
249: | }
|
250: | } else {
|
251: | if (is_object($option)) {
|
252: | $this->_confOptions[] =& $option;
|
253: | }
|
254: | }
|
255: | }
|
256: |
|
257: | |
258: | |
259: | |
260: | |
261: |
|
262: | public function &getConfOptions()
|
263: | {
|
264: | return $this->_confOptions;
|
265: | }
|
266: |
|
267: | |
268: | |
269: | |
270: | |
271: |
|
272: | public function clearConfOptions()
|
273: | {
|
274: | $this->_confOptions = array();
|
275: | }
|
276: | }
|
277: |
|
278: | |
279: | |
280: | |
281: | |
282: | |
283: | |
284: | |
285: | |
286: |
|
287: | class XoopsConfigItemHandler extends XoopsObjectHandler
|
288: | {
|
289: | |
290: | |
291: | |
292: | |
293: | |
294: | |
295: |
|
296: | public function create($isNew = true)
|
297: | {
|
298: | $config = new XoopsConfigItem();
|
299: | if ($isNew) {
|
300: | $config->setNew();
|
301: | }
|
302: |
|
303: | return $config;
|
304: | }
|
305: |
|
306: | |
307: | |
308: | |
309: | |
310: | |
311: |
|
312: | public function get($id)
|
313: | {
|
314: | $config = false;
|
315: | $id = (int)$id;
|
316: | if ($id > 0) {
|
317: | $sql = 'SELECT * FROM ' . $this->db->prefix('config') . ' WHERE conf_id=' . $id;
|
318: | $result = $this->db->query($sql);
|
319: | if (!$this->db->isResultSet($result)) {
|
320: | return $config;
|
321: | }
|
322: | $numrows = $this->db->getRowsNum($result);
|
323: | if ($numrows == 1) {
|
324: | $myrow = $this->db->fetchArray($result);
|
325: | $config = new XoopsConfigItem();
|
326: | $config->assignVars($myrow);
|
327: | }
|
328: | }
|
329: |
|
330: | return $config;
|
331: | }
|
332: |
|
333: | |
334: | |
335: | |
336: | |
337: | |
338: | |
339: |
|
340: | public function insert(XoopsObject $config)
|
341: | {
|
342: | $className = 'XoopsConfigItem';
|
343: | if (!($config instanceof $className)) {
|
344: | return false;
|
345: | }
|
346: | if (!$config->isDirty()) {
|
347: | return true;
|
348: | }
|
349: | if (!$config->cleanVars()) {
|
350: | return false;
|
351: | }
|
352: |
|
353: | $conf_id = $config->getVar('conf_id', 'n');
|
354: | $conf_modid = $config->getVar('conf_modid', 'n');
|
355: | $conf_catid = $config->getVar('conf_catid', 'n');
|
356: | $conf_name = $config->getVar('conf_name', 'n');
|
357: | $conf_title = $config->getVar('conf_title', 'n');
|
358: | $conf_value = $config->getVar('conf_value', 'n');
|
359: | $conf_desc = $config->getVar('conf_desc', 'n');
|
360: | $conf_formtype = $config->getVar('conf_formtype', 'n');
|
361: | $conf_valuetype = $config->getVar('conf_valuetype', 'n');
|
362: | $conf_order = $config->getVar('conf_order', 'n');
|
363: |
|
364: | if ($config->isNew()) {
|
365: | $conf_id = $this->db->genId('config_conf_id_seq');
|
366: | $sql = sprintf('INSERT INTO %s (conf_id, conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) VALUES (%u, %u, %u, %s, %s, %s, %s, %s, %s, %u)', $this->db->prefix('config'), $conf_id, $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order);
|
367: | } else {
|
368: | $sql = sprintf('UPDATE %s SET conf_modid = %u, conf_catid = %u, conf_name = %s, conf_title = %s, conf_value = %s, conf_desc = %s, conf_formtype = %s, conf_valuetype = %s, conf_order = %u WHERE conf_id = %u', $this->db->prefix('config'), $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order, $conf_id);
|
369: | }
|
370: | if (!$result = $this->db->query($sql)) {
|
371: | return false;
|
372: | }
|
373: | if (empty($conf_id)) {
|
374: | $conf_id = $this->db->getInsertId();
|
375: | }
|
376: | $config->assignVar('conf_id', $conf_id);
|
377: |
|
378: | return true;
|
379: | }
|
380: |
|
381: | |
382: | |
383: | |
384: | |
385: | |
386: | |
387: |
|
388: | public function delete(XoopsObject $config)
|
389: | {
|
390: | $className = 'XoopsConfigItem';
|
391: | if (!($config instanceof $className)) {
|
392: | return false;
|
393: | }
|
394: | $sql = sprintf('DELETE FROM %s WHERE conf_id = %u', $this->db->prefix('config'), $config->getVar('conf_id'));
|
395: | if (!$result = $this->db->query($sql)) {
|
396: | return false;
|
397: | }
|
398: |
|
399: | return true;
|
400: | }
|
401: |
|
402: | |
403: | |
404: | |
405: | |
406: | |
407: | |
408: |
|
409: | public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
|
410: | {
|
411: | $ret = array();
|
412: | $limit = $start = 0;
|
413: | $sql = 'SELECT * FROM ' . $this->db->prefix('config');
|
414: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
415: | $sql .= ' ' . $criteria->renderWhere();
|
416: | $sql .= ' ORDER BY conf_order ASC';
|
417: | $limit = $criteria->getLimit();
|
418: | $start = $criteria->getStart();
|
419: | }
|
420: | $result = $this->db->query($sql, $limit, $start);
|
421: | if (!$this->db->isResultSet($result)) {
|
422: | return $ret;
|
423: | }
|
424: |
|
425: | while (false !== ($myrow = $this->db->fetchArray($result))) {
|
426: | $config = new XoopsConfigItem();
|
427: | $config->assignVars($myrow);
|
428: | if (!$id_as_key) {
|
429: | $ret[] =& $config;
|
430: | } else {
|
431: | $ret[$myrow['conf_id']] = &$config;
|
432: | }
|
433: | unset($config);
|
434: | }
|
435: |
|
436: | return $ret;
|
437: | }
|
438: |
|
439: | |
440: | |
441: | |
442: | |
443: | |
444: |
|
445: | public function getCount(CriteriaElement $criteria = null)
|
446: | {
|
447: | $sql = 'SELECT * FROM ' . $this->db->prefix('config');
|
448: | if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
|
449: | $sql .= ' ' . $criteria->renderWhere();
|
450: | }
|
451: | $result = $this->db->query($sql);
|
452: | if (!$this->db->isResultSet($result)) {
|
453: | return 0;
|
454: | }
|
455: | list($count) = $this->db->fetchRow($result);
|
456: |
|
457: | return (int)$count;
|
458: | }
|
459: | }
|
460: | |