jovanzers / dabr

Automatically exported from code.google.com/p/dabr
0 stars 0 forks source link

Expend short URLs on server side #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What would you like dabr to do?
Since the GFW (or gov of China) began blocking bit.ly and j.mp, most dabr
users in China cannot access the URLs shortened by bit.ly.I think the short
url expend work can be done on server side, makes it easier for people
inside the wall...

How would you prefer dabr to do it?
This is my modification:

Index: twitter.php
===================================================================
--- twitter.php (revision 217)
+++ twitter.php (working copy)
@@ -318,9 +318,17 @@
   if (setting_fetch('gwt') == 'on') {
     $encoded = urlencode($url);
     return "<a href='http://google.com/gwt/n?u={$encoded}'
target='_blank'>{$url}</a>";
-  } else {
-    return theme('external_link', $url);
-  }
+  }
+  else
if(preg_match('/http:\/\/bit\.ly\/([a-z0-9]{5}[a-z0-9]*)/i',$url,$match)){
+     $url_id = $match[1];
+     $str =
file_get_contents("http://api.bit.ly/expand?version=2.0.1&shortUrl=".$url."&logi
n=".BITLY_LOGIN."&apiKey=".BITLY_API_KEY);

+     $arr = json_decode($str,TRUE);
+     if($arr['errorCode']==0){
+         $longurl = $arr['results'][$url_id]['longUrl'];
+         return "<a href='".$longurl."' target='_blank' >".$url."</a>";
+     }
+  }
+  return theme('external_link', $url);
 }

This is hard coded and ugly. Maybe you can do it in another way.

Original issue reported on code.google.com by cnye...@gmail.com on 13 Oct 2009 at 3:41

GoogleCodeExporter commented 9 years ago
or get the expand url like the code in the function twitter_url_shorten_callback

 else if(preg_match('/http:\/\/bit\.ly\/([a-z0-9]{5}[a-z0-9]*)/i',$url,$match)) {
    $url_id = $match[1];
    $request =
'http://api.bit.ly/expand?version=2.0.1&hash='.$url_id.'&login='.BITLY_LOGIN.'&a
piKey='.BITLY_API_KEY;
    $json = json_decode(twitter_fetch($request));
    if ($json->errorCode == 0) {
      $results = (array) $json->results;
      $result = array_pop($results);
      return "<a href='".$result->longUrl."' target='_blank' >".$url."</a>";
    }
  }

Original comment by LanG.asnama on 13 Oct 2009 at 7:09

GoogleCodeExporter commented 9 years ago
Hi there~
I found there is a long_url function commented out in common/twitter.php
Why not just enable this function by default, or provide an option to enable 
this
feature?

Original comment by cnye...@gmail.com on 16 Oct 2009 at 3:25

GoogleCodeExporter commented 9 years ago
This is available since R234 http://code.google.com/p/dabr/source/detail?r=234
It is not enabled by default on dabr.co.uk because it does slow things down (a 
little).
It will also produce some *very* long URLs which may cause problems with text 
wrapping.

You can enable it on your own server by uncommenting 
    // define('LONGURL_KEY', 'true');
in config.php

Original comment by terence.eden on 17 Nov 2009 at 10:25

GoogleCodeExporter commented 9 years ago
made modification to batch api calls to expand short URLs. Also made the 
display show 
only the domain part of the link rather than the entire link (like on slashdot)

curious for feedback on the way I did it

Original comment by ldoug...@gmail.com on 5 Dec 2009 at 10:26

Attachments:

GoogleCodeExporter commented 9 years ago
let's do the simple way to make url's 

http://php.net/manual/en/function.get-headers.php

and just get the redirect header :)

Original comment by necenzu...@gmail.com on 13 May 2010 at 11:26

GoogleCodeExporter commented 9 years ago
@necenzurat

Good job:-)

Original comment by cnye...@gmail.com on 14 May 2010 at 1:53

GoogleCodeExporter commented 9 years ago
how do you know which URL is a shortened URL? Couldn't resolving this for all 
URLs
sometimes break the thumbnail code?

Original comment by ldoug...@gmail.com on 16 May 2010 at 2:46

GoogleCodeExporter commented 9 years ago
We now use Twitter Entities to expand all URLs
http://dev.twitter.com/pages/tweet_entities

Twitter's display guidelines say we still have to go via the URL shortner.  But 
you can modify your own twitter so it avoids bit.ly etc

Original comment by terence.eden on 13 Jun 2011 at 12:10