2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Contains class \core\output\icon_system
22 * @copyright 2016 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace core\output
;
31 defined('MOODLE_INTERNAL') ||
die();
34 * Class allowing different systems for mapping and rendering icons.
36 * Possible icon styles are:
37 * 1. standard - image tags are generated which point to pix icons stored in a plugin pix folder.
38 * 2. fontawesome - font awesome markup is generated with the name of the icon mapped from the moodle icon name.
39 * 3. inline - inline tags are used for svg and png so no separate page requests are made (at the expense of page size).
43 * @copyright 2016 Damyon Wiese
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46 class icon_system_fontawesome
extends icon_system_font
{
49 * @var array $map Cached map of moodle icon names to font awesome icon names.
53 public function get_core_icon_map() {
55 'core:docs' => 'fa-info-circle',
56 'core:help' => 'fa-question-circle text-info',
57 'core:req' => 'fa-exclamation-circle text-danger',
58 'core:a/add_file' => 'fa-file-o',
59 'core:a/create_folder' => 'fa-folder-o',
60 'core:a/download_all' => 'fa-download',
61 'core:a/help' => 'fa-question-circle text-info',
62 'core:a/logout' => 'fa-sign-out',
63 'core:a/refresh' => 'fa-refresh',
64 'core:a/search' => 'fa-search',
65 'core:a/setting' => 'fa-cog',
66 'core:a/view_icon_active' => 'fa-th',
67 'core:a/view_list_active' => 'fa-list',
68 'core:a/view_tree_active' => 'fa-folder',
69 'core:b/bookmark-new' => 'fa-bookmark',
70 'core:b/document-edit' => 'fa-pencil',
71 'core:b/document-new' => 'fa-file-o',
72 'core:b/document-properties' => 'fa-info',
73 'core:b/edit-copy' => 'fa-files-o',
74 'core:b/edit-delete' => 'fa-trash',
75 'core:e/abbr' => 'fa-comment',
76 'core:e/absolute' => 'fa-crosshairs',
77 'core:e/accessibility_checker' => 'fa-universal-access',
78 'core:e/acronym' => 'fa-comment',
79 'core:e/advance_hr' => 'fa-arrows-h',
80 'core:e/align_center' => 'fa-align-center',
81 'core:e/align_left' => 'fa-align-left',
82 'core:e/align_right' => 'fa-align-right',
83 'core:e/anchor' => 'fa-chain',
84 'core:e/backward' => 'fa-undo',
85 'core:e/bold' => 'fa-bold',
86 'core:e/bullet_list' => 'fa-list-ul',
87 'core:e/cancel' => 'fa-times',
88 'core:e/cell_props' => 'fa-info',
89 'core:e/cite' => 'fa-quote-right',
90 'core:e/cleanup_messy_code' => 'fa-eraser',
91 'core:e/clear_formatting' => 'fa-i-cursor',
92 'core:e/copy' => 'fa-clone',
93 'core:e/cut' => 'fa-scissors',
94 'core:e/decrease_indent' => 'fa-outdent',
95 'core:e/delete_col' => 'fa-minus',
96 'core:e/delete_row' => 'fa-minus',
97 'core:e/delete' => 'fa-minus',
98 'core:e/delete_table' => 'fa-minus',
99 'core:e/document_properties' => 'fa-info',
100 'core:e/emoticons' => 'fa-smile-o',
101 'core:e/find_replace' => 'fa-search-plus',
102 'core:e/forward' => 'fa-arrow-right',
103 'core:e/fullpage' => 'fa-arrows-alt',
104 'core:e/fullscreen' => 'fa-arrows-alt',
105 'core:e/help' => 'fa-question-circle',
106 'core:e/increase_indent' => 'fa-indent',
107 'core:e/insert_col_after' => 'fa-columns',
108 'core:e/insert_col_before' => 'fa-columns',
109 'core:e/insert_date' => 'fa-calendar',
110 'core:e/insert_edit_image' => 'fa-picture-o',
111 'core:e/insert_edit_link' => 'fa-link',
112 'core:e/insert_edit_video' => 'fa-file-video-o',
113 'core:e/insert_file' => 'fa-file',
114 'core:e/insert_horizontal_ruler' => 'fa-arrows-h',
115 'core:e/insert_nonbreaking_space' => 'fa-square-o',
116 'core:e/insert_page_break' => 'fa-level-down',
117 'core:e/insert_row_after' => 'fa-plus',
118 'core:e/insert_row_before' => 'fa-plus',
119 'core:e/insert' => 'fa-plus',
120 'core:e/insert_time' => 'fa-clock-o',
121 'core:e/italic' => 'fa-italic',
122 'core:e/justify' => 'fa-align-justify',
123 'core:e/layers_over' => 'fa-level-up',
124 'core:e/layers' => 'fa-window-restore',
125 'core:e/layers_under' => 'fa-level-down',
126 'core:e/left_to_right' => 'fa-chevron-right',
127 'core:e/manage_files' => 'fa-files-o',
128 'core:e/math' => 'fa-calculator',
129 'core:e/merge_cells' => 'fa-compress',
130 'core:e/new_document' => 'fa-file-o',
131 'core:e/numbered_list' => 'fa-list-ol',
132 'core:e/page_break' => 'fa-level-down',
133 'core:e/paste' => 'fa-clipboard',
134 'core:e/paste_text' => 'fa-clipboard',
135 'core:e/paste_word' => 'fa-clipboard',
136 'core:e/prevent_autolink' => 'fa-exclamation',
137 'core:e/preview' => 'fa-search-plus',
138 'core:e/print' => 'fa-print',
139 'core:e/question' => 'fa-question',
140 'core:e/redo' => 'fa-repeat',
141 'core:e/remove_link' => 'fa-chain-broken',
142 'core:e/remove_page_break' => 'fa-remove',
143 'core:e/resize' => 'fa-expand',
144 'core:e/restore_draft' => 'fa-undo',
145 'core:e/restore_last_draft' => 'fa-undo',
146 'core:e/right_to_left' => 'fa-chevron-left',
147 'core:e/row_props' => 'fa-info',
148 'core:e/save' => 'fa-floppy-o',
149 'core:e/screenreader_helper' => 'fa-braille',
150 'core:e/search' => 'fa-search',
151 'core:e/select_all' => 'fa-arrows-h',
152 'core:e/show_invisible_characters' => 'fa-eye-slash',
153 'core:e/source_code' => 'fa-code',
154 'core:e/special_character' => 'fa-pencil-square-o',
155 'core:e/spellcheck' => 'fa-check',
156 'core:e/split_cells' => 'fa-columns',
157 'core:e/strikethrough' => 'fa-strikethrough',
158 'core:e/styleprops' => 'fa-info',
159 'core:e/subscript' => 'fa-subscript',
160 'core:e/superscript' => 'fa-superscript',
161 'core:e/table_props' => 'fa-table',
162 'core:e/table' => 'fa-table',
163 'core:e/template' => 'fa-sticky-note',
164 'core:e/text_color_picker' => 'fa-paint-brush',
165 'core:e/text_color' => 'fa-paint-brush',
166 'core:e/text_highlight_picker' => 'fa-lightbulb-o',
167 'core:e/text_highlight' => 'fa-lightbulb-o',
168 'core:e/tick' => 'fa-check',
169 'core:e/toggle_blockquote' => 'fa-quote-left',
170 'core:e/underline' => 'fa-underline',
171 'core:e/undo' => 'fa-undo',
172 'core:e/visual_aid' => 'fa-universal-access',
173 'core:e/visual_blocks' => 'fa-audio-description',
174 'theme:fp/add_file' => 'fa-file-o',
175 'theme:fp/alias' => 'fa-share',
176 'theme:fp/alias_sm' => 'fa-share',
177 'theme:fp/check' => 'fa-check',
178 'theme:fp/create_folder' => 'fa-folder-o',
179 'theme:fp/cross' => 'fa-remove',
180 'theme:fp/download_all' => 'fa-download',
181 'theme:fp/help' => 'fa-question-circle',
182 'theme:fp/link' => 'fa-link',
183 'theme:fp/link_sm' => 'fa-link',
184 'theme:fp/logout' => 'fa-sign-out',
185 'theme:fp/path_folder' => 'fa-folder',
186 'theme:fp/path_folder_rtl' => 'fa-folder',
187 'theme:fp/refresh' => 'fa-refresh',
188 'theme:fp/search' => 'fa-search',
189 'theme:fp/setting' => 'fa-cog',
190 'theme:fp/view_icon_active' => 'fa-th',
191 'theme:fp/view_list_active' => 'fa-list',
192 'theme:fp/view_tree_active' => 'fa-folder',
193 'core:i/addblock' => 'fa-plus-square',
194 'core:i/assignroles' => 'fa-user-plus',
195 'core:i/backup' => 'fa-file-zip-o',
196 'core:i/badge' => 'fa-shield',
197 'core:i/calc' => 'fa-calculator',
198 'core:i/calendar' => 'fa-calendar',
199 'core:i/calendareventdescription' => 'fa-align-left',
200 'core:i/calendareventtime' => 'fa-clock-o',
201 'core:i/caution' => 'fa-exclamation text-warning',
202 'core:i/checked' => 'fa-check',
203 'core:i/checkpermissions' => 'fa-unlock-alt',
204 'core:i/cohort' => 'fa-users',
205 'core:i/competencies' => 'fa-check-square-o',
206 'core:i/completion_self' => 'fa-user-o',
207 'core:i/dashboard' => 'fa-tachometer',
208 'core:i/lock' => 'fa-lock',
209 'core:i/categoryevent' => 'fa-cubes',
210 'core:i/course' => 'fa-graduation-cap',
211 'core:i/courseevent' => 'fa-university',
212 'core:i/db' => 'fa-database',
213 'core:i/delete' => 'fa-trash',
214 'core:i/down' => 'fa-arrow-down',
215 'core:i/dragdrop' => 'fa-arrows',
216 'core:i/duration' => 'fa-clock-o',
217 'core:i/edit' => 'fa-pencil',
218 'core:i/email' => 'fa-envelope',
219 'core:i/empty' => 'fa-fw',
220 'core:i/enrolmentsuspended' => 'fa-pause',
221 'core:i/enrolusers' => 'fa-user-plus',
222 'core:i/expired' => 'fa-exclamation text-warning',
223 'core:i/export' => 'fa-download',
224 'core:i/files' => 'fa-file',
225 'core:i/filter' => 'fa-filter',
226 'core:i/flagged' => 'fa-flag',
227 'core:i/folder' => 'fa-folder',
228 'core:i/grade_correct' => 'fa-check text-success',
229 'core:i/grade_incorrect' => 'fa-remove text-danger',
230 'core:i/grade_partiallycorrect' => 'fa-check-square',
231 'core:i/grades' => 'fa-table',
232 'core:i/groupevent' => 'fa-group',
233 'core:i/groupn' => 'fa-user',
234 'core:i/group' => 'fa-users',
235 'core:i/groups' => 'fa-user-circle',
236 'core:i/groupv' => 'fa-user-circle-o',
237 'core:i/home' => 'fa-home',
238 'core:i/hide' => 'fa-eye',
239 'core:i/hierarchylock' => 'fa-lock',
240 'core:i/import' => 'fa-level-up',
241 'core:i/info' => 'fa-info',
242 'core:i/invalid' => 'fa-times text-danger',
243 'core:i/item' => 'fa-circle',
244 'core:i/loading' => 'fa-circle-o-notch fa-spin',
245 'core:i/loading_small' => 'fa-circle-o-notch fa-spin',
246 'core:i/lock' => 'fa-lock',
247 'core:i/log' => 'fa-list-alt',
248 'core:i/mahara_host' => 'fa-id-badge',
249 'core:i/manual_item' => 'fa-square-o',
250 'core:i/marked' => 'fa-circle',
251 'core:i/marker' => 'fa-circle-o',
252 'core:i/mean' => 'fa-calculator',
253 'core:i/menu' => 'fa-ellipsis-v',
254 'core:i/menubars' => 'fa-bars',
255 'core:i/mnethost' => 'fa-external-link',
256 'core:i/moodle_host' => 'fa-graduation-cap',
257 'core:i/move_2d' => 'fa-arrows',
258 'core:i/navigationitem' => 'fa-fw',
259 'core:i/ne_red_mark' => 'fa-remove',
260 'core:i/new' => 'fa-bolt',
261 'core:i/news' => 'fa-newspaper-o',
262 'core:i/nosubcat' => 'fa-plus-square-o',
263 'core:i/notifications' => 'fa-bell',
264 'core:i/open' => 'fa-folder-open',
265 'core:i/outcomes' => 'fa-tasks',
266 'core:i/payment' => 'fa-money',
267 'core:i/permissionlock' => 'fa-lock',
268 'core:i/permissions' => 'fa-pencil-square-o',
269 'core:i/persona_sign_in_black' => 'fa-male',
270 'core:i/portfolio' => 'fa-id-badge',
271 'core:i/preview' => 'fa-search-plus',
272 'core:i/privatefiles' => 'fa-file-o',
273 'core:i/progressbar' => 'fa-spinner fa-spin',
274 'core:i/publish' => 'fa-share',
275 'core:i/questions' => 'fa-question',
276 'core:i/reload' => 'fa-refresh',
277 'core:i/report' => 'fa-area-chart',
278 'core:i/repository' => 'fa-hdd-o',
279 'core:i/restore' => 'fa-level-up',
280 'core:i/return' => 'fa-arrow-left',
281 'core:i/risk_config' => 'fa-exclamation text-muted',
282 'core:i/risk_managetrust' => 'fa-exclamation-triangle text-warning',
283 'core:i/risk_personal' => 'fa-exclamation-circle text-info',
284 'core:i/risk_spam' => 'fa-exclamation text-primary',
285 'core:i/risk_xss' => 'fa-exclamation-triangle text-danger',
286 'core:i/role' => 'fa-user-md',
287 'core:i/rss' => 'fa-rss',
288 'core:i/rsssitelogo' => 'fa-graduation-cap',
289 'core:i/scales' => 'fa-balance-scale',
290 'core:i/scheduled' => 'fa-calendar-check-o',
291 'core:i/search' => 'fa-search',
292 'core:i/section' => 'fa-folder-o',
293 'core:i/settings' => 'fa-cog',
294 'core:i/show' => 'fa-eye-slash',
295 'core:i/siteevent' => 'fa-globe',
296 'core:i/star-rating' => 'fa-star',
297 'core:i/stats' => 'fa-line-chart',
298 'core:i/switch' => 'fa-exchange',
299 'core:i/switchrole' => 'fa-user-secret',
300 'core:i/twoway' => 'fa-arrows-h',
301 'core:i/unchecked' => 'fa-square-o',
302 'core:i/unflagged' => 'fa-flag-o',
303 'core:i/unlock' => 'fa-unlock',
304 'core:i/up' => 'fa-arrow-up',
305 'core:i/userevent' => 'fa-user',
306 'core:i/user' => 'fa-user',
307 'core:i/users' => 'fa-users',
308 'core:i/valid' => 'fa-check text-success',
309 'core:i/warning' => 'fa-exclamation text-warning',
310 'core:i/withsubcat' => 'fa-plus-square',
311 'core:m/USD' => 'fa-usd',
312 'core:t/addcontact' => 'fa-address-card',
313 'core:t/add' => 'fa-plus',
314 'core:t/approve' => 'fa-thumbs-up',
315 'core:t/assignroles' => 'fa-user-circle',
316 'core:t/award' => 'fa-trophy',
317 'core:t/backpack' => 'fa-shopping-bag',
318 'core:t/backup' => 'fa-arrow-circle-down',
319 'core:t/block' => 'fa-ban',
320 'core:t/block_to_dock_rtl' => 'fa-chevron-right',
321 'core:t/block_to_dock' => 'fa-chevron-left',
322 'core:t/calc_off' => 'fa-calculator', // TODO: Change to better icon once we have stacked icon support or more icons.
323 'core:t/calc' => 'fa-calculator',
324 'core:t/check' => 'fa-check',
325 'core:t/cohort' => 'fa-users',
326 'core:t/collapsed_empty_rtl' => 'fa-plus-square-o',
327 'core:t/collapsed_empty' => 'fa-plus-square-o',
328 'core:t/collapsed_rtl' => 'fa-plus-square',
329 'core:t/collapsed' => 'fa-plus-square',
330 'core:t/contextmenu' => 'fa-cog',
331 'core:t/copy' => 'fa-copy',
332 'core:t/delete' => 'fa-trash',
333 'core:t/dockclose' => 'fa-window-close',
334 'core:t/dock_to_block_rtl' => 'fa-chevron-right',
335 'core:t/dock_to_block' => 'fa-chevron-left',
336 'core:t/download' => 'fa-download',
337 'core:t/down' => 'fa-arrow-down',
338 'core:t/dropdown' => 'fa-cog',
339 'core:t/editinline' => 'fa-pencil',
340 'core:t/edit_menu' => 'fa-cog',
341 'core:t/editstring' => 'fa-pencil',
342 'core:t/edit' => 'fa-cog',
343 'core:t/emailno' => 'fa-ban',
344 'core:t/email' => 'fa-envelope-o',
345 'core:t/enrolusers' => 'fa-user-plus',
346 'core:t/expanded' => 'fa-caret-down',
347 'core:t/go' => 'fa-play',
348 'core:t/grades' => 'fa-table',
349 'core:t/groupn' => 'fa-user',
350 'core:t/groups' => 'fa-user-circle',
351 'core:t/groupv' => 'fa-user-circle-o',
352 'core:t/hide' => 'fa-eye',
353 'core:t/left' => 'fa-arrow-left',
354 'core:t/less' => 'fa-caret-up',
355 'core:t/locked' => 'fa-lock',
356 'core:t/lock' => 'fa-unlock',
357 'core:t/locktime' => 'fa-lock',
358 'core:t/markasread' => 'fa-check',
359 'core:t/messages' => 'fa-comments',
360 'core:t/message' => 'fa-comment',
361 'core:t/more' => 'fa-caret-down',
362 'core:t/move' => 'fa-arrows-v',
363 'core:t/passwordunmask-edit' => 'fa-pencil',
364 'core:t/passwordunmask-reveal' => 'fa-eye',
365 'core:t/portfolioadd' => 'fa-plus',
366 'core:t/preferences' => 'fa-wrench',
367 'core:t/preview' => 'fa-search-plus',
368 'core:t/print' => 'fa-print',
369 'core:t/removecontact' => 'fa-user-times',
370 'core:t/reset' => 'fa-repeat',
371 'core:t/restore' => 'fa-arrow-circle-up',
372 'core:t/right' => 'fa-arrow-right',
373 'core:t/show' => 'fa-eye-slash',
374 'core:t/sort_asc' => 'fa-sort-asc',
375 'core:t/sort_desc' => 'fa-sort-desc',
376 'core:t/sort' => 'fa-sort',
377 'core:t/stop' => 'fa-stop',
378 'core:t/switch_minus' => 'fa-minus',
379 'core:t/switch_plus' => 'fa-plus',
380 'core:t/switch_whole' => 'fa-square-o',
381 'core:t/tags' => 'fa-tags',
382 'core:t/unblock' => 'fa-commenting',
383 'core:t/unlocked' => 'fa-unlock-alt',
384 'core:t/unlock' => 'fa-lock',
385 'core:t/up' => 'fa-arrow-up',
386 'core:t/user' => 'fa-user',
387 'core:t/viewdetails' => 'fa-list',
392 * Overridable function to get a mapping of all icons.
393 * Default is to do no mapping.
395 public function get_icon_name_map() {
396 if ($this->map
=== []) {
397 $cache = \cache
::make('core', 'fontawesomeiconmapping');
399 $this->map
= $cache->get('mapping');
401 if (empty($this->map
)) {
402 $this->map
= $this->get_core_icon_map();
403 $callback = 'get_fontawesome_icon_map';
405 if ($pluginsfunction = get_plugins_with_function($callback)) {
406 foreach ($pluginsfunction as $plugintype => $plugins) {
407 foreach ($plugins as $pluginfunction) {
408 $pluginmap = $pluginfunction();
409 $this->map +
= $pluginmap;
413 $cache->set('mapping', $this->map
);
421 public function get_amd_name() {
422 return 'core/icon_system_fontawesome';
425 public function render_pix_icon(renderer_base
$output, pix_icon
$icon) {
426 $subtype = 'pix_icon_fontawesome';
427 $subpix = new $subtype($icon);
429 $data = $subpix->export_for_template($output);
431 if (!$subpix->is_mapped()) {
432 $data['unmappedIcon'] = $icon->export_for_template($output);
434 return $output->render_from_template('core/pix_icon_fontawesome', $data);