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

patrick-canterino.de