From ad92dd7dae35e7205da3172d4ba35ea01da2bc8b Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 20 Oct 2014 18:21:10 +0200 Subject: First draft for Context object. See https://github.com/marienfressinaud/FreshRSS/issues/634 --- app/FreshRSS.php | 40 ++++++++++++++++++++-------------------- app/Models/Context.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 app/Models/Context.php (limited to 'app') diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 6b7a813bf..e1399ad78 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -1,50 +1,50 @@ loadConfiguration(); - $this->loadParamsView(); + if (Minz_Request::isPost() && !is_referer_from_same_domain()) { - //Basic protection against XSRF attacks + // Basic protection against XSRF attacks FreshRSS_Auth::removeAccess(); + $http_referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; Minz_Error::error( 403, - array('error' => array(_t('access_denied') . ' [HTTP_REFERER=' . - htmlspecialchars(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']) . ']')) + array('error' => array( + _t('access_denied'), + ' [HTTP_REFERER=' . htmlspecialchars($http_referer) . ']' + )) ); } + + // Load context and configuration. + // TODO: remove $this->view->conf variable which is contained in context + FreshRSS_Context::init(); + Minz_View::_param('conf', FreshRSS_Context::$conf); + + $this->loadParamsView(); $this->loadStylesAndScripts(); $this->loadNotifications(); $this->loadExtensions(); } - private function loadConfiguration() { - $current_user = Minz_Session::param('currentUser'); - try { - $this->conf = new FreshRSS_Configuration($current_user); - Minz_View::_param('conf', $this->conf); - } catch(Minz_Exception $e) { - Minz_Log::error('Cannot load configuration file of user `' . $current_user . '`'); - die($e->getMessage()); - } - } - private function loadParamsView() { - Minz_Session::_param('language', $this->conf->language); - Minz_Translate::init(); + // TODO: outputs should be different actions. $output = Minz_Request::param('output', ''); if (($output === '') || ($output !== 'normal' && $output !== 'rss' && $output !== 'reader' && $output !== 'global')) { - $output = $this->conf->view_mode; + $output = FreshRSS_Context::$conf->view_mode; Minz_Request::_param('output', $output); } } private function loadStylesAndScripts() { - $theme = FreshRSS_Themes::load($this->conf->theme); + $theme = FreshRSS_Themes::load(FreshRSS_Context::$conf->theme); if ($theme) { foreach($theme['files'] as $file) { if ($file[0] === '_') { diff --git a/app/Models/Context.php b/app/Models/Context.php new file mode 100644 index 000000000..d984fece7 --- /dev/null +++ b/app/Models/Context.php @@ -0,0 +1,32 @@ +getMessage()); + } + + // Init i18n. + Minz_Session::_param('language', self::$conf->language); + Minz_Translate::init(); + + // Get the current state. + self::$state = self::$conf->default_view; + } + + public static function stateEnabled($state) { + return self::$state & $state; + } +} -- cgit v1.2.3