Topic: Style Switcher

##
##
##        Mod title:  Style Switcher
##
##      Mod version:  1.0
##   Works on PunBB:  1.2.x
##     Release date:  2006-07-07
##           Author:  Aryo Sandiyudo [www.yowis.com]
##
##      Description:  This will allow your visitors to easily select a stylesheet to use during their visit.
##
##       Affects DB:  Yes
##
##   Affected files:  admin_options 
##                    header.php 
##                    lang/LANGUAGE/common.php 
##                    include/template/main.tpl 
##
##            Notes:  This type of user interactivity adds value and style to your users' experience during their visit to your website.
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

Download in Punres

2

Re: Style Switcher

good job....although you have a few errors...it should only display the style switcher in the header while a user is logged in. It shouldnt display it to guests. Another thing is is that it has some bugs when you switch from different styles. Sometimes it mixes 2 styles together when switching.

Re: Style Switcher

to make the style switcher only shown for members only, find inside header.php:

if ($pun_config['o_show_sswitch'] == '1')

Replace with:

if ($pun_config['o_show_sswitch'] == '1' && !$pun_user['is_guest'])

And about 2 styles mixes together, i haven't found that bug yet.
I will try to find it out and do more test, thanks...

4 (edited by whiteh0rs3 2006-07-09 07:51)

Re: Style Switcher

it looks that this mod will only be good if only guest who can use this, cause basically members can switch styles through their Profile -> Display

to fix issues about 2 styles mixes together, here is the changes:

(1) OPEN header.php:

(2) REMOVE:

<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
<?php
if ($pun_config['o_show_sswitch'] == '1')
    echo '<link rel="stylesheet" type="text/css" href="style/imports/styleswitcher.php" />'."\n";
?>

(3) FIND:

if (defined('PUN_ADMIN_CONSOLE'))
    echo '<link rel="stylesheet" type="text/css" href="style/imports/base_admin.css" />'."\n";

(4) BEFORE add:

if ($pun_config['o_show_sswitch'] == '1' && $pun_user['is_guest'])
{
    $mysheet = str_replace('_cs', '', $_COOKIE['my_stylesheet']);

    if ($mysheet == "")
        echo '<link rel="stylesheet" type="text/css" href="style/'.$pun_user['style'].'.css" />'."\n";
    else
        echo '<link rel="stylesheet" type="text/css" href="style/'.$mysheet.'" />'."\n";        

    echo '<link rel="stylesheet" type="text/css" href="style/imports/styleswitcher.php" />'."\n";
}
else
{
    echo '<link rel="stylesheet" type="text/css" href="style/'.$pun_user['style'].'.css" />'."\n";
}

(5) FIND:

// START SUBST - <pun_style>
if ($pun_config['o_show_sswitch'] == '1')
{
    $styles = array();
    $d = dir(PUN_ROOT.'style/imports');
    while (($entry = $d->read()) !== false)
    {
        if (substr($entry, strlen($entry)-4) == '.css' && $entry != 'base.css' && $entry != 'base_admin.css')
            $styles[] = substr($entry, 0, strlen($entry)-4);
    }
    $d->close();

    @natsort($styles);

    $tpl_temp=$lang_common['Style switcher'].'<form name="thisform" action="style/imports/styleswitcher.php" method="post"><select name="sheet" onchange="document.thisform.submit()">';

    $mysheet = $_COOKIE['my_stylesheet'];
    $mysheet = substr($mysheet, 0, strlen($mysheet)-4);

    while (list(, $temp) = @each($styles))
    {
        $fix_temp=str_replace('_', ' ', $temp);
        $fix_temp=trim(str_replace(' cs', ' ', $fix_temp));

        if ($mysheet == $temp)
            // Alternative way to bookmark used sheet
            //$tpl_temp=$tpl_temp."\t\t\t\t\t\t\t\t\t".'<optgroup label="'.$fix_temp.'"></optgroup>'."\n";

            $tpl_temp=$tpl_temp."\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$fix_temp.'</option>'."\n";
        else
            $tpl_temp=$tpl_temp."\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$fix_temp.'</option>'."\n";
    }

    $tpl_temp=$tpl_temp."</select></form>";
    $tpl_main = str_replace('<pun_style>',$tpl_temp, $tpl_main);
}
else
{
    $tpl_main = str_replace('<pun_style>','<div class="block"></div>', $tpl_main);
}
// END SUBST - <pun_style>

(6) REPLACE with:

// START SUBST - <pun_style>
if ($pun_config['o_show_sswitch'] == '1' && $pun_user['is_guest'])
{
    $styles = array();
    $d = dir(PUN_ROOT.'style/imports');
    while (($entry = $d->read()) !== false)
    {
        if (substr($entry, strlen($entry)-4) == '.css' && $entry != 'base.css' && $entry != 'base_admin.css')
            $styles[] = substr($entry, 0, strlen($entry)-4);
    }
    $d->close();

    @natsort($styles);

    $tpl_temp=$lang_common['Style switcher'].'<form id="style" action="style/imports/styleswitcher.php" method="post"><select name="sheet">'."\n";

    $mysheet = $_COOKIE['my_stylesheet'];
    $mysheet = substr($mysheet, 0, strlen($mysheet)-4);

    while (list(, $temp) = @each($styles))
    {
        $fix_temp=str_replace('_cs', '', $temp);

        if ($mysheet == $temp)
            $tpl_temp=$tpl_temp."\t\t\t".'<option value="'.$temp.'" selected="selected">[ '.$fix_temp.' ]</option>'."\n";
        else
            $tpl_temp=$tpl_temp."\t\t\t".'<option value="'.$temp.'">'.$fix_temp.'</option>'."\n";
    }

    $tpl_temp = $tpl_temp."\t\t\t".'<input type="submit" name="sswitch" value="Set" tabindex="0" />';
    $tpl_temp = $tpl_temp."</select></form>";
    $tpl_main = str_replace('<pun_style>',$tpl_temp, $tpl_main);
}
else
{
    $tpl_main = str_replace('<pun_style>','<div class="block"></div>', $tpl_main);
}
// END SUBST - <pun_style>

that's makes the Style Switcher will works only for guest and added button to select style