summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md2
-rw-r--r--config/config.php14
-rw-r--r--controller/admincontroller.php6
-rw-r--r--controller/pagecontroller.php28
-rw-r--r--templates/admin.php19
-rw-r--r--tests/unit/config/ConfigTest.php4
-rw-r--r--tests/unit/controller/AdminControllerTest.php16
-rw-r--r--tests/unit/controller/PageControllerTest.php64
9 files changed, 138 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 240074240..8a713afd3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
owncloud-news (4.1.4)
+* **Enhancement**: Add admin setting to set a custom explore service URL
* **Enhancement**: Add explore button and show explore button on startup
* **Enhancement**: Show a hint when no articles are available
diff --git a/README.md b/README.md
index a849573c3..a6a64482a 100644
--- a/README.md
+++ b/README.md
@@ -172,6 +172,7 @@ maxRedirects = 10
maxSize = 104857600
feedFetcherTimeout = 60
useCronUpdates = true
+exploreUrl =
```
@@ -181,6 +182,7 @@ useCronUpdates = true
* **maxSize**: Maximum feed size in bytes. If the RSS/Atom page is bigger than this value, the update will be aborted
* **feedFetcherTimeout**: Maximum number of seconds to wait for an RSS or Atom feed to load. If a feed takes longer than that number of seconds to update, the update will be aborted
* **useCronUpdates**: To use a custom update/cron script you need to disable the cronjob which is run by ownCloud by default by setting this to false
+* **exploreUrl**: If given that url will be contacted for fetching content for the explore feed
Translations
------------
diff --git a/config/config.php b/config/config.php
index 9cdfa1b0c..0e1eec64b 100644
--- a/config/config.php
+++ b/config/config.php
@@ -30,6 +30,7 @@ class Config {
private $logger;
private $loggerParams;
private $maxSize;
+ private $exploreUrl;
public function __construct($fileSystem, ILogger $logger, $loggerParams) {
@@ -45,6 +46,7 @@ class Config {
$this->proxyPort = 8080;
$this->proxyUser = '';
$this->proxyPassword = '';
+ $this->exploreUrl = '';
$this->loggerParams = $loggerParams;
}
@@ -106,6 +108,11 @@ class Config {
}
+ public function getExploreUrl() {
+ return $this->exploreUrl;
+ }
+
+
public function setAutoPurgeMinimumInterval($value) {
$this->autoPurgeMinimumInterval = $value;
}
@@ -156,6 +163,11 @@ class Config {
}
+ public function setExploreUrl($value) {
+ $this->exploreUrl = $value;
+ }
+
+
public function read($configPath, $createIfNotExists=false) {
if($createIfNotExists && !$this->fileSystem->file_exists($configPath)) {
@@ -202,6 +214,8 @@ class Config {
$this->maxRedirects . "\n" .
'maxSize = ' .
$this->maxSize . "\n" .
+ 'exploreUrl = ' .
+ $this->exploreUrl . "\n" .
'feedFetcherTimeout = ' .
$this->feedFetcherTimeout . "\n" .
'useCronUpdates = ' .
diff --git a/controller/admincontroller.php b/controller/admincontroller.php
index 379d83770..5adaef500 100644
--- a/controller/admincontroller.php
+++ b/controller/admincontroller.php
@@ -42,6 +42,7 @@ class AdminController extends Controller {
'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
'useCronUpdates' => $this->config->getUseCronUpdates(),
'maxSize' => $this->config->getMaxSize(),
+ 'exploreUrl' => $this->config->getExploreUrl(),
];
return new TemplateResponse($this->appName, 'admin', $data, 'blank');
}
@@ -54,17 +55,19 @@ class AdminController extends Controller {
* @param int $feedFetcherTimeout
* @param int $maxSize
* @param bool $useCronUpdates
+ * @param string $exploreUrl
* @return array with the updated values
*/
public function update($autoPurgeMinimumInterval, $autoPurgeCount,
$maxRedirects, $feedFetcherTimeout, $maxSize,
- $useCronUpdates) {
+ $useCronUpdates, $exploreUrl) {
$this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval);
$this->config->setAutoPurgeCount($autoPurgeCount);
$this->config->setMaxRedirects($maxRedirects);
$this->config->setMaxSize($maxSize);
$this->config->setFeedFetcherTimeout($feedFetcherTimeout);
$this->config->setUseCronUpdates($useCronUpdates);
+ $this->config->setExploreUrl($exploreUrl);
$this->config->write($this->configPath);
return [
@@ -75,6 +78,7 @@ class AdminController extends Controller {
'maxSize' => $this->config->getMaxSize(),
'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
'useCronUpdates' => $this->config->getUseCronUpdates(),
+ 'exploreUrl' => $this->config->getExploreUrl(),
];
}
diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php
index d4e7fd0dc..6599a4e49 100644
--- a/controller/pagecontroller.php
+++ b/controller/pagecontroller.php
@@ -81,13 +81,23 @@ class PageController extends Controller {
*/
public function settings() {
$settings = [
- 'showAll',
- 'compact',
- 'preventReadOnScroll',
- 'oldestFirst'
+ 'showAll',
+ 'compact',
+ 'preventReadOnScroll',
+ 'oldestFirst'
];
- $result = ['language' => $this->l10n->getLanguageCode()];
+ $exploreUrl = $this->config->getExploreUrl();
+ if (trim($exploreUrl) === '') {
+ $exploreUrl = $this->urlGenerator->getAbsoluteURL(
+ '/index.php/apps/news/explore'
+ );
+ }
+
+ $result = [
+ 'language' => $this->l10n->getLanguageCode(),
+ 'exploreUrl' => $exploreUrl
+ ];
foreach ($settings as $setting) {
$result[$setting] = $this->settings->getUserValue(
@@ -173,10 +183,10 @@ class PageController extends Controller {
/**
* @NoAdminRequired
- * @NoCSRFRequired
+ *
+ * @param string $lang
*/
- public function explore() {
- $languageCode = $this->l10n->getLanguageCode();
+ public function explore($lang='en') {
$default = 'en';
$this->settings->setUserValue($this->userId, $this->appName,
@@ -184,7 +194,7 @@ class PageController extends Controller {
$this->settings->setUserValue($this->userId, $this->appName,
'lastViewedFeedType', FeedType::EXPLORE);
- return $this->recommendedSites->forLanguage($languageCode, $default);
+ return $this->recommendedSites->forLanguage($lang, $default);
}
diff --git a/templates/admin.php b/templates/admin.php
index 672ea8d64..9f2a815ac 100644
--- a/templates/admin.php
+++ b/templates/admin.php
@@ -103,6 +103,25 @@ style('news', 'admin');
<p><input type="text" name="news-feed-fetcher-timeout"
value="<?php p($_['feedFetcherTimeout']); ?>"></p>
</div>
+ <div class="form-line">
+ <p>
+ <label for="news-explore-url">
+ <?php p($l->t('Explore Service URL')); ?>
+ </label>
+ </p>
+ <p>
+ <em>
+ <?php p($l->t(
+ 'If given, this service\'s URL will be queried for ' .
+ 'displaying the feeds in the explore feed section. To ' .
+ 'fall back to the built in explore service, leave this ' .
+ 'input empty'
+ )); ?>
+ </em>
+ </p>
+ <p><input type="text" name="news-explore-url"
+ value="<?php p($_['exploreUrl']); ?>"></p>
+ </div>
<div id="news-saved-message">
<span class="msg success"><?php p($l->t('Saved')); ?></span>
</div>
diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php
index bdffeb0d1..5baeae3ba 100644
--- a/tests/unit/config/ConfigTest.php
+++ b/tests/unit/config/ConfigTest.php
@@ -50,6 +50,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(null, $this->config->getProxyAuth());
$this->assertEquals('', $this->config->getProxyUser());
$this->assertEquals('', $this->config->getProxyPassword());
+ $this->assertEquals('', $this->config->getExploreUrl());
$this->assertEquals(1024*1024*100, $this->config->getMaxSize());
}
@@ -131,6 +132,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
'autoPurgeCount = 3' . "\n" .
'maxRedirects = 10' . "\n" .
'maxSize = 399' . "\n" .
+ 'exploreUrl = http://google.de' . "\n" .
'feedFetcherTimeout = 60' . "\n" .
'useCronUpdates = true';
$this->config->setAutoPurgeCount(3);
@@ -139,6 +141,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
$this->config->setProxyUser('this is a test');
$this->config->setProxyPassword('se');
$this->config->setMaxSize(399);
+ $this->config->setExploreUrl('http://google.de');
$this->fileSystem->expects($this->once())
->method('file_put_contents')
@@ -166,6 +169,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
'autoPurgeCount = 200' . "\n" .
'maxRedirects = 10' . "\n" .
'maxSize = 104857600' . "\n" .
+ 'exploreUrl = ' . "\n" .
'feedFetcherTimeout = 60' . "\n" .
'useCronUpdates = false';
diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php
index 347e0a4a5..da6e40e36 100644
--- a/tests/unit/controller/AdminControllerTest.php
+++ b/tests/unit/controller/AdminControllerTest.php
@@ -48,7 +48,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
'maxRedirects' => 3,
'feedFetcherTimeout' => 4,
'useCronUpdates' => 5,
- 'maxSize' => 7
+ 'maxSize' => 7,
+ 'exploreUrl' => 'test'
];
$this->config->expects($this->once())
->method('getAutoPurgeMinimumInterval')
@@ -68,6 +69,9 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
$this->config->expects($this->once())
->method('getMaxSize')
->will($this->returnValue($expected['maxSize']));
+ $this->config->expects($this->once())
+ ->method('getExploreUrl')
+ ->will($this->returnValue($expected['exploreUrl']));
$response = $this->controller->index();
$data = $response->getParams();
@@ -88,6 +92,7 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
'feedFetcherTimeout' => 4,
'useCronUpdates' => 5,
'maxSize' => 7,
+ 'exploreUrl' => 'test'
];
$this->config->expects($this->once())
@@ -106,6 +111,9 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
->method('setUseCronUpdates')
->with($this->equalTo($expected['useCronUpdates']));
$this->config->expects($this->once())
+ ->method('setExploreUrl')
+ ->with($this->equalTo($expected['exploreUrl']));
+ $this->config->expects($this->once())
->method('write')
->with($this->equalTo($this->configPath));
@@ -127,6 +135,9 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
$this->config->expects($this->once())
->method('getMaxSize')
->will($this->returnValue($expected['maxSize']));
+ $this->config->expects($this->once())
+ ->method('getExploreUrl')
+ ->will($this->returnValue($expected['exploreUrl']));
$response = $this->controller->update(
$expected['autoPurgeMinimumInterval'],
@@ -134,7 +145,8 @@ class AdminControllerTest extends \PHPUnit_Framework_TestCase {
$expected['maxRedirects'],
$expected['feedFetcherTimeout'],
$expected['maxSize'],
- $expected['useCronUpdates']
+ $expected['useCronUpdates'],
+ $expected['exploreUrl']
);
$this->assertEquals($expected, $response);
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
index 8f00079a3..3b3a38782 100644
--- a/tests/unit/controller/PageControllerTest.php
+++ b/tests/unit/controller/PageControllerTest.php
@@ -143,6 +143,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
'preventReadOnScroll' => true,
'oldestFirst' => true,
'language' => 'de',
+ 'exploreUrl' => 'test'
]
];
@@ -173,12 +174,70 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->appName),
$this->equalTo('oldestFirst'))
->will($this->returnValue('1'));
+ $this->config->expects($this->once())
+ ->method('getExploreUrl')
+ ->will($this->returnValue(' '));
+ $this->urlGenerator->expects($this->once())
+ ->method('getAbsoluteURL')
+ ->with($this->equalTo('/index.php/apps/news/explore'))
+ ->will($this->returnValue('test'));
+
$response = $this->controller->settings();
$this->assertEquals($result, $response);
}
+ public function testSettingsExploreUrlSet() {
+ $result = [
+ 'settings' => [
+ 'showAll' => true,
+ 'compact' => true,
+ 'preventReadOnScroll' => true,
+ 'oldestFirst' => true,
+ 'language' => 'de',
+ 'exploreUrl' => 'abc'
+ ]
+ ];
+
+ $this->l10n->expects($this->once())
+ ->method('getLanguageCode')
+ ->will($this->returnValue('de'));
+ $this->settings->expects($this->at(0))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('showAll'))
+ ->will($this->returnValue('1'));
+ $this->settings->expects($this->at(1))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('compact'))
+ ->will($this->returnValue('1'));
+ $this->settings->expects($this->at(2))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('preventReadOnScroll'))
+ ->will($this->returnValue('1'));
+ $this->settings->expects($this->at(3))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user),
+ $this->equalTo($this->appName),
+ $this->equalTo('oldestFirst'))
+ ->will($this->returnValue('1'));
+ $this->config->expects($this->once())
+ ->method('getExploreUrl')
+ ->will($this->returnValue('abc'));
+ $this->urlGenerator->expects($this->never())
+ ->method('getAbsoluteURL');
+
+
+ $response = $this->controller->settings();
+ $this->assertEquals($result, $response);
+ }
+
public function testUpdateSettings() {
$this->settings->expects($this->at(0))
->method('setUserValue')
@@ -246,9 +305,6 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->appName),
$this->equalTo('lastViewedFeedType'),
$this->equalTo(FeedType::EXPLORE));
- $this->l10n->expects($this->once())
- ->method('getLanguageCode')
- ->will($this->returnValue('de_DE'));
$this->recommended->expects($this->once())
->method('forLanguage')
@@ -256,7 +312,7 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
->will($this->returnValue($in));
- $out = $this->controller->explore();
+ $out = $this->controller->explore('de_DE');
$this->assertEquals($in, $out);
}