\s*', '><', $svg); // Remove whitespace between SVG tags.
return $svg;
}
return null;
}
/**
* GET SOCIAL LINK SVG
* Detects the social network from a URL and returns the SVG code for its icon.
*
* @param string $uri The URL to retrieve SVG for.
* @since BlogBend 1.0.0
*
*/
public static function get_social_link_svg($uri)
{
static $regex_map; // Only compute regex map once, for performance.
if (!isset($regex_map)) {
$regex_map = array();
/**
* Filters BlogBend's array of domain mappings for social icons.
*
* 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).
*
* @param array $social_icons_map Array of default social icons.
* @since BlogBend 1.0.0
*
*/
$map = apply_filters('blogbend_social_icons_map', self::$social_icons_map);
/**
* Filters BlogBend's array of social icons.
*
* @param array $social_icons Array of default social icons.
* @since BlogBend 1.0.0
*
*/
$social_icons = apply_filters('blogbend_svg_icons_social', self::$social_icons);
foreach (array_keys($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 blogbend_get_theme_svg($icon, 'social');
}
}
return null;
}
/**
* ICON STORAGE
* Store the code for all SVGs in an array.
*
* @since BlogBend 1.0.0
* @var array
*/
public static $ui_icons = array(
'arrow-double' => '',
'arrow-down' => '',
'arrow-up' => '',
'arrow-left' => '',
'arrow-right' => '',
'badge' => '',
'bookmark' => '',
'calendar' => '',
'chevron-up' => '',
'chevron-down' => '',
'chevron-left' => '',
'chevron-right' => '',
'clock' => '',
'comment' => '',
'cross' => '',
'cart' => '',
'edit' => '',
'folder' => '',
'geo-fill' => '',
'hourglass' => '',
'home' => '',
'link' => '',
'search' => '',
'tag' => '',
'trending-graph' => '',
'user' => '',
);
/**
* 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).
*
* @since BlogBend 1.0.0
* @var array
*/
public static $social_icons_map = array(
'amazon' => array(
'amazon.com',
'amazon.cn',
'amazon.in',
'amazon.fr',
'amazon.de',
'amazon.it',
'amazon.nl',
'amazon.es',
'amazon.co',
'amazon.ca',
),
'behance' => array(
'behance.net',
),
'codepen' => array(
'codepen.io',
),
'facebook' => array(
'facebook.com',
'fb.me',
),
'feed' => array(
'feed',
),
'google' => array(
'g.page',
),
'lastfm' => array(
'last.fm',
),
'mail' => array(
'mailto:',
),
'mastodon' => array(
'mastodon.social',
'pawoo.net',
'mstdn.jp',
'mastodon.cloud',
'mastodon.online',
'counter.social',
'mstdn.social',
'mas.to',
'mastodon.world',
'gc2.jp',
),
'pocket' => array(
'getpocket.com',
),
'threads' => array(
'threads.net',
),
'tiktok' => array(
'tiktok.com',
),
'telegram' => array(
't.me',
'telegram.org',
'telegram.com',
),
'twitch' => array(
'twitch.tv',
),
'twitter' => array(
'twitter.com',
'x.com',
),
'whatsapp' => array(
'wa.me',
'whatsapp.com',
),
'wordpress' => array(
'wordpress.com',
'wordpress.org',
),
);
/**
* Social Icons – svg sources.
*
* @since BlogBend 1.0.0
* @var array
*/
public static $social_icons = array(
'500px' => '',
'amazon' => '',
'bandcamp' => '',
'behance' => '',
'codepen' => '',
'deviantart' => '',
'dribbble' => '',
'dropbox' => '',
'etsy' => '',
'facebook' => '',
'feed' => '',
'flickr' => '',
'foursquare' => '',
'goodreads' => '',
'google' => '',
'github' => '',
'instagram' => '',
'lastfm' => '',
'linkedin' => '',
'mail' => '',
'mastodon' => '',
'medium' => '',
'meetup' => '',
'pinterest' => '',
'pocket' => '',
'reddit' => '',
'skype' => '',
'snapchat' => '',
'soundcloud' => '',
'spotify' => '',
'telegram' => '',
'threads' => '',
'tumblr' => '',
'tiktok' => '',
'twitch' => '',
'twitter' => '',
'vimeo' => '',
'vk' => '',
'whatsapp' => '',
'wordpress' => '',
'yelp' => '',
'youtube' => '',
);
}
}
/**
* BlogBend SVG Icon helper functions
*
* @package BlogBend
*/
if ( ! function_exists( 'blogbend_the_theme_svg' ) ) {
/**
* Output and Get Theme SVG.
* Output and get the SVG markup for an icon in the BlogBend_SVG_Icons class.
*
* @since BlogBend 1.0.0
*
* @param string $svg_name The name of the icon.
* @param string $group The group the icon belongs to.
* @param string $color Color code.
*/
function blogbend_the_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
echo blogbend_get_theme_svg( $svg_name, $group, $color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in blogbend_get_theme_svg().
}
}
if ( ! function_exists( 'blogbend_get_theme_svg' ) ) {
/**
* Get information about the SVG icon.
*
* @since BlogBend 1.0.0
*
* @param string $svg_name The name of the icon.
* @param string $group The group the icon belongs to.
* @param string $color Color code.
*/
function blogbend_get_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
// Make sure that only our allowed tags and attributes are included.
$svg = wp_kses(
BlogBend_SVG_Icons::get_svg( $svg_name, $group, $color ),
array(
'svg' => array(
'class' => true,
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true,
'aria-hidden' => true,
'role' => true,
'focusable' => true,
),
'path' => array(
'fill' => true,
'fill-rule' => true,
'd' => true,
'transform' => true,
),
'polygon' => array(
'fill' => true,
'fill-rule' => true,
'points' => true,
'transform' => true,
'focusable' => true,
),
)
);
if ( ! $svg ) {
return false;
}
return $svg;
}
}