From 9bd5aad2c3bdb4a283d2b15ed0f91e295099c9e2 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 14 Nov 2008 19:03:58 +0000 Subject: * Introducing get_loggedin_user() and get_loggedin_userid() * ACLs now using get_loggedin_user* * Some logic cleaned up * Some "Undefined..." messages cleaned up git-svn-id: https://code.elgg.org/elgg/trunk@2459 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/sessions.php | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) (limited to 'engine/lib/sessions.php') diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index b7d0ce90f..dda4e960a 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -87,21 +87,50 @@ if ($this->offsetGet($offset)) return true; } } + + + /** + * Return the current logged in user, or null if no user is logged in. + * + * If no user can be found in the current session, a plugin hook - 'session:get' 'user' to give plugin + * authors another way to provide user details to the ACL system without touching the session. + */ + function get_loggedin_user() + { + global $SESSION; + + return $SESSION['user']; + } + + /** + * Return the current logged in user by id. + * + * @see get_loggedin_user() + * @return int + */ + function get_loggedin_userid() + { + $user = get_loggedin_user(); + if ($user) + return $user->guid; + + return 0; + } /** * Returns whether or not the user is currently logged in * - * @uses $_SESSION * @return true|false */ function isloggedin() { + + if (!is_installed()) return false; - global $SESSION; + $user = get_loggedin_user(); - if (!is_installed()) return false; - if ((isset($SESSION['guid'])) && ($SESSION['guid'] > 0) && (isset($SESSION['id'])) && ($SESSION['id'] > 0) ) - - return true; + if ((isset($user)) && ($user->guid > 0)) + return true; + return false; } @@ -109,15 +138,16 @@ /** * Returns whether or not the user is currently logged in and that they are an admin user. * - * @uses $_SESSION * @uses isloggedin() * @return true|false */ function isadminloggedin() { - global $SESSION; + if (!is_installed()) return false; + + $user = get_loggedin_user(); - if ((isloggedin()) && (($SESSION['user']->admin || $SESSION['user']->siteadmin))) + if ((isloggedin()) && (($user->admin || $user->siteadmin))) return true; return false; -- cgit v1.2.3