summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:15:31 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:15:31 +0200
commit5befce51ef9f38609b713cfbc6095a3b60b1d574 (patch)
tree0bbe540c109afa83086ed7ad43adb8a215e54633 /utility
parentdb545b430a513e7fda3fba5859972b6c550958b5 (diff)
add proxy support based on simplepie pr, fix #491
Diffstat (limited to 'utility')
-rw-r--r--utility/config.php14
-rw-r--r--utility/faviconfetcher.php22
-rw-r--r--utility/simplepieapifactory.php6
3 files changed, 29 insertions, 13 deletions
diff --git a/utility/config.php b/utility/config.php
index 92d0b9daf..0fa636ea8 100644
--- a/utility/config.php
+++ b/utility/config.php
@@ -41,7 +41,7 @@ class Config {
private $useCronUpdates; // turn off updates run by owncloud cronjob
private $proxyHost;
private $proxyPort;
- private $proxyPassword;
+ private $proxyAuth;
private $api;
@@ -55,7 +55,7 @@ class Config {
$this->api = $api;
$this->proxyHost = '';
$this->proxyPort = 8080;
- $this->proxyPassword = '';
+ $this->proxyAuth = '';
}
public function getProxyPort() {
@@ -66,8 +66,8 @@ class Config {
return $this->proxyHost;
}
- public function getProxyPassword() {
- return $this->proxyPassword;
+ public function getProxyAuth() {
+ return $this->proxyAuth;
}
public function getAutoPurgeMinimumInterval() {
@@ -128,8 +128,8 @@ class Config {
$this->proxyHost = $value;
}
- public function setProxyPassword($value) {
- $this->proxyPassword = $value;
+ public function setProxyAuth($value) {
+ $this->proxyAuth = $value;
}
@@ -172,7 +172,7 @@ class Config {
"useCronUpdates = " . var_export($this->useCronUpdates, true) . "\n" .
"proxyHost = " . $this->proxyHost . "\n" .
"proxyPort = " . $this->proxyPort . "\n" .
- "proxyPassword = " . $this->proxyPassword;
+ "proxyAuth = " . $this->proxyAuth;
;
$this->fileSystem->file_put_contents($configPath, $ini);
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;
}
diff --git a/utility/simplepieapifactory.php b/utility/simplepieapifactory.php
index 5014838d1..65f482095 100644
--- a/utility/simplepieapifactory.php
+++ b/utility/simplepieapifactory.php
@@ -34,10 +34,12 @@ class SimplePieAPIFactory {
* @return SimplePie_File a new object
*/
public function getFile($url, $timeout=10, $redirects=5, $headers=null,
- $useragent=null, $force_fsockopen=false) {
+ $useragent=null, $force_fsockopen=false,
+ $proxyHost=null, $proxyPort=null, $proxyAuth=null) {
return new \SimplePie_File($url, $timeout, $redirects, $headers,
- $useragent, $force_fsockopen);
+ $useragent, $force_fsockopen, $proxyHost, $proxyPort,
+ $proxyAuth);
}