Changeset 12814


Ignore:
Timestamp:
10/20/11 15:21:41 (19 months ago)
Author:
OlivierRaginel
Message:

Item11189: Better fix: factorise the image testing. Should still put the suffix as a configure parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/Foswiki/Render.pm

    r12813 r12814  
    800800        # [[$link][$text]] 
    801801        $hasExplicitLinkLabel = 1; 
    802         if ( $text =~ /^[^?]*\.(gif|jpg|jpeg|png)$/i ) { 
    803             my $filename = $text; 
    804             $filename =~ s@.*/@@; 
    805             $text = CGI::img( { src => $text, alt => $filename } ); 
     802        if ( my $img = $this->_isImageLink($text) ) { 
     803            $text = $img; 
    806804        } 
    807805        else { 
     
    830828            } 
    831829        } 
    832         return _externalLink( $this, $link, $text ); 
     830        return $this->_externalLink( $link, $text ); 
    833831    } 
    834832 
     
    891889} 
    892890 
     891# Check if text is an image # (as indicated by the file type) 
     892# return an img tag, otherwise nothing 
     893sub _isImageLink { 
     894    my ( $this, $url ) = @_; 
     895 
     896    if ( $url =~ /^[^?]*\.(?:gif|jpg|jpeg|png)$/i ) { 
     897        my $filename = $url; 
     898        $filename =~ s@.*/@@; 
     899        return CGI::img( { src => $url, alt => $filename } ); 
     900    } 
     901    return; 
     902} 
     903 
    893904# Handle an external link typed directly into text. If it's an image 
    894 # (as indicated by the file type), and no text is specified, then use 
    895 # an img tag, otherwise generate a link. 
     905# and no text is specified, then use an img tag, otherwise generate a link. 
    896906sub _externalLink { 
    897907    my ( $this, $url, $text ) = @_; 
    898908 
    899     if ( $url =~ /^[^?]*\.(gif|jpg|jpeg|png)$/i && !$text ) { 
    900         my $filename = $url; 
    901         $filename =~ s@.*/([^/]*)@$1@go; 
    902         return CGI::img( { src => $url, alt => $filename } ); 
     909    if ( !$text && ( my $img = $this->_isImageLink($url) ) ) { 
     910        return $img; 
    903911    } 
    904912    my $opt = ''; 
Note: See TracChangeset for help on using the changeset viewer.