Commit 6b2dfb8c authored by Jonny Bradley's avatar Jonny Bradley

[ENH] Add support for theme options to theme control (categories only so far)

parent 4e3eeea0
......@@ -11,13 +11,17 @@ class ThemeControlLib extends TikiLib {
$this->TikiLib($db);
}
function tc_assign_category($categId, $theme) {
function tc_assign_category($categId, $theme, $option) {
$this->tc_remove_cat($categId);
$query = "delete from `tiki_theme_control_categs` where `categId`=?";
$this->query($query,array($categId),-1,-1,false);
$query = "insert into `tiki_theme_control_categs`(`categId`,`theme`) values(?,?)";
$this->query($query,array($categId,$theme));
$themeoption = $theme;
if ($option) {
$themeoption .= '/'.$option;
}
$this->query($query,array($categId,$themeoption));
}
function tc_assign_section($section, $theme) {
......
......@@ -22,6 +22,7 @@
<tr>
<td class="formcolor">{tr}Category{/tr}</td>
<td class="formcolor">{tr}Theme{/tr}</td>
<td class="formcolor">{tr}Option{/tr}</td>
<td class="formcolor">&nbsp;</td>
</tr>
<tr>
......@@ -33,9 +34,16 @@
</select>
</td>
<td class="formcolor">
<select name="theme">
<select name="theme" onchange="this.form.submit();">
{section name=ix loop=$styles}
<option value="{$styles[ix]|escape}">{$styles[ix]}</option>
<option value="{$styles[ix]|escape}" {if $a_style eq $styles[ix]}selected="selected"{/if}>{$styles[ix]}</option>
{/section}
</select>
</td>
<td class="formcolor">
<select name="theme-option">
{section name=ix loop=$style_options}
<option value="{$style_options[ix]|escape}">{$style_options[ix]}</option>
{/section}
</select>
</td>
......
......@@ -34,7 +34,14 @@ if ($prefs['feature_theme_control'] == 'y') {
if (count($tc_categs)) {
foreach ($tc_categs as $cat) {
if ($cat_theme = $tcontrollib->tc_get_theme_by_categ($cat)) {
$tc_theme = $cat_theme;
$p = strpos($cat_theme, '/'); // theme option starts after a / char
if ($p === false) {
$tc_theme = $cat_theme;
$tc_theme_option = '';
} else {
$tc_theme = substr($cat_theme, 0, $p);
$tc_theme_option = substr($cat_theme, $p+1);
}
$catt=$categlib->get_category($cat);
$smarty->assign_by_ref('category', $catt["name"]);
break;
......@@ -54,13 +61,23 @@ if ($prefs['feature_theme_control'] == 'y') {
if ($tc_theme) {
if ($tikidomain and is_file("styles/$tikidomain/$tc_theme")) {
$headerlib->drop_cssfile('styles/'.$tikidomain.'/'.$prefs['style']);
$headerlib->add_cssfile('styles/'.$tikidomain.'/'.$tc_theme,50);
$headerlib->add_cssfile('styles/'.$tikidomain.'/'.$tc_theme,51);
} else {
$headerlib->drop_cssfile('styles/'.$prefs['style']);
$headerlib->add_cssfile('styles/'.$tc_theme,50);
$headerlib->add_cssfile('styles/'.$tc_theme,51);
}
$stlstl = split("-|\.",$tc_theme);
$style_base = $stlstl[0];
if ($tc_theme_option) {
if ($tikidomain and is_file("styles/$tikidomain/$style_base/options/$tc_theme_option")) {
$headerlib->drop_cssfile('styles/'.$tikidomain.'/'.$prefs['style_option']);
$headerlib->add_cssfile("styles/$tikidomain/$style_base/options/$tc_theme_option",52);
} else {
$headerlib->drop_cssfile('styles/'.$prefs['style_option']);
$headerlib->add_cssfile("styles/$style_base/options/$tc_theme_option",52);
}
}
}
}
......
......@@ -32,11 +32,27 @@ $smarty->assign('categories', $categories);
$list_styles = $tikilib->list_styles();
$smarty->assign_by_ref('styles',$list_styles);
if ($_REQUEST['theme']) {
$a_style = $_REQUEST['theme'];
} else {
$a_style = $prefs['style'];
}
$smarty->assign('a_style', $a_style);
$loplist = $tikilib->list_style_options($a_style);
if (!$loplist) {
$loplist = Array(tra('None'));
}
$smarty->assign_by_ref( "style_options", $loplist);
if (isset($_REQUEST['assigcat'])) {
if (isset($_REQUEST['categId'])) {
check_ticket('theme-control');
$tcontrollib->tc_assign_category($_REQUEST['categId'], $_REQUEST['theme']);
if (!isset($_REQUEST['theme-option']) || $_REQUEST['theme-option'] == tra('None')) {
$option = '';
} else {
$option = $_REQUEST['theme-option'];
}
$tcontrollib->tc_assign_category($_REQUEST['categId'], $_REQUEST['theme'], $option);
} else {
$smarty->assign('msg', tra("Please create a category first"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment