line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: MakePS.pm,v 1.8 2004/03/08 10:43:59 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2004 Slaven Rezic. All rights reserved. |
8
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
12
|
|
|
|
|
|
|
# WWW: http://www.rezic.de/eserte/ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package WebEditor::OldFeatures::MakePS; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakePS - create a postscript file from the site |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use WebEditor::OldFeatures::MakePS; |
24
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakePS::makeps($webeditor_oldcontroller_object, %args); |
25
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakePS::makeps_send($webeditor_oldcontroller_object, %args); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module provides the B function which create Postscript |
30
|
|
|
|
|
|
|
output from a web.editor site. It uses html2ps (available from |
31
|
|
|
|
|
|
|
L) to create the output from |
32
|
|
|
|
|
|
|
an intermediate auto-generated HTML page (which is generated by |
33
|
|
|
|
|
|
|
L). |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
See L for a description on |
36
|
|
|
|
|
|
|
HTML templates. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 FUNCTIONS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The B function arguments: |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item -o => $output_file |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Specify an output file. If not set, then the output will be returned |
47
|
|
|
|
|
|
|
by the B function. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item -toc => $bool |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Create a TOC at the end of the document. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item -pagenumbers => $bool |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Use page numbers. Turned by default on if C<-toc> is set. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The function also accepts C<-lang> and C<-debug> like |
60
|
|
|
|
|
|
|
B. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The B function arguments are same as for B. This |
63
|
|
|
|
|
|
|
function automatically creates an HTTP header and prints the output to |
64
|
|
|
|
|
|
|
STDOUT. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 AUTHOR |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Slaven Rezic. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
|
1767
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
73
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
74
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
4
|
use CGI (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
77
|
1
|
|
|
1
|
|
3459
|
use File::Temp qw(tempfile); |
|
1
|
|
|
|
|
12861
|
|
|
1
|
|
|
|
|
88
|
|
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
1
|
|
10
|
use WE_Frontend::Plugin::Linear; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
80
|
1
|
|
|
1
|
|
6
|
use WE::Util::LangString qw(langstring); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
81
|
1
|
|
|
1
|
|
6
|
use WebEditor::OldFeatures::MakeOnePageHTML; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
544
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub makeps { |
84
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $debug = $args{-debug}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# my $objdb = $self->Root->ObjDB; |
89
|
|
|
|
|
|
|
# my $root_object = $objdb->root_object; |
90
|
|
|
|
|
|
|
# my $c = $self->C; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# my @objids; |
93
|
|
|
|
|
|
|
# my $curr_id = $root_object->Id; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# while (1) { |
96
|
|
|
|
|
|
|
# my $doc_id = $curr_id; |
97
|
|
|
|
|
|
|
# # XXX code doubled in WE_Frontend::Plugin::WE_Navigation::Object |
98
|
|
|
|
|
|
|
# # XXX IndexDoc handling missing! |
99
|
|
|
|
|
|
|
# my $obj = $objdb->get_object($curr_id); |
100
|
|
|
|
|
|
|
# if ($obj->is_folder) { |
101
|
|
|
|
|
|
|
# if (defined $obj->IndexDoc) { |
102
|
|
|
|
|
|
|
# $doc_id = $obj->IndexDoc; |
103
|
|
|
|
|
|
|
# } else { |
104
|
|
|
|
|
|
|
# my $autoindexdoc = $c->project->features->{autoindexdoc}; |
105
|
|
|
|
|
|
|
# if (defined $autoindexdoc && $autoindexdoc eq 'first') { |
106
|
|
|
|
|
|
|
# my(@children_ids) = $objdb->get_released_children($curr_id); |
107
|
|
|
|
|
|
|
# if (@children_ids) { |
108
|
|
|
|
|
|
|
# $doc_id = $children_ids[0]->Id; |
109
|
|
|
|
|
|
|
# } else { |
110
|
|
|
|
|
|
|
# undef $doc_id; |
111
|
|
|
|
|
|
|
# } |
112
|
|
|
|
|
|
|
# } |
113
|
|
|
|
|
|
|
# } |
114
|
|
|
|
|
|
|
# } |
115
|
|
|
|
|
|
|
# push @objids, {Id => $curr_id, DocId => $doc_id}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# if (defined $doc_id) { |
118
|
|
|
|
|
|
|
# # XXX document WE_Frontend::Plugin::Linear how to use in |
119
|
|
|
|
|
|
|
# # offline (non-TT) mode |
120
|
|
|
|
|
|
|
# my $linear = WE_Frontend::Plugin::Linear->new |
121
|
|
|
|
|
|
|
# (undef, |
122
|
|
|
|
|
|
|
# { rootdb => $self->Root, |
123
|
|
|
|
|
|
|
# objdb => $objdb, |
124
|
|
|
|
|
|
|
# objid => $doc_id, |
125
|
|
|
|
|
|
|
# }, |
126
|
|
|
|
|
|
|
# ); |
127
|
|
|
|
|
|
|
# my $next = $linear->next; |
128
|
|
|
|
|
|
|
# if (defined $next) { |
129
|
|
|
|
|
|
|
# $curr_id = $next->o->Id; |
130
|
|
|
|
|
|
|
# } else { |
131
|
|
|
|
|
|
|
# last; |
132
|
|
|
|
|
|
|
# } |
133
|
|
|
|
|
|
|
# } else { |
134
|
|
|
|
|
|
|
# die "XXX Non-linear site (folder object $curr_id has no indexdoc)"; |
135
|
|
|
|
|
|
|
# } |
136
|
|
|
|
|
|
|
# } |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# my $lang = $args{-lang} || $c->project->sitelanguages->[0] || "en"; |
139
|
|
|
|
|
|
|
# my $debug = $args{-debug}; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# my $html_ps = ""; |
142
|
|
|
|
|
|
|
# my $t = Template->new($self->TemplateConf); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# # XXX OK to hardcode template name? |
145
|
|
|
|
|
|
|
# $t->process |
146
|
|
|
|
|
|
|
# ($c->paths->site_templatebase . "/html_ps_header.tpl.html", |
147
|
|
|
|
|
|
|
# { %{ $self->TemplateVars }, |
148
|
|
|
|
|
|
|
# lang => $lang, |
149
|
|
|
|
|
|
|
# }, \$html_ps) or die $t->error; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# for my $def (@objids) { |
152
|
|
|
|
|
|
|
# my $id = $def->{Id}; |
153
|
|
|
|
|
|
|
# my $doc_id = $def->{DocId}; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# # XXX code doubled from makehtmlpage... |
156
|
|
|
|
|
|
|
# my $content = $objdb->content($doc_id); |
157
|
|
|
|
|
|
|
# my $outdata = $self->_get_outdata($content); |
158
|
|
|
|
|
|
|
# my $obj = $objdb->get_object($doc_id); |
159
|
|
|
|
|
|
|
# my $mainid = $obj->Version_Parent || $doc_id; |
160
|
|
|
|
|
|
|
# my $template = $c->project->templatefortype->{ $outdata->{'data'}->{'pagetype'} }; |
161
|
|
|
|
|
|
|
# if (!defined $template) { |
162
|
|
|
|
|
|
|
# die "No template for pagetype $outdata->{'data'}->{'pagetype'} defined"; |
163
|
|
|
|
|
|
|
# } |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# my $folder_title; |
166
|
|
|
|
|
|
|
# my $folder_done; |
167
|
|
|
|
|
|
|
# if ($id != $doc_id) { |
168
|
|
|
|
|
|
|
# my $folder_obj = $objdb->get_object($id); |
169
|
|
|
|
|
|
|
# $folder_title = langstring($folder_obj->Title, $lang); |
170
|
|
|
|
|
|
|
# my $template_file = $c->paths->site_templatebase . "/html_ps_headline.tpl.html"; |
171
|
|
|
|
|
|
|
# $html_ps .= "\n"; |
172
|
|
|
|
|
|
|
# $t->process |
173
|
|
|
|
|
|
|
# ($template_file, |
174
|
|
|
|
|
|
|
# { %{ $self->TemplateVars }, |
175
|
|
|
|
|
|
|
# lang => $lang, |
176
|
|
|
|
|
|
|
# objid => $id, |
177
|
|
|
|
|
|
|
# object => $folder_obj, |
178
|
|
|
|
|
|
|
# title => $folder_title, |
179
|
|
|
|
|
|
|
# level => ($objdb->depth($folder_obj))[0], |
180
|
|
|
|
|
|
|
# pagetype => "_folder", |
181
|
|
|
|
|
|
|
# }, \$html_ps) or die $t->error; |
182
|
|
|
|
|
|
|
# $folder_done = 1; |
183
|
|
|
|
|
|
|
# } |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# my $page_title = langstring($obj->Title, $lang); |
186
|
|
|
|
|
|
|
# $html_ps .= "\n"; |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# $outdata->{'data'}->{'language'} = $lang; |
189
|
|
|
|
|
|
|
# my $keywords = langstring($obj->{Keywords}, $lang) || undef; |
190
|
|
|
|
|
|
|
# #warn "Using template ".$c->paths->site_templatebase."/".$template."\n"; |
191
|
|
|
|
|
|
|
# $template =~ s/\.tpl\.html$/_ps\.tpl\.html/; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# $t->process($c->paths->site_templatebase."/".$template, |
194
|
|
|
|
|
|
|
# { %{ $self->TemplateVars }, |
195
|
|
|
|
|
|
|
# objid => $mainid, |
196
|
|
|
|
|
|
|
# lang => $lang, |
197
|
|
|
|
|
|
|
# keywords => $keywords, |
198
|
|
|
|
|
|
|
# level => ($objdb->depth($mainid))[0], |
199
|
|
|
|
|
|
|
# omit_title => (defined $page_title && $page_title eq $folder_title), |
200
|
|
|
|
|
|
|
# omit_pagebreak => $folder_done, |
201
|
|
|
|
|
|
|
# %$outdata }, |
202
|
|
|
|
|
|
|
# \$html_ps) |
203
|
|
|
|
|
|
|
# or die "Template process failed: " . $t->error . "\n"; |
204
|
|
|
|
|
|
|
# } |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# # XXX OK to hardcode template name? |
207
|
|
|
|
|
|
|
# $html_ps .= "\n"; |
208
|
|
|
|
|
|
|
# $t->process |
209
|
|
|
|
|
|
|
# ($c->paths->site_templatebase . "/html_ps_footer.tpl.html", |
210
|
|
|
|
|
|
|
# { %{ $self->TemplateVars }, |
211
|
|
|
|
|
|
|
# lang => $lang, |
212
|
|
|
|
|
|
|
# }, |
213
|
|
|
|
|
|
|
# \$html_ps) |
214
|
|
|
|
|
|
|
# or die $t->error; |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
my($htmlfh,$htmltmp) = tempfile(SUFFIX => ".html", |
217
|
|
|
|
|
|
|
UNLINK => !$debug); |
218
|
|
|
|
|
|
|
{ |
219
|
0
|
|
|
|
|
|
local $args{-o} = $htmltmp; |
|
0
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
WebEditor::OldFeatures::MakeOnePageHTML::makeonepagehtml($self, %args); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my($psfh, $pstmp); |
224
|
0
|
0
|
|
|
|
|
if (!defined $args{-o}) { |
225
|
0
|
|
|
|
|
|
($psfh, $pstmp) = tempfile(SUFFIX => ".ps", |
226
|
|
|
|
|
|
|
UNLINK => !$debug); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my @cmd = ('html2ps'); |
230
|
0
|
|
|
|
|
|
push @cmd, '-D'; |
231
|
0
|
0
|
|
|
|
|
if ($args{-toc}) { |
232
|
0
|
|
|
|
|
|
push @cmd, "-C", "h"; |
233
|
|
|
|
|
|
|
} |
234
|
0
|
0
|
|
|
|
|
if ($debug) { |
235
|
|
|
|
|
|
|
# XXX writes to current directory, which might be unwritable |
236
|
|
|
|
|
|
|
#push @cmd, "-d"; |
237
|
|
|
|
|
|
|
} |
238
|
0
|
0
|
|
|
|
|
if ($args{-pagenumbers}) { |
239
|
0
|
|
|
|
|
|
push @cmd, "-n"; |
240
|
|
|
|
|
|
|
} |
241
|
0
|
0
|
|
|
|
|
if ($args{-o}) { |
242
|
0
|
|
|
|
|
|
push @cmd, "-o", $args{-o}; |
243
|
|
|
|
|
|
|
} else { |
244
|
0
|
|
|
|
|
|
push @cmd, "-o", $pstmp; |
245
|
|
|
|
|
|
|
} |
246
|
0
|
|
|
|
|
|
push @cmd, $htmltmp; |
247
|
|
|
|
|
|
|
|
248
|
0
|
0
|
|
|
|
|
warn "@cmd\n" if $debug; |
249
|
0
|
0
|
|
|
|
|
system(@cmd) and die "Error while doing @cmd"; |
250
|
|
|
|
|
|
|
|
251
|
0
|
|
|
|
|
|
my $ps; |
252
|
|
|
|
|
|
|
|
253
|
0
|
0
|
|
|
|
|
if (!defined $args{-o}) { |
254
|
0
|
0
|
|
|
|
|
open(FH, $pstmp) or die "Can't open $pstmp: $!"; |
255
|
0
|
|
|
|
|
|
local $/ = undef; |
256
|
0
|
|
|
|
|
|
$ps = ; |
257
|
0
|
|
|
|
|
|
close FH; |
258
|
0
|
|
|
|
|
|
close $psfh; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
0
|
0
|
|
|
|
|
unless ($debug) { |
262
|
0
|
|
|
|
|
|
unlink $htmltmp; |
263
|
0
|
|
|
|
|
|
unlink $pstmp; |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
|
$ps; |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub makeps_send { |
270
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $ps = makeps($self, %args); |
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
|
my $q = CGI->new; |
275
|
0
|
|
|
|
|
|
print $q->header("application/postscript"); |
276
|
0
|
|
|
|
|
|
print $ps; |
277
|
0
|
|
|
|
|
|
return 1; |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
1; |