move schema settings into the display settings main so we can set theme:schema theme selectors in settings

This commit is contained in:
redmatrix 2016-08-15 22:45:07 -07:00
parent 7fc254a81c
commit 8a89cfb158
5 changed files with 83 additions and 35 deletions

View File

@ -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;
}

View File

@ -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 : '');

View File

@ -1,11 +1,30 @@
<?php
class RedbasicConfig {
function get_schemas() {
$scheme_choices = array();
$scheme_choices["---"] = t("Focus (Hubzilla default)");
$files = glob('view/theme/redbasic/schema/*.php');
if($files) {
foreach($files as $file) {
$f = basename($file, ".php");
if($f != 'default') {
$scheme_name = $f;
$scheme_choices[$f] = $scheme_name;
}
}
}
return $scheme_choices;
}
}
function theme_content(&$a) {
if(!local_channel()) { return;}
$arr = array();
$arr['schema'] = get_pconfig(local_channel(),'redbasic', 'schema' );
// $arr['schema'] = get_pconfig(local_channel(),'redbasic', 'schema' );
$arr['narrow_navbar'] = get_pconfig(local_channel(),'redbasic', 'narrow_navbar' );
$arr['nav_bg'] = get_pconfig(local_channel(),'redbasic', 'nav_bg' );
$arr['nav_gradient_top'] = get_pconfig(local_channel(),'redbasic', 'nav_gradient_top' );
@ -42,7 +61,7 @@ function theme_post(&$a) {
if(!local_channel()) { return;}
if (isset($_POST['redbasic-settings-submit'])) {
set_pconfig(local_channel(), 'redbasic', 'schema', $_POST['redbasic_schema']);
// set_pconfig(local_channel(), 'redbasic', 'schema', $_POST['redbasic_schema']);
set_pconfig(local_channel(), 'redbasic', 'narrow_navbar', $_POST['redbasic_narrow_navbar']);
set_pconfig(local_channel(), 'redbasic', 'nav_bg', $_POST['redbasic_nav_bg']);
set_pconfig(local_channel(), 'redbasic', 'nav_gradient_top', $_POST['redbasic_nav_gradient_top']);
@ -78,18 +97,6 @@ function theme_post(&$a) {
function redbasic_form(&$a, $arr) {
$scheme_choices = array();
$scheme_choices["---"] = t("Focus (Hubzilla default)");
$files = glob('view/theme/redbasic/schema/*.php');
if($files) {
foreach($files as $file) {
$f = basename($file, ".php");
if($f != 'default') {
$scheme_name = $f;
$scheme_choices[$f] = $scheme_name;
}
}
}
if(feature_enabled(local_channel(),'expert'))
$expert = 1;
@ -101,7 +108,6 @@ if(feature_enabled(local_channel(),'expert'))
'$theme' => 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']),

View File

@ -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}}

View File

@ -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}}