- Timestamp:
- 2010-08-04T14:01:35+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm
r22349 r22565 157 157 'deft' => &get_default_process_exp(), 158 158 'reqd' => "no" }, 159 { 'name' => "block_exp",160 'desc' => "{BasePlugin.block_exp}",161 'type' => "string",162 'deft' => &get_default_block_exp(),163 'reqd' => "no" },164 159 { 'name' => "title_sub", 165 160 'desc' => "{HTMLPlugin.title_sub}", … … 248 243 249 244 250 # want to block everything except the .item ones251 # but instead we will block images and txt files252 sub get_default_block_exp {253 my $self = shift (@_);254 255 return q^(?i)(\.jpe?g|\.gif|\.png|\.tif?f|\.te?xt|\.html?|~)$^256 ### return q^(?i)(\.jpe?g|\.gif|\.png|\.tif?f|\.te?xt|\.html?|\.css|\.opd|\.pdf|~)$^257 }258 259 260 245 # want to use BasePlugin's version of this, not ReadXMLFile's 261 246 sub can_process_this_file { 262 247 my $self = shift(@_); 263 264 248 return $self->BasePlugin::can_process_this_file(@_); 249 } 250 251 # instead of a block exp, now we scan the file and record all text and img files mentioned there for blocking. 252 sub store_block_files 253 { 254 my $self = shift (@_); 255 my ($filename_full_path, $block_hash) = @_; 256 257 my $xml_version = $self->is_xml_item_file($filename_full_path); 258 259 # do we need to do this? if we do it here, then don't need to do it later 260 $self->tidy_item_file($filename_full_path); 261 262 my ($dir, $file) = $filename_full_path =~ /^(.*?)([^\/\\]*)$/; 263 if ($xml_version) { 264 265 # do something 266 $self->scan_xml_for_files_to_block($filename_full_path, $dir, $block_hash); 267 } else { 268 269 $self->scan_item_for_files_to_block($filename_full_path, $dir, $block_hash); 270 } 271 265 272 } 266 273 … … 294 301 my $xml_version = $self->is_xml_item_file($filename_full_path); 295 302 296 $self->tidy_item_file($filename_full_path); 303 # have done this already in store_block_files 304 #$self->tidy_item_file($filename_full_path); 297 305 298 306 my $doc_obj; … … 552 560 } 553 561 562 sub scan_xml_for_files_to_block 563 { 564 my $self = shift (@_); 565 my ($filename_full_path, $dir, $block_hash) = @_; 566 567 open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path to work out which files to block\n"; 568 my $line = ""; 569 while (defined ($line = <ITEMFILE>)) { 570 next unless $line =~ /\w/; 571 572 if ($line =~ /imgfile=\"([^\"]+)\"/) { 573 $block_hash->{'file_blocks'}->{$dir.$1} = 1; 574 } 575 if ($line =~ /txtfile=\"([^\"]+)\"/) { 576 $block_hash->{'file_blocks'}->{$dir.$1} = 1; 577 } 578 } 579 close ITEMFILE; 580 581 } 582 583 sub scan_item_for_files_to_block 584 { 585 my $self = shift (@_); 586 my ($filename_full_path, $dir, $block_hash) = @_; 587 588 open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path to work out which files to block\n"; 589 my $line = ""; 590 while (defined ($line = <ITEMFILE>)) { 591 next unless $line =~ /\w/; 592 chomp $line; 593 next if $line =~ /^#/; # ignore comment lines 594 next if ($line =~ /^<([^>]*)>\s*(.*?)\s*$/); # ignore metadata lines 595 # line should be like page:imagefilename:textfilename:r 596 $line =~ s/^\s+//; #remove space at the front 597 $line =~ s/\s+$//; #remove space at the end 598 my ($pagenum, $imgname, $txtname, $rotate) = split /:/, $line; 599 600 # find the image file if there is one 601 if (defined $imgname && $imgname ne "") { 602 $block_hash->{'file_blocks'}->{$dir.$imgname}=1; 603 } 604 # find the text file if there is one 605 if (defined $txtname && $txtname ne "") { 606 $block_hash->{'file_blocks'}->{$dir.$txtname} = 1; 607 } 608 } 609 close ITEMFILE; 610 611 } 554 612 555 613 sub process_item { … … 661 719 $text = $1; 662 720 663 # insert preformat tags andadd text to document object721 # add text to document object 664 722 $doc_obj->add_utf8_text($cursection, "$text"); 665 723 }
Note:
See TracChangeset
for help on using the changeset viewer.