From 0bfd4e4d3f4fa3db0b2de50277b0cfbddcf6efdf Mon Sep 17 00:00:00 2001 From: mensonge Date: Fri, 11 Jan 2008 09:34:32 +0000 Subject: Interface design: structured tags on frontpage and tag pages + permission control added to add and delete tag links git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@10 b3834d28-1941-0410-a4f8-b48e95affb8f --- index.php | 4 ++-- services/tag2tagservice.php | 10 +++++++--- tag2tagadd.php | 12 ++++++++++-- tag2tagdelete.php | 11 +++++++++-- tags.php | 2 +- templates/sidebar.block.linked.php | 6 +++++- tests/tag2TagTest.php | 5 +++++ 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index b760bd7..fe55e59 100644 --- a/index.php +++ b/index.php @@ -67,7 +67,7 @@ $dtstart = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' day $tplVars['page'] = $page; $tplVars['start'] = $start; $tplVars['popCount'] = 30; -$tplVars['sidebar_blocks'] = array('recent'); +$tplVars['sidebar_blocks'] = array('linked', 'recent'); $tplVars['range'] = 'all'; $tplVars['pagetitle'] = T_('Store, share and tag your favourite links'); $tplVars['subtitle'] = T_('Recent Bookmarks'); @@ -84,4 +84,4 @@ if ($usecache) { // Cache output if existing copy has expired $cacheservice->End($hash); } -?> \ No newline at end of file +?> diff --git a/services/tag2tagservice.php b/services/tag2tagservice.php index 0b53d64..d522039 100644 --- a/services/tag2tagservice.php +++ b/services/tag2tagservice.php @@ -88,14 +88,18 @@ class Tag2TagService { return $output; } - function getOrphewTags($relationType, $uId) { + function getOrphewTags($relationType, $uId = 0) { $query = "SELECT DISTINCT tag1 as tag FROM `". $this->getTableName() ."`"; $query.= " WHERE tag1 <> ALL"; $query.= " (SELECT DISTINCT tag2 FROM `". $this->getTableName() ."`"; $query.= " WHERE relationType = '".$relationType."'"; - $query.= " AND uId = '".$uId."'"; + if($uId > 0) { + $query.= " AND uId = '".$uId."'"; + } $query.= ")"; - $query.= " AND uId = '".$uId."'"; + if($uId > 0) { + $query.= " AND uId = '".$uId."'"; + } //die($query); diff --git a/tag2tagadd.php b/tag2tagadd.php index 916c388..83af1d6 100644 --- a/tag2tagadd.php +++ b/tag2tagadd.php @@ -24,13 +24,22 @@ $tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2TagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); +$logged_on_user = $userservice->getCurrentUser(); + +//permissions +if($logged_on_user == null) { + $tplVars['error'] = T_('Permission denied.'); + $templateservice->loadTemplate('error.500.tpl', $tplVars); + exit(); +} + + list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']); if ($_POST['confirm']) { $newTag = $_POST['newTag']; if ($tag2tagservice->addLinkedTags($tag, $newTag, '>', $userservice->getCurrentUserId())) { $tplVars['msg'] = T_('Tag link created'); - $logged_on_user = $userservice->getCurrentUser(); header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')])); } else { $tplVars['error'] = T_('Failed to create the link'); @@ -38,7 +47,6 @@ if ($_POST['confirm']) { exit(); } } elseif ($_POST['cancel']) { - $logged_on_user = $userservice->getCurrentUser(); header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags)); } diff --git a/tag2tagdelete.php b/tag2tagdelete.php index e75e60a..f794456 100644 --- a/tag2tagdelete.php +++ b/tag2tagdelete.php @@ -24,12 +24,20 @@ $tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2TagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); +$logged_on_user = $userservice->getCurrentUser(); + +//permissions +if($logged_on_user == null) { + $tplVars['error'] = T_('Permission denied.'); + $templateservice->loadTemplate('error.500.tpl', $tplVars); + exit(); +} + list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']); if ($_POST['confirm']) { if ($tag2tagservice->removeLinkedTags($_POST['tag1'], $_POST['tag2'], '>', $userservice->getCurrentUserId())) { $tplVars['msg'] = T_('Tag link deleted'); - $logged_on_user = $userservice->getCurrentUser(); header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')])); } else { $tplVars['error'] = T_('Failed to delete the link'); @@ -37,7 +45,6 @@ if ($_POST['confirm']) { exit(); } } elseif ($_POST['cancel']) { - $logged_on_user = $userservice->getCurrentUser(); header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags)); } diff --git a/tags.php b/tags.php index ff46881..81956fd 100644 --- a/tags.php +++ b/tags.php @@ -70,7 +70,7 @@ $tplVars['page'] = $page; $tplVars['start'] = $start; $tplVars['popCount'] = 25; $tplVars['currenttag'] = $cat; -$tplVars['sidebar_blocks'] = array('related', 'popular'); +$tplVars['sidebar_blocks'] = array('linked', 'related', 'popular'); $tplVars['subtitle'] = filter($pagetitle); $tplVars['bookmarkCount'] = $start + 1; $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, NULL, $cat, NULL, getSortOrder()); diff --git a/templates/sidebar.block.linked.php b/templates/sidebar.block.linked.php index 23bcb0c..5a891ea 100644 --- a/templates/sidebar.block.linked.php +++ b/templates/sidebar.block.linked.php @@ -64,7 +64,11 @@ if(count($explodedTags) > 0) {
', $userid, $cat_url, $user, $editingMode); } diff --git a/tests/tag2TagTest.php b/tests/tag2TagTest.php index 6660761..3a8466f 100644 --- a/tests/tag2TagTest.php +++ b/tests/tag2TagTest.php @@ -57,6 +57,9 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $this->assertEquals(2, sizeof($orphewTags)); $this->assertSame('a', $orphewTags[0]['tag']); $this->assertSame('f', $orphewTags[1]['tag']); + $orphewTags = $tts->getOrphewTags('>'); + $this->assertEquals(2, sizeof($orphewTags)); + $this->assertSame('f', $orphewTags[0]['tag']); $linkedTags = $tts->getLinkedTags('a', '>', 1); $this->assertSame(array('b', 'c'), $linkedTags); @@ -66,6 +69,8 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $tts->removeLinkedTags('a', 'c', '>', 1); $linkedTags = $tts->getLinkedTags('a', '>', 1); $this->assertEquals(0, sizeof($linkedTags)); + $linkedTags = $tts->getLinkedTags('a', '>'); + $this->assertSame(array('b', 'c', 'd'), $linkedTags); } public function testAddLinkedTagsThroughBookmarking() -- cgit v1.2.3