From 5befce51ef9f38609b713cfbc6095a3b60b1d574 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 10 Apr 2014 19:15:31 +0200 Subject: add proxy support based on simplepie pr, fix #491 --- articleenhancer/xpatharticleenhancer.php | 39 ++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'articleenhancer') diff --git a/articleenhancer/xpatharticleenhancer.php b/articleenhancer/xpatharticleenhancer.php index 50dc402cc..0d7589fec 100644 --- a/articleenhancer/xpatharticleenhancer.php +++ b/articleenhancer/xpatharticleenhancer.php @@ -36,6 +36,7 @@ class XPathArticleEnhancer implements ArticleEnhancer { private $feedRegex; private $fileFactory; private $maximumTimeout; + private $config; /** @@ -50,6 +51,7 @@ class XPathArticleEnhancer implements ArticleEnhancer { $this->regexXPathPair = $regexXPathPair; $this->fileFactory = $fileFactory; $this->maximumTimeout = $config->getFeedFetcherTimeout(); + $this->config = $config; } @@ -58,13 +60,7 @@ class XPathArticleEnhancer implements ArticleEnhancer { foreach($this->regexXPathPair as $regex => $search) { if(preg_match($regex, $item->getUrl())) { - $file = $this->fileFactory->getFile( - $item->getUrl(), - $this->maximumTimeout, - 5, - null, - "Mozilla/5.0 AppleWebKit" - ); + $file = $this->getFile($item->getUrl()); // convert encoding by detecting charset from header $contentType = $file->headers['content-type']; @@ -98,6 +94,35 @@ class XPathArticleEnhancer implements ArticleEnhancer { } + private function getFile($url) { + if(trim($this->config->getProxyHost()) === '') { + return $this->fileFactory->getFile( + $url, + $this->maximumTimeout, + 5, + null, + "Mozilla/5.0 AppleWebKit", + false, + null, + null, + null + ); + } else { + return $this->fileFactory->getFile( + $url, + $this->maximumTimeout, + 5, + null, + "Mozilla/5.0 AppleWebKit", + false, + $this->config->getProxyHost(), + $this->config->getProxyPort(), + $this->config->getProxyAuth() + ); + } + } + + /** * Method which converts all relative "href" and "src" URLs of * a HTML snippet with their absolute equivalent -- cgit v1.2.3