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

patrick-canterino.de