Skip to content

Commit

Permalink
MDL-24507 support for the TinyMCE moodleemoticon plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Oct 27, 2010
1 parent fc98c3a commit b9fadae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/editor/tinymce/lang/en/editor_tinymce.php
Expand Up @@ -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';


Expand Down
25 changes: 22 additions & 3 deletions lib/editor/tinymce/lib.php
Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -115,15 +120,15 @@ 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",
'theme_advanced_buttons1' => "fontselect,fontsizeselect,formatselect",
'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,
Expand All @@ -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 :-(
Expand Down
7 changes: 4 additions & 3 deletions lib/moodlelib.php
Expand Up @@ -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);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions lib/outputcomponents.php
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b9fadae

Please sign in to comment.