Doc rewrite.pl

From EPrints Documentation
Jump to: navigation, search

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


Back to cfg.d

doc_rewrite.pl contains an EP_TRIGGER_DOC_URL_REWRITE trigger to take the request document URL and ensure the right version is returned based on the relationship (to the original document) supplied in the call. E.g. Returning the thumbnail preview of the document.

Example

$c->add_trigger( EP_TRIGGER_DOC_URL_REWRITE, sub {
  my( %args ) = @_;

  my( $request, $doc, $relations, $filename ) = @args{qw( request document relations filename )};

  foreach my $r (@$relations)
  {
    $r =~ s/^has(.+)$/is$1Of/;
    $doc = $doc->search_related( $r )->item( 0 );
    if( !defined $doc )
    {
      $request->status( 404 );
      return EP_TRIGGER_DONE;
    }
    $filename = $doc->get_main;
  }

  $request->pnotes( dataobj => $doc );
  $request->pnotes( filename => $filename );
}, priority => 100 );