source on its own array key, without adding the
* both `width` and `height` attributes, since these are added dnamically,
* before rendering the SVG code.
*
* All icons are assumed to have equal width and height, hence the option
* to only specify a `$size` parameter in the svg methods.
*
* @since 1.0.0
*/
class Varia_SVG_Icons {
/**
* Gets the SVG code for a given icon.
*/
public static function get_svg( $group, $icon, $size ) {
if ( 'ui' == $group ) {
$arr = self::$ui_icons;
} elseif ( 'social' == $group ) {
$arr = self::$social_icons;
} else {
$arr = array();
}
if ( array_key_exists( $icon, $arr ) ) {
$repl = sprintf( '\s*', '><', $svg ); // Remove white space between SVG tags.
return $svg;
}
return null;
}
/**
* Detects the social network from a URL and returns the SVG code for its icon.
*/
public static function get_social_link_svg( $uri, $size ) {
static $regex_map; // Only compute regex map once, for performance.
if ( ! isset( $regex_map ) ) {
$regex_map = array();
$map = &self::$social_icons_map; // Use reference instead of copy, to save memory.
foreach ( array_keys( self::$social_icons ) as $icon ) {
$domains = array_key_exists( $icon, $map ) ? $map[ $icon ] : array( sprintf( '%s.com', $icon ) );
$domains = array_map( 'trim', $domains ); // Remove leading/trailing spaces, to prevent regex from failing to match.
$domains = array_map( 'preg_quote', $domains );
$regex_map[ $icon ] = sprintf( '/(%s)/i', implode( '|', $domains ) );
}
}
foreach ( $regex_map as $icon => $regex ) {
if ( preg_match( $regex, $uri ) ) {
return self::get_svg( 'social', $icon, $size );
}
}
return null;
}
/**
* User Interface icons – svg sources.
*
* @var array
*/
static $ui_icons = array(
'link' => /* material-design – link */ '
',
'watch' => /* material-design – watch-later */ '
',
'archive' => /* material-design – folder */ '
',
'tag' => /* material-design – local_offer */ '
',
'comment' => /* material-design – comment */ '
',
'person' => /* material-design – person */ '
',
'edit' => /* material-design – edit */ '
',
'chevron_left' => /* material-design – chevron_left */ '
',
'chevron_right' => /* material-design – chevron_right */ '
',
'check' => /* material-design – check */ '
',
'arrow_drop_down_circle' => /* material-design – arrow_drop_down_circle */ '
',
'keyboard_arrow_down' => /* material-design – keyboard_arrow_down */ '
',
'keyboard_arrow_right' => /* material-design – keyboard_arrow_right */ '
',
'keyboard_arrow_left' => /* material-design – keyboard_arrow_left */ '
',
'arrow_drop_down_ellipsis' => /* custom – arrow_drop_down_ellipsis */ '
',
'shopping_cart' => /* material-design - shopping_cart */ '
',
);
/**
* Social Icons – domain mappings.
*
* By default, each Icon ID is matched against a .com TLD. To override this behavior,
* specify all the domains it covers (including the .com TLD too, if applicable).
*
* @var array
*/
static $social_icons_map = array(
'500px' => array(
'500px.com',
),
'amazon' => array(
'amazon.com',
'amazon.cn',
'amazon.in',
'amazon.fr',
'amazon.de',
'amazon.it',
'amazon.nl',
'amazon.es',
'amazon.co',
'amazon.ca',
),
'apple' => array(
'apple.com',
'itunes.com',
),
'bandcamp' => array(
'bandcamp.com',
),
'behance' => array(
'behance.net',
),
'codepen' => array(
'codepen.io',
),
'deviantart' => array(
'deviantart.com',
),
'digg' => array(
'digg.com',
),
'discord' => array(
'discord.gg',
'discordapp.com',
),
'dribbble' => array(
'dribbble.com',
),
'dropbox' => array(
'dropbox.com',
),
'etsy' => array(
'etsy.com',
),
'eventbrite' => array(
'eventbrite.com',
),
'facebook' => array(
'facebook.com',
'fb.me',
),
'feed' => array(
'feed',
),
'flickr' => array(
'flickr.com',
),
'foursquare' => array(
'foursquare.com',
),
'ghost' => array(
'ghost.org',
),
'github' => array(
'github.com',
),
'google' => array(
'google.com',
),
'google-plus' => array(
'plus.google.com',
),
'goodreads' => array(
'goodreads.com',
),
'instagram' => array(
'instagram.com',
),
'lastfm' => array(
'last.fm',
),
'linkedin' => array(
'linkedin.com',
),
'mail' => array(
'mailto:',
),
'mastodon' => array(
'mastodon.',
'mstdn.',
'counter.social',
'fosstodon.org',
'gc2.jp',
'hachyderm.io',
'infosec.exchange',
'mas.to',
'pawoo.net',
),
'medium' => array(
'medium.com',
),
'meetup' => array(
'meetup.com',
),
'nextdoor' => array(
'nextdoor.com',
),
'patreon' => array(
'patreon.com',
),
'phone' => array(
'tel:',
),
'pinterest' => array(
'pinterest.',
),
'pocket' => array(
'getpocket.com',
),
'ravelry' => array(
'ravelry.com',
),
'reddit' => array(
'reddit.com',
),
'skype' => array(
'skype.com',
'skype:',
),
'slideshare' => array(
'slideshare.net',
),
'snapchat' => array(
'snapchat.com',
),
'soundcloud' => array(
'soundcloud.com',
),
'spotify' => array(
'spotify.com',
),
'stackoverflow' => array(
'stackoverflow.com',
),
'strava' => array(
'strava.com',
),
'stumbleupon' => array(
'stumbleupon.com',
),
'telegram' => array(
'telegram.me',
),
'threads' => array(
'threads.net',
),
'tiktok' => array(
'tiktok.com',
),
'tumblr' => array(
'tumblr.com',
),
'twitch' => array(
'twitch.tv',
),
'twitter' => array(
'twitter.com',
),
'x' => array(
'x.com',
),
'vimeo' => array(
'vimeo.com',
),
'vk' => array(
'vk.com',
),
'whatsapp' => array(
'whatsapp.com',
),
'woocommerce' => array(
'woocommerce.com',
),
'wordpress' => array(
'wordpress.com',
'wordpress.org',
),
'youtube' => array(
'youtube.com',
),
'yelp' => array(
'yelp.com',
),
);
/**
* Social Icons – svg sources.
*
* @var array
*/
static $social_icons = array(
'500px' => '
',
'amazon' => '
',
'apple' => '
',
'bandcamp' => '
',
'behance' => '
',
'chain' => '
',
'codepen' => '
',
'deviantart' => '
',
'digg' => '
',
'discord' => '
',
'dribbble' => '
',
'dropbox' => '
',
'etsy' => '
',
'eventbrite' => '
',
'facebook' => '
',
'feed' => '
',
'flickr' => '
',
'foursquare' => '
',
'ghost' => '
',
'github' => '
',
'goodreads' => '
',
'google-plus' => '
',
'google' => '
',
'instagram' => '
',
'lastfm' => '
',
'linkedin' => '
',
'mail' => '
',
'mastodon' => '
',
'meetup' => '
',
'medium' => '
',
'nextdoor' => '
',
'patreon' => '
',
'pinterest' => '
',
'pocket' => '
',
'ravelry' => '
',
'reddit' => '
',
'skype' => '
',
'slideshare' => '
',
'snapchat' => '
',
'soundcloud' => '
',
'spotify' => '
',
'stackoverflow' => '
',
'strava' => '
',
'stumbleupon' => '
',
'telegram' => '
',
'threads' => '
',
'tiktok' => '
',
'tumblr' => '
',
'twitch' => '
',
'twitter' => '
',
'x' => '
',
'vimeo' => '
',
'vk' => '
',
'whatsapp' => '
',
'wordpress' => '
',
'yelp' => '
',
'youtube' => '
',
'phone' => '
',
);
}