Permalink
Browse files

Reduced redundant code thanks to help from Adam Harley

  • Loading branch information...
1 parent 7bc2c56 commit 34a6afeff60a6b1f3259d2fb0b8efe0a09bcae35 @tw2113 committed Jun 19, 2011
Showing with 48 additions and 125 deletions.
  1. +48 −125 social_media_shortcode_plugin.php
@@ -3,132 +3,55 @@
Plugin Name: Social Media Shortcode Pack
Plugin URI: http://michaelbox.net
Description: Plugin that declares shortcodes for several different social media websites. Makes it easier to provide semantic links to them when linking a user ID.
-Version: 1.0
+Version: 1.1
Author: Michael Beckwith
Author URI: http://michaelbox.net
*/
-function social_link_sc($service, $link, $atts){
- extract(shortcode_atts( array(
- 'name' => '',
- 'text' => '',
- ), $atts));
-
- if ( empty($text) )
- $text = "$name ($service)";
-
- return "<a href=\"$link/$name\" title=\"$name's $service profile\">$text</a>";
-}
-//First is the service name, then the profile url sans user ID. Gets passed to social_link_sc and has the actual link returned.
-function twitter_sc($atts){
- return social_link_sc('Twitter', 'http://twitter.com', $atts);
-}
-function identica_sc($atts){
- return social_link_sc('Identica', 'http://identi.ca', $atts);
-}
-function facebook_sc($atts){
- return social_link_sc('Facebook', 'http://www.facebook.com', $atts);
-}
-function reddit_sc($atts){
- return social_link_sc('Reddit', 'http://www.reddit.com/user', $atts);
-}
-function linkedin_sc($atts){
- return social_link_sc('Linkedin', 'http://www.linkedin.com/in', $atts);
-}
-function stumbleupon_sc($atts){
- return social_link_sc('StumbleUpon', 'http://www.stumbleupon.com/stumbler', $atts);
-}
-function myspace_sc($atts){
- return social_link_sc('Myspace', 'http://www.myspace.com', $atts);
-}
-function digg_sc($atts){
- return social_link_sc('Digg', 'http://www.digg.com', $atts);
-}
-function foursquare_sc($atts){
- return social_link_sc('Foursquare', 'http://foursquare.com', $atts);
-}
-function delicious_sc($atts){
- return social_link_sc('Delicious', 'http://www.delicious.com', $atts);
-}
-function youtube_sc($atts){
- return social_link_sc('Youtube', 'http://www.youtube.com', $atts);
-}
-function gowalla_sc($atts){
- return social_link_sc('Gowalla', 'http://www.gowalla.com/users', $atts);
-}
-function flickr_sc($atts){
- return social_link_sc('Flickr', 'http://www.flickr.com/photos', $atts);
-}
-function vimeo_sc($atts){
- return social_link_sc('Vimeo', 'http://www.vimeo.com', $atts);
-}
-function stickam_sc($atts){
- return social_link_sc('Stickam', 'http://www.stickam.com', $atts);
-}
-function scribd_sc($atts){
- return social_link_sc('Scribd', 'http://www.scribd.com', $atts);
-}
-function slideshare_sc($atts){
- return social_link_sc('Slideshare', 'http://www.slideshare.net', $atts);
-}
-function dailybooth_sc($atts){
- return social_link_sc('Daily Booth', 'http://www.dailybooth.com', $atts);
-}
-function codesnippit_sc($atts){
- return social_link_sc('Codesnipp.it', 'http://www.codesnipp.it', $atts);
-}
-function forrst_sc($atts){
- return social_link_sc('Forrst', 'http://www.forrst.com/people', $atts);
-}
-function dribbble_sc($atts){
- return social_link_sc('Dribbble', 'http://www.dribbble.com', $atts);
-}
-function lastfm_sc($atts){
- return social_link_sc('Last.fm', 'http://www.last.fm/user', $atts);
-}
-function favstarfm_sc($atts){
- return social_link_sc('Favstar.fm', 'http://www.favstar.fm/users', $atts);
-}
-function okcupid_sc($atts){
- return social_link_sc('Okcupid', 'http://www.okcupid.com/profile', $atts);
-}
-function github_sc($atts){
- return social_link_sc('Github', 'https://github.com/', $atts);
-}
-function programmableweb_sc($atts){
- return social_link_sc('Programmable Web', 'http://www.programmableweb.com/profile', $atts);
-}
-function colourlovers_sc($atts){
- return social_link_sc('Colourlovers', 'http://www.colourlovers.com/lover', $atts);
-}
-
-//foreach loop
-add_shortcode('twitter', 'twitter_sc');
-add_shortcode('identica', 'identica_sc');
-add_shortcode('facebook', 'facebook_sc');
-add_shortcode('reddit', 'reddit_sc');
-add_shortcode('linkedin', 'linkedin_sc');
-add_shortcode('stumbleupon', 'stumbleupon_sc');
-add_shortcode('myspace', 'myspace_sc');
-add_shortcode('digg', 'digg_sc');
-add_shortcode('foursquare', 'foursquare_sc');
-add_shortcode('delicious', 'delicious_sc');
-add_shortcode('youtube', 'youtube_sc');
-add_shortcode('gowalla', 'gowalla_sc');
-add_shortcode('flickr', 'flickr_sc');
-add_shortcode('vimeo', 'vimeo_sc');
-add_shortcode('stickam', 'stickam_sc');
-add_shortcode('scribd', 'scribd_sc');
-add_shortcode('slideshare', 'slideshare_sc');
-add_shortcode('dailybooth', 'dailybooth_sc');
-add_shortcode('codesnippit', 'codesnippit_sc');
-add_shortcode('forrst', 'forrst_sc');
-add_shortcode('dribbble', 'dribbble_sc');
-add_shortcode('lastfm', 'lastfm_sc');
-add_shortcode('favstarfm', 'favstarfm_sc');
-add_shortcode('okcupid', 'okcupid_sc');
-add_shortcode('github', 'github_sc');
-add_shortcode('programmableweb', 'programmableweb_sc');
-add_shortcode('colourlovers', 'colourlovers_sc');
-
-?>
+$my_shortcodes = array(
+ 'identica' => array( 'Identica', 'http://identi.ca' ),
+ 'facebook' => array( 'Facebook', 'http://www.facebook.com' ),
+ 'twitter' => array( 'Twitter', 'http://twitter.com' ),
+ 'reddit' => array('Reddit', 'http://www.reddit.com/user'),
+ 'linkedin' => array('Linkedin', 'http://www.linkedin.com/in'),
+ 'stumbleupon' => array('StumbleUpon', 'http://www.stumbleupon.com/stumbler'),
+ 'myspace' => array('Myspace', 'http://www.myspace.com'),
+ 'digg' => array('Digg', 'http://www.digg.com'),
+ 'foursquare' => array('Foursquare', 'http://foursquare.com'),
+ 'delicious' => array('Delicious', 'http://www.delicious.com'),
+ 'youtube' => array('Youtube', 'http://www.youtube.com'),
+ 'gowalla' => array('Gowalla', 'http://www.gowalla.com/users'),
+ 'flickr' => array('Flickr', 'http://www.flickr.com/photos'),
+ 'vimeo' => array('Vimeo', 'http://www.vimeo.com'),
+ 'stickam' => array('Stickam', 'http://www.stickam.com'),
+ 'scribd' => array('Scribd', 'http://www.scribd.com'),
+ 'slideshare' => array('Slideshare', 'http://www.slideshare.net'),
+ 'dailybooth' => array('Daily Booth', 'http://www.dailybooth.com'),
+ 'codesnippit' => array('Codesnipp.it', 'http://www.codesnipp.it'),
+ 'forrst' => array('Forrst', 'http://www.forrst.com/people'),
+ 'dribbble' => array('Dribbble', 'http://www.dribbble.com'),
+ 'lastfm' => array('Last.FM', 'http://www.last.fm/user'),
+ 'favstarfm' => array('Favstar.FM', 'http://www.favstar.fm/users'),
+ 'okcupid' => array('OkCupid', 'http://www.okcupid.com/profile'),
+ 'github' => array('Github', 'https://github.com'),
+ 'programmableweb' => array('Programmable Web', 'http://www.programmableweb.com/profile'),
+ 'colourlovers' => array('Colourlovers', 'http://www.colourlovers.com/lover')
+);
+
+foreach( array_keys( $my_shortcodes ) as $shortcode )
+ add_shortcode( $shortcode, 'my_shortcode_handler' );
+
+ function my_shortcode_handler( $atts, $enclosed, $shortcode ) {
+ extract(shortcode_atts( array(
+ 'name' => '',
+ 'text' => '',
+ ), $atts));
+
+ global $my_shortcodes;
+ $service = $my_shortcodes[$shortcode][0];
+ $link = $my_shortcodes[$shortcode][1];
+
+ if ( empty($text) ) $text = "$name ($service)";
+
+ return "<a href=\"$link/$name\" title=\"$name's $service profile\">$text</a>";
+ }

0 comments on commit 34a6afe

Please sign in to comment.