From 7e8940b544871b186c0fbe6ac5a8458b824dffd6 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 21 Mar 2017 10:31:22 +0800 Subject: [PATCH 1/2] MDL-40759 fontawesome: Use a cache Cache the callback info. --- lang/en/cache.php | 1 + .../output/icon_system_fontawesome.php | 21 ++++++++++++------- lib/db/caches.php | 10 +++++++++ version.php | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lang/en/cache.php b/lang/en/cache.php index b97ae2b189e..e54522fcda0 100644 --- a/lang/en/cache.php +++ b/lang/en/cache.php @@ -48,6 +48,7 @@ $string['cachedef_completion'] = 'Activity completion status'; $string['cachedef_databasemeta'] = 'Database meta information'; $string['cachedef_eventinvalidation'] = 'Event invalidation'; $string['cachedef_externalbadges'] = 'External badges for particular user'; +$string['cachedef_fontawesomeiconmapping'] = 'Mapping of icons for font awesome'; $string['cachedef_suspended_userids'] = 'List of suspended users per course'; $string['cachedef_groupdata'] = 'Course group information'; $string['cachedef_htmlpurifier'] = 'HTML Purifier - cleaned content'; diff --git a/lib/classes/output/icon_system_fontawesome.php b/lib/classes/output/icon_system_fontawesome.php index b574524bd1d..5a44628111f 100644 --- a/lib/classes/output/icon_system_fontawesome.php +++ b/lib/classes/output/icon_system_fontawesome.php @@ -431,16 +431,23 @@ class icon_system_fontawesome extends icon_system_font { */ public function get_icon_name_map() { if ($this->map === []) { - $this->map = $this->get_core_icon_map(); - $callback = 'get_fontawesome_icon_map'; + $cache = \cache::make('core', 'fontawesomeiconmapping'); - if ($pluginsfunction = get_plugins_with_function($callback)) { - foreach ($pluginsfunction as $plugintype => $plugins) { - foreach ($plugins as $pluginfunction) { - $pluginmap = $pluginfunction(); - $this->map += $pluginmap; + $this->map = $cache->get('mapping'); + + if (empty($this->map)) { + $this->map = $this->get_core_icon_map(); + $callback = 'get_fontawesome_icon_map'; + + if ($pluginsfunction = get_plugins_with_function($callback)) { + foreach ($pluginsfunction as $plugintype => $plugins) { + foreach ($plugins as $pluginfunction) { + $pluginmap = $pluginfunction(); + $this->map += $pluginmap; + } } } + $cache->set('mapping', $this->map); } } diff --git a/lib/db/caches.php b/lib/db/caches.php index 9a8e9f24e5d..52855727e83 100644 --- a/lib/db/caches.php +++ b/lib/db/caches.php @@ -309,4 +309,14 @@ $definitions = array( 'simplevalues' => true, 'datasource' => '\core_message\time_last_message_between_users', ), + + // Caches font awesome icons. + 'fontawesomeiconmapping' => array( + 'mode' => cache_store::MODE_APPLICATION, + 'simplekeys' => true, + 'simpledata' => true, + 'staticacceleration' => true, + 'staticaccelerationsize' => 1 + ), + ); diff --git a/version.php b/version.php index dfc92b4794c..a151f705041 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017031600.01; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2017031600.02; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. From dc633a24b900047e4f2fed290e2701fcb57e5785 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Tue, 21 Mar 2017 11:13:43 +0800 Subject: [PATCH 2/2] MDL-40759 fontawesome: lang strings comments --- comment/comment.js | 13 +++++++------ comment/lib.php | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/comment/comment.js b/comment/comment.js index dfb7e8f3063..6e30eed05b5 100644 --- a/comment/comment.js +++ b/comment/comment.js @@ -332,14 +332,15 @@ M.core_comment = { } }, '13,32'); // 13 and 32 are the keycodes for space and enter. + + require(['core/templates', 'core/notification'], function(Templates, Notification) { + var title = node.getAttribute('title'); + Templates.renderPix('t/delete', 'core', title).then(function(html) { + node.set('innerHTML', html); + }).catch(Notification.exception); + }); } ); - - require(['core/templates', 'core/notification'], function(Templates, Notification) { - Templates.renderPix('t/delete', 'core', M.util.get_string('deletecomment', 'moodle')).then(function(html) { - Y.all('div.comment-delete a').set('innerHTML', html); - }).catch(Notification.exception); - }); }, register_pagination: function() { var scope = this; diff --git a/comment/lib.php b/comment/lib.php index 5033e2c7916..16fa9b6d38f 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -263,8 +263,7 @@ class comment { 'comments', 'commentscount', 'commentsrequirelogin', - 'deletecommentbyon', - 'deletecomment', + 'deletecommentbyon' ), 'moodle' ); @@ -916,8 +915,11 @@ class comment { $replacements = array(); if (!empty($cmt->delete) && empty($nonjs)) { + $strdelete = get_string('deletecommentbyon', 'moodle', (object)['user' => $cmt->fullname, 'time' => $cmt->time]); $deletelink = html_writer::start_tag('div', array('class'=>'comment-delete')); - $deletelink .= html_writer::start_tag('a', array('href' => '#', 'id' => 'comment-delete-'.$this->cid.'-'.$cmt->id)); + $deletelink .= html_writer::start_tag('a', array('href' => '#', 'id' => 'comment-delete-'.$this->cid.'-'.$cmt->id, + 'title' => $strdelete)); + $deletelink .= $OUTPUT->pix_icon('t/delete', get_string('delete')); $deletelink .= html_writer::end_tag('a'); $deletelink .= html_writer::end_tag('div');