remember given style option in cookie
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 18 Oct 2009 18:36:10 +0000 (18:36 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 18 Oct 2009 18:36:10 +0000 (18:36 +0000)
common.inc.plp

index 576e39c88d25c1f50c3933b5fc156586da440aef..28a14cedc450b8debf5c59b04f1a04cb1afff2b5 100644 (file)
@@ -12,7 +12,20 @@ $header{content_type} = 'text/html; charset=utf-8';
 
 sub stylesheet {
        my %styles = map {$_ => $_} @_;
 
 sub stylesheet {
        my %styles = map {$_ => $_} @_;
-       $style = exists $get{style} && $styles{$get{style}} || $_[0];
+
+       if (exists $get{style}) {
+               $style = $styles{ $get{style} };
+               require CGI::Cookie;
+               AddCookie(CGI::Cookie->new(
+                       -name    => 'style',
+                       -value   => $style,
+                       -path    => '/',  # site-wide; current page is confusing to most users
+                       -expires => $style ? '+5y' : '-1d',
+               )->as_string);
+       }
+
+       $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
+
        return join "\n", map { sprintf(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
                $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_
        return join "\n", map { sprintf(
                '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
                $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_