Owen Stubbs wrote:Because if Bulletproof (or any other theme) had BOTH the dynamic nav bar, AND this code to set additional variables, barring any discovery of a single serendipity_loadThemeOptions that serves both purposes, it would be called twice - once for the dynamic navbar, and once for the additional variables.
Hm, I just tried something which
seems to work and needs only
one serendipity_loadThemeOptions ... (beware, looong config.inc.php post coming up!):
Code: Select all
<?php
// Be nice to the frontend users. They don't need the additional constants
// and file lookups. Only load them when in Admin mode.
if ($serendipity['GET']['adminModule'] == 'templates' || $serendipity['POST']['adminModule'] != 'templates') {
// Probe for a language include with constants. Still include defines
// later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
}
$serendipity['smarty']->assign(array('currpage'=> "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
$template_config = array(
array(
'var' => 'colorset',
'name' => THEME_COLORSET,
'description' => THEME_COLORSET_DESC,
'type' => 'select',
'default' => 'red',
'select_values' => array('red' => 'Red',
'blue' => 'Blue')
),
array(
'var' => 'layouttype',
'name' => LAYOUT_TYPE,
'description' => LAYOUT_TYPE_DESC,
'type' => 'select',
'default' => '3col',
'select_values' => array('3col' => LAYOUT_THREE,
'2coll' => LAYOUT_TWOLEFT,
'2colr' => LAYOUT_TWORIGHT)
),
array(
'var' => 'firbtitle',
'name' => FIR_BTITLE,
'description' => FIR_BTITLE_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'firbdescr',
'name' => FIR_BDESCR,
'description' => FIR_BDESCR_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'entryfooterpos',
'name' => ENTRY_FOOTER_POS,
'description' => ENTRY_FOOTER_POS_DESC,
'type' => 'select',
'default' => 'belowentry',
'select_values' => array('belowentry' => BELOW_ENTRY,
'belowtitle' => BELOW_TITLE,
'splitfoot' => SPLIT_FOOTER)
),
array(
'var' => 'footerauthor',
'name' => FOOTER_AUTHOR,
'description' => FOOTER_AUTHOR_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'footercategories',
'name' => FOOTER_CATEGORIES,
'description' => FOOTER_CATEGORIES_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'footertimestamp',
'name' => FOOTER_TIMESTAMP,
'description' => FOOTER_TIMESTAMP_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'footercomments',
'name' => FOOTER_COMMENTS,
'description' => FOOTER_COMMENTS_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'footertrackbacks',
'name' => FOOTER_TRACKBACKS,
'description' => FOOTER_TRACKBACKS_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'true',
),
array(
'var' => 'sitenavpos',
'name' => SITENAV_POSITION,
'description' => SITENAV_POSITION_DESC,
'type' => 'select',
'default' => 'none',
'select_values' => array('none' => SITENAV_NONE,
'above' => SITENAV_ABOVE,
'below' => SITENAV_BELOW,
'left' => SITENAV_LEFT,
'right' => SITENAV_RIGHT)
),
array(
'var' => 'cocommentactive',
'name' => COCOMMENT_ACTIVE,
'description' => COCOMMENT_ACTIVE_DESC,
'type' => 'select',
'default' => 'inactive',
'select_values' => array('active' => USE_COCOMMENT,
'inactive' => NO_COCOMMENT)
),
array(
'var' => 'counter_code',
'name' => COUNTER_CODE,
'description' => COUNTER_CODE_DESC,
'type' => 'text',
'default' => '',
),
array(
'var' => 'counter_code_toggle',
'name' => USE_COUNTER,
'description' => USE_COUNTER_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'false'
),
array(
'var' => 'footer_text',
'name' => FOOTER_TEXT,
'description' => FOOTER_TEXT_DESC,
'type' => 'text',
'default' => '',
),
array(
'var' => 'footer_text_toggle',
'name' => USE_FOOTER_TEXT,
'description' => USE_FOOTER_TEXT_DESC,
'type' => 'radio',
'radio' => array('value' => array('true', 'false'),
'desc' => array(BP_YES, BP_NO)),
'default' => 'false'
),
array(
'var' => 'amount',
'name' => NAVLINK_AMOUNT,
'description' => NAVLINK_AMOUNT_DESC,
'type' => 'string',
'default' => '5',
)
);
$vars = serendipity_loadThemeOptions($template_config);
$navlinks = array();
for ($i = 0; $i < $vars['amount']; $i++) {
$navlinks[] = array(
'title' => $vars['navlink' . $i . 'text'],
'href' => $vars['navlink' . $i . 'url']
);
$template_config[] = array(
'var' => 'navlink' . $i . 'text',
'name' => NAV_LINK_TEXT . ' #' . $i,
'description' => NAV_LINK_DESC . ' #' .$i,
'type' => 'string',
'default' => constant('NAV_DEFAULT_' . $i),
);
$template_config[] = array(
'var' => 'navlink' . $i . 'url',
'name' => NAV_LINK_URL . ' #' . $i,
'description' => NAV_LINK_URL_DESC . ' #' . $i,
'type' => 'string',
'default' => '#',
);
}
switch ($vars['colorset']) {
case 'red':
$serendipity['smarty']->assign(array
('template_stylesheet' => 'red.css'));
break;
case 'blue':
$serendipity['smarty']->assign(array
('template_stylesheet' => 'blue.css'));
break;
default:
$serendipity['smarty']->assign(array
('template_stylesheet' => 'red.css'));
}
$serendipity['smarty']->assign_by_ref('navlinks', $navlinks);
?>
This is the config.inc.php I'm using for my local copy of bulletproof right now. Seems to work perfectly fine, although I have only tested it with the rather simple option to switch stylesheets.
So, am I smarty code hero of the day?
BTW, there's one thing I don't like about your code: it switches stylesheets according to the selected colorset, which means you have to have a full stylesheet for every colorset. I think it would be better to have a 'master stylesheet' (style.css comes to mind) plus an
additional individual stylesheet (blue.css, red.css, and the likes) for each colorset. These individual stylesheets need to have only those css statements which actually
change in a colorset. I have already changed that in the example code.
Usually, the only things that change from colorset to colorset are the colors - hence the name 'colorsets'

So you'd include margins, paddings, and stuff like that in style.css, and put
only things that are different to that stylesheet into blue.css, red.css etc., 'overwriting' the statements in style.css due to the css cascade. Saves a
lot of double code. I'm going to upload a new version of bulletproof tomorrow which demonstrates this in a very simple way.
Here's a question for the php experts: Do we actually need the default: in the switch statement? Or is that mandatory in a switch statement?
Owen Stubbs wrote:EDIT: Also, it is {assign var="..." value="..."}..
Yeah, I was aware of that, I was just too lazy to edit the quoted part
YL