Difference between revisions of "Export bar on abstract page"

From EPrints Documentation
Jump to: navigation, search
(cgi/export_redirect)
Line 6: Line 6:
 
===cgi/export_redirect===
 
===cgi/export_redirect===
  
<pre>
+
<source lang="perl">
 
#!/usr/bin/perl
 
#!/usr/bin/perl
  
Line 40: Line 40:
 
$repo->redirect( $plugin->dataobj_export_url( $dataobj ) );
 
$repo->redirect( $plugin->dataobj_export_url( $dataobj ) );
 
exit( 0 );
 
exit( 0 );
</pre>
+
</source>
  
 
===archives/[repoid]/cfg/cfg.d/eprint_render.pl===
 
===archives/[repoid]/cfg/cfg.d/eprint_render.pl===

Revision as of 19:44, 17 June 2015


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

#!/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

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

    my $export_bar = $session->make_element( "div", style => "ep_block" );
    $fragments{export_bar} = $export_bar;
    {
        my @plugins = $session->get_plugins(
            type => "Export",
            can_accept => "dataobj/eprint",
            is_advertised => 1,
            is_visible => "all" );
        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

Where you want the export bar to appear add this:

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