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

154
lib/perl5/Selima/Preview.pm Normal file
View File

@@ -0,0 +1,154 @@
# Selima Website Content Management System
# Preview.pm: The subroutines to handle the HTML output of the page preview.
# 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-07
package Selima::Preview;
use 5.008;
use strict;
use warnings;
use base qw(Exporter);
use vars qw(@EXPORT @EXPORT_OK);
BEGIN {
@EXPORT = qw(fetch_preview html_preview html_preview_mark);
@EXPORT_OK = @EXPORT;
# Prototype declaration
sub fetch_preview();
sub html_preview();
sub html_preview_mark(;$);
}
use Fcntl qw(:flock);
use Selima::DataVars qw($DBH :dataman :input :rebuild :requri :scptconf);
use Selima::CallForm;
use Selima::HTTP;
use Selima::Page2Rel;
use Selima::PageFunc;
use Selima::ReqURI;
use Selima::ShortCut;
# fetch_preview: Retrieve a previously suspended preview from,
# from $SESSION or database
sub fetch_preview() {
local ($_, %_);
my $source;
# S/N not specified
return {"msg"=>N_("The following field was not received: \"[_1]\"."),
"margs"=>["sn"],
"isform"=>0}
if !defined $GET->param("sn");
# Check the source to retrieve the preview form
$source = "session";
if (defined $GET->param("source")) {
# Retrieve from the database
if ($GET->param("source") eq "db") {
$source = "db";
# Retrieve from the $SESSION saveform
} elsif ($GET->param("source") eq "session") {
$source = "session";
# Other preview sources
} else {
return {"msg"=>N_("Unknown preview source: \"[_1]\"."),
"margs"=>[$GET->param("source")],
"isform"=>0}
}
}
# Retrieve the preview form
# Retrieve from the database
if ($source eq "db") {
# Fetch with fetch_curitem()
$_ = $MAIN->can("fetch_curitem");
&$_();
%PREVIEW = %CURRENT;
# Retrieve from the $SESSION saveform
} elsif ($source eq "session") {
%PREVIEW = retrieve_form($GET->param("sn"))->Vars;
return {"msg"=>N_("Unknown preview form: \"[_1]\"."),
"margs"=>[$GET->param("sn")],
"isform"=>0}
if keys %PREVIEW == 0
}
# Tag that this is a preview content
$PREVIEW{"preview"} = 1;
# OK
return;
}
# html_preview: Display the preview
sub html_preview() {
local ($_, %_);
my ($lang, $html);
$lang = exists $PREVIEW{"lang"}? $PREVIEW{"lang"}: undef;
# Lock the required tables
$DBH->lock(map { $_ => LOCK_SH } @REBUILD_TABLES);
$_ = $MAIN->can("compose_page");
$html = &$_({%PREVIEW}, $lang);
$html = page2rel(page2abs($html, $PREVIEW{"path"}), $REQUEST_PATH);
print $html;
return;
}
# html_preview_mark: Print the HTML preview mark
sub html_preview_mark(;$) {
local ($_, %_);
my ($args, $source, $uri, $title, $ret);
$args = $_[0];
# Obtain the page parameters
$args = page_param $args;
# This is only for the preview
return unless defined $$args{"preview"};
# Decide the data source
$source = "session";
if (defined $GET->param("source")) {
# Retrieve from the database
if ($GET->param("source") eq "db") {
$source = "db";
# Retrieve from the $SESSION saveform
} elsif ($GET->param("source") eq "session") {
$source = "session";
# Other preview sources
} else {
http_500 C_("Unknown preview source: \"[_1]\".", $GET->param("source"));
}
}
# Retrieve from the database
if ($source eq "db") {
$uri = h($REQUEST_PATH . "?form=cur&sn=" . $GET->param("sn"));
# Retrieve from the $SESSION saveform
} elsif ($source eq "session") {
$uri = h($REQUEST_PATH . "?formid=" . $GET->param("sn"));
}
$title = h(C_("Preview"));
$ret = h(C_("Finish preview and return."));
print << "EOT";
<div class="previewmark">
<h2>$title</h2>
<p><a href="$uri">$ret</a></p>
</div>
EOT
return;
}
return 1;