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

patrick-canterino.de