1 package Posting
::Handle
;
3 ################################################################################
5 # File: shared/Posting/Handle.pm #
7 # Authors: Frank Schoenmann <fs@tower.de>, 2001-02-27 #
9 # Description: Allow modifications of postings #
11 ################################################################################
16 use base qw(Exporter);
18 @EXPORT = qw(hide_posting recover_posting modify_posting);
20 use Posting
::_lib
qw(get_message_node save_file get_all_threads
21 create_forum_xml_string);
25 ### hide_posting () ############################################################
27 # Hide a posting: set 'invisible' flag
29 # Params: $forum Path and filename of forum
30 # $tpath Path to thread files
31 # \%info Hash reference: 'thread', 'posting', 'indexFile'
36 my ($forum, $tpath, $info) = @_;
37 my ($tid, $mid, $indexFile) = ($info->{'thread'},
39 $info->{'indexFile'});
42 my $tfile = $tpath . '/t' . $tid . '.xml';
43 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 1);
46 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 1); # OBSOLETE
48 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
52 if ($_->{'mid'} == $mid)
60 'lastMessage' => $lmsg,
61 'lastThread' => $lthread
63 create_forum_xml_string
($f, \
%cfxs);
66 ### recover_posting() ##########################################################
68 # Recover a posting: delete 'invisible' flag
70 # Params: $forum Path and filename of forum
71 # $tpath Path to thread files
72 # \%hashref Reference: 'thread', 'posting', 'indexFile'
75 sub recover_posting
($$$)
77 my ($forum, $tpath, $info) = @_;
78 my ($tid, $mid, $indexFile) = ($info->{'thread'},
80 $info->{'indexFile'});
83 my $tfile = $tpath . '/t' . $tid . '.xml';
84 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
87 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); # OBSOLETE
89 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
93 if ($_->{'mid'} == $mid)
101 'lastMessage' => $lmsg,
102 'lastThread' => $lthread
104 create_forum_xml_string
($f, \
%cfxs);
107 ### change_posting_visibility () ###############################################
109 # Set a postings visibility flag to $invisible
111 # Params: $fname Filename
114 # $invisible 1 - invisible, 0 - visible
115 # Return: Status code
117 sub change_posting_visibility
($$$$)
119 my ($fname, $tid, $mid, $invisible) = @_;
121 my $parser = new XML
::DOM
::Parser
;
122 my $xml = $parser->parsefile($fname);
124 # Set flag in given msg
125 my $mnode = get_message_node
($xml, $tid, $mid);
126 $mnode->setAttribute('invisible', $invisible);
128 # Set flag in sub nodes
129 for ($mnode->getElementsByTagName('Message'))
131 $_->setAttribute('invisible', $invisible);
134 return save_file
($fname, \
$xml->toString);
137 ### modify_posting () ##########################################################
139 # Modify a posting (only subject and category until now!)
141 # Params: $forum Path and filename of forum
142 # $tpath Path to thread files
143 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
144 # (\%hashref: 'subject', 'category', 'body')
147 sub modify_posting
($$$)
149 my ($forum, $tpath, $info) = @_;
150 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
151 'm' . $info->{'posting'},
152 $info->{'indexFile'},
154 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
158 # These values may be changed by change_posting_value()
159 $subject && $msgdata{'Subject'} = $subject;
160 $category && $msgdata{'Category'} = $category;
163 my $tfile = $tpath . '/' . $tid . '.xml';
164 change_posting_value
($tfile, $tid, $mid, \
$msgdata);
165 change_posting_value
($forum, $tid, $mid, \
$msgdata);
168 ### change_posting_value () ####################################################
170 # Change specific values of a posting
172 # Params: $fname Filename
175 # \%values New values
176 # Return: Status code
178 sub change_posting_value
($$$$)
180 my ($fname, $tid, $mid, $values) = @_;
182 my $parser = new XML
::DOM
::Parser
;
183 my $xml = $parser->parsefile($fname);
185 my $mnode = get_message_node
($xml, $tid, $mid);
189 # Find first direct child node with name $_
190 my $nodes = $mnode->getElementsByTagName($_, 0);
191 my $node = $nodes->item(0);
192 $node->setValue($values->{$_});
195 return save_file
($fname, \
$xml->toString);