aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2017-01-06 11:40:54 +0100
committerGitHub <noreply@github.com>2017-01-06 11:40:54 +0100
commit7418f7cb60524c3bfc2f240386b5e3e7eb9b3257 (patch)
tree4b0c89c133ad1679c5db3a4f0f6b94079f776395 /application
parent93b1fe54fb99efff30eec0d405cc7319fbbc1f95 (diff)
parent01c6e32a02034ab119d83364c4648ce55d75543b (diff)
downloadShaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.tar.gz
Shaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.tar.zst
Shaarli-7418f7cb60524c3bfc2f240386b5e3e7eb9b3257.zip
Merge pull request #732 from ArthurHoaro/feature/theme-manager
Theme manager: improvements
Diffstat (limited to 'application')
-rw-r--r--application/ApplicationUtils.php1
-rw-r--r--application/ThemeUtils.php33
-rw-r--r--application/Updater.php29
-rw-r--r--application/config/ConfigManager.php1
-rw-r--r--application/config/ConfigPhp.php3
5 files changed, 66 insertions, 1 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index 7f963e97..a0f482b0 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -150,6 +150,7 @@ class ApplicationUtils
150 'inc', 150 'inc',
151 'plugins', 151 'plugins',
152 $conf->get('resource.raintpl_tpl'), 152 $conf->get('resource.raintpl_tpl'),
153 $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme'),
153 ) as $path) { 154 ) as $path) {
154 if (! is_readable(realpath($path))) { 155 if (! is_readable(realpath($path))) {
155 $errors[] = '"'.$path.'" directory is not readable'; 156 $errors[] = '"'.$path.'" directory is not readable';
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/**
diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php
index ca8918b5..a401887c 100644
--- a/application/config/ConfigManager.php
+++ b/application/config/ConfigManager.php
@@ -299,6 +299,7 @@ class ConfigManager
299 $this->setEmpty('resource.log', 'data/log.txt'); 299 $this->setEmpty('resource.log', 'data/log.txt');
300 $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); 300 $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt');
301 $this->setEmpty('resource.raintpl_tpl', 'tpl/'); 301 $this->setEmpty('resource.raintpl_tpl', 'tpl/');
302 $this->setEmpty('resource.theme', 'default');
302 $this->setEmpty('resource.raintpl_tmp', 'tmp/'); 303 $this->setEmpty('resource.raintpl_tmp', 'tmp/');
303 $this->setEmpty('resource.thumbnails_cache', 'cache'); 304 $this->setEmpty('resource.thumbnails_cache', 'cache');
304 $this->setEmpty('resource.page_cache', 'pagecache'); 305 $this->setEmpty('resource.page_cache', 'pagecache');
diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php
index 9dd9a65d..d7fd4baf 100644
--- a/application/config/ConfigPhp.php
+++ b/application/config/ConfigPhp.php
@@ -41,6 +41,7 @@ class ConfigPhp implements ConfigIO
41 'resource.log' => 'config.LOG_FILE', 41 'resource.log' => 'config.LOG_FILE',
42 'resource.update_check' => 'config.UPDATECHECK_FILENAME', 42 'resource.update_check' => 'config.UPDATECHECK_FILENAME',
43 'resource.raintpl_tpl' => 'config.RAINTPL_TPL', 43 'resource.raintpl_tpl' => 'config.RAINTPL_TPL',
44 'resource.theme' => 'config.theme',
44 'resource.raintpl_tmp' => 'config.RAINTPL_TMP', 45 'resource.raintpl_tmp' => 'config.RAINTPL_TMP',
45 'resource.thumbnails_cache' => 'config.CACHEDIR', 46 'resource.thumbnails_cache' => 'config.CACHEDIR',
46 'resource.page_cache' => 'config.PAGECACHE', 47 'resource.page_cache' => 'config.PAGECACHE',
@@ -99,7 +100,7 @@ class ConfigPhp implements ConfigIO
99 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL; 100 $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL;
100 } 101 }
101 } 102 }
102 103
103 // Store all $conf['config'] 104 // Store all $conf['config']
104 foreach ($conf['config'] as $key => $value) { 105 foreach ($conf['config'] as $key => $value) {
105 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; 106 $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL;