Difference between revisions of "Export bar on abstract page"

From EPrints Documentation
Jump to: navigation, search
(Created page with '{{Template:version_3_2}} This page demonstrates how to add an "Export" bar to the abstract page. ===cgi/export_redirect=== <pre> #!/usr/bin/perl use strict; use warnings; us…')
 
m (archives/[repoid]/cfg/cfg.d/eprint_render.pl)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:version_3_2}}
+
[[Category:Abstract Pages]]
 +
{{Version|since=3.2.0}}
  
This page demonstrates how to add an "Export" bar to the abstract page.
+
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===
 
===cgi/export_redirect===
  
<pre>
+
<source lang="perl">
 
#!/usr/bin/perl
 
#!/usr/bin/perl
  
Line 39: 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===
  
Somewhere in eprint_render.pl, below my $fragments 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, "XHTML" ];
+
     $fragments{export_bar} = $export_bar;
 
     {
 
     {
 
         my @plugins = $session->get_plugins(
 
         my @plugins = $session->get_plugins(
Line 54: Line 55:
 
             is_advertised => 1,
 
             is_advertised => 1,
 
             is_visible => "all" );
 
             is_visible => "all" );
         my $uri = $session->get_url( path => "cgi" ) . "/roar/export_redirect";
+
         my $uri = $session->get_url( path => "cgi" ) . "/export_redirect";
 
         my $form = $session->render_form( "GET", $uri );
 
         my $form = $session->render_form( "GET", $uri );
 
         $export_bar->appendChild( $form );
 
         $export_bar->appendChild( $form );
Line 71: 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===
  
<pre>
+
Where you want the export bar to appear add this:
 +
 
 +
<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" />