From 2ea89aba4faa5509ca68c7e9b6b9ab71c1929935 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 11 Mar 2017 14:11:06 +0100 Subject: [PATCH] Fixes #304: use atom feed as default RSS feed is still available with the setting set to false --- application/PageBuilder.php | 3 +- application/Updater.php | 16 ++++++++++ application/config/ConfigManager.php | 2 +- tests/Updater/UpdaterTest.php | 45 ++++++++++++++++++++++++++++ tpl/default/page.header.html | 4 +-- 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 544aba7..b133dee 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -75,7 +75,8 @@ class PageBuilder } $this->tpl->assign('shaarlititle', $this->conf->get('general.title', 'Shaarli')); $this->tpl->assign('openshaarli', $this->conf->get('security.open_shaarli', false)); - $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', false)); + $this->tpl->assign('showatom', $this->conf->get('feed.show_atom', true)); + $this->tpl->assign('feed_type', $this->conf->get('feed.show_atom', true) !== false ? 'atom' : 'rss'); $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); $this->tpl->assign('token', getToken($this->conf)); // To be removed with a proper theme configuration. diff --git a/application/Updater.php b/application/Updater.php index fd7e207..efbfc83 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -378,6 +378,22 @@ class Updater $this->conf->set('plugins.PIWIK_URL', 'http://'. $this->conf->get('plugins.PIWIK_URL')); $this->conf->write($this->isLoggedIn); + + return true; + } + + /** + * Use ATOM feed as default. + */ + public function updateMethodAtomDefault() + { + if (!$this->conf->exists('feed.show_atom') || $this->conf->get('feed.show_atom') === true) { + return true; + } + + $this->conf->set('feed.show_atom', true); + $this->conf->write($this->isLoggedIn); + return true; } } diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index f209741..c5eeda0 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -317,7 +317,7 @@ class ConfigManager $this->setEmpty('updates.check_updates_interval', 86400); $this->setEmpty('feed.rss_permalinks', true); - $this->setEmpty('feed.show_atom', false); + $this->setEmpty('feed.show_atom', true); $this->setEmpty('privacy.default_private_links', false); $this->setEmpty('privacy.hide_public_links', false); diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index b522d61..11b6444 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -615,4 +615,49 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; $this->assertTrue($updater->updateMethodPiwikUrl()); $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL')); } + + /** + * Test updateMethodAtomDefault with show_atom set to false + * => update to true. + */ + public function testUpdateMethodAtomDefault() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('feed.show_atom', false); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertTrue($this->conf->get('feed.show_atom')); + } + /** + * Test updateMethodAtomDefault with show_atom not set. + * => nothing to do + */ + public function testUpdateMethodAtomDefaultNoExist() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + } + /** + * Test updateMethodAtomDefault with show_atom set to true. + * => nothing to do + */ + public function testUpdateMethodAtomDefaultAlreadyTrue() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('feed.show_atom', true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodAtomDefault()); + $this->assertTrue($this->conf->get('feed.show_atom')); + } } diff --git a/tpl/default/page.header.html b/tpl/default/page.header.html index b76fc03..04f33ea 100644 --- a/tpl/default/page.header.html +++ b/tpl/default/page.header.html @@ -48,7 +48,7 @@ {/loop}
  • - {'RSS Feed'|t} + {'RSS Feed'|t}
  • {if="isLoggedIn()"}
  • @@ -70,7 +70,7 @@
  • - +