Forums

[Plugin: Sociable] Shortened URLs (11 posts)

  1. paulholmes
    Member
    Posted 2 years ago #

    I'm loving Sociable. What a terrific plugin!

    It would be really cool to have URL shortener's built in (other than awe.sm, such as bit.ly). Obviously many of the services don't need it, but for Twitter and Identi.ca, and perhaps a few others, this would be a neat feature to have.

    http://wordpress.org/extend/plugins/sociable/

  2. Baden
    Member
    Posted 2 years ago #

    Mark me down for a yes on the bit.ly integration. I am about to google it and if no solution is available, guess we will just have to hack-n-roll our own, eh? I'll post my progress.

  3. Baden
    Member
    Posted 2 years ago #

    Found a solution (in less than the time it took to write that last post—doh!) Check out the end result here: http://www.website-marketing.ch/ and how it's done here: http://webexpedition18.com/articles/how-to-sociable-wp-plugin-with-auto-tinyurl-or-bitly-shortening/

    Cheers!

  4. Baden
    Member
    Posted 2 years ago #

    I posted a fix on that webexpedition post linked above, but it seems that Nikola aka Colaja from Nis, Serbia removed it. Very well, I will post it here.

    The issue I faced when using Coloja's hack was that it generated a shortened url (bit.ly in my case) during the page loop. So, on the main page, where we are showing the latest 10 posts... the loop hit the bit.ly API, get a shortened URL 10 times, adding about 11 seconds to the load time of homepage--not very efficient. What I opted for was to pass permalink to a custom bit2twitt.php file that would bit.ly-ize the link only after the user clicked on it, then redirect to twitter, passing the shorted url.

    To sum up what you need to do:
    1. Open sociable.php and find the following block:

    'Twitter' => Array(
    		'favicon' => 'twitter.png',
    		'awesm_channel' => 'twitter',
    		'url' => 'http://twitter.com/home?status=PERMALINK',
    	),

    and change it to:

    'Twitter' => Array(
    		'favicon' => 'twitter.png',
    		'awesm_channel' => 'twitter',
    		'url' => 'bit2twit.php?url=PERMALINK',
    	),

    2. create a new file called bit2twit.php with the following code:

    <?php
    $url = $_GET['url'];
    // Ondemand function to generate dynamic bit.ly urls
    function getBitlyUrl($url) {
        // fill up this 2 lines below with your login and api key
        $bitlylogin = '<your bit.ly login goes here>';
        $bitlyapikey= '<your bit.ly api key goes here>';
    
        // you dont need to change below this line
        $bitlyurl = file_get_contents('http://api.bit.ly/shorten?version=2.0.1&longUrl='.$url.'&login='.$bitlylogin.'&apiKey='.$bitlyapikey);  
    
        $bitlycontent = json_decode($bitlyurl,true);
    
        $bitlyerror = $bitlycontent["errorCode"];
    
        if ($bitlyerror == 0){
            $bitlyurl = $bitlycontent["results"][$url]["shortUrl"];
        }
        else $bitlyurl = $url;
    
        return $bitlyurl;
    }
    
    header('Location: http://twitter.com/home?status='.getBitlyUrl($url));
    
    ?>

    3. place the bit2twit.php file you just created in your wordpress root and you are golden.

  5. kevindonahue
    Member
    Posted 2 years ago #

    I'm sorry, but... wouldn't this hack be wiped out by future updates to Sociable?

  6. isra17
    Member
    Posted 1 year ago #

    I wrote a patch to support bit.ly with every service (not only twitter) : http://wordpress.org/support/topic/379015?replies=1

  7. victoraroestad
    Member
    Posted 1 year ago #

    I got the following error (I've hidden part of username and api):

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/victorar/public_html/bit2twit.php  on line 10
    
    Warning: file_get_contents(http://api.bit.ly/shorten?version=2.0.1&longUrl=http://www.victoraroestad.com/network-marketing/realtionship-marketing/the-ultimate-secrets-to-relationship-marketing/?&login=v*********&apiKey=R_9db*********1ce3f3ca57b) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/victorar/public_html/bit2twit.php on line 10
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/victorar/public_html/bit2twit.php:10) in /home/victorar/public_html/bit2twit.php on line 24

    What am I doing wrong here?

    Thanks for any help.

  8. reeley
    Member
    Posted 1 year ago #

    This was my take on this:
    bit.ly shortening

    ~Josh

  9. isra17
    Member
    Posted 1 year ago #

    victoraroestad> You server doesn't allow file_get_content to get the content of external url. You try to use HTTP or curl or configure your server (if you have access to it).

  10. Hybris
    Member
    Posted 1 year ago #

    Hello,

    i have the same problem of file_get_content ... but short url work with other plugin... Have you an idea ?

    Kevin

  11. melstan1
    Member
    Posted 1 year ago #

    you can host and customize short urls on your own site using the su.pr plugin by StumbleUpon, apparently. I'm having a hard time understanding how to configure it, but it's free if anyone wants to give it a go.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags