Skip to content

Commit

Permalink
Item13151: work around ways to get abs urls
Browse files Browse the repository at this point in the history
also:
- support extracting thumbnails from movies (mp4,mov,m4v,mpeg,mpg and wmv)
  • Loading branch information
MichaelDaum committed Dec 16, 2014
1 parent 510a48c commit bfb6ecd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
8 changes: 4 additions & 4 deletions data/Sandbox/ImagePluginTest.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1409847733" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1418735227" format="1.1" version="1"}%
---+!! Exhaustive Test Page for !ImagePlugin
%TOC%

Expand Down Expand Up @@ -87,6 +87,6 @@ colon before "image" in an intra-wiki link, like this
%IMAGE{":STS-32_crew.jpg|STS-32 crew"}%


%META:FILEATTACHMENT{name="Westminstpalace.jpg" attr="h" comment="" date="1409847733" path="Westminstpalace.jpg" size="19790" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Tst.png" attr="h" comment="" date="1409847733" path="Tst.png" size="499" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="STS-32_crew.jpg" attr="h" comment="" date="1409847733" path="STS-32_crew.jpg" size="49583" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Westminstpalace.jpg" attr="h" comment="" date="1418735227" path="Westminstpalace.jpg" size="19790" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Tst.png" attr="h" comment="" date="1418735227" path="Tst.png" size="499" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="STS-32_crew.jpg" attr="h" comment="" date="1418735227" path="STS-32_crew.jpg" size="49583" user="ProjectContributor" version="1"}%
8 changes: 5 additions & 3 deletions data/System/ImagePlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1409847733" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1418735227" format="1.1" version="1"}%
---+!! <nop>%TOPIC%
%TOC%

Expand Down Expand Up @@ -227,6 +227,8 @@ $Foswiki::cfg{ImagePlugin}{Mode} = 'Image::Magick';
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 16 Dec 2014 | work around call to unofficial internal api to get absolute pub urls;\
support extracting thumbnails from movies (mp4,mov,m4v,mpeg,mpg and wmv) |
| 17 Sep 2014 | added feature to convert inline image data to proper attachments |
| 08 Sep 2014 | added =rotate= parameter |
| 04 Sep 2014 | implemented =frame= and =layer= parameter for thumbnail extraction from videos, animations and layered images |
Expand Down Expand Up @@ -300,5 +302,5 @@ $Foswiki::cfg{ImagePlugin}{Mode} = 'Image::Magick';
| Support: | Foswiki:Support/%TOPIC% |


%META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" comment="" date="1409847733" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attachment="logo.gif" attr="h" date="1409847733" path="http://www.google.com/intl/en_ALL/images/logo.gif" size="8558" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" comment="" date="1418735227" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attachment="logo.gif" attr="h" date="1418735227" path="http://www.google.com/intl/en_ALL/images/logo.gif" size="8558" user="ProjectContributor" version="1"}%
19 changes: 15 additions & 4 deletions lib/Foswiki/Plugins/ImagePlugin.pm
Expand Up @@ -29,8 +29,8 @@ use warnings;

our $imageCore;

our $VERSION = '5.00';
our $RELEASE = '5.00';
our $VERSION = '6.00';
our $RELEASE = '6.00';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Image and thumbnail services to display and alignment images using an easy syntax';

Expand Down Expand Up @@ -163,8 +163,7 @@ sub renderExternalLink {
my $href = '';
my $title = $url;

my $session = $Foswiki::Plugins::SESSION;
my $pubUrl = $session->getPubUrl(1);
my $pubUrl = getPubUrl();

# skip "external links" to self and to any other excluded url
my $excludePattern = $Foswiki::cfg{ImagePlugin}{Exclude};
Expand Down Expand Up @@ -193,5 +192,17 @@ sub renderExternalLink {
return $prefix.$url;
}

sub getPubUrl {
my $session = $Foswiki::Plugins::SESSION;

if ($session->can("getPubUrl")) {
# pre 1.2
return $session->getPubUrl(1);
}

# post 1.2
return Foswiki::Func::getPubUrlPath(absolute=>1);
}

1;

14 changes: 11 additions & 3 deletions lib/Foswiki/Plugins/ImagePlugin/Core.pm
Expand Up @@ -396,6 +396,14 @@ sub handleIMAGE {
my $thumbFileUrl = $pubUrl . '/' . $imgWeb . '/' . $imgTopic . '/' . $imgInfo->{file};
$thumbFileUrl = urlEncode($thumbFileUrl);

my $baseTopic = $this->{session}{topicName};
my $absolute = ($context->{'command_line'} || $context->{'rss'} || $context->{'absolute_urls'} || $baseTopic =~ /^(WebRss|WebAtom)/);

if ($absolute) {
$params->{href} = $this->{session}{urlHost} . $params->{href} unless $params->{href} =~ /^[a-z]+:/;
$thumbFileUrl = $this->{session}{urlHost} . $thumbFileUrl unless $thumbFileUrl =~ /^[a-z]+:/;
}

$result =~ s/\$href/$params->{href}/g;
$result =~ s/\$src/$thumbFileUrl/g;
$result =~ s/\$thumbfile/$imgInfo->{file}/g;
Expand Down Expand Up @@ -497,7 +505,7 @@ sub processImage {
imgPath => undef,
);

if ($size || $width || $height || $rotate || $doRefresh || $imgFile =~ /\.(svg|tiff?|xcf|psd)$/ || $output) {
if ($size || $width || $height || $rotate || $doRefresh || $imgFile =~ /\.(svgz?|tiff?|xcf|psd)$/ || $output) {
if (!$size) {
if ($width || $height) {
$size = $width . 'x' . $height;
Expand All @@ -520,7 +528,7 @@ sub processImage {
} elsif (defined $params->{frame}) {
$frame = $params->{frame};
} else {
$frame = '0' if $imgInfo{origImgPath} =~ /\.gif$/;
$frame = '0' if $imgInfo{origImgPath} =~ /\.gif|mp4|mov|m4v|mpeg|mpg|wmv$/i;
}
if (defined $frame) {
$frame =~ s/^.*?(\d+).*$/$1/g;
Expand Down Expand Up @@ -932,7 +940,7 @@ sub getImageFile {
my $digest = Digest::MD5::md5_hex($size, $zoom, $crop, $rotate, $frame, $fileSize);

# force conversion of some non-webby image formats
$imgFile =~ s/\.(svg|tiff?|xcf|psd)$/\.png/g;
$imgFile =~ s/\.(svgz?|tiff?|xcf|psd)$/\.png/g;

# switch manually specified output format
if ($output && $imgFile =~ /^(.+)\.([^\.]+)$/) {
Expand Down
1 change: 1 addition & 0 deletions pub/System/ImagePlugin/style.uncompressed.css
Expand Up @@ -63,6 +63,7 @@ a:hover.imageHref {
float:left;
margin:0 1em 1em 0;
}
.imagePlain_center,
.imageThumb_center,
.imageSimple_center,
.imageFrame_center,
Expand Down

0 comments on commit bfb6ecd

Please sign in to comment.