Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: enhancement

Widgets: add Mastodon to Social Icons Widget and Social Menu
35 changes: 35 additions & 0 deletions projects/plugins/jetpack/functions.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,38 @@ function jetpack_is_frontend() {
*/
return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend );
}

/**
* Build a list of Mastodon instance hosts.
* That list can be extended via a filter.
*
* @since $$next-version$$
*
* @return array
*/
function jetpack_mastodon_get_instance_list() {
$mastodon_instance_list = array(
// Regex pattern to match any .tld for the mastodon host name.
'#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#',
// Regex pattern to match any .tld for the mstdn host name.
'#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#',
'counter.social',
'fosstodon.org',
'gc2.jp',
'hachyderm.io',
'infosec.exchange',
'mas.to',
'pawoo.net',
);

/**
* Filter the list of Mastodon instances.
*
* @since $$next-version$$
*
* @module widgets, theme-tools
*
* @param array $mastodon_instance_list Array of Mastodon instances.
*/
return (array) apply_filters( 'jetpack_mastodon_instance_list', $mastodon_instance_list );
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ function jetpack_social_menu_social_links_icons() {
'youtube.com' => 'youtube',
);

/*
* Add Mastodon instances to this array.
*/
$mastodon_instance_list = jetpack_mastodon_get_instance_list();
foreach ( $mastodon_instance_list as $instance ) {
$social_links_icons[ $instance ] = 'mastodon';
}

return $social_links_icons;
}
endif;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 23 additions & 15 deletions projects/plugins/jetpack/modules/widgets/social-icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,19 @@ public function widget( $args, $instance ) {

foreach ( $social_icons as $social_icon ) {
foreach ( $social_icon['url'] as $url_fragment ) {
if ( false !== stripos( $icon['url'], $url_fragment ) ) {
/*
* url_fragment can be a URL host, or a regex, starting with #.
* Let's check for both scenarios.
*/
if (
// First Regex.
(
'#' === substr( $url_fragment, 0, 1 ) && '#' === substr( $url_fragment, -1 )
&& preg_match( $url_fragment, $icon['url'] )
)
// Then, regular host name.
|| false !== strpos( $icon['url'], $url_fragment )
) {
printf(
'<span class="screen-reader-text">%1$s</span>%2$s',
esc_attr( $social_icon['label'] ),
Expand Down Expand Up @@ -445,16 +457,7 @@ public function get_supported_icons() {
),
array(
'url' => array(
'amazon.cn',
'amazon.in',
'amazon.fr',
'amazon.de',
'amazon.it',
'amazon.nl',
'amazon.es',
'amazon.co',
'amazon.ca',
'amazon.com',
'#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#',
),
'icon' => 'amazon',
'label' => 'Amazon',
Expand Down Expand Up @@ -503,7 +506,7 @@ public function get_supported_icons() {
'label' => 'Digg',
),
array(
'url' => array( 'discord.gg', 'discordapp.com' ),
'url' => array( '#discord\.gg|discordapp\.com#' ),
'icon' => 'discord',
'label' => 'Discord',
),
Expand Down Expand Up @@ -553,7 +556,7 @@ public function get_supported_icons() {
'label' => 'Goodreads',
),
array(
'url' => array( 'google.com', 'google.co.uk', 'google.ca', 'google.cn', 'google.it' ),
'url' => array( '#google\.(com|co\.uk|ca|cn|it)#' ),
'icon' => 'google',
'label' => 'Google',
),
Expand All @@ -577,6 +580,11 @@ public function get_supported_icons() {
'icon' => 'mail',
'label' => __( 'Email', 'jetpack' ),
),
array(
'url' => jetpack_mastodon_get_instance_list(),
'icon' => 'mastodon',
'label' => 'Mastodon',
),
array(
'url' => array( 'meetup.com' ),
'icon' => 'meetup',
Expand Down Expand Up @@ -658,7 +666,7 @@ public function get_supported_icons() {
'label' => 'StumbleUpon',
),
array(
'url' => array( 'telegram.me', 't.me' ),
'url' => array( '#https?:\/\/(www\.)?(telegram|t)\.me#' ),
'icon' => 'telegram',
'label' => 'Telegram',
),
Expand Down Expand Up @@ -703,7 +711,7 @@ public function get_supported_icons() {
'label' => 'WooCommerce',
),
array(
'url' => array( 'wordpress.com', 'wordpress.org' ),
'url' => array( '#wordpress\.(com|org)#' ),
'icon' => 'wordpress',
'label' => 'WordPress',
),
Expand Down