From 0c930607f0444fef11e2fb7d5c50eadd905cccc7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:50:49 +0000 Subject: do not return numbers < 0 git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@652 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 0ac1855..3ea5b5c 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -916,9 +916,10 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); } - $output = $this->db->sql_fetchfield(0, 0) - 1; + $count = $this->db->sql_fetchfield(0, 0); + $count = ($count > 0) ? $count - 1 : (int)$count; $this->db->sql_freeresult($dbresult); - return $output; + return $count; } -- cgit v1.2.3 From 7f2e3472174354bd3f23875bdbe23914f89269dd Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:52:45 +0000 Subject: do not return numbers < 0 git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@653 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 3ea5b5c..c4d198d 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -911,7 +911,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; + $sql = 'SELECT COUNT(*) as "0" FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; if (!($dbresult = & $this->db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); } -- cgit v1.2.3 From 91da444e762bd2676e94a19d45401d2e83858202 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:59:39 +0000 Subject: reformat countOthers() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@658 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 46 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index c4d198d..05ea060 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -889,31 +889,51 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService - function countOthers($address) + /** + * Counts the number of bookmarks that have the same address + * as the given address + * + * @param string $address Address/URL to look for + * + * @return integer Number of bookmarks minus one that have the address + */ + public function countOthers($address) { if (!$address) { return false; } - $userservice = SemanticScuttle_Service_Factory :: get('User'); - $sId = $userservice->getCurrentUserId(); + $us = SemanticScuttle_Service_Factory::get('User'); + $sId = (int)$us->getCurrentUserId(); - if ($userservice->isLoggedOn()) { - // All public bookmarks, user's own bookmarks and any shared with user - $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; - $watchnames = $userservice->getWatchNames($sId, true); - foreach($watchnames as $watchuser) { - $privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)'; + if ($us->isLoggedOn()) { + //All public bookmarks, user's own bookmarks + // and any shared with our user + $privacy = ' AND ((B.bStatus = 0) OR (B.uId = ' . $sId . ')'; + $watchnames = $us->getWatchNames($sId, true); + foreach ($watchnames as $watchuser) { + $privacy .= ' OR (U.username = "' + . $this->db->sql_escape($watchuser) + . '" AND B.bStatus = 1)'; } $privacy .= ')'; } else { - // Just public bookmarks + //Just public bookmarks $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) as "0" FROM '. $userservice->getTableName() .' AS U, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE U.'. $userservice->getFieldName('primary') .' = B.uId AND B.bHash = "'. md5($address) .'"'. $privacy; - if (!($dbresult = & $this->db->sql_query($sql))) { - message_die(GENERAL_ERROR, 'Could not get vars', '', __LINE__, __FILE__, $sql, $this->db); + $sql = 'SELECT COUNT(*) as "0" FROM ' + . $us->getTableName() . ' AS U' + . ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B' + . ' WHERE U.'. $us->getFieldName('primary') .' = B.uId' + . ' AND B.bHash = "'. md5($address) . '"' + . $privacy; + + if (!($dbresult = $this->db->sql_query($sql))) { + message_die( + GENERAL_ERROR, 'Could not get other count', + '', __LINE__, __FILE__, $sql, $this->db + ); } $count = $this->db->sql_fetchfield(0, 0); -- cgit v1.2.3 From 6b7217daf298be65347205aa7a0fee17ff37b87c Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:03:20 +0000 Subject: make countOthers() accept an array of addresses git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@659 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 57 +++++++++++++++++------ tests/BookmarkTest.php | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 13 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 05ea060..c7bfb3b 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -891,17 +891,29 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService /** * Counts the number of bookmarks that have the same address - * as the given address - * - * @param string $address Address/URL to look for - * - * @return integer Number of bookmarks minus one that have the address + * as the given address. + * + * @internal + * We do support fetching counts for multiple addresses at once + * because that allows us to reduce the number of queries + * we need in the web interface when displaying i.e. + * 10 bookmarks - only one SQL query is needed then. + * + * @param string|array $addresses Address/URL to look for, string + * of one address or array with + * multiple ones + * + * @return integer Number of bookmarks minus one that have the address. + * In case $addresses was an array, key-value array + * with key being the address, value said number of + * bookmarks */ - public function countOthers($address) + public function countOthers($addresses) { - if (!$address) { + if (!$addresses) { return false; } + $bArray = is_array($addresses); $us = SemanticScuttle_Service_Factory::get('User'); $sId = (int)$us->getCurrentUserId(); @@ -922,12 +934,22 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) as "0" FROM ' + $addressesSql = ' AND (0'; + foreach ((array)$addresses as $address) { + $addressesSql .= ' OR B.bHash = "' + . $this->db->sql_escape(md5($address)) + . '"'; + } + $addressesSql .= ')'; + + + $sql = 'SELECT B.bAddress, COUNT(*) as count FROM ' . $us->getTableName() . ' AS U' . ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B' . ' WHERE U.'. $us->getFieldName('primary') .' = B.uId' - . ' AND B.bHash = "'. md5($address) . '"' - . $privacy; + . $addressesSql + . $privacy + . ' GROUP BY B.bHash'; if (!($dbresult = $this->db->sql_query($sql))) { message_die( @@ -936,10 +958,19 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService ); } - $count = $this->db->sql_fetchfield(0, 0); - $count = ($count > 0) ? $count - 1 : (int)$count; + //be sure we also list urls in our array + // that are not found in the database + $counts = array_combine( + (array)$addresses, + array_fill(0, count((array)$addresses), 0) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $counts[$row['bAddress']] + = $row['count'] > 0 ? $row['count'] - 1 : 0; + } $this->db->sql_freeresult($dbresult); - return $count; + + return $bArray ? $counts : reset($counts); } diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index d791b9e..69e6e8a 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -943,6 +943,86 @@ class BookmarkTest extends TestBase + /** + * Test what countOther() returns when multiple addresses are + * passed to it and none of them exists. + * + * @return void + */ + public function testCountOthersArrayNone() + { + $this->assertEquals( + array('1' => 0, '2' => 0, '3' => 0), + $this->bs->countOthers(array('1', '2', '3')) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are + * passed to it and only one of them exists. + * + * @return void + */ + public function testCountOthersArrayOneNone() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + $this->addBookmark($uid2, $address1); + $this->assertEquals( + array( + $address1 => 1, + $address2 => 0 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are passed + * to it and both of them exist with different numbers for each. + * + * @return void + */ + public function testCountOthersArrayTwoOne() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $uid3 = $this->addUser(); + + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + + $this->addBookmark($uid2, $address1); + $this->addBookmark($uid2, $address2); + + $this->addBookmark($uid3, $address1); + + $this->assertEquals( + array( + $address1 => 2, + $address2 => 1 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + } -- cgit v1.2.3 From c4b8719b5b0b61d5fc4c7c4691f23d6635ef8f4d Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:12:51 +0000 Subject: reformat and CS git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@666 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark2Tag.php | 30 ++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 8e5cb22..e0f831e 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -266,21 +266,39 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return true; } - function &getTagsForBookmark($bookmarkid) { + + /** + * Retrieves all tags for a given bookmark except system tags. + * + * @param integer $bookmarkid ID of the bookmark + * + * @return array Array of tags + */ + public function getTagsForBookmark($bookmarkid) + { if (!is_numeric($bookmarkid)) { - message_die(GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query); + message_die( + GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', + '', __LINE__, __FILE__, $query + ); return false; } - $query = 'SELECT tag FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND LEFT(tag, 7) <> "system:" ORDER BY id ASC'; + $query = 'SELECT tag FROM ' . $this->getTableName() + . ' WHERE bId = ' . intval($bookmarkid) + . ' AND LEFT(tag, 7) <> "system:"' + . ' ORDER BY id ASC'; - if (!($dbresult =& $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db); + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get tags', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } $tags = array(); - while ($row =& $this->db->sql_fetchrow($dbresult)) { + while ($row = $this->db->sql_fetchrow($dbresult)) { $tags[] = $row['tag']; } $this->db->sql_freeresult($dbresult); -- cgit v1.2.3 From 3e9c2cd0a57d798bb7cbcf89575cbc0199e0d2e5 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:14:39 +0000 Subject: add new method for better sql performance: Bookmark2Tag::getTagsForBookmarks() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@667 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark2Tag.php | 48 ++++++++++++++++++ tests/Bookmark2TagTest.php | 73 ++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index e0f831e..770b1d9 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -305,6 +305,54 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return $tags; } + + /** + * Retrieves all tags for an array of bookmark IDs + * + * @param array $bookmarkids Array of bookmark IDs + * + * @return array Array of tag arrays. Key is bookmark ID. + */ + public function getTagsForBookmarks($bookmarkids) + { + if (!is_array($bookmarkids)) { + message_die( + GENERAL_ERROR, 'Could not get tags (invalid bookmarkids)', + '', __LINE__, __FILE__, $query + ); + return false; + } + + $sql = ''; + foreach ($bookmarkids as $bookmarkid) { + $sql .= ' OR bId = ' . intval($bookmarkid); + } + + $query = 'SELECT tag, bId FROM ' . $this->getTableName() + . ' WHERE (1' . $sql . ')' + . ' AND LEFT(tag, 7) <> "system:"' + . ' ORDER BY id, bId ASC'; + + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get tags', + '', __LINE__, __FILE__, $query, $this->db + ); + return false; + } + + $tags = array_combine( + $bookmarkids, + array_fill(0, count($bookmarkids), array()) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $tags[$row['bId']][] = $row['tag']; + } + $this->db->sql_freeresult($dbresult); + return $tags; + } + + function &getTags($userid = NULL) { $userservice =SemanticScuttle_Service_Factory::get('User'); $logged_on_user = $userservice->getCurrentUserId(); diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index d75afd8..0afaaf8 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -126,6 +126,79 @@ class Bookmark2TagTest extends TestBase $this->assertContains('bar', $tags); $this->assertContains('fuu', $tags); } + + + + /** + * Test getTagsForBookmarks() when no bookmarks have tags. + * + * @return void + */ + public function testGetTagsForBookmarksNone() + { + $bid1 = $this->addBookmark(null, null, 0, array()); + $bid2 = $this->addBookmark(null, null, 0, array()); + + $alltags = $this->b2ts->getTagsForBookmarks( + array($bid1, $bid2) + ); + $this->assertType('array', $alltags); + $this->assertEquals(2, count($alltags)); + $this->assertType('array', $alltags[$bid1]); + $this->assertType('array', $alltags[$bid2]); + $this->assertEquals(0, count($alltags[$bid1])); + $this->assertEquals(0, count($alltags[$bid2])); + } + + + + /** + * Test getTagsForBookmarks() when most bookmarks have tags. + * + * @return void + */ + public function testGetTagsForBookmarksMost() + { + $bid1 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid1, array('foo', 'bar', 'fuu')); + + $bid2 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid2, array('foo', 'bar2', 'fuu2')); + + $bid3 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid3, array('foo', 'bar2', 'fuu3')); + + $bid4 = $this->addBookmark(null, null, 0, array()); + //no tags + + $alltags = $this->b2ts->getTagsForBookmarks( + array($bid1, $bid2, $bid3, $bid4) + ); + $this->assertType('array', $alltags); + foreach ($alltags as $bid => $btags) { + $this->assertType('array', $btags); + if ($bid == $bid1) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar', $btags); + $this->assertContains('fuu', $btags); + } else if ($bid == $bid2) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar2', $btags); + $this->assertContains('fuu2', $btags); + } else if ($bid == $bid3) { + $this->assertEquals(3, count($btags)); + $this->assertContains('foo', $btags); + $this->assertContains('bar2', $btags); + $this->assertContains('fuu3', $btags); + } else if ($bid == $bid4) { + $this->assertEquals(0, count($btags)); + } else { + $this->assertTrue(false, 'Unknown bookmark id'); + } + } + } } if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') { -- cgit v1.2.3 From 6a6cba1a4d61d42bd93fb385f576d299bd99cc59 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:16:34 +0000 Subject: sql optimization: fetch all tags at once git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@668 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 15 +++++++++++---- src/SemanticScuttle/Service/Bookmark2Tag.php | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index c7bfb3b..9d72023 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -804,10 +804,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $total = $row['total']; $this->db->sql_freeresult($totalresult); - $bookmarks = array(); - while ($row = & $this->db->sql_fetchrow($dbresult)) { - $row['tags'] = $b2tservice->getTagsForBookmark(intval($row['bId'])); - $bookmarks[] = $row; + $bookmarks = array(); + $bookmarkids = array(); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $bookmarks[] = $row; + $bookmarkids[] = $row['bId']; + } + if (count($bookmarkids)) { + $tags = $b2tservice->getTagsForBookmarks($bookmarkids); + foreach ($bookmarks as &$bookmark) { + $bookmark['tags'] = $tags[$bookmark['bId']]; + } } $this->db->sql_freeresult($dbresult); diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 770b1d9..d6c0e58 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -321,6 +321,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService '', __LINE__, __FILE__, $query ); return false; + } else if (count($bookmarkids) == 0) { + return array(); } $sql = ''; -- cgit v1.2.3 From 6c9542f24b630f60490949f4e77bcb0cf1bf7377 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:18:49 +0000 Subject: make isAdmin accept a user name, too git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@669 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/User.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index cedde92..0b28663 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -305,9 +305,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService /** * Checks if the given user is an administrator. * Uses global admin_users property containing admin - * user names + * user names. * - * @param integer|array $user User ID or user row from DB + * Passing the user id makes this function load the user + * from database. For efficiency reasons, try to pass + * the user name or database row. + * + * @param integer|array|string $user User ID or user row from DB + * or user name * * @return boolean True if the user is admin */ @@ -315,10 +320,13 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService { if (is_numeric($user)) { $user = $this->getUser($user); + $user = $user['username']; + } else if (is_array($user)) { + $user = $user['username']; } if (isset($GLOBALS['admin_users']) - && in_array($user['username'], $GLOBALS['admin_users']) + && in_array($user, $GLOBALS['admin_users']) ) { return true; } else { -- cgit v1.2.3 From 01c792a78969dcfa3e9dd99a4491ccb6836ca8c1 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:23:07 +0000 Subject: new config option to disable "SET NAMES UTF8" sql call git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@671 b3834d28-1941-0410-a4f8-b48e95affb8f --- data/config.default.php | 9 +++++++++ doc/ChangeLog | 7 +++++++ src/SemanticScuttle/Service/Factory.php | 6 ++++-- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/data/config.default.php b/data/config.default.php index 1b040c0..fdbdaee 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -180,6 +180,15 @@ $dbname = 'scuttle'; */ $tableprefix = 'sc_'; +/* + * If the database needs to be switched to UTF8 + * manually or not. If true, a "SET NAMES UTF8" query + * will be sent at the beginning. If you need performance, + * save this query and set it in your mysql server options. + * + * @var boolean + */ +$dbneedssetnames = true; /*************************************************** diff --git a/doc/ChangeLog b/doc/ChangeLog index c797f56..05757ac 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,10 +1,17 @@ ChangeLog for SemantiScuttle ============================ +0.97.0 - 2010-????? +------------------- +- Many SQL optimizations +- New config option to skip "SET NAMES UTF8" call: $dbneedssetnames + + 0.96.1 - 2010-02-09 ------------------- - Fix bug #2948410: API is broken in 0.96.0 + 0.96.0 - 2010-02-08 ------------------- - Fix bug #2843523: ArtViper thumbnail license change diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php index 9b79e6c..d7ff1d4 100644 --- a/src/SemanticScuttle/Service/Factory.php +++ b/src/SemanticScuttle/Service/Factory.php @@ -113,7 +113,7 @@ class SemanticScuttle_Service_Factory protected static function loadDb() { global $dbhost, $dbuser, $dbpass, $dbname, - $dbport, $dbpersist, $dbtype; + $dbport, $dbpersist, $dbtype, $dbneedssetnames; if (self::$db !== null) { return; @@ -130,7 +130,9 @@ class SemanticScuttle_Service_Factory self::$db ); } - $db->sql_query('SET NAMES UTF8'); + + $dbneedssetnames && $db->sql_query('SET NAMES UTF8'); + self::$db = $db; } -- cgit v1.2.3 From ab75c7ff445bb8659293af3a39a355185221cb37 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:26:16 +0000 Subject: docblock git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@673 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/functions.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/functions.php b/src/SemanticScuttle/functions.php index d21a094..15db022 100644 --- a/src/SemanticScuttle/functions.php +++ b/src/SemanticScuttle/functions.php @@ -35,10 +35,23 @@ function filter($data, $type = NULL) { return $data; } -function getPerPageCount($userObject = null) { +/** + * Returns the number of bookmarks that shall be displayed on one page. + * + * @param SemanticScuttle_Model_User $userObject Object of the current user + * + * @return integer Number of bookmarks per page + * + * @uses $defaultPerPage + * @uses $defaultPerPageForAdmins + */ +function getPerPageCount($userObject = null) +{ global $defaultPerPage, $defaultPerPageForAdmins; - if(isset($defaultPerPageForAdmins) && $userObject != null && $userObject->isAdmin()) { + if (isset($defaultPerPageForAdmins) + && $userObject != null && $userObject->isAdmin() + ) { return $defaultPerPageForAdmins; } else { return $defaultPerPage; -- cgit v1.2.3 From 74614e0f99221f1b137d9d9aedd3f38570430981 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:27:57 +0000 Subject: header docblock git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@674 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/functions.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/functions.php b/src/SemanticScuttle/functions.php index 15db022..84e9c5f 100644 --- a/src/SemanticScuttle/functions.php +++ b/src/SemanticScuttle/functions.php @@ -1,6 +1,19 @@ + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ // Converts tags: // - direction = out: convert spaces to underscores; @@ -48,7 +61,7 @@ function filter($data, $type = NULL) { function getPerPageCount($userObject = null) { global $defaultPerPage, $defaultPerPageForAdmins; - + if (isset($defaultPerPageForAdmins) && $userObject != null && $userObject->isAdmin() ) { -- cgit v1.2.3 From 35058ddd07266a70611b055b7e66c4cdd13d47e7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:29:31 +0000 Subject: reformat _getuser and add docblock git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@675 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/User.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 0b28663..7b03dd2 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -76,15 +76,28 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService $this->updateSessionStability(); } - function _getuser($fieldname, $value) { - $query = 'SELECT * FROM '. $this->getTableName() .' WHERE '. $fieldname .' = "'. $this->db->sql_escape($value) .'"'; + /** + * Fetches the desired user row from database, specified by column and value + * + * @param string $fieldname Name of database column to identify user + * @param string $value Value of $fieldname + * + * @return array Database row or boolean false + */ + protected function _getuser($fieldname, $value) + { + $query = 'SELECT * FROM '. $this->getTableName() + . ' WHERE ' . $fieldname . ' = "' . $this->db->sql_escape($value) . '"'; - if (! ($dbresult =& $this->db->sql_query($query)) ) { - message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db); + if (!($dbresult = $this->db->sql_query($query)) ) { + message_die( + GENERAL_ERROR, 'Could not get user', + '', __LINE__, __FILE__, $query, $this->db + ); return false; } - $row =& $this->db->sql_fetchrow($dbresult); + $row = $this->db->sql_fetchrow($dbresult); $this->db->sql_freeresult($dbresult); if ($row) { return $row; -- cgit v1.2.3 From 51e844e17e7adaa3a1d34cd85b29d3cbcd8eb8f3 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:31:18 +0000 Subject: save another query git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@676 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Model/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Model/User.php b/src/SemanticScuttle/Model/User.php index 03af5c7..ed9f454 100644 --- a/src/SemanticScuttle/Model/User.php +++ b/src/SemanticScuttle/Model/User.php @@ -158,7 +158,7 @@ class SemanticScuttle_Model_User // Look for value only if not already set if(!isset($this->isAdmin)) { $us = SemanticScuttle_Service_Factory::get('User'); - $this->isAdmin = $us->isAdmin($this->id); + $this->isAdmin = $us->isAdmin($this->username); } return $this->isAdmin; } -- cgit v1.2.3 From 41a29f49ee4446b1e743356a837a96ca29118f78 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:33:11 +0000 Subject: save another query git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@677 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 9d72023..37a6a5e 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -284,7 +284,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService } $userservice = SemanticScuttle_Service_Factory::get('User'); - $user = $userservice->getCurrentUser(); + $user = $userservice->getCurrentObjectUser(); //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] @@ -292,7 +292,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService ) { return true; } else { - return ($bookmark['uId'] == $user['uId']); + return ($bookmark['uId'] == $user->id); } } -- cgit v1.2.3 From cae9f4de38376974b805dab6b7a95105dc61dfd9 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:35:16 +0000 Subject: fix tests after last commit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@678 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 5 ++++- src/SemanticScuttle/Service/User.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 37a6a5e..87d9e02 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -285,10 +285,13 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $userservice = SemanticScuttle_Service_Factory::get('User'); $user = $userservice->getCurrentObjectUser(); + if ($user === null) { + return false; + } //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] - && $userservice->isAdmin($user) + && $userservice->isAdmin($user->id) ) { return true; } else { diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 7b03dd2..281c18c 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -407,6 +407,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService } //reload user object $this->getCurrentUser(true); + $this->getCurrentObjectUser(true); } -- cgit v1.2.3 From 6a2f1f4f573613400479d427c32b083a7274158b Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:37:03 +0000 Subject: reformat query git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@679 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 87d9e02..10b0b8b 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -325,7 +325,9 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $crit['uId'] = $uid; } - $sql = 'SELECT COUNT(*) as "0" FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE '. $this->db->sql_build_array('SELECT', $crit); + $sql = 'SELECT COUNT(*) as "0" FROM ' + . $GLOBALS['tableprefix'] . 'bookmarks' + . ' WHERE '. $this->db->sql_build_array('SELECT', $crit); if (!($dbresult = $this->db->sql_query($sql))) { message_die( -- cgit v1.2.3 From 17374001b8ccfe806851862c91b29671ba998828 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:39:03 +0000 Subject: add SemanticScuttle_Service_Bookmark::bookmarksExist() method to check for existance of multiple bookmarks at once for future sql optimization git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@680 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 56 +++++++++++++- tests/BookmarkTest.php | 122 +++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 10b0b8b..a1bb1a5 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -312,7 +312,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService * @return boolean True when the bookmark with the given URL * exists for the user, false if not. */ - function bookmarkExists($address = false, $uid = null) + public function bookmarkExists($address = false, $uid = null) { if (!$address) { return false; @@ -346,6 +346,60 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService + /** + * Checks if the given addresses exist + * + * @param array $addresses Array of addresses + * @param integer $uid User ID the addresses shall belong to + * + * @return array Array with addresses as keys, true/false for existence + * as value + */ + public function bookmarksExist($addresses, $uid = null) + { + if (count($addresses) == 0) { + return array(); + } + + $hashes = array(); + $sql = '(1'; + foreach ($addresses as $key => $address) { + $hash = md5($this->normalize($address)); + $hashes[$hash] = $address; + $sql .= ' OR bHash = "' + . $this->db->sql_escape($hash) + . '"'; + } + $sql .= ')'; + if ($uid !== null) { + $sql .= ' AND uId = ' . intval($uid); + } + + $sql = 'SELECT bHash, COUNT(*) as "count" FROM ' + . $this->getTableName() + . ' WHERE ' . $sql + . ' GROUP BY bHash'; + + if (!($dbresult = $this->db->sql_query($sql))) { + message_die( + GENERAL_ERROR, 'Could not get bookmark counts', '', + __LINE__, __FILE__, $sql, $this->db + ); + } + + $existence = array_combine( + $addresses, + array_fill(0, count($addresses), false) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $existence[$hashes[$row['bHash']]] = $row['count'] > 0; + } + + return $existence; + } + + + /** * Adds a bookmark to the database. * diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 39a9974..74685c4 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -252,6 +252,128 @@ class BookmarkTest extends TestBase + /** + * Tests if bookmarksExist() returns true when a bookmark + * exists + * + * @return void + */ + public function testBookmarksExistTrueSingle() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $ret = $this->bs->bookmarksExist(array($bookmark['bAddress'])); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns true when all bookmarks + * exist + * + * @return void + */ + public function testBookmarksExistTrueMultiple() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + $bookmark2['bAddress'] + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(2, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns false when a bookmark + * does not exist + * + * @return void + */ + public function testBookmarksExistFalseSingle() + { + $ret = $this->bs->bookmarksExist(array('does-not-exist')); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertFalse($ret['does-not-exist']); + } + + + + /** + * Tests if bookmarksExist() returns false when all bookmarks + * do not exist + * + * @return void + */ + public function testBookmarksExistFalseMultiple() + { + $bms = array( + 'does-not-exist', + 'does-not-exist-2', + 'does-not-exist-3', + ); + $ret = $this->bs->bookmarksExist($bms); + $this->assertType('array', $ret); + $this->assertEquals(3, count($ret)); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + + /** + * Tests if bookmarksExist() returns true when some bookmarks + * exist. + * + * @return void + */ + public function testBookmarksExistSome() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + 'does-not-exist', + $bookmark2['bAddress'], + 'does-not-exist-2', + 'does-not-exist-3' + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(5, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + /** * Test if countBookmarks() works with no bookmarks * -- cgit v1.2.3 From e993e994bb42637edc92bc139ac695a1d6458e67 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:42:44 +0000 Subject: re-fix isAdmin() sql optimization git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@682 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index a1bb1a5..88a9055 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -291,7 +291,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService //user has to be either admin, or owner if ($GLOBALS['adminsCanModifyBookmarksFromOtherUsers'] - && $userservice->isAdmin($user->id) + && $userservice->isAdmin($user->username) ) { return true; } else { -- cgit v1.2.3 From 5a93096431eebb4cb458351ce5f8d1b836328ca0 Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:07:04 +0000 Subject: fix bug #2953732 and make corresponding test work. git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@688 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 88a9055..3cdec72 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -178,7 +178,8 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService */ public function getBookmarkByAddress($address) { - $hash = md5($address); + $address = $this->normalize($address); + $hash = md5($address); return $this->getBookmarkByHash($hash); } -- cgit v1.2.3 From 4d3d00ade282e27b765a64c86f6607f1a92af2c0 Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:11:21 +0000 Subject: Fix bug #2960663: do not send content-type headers twice for ajax/api scripts git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@690 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/header.php | 8 +++++++- www/ajax/getadminlinkedtags.php | 2 +- www/ajax/getadmintags.php | 2 +- www/ajax/getcontacttags.php | 2 +- www/ajax/getlinkedtags.php | 2 +- www/ajax/gettags.php | 2 +- www/ajaxDelete.php | 2 +- www/ajaxGetTitle.php | 2 +- www/ajaxIsAvailable.php | 2 +- www/ajaxVote.php | 2 +- www/api/export_csv.php | 8 +++----- www/api/export_gcs.php | 5 +++-- www/api/export_sioc.php | 2 +- www/api/opensearch.php | 2 +- www/api/posts_add.php | 5 ++--- www/api/posts_all.php | 5 ++--- www/api/posts_dates.php | 2 +- www/api/posts_delete.php | 5 ++--- www/api/posts_get.php | 2 +- www/api/posts_public.php | 2 +- www/api/posts_recent.php | 2 +- www/api/posts_update.php | 5 ++--- www/api/tags_get.php | 5 ++--- www/api/tags_rename.php | 5 ++--- www/go.php | 1 + www/jsScuttle.php | 2 +- www/rss.php | 3 +-- 27 files changed, 43 insertions(+), 44 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index 12c1f72..ef36e83 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -107,6 +107,12 @@ $tplVars['userservice'] = $userservice; // 6 // Force UTF-8 behaviour for server (cannot be moved into top.inc.php which is not included into every file) if (!defined('UNIT_TEST_MODE')) { - header('Content-Type: text/html; charset=utf-8'); + //API files define that, so we need a way to support both of them + if (!isset($httpContentType)) { + $httpContentType = 'text/html'; + } + if ($httpContentType !== false) { + header('Content-Type: ' . $httpContentType . '; charset=utf-8'); + } } ?> diff --git a/www/ajax/getadminlinkedtags.php b/www/ajax/getadminlinkedtags.php index 6abc067..6646c50 100644 --- a/www/ajax/getadminlinkedtags.php +++ b/www/ajax/getadminlinkedtags.php @@ -20,7 +20,7 @@ ***************************************************************************/ /* Return a json file with list of linked tags */ - +$httpContentType = 'application/json'; require_once '../www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajax/getadmintags.php b/www/ajax/getadmintags.php index db62fc7..ffd20bb 100644 --- a/www/ajax/getadmintags.php +++ b/www/ajax/getadmintags.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ /* Return a json file with list of tags according to current user and sort by popularity*/ - +$httpContentType = 'application/json'; require_once '../www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajax/getcontacttags.php b/www/ajax/getcontacttags.php index 85ef1ae..89d6a3a 100644 --- a/www/ajax/getcontacttags.php +++ b/www/ajax/getcontacttags.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ /* Return a json file with list of tags according to current user and sort by popularity*/ - +$httpContentType = 'application/json'; require_once '../www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajax/getlinkedtags.php b/www/ajax/getlinkedtags.php index 6de272b..f412998 100644 --- a/www/ajax/getlinkedtags.php +++ b/www/ajax/getlinkedtags.php @@ -20,7 +20,7 @@ ***************************************************************************/ /* Return a json file with list of linked tags */ - +$httpContentType = 'application/json'; require_once '../www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajax/gettags.php b/www/ajax/gettags.php index 3672832..cb73720 100644 --- a/www/ajax/gettags.php +++ b/www/ajax/gettags.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ /* Return a json file with list of tags according to current user and sort by popularity*/ - +$httpContentType = 'application/json'; require_once '../www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajaxDelete.php b/www/ajaxDelete.php index 467e20e..2812612 100644 --- a/www/ajaxDelete.php +++ b/www/ajaxDelete.php @@ -19,9 +19,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ -header('Content-Type: text/xml; charset=UTF-8'); header('Last-Modified: '. gmdate("D, d M Y H:i:s") .' GMT'); header('Cache-Control: no-cache, must-revalidate'); +$httpContentType = 'text/xml'; require_once 'www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajaxGetTitle.php b/www/ajaxGetTitle.php index 6caa742..b4f44ca 100644 --- a/www/ajaxGetTitle.php +++ b/www/ajaxGetTitle.php @@ -19,10 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ -header('Content-Type: text/xml; charset=UTF-8'); header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT"); header("Cache-Control: no-cache, must-revalidate"); +$httpContentType = 'text/xml'; require_once 'www-header.php'; /* Managing all possible inputs */ diff --git a/www/ajaxIsAvailable.php b/www/ajaxIsAvailable.php index 3390569..41e825e 100644 --- a/www/ajaxIsAvailable.php +++ b/www/ajaxIsAvailable.php @@ -19,10 +19,10 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ -header('Content-Type: text/xml; charset=UTF-8'); header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT"); header("Cache-Control: no-cache, must-revalidate"); +$httpContentType = 'text/xml'; require_once 'www-header.php'; /* Service creation: only useful services are created */ diff --git a/www/ajaxVote.php b/www/ajaxVote.php index 3e603da..f2572fb 100644 --- a/www/ajaxVote.php +++ b/www/ajaxVote.php @@ -2,6 +2,7 @@ /** * We re-use vote.php but set the ajax flag */ +$httpContentType = 'text/xml'; $GLOBALS['ajaxRequest'] = true; require 'vote.php'; @@ -17,7 +18,6 @@ default: $template = 'bookmarks-vote.inc.tpl.php'; } -header('Content-Type: text/xml; charset=utf-8'); echo '' . $bookmark . '' . ''; $ts->loadTemplate( diff --git a/www/api/export_csv.php b/www/api/export_csv.php index 3f63692..b9cf497 100644 --- a/www/api/export_csv.php +++ b/www/api/export_csv.php @@ -2,8 +2,9 @@ // Export in CSV format in order to allow the import into a spreadsheet tool like Excel // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'application/csv-tab-delimited-table'; +require_once 'httpauth.inc.php'; +header("Content-disposition: filename=exportBookmarks.csv"); /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -17,9 +18,6 @@ else // Get the posts relevant to the passed-in variables. $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder()); -header("Content-Type: application/csv-tab-delimited-table;charset=UTF-8"); -header("Content-disposition: filename=exportBookmarks.csv"); - //columns titles echo 'url;title;tags;description'; echo "\n"; diff --git a/www/api/export_gcs.php b/www/api/export_gcs.php index 07bc726..9c0d85c 100644 --- a/www/api/export_gcs.php +++ b/www/api/export_gcs.php @@ -5,6 +5,7 @@ // Force HTTP authentication first! //require_once('httpauth.inc.php'); +$httpContentType = false; require_once '../www-header.php'; if($GLOBALS['enableGoogleCustomSearch'] == false) { @@ -39,7 +40,7 @@ $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag, NULL, getSortO // Set up the plain file and output all the posts. -header('Content-Type: text/plain'); +header('Content-Type: text/plain; charset=utf-8'); if(!$xml) { header('Content-Type: text/plain'); foreach($bookmarks['bookmarks'] as $row) { @@ -48,7 +49,7 @@ if(!$xml) { } } } else { - header('Content-Type: application/xml'); + header('Content-Type: text/xml'); echo ''."\n"; echo ' '."\n"; foreach($bookmarks['bookmarks'] as $row) { diff --git a/www/api/export_sioc.php b/www/api/export_sioc.php index ff1d1c0..8bdfd70 100644 --- a/www/api/export_sioc.php +++ b/www/api/export_sioc.php @@ -1,8 +1,8 @@ diff --git a/www/api/posts_add.php b/www/api/posts_add.php index c919ee7..59f7dce 100644 --- a/www/api/posts_add.php +++ b/www/api/posts_add.php @@ -11,8 +11,8 @@ // - No support for 'replace' variable // Force HTTP authentication -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -82,7 +82,6 @@ if (is_null($url) || is_null($description)) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''; ?> \ No newline at end of file diff --git a/www/api/posts_all.php b/www/api/posts_all.php index f53f363..2d274f4 100644 --- a/www/api/posts_all.php +++ b/www/api/posts_all.php @@ -5,8 +5,8 @@ // - doesn't include the filtered tag as an attribute on the root element (we do) // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -22,7 +22,6 @@ else $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag); // Set up the XML file and output all the posts. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_dates.php b/www/api/posts_dates.php index 7b1240f..508c46a 100644 --- a/www/api/posts_dates.php +++ b/www/api/posts_dates.php @@ -17,6 +17,7 @@ */ // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -36,7 +37,6 @@ $bookmarks = $bookmarkservice->getBookmarks( ); // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_delete.php b/www/api/posts_delete.php index 88e2584..a63cc62 100644 --- a/www/api/posts_delete.php +++ b/www/api/posts_delete.php @@ -7,8 +7,8 @@ // - doesn't set the Content-Type to text/xml (we do). // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -28,7 +28,6 @@ if (is_null($_REQUEST['url'])) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''; ?> \ No newline at end of file diff --git a/www/api/posts_get.php b/www/api/posts_get.php index b020f51..c20f904 100644 --- a/www/api/posts_get.php +++ b/www/api/posts_get.php @@ -25,6 +25,7 @@ */ // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -54,7 +55,6 @@ $bookmarks = $bookmarkservice->getBookmarks( // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_public.php b/www/api/posts_public.php index 0c93ca2..4258550 100644 --- a/www/api/posts_public.php +++ b/www/api/posts_public.php @@ -6,6 +6,7 @@ // Force HTTP authentication first! //require_once('httpauth.inc.php'); +$httpContentType = 'text/xml'; require_once '../www-header.php'; /* Service creation: only useful services are created */ @@ -22,7 +23,6 @@ else $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag); // Set up the XML file and output all the posts. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_recent.php b/www/api/posts_recent.php index 46e46f1..6c71e22 100644 --- a/www/api/posts_recent.php +++ b/www/api/posts_recent.php @@ -22,6 +22,7 @@ $countDefault = 15; $countMax = 100; // Force HTTP authentication first! +$httpContentType = 'text/xml'; require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ @@ -54,7 +55,6 @@ $bookmarks = $bookmarkservice->getBookmarks( // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo '\r\n"; diff --git a/www/api/posts_update.php b/www/api/posts_update.php index 9152f26..4aeedc3 100644 --- a/www/api/posts_update.php +++ b/www/api/posts_update.php @@ -5,8 +5,8 @@ // - doesn't set the Content-Type to text/xml (we do). // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); @@ -17,7 +17,6 @@ $bookmarks =& $bookmarkservice->getBookmarks(0, 1, $userservice->getCurrentUserI // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; foreach($bookmarks['bookmarks'] as $row) { echo ''; diff --git a/www/api/tags_get.php b/www/api/tags_get.php index 85684d4..06a40d9 100644 --- a/www/api/tags_get.php +++ b/www/api/tags_get.php @@ -5,8 +5,8 @@ // - tags can't have spaces // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); @@ -16,7 +16,6 @@ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $tags =& $b2tservice->getTags($userservice->getCurrentUserId()); // Set up the XML file and output all the tags. -header('Content-Type: text/xml'); echo '\r\n"; echo "\r\n"; foreach($tags as $row) { diff --git a/www/api/tags_rename.php b/www/api/tags_rename.php index 59ba8a4..cf56c83 100644 --- a/www/api/tags_rename.php +++ b/www/api/tags_rename.php @@ -5,8 +5,8 @@ // - oddly, returns an entirely different result () than the other API calls. // Force HTTP authentication first! -require_once('httpauth.inc.php'); -require_once '../www-header.php'; +$httpContentType = 'text/xml'; +require_once 'httpauth.inc.php'; /* Service creation: only useful services are created */ $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); @@ -31,7 +31,6 @@ if (is_null($old) || is_null($new)) { } // Set up the XML file and output the result. -header('Content-Type: text/xml'); echo '\r\n"; echo ''. ($renamed ? 'done' : 'something went wrong') .''; ?> diff --git a/www/go.php b/www/go.php index 3d271c4..6a36ba9 100644 --- a/www/go.php +++ b/www/go.php @@ -15,6 +15,7 @@ * @license GPL http://www.gnu.org/licenses/gpl.html * @link http://sourceforge.net/projects/semanticscuttle */ +$httpContentType = false; require_once 'www-header.php'; if (!$GLOBALS['shorturl']) { diff --git a/www/jsScuttle.php b/www/jsScuttle.php index cc4e16d..f37da78 100644 --- a/www/jsScuttle.php +++ b/www/jsScuttle.php @@ -1,6 +1,6 @@ 1) { list($url, $user, $cat) = explode('/', $_SERVER['PATH_INFO']); } else { -- cgit v1.2.3 From 602ec95bbb91400b6ef2647df55e83e68f4223b5 Mon Sep 17 00:00:00 2001 From: cweiske Date: Thu, 18 Mar 2010 19:24:21 +0000 Subject: unify hashing code in a separate method git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@692 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 65 ++++++++++++++++++++------------ www/bookmarks.php | 2 +- 2 files changed, 42 insertions(+), 25 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 3cdec72..2258625 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -178,9 +178,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService */ public function getBookmarkByAddress($address) { - $address = $this->normalize($address); - $hash = md5($address); - return $this->getBookmarkByHash($hash); + return $this->getBookmarkByHash($this->getHash($address)); } @@ -189,10 +187,12 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService * Retrieves a bookmark with the given hash. * DOES NOT RESPECT PRIVACY SETTINGS! * - * @param string $hash URL hash (MD5) + * @param string $hash URL hash * * @return mixed Array with bookmark data or false in case * of an error (i.e. not found). + * + * @see getHash() */ public function getBookmarkByHash($hash) { @@ -201,6 +201,25 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService + /** + * Returns the hash value of a given address. + * + * @param string $address URL to hash + * @param boolean $bNormalize If the address shall be normalized before + * being hashed + * + * @return string Hash value + */ + public function getHash($address, $bNormalize = true) + { + if ($bNormalize) { + $address = $this->normalize($address); + } + return md5($address); + } + + + /** * Retrieves a bookmark that has a given short * name. @@ -319,9 +338,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService return false; } - $address = $this->normalize($address); - - $crit = array('bHash' => md5($address)); + $crit = array('bHash' => $this->getHash($address)); if (isset ($uid)) { $crit['uId'] = $uid; } @@ -365,7 +382,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $hashes = array(); $sql = '(1'; foreach ($addresses as $key => $address) { - $hash = md5($this->normalize($address)); + $hash = $this->getHash($address); $hashes[$hash] = $address; $sql .= ' OR bHash = "' . $this->db->sql_escape($hash) @@ -462,17 +479,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService // Set up the SQL insert statement and execute it. $values = array( - 'uId' => intval($sId), - 'bIp' => $ip, - 'bDatetime' => $datetime, - 'bModified' => $datetime, - 'bTitle' => $title, - 'bAddress' => $address, + 'uId' => intval($sId), + 'bIp' => $ip, + 'bDatetime' => $datetime, + 'bModified' => $datetime, + 'bTitle' => $title, + 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, - 'bStatus' => intval($status), - 'bHash' => md5($address), - 'bShort' => $short + 'bStatus' => intval($status), + 'bHash' => $this->getHash($address), + 'bShort' => $short ); $sql = 'INSERT INTO '. $this->getTableName() @@ -582,14 +599,14 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService // Set up the SQL update statement and execute it. $updates = array( - 'bModified' => $moddatetime, - 'bTitle' => $title, - 'bAddress' => $address, + 'bModified' => $moddatetime, + 'bTitle' => $title, + 'bAddress' => $address, 'bDescription' => $description, 'bPrivateNote' => $privateNote, - 'bStatus' => $status, - 'bHash' => md5($address), - 'bShort' => $short + 'bStatus' => $status, + 'bHash' => $this->getHash($address, false), + 'bShort' => $short ); if (!is_null($date)) { @@ -1004,7 +1021,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $addressesSql = ' AND (0'; foreach ((array)$addresses as $address) { $addressesSql .= ' OR B.bHash = "' - . $this->db->sql_escape(md5($address)) + . $this->db->sql_escape($this->getHash($address)) . '"'; } $addressesSql .= ')'; diff --git a/www/bookmarks.php b/www/bookmarks.php index 0c9bfa4..5241481 100644 --- a/www/bookmarks.php +++ b/www/bookmarks.php @@ -167,7 +167,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') { if (GET_ACTION == "add") { // If the bookmark exists already, edit the original if ($bookmarkservice->bookmarkExists(stripslashes(GET_ADDRESS), $currentUserID)) { - $bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, md5($bookmarkservice->normalize(stripslashes(GET_ADDRESS)))); + $bookmark =& $bookmarkservice->getBookmarks(0, NULL, $currentUserID, NULL, NULL, NULL, NULL, NULL, NULL, $bookmarkservice->getHash(stripslashes(GET_ADDRESS))); $popup = (GET_POPUP!='') ? '?popup=1' : ''; header('Location: '. createURL('edit', $bookmark['bookmarks'][0]['bId'] . $popup)); exit(); -- cgit v1.2.3 From d249a8ad19514e0c386391ae37081445ee6c23c7 Mon Sep 17 00:00:00 2001 From: cweiske Date: Thu, 18 Mar 2010 19:26:09 +0000 Subject: fix bad bug that was introduced due to performance optimizations git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@693 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 2258625..364b1a0 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -380,7 +380,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService } $hashes = array(); - $sql = '(1'; + $sql = '(0'; foreach ($addresses as $key => $address) { $hash = $this->getHash($address); $hashes[$hash] = $address; -- cgit v1.2.3 From 0f3c51ef7ebb18919a65ccdc25782f9550a1c680 Mon Sep 17 00:00:00 2001 From: cweiske Date: Fri, 19 Mar 2010 07:43:21 +0000 Subject: fix notice git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@695 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/db/mysqli.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/db/mysqli.php b/src/SemanticScuttle/db/mysqli.php index 27814a7..03b36ea 100644 --- a/src/SemanticScuttle/db/mysqli.php +++ b/src/SemanticScuttle/db/mysqli.php @@ -440,7 +440,7 @@ class sql_db echo '' . $msg_title . ''; + echo 'DB query explanation'; echo '
phpBB LogoSQL Report      

