Skip to content

Commit d204d17

Browse files
authored
Merge pull request #151 from dshanske/refreshicons1219
Refresh Icons
2 parents ab55cee + 39ab9a9 commit d204d17

474 files changed

Lines changed: 1900 additions & 2174 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = function (grunt) {
8585

8686
grunt.loadNpmTasks('grunt-wp-readme-to-markdown');
8787
grunt.loadNpmTasks('grunt-wp-i18n');
88-
grunt.loadNpmTasks('grunt-sass');
88+
grunt.loadNpmTasks('grunt-contrib-sass');
8989
grunt.loadNpmTasks('grunt-checktextdomain');
9090
grunt.loadNpmTasks('grunt-execute');
9191
grunt.loadNpmTasks('grunt-contrib-copy');

includes/class-general-settings.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,14 @@ public static function identity_options_callback() {
134134
echo '<p>';
135135
esc_html_e(
136136
'Using rel=me on a link indicates the link represents the same person or entity as
137-
the current page. On a site with a single author, rel=me links from their user profile will
138-
appear on the homepage. On a site with multiple authors rel=me will appear in the links on the author page only.',
137+
the current page. On a site with a single author, links to other profiles from their user profile will
138+
appear on the homepage. On a site with multiple authors these links will appear on the author page only.',
139139
'indieweb'
140140
);
141141
echo '</p>';
142142
echo '<p>';
143143
esc_html_e(
144-
'The Default Author is the one whose that will be used on the home pages and archive pages. The default author setting is also used
145-
by the IndieAuth plugin to identify the primary author of a site. If the single author setting is not set,
144+
'The Default Author is the one whose that will be used on the home pages and archive pages. If the single author setting is not set,
146145
on all other pages, the post author links will be used. To display the links, add the
147146
widget, otherwise they will remain hidden. ',
148147
'indieweb'

includes/class-hcard-user.php

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public static function silos() {
7272
'baseurl' => 'https://www.flickr.com/people/%s',
7373
'display' => __( 'Flickr username', 'indieweb' ),
7474
),
75+
'mastodon' => array(
76+
'baseurl' => '%s',
77+
'display' => __( 'Mastodon Server (URL)', 'indieweb' ),
78+
),
7579
);
7680
return apply_filters( 'wp_relme_silos', $silos );
7781
}
@@ -160,7 +164,7 @@ public static function extended_user_profile( $user ) {
160164
foreach ( self::extra_fields() as $key => $value ) {
161165
self::extended_profile_text_field( $user, $key, $value['title'], $value['description'] );
162166
}
163-
self::extended_profile_textarea_field( $user, 'relme', __( 'Other Sites', 'indieweb' ), __( 'Sites not listed in the profile to add to rel-me (One URL per line)', 'indieweb' ) );
167+
self::extended_profile_textarea_field( $user, 'relme', __( 'Other Sites', 'indieweb' ), __( 'Other profiles without their own field in your user profile (One URL per line)', 'indieweb' ) );
164168
echo '</table>';
165169
}
166170

@@ -214,6 +218,7 @@ public static function save_profile( $user_id ) {
214218
delete_user_meta( $user_id, 'relme' );
215219
}
216220
}
221+
delete_transient( 'indieweb_mastodon' );
217222
}
218223

