line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: MakeOnePageHTML.pm,v 1.3 2004/12/22 11:23:07 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::MakeOnePageHTML; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakeOnePageHTML - create a postscript file from the site |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use WebEditor::OldFeatures::MakeOnePageHTML; |
24
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakeOnePageHTML::makeonepagehtml($webeditor_oldcontroller_object, %args); |
25
|
|
|
|
|
|
|
WebEditor::OldFeatures::MakeOnePageHTML::makeonepagehtml_send($webeditor_oldcontroller_object, %args); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module provides the B function which creates a |
30
|
|
|
|
|
|
|
single page HTML a web.editor site. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 HTML TEMPLATES |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The HTML templates should be the same as the normal pagetype templates |
35
|
|
|
|
|
|
|
with the suffix C<_oph.tpl.html> instead of C<.tpl.html>. Usually these |
36
|
|
|
|
|
|
|
templates contain only partial HTML without C<< >>, C<< |
37
|
|
|
|
|
|
|
>> and C<< >> tags and should have no navigational elements. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
The templates receive the normal parameters as in B and |
40
|
|
|
|
|
|
|
additionally the parameters C (useful in constructing the C<< |
41
|
|
|
|
|
|
|
>> tag) and C (true if it is advisable to omit the |
42
|
|
|
|
|
|
|
C<< >> tag). |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Additionally, the following templates should be defined: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item one_page_html_header.tpl.html |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The overall header of the HTML document. Here goes the C<< >> |
51
|
|
|
|
|
|
|
definitions and the opening C<< >> and C<< >> tags. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The template receives the normal TemplateVars and additionally the |
54
|
|
|
|
|
|
|
current C parameter. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item one_page_html_footer.tpl.html |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
The overall footer of the HTML document. Here goes the closing C<< |
59
|
|
|
|
|
|
|
>> and C<< >> tags along with footer text for the |
60
|
|
|
|
|
|
|
document. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The template receives the normal TemplateVars and additionally the |
63
|
|
|
|
|
|
|
current C parameter. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item one_page_html_headline.tpl.html |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
A template for a folder object with no own content. Typically this |
68
|
|
|
|
|
|
|
will contain only one C<< title >> element. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This template receives the normal TemplateVars and additionally the |
71
|
|
|
|
|
|
|
C, C |
72
|
|
|
|
|
|
|
C. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 FUNCTIONS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The B function arguments: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=over |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item -lang => $lang |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The language to process. By default the first site language is used. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item -debug => $bool |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Turn on debug mode if true. This will leave the temporary files after |
89
|
|
|
|
|
|
|
processing and show the command line arguments. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item -o => $output_file |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Specify an output file. If not set, then the output will be returned |
94
|
|
|
|
|
|
|
by the B function. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The B function arguments are same as for |
99
|
|
|
|
|
|
|
B. This function automatically creates an HTTP header |
100
|
|
|
|
|
|
|
and prints the output to STDOUT. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Slaven Rezic. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
1
|
|
1319
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
109
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
55
|
|
110
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
1
|
|
4
|
use CGI (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
113
|
1
|
|
|
1
|
|
4
|
use HTML::Entities (); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
17
|
|
114
|
1
|
|
|
1
|
|
4
|
use Template; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
16
|
|
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
1
|
|
5
|
use WE_Frontend::Plugin::Linear; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
117
|
1
|
|
|
1
|
|
6
|
use WE::Util::LangString qw(langstring); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1090
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub makeonepagehtml { |
120
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $objdb = $self->Root->ObjDB; |
123
|
0
|
|
|
|
|
|
my $root_object = $objdb->root_object; |
124
|
0
|
|
|
|
|
|
my $c = $self->C; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my @objids; |
127
|
0
|
|
|
|
|
|
my $curr_id = $root_object->Id; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
while (1) { |
130
|
0
|
|
|
|
|
|
my $doc_id = $curr_id; |
131
|
|
|
|
|
|
|
# XXX code doubled in WE_Frontend::Plugin::WE_Navigation::Object |
132
|
|
|
|
|
|
|
# XXX IndexDoc handling missing! |
133
|
0
|
|
|
|
|
|
my $curr_obj = $objdb->get_object($curr_id); |
134
|
0
|
0
|
|
|
|
|
if ($curr_obj->is_folder) { |
135
|
0
|
0
|
|
|
|
|
if (defined $curr_obj->IndexDoc) { |
136
|
0
|
|
|
|
|
|
$doc_id = $curr_obj->IndexDoc; |
137
|
|
|
|
|
|
|
} else { |
138
|
0
|
|
|
|
|
|
my $autoindexdoc = $c->project->features->{autoindexdoc}; |
139
|
0
|
0
|
0
|
|
|
|
if (defined $autoindexdoc && $autoindexdoc eq 'first') { |
140
|
0
|
|
|
|
|
|
my(@children_ids) = $objdb->get_released_children($curr_id); |
141
|
0
|
0
|
|
|
|
|
if (@children_ids) { |
142
|
0
|
|
|
|
|
|
$doc_id = $children_ids[0]->Id; |
143
|
|
|
|
|
|
|
} else { |
144
|
0
|
|
|
|
|
|
undef $doc_id; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
0
|
|
|
|
|
|
push @objids, {Id => $curr_id, DocId => $doc_id}; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if (defined $doc_id) { |
152
|
|
|
|
|
|
|
# XXX document WE_Frontend::Plugin::Linear how to use in |
153
|
|
|
|
|
|
|
# offline (non-TT) mode |
154
|
0
|
|
|
|
|
|
my $linear = WE_Frontend::Plugin::Linear->new |
155
|
|
|
|
|
|
|
(undef, |
156
|
|
|
|
|
|
|
{ rootdb => $self->Root, |
157
|
|
|
|
|
|
|
objdb => $objdb, |
158
|
|
|
|
|
|
|
objid => $doc_id, |
159
|
|
|
|
|
|
|
}, |
160
|
|
|
|
|
|
|
); |
161
|
0
|
|
|
|
|
|
my $next = $linear->next; |
162
|
0
|
0
|
|
|
|
|
if (defined $next) { |
163
|
0
|
|
|
|
|
|
$curr_id = $next->o->Id; |
164
|
|
|
|
|
|
|
} else { |
165
|
0
|
|
|
|
|
|
last; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} else { |
168
|
0
|
|
|
|
|
|
die "This is a non-linear site. The folder object <" . langstring($curr_obj->Title) . "> (Id $curr_id) has no Index document."; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
0
|
|
|
|
my $lang = $args{-lang} || $c->project->sitelanguages->[0] || "en"; |
173
|
0
|
|
|
|
|
|
my $debug = $args{-debug}; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $html = ""; |
176
|
0
|
|
|
|
|
|
my $t = Template->new($self->TemplateConf); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# XXX OK to hardcode template name? |
179
|
0
|
|
|
|
|
|
$t->process |
180
|
|
|
|
|
|
|
($c->paths->site_templatebase . "/one_page_html_header.tpl.html", |
181
|
0
|
0
|
|
|
|
|
{ %{ $self->TemplateVars }, |
182
|
|
|
|
|
|
|
lang => $lang, |
183
|
|
|
|
|
|
|
}, \$html) or die $t->error; |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
for my $def (@objids) { |
186
|
0
|
|
|
|
|
|
my $id = $def->{Id}; |
187
|
0
|
|
|
|
|
|
my $doc_id = $def->{DocId}; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# XXX code doubled from makehtmlpage... |
190
|
0
|
|
|
|
|
|
my $content = $objdb->content($doc_id); |
191
|
0
|
|
|
|
|
|
my $outdata = $self->_get_outdata($content); |
192
|
0
|
|
|
|
|
|
my $obj = $objdb->get_object($doc_id); |
193
|
0
|
|
0
|
|
|
|
my $mainid = $obj->Version_Parent || $doc_id; |
194
|
0
|
|
|
|
|
|
my $template = $c->project->templatefortype->{ $outdata->{'data'}->{'pagetype'} }; |
195
|
0
|
0
|
|
|
|
|
if (!defined $template) { |
196
|
0
|
|
|
|
|
|
die "No template for pagetype $outdata->{'data'}->{'pagetype'} defined"; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
my $folder_title; |
200
|
|
|
|
|
|
|
my $folder_done; |
201
|
0
|
0
|
|
|
|
|
if ($id != $doc_id) { |
202
|
0
|
|
|
|
|
|
my $folder_obj = $objdb->get_object($id); |
203
|
0
|
|
|
|
|
|
$folder_title = langstring($folder_obj->Title, $lang); |
204
|
0
|
|
|
|
|
|
my $template_file = $c->paths->site_templatebase . "/one_page_html_headline.tpl.html"; |
205
|
0
|
|
|
|
|
|
$html .= "\n"; |
206
|
0
|
|
|
|
|
|
$t->process |
207
|
|
|
|
|
|
|
($template_file, |
208
|
0
|
0
|
|
|
|
|
{ %{ $self->TemplateVars }, |
209
|
|
|
|
|
|
|
lang => $lang, |
210
|
|
|
|
|
|
|
objid => $id, |
211
|
|
|
|
|
|
|
object => $folder_obj, |
212
|
|
|
|
|
|
|
title => $folder_title, |
213
|
|
|
|
|
|
|
level => ($objdb->depth($folder_obj))[0], |
214
|
|
|
|
|
|
|
pagetype => "_folder", |
215
|
|
|
|
|
|
|
}, \$html) or die $t->error; |
216
|
0
|
|
|
|
|
|
$folder_done = 1; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my $page_title = langstring($obj->Title, $lang); |
220
|
0
|
|
|
|
|
|
$html .= "\n"; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
$outdata->{'data'}->{'language'} = $lang; |
223
|
0
|
|
0
|
|
|
|
my $keywords = langstring($obj->{Keywords}, $lang) || undef; |
224
|
|
|
|
|
|
|
#warn "Using template ".$c->paths->site_templatebase."/".$template."\n"; |
225
|
0
|
|
|
|
|
|
$template =~ s/\.tpl\.html$/_oph\.tpl\.html/; |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
$t->process($c->paths->site_templatebase."/".$template, |
228
|
0
|
0
|
0
|
|
|
|
{ %{ $self->TemplateVars }, |
229
|
|
|
|
|
|
|
objid => $mainid, |
230
|
|
|
|
|
|
|
lang => $lang, |
231
|
|
|
|
|
|
|
keywords => $keywords, |
232
|
|
|
|
|
|
|
level => ($objdb->depth($mainid))[0], |
233
|
|
|
|
|
|
|
omit_title => (defined $page_title && $page_title eq $folder_title), |
234
|
|
|
|
|
|
|
omit_pagebreak => $folder_done, |
235
|
|
|
|
|
|
|
%$outdata }, |
236
|
|
|
|
|
|
|
\$html) |
237
|
|
|
|
|
|
|
or die "Template process failed: " . $t->error . "\n"; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# XXX OK to hardcode template name? |
241
|
0
|
|
|
|
|
|
$html .= "\n"; |
242
|
0
|
|
|
|
|
|
$t->process |
243
|
|
|
|
|
|
|
($c->paths->site_templatebase . "/one_page_html_footer.tpl.html", |
244
|
0
|
0
|
|
|
|
|
{ %{ $self->TemplateVars }, |
245
|
|
|
|
|
|
|
lang => $lang, |
246
|
|
|
|
|
|
|
}, |
247
|
|
|
|
|
|
|
\$html) |
248
|
|
|
|
|
|
|
or die $t->error; |
249
|
|
|
|
|
|
|
|
250
|
0
|
0
|
|
|
|
|
if (defined $args{-o}) { |
251
|
0
|
0
|
|
|
|
|
open(HTML, ">$args{-o}") or die "Can't write to $args{-o}: $!"; |
252
|
0
|
|
|
|
|
|
print HTML $html; |
253
|
0
|
|
|
|
|
|
close HTML; |
254
|
|
|
|
|
|
|
} else { |
255
|
0
|
|
|
|
|
|
return $html; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub makeonepagehtml_send { |
260
|
0
|
|
|
0
|
0
|
|
my($self, %args) = @_; |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
my $html = makeonepagehtml($self, %args); |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
my $q = CGI->new; |
265
|
0
|
|
|
|
|
|
print $q->header("text/html"); |
266
|
0
|
|
|
|
|
|
print $html; |
267
|
0
|
|
|
|
|
|
return 1; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; |