aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-01-03 12:01:25 +0100
committerArthurHoaro <arthur@hoa.ro>2017-01-05 16:16:27 +0100
commit04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2 (patch)
tree20c99e86f3fc862f90d3d7475f4a49b89557a7d4 /application
parenta0df06517bada0f811b464017ce385290e02c2bf (diff)
downloadShaarli-04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2.tar.gz
Shaarli-04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2.tar.zst
Shaarli-04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2.zip
Updater: keep custom theme preference with the new theme setting
Diffstat (limited to 'application')
-rw-r--r--application/ApplicationUtils.php20
-rw-r--r--application/ThemeUtils.php33
-rw-r--r--application/Updater.php29
3 files changed, 62 insertions, 20 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index cc009a1d..a0f482b0 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -195,24 +195,4 @@ class ApplicationUtils
195 195
196 return $errors; 196 return $errors;
197 } 197 }
198
199 /**
200 * Get a list of available themes.
201 *
202 * It will return the name of any directory present in the template folder.
203 *
204 * @param string $tplDir Templates main directory.
205 *
206 * @return array List of theme names.
207 */
208 public static function getThemes($tplDir)
209 {
210 $allTheme = glob($tplDir.'/*', GLOB_ONLYDIR);
211 $themes = [];
212 foreach ($allTheme as $value) {
213 $themes[] = str_replace($tplDir.'/', '', $value);
214 }
215
216 return $themes;
217 }
218} 198}
diff --git a/application/ThemeUtils.php b/application/ThemeUtils.php
new file mode 100644
index 00000000..2718ed13
--- /dev/null
+++ b/application/ThemeUtils.php
@@ -0,0 +1,33 @@
1<?php
2
3namespace Shaarli;
4
5/**
6 * Class ThemeUtils
7 *
8 * Utility functions related to theme management.
9 *
10 * @package Shaarli
11 */
12class ThemeUtils
13{
14 /**
15 * Get a list of available themes.
16 *
17 * It will return the name of any directory present in the template folder.
18 *
19 * @param string $tplDir Templates main directory.
20 *
21 * @return array List of theme names.
22 */
23 public static function getThemes($tplDir)
24 {
25 $allTheme = glob($tplDir.'/*', GLOB_ONLYDIR);
26 $themes = [];
27 foreach ($allTheme as $value) {
28 $themes[] = str_replace($tplDir.'/', '', $value);
29 }
30
31 return $themes;
32 }
33}
diff --git a/application/Updater.php b/application/Updater.php
index 38de3350..621c7238 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -279,6 +279,35 @@ class Updater
279 $this->conf->write($this->isLoggedIn); 279 $this->conf->write($this->isLoggedIn);
280 return true; 280 return true;
281 } 281 }
282
283 /**
284 * New setting: theme name. If the default theme is used, nothing to do.
285 *
286 * If the user uses a custom theme, raintpl_tpl dir is updated to the parent directory,
287 * and the current theme is set as default in the theme setting.
288 *
289 * @return bool true if the update is successful, false otherwise.
290 */
291 public function updateMethodDefaultTheme()
292 {
293 // raintpl_tpl isn't the root template directory anymore.
294 // We run the update only if this folder still contains the template files.
295 $tplDir = $this->conf->get('resource.raintpl_tpl');
296 $tplFile = $tplDir . '/linklist.html';
297 if (! file_exists($tplFile)) {
298 return true;
299 }
300
301 $parent = dirname($tplDir);
302 $this->conf->set('resource.raintpl_tpl', $parent);
303 $this->conf->set('resource.theme', trim(str_replace($parent, '', $tplDir), '/'));
304 $this->conf->write($this->isLoggedIn);
305
306 // Dependency injection gore
307 RainTPL::$tpl_dir = $tplDir;
308
309 return true;
310 }
282} 311}
283 312
284/** 313/**