]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Archive.pm
1 package Template
::Archive
;
3 ################################################################################
5 # File: shared/Template/Archive.pm #
7 # Authors: André Malo <nd@o3media.de> #
8 # Frank Schönmann <fs@tower.de> #
10 # Description: archive display #
12 ################################################################################
21 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
40 use Template
::_thread
;
42 ################################################################################
50 sub VERSION
{(q
$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
52 ################################################################################
56 use base
qw(Exporter);
58 print_overview_as_HTML
64 ### print_overview_as_HTML () ##################################################
68 # Params: $arcdir main archive directory
69 # $tempfile template filename
70 # $param hash reference
73 sub print_overview_as_HTML
($$$) {
74 my ($arcdir, $tempfile, $param) = @_;
76 my $assign = $param->{'assign'};
78 my $template = new Template
$tempfile;
83 print ${$template->scrap(
84 $assign->{'archiveDocStart'}
88 # globbing to find year directories
92 print ${$template->scrap(
93 $assign->{'archiveDocEntry'},
95 $assign->{'year'} => $_
101 # for (my $month = 1; $month <= 12; $month++) {
102 # if (-e $yeardir.$month.'/') {
103 # print ${$template->scrap(
104 # $assign->{'yearDocEntry'},
106 # $assign->{'year'} => $param->{'year'},
107 # $assign->{'month'} => $month,
108 # $assign->{'monthName'} => month($month)
117 print ${$template->scrap(
118 $assign->{'archiveDocEnd'}
122 ### print_year_as_HTML () ######################################################
124 # yearly overview over months
126 # Params: $yeardir directory, which contains month directories
127 # $tempfile template filename
128 # $param hash reference
131 sub print_year_as_HTML
($$$) {
132 my ($yeardir, $tempfile, $param) = @_;
134 my $assign = $param->{'assign'};
136 my $template = new Template
$tempfile;
139 # check if this year's archive exist
141 unless (-e
$yeardir) {
142 print ${$template->scrap(
145 $assign->{'errorText'} => "Es existieren keine Nachrichten für dieses Jahr."
151 $assign->{'year'} => $param->{'year'},
157 print ${$template->scrap(
158 $assign->{'yearDocStart'},
162 for (my $month = 1; $month <= 12; $month++) {
163 if (-e
$yeardir.$month.'/') {
164 print ${$template->scrap(
165 $assign->{'yearDocEntry'},
167 $assign->{'year'} => $param->{'year'},
168 $assign->{'month'} => $month,
169 $assign->{'monthName'} => month
($month)
178 print ${$template->scrap(
179 $assign->{'yearDocEnd'},
184 ### print_month_as_HTML () #####################################################
186 # monthly overview over threads
188 # Params: $mainfile XML file on a per-month base
189 # $tempfile template filename
190 # $param hash reference
193 sub print_month_as_HTML
($$$) {
194 my ($mainfile, $tempfile, $param) = @_;
195 my $main = new Lock
($mainfile);
197 my $assign = $param->{'assign'};
199 my $template = new Template
$tempfile;
202 # check if XML file exists
204 unless (-f
$main->filename) {
205 print ${$template->scrap(
208 $assign->{'errorText'} => "Es existieren keine Nachrichten für diesen Monat."
215 # try locking and read/parse threads
218 unless ($main->lock (LH_SHARED
) and $threads = get_all_threads
($mainfile, KILL_DELETED
)) {
219 print ${$template->scrap(
222 $assign->{'errorText'} => "Fehler beim Locking."
230 $assign->{'year'} => $param->{'year'},
231 $assign->{'month'} => $param->{'month'},
232 $assign->{'monthName'} => month
($param->{'month'})
238 print ${$template->scrap(
239 $assign->{'monthDocStart'},
246 for (sort {$a <=> $b} keys %$threads) {
247 print ${$template->scrap(
248 $assign->{'monthThreadEntry'},
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'}
264 print ${$template->scrap(
265 $assign->{'monthDocEnd'},
270 ### print_thread_as_HTML () ####################################################
272 # print a complete thread
274 # Params: $mainfile thread XML file
275 # $tempfile template filename
276 # $param hash reference
279 sub print_thread_as_HTML
($$$) {
280 my ($mainfile, $tempfile, $param) = @_;
282 my $assign = $param->{'assign'};
283 my $tree = $param->{'tree'};
284 my $tid = $param->{'thread'};
286 my $template = new Template
$tempfile;
289 # check if XML file exists
291 unless (-f
$mainfile) {
292 print ${$template->scrap(
295 $assign->{'errorText'} => "Der gewünschte Thread existiert nicht."
301 my $view = get_view_params
({
302 'adminDefault' => $param->{'adminDefault'}
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
);
309 $tree->{'year'} => $param->{'year'},
310 $tree->{'month'} => $param->{'month'}
314 # used to print the thread view
317 'thread' => $param->{'thread'},
318 'template' => $param->{'tree'},
320 'cgi' => $param->{'cgi'},
321 'addParam' => $addparam
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)
336 print ${$template->scrap(
337 $assign->{'threadDocStart'},
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'});
350 my $text = message_field
(
353 'quoteChars' => plain
($view->{'quoteChars'}),
354 'quoting' => $view->{'quoting'},
355 'startCite' => ${$template->scrap($assign->{'startCite'})},
356 'endCite' => ${$template->scrap($assign->{'endCite'})}
361 print ${$template->scrap(
362 $assign->{'posting'},
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
380 print ${$template->scrap(
381 $assign->{'threadDocEnd'},
388 # keep 'require' happy
393 ### end of Template::Archive ###################################################
patrick-canterino.de