diff --git a/lib/editor/tinymce/lang/en/editor_tinymce.php b/lib/editor/tinymce/lang/en/editor_tinymce.php index d799d494b5e0c..978c3334abe7f 100644 --- a/lib/editor/tinymce/lang/en/editor_tinymce.php +++ b/lib/editor/tinymce/lang/en/editor_tinymce.php @@ -32,7 +32,8 @@ $string['dragmath:dragmath_javaneeded'] = 'To use this page you need a Java-enabled browser. Download the latest Java plug-in from {$a}.'; $string['dragmath:dragmath_title'] = 'DragMath Equation Editor'; $string['media_dlg:filename'] = 'Filename'; -$string['moodlenolink:desc'] = "Prevent automatic linking"; +$string['moodlenolink:desc'] = 'Prevent automatic linking'; +$string['moodleemoticon:desc'] = 'Insert emoticon'; $string['pluginname'] = 'TinyMCE HTML editor'; diff --git a/lib/editor/tinymce/lib.php b/lib/editor/tinymce/lib.php index 31d42092d3d21..4bbe2b4b1cb4e 100644 --- a/lib/editor/tinymce/lib.php +++ b/lib/editor/tinymce/lib.php @@ -71,7 +71,7 @@ public function use_editor($elementid, array $options=null, $fpoptions=null) { } protected function get_init_params($elementid, array $options=null) { - global $CFG, $PAGE; + global $CFG, $PAGE, $OUTPUT; //TODO: we need to implement user preferences that affect the editor setup too @@ -98,6 +98,11 @@ protected function get_init_params($elementid, array $options=null) { } else { $xdragmath = ''; } + if (array_key_exists('filter/emoticon', $filters)) { + $xemoticon = 'moodleemoticon,'; + } else { + $xemoticon = ''; + } $params = array( 'mode' => "exact", @@ -115,7 +120,7 @@ protected function get_init_params($elementid, array $options=null) { 'apply_source_formatting' => true, 'remove_script_host' => false, 'entity_encoding' => "raw", - 'plugins' => "{$xmedia}advimage,safari,table,style,layer,advhr,advlink,emotions,inlinepopups,searchreplace,paste,directionality,fullscreen,moodlenolink,{$xdragmath}nonbreaking,contextmenu,insertdatetime,save,iespell,preview,print,noneditable,visualchars,xhtmlxtras,template,pagebreak,spellchecker", + '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", 'theme_advanced_font_sizes' => "1,2,3,4,5,6,7", 'theme_advanced_layout_manager' => "SimpleLayout", 'theme_advanced_toolbar_align' => "left", @@ -123,7 +128,7 @@ protected function get_init_params($elementid, array $options=null) { 'theme_advanced_buttons1_add' => "|,undo,redo,|,search,replace,|,fullscreen", 'theme_advanced_buttons2' => "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright", 'theme_advanced_buttons2_add' => "|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl", - 'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,|,image,{$xmedia}{$xdragmath}nonbreaking,charmap", + 'theme_advanced_buttons3' => "bullist,numlist,outdent,indent,|,link,unlink,moodlenolink,|,image,{$xemoticon}{$xmedia}{$xdragmath}nonbreaking,charmap", 'theme_advanced_buttons3_add' => "table,|,code,spellchecker", '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", 'theme_advanced_resize_horizontal' => true, @@ -132,6 +137,20 @@ protected function get_init_params($elementid, array $options=null) { 'theme_advanced_statusbar_location' => "bottom", 'spellchecker_rpc_url' => $CFG->wwwroot."/lib/editor/tinymce/tiny_mce/$this->version/plugins/spellchecker/rpc.php" ); + + if ($xemoticon) { + $manager = get_emoticon_manager(); + $emoticons = $manager->get_emoticons(); + $imgs = array(); + // see the TinyMCE plugin moodleemoticon for how the emoticon index is (ab)used :-S + $index = 0; + foreach ($emoticons as $emoticon) { + $imgs[$emoticon->text] = $OUTPUT->render( + $manager->prepare_renderable_emoticon($emoticon, array('class' => 'emoticon emoticon-index-'.$index++))); + } + $params['moodleemoticon_emoticons'] = json_encode($imgs); + } + if (empty($CFG->xmlstrictheaders) and (!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 :-( diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fc4f95f652fc0..30252a4f1581a 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -6781,16 +6781,17 @@ public function get_emoticons() { * Converts emoticon object into renderable pix_emoticon object * * @param stdClass $emoticon emoticon object + * @param array $attributes explicit HTML attributes to set * @return pix_emoticon */ - public function prepare_renderable_emoticon(stdClass $emoticon) { + public function prepare_renderable_emoticon(stdClass $emoticon, array $attributes = array()) { $stringmanager = get_string_manager(); if ($stringmanager->string_exists($emoticon->altidentifier, $emoticon->altcomponent)) { $alt = get_string($emoticon->altidentifier, $emoticon->altcomponent); } else { - $alt = $emoticon->text; + $alt = s($emoticon->text); } - return new pix_emoticon($emoticon->imagename, $alt, $emoticon->imagecomponent); + return new pix_emoticon($emoticon->imagename, $alt, $emoticon->imagecomponent, $attributes); } /** diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 3938f93f362f2..10506329cabda 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -348,10 +348,14 @@ class pix_emoticon extends pix_icon implements renderable { /** * Constructor * @param string $pix short icon name - * @param string $component component name + * @param string $alt alternative text + * @param string $component emoticon image provider + * @param array $attributes explicit HTML attributes */ - public function __construct($pix, $alt, $component = 'moodle') { - $attributes = array('class' => 'emoticon'); + public function __construct($pix, $alt, $component = 'moodle', array $attributes = array()) { + if (empty($attributes['class'])) { + $attributes['class'] = 'emoticon'; + } parent::__construct($pix, $alt, $component, $attributes); } }