Skip to content

Instantly share code, notes, and snippets.

@yaroot
Created March 29, 2010 13:12
Show Gist options
  • Save yaroot/347818 to your computer and use it in GitHub Desktop.
Save yaroot/347818 to your computer and use it in GitHub Desktop.
function twitter_url_shorten_callback($match) {
if (preg_match('#http://www.flickr.com/photos/[^/]+/(\d+)/#', $match[0], $matches)) {
return 'http://flic.kr/p/'.flickr_encode($matches[1]);
}
/*
if (!defined('BITLY_API_KEY')) return $match[0];
$request = 'http://api.bit.ly/shorten?version=2.0.1&longUrl='.urlencode($match[0]).'&login='.BITLY_LOGIN.'&apiKey='.BITLY_API_KEY;
$json = json_decode(twitter_fetch($request));
if ($json->errorCode == 0) {
$results = (array) $json->results;
$result = array_pop($results);
return $result->shortUrl;
} else {
return $match[0];
}
*/
if (!defined('GOOGLE_URL_SHORTENER')) return $match[0];
$request = 'http://ggl-shortener.appspot.com/?url='.urlencode($match[0]);
$json = json_decode(twitter_fetch($request));//lzq
if (!isset($json->error_message)) {
return $json->short_url;
} else {
return $match[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment