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

patrick-canterino.de