From adc4aee80f7cd3242f65f0b316af2b560a64712c Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Wed, 7 Dec 2016 11:58:25 +0100 Subject: [PATCH] Change templates set through administration UI --- application/ApplicationUtils.php | 1 + application/PageBuilder.php | 2 +- application/Utils.php | 10 ++++++++++ application/config/ConfigManager.php | 1 + application/config/ConfigPhp.php | 3 ++- index.php | 7 ++++++- tests/ApplicationUtilsTest.php | 3 +++ tpl/{ => default}/404.html | 0 tpl/{ => default}/addlink.html | 0 tpl/{ => default}/changepassword.html | 0 tpl/{ => default}/changetag.html | 2 +- tpl/{ => default}/configure.html | 17 +++++++++++++++++ tpl/{ => default}/daily.html | 8 ++++---- tpl/{ => default}/dailyrss.html | 0 tpl/{ => default}/editlink.html | 2 +- tpl/{ => default}/export.bookmarks.html | 0 tpl/{ => default}/export.html | 0 tpl/{ => default}/feed.atom.html | 0 tpl/{ => default}/feed.rss.html | 0 .../default/images}/50pc_transparent.png | Bin .../Paper_texture_v5_by_bashcorpo_w1000.jpg | Bin {images => tpl/default/images}/calendar.png | Bin {images => tpl/default/images}/private.png | Bin {images => tpl/default/images}/tag_blue.png | Bin tpl/{ => default}/import.html | 0 {inc => tpl/default/inc}/reset.css | 0 {inc => tpl/default/inc}/shaarli.css | 2 +- tpl/{ => default}/includes.html | 6 +++--- tpl/{ => default}/install.html | 0 tpl/{ => default}/linklist.html | 2 +- tpl/{ => default}/linklist.paging.html | 0 tpl/{ => default}/loginform.html | 0 tpl/{ => default}/opensearch.html | 0 tpl/{ => default}/page.footer.html | 0 tpl/{ => default}/page.header.html | 0 tpl/{ => default}/page.html | 0 tpl/{ => default}/picwall.html | 0 tpl/{ => default}/pluginsadmin.html | 0 tpl/{ => default}/readme.txt | 0 tpl/{ => default}/tagcloud.html | 0 tpl/{ => default}/tools.html | 0 41 files changed, 52 insertions(+), 14 deletions(-) rename tpl/{ => default}/404.html (100%) rename tpl/{ => default}/addlink.html (100%) rename tpl/{ => default}/changepassword.html (100%) rename tpl/{ => default}/changetag.html (94%) rename tpl/{ => default}/configure.html (88%) rename tpl/{ => default}/daily.html (88%) rename tpl/{ => default}/dailyrss.html (100%) rename tpl/{ => default}/editlink.html (97%) rename tpl/{ => default}/export.bookmarks.html (100%) rename tpl/{ => default}/export.html (100%) rename tpl/{ => default}/feed.atom.html (100%) rename tpl/{ => default}/feed.rss.html (100%) rename {images => tpl/default/images}/50pc_transparent.png (100%) rename {images => tpl/default/images}/Paper_texture_v5_by_bashcorpo_w1000.jpg (100%) rename {images => tpl/default/images}/calendar.png (100%) rename {images => tpl/default/images}/private.png (100%) rename {images => tpl/default/images}/tag_blue.png (100%) rename tpl/{ => default}/import.html (100%) rename {inc => tpl/default/inc}/reset.css (100%) rename {inc => tpl/default/inc}/shaarli.css (99%) rename tpl/{ => default}/includes.html (83%) rename tpl/{ => default}/install.html (100%) rename tpl/{ => default}/linklist.html (98%) rename tpl/{ => default}/linklist.paging.html (100%) rename tpl/{ => default}/loginform.html (100%) rename tpl/{ => default}/opensearch.html (100%) rename tpl/{ => default}/page.footer.html (100%) rename tpl/{ => default}/page.header.html (100%) rename tpl/{ => default}/page.html (100%) rename tpl/{ => default}/picwall.html (100%) rename tpl/{ => default}/pluginsadmin.html (100%) rename tpl/{ => default}/readme.txt (100%) rename tpl/{ => default}/tagcloud.html (100%) rename tpl/{ => default}/tools.html (100%) diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index 7f963e9..a0f482b 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -150,6 +150,7 @@ class ApplicationUtils 'inc', 'plugins', $conf->get('resource.raintpl_tpl'), + $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme'), ) as $path) { if (! is_readable(realpath($path))) { $errors[] = '"'.$path.'" directory is not readable'; diff --git a/application/PageBuilder.php b/application/PageBuilder.php index 32c7f9f..e226a77 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -79,7 +79,7 @@ class PageBuilder $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); $this->tpl->assign('token', getToken($this->conf)); // To be removed with a proper theme configuration. - $this->tpl->assign('conf', $this->conf); + $this->tpl->assign('theme', $this->conf->get('resource.theme', 'default')); } /** diff --git a/application/Utils.php b/application/Utils.php index 35d6522..7556d3c 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -270,3 +270,13 @@ function normalize_spaces($string) { return preg_replace('/\s{2,}/', ' ', trim($string)); } + +function getAllTheme($raintpl_tpl) +{ + $allTheme = glob($raintpl_tpl.'/*', GLOB_ONLYDIR); + foreach ($allTheme as $value) { + $themes[] = str_replace($raintpl_tpl.'/', '', $value); + } + + return $themes; +} diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index ca8918b..a401887 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -299,6 +299,7 @@ class ConfigManager $this->setEmpty('resource.log', 'data/log.txt'); $this->setEmpty('resource.update_check', 'data/lastupdatecheck.txt'); $this->setEmpty('resource.raintpl_tpl', 'tpl/'); + $this->setEmpty('resource.theme', 'default'); $this->setEmpty('resource.raintpl_tmp', 'tmp/'); $this->setEmpty('resource.thumbnails_cache', 'cache'); $this->setEmpty('resource.page_cache', 'pagecache'); diff --git a/application/config/ConfigPhp.php b/application/config/ConfigPhp.php index 27187b6..2eb68d8 100644 --- a/application/config/ConfigPhp.php +++ b/application/config/ConfigPhp.php @@ -41,6 +41,7 @@ class ConfigPhp implements ConfigIO 'resource.log' => 'config.LOG_FILE', 'resource.update_check' => 'config.UPDATECHECK_FILENAME', 'resource.raintpl_tpl' => 'config.RAINTPL_TPL', + 'resource.theme' => 'config.theme', 'resource.raintpl_tmp' => 'config.RAINTPL_TMP', 'resource.thumbnails_cache' => 'config.CACHEDIR', 'resource.page_cache' => 'config.PAGECACHE', @@ -99,7 +100,7 @@ class ConfigPhp implements ConfigIO $configStr .= '$GLOBALS[\'' . $key . '\'] = ' . var_export($conf[$key], true) . ';' . PHP_EOL; } } - + // Store all $conf['config'] foreach ($conf['config'] as $key => $value) { $configStr .= '$GLOBALS[\'config\'][\''. $key .'\'] = '.var_export($conf['config'][$key], true).';'. PHP_EOL; diff --git a/index.php b/index.php index 2ed14d4..62d719e 100644 --- a/index.php +++ b/index.php @@ -122,7 +122,8 @@ if (isset($_COOKIE['shaarli']) && !is_session_id_valid($_COOKIE['shaarli'])) { $conf = new ConfigManager(); $conf->setEmpty('general.timezone', date_default_timezone_get()); $conf->setEmpty('general.title', 'Shared links on '. escape(index_url($_SERVER))); -RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl'); // template directory +$conf->setEmpty('resource.theme', 'default'); +RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory $pluginManager = new PluginManager($conf); @@ -1124,6 +1125,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) $conf->set('general.timezone', $tz); $conf->set('general.title', escape($_POST['title'])); $conf->set('general.header_link', escape($_POST['titleLink'])); + $conf->set('resource.theme', escape($_POST['theme'])); $conf->set('redirector.url', escape($_POST['redirector'])); $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection'])); $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault'])); @@ -1134,6 +1136,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) $conf->set('api.secret', escape($_POST['apiSecret'])); try { $conf->write(isLoggedIn()); + invalidateCaches($conf->get('resource.page_cache')); } catch(Exception $e) { error_log( @@ -1151,6 +1154,8 @@ function renderPage($conf, $pluginManager, $LINKSDB) else // Show the configuration form. { $PAGE->assign('title', $conf->get('general.title')); + $PAGE->assign('theme', $conf->get('resource.theme')); + $PAGE->assign('theme_available', getAllTheme($conf->get('resource.raintpl_tpl'))); $PAGE->assign('redirector', $conf->get('redirector.url')); list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); $PAGE->assign('timezone_form', $timezone_form); diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index 861b8d4..634bd0e 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -289,6 +289,7 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase $conf->set('resource.page_cache', 'pagecache'); $conf->set('resource.raintpl_tmp', 'tmp'); $conf->set('resource.raintpl_tpl', 'tpl'); + $conf->set('resource.theme', 'default'); $conf->set('resource.update_check', 'data/lastupdatecheck.txt'); $this->assertEquals( @@ -312,10 +313,12 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase $conf->set('resource.page_cache', 'null/pagecache'); $conf->set('resource.raintpl_tmp', 'null/tmp'); $conf->set('resource.raintpl_tpl', 'null/tpl'); + $conf->set('resource.raintpl_theme', 'null/tpl/default'); $conf->set('resource.update_check', 'null/data/lastupdatecheck.txt'); $this->assertEquals( array( '"null/tpl" directory is not readable', + '"null/tpl/default" directory is not readable', '"null/cache" directory is not readable', '"null/cache" directory is not writable', '"null/data" directory is not readable', diff --git a/tpl/404.html b/tpl/default/404.html similarity index 100% rename from tpl/404.html rename to tpl/default/404.html diff --git a/tpl/addlink.html b/tpl/default/addlink.html similarity index 100% rename from tpl/addlink.html rename to tpl/default/addlink.html diff --git a/tpl/changepassword.html b/tpl/default/changepassword.html similarity index 100% rename from tpl/changepassword.html rename to tpl/default/changepassword.html diff --git a/tpl/changetag.html b/tpl/default/changetag.html similarity index 94% rename from tpl/changetag.html rename to tpl/default/changetag.html index 13cc5cf..a0df332 100644 --- a/tpl/changetag.html +++ b/tpl/default/changetag.html @@ -1,7 +1,7 @@ {include="includes"} - + diff --git a/tpl/configure.html b/tpl/default/configure.html similarity index 88% rename from tpl/configure.html rename to tpl/default/configure.html index b4197bf..94f6df6 100644 --- a/tpl/configure.html +++ b/tpl/default/configure.html @@ -19,6 +19,23 @@
+ + + Theme: + + + + + + Timezone: {$timezone_form} diff --git a/tpl/daily.html b/tpl/default/daily.html similarity index 88% rename from tpl/daily.html rename to tpl/default/daily.html index eba0af3..024ee32 100644 --- a/tpl/daily.html +++ b/tpl/default/daily.html @@ -28,9 +28,9 @@
- floral_left + floral_left The Daily Shaarli - floral_right + floral_right
@@ -50,7 +50,7 @@
{if="!$hide_timestamps || isLoggedIn()"} @@ -94,7 +94,7 @@ {$value} {/loop}
-
-
+
-
{include="page.footer"} diff --git a/tpl/dailyrss.html b/tpl/default/dailyrss.html similarity index 100% rename from tpl/dailyrss.html rename to tpl/default/dailyrss.html diff --git a/tpl/editlink.html b/tpl/default/editlink.html similarity index 97% rename from tpl/editlink.html rename to tpl/default/editlink.html index 870cc16..d3f99fe 100644 --- a/tpl/editlink.html +++ b/tpl/default/editlink.html @@ -1,7 +1,7 @@ {include="includes"} - + - - -{if="is_file('inc/user.css')"}{/if} + + +{if="is_file('inc/user.css')"}{/if} {loop="$plugins_includes.css_files"} {/loop} diff --git a/tpl/install.html b/tpl/default/install.html similarity index 100% rename from tpl/install.html rename to tpl/default/install.html diff --git a/tpl/linklist.html b/tpl/default/linklist.html similarity index 98% rename from tpl/linklist.html rename to tpl/default/linklist.html index d423234..5accc92 100644 --- a/tpl/linklist.html +++ b/tpl/default/linklist.html @@ -1,7 +1,7 @@ - + {include="includes"} diff --git a/tpl/linklist.paging.html b/tpl/default/linklist.paging.html similarity index 100% rename from tpl/linklist.paging.html rename to tpl/default/linklist.paging.html diff --git a/tpl/loginform.html b/tpl/default/loginform.html similarity index 100% rename from tpl/loginform.html rename to tpl/default/loginform.html diff --git a/tpl/opensearch.html b/tpl/default/opensearch.html similarity index 100% rename from tpl/opensearch.html rename to tpl/default/opensearch.html diff --git a/tpl/page.footer.html b/tpl/default/page.footer.html similarity index 100% rename from tpl/page.footer.html rename to tpl/default/page.footer.html diff --git a/tpl/page.header.html b/tpl/default/page.header.html similarity index 100% rename from tpl/page.header.html rename to tpl/default/page.header.html diff --git a/tpl/page.html b/tpl/default/page.html similarity index 100% rename from tpl/page.html rename to tpl/default/page.html diff --git a/tpl/picwall.html b/tpl/default/picwall.html similarity index 100% rename from tpl/picwall.html rename to tpl/default/picwall.html diff --git a/tpl/pluginsadmin.html b/tpl/default/pluginsadmin.html similarity index 100% rename from tpl/pluginsadmin.html rename to tpl/default/pluginsadmin.html diff --git a/tpl/readme.txt b/tpl/default/readme.txt similarity index 100% rename from tpl/readme.txt rename to tpl/default/readme.txt diff --git a/tpl/tagcloud.html b/tpl/default/tagcloud.html similarity index 100% rename from tpl/tagcloud.html rename to tpl/default/tagcloud.html diff --git a/tpl/tools.html b/tpl/default/tools.html similarity index 100% rename from tpl/tools.html rename to tpl/default/tools.html