MDL-40759 icons: Refactor to allow theme icon systems
[moodle.git] / lib / classes / output / icon_system_fontawesome.php
CommitLineData
95b06c13
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Contains class \core\output\icon_system
19 *
20 * @package core
21 * @category output
22 * @copyright 2016 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26namespace core\output;
27
e330b1c2
DW
28use renderer_base;
29use pix_icon;
30
95b06c13
DW
31/**
32 * Class allowing different systems for mapping and rendering icons.
33 *
34 * Possible icon styles are:
35 * 1. standard - image tags are generated which point to pix icons stored in a plugin pix folder.
36 * 2. fontawesome - font awesome markup is generated with the name of the icon mapped from the moodle icon name.
37 * 3. inline - inline tags are used for svg and png so no separate page requests are made (at the expense of page size).
38 *
39 * @package core
40 * @category output
41 * @copyright 2016 Damyon Wiese
42 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43 */
44class icon_system_fontawesome extends icon_system_font {
45
46 public function get_core_icon_map() {
47 return [
48 'core:docs' => 'fa-info-circle',
49 'core:help' => 'fa-question-circle',
50 'core:req' => 'fa-exclamation-circle',
51 'core:a/add_file' => 'fa-file-o',
52 'core:a/create_folder' => 'fa-folder-o',
53 'core:a/download_all' => 'fa-download',
54 'core:a/help' => 'fa-question-circle',
55 'core:a/logout' => 'fa-sign-out',
56 'core:a/refresh' => 'fa-refresh',
57 'core:a/search' => 'fa-search',
58 'core:a/setting' => 'fa-cog',
59 'core:a/view_icon_active' => 'fa-th',
60 'core:a/view_list_active' => 'fa-list',
61 'core:a/view_tree_active' => 'fa-folder',
62 'core:b/bookmark-new' => 'fa-bookmark',
63 'core:b/document-edit' => 'fa-pencil',
64 'core:b/document-new' => 'fa-file-o',
65 'core:b/document-properties' => 'fa-info',
66 'core:b/edit-copy' => 'fa-files-o',
67 'core:b/edit-delete' => 'fa-trash',
68 'core:e/abbr' => 'fa-comment',
69 'core:e/absolute' => 'fa-crosshairs',
70 'core:e/accessibility_checker' => 'fa-universal-access',
71 'core:e/acronym' => 'fa-comment',
72 'core:e/advance_hr' => 'fa-arrows-h',
73 'core:e/align_center' => 'fa-align-center',
74 'core:e/align_left' => 'fa-align-left',
75 'core:e/align_right' => 'fa-align-right',
76 'core:e/anchor' => 'fa-chain',
77 'core:e/backward' => 'fa-undo',
78 'core:e/bold' => 'fa-bold',
79 'core:e/bullet_list' => 'fa-list-ul',
80 'core:e/cell_props' => 'fa-info',
81 'core:e/cite' => 'fa-quote-right',
82 'core:e/cleanup_messy_code' => 'fa-eraser',
83 'core:e/clear_formatting' => 'fa-fire',
84 'core:e/copy' => 'fa-clone',
85 'core:e/cut' => 'fa-scissors',
86 'core:e/decrease_indent' => 'fa-outdent',
87 'core:e/delete_col' => 'fa-minus',
88 'core:e/delete_row' => 'fa-minus',
89 'core:e/delete' => 'fa-minus',
90 'core:e/delete_table' => 'fa-minus',
91 'core:e/document_properties' => 'fa-info',
92 'core:e/emoticons' => 'fa-meh-o',
93 'core:e/find_replace' => 'fa-search-plus',
94 'core:e/forward' => 'fa-arrow-right',
95 'core:e/fullpage' => 'fa-arrows-alt',
96 'core:e/fullscreen' => 'fa-arrows-alt',
97 'core:e/help' => 'fa-question-circle',
98 'core:e/increase_indent' => 'fa-indent',
99 'core:e/insert_col_after' => 'fa-columns',
100 'core:e/insert_col_before' => 'fa-columns',
101 'core:e/insert_date' => 'fa-calendar',
102 'core:e/insert_edit_image' => 'fa-picture-o',
103 'core:e/insert_edit_link' => 'fa-link',
104 'core:e/insert_edit_video' => 'fa-video-camera',
105 'core:e/insert_file' => 'fa-file',
106 'core:e/insert_horizontal_ruler' => 'fa-arrows-h',
107 'core:e/insert_nonbreaking_space' => 'fa-square-o',
108 'core:e/insert_page_break' => 'fa-level-down',
109 'core:e/insert_row_after' => 'fa-plus',
110 'core:e/insert_row_before' => 'fa-plus',
111 'core:e/insert' => 'fa-plus',
112 'core:e/insert_time' => 'fa-clock-o',
113 'core:e/italic' => 'fa-italic',
114 'core:e/justify' => 'fa-align-justify',
115 'core:e/layers_over' => 'fa-level-up',
116 'core:e/layers' => 'fa-window-restore',
117 'core:e/layers_under' => 'fa-level-down',
118 'core:e/left_to_right' => 'fa-chevron-right',
119 'core:e/manage_files' => 'fa-files-o',
120 'core:e/math' => 'fa-calculator',
121 'core:e/merge_cells' => 'fa-compress',
122 'core:e/new_document' => 'fa-file-o',
123 'core:e/numbered_list' => 'fa-list-ol',
124 'core:e/page_break' => 'fa-level-down',
125 'core:e/paste' => 'fa-clipboard',
126 'core:e/paste_text' => 'fa-clipboard',
127 'core:e/paste_word' => 'fa-clipboard',
128 'core:e/prevent_autolink' => 'fa-exclamation',
129 'core:e/preview' => 'fa-search-plus',
130 'core:e/print' => 'fa-print',
131 'core:e/question' => 'fa-question',
132 'core:e/redo' => 'fa-repeat',
133 'core:e/remove_link' => 'fa-remove',
134 'core:e/remove_page_break' => 'fa-remove',
135 'core:e/resize' => 'fa-expand',
136 'core:e/restore_draft' => 'fa-undo',
137 'core:e/restore_last_draft' => 'fa-undo',
138 'core:e/right_to_left' => 'fa-chevron-left',
139 'core:e/row_props' => 'fa-info',
140 'core:e/save' => 'fa-floppy-o',
141 'core:e/screenreader_helper' => 'fa-braille',
142 'core:e/search' => 'fa-search',
143 'core:e/select_all' => 'fa-arrows-h',
144 'core:e/show_invisible_characters' => 'fa-eye',
145 'core:e/source_code' => 'fa-code',
146 'core:e/special_character' => 'fa-heart',
147 'core:e/spellcheck' => 'fa-check',
148 'core:e/split_cells' => 'fa-columns',
149 'core:e/strikethrough' => 'fa-strikethrough',
150 'core:e/styleprops' => 'fa-info',
151 'core:e/subscript' => 'fa-subscript',
152 'core:e/superscript' => 'fa-superscript',
153 'core:e/table_props' => 'fa-table',
154 'core:e/table' => 'fa-table',
155 'core:e/template' => 'fa-sticky-note',
156 'core:e/text_color_picker' => 'fa-paint-brush',
157 'core:e/text_color' => 'fa-paint-brush',
158 'core:e/text_highlight_picker' => 'fa-lightbulb-o',
159 'core:e/text_highlight' => 'fa-lightbulb-o',
160 'core:e/tick' => 'fa-check',
161 'core:e/toggle_blockquote' => 'fa-quote-left',
162 'core:e/underline' => 'fa-underline',
163 'core:e/undo' => 'fa-undo',
164 'core:e/visual_aid' => 'fa-universal-access',
165 'core:e/visual_blocks' => 'fa-audio-description',
166 'core:f/archive' => 'fa-file-zip-o',
95b06c13 167 'core:f/audio' => 'fa-file-audio-o',
95b06c13 168 'core:f/avi' => 'fa-file-movie-o',
95b06c13 169 'core:f/base' => 'fa-file-o',
95b06c13 170 'core:f/bmp' => 'fa-file-image-o',
95b06c13 171 'core:f/calc' => 'fa-file-excel-o',
95b06c13 172 'core:f/chart' => 'fa-bar-chart',
95b06c13 173 'core:f/database' => 'fa-database',
95b06c13 174 'core:f/document' => 'fa-file',
95b06c13 175 'core:f/draw' => 'fa-file-image-o',
95b06c13 176 'core:f/eps' => 'fa-file-pdf-o',
95b06c13 177 'core:f/epub' => 'fa-book',
95b06c13 178 'core:f/flash' => 'fa-flash',
3c885071 179 'core:f/folder' => 'fa-folder-o',
3c885071 180 'core:f/folder-open' => 'fa-folder-open-o',
95b06c13 181 'core:f/gif' => 'fa-file-image-o',
95b06c13 182 'core:f/html' => 'fa-file-code-o',
95b06c13 183 'core:f/image' => 'fa-file-image-o',
95b06c13 184 'core:f/impress' => 'fa-file-powerpoint-o',
95b06c13 185 'core:f/isf' => 'fa-file-image-o',
95b06c13 186 'core:f/jpeg' => 'fa-file-image-o',
95b06c13 187 'core:f/markup' => 'fa-file-code-o',
95b06c13 188 'core:f/math' => 'fa-calculator',
95b06c13 189 'core:f/moodle' => 'fa-graduation-cap',
95b06c13 190 'core:f/mp3' => 'fa-file-audio-o',
95b06c13 191 'core:f/mpeg' => 'fa-file-video-o',
95b06c13 192 'core:f/oth' => 'fa-file-o',
95b06c13 193 'core:f/pdf' => 'fa-file-pdf-o',
95b06c13 194 'core:f/png' => 'fa-file-image-o',
95b06c13 195 'core:f/powerpoint' => 'fa-file-powerpoint-o',
95b06c13 196 'core:f/psd' => 'fa-file-image-o',
95b06c13 197 'core:f/publisher' => 'fa-file-image-o',
95b06c13 198 'core:f/quicktime' => 'fa-file-video-o',
95b06c13 199 'core:f/sourcecode' => 'fa-file-code-o',
95b06c13 200 'core:f/spreadsheet' => 'fa-file-excel-o',
95b06c13 201 'core:f/text' => 'fa-file-text-o',
95b06c13 202 'core:f/tiff' => 'fa-file-image-o',
95b06c13 203 'core:f/unknown' => 'fa-file-o',
95b06c13 204 'core:f/video' => 'fa-file-video-o',
95b06c13 205 'core:f/wav' => 'fa-file-audio-o',
95b06c13 206 'core:f/wmv' => 'fa-file-video-o',
95b06c13 207 'core:f/writer' => 'fa-file-word-o',
95b06c13
DW
208 'theme:fp/add_file' => 'fa-file-o',
209 'theme:fp/alias' => 'fa-link',
210 'theme:fp/check' => 'fa-check',
3c885071 211 'theme:fp/create_folder' => 'fa-folder-o',
95b06c13
DW
212 'theme:fp/cross' => 'fa-remove',
213 'theme:fp/download_all' => 'fa-download',
214 'theme:fp/help' => 'fa-question-circle',
215 'theme:fp/link' => 'fa-link',
216 'theme:fp/link_sm' => 'fa-link',
217 'theme:fp/logout' => 'fa-sign-out',
218 'theme:fp/path_folder' => 'fa-folder',
219 'theme:fp/path_folder_rtl' => 'fa-folder',
220 'theme:fp/refresh' => 'fa-refresh',
221 'theme:fp/search' => 'fa-search',
222 'theme:fp/setting' => 'fa-cog',
223 'theme:fp/view_icon_active' => 'fa-th',
224 'theme:fp/view_list_active' => 'fa-list',
225 'theme:fp/view_tree_active' => 'fa-folder',
226 'core:i/assignroles' => 'fa-user-plus',
227 'core:i/backup' => 'fa-file-zip-o',
228 'core:i/badge' => 'fa-shield',
229 'core:i/calc' => 'fa-calculator',
230 'core:i/calendar' => 'fa-calendar',
231 'core:i/caution' => 'fa-exclamation',
232 'core:i/checked' => 'fa-check',
233 'core:i/checkpermissions' => 'fa-unlock-alt',
234 'core:i/cohort' => 'fa-users',
235 'core:i/competencies' => 'fa-check-square-o',
236 'core:i/completion-auto-enabled' => 'fa-check-square',
237 'core:i/completion-auto-fail' => 'fa-square-o',
238 'core:i/completion-auto-n' => 'fa-square-o',
239 'core:i/completion-auto-pass' => 'fa-check-square',
240 'core:i/completion-auto-y' => 'fa-check-square',
241 'core:i/completion-manual-enabled' => 'fa-square-o',
242 'core:i/completion-manual-y' => 'fa-check-square',
243 'core:i/completion-manual-n' => 'fa-minus-square',
244 'core:i/completion-self' => 'fa-user-o',
245 'core:i/lock' => 'fa-lock',
246 'core:i/courseevent' => 'fa-calendar',
247 'core:i/course' => 'fa-globe',
248 'core:i/db' => 'fa-database',
249 'core:i/delete' => 'fa-trash',
250 'core:i/down' => 'fa-arrow-down',
251 'core:i/dragdrop' => 'fa-arrows',
252 'core:i/duration' => 'fa-clock',
253 'core:i/edit' => 'fa-pencil',
254 'core:i/email' => 'fa-envelope',
255 'core:i/enrolmentsuspended' => 'fa-user-circle',
256 'core:i/enrolusers' => 'fa-user-plus',
257 'core:i/expired' => 'fa-exclamation',
258 'core:i/export' => 'fa-level-down',
259 'core:i/files' => 'fa-file',
260 'core:i/filter' => 'fa-filter',
261 'core:i/flagged' => 'fa-flag',
262 'core:i/folder' => 'fa-folder',
263 'core:i/grade_correct' => 'fa-check',
264 'core:i/grade_incorrect' => 'fa-remove',
265 'core:i/grade_partiallycorrect' => 'fa-check-square',
266 'core:i/grades' => 'fa-graduation-cap',
267 'core:i/groupevent' => 'fa-group',
268 'core:i/groupn' => 'fa-user',
269 'core:i/group' => 'fa-users',
270 'core:i/groups' => 'fa-user-circle-o',
271 'core:i/groupv' => 'fa-users',
272 'core:i/hide' => 'fa-eye',
273 'core:i/heirarchylock' => 'fa-lock',
274 'core:i/import' => 'fa-level-up',
275 'core:i/info' => 'fa-info',
276 'core:i/invalid' => 'fa-exclamation',
277 'core:i/item' => 'fa-circle',
278 'core:i/loading' => 'fa-circle-o-notch fa-spin',
279 'core:i/loading_small' => 'fa-circle-o-notch fa-spin',
280 'core:i/lock' => 'fa-lock',
281 'core:i/log' => 'fa-list-alt',
282 'core:i/mahara_host' => 'fa-id-badge',
283 'core:i/manual_item' => 'fa-square-o',
284 'core:i/marked' => 'fa-check-square',
285 'core:i/marker' => 'fa-user-o',
286 'core:i/mean' => 'fa-calculator',
287 'core:i/menu' => 'fa-ellipsis-v',
288 'core:i/mnethost' => 'fa-external-link',
289 'core:i/moodle_host' => 'fa-graduation-cap',
290 'core:i/move_2d' => 'fa-arrows',
291 'core:i/navigationitem' => 'fa-angle-right',
292 'core:i/ns_red_mark' => 'fa-remove',
293 'core:i/new' => 'fa-plus',
294 'core:i/news' => 'fa-newspaper',
295 'core:i/nosubcat' => 'fa-plus-square-o',
296 'core:i/notifications' => 'fa-bell',
297 'core:i/open' => 'fa-folder-open',
298 'core:i/outcomes' => 'fa-tasks',
299 'core:i/payment' => 'fa-money',
300 'core:i/permissionlock' => 'fa-lock',
301 'core:i/permissions' => 'fa-pencil-square-o',
302 'core:i/persona_sign_in_black' => 'fa-male',
303 'core:i/portfolio' => 'fa-id-badge',
304 'core:i/preview' => 'fa-search-plus',
305 'core:i/progressbar' => 'fa-spinner fa-spin',
306 'core:i/publish' => 'fa-share',
307 'core:i/questions' => 'fa-question',
308 'core:i/reload' => 'fa-refresh',
309 'core:i/report' => 'fa-area-chart',
310 'core:i/repository' => 'fa-hdd-o',
311 'core:i/restore' => 'fa-level-up',
312 'core:i/return' => 'fa-arrow-left',
313 'core:i/risk_config' => 'fa-cog',
314 'core:i/risk_managetrust' => 'fa-exclamation-triangle',
315 'core:i/risk_personal' => 'fa-user',
316 'core:i/risk_spam' => 'fa-trash',
317 'core:i/risk_xss' => 'fa-exchange',
318 'core:i/role' => 'fa-user-md',
319 'core:i/rss' => 'fa-rss',
24a6b594 320 'core:i/rsssitelogo' => 'fa-graduation-cap',
95b06c13
DW
321 'core:i/scales' => 'fa-balance-scale',
322 'core:i/scheduled' => 'fa-calendar-check-o',
323 'core:i/search' => 'fa-search',
324 'core:i/settings' => 'fa-cogs',
325 'core:i/show' => 'fa-eye-slash',
326 'core:i/siteevent' => 'fa-share-alt',
327 'core:i/starrating' => 'fa-star',
328 'core:i/stats' => 'fa-line-chart',
329 'core:i/switch' => 'fa-exchange',
330 'core:i/switchrole' => 'fa-user-secret',
331 'core:i/twoway' => 'fa-arrows-h',
332 'core:i/unchecked' => 'fa-square-o',
333 'core:i/unflagged' => 'fa-flag-o',
334 'core:i/unlock' => 'fa-unlock',
335 'core:i/up' => 'fa-arrow-up',
336 'core:i/userevent' => 'fa-user',
337 'core:i/user' => 'fa-user',
338 'core:i/users' => 'fa-users',
339 'core:i/valid' => 'fa-check-square-o',
340 'core:i/warning' => 'fa-exclamation',
341 'core:i/withsubcat' => 'fa-plus-square',
342 'core:m/USD' => 'fa-usd',
343 'core:t/addcontact' => 'fa-address-card',
344 'core:t/add' => 'fa-plus',
345 'core:t/approve' => 'fa-thumbs-up',
346 'core:t/assignroles' => 'fa-user-circle',
347 'core:t/award' => 'fa-trophy',
348 'core:t/backpack' => 'fa-shopping-bag',
349 'core:t/backup' => 'fa-arrow-circle-down',
350 'core:t/block' => 'fa-commenting-o',
351 'core:t/block_to_dock_rtl' => 'fa-chevron-right',
352 'core:t/block_to_dock' => 'fa-chevron-left',
353 'core:t/calc_off' => 'fa-times',
354 'core:t/calc' => 'fa-calculator',
355 'core:t/check' => 'fa-check',
356 'core:t/cohort' => 'fa-users',
357 'core:t/collapsed_empty_rtl' => 'fa-plus-square-o',
358 'core:t/collapsed_empty' => 'fa-plus-square-o',
359 'core:t/collapsed_rtl' => 'fa-plus-square',
360 'core:t/collapsed' => 'fa-plus-square',
361 'core:t/contextmenu' => 'fa-cog',
362 'core:t/copy' => 'fa-copy',
363 'core:t/delete' => 'fa-trash',
364 'core:t/dockclose' => 'fa-window-close',
365 'core:t/dock_to_block_rtl' => 'fa-chevron-right',
366 'core:t/dock_to_block' => 'fa-chevron-left',
367 'core:t/download' => 'fa-download',
368 'core:t/down' => 'fa-arrow-down',
369 'core:t/dropdown' => 'fa-cog',
370 'core:t/editinline' => 'fa-pencil',
371 'core:t/edit_menu' => 'fa-cog',
372 'core:t/editstring' => 'fa-pencil',
373 'core:t/edit' => 'fa-cog',
374 'core:t/emailno' => 'fa-envelope-o',
375 'core:t/email' => 'fa-envelope',
376 'core:t/enrolusers' => 'fa-user-plus',
377 'core:t/expanded' => 'fa-caret-down',
378 'core:t/go' => 'fa-arrow-right',
379 'core:t/grades' => 'fa-graduation-cap',
380 'core:t/groupn' => 'fa-users',
381 'core:t/groups' => 'fa-users',
382 'core:t/groupv' => 'fa-users',
383 'core:t/hide' => 'fa-eye',
384 'core:t/left' => 'fa-arrow-left',
385 'core:t/less' => 'fa-caret-up',
386 'core:t/locked' => 'fa-lock',
387 'core:t/lock' => 'fa-lock',
388 'core:t/locktime' => 'fa-lock',
389 'core:t/markasread' => 'fa-check',
390 'core:t/messages' => 'fa-comments',
391 'core:t/message' => 'fa-comment',
392 'core:t/more' => 'fa-caret-down',
393 'core:t/move' => 'fa-arrows',
394 'core:t/passwordunmask-edit' => 'fa-pencil',
395 'core:t/passwordunmask-reveal' => 'fa-eye',
396 'core:t/portfolioadd' => 'fa-plus',
397 'core:t/preferences' => 'fa-wrench',
398 'core:t/preview' => 'fa-search-plus',
399 'core:t/print' => 'fa-print',
400 'core:t/removecontact' => 'fa-user-times',
401 'core:t/reset' => 'fa-repeat',
402 'core:t/restore' => 'fa-arrow-circle-up',
403 'core:t/right' => 'fa-arrow-right',
404 'core:t/show' => 'fa-eye-slash',
405 'core:t/sort_asc' => 'fa-sort-asc',
406 'core:t/sort_desc' => 'fa-sort-desc',
407 'core:t/sort' => 'fa-sort',
408 'core:t/stop' => 'fa-stop',
409 'core:t/switch_minus' => 'fa-minus',
410 'core:t/switch_plus' => 'fa-plus',
411 'core:t/switch_whole' => 'fa-square-o',
412 'core:t/unblock' => 'fa-commenting',
413 'core:t/unlocked' => 'fa-unlock-alt',
414 'core:t/unlock' => 'fa-unlock',
415 'core:t/up' => 'fa-arrow-up',
416 'core:t/user' => 'fa-user',
417 'core:t/viewdetails' => 'fa-list',
418 ];
419 }
e330b1c2
DW
420
421 private $map = [];
422
423 /**
424 * Overridable function to get a mapping of all icons.
425 * Default is to do no mapping.
426 */
427 public function get_icon_name_map() {
428 if ($this->map === []) {
429 $this->map = $this->get_core_icon_map();
430 $callback = 'get_fontawesome_icon_map';
431
432 if ($pluginsfunction = get_plugins_with_function($callback)) {
433 foreach ($pluginsfunction as $plugintype => $plugins) {
434 foreach ($plugins as $pluginfunction) {
435 $pluginmap = $pluginfunction();
436 $this->map += $pluginmap;
437 }
438 }
439 }
440
441 }
442 return $this->map;
443 }
444
445
446 public function get_amd_name() {
447 return 'core/icon_system_fontawesome';
448 }
449
450 public function render_pix_icon(renderer_base $output, pix_icon $icon) {
451 $subtype = 'pix_icon_fontawesome';
452 $subpix = new $subtype($icon);
453 $data = $subpix->export_for_template($output);
454
455 return $output->render_from_template('core/pix_icon_fontawesome', $data);
456 }
457
95b06c13
DW
458}
459