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

patrick-canterino.de