Changeset 985

Show
Ignore:
Timestamp:
08/26/08 23:45:41 (3 months ago)
Author:
mpaschal
Message:

Allow slashes in url() references, since we take care with the URL later
Build the base theme URL correctly
(Slice sequences are sequences first and slices second, no matter how perfectly reasonable a slice 0..-2 actually is)
Make any additional path segments that might be included in an image path

Files:

Legend:

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

    r984 r985  
    151151        or return; 
    152152 
    153     # Break up the css url in to a couple useful pieces 
    154153    my @url = split( /\//, $url ); 
    155  
    156     my $theme_url = join(q{/}, @url[0..-2]) . '/'; 
    157     my ($basename, $extension) = split( /\./, $url[-1] ); 
     154    my $stylesheet_filename = pop @url; 
     155    my $theme_url = join(q{/}, @url) . '/'; 
     156 
     157    my ($basename, $extension) = split /\./, $stylesheet_filename; 
    158158    if ($basename eq 'screen' || $basename eq 'style') { 
    159         $basename = $url[-2]; 
     159        $basename = $url[-1]; 
    160160    } 
    161161 
     
    168168    $stylesheet =~ s!/\*.*?\*/!!gs;    # strip all comments first 
    169169    my @images = $stylesheet =~ m{ 
    170         \b url\( \s*                     # opening url() reference 
    171         ( [\w\.-]+\.(?:gif|jpe?g|png) )  # a filename ending in an image extension 
    172         \s* \)                           # close of url() reference 
     170        \b url\( \s*                      # opening url() reference 
     171        ( [\w\.-/]+\.(?:gif|jpe?g|png) )  # a filename ending in an image extension 
     172        \s* \)                            # close of url() reference 
    173173    }xmsgi; 
    174174 
     
    198198        my $canon_rel_url = URI->new($rel_url)->rel($theme_url); 
    199199        my @image_path = split /\//, $canon_rel_url->as_string(); 
    200         my $image_filename = File::Spec->catfile($theme_path, @image_path); 
    201         $filemgr->put_data($res->content, $image_filename, 'upload') 
     200        my $image_filename = pop @image_path; 
     201 
     202        my $image_path = File::Spec->catdir($theme_path, @image_path);         
     203        if (!$filemgr->exists($image_path) && !$filemgr->mkpath($image_path)) { 
     204            my $error = $app->translate("Could not create [_1] folder - Check that your 'themes' folder is webserver-writable.", 
     205                $basename); 
     206            return $app->json_error($error); 
     207        } 
     208 
     209        my $image_full_path = File::Spec->catfile($image_path, $image_filename); 
     210        $filemgr->put_data($res->content, $image_full_path, 'upload') 
    202211          or return $app->json_error( $filemgr->errstr ); 
    203212    }