From 8a89cfb158986dd6be4c820188326f10f0bc1a94 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 15 Aug 2016 22:45:07 -0700 Subject: move schema settings into the display settings main so we can set theme:schema theme selectors in settings --- Zotlabs/Module/Settings.php | 74 +++++++++++++++++++++++------- Zotlabs/Render/Theme.php | 2 +- view/theme/redbasic/php/config.php | 36 +++++++++------ view/theme/redbasic/tpl/theme_settings.tpl | 3 -- view/tpl/settings_display.tpl | 3 ++ 5 files changed, 83 insertions(+), 35 deletions(-) diff --git a/Zotlabs/Module/Settings.php b/Zotlabs/Module/Settings.php index 12157944f..2679b364b 100644 --- a/Zotlabs/Module/Settings.php +++ b/Zotlabs/Module/Settings.php @@ -210,13 +210,21 @@ class Settings extends \Zotlabs\Web\Controller { if((argc() > 1) && (argv(1) == 'display')) { check_form_security_token_redirectOnErr('/settings/display', 'settings_display'); - - $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : \App::$channel['channel_theme']); - $mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme'])) : ''); - $preload_images = ((x($_POST,'preload_images')) ? intval($_POST['preload_images']) : 0); - $user_scalable = ((x($_POST,'user_scalable')) ? intval($_POST['user_scalable']) : 0); - $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile']) : 0); - $title_tosource = ((x($_POST,'title_tosource')) ? intval($_POST['title_tosource']) : 0); + + $themespec = explode(':', \App::$channel['channel_theme']); + $existing_theme = $themespec[0]; + $existing_schema = $themespec[1]; + + $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : $existing_theme); + + if(! $theme) + $theme = 'redbasic'; + + $mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme'])) : ''); + $preload_images = ((x($_POST,'preload_images')) ? intval($_POST['preload_images']) : 0); + $user_scalable = ((x($_POST,'user_scalable')) ? intval($_POST['user_scalable']) : 0); + $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile']) : 0); + $title_tosource = ((x($_POST,'title_tosource')) ? intval($_POST['title_tosource']) : 0); $channel_list_mode = ((x($_POST,'channel_list_mode')) ? intval($_POST['channel_list_mode']) : 0); $network_list_mode = ((x($_POST,'network_list_mode')) ? intval($_POST['network_list_mode']) : 0); @@ -235,8 +243,7 @@ class Settings extends \Zotlabs\Web\Controller { $itemspage = ((x($_POST,'itemspage')) ? intval($_POST['itemspage']) : 20); if($itemspage > 100) $itemspage = 100; - - + if ($mobile_theme == "---") del_pconfig(local_channel(),'system','mobile_theme'); else { @@ -254,16 +261,31 @@ class Settings extends \Zotlabs\Web\Controller { set_pconfig(local_channel(),'system','channel_divmore_height', $channel_divmore_height); set_pconfig(local_channel(),'system','network_divmore_height', $network_divmore_height); - if ($theme == \App::$channel['channel_theme']){ + $newschema = ''; + if($theme == $existing_theme){ // call theme_post only if theme has not been changed if( ($themeconfigfile = $this->get_theme_config_file($theme)) != null){ require_once($themeconfigfile); + if(class_exists(ucfirst($theme) . 'Config')) { + $clsname = ucfirst($theme) . 'Config'; + $theme_config = new $clsname(); + $schemas = $theme_config->get_schemas(); + if(array_key_exists($_POST['schema'],$schemas)) + $newschema = $_POST['schema']; + if($newschema === '---') + $newschema = ''; + } + theme_post($a); } } + + logger('theme: ' . $theme . (($newschema) ? ':' . $newschema : '')); + + $_SESSION['theme'] = $theme . (($newschema) ? ':' . $newschema : ''); $r = q("UPDATE channel SET channel_theme = '%s' WHERE channel_id = %d", - dbesc($theme), + dbesc($theme . (($newschema) ? ':' . $newschema : '')), intval(local_channel()) ); @@ -914,7 +936,6 @@ class Settings extends \Zotlabs\Web\Controller { '$settings_connectors' => $settings_connectors )); - call_hooks('display_settings', $o); return $o; } @@ -923,9 +944,18 @@ class Settings extends \Zotlabs\Web\Controller { */ if((argc() > 1) && (argv(1) === 'display')) { + + $default_theme = get_config('system','theme'); if(! $default_theme) - $default_theme = 'default'; + $default_theme = 'redbasic'; + + $themespec = explode(':', \App::$channel['channel_theme']); + $existing_theme = $themespec[0]; + $existing_schema = $themespec[1]; + + $theme = (($existing_theme) ? $existing_theme : $default_theme); + $default_mobile_theme = get_config('system','mobile_theme'); if(! $mobile_default_theme) $mobile_default_theme = 'none'; @@ -964,7 +994,9 @@ class Settings extends \Zotlabs\Web\Controller { } } - $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']); + + $theme_selected = ((array_key_exists('theme',$_SESSION) && $_SESSION['theme']) ? $_SESSION['theme'] : $theme); + $mobile_theme_selected = (!x($_SESSION,'mobile_theme')? $default_mobile_theme : $_SESSION['mobile_theme']); $preload_images = get_pconfig(local_channel(),'system','preload_images'); @@ -986,10 +1018,17 @@ class Settings extends \Zotlabs\Web\Controller { $title_tosource = (($title_tosource===false)? '0': $title_tosource); // default if not set: 0 $theme_config = ""; - if( ($themeconfigfile = $this->get_theme_config_file($theme_selected)) != null){ + if(($themeconfigfile = $this->get_theme_config_file($theme)) != null){ require_once($themeconfigfile); + if(class_exists(ucfirst($theme) . 'Config')) { + $clsname = ucfirst($theme) . 'Config'; + $theme_config = new $clsname(); + $schemas = $theme_config->get_schemas(); + } $theme_config = theme_content($a); } + +logger('schemas: ' . print_r($schemas,true)); $tpl = get_markup_template("settings_display.tpl"); $o = replace_macros($tpl, array( @@ -1003,6 +1042,8 @@ class Settings extends \Zotlabs\Web\Controller { '$uid' => local_channel(), '$theme' => (($themes) ? array('theme', t('Display Theme:'), $theme_selected, '', $themes, 'preview') : false), + '$schema' => (($schemas) ? array('schema', t('Select scheme'), $existing_schema, '' , $schemas) : ''), + '$mobile_theme' => (($mobile_themes) ? array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, '') : false), '$preload_images' => array('preload_images', t("Preload images before rendering the page"), $preload_images, t("The subjective page load time will be longer but the page will be ready when displayed"), $yes_no), '$user_scalable' => array('user_scalable', t("Enable user zoom on mobile devices"), $user_scalable, '', $yes_no), @@ -1020,7 +1061,8 @@ class Settings extends \Zotlabs\Web\Controller { )); - + + call_hooks('display_settings',$o); return $o; } diff --git a/Zotlabs/Render/Theme.php b/Zotlabs/Render/Theme.php index a8b86f371..a732e4fef 100644 --- a/Zotlabs/Render/Theme.php +++ b/Zotlabs/Render/Theme.php @@ -112,7 +112,7 @@ class Theme { $theme = self::current(); $t = $theme[0]; - $s = ((count($theme) > 1) ? $t[1] : ''); + $s = ((count($theme) > 1) ? $theme[1] : ''); $opts = ''; $opts = ((\App::$profile_uid) ? '?f=&puid=' . \App::$profile_uid : ''); diff --git a/view/theme/redbasic/php/config.php b/view/theme/redbasic/php/config.php index 04cf4f904..8f256bde4 100644 --- a/view/theme/redbasic/php/config.php +++ b/view/theme/redbasic/php/config.php @@ -1,11 +1,30 @@ App::$channel['channel_theme'], '$expert' => $expert, '$title' => t("Theme settings"), - '$schema' => array('redbasic_schema', t('Select scheme'), $arr['schema'], '', $scheme_choices), '$narrow_navbar' => array('redbasic_narrow_navbar',t('Narrow navbar'),$arr['narrow_navbar'], '', array(t('No'),t('Yes'))), '$nav_bg' => array('redbasic_nav_bg', t('Navigation bar background color'), $arr['nav_bg']), '$nav_gradient_top' => array('redbasic_nav_gradient_top', t('Navigation bar gradient top color'), $arr['nav_gradient_top']), diff --git a/view/theme/redbasic/tpl/theme_settings.tpl b/view/theme/redbasic/tpl/theme_settings.tpl index 0ec6d1741..9672d3d05 100644 --- a/view/theme/redbasic/tpl/theme_settings.tpl +++ b/view/theme/redbasic/tpl/theme_settings.tpl @@ -1,6 +1,3 @@ -{{if $theme == redbasic}} -{{include file="field_select.tpl" field=$schema}} -{{/if}} {{include file="field_checkbox.tpl" field=$align_left}} {{include file="field_checkbox.tpl" field=$narrow_navbar}} {{include file="field_input.tpl" field=$converse_width}} diff --git a/view/tpl/settings_display.tpl b/view/tpl/settings_display.tpl index cf79671fd..2e11fdbaa 100755 --- a/view/tpl/settings_display.tpl +++ b/view/tpl/settings_display.tpl @@ -20,6 +20,9 @@ {{if $theme}} {{include file="field_themeselect.tpl" field=$theme}} {{/if}} + {{if $schema}} + {{include file="field_select.tpl" field=$schema}} + {{/if}} {{if $mobile_theme}} {{include file="field_themeselect.tpl" field=$mobile_theme}} {{/if}} -- cgit v1.2.3