Release plat/al core v1.1.13
[platal.git] / classes / s.php
index 9f71872..e741e8a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 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 = '')
@@ -117,9 +117,9 @@ 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')) {
+        if (($forceFetch || self::$user == null) && class_exists('User')) {
             if (S::has('user') && S::v('user') instanceof User) {
                 self::$user = S::v('user');
             } else {
@@ -129,6 +129,14 @@ class S
         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();
@@ -183,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:
 ?>