aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/config/ConfigManager.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-07-28 11:07:55 +0200
committerArthurHoaro <arthur@hoa.ro>2018-07-28 11:07:55 +0200
commit83faedadff76c5bdca036f39f13943f63b27e164 (patch)
tree6f44cede16ec6a60f10b9699e211e0818f06d2c8 /application/config/ConfigManager.php
parent1d9eb22a3df85b67fe6652c0876cd7382c2fb525 (diff)
parent658988f3aeba7a5a938783249ccf2765251e5597 (diff)
downloadShaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.gz
Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.zst
Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.zip
Merge tag 'v0.9.7' into stable
Release v0.9.7
Diffstat (limited to 'application/config/ConfigManager.php')
-rw-r--r--application/config/ConfigManager.php73
1 files changed, 28 insertions, 45 deletions
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index f5f753f8..9e4c9f63 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -1,17 +1,16 @@
1<?php 1<?php
2namespace Shaarli\Config;
2 3
3// FIXME! Namespaces... 4use Shaarli\Config\Exception\MissingFieldConfigException;
4require_once 'ConfigIO.php'; 5use Shaarli\Config\Exception\UnauthorizedConfigException;
5require_once 'ConfigJson.php';
6require_once 'ConfigPhp.php';
7 6
8/** 7/**
9 * Class ConfigManager 8 * Class ConfigManager
10 * 9 *
11 * Manages all Shaarli's settings. 10 * Manages all Shaarli's settings.
12 * See the documentation for more information on settings: 11 * See the documentation for more information on settings:
13 * - doc/Shaarli-configuration.html 12 * - doc/md/Shaarli-configuration.md
14 * - https://github.com/shaarli/Shaarli/wiki/Shaarli-configuration 13 * - https://shaarli.readthedocs.io/en/master/Shaarli-configuration/#configuration
15 */ 14 */
16class ConfigManager 15class ConfigManager
17{ 16{
@@ -20,6 +19,8 @@ class ConfigManager
20 */ 19 */
21 protected static $NOT_FOUND = 'NOT_FOUND'; 20 protected static $NOT_FOUND = 'NOT_FOUND';
22 21
22 public static $DEFAULT_PLUGINS = array('qrcode');
23
23 /** 24 /**
24 * @var string Config folder. 25 * @var string Config folder.
25 */ 26 */
@@ -80,7 +81,11 @@ class ConfigManager
80 */ 81 */
81 protected function load() 82 protected function load()
82 { 83 {
83 $this->loadedConfig = $this->configIO->read($this->getConfigFileExt()); 84 try {
85 $this->loadedConfig = $this->configIO->read($this->getConfigFileExt());
86 } catch (\Exception $e) {
87 die($e->getMessage());
88 }
84 $this->setDefaultValues(); 89 $this->setDefaultValues();
85 } 90 }
86 91
@@ -122,12 +127,12 @@ class ConfigManager
122 * @param bool $write Write the new setting in the config file, default false. 127 * @param bool $write Write the new setting in the config file, default false.
123 * @param bool $isLoggedIn User login state, default false. 128 * @param bool $isLoggedIn User login state, default false.
124 * 129 *
125 * @throws Exception Invalid 130 * @throws \Exception Invalid
126 */ 131 */
127 public function set($setting, $value, $write = false, $isLoggedIn = false) 132 public function set($setting, $value, $write = false, $isLoggedIn = false)
128 { 133 {
129 if (empty($setting) || ! is_string($setting)) { 134 if (empty($setting) || ! is_string($setting)) {
130 throw new Exception('Invalid setting key parameter. String expected, got: '. gettype($setting)); 135 throw new \Exception(t('Invalid setting key parameter. String expected, got: '). gettype($setting));
131 } 136 }
132 137
133 // During the ConfigIO transition, map legacy settings to the new ones. 138 // During the ConfigIO transition, map legacy settings to the new ones.
@@ -175,7 +180,7 @@ class ConfigManager
175 * 180 *
176 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf. 181 * @throws MissingFieldConfigException: a mandatory field has not been provided in $conf.
177 * @throws UnauthorizedConfigException: user is not authorize to change configuration. 182 * @throws UnauthorizedConfigException: user is not authorize to change configuration.
178 * @throws IOException: an error occurred while writing the new config file. 183 * @throws \IOException: an error occurred while writing the new config file.
179 */ 184 */
180 public function write($isLoggedIn) 185 public function write($isLoggedIn)
181 { 186 {
@@ -296,7 +301,9 @@ class ConfigManager
296 $this->setEmpty('resource.updates', 'data/updates.txt'); 301 $this->setEmpty('resource.updates', 'data/updates.txt');
297 $this->setEmpty('resource.log', 'data/log.txt'); 302 $this->setEmpty('resource.log', 'data/log.txt');
298 $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); 303 $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt');
304 $this->setEmpty('resource.history', 'data/history.php');
299 $this->setEmpty('resource.raintpl_tpl', 'tpl/'); 305 $this->setEmpty('resource.raintpl_tpl', 'tpl/');
306 $this->setEmpty('resource.theme', 'default');
300 $this->setEmpty('resource.raintpl_tmp', 'tmp/'); 307 $this->setEmpty('resource.raintpl_tmp', 'tmp/');
301 $this->setEmpty('resource.thumbnails_cache', 'cache'); 308 $this->setEmpty('resource.thumbnails_cache', 'cache');
302 $this->setEmpty('resource.page_cache', 'pagecache'); 309 $this->setEmpty('resource.page_cache', 'pagecache');
@@ -305,21 +312,26 @@ class ConfigManager
305 $this->setEmpty('security.ban_duration', 1800); 312 $this->setEmpty('security.ban_duration', 1800);
306 $this->setEmpty('security.session_protection_disabled', false); 313 $this->setEmpty('security.session_protection_disabled', false);
307 $this->setEmpty('security.open_shaarli', false); 314 $this->setEmpty('security.open_shaarli', false);
315 $this->setEmpty('security.allowed_protocols', ['ftp', 'ftps', 'magnet']);
308 316
309 $this->setEmpty('general.header_link', '?'); 317 $this->setEmpty('general.header_link', '?');
310 $this->setEmpty('general.links_per_page', 20); 318 $this->setEmpty('general.links_per_page', 20);
311 $this->setEmpty('general.enabled_plugins', array('qrcode')); 319 $this->setEmpty('general.enabled_plugins', self::$DEFAULT_PLUGINS);
320 $this->setEmpty('general.default_note_title', 'Note: ');
312 321
313 $this->setEmpty('updates.check_updates', false); 322 $this->setEmpty('updates.check_updates', false);
314 $this->setEmpty('updates.check_updates_branch', 'stable'); 323 $this->setEmpty('updates.check_updates_branch', 'stable');
315 $this->setEmpty('updates.check_updates_interval', 86400); 324 $this->setEmpty('updates.check_updates_interval', 86400);
316 325
317 $this->setEmpty('feed.rss_permalinks', true); 326 $this->setEmpty('feed.rss_permalinks', true);
318 $this->setEmpty('feed.show_atom', false); 327 $this->setEmpty('feed.show_atom', true);
319 328
320 $this->setEmpty('privacy.default_private_links', false); 329 $this->setEmpty('privacy.default_private_links', false);
321 $this->setEmpty('privacy.hide_public_links', false); 330 $this->setEmpty('privacy.hide_public_links', false);
331 $this->setEmpty('privacy.force_login', false);
322 $this->setEmpty('privacy.hide_timestamps', false); 332 $this->setEmpty('privacy.hide_timestamps', false);
333 // default state of the 'remember me' checkbox of the login form
334 $this->setEmpty('privacy.remember_user_default', true);
323 335
324 $this->setEmpty('thumbnail.enable_thumbnails', true); 336 $this->setEmpty('thumbnail.enable_thumbnails', true);
325 $this->setEmpty('thumbnail.enable_localcache', true); 337 $this->setEmpty('thumbnail.enable_localcache', true);
@@ -327,6 +339,10 @@ class ConfigManager
327 $this->setEmpty('redirector.url', ''); 339 $this->setEmpty('redirector.url', '');
328 $this->setEmpty('redirector.encode_url', true); 340 $this->setEmpty('redirector.encode_url', true);
329 341
342 $this->setEmpty('translation.language', 'auto');
343 $this->setEmpty('translation.mode', 'php');
344 $this->setEmpty('translation.extensions', []);
345
330 $this->setEmpty('plugins', array()); 346 $this->setEmpty('plugins', array());
331 } 347 }
332 348
@@ -359,36 +375,3 @@ class ConfigManager
359 $this->configIO = $configIO; 375 $this->configIO = $configIO;
360 } 376 }
361} 377}
362
363/**
364 * Exception used if a mandatory field is missing in given configuration.
365 */
366class MissingFieldConfigException extends Exception
367{
368 public $field;
369
370 /**
371 * Construct exception.
372 *
373 * @param string $field field name missing.
374 */
375 public function __construct($field)
376 {
377 $this->field = $field;
378 $this->message = 'Configuration value is required for '. $this->field;
379 }
380}
381
382/**
383 * Exception used if an unauthorized attempt to edit configuration has been made.
384 */
385class UnauthorizedConfigException extends Exception
386{
387 /**
388 * Construct exception.
389 */
390 public function __construct()
391 {
392 $this->message = 'You are not authorized to alter config.';
393 }
394}