From 50b177833c222d41d195398cb48efb476e1ea2ef Mon Sep 17 00:00:00 2001 From: Andjelko Horvat <comel@vingd.com> Date: Mon, 7 Jan 2013 12:39:56 +0000 Subject: [PATCH] SimpleSAML_XHTML_Template: language cookie options (issue #527). git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3216 44740490-163a-0410-bde0-09ae8108e29a --- config-templates/config.php | 8 ++++++++ lib/SimpleSAML/XHTML/Template.php | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/config-templates/config.php b/config-templates/config.php index 64818e625..dc63b94ed 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -277,6 +277,14 @@ $config = array ( 'language.rtl' => array('ar','dv','fa','ur','he'), '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(). * Function should return language code of one of the available languages or NULL. diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index c7db50eb3..b58af7e21 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -669,9 +669,10 @@ class SimpleSAML_XHTML_Template { public static function getLanguageCookie() { $config = SimpleSAML_Configuration::getInstance(); $availableLanguages = $config->getArray('language.available', array('en')); + $name = $config->getString('language.cookie.name', 'language'); - if (isset($_COOKIE['language'])) { - $language = strtolower((string)$_COOKIE['language']); + if (isset($_COOKIE[$name])) { + $language = strtolower((string)$_COOKIE[$name]); if (in_array($language, $availableLanguages, TRUE)) { return $language; } @@ -696,7 +697,19 @@ class SimpleSAML_XHTML_Template { if (!in_array($language, $availableLanguages, TRUE) || headers_sent()) { 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); } } -- GitLab