Rewrite translations loading, remove useless language cookie

This commit is contained in:
Frederic Guillot 2013-07-06 11:47:20 -04:00
parent a79211d47f
commit 2a67751e84
2 changed files with 12 additions and 21 deletions

View File

@ -26,27 +26,19 @@ Router\before(function($action) {
Response\redirect('?action=login'); Response\redirect('?action=login');
} }
$language = 'en_US'; // Load translations
$language = Model\get_config_value('language') ?: 'en_US';
if (isset($_SESSION['user']['language'])) { if ($language !== 'en_US') PicoTools\Translator\load($language);
$language = $_SESSION['user']['language'];
}
else if (isset($_COOKIE['language'])) {
$language = $_COOKIE['language'];
}
if ($language !== 'en_US') {
PicoTools\Translator\load($language);
}
setcookie('language', $language, time()+365*24*3600, dirname($_SERVER['PHP_SELF']));
// HTTP secure headers
Response\csp(array( Response\csp(array(
'img-src' => '*', 'img-src' => '*',
'frame-src' => 'http://www.youtube.com https://www.youtube.com http://player.vimeo.com https://player.vimeo.com' 'frame-src' => implode(' ', array(
'http://www.youtube.com',
'https://www.youtube.com',
'http://player.vimeo.com',
'https://player.vimeo.com',
))
)); ));
Response\xframe(); Response\xframe();

View File

@ -624,6 +624,7 @@ function validate_config_update(array $values)
function save_config(array $values) function save_config(array $values)
{ {
// Update the password if needed
if (! empty($values['password'])) { if (! empty($values['password'])) {
$values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT); $values['password'] = \password_hash($values['password'], PASSWORD_BCRYPT);
@ -638,9 +639,7 @@ function save_config(array $values)
// Reload configuration in session // Reload configuration in session
$_SESSION['config'] = $values; $_SESSION['config'] = $values;
$_SESSION['user']['language'] = $values['language']; // Reload translations for flash session message
unset($_COOKIE['language']);
\PicoTools\Translator\load($values['language']); \PicoTools\Translator\load($values['language']);
// If the user does not want content of feeds, remove it in previous ones // If the user does not want content of feeds, remove it in previous ones