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.
pull/2531/head^2
rabuzarus 2016-04-29 01:49:09 +02:00
rodzic ad2611c92e
commit be1f18146e
5 zmienionych plików z 97 dodań i 12 usunięć

Wyświetl plik

@ -32,6 +32,11 @@ function theme_post(&$a) {
} }
function frio_form(&$a, $arr) { 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 = array();
$scheme_choices["---"] = t("Default"); $scheme_choices["---"] = t("Default");
$files = glob('view/theme/frio/schema/*.php'); $files = glob('view/theme/frio/schema/*.php');
@ -52,12 +57,12 @@ function frio_form(&$a, $arr) {
'$baseurl' => $a->get_baseurl(), '$baseurl' => $a->get_baseurl(),
'$title' => t("Theme settings"), '$title' => t("Theme settings"),
'$schema' => array('frio_schema', t("Select scheme"), $arr["schema"], '', $scheme_choices), '$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_bg' => array_key_exists("nav_bg", $disable) ? "" : 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']), '$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('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors), '$link_color' => array_key_exists("link_color", $disable) ? "" : array('frio_link_color', t('Link color'), $arr['link_color'], '', $link_colors),
'$bgcolor' => array('frio_background_color', t('Set the background color'), $arr['bgcolor']), '$bgcolor' => array_key_exists("bgcolor", $disable) ? "" : 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 )), '$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('frio_background_image', t('Set the background image'), $arr['background_image']), '$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), '$bg_image_options' => Image::get_options($arr),
)); ));

71
php/schema.php 100644
Wyświetl plik

@ -0,0 +1,71 @@
<?php
/**
* @brief: Get info header of the shema
*
* This function parses the header of the shemename.php file for inormations like
* Author, Description and Overwrites. Most of the code comes from the get_plugin_info()
* function. We use this to get the variables which get overwritten through the shema.
* All color variables which get overwritten through the theme have to be
* listed (comma seperated) in the shema header under Overwrites:
* This seemst not to be the best solution. We need to investigate further.
*
* @param string $schema Name of the shema
* @return array With theme information
* 'author' => 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;
}

Wyświetl plik

@ -1,6 +1,7 @@
<?php <?php
/* Licence: AGP /* Licence: AGP
* Author: rabuzarus * Author: rabuzarus
* Overwrites: nav_bg, nav_icon_color, link_color, bgcolor, contentbg_transp, background_image, bg_image_option, link_hover_color
*/ */
$nav_bg = "#000"; $nav_bg = "#000";

Wyświetl plik

@ -1,5 +1,11 @@
<?php <?php
/*
* Name: Red
* Author: Rabuzarus
*
* List here all variables which will get overwritten through this schema
* Overwrites: nav_bg, nav_icon_color, link_color, bgcolor, contentbg_transp
*/
$nav_bg = "#870000"; $nav_bg = "#870000";
$nav_icon_color = "#f5f5f5"; $nav_icon_color = "#f5f5f5";

Wyświetl plik

@ -4,21 +4,23 @@
{{include file="field_select.tpl" field=$schema}} {{include file="field_select.tpl" field=$schema}}
{{include file="field_colorinput.tpl" field=$nav_bg}} {{if $nav_bg}}{{include file="field_colorinput.tpl" field=$nav_bg}}{{/if}}
{{include file="field_colorinput.tpl" field=$nav_icon_color}} {{if $nav_icon_color}}{{include file="field_colorinput.tpl" field=$nav_icon_color}}{{/if}}
{{include file="field_colorinput.tpl" field=$link_color}} {{if $link_color}}{{include file="field_colorinput.tpl" field=$link_color}}{{/if}}
{{include file="field_colorinput.tpl" field=$bgcolor}} {{if $bgcolor}}{{include file="field_colorinput.tpl" field=$bgcolor}}{{/if}}
{{* The slider for the content opacity - We use no template for this since it is only used at this page *}} {{* The slider for the content opacity - We use no template for this since it is only used at this page *}}
{{if $contentbg_transp}}
<div class="form-group field input color"> <div class="form-group field input color">
<label for="id_{{$contentbg_transp.0}}" id="label_{{$contentbg_transp.0}}">{{$contentbg_transp.1}}</label> <label for="id_{{$contentbg_transp.0}}" id="label_{{$contentbg_transp.0}}">{{$contentbg_transp.1}}</label>
<input type="hidden" class="form-control color slider-input" name="{{$contentbg_transp.0}}" id="{{$contentbg_transp.0}}" type="text" value="{{$contentbg_transp.2}}"> <input type="hidden" class="form-control color slider-input" name="{{$contentbg_transp.0}}" id="{{$contentbg_transp.0}}" type="text" value="{{$contentbg_transp.2}}">
<span id="help_{{$contentbg_transp.0}}" class="help-block">{{$contentbg_transp.3}}</span> <span id="help_{{$contentbg_transp.0}}" class="help-block">{{$contentbg_transp.3}}</span>
<div id="end_{{$contentbg_transp.0}}" class="field_end"></div> <div id="end_{{$contentbg_transp.0}}" class="field_end"></div>
</div> </div>
{{/if}}
{{include file="field_colorinput.tpl" field=$background_image}} {{if $background_image}}{{include file="field_colorinput.tpl" field=$background_image}}{{/if}}
<div id="frio_bg_image_options" style="display: none;"> <div id="frio_bg_image_options" style="display: none;">
{{foreach $bg_image_options as $options}} {{foreach $bg_image_options as $options}}