Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
buechereielektrik:unapi:unapi.php [2009-12-20 13:42] – Some minor style corrections strols | buechereielektrik:unapi:unapi.php [2010-02-19 13:18] – Added csv as format. strols |
---|
<code> | <code php unAPI.php> |
<?php | <?php |
| |
// hatop@ub.uni-marburg.de 2008-12-08 2009-12-03 | /* |
// http://unapi.info/specs/ | * Purpose |
| * |
| * This is an implementation of an unAPI for PICA-LBSs. |
| * It uses the XML-interface of the OPC4 for extracting bibliographic |
| * data. |
| * For the specification of unAPI, see <http://unapi.info/specs/>. |
| */ |
| |
/* Copyright 2008 2009 Goetz Hatop | /* |
| * Copyright |
| * |
| * Copyright 2008 2009 Goetz Hatop <hatop@ub.uni-marburg.de>. |
* Goetz Hatop's original Version can be found at | * Goetz Hatop's original Version can be found at |
* <ftp://ftp.ub.uni-marburg.de/pub/research/unapi.tar.gz> | * <ftp://ftp.ub.uni-marburg.de/pub/research/unapi.tar.gz>. |
| * |
| * Copyright 2009 2010 Stephan Rosenke <rosenke@ulb.tu-darmstadt.de> or |
| * <r01-551@r0s.de>. See also <http://r0s.de/unapi>. |
*/ | */ |
| |
/* Copyright 2009 Stephan Rosenke <rosenke@ulb.tu-darmstadt.de> */ | /* |
| * License |
/* This program is free software: you can redistribute it and/or modify | * |
| * This program is free software: you can redistribute it and/or modify |
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by |
* the Free Software Foundation, either version 3 of the License, or | * the Free Software Foundation, either version 3 of the License, or |
*/ | */ |
| |
/* Version: 0.1 */ | /* |
| * Version |
| * |
| * 0.5 |
| */ |
| |
/* Changelog | /* |
* | * Changelog |
* 20091216: Some minor style corrections. | * |
| * 20100219: Added csv as format. |
| * 20100127: Added link in copyright. |
| * 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. | * 20091215: Added JSON as format. |
* 20091214: s/require/require_once/. | * 20091214: s/require/require_once/. |
* Made last switch() more validator compliant. | * Made last switch() more validator compliant. |
* 20091211: Added HTTP-Response-Codes to some cases in the last switch. | * 20091211: Added HTTP-Response-Codes to some cases in the last switch. |
* Corrected answer if format=''. | * Corrected answer if format=''. |
* Added BibTex as format. | * Added BibTex as format. |
* 20091210: Put class Picappn to PicaRecord.php. | * 20091210: Put class Picappn to PicaRecord.php. |
* Inserted conditional for textual output of array. | * Inserted conditional for textual output of array. |
* Ordered final switch() alphabetically. | * Ordered final switch() alphabetically. |
* Added format "plain", renamed "picaplus" to "extpp". | * Added format "plain", renamed "picaplus" to "extpp". |
Put header() in the case-loops in final switch(). | * Put header() in the case-loops in final switch(). |
* 20091210: Started with Goetz Hatop's version of 2009-12-08 | * 20091210: Started with Goetz Hatop's version of 2009-12-08. |
*/ | */ |
| |
require_once('PicaRecord.php'); | |
| |
| /* |
| * |
| * DO NOT MESS BEHIND THIS LINE |
| * |
| */ |
| |
| // include some objects and methods |
| require_once('unAPI.inc.php'); |
| |
| // make some GET-variables a little bit handier |
| $format = $_GET['format']; |
| $id = $_GET['id']; |
| |
| /* |
| * 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\"?> | $noparam = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
<formats> | <formats> |
<format name=\"bibtex\" type=\"text/plain\" /> | <format name=\"bibtex\" type=\"text/plain\" /> |
| <format name=\"csv\" type=\"text/plain\" /> |
<format name=\"dc\" type=\"application/xml\" /> | <format name=\"dc\" type=\"application/xml\" /> |
<format name=\"extpp\" 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=\"rdf\" type=\"application/xml\" /> |
<format name=\"text\" type=\"text/plain\" /> | <format name=\"text\" type=\"text/plain\" /> |
"; | "; |
| |
$idparam = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> | /* |
<formats id=\"info:pica/004\"> | * check if $id is not empty, if it's empty show |
<format name=\"text\" type=\"text/plain\" /> | * available formats. |
</formats> | */ |
"; | if (!isset($id) || $id == '') { |
| |
if (!isset($_GET['id']) || $_GET['id']=='') { | |
header('Content-type: application/xml'); | header('Content-type: application/xml'); |
echo "$noparam"; | echo "$noparam"; |
return; | return; |
} | } |
| |
| // instantiate new Picappn() |
$pica = new Picappn(); | $pica = new Picappn(); |
$pica->setPpn( $_GET['id'] ); | |
| |
if ($_GET['format'] == "array") { | // set PPN as identifier |
| $pica->setPpn($id); |
| |
| /* |
| * This is no part of the unAPI but for debugging. |
| * It is triggered by supplying "array" as $format and print_rs the |
| * pica-data as array. |
| */ |
| if ($format == "array") { |
echo "<head></head>\n<body>\n <pre>\n"; | echo "<head></head>\n<body>\n <pre>\n"; |
print_r($pica->getArray()); | print_r($pica->getArray()); |
} | } |
| |
switch ($_GET['format']) { | // Final switch for printing result according to $format |
| switch ($format) { |
| // BibTeX |
case 'bibtex': | case 'bibtex': |
$res = $pica->getBibTex(); | $res = $pica->getBibTex(); |
final_result($res, 'text/plain'); | final_result($res, 'text/plain'); |
break; | break; |
| // CSV |
| case 'csv': |
| $res = $pica->getCsv(); |
| final_result($res, 'text/plain'); |
| break; |
| // Dublin Core |
case 'dc': | case 'dc': |
$res = $pica->getDublinCore(); | $res = $pica->getDublinCore(); |
final_result($res, 'application/xml'); | final_result($res, 'application/xml'); |
break; | break; |
| // External PICA+ |
case 'extpp': | case 'extpp': |
$res = $pica->getPicaPlus(); | $res = $pica->getPicaPlus(); |
final_result($res, 'application/xml'); | final_result($res, 'application/xml'); |
break; | break; |
| // JSON |
case 'json': | case 'json': |
$res = $pica->getJson(); | $res = $pica->getJson(); |
final_result($res, 'application/json'); | final_result($res, 'application/json'); |
break; | break; |
| // OpenURL-KEV |
| case 'openurl-kev': |
| $res = $pica->getOpenUrlKev(); |
| final_result($res, 'text/plain'); |
| break; |
| // pseudo-XML |
case 'plain': | case 'plain': |
$res = $pica->getPlain(); | $res = $pica->getPlain(); |
break; | break; |
| // RDF |
case 'rdf': | case 'rdf': |
$res = $pica->getDublinCoreRDF(); | $res = $pica->getDublinCoreRDF(); |
final_result($res, 'application/xml'); | final_result($res, 'application/xml'); |
break; | break; |
| // plain text |
case 'text': | case 'text': |
$res = $pica->getText(); | $res = $pica->getText(); |
final_result($res, 'text/plain'); | final_result($res, 'text/plain'); |
break; | break; |
| // XML |
case 'xml': | case 'xml': |
$res = $pica->getXmlData(); | $res = $pica->getXmlData(); |
final_result($res, 'application/xml'); | final_result($res, 'application/xml'); |
break; | break; |
| // if no $format is given but $id is set |
case '': | case '': |
header('HTTP/1.0 300 Multiple Choices'); | header('HTTP/1.0 300 Multiple Choices'); |
echo "$noparam"; | echo "$noparam"; |
break; | break; |
| // for all other values of $format |
default: | default: |
header('HTTP/1.0 406 Not Acceptable'); | header('HTTP/1.0 406 Not Acceptable'); |