Initial commit.

This commit is contained in:
2026-03-10 21:25:26 +08:00
commit 78739bf725
3089 changed files with 472990 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
# Selima Website Content Management System
# LinkCatz.pm: The related-link category membership 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-03-17
package Selima::Processor::LinkCatz;
use 5.008;
use strict;
use warnings;
use base qw(Selima::Processor::Categorz);
use Selima::DataVars qw($DBH :addcol :scptconf);
use Selima::Guest;
use Selima::Links;
# new: Initialize the processor
sub new : method {
local ($_, %_);
my ($self, $class);
($class, @_) = @_;
$_[1] = "linkcatz" 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"}->addnum("cat", $self->_form("cat"));
$self->{"cols"}->addnum("link", $self->_form("link"));
# A form to edit a current item
} elsif ($self->{"type"} eq "cur") {
$self->{"cols"} = new Selima::AddCol($self->{"table"}, ADDCOL_UPDATE);
$self->{"cols"}->addnum("cat", $self->_form("cat"), scalar $cur->param("cat"));
$self->{"cols"}->addnum("link", $self->_form("link"), scalar $cur->param("link"));
}
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 link categorization record " . link_url($form->param("link"))
. " in category " . linkcat_title($form->param("cat"))
. " with s/n " . $self->{"sn"} . "."
if $self->{"type"} eq "new";
# A form to edit a current item
return gactlog "Update the link categorization record " . link_url($form->param("link"))
. " in category " . linkcat_title($form->param("cat"))
. " with s/n " . $self->{"sn"} . "."
if $self->{"type"} eq "cur";
# A form to delete a current item
return gactlog "Delete the link categorization record " . link_url($cur->param("link"))
. " in category " . linkcat_title($cur->param("cat"))
. " with s/n " . $self->{"sn"} . "."
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, @parents, @cats, $cond);
$self = $_[0];
($form, $cur) = ($self->{"form"}, $self->{"cur"});
$self->{"newshown"} = $self->_shown_parts;
# Remove the unwanted pages
$self->_remove_curfile;
# Find the affected parents
@parents = qw();
@_ = qw();
%_ = map { $_ => 1 } @{${$self->{"curshown"}}{"cats"}};
push @_, grep !exists $_{$_}, @{${$self->{"newshown"}}{"cats"}};
%_ = map { $_ => 1 } @{${$self->{"newshown"}}{"cats"}};
push @_, grep !exists $_{$_}, @{${$self->{"curshown"}}{"cats"}};
if (@_ > 0) {
my ($sql, $sth, $count, $row);
$sql = "SELECT parent FROM linkcat"
. " WHERE " . join(" OR ", map "sn=$_", @_)
. " GROUP BY parent;\n";
$sth = $DBH->prepare($sql);
$sth->execute;
$count = $sth->rows;
for ($_ = 0; $_ < $count; $_++) {
push @parents, ${$sth->fetch}[0];
}
}
# Find the affected parts
# Only the shown parts are added
%_ = qw();
# A form to create a new item
if ($self->{"type"} eq "new") {
$_{$form->param("cat")} = 1;
# A form to edit a current item
} elsif ($self->{"type"} eq "cur") {
$_{$form->param("cat")} = 1;
$_{$cur->param("cat")} = 1;
# A form to delete a current item
} elsif ($self->{"type"} eq "del") {
$_{$cur->param("cat")} = 1;
}
@cats = keys %_;
# The statistics pages on their parents are affected
unless ($self->{"type"} eq "cur"
&& $form->param("cat") == $cur->param("cat")) {
my ($sql, $sth, $count);
$_ = join(" OR ", map "sn=$_", @cats);
$_ = "($_)" if @_ > 1;
$sql = "SELECT parent FROM linkcat"
. " WHERE $_"
. " AND parent IS NOT NULL"
. " AND linkcat_isshown(sn, hid, parent)"
. " GROUP BY parent;\n";
$sth = $DBH->prepare($sql);
$sth->execute;
$count = $sth->rows;
for ($_ = 0; $_ < $count; $_++) {
push @cats, ${$sth->fetch}[0];
}
}
%_ = map { $_ => 1 } @cats;
@cats = keys %_;
# Compose the SQL statement
@_ = qw();
push @_, "sn=" . $_ foreach @cats;
foreach (@parents) {
# The parent page and those share the same parent
if (defined $_) {
push @_, "sn=" . $_;
push @_, "parent=" . $_;
# The topmost pages
} else {
push @_, "parent IS NULL";
}
}
$cond = join " OR ", @_;
$cond = "($cond)" if @_ > 1;
@_ = $DBH->cols("linkcat");
push @_, $DBH->strcat("'/links'", "linkcat_path(sn, id, parent)")
. " AS path";
$sql = "SELECT " . join(", ", @_) . " FROM linkcat"
. " WHERE $cond"
. " AND linkcat_isshown(sn, hid, parent);\n";
# Rebuild the pages
$_ = $MAIN->can("rebuild_links");
&$_($sql);
return;
}
# _remove_curfile: Remove the unwanted page
sub _remove_curfile : method {
local ($_, %_);
my $self;
$self = $_[0];
# Remove the unwanted category files
%_ = map { $_ => 1 } @{${$self->{"newshown"}}{"catspath"}};
grmoldpage $_
foreach grep !exists $_{$_}, @{${$self->{"curshown"}}{"catspath"}};
return;
}
# _shown_parts: Obtain the shown parts
sub _shown_parts : method {
return links_shown_parts;
}
return 1;