From a0df06517bada0f811b464017ce385290e02c2bf Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 3 Jan 2017 11:42:21 +0100 Subject: [PATCH] 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 9121905..19f3dc8 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 fe775b3..d3ecc1e 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 2292946..547ea57 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 a0f482b..cc009a1 100644 --- a/application/ApplicationUtils.php +++ b/application/ApplicationUtils.php @@ -195,4 +195,24 @@ class ApplicationUtils 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 e226a77..32c7f9f 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('theme', $this->conf->get('resource.theme', 'default')); + $this->tpl->assign('conf', $this->conf); } /** diff --git a/application/Utils.php b/application/Utils.php index 7556d3c..35d6522 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 634bd0e..c39649e 100644 --- a/tests/ApplicationUtilsTest.php +++ b/tests/ApplicationUtilsTest.php @@ -331,4 +331,48 @@ class ApplicationUtilsTest extends PHPUnit_Framework_TestCase 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 0171daa..a153099 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 06a302e..13d38c6 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 94f6df6..e71133b 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 024ee32..e86e90b 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 2ff5d8d..c3b837f 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"}