From adc4aee80f7cd3242f65f0b316af2b560a64712c Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Wed, 7 Dec 2016 11:58:25 +0100 Subject: [PATCH 1/4] 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 7f963e97..a0f482b0 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -150,6 +150,7 @@ public static function checkResourcePermissions($conf) '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 32c7f9f1..e226a77d 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -79,7 +79,7 @@ private function initialize() $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 35d65224..7556d3c9 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 ca8918b5..a401887c 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -299,6 +299,7 @@ protected function setDefaultValues() $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 27187b66..2eb68d80 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 @@ function write($filepath, $conf) $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 2ed14d4f..62d719e1 100644 --- a/index.php +++ b/index.php @@ -122,7 +122,8 @@ $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 861b8d4e..634bd0ed 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -289,6 +289,7 @@ public function testCheckCurrentResourcePermissions() $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 @@ public function testCheckCurrentResourcePermissionsErrors() $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 13cc5cf1..a0df3328 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 b4197bf9..94f6df69 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 eba0af3b..024ee32e 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 870cc168..d3f99fe6 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 d4232342..5accc92f 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 From a0df06517bada0f811b464017ce385290e02c2bf Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 11:42:21 +0100 Subject: [PATCH 2/4] Minor improvements regarding #705 (coding style, unit tests, etc.) --- .gitignore | 4 ++ CHANGELOG.md | 5 +- COPYING | 2 +- application/ApplicationUtils.php | 20 ++++++++ application/PageBuilder.php | 2 +- application/Utils.php | 10 ---- images/squiggle.png | Bin 684 -> 0 bytes index.php | 4 +- tests/ApplicationUtilsTest.php | 44 ++++++++++++++++++ tests/Updater/UpdaterTest.php | 1 + tests/utils/config/configJson.json.php | 3 +- tpl/default/configure.html | 13 +++--- tpl/default/{inc => css}/reset.css | 0 tpl/default/{inc => css}/shaarli.css | 0 tpl/default/daily.html | 8 ++-- .../default/images}/floral_left.png | Bin .../default/images}/floral_right.png | Bin .../default/images/squiggle.png | Bin .../default/images}/squiggle_closing.png | Bin tpl/default/includes.html | 4 +- 20 files changed, 92 insertions(+), 28 deletions(-) delete mode 100644 images/squiggle.png rename tpl/default/{inc => css}/reset.css (100%) rename tpl/default/{inc => css}/shaarli.css (100%) rename {images => tpl/default/images}/floral_left.png (100%) rename {images => tpl/default/images}/floral_right.png (100%) rename images/squiggle2.png => tpl/default/images/squiggle.png (100%) rename {images => tpl/default/images}/squiggle_closing.png (100%) diff --git a/.gitignore b/.gitignore index 9121905d..19f3dc83 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ phpmd.html # User plugin configuration plugins/*/config.php + +# 3rd party themes +tpl/* +!tpl/default diff --git a/CHANGELOG.md b/CHANGELOG.md index fe775b3e..d3ecc1e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [v0.9.0](https://github.com/shaarli/Shaarli/releases/tag/v0.9.0) - UNPUBLISHED -**WARNING**: Shaarli now requires PHP 5.5+. +**WARNING**: Shaarli now requires PHP 5.5+. ### Added - REST API: see [Shaarli API documentation](http://shaarli.github.io/api-documentation/) +- The theme can now be selected in the administration page. ### Changed +- Default template files are moved to a subfolder (`default`). + ### Fixed diff --git a/COPYING b/COPYING index 22929463..547ea570 100644 --- a/COPYING +++ b/COPYING @@ -43,7 +43,7 @@ License: CC-BY (http://creativecommons.org/licenses/by/3.0/) Copyright: (c) 2014 Designmodo Source: http://designmodo.com/linecons-free/ -Files: images/floral_left.png, images/floral_right.png, images/squiggle.png, images/squiggle2.png, images/squiggle_closing.png +Files: images/floral_left.png, images/floral_right.png, images/squiggle.png, images/squiggle_closing.png Licence: Public Domain Source: https://openclipart.org/people/j4p4n/j4p4n_ornimental_bookend_-_left.svg diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php index a0f482b0..cc009a1d 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -195,4 +195,24 @@ public static function checkResourcePermissions($conf) return $errors; } + + /** + * Get a list of available themes. + * + * It will return the name of any directory present in the template folder. + * + * @param string $tplDir Templates main directory. + * + * @return array List of theme names. + */ + public static function getThemes($tplDir) + { + $allTheme = glob($tplDir.'/*', GLOB_ONLYDIR); + $themes = []; + foreach ($allTheme as $value) { + $themes[] = str_replace($tplDir.'/', '', $value); + } + + return $themes; + } } diff --git a/application/PageBuilder.php b/application/PageBuilder.php index e226a77d..32c7f9f1 100644 --- a/application/PageBuilder.php +++ b/application/PageBuilder.php @@ -79,7 +79,7 @@ private function initialize() $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('theme', $this->conf->get('resource.theme', 'default')); + $this->tpl->assign('conf', $this->conf); } /** diff --git a/application/Utils.php b/application/Utils.php index 7556d3c9..35d65224 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -270,13 +270,3 @@ 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/images/squiggle.png b/images/squiggle.png deleted file mode 100644 index a6ce218c71972a1f48e1e7026a8764e2b2a49c9b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 684 zcmV;d0#p5oP)P001!v1^@s6FBSqg00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY4c7nw4c7reD4Tcy000McNliru-UtB;02}HY-Bthq0y#-U zK~z}7?bb_(jbR)H@ZZdt8Iw!ycTvfihIz2AAC_y7EFhXxvGpn(P&Xy8A@#O8lM zvbo*_gK)jxo-D-FdXr2-TRlluU;#??BpHK67}-)Mf=%d1;MId<8Ft_;zSqNp@i>JF zUf?#q{;k8CqW?ww3P}a;QT`hQ!>|R9(T%RGRiaAM01huce#V=c(Te4Gf;$+T_oE_R6|)ognn~KQ9xwCbGkM>Mz1WV4h3^mITd78p z(Ks48zJ=^sh$kfA;^O@KX>CR$4rX@L=`&%qs z(S2oP`VgYS*?)y+7=iYIcHyTuhT(V=$sR?%_vy$V`zqID97rKnN5n52!Udehy<}NA z1Td$s#n^#MY1u0aZDsr)72b)hg<_nC^O-BXq7#=39rb#uz9+O~B5uME?1`LRz5QQW zn_Mr>hcb@za;Z_+iF0_6?<+mchIMiCO>rg^>`Q_@ws4_h^V}C{zgI8VgsBP8Jgmuc zTOW$?F0LeIHsetEmpty('general.timezone', date_default_timezone_get()); $conf->setEmpty('general.title', 'Shared links on '. escape(index_url($_SERVER))); -$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 @@ -1155,7 +1155,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) { $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('theme_available', ThemeUtils::getThemes($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 634bd0ed..c39649e8 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -331,4 +331,48 @@ public function testCheckCurrentResourcePermissionsErrors() ApplicationUtils::checkResourcePermissions($conf) ); } + + /** + * Test getThemes() with existing theme directories. + */ + public function testGetThemes() + { + $themes = ['theme1', 'default', 'Bl1p_- bL0p']; + foreach ($themes as $theme) { + mkdir('sandbox/tpl/'. $theme, 0777, true); + } + + // include a file which should be ignored + touch('sandbox/tpl/supertheme'); + + $res = ApplicationUtils::getThemes('sandbox/tpl/'); + foreach ($res as $theme) { + $this->assertTrue(in_array($theme, $themes)); + } + $this->assertFalse(in_array('supertheme', $res)); + + foreach ($themes as $theme) { + rmdir('sandbox/tpl/'. $theme); + } + unlink('sandbox/tpl/supertheme'); + rmdir('sandbox/tpl'); + } + + /** + * Test getThemes() without any theme dir. + */ + public function testGetThemesEmpty() + { + mkdir('sandbox/tpl/', 0777, true); + $this->assertEquals([], ApplicationUtils::getThemes('sandbox/tpl/')); + rmdir('sandbox/tpl/'); + } + + /** + * Test getThemes() with an invalid path. + */ + public function testGetThemesInvalid() + { + $this->assertEquals([], ApplicationUtils::getThemes('nope')); + } } diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 0171daad..a1530996 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -2,6 +2,7 @@ require_once 'application/config/ConfigManager.php'; require_once 'tests/Updater/DummyUpdater.php'; +require_once 'inc/rain.tpl.class.php'; /** * Class UpdaterTest. diff --git a/tests/utils/config/configJson.json.php b/tests/utils/config/configJson.json.php index 06a302e8..13d38c66 100644 --- a/tests/utils/config/configJson.json.php +++ b/tests/utils/config/configJson.json.php @@ -24,7 +24,8 @@ }, "resource": { "datastore": "tests\/utils\/config\/datastore.php", - "data_dir": "tests\/utils\/config" + "data_dir": "tests\/utils\/config", + "raintpl_tpl": "tpl/" }, "plugins": { "WALLABAG_VERSION": 1 diff --git a/tpl/default/configure.html b/tpl/default/configure.html index 94f6df69..e71133b4 100644 --- a/tpl/default/configure.html +++ b/tpl/default/configure.html @@ -25,14 +25,15 @@ - diff --git a/tpl/default/inc/reset.css b/tpl/default/css/reset.css similarity index 100% rename from tpl/default/inc/reset.css rename to tpl/default/css/reset.css diff --git a/tpl/default/inc/shaarli.css b/tpl/default/css/shaarli.css similarity index 100% rename from tpl/default/inc/shaarli.css rename to tpl/default/css/shaarli.css diff --git a/tpl/default/daily.html b/tpl/default/daily.html index 024ee32e..e86e90b1 100644 --- a/tpl/default/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/images/floral_left.png b/tpl/default/images/floral_left.png similarity index 100% rename from images/floral_left.png rename to tpl/default/images/floral_left.png diff --git a/images/floral_right.png b/tpl/default/images/floral_right.png similarity index 100% rename from images/floral_right.png rename to tpl/default/images/floral_right.png diff --git a/images/squiggle2.png b/tpl/default/images/squiggle.png similarity index 100% rename from images/squiggle2.png rename to tpl/default/images/squiggle.png diff --git a/images/squiggle_closing.png b/tpl/default/images/squiggle_closing.png similarity index 100% rename from images/squiggle_closing.png rename to tpl/default/images/squiggle_closing.png diff --git a/tpl/default/includes.html b/tpl/default/includes.html index 2ff5d8df..c3b837f5 100644 --- a/tpl/default/includes.html +++ b/tpl/default/includes.html @@ -6,8 +6,8 @@ - - + + {if="is_file('inc/user.css')"}{/if} {loop="$plugins_includes.css_files"} From 04a0e8ea34c241fdf6bd30b11f5242656f9cd1c2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 12:01:25 +0100 Subject: [PATCH 3/4] Updater: keep custom theme preference with the new theme setting --- application/ApplicationUtils.php | 20 ------------ application/ThemeUtils.php | 33 +++++++++++++++++++ application/Updater.php | 29 +++++++++++++++++ composer.json | 1 + tests/ApplicationUtilsTest.php | 44 ------------------------- tests/ThemeUtilsTest.php | 55 ++++++++++++++++++++++++++++++++ tests/Updater/UpdaterTest.php | 44 +++++++++++++++++++++++++ tpl/default/configure.html | 6 +--- 8 files changed, 163 insertions(+), 69 deletions(-) create mode 100644 application/ThemeUtils.php create mode 100644 tests/ThemeUtilsTest.php 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 @@ public static function checkResourcePermissions($conf) return $errors; } - - /** - * Get a list of available themes. - * - * It will return the name of any directory present in the template folder. - * - * @param string $tplDir Templates main directory. - * - * @return array List of theme names. - */ - public static function getThemes($tplDir) - { - $allTheme = glob($tplDir.'/*', GLOB_ONLYDIR); - $themes = []; - foreach ($allTheme as $value) { - $themes[] = str_replace($tplDir.'/', '', $value); - } - - return $themes; - } } 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 @@ +conf->write($this->isLoggedIn); return true; } + + /** + * New setting: theme name. If the default theme is used, nothing to do. + * + * If the user uses a custom theme, raintpl_tpl dir is updated to the parent directory, + * and the current theme is set as default in the theme setting. + * + * @return bool true if the update is successful, false otherwise. + */ + public function updateMethodDefaultTheme() + { + // raintpl_tpl isn't the root template directory anymore. + // We run the update only if this folder still contains the template files. + $tplDir = $this->conf->get('resource.raintpl_tpl'); + $tplFile = $tplDir . '/linklist.html'; + if (! file_exists($tplFile)) { + return true; + } + + $parent = dirname($tplDir); + $this->conf->set('resource.raintpl_tpl', $parent); + $this->conf->set('resource.theme', trim(str_replace($parent, '', $tplDir), '/')); + $this->conf->write($this->isLoggedIn); + + // Dependency injection gore + RainTPL::$tpl_dir = $tplDir; + + return true; + } } /** diff --git a/composer.json b/composer.json index cfbde1a0..2fed0df7 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ }, "autoload": { "psr-4": { + "Shaarli\\": "application", "Shaarli\\Api\\": "application/api/", "Shaarli\\Api\\Controllers\\": "application/api/controllers", "Shaarli\\Api\\Exceptions\\": "application/api/exceptions" diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php index c39649e8..634bd0ed 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -331,48 +331,4 @@ public function testCheckCurrentResourcePermissionsErrors() ApplicationUtils::checkResourcePermissions($conf) ); } - - /** - * Test getThemes() with existing theme directories. - */ - public function testGetThemes() - { - $themes = ['theme1', 'default', 'Bl1p_- bL0p']; - foreach ($themes as $theme) { - mkdir('sandbox/tpl/'. $theme, 0777, true); - } - - // include a file which should be ignored - touch('sandbox/tpl/supertheme'); - - $res = ApplicationUtils::getThemes('sandbox/tpl/'); - foreach ($res as $theme) { - $this->assertTrue(in_array($theme, $themes)); - } - $this->assertFalse(in_array('supertheme', $res)); - - foreach ($themes as $theme) { - rmdir('sandbox/tpl/'. $theme); - } - unlink('sandbox/tpl/supertheme'); - rmdir('sandbox/tpl'); - } - - /** - * Test getThemes() without any theme dir. - */ - public function testGetThemesEmpty() - { - mkdir('sandbox/tpl/', 0777, true); - $this->assertEquals([], ApplicationUtils::getThemes('sandbox/tpl/')); - rmdir('sandbox/tpl/'); - } - - /** - * Test getThemes() with an invalid path. - */ - public function testGetThemesInvalid() - { - $this->assertEquals([], ApplicationUtils::getThemes('nope')); - } } diff --git a/tests/ThemeUtilsTest.php b/tests/ThemeUtilsTest.php new file mode 100644 index 00000000..e44564be --- /dev/null +++ b/tests/ThemeUtilsTest.php @@ -0,0 +1,55 @@ +assertTrue(in_array($theme, $themes)); + } + $this->assertFalse(in_array('supertheme', $res)); + + foreach ($themes as $theme) { + rmdir('sandbox/tpl/'. $theme); + } + unlink('sandbox/tpl/supertheme'); + rmdir('sandbox/tpl'); + } + + /** + * Test getThemes() without any theme dir. + */ + public function testGetThemesEmpty() + { + mkdir('sandbox/tpl/', 0755, true); + $this->assertEquals([], ThemeUtils::getThemes('sandbox/tpl/')); + rmdir('sandbox/tpl/'); + } + + /** + * Test getThemes() with an invalid path. + */ + public function testGetThemesInvalid() + { + $this->assertEquals([], ThemeUtils::getThemes('nope')); + } +} diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index a1530996..1d15cfaa 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -422,4 +422,48 @@ public function testDatastoreIdsNothingToDo() $this->assertTrue($updater->updateMethodDatastoreIds()); $this->assertEquals($checksum, hash_file('sha1', self::$testDatastore)); } + + /** + * Test defaultTheme update with default settings: nothing to do. + */ + public function testDefaultThemeWithDefaultSettings() + { + $sandbox = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandbox . '.json.php'); + $this->conf = new ConfigManager($sandbox); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultTheme()); + + $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals('default', $this->conf->get('resource.theme')); + $this->conf = new ConfigManager($sandbox); + $this->assertEquals('tpl/', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals('default', $this->conf->get('resource.theme')); + unlink($sandbox . '.json.php'); + } + + /** + * Test defaultTheme update with a custom theme in a subfolder + */ + public function testDefaultThemeWithCustomTheme() + { + $theme = 'iamanartist'; + $sandbox = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandbox . '.json.php'); + $this->conf = new ConfigManager($sandbox); + mkdir('sandbox/'. $theme); + touch('sandbox/'. $theme .'/linklist.html'); + $this->conf->set('resource.raintpl_tpl', 'sandbox/'. $theme .'/'); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultTheme()); + + $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + $this->conf = new ConfigManager($sandbox); + $this->assertEquals('sandbox', $this->conf->get('resource.raintpl_tpl')); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + unlink($sandbox . '.json.php'); + unlink('sandbox/'. $theme .'/linklist.html'); + rmdir('sandbox/'. $theme); + } } diff --git a/tpl/default/configure.html b/tpl/default/configure.html index e71133b4..5820e6e4 100644 --- a/tpl/default/configure.html +++ b/tpl/default/configure.html @@ -25,11 +25,7 @@