Changeset 9067


Ignore:
Timestamp:
2005-02-16T16:26:34+13:00 (19 years ago)
Author:
kjdon
Message:

moved smart blocking stuff in htmlplug metadata_read into basplug metadata read. htmlplug now just needs to implement store_block_files. basplug smart block will block a cover image if -cover_images is on. Converttoplug store_block_files needs to call the basplug default one (do nothing) cos it doesn't want to use the html specific one. Image plug needs to implement store_cover_image to do nothing cos it doesn'tmake sense

Location:
trunk/gsdl/perllib/plugins
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/BasPlug.pm

    r8915 r9067  
    6969    'type' => "regexp",
    7070    'deft' => "",
     71    'reqd' => "no" },
     72      { 'name' => "smart_block",
     73    'desc' => "{BasPlug.smart_block}",
     74    'type' => "flag",
    7175    'reqd' => "no" },
    7276      { 'name' => "associate_ext",
     
    428432}
    429433
     434# default implementation is to do nothing.
     435sub store_block_files
     436{
     437    my $self =shift (@_);
     438    my ($filename) = @_;
     439    return;
     440}
     441
     442#default implementation is to block a file with same name as this, but extension jpg or JPG, if cover_images is on.
     443sub block_cover_image
     444{
     445    my $self =shift (@_);
     446    my ($filename) = @_;
     447    if ($self->{'cover_image'}) {
     448    my $coverfile = $filename;
     449    $coverfile =~ s/\.[^\\\/\.]+$/\.jpg/;
     450    if (!-e $coverfile) {
     451        $coverfile =~ s/jpg$/JPG/;
     452    }   
     453    if (-e $coverfile) {
     454        $self->{'file_blocks'}->{$coverfile} = 1;
     455    }
     456    }
     457
     458    return;
     459}
     460   
    430461sub metadata_read {
    431462    my $self = shift (@_); 
    432463    my ($pluginfo, $base_dir, $file, $metadata, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli) = @_;
    433 
    434464    # Keep track of filenames with same root but different extensions
    435     # Used to support -assoicate_ext
     465    # Used to support -associate_ext
    436466
    437467    my $associate_ext = $self->{'associate_ext'};
     
    460490    }
    461491    }
    462 
    463     return undef;
     492   
     493    # now check whether we are actually processing this
     494    my $filename = $file;
     495    $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
     496    if ($self->{'process_exp'} eq "" || $filename !~ /$self->{'process_exp'}/ || !-f $filename) {
     497    return undef; # can't recognise
     498    }
     499
     500    # do smart blocking if appropriate
     501    if (defined $self->{'smart_block'}) {
     502    $self->block_cover_image($filename);
     503    $self->store_block_files($filename);
     504    }
     505       
     506    return 1;
    464507}
    465508
  • trunk/gsdl/perllib/plugins/ConvertToPlug.pm

    r9046 r9067  
    151151
    152152# Go straight to BasPlug and avoid the special case implemented by HTMLPlug
    153 sub metadata_read {
    154     return BasPlug::metadata_read(@_);
     153sub store_block_files {
     154    return BasPlug::store_block_files(@_);
    155155}
    156156
  • trunk/gsdl/perllib/plugins/HTMLPlug.pm

    r9057 r9067  
    9191      { 'name' => "description_tags",
    9292    'desc' => "{HTMLPlug.description_tags}",
    93     'type' => "flag" } ,
     93    'type' => "flag" },
    9494      { 'name' => "no_strip_metadata_html",
    9595    'desc' => "{HTMLPlug.no_strip_metadata_html}",
     
    161161}
    162162
    163 
    164 sub metadata_read {
    165     my $self = shift (@_); 
    166     my ($pluginfo, $base_dir, $file, $metadata, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli) = @_;
    167 
    168     my $outhandle = $self->{'outhandle'};
    169 
    170     my $filename = $file;
    171     $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
    172 
    173     my ($dir) = $filename =~ /^(.*?)[^\/\\]*$/;
    174 
    175     if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
    176     return undef; # can't recognise
    177     }
    178 
    179     if ($self->{'smart_block'}) {
    180        # Do encoding stuff
    181        my ($language, $encoding) = $self->textcat_get_language_encoding ($filename);
    182    
    183        # read in file ($text will be in utf8)
    184        my $text = "";
    185        $self->read_file ($filename, $encoding, $language, \$text);
    186        $self->store_block_files (\$text, $filename);
    187    }
    188     return 1;
    189 }
    190 
    191163sub store_block_files
    192164{
    193165    my $self =shift (@_);
    194     my ($textref, $filename) = @_;
    195 
     166    my ($filename) = @_;
    196167    my $html_fname = $filename;
    197168    my @file_blocks;
    198 
     169   
     170    my ($language, $encoding) = $self->textcat_get_language_encoding ($filename);
     171   
     172    # read in file ($text will be in utf8)
     173    my $text = "";
     174    $self->read_file ($filename, $encoding, $language, \$text);
     175    my $textref = \$text;
    199176    my $opencom = '(?:<!--|&lt;!(?:&mdash;|&#151;|--))';
    200177    my $closecom = '(?:-->|(?:&mdash;|&#151;|--)&gt;)';
     
    226203    }
    227204}
     205
    228206 
    229207# do plugin specific processing of doc_obj
     
    312290                    # were probably introduced when converting to HTML from
    313291                    # some other format).
    314             # actually some people want to have html tags in their 
     292            # actually some people want to have html tags in their
    315293            # metadata.
    316294            $metavalue =~ s/[\cJ\cM]/ /sg;
  • trunk/gsdl/perllib/plugins/ImagePlug.pm

    r8365 r9067  
    122122}
    123123
    124 
     124# this makes no sense for images
     125sub block_cover_image
     126{
     127    my $self =shift (@_);
     128    my ($filename) = @_;
     129
     130    return;
     131}
    125132# Create the thumbnail and screenview images, and discover the Image's
    126133# size, width, and height using the convert utility.
Note: See TracChangeset for help on using the changeset viewer.