MDL-13766
[moodle.git] / lib / editor / tinymce.js.php
CommitLineData
07f8feca 1<?php
2
dfc5838e 3define('NO_MOODLE_COOKIES', true);
4
07f8feca 5require_once('../../config.php');
6
66d68c08 7$editorlanguage = optional_param('editorlanguage', 'en_utf8', PARAM_ALPHANUMEXT);
8
9$SESSION->lang = $editorlanguage;
66d68c08 10$directionality = get_string('thisdirection');
d074c20e 11
07f8feca 12/*
07f8feca 13 * This section configures the TinyMCE toolbar buttons on and off
14 * depending on the Moodle settings
15 *
16 * The changes are applied on a global basis,
17 * ..... but there is scope here to modify and restrict the config
18 * on a role basis, course basis, user basis, etc. if so desired.
19 *
20 */
a4d220dc 21if (empty($CFG->tinymcehidebuttons)) {
22 $CFG->tinymcehidebuttons = '';
23}
24
07f8feca 25$editorhidebuttons = str_replace(' ', ',', $CFG->tinymcehidebuttons);
26
27$editorhidebuttons1 = $editorhidebuttons . ',visualaid,styleselect';
28
29$editorhidebuttons = 'theme_advanced_disable : "'.$editorhidebuttons1.'",';
30
31$editorhidebuttons = str_replace('fontsize', 'fontsizeselect', $editorhidebuttons);
32$editorhidebuttons = str_replace('subscript', 'sub', $editorhidebuttons);
33$editorhidebuttons = str_replace('superscript', 'sup', $editorhidebuttons);
34$editorhidebuttons = str_replace('insertorderedlist', 'numlist', $editorhidebuttons);
35$editorhidebuttons = str_replace('insertunorderedlist', 'bullist', $editorhidebuttons);
36$editorhidebuttons = str_replace('createanchor', 'anchor', $editorhidebuttons);
37$editorhidebuttons = str_replace('createlink', 'link', $editorhidebuttons);
38$editorhidebuttons = str_replace('htmlmode', 'code', $editorhidebuttons);
39$editorhidebuttons = str_replace('insertchar', 'charmap', $editorhidebuttons);
40$editorhidebuttons = str_replace('insertimage', 'image', $editorhidebuttons);
41$editorhidebuttons = str_replace('inserthorizontalrule', 'hr', $editorhidebuttons);
42$editorhidebuttons = str_replace('formatblock', 'formatselect', $editorhidebuttons);
43$editorhidebuttons = str_replace('clean', 'cleanup,removeformat', $editorhidebuttons);
44
45// insertsmile,
46
47$pieces = explode(",", $editorhidebuttons1);
48
49$spellcheck = '';
50if (! in_array("spellcheck", $pieces)) {
51 $spellcheck = 'spellchecker,';
52}
53$inserttable = '';
54if (! in_array("inserttable", $pieces)) {
55 $inserttable = 'tablecontrols,separator,';
56}
57$search_replace = '';
58if (! in_array("search_replace", $pieces)) {
59 $search_replace = 'search,replace,separator,';
60}
61$lefttoright = '';
62if (! in_array("lefttoright", $pieces)) {
63 $lefttoright = 'ltr,separator,';
64}
65$righttoleft = '';
66if (! in_array("righttoleft", $pieces)) {
67 $righttoleft = 'rtl,separator,';
68}
69$cleanup = '';
70if (! in_array("cleanup", $pieces)) {
71 $cleanup = 'cleanup,removeformat,separator,';
72}
73$fontselect = '';
74if (! in_array("fontname", $pieces)) {
75 $fontselect = 'fontselect,';
76}
77$fontsize = '';
78if (! in_array("fontsize", $pieces)) {
79 $fontsize = 'fontsizeselect,';
80}
81$forecolor = '';
82if (! in_array("forecolor", $pieces)) {
83 $forecolor = 'forecolor,';
84}
85$hilitecolor = '';
86if (! in_array("hilitecolor", $pieces)) {
87 $hilitecolor = 'backcolor,';
88}
89$popupeditor = '';
90if (! in_array("popupeditor", $pieces)) {
91 $popupeditor = 'fullscreen,';
92}
93
94$editoraddbuttons3 = 'theme_advanced_buttons3_add : "'.$fontselect.$fontsize.$forecolor.$hilitecolor.'",';
95$editoraddbuttons4 = 'theme_advanced_buttons4 : "'.$spellcheck.$search_replace.$inserttable.$lefttoright.$righttoleft.$popupeditor.$cleanup.'",';
96
97/*
98 *
99 * ********************************************************************************************************
100 *
101 */
102
103
104$temp = $_SERVER["REQUEST_URI"];
105$temp = explode('/', $temp);
106$root = $temp[1];
107
108$configuration = <<<EOF
66d68c08 109tinyMCE.init({
110 mode : "exact",
111 elements : id,
112 theme : "advanced",
07f8feca 113
66d68c08 114 plugins : "safari,spellchecker,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,pagebreak,",
115 spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv",
07f8feca 116
66d68c08 117 plugin_insertdate_dateFormat : "%Y-%m-%d",
118 plugin_insertdate_timeFormat : "%H:%M:%S",
07f8feca 119
66d68c08 120 content_css : "/$root/lib/editor/tinymce/examples/css/content.css",
07f8feca 121
66d68c08 122 theme_advanced_toolbar_location : "top",
123 theme_advanced_toolbar_align : "top",
124 theme_advanced_statusbar_location : "bottom",
07f8feca 125
66d68c08 126 theme_advanced_resize_horizontal : true,
127 theme_advanced_resizing : true,
128 apply_source_formatting : true,
07f8feca 129
66d68c08 130 $editorhidebuttons
131 $editoraddbuttons3
132 $editoraddbuttons4
07f8feca 133
66d68c08 134});
07f8feca 135EOF;
136
66d68c08 137$strtime = get_string('strftimetime');
138$strdate = get_string('strftimedaydate');
a4d220dc 139
86a246e9 140// $contentcss should be customizable, but default to this.
141$contentcss = $CFG->themewww .'/'. current_theme() .'/styles.php';
142
e57fc041 143$output = <<<EOF
07f8feca 144 tinyMCE.init({
4644313b 145 mode: "textareas",
07f8feca 146 relative_urls: false,
147 editor_selector: "form-textarea-simple",
148 document_base_url: "$CFG->httpswwwroot",
86a246e9 149 content_css: "$contentcss",
07f8feca 150 theme: "simple",
151 skin: "o2k7",
d602f3b5 152 skin_variant: "silver",
07f8feca 153 apply_source_formatting: true,
154 remove_script_host: false,
155 entity_encoding: "raw",
a4d220dc 156 language: "$editorlanguage",
157 directionality: "$directionality",
f4da8f15 158 plugins: "spellchecker,emoticons,paste,standardmenu,directionality,contextmenu"
07f8feca 159 });
160 tinyMCE.init({
4644313b 161 mode: "textareas",
07f8feca 162 relative_urls: false,
163 editor_selector: "form-textarea-advanced",
164 document_base_url: "$CFG->httpswwwroot",
86a246e9 165 content_css: "$contentcss",
07f8feca 166 theme: "advanced",
167 skin: "o2k7",
d602f3b5 168 skin_variant: "silver",
07f8feca 169 apply_source_formatting: true,
170 remove_script_host: false,
171 entity_encoding: "raw",
a4d220dc 172 language: "$editorlanguage",
173 directionality: "$directionality",
86a246e9 174 plugins: "safari,spellchecker,table,style,layer,advhr,advimage,advlink,emoticons,inlinepopups,media,searchreplace,paste,standardmenu,directionality,fullscreen,moodlenolink,dragmath,nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak",
66d68c08 175 plugin_insertdate_dateFormat : "$strdate",
176 plugin_insertdate_timeFormat : "$strtime",
7d380f79 177 theme_advanced_font_sizes: "1,2,3,4,5,6,7",
07f8feca 178 theme_advanced_layout_manager: "SimpleLayout",
179 theme_advanced_toolbar_align : "left",
09f295fd 180 theme_advanced_buttons1: "fontselect,fontsizeselect,formatselect,styleselect",
66d68c08 181 theme_advanced_buttons1_add: "|,undo,redo,|,search,replace,spellchecker,|,fullscreen",
182 theme_advanced_buttons2: "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
09f295fd 183 theme_advanced_buttons2_add: "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
86a246e9 184 theme_advanced_buttons3: "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emoticons,image,media,dragmath,advhr,nonbreaking,charmap",
66d68c08 185 theme_advanced_buttons3_add: "|,table,insertlayer,styleprops,visualchars,|,code,preview",
07f8feca 186 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",
07f8feca 187 theme_advanced_resize_horizontal: true,
188 theme_advanced_resizing: true,
189 theme_advanced_toolbar_location : "top",
190 theme_advanced_statusbar_location : "bottom",
4b844d63 191 file_browser_callback : "moodlefilemanager",
07f8feca 192
193EOF;
194// the xhtml ruleset must be the last one - no comma at the end of the file
e57fc041 195$output .= file_get_contents('tinymce/xhtml_ruleset.txt');
196$output .= <<<EOF
07f8feca 197 });
4644313b 198
d5ef3136 199 function mce_toggleEditor(id) {
4644313b 200 tinyMCE.execCommand('mceToggleEditor',false,id);
07f8feca 201 }
4b844d63 202
d5ef3136 203 function mce_saveOnSubmit(id) {
204 var prevOnSubmit = document.getElementById(id).form.onsubmit;
205 document.getElementById(id).form.onsubmit = function() {
206 tinyMCE.triggerSave();
7d380f79 207 var ret = true;
f729b199 208 if (prevOnSubmit != undefined) {
209 if (prevOnSubmit()) {
210 ret = true;
211 prevOnSubmit = null;
212 } else {
213 ret = false;
214 }
7d380f79 215 }
216 return ret;
d5ef3136 217 };
218 }
765943ed 219 function moodlefilemanager(field_name, url, type, win) {
220 //alert(id2suffix[tinyMCE.selectedInstance.editorId]);
221 var suffix = id2suffix[tinyMCE.selectedInstance.editorId];
d373f63f 222 document.body.className += ' yui-skin-sam';
223 var picker = document.createElement('DIV');
911e0eb0 224 picker.className = "file-picker";
d373f63f 225 picker.id = 'file-picker-'+suffix;
226 document.body.appendChild(picker);
765943ed 227 var el = win.document.getElementById(field_name);
228 eval('openpicker_'+suffix+'({"env":"editor","target":el})');
229 }
07f8feca 230EOF;
e57fc041 231
232$lifetime = '86400';
233@header('Content-type: text/javascript; charset=utf-8');
234@header('Content-length: '.strlen($output));
235@header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
236@header('Cache-control: max-age='.$lifetime);
237@header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
238@header('Pragma: ');
239
240echo $output;
241
07f8feca 242?>