]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Archive.pm
08d215cf7f1009718a55b74474373c1ef5237358
[selfforum.git] / selfforum-cgi / shared / Template / Archive.pm
1 package Template::Archive;
2
3 ################################################################################
4 # #
5 # File: shared/Template/Archive.pm #
6 # #
7 # Authors: Frank Schoenmann <fs@tower.de>, 2001-06-04 #
8 # #
9 # Description: archive display #
10 # #
11 ################################################################################
12
13 use strict;
14
15 use Lock qw(:READ);
16 use Encode::Posting;
17 use Encode::Plain; $Encode::Plain::utf8 = 1;
18 use Posting::_lib qw(
19 get_message_node
20 get_message_header
21 get_message_body
22
23 get_all_threads
24 parse_single_thread
25 parse_xml_file
26
27 very_short_hr_time
28 short_hr_time
29 hr_time
30 month
31
32 KILL_DELETED
33 );
34 use Template;
35 use Template::_conf;
36 use Template::_thread;
37
38 ################################################################################
39 #
40 # Export
41 #
42 use base qw(Exporter);
43 @Template::Archive::EXPORT = qw(
44 print_month_as_HTML
45 print_thread_as_HTML
46 );
47
48
49 ### print_year_as_HTML () ######################################################
50 #
51 # yearly overview over months
52 #
53 # Params:
54 # $tempfile template filename
55 # $param hash reference
56 # Return: -none-
57 #
58
59
60 ### print_month_as_HTML () #####################################################
61 #
62 # monthly overview over threads
63 #
64 # Params: $mainfile XML file on a per-month base
65 # $tempfile template filename
66 # $param hash reference
67 # Return: -none-
68 #
69 sub print_month_as_HTML($$$) {
70 my ($mainfile, $tempfile, $param) = @_;
71
72 my $assign = $param->{'assign'};
73
74 my $template = new Template $tempfile;
75
76 #
77 # check if XML file exists
78 #
79 unless (-e $mainfile) {
80 print ${$template->scrap(
81 $assign->{'error'},
82 {
83 $assign->{'errorText'} => "Es existieren keine Nachrichten für diesen Monat."
84 }
85 )};
86 return;
87 }
88
89 #
90 # try locking and read/parse threads
91 #
92 my ($threads, $locked);
93 unless ($locked = lock_file($mainfile) and $threads = get_all_threads($mainfile, KILL_DELETED)) {
94 print ${$template->scrap(
95 $assign->{'error'},
96 {
97 $assign->{'errorText'} => "Fehler beim Locking."
98 }
99 )};
100 return;
101 }
102 unlock_file($mainfile);
103
104 my $tmplparam = {
105 $assign->{'year'} => $param->{'year'},
106 $assign->{'month'} => $param->{'month'},
107 $assign->{'monthName'} => month($param->{'month'})
108 };
109
110 #
111 # monthDocStart
112 #
113 print ${$template->scrap(
114 $assign->{'monthDocStart'},
115 $tmplparam
116 )};
117
118 #
119 # thread overview
120 #
121 for (sort keys %$threads) {
122 print ${$template->scrap(
123 $assign->{'monthThreadEntry'},
124 {
125 $assign->{'threadID'} => $_,
126 $assign->{'threadCategory'} => $threads->{$_}->[0]->{'cat'},
127 $assign->{'threadTitle'} => $threads->{$_}->[0]->{'subject'},
128 $assign->{'threadTime'} => short_hr_time($threads->{$_}->[0]->{'time'}),
129 $assign->{'threadDate'} => very_short_hr_time($threads->{$_}->[0]->{'time'}),
130 $assign->{'year'} => $param->{'year'},
131 $assign->{'month'} => $param->{'month'}
132 }
133 )};
134 }
135
136 #
137 # monthDocEnd
138 #
139 print ${$template->scrap(
140 $assign->{'monthDocEnd'},
141 $tmplparam
142 )};
143
144
145 }
146
147 ### print_thread_as_HTML () ####################################################
148 #
149 # print a complete thread
150 #
151 # Params: $mainfile thread XML file
152 # $tempfile template filename
153 # $param hash reference
154 # Return: -none-
155 #
156 sub print_thread_as_HTML($$$) {
157 my ($mainfile, $tempfile, $param) = @_;
158
159 my $assign = $param->{'assign'};
160 my $tree = $param->{'tree'};
161 my $tid = $param->{'thread'};
162
163 my $template = new Template $tempfile;
164
165 #
166 # check if XML file exists
167 #
168 unless (-e $mainfile) {
169 print ${$template->scrap(
170 $assign->{'error'},
171 {
172 $assign->{'errorText'} => "Der gewünschte Thread existiert nicht."
173 }
174 )};
175 return;
176 }
177
178 my $view = get_view_params ({
179 'adminDefault' => $param->{'adminDefault'}
180 });
181 my $xml = parse_xml_file($mainfile);
182 my $tnode = $xml->getElementsByTagName('Thread', 1)->item(0);
183 my $thread = parse_single_thread($tnode, KILL_DELETED);
184
185 my $addparam = {
186 $tree->{'year'} => $param->{'year'},
187 $tree->{'month'} => $param->{'month'}
188 };
189
190 #
191 # used to print the thread view
192 #
193 my $tpar = {
194 'thread' => $param->{'thread'},
195 'template' => $param->{'tree'},
196 'start' => '-1',
197 'cgi' => $param->{'cgi'},
198 'addParam' => $addparam
199 };
200
201 #
202 # threadDocStart
203 #
204 my $tmplparam = {
205 $assign->{'threadCategory'} => $thread->[0]->{'cat'},
206 $assign->{'threadTitle'} => $thread->[0]->{'subject'},
207 $assign->{'year'} => $param->{'year'},
208 $assign->{'month'} => $param->{'month'},
209 $assign->{'monthName'} => month($param->{'month'}),
210 $param->{'tree'}->{'main'} => html_thread($thread, $template, $tpar)
211 };
212
213 print ${$template->scrap(
214 $assign->{'threadDocStart'},
215 $tmplparam,
216 1
217 )};
218
219 #
220 # print thread msgs
221 #
222 for (@$thread) {
223 my $mnode = get_message_node($xml, 't'.$tid, 'm'.$_->{'mid'});
224 my $header = get_message_header($mnode);
225 my $body = get_message_body($xml, 'm'.$_->{'mid'});
226
227 my $text = message_field(
228 $body,
229 {
230 'quoteChars' => plain($view->{'quoteChars'}),
231 'quoting' => $view->{'quoting'},
232 'startCite' => ${$template->scrap($assign->{'startCite'})},
233 'endCite' => ${$template->scrap($assign->{'endCite'})}
234 }
235 );
236
237
238 print ${$template->scrap(
239 $assign->{'posting'},
240 {
241 $assign->{'msgID'} => $_->{'mid'},
242 $assign->{'msgAuthor'} => $_->{'name'},
243 $assign->{'msgMail'} => $header->{'email'},
244 $assign->{'msgHomepage'} => $header->{'home'},
245 $assign->{'msgTime'} => hr_time($header->{'time'}),
246 $assign->{'msgCategory'} => plain($header->{'category'}),
247 $assign->{'msgSubject'} => plain($header->{'subject'}),
248 $assign->{'msgBody'} => $text
249 },
250 1
251 )};
252 }
253
254 #
255 # threadDocEnd
256 #
257 print ${$template->scrap(
258 $assign->{'threadDocEnd'},
259 $tmplparam,
260 1
261 )};
262 }
263
264
265 # keep require happy
266 1;
267
268 #
269 #
270 ### end of Template::Archive ###################################################

patrick-canterino.de