- Timestamp:
- 07/18/08 18:30:37 (17 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/release-41/plugins/StyleCatcher/lib/StyleCatcher/CMS.pm
r2743 r2812 9 9 use strict; 10 10 use File::Basename qw(basename); 11 use MT::Util qw( caturl ); 11 12 12 13 our $DEFAULT_STYLE_LIBRARY; … … 155 156 $app->validate_magic or return $app->json_error($app->translate("Invalid request")); 156 157 return $app->json_error($app->translate("Invalid request")) 157 unless $blog_id && $url && $tmpl;158 unless $blog_id && $url && $tmpl; 158 159 159 160 my $static_path = $app->static_file_path; … … 162 163 } 163 164 164 my $themeroot = 165 File::Spec->catdir( $static_path, 'support', 'themes' ); 165 my $themeroot = File::Spec->catdir( $static_path, 'support', 'themes' ); 166 166 my $webthemeroot = $app->static_path . 'support/themes/'; 167 167 my $mtthemeroot = $app->static_path . 'themes/'; … … 174 174 # yonder... 175 175 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"; 177 178 178 179 if ( $url !~ m/^(\Q$webthemeroot\E|\Q$mtthemeroot\E)/ ) { 179 180 my $new_url = ''; 180 181 181 for (0..(scalar(@url)-2)) { 182 182 $new_url .= $url[$_] . '/'; 183 183 } 184 print STDERR "Processing for application: $url\n"; 184 185 my ( $basename, $extension ) = split( /\./, $url[-1] ); 185 186 if ($basename eq 'screen') { … … 206 207 $content =~ s!/\*.*?\*/!!gs; # strip all comments first 207 208 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; 209 210 $filemgr->mkpath( File::Spec->catdir( $themeroot, $basename ) ) 210 211 or return $app->json_error( … … 233 234 } 234 235 235 # Pick up the images we parsed earlier and write them to the theme folder236 # Pick up the images we parsed earlier and write them to the theme folder 236 237 for my $image_url (@images) { 237 238 my $image_request = … … 253 254 $url = "$webthemeroot$basename/$basename.css"; 254 255 } 256 print STDERR "url: $url\n"; 255 257 256 258 my $blog = MT->model('blog')->load($blog_id) … … 267 269 my $footer = '/* end StyleCatcher imports */'; 268 270 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; 270 272 $styles .= "\@import url($url);\n"; 271 273 $styles .= $footer; 272 print STDERR "styles=$styles\n";273 274 274 275 if ($template_text =~ s/\Q$header\E.*\Q$footer\E/$styles/s) { … … 426 427 my $data = {}; 427 428 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) 429 430 # Pick up the file (html with <link>s or a css file with metadata) 430 431 my $user_agent = $app->new_ua; … … 593 594 return unless $stylesheet; 594 595 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) 596 597 $theme = $url; 597 598 # discard any generic 'screen.css' filename … … 602 603 $new_url .= $url[$_] . '/'; 603 604 } 605 # note: this stripped off the css file and left a path only 604 606 } 605 607 else { … … 651 653 # Trim me white space, yarr 652 654 for (@comments) { 653 654 655 # TBD: strip any "risky" content; we don't want any 655 656 # XSS in this content. … … 663 664 } 664 665 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 665 680 my $thumbnail_link; 666 681 $thumbnail_link = $new_url . 'thumbnail.gif'; … … 669 684 670 685 require MT::Util; 686 my $name = delete $metadata{'name'} || delete $metadata{'theme name'}; 687 print STDERR "name = $name\n"; 671 688 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)', 675 693 url => $url, 676 694 imageSmall => $thumbnail_link, 677 695 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 || '', 683 701 tags => $tags, 684 702 blogs => [], 685 703 }; 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)); 686 711 $data; 687 712 }
