Skip to content

Commit

Permalink
add sandbox switch compatibility to advance plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dennmuel committed Apr 11, 2019
1 parent e6614a3 commit 090c251
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
48 changes: 27 additions & 21 deletions cfg/cfg.d/z_orcid_support.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ =head2 Changes
$c->{plugins}{"Export::Report::CSV::CreatorsOrcid"}{params}{disable} = 0;

#---Users---#
#add orcid field to the user profile's
#but checking first to see if the field is already present in the user dataset before adding it
#add orcid field to the user profile's
#but checking first to see if the field is already present in the user dataset before adding it
my $orcid_present = 0;
for(@{$c->{fields}->{user}})
{
Expand Down Expand Up @@ -63,7 +63,7 @@ =head2 Changes
last;
}
}

#add orcid subfield
if( !$orcid_present )
{
Expand All @@ -74,9 +74,9 @@ =head2 Changes
input_cols => 19,
allow_null => 1,
}
));
));
}
}
}
}

#automatic update of eprint creator field
Expand Down Expand Up @@ -117,7 +117,7 @@ =head2 Changes
$eprint->set_value("creators", \@new_creators);
}


}, priority => 50 );

#automatic update of eprint editor field
Expand Down Expand Up @@ -158,29 +158,29 @@ =head2 Changes
$eprint->set_value("editors", \@new_editors);
}


}, priority => 50 );


#Rendering ORCIDs
{
package EPrints::Script::Compiled;
use strict;

sub run_people_with_orcids
{
my( $self, $state, $value ) = @_;

my $session = $state->{session};
my $r = $state->{session}->make_doc_fragment;

my $creators = $value->[0];

foreach my $i (0..$#$creators)
{

my $creator = @$creators[$i];

if( $i > 0 )
{
#not first item (or only one item)
Expand All @@ -194,25 +194,31 @@ sub run_people_with_orcids
$r->appendChild( $session->make_text( ", " ) );
}
}

my $person_span = $session->make_element( "span", "class" => "person" );
$person_span->appendChild( $session->render_name( $creator->{name} ) );


my $orcid_domain;
if( $session->config( 'orcid_support_advance', 'orcid_domain' ) ) {
$orcid_domain = $c->{orcid_support_advance}->{orcid_domain};
} else {
$orcid_domain = "orcid.org";
}
my $orcid = $creator->{orcid};
if( defined $orcid && $orcid =~ m/^(?:orcid.org\/)?(\d{4}\-\d{4}\-\d{4}\-\d{3}(?:\d|X))$/ )
if( defined $orcid && $orcid =~ m/^(?:\Q$orcid_domain\E\/)?(\d{4}\-\d{4}\-\d{4}\-\d{3}(?:\d|X))$/ )
{
my $orcid_link = $session->make_element( "a",
my $orcid_link = $session->make_element( "a",
"class" => "orcid",
"href" => "https://orcid.org/$1",
"href" => "https://" . $orcid_domain . "/" . $1,
"target" => "_blank",
);
$orcid_link->appendChild( $session->make_element( "img", "src" => "/images/orcid_16x16.png" ) );

my $orcid_span = $session->make_element( "span", "class" => "orcid-tooltip" );

$orcid_span->appendChild( $session->make_text( "ORCID: " ) );
$orcid_span->appendChild( $session->make_text( "https://orcid.org/$1" ) );
$orcid_link->appendChild( $orcid_span );
$orcid_span->appendChild( $session->make_text( "https://" . $orcid_domain . "/" . $1 ) );
$orcid_link->appendChild( $orcid_span );

$person_span->appendChild( $session->make_text( " " ) );
$person_span->appendChild( $orcid_link );
Expand Down
27 changes: 18 additions & 9 deletions cfg/cfg.d/zzz_rioxx2_orcid.pl
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
#Adapted from John Salter's work at: https://wiki.eprints.org/w/ORCID#Exposing_the_ORCID_in_RIOXX
#Adapted from John Salter's work at: https://wiki.eprints.org/w/ORCID#Exposing_the_ORCID_in_RIOXX
$c->{rioxx2_value_author} = sub {
my( $eprint ) = @_;


my $session = $eprint->{session};
my $orcid_domain;

if( $session->config( 'orcid_support_advance', 'orcid_domain' ) ) {
$orcid_domain = $session->config( 'orcid_support_advance', 'orcid_domain' );
} else {
$orcid_domain = "orcid.org";
}

my @authors;
for( @{ $eprint->value( "creators" ) } )
{
{
my $id = $_->{orcid};
$id = EPrints::ORCID::Utils::get_normalised_orcid( $id );
if( $id )
$id = EPrints::ORCID::Utils::get_normalised_orcid( $id );
if( $id )
{
push @authors, {
author => EPrints::Utils::make_name_string( $_->{name} ),
id => "https://orcid.org/$id"
id => "https://" . $orcid_domain . "/" . $id
};
}
}
else
{
push @authors, {
author => EPrints::Utils::make_name_string( $_->{name} ),
};
}
}

#NB If your corp_creators has DOIs or ISNIs for the entries, a similar method could be used to include these here.
foreach my $corp ( @{ $eprint->value( "corp_creators" ) } )
{
my $entry = {};
$entry->{name} = $corp;
push @authors, { author => $corp };
}

return \@authors;
};
24 changes: 15 additions & 9 deletions lib/plugins/EPrints/MetaField/Orcid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ sub get_basic_input_elements
sub render_single_value
{
my( $self, $session, $value ) = @_;

my $url = "https://orcid.org/$value";

my $link = $session->render_link( $url, "_blank" );
$link->appendChild( $session->make_element( "img", src => "/images/orcid_16x16.png", class => "orcid-icon" ) );
$link->appendChild( $session->make_text( "https://orcid.org/$value" ) );

return $link;
my $orcid_domain;
if( $session->config( 'orcid_support_advance', 'orcid_domain' ) ) {
$orcid_domain = $session->config( 'orcid_support_advance', 'orcid_domain' );
} else {
$orcid_domain = "orcid.org";
}

my $url = "https://" . $orcid_domain . "/" . $value;

my $link = $session->render_link( $url, "_blank" );
$link->appendChild( $session->make_element( "img", src => "/images/orcid_16x16.png", class => "orcid-icon" ) );
$link->appendChild( $session->make_text( "https://" . $orcid_domain . "/" . $value ) );

return $link;
}

sub validate
Expand Down Expand Up @@ -144,7 +150,7 @@ sub validate_orcid
{
push @problems, $session->html_phrase( "validate:invalid_orcid_format" );
}

return @problems;
}

Expand Down

0 comments on commit 090c251

Please sign in to comment.