Page generated in ' . round($totaltime, 4) . " seconds with {$this->num_queries} queries" . (($cache_num_queries) ? " + $cache_num_queries " . (($cache_num_queries == 1) ? 'query' : 'queries') . ' returning data from cache' : '') . '
Time spent on MySQL queries: ' . round($this->sql_time, 5) . 's | Time spent on PHP: ' . round($totaltime - $this->sql_time, 5) . 's
'; echo $sql_report; echo '

'; -- cgit v1.2.3 From 31570df64ce6543de407e7b9d751ba9033d930de Mon Sep 17 00:00:00 2001 From: cweiske Date: Fri, 9 Jul 2010 10:04:35 +0000 Subject: Fix bug getTagsForBookmarks() that fetched all tags, see http://sourceforge.net/projects/semanticscuttle/forums/forum/759510/topic/3752670 for details git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@715 b3834d28-1941-0410-a4f8-b48e95affb8f --- doc/ChangeLog | 5 +++++ src/SemanticScuttle/Service/Bookmark2Tag.php | 7 +------ tests/Bookmark2TagTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/doc/ChangeLog b/doc/ChangeLog index 5b4e4d3..5e24f07 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,11 @@ ChangeLog for SemantiScuttle ============================ +0.9X.X - 2010-XX-XX +------------------- +- Fix bug getTagsForBookmarks() that fetched all tags + + 0.97.0 - 2010-06-09 ------------------- - Many SQL optimizations - SemanticScuttle shows bookmarks 4 times faster now diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index d6c0e58..4d2c969 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -325,13 +325,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return array(); } - $sql = ''; - foreach ($bookmarkids as $bookmarkid) { - $sql .= ' OR bId = ' . intval($bookmarkid); - } - $query = 'SELECT tag, bId FROM ' . $this->getTableName() - . ' WHERE (1' . $sql . ')' + . ' WHERE bId IN (' . implode(',', $bookmarkids) . ')' . ' AND LEFT(tag, 7) <> "system:"' . ' ORDER BY id, bId ASC'; diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php index 0afaaf8..14b71cc 100644 --- a/tests/Bookmark2TagTest.php +++ b/tests/Bookmark2TagTest.php @@ -171,6 +171,12 @@ class Bookmark2TagTest extends TestBase $bid4 = $this->addBookmark(null, null, 0, array()); //no tags + //bookmark that does not get queried + //http://sourceforge.net/projects/semanticscuttle/forums/forum/759510/topic/3752670 + $bid5 = $this->addBookmark(null, null, 0, array()); + $this->b2ts->attachTags($bid5, array('foo', 'bar2', 'fuu5')); + + $alltags = $this->b2ts->getTagsForBookmarks( array($bid1, $bid2, $bid3, $bid4) ); -- cgit v1.2.3