From 4de56ed6623c57c1c767be192ffe2af5926fe598 Mon Sep 17 00:00:00 2001 From: mensonge Date: Mon, 21 Apr 2008 08:44:44 +0000 Subject: Refactoring: rename sc_tags into sc_bookmarks2tags (and services, codes...) git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@116 b3834d28-1941-0410-a4f8-b48e95affb8f --- .htaccess | 26 ++- alltags.php | 6 +- api/tags_get.php | 6 +- api/tags_rename.php | 4 +- bookmarkcommondescriptionedit.php | 1 - header.inc.php | 6 - populartags.php | 6 +- services/bookmark2tagservice.php | 410 +++++++++++++++++++++++++++++++++ services/bookmarkservice.php | 20 +- services/tagservice.php | 410 --------------------------------- tables.sql | 20 +- tagcommondescriptionedit.php | 2 +- tagdelete.php | 4 +- tagrename.php | 4 +- templates/dynamictags.inc.php | 8 +- templates/sidebar.block.common.php | 6 +- templates/sidebar.block.popular.php | 6 +- templates/sidebar.block.recent.php | 6 +- templates/sidebar.block.related.php | 4 +- templates/sidebar.block.search.php | 1 - templates/sidebar.block.tagactions.php | 1 - templates/sidebar.block.users.php | 1 - tests/LAUNCH_TESTS | 2 +- tests/bookmarksTest.php | 4 +- tests/commonDescriptionTest.php | 6 +- tests/searchTest.php | 6 +- tests/tag2TagTest.php | 18 +- upgrade.txt | 10 +- 28 files changed, 515 insertions(+), 489 deletions(-) create mode 100644 services/bookmark2tagservice.php delete mode 100644 services/tagservice.php diff --git a/.htaccess b/.htaccess index 323c2fa..8262b68 100644 --- a/.htaccess +++ b/.htaccess @@ -1,16 +1,28 @@ # this file is used if you configure your scuttle for nice urls # (see $cleanurls in config.inc.php) -Options +FollowSymlinks -# AcceptPathInfo On -RewriteEngine On -RewriteBase / -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^([^/]+)/?(.*) $1.php/$2 [L] +#Options +FollowSymlinks +#RewriteEngine On +#RewriteBase / +#RewriteCond %{REQUEST_FILENAME} !-f +#RewriteCond %{REQUEST_FILENAME} !-d +#RewriteRule ^([^/]+)/?(.*) $1.php/$2 [L] # If you have Scuttle in subdirectories e.g. http://www.example.com/myscuttle/links/ # then you need to comment the precedent line and remove comment of the following one # (replace "myscuttle/links/" with your subdirectories name) #RewriteRule ^([^/]+)/?(.*) myscuttle/links/$1.php/$2 [L] + +#### + +# Rewrite clean URLs onto real files + +Options +FollowSymlinks +RewriteEngine On +RewriteBase / +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME}.php -f +RewriteRule ^([^/]+)/?(.*) $1.php?query=$2 [L,QSA] + diff --git a/alltags.php b/alltags.php index 3805a3d..f2520a0 100644 --- a/alltags.php +++ b/alltags.php @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require_once('header.inc.php'); $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); -$tagservice =& ServiceFactory::getServiceInstance('TagService'); +$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); $cacheservice =& ServiceFactory::getServiceInstance('CacheService'); @@ -65,8 +65,8 @@ if (isset($user) && $user != '') { $userid = NULL; } -$tags =& $tagservice->getTags($userid); -$tplVars['tags'] =& $tagservice->tagCloud($tags, 5, 90, 225, getSortOrder()); +$tags =& $b2tservice->getTags($userid); +$tplVars['tags'] =& $b2tservice->tagCloud($tags, 5, 90, 225, getSortOrder()); $tplVars['user'] = $user; if (isset($userid)) { diff --git a/api/tags_get.php b/api/tags_get.php index 2584566..172dd0a 100644 --- a/api/tags_get.php +++ b/api/tags_get.php @@ -8,11 +8,11 @@ require_once('httpauth.inc.php'); require_once('../header.inc.php'); -$tagservice =& ServiceFactory::getServiceInstance('TagService'); +$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); // Get the tags relevant to the passed-in variables. -$tags =& $tagservice->getTags($userservice->getCurrentUserId()); +$tags =& $b2tservice->getTags($userservice->getCurrentUserId()); // Set up the XML file and output all the tags. header('Content-Type: text/xml'); @@ -22,4 +22,4 @@ foreach($tags as $row) { echo "\t\r\n"; } echo ""; -?> \ No newline at end of file +?> diff --git a/api/tags_rename.php b/api/tags_rename.php index 20831e7..fc4f2ad 100644 --- a/api/tags_rename.php +++ b/api/tags_rename.php @@ -8,7 +8,7 @@ require_once('httpauth.inc.php'); require_once('../header.inc.php'); -$tagservice =& ServiceFactory::getServiceInstance('TagService'); +$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); // Get the tag info. @@ -26,7 +26,7 @@ if (is_null($old) || is_null($new)) { $renamed = false; } else { // Rename the tag. - $result = $tagservice->renameTag($userservice->getCurrentUserId(), $old, $new, true); + $result = $b2tservice->renameTag($userservice->getCurrentUserId(), $old, $new, true); $renamed = $result; } diff --git a/bookmarkcommondescriptionedit.php b/bookmarkcommondescriptionedit.php index 2abdf4f..c70dac0 100644 --- a/bookmarkcommondescriptionedit.php +++ b/bookmarkcommondescriptionedit.php @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require_once('header.inc.php'); $bookmarkservice = & ServiceFactory :: getServiceInstance('BookmarkService'); -$tagservice = & ServiceFactory :: getServiceInstance('TagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); $cdservice = & ServiceFactory :: getServiceInstance('CommonDescriptionService'); diff --git a/header.inc.php b/header.inc.php index 55defdb..361d233 100644 --- a/header.inc.php +++ b/header.inc.php @@ -26,10 +26,4 @@ if (!isset($root)) { } $root = 'http://'. $_SERVER['HTTP_HOST'] . $root; } - -// Error codes -define('GENERAL_MESSAGE', 200); -define('GENERAL_ERROR', 202); -define('CRITICAL_MESSAGE', 203); -define('CRITICAL_ERROR', 204); ?> diff --git a/populartags.php b/populartags.php index 6bed82d..a51ff68 100644 --- a/populartags.php +++ b/populartags.php @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require_once('header.inc.php'); $templateservice =& ServiceFactory::getServiceInstance('TemplateService'); -$tagservice =& ServiceFactory::getServiceInstance('TagService'); +$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); $userservice =& ServiceFactory::getServiceInstance('UserService'); $cacheservice =& ServiceFactory::getServiceInstance('CacheService'); @@ -66,8 +66,8 @@ if (isset($user) && $user != '') { $userid = NULL; } -$tags = $tagservice->getPopularTags($userid, 150, $logged_on_userid); -$tplVars['tags'] =& $tagservice->tagCloud($tags, 5, 90, 225, getSortOrder('alphabet_asc')); +$tags = $b2tservice->getPopularTags($userid, 150, $logged_on_userid); +$tplVars['tags'] =& $b2tservice->tagCloud($tags, 5, 90, 225, getSortOrder('alphabet_asc')); $tplVars['user'] = $user; if (isset($userid)) { diff --git a/services/bookmark2tagservice.php b/services/bookmark2tagservice.php new file mode 100644 index 0000000..148ad3a --- /dev/null +++ b/services/bookmark2tagservice.php @@ -0,0 +1,410 @@ +db =& $db; + $this->tablename = $GLOBALS['tableprefix'] .'bookmarks2tags'; + } + + function isNotSystemTag($var) { + if (utf8_substr($var, 0, 7) == 'system:') + return false; + else + return true; + } + + function attachTags($bookmarkid, $tags, $fromApi = false, $extension = NULL, $replace = true, $fromImport = false) { + // Make sure that categories is an array of trimmed strings, and that if the categories are + // coming in from an API call to add a bookmark, that underscores are converted into strings. + if (!is_array($tags)) { + $tags = trim($tags); + if ($tags != '') { + if (substr($tags, -1) == ',') { + $tags = substr($tags, 0, -1); + } + if ($fromApi) { + $tags = explode(' ', $tags); + } else { + $tags = explode(',', $tags); + } + } else { + $tags = null; + } + } + + //clean tags from strange characters + $tags = str_replace(array('"', '\''), "_", $tags); + + + $tags_count = count($tags); + for ($i = 0; $i < $tags_count; $i++) { + $tags[$i] = trim(strtolower($tags[$i])); + if ($fromApi) { + include_once(dirname(__FILE__) .'/../functions.inc.php'); + $tags[$i] = convertTag($tags[$i], 'in'); + } + } + + if ($tags_count > 0) { + // Remove system tags + $tags = array_filter($tags, array($this, "isNotSystemTag")); + + // Eliminate any duplicate categories + $temp = array_unique($tags); + $tags = array_values($temp); + } else { + // Unfiled + $tags[] = 'system:unfiled'; + } + + // Media and file types + if (!is_null($extension)) { + include_once(dirname(__FILE__) .'/../functions.inc.php'); + if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { + $tags[] = 'system:filetype:'. $extension; + $tags[] = 'system:media:'. array_shift($keys); + } + } + + // Imported + if ($fromImport) { + $tags[] = 'system:imported'; + } + + $this->db->sql_transaction('begin'); + + if ($replace) { + if (!$this->deleteTagsForBookmark($bookmarkid)){ + $this->db->sql_transaction('rollback'); + message_die(GENERAL_ERROR, 'Could not attach tags (deleting old ones failed)', '', __LINE__, __FILE__, $sql, $this->db); + return false; + } + } + + $bs =& ServiceFactory::getServiceInstance('BookmarkService'); + $tts =& ServiceFactory::getServiceInstance('Tag2TagService'); + + // Create links between tags + foreach($tags as $key => $tag) { + if(strpos($tag, '=')) { + // case "=" + $pieces = explode('=', $tag); + $nbPieces = count($pieces); + if($nbPieces > 1) { + for($i = 0; $i < $nbPieces-1; $i++) { + $bookmark = $bs->getBookmark($bookmarkid); + $uId = $bookmark['uId']; + $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '=', $uId); + } + $tags[$key] = $pieces[0]; // Attach just the last tag to the bookmark + } + } else { + // case ">" + $pieces = explode('>', $tag); + $nbPieces = count($pieces); + if($nbPieces > 1) { + for($i = 0; $i < $nbPieces-1; $i++) { + $bookmark = $bs->getBookmark($bookmarkid); + $uId = $bookmark['uId']; + $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '>', $uId); + } + $tags[$key] = $pieces[$nbPieces-1]; // Attach just the last tag to the bookmark + } + } + + + } + + // Add the categories to the DB. + for ($i = 0; $i < count($tags); $i++) { + if ($tags[$i] != '') { + $values = array( + 'bId' => intval($bookmarkid), + 'tag' => $tags[$i] + ); + + if (!$this->hasTag($bookmarkid, $tags[$i])) { + $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); + if (!($dbresult =& $this->db->sql_query($sql))) { + $this->db->sql_transaction('rollback'); + message_die(GENERAL_ERROR, 'Could not attach tags', '', __LINE__, __FILE__, $sql, $this->db); + return false; + } + } + } + } + $this->db->sql_transaction('commit'); + return true; + } + + function deleteTag($uId, $tag) { + $bs =& ServiceFactory::getServiceInstance('BookmarkService'); + + $query = 'DELETE FROM '. $this->getTableName(); + $query.= ' USING '. $this->getTableName() .', '. $bs->getTableName(); + $query.= ' WHERE '. $this->getTableName() .'.bId = '. $bs->getTableName() .'.bId'; + $query.= ' AND '. $bs->getTableName() .'.uId = '. $uId; + $query.= ' AND '. $this->getTableName() .'.tag = "'. $this->db->sql_escape($tag) .'"'; + + if (!($dbresult =& $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return true; + } + + function deleteTagsForBookmark($bookmarkid) { + if (!is_int($bookmarkid)) { + message_die(GENERAL_ERROR, 'Could not delete tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query); + return false; + } + + $query = 'DELETE FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid); + + if (!($dbresult =& $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return true; + } + + function &getTagsForBookmark($bookmarkid) { + if (!is_int($bookmarkid)) { + 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 tag'; + + 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)) { + $tags[] = $row['tag']; + } + + return $tags; + } + + function &getTags($userid = NULL) { + $userservice =& ServiceFactory::getServiceInstance('UserService'); + $logged_on_user = $userservice->getCurrentUserId(); + + $query = 'SELECT T.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B INNER JOIN '. $userservice->getTableName() .' AS U ON B.uId = U.'. $userservice->getFieldName('primary') .' INNER JOIN '. $GLOBALS['tableprefix'] .'bookmarks2tags AS T ON B.bId = T.bId'; + + $conditions = array(); + if (!is_null($userid)) { + $conditions['U.'. $userservice->getFieldName('primary')] = intval($userid); + if ($logged_on_user != $userid) + $conditions['B.bStatus'] = 0; + } else { + $conditions['B.bStatus'] = 0; + } + + $query .= ' WHERE '. $this->db->sql_build_array('SELECT', $conditions) .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag'; + + if (!($dbresult =& $this->db->sql_query($query))) { + message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + return $this->db->sql_fetchrowset($dbresult); + } + + + // Returns the tags related to the specified tags; i.e. attached to the same bookmarks + function &getRelatedTags($tags, $for_user = NULL, $logged_on_user = NULL, $limit = 10) { + $conditions = array(); + // Only count the tags that are visible to the current user. + if ($for_user != $logged_on_user || is_null($for_user)) + $conditions['B.bStatus'] = 0; + + if (!is_null($for_user)) + $conditions['B.uId'] = $for_user; + + // Set up the tags, if need be. + if (is_numeric($tags)) + $tags = NULL; + if (!is_array($tags) and !is_null($tags)) + $tags = explode('+', trim($tags)); + + $tagcount = count($tags); + for ($i = 0; $i < $tagcount; $i++) { + $tags[$i] = trim($tags[$i]); + } + + // Set up the SQL query. + $query_1 = 'SELECT DISTINCTROW T0.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B, '. $this->getTableName() .' AS T0'; + $query_2 = ''; + $query_3 = ' WHERE B.bId = T0.bId '; + if (count($conditions) > 0) + $query_4 = ' AND '. $this->db->sql_build_array('SELECT', $conditions); + else + $query_4 = ''; + // Handle the parts of the query that depend on any tags that are present. + for ($i = 1; $i <= $tagcount; $i++) { + $query_2 .= ', '. $this->getTableName() .' AS T'. $i; + $query_4 .= ' AND T'. $i .'.bId = B.bId AND T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i - 1]) .'" AND T0.tag <> "'. $this->db->sql_escape($tags[$i - 1]) .'"'; + } + $query_5 = ' AND LEFT(T0.tag, 7) <> "system:" GROUP BY T0.tag ORDER BY bCount DESC, T0.tag'; + $query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5; + + if (! ($dbresult =& $this->db->sql_query_limit($query, $limit)) ){ + message_die(GENERAL_ERROR, 'Could not get related tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + return $this->db->sql_fetchrowset($dbresult); + } + + // Returns the most popular tags used for a particular bookmark hash + function &getRelatedTagsByHash($hash, $limit = 20) { + $userservice = & ServiceFactory :: getServiceInstance('UserService'); + $sId = $userservice->getCurrentUserId(); + // Logged in + if ($userservice->isLoggedOn()) { + $arrWatch = $userservice->getWatchList($sId); + // From public bookmarks or user's own + $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; + // From shared bookmarks in watchlist + foreach ($arrWatch as $w) { + $privacy .= ' OR (B.uId = '. $w .' AND B.bStatus = 1)'; + } + $privacy .= ') '; + // Not logged in + } else { + $privacy = ' AND B.bStatus = 0 '; + } + + $query = 'SELECT T.tag, COUNT(T.tag) AS bCount FROM '.$GLOBALS['tableprefix'].'bookmarks AS B LEFT JOIN '.$GLOBALS['tableprefix'].'bookmarks2tags AS T ON B.bId = T.bId WHERE B.bHash = "'. $hash .'" '. $privacy .'AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC'; + + if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) { + message_die(GENERAL_ERROR, 'Could not get related tags for this hash', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + return $this->db->sql_fetchrowset($dbresult); + } + + function &getPopularTags($user = NULL, $limit = 30, $logged_on_user = NULL, $days = NULL) { + // Only count the tags that are visible to the current user. + if (($user != $logged_on_user) || is_null($user) || ($user === false)) + $privacy = ' AND B.bStatus = 0'; + else + $privacy = ''; + + if (is_null($days) || !is_int($days)) + $span = ''; + else + $span = ' AND B.bDatetime > "'. date('Y-m-d H:i:s', time() - (86400 * $days)) .'"'; + + $query = 'SELECT T.tag, COUNT(T.bId) AS bCount FROM '. $this->getTableName() .' AS T, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE '; + if (is_null($user) || ($user === false)) { + $query .= 'B.bId = T.bId AND B.bStatus = 0'; + } else { + $query .= 'B.uId = '. $this->db->sql_escape($user) .' AND B.bId = T.bId'. $privacy; + } + $query .= $span .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag'; + + if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) { + message_die(GENERAL_ERROR, 'Could not get popular tags', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + return $this->db->sql_fetchrowset($dbresult); + } + + function hasTag($bookmarkid, $tag) { + $query = 'SELECT COUNT(*) AS tCount FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND tag ="'. $this->db->sql_escape($tag) .'"'; + + if (! ($dbresult =& $this->db->sql_query($query)) ) { + message_die(GENERAL_ERROR, 'Could not find tag', '', __LINE__, __FILE__, $query, $this->db); + return false; + } + + if ($row =& $this->db->sql_fetchrow($dbresult)) { + if ($row['tCount'] > 0) { + return true; + } + } + return false; + } + + function renameTag($userid, $old, $new, $fromApi = false) { + $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); + + if (is_null($userid) || is_null($old) || is_null($new)) + return false; + + // Find bookmarks with old tag + $bookmarksInfo =& $bookmarkservice->getBookmarks(0, NULL, $userid, $old); + $bookmarks =& $bookmarksInfo['bookmarks']; + + // Delete old tag + $this->deleteTag($userid, $old); + + // Attach new tags + foreach(array_keys($bookmarks) as $key) { + $row =& $bookmarks[$key]; + $this->attachTags($row['bId'], $new, $fromApi, NULL, false); + } + + return true; + } + + function &tagCloud($tags = NULL, $steps = 5, $sizemin = 90, $sizemax = 225, $sortOrder = NULL) { + + if (is_null($tags) || count($tags) < 1) { + return false; + } + + $min = $tags[count($tags) - 1]['bCount']; + $max = $tags[0]['bCount']; + + for ($i = 1; $i <= $steps; $i++) { + $delta = ($max - $min) / (2 * $steps - $i); + $limit[$i] = $i * $delta + $min; + } + $sizestep = ($sizemax - $sizemin) / $steps; + foreach ($tags as $row) { + $next = false; + for ($i = 1; $i <= $steps; $i++) { + if (!$next && $row['bCount'] <= $limit[$i]) { + $size = $sizestep * ($i - 1) + $sizemin; + $next = true; + } + } + $tempArray = array('size' => $size .'%'); + $row = array_merge($row, $tempArray); + $output[] = $row; + } + + if ($sortOrder == 'alphabet_asc') { + usort($output, create_function('$a,$b','return strcasecmp(utf8_deaccent($a["tag"]), utf8_deaccent($b["tag"]));')); + } + + return $output; + } + + function deleteAll() { + $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`'; + $this->db->sql_query($query); + } + + + // Properties + function getTableName() { return $this->tablename; } + function setTableName($value) { $this->tablename = $value; } +} +?> diff --git a/services/bookmarkservice.php b/services/bookmarkservice.php index 54c2773..5339004 100644 --- a/services/bookmarkservice.php +++ b/services/bookmarkservice.php @@ -47,8 +47,8 @@ class BookmarkService { if ($row = & $this->db->sql_fetchrow($dbresult)) { if ($include_tags) { - $tagservice = & ServiceFactory :: getServiceInstance('TagService'); - $row['tags'] = $tagservice->getTagsForBookmark($bid); + $b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); + $row['tags'] = $b2tservice->getTagsForBookmark($bid); } return $row; } else { @@ -157,8 +157,8 @@ class BookmarkService { $extension = end($uriparts); unset($uriparts); - $tagservice = & ServiceFactory :: getServiceInstance('TagService'); - if (!$tagservice->attachTags($bId, $categories, $fromApi, $extension, false, $fromImport)) { + $b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); + if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension, false, $fromImport)) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not insert bookmark', '', __LINE__, __FILE__, $sql, $this->db); return false; @@ -204,8 +204,8 @@ class BookmarkService { $extension = end($uriparts); unset($uriparts); - $tagservice = & ServiceFactory :: getServiceInstance('TagService'); - if (!$tagservice->attachTags($bId, $categories, $fromApi, $extension)) { + $b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); + if (!$b2tservice->attachTags($bId, $categories, $fromApi, $extension)) { $this->db->sql_transaction('rollback'); message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db); return false; @@ -226,7 +226,7 @@ class BookmarkService { // bookmarks; otherwise, just get the public bookmarks. // - if the $user is set and IS the logged-in user, then get all bookmarks. $userservice =& ServiceFactory::getServiceInstance('UserService'); - $tagservice =& ServiceFactory::getServiceInstance('TagService'); + $b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); $tag2tagservice =& ServiceFactory::getServiceInstance('Tag2TagService'); $sId = $userservice->getCurrentUserId(); @@ -307,7 +307,7 @@ class BookmarkService { // Handle the parts of the query that depend on any tags that are present. $query_4 = ''; for ($i = 0; $i < $tagcount; $i ++) { - $query_2 .= ', '. $tagservice->getTableName() .' AS T'. $i; + $query_2 .= ', '. $b2tservice->getTableName() .' AS T'. $i; $query_4 .= ' AND ('; $allLinkedTags = $tag2tagservice->getAllLinkedTags($this->db->sql_escape($tags[$i]), '>', $user); @@ -331,7 +331,7 @@ class BookmarkService { // Search terms in tags as well when none given if (!count($tags)) { - $query_2 .= ' LEFT JOIN '. $tagservice->getTableName() .' AS T ON B.bId = T.bId'; + $query_2 .= ' LEFT JOIN '. $b2tservice->getTableName() .' AS T ON B.bId = T.bId'; $dotags = true; } else { $dotags = false; @@ -386,7 +386,7 @@ class BookmarkService { $bookmarks = array(); while ($row = & $this->db->sql_fetchrow($dbresult)) { - $row['tags'] = $tagservice->getTagsForBookmark(intval($row['bId'])); + $row['tags'] = $b2tservice->getTagsForBookmark(intval($row['bId'])); $bookmarks[] = $row; } return array ('bookmarks' => $bookmarks, 'total' => $total); diff --git a/services/tagservice.php b/services/tagservice.php deleted file mode 100644 index 1aba11e..0000000 --- a/services/tagservice.php +++ /dev/null @@ -1,410 +0,0 @@ -db =& $db; - $this->tablename = $GLOBALS['tableprefix'] .'tags'; - } - - function isNotSystemTag($var) { - if (utf8_substr($var, 0, 7) == 'system:') - return false; - else - return true; - } - - function attachTags($bookmarkid, $tags, $fromApi = false, $extension = NULL, $replace = true, $fromImport = false) { - // Make sure that categories is an array of trimmed strings, and that if the categories are - // coming in from an API call to add a bookmark, that underscores are converted into strings. - if (!is_array($tags)) { - $tags = trim($tags); - if ($tags != '') { - if (substr($tags, -1) == ',') { - $tags = substr($tags, 0, -1); - } - if ($fromApi) { - $tags = explode(' ', $tags); - } else { - $tags = explode(',', $tags); - } - } else { - $tags = null; - } - } - - //clean tags from strange characters - $tags = str_replace(array('"', '\''), "_", $tags); - - - $tags_count = count($tags); - for ($i = 0; $i < $tags_count; $i++) { - $tags[$i] = trim(strtolower($tags[$i])); - if ($fromApi) { - include_once(dirname(__FILE__) .'/../functions.inc.php'); - $tags[$i] = convertTag($tags[$i], 'in'); - } - } - - if ($tags_count > 0) { - // Remove system tags - $tags = array_filter($tags, array($this, "isNotSystemTag")); - - // Eliminate any duplicate categories - $temp = array_unique($tags); - $tags = array_values($temp); - } else { - // Unfiled - $tags[] = 'system:unfiled'; - } - - // Media and file types - if (!is_null($extension)) { - include_once(dirname(__FILE__) .'/../functions.inc.php'); - if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) { - $tags[] = 'system:filetype:'. $extension; - $tags[] = 'system:media:'. array_shift($keys); - } - } - - // Imported - if ($fromImport) { - $tags[] = 'system:imported'; - } - - $this->db->sql_transaction('begin'); - - if ($replace) { - if (!$this->deleteTagsForBookmark($bookmarkid)){ - $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not attach tags (deleting old ones failed)', '', __LINE__, __FILE__, $sql, $this->db); - return false; - } - } - - $bs =& ServiceFactory::getServiceInstance('BookmarkService'); - $tts =& ServiceFactory::getServiceInstance('Tag2TagService'); - - // Create links between tags - foreach($tags as $key => $tag) { - if(strpos($tag, '=')) { - // case "=" - $pieces = explode('=', $tag); - $nbPieces = count($pieces); - if($nbPieces > 1) { - for($i = 0; $i < $nbPieces-1; $i++) { - $bookmark = $bs->getBookmark($bookmarkid); - $uId = $bookmark['uId']; - $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '=', $uId); - } - $tags[$key] = $pieces[0]; // Attach just the last tag to the bookmark - } - } else { - // case ">" - $pieces = explode('>', $tag); - $nbPieces = count($pieces); - if($nbPieces > 1) { - for($i = 0; $i < $nbPieces-1; $i++) { - $bookmark = $bs->getBookmark($bookmarkid); - $uId = $bookmark['uId']; - $tts->addLinkedTags($pieces[$i], $pieces[$i+1], '>', $uId); - } - $tags[$key] = $pieces[$nbPieces-1]; // Attach just the last tag to the bookmark - } - } - - - } - - // Add the categories to the DB. - for ($i = 0; $i < count($tags); $i++) { - if ($tags[$i] != '') { - $values = array( - 'bId' => intval($bookmarkid), - 'tag' => $tags[$i] - ); - - if (!$this->hasTag($bookmarkid, $tags[$i])) { - $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); - if (!($dbresult =& $this->db->sql_query($sql))) { - $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not attach tags', '', __LINE__, __FILE__, $sql, $this->db); - return false; - } - } - } - } - $this->db->sql_transaction('commit'); - return true; - } - - function deleteTag($uId, $tag) { - $bs =& ServiceFactory::getServiceInstance('BookmarkService'); - - $query = 'DELETE FROM '. $this->getTableName(); - $query.= ' USING '. $this->getTableName() .', '. $bs->getTableName(); - $query.= ' WHERE '. $this->getTableName() .'.bId = '. $bs->getTableName() .'.bId'; - $query.= ' AND '. $bs->getTableName() .'.uId = '. $uId; - $query.= ' AND '. $this->getTableName() .'.tag = "'. $this->db->sql_escape($tag) .'"'; - - if (!($dbresult =& $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - - return true; - } - - function deleteTagsForBookmark($bookmarkid) { - if (!is_int($bookmarkid)) { - message_die(GENERAL_ERROR, 'Could not delete tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query); - return false; - } - - $query = 'DELETE FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid); - - if (!($dbresult =& $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - - return true; - } - - function &getTagsForBookmark($bookmarkid) { - if (!is_int($bookmarkid)) { - 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 tag'; - - 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)) { - $tags[] = $row['tag']; - } - - return $tags; - } - - function &getTags($userid = NULL) { - $userservice =& ServiceFactory::getServiceInstance('UserService'); - $logged_on_user = $userservice->getCurrentUserId(); - - $query = 'SELECT T.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B INNER JOIN '. $userservice->getTableName() .' AS U ON B.uId = U.'. $userservice->getFieldName('primary') .' INNER JOIN '. $GLOBALS['tableprefix'] .'tags AS T ON B.bId = T.bId'; - - $conditions = array(); - if (!is_null($userid)) { - $conditions['U.'. $userservice->getFieldName('primary')] = intval($userid); - if ($logged_on_user != $userid) - $conditions['B.bStatus'] = 0; - } else { - $conditions['B.bStatus'] = 0; - } - - $query .= ' WHERE '. $this->db->sql_build_array('SELECT', $conditions) .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag'; - - if (!($dbresult =& $this->db->sql_query($query))) { - message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - return $this->db->sql_fetchrowset($dbresult); - } - - - // Returns the tags related to the specified tags; i.e. attached to the same bookmarks - function &getRelatedTags($tags, $for_user = NULL, $logged_on_user = NULL, $limit = 10) { - $conditions = array(); - // Only count the tags that are visible to the current user. - if ($for_user != $logged_on_user || is_null($for_user)) - $conditions['B.bStatus'] = 0; - - if (!is_null($for_user)) - $conditions['B.uId'] = $for_user; - - // Set up the tags, if need be. - if (is_numeric($tags)) - $tags = NULL; - if (!is_array($tags) and !is_null($tags)) - $tags = explode('+', trim($tags)); - - $tagcount = count($tags); - for ($i = 0; $i < $tagcount; $i++) { - $tags[$i] = trim($tags[$i]); - } - - // Set up the SQL query. - $query_1 = 'SELECT DISTINCTROW T0.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B, '. $this->getTableName() .' AS T0'; - $query_2 = ''; - $query_3 = ' WHERE B.bId = T0.bId '; - if (count($conditions) > 0) - $query_4 = ' AND '. $this->db->sql_build_array('SELECT', $conditions); - else - $query_4 = ''; - // Handle the parts of the query that depend on any tags that are present. - for ($i = 1; $i <= $tagcount; $i++) { - $query_2 .= ', '. $this->getTableName() .' AS T'. $i; - $query_4 .= ' AND T'. $i .'.bId = B.bId AND T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i - 1]) .'" AND T0.tag <> "'. $this->db->sql_escape($tags[$i - 1]) .'"'; - } - $query_5 = ' AND LEFT(T0.tag, 7) <> "system:" GROUP BY T0.tag ORDER BY bCount DESC, T0.tag'; - $query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5; - - if (! ($dbresult =& $this->db->sql_query_limit($query, $limit)) ){ - message_die(GENERAL_ERROR, 'Could not get related tags', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - return $this->db->sql_fetchrowset($dbresult); - } - - // Returns the most popular tags used for a particular bookmark hash - function &getRelatedTagsByHash($hash, $limit = 20) { - $userservice = & ServiceFactory :: getServiceInstance('UserService'); - $sId = $userservice->getCurrentUserId(); - // Logged in - if ($userservice->isLoggedOn()) { - $arrWatch = $userservice->getWatchList($sId); - // From public bookmarks or user's own - $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; - // From shared bookmarks in watchlist - foreach ($arrWatch as $w) { - $privacy .= ' OR (B.uId = '. $w .' AND B.bStatus = 1)'; - } - $privacy .= ') '; - // Not logged in - } else { - $privacy = ' AND B.bStatus = 0 '; - } - - $query = 'SELECT T.tag, COUNT(T.tag) AS bCount FROM sc_bookmarks AS B LEFT JOIN sc_tags AS T ON B.bId = T.bId WHERE B.bHash = "'. $hash .'" '. $privacy .'AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC'; - - if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) { - message_die(GENERAL_ERROR, 'Could not get related tags for this hash', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - return $this->db->sql_fetchrowset($dbresult); - } - - function &getPopularTags($user = NULL, $limit = 30, $logged_on_user = NULL, $days = NULL) { - // Only count the tags that are visible to the current user. - if (($user != $logged_on_user) || is_null($user) || ($user === false)) - $privacy = ' AND B.bStatus = 0'; - else - $privacy = ''; - - if (is_null($days) || !is_int($days)) - $span = ''; - else - $span = ' AND B.bDatetime > "'. date('Y-m-d H:i:s', time() - (86400 * $days)) .'"'; - - $query = 'SELECT T.tag, COUNT(T.bId) AS bCount FROM '. $this->getTableName() .' AS T, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE '; - if (is_null($user) || ($user === false)) { - $query .= 'B.bId = T.bId AND B.bStatus = 0'; - } else { - $query .= 'B.uId = '. $this->db->sql_escape($user) .' AND B.bId = T.bId'. $privacy; - } - $query .= $span .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag'; - - if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) { - message_die(GENERAL_ERROR, 'Could not get popular tags', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - - return $this->db->sql_fetchrowset($dbresult); - } - - function hasTag($bookmarkid, $tag) { - $query = 'SELECT COUNT(*) AS tCount FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND tag ="'. $this->db->sql_escape($tag) .'"'; - - if (! ($dbresult =& $this->db->sql_query($query)) ) { - message_die(GENERAL_ERROR, 'Could not find tag', '', __LINE__, __FILE__, $query, $this->db); - return false; - } - - if ($row =& $this->db->sql_fetchrow($dbresult)) { - if ($row['tCount'] > 0) { - return true; - } - } - return false; - } - - function renameTag($userid, $old, $new, $fromApi = false) { - $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService'); - - if (is_null($userid) || is_null($old) || is_null($new)) - return false; - - // Find bookmarks with old tag - $bookmarksInfo =& $bookmarkservice->getBookmarks(0, NULL, $userid, $old); - $bookmarks =& $bookmarksInfo['bookmarks']; - - // Delete old tag - $this->deleteTag($userid, $old); - - // Attach new tags - foreach(array_keys($bookmarks) as $key) { - $row =& $bookmarks[$key]; - $this->attachTags($row['bId'], $new, $fromApi, NULL, false); - } - - return true; - } - - function &tagCloud($tags = NULL, $steps = 5, $sizemin = 90, $sizemax = 225, $sortOrder = NULL) { - - if (is_null($tags) || count($tags) < 1) { - return false; - } - - $min = $tags[count($tags) - 1]['bCount']; - $max = $tags[0]['bCount']; - - for ($i = 1; $i <= $steps; $i++) { - $delta = ($max - $min) / (2 * $steps - $i); - $limit[$i] = $i * $delta + $min; - } - $sizestep = ($sizemax - $sizemin) / $steps; - foreach ($tags as $row) { - $next = false; - for ($i = 1; $i <= $steps; $i++) { - if (!$next && $row['bCount'] <= $limit[$i]) { - $size = $sizestep * ($i - 1) + $sizemin; - $next = true; - } - } - $tempArray = array('size' => $size .'%'); - $row = array_merge($row, $tempArray); - $output[] = $row; - } - - if ($sortOrder == 'alphabet_asc') { - usort($output, create_function('$a,$b','return strcasecmp(utf8_deaccent($a["tag"]), utf8_deaccent($b["tag"]));')); - } - - return $output; - } - - function deleteAll() { - $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`'; - $this->db->sql_query($query); - } - - - // Properties - function getTableName() { return $this->tablename; } - function setTableName($value) { $this->tablename = $value; } -} -?> diff --git a/tables.sql b/tables.sql index 92c42c7..8280ac3 100644 --- a/tables.sql +++ b/tables.sql @@ -1,5 +1,6 @@ -- Semantice Scuttle - Tables creation SQL script -- ! Dont forget to change table names according to $tableprefix defined in config.inc.php ! + -- -- Table structure for table `sc_bookmarks` -- @@ -28,12 +29,27 @@ CREATE TABLE `sc_bookmarks` ( -- CREATE TABLE `sc_tags` ( + `tId` int(11) NOT NULL auto_increment, + `tag` varchar(32) NOT NULL default '', + `uId` int(11) NOT NULL default '0', + `tDescription` varchar(255) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `sc_tags_tag_uId` (`tag`, `uId`) +); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `sc_bookmarks2tags` +-- + +CREATE TABLE `sc_bookmarks2tags` ( `id` int(11) NOT NULL auto_increment, `bId` int(11) NOT NULL default '0', `tag` varchar(32) NOT NULL default '', PRIMARY KEY (`id`), - UNIQUE KEY `sc_tags_tag_bId` (`tag`,`bId`), - KEY `sc_tags_bId` (`bId`) + UNIQUE KEY `sc_bookmarks2tags_tag_bId` (`tag`,`bId`), + KEY `sc_bookmarks2tags_bId` (`bId`) ); -- -------------------------------------------------------- diff --git a/tagcommondescriptionedit.php b/tagcommondescriptionedit.php index bb167d8..4c77b14 100644 --- a/tagcommondescriptionedit.php +++ b/tagcommondescriptionedit.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ require_once('header.inc.php'); -$tagservice = & ServiceFactory :: getServiceInstance('TagService'); +$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); $cdservice = & ServiceFactory :: getServiceInstance('CommonDescriptionService'); diff --git a/tagdelete.php b/tagdelete.php index c5325c5..efdca16 100644 --- a/tagdelete.php +++ b/tagdelete.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ require_once('header.inc.php'); -$tagservice = & ServiceFactory :: getServiceInstance('TagService'); +$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); @@ -29,7 +29,7 @@ $logged_on_user = $userservice->getCurrentUser(); list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']); if ($_POST['confirm']) { - if ($tagservice->deleteTag($logged_on_user['uId'], $tag)) { + if ($b2tservice->deleteTag($logged_on_user['uId'], $tag)) { $tplVars['msg'] = T_('Tag deleted'); header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')])); } else { diff --git a/tagrename.php b/tagrename.php index 18e9675..23cb00b 100644 --- a/tagrename.php +++ b/tagrename.php @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ require_once('header.inc.php'); -$tagservice = & ServiceFactory :: getServiceInstance('TagService'); +$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); $tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2tagService'); $templateservice = & ServiceFactory :: getServiceInstance('TemplateService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); @@ -43,7 +43,7 @@ if ($_POST['confirm']) { if ( !is_null($old) && !is_null($new) && - $tagservice->renameTag($userservice->getCurrentUserId(), $old, $new) && + $b2tservice->renameTag($userservice->getCurrentUserId(), $old, $new) && $tag2tagservice->renameTag($userservice->getCurrentUserId(), $old, $new) ) { $tplVars['msg'] = T_('Tag renamed'); diff --git a/templates/dynamictags.inc.php b/templates/dynamictags.inc.php index 5a85143..4bc0421 100644 --- a/templates/dynamictags.inc.php +++ b/templates/dynamictags.inc.php @@ -19,13 +19,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ***************************************************************************/ -$tagservice = & ServiceFactory :: getServiceInstance('TagService'); +$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService'); $userservice = & ServiceFactory :: getServiceInstance('UserService'); $logged_on_userid = $userservice->getCurrentUserId(); -$userPopularTags =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid); -$userPopularTagsCloud =& $tagservice->tagCloud($userPopularTags, 5, 90, 175); +$userPopularTags =& $b2tservice->getPopularTags($logged_on_userid, 25, $logged_on_userid); +$userPopularTagsCloud =& $b2tservice->tagCloud($userPopularTags, 5, 90, 175); $userPopularTagsCount = count($userPopularTags); if ($userPopularTagsCount > 0) { @@ -117,4 +117,4 @@ document.write('<\/div>'); \ No newline at end of file +?> diff --git a/templates/sidebar.block.common.php b/templates/sidebar.block.common.php index e92efa7..dd3ce18 100644 --- a/templates/sidebar.block.common.php +++ b/templates/sidebar.block.common.php @@ -1,7 +1,7 @@ getRelatedTagsByHash($hash); -$commonTags =& $tagservice->tagCloud($commonTags, 5, 90, 225, 'alphabet_asc'); +$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService'); +$commonTags =& $b2tservice->getRelatedTagsByHash($hash); +$commonTags =& $b2tservice->tagCloud($commonTags, 5, 90, 225, 'alphabet_asc'); if ($commonTags && count($commonTags) > 0) { ?> diff --git a/templates/sidebar.block.popular.php b/templates/sidebar.block.popular.php index 446e9b2..cc5c73a 100644 --- a/templates/sidebar.block.popular.php +++ b/templates/sidebar.block.popular.php @@ -1,13 +1,13 @@ getCurrentUserId(); if ($logged_on_userid === false) { $logged_on_userid = NULL; } -$popularTags =& $tagservice->getPopularTags($userid, $popCount, $logged_on_userid); -$popularTags =& $tagservice->tagCloud($popularTags, 5, 90, 225, 'alphabet_asc'); +$popularTags =& $b2tservice->getPopularTags($userid, $popCount, $logged_on_userid); +$popularTags =& $b2tservice->tagCloud($popularTags, 5, 90, 225, 'alphabet_asc'); if ($popularTags && count($popularTags) > 0) { ?> diff --git a/templates/sidebar.block.recent.php b/templates/sidebar.block.recent.php index 58a9f84..6d25478 100644 --- a/templates/sidebar.block.recent.php +++ b/templates/sidebar.block.recent.php @@ -1,13 +1,13 @@ getCurrentUserId(); if ($logged_on_userid === false) { $logged_on_userid = NULL; } -$recentTags = $tagservice->getPopularTags($userid, $popCount, $logged_on_userid, $GLOBALS['defaultRecentDays']); -$recentTags =& $tagservice->tagCloud($recentTags, 5, 90, 225, 'alphabet_asc'); +$recentTags = $b2tservice->getPopularTags($userid, $popCount, $logged_on_userid, $GLOBALS['defaultRecentDays']); +$recentTags =& $b2tservice->tagCloud($recentTags, 5, 90, 225, 'alphabet_asc'); if ($recentTags && count($recentTags) > 0) { ?> diff --git a/templates/sidebar.block.related.php b/templates/sidebar.block.related.php index fd305a6..380c789 100644 --- a/templates/sidebar.block.related.php +++ b/templates/sidebar.block.related.php @@ -1,5 +1,5 @@ getCurrentUserId(); @@ -10,7 +10,7 @@ if(strlen($user)==0) { $cat_url = createURL('tags', '%2$s'); } if ($currenttag) { - $relatedTags = $tagservice->getRelatedTags($currenttag, $userid, $logged_on_userid); + $relatedTags = $b2tservice->getRelatedTags($currenttag, $userid, $logged_on_userid); if (sizeof($relatedTags) > 0) { ?> diff --git a/templates/sidebar.block.search.php b/templates/sidebar.block.search.php index e9638d2..8b00bb4 100644 --- a/templates/sidebar.block.search.php +++ b/templates/sidebar.block.search.php @@ -1,5 +1,4 @@ isLoggedOn()) { $currentUser = $userservice->getCurrentUser(); diff --git a/templates/sidebar.block.users.php b/templates/sidebar.block.users.php index b2d5b4e..813c163 100644 --- a/templates/sidebar.block.users.php +++ b/templates/sidebar.block.users.php @@ -1,5 +1,4 @@ getCurrentUserId(); diff --git a/tests/LAUNCH_TESTS b/tests/LAUNCH_TESTS index 52d4ba5..531d239 100644 --- a/tests/LAUNCH_TESTS +++ b/tests/LAUNCH_TESTS @@ -4,4 +4,4 @@ Then To launch the tests, put in a console situated in the root of the SEMANTICSCUTTLE project (where is the SEMANTICSCUTTLE config file): -phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php ; phpunit SearchTest tests/searchTest.php +phpunit BookmarksTest ./tests/bookmarksTest.php ; phpunit CommonDescriptionTest tests/commonDescriptionTest.php ; phpunit Tag2TagTest tests/tag2TagTest.php ; phpunit SearchTest tests/searchTest.php ; phpunit TagsTest tests/tagsTest.php diff --git a/tests/bookmarksTest.php b/tests/bookmarksTest.php index ac6a79f..9c8e533 100644 --- a/tests/bookmarksTest.php +++ b/tests/bookmarksTest.php @@ -22,8 +22,8 @@ class BookmarksTest extends PHPUnit_Framework_TestCase $this->us =& ServiceFactory::getServiceInstance('UserService'); $this->bs =& ServiceFactory::getServiceInstance('BookmarkService'); $this->bs->deleteAll(); - $this->ts =& ServiceFactory::getServiceInstance('TagService'); - $this->ts->deleteAll(); + $this->b2ts=& ServiceFactory::getServiceInstance('Bookmark2TagService'); + $this->b2ts->deleteAll(); $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService'); $this->tts->deleteAll(); $this->tsts =& ServiceFactory::getServiceInstance('TagStatService'); diff --git a/tests/commonDescriptionTest.php b/tests/commonDescriptionTest.php index 4de4d84..c8666c2 100644 --- a/tests/commonDescriptionTest.php +++ b/tests/commonDescriptionTest.php @@ -11,7 +11,7 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase { protected $us; protected $bs; - protected $ts; + protected $b2ts; protected $tts; protected $tsts; protected $cds; @@ -24,8 +24,8 @@ class CommonDescriptionTest extends PHPUnit_Framework_TestCase $this->us =& ServiceFactory::getServiceInstance('UserService'); $this->bs =& ServiceFactory::getServiceInstance('BookmarkService'); $this->bs->deleteAll(); - $this->ts =& ServiceFactory::getServiceInstance('TagService'); - $this->ts->deleteAll(); + $this->b2ts =& ServiceFactory::getServiceInstance('Bookmark2TagService'); + $this->b2ts->deleteAll(); $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService'); $this->tts->deleteAll(); $this->tsts =& ServiceFactory::getServiceInstance('TagStatService'); diff --git a/tests/searchTest.php b/tests/searchTest.php index ecdc6ad..2e51717 100644 --- a/tests/searchTest.php +++ b/tests/searchTest.php @@ -11,7 +11,7 @@ class SearchTest extends PHPUnit_Framework_TestCase { protected $us; protected $bs; - protected $ts; + protected $b2ts; protected $tts; protected $shs; @@ -23,8 +23,8 @@ class SearchTest extends PHPUnit_Framework_TestCase $this->us =& ServiceFactory::getServiceInstance('UserService'); $this->bs =& ServiceFactory::getServiceInstance('BookmarkService'); $this->bs->deleteAll(); - $this->ts =& ServiceFactory::getServiceInstance('TagService'); - $this->ts->deleteAll(); + $this->b2ts =& ServiceFactory::getServiceInstance('Bookmark2TagService'); + $this->b2ts->deleteAll(); $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService'); $this->tts->deleteAll(); $this->tsts =& ServiceFactory::getServiceInstance('TagStatService'); diff --git a/tests/tag2TagTest.php b/tests/tag2TagTest.php index 70925bd..3f686a4 100644 --- a/tests/tag2TagTest.php +++ b/tests/tag2TagTest.php @@ -11,7 +11,7 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase { protected $us; protected $bs; - protected $ts; + protected $b2ts; protected $tts; protected function setUp() @@ -22,8 +22,8 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $this->us =& ServiceFactory::getServiceInstance('UserService'); $this->bs =& ServiceFactory::getServiceInstance('BookmarkService'); $this->bs->deleteAll(); - $this->ts =& ServiceFactory::getServiceInstance('TagService'); - $this->ts->deleteAll(); + $this->b2ts =& ServiceFactory::getServiceInstance('Bookmark2TagService'); + $this->b2ts->deleteAll(); $this->tts =& ServiceFactory::getServiceInstance('Tag2TagService'); $this->tts->deleteAll(); $this->tsts =& ServiceFactory::getServiceInstance('TagStatService'); @@ -237,8 +237,8 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $bs->addBookmark("http://google.com", "title", "description", "status", $tags, null, false, false, 1); $bookmark = $bs->getBookmarkByAddress("http://google.com"); - $ts = $this->ts; - $savedTags = $ts->getTagsForBookmark(intval($bookmark['bId'])); + $b2ts = $this->b2ts; + $savedTags = $b2ts->getTagsForBookmark(intval($bookmark['bId'])); $this->assertEquals(6, sizeof($savedTags)); $this->assertContains('b', $savedTags); $this->assertContains('c', $savedTags); @@ -425,7 +425,7 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase public function testRenameFunction() { $tts = $this->tts; - $ts = $this->ts; + $b2ts = $this->b2ts; $bs = $this->bs; $tsts = $this->tsts; @@ -436,10 +436,10 @@ class Tag2TagTest extends PHPUnit_Framework_TestCase $bookmarks =& $bs->getBookmarks(0, 1, NULL, NULL, NULL, getSortOrder(), NULL, 0, $dtend); $this->assertEquals(1, $bookmarks['total']); - $ts->renameTag(1, 'tag1', 'newtag1'); - $tags1 = $ts->getTagsForBookmark(1); + $b2ts->renameTag(1, 'tag1', 'newtag1'); + $tags1 = $b2ts->getTagsForBookmark(1); $this->assertSame(array('newtag1', 'tag11', 'tag111'), $tags1); - $tags1 = $ts->getTagsForBookmark(2); + $tags1 = $b2ts->getTagsForBookmark(2); $this->assertSame(array('tag2', 'tag22', 'tag222'), $tags1); //should not be changed diff --git a/upgrade.txt b/upgrade.txt index 9891ac9..11464eb 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -3,7 +3,15 @@ === From version 0.88 to 0.89 === - Backup you database - Make a copy from your SemanticScuttle Web directory -- Upgrade your database : add the following table (adapt its name prefix to your convenience) executin the following SQL commands: +- Upgrade your database : + + +* change the table called 'sc_tags' into 'sc_bookmarks2tags' by executing the following SQL commands (after changing 'yourdatabasename' and adapting its name prefix 'sc_' to your convenience): + + RENAME TABLE `yourdatabasename`.`sc_tags` TO `yourdatabasename`.`sc_bookmarks2tags` ; + + +* add the following table (adapt its name prefix to your convenience) executing the following SQL commands: CREATE TABLE `sc_searchhistory` ( `shId` int(11) NOT NULL auto_increment, -- cgit v1.2.3-54-g00ecf