]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Handle.pm
9d2a94abcf1582390e336dd1adbef1f29314d316
[selfforum.git] / selfforum-cgi / shared / Posting / Handle.pm
1 package Posting::Handle;
2
3 ################################################################################
4 # #
5 # File: shared/Posting/Handle.pm #
6 # #
7 # Authors: Frank Schoenmann <fs@tower.de>, 2001-02-27 #
8 # #
9 # Description: Allow modifications of postings #
10 # #
11 ################################################################################
12
13 use strict;
14
15 use vars qw(@EXPORT);
16 use base qw(Exporter);
17
18 @EXPORT = qw(hide_posting recover_posting modify_posting);
19
20 use Posting::_lib qw(get_message_node save_file get_all_threads
21 create_forum_xml_string);
22
23 use XML::DOM;
24
25 ### hide_posting () ############################################################
26 #
27 # Hide a posting: set 'invisible' flag
28 #
29 # Params: $forum Path and filename of forum
30 # $tpath Path to thread files
31 # \%info Hash reference: 'thread', 'posting', 'indexFile'
32 # Return: -none-
33 #
34 sub hide_posting($$$)
35 {
36 my ($forum, $tpath, $info) = @_;
37 my ($tid, $mid, $indexFile) = ($info->{'thread'},
38 $info->{'posting'},
39 $info->{'indexFile'});
40
41 # Thread
42 my $tfile = $tpath . '/t' . $tid . '.xml';
43 change_posting_visibility($tfile, 't'.$tid, 'm'.$mid, 1);
44
45 # Forum
46 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 1); # OBSOLETE
47
48 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads($forum, 1, 0);
49
50 for (@{$f->{$tid}})
51 {
52 if ($_->{'mid'} == $mid)
53 {
54 $_->{'deleted'} = 1;
55 }
56 }
57
58 my %cfxs = (
59 'dtd' => $dtd,
60 'lastMessage' => $lmsg,
61 'lastThread' => $lthread
62 );
63 create_forum_xml_string($f, \%cfxs);
64 }
65
66 ### recover_posting() ##########################################################
67 #
68 # Recover a posting: delete 'invisible' flag
69 #
70 # Params: $forum Path and filename of forum
71 # $tpath Path to thread files
72 # \%hashref Reference: 'thread', 'posting', 'indexFile'
73 # Return: -none-
74 #
75 sub recover_posting($$$)
76 {
77 my ($forum, $tpath, $info) = @_;
78 my ($tid, $mid, $indexFile) = ($info->{'thread'},
79 $info->{'posting'},
80 $info->{'indexFile'});
81
82 # Thread
83 my $tfile = $tpath . '/t' . $tid . '.xml';
84 change_posting_visibility($tfile, 't'.$tid, 'm'.$mid, 0);
85
86 # Forum
87 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); # OBSOLETE
88
89 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads($forum, 1, 0);
90
91 for (@{$f->{$tid}})
92 {
93 if ($_->{'mid'} == $mid)
94 {
95 $_->{'deleted'} = 0;
96 }
97 }
98
99 my %cfxs = (
100 'dtd' => $dtd,
101 'lastMessage' => $lmsg,
102 'lastThread' => $lthread
103 );
104 create_forum_xml_string($f, \%cfxs);
105 }
106
107 ### change_posting_visibility () ###############################################
108 #
109 # Set a postings visibility flag to $invisible
110 #
111 # Params: $fname Filename
112 # $tid Thread ID
113 # $mid Message ID
114 # $invisible 1 - invisible, 0 - visible
115 # Return: Status code
116 #
117 sub change_posting_visibility($$$$)
118 {
119 my ($fname, $tid, $mid, $invisible) = @_;
120
121 my $parser = new XML::DOM::Parser;
122 my $xml = $parser->parsefile($fname);
123
124 # Set flag in given msg
125 my $mnode = get_message_node($xml, $tid, $mid);
126 $mnode->setAttribute('invisible', $invisible);
127
128 # Set flag in sub nodes
129 for ($mnode->getElementsByTagName('Message'))
130 {
131 $_->setAttribute('invisible', $invisible);
132 }
133
134 return save_file($fname, \$xml->toString);
135 }
136
137 ### modify_posting () ##########################################################
138 #
139 # Modify a posting (only subject and category until now!)
140 #
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')
145 # Return: -none-
146 #
147 sub modify_posting($$$)
148 {
149 my ($forum, $tpath, $info) = @_;
150 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
151 'm' . $info->{'posting'},
152 $info->{'indexFile'},
153 $info->{'data'});
154 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
155
156 my %msgdata;
157
158 # These values may be changed by change_posting_value()
159 $subject && $msgdata{'Subject'} = $subject;
160 $category && $msgdata{'Category'} = $category;
161
162 #
163 my $tfile = $tpath . '/' . $tid . '.xml';
164 change_posting_value($tfile, $tid, $mid, \$msgdata);
165 change_posting_value($forum, $tid, $mid, \$msgdata);
166 }
167
168 ### change_posting_value () ####################################################
169 #
170 # Change specific values of a posting
171 #
172 # Params: $fname Filename
173 # $tid Thread ID
174 # $mid Message ID
175 # \%values New values
176 # Return: Status code
177 #
178 sub change_posting_value($$$$)
179 {
180 my ($fname, $tid, $mid, $values) = @_;
181
182 my $parser = new XML::DOM::Parser;
183 my $xml = $parser->parsefile($fname);
184
185 my $mnode = get_message_node($xml, $tid, $mid);
186
187 for (keys %$values)
188 {
189 # Find first direct child node with name $_
190 my $nodes = $mnode->getElementsByTagName($_, 0);
191 my $node = $nodes->item(0);
192 $node->setValue($values->{$_});
193 }
194
195 return save_file($fname, \$xml->toString);
196 }
197
198
199 # Let it be true
200 1;

patrick-canterino.de