1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class LilUrlPlugin extends UrlShortenerPlugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public $serviceUrl;
- function onInitializePlugin(){
- parent::onInitializePlugin();
- if(!isset($this->serviceUrl)){
-
- throw new Exception(_m('A serviceUrl must be specified.'));
- }
- }
- 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 strval($x['href']);
- }
- }
- public function onPluginVersion(array &$versions): bool
- {
- $versions[] = array('name' => sprintf('LilUrl (%s)', $this->shortenerName),
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Craig Andrews',
- 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/LilUrl',
- 'rawdescription' =>
-
-
- sprintf(_m('Uses <a href="http://%1$s/">%1$s</a> URL-shortener service.'),
- $this->shortenerName));
- return true;
- }
- }
|