]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Posting.pm
64b05373f4263c20560deedbeeae2908207daa80
[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 print ${$template -> scrap (
167 $assign->{mainDoc},
168 { $assign->{name} => plain(defined $header->{name} ? $header->{name} : ''),
169 $assign->{email} => plain(defined $header->{email} ? $header->{email} : ''),
170 $assign->{home} => plain(defined $header->{home} ? $header->{home} : ''),
171 $assign->{image} => plain(defined $header->{image} ? $header->{image} : ''),
172 $assign->{time} => plain(hr_time($header->{time})),
173 $assign->{message} => $text,
174 $assign->{messageTitle} => plain(defined $header->{subject} ? $header->{subject} : ''),
175 $assign->{messageCat} => plain(defined $header->{category} ? $header->{category} : ''),
176 $param->{tree}->{main} => html_thread ($msg, $template, $tpar),
177 $formact->{post}->{assign} => $formact->{post}->{url},
178 $formact->{vote}->{assign} => $formact->{vote}->{url},
179 $formdata->{posterBody}->{assign}->{value} => $area,
180 $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id),
181 $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}),
182 $formdata->{quoteChar} ->{assign}->{value} => "&#255;".plain(defined $view -> {quoteChars} ? $view -> {quoteChars} : ''),
183 $formdata->{userID} ->{assign}->{value} => '',
184 $assign->{firsttime} => $param->{firsttime} ? $param->{firsttime} : '',
185 $assign->{voted} => $param->{voted} ? $param->{voted} : ''
186 },
187 $pars,
188 $parent_pars
189 )};
190
191 # all output done
192 #
193 close STDOUT;
194
195 if ($param->{firsttime}) {
196 my $cache = new Posting::Cache ($param->{cachepath});
197 $cache -> add_view (
198 { thread => $param -> {thread},
199 posting => $param -> {posting}
200 }
201 );
202 }
203 }
204 }
205
206 return;
207 }
208
209 ### message_as_HTML () #########################################################
210 #
211 # create HTML String for the Messagetext
212 #
213 # Params: $xml - XML::DOM::Document object
214 # $template - Template object
215 # $param - Hash reference
216 # (assign, posting, quoteChars, quoting)
217 #
218 # Return: HTML String
219 #
220 sub message_as_HTML ($$$) {
221 my ($xml, $template, $param) = @_;
222
223 my $assign = $param -> {assign};
224 my $body = get_message_body ($xml, $param -> {posting});
225
226 my $text = message_field (
227 $body,
228 { quoteChars => plain ($param -> {quoteChars}),
229 quoting => $param -> {quoting},
230 startCite => ${$template -> scrap ($assign -> {startCite})},
231 endCite => ${$template -> scrap ($assign -> {endCite})}
232 }
233 );
234
235 # return
236 $text;
237 }
238
239 # keep 'require' happy
240 1;
241
242 #
243 #
244 ### end of Template::Posting ###################################################

patrick-canterino.de