flag.module | 35 ++++++++++++++++------------------- includes/flag/flag_flag.inc | 2 +- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/flag.module b/flag.module index 3881f60..10f6107 100644 --- a/flag.module +++ b/flag.module @@ -2284,29 +2284,29 @@ function flag_check_token($token, $entity_id) { * @see flag_get_sid() */ function flag_set_sid($uid = NULL, $create = TRUE) { - $sids = &drupal_static(__FUNCTION__, array()); - if (!isset($uid)) { $uid = $GLOBALS['user']->uid; } + // Return 0 for registered users or when Session API is not available. + if ($uid || !module_exists('session_api') || !session_api_available()) { + return 0; + } + + $sid = &drupal_static(__FUNCTION__); + // Set the sid if none has been set yet. If the caller specified to create an // sid and we have an invalid one (-1), create it. - if (!isset($sids[$uid]) || ($sids[$uid] == -1 && $create)) { - if (module_exists('session_api') && session_api_available() && $uid == 0) { - // This returns one of the following: - // - -1. This indicates that no session exists and none was created. - // - A positive integer with the Session ID when it does exist. - $sids[$uid] = session_api_get_sid($create); - } - else { - $sids[$uid] = 0; - } + if (!isset($sid) || ($sid == -1 && $create)) { + // This returns one of the following: + // - -1. This indicates that no session exists and none was created. + // - A positive integer with the Session ID when it does exist. + $sid = session_api_get_sid($create); } // Keep the -1 case internal and let the outside world only distinguish two // cases: (1) there is an SID; (2) there is no SID (-> 0). - return $sids[$uid] == -1 ? 0 : $sids[$uid]; + return $sid == -1 ? 0 : $sid; } /** @@ -2318,17 +2318,14 @@ function flag_set_sid($uid = NULL, $create = TRUE) { * @param int $uid * (optional) The user ID to return the session ID for. Defaults to the * current user. - * @param bool $create - * (optional) Determines whether a session should be created if it doesn't - * exist yet. Defaults to FALSE. * * @return * The session ID, if the session exists. If not, the return value is 0. * * @see flag_set_sid() */ -function flag_get_sid($uid = NULL, $create = FALSE) { - return flag_set_sid($uid, $create); +function flag_get_sid($uid = NULL) { + return flag_set_sid($uid, FALSE); } // --------------------------------------------------------------------------- @@ -2508,6 +2505,6 @@ function flag_properties_get_flagging_users($entity, array $options, $name, $ent * @ingroup callbacks */ function flag_properties_get_user_sid($entity, array $options, $name, $entity_type, $property_info) { - $sid = flag_get_sid($entity->uid, FALSE); + $sid = flag_get_sid($entity->uid); return $sid; } diff --git a/includes/flag/flag_flag.inc b/includes/flag/flag_flag.inc index 071b148..74492e7 100644 --- a/includes/flag/flag_flag.inc +++ b/includes/flag/flag_flag.inc @@ -726,7 +726,7 @@ class flag_flag { $sid = 0; } else { - $sid = flag_get_sid($uid, TRUE); + $sid = flag_set_sid($uid); // Anonymous users must always have a session id. if ($sid == 0 && $account->uid == 0) { $this->errors['session'] = t('Internal error: You are anonymous but you have no session ID.');