]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Posting.pm
7f0d94022fcba6058dee0c672e8b3c1107ea786c
[selfforum.git] / selfforum-cgi / shared / Template / Posting.pm
1 package Template::Posting;
2
3 ################################################################################
4 # #
5 # File: shared/Template/Posting.pm #
6 # #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-06-16 #
8 # #
9 # Description: show HTML formatted posting #
10 # #
11 ################################################################################
12
13 use strict;
14 use vars qw(
15 @EXPORT
16 $VERSION
17 );
18
19 use Encode::Posting;
20 use Encode::Plain; $Encode::Plain::utf8 = 1;
21 use Id;
22 use Lock;
23 use Posting::_lib qw(
24 get_message_node
25 get_message_header
26 get_message_body
27 parse_single_thread
28 parse_xml_file
29 hr_time
30 );
31 use Posting::Cache;
32 use Template;
33 use Template::_conf;
34 use Template::_query;
35 use Template::_thread;
36
37 use XML::DOM;
38
39 ################################################################################
40 #
41 # Version check
42 #
43 $VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
44
45 ################################################################################
46 #
47 # Export
48 #
49 use base qw(Exporter);
50 @EXPORT = qw(
51 print_posting_as_HTML
52 message_as_HTML
53 );
54
55 ### print_posting_as_HTML () ###################################################
56 #
57 # print HTML formatted Posting to STDOUT
58 #
59 # Params: $threadpath - /path/to/thread_files
60 # $tempfile - template file
61 # $param - Hash-Reference (see doc for details)
62 #
63 # Return: -none-
64 #
65 sub print_posting_as_HTML ($$$) {
66 my ($threadpath, $tempfile, $param) = @_;
67
68 my $template = new Template $tempfile;
69 my $assign = $param -> {assign};
70
71 my $view = get_view_params ({
72 adminDefault => $param -> {adminDefault}
73 });
74
75 my $fh = new Lock ($threadpath.'t'.$param -> {thread}.'.xml');
76
77 unless ($fh -> lock (LH_SHARED)) {
78 print ${$template -> scrap (
79 $assign -> {errorDoc},
80 { $assign -> {errorText} => $template -> insert (
81 $assign -> {
82 $fh -> masterlocked
83 ? 'notAvailable'
84 : 'occupied'
85 }
86 )
87 }
88 )};
89 }
90 else {
91 unless (-f $fh -> filename) {
92 $fh -> unlock;
93 print ${$template -> scrap ($assign -> {errorDoc}, {$assign -> {errorText} => $template -> insert ($assign->{notAvailable})})};
94 }
95 else {
96 my $xml = parse_xml_file ($fh -> filename); #...
97 $fh -> unlock;
98
99 unless ($xml) {
100 print ${$template -> scrap ($assign -> {errorDoc}, {$assign -> {errorText} => $template -> insert ($assign->{corrupt})})};
101 }
102 else {
103 my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting});
104
105 unless ($mnode and not $mnode->getAttribute('invisible')) {
106 print ${$template -> scrap (
107 $assign -> {errorDoc},
108 { $assign -> {errorText} => $template -> insert ($assign -> {'notAvailable'}) }
109 )};
110 }
111 else {
112 my $pnode = $mnode -> getParentNode;
113 my $header = get_message_header ($mnode);
114 my $msg = parse_single_thread ($tnode, $param -> {showDeleted}, $view -> {sortedMsg});
115 my $pheader = ($pnode -> getNodeName eq 'Message')?get_message_header ($pnode):{};
116
117 my $formdata = $param -> {form} -> {data};
118 my $formact = $param -> {form} -> {action};
119
120 my $body = get_message_body ($xml, 'm'.$param -> {posting});
121
122 my $text = message_field (
123 $body,
124 { quoteChars => plain($view -> {quoteChars}),
125 quoting => $view -> {quoting},
126 startCite => ${$template -> scrap ($assign -> {startCite})},
127 endCite => ${$template -> scrap ($assign -> {endCite})}
128 }
129 );
130
131 my $area = answer_field (
132 $body,
133 { quoteArea => 1,
134 quoteChars => plain($view -> {quoteChars}),
135 messages => $param -> {messages}
136 }
137 );
138
139 my $pars = {};
140
141 $pars -> {$formdata -> {$_} -> {assign} -> {name}} = plain($formdata -> {$_} -> {name})
142 for (qw(
143 posterBody
144 uniqueID
145 followUp
146 quoteChar
147 userID
148 posterName
149 posterEmail
150 posterURL
151 posterImage
152 )
153 );
154
155 my $cgi = $param -> {cgi};
156
157 my $tpar = {
158 thread => $param -> {thread},
159 template => $param -> {tree},
160 start => $param -> {posting},
161 cgi => $cgi
162 };
163
164 my $parent_pars;
165
166 $parent_pars = {
167 $assign->{parentTitle} => plain(defined $pheader->{subject} ? $pheader->{subject} : ''),
168 $assign->{parentCat} => plain(defined $pheader->{category} ? $pheader->{category} : ''),
169 $assign->{parentName} => plain(defined $pheader->{name} ? $pheader->{name} : ''),
170 $assign->{parentTime} => plain(hr_time($pheader->{time})),
171 $assign->{parentLink} => query_string (
172 { $cgi -> {thread} => $param -> {thread},
173 $cgi -> {posting} => ($pnode -> getAttribute ('id') =~ /(\d+)/)[0]
174 })
175 } if (%$pheader);
176
177 print ${$template -> scrap (
178 $assign->{mainDoc},
179 { $assign->{name} => plain(defined $header->{name} ? $header->{name} : ''),
180 $assign->{email} => plain(defined $header->{email} ? $header->{email} : ''),
181 $assign->{home} => plain(defined $header->{home} ? $header->{home} : ''),
182 $assign->{image} => plain(defined $header->{image} ? $header->{image} : ''),
183 $assign->{time} => plain(hr_time($header->{time})),
184 $assign->{message} => $text,
185 $assign->{messageTitle} => plain(defined $header->{subject} ? $header->{subject} : ''),
186 $assign->{messageCat} => plain(defined $header->{category} ? $header->{category} : ''),
187 $param->{tree}->{main} => html_thread ($msg, $template, $tpar),
188 $formact->{post}->{assign} => $formact->{post}->{url},
189 $formact->{vote}->{assign} => $formact->{vote}->{url},
190 $formdata->{posterBody}->{assign}->{value} => $area,
191 $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id),
192 $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}),
193 $formdata->{quoteChar} ->{assign}->{value} => "&#255;".plain(defined $view -> {quoteChars} ? $view -> {quoteChars} : ''),
194 $formdata->{userID} ->{assign}->{value} => '',
195 $assign->{firsttime} => $param->{firsttime} ? $param->{firsttime} : '',
196 $assign->{voted} => $param->{voted} ? $param->{voted} : ''
197 },
198 $pars,
199 $parent_pars
200 )};
201
202 # all output done
203 #
204 close STDOUT;
205
206 if ($param->{firsttime}) {
207 my $cache = new Posting::Cache ($param->{cachepath});
208 $cache -> add_view (
209 { thread => $param -> {thread},
210 posting => $param -> {posting}
211 }
212 );
213 }
214 }
215 }
216 }
217 }
218
219 return;
220 }
221
222 ### message_as_HTML () #########################################################
223 #
224 # create HTML String for the Messagetext
225 #
226 # Params: $xml - XML::DOM::Document object
227 # $template - Template object
228 # $param - Hash reference
229 # (assign, posting, quoteChars, quoting)
230 #
231 # Return: HTML String
232 #
233 sub message_as_HTML ($$$) {
234 my ($xml, $template, $param) = @_;
235
236 my $assign = $param -> {assign};
237 my $body = get_message_body ($xml, $param -> {posting});
238
239 my $text = message_field (
240 $body,
241 { quoteChars => plain ($param -> {quoteChars}),
242 quoting => $param -> {quoting},
243 startCite => ${$template -> scrap ($assign -> {startCite})},
244 endCite => ${$template -> scrap ($assign -> {endCite})}
245 }
246 );
247
248 # return
249 $text;
250 }
251
252 # keep 'require' happy
253 1;
254
255 #
256 #
257 ### end of Template::Posting ###################################################

patrick-canterino.de