]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_posting.pl
8c9f8da8f97f5aa35bab956a76e50707871a6fed
3 ################################################################################
5 # File: user/fo_posting.pl #
7 # Authors: André Malo <nd@o3media.de>, 2001-03-31 #
9 # Description: Accept new postings, display "Neue Nachricht" page #
11 # not ready, be patient please #
13 ################################################################################
16 use vars
qw($Bin $Shared $Script);
20 my $null = $0; $null =~ s/\\/\//g; # for win :-(
21 ($Bin) = ($null =~ /^(.*)\/.*$/)? $1 : '.';
22 $Shared = "$Bin/../shared";
23 ($Script) = ($null =~ /^.*\/(.*)$/)? $1 : $null;
27 #use CGI::Carp qw(fatalsToBrowser);
30 use Encode
::Plain
; $Encode::Plain
::utf8
= 1;
35 use Posting
::_lib
qw(get_all_threads get_message_node get_message_header hr_time parse_xml_file);
38 use Template
::Posting
;
43 # load script configuration and admin default conf.
44 my $conf = read_script_conf
($Bin, $Shared, $Script);
45 my $adminDefault = read_admin_conf
($conf -> {files
} -> {adminDefault
});
47 # Initializing the request
48 my $response = new Posting
::Response
($conf, $adminDefault);
50 # fetch and parse the cgi-params
51 $response -> parse_cgi
;
54 ################################################################################
55 ### Posting::Response ##########################################################
56 package Posting
::Response
;
58 ### sub new ####################################################################
60 # initialising the Posting::Response object
61 # check parameters and fill in object properties
64 my ($class, $conf, $adminDefault) = @_;
66 my $sp = $conf -> {show
} -> {Posting
};
71 admin
=> $adminDefault,
73 message_path
=> $conf -> {files
} -> {messagePath
},
74 forum_file_name
=> $conf -> {files
} -> {forum
},
77 assign
=> $sp -> {assign
},
78 form_must
=> $sp -> {form
} -> {must
},
79 form_data
=> $sp -> {form
} -> {data
},
80 form_action
=> $sp -> {form
} -> {action
},
83 template
=> new Template
$sp -> {templateFile
}
89 ### sub parse_cgi ##############################################################
91 # fetch and decode cgi-parameters,
92 # find out the kind of response requested by the user (new message, reply)
94 # Return: Status Code (Bool)
95 # try out the error method, if false
100 # create the CGI object
102 $self -> {cgi_object
} = $q;
105 return unless $self -> check_cgi
;
108 ### sub check_cgi ##############################################################
110 # cgi params are like raw eggs...
112 # Return: Status Code (Bool)
113 # creates content for the error method if anything fails
118 # find out the count of the submitted keys and the keys themselves
120 my %got_keys = map {($_ => 1)} $self -> {cgi_object
} -> param
;
121 my $cnt_got_keys = keys %got_keys;
122 my $formdata = $self -> {conf
} -> {form_data
};
123 my $formmust = $self -> {conf
} -> {form_must
};
125 # user requested the 'new thread' page
126 # (no params or only the user-ID has been submitted)
128 if ($cnt_got_keys == 0 or (
129 exists ($formdata -> {userID
})
130 and $cnt_got_keys == 1
131 and $got_keys{$formdata -> {userID
} -> {name
}}
134 $self -> {response
} = {new_thread
=> 1};
138 # now we know, we've got a filled out form
139 # we do the following steps to check it:
141 # 1st: create a reverse Hash (CGI-key - identifier)
142 # 2nd: did we get _all_ must-keys?
143 # check whether reply or new message request
144 # 3rd: did we get too many keys?
145 # 4th: do _all_ submitted values accord to
147 # fetch the "missing" keys
152 my %name = map {($formdata -> {$_} -> {name
} => $_)} keys %$formdata;
156 $self -> {response
} -> {reply
} = $got_keys {$formdata -> {followUp
} -> {name
}}?
1 : 0;
157 $self -> {response
} -> {new
} = not $self -> {response
} -> {reply
};
159 # define the fetch array (values to fetch from parent message)
161 $self -> {fetch
} = [];
163 for ( @
{$formmust -> {$self -> {response
} -> {reply
}?
'reply':'new'}} ) {
165 unless ($got_keys {$formdata -> {$_} -> {name
}}) {
167 # only miss the key unless we're able to fetch it from parent posting
170 $self -> {response
} -> {new
}
171 or $formdata -> {$name {$_}} -> {errorType
} eq 'fetch') {
173 $self -> {error
} = {spec
=> 'missing_key'};
177 # keep in mind to fetch the value later
179 push @
{$self -> {fetch
}} => $name {$_};
186 for ($self -> {cgi_object
} -> param
) {
187 unless (exists ($name {$_})) {
189 spec
=> 'unexpected_key',
198 unless ($self -> decode_param
) {
199 $self -> {error
} = {spec
=> 'unknown_encoding'};
203 # I'm lazy - I know...
204 my $q = $self -> {cgi_object
};
206 if ($self -> {response
} -> {reply
}) {
208 # get the parent-identifiers if we got a reply
210 my ($ftid, $fmid) = split /;/ => $q -> param
($formdata -> {followUp
} -> {name
}) => 2;
212 unless ($ftid =~ /\d+/ and $fmid =~ /\d+/) {
213 $self -> {error
} = {spec
=> 'unknown_followup'};
216 $self -> {fup_tid
} = $ftid;
217 $self -> {fup_mid
} = $fmid;
219 # fetch the missing keys
220 # if it fails, they're too short, too... ;)
223 $got_keys{$_}=1 for (@
{$self -> {fetch
}});
226 # now we can check on length, type etc.
228 for (keys %got_keys) {
230 my $val = $q -> param
($_);
232 $val =~ s/\302\240/ /g; # convert nbsp (UTF-8 encoded) into normal spaces
233 $val =~ s/\015\012|\015|\012/ /g # convert \n into spaces unless it's a multiline field
235 exists ($formdata -> {$name {$_}} -> {type
})
236 and $formdata -> {$name {$_}} -> {type
} eq 'multiline-text'
239 $q -> param
($_ => $val); # write it back
243 if (length $val > $formdata -> {$name {$_}} -> {maxlength
}) {
252 # (only check if there's defined a minimum length)
254 if (exists ($formdata -> {$name {$_}} -> {minlength
})) {
256 # kill the whitespaces to get only the visible characters...
258 (my $val_ww = $val) =~ s/\s+//g;
260 if (length $val_ww < $formdata -> {$name {$_}} -> {minlength
}) {
269 # check the values on expected kinds of content
270 # (email, http-url, url)
272 if (exists ($formdata -> {$name {$_}} -> {type
}) and length $val) {
273 if ($formdata -> {$name {$_}} -> {type
} eq 'email' and not is_email
$val) {
275 spec
=> 'wrong_mail',
281 elsif ($formdata -> {$name {$_}} -> {type
} eq 'http-url' and not is_URL
$val => 'http') {
283 spec
=> 'wrong_http_url',
289 elsif ($formdata -> {$name {$_}} -> {type
} eq 'url' and not is_URL
$val => ':ALL') {
303 ### sub fetch ##################################################################
305 # fetch "missing" keys from parent posting
309 my $q = $self -> {cgi_object
};
310 my $formdata = $self -> {conf
} -> {form_data
};
312 if (@
{$self -> {fetch
}}) {
313 my $filename = $self -> {conf
} -> {message_path
}.'t'.$self -> {fup_tid
}.'.xml';
315 if (lock_file
($filename)) {
316 my $xml = parse_xml_file
($filename);
317 violent_unlock_file
($filename) unless unlock_file
($filename);
320 my $mnode = get_message_node
($xml, 't'.$self -> {fup_tid
}, 'm'.$self -> {fup_mid
});
322 my $header = get_message_header
($mnode);
324 $q -> param
($formdata -> {$_} -> {name
} => $header -> {$formdata -> {$_} -> {header
}})
325 for (@
{$self -> {fetch
}});
332 # fillout the values with an empty string
334 $q -> param
($formdata -> {$_} -> {name
} => '')
335 for (@
{$self -> {fetch
}});
338 ### sub decode_param ###########################################################
340 # convert submitted form data into UTF-8
341 # unless it's not encoded yet
343 # Return: Status Code (Bool)
344 # false if unknown encoding (like UTF-7 for instance)
349 my $q = $self -> {cgi_object
};
350 my $formdata = $self -> {conf
} -> {form_data
};
352 my $code = $q -> param
($formdata -> {quoteChar
} -> {name
});
355 # Latin 1 (we hope so - there's no real way to find out :-( )
356 if ($code =~ /^\377/) {
357 $q -> param
($_ => map {toUTF8
($_)} $q -> param
($_)) for ($q -> param
);
360 # UTF-8 is (probably) correct,
361 # other encodings we don't know and fail
362 return unless $code =~ /^\303\277/;
365 # remove the ÿ (encoded as UTF-8) from quotechars
366 $q -> param
($formdata -> {quoteChar
} -> {name
} => substr ($code, 2));
368 # ok, params now should be UTF-8 encoded
374 ### end of fo_posting.pl #######################################################
patrick-canterino.de