Exemplo n.º 1
0
 /**
  * gets list of editors
  *
  * @return array
  */
 public static function getEditorList()
 {
     return \Xoops\Core\Lists\Editor::getList();
 }
Exemplo n.º 2
0
 /**
  * getForm
  *
  * @param array       &$obj array of config objects
  * @param XoopsModule $mod module
  *
  * @return void
  */
 public function getForm(&$obj, XoopsModule $mod)
 {
     $xoops = Xoops::getInstance();
     $config_handler = $xoops->getHandlerConfig();
     parent::__construct('', 'pref_form', 'admin.php?fct=preferences', 'post', true);
     if ($mod->getVar('dirname') !== 'system') {
         $xoops->loadLanguage('modinfo', $mod->getVar('dirname'));
     }
     $xoops->loadLocale($mod->getVar('dirname'));
     $configs = $mod->getInfo('config');
     $configNames = array();
     foreach (array_keys($configs) as $i) {
         $configNames[$configs[$i]['name']] =& $configs[$i];
     }
     $configCats = $mod->getInfo('configcat');
     if (!$configCats) {
         $configCats = array('default' => array('name' => SystemLocale::OTHER_SETTINGS, 'description' => ''));
     }
     if (!in_array('default', array_keys($configCats))) {
         $configCats['default'] = array('name' => SystemLocale::OTHER_SETTINGS, 'description' => '');
     }
     foreach (array_keys($configNames) as $name) {
         if (!isset($configNames[$name]['category'])) {
             $configNames[$name]['category'] = 'default';
         }
     }
     $tabTray = new Xoops\Form\TabTray('', 'pref_tabtay');
     $tabs = array();
     foreach ($configCats as $name => $info) {
         $tabs[$name] = new Xoops\Form\Tab($info['name'], 'pref_tab_' . $name);
         if (isset($info['description']) && $info['description'] != '') {
             $tabs[$name]->addElement(new Xoops\Form\Label('', $info['description']));
         }
     }
     $xoops->preload()->triggerEvent('onSystemPreferencesForm', array($mod));
     if (!empty($_REQUEST["redirect"])) {
         $myts = \Xoops\Core\Text\Sanitizer::getInstance();
         $this->addElement(new Xoops\Form\Hidden('redirect', $myts->htmlSpecialChars($_REQUEST["redirect"])));
     } elseif ($mod->getInfo('adminindex')) {
         $this->addElement(new Xoops\Form\Hidden('redirect', \XoopsBaseConfig::get('url') . '/modules/' . $mod->getVar('dirname') . '/' . $mod->getInfo('adminindex')));
     }
     $count = count($obj);
     for ($i = 0; $i < $count; ++$i) {
         $title = \Xoops\Locale::translate($obj[$i]->getVar('conf_title'), $mod->getVar('dirname'));
         $desc = $obj[$i]->getVar('conf_desc') != '' ? \Xoops\Locale::translate($obj[$i]->getVar('conf_desc'), $mod->getVar('dirname')) : '';
         switch ($obj[$i]->getVar('conf_formtype')) {
             case 'textarea':
                 $myts = \Xoops\Core\Text\Sanitizer::getInstance();
                 if ($obj[$i]->getVar('conf_valuetype') === 'array') {
                     // this is exceptional.. only when value type is arrayneed a smarter way for this
                     $ele = $obj[$i]->getVar('conf_value') != '' ? new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars(implode('|', $obj[$i]->getConfValueForOutput())), 5, 5) : new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), '', 5, 5);
                 } else {
                     $ele = new Xoops\Form\TextArea($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()), 5, 5);
                 }
                 break;
             case 'select':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
                 $opcount = count($options);
                 for ($j = 0; $j < $opcount; ++$j) {
                     $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
                     $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
                     $ele->addOption($optval, $optkey);
                 }
                 break;
             case 'select_editor':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 \Xoops\Core\Lists\Editor::setOptionsArray($ele);
                 break;
             case 'select_multi':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
                 $options = $config_handler->getConfigOptions(new Criteria('conf_id', $obj[$i]->getVar('conf_id')));
                 $opcount = count($options);
                 for ($j = 0; $j < $opcount; ++$j) {
                     $optval = \Xoops\Locale::translate($options[$j]->getVar('confop_value'), $mod->getVar('dirname'));
                     $optkey = \Xoops\Locale::translate($options[$j]->getVar('confop_name'), $mod->getVar('dirname'));
                     $ele->addOption($optval, $optkey);
                 }
                 break;
             case 'yesno':
                 $ele = new Xoops\Form\RadioYesNo($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 break;
             case 'theme':
             case 'theme_multi':
                 $ele = $obj[$i]->getVar('conf_formtype') !== 'theme_multi' ? new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput()) : new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput(), 5, true);
                 $dirlist = XoopsLists::getThemesList();
                 if (!empty($dirlist)) {
                     asort($dirlist);
                     $ele->addOptionArray($dirlist);
                 }
                 break;
             case 'tplset':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 $tplset_handler = $xoops->getHandlerTplSet();
                 $tplsetlist = $tplset_handler->getNameList();
                 asort($tplsetlist);
                 foreach ($tplsetlist as $key => $name) {
                     $ele->addOption($key, $name);
                 }
                 break;
             case 'cpanel':
                 $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 /*
                                     $ele = new Xoops\Form\Select($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput());
                                     XoopsLoad::load("cpanel", "system");
                                     $list = XoopsSystemCpanel::getGuis();
                                     $ele->addOptionArray($list);  */
                 break;
             case 'timezone':
                 $ele = new Xoops\Form\SelectTimeZone($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 break;
             case 'language':
                 $ele = new Xoops\Form\SelectLanguage($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 break;
             case 'locale':
                 $ele = new Xoops\Form\SelectLocale($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 break;
             case 'startpage':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 $module_handler = $xoops->getHandlerModule();
                 $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
                 $criteria->add(new Criteria('isactive', 1));
                 $moduleslist = $module_handler->getNameList($criteria, true);
                 $moduleslist['--'] = XoopsLocale::NONE;
                 $ele->addOptionArray($moduleslist);
                 break;
             case 'group':
                 $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
                 break;
             case 'group_multi':
                 $ele = new Xoops\Form\SelectGroup($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
                 break;
                 // RMV-NOTIFY: added 'user' and 'user_multi'
             // RMV-NOTIFY: added 'user' and 'user_multi'
             case 'user':
                 $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 1, false);
                 break;
             case 'user_multi':
                 $ele = new Xoops\Form\SelectUser($title, $obj[$i]->getVar('conf_name'), false, $obj[$i]->getConfValueForOutput(), 5, true);
                 break;
             case 'module_cache':
                 $module_handler = $xoops->getHandlerModule();
                 $modules = $module_handler->getObjectsArray(new Criteria('hasmain', 1), true);
                 $currrent_val = $obj[$i]->getConfValueForOutput();
                 $cache_options = array('0' => XoopsLocale::NO_CACHE, '30' => sprintf(XoopsLocale::F_SECONDS, 30), '60' => XoopsLocale::ONE_MINUTE, '300' => sprintf(XoopsLocale::F_MINUTES, 5), '1800' => sprintf(XoopsLocale::F_MINUTES, 30), '3600' => XoopsLocale::ONE_HOUR, '18000' => sprintf(XoopsLocale::F_HOURS, 5), '86400' => XoopsLocale::ONE_DAY, '259200' => sprintf(XoopsLocale::F_DAYS, 3), '604800' => XoopsLocale::ONE_WEEK, '2592000' => XoopsLocale::ONE_MONTH);
                 if (count($modules) > 0) {
                     $ele = new Xoops\Form\ElementTray($title, '<br />');
                     foreach (array_keys($modules) as $mid) {
                         $c_val = isset($currrent_val[$mid]) ? (int) $currrent_val[$mid] : null;
                         $selform = new Xoops\Form\Select($modules[$mid]->getVar('name'), $obj[$i]->getVar('conf_name') . "[{$mid}]", $c_val);
                         $selform->addOptionArray($cache_options);
                         $ele->addElement($selform);
                         unset($selform);
                     }
                 } else {
                     $ele = new Xoops\Form\Label($title, SystemLocale::NO_MODULE_TO_CACHE);
                 }
                 break;
             case 'site_cache':
                 $ele = new Xoops\Form\Select($title, $obj[$i]->getVar('conf_name'), $obj[$i]->getConfValueForOutput());
                 $ele->addOptionArray(array('0' => XoopsLocale::NO_CACHE, '30' => sprintf(XoopsLocale::F_SECONDS, 30), '60' => XoopsLocale::ONE_MINUTE, '300' => sprintf(XoopsLocale::F_MINUTES, 5), '1800' => sprintf(XoopsLocale::F_MINUTES, 30), '3600' => XoopsLocale::ONE_HOUR, '18000' => sprintf(XoopsLocale::F_HOURS, 5), '86400' => XoopsLocale::ONE_DAY, '259200' => sprintf(XoopsLocale::F_DAYS, 3), '604800' => XoopsLocale::ONE_WEEK, '2592000' => XoopsLocale::ONE_MONTH));
                 break;
             case 'password':
                 $myts = \Xoops\Core\Text\Sanitizer::getInstance();
                 $ele = new Xoops\Form\Password($title, $obj[$i]->getVar('conf_name'), 32, 255, $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
                 break;
             case 'color':
                 $myts = \Xoops\Core\Text\Sanitizer::getInstance();
                 $ele = new Xoops\Form\ColorPicker($title, $obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
                 break;
             case 'hidden':
                 $myts = \Xoops\Core\Text\Sanitizer::getInstance();
                 $ele = new Xoops\Form\Hidden($obj[$i]->getVar('conf_name'), $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
                 break;
             case 'textbox':
             default:
                 $myts = \Xoops\Core\Text\Sanitizer::getInstance();
                 $ele = new Xoops\Form\Text($title, $obj[$i]->getVar('conf_name'), 5, 255, $myts->htmlSpecialChars($obj[$i]->getConfValueForOutput()));
                 break;
         }
         $hidden = new Xoops\Form\Hidden('conf_ids[]', $obj[$i]->getVar('conf_id'));
         if (isset($ele)) {
             $ele->setDescription($desc);
             if ($obj[$i]->getVar('conf_formtype') !== 'hidden') {
                 $name = 'default';
                 if (isset($configNames[$obj[$i]->getVar('conf_name')]['category'])) {
                     $name = $configNames[$obj[$i]->getVar('conf_name')]['category'];
                 }
                 $tabs[$name]->addElement($ele);
             } else {
                 $this->addElement($ele);
             }
             $this->addElement($hidden);
             unset($ele);
             unset($hidden);
         }
     }
     foreach (array_keys($tabs) as $name) {
         if ($tabs[$name]->getElements()) {
             $tabTray->addElement($tabs[$name]);
         }
     }
     $this->addElement($tabTray);
     $this->addElement(new Xoops\Form\Hidden('op', 'save'));
     $this->addElement(new Xoops\Form\Button('', 'button', XoopsLocale::A_SUBMIT, 'submit'));
 }