]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TightUrl/TightUrlPlugin.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / TightUrl / TightUrlPlugin.php
index 48efb355f03dd619668f7be9c493230ff109986a..8fd645945b0f5577481697a61821acb03ea5b3bc 100644 (file)
@@ -22,7 +22,7 @@
  * @category  Plugin
  * @package   StatusNet
  * @author    Craig Andrews <candrews@integralblue.com>
- * @copyright 2009 Craig Andrews http://candrews.integralblue.com
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -31,32 +31,40 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-class TightUrlPlugin extends Plugin
+class TightUrlPlugin extends UrlShortenerPlugin
 {
-    function __construct()
-    {
-        parent::__construct();
-    }
+    public $serviceUrl;
 
     function onInitializePlugin(){
-        $this->registerUrlShortener(
-            '2tu.us',
-            array('freeService'=>true),
-            array('TightUrl',array('http://2tu.us/?save=y&url='))
-        );
+        parent::onInitializePlugin();
+        if(!isset($this->serviceUrl)){
+            throw new Exception("must specify a serviceUrl");
+        }
     }
-}
 
-class TightUrl 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->p[0]->code[0]->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('TightUrl (%s)', $this->shortenerName),
+                            'version' => STATUSNET_VERSION,
+                            'author' => 'Craig Andrews',
+                            'homepage' => 'http://status.net/wiki/Plugin:TightUrl',
+                            'rawdescription' =>
+                            sprintf(_m('Uses <a href="http://%1$s/">%1$s</a> URL-shortener service.'),
+                                    $this->shortenerName));
+        return true;
     }
 }