diff -up flag/flag.inc flag_new/flag.inc --- flag/flag.inc 2008-10-16 18:13:00.000000000 +0200 +++ flag_new/flag.inc 2008-12-30 09:25:44.000000000 +0100 @@ -338,6 +338,7 @@ class flag_flag { * applicable to the item, etc.), TRUE otherwise. */ function flag($action, $content_id, $account = NULL, $skip_permission_check = FALSE) { + $sid = session_api_get_sid(); if (!isset($account)) { $account = $GLOBALS['user']; } @@ -345,14 +346,14 @@ class flag_flag { return FALSE; } - if (!$account->uid) { + /*if (!$account->uid) { // Anonymous users can't flag with this system. For now. // // @todo This is legacy code. $flag->user_access() should handle this. // This will also make it posible to have flags that do support anonymous // users. return FALSE; - } + }*/ if (!$skip_permission_check && !$this->user_access($account)) { // User has no permission to use this flag. @@ -369,14 +370,15 @@ class flag_flag { // Perform the flagging or unflagging of this flag. $uid = $this->global ? 0 : $account->uid; - $flagged = $this->_is_flagged($content_id, $uid); + $sid = session_api_get_sid(); + $flagged = $this->_is_flagged($content_id, $uid, $sid); if ($action == 'unflag' && $flagged) { - $this->_unflag($content_id, $uid); + $this->_unflag($content_id, $uid, $sid); // Let other modules perform actions. module_invoke_all('flag', 'unflag', $this, $content_id, $account); } elseif ($action == 'flag' && !$flagged) { - $this->_flag($content_id, $uid); + $this->_flag($content_id, $uid, $sid); // Let other modules perform actions. module_invoke_all('flag', 'flag', $this, $content_id, $account); } @@ -394,17 +396,18 @@ class flag_flag { * Optional. The user ID whose flags we're checking. If none given, the * current user will be used. */ - function is_flagged($content_id, $uid = NULL) { + function is_flagged($content_id, $uid = NULL, $sid = NULL) { $uid = !isset($uid) ? $GLOBALS['user']->uid : $uid; + $sid = !isset($sid) ? session_api_get_sid() : $sid; // flag_get_user_flags() alreday does caching, but nevertheless we manage a // cache of our own to save on function calls. static $flag_status = array(); - if (!isset($flag_status[$uid][$this->content_type][$content_id])) { - $flag_status[$uid][$this->content_type][$content_id] = flag_get_user_flags($this->content_type, $content_id, $uid); + if (!isset($flag_status[$sid][$this->content_type][$content_id])) { # Array CAMBIATO + $flag_status[$sid][$this->content_type][$content_id] = flag_get_user_flags($this->content_type, $content_id, $uid, $sid); } - return isset($flag_status[$uid][$this->content_type][$content_id][$this->name]); + return isset($flag_status[$sid][$this->content_type][$content_id][$this->name]); } /** @@ -419,8 +422,8 @@ class flag_flag { * * @private */ - function _is_flagged($content_id, $uid) { - return db_result(db_query("SELECT fid FROM {flag_content} WHERE fid = %d AND uid = %d AND content_id = %d", $this->fid, $uid, $content_id)); + function _is_flagged($content_id, $uid, $sid) { + return db_result(db_query("SELECT fid FROM {flag_content} WHERE fid = %d AND uid = %d AND sid = %d AND content_id = %d", $this->fid, $uid, session_api_get_sid(), $content_id)); } /** @@ -431,8 +434,8 @@ class flag_flag { * * @private */ - function _flag($content_id, $uid) { - db_query("INSERT INTO {flag_content} (fid, content_type, content_id, uid, timestamp) VALUES (%d, '%s', %d, %d, %d)", $this->fid, $this->content_type, $content_id, $uid, time()); + function _flag($content_id, $uid, $sid) { + db_query("INSERT INTO {flag_content} (fid, content_type, content_id, uid, sid, timestamp) VALUES (%d, '%s', %d, %d, %d, %d)", $this->fid, $this->content_type, $content_id, $uid, $sid, time()); $this->_update_count($content_id); } @@ -444,8 +447,8 @@ class flag_flag { * * @private */ - function _unflag($content_id, $uid) { - db_query("DELETE FROM {flag_content} WHERE fid = %d AND uid = %d AND content_id = %d", $this->fid, $uid, $content_id); + function _unflag($content_id, $uid, $sid) { + db_query("DELETE FROM {flag_content} WHERE fid = %d AND uid = %d AND sid = %d AND content_id = %d", $this->fid, $uid, $sid, $content_id); $this->_update_count($content_id); } @@ -478,8 +481,8 @@ class flag_flag { * * For global flags, pass '0' as the user ID. */ - function get_user_count($uid) { - return db_result(db_query('SELECT COUNT(*) FROM {flag_content} WHERE fid = %d AND uid = %d', $this->fid, $uid)); + function get_user_count($uid, $sid) { + return db_result(db_query('SELECT COUNT(*) FROM {flag_content} WHERE fid = %d AND uid = %d AND sid = %d', $this->fid, $uid, session_api_get_sid())); } /** diff -up flag/flag.install flag_new/flag.install --- flag/flag.install 2008-10-22 23:50:20.000000000 +0200 +++ flag_new/flag.install 2008-12-29 14:47:35.000000000 +0100 @@ -174,6 +174,12 @@ function flag_schema() { 'not null' => TRUE, 'default' => 0, ), + 'sid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), 'timestamp' => array( 'type' => 'int', 'unsigned' => TRUE, @@ -182,10 +188,11 @@ function flag_schema() { 'disp-size' => 11, ) ), - 'primary key' => array('fid', 'content_type', 'content_id', 'uid'), + # 'primary key' => array('fid', 'content_type', 'content_id', 'uid'), + 'primary key' => array('fid', 'content_type', 'content_id', 'uid', 'sid'), 'indexes' => array( 'content_type_content_id' => array('content_type', 'content_id'), - 'content_type_uid' => array('content_type', 'uid'), + 'content_type_uid' => array('content_type', 'uid', 'sid'), ), ); diff -up flag/flag.module flag_new/flag.module --- flag/flag.module 2008-10-13 13:29:01.000000000 +0200 +++ flag_new/flag.module 2008-12-29 15:54:16.000000000 +0100 @@ -132,9 +132,9 @@ function flag_link($type, $object = NULL global $user; // Anonymous users can't create flags with this system. - if (!$user->uid) { + /*if (!$user->uid) { return; - } + }*/ // Get all possible flags for this content-type. $flags = flag_get_flags($type); @@ -200,9 +200,9 @@ function flag_form_alter(&$form, &$form_ } elseif (isset($form['type']) && isset($form['#node']) && ($form_id == $form['type']['#value'] .'_node_form')) { - if (!$user->uid) { + /*if (!$user->uid) { return; - } + }*/ $nid = !empty($form['nid']['#value']) ? $form['nid']['#value'] : NULL; @@ -277,7 +277,7 @@ function flag_user($op, &$edit, &$accoun switch ($op) { case 'delete': // Remove flags by this user. - db_query("DELETE FROM {flag_content} WHERE uid = %d", $account->uid); + db_query("DELETE FROM {flag_content} WHERE uid = %d AND sid = %d", $account->uid, session_api_get_sid()); break; case 'view'; $flags = flag_get_flags('user'); @@ -535,7 +535,8 @@ function flag_form(&$form_state, $name, $form['roles'] = array( '#type' => 'checkboxes', '#title' => t('Roles that may use this flag'), - '#options' => user_roles(TRUE), + #'#options' => user_roles(TRUE), + '#options' => user_roles(), # cfr. http://drupal.org/node/271582#comment-885356 '#default_value' => $flag->roles, '#required' => TRUE, '#description' => t('Checking authenticated user will allow all logged-in users to flag content with this flag. Anonymous users may not flag content.'), @@ -1038,33 +1039,34 @@ function flag_get_flags($content_type = * [nid] => [name] => Object from above. * */ -function flag_get_user_flags($content_type, $content_id = NULL, $uid = NULL, $reset = FALSE) { +function flag_get_user_flags($content_type, $content_id = NULL, $uid = NULL, $sid = NULL, $reset = FALSE) { static $flagged_content; $uid = !isset($uid) ? $GLOBALS['user']->uid : $uid; + $sid = !isset($sid) ? session_api_get_sid() : $sid; if (isset($content_id)) { - if (!isset($flagged_content[$uid][$content_type][$content_id]) || $reset) { + if (!isset($flagged_content[$sid][$content_type][$content_id]) || $reset) { $flags = flag_get_flags($content_type); - $flagged_content[$uid][$content_type][$content_id] = array(); - $result = db_query("SELECT * FROM {flag_content} WHERE content_type = '%s' AND content_id = %d AND (uid = %d OR uid = 0)", $content_type, $content_id, $uid); + $flagged_content[$sid][$content_type][$content_id] = array(); + $result = db_query("SELECT * FROM {flag_content} WHERE content_type = '%s' AND content_id = %d AND (uid = %d OR uid = 0) AND sid = %s", $content_type, $content_id, $uid, $sid); while ($flag = db_fetch_object($result)) { - $flagged_content[$uid][$content_type][$content_id][$flags[$flag->fid]->name] = $flag; + $flagged_content[$sid][$content_type][$content_id][$flags[$flag->fid]->name] = $flag; } } - return $flagged_content[$uid][$content_type][$content_id]; + return $flagged_content[$sid][$content_type][$content_id]; } else { - if (!isset($flagged_content[$uid]['all'][$content_type]) || $reset) { + if (!isset($flagged_content[$sid]['all'][$content_type]) || $reset) { $flags = flag_get_flags($content_type); - $flagged_content[$uid]['all'][$content_type] = TRUE; - $result = db_query("SELECT * FROM {flag_content} WHERE content_type = '%s' AND (uid = %d OR uid = 0)", $content_type, $uid); + $flagged_content[$sid]['all'][$content_type] = TRUE; + $result = db_query("SELECT * FROM {flag_content} WHERE content_type = '%s' AND (uid = %d OR uid = 0) AND sid = %s", $content_type, $uid, $sid); while ($flag = db_fetch_object($result)) { - $flagged_content[$uid][$content_type]['all'][$flags[$flag->fid]->name][$flag->content_id] = $flag; + $flagged_content[$sid][$content_type]['all'][$flags[$flag->fid]->name][$flag->content_id] = $flag; } } - return $flagged_content[$uid][$content_type]['all']; + return $flagged_content[$sid][$content_type]['all']; } } Common subdirectories: flag/includes and flag_new/includes Common subdirectories: flag/theme and flag_new/theme Common subdirectories: flag/translations and flag_new/translations