diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-10 19:15:31 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-10 19:15:31 +0200 |
commit | 5befce51ef9f38609b713cfbc6095a3b60b1d574 (patch) | |
tree | 0bbe540c109afa83086ed7ad43adb8a215e54633 /utility/faviconfetcher.php | |
parent | db545b430a513e7fda3fba5859972b6c550958b5 (diff) |
add proxy support based on simplepie pr, fix #491
Diffstat (limited to 'utility/faviconfetcher.php')
-rw-r--r-- | utility/faviconfetcher.php | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/utility/faviconfetcher.php b/utility/faviconfetcher.php index d5d270a49..ae5d8c184 100644 --- a/utility/faviconfetcher.php +++ b/utility/faviconfetcher.php @@ -28,15 +28,16 @@ namespace OCA\News\Utility; class FaviconFetcher { private $apiFactory; - + private $config; /** * Inject a factory to build a simplepie file object. This is needed because * the file object contains logic in its constructor which makes it * impossible to inject and test */ - public function __construct(SimplePieAPIFactory $apiFactory) { + public function __construct(SimplePieAPIFactory $apiFactory, Config $config) { $this->apiFactory = $apiFactory; + $this->config = $config; } @@ -80,7 +81,7 @@ class FaviconFetcher { return null; } - $file = $this->apiFactory->getFile($url); + $file = $this->getFile($url); if($file->body !== '') { $document = new \DOMDocument(); @@ -99,6 +100,19 @@ class FaviconFetcher { } } + + private function getFile($url) { + if(trim($this->config->getProxyHost()) === '') { + return $this->apiFactory->getFile($url, 10, 5, null, null, false, + null, null, null); + } else { + return $this->apiFactory->getFile($url, 10, 5, null, null, false, + $this->config->getProxyHost(), + $this->config->getProxyPort(), + $this->config->getProxyAuth()); + } + } + /** * Test if the file is an image @@ -111,7 +125,7 @@ class FaviconFetcher { return false; } - $file = $this->apiFactory->getFile($url); + $file = $this->getFile($url); $sniffer = new \SimplePie_Content_Type_Sniffer($file); return $sniffer->image() !== false; } |