Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/editor/tinymce/lib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 class tinymce_texteditor extends texteditor {
00031     public $version = '3.4.6';
00032 
00033     public function supported_by_browser() {
00034         if (check_browser_version('MSIE', 6)) {
00035             return true;
00036         }
00037         if (check_browser_version('Gecko', 20030516)) {
00038             return true;
00039         }
00040         if (check_browser_version('Safari', 412)) {
00041             return true;
00042         }
00043         if (check_browser_version('Chrome', 6)) {
00044             return true;
00045         }
00046         if (check_browser_version('Opera', 9)) {
00047             return true;
00048         }
00049         if (check_browser_version('Safari iOS', 534)) {
00050             return true;
00051         }
00052 
00053         return false;
00054     }
00055 
00056     public function get_supported_formats() {
00057         return array(FORMAT_HTML => FORMAT_HTML);
00058     }
00059 
00060     public function get_preferred_format() {
00061         return FORMAT_HTML;
00062     }
00063 
00064     public function supports_repositories() {
00065         return true;
00066     }
00067 
00068     public function head_setup() {
00069     }
00070 
00071     public function use_editor($elementid, array $options=null, $fpoptions=null) {
00072         global $PAGE;
00073         if (debugging('', DEBUG_DEVELOPER)) {
00074             $PAGE->requires->js('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce_src.js');
00075         } else {
00076             $PAGE->requires->js('/lib/editor/tinymce/tiny_mce/'.$this->version.'/tiny_mce.js');
00077         }
00078         $PAGE->requires->js_init_call('M.editor_tinymce.init_editor', array($elementid, $this->get_init_params($elementid, $options)), true);
00079         if ($fpoptions) {
00080             $PAGE->requires->js_init_call('M.editor_tinymce.init_filepicker', array($elementid, $fpoptions), true);
00081         }
00082     }
00083 
00084     protected function get_init_params($elementid, array $options=null) {
00085         global $CFG, $PAGE, $OUTPUT;
00086 
00087         //TODO: we need to implement user preferences that affect the editor setup too
00088 
00089         $directionality = get_string('thisdirection', 'langconfig');
00090         $strtime        = get_string('strftimetime');
00091         $strdate        = get_string('strftimedaydate');
00092         $lang           = current_language();
00093         $contentcss     = $PAGE->theme->editor_css_url()->out(false);
00094 
00095         $context = empty($options['context']) ? get_context_instance(CONTEXT_SYSTEM) : $options['context'];
00096 
00097         $xmedia = 'moodlemedia,'; // HQ thinks it should be always on, so it is no matter if it will actually work or not
00098         /*
00099         if (!empty($options['legacy'])) {
00100             $xmedia = 'moodlemedia,';
00101         } else {
00102             if (!empty($options['noclean']) or !empty($options['trusted'])) {
00103             }
00104         }*/
00105 
00106         $filters = filter_get_active_in_context($context);
00107         if (array_key_exists('filter/tex', $filters)) {
00108             $xdragmath = 'dragmath,';
00109         } else {
00110             $xdragmath = '';
00111         }
00112         if (array_key_exists('filter/emoticon', $filters)) {
00113             $xemoticon = 'moodleemoticon,';
00114         } else {
00115             $xemoticon = '';
00116         }
00117 
00118         $params = array(
00119                     'mode' => "exact",
00120                     'elements' => $elementid,
00121                     'relative_urls' => false,
00122                     'document_base_url' => $CFG->httpswwwroot,
00123                     'content_css' => $contentcss,
00124                     'language' => $lang,
00125                     'directionality' => $directionality,
00126                     'plugin_insertdate_dateFormat ' => $strdate,
00127                     'plugin_insertdate_timeFormat ' => $strtime,
00128                     'theme' => "advanced",
00129                     'skin' => "o2k7",
00130                     'skin_variant' => "silver",
00131                     'apply_source_formatting' => true,
00132                     'remove_script_host' => false,
00133                     'entity_encoding' => "raw",
00134                     '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",
00135                     'theme_advanced_font_sizes' => "1,2,3,4,5,6,7",
00136                     'theme_advanced_layout_manager' => "SimpleLayout",
00137                     'theme_advanced_toolbar_align' => "left",
00138                     'theme_advanced_buttons1' => "fontselect,fontsizeselect,formatselect",
00139                     'theme_advanced_buttons1_add' => "|,undo,redo,|,search,replace,|,fullscreen",
00140                     'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright",
00141                     'theme_advanced_buttons2_add' => "|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl",
00142                     'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,|,image,{$xemoticon}{$xmedia}{$xdragmath}nonbreaking,charmap",
00143                     'theme_advanced_buttons3_add' => "table,|,code,spellchecker",
00144                     '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",
00145                     'theme_advanced_resize_horizontal' => true,
00146                     'theme_advanced_resizing' => true,
00147                     'theme_advanced_resizing_min_height' => 30,
00148                     'theme_advanced_toolbar_location' => "top",
00149                     'theme_advanced_statusbar_location' => "bottom",
00150                     'spellchecker_rpc_url' => $CFG->wwwroot."/lib/editor/tinymce/tiny_mce/$this->version/plugins/spellchecker/rpc.php",
00151                     'spellchecker_languages' => get_config('editor_tinymce', 'spelllanguagelist')
00152                   );
00153 
00154         if ($xemoticon) {
00155             $manager = get_emoticon_manager();
00156             $emoticons = $manager->get_emoticons();
00157             $imgs = array();
00158             // see the TinyMCE plugin moodleemoticon for how the emoticon index is (ab)used :-S
00159             $index = 0;
00160             foreach ($emoticons as $emoticon) {
00161                 $imgs[$emoticon->text] = $OUTPUT->render(
00162                     $manager->prepare_renderable_emoticon($emoticon, array('class' => 'emoticon emoticon-index-'.$index++)));
00163             }
00164             $params['moodleemoticon_emoticons'] = json_encode($imgs);
00165         }
00166 
00167         if (empty($CFG->xmlstrictheaders) and (!empty($options['legacy']) or !empty($options['noclean']) or !empty($options['trusted']))) {
00168             // now deal somehow with non-standard tags, people scream when we do not make moodle code xtml strict,
00169             // but they scream even more when we strip all tags that are not strict :-(
00170             $params['valid_elements'] = 'script[src|type],*[*]'; // for some reason the *[*] does not inlcude javascript src attribute MDL-25836
00171             $params['invalid_elements'] = '';
00172         }
00173 
00174         if (empty($options['legacy'])) {
00175             if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
00176                 $params['file_browser_callback'] = "M.editor_tinymce.filepicker";
00177             }
00178         }
00179         //Add onblur event for client side text validation
00180         if (!empty($options['required'])) {
00181             $params['init_instance_callback'] = 'M.editor_tinymce.onblur_event';
00182         }
00183         return $params;
00184     }
00185 }
 All Data Structures Namespaces Files Functions Variables Enumerations