URL Sharing Helper


/ Published in: PHP
Save to your folder(s)

This is a quick & dirty helper for pumping out those annoying little link sharing URLS. I've kept it simple, so all it does is return a URL formatted for a particular service.

To use it, just pass a string of the service name to the helper followed by the title. This could definitely be taken to the next level by adding a parameter for the URL, but my needs were incompatible with such a feature.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. #
  4. # URL Sharing Helper
  5. #
  6.  
  7. if ( ! function_exists('share' ))
  8. {
  9. function share($media, $title = '' )
  10. {
  11. $encoded_url = urlencode('http://yourdomain.com');
  12. $encoded_title = urlencode($title);
  13.  
  14. if ( $media == 'twitter' ) return "http://twitter.com/home?status=$encoded_url";
  15. if ( $media == 'technorati' ) return "http://technorati.com/faves/?add=$encoded_url";
  16. if ( $media == 'stumbleupon' ) return "http://www.stumbleupon.com/submit?url=$encoded_url&title=$encoded_title";
  17. if ( $media == 'reddit' ) return "http://reddit.com/submit?url=$encoded_url&title=$encoded_title";
  18. if ( $media == 'myspace' ) return "http://www.myspace.com/Modules/PostTo/Pages/?u=$encoded_url&t=$encoded_title&c=%20";
  19. if ( $media == 'magnolia' ) return "http://ma.gnolia.com/bookmarklet/add?url=$encoded_url&title=$encoded_title";
  20. if ( $media == 'google' ) return "http://www.google.com/bookmarks/mark?op=add&bkmk=$encoded_url&title=$encoded_title";
  21. if ( $media == 'linkedin' ) return "http://www.linkedin.com/shareArticle?mini=true&url=$encoded_url&title=$encoded_title&ro=false&summary=&source=";
  22. if ( $media == 'furl' ) return "http://www.furl.net/savedialog.jsp?p=1&u=$encoded_url&t=$encoded_title&r=&v=1&c=";
  23. if ( $media == 'facebook' ) return "http://www.facebook.com/sharer.php?u=$encoded_url&t=$encoded_title";
  24. if ( $media == 'friendfeed' ) return "http://friendfeed.com/share?url=$encoded_url&title=$encoded_title";
  25. if ( $media == 'bebo' ) return "http://bebo.com/c/share?Url=$encoded_url&Title=$encoded_title";
  26. if ( $media == 'delicious' ) return "http://del.icio.us/post?v=4&partner=[partner]&noui&url=$encoded_url&title=$encoded_title";
  27. }
  28. }

URL: http://brettbergeron.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.