diff options
author | Jean-Christophe Saad-Dupuy <saad.dupuy@gmail.com> | 2013-10-08 13:04:05 +0200 |
---|---|---|
committer | Jean-Christophe Saad-Dupuy <saad.dupuy@gmail.com> | 2013-10-08 13:04:05 +0200 |
commit | 20f00edd1539b18d4d350da27f338f4743fb38b3 (patch) | |
tree | d91fe9786cff14f0b458c7914d854e5902ea2fe4 /inc/poche/Poche.class.php | |
parent | 2f3425dff699dee249bd223ad564395e254552f4 (diff) | |
parent | 5188585864949d939b083d87dcea1e310d588a30 (diff) | |
download | wallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.tar.gz wallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.tar.zst wallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.zip |
Merge branch 'dev' into emded-dependencies
Diffstat (limited to 'inc/poche/Poche.class.php')
-rw-r--r-- | inc/poche/Poche.class.php | 77 |
1 files changed, 77 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 |