]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Posting/Handle.pm
fixed a bug in ~hr_time functions
[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);
21
22 use XML::DOM;
23
24 ### hide_posting () ############################################################
25 #
26 # Hide a posting: set 'invisible' flag
27 #
28 # Params: $forum Path and filename of forum
29 # $tpath Path to thread files
30 # \%info Hash reference: 'thread', 'posting', 'indexFile'
31 # Return: -none-
32 #
33 sub hide_posting($$$)
34 {
35 my ($forum, $tpath, $info) = @_;
36 my ($tid, $mid, $indexFile) = ('t' . $info->{'thread'},
37 'm' . $info->{'posting'},
38 $info->{'indexFile'});
39
40 my $tfile = $tpath . '/' . $tid . '.xml';
41 change_posting_visibility($tfile, $tid, $mid, 1);
42 change_posting_visibility($forum, $tid, $mid, 1);
43 }
44
45 ### recover_posting() ##########################################################
46 #
47 # Recover a posting: delete 'invisible' flag
48 #
49 # Params: $forum Path and filename of forum
50 # $tpath Path to thread files
51 # \%hashref Reference: 'thread', 'posting', 'indexFile'
52 # Return: -none-
53 #
54 sub recover_posting($$$)
55 {
56 my ($forum, $tpath, $info) = @_;
57 my ($tid, $mid, $indexFile) = ('t' . $info->{'thread'},
58 'm' . $info->{'posting'},
59 $info->{'indexFile'});
60
61 my $tfile = $tpath . '/' . $tid . '.xml';
62 change_posting_visibility($tfile, $tid, $mid, 0);
63 change_posting_visibility($forum, $tid, $mid, 0);
64 }
65
66 ### change_posting_visibility () ###############################################
67 #
68 # Set a postings visibility flag to $invisible
69 #
70 # Params: $fname Filename
71 # $tid Thread ID
72 # $mid Message ID
73 # $invisible 1 - invisible, 0 - visible
74 # Return: Status code
75 #
76 sub change_posting_visibility($$$$)
77 {
78 my ($fname, $tid, $mid, $invisible) = @_;
79
80 my $parser = new XML::DOM::Parser;
81 my $xml = $parser->parsefile($fname);
82
83 # Set flag in given msg
84 my $mnode = get_message_node($xml, $tid, $mid);
85 $mnode->setAttribute('invisible', $invisible);
86
87 # Set flag in sub nodes
88 for ($mnode->getElementsByTagName('Message'))
89 {
90 $_->setAttribute('invisible', $invisible);
91 }
92
93 return save_file($fname, \$xml->toString);
94 }
95
96 ### modify_posting () ##########################################################
97 #
98 # Modify a posting (only subject and category until now!)
99 #
100 # Params: $forum Path and filename of forum
101 # $tpath Path to thread files
102 # \%info Reference: 'thread', 'posting', 'indexFile', 'data'
103 # (\%hashref: 'subject', 'category', 'body')
104 # Return: -none-
105 #
106 sub modify_posting($$$)
107 {
108 my ($forum, $tpath, $info) = @_;
109 my ($tid, $mid, $indexFile, $data) = ('t' . $info->{'thread'},
110 'm' . $info->{'posting'},
111 $info->{'indexFile'},
112 $info->{'data'});
113 my ($subject, $category, $body) = ($data->{'subject'}, $data->{'category'}, $data->{'body'});
114
115 my %msgdata;
116
117 # These values may be changed by change_posting_value()
118 $subject && $msgdata{'Subject'} = $subject;
119 $category && $msgdata{'Category'} = $category;
120
121 #
122 my $tfile = $tpath . '/' . $tid . '.xml';
123 change_posting_value($tfile, $tid, $mid, \$msgdata);
124 change_posting_value($forum, $tid, $mid, \$msgdata);
125 }
126
127 ### change_posting_value () ####################################################
128 #
129 # Change specific values of a posting
130 #
131 # Params: $fname Filename
132 # $tid Thread ID
133 # $mid Message ID
134 # \%values New values
135 # Return: Status code
136 #
137 sub change_posting_value($$$$)
138 {
139 my ($fname, $tid, $mid, $values) = @_;
140
141 my $parser = new XML::DOM::Parser;
142 my $xml = $parser->parsefile($fname);
143
144 my $mnode = get_message_node($xml, $tid, $mid);
145
146 for (keys %$values)
147 {
148 # Find first direct child node with name $_
149 my $nodes = $mnode->getElementsByTagName($_, 0);
150 my $node = $nodes->item(0);
151 $node->setValue($values->{$_});
152 }
153
154 return save_file($fname, \$xml->toString);
155 }
156
157
158 1;

patrick-canterino.de