2010.
[platal.git] / classes / s.php
index ff29982..0ee548e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -60,6 +60,20 @@ class S
         return is_numeric($i) ? intval($i) : $default;
     }
 
+    public static function t($key, $default = '')
+    {
+        return trim(S::s($key, $default));
+    }
+
+    public static function blank($key, $strict = false)
+    {
+        if (!S::has($key)) {
+            return true;
+        }
+        $var = $strict ? S::s($key) : S::t($key);
+        return empty($var);
+    }
+
     public static function l(array $keys)
     {
         return array_map(array('S', 'v'), $keys);
@@ -110,11 +124,6 @@ class S
         return self::$user;
     }
 
-    public static function has_perms()
-    {
-        return Platal::session()->checkPerms(PERMS_ADMIN);
-    }
-
     public static function logged()
     {
         return S::i('auth', AUTH_PUBLIC) >= Platal::session()->loggedLevel();
@@ -125,6 +134,25 @@ class S
         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()
     {
@@ -138,8 +166,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');
     }
 }