]> git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Conf/Admin.pm
Admin.pm: hide_posting()/recover_posting(): thread and forum XML files are now locked...
[selfforum.git] / selfforum-cgi / shared / Conf / Admin.pm
1 package Conf::Admin;
2
3 ################################################################################
4 # #
5 # File: shared/CheckRFC.pm #
6 # #
7 # Authors: André Malo <nd@o3media.de> #
8 # #
9 # Description: read and parse admin default config #
10 # #
11 ################################################################################
12
13 use strict;
14 use vars qw(
15 @EXPORT
16 );
17
18 use Lock;
19
20 use XML::DOM;
21
22 ################################################################################
23 #
24 # Version check
25 #
26 # last modified:
27 # $Date$ (GMT)
28 # by $Author$
29 #
30 sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
31
32 ################################################################################
33 #
34 # Export
35 #
36 use base qw(Exporter);
37 @EXPORT = qw(read_admin_conf);
38
39 ### get_severance () ###########################################################
40 #
41 # read out severance config (used twice)
42 #
43 # Params: $severance - element node
44 #
45 # Return: hashref
46 #
47 sub get_severance ($) {
48 my $severance = shift;
49
50 my $after_byte = $severance -> getElementsByTagName ('AfterByte', 0) -> item (0);
51 my $after_message = $severance -> getElementsByTagName ('AfterMessage', 0) -> item (0);
52 my $after_thread = $severance -> getElementsByTagName ('AfterThread', 0) -> item (0);
53 my $last_posting = $severance -> getElementsByTagName ('AfterLastPosting', 0) -> item (0);
54
55 my %conf =(
56 exArchiving => $severance -> getAttribute ('executeArchiving'),
57 archiving => $severance
58 -> getElementsByTagName ('Archiving', 0) -> item (0)
59 -> getElementsByTagName ('*', 0) -> item (0) -> getTagName,
60 severance => $severance -> getAttribute ('executeSeverance'),
61 afterByte => (
62 $after_byte
63 ? $after_byte -> getFirstChild -> getData
64 : undef
65 ),
66 afterThread => (
67 $after_thread
68 ? $after_thread -> getFirstChild -> getData
69 : undef
70 ),
71 afterMessage => (
72 $after_message
73 ? $after_message -> getFirstChild -> getData
74 : undef
75 ),
76 lastPosting => (
77 $last_posting
78 ? $last_posting -> getFirstChild -> getData
79 : undef
80 )
81 );
82
83 \%conf;
84 }
85
86 ### read_admin_conf () #########################################################
87 #
88 # read and parse admin config
89 #
90 # Params: $filename - filename
91 #
92 # Return: hashref
93 #
94 sub read_admin_conf ($) {
95 my $filename=shift;
96 my %conf;
97
98 if (-f $filename) {
99 my $admin = new Lock ($filename);
100 if ($admin -> lock(LH_SHARED)) {
101 my $xml = new XML::DOM::Parser -> parsefile ($admin -> filename);
102 $admin -> unlock;
103
104 # write data into the hash
105 #
106 my $forum = $xml -> getElementsByTagName ('Forum',0) -> item (0);
107
108 # View
109 my $forum_view = $forum -> getElementsByTagName ('ForumView', 0) -> item (0);
110 my $thread_view = $forum_view -> getElementsByTagName ('ThreadView', 0) -> item (0);
111 my $show_thread = $thread_view -> getElementsByTagName ('ShowThread', 0) -> item (0);
112 my $show_how = $show_thread -> getElementsByTagName ('*', 0) -> item (0);
113 my $how_name = $show_how -> getTagName;
114 my $message_view = $forum_view -> getElementsByTagName ('MessageView', 0) -> item (0);
115 my $flags = $forum_view -> getElementsByTagName ('Flags', 0) -> item (0);
116 my $quoting = $forum_view -> getElementsByTagName ('Quoting', 0) -> item (0);
117 my $char = $quoting -> getElementsByTagName ('Chars', 0) -> item (0);
118
119 $conf {View} = {
120 threadOpen => $thread_view -> getAttribute ('threadOpen'),
121 countMessages => $thread_view -> getAttribute ('countMessages'),
122 sortThreads => $thread_view -> getAttribute ('sortThreads'),
123 sortMessages => $thread_view -> getAttribute ('sortMessages'),
124 showThread => (($how_name eq 'ShowAll')
125 ? undef
126 : (($how_name eq 'ShowNone')
127 ? 1
128 : ($show_how -> getFirstChild -> getData))),
129 showPreview => $message_view -> getAttribute ('previewON'),
130 showNA => $flags -> getAttribute ('showNA'),
131 showHQ => $flags -> getAttribute ('showHQ'),
132 quoting => $quoting -> getAttribute ('quotingON'),
133 quoteChars => $char?$char -> getFirstChild -> getData:undef
134 };
135
136 my $voting = $forum -> getElementsByTagName ('Voting', 0) -> item (0);
137 $conf {Voting} = {
138 voteLock => $voting -> getAttribute ('voteLock'),
139 Limit => $voting -> getAttribute ('Limit')
140 };
141
142 # Severance
143 $conf {Severance} = get_severance ($forum -> getElementsByTagName ('Severance', 0) -> item (0));
144
145 # Messaging
146 my $messaging = $forum -> getElementsByTagName ('Messaging', 0) -> item (0);
147 my $call_by_user = $messaging -> getElementsByTagName ('CallByUser', 0) -> item (0);
148
149 $conf {Messaging} = {
150 userAnswer => $messaging -> getAttribute ('callUserAnswer'),
151 thread => $messaging -> getAttribute ('callAdminThread'),
152 na => $messaging -> getAttribute ('callAdminNA'),
153 hq => $messaging -> getAttribute ('callAdminHQ'),
154 voting => $messaging -> getAttribute ('callAdminVoting'),
155 archiving => $messaging -> getAttribute ('callAdminArchiving'),
156 byUser => $messaging -> getAttribute ('callUserAnswer'),
157 callByName => [
158 $call_by_user
159 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('Name', 0)
160 : ()
161 ],
162 callByMail => [
163 $call_by_user
164 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('Email', 0)
165 : ()
166 ],
167 callByIP => [
168 $call_by_user
169 ? map {$_ -> getFirstChild -> getData} $call_by_user -> getElementsByTagName ('IpAddress', 0)
170 : ()
171 ]
172 };
173
174 # Instant
175 my $instant = $forum -> getElementsByTagName ('InstantJob', 0) -> item (0);
176 my $job = $instant -> getElementsByTagName ('*',0) -> item (0);
177 my $job_name = $job -> getTagName;
178 $job_name = $job -> getAttribute ('reason') if ($job_name ne 'Severance');
179
180 $conf {Instant} = {
181 execute => $instant -> getAttribute ('executeJob'),
182 description => $job_name,
183 url => (
184 ($job_name ne 'Severance')
185 ? $job -> getElementsByTagName ('FileUrl', 0) -> item (0) -> getFirstChild -> getData
186 : undef
187 ),
188 Severance => (
189 ($job_name eq 'Severance')
190 ? get_severance ($job)
191 : undef
192 )
193 };
194
195 # User
196 my $user = $forum -> getElementsByTagName ('UserManagement', 0) -> item (0);
197
198 $conf {User} = {
199 deleteAfterDays => $user
200 -> getElementsByTagName ('DeleteUser', 0) -> item (0)
201 -> getElementsByTagName ('AfterDays', 0) -> item (0)
202 -> getFirstChild -> getData
203 };
204 }
205 }
206
207 # return
208 \%conf;
209 }
210
211 # keep 'require' happy
212 1;
213
214 #
215 #
216 ### end of Conf::Admin #########################################################

patrick-canterino.de