X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fs.php;h=9f71872ea3e172e113f30c92536f04462e7c6547;hb=501a6db205b3355bd9e15de6eac20ca033835201;hp=7ba3b24776e593446c436aa769272ddf4a008f21;hpb=ba63661ce2f38974002c7e4113320e9d06010853;p=platal.git diff --git a/classes/s.php b/classes/s.php index 7ba3b24..9f71872 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'])); + S::set('log', $platal->buildLogger(S::i('uid', $uid), $suid['uid'])); } else if (S::has('uid') || $uid) { - S::set('log', new PlLogger(S::v('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() - { - return Platal::session()->checkPerms(PERMS_ADMIN); + /** 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() + { + if (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 logged() { - return S::v('auth', AUTH_PUBLIC) > AUTH_PUBLIC; + return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel(); } public static function identified() { - return S::v('auth', AUTH_PUBLIC) >= Platal::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. @@ -113,8 +171,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'); } }