From: fox_two <> Date: Tue, 27 Feb 2001 22:28:03 +0000 (+0000) Subject: change_posting_visibility(): uses now Posting::_lib::save_file() X-Git-Url: https://git.p6c8.net/selfforum.git/commitdiff_plain/d820e389d9d284d2eb85e19955cbe413ae4ee65d change_posting_visibility(): uses now Posting::_lib::save_file() modify_posting(): modify subject and/or category of a posting (untested!) change_posting_value(): changes values of child nodes of a msg --- diff --git a/selfforum-cgi/shared/Posting/Handle.pm b/selfforum-cgi/shared/Posting/Handle.pm index 11ec9aa..41bb500 100644 --- a/selfforum-cgi/shared/Posting/Handle.pm +++ b/selfforum-cgi/shared/Posting/Handle.pm @@ -15,9 +15,9 @@ use strict; use vars qw(@EXPORT); use base qw(Exporter); -@EXPORT = qw(hide_posting recover_posting); +@EXPORT = qw(hide_posting recover_posting modify_posting); -use Posting::_lib qw(get_message_node); +use Posting::_lib qw(get_message_node save_file); use XML::DOM; @@ -25,9 +25,9 @@ use XML::DOM; # # Hide a posting: set 'invisible' flag # -# Params: $forum Path and filename of forum -# $tpath Path to thread files -# \%hashref Reference: 'thread', 'posting', 'indexFile' +# Params: $forum Path and filename of forum +# $tpath Path to thread files +# \%info Hash reference: 'thread', 'posting', 'indexFile' # Return: -none- # sub hide_posting($$$) @@ -71,9 +71,9 @@ sub recover_posting($$$) # $tid Thread ID # $mid Message ID # $invisible 1 - invisible, 0 - visible -# Return: -none- +# Return: Status code # -sub change_posting_visibility($$$) +sub change_posting_visibility($$$$) { my ($fname, $tid, $mid, $invisible) = @_; @@ -90,8 +90,68 @@ sub change_posting_visibility($$$) $_->setAttribute('invisible', $invisible); } - $xml->printToFile($fname.'.temp'); - rename $fname.'.temp', $fname; + return save_file($fname, \$xml->toString); +} + +### modify_posting () ########################################################## +# +# Modify a posting (only subject and category until now!) +# +# Params: $forum Path and filename of forum +# $tpath Path to thread files +# \%info Reference: 'thread', 'posting', 'indexFile', 'data' +# (\%hashref: 'subject', 'category', 'body') +# Return: -none- +# +sub modify_posting($$$) +{ + my ($forum, $tpath, $info) = @_; + my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'}, + 'm' . $info->{'posting'}, + $info->{'indexFile'}, + $info->{'data'}); + my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'}); + + my %msgdata; + + # These values may be changed by change_posting_value() + $subject && $msgdata{'Subject'} = $subject; + $category && $msgdata{'Category'} = $category; + + # + my $tfile = $tpath . '/' . $tid . '.xml'; + change_posting_value($tfile, $tid, $mid, \$msgdata); + change_posting_value($forum, $tid, $mid, \$msgdata); +} + +### change_posting_value () #################################################### +# +# Change specific values of a posting +# +# Params: $fname Filename +# $tid Thread ID +# $mid Message ID +# \%values New values +# Return: Status code +# +sub change_posting_value($$$$) +{ + my ($fname, $tid, $mid, $values) = @_; + + my $parser = new XML::DOM::Parser; + my $xml = $parser->parsefile($fname); + + my $mnode = get_message_node($xml, $tid, $mid); + + for (keys %$values) + { + # Find first direct child node with name $_ + my $nodes = $mnode->getElementsByTagName($_, 0); + my $node = $nodes->item(0); + $node->setValue($values->{$_}); + } + + return save_file($fname, \$xml->toString); }