Difference between revisions of "Export bar on abstract page"

From EPrints Documentation
Jump to: navigation, search
(archives/[repoid]/cfg/cfg.d/eprint_render.pl)
m (archives/[repoid]/cfg/cfg.d/eprint_render.pl)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Howto]]
+
[[Category:Abstract Pages]]
[[Category:Configuration]]
 
 
{{Version|since=3.2.0}}
 
{{Version|since=3.2.0}}
  
Line 7: Line 6:
 
===cgi/export_redirect===
 
===cgi/export_redirect===
  
<pre>
+
<source lang="perl">
 
#!/usr/bin/perl
 
#!/usr/bin/perl
  
Line 41: 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===
Line 47: Line 46:
 
Somewhere in eprint_render.pl, below <em>my $fragments</em> add this:
 
Somewhere in eprint_render.pl, below <em>my $fragments</em> add this:
  
<pre>
+
<source lang='perl'>
     my $export_bar = $session->make_element( "div", style => "ep_block" );
+
     my $export_bar = $session->make_element( "div", class => "ep_block" );
 
     $fragments{export_bar} = $export_bar;
 
     $fragments{export_bar} = $export_bar;
 
     {
 
     {
Line 73: Line 72:
 
         $form->appendChild( $button );
 
         $form->appendChild( $button );
 
     }
 
     }
</pre>
+
</source>
  
 
===archives/[repoid]/cfg/citations/eprint/summary_page.xml===
 
===archives/[repoid]/cfg/citations/eprint/summary_page.xml===
Line 79: Line 78:
 
Where you want the export bar to appear add this:
 
Where you want the export bar to appear add this:
  
<pre>
+
<source lang='xml'>
 
<epc:print expr="$export_bar" />
 
<epc:print expr="$export_bar" />
</pre>
+
</source>

Latest revision as of 11:45, 12 August 2016


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", 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" );
        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" />