]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Handle.pm
246f4e7fbd4651dd1b970313255df0b2feba2772
[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 my $xmlstring = create_forum_xml_string($f, \%cfxs);
64 save_file($forum, $$xmlstring);
65 }
66
67 ### recover_posting() ##########################################################
68 #
69 # Recover a posting: delete 'invisible' flag
70 #
71 # Params: $forum Path and filename of forum
72 # $tpath Path to thread files
73 # \%hashref Reference: 'thread', 'posting', 'indexFile'
74 # Return: -none-
75 #
76 sub recover_posting($$$)
77 {
78 my ($forum, $tpath, $info) = @_;
79 my ($tid, $mid, $indexFile) = ($info->{'thread'},
80 $info->{'posting'},
81 $info->{'indexFile'});
82
83 # Thread
84 my $tfile = $tpath . '/t' . $tid . '.xml';
85 change_posting_visibility($tfile, 't'.$tid, 'm'.$mid, 0);
86
87 # Forum
88 #change_posting_visibility($forum, 't'.$tid, 'm'.$mid, 0); # OBSOLETE
89
90 my ($f, $lthread, $lmsg, $dtd, $zlev) = get_all_threads($forum, 1, 0);
91
92 for (@{$f->{$tid}})
93 {
94 if ($_->{'mid'} == $mid)
95 {
96 $_->{'deleted'} = 0;
97 }
98 }
99
100 my %cfxs = (
101 'dtd' => $dtd,
102 'lastMessage' => $lmsg,
103 'lastThread' => $lthread
104 );
105 my $xmlstring = create_forum_xml_string($f, \%cfxs);
106 save_file($forum, $$xmlstring);
107 }
108
109 ### change_posting_visibility () ###############################################
110 #
111 # Set a postings visibility flag to $invisible
112 #
113 # Params: $fname Filename
114 # $tid Thread ID
115 # $mid Message ID
116 # $invisible 1 - invisible, 0 - visible
117 # Return: Status code
118 #
119 sub change_posting_visibility($$$$)
120 {
121 my ($fname, $tid, $mid, $invisible) = @_;
122
123 my $parser = new XML::DOM::Parser;
124 my $xml = $parser->parsefile($fname);
125
126 # Set flag in given msg
127 my $mnode = get_message_node($xml, $tid, $mid);
128 $mnode->setAttribute('invisible', $invisible);
129
130 # Set flag in sub nodes
131 for ($mnode->getElementsByTagName('Message'))
132 {
133 $_->setAttribute('invisible', $invisible);
134 }
135
136 return save_file($fname, \$xml->toString);
137 }
138
139 ### modify_posting () ##########################################################
140 #
141 # Modify a posting (only subject and category until now!)
142 #
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')
147 # Return: -none-
148 #
149 sub modify_posting($$$)
150 {
151 my ($forum, $tpath, $info) = @_;
152 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
153 'm' . $info->{'posting'},
154 $info->{'indexFile'},
155 $info->{'data'});
156 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
157
158 my %msgdata;
159
160 # These values may be changed by change_posting_value()
161 $subject && $msgdata{'Subject'} = $subject;
162 $category && $msgdata{'Category'} = $category;
163
164 #
165 my $tfile = $tpath . '/' . $tid . '.xml';
166 change_posting_value($tfile, $tid, $mid, \$msgdata);
167 change_posting_value($forum, $tid, $mid, \$msgdata);
168 }
169
170 ### change_posting_value () ####################################################
171 #
172 # Change specific values of a posting
173 #
174 # Params: $fname Filename
175 # $tid Thread ID
176 # $mid Message ID
177 # \%values New values
178 # Return: Status code
179 #
180 sub change_posting_value($$$$)
181 {
182 my ($fname, $tid, $mid, $values) = @_;
183
184 my $parser = new XML::DOM::Parser;
185 my $xml = $parser->parsefile($fname);
186
187 my $mnode = get_message_node($xml, $tid, $mid);
188
189 for (keys %$values)
190 {
191 # Find first direct child node with name $_
192 my $nodes = $mnode->getElementsByTagName($_, 0);
193 my $node = $nodes->item(0);
194 $node->setValue($values->{$_});
195 }
196
197 return save_file($fname, \$xml->toString);
198 }
199
200
201 # Let it be true
202 1;

patrick-canterino.de