-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathparacite
147 lines (125 loc) · 3.32 KB
/
paracite
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
######################################################################
#
# Paracitation Module
#
######################################################################
#
# __COPYRIGHT__
#
# Copyright 2000-2008 University of Southampton. All Rights Reserved.
#
# __LICENSE__
#
######################################################################
use EPrints;
use ParaTools::CiteParser::Standard;
use URI;
use strict;
my $session = new EPrints::Session;
exit( 0 ) unless( defined $session );
my $ds = $session->dataset( "archive" );
&process( $session );
$session->terminate;
exit;
sub process
{
my( $session ) = @_;
my $title = $session->html_phrase( "cgi/paracite:title" );
unless( EPrints::Utils::is_set( $session->param("ref") ) )
{
$session->build_page(
$title,
$session->html_phrase( "cgi/paracite:no_reference" ),
"paracite" );
$session->send_page();
return;
}
my $ref = $session->param("ref");
my $parser = new ParaTools::CiteParser::Standard();
my $metadata = $parser->parse($ref);
my ($year, $author) = ($metadata->{year}, $metadata->{aulast});
if (!defined $year || $year eq "")
{
$_ = $ref;
/\b(\d{4})\b/;
$year = $1;
if ($year !~ /^\d{4}/) { $year = ""; }
}
if (!defined $author || $author eq "")
{
$ref =~ m/^([a-zA-Z]+)/;
$author = $1;
}
my $url = $ref;
my $uri = URI->new( $url );
$url = $uri->as_string;
$url =~ s/&/%26/g;
my $paraurl = 'http://paracite.eprints.org/cgi-bin/paracite.cgi?ref='.$url;
unless( EPrints::Utils::is_set( $author ) )
{
$session->redirect( $paraurl );
return;
}
my $searchexp = new EPrints::Search(
filters => [
{ meta_fields=>[ 'metadata_visibility' ], value=>'show', match=>'EQ', merge=>"ANY", describe=>0 },
],
session => $session,
dataset => $ds );
if( EPrints::Utils::is_set( $author ) )
{
if( $ds->has_field( "authors" ) )
{
$searchexp->add_field( $ds->get_field( "authors" ), $author );
}
elsif( $ds->has_field( "creators_name" ) )
{
$searchexp->add_field( $ds->get_field( "creators_name" ), $author );
}
elsif( $ds->has_field( "creators" ) )
{
$searchexp->add_field( $ds->get_field( "creators" ), $author );
}
# otherwise dunno what to do.
}
if( EPrints::Utils::is_set( $year ) )
{
if( $ds->has_field( "year" ) )
{
$searchexp->add_field( $ds->get_field( "year" ), $year );
}
elsif( $ds->has_field( "date" ) )
{
$searchexp->add_field( $ds->get_field( "date" ), $year );
}
# otherwise dunno what to do
}
$searchexp->perform_search();
my $count = $searchexp->count();
if( $count == 0 )
{
$session->redirect( $paraurl );
$searchexp->dispose;
return;
}
my $page = $session->make_doc_fragment();
my $p = $session->make_element( "p" );
$p->appendChild( $session->make_text( $ref ) );
$page->appendChild( $p );
my @matches = $searchexp->get_records( 0, 10 );
$page->appendChild( $session->html_phrase( "cgi/paracite:possible_matches" ) );
foreach my $m ( @matches )
{
my $p = $session->make_element( "p" );
$p->appendChild( $m->render_citation_link );
$page->appendChild( $p );
}
$page->appendChild( $session->render_ruler );
my $a = $session->make_element( "a", href=>$paraurl );
$page->appendChild( $session->html_phrase(
"cgi/paracite:paracite_link",
link=>$a ));
$session->build_page( $title, $page, "paracite" );
$session->send_page();
return;
}