aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/sessions.php
diff options
context:
space:
mode:
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;