|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Helper; |
| 4 | + |
| 5 | +/** |
| 6 | + * Class LinkIconMapper |
| 7 | + * |
| 8 | + * @package App\Helper |
| 9 | + */ |
| 10 | +class LinkIconMapper |
| 11 | +{ |
| 12 | + /** @var string Default icon as fallback if no specific icon was found */ |
| 13 | + public static $default_icon = 'fa fa-link'; |
| 14 | + |
| 15 | + /** @var array Array holding the pattern => icon map, sorted alphabetically */ |
| 16 | + public static $icon_map = [ |
| 17 | + '500px\.com' => 'fab fa-500px', |
| 18 | + 'adobe\.com' => 'fab fa-adobe', |
| 19 | + 'aws\.amazon\.com' => 'fab fa-aws', // put before amazon pattern to keep it easy |
| 20 | + 'amazon\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-amazon', // match amazon with every TLD |
| 21 | + 'angel\.co' => 'fab fa-angellist', |
| 22 | + 'itunes\.apple\.com\/app' => 'fab fa-app-store', |
| 23 | + 'apple\.com' => 'fab fa-apple', |
| 24 | + 'artstation\.com' => 'fab fa-artstation', |
| 25 | + 'atlassian\.(com|net)' => 'fab fa-atlassian', |
| 26 | + 'bandcamp\.com' => 'fab fa-bandcamp', |
| 27 | + 'behance\.net' => 'fab fa-behance', |
| 28 | + 'bitbucket\.org' => 'fab fa-bitbucket', |
| 29 | + 'blockchain\.com' => 'fab fa-bitcoin', |
| 30 | + 'blogger\.com' => 'fab fa-blogger-b', |
| 31 | + 'chrome\.google\.com\/webstore' => 'fab fa-chrome', |
| 32 | + 'codepen\.io' => 'fab fa-codepen', |
| 33 | + 'dev\.to' => 'fab fa-dev', |
| 34 | + 'deviantart\.com' => 'fab fa-deviantart', |
| 35 | + 'digitalocean\.com' => 'fab fa-digital-ocean', |
| 36 | + '(discordapp\.com|discord\.gg)' => 'fab fa-discord', |
| 37 | + 'meta\.discourse\.org' => 'fab fa-discourse', |
| 38 | + 'docker\.com' => 'fab fa-docker', |
| 39 | + 'dribbble\.com' => 'fab fa-dribbble', |
| 40 | + 'dropbox\.com' => 'fab fa-dropbox', |
| 41 | + 'drupal\.org' => 'fab fa-drupal', |
| 42 | + 'ebay\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-ebay', |
| 43 | + 'ello\.co' => 'fab fa-ello', |
| 44 | + 'etsy\.com' => 'fab fa-etsy', |
| 45 | + '(facebook\.com|fb\.me)' => 'fab fa-facebook-f', |
| 46 | + 'addons\.mozilla\.org\/[a-zA-Z-_]+\/firefox' => 'fab fa-firefox', |
| 47 | + 'figma\.com' => 'fab fa-figma', |
| 48 | + 'flickr\.com' => 'fab fa-flickr', |
| 49 | + '(flipboard\.com|flip\.it)' => 'fab fa-flipboard', |
| 50 | + 'foursquare\.com' => 'fab fa-foursquare', |
| 51 | + '(getpocket\.com|pocket\.co)' => 'fab fa-get-pocket', |
| 52 | + '(github\.com|github\.io)' => 'fab fa-github', |
| 53 | + 'gitlab\.com' => 'fab fa-gitlab', |
| 54 | + 'gitter\.im' => 'fab fa-gitter', |
| 55 | + 'drive\.google\.com' => 'fab fa-google-drive', |
| 56 | + 'play\.google\.com' => 'fab fa-google-play', |
| 57 | + 'google\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-google', |
| 58 | + 'news\.ycombinator\.com' => 'fab fa-hacker-news', |
| 59 | + 'hackerrank\.com' => 'fab fa-hackerrank', |
| 60 | + 'houzz\.com' => 'fab fa-houzz', |
| 61 | + 'imdb\.com' => 'fab fa-imdb', |
| 62 | + 'instagram\.com' => 'fab fa-instagram', |
| 63 | + 'invisionapp\.com' => 'fab fa-invision', |
| 64 | + 'jsfiddle\.net' => 'fab fa-jsfiddle', |
| 65 | + 'kaggle\.com' => 'fab fa-kaggle', |
| 66 | + 'keybase\.io' => 'fab fa-keybase', |
| 67 | + 'kickstarter\.com' => 'fab fa-kickstarter', |
| 68 | + 'last\.fm' => 'fab fa-lastfm', |
| 69 | + 'leanpub\.com' => 'fab fa-leanpub', |
| 70 | + 'linkedin\.com' => 'fab fa-linkedin-in', |
| 71 | + 'mastodon\.social' => 'fab fa-mastodon', |
| 72 | + 'medium\.com' => 'fab fa-medium-m', |
| 73 | + 'meetup\.com' => 'fab fa-meetup', |
| 74 | + 'microsoft\.com' => 'fab fa-microsoft', |
| 75 | + 'mixcloud\.com' => 'fab fa-mixcloud', |
| 76 | + 'store\.nintendo\.com' => 'fab fa-nintendo-switch', |
| 77 | + 'npmjs\.com' => 'fab fa-npm', |
| 78 | + 'openid\.net' => 'fab fa-openid', |
| 79 | + 'opensource\.org' => 'fab fa-osi', |
| 80 | + 'patreon\.com' => 'fab fa-patreon ', |
| 81 | + 'paypal\.([a-zA-Z]*(\.)?[a-zA-Z]*)' => 'fab fa-paypal', |
| 82 | + 'periscope\.tv' => 'fab fa-periscope', |
| 83 | + 'php\.net' => 'fab fa-php', |
| 84 | + 'pinterest\.com' => 'fab fa-pinterest', |
| 85 | + 'playstation\.com' => 'fab fa-playstation', |
| 86 | + 'producthunt\.com' => 'fab fa-product-hunt', |
| 87 | + 'python\.org' => 'fab fa-python', |
| 88 | + 'quora\.com' => 'fab fa-quora', |
| 89 | + 'readme\.io' => 'fab fa-readme', |
| 90 | + 'reddit\.com' => 'fab fa-reddit', |
| 91 | + 'researchgate\.net' => 'fab fa-researchgate', |
| 92 | + 'rocket\.chat' => 'fab fa-rocketchat', |
| 93 | + 'scribd\.com' => 'fab fa-scribd', |
| 94 | + 'skype\.com' => 'fab fa-skype', |
| 95 | + 'slack\.com' => 'fab fa-slack', |
| 96 | + 'slideshare\.net' => 'fab fa-slideshare', |
| 97 | + 'snapchat\.com' => 'fab fa-snapchat', |
| 98 | + 'soundcloud\.com' => 'fab fa-soundcloud', |
| 99 | + 'spotify\.com' => 'fab fa-spotify', |
| 100 | + 'squarespace\.com' => 'fab fa-squarespace', |
| 101 | + 'stackexchange\.com' => 'fab fa-stack-exchange', |
| 102 | + 'stackoverflow\.com' => 'fab fa-stack-overflow', |
| 103 | + '(steampowered\.com|steamcommunity\.com)' => 'fab fa-steam', |
| 104 | + 'strava\.com' => 'fab fa-strava', |
| 105 | + '(telegram\.org|t\.me)' => 'fab fa-telegram', |
| 106 | + 'trello\.com' => 'fab fa-trello', |
| 107 | + 'tripadvisor\.com' => 'fab fa-tripadvisor', |
| 108 | + 'tumblr\.com' => 'fab fa-tumblr', |
| 109 | + 'twitch\.tv' => 'fab fa-twitch', |
| 110 | + 'twitter\.com' => 'fab fa-twitter', |
| 111 | + 'vimeo\.com' => 'fab fa-vimeo', |
| 112 | + 'weibo\.com' => 'fab fa-weibo', |
| 113 | + 'wikipedia\.org' => 'fab fa-wikipedia-w', |
| 114 | + 'wordpress\.com' => 'fab fa-wordpress', |
| 115 | + 'wordpress\.org' => 'fab fa-wordpress-simple', |
| 116 | + 'xbox\.com' => 'fab fa-xbox', |
| 117 | + 'xing\.com' => 'fab fa-xing', |
| 118 | + 'yahoo\.com' => 'fab fa-yahoo', |
| 119 | + 'yelp\.com' => 'fab fa-yelp', |
| 120 | + 'youtube\.com' => 'fab fa-youtube', |
| 121 | + ]; |
| 122 | + |
| 123 | + /** |
| 124 | + * Check if the given url matches an icon |
| 125 | + * |
| 126 | + * @param $url |
| 127 | + * @return string |
| 128 | + */ |
| 129 | + public static function mapLink($url): string |
| 130 | + { |
| 131 | + foreach (self::$icon_map as $pattern => $icon) { |
| 132 | + if (preg_match('/' . $pattern . '/i', $url)) { |
| 133 | + return $icon; |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + return self::$default_icon; |
| 138 | + } |
| 139 | +} |
0 commit comments