mww / baptiste style switcher doesnt work in CMSMS v1.1

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
rubberglover
Forum Members
Forum Members
Posts: 53
Joined: Mon Jul 23, 2007 5:30 pm

mww / baptiste style switcher doesnt work in CMSMS v1.1

Post by rubberglover »

Hi all,

I always used to make use of the style switching solution made by the forum user "mww", and further modified by forum user "baptiste" (posted below - thanks guys!), but it doesn't seem to work now that I have upgraded to version 1.1 - I think it has something to do with PHP5 and the use of the "foreach" function in the "switcher.php" file, but that's just guess work as I'm not particularly hot on PHP these days!

Could someone with a little more skill take a look at this? It used to work like a dream to switch between different style sheets... I can't really use a java one because all the java switchers I have found make use of external css files, and i need to reference and switch between the css templates through the CMSMS admin, as the person I'm making the site for will want to make changes to the CSS here and there and wants to do so through the CMS; clients eh?! I've posted the solution developed by mww and baptist below, any assistance or new solutions would be greatly appreciated!




There are just 3 places that you need to make changes to the code below :
In '1)' below, change the menu 'set' values to your values, you don't need to change 'default', this option just deletes to cookie, but the other values need to be the names of your stylesheets.
In '3)' below change the acceptable styles to match those in '1)' above.
In '3)' below change the server to be your server name.

And add stylesheets to match your options!

I've probably forgotton something really basic, but here's the stuff :

1) Create a user defined tag to write the menu to the page:
  - Extensions » User Defined Tags » Create User Defined Tag: accessibility_menu
  - Add to your template as '{accessibility_menu}'.

/***********************************************
* Writes the accessibility menu
************************************************/
echo "";
echo "Accessibility Options

";
echo "Default Text/Colour";/*ADD YOUR OPTIONS HERE*/
echo "Larger Text";
echo "Colour option 1";
echo "Colour option 2";
echo "";

2) Create a user defined tag to write the selected css links in the page:
  - Extensions » User Defined Tags » Create User Defined Tag: set_css
  - Add to the 'head' section your template as '{set_css}'.

/***********************************************
* reads a cookie to get values for the accessibility options
* these are stored in an array in the cookie as:
* sitestyle('default', 'larger', 'colour_option1') etc...
************************************************/
if(isset($_COOKIE['sitestyle'])){
    foreach($_COOKIE['sitestyle'] as $style) {
        $css_tag = "";

        echo $css_tag;
    }
}

3) Create a file called 'switcher.php' in your website document root and paste the following in to it:


/************************ End of Code *************************/



Questions welcome.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: mww / baptiste style switcher doesnt work in CMSMS v1.1

Post by Nullig »

What do you mean by "doesn't seem to work now"?
What is happening?
Can you provide a link?

Nullig
rubberglover
Forum Members
Forum Members
Posts: 53
Joined: Mon Jul 23, 2007 5:30 pm

Re: mww / baptiste style switcher doesnt work in CMSMS v1.1

Post by rubberglover »

Hi, sorry should have been more specific - It used to apply the default style via use of the UDT {set_css} in place of the usual {stylesheet} tag, and then clicking on the links to different styles would write the current style sheet to a cookie and apply that until the user switched back again. Now it doesn't actually apply the default style... the code generated comes out like this:



- notice that the ?name GET variable is empty where it used to be set to "?name=default" by default. When you click on a different style it generates the right code but doesn't actually seem to apply the style. I have a text only style called "text" and when you click the link to activate it it produces the following code:



The URL string variable is correctly set to "text" but the actual style sheet is not applied.

Also, the following SQL error occurs when you click on the default style sheet link when the default style sheet is already supposed to be active, though this is probably due to the ?name URL string variable being empty(?)...

*****************************************

Warning: Invalid argument supplied for foreach() in /home/www/twothirt/aha/switcher.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /home/www/twothirt/aha/switcher.php:23) in /home/www/twothirt/aha/switcher.php on line 43

*****************************************

Line 23 of the switcher.php file is where the "foreach" loop is supposed to run through the cookie like so:

foreach($_COOKIE['sitestyle'] as $style) {
    setcookie("sitestyle[$style]", "", time()-86400, '/');
}

Go to http://www.twothirteen.net/aha to see this problem in action.

Any ideas as to what might be happening?
Last edited by rubberglover on Wed Aug 15, 2007 3:40 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: mww / baptiste style switcher doesnt work in CMSMS v1.1

Post by Nullig »

It looks like your {set_css} tag will only work if there's an existing cookie... any new visitors will not have any style applied.

if(isset($_COOKIE['sitestyle'])){
    foreach($_COOKIE['sitestyle'] as $style) {
        $css_tag = "";

        echo $css_tag;
    }
}

I think you need an else in there to set a default $style, when there is no cookie.

Nullig
rubberglover
Forum Members
Forum Members
Posts: 53
Joined: Mon Jul 23, 2007 5:30 pm

Re: mww / baptiste style switcher doesnt work in CMSMS v1.1

Post by rubberglover »

I thought this too, so I changed the {set_css} tag to the following, but it still doesn't work and throws out the same problems...

if(isset($_COOKIE['sitestyle'])){
    foreach($_COOKIE['sitestyle'] as $style) {
        $css_tag = "";
        echo $css_tag;
    }
} else {
        $css_tag = "";
        echo $css_tag;
}

Also, when you click on a link to apply a different style, it creates a cookie and the correct stylsheet link is echoed out but the style does not apply:
rubberglover wrote: I have a text only style called "text" and when you click the link to activate it it produces the following code:



The URL string variable is correctly set to "text" but the actual style sheet is not applied.
Can anyone spot anything else that could be causing this? It works fine on versions prior to 1.1!
Post Reply

Return to “Layout and Design (CSS & HTML)”