5 no warnings 'qw'; # you know what you doing
6 no warnings 'uninitialized'; # save some useless checks for more legible code
7 use open ':std' => ':utf8';
11 use Shiar_Sheet::KeySigns qw(%sign);
14 my ($text, $html) = @_;
15 print '<p class="error"><strong>Fatal error</strong>: '.$html."</p>\n\n";
19 our $showkeys = !exists $get{keys} ? undef :
20 ($get{keys} ne '0' && ($get{keys} || 'always'));
22 $header{content_type} = 'text/html; charset=utf-8';
25 my %styles = map {$_ => $_} @_;
27 if (exists $get{style}) {
28 $style = $styles{ $get{style} };
30 if (my $cookie = CGI::Cookie->new(
33 -path => '/', # site-wide; current page is confusing to most users
34 -expires => $style ? '+5y' : '-1d',
36 AddCookie($cookie->as_string);
40 $style ||= exists $cookie{style} && $styles{ $cookie{style} } || $_[0];
42 return join "\n", map { sprintf(
43 '<link rel="%s" type="text/css" media="all" href="%s" title="%s">',
44 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css?1.6", $_
51 my $mod = stat $_ or next;
52 $mod = $mod->mtime or next;
53 $lastmod = $mod if $mod gt $lastmod;
56 for ($ENV{HTTP_IF_MODIFIED_SINCE} || ()) {
57 next if str2time($_) < $lastmod;
58 $header{status} = '304 Same old';
62 $header{'Last-Modified'} = time2str($lastmod);
68 # announce and check data modification
70 $ENV{SCRIPT_FILENAME},
71 (grep { /\bShiar_/ } values %INC),
72 $meta->{data} ? @{ $meta->{data} } : (),
74 $header{'Cache-Control'} = sprintf 'max-age: ', 24*60*60;
77 $meta->{stylesheet} ||= [qw'light dark circus mono red terse'];
78 $meta->{charset} ||= 'utf-8';
81 push @{ $meta->{raw} }, (
82 '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
83 '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
84 !$showkeys ? '<style type="text/css"> .no {visibility:hidden} </style>'
85 : $showkeys eq 'ghost' ? '<style type="text/css"> .no, .alias {opacity:.5} </style>'
87 '<script type="text/javascript" src="/keys.js?1.6"></script>',
91 ref $_ eq 'ARRAY' and $_ = join ' ', @$_ for $meta->{description};
92 ref $_ eq 'ARRAY' and $_ = join ', ', @$_ for $meta->{keywords};
93 ref $_ eq 'ARRAY' and $_ = join "\n", @$_ for $meta->{rawstyle}, $meta->{raw};
94 ref $_ eq 'ARRAY' and $_ = stylesheet(@$_)."\n" for $meta->{stylesheet};
97 my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
100 $header{content_type} = "text/html; charset=$meta->{charset}";
102 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
103 "http://www.w3.org/TR/html4/loose.dtd">
107 <meta http-equiv="content-type" content="$header{content_type}">
108 <title>$meta->{title}</title>
109 <meta name="description" content="$meta->{description}">
110 <meta name="keywords" content="$meta->{keywords}">
111 <link rel="icon" type="image/png" href="/clip.png">
113 print $_, "\n" for $meta->{stylesheet} || ();
114 print $_, "\n" for $meta->{raw} || ();
115 print qq{</head>\n\n<body id="$file">\n};
117 # prepare trailing output
121 <a href="/" rel="start">sheet.shiar.nl</a>/$file.<a href="/source/$file.plp"
122 rel="code" title="Written in Perl">plp</a>
123 <a href="http://git.shiar.nl/sheet.git/history/HEAD:/$file.plp"
124 rel="vcs-git" title="Git repository">$meta->{version}</a>
125 created by <a href="http://shiar.nl/" rel="author">Shiar</a> $sign{sep}
126 <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
127 title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>