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