diff --git a/lib/editor/tinymce/adminlib.php b/lib/editor/tinymce/adminlib.php index 09fcadae85b..36eb494e803 100644 --- a/lib/editor/tinymce/adminlib.php +++ b/lib/editor/tinymce/adminlib.php @@ -246,3 +246,30 @@ class tiynce_subplugins_settings extends admin_setting { return highlight($query, $return); } } + +class editor_tinymce_json_setting_textarea extends admin_setting_configtextarea { + /** + * Returns an XHTML string for the editor + * + * @param string $data + * @param string $query + * @return string XHTML string for the editor + */ + public function output_html($data, $query='') { + $result = parent::output_html($data, $query); + + $data = trim($data); + if ($data) { + $decoded = json_decode($data, true); + // Note: it is not very nice to abuse these file classes, but anyway... + if (is_array($decoded)) { + $valid = ''; + } else { + $valid = ''; + } + $result = str_replace('', ''.$valid, $result); + } + + return $result; + } +} diff --git a/lib/editor/tinymce/lang/en/editor_tinymce.php b/lib/editor/tinymce/lang/en/editor_tinymce.php index b3c4ee8db36..01448775d17 100644 --- a/lib/editor/tinymce/lang/en/editor_tinymce.php +++ b/lib/editor/tinymce/lang/en/editor_tinymce.php @@ -27,6 +27,8 @@ //== Custom Moodle strings that are not part of upstream TinyMCE == $string['availablebuttons'] = 'Available buttons'; +$string['customconfig'] = 'Custom configuration'; +$string['customconfig_desc'] = 'Custom advanced TinyMCE configuration in JSON format, for example: {"option1" : "value2", "option2" : "value2"}. Any options specified here override standard and plugin settings.'; $string['customtoolbar'] = 'Editor toolbar'; $string['customtoolbar_desc'] = 'Each line contains a list of comma separated button names, use "|" as a group separator, empty lines are ignored. See {$a} for the list of default TinyMCE buttons.'; $string['fontselectlist'] = 'Available fonts list'; diff --git a/lib/editor/tinymce/lib.php b/lib/editor/tinymce/lib.php index 176ff7e7334..6a3c36a8c87 100644 --- a/lib/editor/tinymce/lib.php +++ b/lib/editor/tinymce/lib.php @@ -184,6 +184,16 @@ class tinymce_texteditor extends texteditor { $params['theme_advanced_buttons1'] = ''; } + if (!empty($config->customconfig)) { + $config->customconfig = trim($config->customconfig); + $decoded = json_decode($config->customconfig, true); + if (is_array($decoded)) { + foreach ($decoded as $k=>$v) { + $params[$k] = $v; + } + } + } + if (!empty($options['legacy']) or !empty($options['noclean']) or !empty($options['trusted'])) { // now deal somehow with non-standard tags, people scream when we do not make moodle code xtml strict, // but they scream even more when we strip all tags that are not strict :-( diff --git a/lib/editor/tinymce/settings.php b/lib/editor/tinymce/settings.php index 5b16a610de8..1e8d3f4a004 100644 --- a/lib/editor/tinymce/settings.php +++ b/lib/editor/tinymce/settings.php @@ -40,7 +40,9 @@ bullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,| get_string('customtoolbar', 'editor_tinymce'), get_string('customtoolbar_desc', 'editor_tinymce', 'http://www.tinymce.com/wiki.php/Buttons/controls'), $default, PARAM_RAW, 100, 8)); $settings->add(new admin_setting_configtextarea('editor_tinymce/fontselectlist', get_string('fontselectlist', 'editor_tinymce'), '', - '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', PARAM_RAW)); + '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', PARAM_RAW, 100, 8)); + $settings->add(new editor_tinymce_json_setting_textarea('editor_tinymce/customconfig', + get_string('customconfig', 'editor_tinymce'), get_string('customconfig_desc', 'editor_tinymce'), '', PARAM_RAW, 100, 8)); } $ADMIN->add('editortinymce', $settings); unset($settings);