219224
/**
@@ -230,7 +235,7 @@ public static function clean_url( $string ) {
230235
}
231236
// Rewrite these to https as needed
232237
$secure = apply_filters( 'iwc_rewrite_secure', array( 'facebook.com', 'twitter.com', 'github.com' ) );
233-
if ( in_array( self::extract_domain_name( $url ), $secure, true ) ) {
238+
if ( in_array( preg_replace( '/^www\./', '', wp_parse_url( $url, PHP_URL_HOST ) ), $secure, true ) ) {
234239
$url = preg_replace( '/^http:/i', 'https:', $url );
235240
}
236241
$url = esc_url_raw( $url );
@@ -251,104 +256,6 @@ public static function clean_urls( $urls ) {
251256
return array_filter( array_unique( $array ) );
252257
}
253258

254-
/**
255-
* Returns the Domain Name out of a URL.
256-
*
257-
* @param string $url URL.
258-
*
259-
* @return string domain name
260-
*/
261-
public static function extract_domain_name( $url ) {
262-
$host = wp_parse_url( $url, PHP_URL_HOST );
263-
$host = preg_replace( '/^www\./', '', $host );
264-
return $host;
265-
}
266-
267-
// Try to get the correct icon for the majority of sites by dropping
268-
public static function split_domain( $string ) {
269-
// Strip things we know we dont want. Not every TLD but the common ones in the fontset
270-
$unwanted = array( '-', '.com', '.org', '.net', '.io', '.in', '.tv', '.fm', '.social' );
271-
// Strip these
272-
$string = str_replace( $unwanted, '', $string );
273-
// Strip the dot if it is a TLD other than the above
274-
$string = str_replace( '.', '', $string );
275-
return strtolower( $string );
276-
}
277-
278-
public static function url_to_name( $url ) {
279-
$scheme = wp_parse_url( $url, PHP_URL_SCHEME );
280-
$strings = array_keys( simpleicons_iw_get_names() );
281-
if ( ( 'http' === $scheme ) || ( 'https' === $scheme ) ) {
282-
$domain = self::extract_domain_name( $url );
283-
$strip = self::split_domain( $domain );
284-
if ( in_array( $strip, array_keys( $strings ), true ) ) {
285-
return $strip;
286-
}
287-
// Special Cases
288-
if ( false !== stripos( $url, 'plus.google.com' ) ) {
289-
return 'googleplus';
290-
}
291-
292-
if ( false !== stripos( $url, 'lanyard' ) ) {
293-
return 'lanyrd';
294-
}
295-
296-
if ( false !== stripos( $url, 'micro.blog' ) ) {
297-
return 'micro-dot-blog';
298-
}
299-
// Anything with WordPress in the name that is not matched return WordPress
300-
if ( false !== stripos( $domain, 'WordPress' ) ) {
301-
return 'WordPress';
302-
}
303-
// Some domains have the word app in them check for matches with that
304-
$strip = str_replace( 'app', '', $strip );
305-
if ( in_array( $strip, $strings, true ) ) {
306-
return $strip;
307-
}
308-
return apply_filters( 'indieweb_links_url_to_name', 'website', $url );
309-
}
310-
if ( in_array( $scheme, array_keys( $strings ), true ) ) {
311-
return apply_filters( 'indieweb_links_url_to_name', $strings[ $scheme ], $url );
312-
}
313-
if ( 'sms' === $scheme ) {
314-
return 'phone';
315-
}
316-
if ( 'mailto' === $scheme ) {
317-
return 'mail';
318-
}
319-
if ( 'gtalk' === $scheme ) {
320-
return 'googlehangouts';
321-
}
322-
// Not sure why someone would do a scheme other than web
323-
return 'notice';
324-
}
325-
326-
public static function get_title( $name ) {
327-
$strings = simpleicons_iw_get_names();
328-
if ( isset( $strings[ $name ] ) ) {
329-
return $strings[ $name ];
330-
}
331-
return $name;
332-
}
333-
334-
/**
335-
* Return a marked up SVG icon..
336-
*
337-
* @param string $name name.
338-
*
339-
* @return string svg icon
340-
*/
341-
public static function get_icon( $name ) {
342-
$svg = sprintf( '%1$s/static/svg/%2$s.svg', plugin_dir_path( __DIR__ ), $name );
343-
if ( file_exists( $svg ) ) {
344-
$icon = file_get_contents( $svg );
345-
if ( $icon ) {
346-
return sprintf( '<span class="svg-icon svg-%1$s" aria-hidden="true" aria-label="%2$s" title="%2$s" >%3$s</span>', esc_attr( $name ), esc_attr( $name ), $icon );
347-
}
348-
}
349-
return '';
350-
}
351-
352259
/**
353260
* returns an array of links from the user profile to be used as rel-me
354261
*/
@@ -389,7 +296,7 @@ public static function get_rel_me( $author_id = null ) {
389296
}
390297
$relme = self::clean_urls( $relme );
391298
foreach ( $relme as $url ) {
392-
$list[ self::extract_domain_name( $url ) ] = $url;
299+
$list[ preg_replace( '/^www\./', '', wp_parse_url( $url, PHP_URL_HOST ) ) ] = $url;
393300
}
394301
}
395302
return array_unique( $list );
@@ -413,15 +320,11 @@ public static function get_rel_me_list( $author_id = null, $include_rel = false
413320
$author_name = get_the_author_meta( 'display_name', $author_id );
414321
$r = array();
415322
foreach ( $list as $silo => $profile_url ) {
416-
$name = self::url_to_name( $profile_url );
417-
if ( in_array( $name, array( 'notice', 'website' ), true ) ) {
418-
$title = self::extract_domain_name( $profile_url );
419-
} else {
420-
$title = self::get_title( $name );
421-
}
323+
$name = Rel_Me_Domain_Icon_Map::url_to_name( $profile_url );
324+
$title = Rel_Me_Domain_Icon_Map::get_title( $name );
422325
$r[ $silo ] = '<a ' . ( $include_rel ? 'rel="me" ' : '' ) . 'class="icon-' .
423326
$silo . ' url u-url" href="' . esc_url( $profile_url ) . '" title="' . esc_attr( $author_name ) . ' @ ' .
424-
esc_attr( $title ) . '"><span class="relmename">' . esc_attr( $silo ) . '</span>' . self::get_icon( $name ) . '</a>';
327+
esc_attr( $title ) . '"><span class="relmename">' . esc_attr( $silo ) . '</span>' . Rel_Me_Domain_Icon_Map::get_icon( $name ) . '</a>';
425328
}
426329

427330
$r = "<div class='relme'><ul>\n<li>" . join( "</li>\n<li>", $r ) . "</li>\n</ul></div>";

includes/class-plugin-installer.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ public static function render_template( $plugin, $api, $button_text, $button_cla
124124
$icon = $api->icons['default'];
125125
}
126126

127-
$install_url = add_query_arg( array(
128-
'action' => 'install-plugin',
129-
'plugin' => $api->slug,
130-
'_wpnonce' => wp_create_nonce( 'install-plugin_' . $api->slug ),
131-
), get_admin_url( null, '/update.php' ) );
127+
$install_url = add_query_arg(
128+
array(
129+
'action' => 'install-plugin',
130+
'plugin' => $api->slug,
131+
'_wpnonce' => wp_create_nonce( 'install-plugin_' . $api->slug ),
132+
),
133+
get_admin_url( null, '/update.php' )
134+
);
132135
?>
133136
<div class="plugin">
134137
<div class="plugin-wrap">
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
/* Maps domain names to icons from the provided SVG fontset
3+
*/
4+
class Rel_Me_Domain_Icon_Map {
5+
6+
// Common mappings and custom mappings
7+
private static $map = array(
8+
'twitter.com' => 'twitter',
9+
'facebook.com' => 'facebook',
10+
'swarmapp.com' => 'swarm',
11+
'instagram.com' => 'instagram',
12+
'play.google.com' => 'googleplay',
13+
'plus.google.com' => 'googleplus',
14+
'podcasts.google.com' => 'googlepodcasts',
15+
'podcasts.apple.com' => 'applepodcasts',
16+
'indieweb.xyz' => 'info',
17+
'getpocket.com' => 'pocket',
18+
'flip.it' => 'flipboard',
19+
'micro.blog' => 'micro-dot-blog',
20+
'wordpress.org' => 'wordpress',
21+
'wordpress.com' => 'wordpress',
22+
'itunes.apple.com' => 'applemusic',
23+
'reading.am' => 'book',
24+
25+
);
26+
27+
// Try to get the correct icon for the majority of sites
28+
public static function split_domain( $string ) {
29+
$explode = explode( '.', $string );
30+
if ( 2 === count( $explode ) ) {
31+
return $explode[0];
32+
}
33+
if ( 3 === count( $explode ) ) {
34+
return $explode[1];
35+
}
36+
return $string;
37+
}
38+
39+
// Return the filename of an icon based on name if the file exists
40+
public static function get_icon_filename( $name ) {
41+
$svg = sprintf( '%1$s/static/svg/%2$s.svg', plugin_dir_path( __DIR__ ), $name );
42+
if ( file_exists( $svg ) ) {
43+
return $svg;
44+
}
45+
return null;
46+
}
47+
48+
// Return the retrieved svg based on name
49+
public static function get_icon_svg( $name ) {
50+
$file = self::get_icon_filename( $name );
51+
if ( $file ) {
52+
$icon = file_get_contents( $file ); // phpcs:ignore
53+
if ( $icon ) {
54+
return $icon;
55+
}
56+
}
57+
return null;
58+
}
59+
60+
public static function get_icon( $name ) {
61+
$icon = self::get_icon_svg( $name );
62+
$title = self::get_title( $name );
63+
if ( $icon ) {
64+
return sprintf( '<span class="svg-icon svg-%1$s" aria-hidden="true" aria-label="%2$s" title="%2$s" >%3$s</span>', esc_attr( $name ), esc_attr( $title ), $icon );
65+
}
66+
return $name;
67+
}
68+
69+
public static function get_title( $name ) {
70+
$strings = simpleicons_iw_get_names();
71+
if ( isset( $strings[ $name ] ) ) {
72+
return $strings[ $name ];
73+
}
74+
return $name;
75+
}
76+
77+
public static function mastodon_url() {
78+
$mastodon = get_transient( 'indieweb_mastodon' );
79+
if ( false !== $mastodon ) {
80+
return $mastodon;
81+
}
82+
$args = array(
83+
'number' => 1,
84+
'count_total' => false,
85+
'meta_query' => array(
86+
array(
87+
'key' => 'mastodon',
88+
'compare' => 'EXISTS',
89+
),
90+
),
91+
);
92+
$query = new WP_User_Query( $args );
93+
$results = $query->get_results();
94+
if ( empty( $results ) ) {
95+
$value = false;
96+
} else {
97+
$user = $results[0];
98+
$value = get_user_meta( $user->ID, 'mastodon', true );
99+
if ( ! empty( $value ) && is_string( $value ) ) {
100+
$value = wp_parse_url( $value, PHP_URL_HOST );
101+
}
102+
}
103+
set_transient( 'indieweb_mastodon', $value );
104+
}
105+
106+
public static function url_to_name( $url ) {
107+
$scheme = wp_parse_url( $url, PHP_URL_SCHEME );
108+
// The default if not an http link is to return notice
109+
$return = 'notice';
110+
if ( ( 'http' === $scheme ) || ( 'https' === $scheme ) ) {
111+
$return = 'website'; // default for web links
112+
$url = strtolower( $url );
113+
$domain = wp_parse_url( $url, PHP_URL_HOST );
114+
115+
$domain = str_replace( 'www.', '', $domain ); // Always remove www
116+
117+
// If the domain is already on the pre-loaded list then use that
118+
if ( array_key_exists( $domain, self::$map ) ) {
119+
$return = self::$map[ $domain ];
120+
} elseif ( self::mastodon_url() === $domain ) {
121+
$return = 'mastodon';
122+
} else {
123+
// Remove extra info and try to map it to an icon
124+
$strip = self::split_domain( $domain );
125+
if ( self::get_icon_filename( $strip ) ) {
126+
$return = $strip;
127+
} elseif ( self::get_icon_filename( str_replace( '.', '-dot-', $domain ) ) ) {
128+
$return = str_replace( '.', '-dot-', $domain );
129+
} elseif ( self::get_icon_filename( str_replace( '.', '', $domain ) ) ) {
130+
$return = str_replace( '.', '', $domain );
131+
} else if ( false !== stripos( $domain, 'wordpress' ) ) { // phpcs:ignore
132+
// Anything with WordPress in the name that is not matched return WordPress
133+
$return = 'wordpress'; // phpcs:ignore
134+
} else if ( false !== stripos( $domain, 'read' ) ) { // phpcs:ignore
135+
// Anything with read in the name that is not matched return a book
136+
$return = 'book'; // phpcs:ignore
137+
} else if ( false !== stripos( $domain, 'news' ) ) { // phpcs:ignore
138+
// Anything with news in the name that is not matched return the summary icon
139+
$return = 'summary'; // phpcs:ignore
140+
} else {
141+
// Some domains have the word app in them check for matches with that
142+
$strip = str_replace( 'app', '', $strip );
143+
if ( self::get_icon_filename( $strip ) ) {
144+
$return = $strip;
145+
}
146+
}
147+
}
148+
}
149+
if ( 'sms' === $scheme ) {
150+
return 'phone';
151+
}
152+
if ( 'mailto' === $scheme ) {
153+
return 'mail';
154+
}
155+
if ( 'gtalk' === $scheme ) {
156+
return 'googlehangouts';
157+
}
158+
// Save the determined mapping into the map so that it will not have to look again on the same page load
159+
self::$map[ $domain ] = $return;
160+
$return = apply_filters( 'indieweb_links_url_to_name', $return, $url );
161+
return $return;
162+
}
163+
164+
}
165+

includes/class-relme-widget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RelMe_Widget extends WP_Widget {
1111
public function __construct() {
1212
parent::__construct(
1313
'RelMe_Widget',
14-
__( 'Rel=Me Links', 'indieweb' ),
14+
__( 'Show My Profiles on Other Sites', 'indieweb' ),
1515
array(
1616
'description' => __( 'Adds automatic rel-me URLs based on default author profile information. Rel=me links are links to your presence on other websites and visually appear like many social link widgets', 'indieweb' ),
1717
)

0 commit comments

Comments
 (0)