Commit | Line | Data |
---|---|---|
5ca3c838 | 1 | <?php |
2 | ||
8fd57583 | 3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * TinyMCE text editor integration. | |
20 | * | |
7ad5a627 PS |
21 | * @package editor |
22 | * @subpackage tinymce | |
8fd57583 | 23 | * @copyright 2009 Petr Skoda (http://skodak.org) |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
25 | */ | |
5ca3c838 | 26 | |
7ad5a627 PS |
27 | defined('MOODLE_INTERNAL') || die(); |
28 | ||
5ca3c838 | 29 | class tinymce_texteditor extends texteditor { |
34a30b5c | 30 | /** @var string active version - directory name */ |
ca7d5f8b | 31 | public $version = '3.4.2'; |
34a30b5c | 32 | |
5ca3c838 | 33 | public function supported_by_browser() { |
06671035 | 34 | if (check_browser_version('MSIE', 6)) { |
5ca3c838 | 35 | return true; |
06671035 PS |
36 | } |
37 | if (check_browser_version('Gecko', 20030516)) { | |
5ca3c838 | 38 | return true; |
06671035 PS |
39 | } |
40 | if (check_browser_version('Safari', 412)) { | |
5ca3c838 | 41 | return true; |
06671035 PS |
42 | } |
43 | if (check_browser_version('Chrome', 6)) { | |
44 | return true; | |
45 | } | |
46 | if (check_browser_version('Opera', 9)) { | |
5ca3c838 | 47 | return true; |
48 | } | |
69429650 | 49 | |
c55ff183 | 50 | return false; |
5ca3c838 | 51 | } |
52 | ||
53 | public function get_supported_formats() { | |
54 | return array(FORMAT_HTML => FORMAT_HTML); | |
55 | } | |
56 | ||
57 | public function get_preferred_format() { | |
58 | return FORMAT_HTML; | |
59 | } | |
60 | ||
61 | public function supports_repositories() { | |
62 | return true; | |
63 | } | |
64 | ||
ff5fe311 | 65 | public function head_setup() { |
ff5fe311 | 66 | } |
34a30b5c | 67 | |
4c508047 | 68 | public function use_editor($elementid, array $options=null, $fpoptions=null) { |
ff5fe311 | 69 | global $PAGE; |
a8c86418 TH |
70 | if (debugging('', DEBUG_DEVELOPER)) { |
71 | $PAGE->requires->js('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js'); | |
72 | } else { | |
73 | $PAGE->requires->js('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js'); | |
74 | } | |
4c508047 PS |
75 | $PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true); |
76 | if ($fpoptions) { | |
77 | $PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true); | |
78 | } | |
5ca3c838 | 79 | } |
80 | ||
69429650 | 81 | protected function get_init_params($elementid, array $options=null) { |
b9fadae7 | 82 | global $CFG, $PAGE, $OUTPUT; |
13a220cf | 83 | |
34a30b5c | 84 | //TODO: we need to implement user preferences that affect the editor setup too |
69429650 | 85 | |
e372f4c7 | 86 | $directionality = get_string('thisdirection', 'langconfig'); |
69429650 | 87 | $strtime = get_string('strftimetime'); |
88 | $strdate = get_string('strftimedaydate'); | |
3a915b06 | 89 | $lang = current_language(); |
b9bc2019 | 90 | $contentcss = $PAGE->theme->editor_css_url()->out(false); |
69429650 | 91 | |
92 | $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context']; | |
ca91bc95 PS |
93 | |
94 | $xmedia = 'moodlemedia,'; // HQ thinks it should be always on, so it is no matter if it will actually work or not | |
95 | /* | |
69429650 | 96 | if (!empty($options['legacy'])) { |
46713337 | 97 | $xmedia = 'moodlemedia,'; |
69429650 | 98 | } else { |
99 | if (!empty($options['noclean']) or !empty($options['trusted'])) { | |
69429650 | 100 | } |
ca91bc95 | 101 | }*/ |
69429650 | 102 | |
103 | $filters = filter_get_active_in_context($context); | |
104 | if (array_key_exists('filter/tex', $filters)) { | |
105 | $xdragmath = 'dragmath,'; | |
106 | } else { | |
107 | $xdragmath = ''; | |
108 | } | |
b9fadae7 DM |
109 | if (array_key_exists('filter/emoticon', $filters)) { |
110 | $xemoticon = 'moodleemoticon,'; | |
111 | } else { | |
112 | $xemoticon = ''; | |
113 | } | |
69429650 | 114 | |
115 | $params = array( | |
116 | 'mode' => "exact", | |
117 | 'elements' => $elementid, | |
118 | 'relative_urls' => false, | |
119 | 'document_base_url' => $CFG->httpswwwroot, | |
120 | 'content_css' => $contentcss, | |
121 | 'language' => $lang, | |
122 | 'directionality' => $directionality, | |
123 | 'plugin_insertdate_dateFormat ' => $strdate, | |
124 | 'plugin_insertdate_timeFormat ' => $strtime, | |
125 | 'theme' => "advanced", | |
126 | 'skin' => "o2k7", | |
127 | 'skin_variant' => "silver", | |
128 | 'apply_source_formatting' => true, | |
129 | 'remove_script_host' => false, | |
130 | 'entity_encoding' => "raw", | |
b9fadae7 | 131 | 'plugins' => "{$xmedia}advimage,safari,table,style,layer,advhr,advlink,emotions,inlinepopups,searchreplace,paste,directionality,fullscreen,moodlenolink,{$xemoticon}{$xdragmath}nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak,spellchecker", |
69429650 | 132 | 'theme_advanced_font_sizes' => "1,2,3,4,5,6,7", |
133 | 'theme_advanced_layout_manager' => "SimpleLayout", | |
134 | 'theme_advanced_toolbar_align' => "left", | |
69ee96d2 | 135 | 'theme_advanced_buttons1' => "fontselect,fontsizeselect,formatselect", |
69429650 | 136 | 'theme_advanced_buttons1_add' => "|,undo,redo,|,search,replace,|,fullscreen", |
69ee96d2 PS |
137 | 'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright", |
138 | 'theme_advanced_buttons2_add' => "|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl", | |
b9fadae7 | 139 | 'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,|,image,{$xemoticon}{$xmedia}{$xdragmath}nonbreaking,charmap", |
69ee96d2 | 140 | 'theme_advanced_buttons3_add' => "table,|,code,spellchecker", |
69429650 | 141 | '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", |
142 | 'theme_advanced_resize_horizontal' => true, | |
143 | 'theme_advanced_resizing' => true, | |
0f83538e | 144 | 'theme_advanced_resizing_min_height' => 30, |
69429650 | 145 | 'theme_advanced_toolbar_location' => "top", |
146 | 'theme_advanced_statusbar_location' => "bottom", | |
024a2179 | 147 | 'spellchecker_rpc_url' => $CFG->wwwroot."/lib/editor/tinymce/tiny_mce/$this->version/plugins/spellchecker/rpc.php" |
69429650 | 148 | ); |
b9fadae7 DM |
149 | |
150 | if ($xemoticon) { | |
151 | $manager = get_emoticon_manager(); | |
152 | $emoticons = $manager->get_emoticons(); | |
153 | $imgs = array(); | |
154 | // see the TinyMCE plugin moodleemoticon for how the emoticon index is (ab)used :-S | |
155 | $index = 0; | |
156 | foreach ($emoticons as $emoticon) { | |
157 | $imgs[$emoticon->text] = $OUTPUT->render( | |
158 | $manager->prepare_renderable_emoticon($emoticon, array('class' => 'emoticon emoticon-index-'.$index++))); | |
159 | } | |
160 | $params['moodleemoticon_emoticons'] = json_encode($imgs); | |
161 | } | |
162 | ||
38c8aed7 PS |
163 | if (empty($CFG->xmlstrictheaders) and (!empty($options['legacy']) or !empty($options['noclean']) or !empty($options['trusted']))) { |
164 | // now deal somehow with non-standard tags, people scream when we do not make moodle code xtml strict, | |
165 | // but they scream even more when we strip all tags that are not strict :-( | |
79abc6d1 | 166 | $params['valid_elements'] = 'script[src|type],*[*]'; // for some reason the *[*] does not inlcude javascript src attribute MDL-25836 |
38c8aed7 PS |
167 | $params['invalid_elements'] = ''; |
168 | } | |
69429650 | 169 | |
170 | if (empty($options['legacy'])) { | |
171 | if (isset($options['maxfiles']) and $options['maxfiles'] != 0) { | |
4c508047 | 172 | $params['file_browser_callback'] = "M.editor_tinymce.filepicker"; |
69429650 | 173 | } |
174 | } | |
13a220cf | 175 | |
69429650 | 176 | return $params; |
5ca3c838 | 177 | } |
69429650 | 178 | } |