Skip to content

Commit

Permalink
MDL-37186 add the ultimate TinyMCE custom parameter setting
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 20, 2012
1 parent 322af44 commit 544f0f9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/editor/tinymce/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,30 @@ public function output_html($data, $query='') {
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 = '<span class="pathok">&#x2714;</span>';
} else {
$valid = '<span class="patherror">&#x2718;</span>';
}
$result = str_replace('</textarea>', '</textarea>'.$valid, $result);
}

return $result;
}
}
2 changes: 2 additions & 0 deletions lib/editor/tinymce/lang/en/editor_tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 href="{$a}" target="_blank">{$a}</a> for the list of default TinyMCE buttons.';
$string['fontselectlist'] = 'Available fonts list';
Expand Down
10 changes: 10 additions & 0 deletions lib/editor/tinymce/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ protected function get_init_params($elementid, array $options=null) {
$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 :-(
Expand Down
4 changes: 3 additions & 1 deletion lib/editor/tinymce/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
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);
Expand Down

0 comments on commit 544f0f9

Please sign in to comment.