]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/user/fo_posting.pl
3 ################################################################################
5 # File: user/fo_posting.pl #
7 # Authors: André Malo <nd@o3media.de>, 2001-03-30 #
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 ###################################################
139 # now we know, we've got a filled out form
140 # we do the following steps to check it:
142 # 1st: create a reverse Hash (CGI-key - identifier)
143 # 2nd: did we get _all_ must-keys?
144 # check whether reply or new message request
145 # 3rd: did we get too many keys?
146 # 4th: do _all_ requested values accord to
148 # fetch the "missing" keys
153 my %name = map {($formdata -> {$_} -> {name
} => $_)} keys %$formdata;
157 $self -> {response
} -> {reply
} = $got_keys {$formdata -> {followUp
} -> {name
}}?
1 : 0;
158 $self -> {response
} -> {new
} = not $self -> {response
} -> {reply
};
160 # define the fetch array (values to fetch from parent message)
162 $self -> {fetch
} = [];
164 for ( @
{$formmust -> {$self -> {response
} -> {reply
}?
'reply':'new'}} ) {
166 unless ($got_keys {$formdata -> {$_} -> {name
}}) {
168 # only miss the key unless we're able to fetch it from parent posting
171 $self -> {response
} -> {new
}
172 or $formdata -> {$name {$_}} -> {errorType
} eq 'fetch') {
174 $self -> {error
} = {spec
=> 'missing_key'};
178 # keep in mind to fetch the value later
180 push @
{$self -> {fetch
}} => $name {$_};
187 for ($self -> {cgi_object
} -> param
) {
188 unless (exists ($name {$_})) {
190 spec
=> 'unexpected_key',
199 unless ($self -> decode_param
) {
200 $self -> {error
} = {spec
=> 'unknown_encoding'};
204 # I'm lazy - I know...
205 my $q = $self -> {cgi_object
};
207 if ($self -> {response
} -> {reply
}) {
209 # get the parent-identifiers if we got a reply
211 my ($ftid, $fmid) = split /;/ => $q -> param
($formdata -> {followUp
} -> {name
}) => 2;
213 unless ($ftid =~ /\d+/ and $fmid =~ /\d+/) {
214 $self -> {error
} = {spec
=> 'unknown_followup'};
217 $self -> {fup_tid
} = $ftid;
218 $self -> {fup_mid
} = $fmid;
220 # now fetching the missing keys
221 # if it fails, they're too short, too... ;)
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 to normal spaces
233 $q -> param
($_ => $val); # write it back
237 if (length $val > $formdata -> {$name {$_}} -> {maxlength
}) {
246 # (only check if there's defined a minimum length)
248 if (exists ($formdata -> {$name {$_}} -> {minlength
})) {
250 # kill the whitespaces to get only the visible characters...
252 (my $val_ww = $val) =~ s/\s+//g;
254 if (length $val_ww < $formdata -> {$name {$_}} -> {minlength
}) {
263 # return 'wrongMail' if ($formdata -> {$name{$_}} -> {type} eq 'email' and length ($dparam{$_}) and not is_mail_address ($dparam{$_}));
270 # delete $dparam {$formdata -> {posterURL} -> {name}}
271 # unless ($dparam {$formdata -> {posterURL} -> {name}} =~ /$httpurl/);
273 # delete $dparam {$formdata -> {posterImage} -> {name}}
274 # unless ($dparam {$formdata -> {posterImage} -> {name}} =~ /$httpurl/);
276 ### sub fetch ##################################################################
278 # fetch "missing" keys from parent posting
282 my $q = $self -> {cgi_object
};
283 my $formdata = $self -> {conf
} -> {form_data
};
285 if (@
{$self -> {fetch
}}) {
286 my $filename = $self -> {conf
} -> {message_path
}.'t'.$self -> {fup_tid
}.'.xml';
288 if (lock_file
($filename)) {
289 my $xml = parse_xml_file
($filename);
290 violent_unlock_file
($filename) unless unlock_file
($filename);
293 my $mnode = get_message_node
($xml, 't'.$self -> {fup_tid
}, 'm'.$self -> {fup_mid
});
295 my $header = get_message_header
($mnode);
297 $q -> param
($formdata -> {$_} -> {name
} => $header -> {$formdata -> {$_} -> {header
}})
298 for (@
{$self -> {fetch
}});
305 # fillout the values with an empty string
307 $q -> param
($formdata -> {$_} -> {name
} => '')
308 for (@
{$self -> {fetch
}});
311 ### sub decode_param ###########################################################
313 # convert submitted form data into UTF-8
314 # unless it's not encoded yet
316 # Return: Status Code (Bool)
317 # false if unknown encoding (like UTF-7 for instance)
322 my $q = $self -> {cgi_object
};
323 my $formdata = $self -> {conf
} -> {form_data
};
325 my $code = $q -> param
($formdata -> {quoteChar
} -> {name
});
328 # Latin 1 (we hope so - there's no real way to find out :-( )
329 if ($code =~ /^\377/) {
330 $q -> param
($_ => map {toUTF8
($_)} $q -> param
($_)) for ($q -> param
);
333 # UTF-8 is (probably) correct,
334 # other encodings we don't know and fail
335 return unless $code =~ /^\303\277/;
338 # remove the ÿ (encoded as UTF-8) from quotechars
339 $q -> param
($formdata -> {quoteChar
} -> {name
} => substr ($code, 2));
341 # ok, params now should be UTF-8 encoded
347 ### end of fo_posting.pl #######################################################
patrick-canterino.de