From be1f18146e757cbbe913129af716600555dfb6c8 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 29 Apr 2016 01:49:09 +0200 Subject: [PATCH] theme-settings: hide custom settings if the scheme overwrites it - fixes https://github.com/rabuzarus/frio/issues/9 Note: this isn't a very beautiful solution since the schema developer have to list all overwriting variables in the schema header. We need a better solution for this. --- config.php | 17 ++++++--- php/schema.php | 71 ++++++++++++++++++++++++++++++++++++ schema/love-music.php | 1 + schema/red.php | 8 +++- templates/theme_settings.tpl | 12 +++--- 5 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 php/schema.php diff --git a/config.php b/config.php index 645613363a..0fad473e48 100644 --- a/config.php +++ b/config.php @@ -32,6 +32,11 @@ function theme_post(&$a) { } function frio_form(&$a, $arr) { + require_once("view/theme/frio/php/schema.php"); + + $scheme_info = get_schema_info($arr["schema"]); + $disable = $scheme_info["overwrites"]; + $scheme_choices = array(); $scheme_choices["---"] = t("Default"); $files = glob('view/theme/frio/schema/*.php'); @@ -52,12 +57,12 @@ function frio_form(&$a, $arr) { '$baseurl' => $a->get_baseurl(), '$title' => t("Theme settings"), '$schema' => array('frio_schema', t("Select scheme"), $arr["schema"], '', $scheme_choices), - '$nav_bg' => array('frio_nav_bg', t('Navigation bar background color'), $arr['nav_bg']), - '$nav_icon_color' => array('frio_nav_icon_color', t('Navigation bar icon color '), $arr['nav_icon_color']), - '$link_color' => array('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors), - '$bgcolor' => array('frio_background_color', t('Set the background color'), $arr['bgcolor']), - '$contentbg_transp' => array('frio_contentbg_transp', t("Content background transparency"), ($arr["contentbg_transp"] ? $arr["contentbg_transp"] : 0 )), - '$background_image' => array('frio_background_image', t('Set the background image'), $arr['background_image']), + '$nav_bg' => array_key_exists("nav_bg", $disable) ? "" : array('frio_nav_bg', t('Navigation bar background color'), $arr['nav_bg']), + '$nav_icon_color' => array_key_exists("nav_icon_color", $disable) ? "" : array('frio_nav_icon_color', t('Navigation bar icon color '), $arr['nav_icon_color']), + '$link_color' => array_key_exists("link_color", $disable) ? "" : array('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors), + '$bgcolor' => array_key_exists("bgcolor", $disable) ? "" : array('frio_background_color', t('Set the background color'), $arr['bgcolor']), + '$contentbg_transp' => array_key_exists("contentbg_transp", $disable) ? "" : array('frio_contentbg_transp', t("Content background transparency"), ($arr["contentbg_transp"] ? $arr["contentbg_transp"] : 0 )), + '$background_image' => array_key_exists("background_image", $disable ) ? "" : array('frio_background_image', t('Set the background image'), $arr['background_image']), '$bg_image_options' => Image::get_options($arr), )); diff --git a/php/schema.php b/php/schema.php new file mode 100644 index 0000000000..be3a3bcd97 --- /dev/null +++ b/php/schema.php @@ -0,0 +1,71 @@ + Author Name + * 'description' => Schema description + * 'version' => Schema version + * 'overwrites' => Variables which overwriting custom settings + */ +function get_schema_info($schema){ + + $theme = current_theme(); + $themepath = "view/theme/" . $theme . "/"; + $schema = get_pconfig(local_user(),'frio', 'schema'); + + $info=Array( + 'name' => $schema, + 'description' => "", + 'author' => array(), + 'version' => "", + 'overwrites' => "" + ); + + if (!is_file($themepath . "schema/" . $schema . ".php")) return $info; + + $f = file_get_contents($themepath . "schema/" . $schema . ".php"); + + $r = preg_match("|/\*.*\*/|msU", $f, $m); + + if ($r){ + $ll = explode("\n", $m[0]); + foreach( $ll as $l ) { + $l = trim($l,"\t\n\r */"); + if ($l!=""){ + list($k,$v) = array_map("trim", explode(":",$l,2)); + $k= strtolower($k); + if ($k=="author"){ + $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + if ($r) { + $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]); + } else { + $info['author'][] = array('name'=>$v); + } + } elseif ($k == "overwrites") { + $theme_settings = explode(',',str_replace(' ','', $v)); + foreach ($theme_settings as $key => $value) { + $info["overwrites"][$value] = true; + } + } else { + if (array_key_exists($k,$info)){ + $info[$k]=$v; + } + } + + } + } + + } + return $info; +} diff --git a/schema/love-music.php b/schema/love-music.php index 8908057272..528093e3a9 100644 --- a/schema/love-music.php +++ b/schema/love-music.php @@ -1,6 +1,7 @@ {{$contentbg_transp.3}}
+{{/if}} -{{include file="field_colorinput.tpl" field=$background_image}} +{{if $background_image}}{{include file="field_colorinput.tpl" field=$background_image}}{{/if}}