Minor improvements regarding #705 (coding style, unit tests, etc.)

This commit is contained in:
ArthurHoaro 2017-01-03 11:42:21 +01:00
parent adc4aee80f
commit a0df06517b
20 changed files with 92 additions and 28 deletions

4
.gitignore vendored
View file

@ -28,3 +28,7 @@ phpmd.html
# User plugin configuration # User plugin configuration
plugins/*/config.php plugins/*/config.php
# 3rd party themes
tpl/*
!tpl/default

View file

@ -12,9 +12,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added ### Added
- REST API: see [Shaarli API documentation](http://shaarli.github.io/api-documentation/) - REST API: see [Shaarli API documentation](http://shaarli.github.io/api-documentation/)
- The theme can now be selected in the administration page.
### Changed ### Changed
- Default template files are moved to a subfolder (`default`).
### Fixed ### Fixed

View file

@ -43,7 +43,7 @@ License: CC-BY (http://creativecommons.org/licenses/by/3.0/)
Copyright: (c) 2014 Designmodo Copyright: (c) 2014 Designmodo
Source: http://designmodo.com/linecons-free/ 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 Licence: Public Domain
Source: https://openclipart.org/people/j4p4n/j4p4n_ornimental_bookend_-_left.svg Source: https://openclipart.org/people/j4p4n/j4p4n_ornimental_bookend_-_left.svg

View file

@ -195,4 +195,24 @@ public static function checkResourcePermissions($conf)
return $errors; 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;
}
} }

View file

@ -79,7 +79,7 @@ private function initialize()
$this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
$this->tpl->assign('token', getToken($this->conf)); $this->tpl->assign('token', getToken($this->conf));
// To be removed with a proper theme configuration. // To be removed with a proper theme configuration.
$this->tpl->assign('theme', $this->conf->get('resource.theme', 'default')); $this->tpl->assign('conf', $this->conf);
} }
/** /**

View file

@ -270,13 +270,3 @@ function normalize_spaces($string)
{ {
return preg_replace('/\s{2,}/', ' ', trim($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;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 684 B

View file

@ -79,6 +79,7 @@
require_once 'application/PluginManager.php'; require_once 'application/PluginManager.php';
require_once 'application/Router.php'; require_once 'application/Router.php';
require_once 'application/Updater.php'; require_once 'application/Updater.php';
use \Shaarli\ThemeUtils;
// Ensure the PHP version is supported // Ensure the PHP version is supported
try { try {
@ -122,7 +123,6 @@
$conf = new ConfigManager(); $conf = new ConfigManager();
$conf->setEmpty('general.timezone', date_default_timezone_get()); $conf->setEmpty('general.timezone', date_default_timezone_get());
$conf->setEmpty('general.title', 'Shared links on '. escape(index_url($_SERVER))); $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::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory
RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache 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('title', $conf->get('general.title'));
$PAGE->assign('theme', $conf->get('resource.theme')); $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')); $PAGE->assign('redirector', $conf->get('redirector.url'));
list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone')); list($timezone_form, $timezone_js) = generateTimeZoneForm($conf->get('general.timezone'));
$PAGE->assign('timezone_form', $timezone_form); $PAGE->assign('timezone_form', $timezone_form);

View file

@ -331,4 +331,48 @@ public function testCheckCurrentResourcePermissionsErrors()
ApplicationUtils::checkResourcePermissions($conf) 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'));
}
} }

View file

@ -2,6 +2,7 @@
require_once 'application/config/ConfigManager.php'; require_once 'application/config/ConfigManager.php';
require_once 'tests/Updater/DummyUpdater.php'; require_once 'tests/Updater/DummyUpdater.php';
require_once 'inc/rain.tpl.class.php';
/** /**
* Class UpdaterTest. * Class UpdaterTest.

View file

@ -24,7 +24,8 @@
}, },
"resource": { "resource": {
"datastore": "tests\/utils\/config\/datastore.php", "datastore": "tests\/utils\/config\/datastore.php",
"data_dir": "tests\/utils\/config" "data_dir": "tests\/utils\/config",
"raintpl_tpl": "tpl/"
}, },
"plugins": { "plugins": {
"WALLABAG_VERSION": 1 "WALLABAG_VERSION": 1

View file

@ -25,14 +25,15 @@
<td> <td>
<select name="theme" id="theme"> <select name="theme" id="theme">
{loop="$theme_available"} {loop="$theme_available"}
<option value="{$value}"
{if="$value===$theme"} {if="$value===$theme"}
<option selected value="{$value}">{$value|ucfirst}</option> selected="selected"
{else}
<option value="{$value}">{$value|ucfirst}</option>
{/if} {/if}
>
{$value|ucfirst}
</option>
{/loop} {/loop}
</select> </select>
<label for="theme">(default value is: Default)</label>
</td> </td>
</tr> </tr>

View file

@ -28,9 +28,9 @@
</div> </div>
<div class="dailyTitle"> <div class="dailyTitle">
<img src="../../images/floral_left.png" width="51" height="50" class="nomobile" alt="floral_left"> <img src="images/floral_left.png" width="51" height="50" class="nomobile" alt="floral_left">
The Daily Shaarli The Daily Shaarli
<img src="../../images/floral_right.png" width="51" height="50" class="nomobile" alt="floral_right"> <img src="images/floral_right.png" width="51" height="50" class="nomobile" alt="floral_right">
</div> </div>
<div class="dailyDate"> <div class="dailyDate">
@ -50,7 +50,7 @@
<div class="dailyEntry"> <div class="dailyEntry">
<div class="dailyEntryPermalink"> <div class="dailyEntryPermalink">
<a href="?{$value.shorturl}"> <a href="?{$value.shorturl}">
<img src="../../images/squiggle2.png" width="25" height="26" title="permalink" alt="permalink"> <img src="images/squiggle.png" width="25" height="26" title="permalink" alt="permalink">
</a> </a>
</div> </div>
{if="!$hide_timestamps || isLoggedIn()"} {if="!$hide_timestamps || isLoggedIn()"}
@ -94,7 +94,7 @@
{$value} {$value}
{/loop} {/loop}
</div> </div>
<div id="closing"><img src="../../images/squiggle_closing.png" width="66" height="61" alt="-"></div> <div id="closing"><img src="images/squiggle_closing.png" width="66" height="61" alt="-"></div>
</div> </div>
{include="page.footer"} {include="page.footer"}
</body> </body>

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 720 B

After

Width:  |  Height:  |  Size: 720 B

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -6,8 +6,8 @@
<link rel="alternate" type="application/rss+xml" href="{$feedurl}?do=rss{$searchcrits}#" title="RSS Feed" /> <link rel="alternate" type="application/rss+xml" href="{$feedurl}?do=rss{$searchcrits}#" title="RSS Feed" />
<link rel="alternate" type="application/atom+xml" href="{$feedurl}?do=atom{$searchcrits}#" title="ATOM Feed" /> <link rel="alternate" type="application/atom+xml" href="{$feedurl}?do=atom{$searchcrits}#" title="ATOM Feed" />
<link href="images/favicon.ico#" rel="shortcut icon" type="image/x-icon" /> <link href="images/favicon.ico#" rel="shortcut icon" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="inc/reset.css" /> <link type="text/css" rel="stylesheet" href="css/reset.css" />
<link type="text/css" rel="stylesheet" href="inc/shaarli.css" /> <link type="text/css" rel="stylesheet" href="css/shaarli.css" />
{if="is_file('inc/user.css')"}<link type="text/css" rel="stylesheet" href="inc/user.css#" />{/if} {if="is_file('inc/user.css')"}<link type="text/css" rel="stylesheet" href="inc/user.css#" />{/if}
{loop="$plugins_includes.css_files"} {loop="$plugins_includes.css_files"}
<link type="text/css" rel="stylesheet" href="{$value}#"/> <link type="text/css" rel="stylesheet" href="{$value}#"/>