Show
Ignore:
Timestamp:
07/18/08 18:30:37 (17 months ago)
Author:
breese
Message:

fixed bug 80518 - finalized the upgrade widget copy

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-41/plugins/StyleCatcher/lib/StyleCatcher/CMS.pm

    r2743 r2812  
    99use strict; 
    1010use File::Basename qw(basename); 
     11use MT::Util qw( caturl ); 
    1112 
    1213our $DEFAULT_STYLE_LIBRARY; 
     
    155156    $app->validate_magic or return $app->json_error($app->translate("Invalid request")); 
    156157    return $app->json_error($app->translate("Invalid request")) 
    157       unless $blog_id && $url && $tmpl; 
     158        unless $blog_id && $url && $tmpl; 
    158159 
    159160    my $static_path = $app->static_file_path; 
     
    162163    } 
    163164 
    164     my $themeroot = 
    165       File::Spec->catdir( $static_path, 'support', 'themes' ); 
     165    my $themeroot =  File::Spec->catdir( $static_path, 'support', 'themes' ); 
    166166    my $webthemeroot = $app->static_path . 'support/themes/'; 
    167167    my $mtthemeroot  = $app->static_path . 'themes/'; 
     
    174174    # yonder... 
    175175    my $filemgr = file_mgr() 
    176       or return $app->json_error( MT::FileMgr->errstr ); 
     176        or return $app->json_error( MT::FileMgr->errstr ); 
     177    print STDERR "Applying theme... ($url)\n"; 
    177178 
    178179    if ( $url !~ m/^(\Q$webthemeroot\E|\Q$mtthemeroot\E)/ ) { 
    179180        my $new_url = ''; 
    180  
    181181        for (0..(scalar(@url)-2)) { 
    182182            $new_url .= $url[$_] . '/'; 
    183183        } 
     184        print STDERR "Processing for application: $url\n"; 
    184185        my ( $basename, $extension ) = split( /\./, $url[-1] ); 
    185186        if ($basename eq 'screen') { 
     
    206207        $content =~ s!/\*.*?\*/!!gs;    # strip all comments first 
    207208        my @images = $content =~ 
    208           m/\b(?:url\(\s*)([a-zA-Z0-9_.-]+\.(?:gif|jpe?g|png))(?:\s*?\))/gi; 
     209          m/\b(?:url\(\s*)([a-zA-Z0-9_.-]+\.(?:gif|jpe?g|png|css))(?:\s*?\))/gi; 
    209210        $filemgr->mkpath( File::Spec->catdir( $themeroot, $basename ) ) 
    210211          or return $app->json_error( 
     
    233234        } 
    234235 
    235        # Pick up the images we parsed earlier and write them to the theme folder 
     236        # Pick up the images we parsed earlier and write them to the theme folder 
    236237        for my $image_url (@images) { 
    237238            my $image_request = 
     
    253254        $url = "$webthemeroot$basename/$basename.css"; 
    254255    } 
     256    print STDERR "url: $url\n"; 
    255257     
    256258    my $blog = MT->model('blog')->load($blog_id)     
     
    267269    my $footer = '/* end StyleCatcher imports */'; 
    268270    my $styles = $header . "\n"; 
    269     $styles .= "\@import url(".File::Spec->catfile($app->static_path, $base_css).");\n" if $base_css; 
     271    $styles .= "\@import url(".caturl($app->static_path, $base_css).");\n" if $base_css; 
    270272    $styles .= "\@import url($url);\n"; 
    271273    $styles .= $footer; 
    272     print STDERR "styles=$styles\n"; 
    273274 
    274275    if ($template_text =~ s/\Q$header\E.*\Q$footer\E/$styles/s) { 
     
    426427    my $data    = {}; 
    427428 
    428   # If we have a url then we're specifying a specific theme (css) or repo (html) 
     429    # If we have a url then we're specifying a specific theme (css) or repo (html) 
    429430    # Pick up the file (html with <link>s or a css file with metadata) 
    430431    my $user_agent = $app->new_ua; 
     
    593594        return unless $stylesheet; 
    594595 
    595 # Break up the css url in to a couple useful pieces (generalize and break me out) 
     596        # Break up the css url in to a couple useful pieces (generalize and break me out) 
    596597        $theme = $url; 
    597598        # discard any generic 'screen.css' filename 
     
    602603            $new_url .= $url[$_] . '/'; 
    603604        } 
     605        # note: this stripped off the css file and left a path only 
    604606    } 
    605607    else { 
     
    651653    # Trim me white space, yarr 
    652654    for (@comments) { 
    653  
    654655        # TBD: strip any "risky" content; we don't want any 
    655656        # XSS in this content. 
     
    663664    } 
    664665 
     666#    for my $line (@comments) { 
     667#        # TBD: strip any "risky" content; we don't want any 
     668#        # XSS in this content. 
     669#        # Strip any null bytes 
     670#        $line =~ tr/\x00//d; 
     671#        $line =~ s/^\s+|\s+$//g; 
     672#       if ($line =~ m{ \A (\w+) : \s* (.*) \z }xmsg) { 
     673#           my ( $key, $value ) = ($1, $2); 
     674#           print STDERR "$key => $value\n";# if (lc $key eq 'theme name' || lc $key eq 'name'); 
     675#           next if !$value; 
     676#           $metadata{ lc $key } = $value; 
     677#       } 
     678#    } 
     679 
    665680    my $thumbnail_link; 
    666681    $thumbnail_link = $new_url . 'thumbnail.gif'; 
     
    669684 
    670685    require MT::Util; 
     686    my $name = delete $metadata{'name'} || delete $metadata{'theme name'}; 
     687    print STDERR "name = $name\n"; 
    671688    my $data = { 
    672         name        => $theme, 
    673         description => $metadata{description} || '', 
    674         title       => $metadata{name} || '(Untitled)', 
     689#        name        => $theme, 
     690        name        => $name, 
     691#        description => $metadata{'description'} || $metadata{'description'} || '', 
     692        title       => $name || '(Untitled)', 
    675693        url         => $url, 
    676694        imageSmall  => $thumbnail_link, 
    677695        imageBig    => $thumbnail_large_link, 
    678         author      => $metadata{designer} || $metadata{author} || '', 
    679         author_url  => $metadata{designer_url} || $metadata{author_url} || '', 
    680         author_affiliation => $metadata{author_affiliation} || '', 
    681         layouts            => $metadata{layouts} || '', 
    682         'sort'             => $metadata{name} || '', 
     696        author      => delete $metadata{'designer'} || delete $metadata{'author'} || '', 
     697        author_url  => delete $metadata{'designer_url'} || delete $metadata{'author_url'} || delete $metadata{'author uri'} || '', 
     698#        author_affiliation => $metadata{'author_affiliation'} || '', 
     699#        layouts            => $metadata{'layouts'} || '', 
     700        'sort'             => $name || '', 
    683701        tags               => $tags, 
    684702        blogs              => [], 
    685703    }; 
     704    for my $field (qw( author_affiliation layouts description )) { 
     705        $data->{$field} = delete $metadata{$field} || ''; 
     706    } 
     707    # Toss in all the other metadata too. 
     708    @$data{keys %metadata} = values %metadata; 
     709    require Data::Dumper; 
     710    MT->log('YAY THEME DATA: ' . Data::Dumper::Dumper($data)); 
    686711    $data; 
    687712}