Changeset 1008
- Timestamp:
- 09/03/08 00:21:02 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/StyleCatcher-2.1-dev/plugins/StyleCatcher/lib/StyleCatcher/CMS.pm
r1003 r1008 143 143 } 144 144 145 sub files_from_response { 146 my ($res) = @_; 147 148 my $stylesheet = $res->content; 149 $stylesheet =~ s!/\*.*?\*/!!gs; # strip all comments first 150 my @images = $stylesheet =~ m{ 151 \b url\( \s* # opening url() reference 152 ( [\w\.-/]+\.(?:gif|jpe?g|png|css) ) # a filename ending in an image extension 153 \s* \) # close of url() reference 154 }xmsgi; 155 156 return @images; 157 } 158 145 159 sub download_theme { 146 160 my $app = shift; … … 165 179 my $stylesheet_res = $ua->get($url); 166 180 167 # Parse out image filenames in the css and then write out the css file 168 # and thumbnails to our theme folder 169 my $stylesheet = $stylesheet_res->content; 170 $stylesheet =~ s!/\*.*?\*/!!gs; # strip all comments first 171 my @images = $stylesheet =~ m{ 172 \b url\( \s* # opening url() reference 173 ( [\w\.-/]+\.(?:gif|jpe?g|png) ) # a filename ending in an image extension 174 \s* \) # close of url() reference 175 }xmsgi; 181 my @images = files_from_response($stylesheet_res); 176 182 177 183 my $theme_path = File::Spec->catdir($themeroot, $basename); … … 186 192 187 193 # Pick up the images we parsed earlier and write them to the theme folder 188 my @thumbs = ("thumbnail.gif", "thumbnail-large.gif"); 189 IMAGE: for my $rel_url (@thumbs, @images) { 194 my %got_files; 195 my @files = ('thumbnail.gif', 'thumbnail-large.gif', @images); 196 FILE: while (my $rel_url = shift @files) { 190 197 # Is this safe to get? 191 198 my $full_url = URI->new_abs($rel_url, $theme_url); 192 next IMAGE if !$full_url; 193 next IMAGE if $full_url->as_string() !~ m{ \A \Q$theme_url\E }xms; 194 195 my $res = $ua->get($full_url->as_string()); 196 197 # Skip images that don't download; we were accidentally doing so already. 198 next IMAGE if !$res->is_success(); 199 next FILE if !$full_url; 200 my $url = $full_url->as_string(); 201 next FILE if $url !~ m{ \A \Q$theme_url\E }xms; 202 203 next FILE if $got_files{$url}; 204 $got_files{$url} = 1; 205 my $res = $ua->get($url); 206 207 # Skip files that don't download; we were accidentally doing so already. 208 next FILE if !$res->is_success(); 199 209 200 210 my $canon_rel_url = URI->new($rel_url)->rel($theme_url);
