1 package Posting
::Handle
;
3 ################################################################################
5 # File: shared/Posting/Handle.pm #
7 # Authors: Frank Schoenmann <fs@tower.de>, 2001-03-08 #
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'
35 # * set flags recursive in forum xml
39 my ($forum, $tpath, $info) = @_;
40 my ($tid, $mid, $indexFile) = ($info->{'thread'},
42 $info->{'indexFile'});
45 my $tfile = $tpath . '/t' . $tid . '.xml';
46 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 1);
49 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 1); # OBSOLETE
51 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
55 if ($_->{'mid'} == $mid)
63 'lastMessage' => $lmsg,
64 'lastThread' => $lthread
66 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
67 save_file
($forum, $$xmlstring);
70 ### recover_posting() ##########################################################
72 # Recover a posting: delete 'invisible' flag
74 # Params: $forum Path and filename of forum
75 # $tpath Path to thread files
76 # \%info Hash reference: 'thread', 'posting', 'indexFile'
80 # * set flags recursive in forum xml
82 sub recover_posting
($$$)
84 my ($forum, $tpath, $info) = @_;
85 my ($tid, $mid, $indexFile) = ($info->{'thread'},
87 $info->{'indexFile'});
90 my $tfile = $tpath . '/t' . $tid . '.xml';
91 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
94 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); # OBSOLETE
96 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
100 if ($_->{'mid'} == $mid)
108 'lastMessage' => $lmsg,
109 'lastThread' => $lthread
111 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
112 save_file
($forum, $$xmlstring);
115 ### change_posting_visibility () ###############################################
117 # Set a postings visibility flag to $invisible
119 # Params: $fname Filename
122 # $invisible 1 - invisible, 0 - visible
123 # Return: Status code
125 sub change_posting_visibility
($$$$)
127 my ($fname, $tid, $mid, $invisible) = @_;
129 my $parser = new XML
::DOM
::Parser
;
130 my $xml = $parser->parsefile($fname);
132 # Set flag in given msg
133 my $mnode = get_message_node
($xml, $tid, $mid);
134 $mnode->setAttribute('invisible', $invisible);
136 # Set flag in sub nodes
137 for ($mnode->getElementsByTagName('Message'))
139 $_->setAttribute('invisible', $invisible);
142 return save_file
($fname, \
$xml->toString);
145 ### modify_posting () ##########################################################
147 # Modify a posting (only subject and category until now!)
149 # Params: $forum Path and filename of forum
150 # $tpath Path to thread files
151 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
152 # (data = \%hashref: 'subject', 'category', 'body')
155 sub modify_posting
($$$)
157 my ($forum, $tpath, $info) = @_;
158 my ($tid, $mid, $indexFile, $data) = ($info->{'thread'},
160 $info->{'indexFile'},
162 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
166 # These values may be changed by change_posting_value()
167 $subject && $msgdata{'Subject'} = $subject;
168 $category && $msgdata{'Category'} = $category;
171 my $tfile = $tpath . '/t' . $tid . '.xml';
172 change_posting_value
($tfile, 't'.$tid, 'm'.$mid, \
$msgdata);
173 $body && change_posting_body
($tfile, 't'.$tid, 'm'.$mid, $body);
175 # Forum (does not contain msg bodies)
176 #change_posting_value($forum, 't'.$tid, 'm'.$mid, \$msgdata);
178 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
182 if ($_->{'mid'} == $mid)
184 $subject && $_->{'subject'} = $subject;
185 $category && $_->{'cat'} = $category;
191 'lastMessage' => $lmsg,
192 'lastThread' => $lthread
194 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
195 save_file
($forum, $$xmlstring);
198 ### change_posting_value () ####################################################
200 # Change specific values of a posting
202 # Params: $fname Filename
205 # \%values New values
206 # Return: Status code
208 sub change_posting_value
($$$$)
210 my ($fname, $tid, $mid, $values) = @_;
212 my $parser = new XML
::DOM
::Parser
;
213 my $xml = $parser->parsefile($fname);
215 my $mnode = get_message_node
($xml, $tid, $mid);
219 # Find first direct child node with name $_
220 my $nodes = $mnode->getElementsByTagName($_, 0);
221 my $node = $nodes->item(0);
222 $node->setValue($values->{$_});
225 return save_file
($fname, \
$xml->toString);
228 ### change_posting_body () #####################################################
230 # Change body of a posting
232 # Params: $fname Filename
233 # $tid Thread ID (unused, for compatibility purposes)
236 # Return: Status code
238 sub change_posting_body
($$$$)
240 my ($fname, $tid, $mid, $body) = @_;
242 my $parser = new XML
::DOM
::Parser
;
243 my $xml = $parser->parsefile($fname);
245 my $mbnody = get_message_body
($xml, $mid);
249 return save_file
($fname, \
$xml->toString);