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 ################################################################################
31 create_forum_xml_string
36 ################################################################################
40 $VERSION = do { my @r =(q
$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r };
42 ################################################################################
46 use base
qw(Exporter);
56 ### add_user_vote () ###########################################################
58 # Increase number of user votes (only in thread file)
60 # Params: $forum Path and filename of forum
61 # $tpath Path to thread files
62 # \%info Hash reference: 'thread', 'posting', 'percent'
63 # Return: Status code (Bool)
66 # * Lock files before modification
68 sub add_user_vote
($$$) {
69 my ($forum, $tpath, $info) = @_;
70 my ($tid, $mid, $percent) = ($info->{'thread'},
75 my $tfile = $tpath . '/t' . $tid . '.xml';
77 my $parser = new XML
::DOM
::Parser
;
78 my $xml = $parser->parsefile($tfile);
80 my $mnode = get_message_node
($xml, $tid, $mid);
81 my $votes = $mnode->getAttribute('votingUser') + 1;
82 $mnode->setAttribute('votingUser', $votes);
84 return save_file
($tfile, \
$xml->toString);
87 ### level_vote () ##############################################################
89 # Set 1st or 2nd level voting (only in thread file)
91 # Params: $forum Path and filename of forum
92 # $tpath Path to thread files
93 # \%info Hash reference: 'thread', 'posting', 'level', 'value'
94 # Return: Status code (Bool)
97 # * Lock files before modification
100 my ($forum, $tpath, $infoยด
) = @_;
101 my ($tid, $mid, $level, $value) = (
109 my $tfile = $tpath . '/t' . $tid . '.xml';
111 my $parser = new XML
::DOM
::Parser
;
112 my $xml = $parser->parsefile($tfile);
114 my $mnode = get_message_node
($xml, $tid, $mid);
116 unless (defined $value) {
117 removeAttribute
($level);
120 $mnode->setAttribute($level, $value);
123 return save_file
($tfile, \
$xml->toString);
126 ### hide_posting () ############################################################
128 # Hide a posting: set 'invisible' flag
130 # Params: $forum Path and filename of forum
131 # $tpath Path to thread files
132 # \%info Hash reference: 'thread', 'posting', 'indexFile'
136 # * set flags recursively in forum xml
137 # * lock files before modification
139 sub hide_posting
($$$) {
140 my ($forum, $tpath, $info) = @_;
141 my ($tid, $mid, $indexFile) = ($info->{'thread'},
143 $info->{'indexFile'});
146 my $tfile = $tpath . '/t' . $tid . '.xml';
147 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 1);
150 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 0, 0); # filter deleted, descending
154 if ($_->{'mid'} == $mid)
162 'lastMessage' => $lmsg,
163 'lastThread' => $lthread
165 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
166 save_file
($forum, $$xmlstring);
169 ### recover_posting() ##########################################################
171 # Recover a posting: delete 'invisible' flag
173 # Params: $forum Path and filename of forum
174 # $tpath Path to thread files
175 # \%info Hash reference: 'thread', 'posting', 'indexFile'
179 # * set flags recursive in forum xml
180 # * lock files before modification
182 sub recover_posting
($$$) {
183 my ($forum, $tpath, $info) = @_;
184 my ($tid, $mid, $indexFile) = ($info->{'thread'},
186 $info->{'indexFile'});
189 my $tfile = $tpath . '/t' . $tid . '.xml';
190 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
193 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0); # do not filter deleted, descending
197 if ($_->{'mid'} == $mid)
205 'lastMessage' => $lmsg,
206 'lastThread' => $lthread
208 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
209 save_file
($forum, $$xmlstring);
212 ### change_posting_visibility () ###############################################
214 # Set a postings visibility flag to $invisible
216 # Params: $fname Filename
219 # $invisible 1 - invisible, 0 - visible
220 # Return: Status code
222 sub change_posting_visibility
($$$$)
224 my ($fname, $tid, $mid, $invisible) = @_;
226 my $parser = new XML
::DOM
::Parser
;
227 my $xml = $parser->parsefile($fname);
229 # Set flag in given msg
230 my $mnode = get_message_node
($xml, $tid, $mid);
231 $mnode->setAttribute('invisible', $invisible);
233 # Set flag in sub nodes
234 for ($mnode->getElementsByTagName('Message')) {
235 $_->setAttribute('invisible', $invisible);
238 return save_file
($fname, \
$xml->toString);
241 ### modify_posting () ##########################################################
243 # Modify a posting (only subject and category until now!)
245 # Params: $forum Path and filename of forum
246 # $tpath Path to thread files
247 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
248 # (data = \%hashref: 'subject', 'category', 'body')
251 sub modify_posting
($$$) {
252 my ($forum, $tpath, $info) = @_;
253 my ($tid, $mid, $indexFile, $data) = (
256 $info->{'indexFile'},
260 my ($subject, $category, $body) = (
268 # These values may be changed by change_posting_value()
269 $subject && $msgdata{'Subject'} = $subject;
270 $category && $msgdata{'Category'} = $category;
273 my $tfile = $tpath . '/t' . $tid . '.xml';
274 change_posting_value
($tfile, 't'.$tid, 'm'.$mid, \
$msgdata);
275 $body && change_posting_body
($tfile, 't'.$tid, 'm'.$mid, $body);
277 # Forum (does not contain msg bodies)
278 if ($subject or $category) {
279 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
281 for (@
{$f->{$tid}}) {
282 if ($_->{'mid'} == $mid) {
283 $subject && $_->{'subject'} = $subject;
284 $category && $_->{'cat'} = $category;
290 'lastMessage' => $lmsg,
291 'lastThread' => $lthread
293 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
294 save_file
($forum, $$xmlstring);
297 ### change_posting_value () ####################################################
299 # Change specific values of a posting
301 # Params: $fname Filename
304 # \%values New values
305 # Return: Status code
307 sub change_posting_value
($$$$) {
308 my ($fname, $tid, $mid, $values) = @_;
310 my $parser = new XML
::DOM
::Parser
;
311 my $xml = $parser->parsefile($fname);
313 my $mnode = get_message_node
($xml, $tid, $mid);
317 # Find first direct child node with name $_
318 my $nodes = $mnode->getElementsByTagName($_, 0);
319 my $node = $nodes->item(0);
320 $node->setValue($values->{$_});
323 return save_file
($fname, \
$xml->toString);
326 ### change_posting_body () #####################################################
328 # Change body of a posting
330 # Params: $fname Filename
331 # $tid Thread ID (unused, for compatibility purposes)
334 # Return: Status code
339 sub change_posting_body
($$$$) {
340 my ($fname, $tid, $mid, $body) = @_;
342 my $parser = new XML
::DOM
::Parser
;
343 my $xml = $parser->parsefile($fname);
345 my $mbnody = get_message_body
($xml, $mid);
349 return save_file
($fname, \
$xml->toString);
358 ### end of Posting::Admin ######################################################