}
$editor = get_preferred_texteditor(FORMAT_HTML);
- $editorclass = $editor->get_legacy_textarea_class();
- $editor->use_editor($this->get_id());
+ $editor->use_editor($this->get_id(), array('noclean'=>true));
return format_admin_setting($this, $this->visiblename,
- '<div class="form-textarea"><textarea class="'.$editorclass.'" rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
+ '<div class="form-textarea"><textarea rows="'. $this->rows .'" cols="'. $this->cols .'" id="'. $this->get_id() .'" name="'. $this->get_full_name() .'">'. s($data) .'</textarea></div>',
$this->description, true, '', $defaultinfo, $query);
}
}
return true;
}
- public function get_editor_element_class() {
- return 'form-textarea-simple';
- }
-
- public function get_legacy_textarea_class() {
- return 'form-textarea-legacy';
- }
-
- public function use_editor($elementid=null) {
+ public function use_editor($elementid, array $options=null) {
return;
- }
+ }
}
+++ /dev/null
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * On-the-fly conversion of Moodle lang strings to TinyMCE expected JS format.
- *
- * @package moodlecore
- * @subpackage editor
- * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-define('NO_MOODLE_COOKIES', true);
-define('NO_UPGRADE_CHECK', true);
-
-require_once('../../../../config.php');
-
-$lang = optional_param('elanguage', 'en_utf8', PARAM_SAFEDIR);
-$theme = optional_param('etheme', 'standard', PARAM_SAFEDIR);
-$usehttps = optional_param('eusehttps', 0, PARAM_BOOL);
-
-if (file_exists("$CFG->dataroot/lang/$lang") or file_exists("$CFG->dirroot/lang/$lang")) {
- $SESSION->lang = $lang;
-} else if (file_exists("$CFG->dataroot/lang/{$lang}_utf8") or file_exists("$CFG->dirroot/lang/{$lang}_utf8")) {
- $SESSION->lang = $lang.'_utf8';
-}
-
-$xmlruleset = file_get_contents('xhtml_ruleset.txt');
-
-$directionality = get_string('thisdirection');
-
-$strtime = get_string('strftimetime');
-$strdate = get_string('strftimedaydate');
-
-$lang = str_replace('_utf8', '', $lang); // use more standard language codes
-
-if ($usehttps) {
- $wwwbase = str_replace('http:', 'https:', $CFG->wwwroot);
-} else {
- $wwwbase = $CFG->wwwroot;
-}
-
-// $contentcss should be customizable
-$contentcss = "$CFG->themewww/$theme/styles.php";
-
-//TODO: reimplement spellchecker support - the TinyMCE one is hardcoded for linux, has encoding problems, etc.
-
-$output = <<<EOF
-function mc_init_editors() {
- tinyMCE.init({
- mode: "textareas",
- relative_urls: false,
- editor_selector: "form-tinymce-legacy",
- document_base_url: "$wwwbase",
- content_css: "$contentcss",
- language: "$lang",
- directionality: "$directionality",
- plugin_insertdate_dateFormat : "$strdate",
- plugin_insertdate_timeFormat : "$strtime",
- theme: "advanced",
- skin: "o2k7",
- skin_variant: "silver",
- apply_source_formatting: true,
- remove_script_host: false,
- entity_encoding: "raw",
- plugins: "safari,table,style,layer,advhr,advimage,advlink,emotions,inlinepopups,media,searchreplace,paste,directionality,fullscreen,moodlenolink,dragmath,nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak",
- theme_advanced_font_sizes: "1,2,3,4,5,6,7",
- theme_advanced_layout_manager: "SimpleLayout",
- theme_advanced_toolbar_align : "left",
- theme_advanced_buttons1: "fontselect,fontsizeselect,formatselect,styleselect",
- theme_advanced_buttons1_add: "|,undo,redo,|,search,replace,|,fullscreen",
- theme_advanced_buttons2: "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
- theme_advanced_buttons2_add: "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
- theme_advanced_buttons3: "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emotions,image,dragmath,advhr,nonbreaking,charmap",
- theme_advanced_buttons3_add: "|,table,insertlayer,styleprops,visualchars,|,code,preview",
- theme_advanced_fonts: "Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings",
- theme_advanced_resize_horizontal: true,
- theme_advanced_resizing: true,
- theme_advanced_toolbar_location : "top",
- theme_advanced_statusbar_location : "bottom",
- $xmlruleset
- });
-
- tinyMCE.init({
- mode: "textareas",
- relative_urls: false,
- editor_selector: "form-tinymce-advanced",
- document_base_url: "$wwwbase",
- content_css: "$contentcss",
- language: "$lang",
- directionality: "$directionality",
- plugin_insertdate_dateFormat : "$strdate",
- plugin_insertdate_timeFormat : "$strtime",
- theme: "advanced",
- skin: "o2k7",
- skin_variant: "silver",
- apply_source_formatting: true,
- remove_script_host: false,
- entity_encoding: "raw",
- plugins: "safari,table,style,layer,advhr,advimage,advlink,emotions,inlinepopups,media,searchreplace,paste,directionality,fullscreen,moodlenolink,dragmath,nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak",
- theme_advanced_font_sizes: "1,2,3,4,5,6,7",
- theme_advanced_layout_manager: "SimpleLayout",
- theme_advanced_toolbar_align : "left",
- theme_advanced_buttons1: "fontselect,fontsizeselect,formatselect,styleselect",
- theme_advanced_buttons1_add: "|,undo,redo,|,search,replace,|,fullscreen",
- theme_advanced_buttons2: "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
- theme_advanced_buttons2_add: "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
- theme_advanced_buttons3: "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emotions,image,media,dragmath,advhr,nonbreaking,charmap",
- theme_advanced_buttons3_add: "|,table,insertlayer,styleprops,visualchars,|,code,preview",
- theme_advanced_fonts: "Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings",
- theme_advanced_resize_horizontal: true,
- theme_advanced_resizing: true,
- theme_advanced_toolbar_location : "top",
- theme_advanced_statusbar_location : "bottom",
- file_browser_callback : "mce_moodlefilemanager",
- $xmlruleset
- });
-}
-
-function mce_toggleEditor(id) {
- tinyMCE.execCommand('mceToggleEditor',false,id);
-}
-
-function mce_saveOnSubmit(id) {
- var prevOnSubmit = document.getElementById(id).form.onsubmit;
- document.getElementById(id).form.onsubmit = function() {
- tinyMCE.triggerSave();
- var ret = true;
- if (prevOnSubmit != undefined) {
- if (prevOnSubmit()) {
- ret = true;
- prevOnSubmit = null;
- } else {
- ret = false;
- }
- }
- return ret;
- };
-}
-
-function mce_moodlefilemanager(field_name, url, type, win) {
- var client_id = id2clientid[tinyMCE.selectedInstance.editorId];
- var picker = document.createElement('DIV');
- picker.className = "file-picker";
- picker.id = 'file-picker-'+client_id;
- document.body.appendChild(picker);
- var el = win.document.getElementById(field_name);
- eval('open_filepicker(client_id, {"env":"editor","target":el,"filetype":type})');
-}
-
-// finally init editors
-mc_init_editors();
-
-EOF;
-
-
-$lifetime = '10'; // TODO: increase later
-header('Content-type: text/javascript; charset=utf-8');
-header('Content-length: '.strlen($output));
-header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
-header('Cache-control: max-age='.$lifetime);
-header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
-header('Pragma: ');
-
-echo $output;
--- /dev/null
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * TinyMCE helper javascript functions
+ *
+ * @package moodlecore
+ * @subpackage editor
+ * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+function mce_init_editor(elementid, params) {
+ tinyMCE.init(params);
+}
+
+function mce_toggleEditor(id) {
+ tinyMCE.execCommand('mceToggleEditor',false,id);
+}
+
+function mce_saveOnSubmit(id) {
+ var prevOnSubmit = document.getElementById(id).form.onsubmit;
+ document.getElementById(id).form.onsubmit = function() {
+ tinyMCE.triggerSave();
+ var ret = true;
+ if (prevOnSubmit != undefined) {
+ if (prevOnSubmit()) {
+ ret = true;
+ prevOnSubmit = null;
+ } else {
+ ret = false;
+ }
+ }
+ return ret;
+ };
+}
+
+function mce_moodlefilemanager(field_name, url, type, win) {
+ var client_id = id2clientid[tinyMCE.selectedInstance.editorId];
+ var picker = document.createElement('DIV');
+ picker.className = "file-picker";
+ picker.id = 'file-picker-'+client_id;
+ document.body.appendChild(picker);
+ var el = win.document.getElementById(field_name);
+ eval('open_filepicker(client_id, {"env":"editor","target":el,"filetype":type})');
+}
} else if (check_browser_version('Opera', 9)) {
return true;
}
-
+
return true;
}
return true;
}
- public function get_editor_element_class() {
- return 'form-tinymce-advanced';
- }
-
- public function get_legacy_textarea_class() {
- return 'form-tinymce-legacy';
+ public function use_editor($elementid, array $options=null) {
+ global $CFG, $PAGE;
+
+ $PAGE->requires->js('/lib/editor/tinymce/tiny_mce_src.js');
+ $PAGE->requires->js('/lib/editor/tinymce/extra/tinymce_utils.js');
+ $PAGE->requires->js_function_call('mce_init_editor', array($elementid, $this->get_init_params($elementid, $options)));
}
- public function use_editor($elementid=null) {
+ protected function get_init_params($elementid, array $options=null) {
global $CFG, $PAGE;
- $usehttps = (int)($CFG->httpswwwroot !== $CFG->wwwroot); //hmm, is there a better test?
- //TODO: requirements manager does not support parameters :-(
+ //TODO: we need to implement user preferences that affec tthe editor setup too
+
+ //TODO: reimplement rulesets, maybe it would be better to implement it some other way
+ //$xmlruleset = file_get_contents('extra/xhtml_ruleset.txt');
+
+ $directionality = get_string('thisdirection');
+ $strtime = get_string('strftimetime');
+ $strdate = get_string('strftimedaydate');
+ $lang = str_replace('_utf8', '', current_language()); // use more standard language codes
+ $contentcss = $CFG->themewww.'/'.current_theme().'/styles.php'; // should be customizable
+
+ $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context'];
+ if (!empty($options['legacy'])) {
+ $xmedia = '';
+ } else {
+ if (!empty($options['noclean']) or !empty($options['trusted'])) {
+ $xmedia = 'media,';
+ } else {
+ $xmedia = '';
+ }
+ }
+
+ $filters = filter_get_active_in_context($context);
+ if (array_key_exists('filter/tex', $filters)) {
+ $xdragmath = 'dragmath,';
+ } else {
+ $xdragmath = '';
+ }
+
+ $params = array(
+ 'mode' => "exact",
+ 'elements' => $elementid,
+ 'relative_urls' => false,
+ 'document_base_url' => $CFG->httpswwwroot,
+ 'content_css' => $contentcss,
+ 'language' => $lang,
+ 'directionality' => $directionality,
+ 'plugin_insertdate_dateFormat ' => $strdate,
+ 'plugin_insertdate_timeFormat ' => $strtime,
+ 'theme' => "advanced",
+ 'skin' => "o2k7",
+ 'skin_variant' => "silver",
+ 'apply_source_formatting' => true,
+ 'remove_script_host' => false,
+ 'entity_encoding' => "raw",
+ 'plugins' => "safari,table,style,layer,advhr,advimage,advlink,emotions,inlinepopups,{$xmedia}searchreplace,paste,directionality,fullscreen,moodlenolink,{$xdragmath}nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak",
+ 'theme_advanced_font_sizes' => "1,2,3,4,5,6,7",
+ 'theme_advanced_layout_manager' => "SimpleLayout",
+ 'theme_advanced_toolbar_align' => "left",
+ 'theme_advanced_buttons1' => "fontselect,fontsizeselect,formatselect,styleselect",
+ 'theme_advanced_buttons1_add' => "|,undo,redo,|,search,replace,|,fullscreen",
+ 'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
+ 'theme_advanced_buttons2_add' => "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
+ 'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emotions,image,{$xmedia}{$xdragmath}advhr,nonbreaking,charmap",
+ 'theme_advanced_buttons3_add' => "|,table,insertlayer,styleprops,visualchars,|,code,preview",
+ 'theme_advanced_fonts' => "Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings",
+ 'theme_advanced_resize_horizontal' => true,
+ 'theme_advanced_resizing' => true,
+ 'theme_advanced_toolbar_location' => "top",
+ 'theme_advanced_statusbar_location' => "bottom",
+ );
+
+ if (empty($options['legacy'])) {
+ if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
+ $params['file_browser_callback'] = "mce_moodlefilemanager";
+ }
+ }
- $PAGE->requires->js($CFG->httpswwwroot.'/lib/editor/tinymce/tiny_mce_src.js', true);
- $PAGE->requires->js($CFG->httpswwwroot.'/lib/editor/tinymce/extra/tinymce.js.php?elanguage='.current_language().'&etheme='.current_theme().'&eusehttps='.$usehttps, true);
+ return $params;
}
-
-}
\ No newline at end of file
+}
*/
public abstract function supports_repositories();
- /**
- * Returns textarea class in formslib editor element
- * @return string
- */
- public abstract function get_editor_element_class();
-
- /**
- * Returns textarea class for legacy text editor
- * @return string
- */
- public abstract function get_legacy_textarea_class();
-
/**
* Add required JS needed for editor
+ * @param string $elementid id of text area to be converted to editor
+ * @param array $options
* @return void
*/
- public abstract function use_editor($elementid=null);
+ public abstract function use_editor($elementid, array $options=null);
}
// * locking
// * freezing
// * ajax format conversion
-// * better area files handling
class MoodleQuickForm_editor extends HTML_QuickForm_element {
protected $_helpbutton = '';
- protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0, 'changeformat'=>0);
+ protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0, 'changeformat'=>0,
+ 'context'=>null, 'noclean'=>0, 'trusttext'=>0);
protected $_values = array('text'=>null, 'format'=>null, 'itemid'=>null);
function MoodleQuickForm_editor($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
+ if (!$this->_options['context']) {
+ $this->_options['context'] = get_context_instance(CONTEXT_SYSTEM);
+ }
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}
}
/// print text area - TODO: add on-the-fly switching, size configuration, etc.
- $editorclass = $editor->get_editor_element_class();
- $editor->use_editor($id);
+ $editor->use_editor($id, $this->_options);
+ $ctx = $this->_options['context'];
- $str .= '<div><textarea class="'.$editorclass.'" id="'.$id.'" name="'.$elname.'[text]" rows="15" cols="80">';
+ $str .= '<div><textarea id="'.$id.'" name="'.$elname.'[text]" rows="15" cols="80">';
$str .= s($text);
$str .= '</textarea></div>';
$draftitemid = $this->_values['itemid'];
}
$str .= '<div><input type="hidden" name="'.$elname.'[itemid]" value="'.$draftitemid.'" /></div>';
-
- if (empty($COURSE->context)) {
- $ctx = get_context_instance(CONTEXT_SYSTEM);
- } else {
- $ctx = $COURSE->context;
- }
/// embedded image files - TODO: hide on the fly when switching editors
$str .= '<div id="'.$id.'_filemanager">';
$editorurl = "$CFG->wwwroot/repository/filepicker.php?action=embedded&itemid=$draftitemid&subdirs=$subdirs&maxbytes=$maxbytes&ctx_id=".$ctx->id;
if ($usehtmleditor) {
$editor = get_preferred_texteditor(FORMAT_HTML);
- $editorclass = $editor->get_legacy_textarea_class();
- $editor->use_editor($id);
+ $editor->use_editor($id, array('legacy'=>true));
} else {
$editorclass = '';
}
- $str .= "\n".'<textarea class="form-textarea '.$editorclass.'" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
+ $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
if ($usehtmleditor) {
$str .= htmlspecialchars($value); // needed for editing of cleaned text!
} else {
/// Processing submitted data, i.e updating form.
$resettemplate = false;
-/// html editor is by default disabled
- $editor = isset($SESSION->data_use_editor) ? $SESSION->data_use_editor : (can_use_html_editor() ? 1 : 0);
-
if (($mytemplate = data_submitted()) && confirm_sesskey()) {
$newtemplate->id = $data->id;
$newtemplate->{$mode} = $mytemplate->template;
- if (!empty($mytemplate->switcheditor)) {
- $editor = $editor ? 0 : 1;
- $SESSION->data_use_editor = $editor;
- } else if (!empty($mytemplate->defaultform)) {
+ if (!empty($mytemplate->defaultform)) {
// Reset the template to default, but don't save yet.
$resettemplate = true;
$data->{$mode} = data_generate_default_template($data, $mode, 0, false, false);