]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Minor improvements regarding #705 (coding style, unit tests, etc.)
authorArthurHoaro <arthur@hoa.ro>
Tue, 3 Jan 2017 10:42:21 +0000 (11:42 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 5 Jan 2017 15:16:23 +0000 (16:16 +0100)
20 files changed:
.gitignore
CHANGELOG.md
COPYING
application/ApplicationUtils.php
application/PageBuilder.php
application/Utils.php
images/squiggle.png [deleted file]
index.php
tests/ApplicationUtilsTest.php
tests/Updater/UpdaterTest.php
tests/utils/config/configJson.json.php
tpl/default/configure.html
tpl/default/css/reset.css [moved from tpl/default/inc/reset.css with 100% similarity]
tpl/default/css/shaarli.css [moved from tpl/default/inc/shaarli.css with 100% similarity]
tpl/default/daily.html
tpl/default/images/floral_left.png [moved from images/floral_left.png with 100% similarity]
tpl/default/images/floral_right.png [moved from images/floral_right.png with 100% similarity]
tpl/default/images/squiggle.png [moved from images/squiggle2.png with 100% similarity]
tpl/default/images/squiggle_closing.png [moved from images/squiggle_closing.png with 100% similarity]
tpl/default/includes.html

index 9121905d84603c1943753a4e7bd8d981af6f9aec..19f3dc836873ea5196e2bdece1477de4d4d937c8 100644 (file)
@@ -28,3 +28,7 @@ phpmd.html
 
 # User plugin configuration
 plugins/*/config.php
+
+# 3rd party themes
+tpl/*
+!tpl/default
index fe775b3e61de9c8c426ce637466b5f420261cef1..d3ecc1e61a9c2d9e8825d81c84b82f9994d49281 100644 (file)
@@ -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 22929463e48ee2a32c7caf44649903c813a96483..547ea570d549cc87d720756b926bf46f43b8c273 100644 (file)
--- 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
 
index a0f482b0b9791e0f4c1e28b5406dc4895459a239..cc009a1d25807fe4167750edf4110f6d3a704705 100644 (file)
@@ -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;
+    }
 }
index e226a77d2677d4327bda9370abf26b3c150fab1e..32c7f9f18b01ba131be61bb778dc3d7a9239b727 100644 (file)
@@ -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);
     }
 
     /**
index 7556d3c9a9a46c7011fc68d659d7752531907790..35d652241bb6a5a4c42c7ded7b7381be48dc7f15 100644 (file)
@@ -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 (file)
index a6ce218..0000000
Binary files a/images/squiggle.png and /dev/null differ
index 62d719e1141cd757d18242b93da8c305cec371ef..14754269f38dbbf9df72651f96fd2f282c464040 100644 (file)
--- a/index.php
+++ b/index.php
@@ -79,6 +79,7 @@ require_once 'application/Utils.php';
 require_once 'application/PluginManager.php';
 require_once 'application/Router.php';
 require_once 'application/Updater.php';
+use \Shaarli\ThemeUtils;
 
 // Ensure the PHP version is supported
 try {
@@ -122,7 +123,6 @@ 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)));
-$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);
index 634bd0eda01a76848ef80058aadcfc4db71e6d1c..c39649e81876ca51d518be966f4df639a79d26d0 100644 (file)
@@ -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'));
+    }
 }
index 0171daada17ca4d424fc3ceb811c692b4da7d63c..a1530996bf6ee473ff9bdeab0e2832e742308fd8 100644 (file)
@@ -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.
index 06a302e875b8e61779a0981c85731c63ebb18723..13d38c6680b4a4515192ee0045adcfea05c45b0e 100644 (file)
@@ -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
index 94f6df69bb9dfb6325ff76d5d5a4909a2d665557..e71133b447f34d1b46901c58df44cf56cc8c1900 100644 (file)
         <td>
           <select name="theme" id="theme">
             {loop="$theme_available"}
-              {if="$value===$theme"}
-                <option selected value="{$value}">{$value|ucfirst}</option>
-              {else}
-                <option value="{$value}">{$value|ucfirst}</option>
-              {/if}
+              <option value="{$value}"
+                {if="$value===$theme"}
+                  selected="selected"
+                {/if}
+              >
+                {$value|ucfirst}
+              </option>
             {/loop}
           </select>
-          <label for="theme">(default value is: Default)</label>
         </td>
       </tr>
 
index 024ee32e3fbb3cc426edf832a6ef839229020c4c..e86e90b1e0bd3c13e12a7d4286d62600ed917808 100644 (file)
@@ -28,9 +28,9 @@
     </div>
 
     <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
-        <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 class="dailyDate">
@@ -50,7 +50,7 @@
                     <div class="dailyEntry">
                         <div class="dailyEntryPermalink">
                             <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>
                         </div>
                         {if="!$hide_timestamps || isLoggedIn()"}
@@ -94,7 +94,7 @@
             {$value}
         {/loop}
     </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>
 {include="page.footer"}
 </body>
index 2ff5d8df051ebd69da83bbe69402b265788e0cfa..c3b837f5de350bb683804f1f408767d4afafcf27 100644 (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/atom+xml" href="{$feedurl}?do=atom{$searchcrits}#" title="ATOM Feed" />
 <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="inc/shaarli.css" />
+<link type="text/css" rel="stylesheet" href="css/reset.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}
 {loop="$plugins_includes.css_files"}
 <link type="text/css" rel="stylesheet" href="{$value}#"/>