diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 4900528d3..002a70af5 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -17,10 +17,15 @@ class FreshRSS extends Minz_FrontController { } private function initConfiguration() { + $configuration_setter = new FreshRSS_ConfigurationSetter(); $current_user = Minz_Session::param('currentUser', '_'); + Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php'), - join_path(USERS_PATH, '_', 'config.default.php')); + join_path(USERS_PATH, '_', 'config.default.php'), + $configuration_setter); + $system_conf = Minz_Configuration::get('system'); + $system_conf->_configurationSetter($configuration_setter); } private function initAuth() { diff --git a/app/Models/ConfigurationSetter.php b/app/Models/ConfigurationSetter.php new file mode 100644 index 000000000..e30cb0187 --- /dev/null +++ b/app/Models/ConfigurationSetter.php @@ -0,0 +1,37 @@ + '_language', + 'posts_per_page' => '_posts_per_page', + 'view_mode' => '_view_mode', + ); + + public function handle($key, $value) { + if (isset($this->setters[$key])) { + $value = call_user_func(array($this, $this->setters[$key]), $value); + } + return $value; + } + + private function _language($value) { + $languages = Minz_Translate::availableLanguages(); + if (!isset($languages[$value])) { + $value = 'en'; + } + + return $value; + } + + private function _posts_per_page($value) { + $value = intval($value); + return $value > 0 ? $value : 10; + } + + private function _view_mode($value) { + if (!in_array($value, array('global', 'normal', 'reader'))) { + $value = 'normal'; + } + return $value; + } +}