]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Template/Posting.pm
shared/Lock.pm: fixed a small bug (now returns 0 if occupied)
[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
59 # Datei sperren... (eigentlich)
60 my $view = get_view_params ({
61 adminDefault => $param -> {adminDefault}
62 });
63
64 my $xml = parse_xml_file ($threadpath.'t'.$param -> {thread}.'.xml');
65
66 my ($mnode, $tnode) = get_message_node ($xml, 't'.$param -> {thread}, 'm'.$param -> {posting});
67 my $pnode = $mnode -> getParentNode;
68 my $header = get_message_header ($mnode);
69 my $msg = parse_single_thread ($tnode, $param -> {showDeleted}, $view -> {sortedMsg});
70 my $pheader = ($pnode -> getNodeName eq 'Message')?get_message_header ($pnode):{};
71
72 my $assign = $param -> {assign};
73 my $formdata = $param -> {form} -> {data};
74 my $formact = $param -> {form} -> {action};
75
76 my $body = get_message_body ($xml, 'm'.$param -> {posting});
77
78 my $text = message_field (
79 $body,
80 { quoteChars => plain($view -> {quoteChars}),
81 quoting => 1,
82 startCite => ${$template -> scrap ($assign -> {startCite})},
83 endCite => ${$template -> scrap ($assign -> {endCite})}
84 }
85 );
86
87 my $area = answer_field (
88 $body,
89 { quoteArea => 1,
90 quoteChars => plain($view -> {quoteChars}),
91 messages => $param -> {messages}
92 }
93 );
94
95 my $pars = {};
96
97 $pars -> {$formdata -> {$_} -> {assign} -> {name}} = plain($formdata -> {$_} -> {name})
98 for (qw(
99 posterBody
100 uniqueID
101 followUp
102 quoteChar
103 userID
104 posterName
105 posterEmail
106 posterURL
107 posterImage
108 ));
109
110 my $cgi = $param -> {cgi};
111
112 my $tpar = {
113 thread => $param -> {thread},
114 template => $param -> {tree},
115 start => $param -> {posting},
116 cgi => $cgi
117 };
118
119 my $parent_pars;
120
121 $parent_pars = {
122 $assign->{parentTitle} => plain($pheader->{subject}),
123 $assign->{parentCat} => plain($pheader->{category}),
124 $assign->{parentName} => plain($pheader->{name}),
125 $assign->{parentTime} => plain(hr_time($pheader->{time})),
126 $assign->{parentLink} => query_string (
127 { $cgi -> {thread} => $param -> {thread},
128 $cgi -> {posting} => ($pnode -> getAttribute ('id') =~ /(\d+)/)[0]
129 })
130 } if (%$pheader);
131
132 print ${$template -> scrap (
133 $assign->{mainDoc},
134 { $assign->{name} => plain($header->{name}),
135 $assign->{email} => plain($header->{email}),
136 $assign->{home} => plain($header->{home}),
137 $assign->{image} => plain($header->{image}),
138 $assign->{time} => plain(hr_time($header->{time})),
139 $assign->{message} => $text,
140 $assign->{messageTitle} => plain($header->{subject}),
141 $assign->{messageCat} => plain($header->{category}),
142 $param->{tree}->{main} => html_thread ($msg, $template, $tpar),
143 $formact->{post}->{assign} => $formact->{post}->{url},
144 $formact->{vote}->{assign} => $formact->{vote}->{url},
145 $formdata->{posterBody}->{assign}->{value} => $area,
146 $formdata->{uniqueID} ->{assign}->{value} => plain(unique_id),
147 $formdata->{followUp} ->{assign}->{value} => plain($param -> {thread}.';'.$param -> {posting}),
148 $formdata->{quoteChar} ->{assign}->{value} => "&#255;".plain($view -> {quoteChars}),
149 $formdata->{userID} ->{assign}->{value} => ''
150 },
151 $pars,
152 $parent_pars
153 )};
154
155 return;
156 }
157
158 ### sub message_as_HTML ($$$) ##################################################
159 #
160 # create HTML String for the Messagetext
161 #
162 # Params: $xml - XML::DOM::Document object
163 # $template - Template object
164 # $param - Hash reference
165 # (assign, posting, quoteChars, quoting)
166 #
167 # Return: HTML String
168 #
169 sub message_as_HTML ($$$) {
170 my ($xml, $template, $param) = @_;
171
172 my $assign = $param -> {assign};
173 my $body = get_message_body ($xml, $param -> {posting});
174
175 my $text = message_field (
176 $body,
177 { quoteChars => plain ($param -> {quoteChars}),
178 quoting => $param -> {quoting},
179 startCite => ${$template -> scrap ($assign -> {startCite})},
180 endCite => ${$template -> scrap ($assign -> {endCite})}
181 }
182 );
183
184 # return
185 $text;
186 }
187
188 # keep require happy
189 1;
190
191 #
192 #
193 ### end of Template::Posting ###################################################
194

patrick-canterino.de