X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FLilUrl%2FLilUrlPlugin.php;h=0ca3d3d6bed21c58402d1f3a2dd072c71c0e04b0;hb=c97048d01bea468e0cf8865b60c3c250b4515c39;hp=852253b02326c91ea2e228b5c40c12a36498836a;hpb=2d8ad0409d8e78ec35a65156bc375eacbe561963;p=quix0rs-gnu-social.git diff --git a/plugins/LilUrl/LilUrlPlugin.php b/plugins/LilUrl/LilUrlPlugin.php index 852253b023..0ca3d3d6be 100644 --- a/plugins/LilUrl/LilUrlPlugin.php +++ b/plugins/LilUrl/LilUrlPlugin.php @@ -22,7 +22,7 @@ * @category Plugin * @package StatusNet * @author Craig Andrews - * @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,37 +31,44 @@ if (!defined('STATUSNET')) { exit(1); } -require_once(INSTALLDIR.'/lib/Shorturl_api.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)){ + // TRANS: Exception thrown when URL shortening plugin was configured incorrectly. + throw new Exception(_m('A serviceUrl must be specified.')); + } } -} -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'])) { - common_log(LOG_INFO, __CLASS__ . ": shortened $url to $x[href]"); - return $x['href']; + return strval($x['href']); } - return $url; + } + + 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' => + // TRANS: Plugin description. + // TRANS: %1$s is the service URL. + sprintf(_m('Uses %1$s URL-shortener service.'), + $this->shortenerName)); + + return true; } }