1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: if (!defined('XOOPS_INSTALL')) {
18: die('XOOPS Custom Installation die');
19: }
20:
21: include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
22: include_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
23:
24: define('PREF_1', _MD_AM_GENERAL);
25: define('PREF_2', _MD_AM_USERSETTINGS);
26: define('PREF_3', _MD_AM_METAFOOTER);
27: define('PREF_4', _MD_AM_CENSOR);
28: define('PREF_5', _MD_AM_SEARCH);
29: define('PREF_6', _MD_AM_MAILER);
30: if (defined('_MD_AM_AUTHENTICATION')) {
31: define('PREF_7', _MD_AM_AUTHENTICATION);
32: }
33:
34: 35: 36: 37: 38:
39: function createConfigform($config)
40: {
41: xoops_load('XoopsFormRendererBootstrap3');
42: XoopsFormRenderer::getInstance()->set(new XoopsFormRendererBootstrap3());
43:
44:
45: $config_handler = xoops_getHandler('config');
46: $GLOBALS['xoopsConfig'] = $xoopsConfig = $config_handler->getConfigsByCat(XOOPS_CONF);
47:
48: $ret = array();
49: $confcount = count($config);
50:
51: for ($i = 0; $i < $confcount; ++$i) {
52: $conf_catid = $config[$i]->getVar('conf_catid');
53: if (!isset($ret[$conf_catid])) {
54: $form_title = constant('PREF_' . $conf_catid);
55: $ret[$conf_catid] = new XoopsThemeForm($form_title, 'configs', 'index.php', 'post');
56: }
57:
58: $title = constant($config[$i]->getVar('conf_title'));
59:
60: switch ($config[$i]->getVar('conf_formtype')) {
61: case 'textarea':
62: $myts = MyTextSanitizer::getInstance();
63: if ($config[$i]->getVar('conf_valuetype') === 'array') {
64:
65: $ele = ($config[$i]->getVar('conf_value') != '') ? new XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars(implode('|', $config[$i]->getConfValueForOutput())), 5, 50) : new XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), '', 5, 50);
66: } else {
67: $ele = new XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()), 5, 100);
68: }
69: break;
70:
71: case 'select':
72: $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
73: $options = $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
74: $opcount = count($options);
75: for ($j = 0; $j < $opcount; ++$j) {
76: $optval = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value');
77: $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name');
78: $ele->addOption($optval, $optkey);
79: }
80: break;
81:
82: case 'select_multi':
83: $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
84: $options = $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
85: $opcount = count($options);
86: for ($j = 0; $j < $opcount; ++$j) {
87: $optval = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value');
88: $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name');
89: $ele->addOption($optval, $optkey);
90: }
91: break;
92:
93: case 'yesno':
94: $ele = new XoopsFormRadioYN($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), _YES, _NO);
95: break;
96:
97: case 'theme':
98: case 'theme_multi':
99: $ele = ($config[$i]->getVar('conf_formtype') !== 'theme_multi') ? new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput()) : new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
100: require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
101: $dirlist = XoopsLists::getThemesList();
102: if (!empty($dirlist)) {
103: asort($dirlist);
104: $ele->addOptionArray($dirlist);
105: }
106:
107: $form->addElement(new XoopsFormHidden('_old_theme', $config[$i]->getConfValueForOutput()));
108: break;
109:
110: case 'tplset':
111: $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
112: $tplset_handler = xoops_getHandler('tplset');
113: $tplsetlist = $tplset_handler->getList();
114: asort($tplsetlist);
115: foreach ($tplsetlist as $key => $name) {
116: $ele->addOption($key, $name);
117: }
118:
119: $form->addElement(new XoopsFormHidden('_old_theme', $config[$i]->getConfValueForOutput()));
120: break;
121:
122: case 'timezone':
123: $ele = new XoopsFormSelectTimezone($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
124: break;
125:
126: case 'language':
127: $ele = new XoopsFormSelectLang($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
128: break;
129:
130: case 'startpage':
131: $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
132:
133: $module_handler = xoops_getHandler('module');
134: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
135: $criteria->add(new Criteria('isactive', 1));
136: $moduleslist = $module_handler->getList($criteria, true);
137: $moduleslist['--'] = _MD_AM_NONE;
138: $ele->addOptionArray($moduleslist);
139: break;
140:
141: case 'group':
142: $ele = new XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
143: break;
144:
145: case 'group_multi':
146: $ele = new XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
147: break;
148:
149:
150: case 'user':
151: $ele = new XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
152: break;
153:
154: case 'user_multi':
155: $ele = new XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
156: break;
157:
158: case 'module_cache':
159:
160: $module_handler = xoops_getHandler('module');
161: $modules = $module_handler->getObjects(new Criteria('hasmain', 1), true);
162: $currrent_val = $config[$i]->getConfValueForOutput();
163: $cache_options = array(
164: '0' => _NOCACHE,
165: '30' => sprintf(_SECONDS, 30),
166: '60' => _MINUTE,
167: '300' => sprintf(_MINUTES, 5),
168: '1800' => sprintf(_MINUTES, 30),
169: '3600' => _HOUR,
170: '18000' => sprintf(_HOURS, 5),
171: '86400' => _DAY,
172: '259200' => sprintf(_DAYS, 3),
173: '604800' => _WEEK);
174: if (count($modules) > 0) {
175: $ele = new XoopsFormElementTray($title, '<br>');
176: foreach (array_keys($modules) as $mid) {
177: $c_val = isset($currrent_val[$mid]) ? (int)$currrent_val[$mid] : null;
178: $selform = new XoopsFormSelect($modules[$mid]->getVar('name'), $config[$i]->getVar('conf_name') . "[$mid]", $c_val);
179: $selform->addOptionArray($cache_options);
180: $ele->addElement($selform);
181: unset($selform);
182: }
183: } else {
184: $ele = new XoopsFormLabel($title, _MD_AM_NOMODULE);
185: }
186: break;
187:
188: case 'site_cache':
189: $ele = new XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
190: $ele->addOptionArray(array(
191: '0' => _NOCACHE,
192: '30' => sprintf(_SECONDS, 30),
193: '60' => _MINUTE,
194: '300' => sprintf(_MINUTES, 5),
195: '1800' => sprintf(_MINUTES, 30),
196: '3600' => _HOUR,
197: '18000' => sprintf(_HOURS, 5),
198: '86400' => _DAY,
199: '259200' => sprintf(_DAYS, 3),
200: '604800' => _WEEK));
201: break;
202:
203: case 'password':
204: $myts = MyTextSanitizer::getInstance();
205: $ele = new XoopsFormPassword($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
206: break;
207:
208: case 'color':
209: $myts = MyTextSanitizer::getInstance();
210: $ele = new XoopsFormColorPicker($title, $config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
211: break;
212:
213: case 'hidden':
214: $myts = MyTextSanitizer::getInstance();
215: $ele = new XoopsFormHidden($config[$i]->getVar('conf_name'), $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
216: break;
217:
218: case 'textbox':
219: default:
220: $myts = MyTextSanitizer::getInstance();
221: $ele = new XoopsFormText($title, $config[$i]->getVar('conf_name'), 50, 255, $myts->htmlspecialchars($config[$i]->getConfValueForOutput()));
222: break;
223: }
224:
225: if (defined($config[$i]->getVar('conf_desc')) && constant($config[$i]->getVar('conf_desc')) != '') {
226: $ele->setDescription(constant($config[$i]->getVar('conf_desc')));
227: }
228: $ret[$conf_catid]->addElement($ele);
229:
230: $hidden = new XoopsFormHidden('conf_ids[]', $config[$i]->getVar('conf_id'));
231: $ret[$conf_catid]->addElement($hidden);
232:
233: unset($ele, $hidden);
234: }
235:
236: return $ret;
237: }
238:
239: 240: 241: 242: 243:
244: function createThemeform($config)
245: {
246: xoops_load('XoopsFormRendererBootstrap3');
247: XoopsFormRenderer::getInstance()->set(new XoopsFormRendererBootstrap3());
248:
249: $title = (!defined($config->getVar('conf_desc')) || constant($config->getVar('conf_desc')) === '') ? constant($config->getVar('conf_title')) : constant($config->getVar('conf_title')) . '<br><br><span>' . constant($config->getVar('conf_desc')) . '</span>';
250: $form_theme_set = new XoopsFormSelect('', $config->getVar('conf_name'), $config->getConfValueForOutput(), 1, false);
251: $dirlist = XoopsLists::getThemesList();
252: if (!empty($dirlist)) {
253: asort($dirlist);
254: $form_theme_set->addOptionArray($dirlist);
255: }
256:
257: $label_content = '';
258:
259:
260: foreach ($dirlist as $theme) {
261:
262: $theme_ini = array(
263: 'Name' => $theme,
264: 'Description' => '',
265: 'Version' => '',
266: 'Format' => '',
267: 'Author' => '',
268: 'Demo' => '',
269: 'Url' => '',
270: 'Download' => '',
271: 'W3C' => '',
272: 'Licence' => '',
273: 'thumbnail' => 'screenshot.gif',
274: 'screenshot' => 'screenshot.png');
275:
276: if ($theme == $config->getConfValueForOutput()) {
277: $label_content .= '<div class="theme_preview" id="'.$theme.'" style="display:block;">';
278: } else {
279: $label_content .= '<div class="theme_preview" id="'.$theme.'" style="display:none;">';
280: }
281: if (file_exists(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini")) {
282: $theme_ini = parse_ini_file(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini");
283: if ($theme_ini['screenshot'] == '') {
284: $theme_ini['screenshot'] = 'screenshot.png';
285: $theme_ini['thumbnail'] = 'thumbnail.png';
286: }
287: }
288:
289: if ($theme_ini['screenshot'] !== '' && file_exists(XOOPS_ROOT_PATH . '/themes/' . $theme . '/' . $theme_ini['screenshot'])) {
290: $label_content .= '<img class="img-responsive" src="' . XOOPS_URL . '/themes/' . $theme . '/' . $theme_ini['screenshot'] . '" alt="Screenshot" />';
291: } elseif ($theme_ini['thumbnail'] !== '' && file_exists(XOOPS_ROOT_PATH . '/themes/' . $theme .'/' . $theme_ini['thumbnail'])) {
292: $label_content .= '<img class="img-responsive" src="' . XOOPS_URL . '/themes/' . $theme . '/' . $theme_ini['thumbnail'] . '" alt="$theme" />';
293: } else {
294: $label_content .= THEME_NO_SCREENSHOT;
295: }
296: $label_content .= '</div>';
297: }
298:
299:
300: $form_theme_set->setExtra("onchange='showThemeSelected(this)'");
301:
302: $form = new XoopsThemeForm($title, 'themes', 'index.php', 'post');
303: $form->addElement($form_theme_set);
304: $form->addElement(new XoopsFormLabel('', "<div id='screenshot'>" . $label_content . '</div>'));
305:
306: $form->addElement(new XoopsFormHidden('conf_ids[]', $config->getVar('conf_id')));
307:
308: return $ret = array($form);
309: }
310: