]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Posting.pm
made perl 5.005 compilant
[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 qw(:READ);
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 ($xmlfile, $locked, $xml) = ($threadpath.'t'.$param -> {thread}.'.xml', 0);
76
77 unless (($locked = lock_file ($xmlfile)) and ($xml = parse_xml_file ($xmlfile))) {
78 violent_unlock_file ($xmlfile);
79 print ${$template -> scrap (
80 $assign -> {errorDoc},
81 { $assign -> {errorText} => $template -> insert (
82 $assign -> {(defined $locked)
83 ? 'occupied'
84 : 'notAvailable'
85 })
86 }
87 )};
88 }
89 else {
90 violent_unlock_file ($xmlfile) unless (unlock_file($xmlfile));
91
92 my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting});
93
94 unless ($mnode and not $mnode->getAttribute('invisible')) {
95 print ${$template -> scrap (
96 $assign -> {errorDoc},
97 { $assign -> {errorText} => $template -> insert ($assign -> {'notAvailable'}) }
98 )};
99 }
100 else {
101 my $pnode = $mnode -> getParentNode;
102 my $header = get_message_header ($mnode);
103 my $msg = parse_single_thread ($tnode, $param -> {showDeleted}, $view -> {sortedMsg});
104 my $pheader = ($pnode -> getNodeName eq 'Message')?get_message_header ($pnode):{};
105
106 my $formdata = $param -> {form} -> {data};
107 my $formact = $param -> {form} -> {action};
108
109 my $body = get_message_body ($xml, 'm'.$param -> {posting});
110
111 my $text = message_field (
112 $body,
113 { quoteChars => plain($view -> {quoteChars}),
114 quoting => $view -> {quoting},
115 startCite => ${$template -> scrap ($assign -> {startCite})},
116 endCite => ${$template -> scrap ($assign -> {endCite})}
117 }
118 );
119
120 my $area = answer_field (
121 $body,
122 { quoteArea => 1,
123 quoteChars => plain($view -> {quoteChars}),
124 messages => $param -> {messages}
125 }
126 );
127
128 my $pars = {};
129
130 $pars -> {$formdata -> {$_} -> {assign} -> {name}} = plain($formdata -> {$_} -> {name})
131 for (qw(
132 posterBody
133 uniqueID
134 followUp
135 quoteChar
136 userID
137 posterName
138 posterEmail
139 posterURL
140 posterImage
141 )
142 );
143
144 my $cgi = $param -> {cgi};
145
146 my $tpar = {
147 thread => $param -> {thread},
148 template => $param -> {tree},
149 start => $param -> {posting},
150 cgi => $cgi
151 };
152
153 my $parent_pars;
154
155 $parent_pars = {
156 $assign->{parentTitle} => plain(defined $pheader->{subject} ? $pheader->{subject} : ''),
157 $assign->{parentCat} => plain(defined $pheader->{category} ? $pheader->{category} : ''),
158 $assign->{parentName} => plain(defined $pheader->{name} ? $pheader->{name} : ''),
159 $assign->{parentTime} => plain(hr_time($pheader->{time})),
160 $assign->{parentLink} => query_string (
161 { $cgi -> {thread} => $param -> {thread},
162 $cgi -> {posting} => ($pnode -> getAttribute ('id') =~ /(\d+)/)[0]
163 })
164 } if (%$pheader);
165
166 $|++;
167 print ${$template -> scrap (
168 $assign->{mainDoc},
169 { $assign->{name} => plain(defined $header->{name} ? $header->{name} : ''),
170 $assign->{email} => plain(defined $header->{email} ? $header->{email} : ''),
171 $assign->{home} => plain(defined $header->{home} ? $header->{home} : ''),
172 $assign->{image} => plain(defined $header->{image} ? $header->{image} : ''),
173 $assign->{time} => plain(hr_time($header->{time})),
174 $assign->{message} => $text,
175 $assign->{messageTitle} => plain(defined $header->{subject} ? $header->{subject} : ''),
176 $assign->{messageCat} => plain(defined $header->{category} ? $header->{category} : ''),
177 $param->{tree}->{main} => html_thread ($msg, $template, $tpar),
178 $formact->{post}->{assign} => $formact->{post}->{url},
179 $formact->{vote}->{assign} => $formact->{vote}->{url},
180 $formdata->{posterBody}->{assign}->{value} => $area,
181 $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id),
182 $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}),
183 $formdata->{quoteChar} ->{assign}->{value} => "&#255;".plain(defined $view -> {quoteChars} ? $view -> {quoteChars} : ''),
184 $formdata->{userID} ->{assign}->{value} => '',
185 $assign->{firsttime} => $param->{firsttime} ? $param->{firsttime} : '',
186 $assign->{voted} => $param->{voted} ? $param->{voted} : ''
187 },
188 $pars,
189 $parent_pars
190 )};
191
192 # all output done
193 #
194 close STDOUT;
195
196 if ($param->{firsttime}) {
197 my $cache = new Posting::Cache ($param->{cachepath});
198 $cache -> add_view (
199 { thread => $param -> {thread},
200 posting => $param -> {posting}
201 }
202 );
203 }
204 }
205 }
206
207 return;
208 }
209
210 ### message_as_HTML () #########################################################
211 #
212 # create HTML String for the Messagetext
213 #
214 # Params: $xml - XML::DOM::Document object
215 # $template - Template object
216 # $param - Hash reference
217 # (assign, posting, quoteChars, quoting)
218 #
219 # Return: HTML String
220 #
221 sub message_as_HTML ($$$) {
222 my ($xml, $template, $param) = @_;
223
224 my $assign = $param -> {assign};
225 my $body = get_message_body ($xml, $param -> {posting});
226
227 my $text = message_field (
228 $body,
229 { quoteChars => plain ($param -> {quoteChars}),
230 quoting => $param -> {quoting},
231 startCite => ${$template -> scrap ($assign -> {startCite})},
232 endCite => ${$template -> scrap ($assign -> {endCite})}
233 }
234 );
235
236 # return
237 $text;
238 }
239
240 # keep 'require' happy
241 1;
242
243 #
244 #
245 ### end of Template::Posting ###################################################

patrick-canterino.de