]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/LilUrl/LilUrlPlugin.php
Better log msgs. Removed debugging statement.
[quix0rs-gnu-social.git] / plugins / LilUrl / LilUrlPlugin.php
index 7665b6c1e4f5b1330148b8ec41a9cd9eed5ab460..c3e37c0c0f358a76bde8bf9633992f947fe7c034 100644 (file)
@@ -31,34 +31,44 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once(INSTALLDIR.'/lib/Shorturl_api.php');
+require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php';
 
-class LilUrlPlugin extends Plugin
+class LilUrlPlugin extends UrlShortenerPlugin
 {
-    function __construct()
-    {
-        parent::__construct();
-    }
+    public $serviceUrl;
 
     function onInitializePlugin(){
-        $this->registerUrlShortener(
-            'ur1.ca',
-            array('freeService'=>true),
-            array('LilUrl',array('http://ur1.ca/'))
-        );
+        parent::onInitializePlugin();
+        if(!isset($this->serviceUrl)){
+            throw new Exception("must specify a serviceUrl");
+        }
     }
-}
 
-class LilUrl extends ShortUrlApi
-{
-    protected function shorten_imp($url) {
-        $data['longurl'] = $url;
-        $response = $this->http_post($data);
-        if (!$response) return $url;
-        $y = @simplexml_load_string($response);
-        if (!isset($y->body)) return $url;
+    protected function shorten($url) {
+        $data = array('longurl' => $url);
+
+        $responseBody = $this->http_post($this->serviceUrl,$data);
+
+        if (!$responseBody) return;
+        $y = @simplexml_load_string($responseBody);
+        if (!isset($y->body)) return;
         $x = $y->body->p[0]->a->attributes();
-        if (isset($x['href'])) return $x['href'];
-        return $url;
+        if (isset($x['href'])) {
+            return strval($x['href']);
+        }
+    }
+
+    function onPluginVersion(&$versions)
+    {
+        $versions[] = array('name' => sprintf('LilUrl (%s)', $this->shortenerName),
+                            'version' => STATUSNET_VERSION,
+                            'author' => 'Craig Andrews',
+                            'homepage' => 'http://status.net/wiki/Plugin:LilUrl',
+                            'rawdescription' =>
+                            sprintf(_m('Uses <a href="http://%1$s/">%1$s</a> URL-shortener service.'),
+                                    $this->shortenerName));
+
+        return true;
     }
 }
+