]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Change templates set through administration UI
authorKnah Tsaeb <Knah-Tsaeb@knah-tsaeb.org>
Wed, 7 Dec 2016 10:58:25 +0000 (11:58 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 5 Jan 2017 11:04:02 +0000 (12:04 +0100)
41 files changed:
application/ApplicationUtils.php
application/PageBuilder.php
application/Utils.php
application/config/ConfigManager.php
application/config/ConfigPhp.php
index.php
tests/ApplicationUtilsTest.php
tpl/default/404.html [moved from tpl/404.html with 100% similarity]
tpl/default/addlink.html [moved from tpl/addlink.html with 100% similarity]
tpl/default/changepassword.html [moved from tpl/changepassword.html with 100% similarity]
tpl/default/changetag.html [moved from tpl/changetag.html with 94% similarity]
tpl/default/configure.html [moved from tpl/configure.html with 88% similarity]
tpl/default/daily.html [moved from tpl/daily.html with 88% similarity]
tpl/default/dailyrss.html [moved from tpl/dailyrss.html with 100% similarity]
tpl/default/editlink.html [moved from tpl/editlink.html with 97% similarity]
tpl/default/export.bookmarks.html [moved from tpl/export.bookmarks.html with 100% similarity]
tpl/default/export.html [moved from tpl/export.html with 100% similarity]
tpl/default/feed.atom.html [moved from tpl/feed.atom.html with 100% similarity]
tpl/default/feed.rss.html [moved from tpl/feed.rss.html with 100% similarity]
tpl/default/images/50pc_transparent.png [moved from images/50pc_transparent.png with 100% similarity]
tpl/default/images/Paper_texture_v5_by_bashcorpo_w1000.jpg [moved from images/Paper_texture_v5_by_bashcorpo_w1000.jpg with 100% similarity]
tpl/default/images/calendar.png [moved from images/calendar.png with 100% similarity]
tpl/default/images/private.png [moved from images/private.png with 100% similarity]
tpl/default/images/tag_blue.png [moved from images/tag_blue.png with 100% similarity]
tpl/default/import.html [moved from tpl/import.html with 100% similarity]
tpl/default/inc/reset.css [moved from inc/reset.css with 100% similarity]
tpl/default/inc/shaarli.css [moved from inc/shaarli.css with 99% similarity]
tpl/default/includes.html [moved from tpl/includes.html with 83% similarity]
tpl/default/install.html [moved from tpl/install.html with 100% similarity]
tpl/default/linklist.html [moved from tpl/linklist.html with 98% similarity]
tpl/default/linklist.paging.html [moved from tpl/linklist.paging.html with 100% similarity]
tpl/default/loginform.html [moved from tpl/loginform.html with 100% similarity]
tpl/default/opensearch.html [moved from tpl/opensearch.html with 100% similarity]
tpl/default/page.footer.html [moved from tpl/page.footer.html with 100% similarity]
tpl/default/page.header.html [moved from tpl/page.header.html with 100% similarity]
tpl/default/page.html [moved from tpl/page.html with 100% similarity]
tpl/default/picwall.html [moved from tpl/picwall.html with 100% similarity]
tpl/default/pluginsadmin.html [moved from tpl/pluginsadmin.html with 100% similarity]
tpl/default/readme.txt [moved from tpl/readme.txt with 100% similarity]
tpl/default/tagcloud.html [moved from tpl/tagcloud.html with 100% similarity]
tpl/default/tools.html [moved from tpl/tools.html with 100% similarity]

index 7f963e9786cc50901863789341bc802ed1e22403..a0f482b0b9791e0f4c1e28b5406dc4895459a239 100644 (file)
@@ -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';
index 32c7f9f18b01ba131be61bb778dc3d7a9239b727..e226a77d2677d4327bda9370abf26b3c150fab1e 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('conf', $this->conf);
+        $this->tpl->assign('theme', $this->conf->get('resource.theme', 'default'));
     }
 
     /**
index 35d652241bb6a5a4c42c7ded7b7381be48dc7f15..7556d3c9a9a46c7011fc68d659d7752531907790 100644 (file)
@@ -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;
+}
index ca8918b52b2be8693bc53397cad247e72f3661b4..a401887c5367389e34785a8dd7d7c5c906238f41 100644 (file)
@@ -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');
index 27187b662f34c3e984d1097776017050e88c4d6a..2eb68d80a5b9d517a7f0eb36f112d0124df5b0e4 100644 (file)
@@ -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;
index 2ed14d4f2f3ac67ed6bd5e041fc434b27a7aa050..62d719e1141cd757d18242b93da8c305cec371ef 100644 (file)
--- 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);
index 861b8d4e506533c1f155f6542018692f64aaea67..634bd0eda01a76848ef80058aadcfc4db71e6d1c 100644 (file)
@@ -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',
similarity index 100%
rename from tpl/404.html
rename to tpl/default/404.html
similarity index 100%
rename from tpl/addlink.html
rename to tpl/default/addlink.html
similarity index 94%
rename from tpl/changetag.html
rename to tpl/default/changetag.html
index 13cc5cf1ede43a62815f4f18c225face60ce154b..a0df3328ed67d1529b8d1a81c0ab2eaae25c72fc 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>{include="includes"}
-    <link type="text/css" rel="stylesheet" href="../inc/awesomplete.css" />
+    <link type="text/css" rel="stylesheet" href="inc/awesomplete.css#" />
     <script src="inc/awesomplete.min.js#"></script>
 </head>
 <body onload="document.changetag.fromtag.focus();">
similarity index 88%
rename from tpl/configure.html
rename to tpl/default/configure.html
index b4197bf9faee7d6b07b552c0250cd6cd757b1222..94f6df69bb9dfb6325ff76d5d5a4909a2d665557 100644 (file)
         <td><input type="text" name="titleLink" id="titleLink" size="50" value="{$titleLink}"><br/><label
             for="titleLink">(default value is: ?)</label></td>
       </tr>
+
+      <tr>
+        <td><b>Theme:</b></td>
+        <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}
+            {/loop}
+          </select>
+          <label for="theme">(default value is: Default)</label>
+        </td>
+      </tr>
+
       <tr>
         <td><b>Timezone:</b></td>
         <td>{$timezone_form}</td>
similarity index 88%
rename from tpl/daily.html
rename to tpl/default/daily.html
index eba0af3bfcb290a114874ac4f7625a8260aa146d..024ee32e3fbb3cc426edf832a6ef839229020c4c 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/squiggle2.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>
similarity index 100%
rename from tpl/dailyrss.html
rename to tpl/default/dailyrss.html
similarity index 97%
rename from tpl/editlink.html
rename to tpl/default/editlink.html
index 870cc1688ac4d3ffb29f4b17bbb65b658a910b02..d3f99fe6482c75ad7fbe23e79a5f2d60b0b87e28 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>{include="includes"}
-    <link type="text/css" rel="stylesheet" href="../inc/awesomplete.css" />
+    <link type="text/css" rel="stylesheet" href="inc/awesomplete.css#" />
 </head>
 <body
 {if="$link.title==''"}onload="document.linkform.lf_title.focus();"
similarity index 100%
rename from tpl/export.html
rename to tpl/default/export.html
similarity index 100%
rename from tpl/feed.rss.html
rename to tpl/default/feed.rss.html
similarity index 100%
rename from tpl/import.html
rename to tpl/default/import.html
similarity index 100%
rename from inc/reset.css
rename to tpl/default/inc/reset.css
similarity index 99%
rename from inc/shaarli.css
rename to tpl/default/inc/shaarli.css
index a24d4b7c1e384cfc72a03000e462263063c77fb0..45890f626822d47e13476bc9502fd800ac299bda 100644 (file)
@@ -103,7 +103,7 @@ strong {
 }
 
 #pageheader #logo {
-    background-image: url('../images/logo.png');
+    background-image: url('../../../images/logo.png');
     background-repeat: no-repeat;
     float: left;
     margin: 0 10px 0 10px;
similarity index 83%
rename from tpl/includes.html
rename to tpl/default/includes.html
index 7b2997ce45e73b8dd8ce7df72dd3ba93a08d3864..2ff5d8df051ebd69da83bbe69402b265788e0cfa 100644 (file)
@@ -6,9 +6,9 @@
 <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" />
-{if="is_file('inc/user.css')"}<link type="text/css" rel="stylesheet" href="../inc/user.css" />{/if}
+<link type="text/css" rel="stylesheet" href="inc/reset.css" />
+<link type="text/css" rel="stylesheet" href="inc/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}#"/>
 {/loop}
similarity index 100%
rename from tpl/install.html
rename to tpl/default/install.html
similarity index 98%
rename from tpl/linklist.html
rename to tpl/default/linklist.html
index d42323423bc3411bc75de98ecda8bf0ead6cb6ac..5accc92fa4eed0367a187c3509d27e943ffd50fd 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
-    <link type="text/css" rel="stylesheet" href="../inc/awesomplete.css" />
+    <link type="text/css" rel="stylesheet" href="inc/awesomplete.css#" />
     {include="includes"}
 </head>
 <body>
similarity index 100%
rename from tpl/page.html
rename to tpl/default/page.html
similarity index 100%
rename from tpl/picwall.html
rename to tpl/default/picwall.html
similarity index 100%
rename from tpl/readme.txt
rename to tpl/default/readme.txt
similarity index 100%
rename from tpl/tagcloud.html
rename to tpl/default/tagcloud.html
similarity index 100%
rename from tpl/tools.html
rename to tpl/default/tools.html