148 lines
4.1 KiB
Perl
148 lines
4.1 KiB
Perl
# Selima Website Content Management System
|
|
# ListPref.pm: The list preference administration.
|
|
|
|
# Copyright (c) 2004-2018 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: 2004-10-14
|
|
|
|
package Selima::ListPref;
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Fcntl qw(:flock);
|
|
use URI qw();
|
|
|
|
use Selima::AddGet;
|
|
use Selima::CallForm;
|
|
use Selima::DataVars qw($DBH :env :requri);
|
|
use Selima::HTTP;
|
|
|
|
use Selima::Checker::ListPref;
|
|
use Selima::Processor::ListPref;
|
|
|
|
# Load these classes
|
|
use Selima::ListPref::AcctReps;
|
|
|
|
# new: Initialize the handler
|
|
sub new : method {
|
|
local ($_, %_);
|
|
my ($class, $form, $self);
|
|
($class, $form) = @_;
|
|
$self = bless {}, $class;
|
|
$self->{"form"} = $form;
|
|
$self->_set_referer;
|
|
$self->_set_domain;
|
|
return $self;
|
|
}
|
|
|
|
# main: Change the list preference
|
|
sub main : method {
|
|
local ($_, %_);
|
|
my ($self, $error, $processor);
|
|
$self = $_[0];
|
|
# Lock the necessary tables
|
|
$DBH->lock("userpref" => LOCK_EX);
|
|
|
|
$error = $self->_check_post();
|
|
# If an error occurs
|
|
if (defined $error) {
|
|
$$error{"isform"} = 0;
|
|
error_redirect $error;
|
|
|
|
# Else, save the data
|
|
} else {
|
|
$processor = new Selima::Processor::ListPref($self->{"form"});
|
|
$processor->process;
|
|
http_303 $self->{"referer"};
|
|
}
|
|
}
|
|
|
|
# _check_post: Check the list preference form
|
|
sub _check_post : method {
|
|
local ($_, %_);
|
|
my ($self, $checker, $error);
|
|
$self = $_[0];
|
|
# Run the checker
|
|
$checker = new Selima::Checker::ListPref($self->{"form"});
|
|
$error = $checker->check(qw(domain listcols listsize));
|
|
return $error if defined $error;
|
|
# OK
|
|
return;
|
|
}
|
|
|
|
# _set_referer: Obtain the referer to return to
|
|
sub _set_referer : method {
|
|
local ($_, %_);
|
|
my $self;
|
|
$self = $_[0];
|
|
# Obtained before
|
|
return $self->{"referer"} if exists $self->{"referer"};
|
|
# Remove the status from the source referer
|
|
return ($self->{"referer"} = rem_get_arg $self->_source_referer, "statid");
|
|
}
|
|
|
|
# _source_referer: Obtain the source referer
|
|
sub _source_referer : method {
|
|
local ($_, %_);
|
|
my ($self, $r);
|
|
$self = $_[0];
|
|
# Use the POSTed referer
|
|
return $_ if defined($_ = $self->{"form"}->param("referer"));
|
|
# Use the referer from the request
|
|
if ($IS_MODPERL) {
|
|
$r = $IS_MP2? Apache2::RequestUtil->request:
|
|
Apache->request;
|
|
return $_ if defined($_ = $r->headers_in->get("Referer"));
|
|
} else {
|
|
return $ENV{"HTTP_REFERER"} if exists $ENV{"HTTP_REFERER"};
|
|
}
|
|
# Fall back to myself
|
|
return $REQUEST_FULLURI;
|
|
}
|
|
|
|
# _set_domain: Obtain the domain this preference belongs to
|
|
sub _set_domain : method {
|
|
local ($_, %_);
|
|
my ($self, $form, $uri);
|
|
$self = $_[0];
|
|
$form = $self->{"form"};
|
|
# Obtained before
|
|
return $self->{"domain"} if exists $self->{"domain"};
|
|
# Return the supplied domain
|
|
return ($self->{"domain"} = $_)
|
|
if defined($_ = $form->param("domain"));
|
|
# Obtain the referer first
|
|
$self->_set_referer;
|
|
# Return the current script path for the most cases
|
|
if ($self->{"referer"} eq $REQUEST_FULLURI) {
|
|
$self->{"domain"} = $REQUEST_PATH;
|
|
$form->param("domain", $self->{"domain"});
|
|
return $self->{"domain"};
|
|
}
|
|
|
|
# Parse the referer to get the script path
|
|
$uri = new URI($self->{"referer"});
|
|
# Fall back to the root directory if there is no script part
|
|
$self->{"domain"} = (($_ = $uri->path) ne "")? $_: "/";
|
|
# Strip the leading root difference
|
|
$self->{"domain"} =~ s/^$ROOT_DIFF//;
|
|
$form->param("domain", $self->{"domain"});
|
|
return $self->{"domain"};
|
|
}
|
|
|
|
return 1;
|