From a959b419d2703905a0dc31856e12801c1143aec7 Mon Sep 17 00:00:00 2001 From: Rick Curran Date: Mon, 5 Aug 2019 15:33:50 +0100 Subject: [PATCH 1/9] Added more common feed url components to get_supported_icons() As an improvement based on the issue #10662 "Social Icons Widget: allow for alternate feed URLs" this adds some more common feed url components to the get_supported_icons() function. The existing version only matches the existence of "/feed/" in the url being added, as such many other feed URL formats would end up showing with the default link icon instead. Whilst it may still not catch all possilbe feed url formats it will catch many commonly used formats as well as non-permalink versions of WordPress feeds. --- modules/widgets/social-icons.php | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 7a323ed150772..e53ef1aa003b4 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -512,6 +512,106 @@ public function get_supported_icons() { 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), + array( + 'url' => '/feeds/', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'format=RSS', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/rss', // Used by Tumblr + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/.rss', // Yep, Reddit uses this + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/rss.xml', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'http://rss', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'https://rss', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'rss=1', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/feed=rss', // Catches feed=rss / feed=rss2 + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '?feed=rss', // Catches feed=rss / feed=rss2 + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '?feed=rdf', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '?feed=atom', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'http://feeds', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'https://feeds', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/feed.xml', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/index.xml', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/blog/feed', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/atom.xml', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '.atom', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => '/atom', + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), array( 'url' => 'flickr.com', 'icon' => 'flickr', From c445ccb1f269de0a0c73e85ec74644f9140e9de6 Mon Sep 17 00:00:00 2001 From: Rick Curran Date: Mon, 5 Aug 2019 20:35:06 +0100 Subject: [PATCH 2/9] Corrected spaces to tabs, clarified some of the RSS feed sources Fixed incorrect use of spaces instead of tabs. Added some additional comments regarding which sources RSS feeds may come from. --- modules/widgets/social-icons.php | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index e53ef1aa003b4..913f8e71ba910 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -508,17 +508,22 @@ public function get_supported_icons() { 'label' => 'Facebook', ), array( - 'url' => '/feed/', + 'url' => '/feed/', // WordPress default feed url 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/feeds/', + 'url' => '/feeds/', // Blogspot, and others 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => 'format=RSS', + 'url' => '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), + array( + 'url' => 'format=RSS', // Squarespace feed url, and others 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), @@ -527,13 +532,13 @@ public function get_supported_icons() { 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), - array( + array( 'url' => '/.rss', // Yep, Reddit uses this 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/rss.xml', + 'url' => '/rss.xml', // Moveable Type, Typepad 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), @@ -558,57 +563,57 @@ public function get_supported_icons() { 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '?feed=rss', // Catches feed=rss / feed=rss2 + 'url' => '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '?feed=rdf', + 'url' => '?feed=rdf', // WordPress non-permalink 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '?feed=atom', + 'url' => '?feed=atom', // WordPress non-permalink 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => 'http://feeds', + 'url' => 'http://feeds', // FeedBurner 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => 'https://feeds', + 'url' => 'https://feeds', // FeedBurner 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/feed.xml', + 'url' => '/feed.xml', // Alias used with Feedburner, and others 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/index.xml', + 'url' => '/index.xml', // Moveable Type, and others 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/blog/feed', + 'url' => '/atom.xml', // Typepad 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/atom.xml', + 'url' => '.atom', // Shopify blogs 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '.atom', + 'url' => '/atom', // Some non-WordPress feeds 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), array( - 'url' => '/atom', + 'url' => 'index.rdf', // Typepad 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ), ), From 9a6bb55c6033edb2f3c0e297da634e486ea8598f Mon Sep 17 00:00:00 2001 From: Rick Curran Date: Tue, 6 Aug 2019 12:52:48 +0100 Subject: [PATCH 3/9] Moved Feed formats into $feed_url_formats array There are many possible RSS Feed url formats that can be used to match for the RSS Feed icon, so to reduce repetition of multiple 'feed' entries in the `$social_links_icons` array a separate `$feed_url_formats` now contains the common 'feed' icon and the various feed url parameters. As such it means the 'url' of an item in the `$social_links_icons` array can itself be an array so the code for rendering the widget has been updated to accommodate this. --- modules/widgets/social-icons.php | 173 +++++++++++-------------------- 1 file changed, 58 insertions(+), 115 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 913f8e71ba910..02fa2b96b57a9 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -137,11 +137,27 @@ public function widget( $args, $instance ) { $found_icon = false; foreach ( $social_icons as $social_icon ) { - if ( false !== stripos( $icon['url'], $social_icon['url'] ) ) { - echo '' . esc_attr( $social_icon['label'] ) . ''; - echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); - $found_icon = true; - break; + + // Check if the $social_icon['url'] is an array ('Feed' url is provided as an array of url components) + if ( is_array( $social_icon['url'] ) ) { + // If array then we loop over the array to do the stripos match using each array item + foreach ( $social_icon['url'] as $url_fragment ) { + if ( false !== stripos( $icon['url'], $url_fragment ) ) { + echo '' . esc_attr( $social_icon['label'] ) . ''; + echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); + $found_icon = true; + break; + } + } + + } else { + // If not array then we can do a regular stripos match using $social_icon['url'] + if ( false !== stripos( $icon['url'], $social_icon['url'] ) ) { + echo '' . esc_attr( $social_icon['label'] ) . ''; + echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); + $found_icon = true; + break; + } } } @@ -507,116 +523,6 @@ public function get_supported_icons() { 'icon' => 'facebook', 'label' => 'Facebook', ), - array( - 'url' => '/feed/', // WordPress default feed url - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/feeds/', // Blogspot, and others - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'format=RSS', // Squarespace feed url, and others - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/rss', // Used by Tumblr - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/.rss', // Yep, Reddit uses this - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/rss.xml', // Moveable Type, Typepad - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'http://rss', - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'https://rss', - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'rss=1', - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/feed=rss', // Catches feed=rss / feed=rss2 - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2 - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '?feed=rdf', // WordPress non-permalink - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '?feed=atom', // WordPress non-permalink - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'http://feeds', // FeedBurner - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'https://feeds', // FeedBurner - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/feed.xml', // Alias used with Feedburner, and others - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/index.xml', // Moveable Type, and others - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/atom.xml', // Typepad - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '.atom', // Shopify blogs - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => '/atom', // Some non-WordPress feeds - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), - array( - 'url' => 'index.rdf', // Typepad - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ), array( 'url' => 'flickr.com', 'icon' => 'flickr', @@ -768,6 +674,43 @@ public function get_supported_icons() { 'label' => 'YouTube', ), ); + + /* + * There are many possible RSS Feed url formats + * + * This array of common feed url parameters is used to try and match a variety of feed urls in order to correctly display them as Feeds + */ + $feed_url_formats = array( + 'url' => array( + '/feed/', // WordPress default feed url + '/feeds/', // Blogspot, and others + '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly + 'format=RSS', // Squarespace feed url, and others + '/rss', // Used by Tumblr + '/.rss', // Yep, Reddit uses this + '/rss.xml', // Moveable Type, Typepad + 'http://rss', + 'https://rss', + 'rss=1', + '/feed=rss', // Catches feed=rss / feed=rss2 + '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2 + '?feed=rdf', // WordPress non-permalink + '?feed=atom', // WordPress non-permalink + 'http://feeds', // FeedBurner + 'https://feeds', // FeedBurner + '/feed.xml', // Alias used with Feedburner, and others + '/index.xml', // Moveable Type, and others + '/atom.xml', // Typepad, Squarespace + '.atom', // Shopify blog + '/atom', // Some non-WordPress feeds + 'index.rdf', // Typepad + ), + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ); + + // Push the $feed_url_formats onto the main $social_links_icons array + array_push( $social_links_icons, $feed_url_formats ); return $social_links_icons; } From 1be5dcbe65ef890f14fa7980d65b3eb6dd22f93d Mon Sep 17 00:00:00 2001 From: Rick Curran Date: Tue, 6 Aug 2019 17:29:37 +0100 Subject: [PATCH 4/9] Simplified the code by setting all `$social_links_icons` urls as arrays The previous commit added the various `$social_links_icons` 'feed' items as an array. This cleaned up the code but also added a bit of repetition due to having to check whether a `$social_links_icons` url element was an array and subsequently handle them in two different ways but duplicating some code in the process. This update changes all url elements in the `$social_links_icons` array to be an array even if there is only one item (as most of them do). This means that the code used to check if a url matches only needs to presume the url element comes as an array. This also enables the possibilty that some of the existing items e.g. Amazon can be reduced to one entry in the `$social_links_icons` array. --- modules/widgets/social-icons.php | 119 +++++++++++++++---------------- 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 02fa2b96b57a9..a8fa98e0c92eb 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -138,7 +138,8 @@ public function widget( $args, $instance ) { foreach ( $social_icons as $social_icon ) { - // Check if the $social_icon['url'] is an array ('Feed' url is provided as an array of url components) + // All $social_icon['url'] elements are now provided as an array even if there is only one item, + // but we'll check if the $social_icon['url'] is an array anyway if ( is_array( $social_icon['url'] ) ) { // If array then we loop over the array to do the stripos match using each array item foreach ( $social_icon['url'] as $url_fragment ) { @@ -150,14 +151,6 @@ public function widget( $args, $instance ) { } } - } else { - // If not array then we can do a regular stripos match using $social_icon['url'] - if ( false !== stripos( $icon['url'], $social_icon['url'] ) ) { - echo '' . esc_attr( $social_icon['label'] ) . ''; - echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); - $found_icon = true; - break; - } } } @@ -404,272 +397,272 @@ public function get_svg_icon( $args = array() ) { public function get_supported_icons() { $social_links_icons = array( array( - 'url' => '500px.com', + 'url' => array( '500px.com' ), 'icon' => '500px', 'label' => '500px', ), array( - 'url' => 'amazon.cn', + 'url' => array( 'amazon.cn' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.in', + 'url' => array( 'amazon.in' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.fr', + 'url' => array( 'amazon.fr' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.de', + 'url' => array( 'amazon.de' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.it', + 'url' => array( 'amazon.it' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.nl', + 'url' => array( 'amazon.nl' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.es', + 'url' => array( 'amazon.es' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.co', + 'url' => array( 'amazon.co' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.ca', + 'url' => array( 'amazon.ca' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'amazon.com', + 'url' => array( 'amazon.com' ), 'icon' => 'amazon', 'label' => 'Amazon', ), array( - 'url' => 'apple.com', + 'url' => array( 'apple.com' ), 'icon' => 'apple', 'label' => 'Apple', ), array( - 'url' => 'itunes.com', + 'url' => array( 'itunes.com' ), 'icon' => 'apple', 'label' => 'iTunes', ), array( - 'url' => 'bandcamp.com', + 'url' => array( 'bandcamp.com' ), 'icon' => 'bandcamp', 'label' => 'Bandcamp', ), array( - 'url' => 'behance.net', + 'url' => array( 'behance.net' ), 'icon' => 'behance', 'label' => 'Behance', ), array( - 'url' => 'codepen.io', + 'url' => array( 'codepen.io' ), 'icon' => 'codepen', 'label' => 'CodePen', ), array( - 'url' => 'deviantart.com', + 'url' => array( 'deviantart.com' ), 'icon' => 'deviantart', 'label' => 'DeviantArt', ), array( - 'url' => 'digg.com', + 'url' => array( 'digg.com' ), 'icon' => 'digg', 'label' => 'Digg', ), array( - 'url' => 'discord.gg', + 'url' => array( 'discord.gg' ), 'icon' => 'discord', 'label' => 'Discord', ), array( - 'url' => 'discordapp.com', + 'url' => array( 'discordapp.com' ), 'icon' => 'discord', 'label' => 'Discord', ), array( - 'url' => 'dribbble.com', + 'url' => array( 'dribbble.com' ), 'icon' => 'dribbble', 'label' => 'Dribbble', ), array( - 'url' => 'dropbox.com', + 'url' => array( 'dropbox.com' ), 'icon' => 'dropbox', 'label' => 'Dropbox', ), array( - 'url' => 'etsy.com', + 'url' => array( 'etsy.com' ), 'icon' => 'etsy', 'label' => 'Etsy', ), array( - 'url' => 'facebook.com', + 'url' => array( 'facebook.com' ), 'icon' => 'facebook', 'label' => 'Facebook', ), array( - 'url' => 'flickr.com', + 'url' => array( 'flickr.com' ), 'icon' => 'flickr', 'label' => 'Flickr', ), array( - 'url' => 'foursquare.com', + 'url' => array( 'foursquare.com' ), 'icon' => 'foursquare', 'label' => 'Foursquare', ), array( - 'url' => 'goodreads.com', + 'url' => array( 'goodreads.com' ), 'icon' => 'goodreads', 'label' => 'Goodreads', ), array( - 'url' => 'google.com', + 'url' => array( 'google.com' ), 'icon' => 'google', 'label' => 'Google', ), array( - 'url' => 'github.com', + 'url' => array( 'github.com' ), 'icon' => 'github', 'label' => 'GitHub', ), array( - 'url' => 'instagram.com', + 'url' => array( 'instagram.com' ), 'icon' => 'instagram', 'label' => 'Instagram', ), array( - 'url' => 'linkedin.com', + 'url' => array( 'linkedin.com' ), 'icon' => 'linkedin', 'label' => 'LinkedIn', ), array( - 'url' => 'mailto:', + 'url' => array( 'mailto:' ), 'icon' => 'mail', 'label' => __( 'Email', 'jetpack' ), ), array( - 'url' => 'meetup.com', + 'url' => array( 'meetup.com' ), 'icon' => 'meetup', 'label' => 'Meetup', ), array( - 'url' => 'medium.com', + 'url' => array( 'medium.com' ), 'icon' => 'medium', 'label' => 'Medium', ), array( - 'url' => 'pinterest.', + 'url' => array( 'pinterest.' ), 'icon' => 'pinterest', 'label' => 'Pinterest', ), array( - 'url' => 'getpocket.com', + 'url' => array( 'getpocket.com' ), 'icon' => 'pocket', 'label' => 'Pocket', ), array( - 'url' => 'reddit.com', + 'url' => array( 'reddit.com' ), 'icon' => 'reddit', 'label' => 'Reddit', ), array( - 'url' => 'skype.com', + 'url' => array( 'skype.com' ), 'icon' => 'skype', 'label' => 'Skype', ), array( - 'url' => 'skype:', + 'url' => array( 'skype:' ), 'icon' => 'skype', 'label' => 'Skype', ), array( - 'url' => 'slideshare.net', + 'url' => array( 'slideshare.net' ), 'icon' => 'slideshare', 'label' => 'SlideShare', ), array( - 'url' => 'snapchat.com', + 'url' => array( 'snapchat.com' ), 'icon' => 'snapchat', 'label' => 'Snapchat', ), array( - 'url' => 'soundcloud.com', + 'url' => array( 'soundcloud.com' ), 'icon' => 'soundcloud', 'label' => 'SoundCloud', ), array( - 'url' => 'spotify.com', + 'url' => array( 'spotify.com' ), 'icon' => 'spotify', 'label' => 'Spotify', ), array( - 'url' => 'stackoverflow.com', + 'url' => array( 'stackoverflow.com' ), 'icon' => 'stackoverflow', 'label' => 'Stack Overflow', ), array( - 'url' => 'stumbleupon.com', + 'url' => array( 'stumbleupon.com' ), 'icon' => 'stumbleupon', 'label' => 'StumbleUpon', ), array( - 'url' => 'tumblr.com', + 'url' => array( 'tumblr.com' ), 'icon' => 'tumblr', 'label' => 'Tumblr', ), array( - 'url' => 'twitch.tv', + 'url' => array( 'twitch.tv' ), 'icon' => 'twitch', 'label' => 'Twitch', ), array( - 'url' => 'twitter.com', + 'url' => array( 'twitter.com' ), 'icon' => 'twitter', 'label' => 'Twitter', ), array( - 'url' => 'vimeo.com', + 'url' => array( 'vimeo.com' ), 'icon' => 'vimeo', 'label' => 'Vimeo', ), array( - 'url' => 'vk.com', + 'url' => array( 'vk.com' ), 'icon' => 'vk', 'label' => 'VK', ), array( - 'url' => 'wordpress.com', + 'url' => array( 'wordpress.com' ), 'icon' => 'wordpress', 'label' => 'WordPress.com', ), array( - 'url' => 'wordpress.org', + 'url' => array( 'wordpress.org' ), 'icon' => 'wordpress', 'label' => 'WordPress', ), array( - 'url' => 'yelp.com', + 'url' => array( 'yelp.com' ), 'icon' => 'yelp', 'label' => 'Yelp', ), array( - 'url' => 'youtube.com', + 'url' => array( 'youtube.com' ), 'icon' => 'youtube', 'label' => 'YouTube', ), From 3617123e5e6adb55291ab4b396eeba7a12f3c56f Mon Sep 17 00:00:00 2001 From: Rick Curran Date: Tue, 6 Aug 2019 18:39:33 +0100 Subject: [PATCH 5/9] Reduced multiple entries for Amazon & others urls in `$social_links_icons` array This commit reduces the separate entries that exist for Amazon, Google, Discord and WordPress domains into single items with multiple url array items instead. --- modules/widgets/social-icons.php | 63 ++------------------------------ 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index a8fa98e0c92eb..4008333c38bbb 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -402,52 +402,7 @@ public function get_supported_icons() { 'label' => '500px', ), array( - 'url' => array( 'amazon.cn' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.in' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.fr' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.de' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.it' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.nl' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.es' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.co' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.ca' ), - 'icon' => 'amazon', - 'label' => 'Amazon', - ), - array( - 'url' => array( 'amazon.com' ), + 'url' => array( 'amazon.cn', 'amazon.in', 'amazon.fr', 'amazon.de', 'amazon.it', 'amazon.nl', 'amazon.es', 'amazon.co', 'amazon.ca', 'amazon.com' ), 'icon' => 'amazon', 'label' => 'Amazon', ), @@ -487,12 +442,7 @@ public function get_supported_icons() { 'label' => 'Digg', ), array( - 'url' => array( 'discord.gg' ), - 'icon' => 'discord', - 'label' => 'Discord', - ), - array( - 'url' => array( 'discordapp.com' ), + 'url' => array( 'discord.gg', 'discordapp.com' ), 'icon' => 'discord', 'label' => 'Discord', ), @@ -532,7 +482,7 @@ public function get_supported_icons() { 'label' => 'Goodreads', ), array( - 'url' => array( 'google.com' ), + 'url' => array( 'google.com', 'google.co.uk', 'google.ca', 'google.cn', 'google.it' ), 'icon' => 'google', 'label' => 'Google', ), @@ -647,12 +597,7 @@ public function get_supported_icons() { 'label' => 'VK', ), array( - 'url' => array( 'wordpress.com' ), - 'icon' => 'wordpress', - 'label' => 'WordPress.com', - ), - array( - 'url' => array( 'wordpress.org' ), + 'url' => array( 'wordpress.com', 'wordpress.org' ), 'icon' => 'wordpress', 'label' => 'WordPress', ), From 2885b8a279a2f594a4d70043ae48aa207b0fa39b Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 7 Aug 2019 12:51:24 +0200 Subject: [PATCH 6/9] Widgets: merge Feed array with rest of supported icons Now that all supported services use the array format, we can move this whole array back in without creating any confusion. --- modules/widgets/social-icons.php | 78 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 4008333c38bbb..15d8657c0bea2 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -402,7 +402,18 @@ public function get_supported_icons() { 'label' => '500px', ), array( - 'url' => array( 'amazon.cn', 'amazon.in', 'amazon.fr', 'amazon.de', 'amazon.it', 'amazon.nl', 'amazon.es', 'amazon.co', 'amazon.ca', 'amazon.com' ), + 'url' => array( + 'amazon.cn', + 'amazon.in', + 'amazon.fr', + 'amazon.de', + 'amazon.it', + 'amazon.nl', + 'amazon.es', + 'amazon.co', + 'amazon.ca', + 'amazon.com', + ), 'icon' => 'amazon', 'label' => 'Amazon', ), @@ -466,6 +477,34 @@ public function get_supported_icons() { 'icon' => 'facebook', 'label' => 'Facebook', ), + array( + 'url' => array( + '/feed/', // WordPress default feed url. + '/feeds/', // Blogspot and others. + '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly. + 'format=RSS', // Squarespace and others. + '/rss', // Tumblr. + '/.rss', // Reddit. + '/rss.xml', // Moveable Type, Typepad. + 'http://rss', + 'https://rss', + 'rss=1', + '/feed=rss', // Catches feed=rss / feed=rss2. + '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2. + '?feed=rdf', // WordPress non-permalink. + '?feed=atom', // WordPress non-permalink. + 'http://feeds', // FeedBurner. + 'https://feeds', // FeedBurner. + '/feed.xml', // Feedburner Alias, and others. + '/index.xml', // Moveable Type, and others. + '/atom.xml', // Typepad, Squarespace. + '.atom', // Shopify blog. + '/atom', // Some non-WordPress feeds. + 'index.rdf', // Typepad. + ), + 'icon' => 'feed', + 'label' => __( 'RSS Feed', 'jetpack' ), + ), array( 'url' => array( 'flickr.com' ), 'icon' => 'flickr', @@ -612,43 +651,6 @@ public function get_supported_icons() { 'label' => 'YouTube', ), ); - - /* - * There are many possible RSS Feed url formats - * - * This array of common feed url parameters is used to try and match a variety of feed urls in order to correctly display them as Feeds - */ - $feed_url_formats = array( - 'url' => array( - '/feed/', // WordPress default feed url - '/feeds/', // Blogspot, and others - '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly - 'format=RSS', // Squarespace feed url, and others - '/rss', // Used by Tumblr - '/.rss', // Yep, Reddit uses this - '/rss.xml', // Moveable Type, Typepad - 'http://rss', - 'https://rss', - 'rss=1', - '/feed=rss', // Catches feed=rss / feed=rss2 - '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2 - '?feed=rdf', // WordPress non-permalink - '?feed=atom', // WordPress non-permalink - 'http://feeds', // FeedBurner - 'https://feeds', // FeedBurner - '/feed.xml', // Alias used with Feedburner, and others - '/index.xml', // Moveable Type, and others - '/atom.xml', // Typepad, Squarespace - '.atom', // Shopify blog - '/atom', // Some non-WordPress feeds - 'index.rdf', // Typepad - ), - 'icon' => 'feed', - 'label' => __( 'RSS Feed', 'jetpack' ), - ); - - // Push the $feed_url_formats onto the main $social_links_icons array - array_push( $social_links_icons, $feed_url_formats ); return $social_links_icons; } From 517f657f3dd819d4493be0351a9198e8619986f1 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 7 Aug 2019 12:52:13 +0200 Subject: [PATCH 7/9] Simplify the display of each icon - Since we know for sure $social_icon['url'] is going to be an array, let's remove the extra check - Use printf instead of 2 echo - Add phpcs:ignore to avoid error on output --- modules/widgets/social-icons.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 15d8657c0bea2..134caad10cbeb 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -137,20 +137,21 @@ public function widget( $args, $instance ) { $found_icon = false; foreach ( $social_icons as $social_icon ) { - - // All $social_icon['url'] elements are now provided as an array even if there is only one item, - // but we'll check if the $social_icon['url'] is an array anyway - if ( is_array( $social_icon['url'] ) ) { - // If array then we loop over the array to do the stripos match using each array item - foreach ( $social_icon['url'] as $url_fragment ) { - if ( false !== stripos( $icon['url'], $url_fragment ) ) { - echo '' . esc_attr( $social_icon['label'] ) . ''; - echo $this->get_svg_icon( array( 'icon' => esc_attr( $social_icon['icon'] ) ) ); - $found_icon = true; - break; - } + foreach ( $social_icon['url'] as $url_fragment ) { + if ( false !== stripos( $icon['url'], $url_fragment ) ) { + printf( + '%1$s%2$s', + esc_attr( $social_icon['label'] ), + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + $this->get_svg_icon( + array( + 'icon' => esc_attr( $social_icon['icon'] ), + ) + ) + ); + $found_icon = true; + break; } - } } From e9d16a825194b0691ba2c021618ce066cb6b71ef Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 7 Aug 2019 15:37:23 +0200 Subject: [PATCH 8/9] Social Icons: fix all PHPCS errors and warnings, & add to whitelist --- bin/phpcs-whitelist.js | 1 + modules/widgets/social-icons.php | 76 ++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/bin/phpcs-whitelist.js b/bin/phpcs-whitelist.js index 555f217197a7d..04d3c4929ed31 100644 --- a/bin/phpcs-whitelist.js +++ b/bin/phpcs-whitelist.js @@ -23,6 +23,7 @@ module.exports = [ 'modules/sitemaps/sitemaps.php', 'modules/theme-tools/social-menu/', 'modules/verification-tools.php', + 'modules/widgets/social-icons.php', 'modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php', 'packages', ]; diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index 134caad10cbeb..da7c8296a21c1 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -1,6 +1,12 @@ - + ?> - id_base ); - echo $args['before_widget']; + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( ! empty( $title ) ) { - echo $args['before_title'] . esc_html( $title ) . $args['after_title']; + echo $args['before_title'] . esc_html( $title ) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } if ( ! empty( $instance['icons'] ) ) : @@ -118,13 +135,13 @@ public function widget( $args, $instance ) { $social_icons = $this->get_supported_icons(); $default_icon = $this->get_svg_icon( array( 'icon' => 'chain' ) ); - // Set target attribute for the link + // Set target attribute for the link. if ( true === $instance['new-tab'] ) { $target = '_blank'; } else { $target = '_self'; } - ?> + ?>
    @@ -132,7 +149,7 @@ public function widget( $args, $instance ) {
  • - + @@ -167,10 +184,10 @@ public function widget( $args, $instance ) {
- defaults['icon-size']; - if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ) ) ) { + if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ), true ) ) { $instance['icon-size'] = $new_instance['icon-size']; } $instance['new-tab'] = isset( $new_instance['new-tab'] ) ? (bool) $new_instance['new-tab'] : false; - $icon_count = count( $new_instance['url-icons'] ); $instance['icons'] = array(); foreach ( $new_instance['url-icons'] as $url ) { @@ -232,13 +250,13 @@ public function form( $instance ) { ?>

- - + +

- - $label ) : ?> @@ -246,8 +264,8 @@ public function form( $instance ) {

- /> - + /> +

- '', 'url-icon-name' => '', From b82da9ec4ddb0ca3198fa52be6fbdae6ae207999 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Wed, 21 Aug 2019 11:57:27 +0200 Subject: [PATCH 9/9] Clarify comments for RSS list. See: - https://github.com/Automattic/jetpack/pull/13183/files#r314844476 - https://github.com/Automattic/jetpack/pull/13183/files#r314844856 - https://github.com/Automattic/jetpack/pull/13183/files#r314844732 --- modules/widgets/social-icons.php | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/widgets/social-icons.php b/modules/widgets/social-icons.php index da7c8296a21c1..bea4a14720b01 100644 --- a/modules/widgets/social-icons.php +++ b/modules/widgets/social-icons.php @@ -498,28 +498,28 @@ public function get_supported_icons() { ), array( 'url' => array( - '/feed/', // WordPress default feed url. - '/feeds/', // Blogspot and others. - '/blog/feed', // No trailing space WordPress feed, could use /feed but may match unexpectedly. - 'format=RSS', // Squarespace and others. - '/rss', // Tumblr. - '/.rss', // Reddit. - '/rss.xml', // Moveable Type, Typepad. - 'http://rss', - 'https://rss', + '/feed/', // WordPress default feed url. + '/feeds/', // Blogspot and others. + '/blog/feed', // No trailing slash WordPress feed, could use /feed but may match unexpectedly. + 'format=RSS', // Squarespace and others. + '/rss', // Tumblr. + '/.rss', // Reddit. + '/rss.xml', // Moveable Type, Typepad. + 'http://rss.', // Old custom format. + 'https://rss.', // Old custom format. 'rss=1', - '/feed=rss', // Catches feed=rss / feed=rss2. - '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2. - '?feed=rdf', // WordPress non-permalink. - '?feed=atom', // WordPress non-permalink. - 'http://feeds', // FeedBurner. - 'https://feeds', // FeedBurner. - '/feed.xml', // Feedburner Alias, and others. - '/index.xml', // Moveable Type, and others. - '/atom.xml', // Typepad, Squarespace. - '.atom', // Shopify blog. - '/atom', // Some non-WordPress feeds. - 'index.rdf', // Typepad. + '/feed=rss', // Catches feed=rss / feed=rss2. + '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2. + '?feed=rdf', // WordPress non-permalink. + '?feed=atom', // WordPress non-permalink. + 'http://feeds.', // FeedBurner. + 'https://feeds.', // FeedBurner. + '/feed.xml', // Feedburner Alias, and others. + '/index.xml', // Moveable Type, and others. + '/atom.xml', // Typepad, Squarespace. + '.atom', // Shopify blog. + '/atom', // Some non-WordPress feeds. + 'index.rdf', // Typepad. ), 'icon' => 'feed', 'label' => __( 'RSS Feed', 'jetpack' ),