From a5747cf8289932b50ab652f46e5d9eb0701343fa Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 17 May 2009 21:10:06 +0000 Subject: [PATCH] MDL-19211 text editor plugins configuration --- admin/editors.php | 91 ++++++++++++++++++++++ admin/settings/plugins.php | 8 ++ admin/uploaduser_form.php | 2 + lang/en_utf8/editor.php | 6 ++ lang/en_utf8/editor_tinymce.php | 2 +- lib/adminlib.php | 134 +++++++++++++++++++++++++++++++- lib/db/install.php | 1 + lib/db/upgrade.php | 18 ++++- lib/editorlib.php | 7 +- lib/javascript.php | 11 +-- version.php | 2 +- 11 files changed, 266 insertions(+), 16 deletions(-) create mode 100644 admin/editors.php diff --git a/admin/editors.php b/admin/editors.php new file mode 100644 index 0000000000..e63dc2ef25 --- /dev/null +++ b/admin/editors.php @@ -0,0 +1,91 @@ +libdir.'/adminlib.php'); +require_once($CFG->libdir.'/tablelib.php'); + +require_login(); +require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + +$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageeditors"; + +$action = optional_param('action', '', PARAM_ACTION); +$editor = optional_param('editor', '', PARAM_SAFEDIR); + +// get currently installed and enabled auth plugins +$available_editors = get_available_editors(); +if (!empty($editor) and empty($available_editors[$editor])) { + redirect ($returnurl); +} + +$active_editors = explode(',', $CFG->texteditors); +foreach ($active_editors as $key=>$active) { + if (empty($available_editors[$active])) { + unset($active_editors[$key]); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// process actions + +if (!confirm_sesskey()) { + redirect($returnurl); +} + +switch ($action) { + case 'disable': + // remove from enabled list + $key = array_search($editor, $active_editors); + unset($active_editors[$key]); + break; + + case 'enable': + // add to enabled list + if (!in_array($editor, $active_editors)) { + $active_editors[] = $editor; + $active_editors = array_unique($active_editors); + } + break; + + case 'down': + $key = array_search($editor, $active_editors); + // check auth plugin is valid + if ($key !== false) { + // move down the list + if ($key < (count($active_editors) - 1)) { + $fsave = $active_editors[$key]; + $active_editors[$key] = $active_editors[$key + 1]; + $active_editors[$key + 1] = $fsave; + } + } + break; + + case 'up': + $key = array_search($editor, $active_editors); + // check auth is valid + if ($key !== false) { + // move up the list + if ($key >= 1) { + $fsave = $active_editors[$key]; + $active_editors[$key] = $active_editors[$key - 1]; + $active_editors[$key - 1] = $fsave; + } + } + break; + + default: + break; +} + +// at least one editor must be active +if (empty($active_editors)) { + $active_editors = array('textarea'); +} + +set_config('texteditors', implode(',', $active_editors)); + +redirect ($returnurl); diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index b48e54aa03..bffb8b11a1 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -73,6 +73,14 @@ if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) } +/// Editor plugins + $ADMIN->add('modules', new admin_category('editorsettings', get_string('editors', 'editor'))); + $temp = new admin_settingpage('manageeditors', get_string('editorsettings', 'editor')); + $temp->add(new admin_setting_manageeditors()); + $ADMIN->add('editorsettings', $temp); + + +/// Filter plugins $ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters'))); $ADMIN->add('filtersettings', new admin_page_managefilters()); diff --git a/admin/uploaduser_form.php b/admin/uploaduser_form.php index 3a2cb84027..370bb55db0 100644 --- a/admin/uploaduser_form.php +++ b/admin/uploaduser_form.php @@ -174,6 +174,7 @@ class admin_uploaduser_form2 extends moodleform { $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices); $mform->setDefault('autosubscribe', 1); +/* TODO: reimplement editor preferences if ($CFG->htmleditor) { $choices = array(0 => get_string('texteditor'), 1 => get_string('htmleditor')); $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices); @@ -182,6 +183,7 @@ class admin_uploaduser_form2 extends moodleform { $mform->addElement('static', 'htmleditor', get_string('textediting'), get_string('texteditor')); } $mform->setAdvanced('htmleditor'); +*/ if (empty($CFG->enableajax)) { $mform->addElement('static', 'ajax', get_string('ajaxuse'), get_string('ajaxno')); diff --git a/lang/en_utf8/editor.php b/lang/en_utf8/editor.php index a335fbbd15..ed86b4161b 100644 --- a/lang/en_utf8/editor.php +++ b/lang/en_utf8/editor.php @@ -1,6 +1,12 @@ $editorstr) { + if (strpos($editor, $query) !== false) { + return true; + } + if (strpos($textlib->strtolower($editorstr), $query) !== false) { + return true; + } + } + return false; + } + + public function output_html($data, $query='') { + global $CFG; + + // display strings + $txt = get_strings(array('administration', 'settings', 'edit', 'name', 'enable', 'disable', + 'up', 'down', 'none')); + $txt->updown = "$txt->up/$txt->down"; + + $editors_available = get_available_editors(); + $active_editors = explode(',', $CFG->texteditors); + + $active_editors = array_reverse($active_editors); + foreach ($active_editors as $key=>$editor) { + if (empty($editors_available[$editor])) { + unset($active_editors[$key]); + } else { + $name = $editors_available[$editor]; + unset($editors_available[$editor]); + $editors_available[$editor] = $name; + } + } + if (empty($active_editors)) { + //$active_editors = array('textarea'); + } + $editors_available = array_reverse($editors_available, true); + $return = print_heading(get_string('acteditorshhdr', 'editor'), '', 3, 'main', true); + $return .= print_box_start('generalbox editorsui', '', true); + + $table = new object(); + $table->head = array($txt->name, $txt->enable, $txt->updown, $txt->settings); + $table->align = array('left', 'center', 'center', 'center'); + $table->width = '90%'; + $table->data = array(); + + // iterate through auth plugins and add to the display table + $updowncount = 1; + $editorcount = count($active_editors); + $url = "editors.php?sesskey=" . sesskey(); + foreach ($editors_available as $editor => $name) { + // hide/show link + if (in_array($editor, $active_editors)) { + $hideshow = ""; + $hideshow .= "pixpath}/i/hide.gif\" class=\"icon\" alt=\"disable\" />"; + // $hideshow = ""; + $enabled = true; + $displayname = "$name"; + } + else { + $hideshow = ""; + $hideshow .= "pixpath}/i/show.gif\" class=\"icon\" alt=\"enable\" />"; + // $hideshow = ""; + $enabled = false; + $displayname = "$name"; + } + + // up/down link (only if auth is enabled) + $updown = ''; + if ($enabled) { + if ($updowncount > 1) { + $updown .= ""; + $updown .= "pixpath}/t/up.gif\" alt=\"up\" /> "; + } + else { + $updown .= "pixpath}/spacer.gif\" class=\"icon\" alt=\"\" /> "; + } + if ($updowncount < $editorcount) { + $updown .= ""; + $updown .= "pixpath}/t/down.gif\" alt=\"down\" />"; + } + else { + $updown .= "pixpath}/spacer.gif\" class=\"icon\" alt=\"\" />"; + } + ++ $updowncount; + } + + // settings link + if (file_exists($CFG->dirroot.'/editor/'.$editor.'/settings.php')) { + $settings = "{$txt->settings}"; + } else { + $settings = ''; + } + + // add a row to the table + $table->data[] =array($displayname, $hideshow, $updown, $settings); + } + $return .= print_table($table, true); + $return .= get_string('configeditorplugins', 'editor').'
'.get_string('tablenosave', 'filters'); + $return .= print_box_end(true); + return highlight($query, $return); + } +} + /** * Special class for filter administration. */ @@ -4724,7 +4856,7 @@ class admin_setting_managerepository extends admin_setting { $instanceoptionnames = repository::static_function($i->get_typename(), 'get_instance_option_names'); if ( !empty($typeoptionnames) || !empty($instanceoptionnames)) { - + //calculate number of instances in order to display them for the Moodle administrator if (!empty($instanceoptionnames)) { $admininstancenumber = count(repository::static_function($i->get_typename(), 'get_instances', array(get_context_instance(CONTEXT_SYSTEM)),null,false,$i->get_typename())); diff --git a/lib/db/install.php b/lib/db/install.php index 691bf0f9a7..7c441bf0a2 100644 --- a/lib/db/install.php +++ b/lib/db/install.php @@ -59,6 +59,7 @@ function xmldb_main_install() { 'sessiontimeout' => 7200, // must be present during roles installation 'stringfilters' => '', // These two are managed in a strange way by the filters 'filterall' => 0, // setting page, so have to be initialised here. + 'texteditors' => 'tinymce,textarea', ); foreach($defaults as $key => $value) { set_config($key, $value); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 958dd0a22e..d8a70fbc0e 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2137,8 +2137,22 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009051200); } + + if ($result && $oldversion < 2009051700) { + /// migrate editor settings + if (empty($CFG->htmleditor)) { + set_config('texteditors', 'textarea'); + } else { + set_config('texteditors', 'tinymce,textarea'); + } + + unset_config('htmleditor'); + unset_config('defaulthtmleditor'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009051700); + } + return $result; } - -?> diff --git a/lib/editorlib.php b/lib/editorlib.php index f1ccd5c1a8..c35bc55c25 100644 --- a/lib/editorlib.php +++ b/lib/editorlib.php @@ -23,11 +23,6 @@ // // /////////////////////////////////////////////////////////////////////////// -//TODO: -// * remove $CFG->htmleditor and $CFG->defaulthtmleditor and $USER->htmleditor -// * - - function get_preferred_texteditor($format=null) { global $CFG, $USER; @@ -91,7 +86,7 @@ function get_texteditor($editor) { function get_available_editors() { $editors = array(); foreach (get_list_of_plugins('lib/editor') as $editor) { - $editors['editor'] = get_string('modulename', 'editor_'.$editor); + $editors[$editor] = get_string('modulename', 'editor_'.$editor); } return $editors; } diff --git a/lib/javascript.php b/lib/javascript.php index b7c5fbeaaf..eaa53685ce 100644 --- a/lib/javascript.php +++ b/lib/javascript.php @@ -14,7 +14,7 @@ if (!defined('MOODLE_INTERNAL')) { - + -texteditors)) { $CFG->texteditors = 'tinymce,textarea'; } $activeeditors = explode(',', $CFG->texteditors); foreach ($activeeditors as $editor) { - $editor = get_texteditor($editor); - echo $editor->header_js(); + if ($editor = get_texteditor($editor)) { + echo $editor->header_js(); + } } ?> \ No newline at end of file diff --git a/version.php b/version.php index b69f081620..10fc3a2776 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2009051200; // YYYYMMDD = date of the last version bump + $version = 2009051700; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20090517)'; // Human-friendly version name -- 2.39.5