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);
48 #my $f = get_all_threads($forum, 1, 0);
51 # if ($_->{'mid'} == $mid)
53 # $_->{'deleted'} = 1;
57 #create_forum_xml_string($f, );
60 ### recover_posting() ##########################################################
62 # Recover a posting: delete 'invisible' flag
64 # Params: $forum Path and filename of forum
65 # $tpath Path to thread files
66 # \%hashref Reference: 'thread', 'posting', 'indexFile'
69 sub recover_posting
($$$)
71 my ($forum, $tpath, $info) = @_;
72 my ($tid, $mid, $indexFile) = ($info->{'thread'},
74 $info->{'indexFile'});
77 my $tfile = $tpath . '/t' . $tid . '.xml';
78 change_posting_visibility
($tfile, 't'.$tid, 'm'.$mid, 0);
81 change_posting_visibility
($forum, 't'.$tid, 'm'.$mid, 0);
83 #my $f = get_all_threads($forum, 1, 0);
86 # if ($_->{'mid'} == $mid)
88 # $_->{'deleted'} = 0;
92 #create_forum_xml_string($f, );
95 ### change_posting_visibility () ###############################################
97 # Set a postings visibility flag to $invisible
99 # Params: $fname Filename
102 # $invisible 1 - invisible, 0 - visible
103 # Return: Status code
105 sub change_posting_visibility
($$$$)
107 my ($fname, $tid, $mid, $invisible) = @_;
109 my $parser = new XML
::DOM
::Parser
;
110 my $xml = $parser->parsefile($fname);
112 # Set flag in given msg
113 my $mnode = get_message_node
($xml, $tid, $mid);
114 $mnode->setAttribute('invisible', $invisible);
116 # Set flag in sub nodes
117 for ($mnode->getElementsByTagName('Message'))
119 $_->setAttribute('invisible', $invisible);
122 return save_file
($fname, \
$xml->toString);
125 ### modify_posting () ##########################################################
127 # Modify a posting (only subject and category until now!)
129 # Params: $forum Path and filename of forum
130 # $tpath Path to thread files
131 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
132 # (\%hashref: 'subject', 'category', 'body')
135 sub modify_posting
($$$)
137 my ($forum, $tpath, $info) = @_;
138 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
139 'm' . $info->{'posting'},
140 $info->{'indexFile'},
142 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
146 # These values may be changed by change_posting_value()
147 $subject && $msgdata{'Subject'} = $subject;
148 $category && $msgdata{'Category'} = $category;
151 my $tfile = $tpath . '/' . $tid . '.xml';
152 change_posting_value
($tfile, $tid, $mid, \
$msgdata);
153 change_posting_value
($forum, $tid, $mid, \
$msgdata);
156 ### change_posting_value () ####################################################
158 # Change specific values of a posting
160 # Params: $fname Filename
163 # \%values New values
164 # Return: Status code
166 sub change_posting_value
($$$$)
168 my ($fname, $tid, $mid, $values) = @_;
170 my $parser = new XML
::DOM
::Parser
;
171 my $xml = $parser->parsefile($fname);
173 my $mnode = get_message_node
($xml, $tid, $mid);
177 # Find first direct child node with name $_
178 my $nodes = $mnode->getElementsByTagName($_, 0);
179 my $node = $nodes->item(0);
180 $node->setValue($values->{$_});
183 return save_file
($fname, \
$xml->toString);