]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/_thread.pm
fixed a warning producing bug, style changes, some comments added
[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 },
75 $par -> {addParam}
76 )} .
77 '</dt>';
78 }
79
80 else {
81 $html =
82 '<dd>'.
83 ${$template -> scrap (
84 $temp -> {
85 length $_ -> {cat}
86 ? 'start'
87 : 'startNC'
88 },
89 { $temp -> {name} => $_ -> {name},
90 $temp -> {subject} => $_ -> {subject},
91 $temp -> {cat} => $_ -> {cat},
92 $temp -> {time} => plain(short_hr_time ($_ -> {time})),
93 $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})
94 },
95 $par -> {addParam}
96 )}.
97 '</dd>';
98
99 return \$html;
100 }
101 }
102
103 # only subthread
104 #
105 else {
106 my $start=-1;
107 for (@$msg) {$start++; last if ($_ -> {mid} == $par -> {start});}
108 my $end = $start + $msg -> [$start] -> {answers};
109 $start++;
110 @indexes = ($start..$end);
111 $oldlevel = $startlevel = $msg -> [$start] -> {level}
112 if (defined $msg -> [$start] -> {level});
113 }
114
115 # create HTML
116 #
117 for (@$msg[@indexes]) {
118
119 if ($_ -> {level} < $oldlevel) {
120 $html.='</dl></dd>' x ($oldlevel - $_ -> {level});}
121
122 $oldlevel = $_ -> {level};
123
124 if ($_ -> {answers}) {
125 $html.=
126 '<dd><dl><dt>'.
127 ${$template -> scrap (
128 $temp -> {
129 length $_ -> {cat}
130 ? 'line'
131 : 'lineNC'
132 },
133 { $temp -> {name} => $_ -> {name},
134 $temp -> {subject} => $_ -> {subject},
135 $temp -> {cat} => $_ -> {cat},
136 $temp -> {time} => plain(short_hr_time ($_ -> {time})),
137 $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})
138 },
139 $par -> {addParam}
140 )}.
141 '</dt>';
142 }
143 else {
144 $html.=
145 '<dd>'.
146 ${$template -> scrap (
147 $temp -> {
148 length $_ -> {cat}
149 ? 'line'
150 : 'lineNC'
151 },
152 { $temp -> {name} => $_ -> {name},
153 $temp -> {subject} => $_ -> {subject},
154 $temp -> {cat} => $_ -> {cat},
155 $temp -> {time} => plain(short_hr_time ($_ -> {time})),
156 $temp -> {link} => query_string({$t => $tid, $p => $_ -> {mid}})
157 },
158 $par -> {addParam}
159 )}.
160 '</dd>';
161 }
162 }
163 $html.='</dl></dd>' x ($oldlevel - $startlevel);
164
165 \$html;
166 }
167
168 # keep require happy
169 1;
170
171 #
172 #
173 ### end of Template::_thread ###################################################
174

patrick-canterino.de