source: trunk/gsdl/perllib/plugins/HTMLPlug.pm@ 2817

Last change on this file since 2817 was 2817, checked in by sjboddie, 23 years ago

Implemented a description_tags option to HTMLPlug for splitting an HTML
document into subsections.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 21.8 KB
Line 
1###########################################################################
2#
3# HTMLPlug.pm -- basic html plugin
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 1999 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26
27#
28# Note that this plugin handles frames only in a very simple way
29# i.e. each frame is treated as a separate document. This means
30# search results will contain links to individual frames rather
31# than linking to the top level frameset.
32# There may also be some problems caused by the _parent target
33# (it's removed by this plugin)
34# To use frames properly you'll need to use the WebPlug plugin.
35#
36
37
38package HTMLPlug;
39
40use BasPlug;
41use ghtml;
42use unicode;
43use util;
44use parsargv;
45
46sub BEGIN {
47 @ISA = ('BasPlug');
48}
49
50sub print_usage {
51 print STDERR "\n usage: plugin HTMLPlug [options]\n\n";
52 print STDERR " options:\n";
53 print STDERR " -nolinks Don't make any attempt to trap links (setting this flag may\n";
54 print STDERR " improve speed of building/importing but any relative links within\n";
55 print STDERR " documents will be broken).\n";
56 print STDERR " -keep_head Don't remove headers from html files.\n";
57 print STDERR " -no_metadata Don't attempt to extract any metadata from files.\n";
58 print STDERR " -metadata_fields Comma separated list of metadata fields to attempt to extract.\n";
59 print STDERR " Defaults to 'Title'.\n";
60 print STDERR " Use 'tag<tagname>' to have the contents of the first <tagname>\n";
61 print STDERR " pair put in a metadata element called 'tagname' Capitalise \n";
62 print STDERR " 'tagname' as you want the metadata capitalised in the GML \n";
63 print STDERR " file, since the tag extraction is case insensitive.\n";
64 print STDERR " -hunt_creator_metadata Find as much metadata as possible on authorship and place it in the\n ";
65 print STDERR " 'Creator' field. Requires the -metadata_fields flag.\n ";
66 print STDERR " -file_is_url Set if input filenames make up url of original source documents\n";
67 print STDERR " e.g. if a web mirroring tool was used to create the import\n";
68 print STDERR " directory structure\n";
69 print STDERR " -assoc_files Perl regular expression of file extensions to associate with\n";
70 print STDERR " html documents. Defaults to '(?i)\.(jpe?g|gif|png|css)\$'\n";
71 print STDERR " -rename_assoc_files Renames files associated with documents (e.g. images). Also\n";
72 print STDERR " creates much shallower directory structure (useful when creating\n";
73 print STDERR " collections to go on cd-rom).\n\n";
74 print STDERR " -title_sub Substitution expression to modify string stored as Title.\n";
75 print STDERR " Used by, for example, PDFHtml to remove Page 1 etc from text\n";
76 print STDERR " chosen to be used as the title.\n";
77 print STDERR " -description_tags Split document into sub-sections where <Section> tags occur.\n";
78 print STDERR " Note that by setting this option you implicitly set -no_metadata\n";
79 print STDERR " as all metadata should be included within the <Section> tags.\n";
80 print STDERR " Also, -keep_head will have no effect when this option is set.\n";
81}
82
83sub new {
84 my $class = shift (@_);
85 my $self = new BasPlug ($class, @_);
86
87 if (!parsargv::parse(\@_,
88 q^nolinks^, \$self->{'nolinks'},
89 q^keep_head^, \$self->{'keep_head'},
90 q^no_metadata^, \$self->{'no_metadata'},
91 q^metadata_fields/.*/Title^, \$self->{'metadata_fields'},
92 q^hunt_creator_metadata^, \$self->{'hunt_creator_metadata'},
93 q^w3mir^, \$self->{'w3mir'},
94 q^file_is_url^, \$self->{'file_is_url'},
95 q^assoc_files/.*/(?i)\.(jpe?g|gif|png|css)$^, \$self->{'assoc_files'},
96 q^rename_assoc_files^, \$self->{'rename_assoc_files'},
97 q^title_sub/.*/^, \$self->{'title_sub'},
98 q^description_tags^, \$self->{'description_tags'},
99 "allow_extra_options")) {
100
101 print STDERR "\nIncorrect options passed to HTMLPlug, check your collect.cfg configuration file\n";
102 &print_usage();
103 die "\n";
104 }
105
106 # retain this for backward compatibility (w3mir option was replaced by
107 # file_is_url)
108 if ($self->{'w3mir'}) {
109 $self->{'file_is_url'} = 1;
110 }
111
112 $self->{'aux_files'} = {};
113 $self->{'dir_num'} = 0;
114 $self->{'file_num'} = 0;
115
116 return bless $self, $class;
117}
118
119
120sub get_default_block_exp {
121 my $self = shift (@_);
122
123 return q^(?i)\.(gif|jpe?g|png|css)$^;
124}
125
126sub get_default_process_exp {
127 my $self = shift (@_);
128
129 # the last option is an attempt to encode the concept of an html query ...
130 return q^(?i)(\.html?|\.shtml|\.shm|\.asp|\.php|\.cgi|.+\?.+=.*)$^;
131}
132
133
134# do plugin specific processing of doc_obj
135sub process {
136 my $self = shift (@_);
137 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
138 my $outhandle = $self->{'outhandle'};
139
140 print $outhandle "HTMLPlug: processing $file\n"
141 if $self->{'verbosity'} > 1;
142
143 my $cursection = $doc_obj->get_top_section();
144
145 $self->extract_metadata ($textref, $metadata, $doc_obj, $cursection)
146 unless $self->{'no_metadata'} || $self->{'description_tags'};
147
148 # Store URL for page as metadata - this can be used for an
149 # altavista style search interface. The URL won't be valid
150 # unless the file structure contains the domain name (i.e.
151 # like when w3mir is used to download a website).
152 my $web_url = "http://$file";
153 $web_url =~ s/\\/\//g; # for windows
154 $doc_obj->add_utf8_metadata($cursection, "URL", $web_url);
155
156 if ($self->{'description_tags'}) {
157
158 my $found_something = 0; my $top = 1;
159 while ($$textref =~ s/^(.*?)<!--(.*?)-->//s) {
160 my $text = $1;
161 my $comment = $2;
162 if (defined $text) {
163 $self->process_section(\$text, $base_dir, $file, $doc_obj, $cursection);
164 }
165 while ($comment =~ s/<([^>]+)>//s) {
166 my $tag = $1;
167 if ($tag eq "Section") {
168 $found_something = 1;
169 $cursection = $doc_obj->insert_section($doc_obj->get_end_child($cursection)) unless $top;
170 $top = 0;
171 } elsif ($tag eq "/Section") {
172 $found_something = 1;
173 $cursection = $doc_obj->get_parent_section ($cursection);
174 } elsif ($tag =~ /^Metadata name=\"([^\"]+)\"/s) {
175 my $metaname = $1;
176 $comment =~ s/^(.*?)<\/Metadata>//s;
177 my $metavalue = $1;
178 $metavalue =~ s/^\s+//;
179 $metavalue =~ s/\s+$//;
180 $doc_obj->set_utf8_metadata_element($cursection, $metaname, $metavalue);
181 }
182 }
183 }
184 if ($cursection ne "") {
185 print $outhandle "HTMLPlug: WARNING: $file contains unmatched <Section></Section> tags\n";
186 }
187
188 $$textref =~ s/^.*?<body[^>]*>//is;
189 $$textref =~ s/(<\/body[^>]*>|<\/html[^>]*>)//isg;
190 if ($$textref =~ /\S/) {
191 if (!$found_something) {
192 print $outhandle "HTMLPlug: WARNING: $file appears to contain no Section tags so\n";
193 print $outhandle " will be processed as a single section document\n";
194 $self->process_section($$textref, $base_dir, $file, $doc_obj, $cursection);
195 } else {
196 print $outhandle "HTMLPlug: WARNING: $file contains the following text outside\n";
197 print $outhandle " of the final closing </Section> tag. This text will\n";
198 print $outhandle " be ignored.";
199 if (length($$textref) > 30) {
200 $text = substr($$textref, 0, 30) . "...";
201 }
202 $text =~ s/\n/ /isg;
203 print $outhandle " ($text)\n";
204 }
205 }
206
207 } else {
208 # single section document
209 $self->process_section($textref, $base_dir, $file, $doc_obj, $cursection);
210 }
211 return 1;
212}
213
214# note that process_section may be called multiple times for a single
215# section (relying on the fact that add_utf8_text appends the text to any
216# that may exist already).
217sub process_section {
218 my $self = shift (@_);
219 my ($textref, $base_dir, $file, $doc_obj, $cursection) = @_;
220
221 # remove header and footer
222 if (!$self->{'keep_head'} || $self->{'description_tags'}) {
223 $$textref =~ s/^.*?<body[^>]*>//is;
224 $$textref =~ s/(<\/body[^>]*>|<\/html[^>]*>)//isg;
225 }
226
227 # trap links
228 if (!$self->{'nolinks'}) {
229
230 # usemap="./#index" not handled correctly => change to "#index"
231 $$textref =~ s/(<img[^>]*?usemap\s*=\s*\"?)([^\">\s]+)(\"?[^>]*>)/
232 $self->replace_usemap_links($1, $2, $3)/isge;
233
234 $$textref =~ s/(<(?:a|area|frame|link)\s+[^>]*?\s*(?:href|src)\s*=\s*\"?)([^\">\s]+)(\"?[^>]*>)/
235 $self->replace_href_links ($1, $2, $3, $base_dir, $file, $doc_obj, $cursection)/isge;
236 }
237
238 # trap images
239
240 # allow spaces if inside quotes - jrm21
241 $$textref =~ s/(<img[^>]*?src\s*=\s*)(\"[^\"]+\"|[^\s>]+)([^>]*>)/
242 $self->replace_images ($1, $2, $3, $base_dir, $file, $doc_obj, $cursection)/isge;
243
244 # add text to document object
245 $doc_obj->add_utf8_text($cursection, $$textref);
246}
247
248sub replace_images {
249 my $self = shift (@_);
250 my ($front, $link, $back, $base_dir,
251 $file, $doc_obj, $section) = @_;
252 # remove quotes from link at start and end if necessary
253 if ($link=~/^\"/) {
254 $link=~s/^\"//;$link=~s/\"$//;
255 $front.='"';
256 $back="\"$back";
257 }
258
259 $link =~ s/\n/ /g;
260 my ($href, $hash_part, $rl) = $self->format_link ($link, $base_dir, $file);
261 return $front . $self->add_file ($href, $rl, $hash_part, $base_dir, $doc_obj, $section) . $back;
262}
263
264sub replace_href_links {
265 my $self = shift (@_);
266 my ($front, $link, $back, $base_dir, $file, $doc_obj, $section) = @_;
267
268 # attempt to sort out targets - frames are not handled
269 # well in this plugin and some cases will screw things
270 # up - e.g. the _parent target (so we'll just remove
271 # them all ;-)
272 $front =~ s/(target=\"?)_top(\"?)/$1_gsdltop_$2/is;
273 $back =~ s/(target=\"?)_top(\"?)/$1_gsdltop_$2/is;
274 $front =~ s/target=\"?_parent\"?//is;
275 $back =~ s/target=\"?_parent\"?//is;
276
277 return $front . $link . $back if $link =~ /^\#/s;
278 $link =~ s/\n/ /g;
279
280 my ($href, $hash_part, $rl) = $self->format_link ($link, $base_dir, $file);
281 # href may use '\'s where '/'s should be on Windows
282 $href =~ s/\\/\//g;
283
284 my ($filename) = $href =~ /^(?:.*?):(?:\/\/)?(.*)/;
285
286 ##### leave all these links alone (they won't be picked up by intermediate
287 ##### pages). I think that's safest when dealing with frames, targets etc.
288 ##### (at least until I think of a better way to do it). Problems occur with
289 ##### mailto links from within small frames, the intermediate page is displayed
290 ##### within that frame and can't be seen. There is still potential for this to
291 ##### happen even with html pages - the solution seems to be to somehow tell
292 ##### the browser from the server side to display the page being sent (i.e.
293 ##### the intermediate page) in the top level window - I'm not sure if that's
294 ##### possible - the following line should probably be deleted if that can be done
295 return $front . $link . $back if $href =~ /^(mailto|news|gopher|nntp|telnet|javascript):/is;
296
297
298 if (($rl == 0) || ($filename =~ /$self->{'process_exp'}/) ||
299 ($href =~ /\/$/) || ($href =~ /^(mailto|news|gopher|nntp|telnet|javascript):/i)) {
300 &ghtml::urlsafe ($href);
301 return $front . "_httpextlink_&rl=" . $rl . "&href=" . $href . $hash_part . $back;
302
303 } else {
304 # link is to some other type of file (eg image) so we'll
305 # need to associate that file
306 return $front . $self->add_file ($href, $rl, $hash_part, $base_dir, $doc_obj, $section) . $back;
307 }
308}
309
310sub add_file {
311 my $self = shift (@_);
312 my ($href, $rl, $hash_part, $base_dir, $doc_obj, $section) = @_;
313 my ($newname);
314
315 my $filename = $href;
316 $filename =~ s/^[^:]*:\/\///;
317 $filename = &util::filename_cat($base_dir, $filename);
318
319 my ($ext) = $filename =~ /(\.[^\.]*)$/;
320
321 if ((!defined $ext) || ($ext !~ /$self->{'assoc_files'}/)) {
322 return "_httpextlink_&rl=" . $rl . "&href=" . $href . $hash_part;
323 }
324
325 if ($self->{'rename_assoc_files'}) {
326 if (defined $self->{'aux_files'}->{$href}) {
327 $newname = $self->{'aux_files'}->{$href}->{'dir_num'} . "/" .
328 $self->{'aux_files'}->{$href}->{'file_num'} . $ext;
329 } else {
330 $newname = $self->{'dir_num'} . "/" . $self->{'file_num'} . $ext;
331 $self->{'aux_files'}->{$href} = {'dir_num' => $self->{'dir_num'}, 'file_num' => $self->{'file_num'}};
332 $self->inc_filecount ();
333 }
334 $doc_obj->associate_file($filename, $newname, undef, $section);
335 return "_httpcollimg_/$newname";
336
337 } else {
338 ($newname) = $filename =~ /([^\/\\]*)$/;
339 $doc_obj->associate_file($filename, $newname, undef, $section);
340 return "_httpdocimg_/$newname";
341 }
342}
343
344
345sub format_link {
346 my $self = shift (@_);
347 my ($link, $base_dir, $file) = @_;
348
349 my ($before_hash, $hash_part) = $link =~ /^([^\#]*)(\#?.*)$/;
350
351 $hash_part = "" if !defined $hash_part;
352 if (!defined $before_hash || $before_hash !~ /[\w\.\/]/) {
353 my $outhandle = $self->{'outhandle'};
354 print $outhandle "HTMLPlug: ERROR - badly formatted tag ignored ($link)\n"
355 if $self->{'verbosity'};
356 return ($link, "", 0);
357 }
358
359 if ($before_hash =~ s/^((?:http|ftp|file):\/\/)//i) {
360 my $type = $1;
361
362 if ($link =~ /^(http|ftp):/i) {
363 # Turn url (using /) into file name (possibly using \ on windows)
364 my @http_dir_split = split('/', $before_hash);
365 $before_hash = &util::filename_cat(@http_dir_split);
366 }
367
368 $before_hash = $self->eval_dir_dots($before_hash);
369
370 my $linkfilename = &util::filename_cat ($base_dir, $before_hash);
371
372 my $rl = 0;
373 $rl = 1 if (-e $linkfilename);
374
375 # make sure there's a slash on the end if it's a directory
376 if ($before_hash !~ /\/$/) {
377 $before_hash .= "/" if (-d $linkfilename);
378 }
379
380 return ($type . $before_hash, $hash_part, $rl);
381
382 } elsif ($link !~ /^(mailto|news|gopher|nntp|telnet|javascript):/i) {
383 if ($before_hash =~ s/^\/// || $before_hash =~ /\\/) {
384
385 # the first directory will be the domain name if file_is_url
386 # to generate archives, otherwise we'll assume all files are
387 # from the same site and base_dir is the root
388 # This is not called in Windows
389 if ($self->{'file_is_url'}) {
390 my @dirs = split /[\/\\]/, $file;
391 my $domname = shift (@dirs);
392 $before_hash = &util::filename_cat($domname, $before_hash);
393 $before_hash =~ s/\\/\//g; # for windows
394 }
395 else
396 {
397 # see if link shares directory with source document
398 # => turn into relative link if this is so!
399 my $before_hash_fix = "";
400
401 # filename_cat appends / or \ to the beginning of the
402 # file pathname but in Windows we don't want to do that
403 if ($ENV{'GSDLOS'} =~ /^windows/i) {
404 $before_hash_fix = $before_hash;
405 }
406 else {
407 $before_hash_fix = &util::filename_cat("",$before_hash);
408 }
409
410 my $base_dir_win_match = $base_dir;
411 $base_dir_win_match =~ s/\\/\\\\/g;
412
413 $before_hash_fix =~ s/^$base_dir_win_match(\\|\/)//;
414 $before_hash = $before_hash_fix;
415
416 }
417
418 } else {
419 # Turn relative file path into full path
420 my $dirname = &File::Basename::dirname($file);
421 $before_hash = &util::filename_cat($dirname, $before_hash);
422 $before_hash = $self->eval_dir_dots($before_hash);
423 }
424
425 my $linkfilename = &util::filename_cat ($base_dir, $before_hash);
426
427 # make sure there's a slash on the end if it's a directory
428 if ($before_hash !~ /\/$/) {
429 $before_hash .= "/" if (-d $linkfilename);
430 }
431
432 return ("http://" . $before_hash, $hash_part, 1);
433
434 } else {
435 # mailto, news, nntp, telnet, javascript or gopher link
436 return ($before_hash, "", 0);
437 }
438}
439
440sub extract_first_NNNN_characters {
441 my $self = shift (@_);
442 my ($textref, $doc_obj, $thissection) = @_;
443
444 foreach my $size (split /,/, $self->{'first'}) {
445 my $tmptext = $$textref;
446 $tmptext =~ s/.*<body[^>]*>//i;
447 $tmptext =~ s/$self->{'title_sub'}// if (defined $self->{'title_sub'});
448 $tmptext =~ s/<[^>]*>/ /g;
449 $tmptext =~ s/&nbsp;/ /g;
450 $tmptext =~ s/^\s+//;
451 $tmptext =~ s/\s+$//;
452 $tmptext =~ s/\s+/ /gs;
453 $tmptext = substr ($tmptext, 0, $size);
454 $tmptext =~ s/\s\S*$/&#8230;/;
455 $doc_obj->add_utf8_metadata ($thissection, "First$size", $tmptext);
456 }
457}
458
459sub extract_metadata {
460 my $self = shift (@_);
461 my ($textref, $metadata, $doc_obj, $section) = @_;
462 my $outhandle = $self->{'outhandle'};
463
464 # if we don't want metadata, we may as well not be here ...
465 return if (!defined $self->{'metadata_fields'});
466
467 # hunt for an author look in the metadata elements:
468 if (defined $self->{'hunt_creator_metadata'}) {
469 for my $name (split /,/, "AUTHOR,AUTHOR.EMAIL,CREATOR,DC.CREATOR,DC.CREATOR.CORPORATENAME") {
470 if ($$textref =~ /<meta(\s*?)(?:name|http-equiv)\s*=\s*\"?$name\"?([^>]*)/is) {
471 my $content = $1 . $2;
472 if ($content =~ /content\s*=\s*\"?(.*)\"?/is) {
473 if (defined $1) {
474 my $value = $1;
475 $value =~ s/\"$//;
476 $value =~ s/\s+/ /gs;
477 $doc_obj->add_utf8_metadata($section, "Creator", $value);
478 print $outhandle " extracted Creator metadata \"$value\"\n"
479 if ($self->{'verbosity'} > 2);
480 next;
481 }
482 }
483 }
484 }
485 }
486
487 foreach my $field (split /,/, $self->{'metadata_fields'}) {
488
489 # don't need to extract field if it was passed in from a previous
490 # (recursive) plugin
491 next if defined $metadata->{$field};
492
493 # see if there's a <meta> tag for this field
494 if ($$textref =~ /<meta(\s*?)(?:name|http-equiv)\s*=\s*\"?$field\"?([^>]*)/is) {
495 my $content = $1 . $2;
496 if ($content =~ /content\s*=\s*\"?(.*)\"?/is) {
497 if (defined $1) {
498 my $value = $1;
499 $value =~ s/\"$//;
500 $value =~ s/\s+/ /gs;
501 $value =~ s/\".*//gs;
502 $doc_obj->add_utf8_metadata($section, $field, $value);
503 print $outhandle " extracted \"$field\" metadata \"$value\"\n"
504 if ($self->{'verbosity'} > 2);
505 next;
506 }
507 }
508 }
509
510 # TITLE: extract the document title
511
512 if ($field =~ /^title$/i) {
513
514 # see if there's a <title> tag
515 if ($$textref =~ /<title[^>]*>([^<]*)<\/title[^>]*>/is) {
516 if (defined $1) {
517 my $title = $1;
518 if ($title =~ /\w/) {
519 $title =~ s/<[^>]*>/ /g;
520 $title =~ s/&nbsp;/ /g;
521 $title =~ s/\s+/ /gs;
522 $title =~ s/^\s+//;
523 $title =~ s/\s+$//;
524 $doc_obj->add_utf8_metadata ($section, $field, $title);
525 print $outhandle " extracted \"$field\" metadata \"$title\"\n"
526 if ($self->{'verbosity'} > 2);
527 next;
528 }
529 }
530 }
531
532 # if no title use first 100 characters
533 my $tmptext = $$textref;
534 $tmptext =~ s/<\/([^>]+)><\1>//g; # (eg) </b><b> - no space
535 $tmptext =~ s/<[^>]*>/ /g;
536 $tmptext =~ s/&nbsp;/ /g;
537 $tmptext =~ s/^\s+//s;
538 $tmptext =~ s/\s+$//;
539 $tmptext =~ s/\s+/ /gs;
540 $tmptext =~ s/$self->{'title_sub'}// if (defined $self->{'title_sub'});
541 $tmptext = substr ($tmptext, 0, 100);
542 $tmptext =~ s/\s\S*$/.../;
543 $doc_obj->add_utf8_metadata ($section, $field, $tmptext);
544 print $outhandle " extracted \"$field\" metadata \"$tmptext\"\n"
545 if ($self->{'verbosity'} > 2);
546 next;
547 }
548
549
550 # tag: extract the text between the first <H1> and </H1> tags
551 if ($field =~ /^tag[a-z0-9]+$/i) {
552
553 my $tag = $field;
554 $tag =~ s/^tag//i;
555 my $tmptext = $$textref;
556 $tmptext =~ s/\s+/ /gs;
557 if ($tmptext =~ /<$tag[^>]*>/i) {
558 foreach my $word ($tmptext =~ m/<$tag[^>]*>(.*?)<\/$tag[^>]*>/g) {
559 $word =~ s/&nbsp;/ /g;
560 $word =~ s/<[^>]*>/ /g;
561 $word =~ s/^\s+//;
562 $word =~ s/\s+$//;
563 $word =~ s/\s+/ /gs;
564 if ($word ne "") {
565 $doc_obj->add_utf8_metadata ($section, $tag, $word);
566 print $outhandle " extracted \"$tag\" metadata \"$word\"\n"
567 if ($self->{'verbosity'} > 2);
568 }
569 }
570 }
571 next;
572 }
573 }
574}
575
576
577# evaluate any "../" to next directory up
578# evaluate any "./" as here
579sub eval_dir_dots {
580 my $self = shift (@_);
581 my ($filename) = @_;
582
583 my $dirsep_os = &util::get_os_dirsep();
584 my @dirsep = split(/$dirsep_os/,$filename);
585
586 my @eval_dirs = ();
587 foreach my $d (@dirsep) {
588 if ($d eq "..") {
589 pop(@eval_dirs);
590
591 } elsif ($d eq ".") {
592 # do nothing!
593
594 } else {
595 push(@eval_dirs,$d);
596 }
597 }
598
599 return &util::filename_cat(@eval_dirs);
600}
601
602sub replace_usemap_links {
603 my $self = shift (@_);
604 my ($front, $link, $back) = @_;
605
606 $link =~ s/^\.\///;
607 return $front . $link . $back;
608}
609
610sub inc_filecount {
611 my $self = shift (@_);
612
613 if ($self->{'file_num'} == 1000) {
614 $self->{'dir_num'} ++;
615 $self->{'file_num'} = 0;
616 } else {
617 $self->{'file_num'} ++;
618 }
619}
620
621
622# Extend the BasPlug read_file so that strings like &eacute; are
623# converted to UTF8 internally.
624#
625# We don't convert &lt; or &gt; or &amp; or &quot; in case
626# they interfere with the GML files
627
628sub read_file {
629 my ($self, $filename, $encoding, $language, $textref) = @_;
630
631 &BasPlug::read_file($self, $filename, $encoding, $language, $textref);
632
633 # turn \ into \\ so that the rest of greenstone doesn't think there
634 # is an escape code following.
635 $$textref =~ s/\\/\\\\/go;
636
637 # Convert things like &eacute; to their UTF8 equivalents
638 $$textref =~ s/&(lt|gt|amp|quot);/&z$1;/go;
639 $$textref =~ s/&([^;]+);/&unicode::ascii2utf8(\&ghtml::getcharequiv($1,1))/gseo;
640 $$textref =~ s/&z(lt|gt|amp|quot);/&$1;/go;
641}
642
6431;
Note: See TracBrowser for help on using the repository browser.