Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
buechereielektrik:unapi:unapi.php [2010-01-27 20:22] – Added link in copyright rosenkebuechereielektrik:unapi:unapi.php [2010-02-19 13:18] – Added csv as format. strols
Line 5: Line 5:
   Purpose   Purpose
  *  *
- *  Take an unique identifier as id-parameter and return bibliographic data + *  This is an implementation of an unAPI for PICA-LBSs. 
- *  as COinS wrapped in JavaScript+  It uses the XML-interface of the OPC4 for extracting bibliographic 
-  For the specification of COinS, see <http://ocoins.info/>.+ *  data
 +  For the specification of unAPI, see <http://unapi.info/specs/>.
  */  */
  
Line 14: Line 15:
  *  *
   Copyright 2008 2009 Goetz Hatop <hatop@ub.uni-marburg.de>.   Copyright 2008 2009 Goetz Hatop <hatop@ub.uni-marburg.de>.
 +  Goetz Hatop's original Version can be found at
 +  <ftp://ftp.ub.uni-marburg.de/pub/research/unapi.tar.gz>.
  *  *
   Copyright 2009 2010 Stephan Rosenke <rosenke@ulb.tu-darmstadt.de> or   Copyright 2009 2010 Stephan Rosenke <rosenke@ulb.tu-darmstadt.de> or
Line 45: Line 48:
   Changelog   Changelog
  *  *
 +  20100219: Added csv as format.
   20100127: Added link in copyright.   20100127: Added link in copyright.
-  20100111: stripped Bibsonomy.php for use as COinS-Generator.+  20100111: Added openurl-kev as format. 
 +  20100110: Some style improvements, added comments, removed some old code. 
 +  20100109: Some style improvements, added comments. 
 +  20091216: Some minor style and other corrections. 
 +  20091215:   Added JSON as format. 
 +  20091214:   s/require/require_once/
 +              Made last switch() more validator compliant. 
 +  20091211: Added HTTP-Response-Codes to some cases in the last switch. 
 + * Corrected answer if format=''
 + * Added BibTex as format. 
 +  20091210: Put class Picappn to PicaRecord.php
 + * Inserted conditional for textual output of array. 
 + * Ordered final switch() alphabetically. 
 + * Added format "plain", renamed "picaplus" to "extpp"
 + * Put header() in the case-loops in final switch(). 
 +  20091210: Started with Goetz Hatop's version of 2009-12-08.
  */  */
  
-/* 
-  Readme 
- * 
-  For generating COinS using this script include it in a HTML-file by these 
-  lines: 
-  <script src="http://example.com/Coins.php?id=123" type="text/javascript" 
-   language="JavaScript"></script> 
- */ 
- 
-/* 
-  set some user-defineable variables 
- */ 
- 
-//  Default text for COinS 
-$text = ''; 
  
 /* /*
Line 75: Line 79:
  
 //  make some GET-variables a little bit handier //  make some GET-variables a little bit handier
 +$format = $_GET['format'];
 $id = $_GET['id']; $id = $_GET['id'];
  
-//  check if $id is not empty+/
 +  Output if no id-parameter or no parameter at all is given. 
 +  Plain-format is not announced. 
 + */ 
 +$noparam = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> 
 +<formats> 
 +<format name=\"bibtex\" type=\"text/plain\" /> 
 +<format name=\"csv\" type=\"text/plain\" /> 
 +<format name=\"dc\" type=\"application/xml\" /> 
 +<format name=\"extpp\" type=\"application/xml\" /> 
 +<format name=\"json\" type=\"application/json\" /> 
 +<format name=\"openurl-kev\" type=\"text/plain\" /> 
 +<format name=\"rdf\" type=\"application/xml\" /> 
 +<format name=\"text\" type=\"text/plain\" /> 
 +<format name=\"xml\" type=\"application/xml\" /> 
 +</formats> 
 +"; 
 + 
 +/
 +  check if $id is not empty, if it's empty show 
 +  available formats. 
 + */
 if (!isset($id) || $id == '') { if (!isset($id) || $id == '') {
-  header('HTTP/1.0 406 Not Acceptable'); +  header('Content-type: application/xml'); 
-  echo "406: Not Acceptable";+  echo "$noparam";
   return;   return;
 } }
Line 90: Line 116:
 $pica->setPpn($id); $pica->setPpn($id);
  
-/ get URL for redirecting to Bibsonomy +/
-$res = $pica->getOpenUrlKev(); +  This is no part of the unAPI but for debugging. 
- + *  It is triggered by supplying "array" as $format and print_rs the 
-//  check if $res is not empty and return COinS with JavaScript + *  pica-data as array. 
-if (!isset($res) || $res == '') { + *
-  header('HTTP/1.0 406 Not Acceptable')+if ($format == "array") { 
-  return; +  echo "<head></head>\n<body>\n <pre>\n"
-} else { +  print_r($pica->getArray())
-  echo 'document.write("<span class=\"Z3988\" title=\"'.$res.'\">'.$text. +  echo " </pre>\n</body>\n"
-   '</span>")';+  die(0);
 } }
  
 +//  Final switch for printing result according to $format
 +switch ($format) {
 +  //  BibTeX
 +  case 'bibtex':
 +     $res = $pica->getBibTex();
 +     final_result($res, 'text/plain');
 +     break;
 +  //  CSV
 +  case 'csv':
 +     $res = $pica->getCsv();
 +     final_result($res, 'text/plain');
 +     break;
 +  //  Dublin Core
 +  case 'dc':
 +     $res = $pica->getDublinCore();
 +     final_result($res, 'application/xml');
 +     break;
 +  //  External PICA+
 +  case 'extpp':
 +     $res = $pica->getPicaPlus();
 +     final_result($res, 'application/xml');
 +     break;
 +  //  JSON
 +  case 'json':
 +     $res = $pica->getJson();
 +     final_result($res, 'application/json');
 +     break;
 +  //  OpenURL-KEV
 +  case 'openurl-kev':
 +     $res = $pica->getOpenUrlKev();
 +     final_result($res, 'text/plain');
 +     break;
 +  //  pseudo-XML
 +  case 'plain':
 +     $res = $pica->getPlain();
 +     break;
 +  //  RDF
 +  case 'rdf':
 +     $res = $pica->getDublinCoreRDF();
 +     final_result($res, 'application/xml');
 +     break;
 +  //  plain text
 +  case 'text':
 +     $res = $pica->getText();
 +     final_result($res, 'text/plain');
 +     break;
 +  //  XML
 +  case 'xml':
 +     $res = $pica->getXmlData();
 +     final_result($res, 'application/xml');
 +     break;
 +  //  if no $format is given but $id is set
 +  case '':
 +     header('HTTP/1.0 300 Multiple Choices');
 +     header('Content-type: application/xml');
 +     echo "$noparam";
 +     break;
 +  //  for all other values of $format
 +  default:
 +     header('HTTP/1.0 406 Not Acceptable');
 +     break;
 +}
 ?> ?>
 </code> </code>
buechereielektrik/unapi/unapi.php.txt · Last modified: 2011-01-20 17:12 by strols
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0