Created
November 16, 2009 03:45
-
-
Save nobodyplace/235709 to your computer and use it in GitHub Desktop.
Smarty plugin to shorten url with bit.ly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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