Release plat/al core v1.1.13
[platal.git] / classes / s.php
index 7df67c9..e741e8a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -56,8 +56,8 @@ class S
 
     public static function i($key, $default = 0)
     {
-        $i = S::v($key, $default);
-        return is_numeric($i) ? intval($i) : $default;
+        $i = to_integer(S::v($key, $default));
+        return $i === false ? $default : $i;
     }
 
     public static function t($key, $default = '')
@@ -95,11 +95,12 @@ class S
     {
         $uid = S::i('uid', $uid);
         if (!S::has('log') || !S::v('log')->isValid($uid)) {
+            global $platal;
             if (S::has('suid')) {
                 $suid = S::v('suid');
-                S::set('log', PlLogger::get(S::i('uid', $uid), $suid['uid']));
+                S::set('log', $platal->buildLogger(S::i('uid', $uid), $suid['uid']));
             } else if (S::has('uid') || $uid) {
-                S::set('log', PlLogger::get(S::i('uid', $uid)));
+                S::set('log', $platal->buildLogger(S::i('uid', $uid)));
             } else {
                 S::set('log', PlLogger::dummy($uid));
             }
@@ -116,18 +117,24 @@ class S
      * move into the php session (and data it helds should be removed from
      * the php session). */
     private static $user = null;
-    public static function &user()
+    public static function &user($forceFetch = false)
     {
-        if (self::$user == null && class_exists('User')) {
-            self::$user = User::getSilentWithValues(S::i('uid'), $_SESSION);
+        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 has_perms()
+    public static function changeSession(array $newSession)
     {
-        // XXX: Deprecated, use S::admin() instead
-        return self::admin();
+        $oldSession = $_SESSION;
+        $_SESSION = $newSession;
+        self::$user = null;
+        return $oldSession;
     }
 
     public static function logged()
@@ -184,5 +191,5 @@ class S
     }
 }
 
-// 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:
 ?>