diff --git a/admin/editors.php b/admin/editors.php index 4604e4c5db8..476df6cd5f8 100644 --- a/admin/editors.php +++ b/admin/editors.php @@ -17,7 +17,7 @@ $action = optional_param('action', '', PARAM_ACTION); $editor = optional_param('editor', '', PARAM_SAFEDIR); // get currently installed and enabled auth plugins -$available_editors = get_available_editors(); +$available_editors = editors_get_available(); if (!empty($editor) and empty($available_editors[$editor])) { redirect ($returnurl); } diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 611ac11ae33..3425105e277 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -133,12 +133,10 @@ if ($hassiteconfig) { $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()); - $htmleditors = get_available_editors(); - $temp->add(new admin_setting_configselect('defaulthtmleditor', get_string('defaulthtmleditor', 'admin'), null, 'tinymce', $htmleditors)); - $temp->add(new admin_setting_configcheckbox('htmleditor', get_string('usehtmleditor', 'admin'), get_string('confightmleditor','admin'), 1)); + $htmleditors = editors_get_available(); $ADMIN->add('editorsettings', $temp); - $editors_available = get_available_editors(); + $editors_available = editors_get_available(); foreach ($editors_available as $editor=>$editorstr) { if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) { $settings = new admin_settingpage('editorsettings'.$editor, get_string('pluginname', 'editor_'.$editor), 'moodle/site:config'); diff --git a/admin/uploaduser_form.php b/admin/uploaduser_form.php index 29d3cb3d9f8..3dbc42eee0a 100644 --- a/admin/uploaduser_form.php +++ b/admin/uploaduser_form.php @@ -50,9 +50,6 @@ class admin_uploaduser_form2 extends moodleform { function definition (){ global $CFG, $USER; - //no editors here - we need proper empty fields - $CFG->htmleditor = null; - $mform =& $this->_form; $columns =& $this->_customdata; @@ -188,16 +185,18 @@ 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')); + $editors = editors_get_enabled(); + if (count($editors) > 1) { + $choices = array(); + $choices['0'] = get_string('texteditor'); + $choices['1'] = get_string('htmleditor'); $mform->addElement('select', 'htmleditor', get_string('textediting'), $choices); $mform->setDefault('htmleditor', 1); } else { - $mform->addElement('static', 'htmleditor', get_string('textediting'), get_string('texteditor')); + $mform->addElement('hidden', 'htmleditor'); + $mform->setDefault('htmleditor', 1); + $mform->setType('htmleditor', PARAM_INT); } - $mform->setAdvanced('htmleditor'); -*/ if (empty($CFG->enableajax)) { $mform->addElement('static', 'ajax', get_string('ajaxuse'), get_string('ajaxno')); diff --git a/admin/user/user_bulk_message.php b/admin/user/user_bulk_message.php index a739a01e3ca..2decac4c04e 100755 --- a/admin/user/user_bulk_message.php +++ b/admin/user/user_bulk_message.php @@ -34,11 +34,6 @@ if ($confirm and !empty($msg) and confirm_sesskey()) { redirect($return); } -// disable html editor if not enabled in preferences -if (!get_user_preferences('message_usehtmleditor', 0)) { - $CFG->htmleditor = ''; -} - $msgform = new user_message_form('user_bulk_message.php'); if ($msgform->is_cancelled()) { diff --git a/calendar/lib.php b/calendar/lib.php index 5eb2f53b591..5c899150778 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1673,14 +1673,7 @@ class calendar_event { $data->description = $data->description['text']; } else if (empty($data->description)) { $data->description = ''; - } - - if (empty($data->format)) { - if (can_use_html_editor()) { - $data->format = FORMAT_HTML; - } else { - $data->format = FORMAT_MOODLE; - } + $data->format = editors_get_preferred_format(); } $this->properties = $data; diff --git a/lang/en/admin.php b/lang/en/admin.php index 979666bfdb4..d4122072e76 100755 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -225,7 +225,6 @@ $string['configgradebookroles'] = 'This setting allows you to control who appear $string['configgradeexport'] = 'Choose which gradebook export formats are your primary methods for exporting grades. Chosen plugins will then set and use a "last exported" field for every grade. For example, this might result in exported records being identified as being "new" or "updated". If you are not sure about this then leave everything unchecked.'; $string['configguestroleid'] = 'This role is automatically assigned to the guest user. It is also temporarily assigned to not enrolled users when they enter course that allows guests without password. Please verify that the role has moodle/legacy:guest and moodle/course:view capability.'; $string['confighiddenuserfields'] = 'Select which user information fields you wish to hide from other users other than course teachers/admins. This will increase student privacy. Hold CTRL key to select multiple fields.'; -$string['confightmleditor'] = 'Choose whether or not to allow use of the embedded HTML text editor. Even if you choose allow, this editor will only appear when the user is using a compatible web browser. Users can also choose not to use it.'; $string['configidnumber'] = 'This option specifies whether (a) Users are not be asked for an ID number at all, (b) Users are asked for an ID number but can leave it blank or (c) Users are asked for an ID Number and cannot leave it blank. If given the User\'s ID number is displayed in their Profile.'; $string['configintcachemax'] = 'For internal cache only. Maximum number of records to keep in the cache. Recommended value: 50. Use lower values to reduce memory usage.'; $string['configintro'] = 'On this page you can specify a number of configuration variables that help make Moodle work properly on your server. Don\'t worry too much about it - the defaults will usually work fine and you can always come back to this page later and change these settings.'; @@ -420,7 +419,6 @@ $string['debugstringids'] = 'Show origin of languages strings'; $string['debugvalidators'] = 'Show validator links'; $string['defaultallowedmodules'] = 'Default allowed modules'; $string['defaulthomepage'] = 'Default home page for users'; -$string['defaulthtmleditor'] = 'Default HTML editor'; $string['defaultrequestcategory'] = 'Default category for course requests'; $string['defaultsettinginfo'] = 'Default: {$a}'; $string['defaultuserroleid'] = 'Default role for all users'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 81730ca12ba..663395bda45 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1690,7 +1690,7 @@ class admin_setting_confightmleditor extends admin_setting_configtext { $defaultinfo = "\n".$default; } - $editor = get_preferred_texteditor(FORMAT_HTML); + $editor = editors_get_preferred_editor(FORMAT_HTML); $editor->use_editor($this->get_id(), array('noclean'=>true)); return format_admin_setting($this, $this->visiblename, @@ -4929,7 +4929,7 @@ class admin_setting_manageeditors extends admin_setting { } $textlib = textlib_get_instance(); - $editors_available = get_available_editors(); + $editors_available = editors_get_available(); foreach ($editors_available as $editor=>$editorstr) { if (strpos($editor, $query) !== false) { return true; @@ -4956,7 +4956,7 @@ class admin_setting_manageeditors extends admin_setting { 'up', 'down', 'none')); $txt->updown = "$txt->up/$txt->down"; - $editors_available = get_available_editors(); + $editors_available = editors_get_available(); $active_editors = explode(',', $CFG->texteditors); $active_editors = array_reverse($active_editors); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 28b829d2013..7596e9b03f1 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4718,6 +4718,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); unset_config('editorkillword'); unset_config('editorhidebuttons'); unset_config('editorfontlist'); + unset_config('htmleditor'); upgrade_main_savepoint(true, 2010071000); } diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9db5c732216..228ad187471 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2761,7 +2761,7 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v if ($usehtmleditor) { editors_head_setup(); - $editor = get_preferred_texteditor(FORMAT_HTML); + $editor = editors_get_preferred_editor(FORMAT_HTML); $editor->use_editor($id, array('legacy'=>true)); } else { $editorclass = ''; diff --git a/lib/editorlib.php b/lib/editorlib.php index e0942dd62da..cbcc06e7048 100644 --- a/lib/editorlib.php +++ b/lib/editorlib.php @@ -18,7 +18,7 @@ /** * Utility classes and functions for text editor integration. * - * @package moodlecore + * @package core * @subpackage editor * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -27,40 +27,42 @@ /** * Returns users preferred editor for given format * - * @todo implement user preferences for text editors - * - * @global object - * @global object * @param int $format text format or null of none * @return texteditor object */ -function get_preferred_texteditor($format=null) { - global $CFG, $USER; +function editors_get_preferred_editor($format = NULL) { + global $USER; - if (empty($CFG->texteditors)) { - $CFG->texteditors = 'tinymce,textarea'; - } - $active = explode(',', $CFG->texteditors); + $enabled = editors_get_enabled(); - // TODO: implement user preferences for text editors + $preventhtml = (count($enabled) > 1 and empty($USER->htmleditor)); // now find some plugin that supports format and is available $editor = false; - foreach ($active as $editorname) { - if (!$e = get_texteditor($editorname)) { - continue; - } + foreach ($enabled as $e) { if (!$e->supported_by_browser()) { // bad luck, this editor is not compatible continue; } + if ($preventhtml and $format == FORMAT_HTML and $e->get_preferred_format() == FORMAT_HTML) { + // this is really not what we want but we could use it if nothing better found + $editor = $e; + continue; + } if (!$supports = $e->get_supported_formats()) { + // buggy editor! continue; } if (is_null($format)) { // format does not matter - $editor = $e; - break; + if ($preventhtml and $e->get_preferred_format() == FORMAT_HTML) { + // this is really not what we want but we could use it if nothing better found + $editor = $e; + continue; + } else { + $editor = $e; + break; + } } if (in_array($format, $supports)) { // editor supports this format, yay! @@ -76,10 +78,59 @@ function get_preferred_texteditor($format=null) { return $editor; } +/** + * Returns users preferred text format. + * @return int standard text format + */ +function editors_get_preferred_format() { + global $USER; + + $editors = editors_get_enabled(); + if (count($editors) == 1) { + $editor = reset($editors); + return $editor->get_preferred_format(); + } + + foreach ($editors as $editor) { + if (empty($USER->htmleditor) and $editor->get_preferred_format() == FORMAT_HTML) { + // we do not prefer this one + continue; + } + return $editor->get_preferred_format(); + } + + // user did not want html editor, but there is no other choice, sorry + $editor = reset($editors); + return $editor->get_preferred_format(); +} + +/** + * Returns list of enabled text editors + * @return array of name=>texteditor + */ +function editors_get_enabled() { + global $CFG; + + if (empty($CFG->texteditors)) { + $CFG->texteditors = 'tinymce,textarea'; + } + $active = array(); + foreach(explode(',', $CFG->texteditors) as $e) { + if ($editor = get_texteditor($e)) { + $active[$e] = $editor; + } + } + + if (empty($active)) { + return array('textarea'=>get_texteditor('textarea')); // must exist and can edit anything + } + + return $active; +} + /** * Returns instance of text editor * - * @global object * @param string $editorname name of editor (textarea, tinymce, ...) * @return object|bool texeditor instance or false if does not exist */ @@ -103,7 +154,7 @@ function get_texteditor($editorname) { * * @return array Array ('editorname'=>'localised editor name') */ -function get_available_editors() { +function editors_get_available() { $editors = array(); foreach (get_plugin_list('editor') as $editorname => $dir) { $editors[$editorname] = get_string('pluginname', 'editor_'.$editorname); @@ -184,16 +235,28 @@ abstract class texteditor { } } -//=== DEPRECATED ===================== +//=== TO BE DEPRECATED in 2.1 ===================== + /** - * can_use_html_editor is deprecated... - * @deprecated - * @todo Deprecated: eradicate completely, replace with something else + * Does the user want and can edit using rich text html editor? + * @todo Deprecate: eradicate completely, replace with something else in the future * @return bool */ function can_use_html_editor() { - //TODO: eradicate completely, replace with something else + global $USER; - $tinymyce = get_texteditor('tinymce'); - return $tinymyce->supported_by_browser(); + $editors = editors_get_enabled(); + if (count($editors) > 1) { + if (empty($USER->htmleditor)) { + return false; + } + } + + foreach ($editors as $editor) { + if ($editor->get_preferred_format() == FORMAT_HTML) { + return true; + } + } + + return false; } diff --git a/lib/filelib.php b/lib/filelib.php index 667553b5099..522b5ecee75 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -201,7 +201,7 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu $data->{$field} = ''; } if (!isset($data->{$field.'format'})) { - $data->{$field.'format'} = FORMAT_HTML; // TODO: use better default based on user preferences and browser capabilities + $data->{$field.'format'} = editors_get_preferred_format(); } if (!$options['noclean']) { $data->{$field} = clean_text($data->{$field}, $data->{$field.'format'}); diff --git a/lib/form/editor.php b/lib/form/editor.php index 16e58a20eaf..2dbe20e4ca9 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -143,7 +143,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { $str = $this->_getTabs(); $str .= '