aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Render/Theme.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Render/Theme.php')
-rw-r--r--Zotlabs/Render/Theme.php56
1 files changed, 36 insertions, 20 deletions
diff --git a/Zotlabs/Render/Theme.php b/Zotlabs/Render/Theme.php
index 9f9009d72..09cc7a4d4 100644
--- a/Zotlabs/Render/Theme.php
+++ b/Zotlabs/Render/Theme.php
@@ -2,6 +2,8 @@
namespace Zotlabs\Render;
+use App;
+
class Theme {
@@ -11,17 +13,28 @@ class Theme {
static $session_theme = null;
static $session_mobile_theme = null;
- static $base_themes = array('redbasic');
+ /**
+ * @brief Array with base or fallback themes.
+ */
+ static $base_themes = array('redbasic');
+
+ /**
+ * @brief Figure out the best matching theme and return it.
+ *
+ * The theme will depend on channel settings, mobile, session, core compatibility, etc.
+ *
+ * @return array
+ */
static public function current(){
- self::$system_theme = ((isset(\App::$config['system']['theme']))
+ self::$system_theme = ((isset(\App::$config['system']['theme']))
? \App::$config['system']['theme'] : '');
- self::$session_theme = ((isset($_SESSION) && x($_SESSION,'theme'))
+ self::$session_theme = ((isset($_SESSION) && x($_SESSION, 'theme'))
? $_SESSION['theme'] : self::$system_theme);
- self::$system_mobile_theme = ((isset(\App::$config['system']['mobile_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'))
+ self::$session_mobile_theme = ((isset($_SESSION) && x($_SESSION, 'mobile_theme'))
? $_SESSION['mobile_theme'] : self::$system_mobile_theme);
$page_theme = null;
@@ -66,13 +79,19 @@ class Theme {
$chosen_theme = $page_theme;
}
}
- if(array_key_exists('theme_preview',$_GET))
+ if(array_key_exists('theme_preview', $_GET))
$chosen_theme = $_GET['theme_preview'];
// Allow theme selection of the form 'theme_name:schema_name'
-
$themepair = explode(':', $chosen_theme);
+ // Check if $chosen_theme is compatible with core. If not fall back to default
+ $info = get_theme_info($themepair[0]);
+ $compatible = check_plugin_versions($info);
+ if(!$compatible) {
+ $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);
}
@@ -85,14 +104,12 @@ class Theme {
}
// 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))));
+ // 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))));
}
@@ -101,12 +118,11 @@ class Theme {
*
* Provide a sane default if nothing is chosen or the specified theme does not exist.
*
- * @param bool $installing default false
+ * @param bool $installing (optional) default false, if true return the name of the first base theme
*
* @return string
*/
-
- function url($installing = false) {
+ static public function url($installing = false) {
if($installing)
return self::$base_themes[0];
@@ -119,21 +135,21 @@ class Theme {
$opts = '';
$opts = ((\App::$profile_uid) ? '?f=&puid=' . \App::$profile_uid : '');
- $schema_str = ((x(\App::$layout,'schema')) ? '&schema=' . App::$layout['schema'] : '');
+ $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 . '/php/style.pcss' . $opts);
- return('view/theme/' . $t . '/css/style.css');
+ return('/view/theme/' . $t . '/css/style.css');
}
function debug() {
logger('system_theme: ' . self::$system_theme);
logger('session_theme: ' . self::$session_theme);
-
}
}