X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fs.php;h=456736ff3abf1abf692baad597aaf5e171ce33be;hb=88541046480799a8d92eba186f22e22c0c64efb0;hp=700fdf6f279491989700ec3fb6a4e0dc83802ee7;hpb=c0799142273fa2dc68697e71e156aaed1fef4d6e;p=platal.git diff --git a/classes/s.php b/classes/s.php index 700fdf6..456736f 100644 --- a/classes/s.php +++ b/classes/s.php @@ -1,6 +1,6 @@ isValid($uid)) { + global $platal; if (S::has('suid')) { $suid = S::v('suid'); - S::set('log', new PlLogger(S::v('uid'), $suid['uid'])); - } else if (S::has('suid')) { - S::set('log', new PlLogger(S::v('uid', $uid))); + S::set('log', $platal->buildLogger(S::i('uid', $uid), $suid['uid'])); + } else if (S::has('uid') || $uid) { + S::set('log', $platal->buildLogger(S::i('uid', $uid))); + } else { + S::set('log', PlLogger::dummy($uid)); } } return S::v('log'); } - public static function has_perms() + /** User object storage and accessor. The user object (an instance of the + * local subclass of PlUser) is currently stored as a S class variable, and + * not as a session variable, so as to avoid bloating the global on-disk + * session. + * TODO: When all the codebase will use S::user() as the only source for + * user ids, fullname/displayname, and forlife/bestalias, S::$user should + * move into the php session (and data it helds should be removed from + * the php session). */ + private static $user = null; + public static function &user($forceFetch = false) + { + if (($forceFetch || self::$user == null) && class_exists('User')) { + if (S::has('user') && S::v('user') instanceof User) { + self::$user = S::v('user'); + } else { + self::$user = User::getSilentWithValues(S::i('uid'), $_SESSION); + } + } + return self::$user; + } + + public static function changeSession(array $newSession) { - global $session; - return $session->checkPerms(PERMS_ADMIN); + $oldSession = $_SESSION; + $_SESSION = $newSession; + self::$user = null; + return $oldSession; } public static function logged() { - return S::v('auth', AUTH_PUBLIC) > AUTH_PUBLIC; + return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel(); } public static function identified() { - global $session; - return S::v('auth', AUTH_PUBLIC) >= $session->sureLevel(); + return S::i('auth', AUTH_PUBLIC) >= Platal::session()->sureLevel(); + } + + public static function admin() + { + return Platal::session()->checkPerms(PERMS_ADMIN); + } + + public static function suid($field = null, $default = null) + { + if (is_null($field)) { + return !S::blank('suid'); + } else { + $suid = S::v('suid', array()); + if (!empty($suid) && isset($suid[$field])) { + return $suid[$field]; + } else { + return $default; + } + } } // Anti-XSRF protections. @@ -115,8 +179,14 @@ class S } } + public static function hasAuthToken() + { + return !S::blank('token'); + } + public static function rssActivated() { + // XXX: Deprecated, to be replaced by S::hasToken() return S::has('core_rss_hash') && S::v('core_rss_hash'); } }