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

patrick-canterino.de