From 195acf9f0931aa3b1a6db8832ab52a260d11090d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 21 Jan 2016 20:18:44 +0100 Subject: [PATCH] Private/Hidden tags Tags starting with a dot '.' are now private. They can only be seen and searched when logged in. Fixes #315 --- application/LinkDB.php | 7 +++++++ tests/LinkDBTest.php | 19 +++++++++++++++++++ tests/Updater/UpdaterTest.php | 1 - tests/utils/ReferenceLinkDB.php | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/application/LinkDB.php b/application/LinkDB.php index 416aa0d..9f4d3e3 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php @@ -264,8 +264,15 @@ You use the community supported version of the original Shaarli project, by Seba foreach ($this->_links as &$link) { // Keep the list of the mapping URLs-->linkdate up-to-date. $this->_urls[$link['url']] = $link['linkdate']; + // Sanitize data fields. sanitizeLink($link); + + // Remove private tags if the user is not logged in. + if (! $this->_loggedIn) { + $link['tags'] = preg_replace('/(^| )\.[^($| )]+/', '', $link['tags']); + } + // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). if (!empty($this->_redirector) && !startsWith($link['url'], '?')) { $link['real_url'] = $this->_redirector . urlencode($link['url']); diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 06edea7..765f771 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -298,6 +298,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'css' => 1, 'Mercurial' => 1, '-exclude' => 1, + '.hidden' => 1, ), self::$privateLinkDB->allTags() ); @@ -349,4 +350,22 @@ class LinkDBTest extends PHPUnit_Framework_TestCase count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) ); } + + /** + * Test hidden tags feature: + * tags starting with a dot '.' are only visible when logged in. + */ + public function testHiddenTags() + { + $tags = '.hidden'; + $this->assertEquals( + 1, + count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + ); + + $this->assertEquals( + 0, + count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + ); + } } diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 84b8235..d865066 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -239,7 +239,6 @@ class UpdaterTest extends PHPUnit_Framework_TestCase $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); $updater = new Updater(array(), self::$configFields, $linkDB, true); $updater->updateMethodRenameDashTags(); - var_dump($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); } } diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 2f188d2..da3e8c6 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php @@ -28,7 +28,7 @@ class ReferenceLinkDB 'A free software media publishing platform', 0, '20130614_184135', - 'gnu media web' + 'gnu media web .hidden' ); $this->addLink(