aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/sessions.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-14 19:03:58 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-14 19:03:58 +0000
commit9bd5aad2c3bdb4a283d2b15ed0f91e295099c9e2 (patch)
tree8cf4279f57f654d5435dacba4dc2bcb4030d2199 /engine/lib/sessions.php
parent2d55e88e095aa1a6b4f58101077aab81788761c9 (diff)
downloadelgg-9bd5aad2c3bdb4a283d2b15ed0f91e295099c9e2.tar.gz
elgg-9bd5aad2c3bdb4a283d2b15ed0f91e295099c9e2.tar.bz2
* 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
Diffstat (limited to 'engine/lib/sessions.php')
-rw-r--r--engine/lib/sessions.php48
1 files changed, 39 insertions, 9 deletions
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;