Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Created November 16, 2009 03:45
Show Gist options
  • Save nobodyplace/235709 to your computer and use it in GitHub Desktop.
Save nobodyplace/235709 to your computer and use it in GitHub Desktop.
Smarty plugin to shorten url with bit.ly
function smarty_function_shorten_url($params, &$smarty)
{
//arguments
if(isset($params['url']) === false)
return null;
$url = $params['url'];
//default domain: bit.ly
//can use j.mp if you specify type
$type = (isset($params['type']) === false || $params['type'] != 'jmp') ?
'bitly' :
'jmp';
//requires
require_once 'Services/Bitly.php';
//settings
$login = LOGIN_NAME; //login name
$apikey = API_KEY; //API Key
//try
try {
$b = new Services_Bitly($login, $apikey);
//j.mp
if($type == 'jmp')
$b->changeBaseDomain();
return $b->shorten($url);
} catch (Services_Bitly_Exception $e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment