Changeset 983

Show
Ignore:
Timestamp:
08/26/08 21:42:06 (3 months ago)
Author:
mpaschal
Message:

If thumbnails are not specified in the theme metadata, look for the files, and use a default 'no thumbnail' thumbnail if none exist

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/StyleCatcher-2.1-dev/plugins/StyleCatcher/lib/StyleCatcher/CMS.pm

    r981 r983  
    581581    my $new_url; 
    582582    my $themeroot; 
    583     if ( $url =~ m/^https?:/i ) { 
    584  
     583    my $url_is_web = $url =~ m{ \A https?: }xms ? 1 : 0; 
     584    if ($url_is_web) { 
    585585        # Pick up the css file 
    586586        my $user_agent  = $app->new_ua; 
     
    660660    } 
    661661 
    662     my $thumbnail_link; 
    663     $thumbnail_link = $new_url . 'thumbnail.gif'; 
    664     my $thumbnail_large_link; 
    665     $thumbnail_large_link = $new_url . 'thumbnail-large.gif'; 
     662    my %thumbnails; 
     663    THUMB: for my $thumb (qw( thumbnail thumbnail_large )) { 
     664        $thumbnails{$thumb} = $metadata{$thumb}; 
     665        next THUMB if $thumbnails{$thumb}; 
     666         
     667        my $thumb_filename = $thumb; 
     668        $thumb_filename =~ tr/_/-/; 
     669        $thumb_filename .= '.gif'; 
     670 
     671        if ($url_is_web) { 
     672            my $thumb_url = $new_url . $thumb_filename; 
     673 
     674            my $user_agent  = $app->new_ua; 
     675            my $css_request = HTTP::Request->new( HEAD => $thumb_url ); 
     676            my $response    = $user_agent->request($css_request); 
     677            if ($response->is_success()) { 
     678                $thumbnails{$thumb} = $thumb_url; 
     679            } 
     680        } 
     681        else { 
     682            my $thumb_path = File::Spec->catfile($themeroot,  
     683                $thumb_filename); 
     684            if (-e $thumb_path) { 
     685                $thumbnails{$thumb} = $new_url . $thumb_filename; 
     686            } 
     687        } 
     688         
     689        $thumbnails{$thumb} ||= $app->static_path . 'plugins/StyleCatcher/' 
     690            . 'images/' . $thumb_filename; 
     691    } 
    666692 
    667693    my %field_map = ( 
     
    681707        title        => $metadata{title} || '(Untitled)', 
    682708        url          => $url, 
    683         imageSmall   => $thumbnail_link
    684         imageBig     => $thumbnail_large_link
     709        imageSmall   => $thumbnails{thumbnail}
     710        imageBig     => $thumbnails{thumbnail_large}
    685711        layouts      => $metadata{layouts} || '', 
    686712        sort         => $metadata{name} || $theme || q{},