chiark / gitweb /
Max gems should be 24 not 25
[ypp-sc-tools.main.git] / yarrg / web / autohandler
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
9   YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10   The YARRG website is covered by the GNU Affero GPL v3 or later, which
11    basically means that every installation of the website will let you
12    download the source.
13
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Affero General Public License as
16  published by the Free Software Foundation, either version 3 of the
17  License, or (at your option) any later version.
18
19  This program is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  GNU Affero General Public License for more details.
23
24  You should have received a copy of the GNU Affero General Public License
25  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
27  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28  are used without permission.  This program is not endorsed or
29  sponsored by Three Rings.
30
31
32  This Mason autohandler contains the doctype, charset and
33  copyright message.
34
35
36 </%doc><%perl>
37
38 use CommodsWeb;
39
40 my $printable= printable($m);
41 if ($printable =~ m/^pdf|^ps/) {
42         my $output;
43         my $got= $m->call_self(\$output);
44         if ($got) {
45                 my @htargs= qw(htmldoc --continuous --gray --size 210x279mm
46                                 --left 1cm --right 1cm);
47                 $printable =~ m/^[a-z]+/;
48                 push @htargs, '-t',$&;
49                 if ($printable =~ m/2$/) {
50                         push @htargs, qw(--nup 2);
51                 }
52                 push @htargs, qw(-);
53
54                 my $tmpfile= IO::File::new_tmpfile();
55                 print $tmpfile $output or die $!;
56                 $tmpfile->flush() or die $!;
57                 seek $tmpfile,0,0 or die $!;
58                 my $htmldoc= open HTMLDOC, "-|";
59                 defined $htmldoc or die $!;
60                 if (!$htmldoc) {
61                         eval {
62                                 $ENV{'HTMLDOC_NOCGI'}=1;
63                                 open STDIN, '<&', $tmpfile or die $!;
64
65                                 exec @htargs;
66                                 die $!;
67                         };
68                         print STDERR "HTMLDOC FAILURE $@";
69                         _exit(1);
70                 }
71                 my ($data,$read);
72                 $r->content_type($printable eq 'pdf' ? 'application/pdf' :
73                                                 'application/postscript');
74                 while ($read= read HTMLDOC,$data,32768) { print $data; }
75                 defined $read or die $!;
76                 $?=0; $!=0; close HTMLDOC or die "$! $? $output ";
77                 return;
78         }
79 }
80 set_ctype_utf8();
81 $r->content_type('text/html; charset=UTF-8');
82
83 </%perl><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
84 <!--
85     This HTML is generated by the YARRG website, which is
86     <& copyrightdate &>.
87
88     The YARRG website is Free Software and licenced according to the
89     GNU Affero General Public Licence (v3 or later).  See the link at
90     the bottom of this page for full licence and copyright
91     information.
92
93     Many YARRG web pages also display data from the YARRG database,
94     which contains mostly contributions from YARRG users and is not
95     covered by the AGPL.
96 -->
97
98 % $m->call_next();