Initial commit.
This commit is contained in:
157
lib/perl5/Selima/Processor/Page.pm
Normal file
157
lib/perl5/Selima/Processor/Page.pm
Normal file
@@ -0,0 +1,157 @@
|
||||
# Selima Website Content Management System
|
||||
# Page.pm: The base web page form data processor.
|
||||
|
||||
# Copyright (c) 2006-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: 2006-04-02
|
||||
|
||||
package Selima::Processor::Page;
|
||||
use 5.008;
|
||||
use strict;
|
||||
use warnings;
|
||||
use base qw(Selima::Processor);
|
||||
|
||||
use Selima::DataVars qw(:addcol :scptconf);
|
||||
use Selima::Guest;
|
||||
use Selima::ShortCut;
|
||||
|
||||
# new: Initialize the processor
|
||||
sub new : method {
|
||||
local ($_, %_);
|
||||
my ($self, $class);
|
||||
($class, @_) = @_;
|
||||
$_[1] = "pages" if @_ < 2;
|
||||
$self = $class->SUPER::new(@_);
|
||||
return $self;
|
||||
}
|
||||
|
||||
# _save_cols: Save the column deposit
|
||||
sub _save_cols : method {
|
||||
local ($_, %_);
|
||||
my ($self, $form, $cur);
|
||||
$self = $_[0];
|
||||
($form, $cur) = ($self->{"form"}, $self->{"cur"});
|
||||
# A form to create a new item
|
||||
if ($self->{"type"} eq "new") {
|
||||
$self->{"sn"} = $self->_new_sn;
|
||||
$self->{"cols"} = new Selima::AddCol($self->{"table"}, ADDCOL_INSERT);
|
||||
$self->{"cols"}->addnum("sn", $self->{"sn"});
|
||||
$self->{"cols"}->addstr("path", $self->_form("path"));
|
||||
$self->{"cols"}->addnum("ord", $self->_form("ord"));
|
||||
$self->{"cols"}->addstr("title", $self->_form("title"));
|
||||
$self->{"cols"}->addstr("body", $self->_form("body"));
|
||||
$self->{"cols"}->addstr("kw", $self->_form("kw"));
|
||||
$self->{"cols"}->addbool("html", $self->_form("html"));
|
||||
$self->{"cols"}->addbool("hid", $self->_form("hid"));
|
||||
# Automatic Traditional Chinese to Simplified Chinese conversion
|
||||
$self->_zhsync;
|
||||
|
||||
# A form to edit a current item
|
||||
} elsif ($self->{"type"} eq "cur") {
|
||||
$self->{"cols"} = new Selima::AddCol($self->{"table"}, ADDCOL_UPDATE);
|
||||
$self->{"cols"}->addstr("path", $self->_form("path"), scalar $cur->param("path"));
|
||||
$self->{"cols"}->addnum("ord", $self->_form("ord"), scalar $cur->param("ord"));
|
||||
$self->{"cols"}->addstr("title", $self->_form("title"), scalar $cur->param("title"));
|
||||
$self->{"cols"}->addstr("body", $self->_form("body"), scalar $cur->param("body"));
|
||||
$self->{"cols"}->addstr("kw", $self->_form("kw"), scalar $cur->param("kw"));
|
||||
$self->{"cols"}->addbool("html", $self->_form("html"), scalar $cur->param("html"));
|
||||
$self->{"cols"}->addbool("hid", $self->_form("hid"), scalar $cur->param("hid"));
|
||||
# Automatic Traditional Chinese to Simplified Chinese conversion
|
||||
$self->_zhsync;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# _actlog: Log the activity
|
||||
sub _actlog : method {
|
||||
local ($_, %_);
|
||||
my ($self, $form, $cur);
|
||||
$self = $_[0];
|
||||
($form, $cur) = ($self->{"form"}, $self->{"cur"});
|
||||
# A form to create a new item
|
||||
return gactlog "Create a page " . $form->param("path")
|
||||
. " with s/n " . $self->{"sn"} . "."
|
||||
if $self->{"type"} eq "new";
|
||||
# A form to edit a current item
|
||||
return gactlog "Update the page " . $form->param("path")
|
||||
. " with s/n " . $self->{"sn"} . "."
|
||||
if $self->{"type"} eq "cur";
|
||||
# A form to delete a current item
|
||||
return gactlog "Delete the page " . $cur->param("path")
|
||||
. " with s/n " . $self->{"sn"} . "."
|
||||
if $self->{"type"} eq "del";
|
||||
}
|
||||
|
||||
# _ret_status: Return the process status
|
||||
sub _ret_status : method {
|
||||
local ($_, %_);
|
||||
my $self;
|
||||
$self = $_[0];
|
||||
return {"msg"=>N_("This page was not modified."),
|
||||
"isform"=>0}
|
||||
if !$self->_modified;
|
||||
# A form to create a new item
|
||||
return {"msg"=>N_("This page has been successfully added."),
|
||||
"isform"=>0}
|
||||
if $self->{"type"} eq "new";
|
||||
# A form to edit a current item
|
||||
return {"msg"=>N_("This page has been successfully updated."),
|
||||
"isform"=>0}
|
||||
if $self->{"type"} eq "cur";
|
||||
# A form to delete a current item
|
||||
return {"msg"=>N_("This page has been successfully deleted."),
|
||||
"isform"=>0}
|
||||
if $self->{"type"} eq "del";
|
||||
}
|
||||
|
||||
# _rebuild_partial_pages: Rebuild a limited part of pages
|
||||
sub _rebuild_partial_pages : method {
|
||||
local ($_, %_);
|
||||
my ($self, $form, $cur);
|
||||
my $sql;
|
||||
$self = $_[0];
|
||||
($form, $cur) = ($self->{"form"}, $self->{"cur"});
|
||||
# Remove the unwanted pages
|
||||
$self->_remove_curfile;
|
||||
# Nothing to rebuild when no shown parts are seen
|
||||
return if $self->{"type"} eq "del" || defined $form->param("hid");
|
||||
|
||||
# Compose the SQL statement
|
||||
$sql = "SELECT * FROM pages"
|
||||
. " WHERE sn=" . $self->{"sn"} . ";\n";
|
||||
# Rebuild the pages
|
||||
$_ = $MAIN->can("rebuild_pages");
|
||||
&$_($sql);
|
||||
return;
|
||||
}
|
||||
|
||||
# _remove_curfile: Remove the unwanted pages
|
||||
sub _remove_curfile : method {
|
||||
local ($_, %_);
|
||||
my ($self, $form, $cur);
|
||||
$self = $_[0];
|
||||
($form, $cur) = ($self->{"form"}, $self->{"cur"});
|
||||
# Nothing to remove if there is no current page
|
||||
return if $self->{"type"} eq "new" || $cur->param("hid");
|
||||
# A current page to be deleted or hidden
|
||||
return grmoldpage $cur->param("path")
|
||||
if $self->{"type"} eq "del" || defined $form->param("hid");
|
||||
# A shown page update with a new page path to check with
|
||||
return grmoldpage $cur->param("path"), $form->param("path");
|
||||
return;
|
||||
}
|
||||
|
||||
return 1;
|
||||
Reference in New Issue
Block a user