1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Handlers\XoopsConfigItem;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: defined('XOOPS_INSTALL') or die('XOOPS Custom Installation die');
28:
29: 30: 31: 32: 33:
34: function createConfigform($config)
35: {
36: $xoops = Xoops::getInstance();
37: $config_handler = $xoops->getHandlerConfig();
38:
39:
40:
41: $ret = array();
42: $confcount = count($config);
43:
44: for ($i = 0; $i < $confcount; ++$i) {
45: $conf_catid = $config[$i]->getVar('conf_catid');
46: if (!isset($ret[$conf_catid])) {
47: $ret[$conf_catid] = new Xoops\Form\ThemeForm('', 'configs', 'index.php', 'post');
48: }
49:
50: $title = \Xoops\Locale::translate($config[$i]->getVar('conf_title'), 'system');
51:
52: switch ($config[$i]->getVar('conf_formtype')) {
53:
54: case 'textarea':
55: if ($config[$i]->getVar('conf_valuetype') === 'array') {
56:
57: $ele = ($config[$i]->getVar('conf_value') != '')
58: ? new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), installHtmlSpecialCharacters(implode('|', $config[$i]->getConfValueForOutput())), 5, 50)
59: : new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), '', 5, 50);
60: } else {
61: $ele = new Xoops\Form\TextArea($title, $config[$i]->getVar('conf_name'), installHtmlSpecialCharacters($config[$i]->getConfValueForOutput()), 5, 100);
62: }
63: break;
64:
65: case 'select':
66: $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
67: $options =& $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
68: $opcount = count($options);
69: for ($j = 0; $j < $opcount; ++$j) {
70: $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), 'system');
71: $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), 'system');
72: $ele->addOption($optval, $optkey);
73: }
74: break;
75:
76: case 'select_multi':
77: $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
78: $options =& $config_handler->getConfigOptions(new Criteria('conf_id', $config[$i]->getVar('conf_id')));
79: $opcount = count($options);
80: for ($j = 0; $j < $opcount; ++$j) {
81: $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), 'system');
82: $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), 'system');
83: $ele->addOption($optval, $optkey);
84: }
85: break;
86:
87: case 'yesno':
88: $ele = new Xoops\Form\RadioYesNo($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), XoopsLocale::YES, XoopsLocale::NO);
89: break;
90:
91: case 'theme':
92: case 'theme_multi':
93: $ele = ($config[$i]->getVar('conf_formtype') !== 'theme_multi')
94: ? new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput())
95: : new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true);
96: $dirlist = XoopsLists::getThemesList();
97: if (!empty($dirlist)) {
98: asort($dirlist);
99: $ele->addOptionArray($dirlist);
100: }
101: break;
102:
103: case 'tplset':
104: $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
105: $tplset_handler = $xoops->getHandlerTplSet();
106: $tplsetlist = $tplset_handler->getNameList();
107: asort($tplsetlist);
108: foreach ($tplsetlist as $key => $name) {
109: $ele->addOption($key, $name);
110: }
111: break;
112:
113: case 'timezone':
114: $ele = new Xoops\Form\SelectTimeZone($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
115: break;
116:
117: case 'language':
118: $ele = new Xoops\Form\SelectLanguage($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
119: break;
120:
121: case 'locale':
122: $ele = new Xoops\Form\SelectLocale($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
123: break;
124:
125: case 'startpage':
126: $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
127: $module_handler = $xoops->getHandlerModule();
128: $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
129: $criteria->add(new Criteria('isactive', 1));
130: $moduleslist =& $module_handler->getNameList($criteria, true);
131: $moduleslist['--'] = XoopsLocale::NONE;
132: $ele->addOptionArray($moduleslist);
133: break;
134:
135: case 'group':
136: $ele = new Xoops\Form\SelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
137: break;
138:
139: case 'group_multi':
140: $ele = new Xoops\Form\SelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
141: break;
142:
143:
144: case 'user':
145: $ele = new Xoops\Form\SelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false);
146: break;
147:
148: case 'user_multi':
149: $ele = new Xoops\Form\SelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true);
150: break;
151:
152: case 'module_cache':
153: $module_handler = $xoops->getHandlerModule();
154: $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
155: $currrent_val = $config[$i]->getConfValueForOutput();
156: $cache_options = array(
157: '0' => XoopsLocale::NO_CACHE,
158: '30' => sprintf(XoopsLocale::F_SECONDS, 30),
159: '60' => XoopsLocale::ONE_MINUTE,
160: '300' => sprintf(XoopsLocale::F_MINUTES, 5),
161: '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
162: '3600' => XoopsLocale::ONE_HOUR,
163: '18000' => sprintf(XoopsLocale::F_HOURS, 5),
164: '86400' => XoopsLocale::ONE_DAY,
165: '259200' => sprintf(XoopsLocale::F_DAYS, 3),
166: '604800' => XoopsLocale::ONE_WEEK,
167: '2592000' => XoopsLocale::ONE_MONTH
168: );
169: if (count($modules) > 0) {
170: $ele = new Xoops\Form\ElementTray($title, '<br />');
171: foreach (array_keys($modules) as $mid) {
172: $c_val = isset($currrent_val[$mid]) ? (int)($currrent_val[$mid]) : null;
173: $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $config[$i]->getVar('conf_name') . "[$mid]", $c_val);
174: $selform->addOptionArray($cache_options);
175: $ele->addElement($selform);
176: unset($selform);
177: }
178: } else {
179: $ele = new Xoops\Form\Label($title, SystemLocale::NO_MODULE_TO_CACHE);
180: }
181: break;
182:
183: case 'site_cache':
184: $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
185: $ele->addOptionArray(array(
186: '0' => XoopsLocale::NO_CACHE,
187: '30' => sprintf(XoopsLocale::F_SECONDS, 30),
188: '60' => XoopsLocale::ONE_MINUTE,
189: '300' => sprintf(XoopsLocale::F_MINUTES, 5),
190: '1800' => sprintf(XoopsLocale::F_MINUTES, 30),
191: '3600' => XoopsLocale::ONE_HOUR,
192: '18000' => sprintf(XoopsLocale::F_HOURS, 5),
193: '86400' => XoopsLocale::ONE_DAY,
194: '259200' => sprintf(XoopsLocale::F_DAYS, 3),
195: '604800' => XoopsLocale::ONE_WEEK,
196: '2592000' => XoopsLocale::ONE_MONTH
197: ));
198: break;
199:
200: case 'password':
201: $ele = new Xoops\Form\Password($title, $config[$i]->getVar('conf_name'), 50, 255, installHtmlSpecialCharacters($config[$i]->getConfValueForOutput()));
202: break;
203:
204: case 'color':
205: $ele = new Xoops\Form\ColorPicker($title, $config[$i]->getVar('conf_name'), installHtmlSpecialCharacters($config[$i]->getConfValueForOutput()));
206: break;
207:
208: case 'hidden':
209: $ele = new Xoops\Form\Hidden($config[$i]->getVar('conf_name'), installHtmlSpecialCharacters($config[$i]->getConfValueForOutput()));
210: break;
211:
212: case 'textbox':
213: default:
214: $ele = new Xoops\Form\Text($title, $config[$i]->getVar('conf_name'), 50, 255, installHtmlSpecialCharacters($config[$i]->getConfValueForOutput()));
215: break;
216: }
217:
218: if ($config[$i]->getVar('conf_desc') != '') {
219: $ele->setDescription(\Xoops\Locale::translate($config[$i]->getVar('conf_desc'), 'system'));
220: }
221: $ret[$conf_catid]->addElement($ele);
222:
223: $hidden = new Xoops\Form\Hidden('conf_ids[]', $config[$i]->getVar('conf_id'));
224: $ret[$conf_catid]->addElement($hidden);
225:
226: unset($ele);
227: unset($hidden);
228: }
229: return $ret;
230: }
231:
232: 233: 234: 235: 236:
237: function createThemeform(XoopsConfigItem $config)
238: {
239: $title = $config->getVar('conf_desc') == '' ? \Xoops\Locale::translate($config->getVar('conf_title'), 'system') : \Xoops\Locale::translate($config->getVar('conf_title'), 'system') . '<br /><br /><span>' . \Xoops\Locale::translate($config->getVar('conf_desc'), 'system') . '</span>';
240: $form_theme_set = new Xoops\Form\Select('', $config->getVar('conf_name'), $config->getConfValueForOutput(), 1, false);
241: $dirlist = XoopsLists::getThemesList();
242: if (!empty($dirlist)) {
243: asort($dirlist);
244: $form_theme_set->addOptionArray($dirlist);
245: }
246:
247: $label_content = "";
248:
249:
250: foreach ($dirlist as $theme) {
251:
252: $theme_ini = array(
253: 'Name' => $theme,
254: 'Description' => '',
255: 'Version' => '',
256: 'Format' => '',
257: 'Author' => '',
258: 'Demo' => '',
259: 'Url' => '',
260: 'Download' => '',
261: 'W3C' => '',
262: 'Licence' => '',
263: 'thumbnail' => 'screenshot.gif',
264: 'screenshot' => 'screenshot.png',
265: );
266:
267: if ($theme == $config->getConfValueForOutput()) {
268: $label_content .= "<div id='$theme' rel='theme' style='display:block;'>";
269: } else {
270: $label_content .= "<div id='$theme' rel='theme' style='display:none;'>";
271: }
272: if (file_exists(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini")) {
273: $theme_ini = parse_ini_file(XOOPS_ROOT_PATH . "/themes/$theme/theme.ini");
274: if ($theme_ini['screenshot'] == '') {
275: $theme_ini['screenshot'] = 'screenshot.png';
276: $theme_ini['thumbnail'] = 'thumbnail.png';
277: }
278: }
279:
280: if ($theme_ini['screenshot'] != '' && file_exists(XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['screenshot'])) {
281: $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['screenshot'] . "' alt='Screenshot' />";
282: } elseif ($theme_ini['thumbnail'] != '' && file_exists(XOOPS_ROOT_PATH . "/themes/$theme/" . $theme_ini['thumbnail'])) {
283: $label_content .= "<img src='" . XOOPS_URL . "/themes/" . $theme . "/" . $theme_ini['thumbnail'] . "' alt='$theme' />";
284: } else {
285: $label_content .= THEME_NO_SCREENSHOT;
286: }
287: $label_content .= "</div>";
288: }
289:
290:
291: $form_theme_set->setExtra("onchange='showThemeSelected(this)'");
292:
293: $form = new Xoops\Form\ThemeForm($title, 'themes', 'index.php', 'post');
294: $form->addElement($form_theme_set);
295: $form->addElement(new Xoops\Form\Label('', "<div id='screenshot'>" . $label_content . "</div>"));
296:
297: $form->addElement(new Xoops\Form\Hidden('conf_ids[]', $config->getVar('conf_id')));
298: return array($form);
299: }
300: