diff options
Diffstat (limited to 'inc/poche')
-rw-r--r-- | inc/poche/Poche.class.php | 114 |
1 files changed, 69 insertions, 45 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 | } |