]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/_thread.pm
_thread.pm: If main forum view is displayed by another script than the
[selfforum.git] / selfforum-cgi / shared / Template / _thread.pm
1 package Template::_thread;
2
3 ################################################################################
4 # #
5 # File: shared/Template/_thread.pm #
6 # #
7 # Authors: André Malo <nd@o3media.de> #
8 # Christian Kruse <ckruse@wwwtech.de> #
9 # #
10 # Description: convert parsed thread to HTML #
11 # #
12 ################################################################################
13
14 use strict;
15 use vars qw(
16 @EXPORT
17 );
18
19 use Encode::Plain; $Encode::Plain::utf8 = 1;
20 use Posting::_lib qw(short_hr_time);
21 use Template;
22 use Template::_query;
23 use Data::Dumper;
24
25 ################################################################################
26 #
27 # Version check
28 #
29 # last modified:
30 # $Date$ (GMT)
31 # by $Author$
32 #
33 sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
34
35 ################################################################################
36 #
37 # Export
38 #
39 use base qw(Exporter);
40 @EXPORT = qw(html_thread);
41
42 ### html_thread () #############################################################
43 #
44 # create HTML string
45 #
46 # Params: $msg Reference of Message-Array
47 # (Output of parse_single_thread in Posting::_lib)
48 # $template Template object
49 # $par Hash Reference (see doc for details)
50 # $params Additional parameters
51 #
52 # Return: Reference of HTML String
53 #
54 sub html_thread ($$$;$) {
55 my ($msg, $template, $par, $params) = @_;
56 my $additionalVariables = $params->{'additionalVariables'} || {};
57 my $actions = {
58 'action' => $params->{'action'},
59 'actionDeleted' => $params->{'actionDeleted'}
60 };
61 my $base = $params->{'base_link'};
62
63 return \'' unless @$msg;
64
65 my $temp = $par->{'template'};
66 my $i = $par->{'cgi'}->{'user'};
67 my $t = $par->{'cgi'}->{'thread'};
68 my $p = $par->{'cgi'}->{'posting'};
69 my $c = $par->{'cgi'}->{'command'};
70 my $tid = $par->{'thread'};
71 my $html = '';
72 my $startlevel = 0;
73 my $oldlevel = 0;
74 my @indexes;
75
76 # whole thread
77 if ($par->{'start'} == -1) {
78 $_ = $msg->[0];
79 @indexes = (1 .. $_->{answers});
80
81 my $del = $_->{deleted} ? 'Deleted' : '';
82 my $action = $actions->{'action'.$del}; $action =~ s/\Q{mid}\E/$_->{mid}/g;
83
84 if ($_->{answers}) {
85 $html =
86 '<dd><dl><dt>'.
87
88 ${$template->scrap(
89 $temp->{
90 (length $_->{'cat'}
91 ? 'start'
92 : 'startNC').$del
93 },
94 { $temp->{'name'} => $_->{'name'},
95 $temp->{'subject'} => $_->{'subject'},
96 $temp->{'cat'} => $_->{'cat'},
97 $temp->{'time'} => plain(short_hr_time($_->{'time'})),
98 $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}),
99 $temp->{'tid'} => $tid,
100 $temp->{'mid'} => $_->{'mid'},
101 $temp->{'command'} => $action,
102 %{$additionalVariables}
103 },
104 $par->{'addParam'}
105 )} .
106 '</dt>';
107 }
108
109 else {
110 $html =
111 '<dd>'.
112 ${$template->scrap(
113 $temp->{
114 (length $_->{'cat'}
115 ? 'start'
116 : 'startNC').$del
117 },
118 { $temp->{'name'} => $_->{'name'},
119 $temp->{'subject'} => $_->{'subject'},
120 $temp->{'cat'} => $_->{'cat'},
121 $temp->{'time'} => plain(short_hr_time ($_->{'time'})),
122 $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}),
123 $temp->{'tid'} => $tid,
124 $temp->{'mid'} => $_->{'mid'},
125 $temp->{'command'} => $action,
126 %{$additionalVariables}
127 },
128 $par->{'addParam'}
129 )}.
130 '</dd>';
131
132 return \$html;
133 }
134 }
135
136 # only subthread
137 #
138 else {
139 my $start = -1;
140 for (@$msg) { $start++; last if ($_->{'mid'} == $par->{'start'}); }
141 my $end = $start + $msg->[$start]->{'answers'};
142 $start++;
143 @indexes = ($start .. $end);
144 $oldlevel = $startlevel = $msg->[$start]->{'level'}
145 if (defined $msg->[$start]->{'level'});
146 }
147
148 # create HTML
149 #
150 for (@$msg[@indexes]) {
151 my $del = $_->{'deleted'} ? 'Deleted' : '';
152 my $action = $actions->{'action'.$del}; $action =~ s/\Q{mid}\E/$_->{mid}/g;
153
154 if ($_->{'level'} < $oldlevel) {
155 $html .= '</dl></dd>' x ($oldlevel - $_->{'level'});
156 }
157
158 $oldlevel = $_->{'level'};
159
160 if ($_->{'answers'}) {
161 $html .=
162 '<dd><dl><dt>'.
163 ${$template->scrap(
164 $temp->{
165 (length $_->{'cat'}
166 ? 'line'
167 : 'lineNC').$del
168 },
169 { $temp->{'name'} => $_->{'name'},
170 $temp->{'subject'} => $_->{'subject'},
171 $temp->{'cat'} => $_->{'cat'},
172 $temp->{'time'} => plain(short_hr_time ($_->{'time'})),
173 $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}),
174 $temp->{'tid'} => $tid,
175 $temp->{'mid'} => $_->{'mid'},
176 $temp->{'command'} => $action,
177 %{$additionalVariables}
178 },
179 $par->{'addParam'}
180 )}.
181 '</dt>';
182 }
183 else {
184 $html .=
185 '<dd>'.
186 ${$template->scrap(
187 $temp->{
188 (length $_->{'cat'}
189 ? 'line'
190 : 'lineNC').$del
191 },
192 { $temp->{'name'} => $_->{'name'},
193 $temp->{'subject'} => $_->{'subject'},
194 $temp->{'cat'} => $_->{'cat'},
195 $temp->{'time'} => plain(short_hr_time ($_->{'time'})),
196 $temp->{'link'} => $base.query_string({$t => $tid, $p => $_->{'mid'}}),
197 $temp->{'tid'} => $tid,
198 $temp->{'mid'} => $_->{'mid'},
199 $temp->{'command'} => $action,
200 %{$additionalVariables}
201 },
202 $par->{'addParam'}
203 )}.
204 '</dd>';
205 }
206 }
207 $html .= '</dl></dd>' x ($oldlevel - $startlevel);
208
209 \$html;
210 }
211
212 # keep 'require' happy
213 1;
214
215 #
216 #
217 ### end of Template::_thread ###################################################

patrick-canterino.de