From 78d3e2164116f299effb11d25b1971e6d375366e Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 22 Oct 2014 01:35:59 +0200 Subject: get rid of simplepie --- articleenhancer/xpatharticleenhancer.php | 38 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'articleenhancer') diff --git a/articleenhancer/xpatharticleenhancer.php b/articleenhancer/xpatharticleenhancer.php index 7dcb9a340..8e45636d2 100644 --- a/articleenhancer/xpatharticleenhancer.php +++ b/articleenhancer/xpatharticleenhancer.php @@ -17,36 +17,27 @@ use \DOMDocument; use \DOMXpath; use \ZendXml\Security; +use \OCA\News\Utility\PicoFeedClientFactory; use \OCA\News\Db\Item; -use \OCA\News\Utility\SimplePieAPIFactory; -use \OCA\News\Config\Config; - - class XPathArticleEnhancer implements ArticleEnhancer { - - private $fileFactory; private $maximumTimeout; - private $config; + private $clientFactory; private $regexXPathPair; /** - * @param \OCA\News\Utility\SimplePieAPIFactory $fileFactory + * @param \Utility\PicoFeedClientFactory $clientFactory * @param array $regexXPathPair an associative array containing regex to * match the url and the xpath that should be used for it to extract the * page - * @param \OCA\News\Config\Config $config */ - public function __construct(SimplePieAPIFactory $fileFactory, - array $regexXPathPair, - Config $config){ - $this->fileFactory = $fileFactory; + public function __construct(PicoFeedClientFactory $clientFactory, + array $regexXPathPair){ + $this->clientFactory = $clientFactory; $this->regexXPathPair = $regexXPathPair; - $this->config = $config; - $this->maximumTimeout = $config->getFeedFetcherTimeout(); } /** @@ -58,12 +49,7 @@ class XPathArticleEnhancer implements ArticleEnhancer { foreach($this->regexXPathPair as $regex => $search) { if(preg_match($regex, $item->getUrl())) { - $file = $this->getFile($item->getUrl()); - - // convert encoding by detecting charset from header - $contentType = $file->headers['content-type']; - $body = $file->body; - + list($body, $contentType) = $this->getFile($item->getUrl()); if(preg_match('/(?<=charset=)[^;]*/', $contentType, $matches)) { $encoding = $matches[0]; $body = mb_convert_encoding($body, 'HTML-ENTITIES', @@ -103,9 +89,13 @@ class XPathArticleEnhancer implements ArticleEnhancer { private function getFile($url) { - return $this->fileFactory->getFile( - $url, $this->maximumTimeout, 5, null, 'Mozilla/5.0 AppleWebKit' - ); + $client = $this->clientFactory->build(); + $client->execute($url); + $client->setUserAgent('Mozilla/5.0 AppleWebKit'); + return [ + $client->getContent(), + $client->getEncoding() + ]; } -- cgit v1.2.3