* add global helper config($key) function + twig binding

This commit is contained in:
slawkens 2018-05-29 20:29:18 +02:00
parent b828b8e44a
commit de36cfd2eb
2 changed files with 18 additions and 6 deletions

View File

@ -948,16 +948,14 @@ function get_browser_real_ip() {
return '0'; return '0';
} }
function setSession($key, $data) { function setSession($key, $data) {
global $config; $_SESSION[config('session_prefix') . $key] = $data;
$_SESSION[$config['session_prefix'] . $key] = $data;
} }
function getSession($key) { function getSession($key) {
global $config; $key = config('session_prefix') . $key;
return (isset($_SESSION[$config['session_prefix'] . $key])) ? $_SESSION[$config['session_prefix'] . $key] : false; return isset($_SESSION[$key]) ? $_SESSION[$key] : false;
} }
function unsetSession($key) { function unsetSession($key) {
global $config; unset($_SESSION[config('session_prefix') . $key]);
unset($_SESSION[$config['session_prefix'] . $key]);
} }
function getTopPlayers($limit = 5) { function getTopPlayers($limit = 5) {
@ -1026,6 +1024,15 @@ function deleteDirectory($dir) {
return rmdir($dir); return rmdir($dir);
} }
function config($key) {
global $config;
if (is_array($key)) {
return $config[$key[0]] = $key[1];
}
return $config[$key];
}
// validator functions // validator functions
require_once LIBS . 'validator.php'; require_once LIBS . 'validator.php';
require_once SYSTEM . 'compat.php'; require_once SYSTEM . 'compat.php';

View File

@ -26,6 +26,11 @@ $function = new Twig_SimpleFunction('hook', function ($hook) {
}); });
$twig->addFunction($function); $twig->addFunction($function);
$function = new Twig_SimpleFunction('config', function ($key) {
return config($key);
});
$twig->addFunction($function);
$filter = new Twig_SimpleFilter('urlencode', function ($s) { $filter = new Twig_SimpleFilter('urlencode', function ($s) {
return urlencode($s); return urlencode($s);
}); });