aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-01-28 11:19:06 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@gmail.com>2014-01-28 11:19:06 +0100
commitf4fbfaa7cbaaf07aae7d8f0533d293fa4dc605cc (patch)
tree6abda8e30037bd3033c8142d7592e62988fc7eed
parent21f50d5a08381d0d2f27d36b0d97a4f518eeefcb (diff)
downloadwallabag-f4fbfaa7cbaaf07aae7d8f0533d293fa4dc605cc.tar.gz
wallabag-f4fbfaa7cbaaf07aae7d8f0533d293fa4dc605cc.tar.zst
wallabag-f4fbfaa7cbaaf07aae7d8f0533d293fa4dc605cc.zip
some fix to courgette theme
-rw-r--r--inc/poche/Poche.class.php114
-rwxr-xr-xthemes/courgette/_top.twig2
-rwxr-xr-xthemes/courgette/config.twig4
-rw-r--r--themes/courgette/img/logo.svg8
-rw-r--r--themes/courgette/theme.ini3
-rw-r--r--themes/dark/theme.ini2
-rw-r--r--themes/default/config.twig4
-rw-r--r--themes/default/theme.ini1
-rw-r--r--themes/dmagenta/theme.ini2
-rw-r--r--themes/solarized-dark/theme.ini2
-rw-r--r--themes/solarized/theme.ini2
11 files changed, 94 insertions, 50 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 0be1668d..e9b14121 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -22,16 +22,6 @@ class Poche
22 private $currentTheme = ''; 22 private $currentTheme = '';
23 private $currentLanguage = ''; 23 private $currentLanguage = '';
24 private $notInstalledMessage = array(); 24 private $notInstalledMessage = array();
25
26 # @todo make this dynamic (actually install themes and save them in the database including author information et cetera)
27 private $installedThemes = array(
28 'default' => array('requires' => array()),
29 'dark' => array('requires' => array('default')),
30 'dmagenta' => array('requires' => array('default')),
31 'solarized' => array('requires' => array('default')),
32 'solarized-dark' => array('requires' => array('default')),
33 'courgette' => array('requires' => array())
34 );
35 25
36 public function __construct() 26 public function __construct()
37 { 27 {
@@ -124,21 +114,26 @@ class Poche
124 } 114 }
125 115
126 # Check if the selected theme and its requirements are present 116 # Check if the selected theme and its requirements are present
127 if ($this->getTheme() != '' && ! is_dir(THEME . '/' . $this->getTheme())) { 117 $theme = $this->getTheme();
128 $this->notInstalledMessage[] = 'The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $this->getTheme() . ')'; 118
119 if ($theme != '' && ! is_dir(THEME . '/' . $theme)) {
120 $this->notInstalledMessage[] = 'The currently selected theme (' . $theme . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $theme . ')';
129 121
130 self::$canRenderTemplates = false; 122 self::$canRenderTemplates = false;
131 123
132 $passTheme = FALSE; 124 $passTheme = FALSE;
133 } 125 }
134 126
135 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) { 127 $themeInfo = $this->getThemeInfo($theme);
136 if (! is_dir(THEME . '/' . $requiredTheme)) { 128 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) {
137 $this->notInstalledMessage[] = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')'; 129 foreach ($themeInfo['requirements'] as $requiredTheme) {
130 if (! is_dir(THEME . '/' . $requiredTheme)) {
131 $this->notInstalledMessage[] = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $theme . ')';
138 132
139 self::$canRenderTemplates = false; 133 self::$canRenderTemplates = false;
140 134
141 $passTheme = FALSE; 135 $passTheme = FALSE;
136 }
142 } 137 }
143 } 138 }
144 139
@@ -194,32 +189,36 @@ class Poche
194 private function initTpl() 189 private function initTpl()
195 { 190 {
196 $loaderChain = new Twig_Loader_Chain(); 191 $loaderChain = new Twig_Loader_Chain();
192 $theme = $this->getTheme();
197 193
198 # add the current theme as first to the loader chain so Twig will look there first for overridden template files 194 # add the current theme as first to the loader chain so Twig will look there first for overridden template files
199 try { 195 try {
200 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $this->getTheme())); 196 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $theme));
201 } catch (Twig_Error_Loader $e) { 197 } catch (Twig_Error_Loader $e) {
202 # @todo isInstalled() should catch this, inject Twig later 198 # @todo isInstalled() should catch this, inject Twig later
203 die('The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (' . THEME . '/' . $this->getTheme() .' is missing)'); 199 die('The currently selected theme (' . $theme . ') does not seem to be properly installed (' . THEME . '/' . $theme .' is missing)');
204 } 200 }
205 201
206 # add all required themes to the loader chain 202 # add all required themes to the loader chain
207 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) { 203 $themeInfo = $this->getThemeInfo($theme);
208 try { 204 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) {
209 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . DEFAULT_THEME)); 205 foreach ($themeInfo['requirements'] as $requiredTheme) {
210 } catch (Twig_Error_Loader $e) { 206 try {
211 # @todo isInstalled() should catch this, inject Twig later 207 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $requiredTheme));
212 die('The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')'); 208 } catch (Twig_Error_Loader $e) {
209 # @todo isInstalled() should catch this, inject Twig later
210 die('The required "' . $requiredTheme . '" theme is missing for the current theme (' . $theme . ')');
211 }
213 } 212 }
214 } 213 }
215 214
216 if (DEBUG_POCHE) { 215 if (DEBUG_POCHE) {
217 $twig_params = array(); 216 $twigParams = array();
218 } else { 217 } else {
219 $twig_params = array('cache' => CACHE); 218 $twigParams = array('cache' => CACHE);
220 } 219 }
221 220
222 $this->tpl = new Twig_Environment($loaderChain, $twig_params); 221 $this->tpl = new Twig_Environment($loaderChain, $twigParams);
223 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); 222 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
224 223
225 # filter to display domain name of an url 224 # filter to display domain name of an url
@@ -235,7 +234,7 @@ class Poche
235 $this->tpl->addFilter($filter); 234 $this->tpl->addFilter($filter);
236 } 235 }
237 236
238 private function install() 237 private function install()
239 { 238 {
240 Tools::logm('poche still not installed'); 239 Tools::logm('poche still not installed');
241 echo $this->tpl->render('install.twig', array( 240 echo $this->tpl->render('install.twig', array(
@@ -266,34 +265,59 @@ class Poche
266 return $this->currentTheme; 265 return $this->currentTheme;
267 } 266 }
268 267
269 public function getLanguage() { 268 /**
270 return $this->currentLanguage; 269 * Provides theme information by parsing theme.ini file if present in the theme's root directory.
270 * In all cases, the following data will be returned:
271 * - name: theme's name, or key if the theme is unnamed,
272 * - current: boolean informing if the theme is the current user theme.
273 *
274 * @param string $theme Theme key (directory name)
275 * @return array|boolean Theme information, or false if the theme doesn't exist.
276 */
277 public function getThemeInfo($theme) {
278 if (!is_dir(THEME . '/' . $theme)) {
279 return false;
280 }
281
282 $themeIniFile = THEME . '/' . $theme . '/theme.ini';
283 $themeInfo = array();
284
285 if (is_file($themeIniFile) && is_readable($themeIniFile)) {
286 $themeInfo = parse_ini_file($themeIniFile);
287 }
288
289 if ($themeInfo === false) {
290 $themeInfo = array();
291 }
292 if (!isset($themeInfo['name'])) {
293 $themeInfo['name'] = $theme;
294 }
295 $themeInfo['current'] = ($theme === $this->getTheme());
296
297 return $themeInfo;
271 } 298 }
272 299
273 public function getInstalledThemes() { 300 public function getInstalledThemes() {
274 $handle = opendir(THEME); 301 $handle = opendir(THEME);
275 $themes = array(); 302 $themes = array();
276 303
277 while (($theme = readdir($handle)) !== false) { 304 while (($theme = readdir($handle)) !== false) {
278 # Themes are stored in a directory, so all directory names are themes 305 # Themes are stored in a directory, so all directory names are themes
279 # @todo move theme installation data to database 306 # @todo move theme installation data to database
280 if (! is_dir(THEME . '/' . $theme) || in_array($theme, array('..', '.'))) { 307 if (!is_dir(THEME . '/' . $theme) || in_array($theme, array('.', '..'))) {
281 continue; 308 continue;
282 } 309 }
283 310
284 $current = false; 311 $themes[$theme] = $this->getThemeInfo($theme);
285
286 if ($theme === $this->getTheme()) {
287 $current = true;
288 }
289
290 $themes[] = array('name' => $theme, 'current' => $current);
291 } 312 }
292 313
293 sort($themes);
294 return $themes; 314 return $themes;
295 } 315 }
296 316
317 public function getLanguage() {
318 return $this->currentLanguage;
319 }
320
297 public function getInstalledLanguages() { 321 public function getInstalledLanguages() {
298 $handle = opendir(LOCALE); 322 $handle = opendir(LOCALE);
299 $languages = array(); 323 $languages = array();
@@ -600,8 +624,8 @@ class Poche
600 $themes = $this->getInstalledThemes(); 624 $themes = $this->getInstalledThemes();
601 $actualTheme = false; 625 $actualTheme = false;
602 626
603 foreach ($themes as $theme) { 627 foreach (array_keys($themes) as $theme) {
604 if ($theme['name'] == $_POST['theme']) { 628 if ($theme == $_POST['theme']) {
605 $actualTheme = true; 629 $actualTheme = true;
606 break; 630 break;
607 } 631 }
diff --git a/themes/courgette/_top.twig b/themes/courgette/_top.twig
index a2a4b28d..792687c0 100755
--- a/themes/courgette/_top.twig
+++ b/themes/courgette/_top.twig
@@ -1,6 +1,6 @@
1 <header> 1 <header>
2 <h1> 2 <h1>
3 {% if view == 'home' %}{% block logo %}<img src="{{ poche_url }}/themes/{{ constant('DEFAULT_THEME') }}/img/logo.png" alt="logo poche" />{% endblock %} 3 {% if view == 'home' %}{% block logo %}<img src="{{ poche_url }}/themes/{{ constant('DEFAULT_THEME') }}/img/logo.svg" alt="logo poche" />{% endblock %}
4 {% elseif view == 'fav' %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }} <span>Favoris</span></a> 4 {% elseif view == 'fav' %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }} <span>Favoris</span></a>
5 {% elseif view == 'archive' %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }} <span>Archive</span></a> 5 {% elseif view == 'archive' %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }} <span>Archive</span></a>
6 {% else %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }}</a> 6 {% else %}<a href="./" title="{% trans "back to home" %}" >{{ block('logo') }}</a>
diff --git a/themes/courgette/config.twig b/themes/courgette/config.twig
index fdeb464b..3ab1d92f 100755
--- a/themes/courgette/config.twig
+++ b/themes/courgette/config.twig
@@ -35,8 +35,8 @@
35 <div class="row"> 35 <div class="row">
36 <label class="col w150p" for="theme">{% trans "Theme:" %}</label> 36 <label class="col w150p" for="theme">{% trans "Theme:" %}</label>
37 <select class="col" id="theme" name="theme"> 37 <select class="col" id="theme" name="theme">
38 {% for theme in themes %} 38 {% for key, theme in themes %}
39 <option value="{{ theme.name }}" {{ theme.current ? 'selected' : '' }}>{{ theme.name }}</option> 39 <option value="{{ key }}" {{ theme.current ? 'selected' : '' }}>{{ theme.name }}</option>
40 {% endfor %} 40 {% endfor %}
41 </select> 41 </select>
42 </div> 42 </div>
diff --git a/themes/courgette/img/logo.svg b/themes/courgette/img/logo.svg
new file mode 100644
index 00000000..865da440
--- /dev/null
+++ b/themes/courgette/img/logo.svg
@@ -0,0 +1,8 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="64" height="64">
3 <circle cx="32" cy="32" r="29.5" style="fill:#000" />
4 <path d="m 16,18 33,0 0,26 -16.5,6 -16.5,-6 z" fill="#fff" />
5 <rect width="9" height="2.5" x="17.5" y="24.5" fill="#000" />
6 <rect width="9" height="2.5" x="28" y="24.5" fill="#000" />
7 <rect width="9" height="2.5" x="38.5" y="24.5" fill="#000" />
8</svg>
diff --git a/themes/courgette/theme.ini b/themes/courgette/theme.ini
new file mode 100644
index 00000000..996d171f
--- /dev/null
+++ b/themes/courgette/theme.ini
@@ -0,0 +1,3 @@
1name = Courgette
2description = Responsive black and white theme especially adapted to smartphones.
3requirements[] = default
diff --git a/themes/dark/theme.ini b/themes/dark/theme.ini
new file mode 100644
index 00000000..4b020d36
--- /dev/null
+++ b/themes/dark/theme.ini
@@ -0,0 +1,2 @@
1name = Dark
2requirements[] = default
diff --git a/themes/default/config.twig b/themes/default/config.twig
index ada238d6..df62520a 100644
--- a/themes/default/config.twig
+++ b/themes/default/config.twig
@@ -49,8 +49,8 @@
49 <div class="row"> 49 <div class="row">
50 <label class="col w150p" for="theme">{% trans "Theme:" %}</label> 50 <label class="col w150p" for="theme">{% trans "Theme:" %}</label>
51 <select class="col" id="theme" name="theme"> 51 <select class="col" id="theme" name="theme">
52 {% for theme in themes %} 52 {% for key, theme in themes %}
53 <option value="{{ theme.name }}" {{ theme.current ? 'selected' : '' }}>{{ theme.name }}</option> 53 <option value="{{ key }}" {{ theme.current ? 'selected' : '' }}>{{ theme.name }}</option>
54 {% endfor %} 54 {% endfor %}
55 </select> 55 </select>
56 </div> 56 </div>
diff --git a/themes/default/theme.ini b/themes/default/theme.ini
new file mode 100644
index 00000000..9f3cfb6a
--- /dev/null
+++ b/themes/default/theme.ini
@@ -0,0 +1 @@
name = Default \ No newline at end of file
diff --git a/themes/dmagenta/theme.ini b/themes/dmagenta/theme.ini
new file mode 100644
index 00000000..24ff3c4a
--- /dev/null
+++ b/themes/dmagenta/theme.ini
@@ -0,0 +1,2 @@
1name = Dark Magenta
2requirements[] = default
diff --git a/themes/solarized-dark/theme.ini b/themes/solarized-dark/theme.ini
new file mode 100644
index 00000000..7b6b341e
--- /dev/null
+++ b/themes/solarized-dark/theme.ini
@@ -0,0 +1,2 @@
1name = Dark Solarized
2requirements[] = default
diff --git a/themes/solarized/theme.ini b/themes/solarized/theme.ini
new file mode 100644
index 00000000..703997b9
--- /dev/null
+++ b/themes/solarized/theme.ini
@@ -0,0 +1,2 @@
1name = Solarized
2requirements[] = default