Skip to content
Snippets Groups Projects
Commit b48e80cc authored by Olav Morken's avatar Olav Morken
Browse files

Template: Add [gs]etLanguageCookie functions.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2409 44740490-163a-0410-bde0-09ae8108e29a
parent eebe3940
No related branches found
No related tags found
No related merge requests found
...@@ -75,11 +75,7 @@ class SimpleSAML_XHTML_Template { ...@@ -75,11 +75,7 @@ class SimpleSAML_XHTML_Template {
*/ */
public function setLanguage($language) { public function setLanguage($language) {
$this->language = $language; $this->language = $language;
// setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] ) SimpleSAML_XHTML_Template::setLanguageCookie($language);
// time()+60*60*24*900 expires 900 days from now.
if (!headers_sent()) {
setcookie('language', $language, time()+60*60*24*900, '/');
}
} }
/** /**
...@@ -97,9 +93,10 @@ class SimpleSAML_XHTML_Template { ...@@ -97,9 +93,10 @@ class SimpleSAML_XHTML_Template {
} }
// Language is provided in a stored COOKIE // Language is provided in a stored COOKIE
if (isset($_COOKIE['language'])) { $languageCookie = SimpleSAML_XHTML_Template::getLanguageCookie();
$this->language = $_COOKIE['language']; if ($languageCookie !== NULL) {
return $this->language; $this->language = $languageCookie;
return $languageCookie;
} }
if ($checkHTTP) { if ($checkHTTP) {
...@@ -608,6 +605,35 @@ class SimpleSAML_XHTML_Template { ...@@ -608,6 +605,35 @@ class SimpleSAML_XHTML_Template {
throw new Exception($error); throw new Exception($error);
} }
/**
* Retrieve the user-selected language from a cookie.
*
* @return string|NULL The language, or NULL if unset.
*/
public static function getLanguageCookie() {
if (!isset($_COOKIE['language'])) {
return NULL;
}
return (string)$_COOKIE['language'];
}
/**
* Set the user-selected language in a cookie.
*
* @param string $language The language.
*/
public static function setLanguageCookie($language) {
assert('is_string($language)');
if (headers_sent()) {
return;
}
setcookie('language', $language, time()+60*60*24*900, '/');
}
} }
?> ?>
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