]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Archive.pm
c71c359d6d31632750e429f150fd1c1deee95e2b
[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 my ($threads, $locked);
77 unless ($locked = lock_file($mainfile) and $threads = get_all_threads($mainfile, KILL_DELETED)) {
78 print ${$template->scrap(
79 $assign->{'errorLocking'}
80 )};
81 return;
82 }
83 unlock_file($mainfile);
84
85 my $tmplparam = {
86 $assign->{'year'} => $param->{'year'},
87 $assign->{'month'} => $param->{'month'},
88 $assign->{'monthName'} => month($param->{'month'})
89 };
90
91 #
92 # monthDocStart
93 #
94 print ${$template->scrap(
95 $assign->{'monthDocStart'},
96 $tmplparam
97 )};
98
99 #
100 # thread overview
101 #
102 for (sort keys %$threads) {
103 print ${$template->scrap(
104 $assign->{'monthThreadEntry'},
105 {
106 $assign->{'threadID'} => $_,
107 $assign->{'threadCategory'} => $threads->{$_}->[0]->{'cat'},
108 $assign->{'threadTitle'} => $threads->{$_}->[0]->{'subject'},
109 $assign->{'threadTime'} => short_hr_time($threads->{$_}->[0]->{'time'}),
110 $assign->{'threadDate'} => very_short_hr_time($threads->{$_}->[0]->{'time'}),
111 $assign->{'year'} => $param->{'year'},
112 $assign->{'month'} => $param->{'month'}
113 }
114 )};
115 }
116
117 #
118 # monthDocEnd
119 #
120 print ${$template->scrap(
121 $assign->{'monthDocEnd'},
122 $tmplparam
123 )};
124
125
126 }
127
128 ### print_thread_as_HTML () ####################################################
129 #
130 # print a complete thread
131 #
132 # Params: $mainfile thread XML file
133 # $tempfile template filename
134 # $param hash reference
135 # Return: -none-
136 #
137 sub print_thread_as_HTML($$$) {
138 my ($mainfile, $tempfile, $param) = @_;
139
140 my $assign = $param->{'assign'};
141 my $tree = $param->{'tree'};
142 my $tid = $param->{'thread'};
143
144 my $template = new Template $tempfile;
145
146 my $view = get_view_params ({
147 'adminDefault' => $param->{'adminDefault'}
148 });
149 my $xml = parse_xml_file($mainfile);
150 my $tnode = $xml->getElementsByTagName('Thread', 1)->item(0);
151 my $thread = parse_single_thread($tnode, KILL_DELETED);
152
153 my $addparam = {
154 $tree->{'year'} => $param->{'year'},
155 $tree->{'month'} => $param->{'month'}
156 };
157
158 #
159 # used to print the thread view
160 #
161 my $tpar = {
162 'thread' => $param->{'thread'},
163 'template' => $param->{'tree'},
164 'start' => '-1',
165 'cgi' => $param->{'cgi'},
166 'addParam' => $addparam
167 };
168
169 #
170 # threadDocStart
171 #
172 my $tmplparam = {
173 $assign->{'threadCategory'} => $thread->[0]->{'cat'},
174 $assign->{'threadTitle'} => $thread->[0]->{'subject'},
175 $assign->{'year'} => $param->{'year'},
176 $assign->{'month'} => $param->{'month'},
177 $assign->{'monthName'} => month($param->{'month'}),
178 $param->{'tree'}->{'main'} => html_thread($thread, $template, $tpar)
179 };
180
181 print ${$template->scrap(
182 $assign->{'threadDocStart'},
183 $tmplparam
184 )};
185
186 #
187 # print thread msgs
188 #
189 for (@$thread) {
190 my $mnode = get_message_node($xml, 't'.$tid, 'm'.$_->{'mid'});
191 my $header = get_message_header($mnode);
192 my $body = get_message_body($xml, 'm'.$_->{'mid'});
193
194 my $text = message_field (
195 $body,
196 {
197 'quoteChars' => plain($view->{'quoteChars'}),
198 'quoting' => $view->{'quoting'},
199 'startCite' => ${$template->scrap($assign->{'startCite'})},
200 'endCite' => ${$template->scrap($assign->{'endCite'})}
201 }
202 );
203
204
205 print ${$template->scrap(
206 $assign->{'posting'},
207 {
208 $assign->{'msgID'} => $_->{'mid'},
209 $assign->{'msgAuthor'} => $_->{'name'},
210 $assign->{'msgMail'} => $header->{'email'},
211 $assign->{'msgHomepage'} => $header->{'home'},
212 $assign->{'msgTime'} => hr_time($header->{'time'}),
213 $assign->{'msgCategory'} => plain($header->{'category'}),
214 $assign->{'msgSubject'} => plain($header->{'subject'}),
215 $assign->{'msgBody'} => $text
216 }
217 )};
218 }
219
220 #
221 # threadDocEnd
222 #
223 print ${$template->scrap(
224 $assign->{'threadDocEnd'},
225 $tmplparam
226 )};
227 }
228
229
230 # keep require happy
231 1;
232
233 #
234 #
235 ### end of Template::Archive ###################################################

patrick-canterino.de