1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # FavouritesPlug.pm -- Plugin for Internet Explorer Favourites files
|
---|
4 | # By Stephen De Gabrielle
|
---|
5 | #
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 2005 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 | # hacked together by Stephen De Gabrielle from various plugins
|
---|
28 | # especially SRCPlug by John McPherson Nov 2000
|
---|
29 |
|
---|
30 | package FavouritesPlug;
|
---|
31 |
|
---|
32 | use BasPlug;
|
---|
33 | use parsargv;
|
---|
34 | use strict;
|
---|
35 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
36 |
|
---|
37 | sub BEGIN {
|
---|
38 | @FavouritesPlug::ISA = ('BasPlug');
|
---|
39 | }
|
---|
40 |
|
---|
41 | my $arguments =
|
---|
42 | [ { 'name' => "process_exp",
|
---|
43 | 'desc' => "{BasPlug.process_exp}",
|
---|
44 | 'type' => "regexp",
|
---|
45 | 'deft' => &get_default_process_exp(),
|
---|
46 | 'reqd' => "no" } ];
|
---|
47 |
|
---|
48 | my $options = { 'name' => "FavouritesPlug",
|
---|
49 | 'desc' => "FavouritesPlug imports Internet Explorer style Favourites. Favourites are often found in the \"C:\\Documents and Settings\\[your username]\\Favorites\" folder on your computer, but can also be made by dragging a bookmark or location from your browser (any) to the desktop.",
|
---|
50 | 'abstract' => "no",
|
---|
51 | 'inherits' => "yes",
|
---|
52 | 'args' => $arguments };
|
---|
53 |
|
---|
54 |
|
---|
55 | sub new {
|
---|
56 | my ($class) = shift(@_);
|
---|
57 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
58 | push(@$pluginlist, $class);
|
---|
59 |
|
---|
60 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
61 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
62 |
|
---|
63 | my $self = (defined $hashArgOptLists)? new BasPlug($pluginlist,$inputargs,$hashArgOptLists): new BasPlug($pluginlist,$inputargs);
|
---|
64 |
|
---|
65 | return bless $self, $class;
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | sub get_default_process_exp
|
---|
70 | {
|
---|
71 | # URL is extension for single bookmarks under windows.
|
---|
72 | return q^(?i)\.URL$^;
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | # do plugin specific processing of doc_obj
|
---|
77 | sub process {
|
---|
78 | my $self = shift (@_);
|
---|
79 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
80 | my $outhandle = $self->{'outhandle'};
|
---|
81 |
|
---|
82 | my $section = $doc_obj->get_top_section();
|
---|
83 | print STDERR "<Processing n='$file' p='FavouritesPlug'>\n" if ($gli);
|
---|
84 | print $outhandle "FavouritesPlug: processing $file\n" if $self->{'verbosity'} > 1;
|
---|
85 |
|
---|
86 | # don't want mg to turn escape chars into actual values
|
---|
87 | $$textref =~ s/\\/\\\\/g;
|
---|
88 |
|
---|
89 | # use filename (minus the .url extension) as the title
|
---|
90 | my $title = $file;
|
---|
91 | $title =~ s/.url$//i;
|
---|
92 | $doc_obj->add_utf8_metadata($section, "Title", $title);
|
---|
93 |
|
---|
94 | # get the URL from the file
|
---|
95 | my ($url) = ($$textref =~ m/^URL=(http.+)/mg);
|
---|
96 | $doc_obj->add_metadata($section, "URL", $url);
|
---|
97 |
|
---|
98 | # Add srclink metadata for an automatic link to the webpage
|
---|
99 | $doc_obj->add_utf8_metadata($section, "srclink", "<a href=\"$url\">");
|
---|
100 | $doc_obj->add_utf8_metadata($section, "srcicon", "_iconworld_");
|
---|
101 | $doc_obj->add_utf8_metadata($section, "/srclink", "</a>");
|
---|
102 |
|
---|
103 | # Tidy up the favourite text to look a bit nicer
|
---|
104 | $$textref =~ s/^\\n/<p>/g;
|
---|
105 | $$textref =~ s/\[/<p><strong>/g;
|
---|
106 | $$textref =~ s/\]/<\/strong><p>/g;
|
---|
107 | $$textref =~ s/^Modified=(.+)$/<strong>Modified<\/strong>$1<p>/g;
|
---|
108 | $doc_obj->add_utf8_text($section, "$$textref");
|
---|
109 |
|
---|
110 | $doc_obj->add_metadata($section, "FileFormat", "Favourite");
|
---|
111 | return 1;
|
---|
112 | }
|
---|
113 |
|
---|
114 | 1;
|
---|