Files
selima-perl/htdocs/emily/magicat/archive/cgi-bin/guestbook.cgi
2026-03-10 21:31:43 +08:00

137 lines
3.5 KiB
Perl
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#! /usr/bin/perl -w
# Emily Wu's Website
# 1-guestbook.cgi: The guestbook.
# Copyright (c) 2003-2021 imacat.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Author: imacat <imacat@mail.imacat.idv.tw>
# First written: 2003-04-07
use 5.008;
use utf8;
use strict;
use warnings;
use lib $ENV{"DOCUMENT_ROOT"} . qw(/magicat/lib/perl5);
use Selima::emily;
local $SIG{"__DIE__"} = \&http_500;
my $d = new Selima::Destroy;
# Prototype declaration
sub main();
sub check_get();
sub check_post();
sub html_page($);
sub html_foreword();
initenv(-session => 0,
-this_table => "guestbook",
-dbi_lock => {"guestbook" => LOCK_EX},
-lastmod => 1,
-page_param => {"keywords" => N_("guestbook"),
"class" => "guestbook",
"javascripts" => [qw(/scripts/guestbook.js)]});
main;
exit 0;
sub main() {
local ($_, %_);
my ($error, $processor);
# If the request is a GET query
if ($ENV{"REQUEST_METHOD"} ne "POST") {
$error = check_get;
# If an error occurs
if (defined $error) {
html_page $error;
# Display the page
} else {
html_page retrieve_status;
}
# If a form was POSTed from the client
} else {
$error = check_post;
# If an error occurs
if (defined $error) {
error_redirect $error;
# Else, save the data
} else {
$processor = new Selima::emily::Processor::Guestbook::Public($POST);
$processor->process;
http_303 $REQUEST_FILE;
}
}
return;
}
# check_get: Check the GET arguments
sub check_get() {
local ($_, %_);
# Old styled page number
http_301 $REQUEST_FILE if defined $GET->param("no");
# List handler handles its own error
return;
}
# check_post: Check the POSTed form
sub check_post() {
local ($_, %_);
my ($checker, $error);
# Run the checker
$checker = new Selima::emily::Checker::Guestbook::Public(curform);
$error = $checker->check(qw(message name identity location
email url flood dup spam));
return $error if defined $error;
# OK
return;
}
# html_page: Display the page
sub html_page($) {
local ($_, %_);
my ($status, $LIST, $FORM, $args);
$status = $_[0];
$FORM = new Selima::emily::Form::Guestbook::Public($status);
$LIST = new Selima::emily::List::Guestbook::Public;
$args = $LIST->page_param;
html_header "留言板", $args;
html_foreword;
html_errmsg $status;
$FORM->html;
$LIST->html;
html_footer $args;
return;
}
##################################
# Subroutines to manage the data #
##################################
# html_foreword: Print the HTML foreword
sub html_foreword() {
local ($_, %_);
print << "EOT";
<div class="foreword">
<p>若您有任何需要或疑問請在此留言我將儘速為您服務</p>
</div>
EOT
return;
}
no utf8;