BSFunctions::cookie() no longer depends on static member values for the domain, timeo...
authorRobert Sesek <rsesek@bluestatic.org>
Fri, 1 May 2009 20:55:16 +0000 (16:55 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Fri, 1 May 2009 20:55:16 +0000 (16:55 -0400)
* Functions.php:
(BSFunctions::cookie): Use paramters instead

CHANGES
Functions.php

diff --git a/CHANGES b/CHANGES
index f5afae8fd1f8a79259e66ad2856ff55c4c9b0d9e..41e11614e0a9c2e37991dce16cf1333a865d4722 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+3.3.0
+===================
+- Change: BSFunctions::cookie() does not use static member values, but only parameters
+
 3.2.3
 ===================
 - Change: More BSDecorator styling updates, creating a .button class to style button links
index bb4c2bfbc42770289638f0c005d20d1e45dc9ed0..6b9fdbb19d9e254914ecd1559e9b56c5a25e2cd2 100644 (file)
  */
 class BSFunctions
 {
-       /**
-        * Cookie path
-        * @var string
-        */
-       private static $cookiePath = '/';
-       
-       /**
-        * Cookie domain setting
-        * @var string
-        */
-       private static $cookieDomain = '';
-       
-       /**
-        * Cookie expiration time
-        * @var integer
-        */
-       private static $cookieTimeout = 900;
-       
        /**
         * Current swapped CSS class
         * @var string
@@ -68,63 +50,39 @@ class BSFunctions
        private function __construct()
        {}
        
-       /**
-        * Sets the cookie path
-        *
-        * @param       string  New path
-        */
-       public static function set_cookie_path($path)
-       {
-               self::$cookiePath = $path;
-       }
-       
-       /**
-        * Sets the cookie domain setting
-        *
-        * @param       string  Cookie domain
-        */
-       public static function set_cookie_domain($domain)
-       {
-               self::$cookieDomain = $domain;
-       }
-       
-       /**
-        * Sets the cookie timeout
-        *
-        * @param       integer Cookie timeout
-        */
-       public static function set_cookie_timeout($timeout)
-       {
-               self::$cookieTimeout = intval($timeout);
-       }
-       
        /**
         * Sets a cookie in the user's computer/browing session
         *
         * @param       string  Name of the cookie
-        * @param       string  Value of the cookie, FALSE to clear
-        * @param       bool    Is the cookie permanent?
+        * @param       string  Value of the cookie
+        * @param       integer Timeout in seconds for non-sticky cookies. Can also be ::COOKIE_EXPIRE or ::COOKIE_STICKY
+        * @param       string  Cookie path
+        * @param       string  Domain
         */
-       public static function cookie($name, $value, $sticky = true)
+       const COOKIE_EXPIRE = -1;
+       const COOKIE_STICKY = -2;
+       
+       public static function cookie($name, $value, $timeout = 900, $path = '/', $domain = '')
        {
                // expire the cookie
-               if ($value === false)
+               if ($timeout == self::COOKIE_EXPIRE)
                {
-                       setcookie($name, $value, time() - (2 * self::$cookieTimeout), self::$cookiePath, self::$cookieDomain);
+                       setcookie($name, $value, time() - 1800, $path, $domain);
                }
                // set the cookie
                else
                {
-                       if ($sticky)
+                       // it's sticky so keep it around for a while
+                       if ($timeout == self::COOKIE_STICKY)
                        {
                                $expire = time() + 60 * 60 * 24 * 365;
                        }
                        else
                        {
-                               $expire = time() + self::$cookieTimeout;
+                               $expire = time() + $timeout;
                        }
                        
-                       setcookie($name, $value, $expire, self::$cookiePath, self::$cookieDomain);
+                       setcookie($name, $value, $expire, $path, $domain);
                }
        }