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

patrick-canterino.de