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

patrick-canterino.de