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

patrick-canterino.de