1 package Posting
::Admin
;
3 ################################################################################
5 # File: shared/Posting/Admin.pm #
8 # Authors: Frank Schoenmann <fs@tower.de>, 2001-03-13 #
9 # Andre Malo <nd@o3media.de>, 2001-03-29 #
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 ################################################################################
22 use base
qw(Exporter);
24 @Posting::Admin
::EXPORT
= qw(hide_posting recover_posting modify_posting add_user_vote level_vote);
27 use Posting
::_lib
qw(get_message_node save_file get_all_threads
28 create_forum_xml_string);
32 ### add_user_vote () ###########################################################
34 # Increase number of user votes (only in thread file)
36 # Params: $forum Path and filename of forum
37 # $tpath Path to thread files
38 # \%info Hash reference: 'thread', 'posting', 'percent'
39 # Return: Status code (Bool)
42 # * Lock files before modification
46 my ($forum, $tpath, $info) = @_;
47 my ($tid, $mid, $percent) = ($info->{'thread'},
52 my $tfile = $tpath . '/t' . $tid . '.xml';
54 my $parser = new XML
::DOM
::Parser
;
55 my $xml = $parser->parsefile($tfile);
57 my $mnode = get_message_node
($xml, $tid, $mid);
58 my $votes = $mnode->getAttribute('votingUser') + 1;
59 $mnode->setAttribute('votingUser', $votes);
61 return save_file
($tfile, \
$xml->toString);
64 ### level_vote () ##############################################################
66 # Set 1st or 2nd level voting (only in thread file)
68 # Params: $forum Path and filename of forum
69 # $tpath Path to thread files
70 # \%info Hash reference: 'thread', 'posting', 'level', 'value'
71 # Return: Status code (Bool)
74 # * Lock files before modification
78 my ($forum, $tpath, $infoยด
) = @_;
79 my ($tid, $mid, $level, $value) = ($info->{'thread'},
85 my $tfile = $tpath . '/t' . $tid . '.xml';
87 my $parser = new XML
::DOM
::Parser
;
88 my $xml = $parser->parsefile($tfile);
90 my $mnode = get_message_node
($xml, $tid, $mid);
94 removeAttribute
($level);
98 $mnode->setAttribute($level, $value);
101 return save_file
($tfile, \
$xml->toString);
104 ### hide_posting () ############################################################
106 # Hide a posting: set 'invisible' flag
108 # Params: $forum Path and filename of forum
109 # $tpath Path to thread files
110 # \%info Hash reference: 'thread', 'posting', 'indexFile'
114 # * set flags recursively in forum xml
115 # * lock files before modification
117 sub hide_posting
($$$)
119 my ($forum, $tpath, $info) = @_;
120 my ($tid, $mid, $indexFile) = ($info->{'thread'},
122 $info->{'indexFile'});
125 my $tfile = $tpath . '/t' . $tid . '.xml';
126 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 1);
129 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 0, 0); # filter deleted, descending
133 if ($_->{'mid'} == $mid)
141 'lastMessage' => $lmsg,
142 'lastThread' => $lthread
144 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
145 save_file
($forum, $$xmlstring);
148 ### recover_posting() ##########################################################
150 # Recover a posting: delete 'invisible' flag
152 # Params: $forum Path and filename of forum
153 # $tpath Path to thread files
154 # \%info Hash reference: 'thread', 'posting', 'indexFile'
158 # * set flags recursive in forum xml
159 # * lock files before modification
161 sub recover_posting
($$$)
163 my ($forum, $tpath, $info) = @_;
164 my ($tid, $mid, $indexFile) = ($info->{'thread'},
166 $info->{'indexFile'});
169 my $tfile = $tpath . '/t' . $tid . '.xml';
170 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
173 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0); # do not filter deleted, descending
177 if ($_->{'mid'} == $mid)
185 'lastMessage' => $lmsg,
186 'lastThread' => $lthread
188 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
189 save_file
($forum, $$xmlstring);
192 ### change_posting_visibility () ###############################################
194 # Set a postings visibility flag to $invisible
196 # Params: $fname Filename
199 # $invisible 1 - invisible, 0 - visible
200 # Return: Status code
202 sub change_posting_visibility
($$$$)
204 my ($fname, $tid, $mid, $invisible) = @_;
206 my $parser = new XML
::DOM
::Parser
;
207 my $xml = $parser->parsefile($fname);
209 # Set flag in given msg
210 my $mnode = get_message_node
($xml, $tid, $mid);
211 $mnode->setAttribute('invisible', $invisible);
213 # Set flag in sub nodes
214 for ($mnode->getElementsByTagName('Message'))
216 $_->setAttribute('invisible', $invisible);
219 return save_file
($fname, \
$xml->toString);
222 ### modify_posting () ##########################################################
224 # Modify a posting (only subject and category until now!)
226 # Params: $forum Path and filename of forum
227 # $tpath Path to thread files
228 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
229 # (data = \%hashref: 'subject', 'category', 'body')
232 sub modify_posting
($$$)
234 my ($forum, $tpath, $info) = @_;
235 my ($tid, $mid, $indexFile, $data) = ($info->{'thread'},
237 $info->{'indexFile'},
239 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
243 # These values may be changed by change_posting_value()
244 $subject && $msgdata{'Subject'} = $subject;
245 $category && $msgdata{'Category'} = $category;
248 my $tfile = $tpath . '/t' . $tid . '.xml';
249 change_posting_value
($tfile, 't'.$tid, 'm'.$mid, \
$msgdata);
250 $body && change_posting_body
($tfile, 't'.$tid, 'm'.$mid, $body);
252 # Forum (does not contain msg bodies)
253 if ($subject or $category)
255 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
259 if ($_->{'mid'} == $mid)
261 $subject && $_->{'subject'} = $subject;
262 $category && $_->{'cat'} = $category;
268 'lastMessage' => $lmsg,
269 'lastThread' => $lthread
271 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
272 save_file
($forum, $$xmlstring);
275 ### change_posting_value () ####################################################
277 # Change specific values of a posting
279 # Params: $fname Filename
282 # \%values New values
283 # Return: Status code
285 sub change_posting_value
($$$$)
287 my ($fname, $tid, $mid, $values) = @_;
289 my $parser = new XML
::DOM
::Parser
;
290 my $xml = $parser->parsefile($fname);
292 my $mnode = get_message_node
($xml, $tid, $mid);
296 # Find first direct child node with name $_
297 my $nodes = $mnode->getElementsByTagName($_, 0);
298 my $node = $nodes->item(0);
299 $node->setValue($values->{$_});
302 return save_file
($fname, \
$xml->toString);
305 ### change_posting_body () #####################################################
307 # Change body of a posting
309 # Params: $fname Filename
310 # $tid Thread ID (unused, for compatibility purposes)
313 # Return: Status code
318 sub change_posting_body
($$$$)
320 my ($fname, $tid, $mid, $body) = @_;
322 my $parser = new XML
::DOM
::Parser
;
323 my $xml = $parser->parsefile($fname);
325 my $mbnody = get_message_body
($xml, $mid);
329 return save_file
($fname, \
$xml->toString);