Skip to content

Instantly share code, notes, and snippets.

@cboulanger
Created December 11, 2011 15:06
Show Gist options
  • Save cboulanger/1461020 to your computer and use it in GitHub Desktop.
Save cboulanger/1461020 to your computer and use it in GitHub Desktop.
Bookends unAPI gateway
<?php
/**
* unAPI gateway for Bookends server
* =================================
*
* requires an output format which adds the following code to all of the format's
* types:
* `<abbr class='unapi-id' title='`@`'> </abbr>
*
* @author Christian Boulanger (c.boulanger@qxtransformer.org)
*/
// configuration, adapt to your setup
$host = "localhost";
$port = 2001;
$db = "cboulanger.bdb";
$formats = array("ris");
$attachmentpath = "file:///Users/Shared/Bibliothek/Volltext";
// params
$id = $_GET['id'];
$format = $_GET['format'];
// if we have format and id, get it from bookends server
if( $id && $format )
{
// params for bookends server request
$params = array(
'DB' => $db,
'Format' => $format,
'SQLQuery' => "uniqueid=$id",
'HTMLOutput' => 2
);
// get server response
$url = "http://$host:$port/\$BEGet?" . http_build_query($params, '', '&');
$content = file_get_contents($url);
// strip tags in case COinS is turned on
$content = strip_tags( $content );
// add attachment folder path to attachment name
if( $format == "ris" )
{
$content = str_replace("L1 - ","L1 - $attachmentpath/", $content);
}
// send data
header("content-type: text/plain; charset=utf-8");
echo $content;
}
// otherwise, send formats
else
{
header("content-type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?><formats>';
foreach( $formats as $f) echo "<format name=\"$f\" type=\"text/plain\" />";
echo '</formats>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment