isLoggedOn()) {
- $currentUser = $userservice->getCurrentUser();
- $currentUsername = $currentUser[$userservice->getFieldName('username')];
- $logged_on = true;
+ $currentUser = $userservice->getCurrentObjectUser();
+ $currentUsername = $currentUser->getUsername();
}
- if ($logged_on || isset($user)) {
+ if ($userservice->isLoggedOn() || isset($user)) {
?>
|
@@ -26,7 +26,7 @@ $select_all = isset($select_all)?$select_all:'';
isLoggedOn()) {
?>
diff --git a/search.php b/search.php
index 6e002bb..ff3729e 100644
--- a/search.php
+++ b/search.php
@@ -1,117 +1,136 @@
getCurrentUserId();
- list($url, $range, $terms, $page) = explode('/', $_SERVER['PATH_INFO']);
+ /* Managing current logged user */
+ $currentUserId = $userservice->getCurrentUserId();
+
+
+ $exploded = explode('/', $_SERVER['PATH_INFO']);
+ if(count($exploded) == 4) {
+ list($url, $range, $terms, $page) = $exploded;
+ } else {
+ list($url, $range, $terms) = $exploded;
+ $page= NULL;
+ }
- $tplvars = array();
- $tplVars['loadjs'] = true;
-
- // Pagination
- $perpage = getPerPageCount();
- if (isset($_GET['page']) && intval($_GET['page']) > 1) {
- $page = $_GET['page'];
- $start = ($page - 1) * $perpage;
- } else {
- $page = 0;
- $start = 0;
- }
-
- $s_user = NULL;
- $s_start = NULL;
- $s_end = NULL;
- $s_watchlist = NULL;
+ $tplvars = array();
+ $tplVars['loadjs'] = true;
- // No search terms
- if (is_null($terms)) {
- $tplVars['subtitle'] = T_('Search Bookmarks');
- $s_start = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' days'));
- $s_end = date('Y-m-d H:i:s', strtotime('tomorrow'));
-
- // Search terms
- } else {
- $tplVars['subtitle'] = T_('Search Results');
- $selected = ' selected="selected"';
+ // Pagination
+ $perpage = getPerPageCount();
+ if (intval(GET_PAGE) > 1) {
+ $page = GET_PAGE;
+ $start = ($page - 1) * $perpage;
+ } else {
+ $page = 0;
+ $start = 0;
+ }
- switch ($range) {
- case 'all':
- $tplVars['select_all'] = $selected;
- $s_user = NULL;
- break;
- case 'watchlist':
- $tplVars['select_watchlist'] = $selected;
- $s_user = $logged_on_userid;
- $s_watchlist = true;
- break;
- default:
- $s_user = $range;
- break;
- }
+ $s_user = NULL;
+ $s_start = NULL;
+ $s_end = NULL;
+ $s_watchlist = NULL;
- if (isset($s_user)) {
- if (is_numeric($s_user)) {
- $s_user = intval($s_user);
- } else {
- if (!($userinfo = $userservice->getUserByUsername($s_user) ) ) {
- $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
- $templateservice->loadTemplate('error.404.tpl', $tplVars);
- exit();
- } else {
- $s_user =& $userinfo[$userservice->getFieldName('primary')];
- }
- }
- }
- }
- $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
+ // No search terms
+ if (is_null($terms)) {
+ $tplVars['subtitle'] = T_('Search Bookmarks');
+ $s_start = date('Y-m-d H:i:s', strtotime($dtend .' -'. $defaultRecentDays .' days'));
+ $s_end = date('Y-m-d H:i:s', strtotime('tomorrow'));
- // Save search
- $searchhistoryservice->addSearch($terms, $range, $bookmarks['total'], $logged_on_userid);
-
- $tplVars['page'] = $page;
- $tplVars['start'] = $start;
- $tplVars['popCount'] = 25;
- $tplVars['sidebar_blocks'] = array('search', 'recent');
- $tplVars['range'] = $range;
- $tplVars['terms'] = $terms;
- $tplVars['pagetitle'] = T_('Search Bookmarks');
- $tplVars['bookmarkCount'] = $start + 1;
- $tplVars['total'] = $bookmarks['total'];
- $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
- $tplVars['cat_url'] = createURL('tags', '%2$s');
- $tplVars['nav_url'] = createURL('search', $range .'/'. $terms .'/%3$s');
-
- $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
+ // Search terms
+ } else {
+ $tplVars['subtitle'] = T_('Search Results');
+ $selected = ' selected="selected"';
+
+ switch ($range) {
+ case 'all':
+ $tplVars['select_all'] = $selected;
+ $s_user = NULL;
+ break;
+ case 'watchlist':
+ $tplVars['select_watchlist'] = $selected;
+ $s_user = $currentUserId;
+ $s_watchlist = true;
+ break;
+ default:
+ $s_user = $range;
+ break;
+ }
+
+ if (isset($s_user)) {
+ if (is_numeric($s_user)) {
+ $s_user = intval($s_user);
+ } else {
+ $userinfo = $userservice->getObjectUserByUsername($s_user);
+ if ($userinfo == '' ) {
+ $tplVars['error'] = sprintf(T_('User with username %s was not found'), $s_user);
+ $templateservice->loadTemplate('error.404.tpl', $tplVars);
+ exit();
+ } else {
+ $s_user =& $userinfo->getId();
+ }
+ }
+ }
+ }
+ $bookmarks =& $bookmarkservice->getBookmarks($start, $perpage, $s_user, NULL, $terms, getSortOrder(), $s_watchlist, $s_start, $s_end);
+
+ // Save search
+ $searchhistoryservice->addSearch($terms, $range, $bookmarks['total'], $currentUserId);
+
+ $tplVars['rsschannels'] = array();
+ $tplVars['page'] = $page;
+ $tplVars['start'] = $start;
+ $tplVars['popCount'] = 25;
+ $tplVars['sidebar_blocks'] = array('search', 'recent');
+ $tplVars['range'] = $range;
+ $tplVars['terms'] = $terms;
+ $tplVars['pagetitle'] = T_('Search Bookmarks');
+ $tplVars['bookmarkCount'] = $start + 1;
+ $tplVars['total'] = $bookmarks['total'];
+ $tplVars['bookmarks'] =& $bookmarks['bookmarks'];
+ $tplVars['cat_url'] = createURL('tags', '%2$s');
+ $tplVars['nav_url'] = createURL('search', $range .'/'. $terms .'/%3$s');
+
+ $templateservice->loadTemplate('bookmarks.tpl', $tplVars);
}
?>
diff --git a/services/bookmark2tagservice.php b/services/bookmark2tagservice.php
index 9cafec9..26a05c1 100644
--- a/services/bookmark2tagservice.php
+++ b/services/bookmark2tagservice.php
@@ -1,188 +1,189 @@
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
- }
- }
-
+ var $db;
+ var $tablename;
+ function &getInstance(&$db) {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new Bookmark2TagService($db);
+ return $instance;
}
- // Add the categories to the DB.
- for ($i = 0; $i < count($tags); $i++) {
- if ($tags[$i] != '') {
- $values = array(
+ function Bookmark2TagService(&$db) {
+ $this->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 = is_array($tags)?count($tags):0;
+
+ 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');
+ 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;
+ }
- $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) .'"';
+ function deleteTag($uId, $tag) {
+ $bs =& ServiceFactory::getServiceInstance('BookmarkService');
- if (!($dbresult =& $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ $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) .'"';
- return true;
- }
-
- function deleteTagsForBookmark($bookmarkid) {
- if (!is_int($bookmarkid)) {
- message_die(GENERAL_ERROR, 'Could not delete tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query);
- return false;
- }
+ if (!($dbresult =& $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- $query = 'DELETE FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid);
+ return true;
+ }
- if (!($dbresult =& $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ function deleteTagsForBookmark($bookmarkid) {
+ if (!is_int($bookmarkid)) {
+ message_die(GENERAL_ERROR, 'Could not delete tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query);
+ return false;
+ }
- return true;
- }
+ $query = 'DELETE FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid);
- /* Allow deletion in admin page */
- function deleteTagsForUser($uId) {
- $qmask = 'DELETE FROM %s USING %s, %s WHERE %s.bId = %s.bId AND %s.uId = %d';
- $query = sprintf($qmask,
+ if (!($dbresult =& $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ return true;
+ }
+
+ /* Allow deletion in admin page */
+ function deleteTagsForUser($uId) {
+ $qmask = 'DELETE FROM %s USING %s, %s WHERE %s.bId = %s.bId AND %s.uId = %d';
+ $query = sprintf($qmask,
$this->getTableName(),
$this->getTableName(),
$GLOBALS['tableprefix'].'bookmarks',
@@ -191,245 +192,246 @@ class Bookmark2TagService {
$GLOBALS['tableprefix'].'bookmarks',
$uId);
- if (!($dbresult =& $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ if (!($dbresult =& $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not delete tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- function &getTagsForBookmark($bookmarkid) {
- if (!is_int($bookmarkid)) {
- message_die(GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query);
- return false;
- }
+ 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';
+ $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;
- }
+ 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'];
- }
+ $tags = array();
+ while ($row =& $this->db->sql_fetchrow($dbresult)) {
+ $tags[] = $row['tag'];
+ }
- return $tags;
- }
+ return $tags;
+ }
- function &getTags($userid = NULL) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
- $logged_on_user = $userservice->getCurrentUserId();
+ 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';
+ $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;
- }
+ $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';
+ $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;
- }
-
- $output = $this->db->sql_fetchrowset($dbresult);
- return $output;
- }
-
-
- // 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 (!($dbresult =& $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- 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;
- }
- $output = $this->db->sql_fetchrowset($dbresult);
- return $output;
- }
-
- // 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;
- }
-
- $output = $this->db->sql_fetchrowset($dbresult);
- return $output;
- }
-
- 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) {
- $output = false;
- return $output;
- }
-
- $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);
- }
+ $output = $this->db->sql_fetchrowset($dbresult);
+ return $output;
+ }
- // Properties
- function getTableName() { return $this->tablename; }
- function setTableName($value) { $this->tablename = $value; }
+ // 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;
+ }
+ $output = $this->db->sql_fetchrowset($dbresult);
+ return $output;
+ }
+
+ // 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;
+ }
+ $output = $this->db->sql_fetchrowset($dbresult);
+ return $output;
+ }
+
+ 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;
+ }
+
+ $output = $this->db->sql_fetchrowset($dbresult);
+ return $output;
+ }
+
+ 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) {
+ $output = false;
+ return $output;
+ }
+
+ $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 9127c12..73cdf84 100644
--- a/services/bookmarkservice.php
+++ b/services/bookmarkservice.php
@@ -20,6 +20,8 @@ class BookmarkService {
$userservice = & ServiceFactory :: getServiceInstance('UserService');
$sId = $userservice->getCurrentUserId();
$range = ' AND uId = '. $sId;
+ } else {
+ $range = '';
}
$query = 'SELECT * FROM '. $this->getTableName() .' WHERE '. $fieldname .' = "'. $this->db->sql_escape($value) .'"'. $range;
@@ -271,6 +273,7 @@ class BookmarkService {
} else {
$arrWatch = $userservice->getWatchlist($user);
if (count($arrWatch) > 0) {
+ $query_3_1 = '';
foreach($arrWatch as $row) {
$query_3_1 .= 'B.uId = '. intval($row) .' OR ';
}
@@ -280,7 +283,7 @@ class BookmarkService {
}
$query_3 .= ' AND ('. $query_3_1 .') AND B.bStatus IN (0, 1)';
}
-
+
$query_5 = '';
if($hash == null) {
$query_5.= ' GROUP BY B.bHash';
diff --git a/services/commondescriptionservice.php b/services/commondescriptionservice.php
index 6c591a9..0a96f74 100644
--- a/services/commondescriptionservice.php
+++ b/services/commondescriptionservice.php
@@ -1,153 +1,153 @@
db =& $db;
- $this->tablename = $GLOBALS['tableprefix'] .'commondescription';
- }
-
- function addTagDescription($tag, $desc, $uId, $time) {
- // Check if no modification
- $lastDesc = $this->getLastTagDescription($tag);
- if($lastDesc['cdDescription'] == $desc) {
- return true;
+ function &getInstance(&$db) {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new CommonDescriptionService($db);
+ return $instance;
}
- // If modification
- $datetime = gmdate('Y-m-d H:i:s', $time);
- $values = array('tag'=>$tag, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
- $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 add tag description', '', __LINE__, __FILE__, $sql, $this->db);
- return false;
+ function CommonDescriptionService(&$db) {
+ $this->db =& $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'commondescription';
}
- return true;
- }
+ function addTagDescription($tag, $desc, $uId, $time) {
+ // Check if no modification
+ $lastDesc = $this->getLastTagDescription($tag);
+ if($lastDesc['cdDescription'] == $desc) {
+ return true;
+ }
- function getLastTagDescription($tag) {
- $query = "SELECT *";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE tag='".$tag."'";
- $query.= " ORDER BY cdDatetime DESC";
+ // If modification
+ $datetime = gmdate('Y-m-d H:i:s', $time);
+ $values = array('tag'=>$tag, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
+ $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
- if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
- message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ if (!($dbresult =& $this->db->sql_query($sql))) {
+ $this->db->sql_transaction('rollback');
+ message_die(GENERAL_ERROR, 'Could not add tag description', '', __LINE__, __FILE__, $sql, $this->db);
+ return false;
+ }
- if ($row =& $this->db->sql_fetchrow($dbresult)) {
- return $row;
- } else {
- return false;
- }
- }
-
- function getAllTagsDescription($tag) {
- $query = "SELECT *";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE tag='".$tag."'";
- $query.= " ORDER BY cdDatetime DESC";
-
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- return $this->db->sql_fetchrowset($dbresult);
-
- }
-
- function getDescriptionById($cdId) {
- $query = "SELECT *";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE cdId='".$cdId."'";
-
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- if ($row =& $this->db->sql_fetchrow($dbresult)) {
- return $row;
- } else {
- return false;
- }
-
- }
-
- function addBookmarkDescription($bHash, $title, $desc, $uId, $time) {
- // Check if no modification
- $lastDesc = $this->getLastBookmarkDescription($bHash);
- if($lastDesc['cdTitle'] == $title && $lastDesc['cdDescription'] == $desc) {
- return true;
+ return true;
}
- // If modification
- $datetime = gmdate('Y-m-d H:i:s', $time);
- $values = array('bHash'=>$bHash, 'cdTitle'=>$title, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
- $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+ function getLastTagDescription($tag) {
+ $query = "SELECT *";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE tag='".$tag."'";
+ $query.= " ORDER BY cdDatetime DESC";
- if (!($dbresult =& $this->db->sql_query($sql))) {
- $this->db->sql_transaction('rollback');
- message_die(GENERAL_ERROR, 'Could not add bookmark description', '', __LINE__, __FILE__, $sql, $this->db);
- return false;
+ if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
+ message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ if ($row =& $this->db->sql_fetchrow($dbresult)) {
+ return $row;
+ } else {
+ return false;
+ }
}
- return true;
- }
- function getLastBookmarkDescription($bHash) {
- $query = "SELECT *";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE bHash='".$bHash."'";
- $query.= " ORDER BY cdDatetime DESC";
+ function getAllTagsDescription($tag) {
+ $query = "SELECT *";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE tag='".$tag."'";
+ $query.= " ORDER BY cdDatetime DESC";
- if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
- message_die(GENERAL_ERROR, 'Could not get bookmark description', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- if ($row =& $this->db->sql_fetchrow($dbresult)) {
- return $row;
- } else {
- return false;
- }
- }
+ return $this->db->sql_fetchrowset($dbresult);
- function getAllBookmarksDescription($bHash) {
- $query = "SELECT *";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE bHash='".$bHash."'";
- $query.= " ORDER BY cdDatetime DESC";
+ }
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get bookmark descriptions', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ function getDescriptionById($cdId) {
+ $query = "SELECT *";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE cdId='".$cdId."'";
- return $this->db->sql_fetchrowset($dbresult);
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get tag descriptions', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- }
+ if ($row =& $this->db->sql_fetchrow($dbresult)) {
+ return $row;
+ } else {
+ return false;
+ }
+
+ }
+
+ function addBookmarkDescription($bHash, $title, $desc, $uId, $time) {
+ // Check if no modification
+ $lastDesc = $this->getLastBookmarkDescription($bHash);
+ if($lastDesc['cdTitle'] == $title && $lastDesc['cdDescription'] == $desc) {
+ return true;
+ }
+
+ // If modification
+ $datetime = gmdate('Y-m-d H:i:s', $time);
+ $values = array('bHash'=>$bHash, 'cdTitle'=>$title, 'cdDescription'=>$desc, 'uId'=>$uId, 'cdDatetime'=>$datetime);
+ $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 add bookmark description', '', __LINE__, __FILE__, $sql, $this->db);
+ return false;
+ }
+ return true;
+ }
+
+ function getLastBookmarkDescription($bHash) {
+ $query = "SELECT *";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE bHash='".$bHash."'";
+ $query.= " ORDER BY cdDatetime DESC";
+
+ if (!($dbresult = & $this->db->sql_query_limit($query, 1, 0))) {
+ message_die(GENERAL_ERROR, 'Could not get bookmark description', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ if ($row =& $this->db->sql_fetchrow($dbresult)) {
+ return $row;
+ } else {
+ return false;
+ }
+ }
+
+ function getAllBookmarksDescription($bHash) {
+ $query = "SELECT *";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE bHash='".$bHash."'";
+ $query.= " ORDER BY cdDatetime DESC";
+
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get bookmark descriptions', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ return $this->db->sql_fetchrowset($dbresult);
+
+ }
- function deleteAll() {
- $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
- $this->db->sql_query($query);
- }
+ function deleteAll() {
+ $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+ $this->db->sql_query($query);
+ }
- // Properties
- function getTableName() { return $this->tablename; }
- function setTableName($value) { $this->tablename = $value; }
+ // Properties
+ function getTableName() { return $this->tablename; }
+ function setTableName($value) { $this->tablename = $value; }
}
?>
diff --git a/services/tag2tagservice.php b/services/tag2tagservice.php
index f24ef79..8c97606 100644
--- a/services/tag2tagservice.php
+++ b/services/tag2tagservice.php
@@ -1,297 +1,297 @@
db =& $db;
- $this->tablename = $GLOBALS['tableprefix'] .'tags2tags';
- }
+ function Tag2TagService(&$db) {
+ $this->db =& $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'tags2tags';
+ }
- function addLinkedTags($tag1, $tag2, $relationType, $uId) {
- if($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0
+ function addLinkedTags($tag1, $tag2, $relationType, $uId) {
+ if($tag1 == $tag2 || strlen($tag1) == 0 || strlen($tag2) == 0
|| ($relationType != ">" && $relationType != "=")
|| ($this->existsLinkedTags($tag1, $tag2, $relationType, $uId))) {
- return false;
- }
- $values = array('tag1' => $tag1, 'tag2' => $tag2, 'relationType'=> $relationType, 'uId'=> $uId);
- $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
-//die($query);
- if (!($dbresult =& $this->db->sql_query($query))) {
- $this->db->sql_transaction('rollback');
- message_die(GENERAL_ERROR, 'Could not attach tag to tag', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
- $this->db->sql_transaction('commit');
-
- // Update stats
- $tsts =& ServiceFactory::getServiceInstance('TagStatService');
- $tsts->updateStat($tag1, $relationType, $uId);
-
- return true;
- }
-
- // Return the target linked tags. If inverseRelation is true, return the source linked tags.
- function getLinkedTags($tag, $relationType, $uId = null, $inverseRelation = false, $stopList = array()) {
- // Set up the SQL query.
- if($inverseRelation) {
- $queriedTag = "tag1";
- $givenTag = "tag2";
- } else {
- $queriedTag = "tag2";
- $givenTag = "tag1";
- }
-
- $query = "SELECT DISTINCT ". $queriedTag ." as 'tag'";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE 1=1";
- if($tag !=null) {
- $query.= " AND ". $givenTag ." = '". $tag ."'";
- }
- if($relationType) {
- $query.= " AND relationType = '". $relationType ."'";
- }
- if($uId != null) {
- $query.= " AND uId = '".$uId."'";
- }
-//die($query);
- if (! ($dbresult =& $this->db->sql_query($query)) ){
- message_die(GENERAL_ERROR, 'Could not get related tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- $rowset = $this->db->sql_fetchrowset($dbresult);
- $output = array();
- foreach($rowset as $row) {
- if(!in_array($row['tag'], $stopList)) {
-
- $output[] = $row['tag'];
- }
- }
-
- //bijective case for '='
- if($relationType == '=' && $inverseRelation == false) {
- //$stopList[] = $tag;
- $bijectiveOutput = $this->getLinkedTags($tag, $relationType, $uId, true, $stopList);
- $output = array_merge($output, $bijectiveOutput);
- //$output = array_unique($output); // remove duplication
- }
-
- return $output;
- }
-
- /* TODO: clean the outputs to obtain homogenous ones*/
- function getAllLinkedTags($tag1, $relationType, $uId, $asFlatList=true, $stopList=array()) {
- $asFlatList = true; //we disable the tree list parameter for the moment
-
- if(in_array($tag1, $stopList)) {
- return array();
- }
-
- $stopList[] = $tag1;
- $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId, false, $stopList);
-
- if($relationType != '=') {
- $linkedTags = array_merge($linkedTags, $this->getLinkedTags($tag1, '=', $uId, false, $stopList));
- }
-
- if(count($linkedTags) == 0) {
- return array();
- } else {
- $output = array();
- if($asFlatList == true) {
- //$output[$tag1] = $tag1;
- } else {
- $output = array('node'=>$tag1);
- }
-
- foreach($linkedTags as $linkedTag) {
- $allLinkedTags = $this->getAllLinkedTags($linkedTag, $relationType, $uId, $asFlatList, $stopList);
-
- if($asFlatList == true) {
- $output[] = $linkedTag;
- if(is_array($allLinkedTags)) {
-
- $output = array_merge($output, $allLinkedTags);
- } else {
- $output[] = $allLinkedTags;
- }
- } else {
- $output[] = $allLinkedTags;
+ return false;
}
- }
- }
- //$output = array_unique($output); // remove duplication
- return $output;
- }
+ $values = array('tag1' => $tag1, 'tag2' => $tag2, 'relationType'=> $relationType, 'uId'=> $uId);
+ $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+ //die($query);
+ if (!($dbresult =& $this->db->sql_query($query))) {
+ $this->db->sql_transaction('rollback');
+ message_die(GENERAL_ERROR, 'Could not attach tag to tag', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+ $this->db->sql_transaction('commit');
- function getOrphewTags($relationType, $uId = 0, $limit = null, $orderBy = null) {
- $query = "SELECT DISTINCT tts.tag1 as tag";
- $query.= " FROM `". $this->getTableName() ."` tts";
- if($orderBy != null) {
- $tsts =& ServiceFactory::getServiceInstance('TagStatService');
- $query.= ", ".$tsts->getTableName() ." tsts";
- }
- $query.= " WHERE tts.tag1 <> ALL";
- $query.= " (SELECT DISTINCT tag2 FROM `". $this->getTableName() ."`";
- $query.= " WHERE relationType = '".$relationType."'";
- if($uId > 0) {
- $query.= " AND uId = '".$uId."'";
- }
- $query.= ")";
- if($uId > 0) {
- $query.= " AND tts.uId = '".$uId."'";
+ // Update stats
+ $tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $tsts->updateStat($tag1, $relationType, $uId);
+
+ return true;
}
- switch($orderBy) {
+ // Return the target linked tags. If inverseRelation is true, return the source linked tags.
+ function getLinkedTags($tag, $relationType, $uId = null, $inverseRelation = false, $stopList = array()) {
+ // Set up the SQL query.
+ if($inverseRelation) {
+ $queriedTag = "tag1";
+ $givenTag = "tag2";
+ } else {
+ $queriedTag = "tag2";
+ $givenTag = "tag1";
+ }
+
+ $query = "SELECT DISTINCT ". $queriedTag ." as 'tag'";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE 1=1";
+ if($tag !=null) {
+ $query.= " AND ". $givenTag ." = '". $tag ."'";
+ }
+ if($relationType) {
+ $query.= " AND relationType = '". $relationType ."'";
+ }
+ if($uId != null) {
+ $query.= " AND uId = '".$uId."'";
+ }
+ //die($query);
+ if (! ($dbresult =& $this->db->sql_query($query)) ){
+ message_die(GENERAL_ERROR, 'Could not get related tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ $rowset = $this->db->sql_fetchrowset($dbresult);
+ $output = array();
+ foreach($rowset as $row) {
+ if(!in_array($row['tag'], $stopList)) {
+
+ $output[] = $row['tag'];
+ }
+ }
+
+ //bijective case for '='
+ if($relationType == '=' && $inverseRelation == false) {
+ //$stopList[] = $tag;
+ $bijectiveOutput = $this->getLinkedTags($tag, $relationType, $uId, true, $stopList);
+ $output = array_merge($output, $bijectiveOutput);
+ //$output = array_unique($output); // remove duplication
+ }
+
+ return $output;
+ }
+
+ /* TODO: clean the outputs to obtain homogenous ones*/
+ function getAllLinkedTags($tag1, $relationType, $uId, $asFlatList=true, $stopList=array()) {
+ $asFlatList = true; //we disable the tree list parameter for the moment
+
+ if(in_array($tag1, $stopList) || $tag1 == '') {
+ return array();
+ }
+
+ $stopList[] = $tag1;
+ $linkedTags = $this->getLinkedTags($tag1, $relationType, $uId, false, $stopList);
+
+ if($relationType != '=') {
+ $linkedTags = array_merge($linkedTags, $this->getLinkedTags($tag1, '=', $uId, false, $stopList));
+ }
+
+ if(count($linkedTags) == 0) {
+ return array();
+ } else {
+ $output = array();
+ if($asFlatList == true) {
+ //$output[$tag1] = $tag1;
+ } else {
+ $output = array('node'=>$tag1);
+ }
+
+ foreach($linkedTags as $linkedTag) {
+ $allLinkedTags = $this->getAllLinkedTags($linkedTag, $relationType, $uId, $asFlatList, $stopList);
+
+ if($asFlatList == true) {
+ $output[] = $linkedTag;
+ if(is_array($allLinkedTags)) {
+
+ $output = array_merge($output, $allLinkedTags);
+ } else {
+ $output[] = $allLinkedTags;
+ }
+ } else {
+ $output[] = $allLinkedTags;
+ }
+ }
+ }
+ //$output = array_unique($output); // remove duplication
+ return $output;
+ }
+
+ function getOrphewTags($relationType, $uId = 0, $limit = null, $orderBy = null) {
+ $query = "SELECT DISTINCT tts.tag1 as tag";
+ $query.= " FROM `". $this->getTableName() ."` tts";
+ if($orderBy != null) {
+ $tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $query.= ", ".$tsts->getTableName() ." tsts";
+ }
+ $query.= " WHERE tts.tag1 <> ALL";
+ $query.= " (SELECT DISTINCT tag2 FROM `". $this->getTableName() ."`";
+ $query.= " WHERE relationType = '".$relationType."'";
+ if($uId > 0) {
+ $query.= " AND uId = '".$uId."'";
+ }
+ $query.= ")";
+ if($uId > 0) {
+ $query.= " AND tts.uId = '".$uId."'";
+ }
+
+ switch($orderBy) {
case "nb":
- $query.= " AND tts.tag1 = tsts.tag1";
- $query.= " AND tsts.relationType = '".$relationType."'";
- if($uId > 0) {
- $query.= " AND tsts.uId = ".$uId;
- }
- $query.= " ORDER BY tsts.nb DESC";
- break;
+ $query.= " AND tts.tag1 = tsts.tag1";
+ $query.= " AND tsts.relationType = '".$relationType."'";
+ if($uId > 0) {
+ $query.= " AND tsts.uId = ".$uId;
+ }
+ $query.= " ORDER BY tsts.nb DESC";
+ break;
case "depth": // by nb of descendants
- $query.= " AND tts.tag1 = tsts.tag1";
- $query.= " AND tsts.relationType = '".$relationType."'";
- if($uId > 0) {
- $query.= " AND tsts.uId = ".$uId;
- }
- $query.= " ORDER BY tsts.depth DESC";
- break;
+ $query.= " AND tts.tag1 = tsts.tag1";
+ $query.= " AND tsts.relationType = '".$relationType."'";
+ if($uId > 0) {
+ $query.= " AND tsts.uId = ".$uId;
+ }
+ $query.= " ORDER BY tsts.depth DESC";
+ break;
case "nbupdate":
- $query.= " AND tts.tag1 = tsts.tag1";
- $query.= " AND tsts.relationType = '".$relationType."'";
- if($uId > 0) {
- $query.= " AND tsts.uId = ".$uId;
- }
- $query.= " ORDER BY tsts.nbupdate DESC";
- break;
+ $query.= " AND tts.tag1 = tsts.tag1";
+ $query.= " AND tsts.relationType = '".$relationType."'";
+ if($uId > 0) {
+ $query.= " AND tsts.uId = ".$uId;
+ }
+ $query.= " ORDER BY tsts.nbupdate DESC";
+ break;
+ }
+
+ if($limit != null) {
+ $query.= " LIMIT 0,".$limit;
+ }
+
+ if (! ($dbresult =& $this->db->sql_query($query)) ){
+ message_die(GENERAL_ERROR, 'Could not get linked tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+ return $this->db->sql_fetchrowset($dbresult);
}
- if($limit != null) {
- $query.= " LIMIT 0,".$limit;
+ function getMenuTags($uId) {
+ if(strlen($GLOBALS['menuTag']) < 1) {
+ return array();
+ } else {
+ // we don't use the getAllLinkedTags function in order to improve performance
+ $query = "SELECT tag2 as 'tag', COUNT(tag2) as 'count'";
+ $query.= " FROM `". $this->getTableName() ."`";
+ $query.= " WHERE tag1 = '".$GLOBALS['menuTag']."'";
+ $query.= " AND relationType = '>'";
+ if($uId > 0) {
+ $query.= " AND uId = '".$uId."'";
+ }
+ $query.= " GROUP BY tag2";
+ $query.= " ORDER BY count DESC";
+ $query.= " LIMIT 0, ".$GLOBALS['maxSizeMenuBlock'];
+
+ if (! ($dbresult =& $this->db->sql_query($query)) ){
+ message_die(GENERAL_ERROR, 'Could not get linked tags', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+ return $this->db->sql_fetchrowset($dbresult);
+ }
}
- if (! ($dbresult =& $this->db->sql_query($query)) ){
- message_die(GENERAL_ERROR, 'Could not get linked tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
- return $this->db->sql_fetchrowset($dbresult);
- }
- function getMenuTags($uId) {
- if(strlen($GLOBALS['menuTag']) < 1) {
- return array();
- } else {
- // we don't use the getAllLinkedTags function in order to improve performance
- $query = "SELECT tag2 as 'tag', COUNT(tag2) as 'count'";
- $query.= " FROM `". $this->getTableName() ."`";
- $query.= " WHERE tag1 = '".$GLOBALS['menuTag']."'";
- $query.= " AND relationType = '>'";
- if($uId > 0) {
- $query.= " AND uId = '".$uId."'";
- }
- $query.= " GROUP BY tag2";
- $query.= " ORDER BY count DESC";
- $query.= " LIMIT 0, ".$GLOBALS['maxSizeMenuBlock'];
+ function existsLinkedTags($tag1, $tag2, $relationType, $uId) {
+ $query = "SELECT tag1, tag2, relationType, uId FROM `". $this->getTableName() ."`";
+ $query.= " WHERE tag1 = '" .$tag1 ."'";
+ $query.= " AND tag2 = '".$tag2."'";
+ $query.= " AND relationType = '". $relationType ."'";
+ $query.= " AND uId = '".$uId."'";
- if (! ($dbresult =& $this->db->sql_query($query)) ){
- message_die(GENERAL_ERROR, 'Could not get linked tags', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
- return $this->db->sql_fetchrowset($dbresult);
- }
- }
-
-
- function existsLinkedTags($tag1, $tag2, $relationType, $uId) {
- $query = "SELECT tag1, tag2, relationType, uId FROM `". $this->getTableName() ."`";
- $query.= " WHERE tag1 = '" .$tag1 ."'";
- $query.= " AND tag2 = '".$tag2."'";
- $query.= " AND relationType = '". $relationType ."'";
- $query.= " AND uId = '".$uId."'";
-
- return $this->db->sql_numrows($this->db->sql_query($query)) > 0;
- }
-
- function getLinks($uId) {
- $query = "SELECT tag1, tag2, relationType, uId FROM `". $this->getTableName() ."`";
- $query.= " WHERE 1=1";
- if($uId > 0) {
- $query.= " AND uId = '".$uId."'";
+ return $this->db->sql_numrows($this->db->sql_query($query)) > 0;
}
- return $this->db->sql_fetchrowset($this->db->sql_query($query));
- }
+ function getLinks($uId) {
+ $query = "SELECT tag1, tag2, relationType, uId FROM `". $this->getTableName() ."`";
+ $query.= " WHERE 1=1";
+ if($uId > 0) {
+ $query.= " AND uId = '".$uId."'";
+ }
- function removeLinkedTags($tag1, $tag2, $relationType, $uId) {
- if(($tag1 != '' && $tag1 == $tag2) ||
- ($relationType != ">" && $relationType != "=" && $relationType != "") ||
- ($tag1 == '' && $tag2 == '' && $relationType == '' && $uId == '')) {
- return false;
+ return $this->db->sql_fetchrowset($this->db->sql_query($query));
}
- $query = 'DELETE FROM '. $this->getTableName();
- $query.= ' WHERE 1=1';
- $query.= strlen($tag1)>0 ? ' AND tag1 = "'. $tag1 .'"' : '';
- $query.= strlen($tag2)>0 ? ' AND tag2 = "'. $tag2 .'"' : '';
- $query.= strlen($relationType)>0 ? ' AND relationType = "'. $relationType .'"' : '';
- $query.= strlen($uId)>0 ? ' AND uId = "'. $uId .'"' : '';
- if (!($dbresult =& $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not remove tag relation', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
+ function removeLinkedTags($tag1, $tag2, $relationType, $uId) {
+ if(($tag1 != '' && $tag1 == $tag2) ||
+ ($relationType != ">" && $relationType != "=" && $relationType != "") ||
+ ($tag1 == '' && $tag2 == '' && $relationType == '' && $uId == '')) {
+ return false;
+ }
+ $query = 'DELETE FROM '. $this->getTableName();
+ $query.= ' WHERE 1=1';
+ $query.= strlen($tag1)>0 ? ' AND tag1 = "'. $tag1 .'"' : '';
+ $query.= strlen($tag2)>0 ? ' AND tag2 = "'. $tag2 .'"' : '';
+ $query.= strlen($relationType)>0 ? ' AND relationType = "'. $relationType .'"' : '';
+ $query.= strlen($uId)>0 ? ' AND uId = "'. $uId .'"' : '';
- // Update stats
- $tsts =& ServiceFactory::getServiceInstance('TagStatService');
- $tsts->updateStat($tag1, $relationType, $uId);
+ if (!($dbresult =& $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not remove tag relation', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- return true;
- }
+ // Update stats
+ $tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $tsts->updateStat($tag1, $relationType, $uId);
- function renameTag($uId, $oldName, $newName) {
- $query = 'UPDATE `'. $this->getTableName() .'`';
- $query.= ' SET tag1="'.$newName.'"';
- $query.= ' WHERE tag1="'.$oldName.'"';
- $query.= ' AND uId="'.$uId.'"';
- $this->db->sql_query($query);
+ return true;
+ }
- $query = 'UPDATE `'. $this->getTableName() .'`';
- $query.= ' SET tag2="'.$newName.'"';
- $query.= ' WHERE tag2="'.$oldName.'"';
- $query.= ' AND uId="'.$uId.'"';
- $this->db->sql_query($query);
+ function renameTag($uId, $oldName, $newName) {
+ $query = 'UPDATE `'. $this->getTableName() .'`';
+ $query.= ' SET tag1="'.$newName.'"';
+ $query.= ' WHERE tag1="'.$oldName.'"';
+ $query.= ' AND uId="'.$uId.'"';
+ $this->db->sql_query($query);
- // Update stats
- $tsts =& ServiceFactory::getServiceInstance('TagStatService');
- $tsts->updateStat($oldName, '=', $uId);
- $tsts->updateStat($oldName, '>', $uId);
- $tsts->updateStat($newName, '=', $uId);
- $tsts->updateStat($newName, '>', $uId);
+ $query = 'UPDATE `'. $this->getTableName() .'`';
+ $query.= ' SET tag2="'.$newName.'"';
+ $query.= ' WHERE tag2="'.$oldName.'"';
+ $query.= ' AND uId="'.$uId.'"';
+ $this->db->sql_query($query);
- return true;
+ // Update stats
+ $tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $tsts->updateStat($oldName, '=', $uId);
+ $tsts->updateStat($oldName, '>', $uId);
+ $tsts->updateStat($newName, '=', $uId);
+ $tsts->updateStat($newName, '>', $uId);
- }
+ return true;
- function deleteAll() {
- $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
- $this->db->sql_query($query);
+ }
- $tsts =& ServiceFactory::getServiceInstance('TagStatService');
- $tsts->deleteAll();
- }
+ function deleteAll() {
+ $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
+ $this->db->sql_query($query);
- // Properties
- function getTableName() { return $this->tablename; }
- function setTableName($value) { $this->tablename = $value; }
+ $tsts =& ServiceFactory::getServiceInstance('TagStatService');
+ $tsts->deleteAll();
+ }
+
+ // Properties
+ function getTableName() { return $this->tablename; }
+ function setTableName($value) { $this->tablename = $value; }
}
?>
diff --git a/services/tagservice.php b/services/tagservice.php
index 47f82d6..83349c6 100644
--- a/services/tagservice.php
+++ b/services/tagservice.php
@@ -1,89 +1,90 @@
db =& $db;
- $this->tablename = $GLOBALS['tableprefix'] .'tags';
- }
-
- function getDescription($tag, $uId) {
- $query = 'SELECT tag, uId, tDescription';
- $query.= ' FROM '.$this->getTableName();
- $query.= ' WHERE tag = "'.$tag.'"';
- $query.= ' AND uId = "'.$uId.'"';
-
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- if ($row =& $this->db->sql_fetchrow($dbresult)) {
- return $row;
- } else {
- return array();
- }
- }
-
- function getAllDescriptions($tag) {
- $query = 'SELECT tag, uId, tDescription';
- $query.= ' FROM '.$this->getTableName();
- $query.= ' WHERE tag = "'.$tag.'"';
-
- if (!($dbresult = & $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
-
- return $this->db->sql_fetchrowset($dbresult);
- }
-
- function updateDescription($tag, $uId, $desc) {
- if(count($this->getDescription($tag, $uId))>0) {
- $query = 'UPDATE '.$this->getTableName();
- $query.= ' SET tDescription="'.$this->db->sql_escape($desc).'"';
- $query.= ' WHERE tag="'.$tag.'" AND uId="'.$uId.'"';
- } else {
- $values = array('tag'=>$tag, 'uId'=>$uId, 'tDescription'=>$desc);
- $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+ function &getInstance(&$db) {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new TagService($db);
+ return $instance;
}
- $this->db->sql_transaction('begin');
- if (!($dbresult = & $this->db->sql_query($query))) {
- $this->db->sql_transaction('rollback');
- message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
- return false;
- }
- $this->db->sql_transaction('commit');
- return true;
- }
+ function TagService(&$db) {
+ $this->db =& $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'tags';
+ }
- function renameTag($uId, $oldName, $newName) {
- $query = 'UPDATE `'. $this->getTableName() .'`';
- $query.= ' SET tag="'.$newName.'"';
- $query.= ' WHERE tag="'.$oldName.'"';
- $query.= ' AND uId="'.$uId.'"';
- $this->db->sql_query($query);
- return true;
- }
+ function getDescription($tag, $uId) {
+ $query = 'SELECT tag, uId, tDescription';
+ $query.= ' FROM '.$this->getTableName();
+ $query.= ' WHERE tag = "'.$tag.'"';
+ $query.= ' AND uId = "'.$uId.'"';
-
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
- function deleteAll() {
- $query = 'TRUNCATE TABLE `'. $this->getTableName() .'`';
- $this->db->sql_query($query);
- }
+ if ($row =& $this->db->sql_fetchrow($dbresult)) {
+ return $row;
+ } else {
+ return array('tDescription'=>'');
+ }
+ }
- // Properties
- function getTableName() { return $this->tablename; }
- function setTableName($value) { $this->tablename = $value; }
+ function getAllDescriptions($tag) {
+ $query = 'SELECT tag, uId, tDescription';
+ $query.= ' FROM '.$this->getTableName();
+ $query.= ' WHERE tag = "'.$tag.'"';
+
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ message_die(GENERAL_ERROR, 'Could not get tag description', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ return $this->db->sql_fetchrowset($dbresult);
+ }
+
+ function updateDescription($tag, $uId, $desc) {
+ $objectTag = $this->getDescription($tag, $uId);
+ if(count($objectTag)>0 && $objectTag['tDescription'] != '') {
+ $query = 'UPDATE '.$this->getTableName();
+ $query.= ' SET tDescription="'.$this->db->sql_escape($desc).'"';
+ $query.= ' WHERE tag="'.$tag.'" AND uId="'.$uId.'"';
+ } else {
+ $values = array('tag'=>$tag, 'uId'=>$uId, 'tDescription'=>$desc);
+ $query = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values);
+ }
+
+ $this->db->sql_transaction('begin');
+ if (!($dbresult = & $this->db->sql_query($query))) {
+ $this->db->sql_transaction('rollback');
+ message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+ $this->db->sql_transaction('commit');
+ return true;
+ }
+
+ function renameTag($uId, $oldName, $newName) {
+ $query = 'UPDATE `'. $this->getTableName() .'`';
+ $query.= ' SET tag="'.$newName.'"';
+ $query.= ' WHERE tag="'.$oldName.'"';
+ $query.= ' AND uId="'.$uId.'"';
+ $this->db->sql_query($query);
+ return true;
+ }
+
+
+
+ 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/userservice.php b/services/userservice.php
index 19e81c6..241934e 100644
--- a/services/userservice.php
+++ b/services/userservice.php
@@ -76,6 +76,22 @@ class UserService {
return $users;
}
+ function & getObjectUsers($nb=0) {
+ $query = 'SELECT * FROM '. $this->getTableName() .' ORDER BY `uId` DESC';
+ if($nb>0) {
+ $query .= ' LIMIT 0, '.$nb;
+ }
+ if (! ($dbresult =& $this->db->sql_query($query)) ) {
+ message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db);
+ return false;
+ }
+
+ while ($row = & $this->db->sql_fetchrow($dbresult)) {
+ $users[] = new User($row[$this->getFieldName('primary')], $row[$this->getFieldName('username')]);
+ }
+ return $users;
+ }
+
function _randompassword() {
$seed = (integer) md5(microtime());
mt_srand($seed);
@@ -109,10 +125,15 @@ class UserService {
return $this->_getuser($this->getFieldName('username'), $username);
}
+ function getObjectUserByUsername($username) {
+ $user = $this->_getuser($this->getFieldName('username'), $username);
+ return new User($user[$this->getFieldName('primary')], $username);
+ }
+
function getUser($id) {
return $this->_getuser($this->getFieldName('primary'), $id);
}
-
+
// Momentary useful in order to go to object code
function getObjectUser($id) {
$user = $this->_getuser($this->getFieldName('primary'), $id);
@@ -136,7 +157,7 @@ class UserService {
}
return $currentuser;
}
-
+
// Momentary useful in order to go to object code
function getCurrentObjectUser($refresh = FALSE, $newval = NULL) {
static $currentObjectUser;
@@ -152,6 +173,22 @@ class UserService {
return $currentObjectUser;
}
+ function existsUserWithUsername($username) {
+ if($this->getUserByUsername($username) != '') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function existsUser($id) {
+ if($this->getUser($id) != '') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
function isAdmin($userid) {
$user = $this->getUser($userid);
@@ -446,27 +483,84 @@ class UserService {
function setCookieKey($value) { $this->cookiekey = $value; }
}
+
+/* Defines a user. Rare fields are filled if required. */
class User {
var $id;
var $username;
+ var $name;
+ var $email;
+ var $homepage;
+ var $content;
+ var $datetime;
var $isAdmin;
function User($id, $username) {
$this->id = $id;
$this->username = $username;
}
-
+
function getId() {
return $this->id;
}
-
+
function getUsername() {
return $this->username;
}
+
+ function getName() {
+ // Look for value only if not already set
+ if(!isset($this->name)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->name = $user['name'];
+ }
+ return $this->name;
+ }
+ function getEmail() {
+ // Look for value only if not already set
+ if(!isset($this->email)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->email = $user['email'];
+ }
+ return $this->email;
+ }
+
+ function getHomepage() {
+ // Look for value only if not already set
+ if(!isset($this->homepage)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->homepage = $user['homepage'];
+ }
+ return $this->homepage;
+ }
+
+ function getContent() {
+ // Look for value only if not already set
+ if(!isset($this->content)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->content = $user['uContent'];
+ }
+ return $this->content;
+ }
+
+ function getDatetime() {
+ // Look for value only if not already set
+ if(!isset($this->content)) {
+ $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $user = $userservice->getUser($this->id);
+ $this->datetime = $user['uDatetime'];
+ }
+ return $this->datetime;
+ }
+
function isAdmin() {
- // Look for value if not already set
+ // Look for value only if not already set
if(!isset($this->isAdmin)) {
$userservice =& ServiceFactory::getServiceInstance('UserService');
$this->isAdmin = $userservice->isAdmin($this->id);
diff --git a/tag2tagadd.php b/tag2tagadd.php
index 935cf88..07ce3a9 100644
--- a/tag2tagadd.php
+++ b/tag2tagadd.php
@@ -20,43 +20,52 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
require_once('header.inc.php');
+
+/* Service creation: only useful services are created */
$tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2TagService');
$templateservice = & ServiceFactory :: getServiceInstance('TemplateService');
$userservice = & ServiceFactory :: getServiceInstance('UserService');
+/* Managing all possible inputs */
+isset($_POST['confirm']) ? define('POST_CONFIRM', $_POST['confirm']): define('POST_CONFIRM', '');
+isset($_POST['cancel']) ? define('POST_CANCEL', $_POST['cancel']): define('POST_CANCEL', '');
+isset($_POST['tag1']) ? define('POST_TAG1', $_POST['tag1']): define('POST_TAG1', '');
+isset($_POST['linkType']) ? define('POST_LINKTYPE', $_POST['linkType']): define('POST_LINKTYPE', '');
+isset($_POST['tag2']) ? define('POST_TAG2', $_POST['tag2']): define('POST_TAG2', '');
-
-$logged_on_user = $userservice->getCurrentUser();
+/* Managing current logged user */
+$currentObjectUser = $userservice->getCurrentObjectUser();
//permissions
-if($logged_on_user == null) {
+if(!$userservice->isLoggedOn()) {
$tplVars['error'] = T_('Permission denied.');
$templateservice->loadTemplate('error.500.tpl', $tplVars);
exit();
}
-
+/* Managing path info */
list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']);
-if ($_POST['confirm']) {
- $tag1 = $_POST['tag1'];
- $linkType = $_POST['linkType'];
- $tag2 = $_POST['tag2'];
- if ($tag2tagservice->addLinkedTags($tag1, $tag2, $linkType, $userservice->getCurrentUserId())) {
+if (POST_CONFIRM != '') {
+ $tag1 = POST_TAG1;
+ $linkType = POST_LINKTYPE;
+ $tag2 = POST_TAG2;
+ if ($tag2tagservice->addLinkedTags($tag1, $tag2, $linkType, $currentObjectUser->getId())) {
$tplVars['msg'] = T_('Tag link created');
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
+ header('Location: '. createURL('bookmarks', $currentObjectUser->getUsername()));
} else {
$tplVars['error'] = T_('Failed to create the link');
$templateservice->loadTemplate('error.500.tpl', $tplVars);
exit();
}
-} elseif ($_POST['cancel']) {
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags));
+} elseif (POST_CANCEL) {
+ header('Location: '. createURL('bookmarks', $currentObjectUser->getUsername() .'/'. $tags));
}
-$tplVars['links'] = $tag2tagservice->getLinks($userservice->getCurrentUserId());
+$tplVars['links'] = $tag2tagservice->getLinks($currentObjectUser->getId());
$tplVars['tag1'] = $tag1;
+$tplVars['tag2'] = '';
$tplVars['subtitle'] = T_('Add Tag Link') .': '. $tag1;
$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag1;
$tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
diff --git a/tag2tagdelete.php b/tag2tagdelete.php
index f0ae6ed..b62b623 100644
--- a/tag2tagdelete.php
+++ b/tag2tagdelete.php
@@ -1,62 +1,87 @@
getCurrentUser();
+/* Managing all possible inputs */
+isset($_POST['confirm']) ? define('POST_CONFIRM', $_POST['confirm']): define('POST_CONFIRM', '');
+isset($_POST['cancel']) ? define('POST_CANCEL', $_POST['cancel']): define('POST_CANCEL', '');
+isset($_POST['tag1']) ? define('POST_TAG1', $_POST['tag1']): define('POST_TAG1', '');
+isset($_POST['linkType']) ? define('POST_LINKTYPE', $_POST['linkType']): define('POST_LINKTYPE', '');
+isset($_POST['tag2']) ? define('POST_TAG2', $_POST['tag2']): define('POST_TAG2', '');
+
+isset($_SERVER['HTTP_REFERER']) ? define('HTTP_REFERER', $_SERVER['HTTP_REFERER']): define('HTTP_REFERER', '');
+
+/* Managing current logged user */
+$currentUser = $userservice->getCurrentObjectUser();
//permissions
-if($logged_on_user == null) {
- $tplVars['error'] = T_('Permission denied.');
- $templateservice->loadTemplate('error.500.tpl', $tplVars);
- exit();
+if(!$userservice->isloggedOn()) {
+ $tplVars['error'] = T_('Permission denied.');
+ $templateservice->loadTemplate('error.500.tpl', $tplVars);
+ exit();
}
-list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
-
-if ($_POST['confirm']) {
- $tag = $_POST['tag1'];
- $linkType = $_POST['linkType'];
- $newTag = $_POST['tag2'];
- if ($tag2tagservice->removeLinkedTags($_POST['tag1'], $_POST['tag2'], $linkType, $userservice->getCurrentUserId())) {
- $tplVars['msg'] = T_('Tag link deleted');
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')].'/'.$tag));
- } else {
- $tplVars['error'] = T_('Failed to delete the link');
- $templateservice->loadTemplate('error.500.tpl', $tplVars);
- exit();
- }
-} elseif ($_POST['cancel']) {
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags));
+/* Managing path info */
+if(isset($_SERVER['PATH_INFO'])) {
+ $exploded = explode('/', $_SERVER['PATH_INFO']);
+ if(count($exploded) == 3) {
+ list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
+ } else {
+ list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']);
+ $tag2 = '';
+ }
+} else {
+ $url = $tag1 = $tag2 = '';
}
-$tplVars['links'] = $tag2tagservice->getLinks($userservice->getCurrentUserId());
+
+
+if (POST_CONFIRM) {
+ $tag = POST_TAG1;
+ $linkType = POST_LINKTYPE;
+ $newTag = POST_TAG2;
+ if ($tag2tagservice->removeLinkedTags(POST_TAG1, POST_TAG2, POST_LINKTYPE, $currentUser->getId())) {
+ $tplVars['msg'] = T_('Tag link deleted');
+ header('Location: '. createURL('bookmarks', $currentUser->getUsername().'/'.$tag));
+ } else {
+ $tplVars['error'] = T_('Failed to delete the link');
+ $templateservice->loadTemplate('error.500.tpl', $tplVars);
+ exit();
+ }
+} elseif (POST_CANCEL) {
+ header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags));
+}
+
+$tplVars['links'] = $tag2tagservice->getLinks($currentUser->getId());
$tplVars['tag1'] = $tag1;
$tplVars['tag2'] = $tag2;
$tplVars['subtitle'] = T_('Delete Link Between Tags') .': '. $tag1.' > '.$tag2;
-$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
-$tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
+$tplVars['formaction'] = $_SERVER['SCRIPT_NAME'];
+$tplVars['referrer'] = HTTP_REFERER;
$templateservice->loadTemplate('tag2tagdelete.tpl', $tplVars);
?>
diff --git a/tag2tagedit.php b/tag2tagedit.php
index 6dd7b51..e75553f 100644
--- a/tag2tagedit.php
+++ b/tag2tagedit.php
@@ -20,12 +20,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
require_once('header.inc.php');
+
+/* Service creation: only useful services are created */
$tag2tagservice = & ServiceFactory :: getServiceInstance('Tag2TagService');
$templateservice = & ServiceFactory :: getServiceInstance('TemplateService');
$userservice = & ServiceFactory :: getServiceInstance('UserService');
+/* Managing all possible inputs */
+isset($_SERVER['HTTP_REFERER']) ? define('HTTP_REFERER', $_SERVER['HTTP_REFERER']): define('HTTP_REFERER', '');
+
+/* Managing current logged user */
$logged_on_user = $userservice->getCurrentUser();
+
//permissions
if($logged_on_user == null) {
$tplVars['error'] = T_('Permission denied.');
@@ -33,23 +40,18 @@ if($logged_on_user == null) {
exit();
}
-list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
-
-/*if ($_POST['confirm']) {
- $tag = $_POST['tag1'];
- $linkType = $_POST['linkType'];
- $newTag = $_POST['tag2'];
- if ($tag2tagservice->removeLinkedTags($_POST['tag1'], $_POST['tag2'], $linkType, $userservice->getCurrentUserId())) {
- $tplVars['msg'] = T_('Tag link deleted');
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
- } else {
- $tplVars['error'] = T_('Failed to delete the link');
- $templateservice->loadTemplate('error.500.tpl', $tplVars);
- exit();
- }
-} elseif ($_POST['cancel']) {
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags));
-}*/
+/* Managing path info */
+if(isset($_SERVER['PATH_INFO'])) {
+ $exploded = explode('/', $_SERVER['PATH_INFO']);
+ if(count($exploded) == 3) {
+ list ($url, $tag1, $tag2) = explode('/', $_SERVER['PATH_INFO']);
+ } else {
+ list ($url, $tag1) = explode('/', $_SERVER['PATH_INFO']);
+ $tag2 = '';
+ }
+} else {
+ $url = $tag1 = $tag2 = '';
+}
$tplVars['links'] = $tag2tagservice->getLinks($userservice->getCurrentUserId());
@@ -58,6 +60,6 @@ $tplVars['tag2'] = $tag2;
$tplVars['subtitle'] = T_('Edit Link Between Tags') .': '. $tag1.' > '.$tag2;
$tplVars['formaddaction'] = createUrl('tag2tagadd');
$tplVars['formdeleteaction'] = createUrl('tag2tagdelete');
-$tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
+$tplVars['referrer'] = HTTP_REFERER;
$templateservice->loadTemplate('tag2tagedit.tpl', $tplVars);
?>
diff --git a/tagcommondescriptionedit.php b/tagcommondescriptionedit.php
index 4c77b14..113c5bf 100644
--- a/tagcommondescriptionedit.php
+++ b/tagcommondescriptionedit.php
@@ -1,62 +1,73 @@
getCurrentUser();
+
+/* Managing current logged user */
+$currentUser = $userservice->getCurrentObjectUser();
+
+/* Managing path info */
+list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
//permissions
-if($logged_on_user == null) {
- $tplVars['error'] = T_('Permission denied.');
- $templateservice->loadTemplate('error.500.tpl', $tplVars);
- exit();
+if(!$userservice->isLoggedOn()) {
+ $tplVars['error'] = T_('Permission denied.');
+ $templateservice->loadTemplate('error.500.tpl', $tplVars);
+ exit();
}
-if ($_POST['confirm']) {
+$template = 'tagcommondescriptionedit.tpl';
- if ( strlen($tag)>0 &&
- $cdservice->addTagDescription($tag, stripslashes($_POST['description']), $logged_on_user['uId'], time())
- ) {
- $tplVars['msg'] = T_('Tag common description updated');
- header('Location: '. $_POST['referrer']);
- } else {
- $tplVars['error'] = T_('Failed to update the tag common description');
- $template = 'error.500.tpl';
- }
-} elseif ($_POST['cancel']) {
- $logged_on_user = $userservice->getCurrentUser();
- header('Location: '. $_POST['referrer']);
+if (POST_CONFIRM) {
+
+ if ( strlen($tag)>0 &&
+ $cdservice->addTagDescription($tag, stripslashes(POST_DESCRIPTION), $currentUser->getId(), time())
+ ) {
+ $tplVars['msg'] = T_('Tag common description updated');
+ header('Location: '. POST_REFERRER);
+ } else {
+ $tplVars['error'] = T_('Failed to update the tag common description');
+ $template = 'error.500.tpl';
+ }
+} elseif (POST_CANCEL) {
+ header('Location: '. POST_REFERRER);
} else {
- $tplVars['subtitle'] = T_('Edit Tag Common Description') .': '. $tag;
- $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
- $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
- $tplVars['tag'] = $tag;
- $tplVars['description'] = $cdservice->getLastTagDescription($tag);
+ $tplVars['subtitle'] = T_('Edit Tag Common Description') .': '. $tag;
+ $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
+ $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
+ $tplVars['tag'] = $tag;
+ $tplVars['description'] = $cdservice->getLastTagDescription($tag);
}
$templateservice->loadTemplate($template, $tplVars);
?>
diff --git a/tagdelete.php b/tagdelete.php
index efdca16..8c4b1af 100644
--- a/tagdelete.php
+++ b/tagdelete.php
@@ -20,25 +20,36 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
require_once('header.inc.php');
+
+/* Service creation: only useful services are created */
$b2tservice = & ServiceFactory :: getServiceInstance('Bookmark2TagService');
$templateservice = & ServiceFactory :: getServiceInstance('TemplateService');
$userservice = & ServiceFactory :: getServiceInstance('UserService');
-$logged_on_user = $userservice->getCurrentUser();
+/* Managing all possible inputs */
+isset($_POST['confirm']) ? define('POST_CONFIRM', $_POST['confirm']): define('POST_CONFIRM', '');
+isset($_POST['cancel']) ? define('POST_CANCEL', $_POST['cancel']): define('POST_CANCEL', '');
+isset($_POST['referrer']) ? define('POST_REFERRER', $_POST['referrer']): define('POST_REFERRER', '');
+/* Managing current logged user */
+$currentUser = $userservice->getCurrentObjectUser();
+
+/* Managing path info */
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
-if ($_POST['confirm']) {
- if ($b2tservice->deleteTag($logged_on_user['uId'], $tag)) {
+
+
+if (POST_CONFIRM) {
+ if ($b2tservice->deleteTag($currentUser->getId(), $tag)) {
$tplVars['msg'] = T_('Tag deleted');
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
+ header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
} else {
$tplVars['error'] = T_('Failed to delete the tag');
$templateservice->loadTemplate('error.500.tpl', $tplVars);
exit();
}
-} elseif ($_POST['cancel']) {
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags));
+} elseif (POST_CANCEL) {
+ header('Location: '. POST_REFERRER);
}
$tplVars['subtitle'] = T_('Delete Tag') .': '. $tag;
diff --git a/tagedit.php b/tagedit.php
index aca0607..cd248a5 100644
--- a/tagedit.php
+++ b/tagedit.php
@@ -1,61 +1,70 @@
getCurrentObjectUser();
+
+/* Managing path info */
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
+
$template = 'tagedit.tpl';
-$logged_on_user = $userservice->getCurrentUser();
-
//permissions
-if($logged_on_user == null) {
- $tplVars['error'] = T_('Permission denied.');
- $templateservice->loadTemplate('error.500.tpl', $tplVars);
- exit();
+if(!$userservice->isLoggedOn()) {
+ $tplVars['error'] = T_('Permission denied.');
+ $templateservice->loadTemplate('error.500.tpl', $tplVars);
+ exit();
}
-if ($_POST['confirm']) {
-
- if ( strlen($tag)>0 &&
- $tagservice->updateDescription($tag, $logged_on_user['uId'], $_POST['description'])
- ) {
- $tplVars['msg'] = T_('Tag description updated');
- header('Location: '. $_POST['referrer']);
- } else {
- $tplVars['error'] = T_('Failed to update the tag description');
- $template = 'error.500.tpl';
- }
-} elseif ($_POST['cancel']) {
- $logged_on_user = $userservice->getCurrentUser();
- header('Location: '. $_POST['referrer']);
+if (POST_CONFIRM) {
+ if ( strlen($tag)>0 &&
+ $tagservice->updateDescription($tag, $currentUser->getId(), POST_DESCRIPTION)
+ ) {
+ $tplVars['msg'] = T_('Tag description updated');
+ header('Location: '. POST_REFERRER);
+ } else {
+ $tplVars['error'] = T_('Failed to update the tag description');
+ $template = 'error.500.tpl';
+ }
+} elseif (POST_CANCEL) {
+ header('Location: '. POST_REFERRER);
} else {
- $tplVars['subtitle'] = T_('Edit Tag Description') .': '. $tag;
- $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
- $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
- $tplVars['tag'] = $tag;
- $tplVars['description'] = $tagservice->getDescription($tag, $logged_on_user['uId']);
+ $tplVars['subtitle'] = T_('Edit Tag Description') .': '. $tag;
+ $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
+ $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
+ $tplVars['tag'] = $tag;
+ $tplVars['description'] = $tagservice->getDescription($tag, $currentUser->getId());
}
$templateservice->loadTemplate($template, $tplVars);
?>
diff --git a/tagrename.php b/tagrename.php
index 29b44fb..3dde296 100644
--- a/tagrename.php
+++ b/tagrename.php
@@ -1,68 +1,80 @@
getCurrentObjectUser();
+
+/* Managing path info */
list ($url, $tag) = explode('/', $_SERVER['PATH_INFO']);
//$tag = isset($_GET['query']) ? $_GET['query'] : NULL;
$template = 'tagrename.tpl';
-if ($_POST['confirm']) {
- if (isset($_POST['old']) && trim($_POST['old']) != '')
- $old = trim($_REQUEST['old']);
- else
- $old = NULL;
+if (POST_CONFIRM) {
+ if (trim(POST_OLD) != '') {
+ $old = trim(POST_OLD);
+ } else {
+ $old = NULL;
+ }
- if (isset($_POST['new']) && trim($_POST['new']) != '')
- $new = trim($_POST['new']);
- else
- $new = NULL;
+ if (trim(POST_NEW) != '') {
+ $new = trim(POST_NEW);
+ } else {
+ $new = NULL;
+ }
- 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');
- $logged_on_user = $userservice->getCurrentUser();
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')]));
- } else {
- $tplVars['error'] = T_('Failed to rename the tag');
- $template = 'error.500.tpl';
- }
-} elseif ($_POST['cancel']) {
- $logged_on_user = $userservice->getCurrentUser();
- header('Location: '. createURL('bookmarks', $logged_on_user[$userservice->getFieldName('username')] .'/'. $tags));
+ if (
+ !is_null($old) &&
+ !is_null($new) &&
+ $tagservice->renameTag($currentUser->getId(), $old, $new) &&
+ $b2tservice->renameTag($currentUser->getId(), $old, $new) &&
+ $tag2tagservice->renameTag($currentUser->getId(), $old, $new)
+ ) {
+ $tplVars['msg'] = T_('Tag renamed');
+ header('Location: '. createURL('bookmarks', $currentUser->getUsername()));
+ } else {
+ $tplVars['error'] = T_('Failed to rename the tag');
+ $template = 'error.500.tpl';
+ }
+} elseif (POST_CANCEL) {
+ header('Location: '. createURL('bookmarks', $currentUser->getUsername() .'/'. $tags));
} else {
- $tplVars['subtitle'] = T_('Rename Tag') .': '. $tag;
- $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
- $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
- $tplVars['old'] = $tag;
+ $tplVars['subtitle'] = T_('Rename Tag') .': '. $tag;
+ $tplVars['formaction'] = $_SERVER['SCRIPT_NAME'] .'/'. $tag;
+ $tplVars['referrer'] = $_SERVER['HTTP_REFERER'];
+ $tplVars['old'] = $tag;
}
$templateservice->loadTemplate($template, $tplVars);
?>
diff --git a/tags.php b/tags.php
index 599b6fb..308069d 100644
--- a/tags.php
+++ b/tags.php
@@ -1,69 +1,80 @@
getCurrentObjectUser();
+
+/* Managing path info */
+list($url, $cat) = explode('/', $_SERVER['PATH_INFO']);
+
$tplVars = array();
-list($url, $cat) = explode('/', $_SERVER['PATH_INFO']);
+
if (!$cat) {
- header('Location: '. createURL('populartags'));
- exit;
+ header('Location: '. createURL('populartags'));
+ exit;
} else {
- $cattitle = str_replace('+', ' + ', $cat);
+ $cattitle = str_replace('+', ' + ', $cat);
}
$pagetitle = T_('Tags') .': '. $cattitle;
if ($usecache) {
- // Generate hash for caching on
- if ($userservice->isLoggedOn()) {
- $hash = md5($_SERVER['REQUEST_URI'] . $userservice->getCurrentUserID());
- } else {
- $hash = md5($_SERVER['REQUEST_URI']);
- }
+ // Generate hash for caching on
+ if ($userservice->isLoggedOn()) {
+ $hash = md5($_SERVER['REQUEST_URI'] . $currentUser->getId());
+ } else {
+ $hash = md5($_SERVER['REQUEST_URI']);
+ }
- // Cache for 30 minutes
- $cacheservice->Start($hash, 1800);
+ // Cache for 30 minutes
+ $cacheservice->Start($hash, 1800);
}
// Header variables
$tplVars['pagetitle'] = $pagetitle;
$tplVars['loadjs'] = true;
$tplVars['rsschannels'] = array(
- array(filter($sitename .': '. $pagetitle), createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder())
+array(filter($sitename .': '. $pagetitle), createURL('rss', 'all/'. filter($cat, 'url')).'?sort='.getSortOrder())
);
// Pagination
$perpage = getPerPageCount();
-if (isset($_GET['page']) && intval($_GET['page']) > 1) {
- $page = $_GET['page'];
- $start = ($page - 1) * $perpage;
+if (intval(GET_PAGE) > 1) {
+ $page = GET_PAGE;
+ $start = ($page - 1) * $perpage;
} else {
- $page = 0;
- $start = 0;
+ $page = 0;
+ $start = 0;
}
$tplVars['page'] = $page;
@@ -82,7 +93,7 @@ $tplVars['nav_url'] = createURL('tags', '%2$s%3$s');
$templateservice->loadTemplate('bookmarks.tpl', $tplVars);
if ($usecache) {
- // Cache output if existing copy has expired
- $cacheservice->End($hash);
+ // Cache output if existing copy has expired
+ $cacheservice->End($hash);
}
?>
diff --git a/templates/about.tpl.php b/templates/about.tpl.php
index 3f3cbe3..a4bc718 100644
--- a/templates/about.tpl.php
+++ b/templates/about.tpl.php
@@ -1,9 +1,13 @@
includeTemplate($GLOBALS['top_include']);
+/* Service creation: only useful services are created */
$userservice =& ServiceFactory::getServiceInstance('UserService');
-$currentUser = $userservice->getCurrentUser();
-$currentUserId = $userservice->getCurrentUserId();
+//$currentUser = $userservice->getCurrentUser();
+//$currentUserId = $userservice->getCurrentUserId();
+
+$currentObjectUser = $userservice->getCurrentObjectUser();
+
+$this->includeTemplate($GLOBALS['top_include']);
?>
@@ -20,9 +24,10 @@ $currentUserId = $userservice->getCurrentUserId();
-isAdmin($currentUserId)): ?>
+isAdmin()): ?>
- SemanticScuttle v0.91
+
includeTemplate($GLOBALS['top_include']);
+/* Service creation: only useful services are created */
$userservice = & ServiceFactory :: getServiceInstance('UserService');
+
+$this->includeTemplate($GLOBALS['top_include']);
+
list ($url, $hash) = explode('/', $_SERVER['PATH_INFO']);
+
+
?>
+
-
+
|