Skip to content
Snippets Groups Projects
Commit 50b17783 authored by Andjelko Horvat's avatar Andjelko Horvat
Browse files

SimpleSAML_XHTML_Template: language cookie options (issue #527).

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3216 44740490-163a-0410-bde0-09ae8108e29a
parent bde9d279
No related branches found
No related tags found
No related merge requests found
...@@ -277,6 +277,14 @@ $config = array ( ...@@ -277,6 +277,14 @@ $config = array (
'language.rtl' => array('ar','dv','fa','ur','he'), 'language.rtl' => array('ar','dv','fa','ur','he'),
'language.default' => 'en', 'language.default' => 'en',
/*
* Options to override the default settings for the language cookie
*/
'language.cookie.name' => 'language',
'language.cookie.domain' => NULL,
'language.cookie.path' => '/',
'language.cookie.lifetime' => (60*60*24*900),
/** /**
* Custom getLanguage function called from SimpleSAML_XHTML_Template::getLanguage(). * Custom getLanguage function called from SimpleSAML_XHTML_Template::getLanguage().
* Function should return language code of one of the available languages or NULL. * Function should return language code of one of the available languages or NULL.
......
...@@ -669,9 +669,10 @@ class SimpleSAML_XHTML_Template { ...@@ -669,9 +669,10 @@ class SimpleSAML_XHTML_Template {
public static function getLanguageCookie() { public static function getLanguageCookie() {
$config = SimpleSAML_Configuration::getInstance(); $config = SimpleSAML_Configuration::getInstance();
$availableLanguages = $config->getArray('language.available', array('en')); $availableLanguages = $config->getArray('language.available', array('en'));
$name = $config->getString('language.cookie.name', 'language');
if (isset($_COOKIE['language'])) { if (isset($_COOKIE[$name])) {
$language = strtolower((string)$_COOKIE['language']); $language = strtolower((string)$_COOKIE[$name]);
if (in_array($language, $availableLanguages, TRUE)) { if (in_array($language, $availableLanguages, TRUE)) {
return $language; return $language;
} }
...@@ -696,7 +697,19 @@ class SimpleSAML_XHTML_Template { ...@@ -696,7 +697,19 @@ class SimpleSAML_XHTML_Template {
if (!in_array($language, $availableLanguages, TRUE) || headers_sent()) { if (!in_array($language, $availableLanguages, TRUE) || headers_sent()) {
return; return;
} }
setcookie('language', $language, time()+60*60*24*900, '/');
$name = $config->getString('language.cookie.name', 'language');
$domain = $config->getString('language.cookie.domain', NULL);
$path = $config->getString('language.cookie.path', '/');
$lifetime = $config->getInteger('language.cookie.lifetime', 60*60*24*900);
if ($lifetime === 0) {
$expire = 0;
} else {
$expire = time() + $lifetime;
}
setcookie($name, $language, $expire, $path, $domain);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment