2004-05-31 00:29:07 +00:00
|
|
|
# Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
|
|
|
|
|
#
|
|
|
|
|
# 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 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the
|
|
|
|
|
# Free Software Foundation, Inc.
|
|
|
|
|
# 59 Temple Place, Suite 330
|
|
|
|
|
# Boston, MA 02111-1307 USA
|
|
|
|
|
|
2005-03-01 16:48:01 +00:00
|
|
|
$ModulesDescription .= '<p>$Id: image.pl,v 1.15 2005/03/01 16:48:01 sblatt Exp $</p>';
|
2004-05-31 00:29:07 +00:00
|
|
|
|
2004-06-19 19:10:31 +00:00
|
|
|
use vars qw($ImageUrlPath);
|
|
|
|
|
|
2005-03-01 16:48:01 +00:00
|
|
|
$ImageUrlPath = '/images'; # URL where the images are to be found
|
2004-06-19 19:10:31 +00:00
|
|
|
|
|
|
|
|
push(@MyRules, \&ImageSupportRule);
|
2004-05-31 00:29:07 +00:00
|
|
|
|
|
|
|
|
# [[image/class:page name|alt text|target]]
|
|
|
|
|
|
|
|
|
|
sub ImageSupportRule {
|
2004-06-17 09:48:52 +00:00
|
|
|
my $result = undef;
|
2004-09-15 22:55:53 +00:00
|
|
|
if (m!\G\[\[image(/[a-z]+)?( external)?:($FreeLinkPattern|$FullUrlPattern)(\|[^]|]+)?(\|($FreeLinkPattern|$FullUrlPattern))?\]\]!gc) {
|
2004-05-31 01:08:17 +00:00
|
|
|
my $oldpos = pos;
|
2004-05-31 01:29:59 +00:00
|
|
|
my $class = 'image';
|
2004-05-31 01:21:25 +00:00
|
|
|
$class .= ' ' . substr($1, 1) if $1;
|
2004-06-19 19:10:31 +00:00
|
|
|
my $external = $2;
|
|
|
|
|
my $name = $3;
|
2004-09-15 22:55:53 +00:00
|
|
|
my $alt = $6 ? substr($6, 1) : T("image: %s", $name);
|
|
|
|
|
my $link = $7 ? substr($7, 1) : '';
|
2004-05-31 00:29:07 +00:00
|
|
|
my $id = FreeToNormal($name);
|
2004-09-15 22:55:53 +00:00
|
|
|
# link to the image if no link was given
|
2004-06-19 19:29:15 +00:00
|
|
|
if (not $link) {
|
|
|
|
|
if ($external) {
|
2005-03-01 16:48:01 +00:00
|
|
|
if ($name =~ /$FullUrlPattern/) {
|
|
|
|
|
$link = $name;
|
|
|
|
|
} else {
|
|
|
|
|
$link = $ImageUrlPath . '/' . UrlEncode($id);
|
|
|
|
|
}
|
2004-06-19 19:29:15 +00:00
|
|
|
} else {
|
2005-03-01 16:48:01 +00:00
|
|
|
$link = UrlEncode($id);
|
2004-06-19 19:29:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2004-05-31 01:29:59 +00:00
|
|
|
if ($link =~ /$FullUrlPattern/) {
|
|
|
|
|
$link = $1;
|
|
|
|
|
$class .= ' outside';
|
|
|
|
|
} else {
|
2004-06-19 19:34:48 +00:00
|
|
|
if (substr($link, 0, 1) eq '/') {
|
2005-03-01 16:48:01 +00:00
|
|
|
# do nothing -- relative URL on the same server
|
2004-06-19 19:34:48 +00:00
|
|
|
} elsif ($UsePathInfo and !$Monolithic) {
|
2005-03-01 16:48:01 +00:00
|
|
|
$link = $ScriptName . '/' . $link;
|
2004-05-31 01:29:59 +00:00
|
|
|
} elsif ($Monolithic) {
|
2005-03-01 16:48:01 +00:00
|
|
|
$link = '#' . $link;
|
2004-05-31 00:29:07 +00:00
|
|
|
} else {
|
2005-03-01 16:48:01 +00:00
|
|
|
$link = $ScriptName . '?' . $link;
|
2004-05-31 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my $src;
|
2004-06-19 19:10:31 +00:00
|
|
|
if ($external) {
|
2004-09-15 22:55:53 +00:00
|
|
|
if ($name =~ /$FullUrlPattern/) {
|
2005-03-01 16:48:01 +00:00
|
|
|
$src = $name;
|
2004-09-15 22:55:53 +00:00
|
|
|
} else {
|
2005-03-01 16:48:01 +00:00
|
|
|
$src = $ImageUrlPath . '/' . UrlEncode($id);
|
2004-09-15 22:55:53 +00:00
|
|
|
}
|
2004-05-31 00:29:07 +00:00
|
|
|
} else {
|
2005-03-01 16:48:01 +00:00
|
|
|
$src = ImageGetInternalUrl($id);
|
2004-05-31 00:29:07 +00:00
|
|
|
}
|
2004-06-19 20:30:21 +00:00
|
|
|
$result = $q->img({-src=>$src, -alt=>$alt, -title=>$alt, -class=>'upload'});
|
2004-05-31 01:29:59 +00:00
|
|
|
$result = $q->a({-href=>$link, -class=>$class}, $result);
|
2004-05-31 01:08:17 +00:00
|
|
|
pos = $oldpos;
|
2004-05-31 00:29:07 +00:00
|
|
|
}
|
2004-05-31 01:08:17 +00:00
|
|
|
return $result;
|
2004-05-31 00:29:07 +00:00
|
|
|
}
|
2005-03-01 16:48:01 +00:00
|
|
|
|
|
|
|
|
# split off to support overriding from Static Extension
|
|
|
|
|
sub ImageGetInternalUrl {
|
|
|
|
|
my $id = shift;
|
|
|
|
|
if ($UsePathInfo) {
|
|
|
|
|
return $ScriptName . "/download/" . UrlEncode($id);
|
|
|
|
|
}
|
|
|
|
|
return $ScriptName . "?action=download;id=" . UrlEncode($id);
|
|
|
|
|
}
|