Themes:
This will create a list of themes for your readers to select.
If you would like a dropdown box rather than a list, add this:
Themes:
*/
$bb_ts['timeout']=180; // default 3 minute demo timeout - increase if you want a longer timeout
$bb_ts['exclude']=array('random-theme','another-theme'); // themes to not show in list - use local path short name, not formal name, ie. 'kakumei-blue'
/* stop editing here */
$bbhash=$bb->wp_siteurl ? md5($bb->wp_siteurl) : md5($bb_table_prefix); // $bbhash is not available before plugins load in 0.8.2.x :-(
bb_ts_set_theme_cookie($bb_ts['timeout']);
if (strpos("bbshowcase.org",$_SERVER["SERVER_NAME"])!==false) {
$bb_ts_optional_text = 'keep _ck_ coding >> donate $1 << ';
}
add_filter('bb_template','bb_ts_add_dropdown',100,2); // disable this line if you don't want the switcher inserted automatically
add_filter('bb_get_active_theme_folder','bb_ts_get_template');
add_filter('bb_get_active_theme_directory','bb_ts_get_template');
add_filter('bb_get_active_theme_uri', 'bb_ts_get_active_theme_uri');
function bb_ts_add_dropdown($template='',$file='') {
global $bb_ts_add_dropdown, $bb_ts_optional_text;
if ($file=='' || ($file=="footer.php" && !$bb_ts_add_dropdown)){
$bb_ts_add_dropdown=true;
echo '';
}
return $template;
}
function bb_ts_set_theme_cookie($timeout=180) { global $bbhash;
$expire = time() + intval($timeout);
if (!empty($_GET["bbtheme"])) {
if ( bb_get_option( 'cookiedomain' ) ) {
setcookie( "bb_theme_".$bbhash, stripslashes($_GET["bbtheme"]), $expire, bb_get_option( 'cookiepath' ), bb_get_option( 'cookiedomain' ) );}
else {setcookie( "bb_theme_".$bbhash, stripslashes($_GET["bbtheme"]), $expire, bb_get_option( 'cookiepath' ) );}
$redirect = remove_query_arg('bbtheme');
if (function_exists('bb_redirect'))
bb_redirect($redirect);
else
header("Location: ". $redirect);
exit;
}
}
function bb_ts_get_theme() { global $bbhash;
if (!empty($_COOKIE["bb_theme_".$bbhash])) {
return $_COOKIE["bb_theme_".$bbhash];
} else {
return '';
}
}
function bb_ts_get_active_theme_uri($uri) {
$theme = bb_ts_get_theme();
if (empty($theme)) {return $uri;}
$theme=bb_get_one_theme($theme);
$active_uri="";
if ( 0 === strpos($theme, BBTHEMEDIR) )
$active_uri = BBTHEMEURL . substr($theme, strlen(BBTHEMEDIR));
elseif ( 0 === strpos($theme, BBPATH) )
$active_uri = bb_get_option( 'uri' ) . substr($theme, strlen(BBPATH));
if ($active_uri) {return $active_uri;} else {return $uri;}
}
function bb_get_one_theme($theme) {
$themes = bb_get_all_themes();
// print " "; // diagnostic
if (array_key_exists($theme, $themes)) {return $themes[$theme];}
return NULL;
}
function bb_get_all_themes() { // replacement for change in function after build 951
$r = array();
$theme_roots = array(BBPATH . 'bb-templates/', BBTHEMEDIR );
foreach ( $theme_roots as $theme_root )
if ( $themes_dir = @dir($theme_root) )
while( ( $theme_dir = $themes_dir->read() ) !== false )
if ( is_dir($theme_root . $theme_dir) && is_readable($theme_root . $theme_dir) && '.' != $theme_dir{0} )
$r[$theme_dir] = $theme_root . $theme_dir . '/';
ksort($r);
return $r;
}
function bb_ts_get_template($template) {
$theme = bb_ts_get_theme();
if (empty($theme)) {
return $template;
}
$theme = bb_get_one_theme($theme);
if (empty($theme)) {
return $template;
}
// Don't let people peek at unpublished themes.
// if (isset($theme['Status']) && $theme['Status'] != 'publish')
// return $template;
return $theme;
}
function bb_theme_switcher($style = "text") {
global $bbhash, $bb_ts;
$themes = bb_get_all_themes();
$default_theme=str_replace(array('core#', 'user#'),'', bb_get_option('bb_active_theme'));
if (!array_key_exists($default_theme, $themes)) {$default_theme =array_search($default_theme,$themes);}
if (!empty($bb_ts['exclude'])) {foreach ($bb_ts['exclude'] as $exclude) {unset($themes[$exclude]);}}
if (count($themes) > 1) {
$theme_names = array_keys($themes);
natcasesort($theme_names);
if ($style == 'dropdown') {
$ts = ''."\n";
$ts .= // ''."\n"
' '."\n";
// . ''."\n";
} else {
$ts = ''."\n";
foreach ($theme_names as $theme_name) {
// Skip unpublished themes.
// if (isset($themes[$theme_name]['Status']) && $themes[$theme_name]['Status'] != 'publish')
// continue;
// $display = htmlspecialchars(ucfirst(str_replace("-"," ",$theme_name)));
$display = explode("/",trim($theme_name," /")); $display = end($display); // lazy fix for build >1000 with full path names
$display = str_replace(array("Bb ","Bbpress"," For "),array("bb ","bbPress"," for "),htmlspecialchars(ucwords(str_replace("-"," ",$display))));
if ((!empty($_COOKIE["bb_theme_".$bbhash]) && $_COOKIE["bb_theme_".$bbhash] == $theme_name)
|| (empty($_COOKIE["bb_theme_".$bbhash]) && ($theme_name == $default_theme))) {
$ts .= ' - '.$display.'
'."\n";
} else {
$ts .= ' - '
.$display.'
'."\n";
}
}
$ts .= '
';
}
}
echo $ts;
}
?>