From f65a8889012f5f79683eae129267b8d24c99c1a5 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 22 Mar 2019 10:02:45 +0800 Subject: [PATCH] MDL-65149 emoticons: Do not show all emoticons Allow some emoticons to still work, but not be selectable from the text editor plugins. --- lib/editor/atto/plugins/emoticon/lib.php | 4 ++-- lib/editor/tinymce/plugins/moodleemoticon/dialog.php | 2 +- lib/editor/tinymce/plugins/moodleemoticon/lib.php | 2 +- lib/moodlelib.php | 12 +++++++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/editor/atto/plugins/emoticon/lib.php b/lib/editor/atto/plugins/emoticon/lib.php index 8be6243dafe..50d0860e8c4 100644 --- a/lib/editor/atto/plugins/emoticon/lib.php +++ b/lib/editor/atto/plugins/emoticon/lib.php @@ -36,7 +36,7 @@ function atto_emoticon_strings_for_js() { // Load the strings required by the emotes. $manager = get_emoticon_manager(); - foreach ($manager->get_emoticons() as $emote) { + foreach ($manager->get_emoticons(true) as $emote) { $PAGE->requires->string_for_js($emote->altidentifier, $emote->altcomponent); } } @@ -49,6 +49,6 @@ function atto_emoticon_strings_for_js() { function atto_emoticon_params_for_js($elementid, $options, $fpoptions) { $manager = get_emoticon_manager(); return array( - 'emoticons' => $manager->get_emoticons() + 'emoticons' => $manager->get_emoticons(true) ); } diff --git a/lib/editor/tinymce/plugins/moodleemoticon/dialog.php b/lib/editor/tinymce/plugins/moodleemoticon/dialog.php index 5987a0e2250..619dcc58a79 100644 --- a/lib/editor/tinymce/plugins/moodleemoticon/dialog.php +++ b/lib/editor/tinymce/plugins/moodleemoticon/dialog.php @@ -51,7 +51,7 @@ header('X-UA-Compatible: IE=edge'); get_emoticons(); +$emoticons = $emoticonmanager->get_emoticons(true); // This is tricky - we must somehow include the information about the original // emoticon text so that we can replace the image back with it on editor save. // so we are going to encode the index of the emoticon. this will break when the diff --git a/lib/editor/tinymce/plugins/moodleemoticon/lib.php b/lib/editor/tinymce/plugins/moodleemoticon/lib.php index 047196a8a25..3cb9b0f9826 100644 --- a/lib/editor/tinymce/plugins/moodleemoticon/lib.php +++ b/lib/editor/tinymce/plugins/moodleemoticon/lib.php @@ -52,7 +52,7 @@ class tinymce_moodleemoticon extends editor_tinymce_plugin { // Extra params specifically for emoticon plugin. $manager = get_emoticon_manager(); - $emoticons = $manager->get_emoticons(); + $emoticons = $manager->get_emoticons(true); $imgs = array(); // See the TinyMCE plugin moodleemoticon for how the emoticon index is (ab)used. $index = 0; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fc88a137b89..72251d1514d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7348,10 +7348,12 @@ class emoticon_manager { /** * Returns the currently enabled emoticons * + * @param boolean $selectable - If true, only return emoticons that should be selectable from a list. * @return array of emoticon objects */ - public function get_emoticons() { + public function get_emoticons($selectable = false) { global $CFG; + $notselectable = ['martin', 'egg']; if (empty($CFG->emoticons)) { return array(); @@ -7364,6 +7366,14 @@ class emoticon_manager { debugging('Invalid format of emoticons setting, please resave the emoticons settings form', DEBUG_NORMAL); return array(); } + if ($selectable) { + foreach ($emoticons as $index => $emote) { + if (in_array($emote->altidentifier, $notselectable)) { + // Skip this one. + unset($emoticons[$index]); + } + } + } return $emoticons; }