From 10f40661a2f517393331b554c2fec295c8c160e8 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 30 Nov 2009 08:09:30 -0800 Subject: Ticket 1870: drop unnecessary Tidy module installation requirement. Tidy was only being used by a couple of non-default URL shortener plugins, PtitUrl and TightUrl. Both were easily changed to load the tag-soup HTML via DOMDocument (using the default DOM module which is already used by other dependencies). Added xml, dom, and simplexml modules to the requirements check in install.php, as they were being used but not checked for. Also cleaned up LilUrl, PtitUrl, and TightUrl to return URL as a string instead of as a SimpleXML node object. --- plugins/LilUrl/LilUrlPlugin.php | 2 +- plugins/PtitUrl/PtitUrlPlugin.php | 9 ++++++--- plugins/TightUrl/TightUrlPlugin.php | 9 ++++++--- plugins/UrlShortener/UrlShortenerPlugin.php | 8 -------- 4 files changed, 13 insertions(+), 15 deletions(-) (limited to 'plugins') diff --git a/plugins/LilUrl/LilUrlPlugin.php b/plugins/LilUrl/LilUrlPlugin.php index e906751e8..4a6f1cdc7 100644 --- a/plugins/LilUrl/LilUrlPlugin.php +++ b/plugins/LilUrl/LilUrlPlugin.php @@ -54,7 +54,7 @@ class LilUrlPlugin extends UrlShortenerPlugin if (!isset($y->body)) return; $x = $y->body->p[0]->a->attributes(); if (isset($x['href'])) { - return $x['href']; + return strval($x['href']); } } } diff --git a/plugins/PtitUrl/PtitUrlPlugin.php b/plugins/PtitUrl/PtitUrlPlugin.php index ef453e96d..76a438dd5 100644 --- a/plugins/PtitUrl/PtitUrlPlugin.php +++ b/plugins/PtitUrl/PtitUrlPlugin.php @@ -47,11 +47,14 @@ class PtitUrlPlugin extends UrlShortenerPlugin { $response = $this->http_get(sprintf($this->serviceUrl,urlencode($url))); if (!$response) return; - $response = $this->tidy($response); - $y = @simplexml_load_string($response); + $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']; + if (isset($xml['href'])) { + return strval($xml['href']); + } } } diff --git a/plugins/TightUrl/TightUrlPlugin.php b/plugins/TightUrl/TightUrlPlugin.php index 56414c8c8..6ced9afdc 100644 --- a/plugins/TightUrl/TightUrlPlugin.php +++ b/plugins/TightUrl/TightUrlPlugin.php @@ -48,10 +48,13 @@ class TightUrlPlugin extends UrlShortenerPlugin { $response = $this->http_get(sprintf($this->serviceUrl,urlencode($url))); if (!$response) return; - $response = $this->tidy($response); - $y = @simplexml_load_string($response); + $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']; + if (isset($xml['href'])) { + return strval($xml['href']); + } } } diff --git a/plugins/UrlShortener/UrlShortenerPlugin.php b/plugins/UrlShortener/UrlShortenerPlugin.php index 37206aa89..027624b7a 100644 --- a/plugins/UrlShortener/UrlShortenerPlugin.php +++ b/plugins/UrlShortener/UrlShortenerPlugin.php @@ -68,14 +68,6 @@ abstract class UrlShortenerPlugin extends Plugin return $response->getBody(); } - protected function tidy($response) { - $response = str_replace(' ', ' ', $response); - $config = array('output-xhtml' => true); - $tidy = new tidy; - $tidy->parseString($response, $config, 'utf8'); - $tidy->cleanRepair(); - return (string)$tidy; - } //------------Below are the methods that connect StatusNet to the implementing Url Shortener plugin------------\\ function onInitializePlugin(){ -- cgit v1.2.3-54-g00ecf