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

patrick-canterino.de