source: trunk/gsdl/perllib/plugins/FavouritesPlug.pm@ 12169

Last change on this file since 12169 was 12169, checked in by mdewsnip, 18 years ago

Tidied up that horrible long line in the new() function of every plugin.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
RevLine 
[9893]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
30package FavouritesPlug;
31
32use BasPlug;
[10254]33use strict;
34no strict 'refs'; # allow filehandles to be variables and viceversa
[9893]35
36sub BEGIN {
[10218]37 @FavouritesPlug::ISA = ('BasPlug');
[9893]38}
39
40my $arguments =
41 [ { 'name' => "process_exp",
42 'desc' => "{BasPlug.process_exp}",
43 'type' => "regexp",
44 'deft' => &get_default_process_exp(),
45 'reqd' => "no" } ];
46
47my $options = { 'name' => "FavouritesPlug",
48 '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.",
49 'abstract' => "no",
50 'inherits' => "yes",
51 'args' => $arguments };
52
53
54sub new {
[10218]55 my ($class) = shift(@_);
56 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
57 push(@$pluginlist, $class);
[9893]58
[10218]59 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
60 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
[9893]61
[12169]62 my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
[10218]63
[9893]64 return bless $self, $class;
65}
66
67
68sub get_default_process_exp
69{
70 # URL is extension for single bookmarks under windows.
71 return q^(?i)\.URL$^;
72}
73
74
75# do plugin specific processing of doc_obj
76sub process {
77 my $self = shift (@_);
78 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
79 my $outhandle = $self->{'outhandle'};
80
[10254]81 my $section = $doc_obj->get_top_section();
[9893]82 print STDERR "<Processing n='$file' p='FavouritesPlug'>\n" if ($gli);
83 print $outhandle "FavouritesPlug: processing $file\n" if $self->{'verbosity'} > 1;
84
85 # don't want mg to turn escape chars into actual values
86 $$textref =~ s/\\/\\\\/g;
87
88 # use filename (minus the .url extension) as the title
89 my $title = $file;
90 $title =~ s/.url$//i;
[10254]91 $doc_obj->add_utf8_metadata($section, "Title", $title);
[9893]92
93 # get the URL from the file
94 my ($url) = ($$textref =~ m/^URL=(http.+)/mg);
[10254]95 $doc_obj->add_metadata($section, "URL", $url);
[9893]96
97 # Add srclink metadata for an automatic link to the webpage
98 $doc_obj->add_utf8_metadata($section, "srclink", "<a href=\"$url\">");
99 $doc_obj->add_utf8_metadata($section, "srcicon", "_iconworld_");
100 $doc_obj->add_utf8_metadata($section, "/srclink", "</a>");
101
102 # Tidy up the favourite text to look a bit nicer
103 $$textref =~ s/^\\n/<p>/g;
104 $$textref =~ s/\[/<p><strong>/g;
105 $$textref =~ s/\]/<\/strong><p>/g;
106 $$textref =~ s/^Modified=(.+)$/<strong>Modified<\/strong>$1<p>/g;
[10254]107 $doc_obj->add_utf8_text($section, "$$textref");
[9893]108
[10254]109 $doc_obj->add_metadata($section, "FileFormat", "Favourite");
[9893]110 return 1;
111}
112
1131;
Note: See TracBrowser for help on using the repository browser.