Jump to content

Export bar on abstract page

From EPrints Documentation


Warning This feature requires EPrints version 3.2.0 or later

To add an export bar to the abstract page requires editing the eprint_render() method, eprint summary citation style and adding a CGI script to link the abstract page's form to the export URL.

cgi/export_redirect[edit]

#!/usr/bin/perl

use strict;
use warnings;

use EPrints;

my $eprints = EPrints->new;
my $repo = $eprints->current_repository;
exit( 0 ) if !defined $repo;

my $id = $repo->param( "dataobj" );
my $format = $repo->param( "format" );

exit( 0 ) if !EPrints::Utils::is_set( $id );
exit( 0 ) if !EPrints::Utils::is_set( $format );

my $dataobj = $repo->dataset( "archive" )->dataobj( $id );
if( !defined $dataobj )
{
    $repo->not_found( "eprint $id doesn't exist" );
    exit( 0 );
}

my $plugin = $repo->plugin( "Export::".$format );
if( !defined $plugin )
{
    $repo->not_found( "export format $format doesn't exist" );
    exit( 0 );
}

$repo->redirect( $plugin->dataobj_export_url( $dataobj ) );
exit( 0 );

archives/[repoid]/cfg/cfg.d/eprint_render.pl[edit]

Somewhere in eprint_render.pl, below my $fragments add this:

    my $export_bar = $session->make_element( "div", class => "ep_block" );
    $fragments{export_bar} = $export_bar;
    {
        my @plugins = $session->get_plugins(
            type => "Export",
            can_accept => "dataobj/eprint",
            is_advertised => 1,
            is_visible => "all" );

        # Added March 2025 - sort the plugins into a consistent order.
        # You may also want to make a custom order somehow. The 'qs' parameter seems
        # more focused on machine users than humans.
        my %names = map { $_ => $_->get_name } @plugins;
        @plugins = sort { $names{$a} cmp $names{$b} } @plugins;
        # /End Added March 2025

        my $uri = $session->get_url( path => "cgi" ) . "/export_redirect";
        my $form = $session->render_form( "GET", $uri );
        $export_bar->appendChild( $form );
        $form->appendChild( $session->render_hidden_field( dataobj => $eprint->id ) );
        my $select = $session->make_element( "select", name => "format" );
        $form->appendChild( $select );
        foreach my $plugin (@plugins)
        {
            my $plugin_id = $plugin->get_id;
            $plugin_id =~ s/^Export:://;
            my $option = $session->make_element( "option", value => $plugin_id );
            $select->appendChild( $option );
            $option->appendChild( $plugin->render_name );
        }
        my $button = $session->make_element( "input", type => "submit", value => $session->phrase( "lib/searchexpression:export_button" ), class => "ep_form_action_button" );
        $form->appendChild( $button );
    }

archives/[repoid]/cfg/citations/eprint/summary_page.xml[edit]

Where you want the export bar to appear add this:

<epc:print expr="$export_bar" />