X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fenv.php;h=abfea489b10c313a93e94f5472f25596e2b8d269;hb=9007d4955f2487e82c0f9f4059e1f6b450bdb528;hp=1d4b7379d9b72db0a1facb08d812ba2a9477750f;hpb=ae0832b8464b182ce1fe87c05f3a538a0bb4a8c5;p=platal.git diff --git a/classes/env.php b/classes/env.php index 1d4b737..abfea48 100644 --- a/classes/env.php +++ b/classes/env.php @@ -1,6 +1,6 @@ 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); } + public static function s($key, $default = '') + { + return (string)Cookie::_get($key, $default); + } + + public static function t($key, $default = '') + { + return trim(Cookie::s($key, $default)); + } + + public static function blank($key, $strict = false) + { + if (!Cookie::has($key)) { + return true; + } + $var = $strict ? Cookie::s($key) : Cookie::t($key); + return empty($var); + } + public static function b($key, $default = false) { return (bool)Cookie::_get($key, $default); @@ -150,8 +294,13 @@ class Cookie public static function i($key, $default = 0) { - $i = Cookie::_get($key, $default); - return is_numeric($i) ? intval($i) : $default; + $i = to_integer(Cookie::_get($key, $default)); + return $i === false ? $default : $i; + } + + public static function l(array $keys) + { + return array_map(array('Cookie', 'v'), $keys); } } @@ -162,13 +311,6 @@ function fix_gpc_magic(&$item, $key) { $item = stripslashes($item); } } -function fix_encoding(&$item, $key) { - if (is_array($item)) { - array_walk($item, 'fix_encoding'); - } elseif (preg_match('/[\x80-\x9f]/', $item)) { - $item = iconv('CP1252', 'ISO-8859-15//TRANSLIT', $item); - } -} if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { array_walk($_GET, 'fix_gpc_magic'); @@ -176,7 +318,6 @@ if (ini_get('magic_quotes_gpc') && empty($DONT_FIX_GPC)) { array_walk($_COOKIE, 'fix_gpc_magic'); array_walk($_REQUEST, 'fix_gpc_magic'); } -array_walk($_POST, 'fix_encoding'); -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>