MDL-19211 spellchecker TODOs
[moodle.git] / lib / editor / tinymce / extra / tinymce.js.php
1 <?php
3 ///////////////////////////////////////////////////////////////////////////
4 //                                                                       //
5 // NOTICE OF COPYRIGHT                                                   //
6 //                                                                       //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
8 //          http://moodle.org                                            //
9 //                                                                       //
10 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
11 //                                                                       //
12 // This program is free software; you can redistribute it and/or modify  //
13 // it under the terms of the GNU General Public License as published by  //
14 // the Free Software Foundation; either version 2 of the License, or     //
15 // (at your option) any later version.                                   //
16 //                                                                       //
17 // This program is distributed in the hope that it will be useful,       //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
20 // GNU General Public License for more details:                          //
21 //                                                                       //
22 //          http://www.gnu.org/copyleft/gpl.html                         //
23 //                                                                       //
24 ///////////////////////////////////////////////////////////////////////////
26 define('NO_MOODLE_COOKIES', true);
27 define('NO_UPGRADE_CHECK', true);
29 require_once('../../../../config.php');
31 $lang     = optional_param('elanguage', 'en_utf8', PARAM_SAFEDIR);
32 $theme    = optional_param('etheme', 'standard', PARAM_SAFEDIR);
33 $usehttps = optional_param('eusehttps', 0, PARAM_BOOL);
35 if (file_exists("$CFG->dataroot/lang/$lang") or file_exists("$CFG->dirroot/lang/$lang")) {
36     $SESSION->lang = $lang;
37 } else if (file_exists("$CFG->dataroot/lang/{$lang}_utf8") or file_exists("$CFG->dirroot/lang/{$lang}_utf8")) {
38     $SESSION->lang = $lang.'_utf8';
39 }
41 $xmlruleset = file_get_contents('xhtml_ruleset.txt');
43 $directionality = get_string('thisdirection');
45 $strtime = get_string('strftimetime');
46 $strdate = get_string('strftimedaydate');
48 $lang = str_replace('_utf8', '', $lang); // use more standard language codes
50 if ($usehttps) {
51     $wwwbase = str_replace('http:', 'https:', $CFG->wwwroot);
52 } else {
53     $wwwbase = $CFG->wwwroot;
54 }
56 // $contentcss should be customizable
57 $contentcss = "$CFG->themewww/$theme/styles.php";
59 //TODO: reimplement spellchecker support - the TinyMCE one is hardcoded for linux, has encoding problems, etc.
61 $output = <<<EOF
62 function mc_init_editors() {
63     tinyMCE.init({
64         mode: "textareas",
65         relative_urls: false,
66         editor_selector: "form-tinymce-legacy",
67         document_base_url: "$wwwbase",
68         content_css: "$contentcss",
69         language: "$lang",
70         directionality: "$directionality",
71         plugin_insertdate_dateFormat : "$strdate",
72         plugin_insertdate_timeFormat : "$strtime",
73         theme: "advanced",
74         skin: "o2k7",
75         skin_variant: "silver",
76         apply_source_formatting: true,
77         remove_script_host: false,
78         entity_encoding: "raw",
79         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",
80         theme_advanced_font_sizes: "1,2,3,4,5,6,7",
81         theme_advanced_layout_manager: "SimpleLayout",
82         theme_advanced_toolbar_align : "left",
83         theme_advanced_buttons1: "fontselect,fontsizeselect,formatselect,styleselect",
84         theme_advanced_buttons1_add: "|,undo,redo,|,search,replace,|,fullscreen",
85         theme_advanced_buttons2: "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
86         theme_advanced_buttons2_add: "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
87         theme_advanced_buttons3: "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emotions,image,advhr,nonbreaking,charmap",
88         theme_advanced_buttons3_add: "|,table,insertlayer,styleprops,visualchars,|,code,preview",
89         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",
90         theme_advanced_resize_horizontal: true,
91         theme_advanced_resizing: true,
92         theme_advanced_toolbar_location : "top",
93         theme_advanced_statusbar_location : "bottom",
94         $xmlruleset
95     });
97     tinyMCE.init({
98         mode: "textareas",
99         relative_urls: false,
100         editor_selector: "form-tinymce-advanced",
101         document_base_url: "$wwwbase",
102         content_css: "$contentcss",
103         language: "$lang",
104         directionality: "$directionality",
105         plugin_insertdate_dateFormat : "$strdate",
106         plugin_insertdate_timeFormat : "$strtime",
107         theme: "advanced",
108         skin: "o2k7",
109         skin_variant: "silver",
110         apply_source_formatting: true,
111         remove_script_host: false,
112         entity_encoding: "raw",
113         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",
114         theme_advanced_font_sizes: "1,2,3,4,5,6,7",
115         theme_advanced_layout_manager: "SimpleLayout",
116         theme_advanced_toolbar_align : "left",
117         theme_advanced_buttons1: "fontselect,fontsizeselect,formatselect,styleselect",
118         theme_advanced_buttons1_add: "|,undo,redo,|,search,replace,|,fullscreen",
119         theme_advanced_buttons2: "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,cite,abbr,acronym",
120         theme_advanced_buttons2_add: "|,selectall,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
121         theme_advanced_buttons3: "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,anchor,|,insertdate,inserttime,|,emotions,image,media,dragmath,advhr,nonbreaking,charmap",
122         theme_advanced_buttons3_add: "|,table,insertlayer,styleprops,visualchars,|,code,preview",
123         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",
124         theme_advanced_resize_horizontal: true,
125         theme_advanced_resizing: true,
126         theme_advanced_toolbar_location : "top",
127         theme_advanced_statusbar_location : "bottom",
128         file_browser_callback : "mce_moodlefilemanager",
129         $xmlruleset
130     });
133 function mce_toggleEditor(id) {
134     tinyMCE.execCommand('mceToggleEditor',false,id);
137 function mce_saveOnSubmit(id) {
138     var prevOnSubmit = document.getElementById(id).form.onsubmit;
139     document.getElementById(id).form.onsubmit = function() {
140         tinyMCE.triggerSave();
141         var ret = true;
142         if (prevOnSubmit != undefined) {
143           if (prevOnSubmit()) {
144             ret = true;
145             prevOnSubmit = null;
146           } else {
147             ret = false;
148           }
149         }
150         return ret;
151     };
154 function mce_moodlefilemanager(field_name, url, type, win) {
155     var client_id = id2clientid[tinyMCE.selectedInstance.editorId];
156     document.body.className += ' yui-skin-sam';
157     var picker = document.createElement('DIV');
158     picker.className = "file-picker";
159     picker.id = 'file-picker-'+client_id;
160     document.body.appendChild(picker);
161     var el = win.document.getElementById(field_name);
162     eval('open_filepicker(client_id, {"env":"editor","target":el,"filetype":type})');
165 // finally init editors
166 mc_init_editors();
168 EOF;
171 $lifetime = '10'; // TODO: increase later
172 header('Content-type: text/javascript; charset=utf-8');
173 header('Content-length: '.strlen($output));
174 header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
175 header('Cache-control: max-age='.$lifetime);
176 header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
177 header('Pragma: ');
179 echo $output;