aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-01-21 20:18:44 +0100
committerArthurHoaro <arthur@hoa.ro>2016-02-15 21:18:43 +0100
commit195acf9f0931aa3b1a6db8832ab52a260d11090d (patch)
tree351663f03ed606f095b88b2f96ca0ef3d41e7f6a
parent1e7331126d81a5759ab91c221f7e0f164aeebfb5 (diff)
downloadShaarli-195acf9f0931aa3b1a6db8832ab52a260d11090d.tar.gz
Shaarli-195acf9f0931aa3b1a6db8832ab52a260d11090d.tar.zst
Shaarli-195acf9f0931aa3b1a6db8832ab52a260d11090d.zip
Private/Hidden tags
Tags starting with a dot '.' are now private. They can only be seen and searched when logged in. Fixes #315
-rw-r--r--application/LinkDB.php7
-rw-r--r--tests/LinkDBTest.php19
-rw-r--r--tests/Updater/UpdaterTest.php1
-rw-r--r--tests/utils/ReferenceLinkDB.php2
4 files changed, 27 insertions, 2 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 416aa0d3..9f4d3e3c 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
264 foreach ($this->_links as &$link) { 264 foreach ($this->_links as &$link) {
265 // Keep the list of the mapping URLs-->linkdate up-to-date. 265 // Keep the list of the mapping URLs-->linkdate up-to-date.
266 $this->_urls[$link['url']] = $link['linkdate']; 266 $this->_urls[$link['url']] = $link['linkdate'];
267
267 // Sanitize data fields. 268 // Sanitize data fields.
268 sanitizeLink($link); 269 sanitizeLink($link);
270
271 // Remove private tags if the user is not logged in.
272 if (! $this->_loggedIn) {
273 $link['tags'] = preg_replace('/(^| )\.[^($| )]+/', '', $link['tags']);
274 }
275
269 // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). 276 // Do not use the redirector for internal links (Shaarli note URL starting with a '?').
270 if (!empty($this->_redirector) && !startsWith($link['url'], '?')) { 277 if (!empty($this->_redirector) && !startsWith($link['url'], '?')) {
271 $link['real_url'] = $this->_redirector . urlencode($link['url']); 278 $link['real_url'] = $this->_redirector . urlencode($link['url']);
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 06edea79..765f771e 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -298,6 +298,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
298 'css' => 1, 298 'css' => 1,
299 'Mercurial' => 1, 299 'Mercurial' => 1,
300 '-exclude' => 1, 300 '-exclude' => 1,
301 '.hidden' => 1,
301 ), 302 ),
302 self::$privateLinkDB->allTags() 303 self::$privateLinkDB->allTags()
303 ); 304 );
@@ -349,4 +350,22 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
349 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 350 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
350 ); 351 );
351 } 352 }
353
354 /**
355 * Test hidden tags feature:
356 * tags starting with a dot '.' are only visible when logged in.
357 */
358 public function testHiddenTags()
359 {
360 $tags = '.hidden';
361 $this->assertEquals(
362 1,
363 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
364 );
365
366 $this->assertEquals(
367 0,
368 count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
369 );
370 }
352} 371}
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php
index 84b82350..d865066b 100644
--- a/tests/Updater/UpdaterTest.php
+++ b/tests/Updater/UpdaterTest.php
@@ -239,7 +239,6 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
239 $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); 239 $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
240 $updater = new Updater(array(), self::$configFields, $linkDB, true); 240 $updater = new Updater(array(), self::$configFields, $linkDB, true);
241 $updater->updateMethodRenameDashTags(); 241 $updater->updateMethodRenameDashTags();
242 var_dump($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
243 $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); 242 $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
244 } 243 }
245} 244}
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index 2f188d29..da3e8c65 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -28,7 +28,7 @@ class ReferenceLinkDB
28 'A free software media publishing platform', 28 'A free software media publishing platform',
29 0, 29 0,
30 '20130614_184135', 30 '20130614_184135',
31 'gnu media web' 31 'gnu media web .hidden'
32 ); 32 );
33 33
34 $this->addLink( 34 $this->addLink(