Expanding URLs in Dabr / Twitter


I hate shortened URLs with a passion.  It makes it hard to see what a link is and whether I've visited it before.  If they fail - like tr.im threatened to do - you lose your links with no way to see where they once went.

So, hurrah for LongURLPlease - a service which takes those horrid little links and turns them in to full sized URLs.

Here's the basic code in PHP to use the service.

function long_url($shortURL)
{
 //Use the LongURLPlease API
 $url = "http://www.longurlplease.com/api/v1.1?q=" . $shortURL;

 //Set up CURL
 $curl_handle=curl_init();
 curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
 curl_setopt($curl_handle,CURLOPT_URL,$url);

 //Get the JSON response
 $url_json = curl_exec($curl_handle);

 //Close the connection
 curl_close($curl_handle);

 //Decode the JSON
 $url_array = json_decode($url_json,true);

 //Get the Long URL out of the array
 $url_long = $url_array["$shortURL"];

 if ($url_long == null) //The service couldn't find a long URL
 {
 return $shortURL;
 }

 return $url_long;
}

So, how should this be displayed to the user in Dabr?

There are three possibilities.

Display

<a href="short.url/foo">VeryVeryLong.Url/Bar</a>

This keeps the redirect, but it displays the full URL for the user.

Pros.

  • Get to see what the content is.
  • Allows the short URL service to record hits etc.

Cons.

  • Won't highlight if you've already visited it.
  • May cause problems if the VeryLong.Url is too long for the screen.

All Change

<a href="VeryVeryLong.Url/Bar">VeryVeryLong.Url/Bar</a>
This completely replaces the short URL.

Pros.

  • Hurrah! No more silly URLs.
  • Will highlight if you've already visited it.
  • You can seen what you're about to click on.

Cons.

  • Breaks any statistics management the short URL service was performing (is this a con? Surely the receiving website should be recording such details?)
  • May cause problems if the VeryLong.Url is too long for the screen.

Background

<a href="VeryVeryLong.Url/Bar">short.url/foo</a>

Pros.

  • Will highlight if you've already visited it.
  • You can seen what you're about to click on if you hover over the URL.
  • Won't cause problems if the URL is too long for the screen.

Cons.

  • Breaks any statistics management the short URL service was performing (is this a con? Surely the receiving website should be recording such details?)
  • User can't immediately see what they're about to click on.

Conclusions

I prefer replacing the URL completely.  I see no value in the various short URL services.  The stats that they gather don't seem any better that those your webserver can provide.

However, long URLs can be messy - especially on small screened devices.

Long URLs on a BlackBerry
Long URLs on a BlackBerry

So, which do you prefer?

7 thoughts on “Expanding URLs in Dabr / Twitter

  1. I think you've missed one possibility that might appeal to you...

    [a href="http://the.real.url/with/all/path/info.html"]page on the.real.url[/a] - or some other shortened form of the real URL as the link text .

    Advantages: Gives people some clue of where they're going, without dumping a six line URL onto a small screen. For maximum w00t, you could only do the trim on the link text if it exceeds a specified length - say 30 chars or something? Loses the shortlink stat gathering.

    Disadvantages: Need to make it clear that the link doesn't go to the site's root page. People would learn, I guess? Loses the shortlink stat gathering.

    1. Hmmm.... a nice idea. The only issue is that you'd see tweets like
      "This is the funniest thing EVER youtube.com"
      or "I can't believe the President did that news.bbc.co.uk".
      Which doens't give as much context as the full URL.

      Perhaps the solution is somewhere in the middle. Show only the first , say, 50 chars of the URL. Enough to get context, but not so much to break things if the URL is huge.

  2. here's how I did it:

    function theme_external_link($url, $content = null) {
    	//Long URL functionality.  Also uncomment function long_url($shortURL)
    	if (!$content)
    	{
    		$longurl = long_url($url);
    		$domain = parse_url(long_url($url));
    		if (setting_fetch('gwt') == 'on') {
    			$encoded = urlencode($longurl);
    			$longurl = "http://google.com/gwt/n?u=$encoded";
    		}
    		return "<a href='$longurl' target='_blank'>[".$domain["host"]."]</a>";
    	}
    	else
    	{
    		return "<a href='$url' target='_blank'>$content</a>";
    	}
    }
    

    I also moved the GWT modifications there since it doesn't handle all shortened urls well, plus I still wanted to get more URL context via the full link if I mousedover it

    hope the code pastes in here correctly

  3. once I put this change in, I realized that it broke the image thumbnails

    so I changed twitter_parse_tags as such:
    $out = twitter_photo_replace($input).$out;

    and changed twitter_photo_replace to only return the imploded images array

    also I'm calling long_url($url) twice up there - yikes!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.