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 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
64 save_file
($forum, $$xmlstring);
67 ### recover_posting() ##########################################################
69 # Recover a posting: delete 'invisible' flag
71 # Params: $forum Path and filename of forum
72 # $tpath Path to thread files
73 # \%hashref Reference: 'thread', 'posting', 'indexFile'
76 sub recover_posting
($$$)
78 my ($forum, $tpath, $info) = @_;
79 my ($tid, $mid, $indexFile) = ($info->{'thread'},
81 $info->{'indexFile'});
84 my $tfile = $tpath . '/t' . $tid . '.xml';
85 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
88 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); # OBSOLETE
90 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads
($forum, 1, 0);
94 if ($_->{'mid'} == $mid)
102 'lastMessage' => $lmsg,
103 'lastThread' => $lthread
105 my $xmlstring = create_forum_xml_string
($f, \
%cfxs);
106 save_file
($forum, $$xmlstring);
109 ### change_posting_visibility () ###############################################
111 # Set a postings visibility flag to $invisible
113 # Params: $fname Filename
116 # $invisible 1 - invisible, 0 - visible
117 # Return: Status code
119 sub change_posting_visibility
($$$$)
121 my ($fname, $tid, $mid, $invisible) = @_;
123 my $parser = new XML
::DOM
::Parser
;
124 my $xml = $parser->parsefile($fname);
126 # Set flag in given msg
127 my $mnode = get_message_node
($xml, $tid, $mid);
128 $mnode->setAttribute('invisible', $invisible);
130 # Set flag in sub nodes
131 for ($mnode->getElementsByTagName('Message'))
133 $_->setAttribute('invisible', $invisible);
136 return save_file
($fname, \
$xml->toString);
139 ### modify_posting () ##########################################################
141 # Modify a posting (only subject and category until now!)
143 # Params: $forum Path and filename of forum
144 # $tpath Path to thread files
145 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
146 # (\%hashref: 'subject', 'category', 'body')
149 sub modify_posting
($$$)
151 my ($forum, $tpath, $info) = @_;
152 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
153 'm' . $info->{'posting'},
154 $info->{'indexFile'},
156 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
160 # These values may be changed by change_posting_value()
161 $subject && $msgdata{'Subject'} = $subject;
162 $category && $msgdata{'Category'} = $category;
165 my $tfile = $tpath . '/' . $tid . '.xml';
166 change_posting_value
($tfile, $tid, $mid, \
$msgdata);
167 change_posting_value
($forum, $tid, $mid, \
$msgdata);
170 ### change_posting_value () ####################################################
172 # Change specific values of a posting
174 # Params: $fname Filename
177 # \%values New values
178 # Return: Status code
180 sub change_posting_value
($$$$)
182 my ($fname, $tid, $mid, $values) = @_;
184 my $parser = new XML
::DOM
::Parser
;
185 my $xml = $parser->parsefile($fname);
187 my $mnode = get_message_node
($xml, $tid, $mid);
191 # Find first direct child node with name $_
192 my $nodes = $mnode->getElementsByTagName($_, 0);
193 my $node = $nodes->item(0);
194 $node->setValue($values->{$_});
197 return save_file
($fname, \
$xml->toString);