4
0
Эх сурвалжийг харах

BREAKING FEATURE: Remove general in config

General attribute has been removed from system config.
Now subattributes (e.g. environment, salt, title, etc.) are directly accessible.

YOU HAVE TO FIX YOUR ./data/config.php file!

- Remove the general array
- Values inside this array must be kept
- To see what it must look like, please have a look to ./data/config.default.php
  (but keep your values!!).

See https://github.com/FreshRSS/FreshRSS/issues/730
Marien Fressinaud 11 жил өмнө
parent
commit
d3a93ea290

+ 13 - 15
app/Controllers/authController.php

@@ -27,7 +27,6 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
 		if (Minz_Request::isPost()) {
 			$ok = true;
 
-			$general = FreshRSS_Context::$system_conf->general;
 			$current_token = FreshRSS_Context::$user_conf->token;
 			$token = Minz_Request::param('token', $current_token);
 			FreshRSS_Context::$user_conf->_token($token);
@@ -40,20 +39,19 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
 			$auth_type = Minz_Request::param('auth_type', 'none');
 			$unsafe_autologin = Minz_Request::param('unsafe_autologin', false);
 			$api_enabled = Minz_Request::param('api_enabled', false);
-			if ($anon != $general['allow_anonymous'] ||
-				$auth_type != $general['auth_type'] ||
-				$anon_refresh != $general['allow_anonymous_refresh'] ||
-				$unsafe_autologin != $general['unsafe_autologin_enabled'] ||
-				$api_enabled != $general['api_enabled']) {
+			if ($anon != FreshRSS_Context::$system_conf->allow_anonymous ||
+				$auth_type != FreshRSS_Context::$system_conf->auth_type ||
+				$anon_refresh != FreshRSS_Context::$system_conf->allow_anonymous_refresh ||
+				$unsafe_autologin != FreshRSS_Context::$system_conf->unsafe_autologin_enabled ||
+				$api_enabled != FreshRSS_Context::$system_conf->api_enabled) {
 
 				// TODO: test values from form
-				$general['auth_type'] = $auth_type;
-				$general['allow_anonymous'] = $anon;
-				$general['allow_anonymous_refresh'] = $anon_refresh;
-				$general['unsafe_autologin_enabled'] = $unsafe_autologin;
-				$general['api_enabled'] = $api_enabled;
+				FreshRSS_Context::$system_conf->auth_type = $auth_type;
+				FreshRSS_Context::$system_conf->allow_anonymous = $anon;
+				FreshRSS_Context::$system_conf->allow_anonymous_refresh = $anon_refresh;
+				FreshRSS_Context::$system_conf->unsafe_autologin_enabled = $unsafe_autologin;
+				FreshRSS_Context::$system_conf->api_enabled = $api_enabled;
 
-				$system_conf->general = $general;
 				$ok &= $system_conf->save();
 			}
 
@@ -80,7 +78,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
 			Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
 		}
 
-		$auth_type = FreshRSS_Context::$system_conf->general['auth_type'];
+		$auth_type = FreshRSS_Context::$system_conf->auth_type;
 		switch ($auth_type) {
 		case 'form':
 			Minz_Request::forward(array('c' => 'auth', 'a' => 'formLogin'));
@@ -160,7 +158,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
 				Minz_Request::bad(_t('feedback.auth.login.invalid'),
 				                  array('c' => 'auth', 'a' => 'login'));
 			}
-		} elseif (FreshRSS_Context::$system_conf->general['unsafe_autologin_enabled']) {
+		} elseif (FreshRSS_Context::$system_conf->unsafe_autologin_enabled) {
 			$username = Minz_Request::param('u', '');
 			$password = Minz_Request::param('p', '');
 			Minz_Request::_param('p');
@@ -301,7 +299,7 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
 
 		$this->view->no_form = false;
 		// Enable changement of auth only if Persona!
-		if (FreshRSS_Context::$system_conf->general['auth_type'] != 'persona') {
+		if (FreshRSS_Context::$system_conf->auth_type != 'persona') {
 			$this->view->message = array(
 				'status' => 'bad',
 				'title' => _t('gen.short.damn'),

+ 1 - 1
app/Controllers/feedController.php

@@ -18,7 +18,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 			$token_param = Minz_Request::param('token', '');
 			$token_is_ok = ($token != '' && $token == $token_param);
 			$action = Minz_Request::actionName();
-			$allow_anonymous_refresh = FreshRSS_Context::$system_conf->general['allow_anonymous_refresh'];
+			$allow_anonymous_refresh = FreshRSS_Context::$system_conf->allow_anonymous_refresh;
 			if ($action !== 'actualize' ||
 					!($allow_anonymous_refresh || $token_is_ok)) {
 				Minz_Error::error(403);

+ 3 - 3
app/Controllers/indexController.php

@@ -20,7 +20,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 	 * This action displays the normal view of FreshRSS.
 	 */
 	public function normalAction() {
-		$allow_anonymous = FreshRSS_Context::$system_conf->general['allow_anonymous'];
+		$allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;
 		if (!FreshRSS_Auth::hasAccess() && !$allow_anonymous) {
 			Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
 			return;
@@ -83,7 +83,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 	 * This action displays the global view of FreshRSS.
 	 */
 	public function globalAction() {
-		$allow_anonymous = FreshRSS_Context::$system_conf->general['allow_anonymous'];
+		$allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;
 		if (!FreshRSS_Auth::hasAccess() && !$allow_anonymous) {
 			Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
 			return;
@@ -111,7 +111,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 	 * This action displays the RSS feed of FreshRSS.
 	 */
 	public function rssAction() {
-		$allow_anonymous = FreshRSS_Context::$system_conf->general['allow_anonymous'];
+		$allow_anonymous = FreshRSS_Context::$system_conf->allow_anonymous;
 		$token = FreshRSS_Context::$user_conf->token;
 		$token_param = Minz_Request::param('token', '');
 		$token_is_ok = ($token != '' && $token === $token_param);

+ 1 - 1
app/Controllers/javascriptController.php

@@ -28,7 +28,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController {
 		$user = isset($_GET['user']) ? $_GET['user'] : '';
 		if (ctype_alnum($user)) {
 			try {
-				$salt = FreshRSS_Context::$system_conf->general['salt'];
+				$salt = FreshRSS_Context::$system_conf->salt;
 				$conf = new FreshRSS_Configuration($user);
 				$s = $conf->passwordHash;
 				if (strlen($s) >= 60) {

+ 2 - 2
app/Controllers/userController.php

@@ -118,7 +118,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 			$ok = ($new_user_name != '') && ctype_alnum($new_user_name);
 
 			if ($ok) {
-				$default_user = FreshRSS_Context::$system_conf->general['default_user'];
+				$default_user = FreshRSS_Context::$system_conf->default_user;
 				$ok &= (strcasecmp($new_user_name, $default_user) !== 0);	//It is forbidden to alter the default user
 
 				$ok &= !in_array(strtoupper($new_user_name), array_map('strtoupper', listUsers()));	//Not an existing user, case-insensitive
@@ -188,7 +188,7 @@ class FreshRSS_user_Controller extends Minz_ActionController {
 			$user_data = join_path(DATA_PATH, 'users', $username);
 
 			if ($ok) {
-				$default_user = FreshRSS_Context::$system_conf->general['default_user'];
+				$default_user = FreshRSS_Context::$system_conf->default_user;
 				$ok &= (strcasecmp($username, $default_user) !== 0);	//It is forbidden to delete the default user
 			}
 			if ($ok) {

+ 1 - 1
app/FreshRSS.php

@@ -62,7 +62,7 @@ class FreshRSS extends Minz_FrontController {
 		Minz_View::appendScript(Minz_Url::display('/scripts/shortcut.js?' . @filemtime(PUBLIC_PATH . '/scripts/shortcut.js')));
 		Minz_View::appendScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js')));
 
-		if (FreshRSS_Context::$system_conf->general['auth_type'] === 'persona') {
+		if (FreshRSS_Context::$system_conf->auth_type === 'persona') {
 			// TODO move it in a plugin
 			// Needed for login AND logout with Persona.
 			Minz_View::appendScript('https://login.persona.org/include.js');

+ 7 - 7
app/Models/Auth.php

@@ -17,7 +17,7 @@ class FreshRSS_Auth {
 		$current_user = Minz_Session::param('currentUser', '');
 		if ($current_user === '') {
 			$conf = Minz_Configuration::get('system');
-			$current_user = $conf->general['default_user'];
+			$current_user = $conf->default_user;
 			Minz_Session::_param('currentUser', $current_user);
 		}
 
@@ -42,7 +42,7 @@ class FreshRSS_Auth {
 	 */
 	private static function accessControl() {
 		$conf = Minz_Configuration::get('system');
-		$auth_type = $conf->general['auth_type'];
+		$auth_type = $conf->auth_type;
 		switch ($auth_type) {
 		case 'form':
 			$credentials = FreshRSS_FormAuth::getCredentialsFromCookie();
@@ -84,7 +84,7 @@ class FreshRSS_Auth {
 	public static function giveAccess() {
 		$user_conf = Minz_Configuration::get('user');
 		$system_conf = Minz_Configuration::get('system');
-		$auth_type = $system_conf->general['auth_type'];
+		$auth_type = $system_conf->auth_type;
 
 		switch ($auth_type) {
 		case 'form':
@@ -115,7 +115,7 @@ class FreshRSS_Auth {
 	 */
 	public static function hasAccess($scope = 'general') {
 		$conf = Minz_Configuration::get('system');
-		$default_user = $conf->general['default_user'];
+		$default_user = $conf->default_user;
 		$ok = self::$login_ok;
 		switch ($scope) {
 		case 'general':
@@ -136,9 +136,9 @@ class FreshRSS_Auth {
 		Minz_Session::_param('loginOk');
 		self::$login_ok = false;
 		$conf = Minz_Configuration::get('system');
-		Minz_Session::_param('currentUser', $conf->general['default_user']);
+		Minz_Session::_param('currentUser', $conf->default_user);
 
-		switch ($conf->general['auth_type']) {
+		switch ($conf->auth_type) {
 		case 'form':
 			Minz_Session::_param('passwordHash');
 			FreshRSS_FormAuth::deleteCookie();
@@ -160,7 +160,7 @@ class FreshRSS_Auth {
 	 */
 	public static function accessNeedLogin() {
 		$conf = Minz_Configuration::get('system');
-		$auth_type = $conf->general['auth_type'];
+		$auth_type = $conf->auth_type;
 		return $auth_type === 'form' || $auth_type === 'persona';
 	}
 }

+ 2 - 2
app/Models/Feed.php

@@ -39,9 +39,9 @@ class FreshRSS_Feed extends Minz_Model {
 	}
 
 	public function hash() {
-		$conf = Minz_Configuration::get('system');
 		if ($this->hash === null) {
-			$this->hash = hash('crc32b', $conf->general['salt'] . $this->url);
+			$salt = FreshRSS_Context::$system_conf->salt;
+			$this->hash = hash('crc32b', $salt . $this->url);
 		}
 		return $this->hash;
 	}

+ 2 - 4
app/layout/header.phtml

@@ -1,7 +1,5 @@
 <?php
 
-$conf = Minz_Configuration::get('system');
-
 if (FreshRSS_Auth::accessNeedLogin()) {
 	?><ul class="nav nav-head nav-login"><?php
 		if (FreshRSS_Auth::hasAccess()) {
@@ -18,13 +16,13 @@ if (FreshRSS_Auth::accessNeedLogin()) {
 		<h1>
 			<a href="<?php echo _url('index', 'index'); ?>">
 				<img class="logo" src="<?php echo _i('icon', true); ?>" alt="⊚" />
-				<?php echo $conf->general['title']; ?>
+				<?php echo FreshRSS_Context::$system_conf->title; ?>
 			</a>
 		</h1>
 	</div>
 
 	<div class="item search">
-		<?php if (FreshRSS_Auth::hasAccess() || $conf->general['allow_anonymous']) { ?>
+		<?php if (FreshRSS_Auth::hasAccess() || FreshRSS_Context::$system_conf->allow_anonymous) { ?>
 		<form action="<?php echo _url('index', 'index'); ?>" method="get">
 			<div class="stick">
 				<?php $search = Minz_Request::param('search', ''); ?>

+ 1 - 1
app/layout/layout.phtml

@@ -35,7 +35,7 @@
 		<link rel="apple-touch-icon" href="<?php echo Minz_Url::display('/themes/icons/apple-touch-icon.png'); ?>">
 		<meta name="apple-mobile-web-app-capable" content="yes" />
 		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
-		<meta name="apple-mobile-web-app-title" content="<?php echo $conf->general['title'] ?>">
+		<meta name="apple-mobile-web-app-title" content="<?php echo FreshRSS_Context::$system_conf->title; ?>">
 		<meta name="msapplication-TileColor" content="#FFF" />
 		<meta name="robots" content="noindex,nofollow" />
 	</head>

+ 1 - 2
app/views/helpers/javascript_vars.phtml

@@ -1,7 +1,6 @@
 "use strict";
 <?php
 
-$conf = Minz_Configuration::get('system');
 $mark = FreshRSS_Context::$user_conf->mark_when;
 $mail = Minz_Session::param('mail', false);
 $auto_actualize = Minz_Session::param('actualize_feeds', false);
@@ -30,7 +29,7 @@ echo 'var context={',
 	'does_lazyload:', FreshRSS_Context::$user_conf->lazyload ? 'true' : 'false', ',',
 	'sticky_post:', FreshRSS_Context::isStickyPostEnabled() ? 'true' : 'false', ',',
 	'html5_notif_timeout:', FreshRSS_Context::$user_conf->html5_notif_timeout, ',',
-	'auth_type:"', $conf->general['auth_type'], '",',
+	'auth_type:"', FreshRSS_Context::$system_conf->auth_type, '",',
 	'current_user_mail:', $mail ? ('"' . $mail . '"') : 'null', ',',
 	'current_view:"', Minz_Request::param('output', 'normal'), '"',
 "},\n";

+ 11 - 13
data/config.default.php

@@ -1,19 +1,17 @@
 <?php
 
 return array(
-	'general' => array(
-		'environment' => 'production',
-		'salt' => '',
-		'base_url' => '',
-		'language' => 'en',
-		'title' => 'FreshRSS',
-		'default_user' => '_',
-		'allow_anonymous' => false,
-		'allow_anonymous_refresh' => false,
-		'auth_type' => 'none',
-		'api_enabled' => false,
-		'unsafe_autologin_enabled' => false,
-	),
+	'environment' => 'production',
+	'salt' => '',
+	'base_url' => '',
+	'language' => 'en',
+	'title' => 'FreshRSS',
+	'default_user' => '_',
+	'allow_anonymous' => false,
+	'allow_anonymous_refresh' => false,
+	'auth_type' => 'none',
+	'api_enabled' => false,
+	'unsafe_autologin_enabled' => false,
 	'limits' => array(
 		'cache_duration' => 800,
 		'timeout' => 10,

+ 1 - 1
lib/Minz/Error.php

@@ -83,7 +83,7 @@ class Minz_Error {
 	 */
 	private static function processLogs ($logs) {
 		$conf = Minz_Configuration::get('system');
-		$env = $conf->general['environment'];
+		$env = $conf->environment;
 		$logs_ok = array ();
 		$error = array ();
 		$warning = array ();

+ 1 - 1
lib/Minz/FrontController.php

@@ -116,7 +116,7 @@ class Minz_FrontController {
 
 	private function setReporting() {
 		$conf = Minz_Configuration::get('system');
-		switch($conf->general['environment']) {
+		switch($conf->environment) {
 		case 'production':
 			error_reporting(E_ALL);
 			ini_set('display_errors','Off');

+ 1 - 1
lib/Minz/Log.php

@@ -33,7 +33,7 @@ class Minz_Log {
 	public static function record ($information, $level, $file_name = null) {
 		try {
 			$conf = Minz_Configuration::get('system');
-			$env = $conf->general['environment'];
+			$env = $conf->environment;
 		} catch (Minz_ConfigurationException $e) {
 			$env = 'production';
 		}

+ 1 - 1
lib/Minz/Request.php

@@ -97,7 +97,7 @@ class Minz_Request {
 	 */
 	public static function getBaseUrl() {
 		$conf = Minz_Configuration::get('system');
-		$defaultBaseUrl = $conf->general['base_url'];
+		$defaultBaseUrl = $conf->base_url;
 		if (!empty($defaultBaseUrl)) {
 			return $defaultBaseUrl;
 		} elseif (isset($_SERVER['REQUEST_URI'])) {

+ 1 - 1
lib/Minz/Translate.php

@@ -29,7 +29,7 @@ class Minz_Translate {
 	 */
 	public static function init() {
 		$conf = Minz_Configuration::get('system');
-		$l = $conf->general['language'];
+		$l = $conf->language;
 		self::$lang_name = Minz_Session::param('language', $l);
 		self::$lang_path = APP_PATH . '/i18n/' . self::$lang_name . '/';
 	}

+ 1 - 1
lib/Minz/View.php

@@ -30,7 +30,7 @@ class Minz_View {
 		                   Minz_Request::actionName());
 
 		$conf = Minz_Configuration::get('system');
-		self::$title = $conf->general['title'];
+		self::$title = $conf->title;
 	}
 
 	/**