diff options
author | redmatrix <git@macgirvin.com> | 2016-05-17 17:46:30 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-17 17:46:30 -0700 |
commit | 20cb4130d47028cbedf09f8da9feb6ccf8f759db (patch) | |
tree | 705d8853724f1555cc797ed85176ad123632bed1 /Zotlabs | |
parent | 51edd472c2e007490bdad3198ba1b2a3d7a09c45 (diff) | |
download | volse-hubzilla-20cb4130d47028cbedf09f8da9feb6ccf8f759db.tar.gz volse-hubzilla-20cb4130d47028cbedf09f8da9feb6ccf8f759db.tar.bz2 volse-hubzilla-20cb4130d47028cbedf09f8da9feb6ccf8f759db.zip |
support work for a long-term fix for issue #390, essentially one can specify a theme:schema string anywhere a theme is input. It will be honoured unless an existing schema setting over-rides this behaviour. This should also be backward compatible but the theme selection code has been cleaned up slightly and there may be subtle differences in behaviour after this commit. On my site this required a page refresh as the first page load after this change was a bit confused.
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Render/Theme.php | 131 | ||||
-rw-r--r-- | Zotlabs/Storage/Browser.php | 8 | ||||
-rw-r--r-- | Zotlabs/Web/Router.php | 8 |
3 files changed, 141 insertions, 6 deletions
diff --git a/Zotlabs/Render/Theme.php b/Zotlabs/Render/Theme.php new file mode 100644 index 000000000..a8b86f371 --- /dev/null +++ b/Zotlabs/Render/Theme.php @@ -0,0 +1,131 @@ +<?php + +namespace Zotlabs\Render; + + +class Theme { + + static $system_theme = null; + static $system_mobile_theme = null; + + static $session_theme = null; + static $session_mobile_theme = null; + + static $base_themes = array('redbasic'); + + static public function current(){ + + self::$system_theme = ((isset(\App::$config['system']['theme'])) + ? \App::$config['system']['theme'] : ''); + self::$session_theme = ((isset($_SESSION) && x($_SESSION,'theme')) + ? $_SESSION['theme'] : self::$system_theme); + self::$system_mobile_theme = ((isset(\App::$config['system']['mobile_theme'])) + ? \App::$config['system']['mobile_theme'] : ''); + self::$session_mobile_theme = ((isset($_SESSION) && x($_SESSION,'mobile_theme')) + ? $_SESSION['mobile_theme'] : self::$system_mobile_theme); + + $page_theme = null; + + // Find the theme that belongs to the channel whose stuff we are looking at + + if(\App::$profile_uid) { + $r = q("select channel_theme from channel where channel_id = %d limit 1", + intval(\App::$profile_uid) + ); + if($r) { + $page_theme = $r[0]['channel_theme']; + } + } + + // Themes from Comanche layouts over-ride the channel theme + + if(array_key_exists('theme', \App::$layout) && \App::$layout['theme']) + $page_theme = \App::$layout['theme']; + + // If the viewer is on a mobile device, ensure that we're using a mobile + // theme of some kind or whatever the viewer's preference is for mobile + // viewing (if applicable) + + if(\App::$is_mobile || \App::$is_tablet) { + if(isset($_SESSION['show_mobile']) && (! $_SESSION['show_mobile'])) { + $chosen_theme = self::$session_theme; + } + else { + $chosen_theme = self::$session_mobile_theme; + + if($chosen_theme === '' || $chosen_theme === '---' ) { + // user has selected to have the mobile theme be the same as the normal one + $chosen_theme = self::$session_theme; + } + } + } + else { + $chosen_theme = self::$session_theme; + + if($page_theme) { + $chosen_theme = $page_theme; + } + } + + // Allow theme selection of the form 'theme_name:schema_name' + + $themepair = explode(':', $chosen_theme); + + if($chosen_theme && (file_exists('view/theme/' . $themepair[0] . '/css/style.css') || file_exists('view/theme/' . $themepair[0] . '/php/style.php'))) { + return($themepair); + } + + foreach(self::$base_themes as $t) { + if(file_exists('view/theme/' . $t . '/css/style.css') || + file_exists('view/theme/' . $t . '/php/style.php')) { + return(array($t)); + } + } + + // Worst case scenario, the default base theme or themes don't exist; perhaps somebody renamed it/them. + + // Find any theme at all and use it. + + $fallback = array_merge(glob('view/theme/*/css/style.css'),glob('view/theme/*/php/style.php')); + if(count($fallback)) + return(array(str_replace('view/theme/','', substr($fallback[0],0,-14)))); + + + } + + + /** + * @brief Return full URL to theme which is currently in effect. + * + * Provide a sane default if nothing is chosen or the specified theme does not exist. + * + * @param bool $installing default false + * + * @return string + */ + + function url($installing = false) { + + if($installing) + return self::$base_themes[0]; + + $theme = self::current(); + + $t = $theme[0]; + $s = ((count($theme) > 1) ? $t[1] : ''); + + $opts = ''; + $opts = ((\App::$profile_uid) ? '?f=&puid=' . \App::$profile_uid : ''); + + $schema_str = ((x(\App::$layout,'schema')) ? '&schema=' . App::$layout['schema'] : ''); + if(($s) && (! $schema_str)) + $schema_str = '&schema=' . $s; + $opts .= $schema_str; + + if(file_exists('view/theme/' . $t . '/php/style.php')) + return('view/theme/' . $t . '/php/style.pcss' . $opts); + + return('view/theme/' . $t . '/css/style.css'); + } +} + diff --git a/Zotlabs/Storage/Browser.php b/Zotlabs/Storage/Browser.php index ca262b739..3556f7f06 100644 --- a/Zotlabs/Storage/Browser.php +++ b/Zotlabs/Storage/Browser.php @@ -246,11 +246,13 @@ class Browser extends DAV\Browser\Plugin { \App::$page['content'] = $html; load_pdl($a); - $theme_info_file = "view/theme/" . current_theme() . "/php/theme.php"; + $current_theme = \Zotlabs\Render\Theme::current(); + + $theme_info_file = "view/theme/" . $current_theme[0] . "/php/theme.php"; if (file_exists($theme_info_file)){ require_once($theme_info_file); - if (function_exists(str_replace('-', '_', current_theme()) . '_init')) { - $func = str_replace('-', '_', current_theme()) . '_init'; + if (function_exists(str_replace('-', '_', $current_theme[0]) . '_init')) { + $func = str_replace('-', '_', $current_theme[0]) . '_init'; $func($a); } } diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index e6733ffdb..f9290ac30 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -206,13 +206,15 @@ class Router { * load current theme info */ - $theme_info_file = 'view/theme/' . current_theme() . '/php/theme.php'; + $current_theme = \Zotlabs\Render\Theme::current(); + + $theme_info_file = 'view/theme/' . $current_theme[0] . '/php/theme.php'; if (file_exists($theme_info_file)){ require_once($theme_info_file); } - if(function_exists(str_replace('-', '_', current_theme()) . '_init')) { - $func = str_replace('-', '_', current_theme()) . '_init'; + if(function_exists(str_replace('-', '_', $current_theme[0]) . '_init')) { + $func = str_replace('-', '_', $current_theme[0]) . '_init'; $func($a); } elseif (x(\App::$theme_info, 'extends') && file_exists('view/theme/' . \App::$theme_info['extends'] . '/php/theme.php')) { |