Redid how URL shorteners work. This way is much more like how Evan wants events to work (and more like how the rest of SN works).

This commit is contained in:
Craig Andrews
2009-11-11 14:02:57 -05:00
parent 086759f32a
commit 014d6b1d19
11 changed files with 210 additions and 215 deletions

View File

@@ -31,31 +31,24 @@ if (!defined('STATUSNET')) {
exit(1);
}
class BitlyUrlPlugin extends Plugin
require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php';
class BitlyUrlPlugin extends UrlShortenerPlugin
{
function __construct()
{
parent::__construct();
}
public $serviceUrl;
function onInitializePlugin(){
$this->registerUrlShortener(
'bit.ly',
array(),
array('BitlyUrl',array('http://bit.ly/api?method=shorten&long_url='))
);
}
}
class BitlyUrl extends ShortUrlApi
{
protected function shorten_imp($url) {
$response = $this->http_get($url);
if(!$response){
return $url;
}else{
return current(json_decode($response)->results)->hashUrl;
parent::onInitializePlugin();
if(!isset($this->serviceUrl)){
throw new Exception("must specify a serviceUrl");
}
}
protected function shorten($url) {
$response = $this->http_get($url);
if(!$response) return;
return current(json_decode($response)->results)->hashUrl;
}
}