diff options
-rw-r--r-- | inc/poche/Poche.class.php | 77 | ||||
-rw-r--r-- | index.php | 3 | ||||
-rw-r--r-- | themes/default/config.twig | 19 |
3 files changed, 99 insertions, 0 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 245f6a13..5299e374 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -20,6 +20,7 @@ class Poche | |||
20 | public $pagination; | 20 | public $pagination; |
21 | 21 | ||
22 | private $currentTheme = ''; | 22 | private $currentTheme = ''; |
23 | private $currentLanguage = ''; | ||
23 | private $notInstalledMessage = array(); | 24 | private $notInstalledMessage = array(); |
24 | 25 | ||
25 | # @todo make this dynamic (actually install themes and save them in the database including author information et cetera) | 26 | # @todo make this dynamic (actually install themes and save them in the database including author information et cetera) |
@@ -83,6 +84,15 @@ class Poche | |||
83 | } | 84 | } |
84 | 85 | ||
85 | $this->currentTheme = $themeDirectory; | 86 | $this->currentTheme = $themeDirectory; |
87 | |||
88 | # Set up language | ||
89 | $languageDirectory = $this->user->getConfigValue('language'); | ||
90 | |||
91 | if ($languageDirectory === false) { | ||
92 | $languageDirectory = DEFAULT_THEME; | ||
93 | } | ||
94 | |||
95 | $this->currentLanguage = $languageDirectory; | ||
86 | } | 96 | } |
87 | 97 | ||
88 | public function configFileIsAvailable() { | 98 | public function configFileIsAvailable() { |
@@ -253,6 +263,10 @@ class Poche | |||
253 | public function getTheme() { | 263 | public function getTheme() { |
254 | return $this->currentTheme; | 264 | return $this->currentTheme; |
255 | } | 265 | } |
266 | |||
267 | public function getLanguage() { | ||
268 | return $this->currentLanguage; | ||
269 | } | ||
256 | 270 | ||
257 | public function getInstalledThemes() { | 271 | public function getInstalledThemes() { |
258 | $handle = opendir(THEME); | 272 | $handle = opendir(THEME); |
@@ -277,6 +291,29 @@ class Poche | |||
277 | return $themes; | 291 | return $themes; |
278 | } | 292 | } |
279 | 293 | ||
294 | public function getInstalledLanguages() { | ||
295 | $handle = opendir(LOCALE); | ||
296 | $languages = array(); | ||
297 | |||
298 | while (($language = readdir($handle)) !== false) { | ||
299 | # Languages are stored in a directory, so all directory names are languages | ||
300 | # @todo move language installation data to database | ||
301 | if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.'))) { | ||
302 | continue; | ||
303 | } | ||
304 | |||
305 | $current = false; | ||
306 | |||
307 | if ($language === $this->getLanguage()) { | ||
308 | $current = true; | ||
309 | } | ||
310 | |||
311 | $languages[] = array('name' => $language, 'current' => $current); | ||
312 | } | ||
313 | |||
314 | return $languages; | ||
315 | } | ||
316 | |||
280 | public function getDefaultConfig() | 317 | public function getDefaultConfig() |
281 | { | 318 | { |
282 | return array( | 319 | return array( |
@@ -369,8 +406,10 @@ class Poche | |||
369 | $compare_dev = version_compare(POCHE, $dev); | 406 | $compare_dev = version_compare(POCHE, $dev); |
370 | $compare_prod = version_compare(POCHE, $prod); | 407 | $compare_prod = version_compare(POCHE, $prod); |
371 | $themes = $this->getInstalledThemes(); | 408 | $themes = $this->getInstalledThemes(); |
409 | $languages = $this->getInstalledLanguages(); | ||
372 | $tpl_vars = array( | 410 | $tpl_vars = array( |
373 | 'themes' => $themes, | 411 | 'themes' => $themes, |
412 | 'languages' => $languages, | ||
374 | 'dev' => $dev, | 413 | 'dev' => $dev, |
375 | 'prod' => $prod, | 414 | 'prod' => $prod, |
376 | 'compare_dev' => $compare_dev, | 415 | 'compare_dev' => $compare_dev, |
@@ -495,6 +534,44 @@ class Poche | |||
495 | Tools::redirect('?view=config'); | 534 | Tools::redirect('?view=config'); |
496 | } | 535 | } |
497 | 536 | ||
537 | public function updateLanguage() | ||
538 | { | ||
539 | # no data | ||
540 | if (empty($_POST['language'])) { | ||
541 | } | ||
542 | |||
543 | # we are not going to change it to the current language... | ||
544 | if ($_POST['language'] == $this->getLanguage()) { | ||
545 | $this->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!')); | ||
546 | Tools::redirect('?view=config'); | ||
547 | } | ||
548 | |||
549 | $languages = $this->getInstalledLanguages(); | ||
550 | $actualLanguage = false; | ||
551 | |||
552 | foreach ($languages as $language) { | ||
553 | if ($language['name'] == $_POST['language']) { | ||
554 | $actualLanguage = true; | ||
555 | break; | ||
556 | } | ||
557 | } | ||
558 | |||
559 | if (! $actualLanguage) { | ||
560 | $this->messages->add('e', _('that language does not seem to be installed')); | ||
561 | Tools::redirect('?view=config'); | ||
562 | } | ||
563 | |||
564 | $this->store->updateUserConfig($this->user->getId(), 'language', $_POST['language']); | ||
565 | $this->messages->add('s', _('you have changed your language preferences')); | ||
566 | |||
567 | $currentConfig = $_SESSION['poche_user']->config; | ||
568 | $currentConfig['language'] = $_POST['language']; | ||
569 | |||
570 | $_SESSION['poche_user']->setConfig($currentConfig); | ||
571 | |||
572 | Tools::redirect('?view=config'); | ||
573 | } | ||
574 | |||
498 | /** | 575 | /** |
499 | * checks if login & password are correct and save the user in session. | 576 | * checks if login & password are correct and save the user in session. |
500 | * it redirects the user to the $referer link | 577 | * it redirects the user to the $referer link |
@@ -67,7 +67,10 @@ if (isset($_GET['login'])) { | |||
67 | $poche->export(); | 67 | $poche->export(); |
68 | } elseif (isset($_GET['updatetheme'])) { | 68 | } elseif (isset($_GET['updatetheme'])) { |
69 | $poche->updateTheme(); | 69 | $poche->updateTheme(); |
70 | } elseif (isset($_GET['updatelanguage'])) { | ||
71 | $poche->updateLanguage(); | ||
70 | } | 72 | } |
73 | |||
71 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { | 74 | elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { |
72 | $plain_url = new Url(base64_encode($_GET['plainurl'])); | 75 | $plain_url = new Url(base64_encode($_GET['plainurl'])); |
73 | $poche->action('add', $plain_url); | 76 | $poche->action('add', $plain_url); |
diff --git a/themes/default/config.twig b/themes/default/config.twig index 13bdaafd..23860ebd 100644 --- a/themes/default/config.twig +++ b/themes/default/config.twig | |||
@@ -47,6 +47,25 @@ | |||
47 | <input type="hidden" name="token" value="{{ token }}"> | 47 | <input type="hidden" name="token" value="{{ token }}"> |
48 | </form> | 48 | </form> |
49 | 49 | ||
50 | <h2>{% trans "Change your language" %}</h2> | ||
51 | <form method="post" action="?updatelanguage" name="changelanguageform"> | ||
52 | <fieldset class="w500p"> | ||
53 | <div class="row"> | ||
54 | <label class="col w150p" for="language">{% trans "Language:" %}</label> | ||
55 | <select class="col" id="language" name="language"> | ||
56 | {% for language in languages %} | ||
57 | <option value="{{ language.name }}" {{ language.current ? 'selected' : '' }}>{{ language.name }}</option> | ||
58 | {% endfor %} | ||
59 | </select> | ||
60 | </div> | ||
61 | <div class="row mts txtcenter"> | ||
62 | <button class="bouton" type="submit" tabindex="4">{% trans "Update" %}</button> | ||
63 | </div> | ||
64 | </fieldset> | ||
65 | <input type="hidden" name="returnurl" value="{{ referer }}"> | ||
66 | <input type="hidden" name="token" value="{{ token }}"> | ||
67 | </form> | ||
68 | |||
50 | <h2>{% trans "Change your password" %}</h2> | 69 | <h2>{% trans "Change your password" %}</h2> |
51 | <form method="post" action="?config" name="loginform"> | 70 | <form method="post" action="?config" name="loginform"> |
52 | <fieldset class="w500p"> | 71 | <fieldset class="w500p"> |