2014-03-18 09:26:04 +01:00
|
|
|
# Copyright (C) 2004-2014 Alex Schroeder <alex@gnu.org>
|
2004-08-18 16:51:02 +00:00
|
|
|
#
|
2013-10-25 08:49:13 +02:00
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
|
# version.
|
2004-08-18 16:51:02 +00:00
|
|
|
#
|
2013-10-25 08:49:13 +02:00
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
2004-08-18 16:51:02 +00:00
|
|
|
#
|
2013-10-25 08:49:13 +02:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-08-18 16:51:02 +00:00
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('static-copy.pl', 'Static Copy Extension');
|
2004-08-18 16:51:02 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, %Page, %IndexHash, $OpenPageName, $ScriptName, $SiteName, $UsePathInfo, %Action, $CommentsPrefix, $FreeLinks, $WikiLinks, $LinkPattern, $FreeLinkPattern, $StyleSheet, $StyleSheetPage, $TopLinkBar, $UserGotoBar, $LogoUrl, $SidebarName);
|
2004-08-18 16:43:25 +00:00
|
|
|
$Action{static} = \&DoStatic;
|
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($StaticDir, $StaticAlways, %StaticMimeTypes, $StaticUrl);
|
2004-08-18 16:43:25 +00:00
|
|
|
|
|
|
|
|
$StaticDir = '/tmp/static';
|
2006-08-09 18:21:23 +00:00
|
|
|
$StaticUrl = ''; # change this!
|
|
|
|
|
$StaticAlways = 0; # 1 = uploaded files only, 2 = all pages
|
2004-10-07 00:22:38 +00:00
|
|
|
|
2004-12-26 00:38:36 +00:00
|
|
|
my $StaticMimeTypes = '/etc/mime.types';
|
2004-10-07 00:22:38 +00:00
|
|
|
my %StaticFiles;
|
2004-08-18 16:43:25 +00:00
|
|
|
|
|
|
|
|
sub DoStatic {
|
|
|
|
|
return unless UserIsAdminOrError();
|
|
|
|
|
my $raw = GetParam('raw', 0);
|
|
|
|
|
if ($raw) {
|
|
|
|
|
print GetHttpHeader('text/plain');
|
|
|
|
|
} else {
|
|
|
|
|
print GetHeader('', T('Static Copy'), '');
|
|
|
|
|
}
|
|
|
|
|
CreateDir($StaticDir);
|
2004-10-07 00:22:38 +00:00
|
|
|
%StaticFiles = ();
|
2014-03-18 11:21:08 +01:00
|
|
|
print '<p>' unless $raw;
|
2004-10-07 00:22:38 +00:00
|
|
|
StaticWriteFiles();
|
|
|
|
|
print '</p>' unless $raw;
|
|
|
|
|
PrintFooter() unless $raw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticMimeTypes {
|
|
|
|
|
my %hash;
|
|
|
|
|
# the default mapping matches the default @UploadTypes...
|
2015-05-15 16:31:47 +02:00
|
|
|
open(my $fh, '<', $StaticMimeTypes)
|
2004-12-26 00:38:36 +00:00
|
|
|
or return ('image/jpeg' => 'jpg', 'image/png' => 'png', );
|
2015-05-15 16:31:47 +02:00
|
|
|
while (<$fh>) {
|
2005-03-01 16:48:01 +00:00
|
|
|
s/\#.*//; # remove comments
|
2004-10-07 00:22:38 +00:00
|
|
|
my($type, $ext) = split;
|
|
|
|
|
$hash{$type} = $ext if $ext;
|
|
|
|
|
}
|
2015-05-15 16:31:47 +02:00
|
|
|
close($fh);
|
2004-10-07 00:22:38 +00:00
|
|
|
return %hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticWriteFiles {
|
|
|
|
|
my $raw = GetParam('raw', 0);
|
2014-03-18 09:26:04 +01:00
|
|
|
my $html = GetParam('html', 0);
|
2015-04-12 22:50:50 +03:00
|
|
|
local *ScriptLink = \&StaticScriptLink;
|
|
|
|
|
local *GetDownloadLink = \&StaticGetDownloadLink;
|
2004-08-18 16:43:25 +00:00
|
|
|
foreach my $id (AllPagesList()) {
|
2013-10-25 08:49:13 +02:00
|
|
|
if ($StaticAlways > 1
|
2014-03-18 09:26:04 +01:00
|
|
|
or $html
|
2013-10-25 08:49:13 +02:00
|
|
|
or PageIsUploadedFile($id)) {
|
2014-03-18 09:26:04 +01:00
|
|
|
StaticWriteFile($id, $html);
|
2013-10-25 08:49:13 +02:00
|
|
|
}
|
2004-10-07 00:22:38 +00:00
|
|
|
}
|
2014-03-18 12:47:16 +01:00
|
|
|
if ($StaticAlways > 1 or $html) {
|
|
|
|
|
StaticWriteCss();
|
|
|
|
|
}
|
2004-10-07 00:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticScriptLink {
|
|
|
|
|
my ($action, $text, $class, $name, $title, $accesskey) = @_;
|
|
|
|
|
my %params;
|
|
|
|
|
if ($action !~ /=/) {
|
2004-10-13 19:01:35 +00:00
|
|
|
# the page might not exist, eg. if called via GetAuthorLink
|
2016-02-02 20:22:06 +02:00
|
|
|
$params{'-href'} = StaticFileName($action) if $IndexHash{UrlDecode($action)};
|
2004-10-07 00:22:38 +00:00
|
|
|
}
|
|
|
|
|
$params{'-class'} = $class if $class;
|
|
|
|
|
$params{'-name'} = UrlEncode($name) if $name;
|
|
|
|
|
$params{'-title'} = $title if $title;
|
|
|
|
|
$params{'-accesskey'} = $accesskey if $accesskey;
|
|
|
|
|
return $q->a(\%params, $text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticGetDownloadLink {
|
|
|
|
|
my ($name, $image, $revision, $alt) = @_; # ignore $revision
|
|
|
|
|
$alt = $name unless $alt;
|
2006-08-13 23:10:49 +00:00
|
|
|
$alt =~ s/_/ /g;
|
2004-10-07 00:22:38 +00:00
|
|
|
my $id = FreeToNormal($name);
|
|
|
|
|
# if the page does not exist
|
|
|
|
|
return '[' . ($image ? 'image' : 'link') . ':' . $name . ']' unless $IndexHash{$id};
|
|
|
|
|
if ($image) {
|
2006-08-13 23:10:49 +00:00
|
|
|
return StaticFileName($id) if $image == 2;
|
2004-10-07 00:22:38 +00:00
|
|
|
my $result = $q->img({-src=>StaticFileName($id), -alt=>$alt, -class=>'upload'});
|
|
|
|
|
$result = ScriptLink($id, $result, 'image');
|
|
|
|
|
return $result;
|
|
|
|
|
} else {
|
|
|
|
|
return ScriptLink($id, $alt, 'upload');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticFileName {
|
|
|
|
|
my $id = shift;
|
2005-03-01 16:48:01 +00:00
|
|
|
$id =~ s/#.*//; # remove named anchors for the filename test
|
2004-10-07 00:22:38 +00:00
|
|
|
return $StaticFiles{$id} if $StaticFiles{$id}; # cache filenames
|
2004-10-07 01:05:45 +00:00
|
|
|
# Don't clober current open page so don't use OpenPage. UrlDecode
|
|
|
|
|
# the $id to open the file because when called from
|
|
|
|
|
# StaticScriptLink, for example, the $action is already encoded.
|
2005-09-02 12:05:48 +00:00
|
|
|
my ($status, $data) = ReadFile(GetPageFile(UrlDecode($id)));
|
2009-05-15 20:25:35 +00:00
|
|
|
# If the link points to a wanted page, we cannot make this static.
|
|
|
|
|
return $id unless $status;
|
2015-09-04 04:55:48 +03:00
|
|
|
my $hash = ParseData($data);
|
2004-10-07 00:22:38 +00:00
|
|
|
my $ext = '.html';
|
2015-09-04 04:55:48 +03:00
|
|
|
if ($hash->{text} =~ /^\#FILE ([^ \n]+ ?[^ \n]*)\n(.*)/s) {
|
2006-08-11 21:20:00 +00:00
|
|
|
%StaticMimeTypes = StaticMimeTypes() unless %StaticMimeTypes;
|
2011-10-13 23:46:21 +00:00
|
|
|
$ext = $StaticMimeTypes{"$1"};
|
2004-10-07 00:22:38 +00:00
|
|
|
$ext = '.' . $ext if $ext;
|
|
|
|
|
}
|
|
|
|
|
$StaticFiles{$id} = $id . $ext;
|
|
|
|
|
return $StaticFiles{$id};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticWriteFile {
|
2014-03-18 09:26:04 +01:00
|
|
|
my ($id, $html) = @_;
|
2004-10-07 00:22:38 +00:00
|
|
|
my $raw = GetParam('raw', 0);
|
|
|
|
|
OpenPage($id);
|
2014-03-18 11:49:28 +01:00
|
|
|
my ($mimetype, $encoding, $data) =
|
2016-06-19 13:09:02 +02:00
|
|
|
$Page{text} =~ /^\#FILE ([^ \n]+) ?([^ \n]*)\n(.*)/s;
|
|
|
|
|
my $filename = StaticFileName($id);
|
|
|
|
|
my $file = "$StaticDir/$filename";
|
2004-12-29 00:52:27 +00:00
|
|
|
if ($data) {
|
2016-06-22 14:43:28 +02:00
|
|
|
open(my $fh, '>', encode_utf8($file))
|
|
|
|
|
or ReportError(Ts('Cannot write %s', $filename));
|
2015-05-15 16:31:47 +02:00
|
|
|
StaticFile($id, $fh, $mimetype, $data);
|
2016-06-22 14:43:28 +02:00
|
|
|
close($fh);
|
2004-12-29 00:41:21 +00:00
|
|
|
} elsif ($html) {
|
2016-06-22 14:43:28 +02:00
|
|
|
open(my $fh, '>:encoding(UTF-8)', encode_utf8($file))
|
|
|
|
|
or ReportError(Ts('Cannot write %s', $filename));
|
2015-05-15 16:31:47 +02:00
|
|
|
StaticHtml($id, $fh);
|
2016-06-22 14:43:28 +02:00
|
|
|
close($fh);
|
2013-10-25 08:49:13 +02:00
|
|
|
} else {
|
|
|
|
|
print "no data for ";
|
2004-10-07 00:22:38 +00:00
|
|
|
}
|
2016-06-22 14:43:28 +02:00
|
|
|
ChangeMod(0644,"$StaticDir/$filename");
|
2004-10-07 00:22:38 +00:00
|
|
|
print $filename, $raw ? "\n" : $q->br();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticFile {
|
2015-05-15 16:31:47 +02:00
|
|
|
my ($id, $fh, $type, $data) = @_;
|
2004-10-07 00:22:38 +00:00
|
|
|
require MIME::Base64;
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh (MIME::Base64::decode($data));
|
2004-10-07 00:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticHtml {
|
2015-05-15 16:31:47 +02:00
|
|
|
my ($id, $fh) = @_; # assume open page
|
2006-10-25 11:16:24 +00:00
|
|
|
# redirect
|
|
|
|
|
if (($FreeLinks and $Page{text} =~ /^\#REDIRECT\s+\[\[$FreeLinkPattern\]\]/)
|
|
|
|
|
or ($WikiLinks and $Page{text} =~ /^\#REDIRECT\s+$LinkPattern/)) {
|
2006-10-25 11:23:44 +00:00
|
|
|
my $target = StaticFileName($1);
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh <<"EOT";
|
2006-10-25 11:16:24 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>$SiteName: $id</title>
|
|
|
|
|
<link type="text/css" rel="stylesheet" href="static.css" />
|
2006-10-25 11:30:31 +00:00
|
|
|
<meta http-equiv="refresh" content="0; url=$target">
|
2012-05-22 11:45:00 +02:00
|
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
2006-10-25 11:16:24 +00:00
|
|
|
</head>
|
|
|
|
|
<body>
|
2006-10-25 11:30:31 +00:00
|
|
|
<p>Redirected to <a href="$target">$1</a>.</p>
|
2006-10-25 11:16:24 +00:00
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
EOT
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh <<"EOT";
|
2006-10-25 11:16:24 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2004-08-31 15:05:04 +00:00
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>$SiteName: $id</title>
|
2004-08-31 15:10:19 +00:00
|
|
|
<link type="text/css" rel="stylesheet" href="static.css" />
|
2012-05-22 11:45:00 +02:00
|
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
2004-08-31 15:05:04 +00:00
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
EOT
|
2004-10-13 18:30:42 +00:00
|
|
|
my $header = '';
|
|
|
|
|
# logo
|
2004-10-08 20:53:27 +00:00
|
|
|
if ($LogoUrl) {
|
|
|
|
|
my $logo = $LogoUrl;
|
2005-03-01 16:48:01 +00:00
|
|
|
$logo =~ s|.*/||; # just the filename
|
2004-10-08 20:53:27 +00:00
|
|
|
my $alt = T('[Home]');
|
2004-10-13 18:30:42 +00:00
|
|
|
$header .= $q->img({-src=>$logo, -alt=>$alt, -class=>'logo'}) if $logo;
|
2004-10-08 20:53:27 +00:00
|
|
|
}
|
2004-10-13 18:30:42 +00:00
|
|
|
# top toolbar
|
2005-03-01 16:48:01 +00:00
|
|
|
local $UserGotoBar = ''; # only allow @UserGotoBarPages
|
2004-10-13 18:30:42 +00:00
|
|
|
my $toolbar = GetGotoBar($id);
|
|
|
|
|
$header .= $toolbar if GetParam('toplinkbar', $TopLinkBar);
|
|
|
|
|
# title
|
|
|
|
|
my $name = $id;
|
|
|
|
|
$name =~ s|_| |g;
|
|
|
|
|
$header .= $q->h1($name);
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh $q->div({-class=>'header'}, $header);
|
2004-10-13 18:30:42 +00:00
|
|
|
# sidebar, if the module is loaded
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh $q->div({-class=>'sidebar'}, PageHtml($SidebarName)) if $SidebarName;
|
2004-10-13 18:30:42 +00:00
|
|
|
# content
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh $q->div({-class=>'content'}, PageHtml($id)); # this reopens the page currently open
|
2004-10-13 18:30:42 +00:00
|
|
|
# footer
|
2004-10-13 19:01:35 +00:00
|
|
|
my $links = '';
|
2014-03-18 13:01:27 +01:00
|
|
|
if ($OpenPageName !~ /^$CommentsPrefix/ # fails if $CommentsPrefix is empty!
|
2015-03-27 03:01:01 +02:00
|
|
|
and $IndexHash{$CommentsPrefix . $OpenPageName}) { # TODO use $CommentsPattern
|
2004-10-13 19:01:35 +00:00
|
|
|
$links .= ScriptLink(UrlEncode($CommentsPrefix . $OpenPageName),
|
2005-03-01 16:48:01 +00:00
|
|
|
T('Comments on this page'));
|
2004-10-13 19:01:35 +00:00
|
|
|
}
|
|
|
|
|
if ($CommentsPrefix and $id =~ /^$CommentsPrefix(.*)/) {
|
|
|
|
|
$links .= ' | ' if $links;
|
|
|
|
|
$links .= Ts('Back to %s', GetPageLink($1, $1));
|
|
|
|
|
}
|
|
|
|
|
$links = $q->br() . $links if $links;
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh $q->div({-class=>'footer'}, $q->hr(), $toolbar,
|
2005-03-01 16:48:01 +00:00
|
|
|
$q->span({-class=>'edit'}, $links),
|
|
|
|
|
$q->span({-class=>'time'}, GetFooterTimestamp($id)));
|
2004-10-13 18:30:42 +00:00
|
|
|
# finish
|
2015-05-15 16:31:47 +02:00
|
|
|
print $fh '</body></html>';
|
2004-08-18 16:43:25 +00:00
|
|
|
}
|
2004-12-26 00:29:27 +00:00
|
|
|
|
2014-03-18 12:47:16 +01:00
|
|
|
sub StaticWriteCss {
|
|
|
|
|
my $css;
|
|
|
|
|
if ($StyleSheet) {
|
2015-10-26 01:03:42 +02:00
|
|
|
if (ref $StyleSheet) {
|
|
|
|
|
$css = join '', map { GetRaw($_) } @$StyleSheet;
|
|
|
|
|
} else {
|
|
|
|
|
$css = GetRaw($StyleSheet);
|
|
|
|
|
}
|
2014-03-18 12:47:16 +01:00
|
|
|
}
|
|
|
|
|
if (not $css and $IndexHash{$StyleSheetPage}) {
|
|
|
|
|
$css = GetPageContent($StyleSheetPage);
|
|
|
|
|
}
|
|
|
|
|
if (not $css) {
|
2015-07-21 12:40:36 +02:00
|
|
|
$css = GetRaw('https://oddmuse.org/default.css');
|
2014-03-18 12:47:16 +01:00
|
|
|
}
|
|
|
|
|
WriteStringToFile("$StaticDir/static.css", $css) if $css;
|
|
|
|
|
chmod 0644,"$StaticDir/static.css";
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*StaticFilesOldSave = \&Save;
|
|
|
|
|
*Save = \&StaticFilesNewSave;
|
2004-12-26 00:29:27 +00:00
|
|
|
|
2007-08-12 11:37:01 +00:00
|
|
|
sub StaticFilesNewSave {
|
|
|
|
|
my ($id, $new) = @_;
|
|
|
|
|
StaticFilesOldSave(@_);
|
2004-12-26 00:29:27 +00:00
|
|
|
if ($StaticAlways) {
|
|
|
|
|
# always delete
|
2007-08-12 11:37:01 +00:00
|
|
|
StaticDeleteFile($id);
|
|
|
|
|
if ($new =~ /^\#FILE / # if a file was uploaded
|
2005-03-01 16:48:01 +00:00
|
|
|
or $StaticAlways > 1) {
|
2004-12-26 00:29:27 +00:00
|
|
|
CreateDir($StaticDir);
|
|
|
|
|
StaticWriteFile($OpenPageName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*StaticOldDeletePage = \&DeletePage;
|
|
|
|
|
*DeletePage = \&StaticNewDeletePage;
|
2004-12-26 00:29:27 +00:00
|
|
|
|
|
|
|
|
sub StaticNewDeletePage {
|
|
|
|
|
my $id = shift;
|
2004-12-26 01:08:21 +00:00
|
|
|
StaticDeleteFile($id) if ($StaticAlways);
|
2004-12-26 00:29:27 +00:00
|
|
|
return StaticOldDeletePage($id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub StaticDeleteFile {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
%StaticMimeTypes = StaticMimeTypes() unless %StaticMimeTypes;
|
|
|
|
|
# we don't care if the files or $StaticDir don't exist -- just delete!
|
|
|
|
|
for my $f (map { "$StaticDir/$id.$_" } (values %StaticMimeTypes, 'html')) {
|
2016-06-15 23:21:07 +02:00
|
|
|
Unlink($f); # delete copies with different extensions
|
2004-12-26 00:29:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-12-26 01:08:21 +00:00
|
|
|
|
|
|
|
|
# override the default!
|
2004-12-26 01:39:00 +00:00
|
|
|
sub GetDownloadLink {
|
2004-12-26 01:08:21 +00:00
|
|
|
my ($name, $image, $revision, $alt) = @_;
|
|
|
|
|
$alt = $name unless $alt;
|
|
|
|
|
my $id = FreeToNormal($name);
|
|
|
|
|
AllPagesList();
|
|
|
|
|
# if the page does not exist
|
|
|
|
|
return '[' . ($image ? T('image') : T('download')) . ':' . $name
|
|
|
|
|
. ']' . GetEditLink($id, '?', 1) unless $IndexHash{$id};
|
|
|
|
|
my $action;
|
|
|
|
|
if ($revision) {
|
|
|
|
|
$action = "action=download;id=" . UrlEncode($id) . ";revision=$revision";
|
|
|
|
|
} elsif ($UsePathInfo) {
|
|
|
|
|
$action = "download/" . UrlEncode($id);
|
|
|
|
|
} else {
|
|
|
|
|
$action = "action=download;id=" . UrlEncode($id);
|
|
|
|
|
}
|
|
|
|
|
if ($image) {
|
|
|
|
|
if ($UsePathInfo and not $revision) {
|
|
|
|
|
if ($StaticAlways and $StaticUrl) {
|
2005-03-01 16:48:01 +00:00
|
|
|
my $url = $StaticUrl;
|
|
|
|
|
my $img = UrlEncode(StaticFileName($id));
|
|
|
|
|
$url =~ s/\%s/$img/g or $url .= $img;
|
|
|
|
|
$action = $url;
|
2004-12-26 01:08:21 +00:00
|
|
|
} else {
|
2005-03-01 16:48:01 +00:00
|
|
|
$action = $ScriptName . '/' . $action;
|
2004-12-26 01:08:21 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$action = $ScriptName . '?' . $action;
|
|
|
|
|
}
|
2006-08-13 23:10:49 +00:00
|
|
|
return $action if $image == 2;
|
2004-12-26 01:08:21 +00:00
|
|
|
my $result = $q->img({-src=>$action, -alt=>$alt, -class=>'upload'});
|
|
|
|
|
$result = ScriptLink(UrlEncode($id), $result, 'image') unless $id eq $OpenPageName;
|
|
|
|
|
return $result;
|
|
|
|
|
} else {
|
|
|
|
|
return ScriptLink($action, $alt, 'upload');
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-03-01 16:48:01 +00:00
|
|
|
|
|
|
|
|
# override function from Image Extension to support advanced image tags
|
2008-12-14 23:59:12 +00:00
|
|
|
sub ImageGetInternalUrl {
|
|
|
|
|
my $id = FreeToNormal(shift);
|
2005-03-01 16:48:01 +00:00
|
|
|
if ($UsePathInfo) {
|
|
|
|
|
if ($StaticAlways and $StaticUrl) {
|
|
|
|
|
my $url = $StaticUrl;
|
|
|
|
|
my $img = UrlEncode(StaticFileName($id));
|
|
|
|
|
$url =~ s/\%s/$img/g or $url .= $img;
|
|
|
|
|
return $url;
|
|
|
|
|
} else {
|
|
|
|
|
return $ScriptName . '/download/' . UrlEncode($id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ScriptName . '?action=download;id=' . UrlEncode($id);
|
|
|
|
|
}
|