Add an embedded mode for platal.
[platal.git] / classes / env.php
index 61cc6cf..cecee84 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   *
@@ -197,19 +197,36 @@ class Cookie
 {
     public static function _get($key, $default)
     {
+        global $globals;
+        $key = $globals->cookie_ns . $key;
         return isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default;
     }
 
     public static function has($key)
     {
+        global $globals;
+        $key = $globals->cookie_ns . $key;
         return isset($_COOKIE[$key]);
     }
 
     public static function kill($key)
     {
+        global $globals;
+        $key = $globals->cookie_ns . $key;
+        setcookie($key, '', time() - 3600, $globals->cookie_path);
         unset($_COOKIE[$key]);
     }
 
+    public static function set($key, $value, $days, $secure = false) {
+        global $globals;
+        $key = $globals->cookie_ns . $key;
+        if (!$secure || @$_SERVER['HTTPS']) {
+            setcookie($key, $value, time() + 86400 * $days, $globals->cookie_path, '',
+                      $secure, $secure);
+            $_COOKIE[$key] = $value;
+        }
+    }
+
     public static function v($key, $default = null)
     {
         return Cookie::_get($key, $default);