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

patrick-canterino.de