isValid($uid)) { global $platal; if (S::has('suid')) { $suid = S::v('suid'); 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'); } /** 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) { $oldSession = $_SESSION; $_SESSION = $newSession; self::$user = null; return $oldSession; } public static function logged() { return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel(); } public static function identified() { 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. public static function has_xsrf_token() { return S::has('xsrf_token') && S::v('xsrf_token') == Env::v('token'); } public static function assert_xsrf_token() { if (!S::has_xsrf_token()) { Platal::page()->kill('L\'opération n\'a pas pu aboutir, merci de réessayer.'); } } 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: ?>