示例#1
0
function configure_rm_plugin()
{
    $name = rmc_server_var($_GET, 'plugin', '');
    if ($name == '') {
        redirectMsg('plugins.php', __('You must specify a existing plugin', 'rmcommon'), 1);
        die;
    }
    $plugin = new RMPlugin($name);
    if ($plugin->isNew()) {
        redirectMsg('plugins.php', __('Specified plugin is not installed yet!', 'rmcommon'), 1);
        die;
    }
    if (!$plugin->getVar('status')) {
        redirectMsg('plugins.php', __('Specified plugin is not active!', 'rmcommon'), 1);
        die;
    }
    $rmc_config = RMFunctions::configs();
    $settings = RMFunctions::get()->plugin_settings($name, true);
    $form = new RMForm(sprintf(__('%s configuration', 'rmcommon'), $plugin->getVar('name')), 'frmconfig', 'plugins.php');
    $form->addElement(new RMFormHidden('plugin', $plugin->getVar('dir')));
    $form->addElement(new RMFormHidden('action', 'savesettings'));
    foreach ($plugin->options() as $config => $option) {
        if (isset($settings[$config])) {
            $option['value'] = $settings[$config];
        }
        if (isset($option['separator']) && !empty($option['separator'])) {
            $form->addElement(new RMFormSubTitle($option['separator']['title'], 1, '', $option['separator']['desc']));
            continue;
        }
        switch ($option['fieldtype']) {
            case 'checkbox_groups':
            case 'group_multi':
                $ele = new RMFormGroups($option['caption'], 'conf_' . $config, 1, 1, 3, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'radio_groups':
                $ele = new RMFormGroups($option['caption'], 'conf_' . $config, 0, 1, 3, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'group':
            case 'select_groups':
                $ele = new RMFormGroups($option['caption'], 'conf_' . $config, 0, 0, 3, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'select_groups_multi':
                $ele = new RMFormGroups($option['caption'], 'conf_' . $config, 1, 0, 3, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'editor':
                if ($rmc_config['editor_type'] == 'tiny') {
                    $tiny = TinyEditor::getInstance();
                    $tiny->add_config('elements', 'conf_' . $config);
                }
                $ele = new RMFormEditor($option['caption'], 'conf_' . $config, is_numeric($option['size']) ? '90%' : $option['size'], '300px', $option['value'], '', 1, array('op'));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'theme':
            case 'select_theme':
                $ele = new RMFormTheme($option['caption'], 'conf_' . $config, 0, 0, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'theme_multi':
            case 'select_theme_multi':
                $ele = new RMFormTheme($option['caption'], 'conf_' . $config, 0, 1, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'checkbox_theme':
                $ele = new RMFormTheme($option['caption'], 'conf_' . $config, 1, 1, $option['value'], 4);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'select_theme_admin':
                $ele = new RMFormTheme($option['caption'], 'conf_' . $config, 0, 0, $option['value'], 3, 'GUI');
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'yesno':
                $ele = new RMFormYesNo($option['caption'], 'conf_' . $config, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'email':
                $ele = new RMFormText($option['caption'], 'conf_' . $config, $option['size'] > 0 ? $option['size'] : 50, null, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele, false, 'email');
                break;
            case 'select':
                $ele = new RMFormSelect($option['caption'], 'conf_' . $config);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                foreach ($option['options'] as $op => $opvalue) {
                    $ele->addOption($opvalue, $op, $opvalue == $option['value'] ? 1 : 0);
                }
                $form->addElement($ele);
                break;
            case 'select_multi':
                $ele = new RMFormSelect($option['caption'], 'conf_' . $config . '[]', 1, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                foreach ($option['options'] as $op => $opvalue) {
                    $ele->addOption($opvalue, $op);
                }
                $form->addElement($ele);
                break;
            case 'language':
            case 'select_language':
                $ele = new RMFormLanguageField($option['caption'], 'conf_' . $config, 0, 0, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'select_language_multi':
                $ele = new RMFormLanguageField($option['caption'], 'conf_' . $config, 1, 0, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'checkbox_language':
                $ele = new RMFormLanguageField($option['caption'], 'conf_' . $config, 1, 1, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'startpage':
            case 'select_modules':
                $ele = new RMFormModules($option['caption'], 'conf_' . $config, 0, 0, $option['value'], 3);
                $ele->setInserted(array('--' => __('None', 'rmcommon')));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'select_modules_multi':
                $ele = new RMFormModules($option['caption'], 'conf_' . $config, 1, 0, $option['value'], 3);
                $ele->setInserted(array('--' => __('None', 'rmcommon')));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'checkbox_modules':
                $ele = new RMFormModules($option['caption'], 'conf_' . $config, 1, 1, $option['value'], 3);
                $ele->setInserted(array('--' => __('None', 'rmcommon')));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'radio_modules':
                $ele = new RMFormModules($option['caption'], 'conf_' . $config, 0, 1, $option['value'], 3);
                $ele->setInserted(array('--' => __('None', 'rmcommon')));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'timezone':
            case 'select_timezone':
                $ele = new RMFormTimeZoneField($option['caption'], 'conf_' . $config, 0, 0, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'select_timezone_multi':
                $ele = new RMFormTimeZoneField($option['caption'], 'conf_' . $config, 0, 1, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'checkbox_timezone':
                $ele = new RMFormTimeZoneField($option['caption'], 'conf_' . $config, 1, 1, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'radio_timezone':
                $ele = new RMFormTimeZoneField($option['caption'], 'conf_' . $config, 1, 0, $option['value'], 3);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'tplset':
                $ele = new RMFormSelect($option['caption'], 'conf_' . $config);
                $tplset_handler =& exm_gethandler('tplset');
                $tplsetlist =& $tplset_handler->getList();
                asort($tplsetlist);
                foreach ($tplsetlist as $key => $name) {
                    $ele->addOption($key, $name, $option['value'] == $key ? 1 : 0);
                }
                $form->addElement($ele);
                break;
            case 'textarea':
                $ele = new RMFormTextArea($option['caption'], 'conf_' . $config, 5, $option['size'] > 0 ? $option['size'] : 50, $option['valuetype'] == 'array' ? $cleaner->htmlspecialchars(implode('|', $option['value'])) : $cleaner->htmlspecialchars($option['value']));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'module_cache':
                $ele = new RMFormCacheModuleField($option['caption'], 'conf_' . $config, $option['value']);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'user_select':
                $ele = new RMFormUser($option['caption'], 'conf_' . $config, $form->getName(), $option['value'], 'select', $limit = '300', '');
                $ele->setOnPage("document.forms[0].op.value='config';");
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele);
                break;
            case 'radio':
                $ele = new RMFormRadio($option['caption'], 'conf_' . $config, 1);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                foreach ($option['options'] as $op => $opvalue) {
                    $ele->addOption($op, $opvalue, $opvalue == $option['value'] ? 1 : 0);
                }
                $form->addElement($ele);
                break;
            case 'font_select':
                $ele = new RMFormSelect($option['caption'], 'conf_' . $config, 0, array($option['value']));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $fonts = EXMLists::getFileListAsArray(ABSPATH . '/rmcommon/fonts/');
                foreach ($fonts as $font) {
                    $info = pathinfo(ABSPATH . '/rmcommon/fonts/' . $font);
                    if (strtoupper($info['extension']) != 'TTF') {
                        continue;
                    }
                    $ele->addOption($font, $font);
                }
                $form->addElement($ele);
                break;
            case 'select_editor':
                $ele = new RMFormSelect($option['caption'], 'conf_' . $config, 0, array($option['value']));
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $ele->addOption('tiny', __('Visual Editor', 'rmcommon'));
                $ele->addOption('code', __('EXMCode Editor', 'rmcommon'));
                $ele->addOption('textarea', __('Simple Editor', 'rmcommon'));
                $ele->addOption('html', __('HTML Editor', 'rmcommon'));
                $form->addElement($ele);
                break;
            case 'textbox':
            case 'password':
            default:
                $ele = new RMFormText($option['caption'], 'conf_' . $config, $option['size'] > 0 ? $option['size'] : 50, null, $option['valuetype'] == 'array' ? implode('|', $option['value']) : $option['value'], $option['fieldtype'] == 'password' ? 1 : 0);
                if ($option['desc'] != '') {
                    $ele->setDescription($option['desc']);
                }
                $form->addElement($ele, false, $option['valuetype'] == 'int' || $option['valuetype'] == 'float' ? 'num' : '');
                break;
        }
    }
    $ele = new RMFormButtonGroup();
    $ele->addButton('', __('Save Settings', 'rmcommon'), 'submit');
    $ele->addButton('', __('Cancel', 'rmcommon'), 'button', 'onclick="history.go(-1);"');
    $form->addElement($ele);
    // Other components can add items to database
    $form = RMEvents::get()->run_event("rmcommon.settings.form", $form, $plugin);
    RMFunctions::create_toolbar();
    xoops_cp_header();
    $form->display();
    xoops_cp_footer();
}
示例#2
0
/**
* This function prepares an option to show in confgiuration form
* @param array Configuration option
* @return string
*/
function xt_form_field($name, $option, $ret = 0)
{
    global $xtAssembler, $xtFunctions;
    static $ids = 0;
    $form = new RMForm('', '', '');
    if ($xtAssembler->theme()->settings($name) !== false) {
        $option['value'] = $xtAssembler->theme()->settings($name);
    } else {
        $option['value'] = $option['default'];
    }
    $cleaner = TextCleaner::getInstance();
    $name = 'conf_' . $name;
    switch ($option['type']) {
        case 'checkbox_groups':
        case 'group_multi':
            $ele = new RMFormGroups($option['caption'], $name, 1, 1, 3, $option['value']);
            break;
        case 'radio_groups':
            $ele = new RMFormGroups($option['caption'], $name, 0, 1, 3, $option['value']);
            break;
        case 'group':
        case 'select_groups':
            $ele = new RMFormGroups($option['caption'], $name, 0, 0, 3, $option['value']);
            break;
        case 'select_groups_multi':
            $ele = new RMFormGroups($option['caption'], $name, 1, 0, 3, $option['value']);
            break;
        case 'editor':
            /*if ($rmc_config['editor_type']=='tiny'){
                  $tiny = TinyEditor::getInstance();
                  $tiny->add_config('elements',$name);
              }*/
            $ele = new RMFormEditor($option['caption'], $name, isset($option['size']) ? $option['size'] : '100%', '300px', $option['value'], '', 1, array('op'));
            break;
        case 'theme':
        case 'select_theme':
            $ele = new RMFormTheme($option['caption'], $name, 0, 0, $option['value'], 3);
            break;
        case 'theme_multi':
        case 'select_theme_multi':
        case 'checkbox_theme':
            $ele = new RMFormTheme($option['caption'], $name, 1, 1, $option['value'], 3);
            break;
        case 'gui':
            $ele = new RMFormTheme($option['caption'], $name, 0, 0, $option['value'], 3, 'GUI');
            break;
        case 'gui_multi':
            $ele = new RMFormTheme($option['caption'], $name, 1, 1, $option['value'], 3, 'GUI');
            break;
        case 'yesno':
            $ele = new RMFormYesNo($option['caption'], $name, $option['value']);
            break;
        case 'email':
            $ele = new RMFormText($option['caption'], $name, isset($option['size']) && $option['size'] > 0 ? $option['size'] : 50, null, $option['value']);
            $ele->setClass('email');
            break;
        case 'select':
            $ele = new RMFormSelect($option['caption'], $name);
            foreach ($option['options'] as $opvalue => $op) {
                $ele->addOption($opvalue, $op, $opvalue == $option['value'] ? 1 : 0);
            }
            break;
        case 'select_multi':
            $ele = new RMFormSelect($option['caption'], $name . '[]', 1, $option['value']);
            foreach ($option['options'] as $opvalue => $op) {
                $ele->addOption($opvalue, $op);
            }
            break;
        case 'language':
        case 'select_language':
            $ele = new RMFormLanguageField($option['caption'], $name, 0, 0, $option['value'], 3);
            break;
        case 'select_language_multi':
        case 'checkbox_language':
        case 'language_multi':
            $ele = new RMFormLanguageField($option['caption'], $name, 1, 1, !is_array($option['value']) ? array($option['value']) : $option['value'], 3);
            break;
        case 'modules':
            $ele = new RMFormModules($option['caption'], $name, 0, 0, $option['value'], 3);
            $ele->setInserted(array('--' => __('None', 'rmcommon')));
            break;
        case 'modules_multi':
        case 'checkbox_modules':
            $ele = new RMFormModules($option['caption'], $name, 1, 1, $option['value'], 3);
            $ele->setInserted(array('--' => __('None', 'rmcommon')));
            break;
        case 'timezone':
        case 'select_timezone':
            $ele = new RMFormTimeZoneField($option['caption'], $name, 0, 0, $option['value'], 3);
            break;
        case 'timezone_multi':
            $ele = new RMFormTimeZoneField($option['caption'], $name, 0, 1, $option['value'], 3);
            break;
        case 'textarea':
            $ele = new RMFormTextArea($option['caption'], $name, 5, isset($option['size']) && $option['size'] > 0 ? $option['size'] : 50, $option['content'] == 'array' ? $cleaner->specialchars(implode('|', $option['value'])) : $cleaner->specialchars($option['value']));
            break;
        case 'user':
            $ele = new RMFormUser($option['caption'], $name, false, $option['value'], 300);
            break;
        case 'user_multi':
            $ele = new RMFormUser($option['caption'], $name, true, !is_array($option['value']) ? array($option['value']) : $option['value'], 300);
            break;
        case 'radio':
            $ele = new RMFormRadio($option['caption'], $name, 1);
            foreach ($option['options'] as $opvalue => $op) {
                $ele->addOption($op, $opvalue, $opvalue == $option['value'] ? 1 : 0);
            }
            break;
        case 'webfonts':
            $ele = new RMFormWebfonts($option['caption'], $name, $option['value']);
            break;
        case 'imageurl':
            $ele = new RMFormImageUrl($option['caption'], $name, $option['value']);
            break;
        case 'slider':
            if ($ret) {
                return;
            }
            $ele = new RMFormSlider($option['caption'], $name, $option['value']);
            $ele->addField('title', array('caption' => __('Slider Title', 'xthemes'), 'description' => __('Show the slider title', 'xthemes'), 'type' => 'textbox'));
            $i = 0;
            foreach ($option['options'] as $id => $data) {
                $ele->addField($id, $data);
            }
            break;
        case 'color':
            $ele = new RMFormColorSelector($option['caption'], $name, $option['value'], true);
            break;
        case 'imageselect':
            $ele = new RMFormImageSelect($option['caption'], $name, $option['value']);
            foreach ($option['options'] as $v => $url) {
                $ele->addImage($v, $url);
            }
            break;
        case 'textbox':
        case 'password':
        default:
            $ele = new RMFormText($option['caption'], $name, isset($option['size']) && $option['size'] > 0 ? $option['size'] : 50, null, $option['value'], $option['type'] == 'password' ? 1 : 0);
            break;
    }
    if (isset($option['attributes'])) {
        $ele->attrs($option['attributes']);
    }
    $ele->setId('xtfield-' . $ids);
    $ids++;
    return $ret ? $ele : $ele->render();
}