示例#1
0
    /**
     * Edit Config
     */
    function config_edit()
    {
        $default_config_settings = Wygwam_helper::default_config_settings();
        if (($config_id = $this->EE->input->get('config_id')) && ($query = $this->EE->db->get_where('wygwam_configs', array('config_id' => $config_id))) && $query->num_rows()) {
            $config = $query->row_array();
            $config['settings'] = unserialize(base64_decode($config['settings']));
            $config['settings'] = array_merge($default_config_settings, $config['settings']);
            // duplicate?
            if ($this->EE->input->get('clone') == 'y') {
                $config['config_id'] = '';
                $config['config_name'] .= ' ' . lang('wygwam_clone');
                $this->_set_page_title(lang('wygwam_create_config'));
            } else {
                $this->_set_page_title(lang('wygwam_edit_config') . ' - ' . $config['config_name']);
            }
        } else {
            $config = array('config_id' => '', 'config_name' => '', 'settings' => $default_config_settings);
            $this->_set_page_title(lang('wygwam_create_config'));
        }
        $vars['config'] = $config;
        $vars['base'] = $this->base;
        $this->EE->load->library('table');
        // -------------------------------------------
        //  Upload Directory
        // -------------------------------------------
        $wygwam_settings = Wygwam_helper::get_global_settings();
        $msm = $this->EE->config->item('multiple_sites_enabled') == 'y';
        // If we're using Assets and it is installed, let's show Assets sources instead of just EE filedirs.
        if (isset($wygwam_settings['file_browser']) && $wygwam_settings['file_browser'] == 'assets' && Wygwam_helper::is_assets_installed()) {
            // Initialize the Assets lib
            require_once PATH_THIRD . 'assets/helper.php';
            $assets_helper = new Assets_helper();
            if ($msm) {
                $query = $this->EE->db->query("SELECT site_id, site_label FROM exp_sites")->result();
                foreach ($query as $row) {
                    $site_map[$row->site_id] = $row->site_label;
                }
            }
            $upload_dirs = array('' => '--');
            $all_sources = ee()->assets_lib->get_all_sources();
            foreach ($all_sources as $source) {
                $upload_dirs[$source->type . ':' . $source->id] = ($msm && $source->type == 'ee' ? $site_map[$source->site_id] . ' - ' : '') . $source->name;
            }
        } else {
            $dir_query = $this->EE->db->query('SELECT u.id, u.name, s.site_label
											   FROM exp_upload_prefs u, exp_sites s
											   WHERE u.site_id = s.site_id
											   ORDER BY site_label, name');
            if ($dir_query->num_rows()) {
                $upload_dirs = array('' => '--');
                foreach ($dir_query->result_array() as $row) {
                    $upload_dirs[$row['id']] = ($msm ? $row['site_label'] . ' - ' : '') . $row['name'];
                }
            }
        }
        if (!empty($upload_dirs)) {
            $vars['upload_dir'] = form_dropdown('settings[upload_dir]', $upload_dirs, $config['settings']['upload_dir'], 'id="upload_dir"');
        } else {
            $this->EE->lang->loadfile('admin_content');
            $vars['upload_dir'] = lang('no_upload_prefs');
        }
        // -------------------------------------------
        //  Advanced Settings
        // -------------------------------------------
        // which settings have we already shown?
        $skip = array_keys($default_config_settings);
        // get settings that should be treated as lists
        $config_lists = Wygwam_helper::config_lists();
        // sort settings by key
        ksort($config['settings']);
        $js = '';
        foreach ($config['settings'] as $setting => $value) {
            // skip?
            if (in_array($setting, $skip)) {
                continue;
            }
            // format_tags?
            if ($setting == 'format_tags') {
                $value = explode(';', $value);
            }
            // list?
            if (in_array($setting, $config_lists)) {
                $value = implode("\n", $value);
            }
            $json = Wygwam_helper::get_json($value);
            $js .= 'new wygwam_addSettingRow("' . $setting . '", ' . $json . ');' . NL;
        }
        // Resources
        Wygwam_helper::include_theme_css('lib/ckeditor/skins/wygwam3/editor.css');
        Wygwam_helper::include_theme_css('styles/config_edit.css');
        $this->EE->cp->add_js_script(array('ui' => 'draggable'));
        Wygwam_helper::include_theme_js('lib/ckeditor/ckeditor.js');
        Wygwam_helper::include_theme_js('scripts/config_edit_toolbar.js');
        Wygwam_helper::include_theme_js('scripts/config_edit_advanced.js');
        Wygwam_helper::insert_js('jQuery(document).ready(function(){' . NL . $js . '});');
        Wygwam_helper::insert_js('jQuery("#restrict_html").ptSwitch();');
        return $this->EE->load->view('config_edit', $vars, TRUE);
    }