diff options
author | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2019-07-27 12:34:30 +0200 |
commit | 38672ba0d1c722e5d6d33a58255ceb55e9410e46 (patch) | |
tree | dae4c7c47532380eac3ae641db99122fc77c93dc /application/config | |
parent | 83faedadff76c5bdca036f39f13943f63b27e164 (diff) | |
parent | 1e77e0448bbd25675d8c0fe4a73206ad9048904b (diff) | |
download | Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.gz Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.tar.zst Shaarli-38672ba0d1c722e5d6d33a58255ceb55e9410e46.zip |
Merge tag 'v0.10.4' into stable
Release v0.10.4
Diffstat (limited to 'application/config')
-rw-r--r-- | application/config/ConfigManager.php | 58 | ||||
-rw-r--r-- | application/config/ConfigPhp.php | 12 | ||||
-rw-r--r-- | application/config/ConfigPlugin.php | 3 |
3 files changed, 64 insertions, 9 deletions
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index 9e4c9f63..32aaea48 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php | |||
@@ -123,7 +123,7 @@ class ConfigManager | |||
123 | * Supports nested settings with dot separated keys. | 123 | * Supports nested settings with dot separated keys. |
124 | * | 124 | * |
125 | * @param string $setting Asked setting, keys separated with dots. | 125 | * @param string $setting Asked setting, keys separated with dots. |
126 | * @param string $value Value to set. | 126 | * @param mixed $value Value to set. |
127 | * @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. |
128 | * @param bool $isLoggedIn User login state, default false. | 128 | * @param bool $isLoggedIn User login state, default false. |
129 | * | 129 | * |
@@ -148,6 +148,33 @@ class ConfigManager | |||
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Remove a config element from the config file. | ||
152 | * | ||
153 | * @param string $setting Asked setting, keys separated with dots. | ||
154 | * @param bool $write Write the new setting in the config file, default false. | ||
155 | * @param bool $isLoggedIn User login state, default false. | ||
156 | * | ||
157 | * @throws \Exception Invalid | ||
158 | */ | ||
159 | public function remove($setting, $write = false, $isLoggedIn = false) | ||
160 | { | ||
161 | if (empty($setting) || ! is_string($setting)) { | ||
162 | throw new \Exception(t('Invalid setting key parameter. String expected, got: '). gettype($setting)); | ||
163 | } | ||
164 | |||
165 | // During the ConfigIO transition, map legacy settings to the new ones. | ||
166 | if ($this->configIO instanceof ConfigPhp && isset(ConfigPhp::$LEGACY_KEYS_MAPPING[$setting])) { | ||
167 | $setting = ConfigPhp::$LEGACY_KEYS_MAPPING[$setting]; | ||
168 | } | ||
169 | |||
170 | $settings = explode('.', $setting); | ||
171 | self::removeConfig($settings, $this->loadedConfig); | ||
172 | if ($write) { | ||
173 | $this->write($isLoggedIn); | ||
174 | } | ||
175 | } | ||
176 | |||
177 | /** | ||
151 | * Check if a settings exists. | 178 | * Check if a settings exists. |
152 | * | 179 | * |
153 | * Supports nested settings with dot separated keys. | 180 | * Supports nested settings with dot separated keys. |
@@ -272,7 +299,7 @@ class ConfigManager | |||
272 | * | 299 | * |
273 | * @param array $settings Ordered array which contains keys to find. | 300 | * @param array $settings Ordered array which contains keys to find. |
274 | * @param mixed $value | 301 | * @param mixed $value |
275 | * @param array $conf Loaded settings, then sub-array. | 302 | * @param array $conf Loaded settings, then sub-array. |
276 | * | 303 | * |
277 | * @return mixed Found setting or NOT_FOUND flag. | 304 | * @return mixed Found setting or NOT_FOUND flag. |
278 | */ | 305 | */ |
@@ -290,6 +317,27 @@ class ConfigManager | |||
290 | } | 317 | } |
291 | 318 | ||
292 | /** | 319 | /** |
320 | * Recursive function which find asked setting in the loaded config and deletes it. | ||
321 | * | ||
322 | * @param array $settings Ordered array which contains keys to find. | ||
323 | * @param array $conf Loaded settings, then sub-array. | ||
324 | * | ||
325 | * @return mixed Found setting or NOT_FOUND flag. | ||
326 | */ | ||
327 | protected static function removeConfig($settings, &$conf) | ||
328 | { | ||
329 | if (!is_array($settings) || count($settings) == 0) { | ||
330 | return self::$NOT_FOUND; | ||
331 | } | ||
332 | |||
333 | $setting = array_shift($settings); | ||
334 | if (count($settings) > 0) { | ||
335 | return self::removeConfig($settings, $conf[$setting]); | ||
336 | } | ||
337 | unset($conf[$setting]); | ||
338 | } | ||
339 | |||
340 | /** | ||
293 | * Set a bunch of default values allowing Shaarli to start without a config file. | 341 | * Set a bunch of default values allowing Shaarli to start without a config file. |
294 | */ | 342 | */ |
295 | protected function setDefaultValues() | 343 | protected function setDefaultValues() |
@@ -333,12 +381,12 @@ class ConfigManager | |||
333 | // default state of the 'remember me' checkbox of the login form | 381 | // default state of the 'remember me' checkbox of the login form |
334 | $this->setEmpty('privacy.remember_user_default', true); | 382 | $this->setEmpty('privacy.remember_user_default', true); |
335 | 383 | ||
336 | $this->setEmpty('thumbnail.enable_thumbnails', true); | ||
337 | $this->setEmpty('thumbnail.enable_localcache', true); | ||
338 | |||
339 | $this->setEmpty('redirector.url', ''); | 384 | $this->setEmpty('redirector.url', ''); |
340 | $this->setEmpty('redirector.encode_url', true); | 385 | $this->setEmpty('redirector.encode_url', true); |
341 | 386 | ||
387 | $this->setEmpty('thumbnails.width', '125'); | ||
388 | $this->setEmpty('thumbnails.height', '90'); | ||
389 | |||
342 | $this->setEmpty('translation.language', 'auto'); | 390 | $this->setEmpty('translation.language', 'auto'); |
343 | $this->setEmpty('translation.mode', 'php'); | 391 | $this->setEmpty('translation.mode', 'php'); |
344 | $this->setEmpty('translation.extensions', []); | 392 | $this->setEmpty('translation.extensions', []); |
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php index 8add8bcd..9625fe1a 100644 --- a/application/config/ConfigPhp.php +++ b/application/config/ConfigPhp.php | |||
@@ -104,12 +104,20 @@ class ConfigPhp implements ConfigIO | |||
104 | 104 | ||
105 | // Store all $conf['config'] | 105 | // Store all $conf['config'] |
106 | foreach ($conf['config'] as $key => $value) { | 106 | foreach ($conf['config'] as $key => $value) { |
107 | $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; | 107 | $configStr .= '$GLOBALS[\'config\'][\'' |
108 | . $key | ||
109 | .'\'] = ' | ||
110 | .var_export($conf['config'][$key], true).';' | ||
111 | . PHP_EOL; | ||
108 | } | 112 | } |
109 | 113 | ||
110 | if (isset($conf['plugins'])) { | 114 | if (isset($conf['plugins'])) { |
111 | foreach ($conf['plugins'] as $key => $value) { | 115 | foreach ($conf['plugins'] as $key => $value) { |
112 | $configStr .= '$GLOBALS[\'plugins\'][\''. $key .'\'] = '.var_export($conf['plugins'][$key], true).';'. PHP_EOL; | 116 | $configStr .= '$GLOBALS[\'plugins\'][\'' |
117 | . $key | ||
118 | .'\'] = ' | ||
119 | .var_export($conf['plugins'][$key], true).';' | ||
120 | . PHP_EOL; | ||
113 | } | 121 | } |
114 | } | 122 | } |
115 | 123 | ||
diff --git a/application/config/ConfigPlugin.php b/application/config/ConfigPlugin.php index b3d9752b..dbb24937 100644 --- a/application/config/ConfigPlugin.php +++ b/application/config/ConfigPlugin.php | |||
@@ -34,8 +34,7 @@ function save_plugin_config($formData) | |||
34 | // If there is no order, it means a disabled plugin has been enabled. | 34 | // If there is no order, it means a disabled plugin has been enabled. |
35 | if (isset($formData['order_' . $key])) { | 35 | if (isset($formData['order_' . $key])) { |
36 | $plugins[(int) $formData['order_' . $key]] = $key; | 36 | $plugins[(int) $formData['order_' . $key]] = $key; |
37 | } | 37 | } else { |
38 | else { | ||
39 | $newEnabledPlugins[] = $key; | 38 | $newEnabledPlugins[] = $key; |
40 | } | 39 | } |
41 | } | 40 | } |