1 package Posting
::Admin
;
3 ################################################################################
5 # File: shared/Posting/Admin.pm #
8 # Authors: Frank Schönmann <fs@tower.de> #
9 # André Malo <nd@o3media.de> #
11 # Description: Allow administration of postings #
13 # Todo: * Lock files before modification #
14 # * Change body in change_posting_body() #
15 # * Recursively set invisibility flag in main forum xml by #
16 # hide_posting() and recover_posting() #
18 ################################################################################
30 create_forum_xml_string
35 ################################################################################
43 sub VERSION
{(q
$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
45 ################################################################################
49 use base
qw(Exporter);
59 ### add_user_vote () ###########################################################
61 # Increase number of user votes (only in thread file)
63 # Params: $forum Path and filename of forum
64 # $tpath Path to thread files
65 # \%info Hash reference: 'thread', 'posting', 'percent'
66 # Return: Status code (Bool)
69 # * Lock files before modification
71 sub add_user_vote
($$$) {
72 my ($forum, $tpath, $info) = @_;
73 my ($tid, $mid, $percent) = ($info->{'thread'},
78 my $tfile = $tpath . '/t' . $tid . '.xml';
80 my $parser = new XML
::DOM
::Parser
;
81 my $xml = $parser->parsefile($tfile);
83 my $mnode = get_message_node
($xml, $tid, $mid);
84 my $votes = $mnode->getAttribute('votingUser') + 1;
85 $mnode->setAttribute('votingUser', $votes);
87 return save_file
($tfile, \
$xml->toString);
90 ### level_vote () ##############################################################
92 # Set 1st or 2nd level voting (only in thread file)
94 # Params: $forum Path and filename of forum
95 # $tpath Path to thread files
96 # \%info Hash reference: 'thread', 'posting', 'level', 'value'
97 # Return: Status code (Bool)
100 # * Lock files before modification
103 my ($forum, $tpath, $info´
) = @_;
104 my ($tid, $mid, $level, $value) = (
112 my $tfile = $tpath . '/t' . $tid . '.xml';
114 my $parser = new XML
::DOM
::Parser
;
115 my $xml = $parser->parsefile($tfile);
117 my $mnode = get_message_node
($xml, $tid, $mid);
119 unless (defined $value) {
120 removeAttribute
($level);
123 $mnode->setAttribute($level, $value);
126 return save_file
($tfile, \
$xml->toString);
129 ### hide_posting () ############################################################
131 # Hide a posting: set 'invisible' flag
133 # Params: $forum Path and filename of forum
134 # $tpath Path to thread files
135 # \%info Hash reference: 'thread', 'posting', 'indexFile'
139 # * set flags recursively in forum xml
140 # * lock files before modification
142 sub hide_posting
($$$) {
143 my ($forum, $tpath, $info) = @_;
144 my ($tid, $mid, $indexFile) = ($info->{'thread'},
146 $info->{'indexFile'});
149 my $tfile = $tpath . '/t' . $tid . '.xml';
150 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 1);
153 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 0, 0); # filter deleted, descending
157 if ($_->{'mid'} == $mid)
165 'lastMessage' => $lmsg,
166 'lastThread' => $lthread
168 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
169 save_file
($forum, $$xmlstring);
172 ### recover_posting() ##########################################################
174 # Recover a posting: delete 'invisible' flag
176 # Params: $forum Path and filename of forum
177 # $tpath Path to thread files
178 # \%info Hash reference: 'thread', 'posting', 'indexFile'
182 # * set flags recursive in forum xml
183 # * lock files before modification
185 sub recover_posting
($$$) {
186 my ($forum, $tpath, $info) = @_;
187 my ($tid, $mid, $indexFile) = ($info->{'thread'},
189 $info->{'indexFile'});
192 my $tfile = $tpath . '/t' . $tid . '.xml';
193 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
196 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0); # do not filter deleted, descending
200 if ($_->{'mid'} == $mid)
208 'lastMessage' => $lmsg,
209 'lastThread' => $lthread
211 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
212 save_file
($forum, $$xmlstring);
215 ### change_posting_visibility () ###############################################
217 # Set a postings visibility flag to $invisible
219 # Params: $fname Filename
222 # $invisible 1 - invisible, 0 - visible
223 # Return: Status code
225 sub change_posting_visibility
($$$$)
227 my ($fname, $tid, $mid, $invisible) = @_;
229 my $parser = new XML
::DOM
::Parser
;
230 my $xml = $parser->parsefile($fname);
232 # Set flag in given msg
233 my $mnode = get_message_node
($xml, $tid, $mid);
234 $mnode->setAttribute('invisible', $invisible);
236 # Set flag in sub nodes
237 for ($mnode->getElementsByTagName('Message')) {
238 $_->setAttribute('invisible', $invisible);
241 return save_file
($fname, \
$xml->toString);
244 ### modify_posting () ##########################################################
246 # Modify a posting (only subject and category until now!)
248 # Params: $forum Path and filename of forum
249 # $tpath Path to thread files
250 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
251 # (data = \%hashref: 'subject', 'category', 'body')
254 sub modify_posting
($$$) {
255 my ($forum, $tpath, $info) = @_;
256 my ($tid, $mid, $indexFile, $data) = (
259 $info->{'indexFile'},
263 my ($subject, $category, $body) = (
271 # These values may be changed by change_posting_value()
272 $subject && $msgdata{'Subject'} = $subject;
273 $category && $msgdata{'Category'} = $category;
276 my $tfile = $tpath . '/t' . $tid . '.xml';
277 change_posting_value
($tfile, 't'.$tid, 'm'.$mid, \
$msgdata);
278 $body && change_posting_body
($tfile, 't'.$tid, 'm'.$mid, $body);
280 # Forum (does not contain msg bodies)
281 if ($subject or $category) {
282 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
284 for (@
{$f->{$tid}}) {
285 if ($_->{'mid'} == $mid) {
286 $subject && $_->{'subject'} = $subject;
287 $category && $_->{'cat'} = $category;
293 'lastMessage' => $lmsg,
294 'lastThread' => $lthread
296 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
297 save_file
($forum, $$xmlstring);
300 ### change_posting_value () ####################################################
302 # Change specific values of a posting
304 # Params: $fname Filename
307 # \%values New values
308 # Return: Status code
310 sub change_posting_value
($$$$) {
311 my ($fname, $tid, $mid, $values) = @_;
313 my $parser = new XML
::DOM
::Parser
;
314 my $xml = $parser->parsefile($fname);
316 my $mnode = get_message_node
($xml, $tid, $mid);
320 # Find first direct child node with name $_
321 my $nodes = $mnode->getElementsByTagName($_, 0);
322 my $node = $nodes->item(0);
323 $node->setValue($values->{$_});
326 return save_file
($fname, \
$xml->toString);
329 ### change_posting_body () #####################################################
331 # Change body of a posting
333 # Params: $fname Filename
334 # $tid Thread ID (unused, for compatibility purposes)
337 # Return: Status code
342 sub change_posting_body
($$$$) {
343 my ($fname, $tid, $mid, $body) = @_;
345 my $parser = new XML
::DOM
::Parser
;
346 my $xml = $parser->parsefile($fname);
348 my $mbnody = get_message_body
($xml, $mid);
352 return save_file
($fname, \
$xml->toString);
361 ### end of Posting::Admin ######################################################