Skip to content

Commit

Permalink
Item11189: Better fix: factorise the image testing. Should still put …
Browse files Browse the repository at this point in the history
…the suffix as a configure parameter

git-svn-id: http://svn.foswiki.org/trunk@12814 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
OlivierRaginel authored and OlivierRaginel committed Oct 20, 2011
1 parent eba5a8e commit d35a32e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions core/lib/Foswiki/Render.pm
Expand Up @@ -799,10 +799,8 @@ sub _handleSquareBracketedLink {

# [[$link][$text]]
$hasExplicitLinkLabel = 1;
if ( $text =~ /^[^?]*\.(gif|jpg|jpeg|png)$/i ) {
my $filename = $text;
$filename =~ s@.*/@@;
$text = CGI::img( { src => $text, alt => $filename } );
if ( my $img = $this->_isImageLink($text) ) {
$text = $img;
}
else {
$text = _escapeAutoLinks($text);
Expand All @@ -829,7 +827,7 @@ sub _handleSquareBracketedLink {
$text = _escapeAutoLinks($candidateText);
}
}
return _externalLink( $this, $link, $text );
return $this->_externalLink( $link, $text );
}

# Extract '?params'
Expand Down Expand Up @@ -890,16 +888,26 @@ sub _handleSquareBracketedLink {
$hasExplicitLinkLabel, $params );
}

# Check if text is an image # (as indicated by the file type)
# return an img tag, otherwise nothing
sub _isImageLink {
my ( $this, $url ) = @_;

if ( $url =~ /^[^?]*\.(?:gif|jpg|jpeg|png)$/i ) {
my $filename = $url;
$filename =~ s@.*/@@;
return CGI::img( { src => $url, alt => $filename } );
}
return;
}

# Handle an external link typed directly into text. If it's an image
# (as indicated by the file type), and no text is specified, then use
# an img tag, otherwise generate a link.
# and no text is specified, then use an img tag, otherwise generate a link.
sub _externalLink {
my ( $this, $url, $text ) = @_;

if ( $url =~ /^[^?]*\.(gif|jpg|jpeg|png)$/i && !$text ) {
my $filename = $url;
$filename =~ s@.*/([^/]*)@$1@go;
return CGI::img( { src => $url, alt => $filename } );
if ( !$text && ( my $img = $this->_isImageLink($url) ) ) {
return $img;
}
my $opt = '';
if ( $url =~ /^mailto:/i ) {
Expand Down

0 comments on commit d35a32e

Please sign in to comment.