]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/PtitUrl/PtitUrlPlugin.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / plugins / PtitUrl / PtitUrlPlugin.php
index f00d3e2f218944a21b554d248e50583f58c05022..ddba942e6d4ab7eb07a8b70306cf5e5f8849cae1 100644 (file)
 if (!defined('STATUSNET')) {
     exit(1);
 }
+require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php';
 
-class PtitUrlPlugin extends Plugin
+class PtitUrlPlugin extends UrlShortenerPlugin
 {
-    function __construct()
-    {
-        parent::__construct();
-    }
+    public $serviceUrl;
 
     function onInitializePlugin(){
-        $this->registerUrlShortener(
-            'ptiturl.com',
-            array(),
-            array('PtitUrl',array('http://ptiturl.com/?creer=oui&action=Reduire&url='))
-        );
+        parent::onInitializePlugin();
+        if(!isset($this->serviceUrl)){
+            throw new Exception("must specify a serviceUrl");
+        }
     }
-}
 
-class PtitUrl extends ShortUrlApi
-{
-    protected function shorten_imp($url) {
-        $response = $this->http_get($url);
-        if (!$response) return $url;
-        $response = $this->tidy($response);
-        $y = @simplexml_load_string($response);
-        if (!isset($y->body)) return $url;
+    protected function shorten($url)
+    {
+        $response = $this->http_get(sprintf($this->serviceUrl,urlencode($url)));
+        if (!$response) return;
+        $dom = new DOMDocument();
+        @$dom->loadHTML($response);
+        $y = @simplexml_import_dom($dom);
+        if (!isset($y->body)) return;
         $xml = $y->body->center->table->tr->td->pre->a->attributes();
-        if (isset($xml['href'])) return $xml['href'];
-        return $url;
+        if (isset($xml['href'])) {
+            return strval($xml['href']);
+        }
+    }
+
+    function onPluginVersion(&$versions)
+    {
+        $versions[] = array('name' => sprintf('PtitUrl (%s)', $this->shortenerName),
+                            'version' => STATUSNET_VERSION,
+                            'author' => 'Craig Andrews',
+                            'homepage' => 'http://status.net/wiki/Plugin:PtitUrl',
+                            'rawdescription' =>
+                            sprintf(_m('Uses <a href="http://%1$s/">%1$s</a> URL-shortener service.'),
+                                    $this->shortenerName));
+
+        return true;
     }
 }
+