1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class PtitUrlPlugin extends UrlShortenerPlugin
- {
- public $serviceUrl;
- function onInitializePlugin(){
- parent::onInitializePlugin();
- if(!isset($this->serviceUrl)){
-
- throw new Exception(_m('You must specify a serviceUrl for ptit URL shortening.'));
- }
- }
- 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 strval($xml['href']);
- }
- }
- function onPluginVersion(&$versions)
- {
- $versions[] = array('name' => sprintf('PtitUrl (%s)', $this->shortenerName),
- 'version' => GNUSOCIAL_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;
- }
- }
|