]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Archive.pm
copyright holders modified
[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-08 #
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_overview_as_HTML
45 print_year_as_HTML
46 print_month_as_HTML
47 print_thread_as_HTML
48 );
49
50
51 ### print_overview_as_HTML () ##################################################
52 #
53 # archive entry
54 #
55 # Params: $arcdir main archive directory
56 # $tempfile template filename
57 # $param hash reference
58 # Return: -none-
59 #
60 sub print_overview_as_HTML($$$) {
61 my ($arcdir, $tempfile, $param) = @_;
62
63 my $assign = $param->{'assign'};
64
65 my $template = new Template $tempfile;
66
67 #
68 # archiveDocStart
69 #
70 print ${$template->scrap(
71 $assign->{'archiveDocStart'}
72 )};
73
74 #
75 # globbing to find year directories
76 #
77 for (<$arcdir????>) {
78 s/$arcdir//;
79 print ${$template->scrap(
80 $assign->{'archiveDocEntry'},
81 {
82 $assign->{'year'} => $_
83 }
84
85 )};
86 }
87
88 # for (my $month = 1; $month <= 12; $month++) {
89 # if (-e $yeardir.$month.'/') {
90 # print ${$template->scrap(
91 # $assign->{'yearDocEntry'},
92 # {
93 # $assign->{'year'} => $param->{'year'},
94 # $assign->{'month'} => $month,
95 # $assign->{'monthName'} => month($month)
96 # }
97 # )};
98 # }
99 # }
100
101 #
102 # archiveDocEnd
103 #
104 print ${$template->scrap(
105 $assign->{'archiveDocEnd'}
106 )};
107 }
108
109 ### print_year_as_HTML () ######################################################
110 #
111 # yearly overview over months
112 #
113 # Params: $yeardir directory, which contains month directories
114 # $tempfile template filename
115 # $param hash reference
116 # Return: -none-
117 #
118 sub print_year_as_HTML($$$) {
119 my ($yeardir, $tempfile, $param) = @_;
120
121 my $assign = $param->{'assign'};
122
123 my $template = new Template $tempfile;
124
125 #
126 # check if this year's archive exist
127 #
128 unless (-e $yeardir) {
129 print ${$template->scrap(
130 $assign->{'error'},
131 {
132 $assign->{'errorText'} => "Es existieren keine Nachrichten für dieses Jahr."
133 }
134 )};
135 }
136
137 my $tmplparam = {
138 $assign->{'year'} => $param->{'year'},
139 };
140
141 #
142 # yearDocStart
143 #
144 print ${$template->scrap(
145 $assign->{'yearDocStart'},
146 $tmplparam
147 )};
148
149 for (my $month = 1; $month <= 12; $month++) {
150 if (-e $yeardir.$month.'/') {
151 print ${$template->scrap(
152 $assign->{'yearDocEntry'},
153 {
154 $assign->{'year'} => $param->{'year'},
155 $assign->{'month'} => $month,
156 $assign->{'monthName'} => month($month)
157 }
158 )};
159 }
160 }
161
162 #
163 # yearDocEnd
164 #
165 print ${$template->scrap(
166 $assign->{'yearDocEnd'},
167 $tmplparam
168 )};
169 }
170
171 ### print_month_as_HTML () #####################################################
172 #
173 # monthly overview over threads
174 #
175 # Params: $mainfile XML file on a per-month base
176 # $tempfile template filename
177 # $param hash reference
178 # Return: -none-
179 #
180 sub print_month_as_HTML($$$) {
181 my ($mainfile, $tempfile, $param) = @_;
182
183 my $assign = $param->{'assign'};
184
185 my $template = new Template $tempfile;
186
187 #
188 # check if XML file exists
189 #
190 unless (-e $mainfile) {
191 print ${$template->scrap(
192 $assign->{'error'},
193 {
194 $assign->{'errorText'} => "Es existieren keine Nachrichten für diesen Monat."
195 }
196 )};
197 return;
198 }
199
200 #
201 # try locking and read/parse threads
202 #
203 my ($threads, $locked);
204 unless ($locked = lock_file($mainfile) and $threads = get_all_threads($mainfile, KILL_DELETED)) {
205 print ${$template->scrap(
206 $assign->{'error'},
207 {
208 $assign->{'errorText'} => "Fehler beim Locking."
209 }
210 )};
211 return;
212 }
213 unlock_file($mainfile);
214
215 my $tmplparam = {
216 $assign->{'year'} => $param->{'year'},
217 $assign->{'month'} => $param->{'month'},
218 $assign->{'monthName'} => month($param->{'month'})
219 };
220
221 #
222 # monthDocStart
223 #
224 print ${$template->scrap(
225 $assign->{'monthDocStart'},
226 $tmplparam
227 )};
228
229 #
230 # thread overview
231 #
232 for (sort keys %$threads) {
233 print ${$template->scrap(
234 $assign->{'monthThreadEntry'},
235 {
236 $assign->{'threadID'} => $_,
237 $assign->{'threadCategory'} => $threads->{$_}->[0]->{'cat'},
238 $assign->{'threadTitle'} => $threads->{$_}->[0]->{'subject'},
239 $assign->{'threadTime'} => short_hr_time($threads->{$_}->[0]->{'time'}),
240 $assign->{'threadDate'} => very_short_hr_time($threads->{$_}->[0]->{'time'}),
241 $assign->{'year'} => $param->{'year'},
242 $assign->{'month'} => $param->{'month'}
243 }
244 )};
245 }
246
247 #
248 # monthDocEnd
249 #
250 print ${$template->scrap(
251 $assign->{'monthDocEnd'},
252 $tmplparam
253 )};
254 }
255
256 ### print_thread_as_HTML () ####################################################
257 #
258 # print a complete thread
259 #
260 # Params: $mainfile thread XML file
261 # $tempfile template filename
262 # $param hash reference
263 # Return: -none-
264 #
265 sub print_thread_as_HTML($$$) {
266 my ($mainfile, $tempfile, $param) = @_;
267
268 my $assign = $param->{'assign'};
269 my $tree = $param->{'tree'};
270 my $tid = $param->{'thread'};
271
272 my $template = new Template $tempfile;
273
274 #
275 # check if XML file exists
276 #
277 unless (-e $mainfile) {
278 print ${$template->scrap(
279 $assign->{'error'},
280 {
281 $assign->{'errorText'} => "Der gewünschte Thread existiert nicht."
282 }
283 )};
284 return;
285 }
286
287 my $view = get_view_params ({
288 'adminDefault' => $param->{'adminDefault'}
289 });
290 my $xml = parse_xml_file($mainfile);
291 my $tnode = $xml->getElementsByTagName('Thread', 1)->item(0);
292 my $thread = parse_single_thread($tnode, KILL_DELETED);
293
294 my $addparam = {
295 $tree->{'year'} => $param->{'year'},
296 $tree->{'month'} => $param->{'month'}
297 };
298
299 #
300 # used to print the thread view
301 #
302 my $tpar = {
303 'thread' => $param->{'thread'},
304 'template' => $param->{'tree'},
305 'start' => '-1',
306 'cgi' => $param->{'cgi'},
307 'addParam' => $addparam
308 };
309
310 #
311 # threadDocStart
312 #
313 my $tmplparam = {
314 $assign->{'threadCategory'} => $thread->[0]->{'cat'},
315 $assign->{'threadTitle'} => $thread->[0]->{'subject'},
316 $assign->{'year'} => $param->{'year'},
317 $assign->{'month'} => $param->{'month'},
318 $assign->{'monthName'} => month($param->{'month'}),
319 $param->{'tree'}->{'main'} => html_thread($thread, $template, $tpar)
320 };
321
322 print ${$template->scrap(
323 $assign->{'threadDocStart'},
324 $tmplparam,
325 1
326 )};
327
328 #
329 # print thread msgs
330 #
331 for (@$thread) {
332 my $mnode = get_message_node($xml, 't'.$tid, 'm'.$_->{'mid'});
333 my $header = get_message_header($mnode);
334 my $body = get_message_body($xml, 'm'.$_->{'mid'});
335
336 my $text = message_field(
337 $body,
338 {
339 'quoteChars' => plain($view->{'quoteChars'}),
340 'quoting' => $view->{'quoting'},
341 'startCite' => ${$template->scrap($assign->{'startCite'})},
342 'endCite' => ${$template->scrap($assign->{'endCite'})}
343 }
344 );
345
346
347 print ${$template->scrap(
348 $assign->{'posting'},
349 {
350 $assign->{'msgID'} => $_->{'mid'},
351 $assign->{'msgAuthor'} => $_->{'name'},
352 $assign->{'msgMail'} => $header->{'email'},
353 $assign->{'msgHomepage'} => $header->{'home'},
354 $assign->{'msgTime'} => hr_time($header->{'time'}),
355 $assign->{'msgCategory'} => plain($header->{'category'}),
356 $assign->{'msgSubject'} => plain($header->{'subject'}),
357 $assign->{'msgBody'} => $text
358 },
359 1
360 )};
361 }
362
363 #
364 # threadDocEnd
365 #
366 print ${$template->scrap(
367 $assign->{'threadDocEnd'},
368 $tmplparam,
369 1
370 )};
371 }
372
373
374 # keep require happy
375 1;
376
377 #
378 #
379 ### end of Template::Archive ###################################################

patrick-canterino.de