1: <?php
2: /**
3: * Functions handling module configs
4: *
5: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
6: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
7: * @author Taiwen Jiang <phppp@users.sourceforge.net>
8: * @since 1.00
9: * @package Frameworks
10: * @subpackage art
11: */
12:
13: if (!defined('FRAMEWORKS_ART_FUNCTIONS_CONFIG')):
14: define('FRAMEWORKS_ART_FUNCTIONS_CONFIG', true);
15:
16: /**
17: * Load configs of a module
18: *
19: *
20: * @param string $dirname module dirname
21: * @return array
22: */
23: function mod_loadConfig($dirname = '')
24: {
25: if (empty($dirname) && empty($GLOBALS['xoopsModule'])) {
26: return null;
27: }
28: $dirname = !empty($dirname) ? $dirname : $GLOBALS['xoopsModule']->getVar('dirname');
29:
30: if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) && $GLOBALS['xoopsModule']->getVar('dirname', 'n') == $dirname) {
31: if (isset($GLOBALS['xoopsModuleConfig'])) {
32: $moduleConfig =& $GLOBALS['xoopsModuleConfig'];
33: } else {
34: return null;
35: }
36: } else {
37: xoops_load('XoopsCache');
38: if (!$moduleConfig = XoopsCache::read("{$dirname}_config")) {
39: $moduleConfig = mod_fetchConfig($dirname);
40: XoopsCache::write("{$dirname}_config", $moduleConfig);
41: }
42: }
43: if ($customConfig = @include XOOPS_ROOT_PATH . "/modules/{$dirname}/include/plugin.php") {
44: $moduleConfig = array_merge($moduleConfig, $customConfig);
45: }
46:
47: return $moduleConfig;
48: }
49:
50: /**
51: * @param string $dirname
52: *
53: * @return array
54: */
55: function mod_loadConfg($dirname = '')
56: {
57: return mod_loadConfig($dirname);
58: }
59:
60: /**
61: * Fetch configs of a module from database
62: *
63: *
64: * @param string $dirname module dirname
65: * @return array
66: */
67: function mod_fetchConfig($dirname = '')
68: {
69: if (empty($dirname)) {
70: return null;
71: }
72:
73: /** @var \XoopsModuleHandler $module_handler */
74: $module_handler = xoops_getHandler('module');
75: if (!$module = $module_handler->getByDirname($dirname)) {
76: trigger_error("Module '{$dirname}' does not exist", E_USER_WARNING);
77:
78: return null;
79: }
80:
81: /** @var XoopsConfigHandler $config_handler */
82: $config_handler = xoops_getHandler('config');
83: $criteria = new CriteriaCompo(new Criteria('conf_modid', $module->getVar('mid')));
84: $configs = $config_handler->getConfigs($criteria);
85: foreach (array_keys($configs) as $i) {
86: $moduleConfig[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
87: }
88: unset($module, $configs);
89:
90: return $moduleConfig;
91: }
92:
93: /**
94: * @param string $dirname
95: *
96: * @return array
97: */
98: function mod_fetchConfg($dirname = '')
99: {
100: return mod_fetchConfig($dirname);
101: }
102:
103: /**
104: * clear config cache of a module
105: *
106: *
107: * @param string $dirname module dirname
108: * @return bool
109: */
110: function mod_clearConfig($dirname = '')
111: {
112: if (empty($dirname)) {
113: return false;
114: }
115:
116: xoops_load('XoopsCache');
117:
118: return XoopsCache::delete("{$dirname}_config");
119: }
120:
121: /**
122: * @param string $dirname
123: *
124: * @return bool
125: */
126: function mod_clearConfg($dirname = '')
127: {
128: return mod_clearConfig($dirname);
129: }
130:
131: endif;
132: