aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJean-Christophe Saad-Dupuy <saad.dupuy@gmail.com>2013-10-08 13:04:05 +0200
committerJean-Christophe Saad-Dupuy <saad.dupuy@gmail.com>2013-10-08 13:04:05 +0200
commit20f00edd1539b18d4d350da27f338f4743fb38b3 (patch)
treed91fe9786cff14f0b458c7914d854e5902ea2fe4
parent2f3425dff699dee249bd223ad564395e254552f4 (diff)
parent5188585864949d939b083d87dcea1e310d588a30 (diff)
downloadwallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.tar.gz
wallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.tar.zst
wallabag-20f00edd1539b18d4d350da27f338f4743fb38b3.zip
Merge branch 'dev' into emded-dependencies
-rw-r--r--inc/poche/Database.class.php4
-rw-r--r--inc/poche/Poche.class.php77
-rw-r--r--index.php3
-rw-r--r--themes/default/config.twig19
4 files changed, 101 insertions, 2 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 0662581b..5c40b026 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -108,8 +108,8 @@ class Database {
108 public function updatePassword($userId, $password) 108 public function updatePassword($userId, $password)
109 { 109 {
110 $sql_update = "UPDATE users SET password=? WHERE id=?"; 110 $sql_update = "UPDATE users SET password=? WHERE id=?";
111 $params_update = array($password, $id); 111 $params_update = array($password, $userId);
112 $this->updateUserConfig($userId, 'password', $password); 112 $query = $this->executeQuery($sql_update, $params_update);
113 } 113 }
114 114
115 public function updateUserConfig($userId, $key, $value) { 115 public function updateUserConfig($userId, $key, $value) {
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
diff --git a/index.php b/index.php
index 22696c6f..a6459270 100644
--- a/index.php
+++ b/index.php
@@ -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
71elseif (isset($_GET['plainurl']) && !empty($_GET['plainurl'])) { 74elseif (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">