Elgg  Version master
AddFontAwesomeClassesHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Icons;
4 
11 
17  public const array COMMON_ICONS = [
18  'delete-alt' => 'circle-xmark',
19  'delete' => 'xmark',
20  'grid' => 'table-cells',
21  'info' => 'info-circle',
22  'mail' => 'envelope-regular',
23  'refresh' => 'arrow-rotate-right',
24  'remove' => 'times',
25  'settings' => 'wrench',
26  'settings-alt' => 'gear',
27  ];
28 
34  public const array BRANDS = [
35  '42-group',
36  '500px',
37  'accessible-icon',
38  'accusoft',
39  'adn',
40  'adversal',
41  'affiliatetheme',
42  'airbnb',
43  'algolia',
44  'alipay',
45  'amazon',
46  'amazon-pay',
47  'amilia',
48  'android',
49  'angellist',
50  'angrycreative',
51  'angular',
52  'app-store',
53  'app-store-ios',
54  'apper',
55  'apple',
56  'apple-pay',
57  'artstation',
58  'asymmetrik',
59  'atlassian',
60  'audible',
61  'autoprefixer',
62  'avianex',
63  'aviato',
64  'aws',
65  'bandcamp',
66  'battle-net',
67  'behance',
68  'bilibili',
69  'bimobject',
70  'bitbucket',
71  'bitcoin',
72  'bity',
73  'black-tie',
74  'blackberry',
75  'blogger',
76  'blogger-b',
77  'bluesky',
78  'bluetooth',
79  'bluetooth-b',
80  'bootstrap',
81  'bots',
82  'brave',
83  'brave-reverse',
84  'btc',
85  'buffer',
86  'buromobelexperte',
87  'buy-n-large',
88  'buysellads',
89  'canadian-maple-leaf',
90  'cash-app',
91  'cc-amazon-pay',
92  'cc-amex',
93  'cc-apple-pay',
94  'cc-diners-club',
95  'cc-discover',
96  'cc-jcb',
97  'cc-mastercard',
98  'cc-paypal',
99  'cc-stripe',
100  'cc-visa',
101  'centercode',
102  'centos',
103  'chrome',
104  'chromecast',
105  'cloudflare',
106  'cloudscale',
107  'cloudsmith',
108  'cloudversify',
109  'cmplid',
110  'codepen',
111  'codiepie',
112  'confluence',
113  'connectdevelop',
114  'contao',
115  'cotton-bureau',
116  'cpanel',
117  'creative-commons',
118  'creative-commons-by',
119  'creative-commons-nc',
120  'creative-commons-nc-eu',
121  'creative-commons-nc-jp',
122  'creative-commons-nd',
123  'creative-commons-pd',
124  'creative-commons-pd-alt',
125  'creative-commons-remix',
126  'creative-commons-sa',
127  'creative-commons-sampling',
128  'creative-commons-sampling-plus',
129  'creative-commons-share',
130  'creative-commons-zero',
131  'critical-role',
132  'css',
133  'css3',
134  'css3-alt',
135  'cuttlefish',
136  'd-and-d',
137  'd-and-d-beyond',
138  'dailymotion',
139  'dart-lang',
140  'dashcube',
141  'debian',
142  'deezer',
143  'delicious',
144  'deploydog',
145  'deskpro',
146  'dev',
147  'deviantart',
148  'dhl',
149  'diaspora',
150  'digg',
151  'digital-ocean',
152  'discord',
153  'discourse',
154  'disqus',
155  'dochub',
156  'docker',
157  'draft2digital',
158  'dribbble',
159  'dropbox',
160  'drupal',
161  'duolingo',
162  'dyalog',
163  'earlybirds',
164  'ebay',
165  'edge',
166  'edge-legacy',
167  'elementor',
168  'eleventy',
169  'ello',
170  'ember',
171  'empire',
172  'envira',
173  'erlang',
174  'ethereum',
175  'etsy',
176  'evernote',
177  'expeditedssl',
178  'facebook',
179  'facebook-f',
180  'facebook-messenger',
181  'fantasy-flight-games',
182  'fedex',
183  'fedora',
184  'figma',
185  'files-pinwheel',
186  'firefox',
187  'firefox-browser',
188  'first-order',
189  'first-order-alt',
190  'firstdraft',
191  'flickr',
192  'flipboard',
193  'flutter',
194  'fly',
195  'font-awesome',
196  'fonticons',
197  'fonticons-fi',
198  'fort-awesome',
199  'fort-awesome-alt',
200  'forumbee',
201  'foursquare',
202  'free-code-camp',
203  'freebsd',
204  'fulcrum',
205  'galactic-republic',
206  'galactic-senate',
207  'get-pocket',
208  'gg',
209  'gg-circle',
210  'git',
211  'git-alt',
212  'github',
213  'github-alt',
214  'gitkraken',
215  'gitlab',
216  'gitter',
217  'glide',
218  'glide-g',
219  'gofore',
220  'golang',
221  'goodreads',
222  'goodreads-g',
223  'google',
224  'google-drive',
225  'google-pay',
226  'google-play',
227  'google-plus',
228  'google-plus-g',
229  'google-scholar',
230  'google-wallet',
231  'gratipay',
232  'grav',
233  'gripfire',
234  'grunt',
235  'guilded',
236  'gulp',
237  'hacker-news',
238  'hackerrank',
239  'hashnode',
240  'hips',
241  'hire-a-helper',
242  'hive',
243  'hooli',
244  'hornbill',
245  'hotjar',
246  'houzz',
247  'html5',
248  'hubspot',
249  'ideal',
250  'imdb',
251  'instagram',
252  'instalod',
253  'intercom',
254  'internet-explorer',
255  'invision',
256  'ioxhost',
257  'itch-io',
258  'itunes',
259  'itunes-note',
260  'java',
261  'jedi-order',
262  'jenkins',
263  'jira',
264  'joget',
265  'joomla',
266  'js',
267  'jsfiddle',
268  'jxl',
269  'kaggle',
270  'kakao-talk',
271  'keybase',
272  'keycdn',
273  'kickstarter',
274  'kickstarter-k',
275  'korvue',
276  'laravel',
277  'lastfm',
278  'leanpub',
279  'less',
280  'letterboxd',
281  'line',
282  'linkedin',
283  'linkedin-in',
284  'linktree',
285  'linode',
286  'linux',
287  'lumon',
288  'lumon-drop',
289  'lyft',
290  'magento',
291  'mailchimp',
292  'mandalorian',
293  'markdown',
294  'mastodon',
295  'maxcdn',
296  'mdb',
297  'medapps',
298  'medium',
299  'medrt',
300  'meetup',
301  'megaport',
302  'mendeley',
303  'meta',
304  'microblog',
305  'microsoft',
306  'mintbit',
307  'mix',
308  'mixcloud',
309  'mixer',
310  'mizuni',
311  'modx',
312  'monero',
313  'napster',
314  'neos',
315  'nfc-directional',
316  'nfc-symbol',
317  'nimblr',
318  'node',
319  'node-js',
320  'notion',
321  'npm',
322  'ns8',
323  'nutritionix',
324  'octopus-deploy',
325  'odnoklassniki',
326  'odysee',
327  'old-republic',
328  'openai',
329  'opencart',
330  'openid',
331  'opensuse',
332  'opera',
333  'optin-monster',
334  'orcid',
335  'osi',
336  'padlet',
337  'page4',
338  'pagelines',
339  'palfed',
340  'pandora',
341  'patreon',
342  'paypal',
343  'perbyte',
344  'periscope',
345  'phabricator',
346  'phoenix-framework',
347  'phoenix-squadron',
348  'php',
349  'pied-piper',
350  'pied-piper-alt',
351  'pied-piper-hat',
352  'pied-piper-pp',
353  'pinterest',
354  'pinterest-p',
355  'pix',
356  'pixelfed',
357  'pixiv',
358  'playstation',
359  'product-hunt',
360  'pushed',
361  'python',
362  'qq',
363  'quinscape',
364  'quora',
365  'r-project',
366  'raspberry-pi',
367  'ravelry',
368  'react',
369  'reacteurope',
370  'readme',
371  'rebel',
372  'red-river',
373  'reddit',
374  'reddit-alien',
375  'redhat',
376  'renren',
377  'replyd',
378  'researchgate',
379  'resolving',
380  'rev',
381  'rocketchat',
382  'rockrms',
383  'rust',
384  'safari',
385  'salesforce',
386  'sass',
387  'schlix',
388  'screenpal',
389  'scribd',
390  'searchengin',
391  'sellcast',
392  'sellsy',
393  'servicestack',
394  'shirtsinbulk',
395  'shoelace',
396  'shopify',
397  'shopware',
398  'signal-messenger',
399  'simplybuilt',
400  'sistrix',
401  'sith',
402  'sitrox',
403  'sketch',
404  'skyatlas',
405  'skype',
406  'slack',
407  'slideshare',
408  'snapchat',
409  'soundcloud',
410  'sourcetree',
411  'space-awesome',
412  'speakap',
413  'speaker-deck',
414  'spotify',
415  'square-behance',
416  'square-bluesky',
417  'square-dribbble',
418  'square-facebook',
419  'square-figma',
420  'square-font-awesome',
421  'square-font-awesome-stroke',
422  'square-git',
423  'square-github',
424  'square-gitlab',
425  'square-google-plus',
426  'square-hacker-news',
427  'square-instagram',
428  'square-js',
429  'square-lastfm',
430  'square-letterboxd',
431  'square-linkedin',
432  'square-odnoklassniki',
433  'square-pied-piper',
434  'square-pinterest',
435  'square-reddit',
436  'square-snapchat',
437  'square-steam',
438  'square-threads',
439  'square-tumblr',
440  'square-twitter',
441  'square-upwork',
442  'square-viadeo',
443  'square-vimeo',
444  'square-web-awesome',
445  'square-web-awesome-stroke',
446  'square-whatsapp',
447  'square-x-twitter',
448  'square-xing',
449  'square-youtube',
450  'squarespace',
451  'stack-exchange',
452  'stack-overflow',
453  'stackpath',
454  'staylinked',
455  'steam',
456  'steam-symbol',
457  'sticker-mule',
458  'strava',
459  'stripe',
460  'stripe-s',
461  'stubber',
462  'studiovinari',
463  'stumbleupon',
464  'stumbleupon-circle',
465  'superpowers',
466  'supple',
467  'suse',
468  'swift',
469  'symfony',
470  'teamspeak',
471  'telegram',
472  'tencent-weibo',
473  'tex',
474  'the-red-yeti',
475  'themeco',
476  'themeisle',
477  'think-peaks',
478  'threads',
479  'tidal',
480  'tiktok',
481  'trade-federation',
482  'trello',
483  'tumblr',
484  'twitch',
485  'twitter',
486  'typo3',
487  'uber',
488  'ubuntu',
489  'uikit',
490  'umbraco',
491  'uncharted',
492  'uniregistry',
493  'unity',
494  'unsplash',
495  'untappd',
496  'ups',
497  'upwork',
498  'usb',
499  'usps',
500  'ussunnah',
501  'vaadin',
502  'viacoin',
503  'viadeo',
504  'viber',
505  'vimeo',
506  'vimeo-v',
507  'vine',
508  'vk',
509  'vnv',
510  'vsco',
511  'vuejs',
512  'w3c',
513  'watchman-monitoring',
514  'waze',
515  'web-awesome',
516  'webflow',
517  'weebly',
518  'weibo',
519  'weixin',
520  'whatsapp',
521  'whmcs',
522  'wikipedia-w',
523  'windows',
524  'wirsindhandwerk',
525  'wix',
526  'wizards-of-the-coast',
527  'wodu',
528  'wolf-pack-battalion',
529  'wordpress',
530  'wordpress-simple',
531  'wpbeginner',
532  'wpexplorer',
533  'wpforms',
534  'wpressr',
535  'x-twitter',
536  'xbox',
537  'xing',
538  'y-combinator',
539  'yahoo',
540  'yammer',
541  'yandex',
542  'yandex-international',
543  'yarn',
544  'yelp',
545  'yoast',
546  'youtube',
547  'zhihu',
548  ];
549 
557  public function __invoke(\Elgg\Event $event) {
558  $vars = $event->getValue();
559 
561 
562  foreach ($classes as $icon_class) {
563  if (!preg_match_all('/^elgg-icon-(.+)/i', $icon_class)) {
564  continue;
565  }
566 
567  // strip elgg-icon-
568  $base_icon = preg_replace('/^elgg-icon-(.+)/i', '$1', $icon_class);
569 
570  // convert common icons
571  $base_icon = elgg_extract($base_icon, self::COMMON_ICONS, $base_icon);
572 
573  // map solid/regular/light/thin iconnames to correct classes
574  if (preg_match('/.*-solid$/', $base_icon)) {
575  $base_icon = preg_replace('/(.*)-solid$/', '$1', $base_icon);
576  $classes[] = 'fa-solid';
577  } elseif (preg_match('/.*-regular$/', $base_icon)) {
578  $base_icon = preg_replace('/(.*)-regular$/', '$1', $base_icon);
579  $classes[] = 'fa-regular';
580  } elseif (preg_match('/.*-light$/', $base_icon)) {
581  // currently light is only available in FontAwesome 7 Pro
582  $base_icon = preg_replace('/(.*)-light$/', '$1', $base_icon);
583  $classes[] = 'fa-light';
584  } elseif (preg_match('/.*-thin$/', $base_icon)) {
585  // currently thin is only available in FontAwesome 7 Pro
586  $base_icon = preg_replace('/(.*)-thin$/', '$1', $base_icon);
587  $classes[] = 'fa-thin';
588  } elseif (in_array($base_icon, self::BRANDS)) {
589  $classes[] = 'fa-brands';
590  } else {
591  $classes[] = 'fa-solid';
592  }
593 
594  $classes[] = "fa-{$base_icon}";
595  }
596 
597  $vars['class'] = array_unique($classes);
598 
599  return $vars;
600  }
601 }
$vars
Definition: theme.php:3
Models an event passed to event handlers.
Definition: Event.php:11
__invoke(\Elgg\Event $event)
Converts icon classes to correct FontAwesome classes.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
Definition: item.php:48
elgg_extract_class(array $array, array|string $existing=[], string $extract_key='class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:269
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:246
$icon_class
Definition: record.php:73
$classes
Definition: users.php:29