X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fs.php;h=e741e8a6dbc428abb702bace60d668c7c627ee3d;hb=fa7ffd661d77b24cdb385aca7bdb04c938214061;hp=7ba3b24776e593446c436aa769272ddf4a008f21;hpb=732e5855cffcd5e2eaaf5bd66760c4432d437244;p=platal.git diff --git a/classes/s.php b/classes/s.php index 7ba3b24..e741e8a 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() + /** 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) { - return Platal::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() { - 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,11 +179,17 @@ 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'); } } -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>