7ba3b24776e593446c436aa769272ddf4a008f21
2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
24 /** Set a constructor because this is called prior to S::s(), so we can
25 * define S::s() for other usages.
27 private function __construct()
32 public static function has($key)
34 return isset($_SESSION[$key]);
37 public static function kill($key)
39 unset($_SESSION[$key]);
42 public static function v($key, $default = null
)
44 return isset($_SESSION[$key]) ?
$_SESSION[$key] : $default;
47 public static function s($key, $default = '')
49 return (string)S
::v($key, $default);
52 public static function i($key, $default = 0)
54 $i = S
::v($key, $default);
55 return is_numeric($i) ?
intval($i) : $default;
58 public static function l(array $keys)
60 return array_map(array('S', 'v'), $keys);
63 public static function set($key, $value)
65 $_SESSION[$key] =& $value;
68 public static function bootstrap($key, $value)
75 public static function logger($uid = null
)
80 S
::set('log', new PlLogger(S
::v('uid'), $suid['uid']));
81 } else if (S
::has('uid') ||
$uid) {
82 S
::set('log', new PlLogger(S
::v('uid', $uid)));
88 public static function has_perms()
90 return Platal
::session()->checkPerms(PERMS_ADMIN
);
93 public static function logged()
95 return S
::v('auth', AUTH_PUBLIC
) > AUTH_PUBLIC
;
98 public static function identified()
100 return S
::v('auth', AUTH_PUBLIC
) >= Platal
::session()->sureLevel();
103 // Anti-XSRF protections.
104 public static function has_xsrf_token()
106 return S
::has('xsrf_token') && S
::v('xsrf_token') == Env
::v('token');
109 public static function assert_xsrf_token()
111 if (!S
::has_xsrf_token()) {
112 Platal
::page()->kill('L\'opération n\'a pas pu aboutir, merci de réessayer.');
116 public static function rssActivated()
118 return S
::has('core_rss_hash') && S
::v('core_rss_hash');
122 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: