Private/Hidden tags

Tags starting with a dot '.' are now private.
They can only be seen and searched when logged in.

Fixes #315
This commit is contained in:
ArthurHoaro 2016-01-21 20:18:44 +01:00
parent 1e7331126d
commit 195acf9f09
4 changed files with 27 additions and 2 deletions

View file

@ -264,8 +264,15 @@ private function _readDB()
foreach ($this->_links as &$link) { foreach ($this->_links as &$link) {
// Keep the list of the mapping URLs-->linkdate up-to-date. // Keep the list of the mapping URLs-->linkdate up-to-date.
$this->_urls[$link['url']] = $link['linkdate']; $this->_urls[$link['url']] = $link['linkdate'];
// Sanitize data fields. // Sanitize data fields.
sanitizeLink($link); 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 '?'). // Do not use the redirector for internal links (Shaarli note URL starting with a '?').
if (!empty($this->_redirector) && !startsWith($link['url'], '?')) { if (!empty($this->_redirector) && !startsWith($link['url'], '?')) {
$link['real_url'] = $this->_redirector . urlencode($link['url']); $link['real_url'] = $this->_redirector . urlencode($link['url']);

View file

@ -298,6 +298,7 @@ public function testAllTags()
'css' => 1, 'css' => 1,
'Mercurial' => 1, 'Mercurial' => 1,
'-exclude' => 1, '-exclude' => 1,
'.hidden' => 1,
), ),
self::$privateLinkDB->allTags() self::$privateLinkDB->allTags()
); );
@ -349,4 +350,22 @@ public function testFilterArray()
count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 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))
);
}
} }

View file

@ -239,7 +239,6 @@ public function testRenameDashTags()
$this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
$updater = new Updater(array(), self::$configFields, $linkDB, true); $updater = new Updater(array(), self::$configFields, $linkDB, true);
$updater->updateMethodRenameDashTags(); $updater->updateMethodRenameDashTags();
var_dump($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
$this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
} }
} }

View file

@ -28,7 +28,7 @@ function __construct()
'A free software media publishing platform', 'A free software media publishing platform',
0, 0,
'20130614_184135', '20130614_184135',
'gnu media web' 'gnu media web .hidden'
); );
$this->addLink( $this->addLink(