termcol: enable dark page styling
[sheet.git] / common.inc.plp
1 <:
2 use utf8;
3 use strict;
4 use warnings;
5 no  warnings 'qw';  # you know what you doing
6 no  warnings 'uninitialized';  # save some useless checks for more legible code
7 use open IO => ':utf8';
8
9 our $style;
10
11 $header{content_type} = 'text/html; charset=utf-8';
12
13 sub stylesheet {
14         my %styles = map {$_ => $_} @_;
15
16         if (exists $get{style}) {
17                 $style = $styles{ $get{style} };
18                 require CGI::Cookie;
19                 AddCookie(CGI::Cookie->new(
20                         -name    => 'style',
21                         -value   => $style,
22                         -path    => '/',  # site-wide; current page is confusing to most users
23                         -expires => $style ? '+5y' : '-1d',
24                 )->as_string);
25         }
26
27         $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
28
29         return join "\n", map { sprintf(
30                 '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
31                 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_
32         ) } @_;
33 }
34