@@ -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> " ;
0 commit comments