Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
buechereielektrik:unapi:unapi.inc.php [2010-01-10 22:21] – created rosenke | buechereielektrik:unapi:unapi.inc.php [2010-03-03 17:13] – strols | ||
---|---|---|---|
Line 2: | Line 2: | ||
<?php | <?php | ||
- | / | + | /* |
- | | + | * |
- | | + | * |
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
*/ | */ | ||
- | /* Copyright 2009 Stephan Rosenke < | + | /* |
+ | | ||
+ | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | * | ||
+ | * Copyright 2009 2010 Stephan Rosenke < | ||
+ | | ||
+ | */ | ||
- | /* This program is free software: you can redistribute it and/or modify | + | /* |
+ | | ||
+ | * | ||
+ | * This program is free software: you can redistribute it and/or modify | ||
| | ||
| | ||
Line 23: | Line 43: | ||
*/ | */ | ||
- | /* Version: 0.1 */ | + | /* |
+ | * Version | ||
+ | * | ||
+ | | ||
+ | */ | ||
- | /* Changelog | + | /* |
+ | * Changelog | ||
* | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
| | ||
- | | + | * "file_get_contents()". |
- | | + | * Some minor bugfixes. |
- | | + | |
- | | + | * Made ISBN in "getBibTex()" |
- | | + | * Filtered some characters in "getArrayNice()". |
- | | + | |
- | | + | |
- | | + | |
- | | + | * Handled empty records for dc and rdf. |
- | | + | |
- | | + | * Defined text-format. |
- | | + | * Defined bibtex-format. |
+ | | ||
| | ||
| | ||
- | | + | |
- | * " | + | |
- | | + | |
- | * class " | + | * " |
- | | + | |
*/ | */ | ||
- | $opac_url = "http:// | + | /* |
- | //$opac_url = "http://opac.ub.uni-marburg.de/XML=1.0/ | + | |
- | //$opac_url = " | + | * |
- | //$opac_url | + | |
+ | | ||
+ | */ | ||
+ | |||
+ | /* | ||
+ | | ||
+ | */ | ||
+ | |||
+ | // | ||
+ | $opac_url = 'http://example.com/DB=1/ | ||
+ | |||
+ | // | ||
+ | $bibsonomy_url | ||
- | $bibsonomy_url | + | // Regex for checking if input is PPN |
+ | $pattern_ppn | ||
+ | // Array for filtering extracted bibliographic data | ||
$filter_nice = array( | $filter_nice = array( | ||
' | ' | ||
- | ' | + | ' |
); | ); | ||
- | /** represents a bibliographic data record from oclc/pica LBS | + | // Hostname for generating rfr_id for OpenURL |
- | */ | + | $rfr_id_hostname= ' |
+ | |||
+ | /* | ||
+ | ******************************************************************************* | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | |||
+ | /* | ||
+ | | ||
+ | | ||
+ | * XML structure or an array | ||
+ | **/ | ||
class PicaRecord { | class PicaRecord { | ||
- | // 15 dublin core elements http:// | + | // 15 dublin core elements http:// |
var $contributor, | var $contributor, | ||
var $identifier, | var $identifier, | ||
var $subject, $title, $type; | var $subject, $title, $type; | ||
- | // 1 for me | + | // 1 for me |
var $signatur; | var $signatur; | ||
+ | /* | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function PicaRecord() { | function PicaRecord() { | ||
- | // | + | // |
| | ||
| | ||
Line 78: | Line 155: | ||
} | } | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function decodePica($str) { | function decodePica($str) { | ||
$tag = ""; | $tag = ""; | ||
Line 102: | Line 184: | ||
| | ||
- | case 226: //pica two byte char accent like " | + | case 226: //PICA two byte char accent like " |
$ch = substr($str, | $ch = substr($str, | ||
$res .= $this-> | $res .= $this-> | ||
Line 114: | Line 196: | ||
} | } | ||
$res .= "</" | $res .= "</" | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** private | + | /* |
- | function | + | * private |
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
+ | function | ||
$tag = ""; | $tag = ""; | ||
$res = ""; | $res = ""; | ||
Line 131: | Line 220: | ||
case 30: // | case 30: // | ||
| | ||
- | case 226: //pica two byte char accent like " | + | case 226: //PICA two byte char accent like " |
$ch = substr($str, | $ch = substr($str, | ||
| | ||
Line 140: | Line 229: | ||
} //switch | } //switch | ||
} | } | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getArray($str) { | function getArray($str) { | ||
- | // pica record separator is ascii record separator | + | |
- | | + | $lines = explode(chr(30), |
- | | + | $res = ""; |
- | | + | foreach ($lines as $line) { |
- | | + | $in1 = ltrim($line); |
- | | + | $ch1 = substr($in1, |
- | | + | // first char between 0-9 |
- | | + | if (ord($ch1) >47 && ord($ch1)< |
- | $pos = strpos($in1, | + | |
- | $key = substr($in1, | + | |
- | $val = substr($in1, | + | |
- | $val = $this->decodePica_array($val); | + | |
- | $pica_array[$key] = $val; | + | |
- | | + | } else { |
- | | + | // not valid |
- | | + | } |
- | | + | } |
- | | + | $res = $pica_array; |
- | | + | |
+ | // return result | ||
+ | | ||
} | } | ||
- | /** private | + | /* |
+ | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
+ | function getArrayNice($array_raw) { | ||
+ | // if $array_raw is empty just return | ||
+ | if (empty($array_raw)) return ""; | ||
+ | // make variable name handier | ||
+ | $record = $array_raw; | ||
+ | |||
+ | // get global, user-defineable variable $filter_nice | ||
+ | global $filter_nice; | ||
+ | |||
+ | // type | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | // type w/o kind of record | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // author | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | // editor | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // title | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // series | ||
+ | if ((!empty($record[' | ||
+ | $res[' | ||
+ | | ||
+ | } | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // address, especially city | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | // publisher | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // edition | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | // year | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | // Erscheinungsverlauf | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // pages | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // ISBNs | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // ISSN | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // DNB Number | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // OCLC Number | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // Foreign Data Identification Number | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // ZDB identification number | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // PPN | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // Link | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // Table of Contents | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // DDC | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // RVK | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // EZB link | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | // return result | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getCode($ch) { | function getCode($ch) { | ||
$xx = ord($ch); | $xx = ord($ch); | ||
Line 177: | Line 447: | ||
// case 62: return " | // case 62: return " | ||
case 62: return "& | case 62: return "& | ||
- | case 64: return ""; | + | case 64: return ""; |
case 209: return " | case 209: return " | ||
case 210: return " | case 210: return " | ||
Line 193: | Line 463: | ||
} | } | ||
- | /** private | + | /* |
- | an accent sign */ | + | * private |
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | **/ | ||
function getCode2($ch) { | function getCode2($ch) { | ||
| | ||
Line 210: | Line 485: | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by Picappn-> | ||
+ | | ||
function getDublinCore($str) { | function getDublinCore($str) { | ||
$res = $this-> | $res = $this-> | ||
Line 235: | Line 514: | ||
$res .= "< | $res .= "< | ||
$res .="</ | $res .="</ | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by Picappn-> | ||
+ | | ||
function getPicaPlus($str) { | function getPicaPlus($str) { | ||
$res = $this-> | $res = $this-> | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getTagName($ch) { | function getTagName($ch) { | ||
if (ord($ch) >47 && ord($ch)< | if (ord($ch) >47 && ord($ch)< | ||
Line 255: | Line 547: | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by PicaRecord-> | ||
+ | * Picappn-> | ||
+ | **/ | ||
function getXmlData($str) { | function getXmlData($str) { | ||
- | // pica record separator is ascii record separator | + | |
- | | + | $lines = explode(chr(30), |
- | | + | |
- | | + | // define $res |
- | | + | |
- | | + | |
- | | + | // check each element of array |
- | | + | |
- | $pos = strpos($in1, | + | $in1 = ltrim($line); |
- | $key = substr($in1, | + | $ch1 = substr($in1, |
- | $val = substr($in1, | + | // first char between 0-9 |
- | $val = $this-> | + | if (ord($ch1) >47 && ord($ch1)< |
- | //$res .= " | + | |
- | $res .= "< | + | |
- | //side effect to scan dublin core elements | + | |
- | $this-> | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | } else { |
+ | //not valid | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // return result | ||
+ | | ||
} | } | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function readData($key, | function readData($key, | ||
// | // | ||
Line 343: | Line 651: | ||
break; | break; | ||
case ' | case ' | ||
- | //source : A related resource from which the described is derived. | + | // source : A related resource from which the described is derived. |
$this-> | $this-> | ||
- | // | ||
break; | break; | ||
case ' | case ' | ||
Line 379: | Line 686: | ||
break; | break; | ||
case ' | case ' | ||
- | //type The nature or genre of the resource. | + | // type The nature or genre of the resource. |
$this-> | $this-> | ||
break; | break; | ||
Line 388: | Line 695: | ||
} | } | ||
- | /** public | + | /* |
- | | + | * public |
- | | + | |
+ | | ||
+ | * Used by unClient.php | ||
+ | * **comment out if using PHP4** | ||
+ | **/ | ||
function readDublinCore($str) { | function readDublinCore($str) { | ||
- | $doc = new DomDocument(); | + | |
- | | + | $doc -> loadXML($str); |
- | | + | $xp = new DomXPath($doc); |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | |
+ | // return result | ||
+ | | ||
} | } | ||
- | /** public | + | /* |
- | // | + | * public |
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | **/ | ||
/* | /* | ||
function readRDF_DC($str) { | function readRDF_DC($str) { | ||
- | $doc = new DomDocument(); | + | |
- | | + | $doc -> loadXML($str); |
- | | + | $xp = new DomXPath($doc); |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | $this-> |
- | | + | |
+ | // return result | ||
+ | | ||
} | } | ||
*/ | */ | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function readTag($val, | function readTag($val, | ||
$x = strpos($val,"<" | $x = strpos($val,"<" | ||
Line 447: | Line 772: | ||
} | } | ||
- | /** public | + | /* |
- | // client functionality | + | * public |
+ | | ||
+ | | ||
+ | * used by unClient.php | ||
+ | | ||
function readXmlData($str) { | function readXmlData($str) { | ||
| | ||
Line 468: | Line 797: | ||
} | } | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function transcribe_pica_rec($str) { | function transcribe_pica_rec($str) { | ||
| | ||
Line 475: | Line 809: | ||
} | } | ||
- | /** private | + | /* |
+ | * private | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function transcribe_pica_utf8($str) { | function transcribe_pica_utf8($str) { | ||
| | ||
Line 482: | Line 821: | ||
)); | )); | ||
} | } | ||
- | } //end class PicaRecord | + | } |
+ | |||
+ | /* | ||
+ | | ||
+ | **/ | ||
- | /** get a pica record via pica xml web interface and return */ | + | /* |
+ | * class Picappn | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
class Picappn { | class Picappn { | ||
- | // require php5-curl | + | // |
var $opac; | var $opac; | ||
var $url; | var $url; | ||
Line 492: | Line 851: | ||
var $myself; | var $myself; | ||
- | | + | // a picarecord |
+ | var $prec; | ||
- | //constructor | + | /* |
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function Picappn() { | function Picappn() { | ||
- | //probably localhost on a typical pica psi production system | + | // get global user-defineable $opac_url |
global $opac_url; | global $opac_url; | ||
+ | |||
+ | // preset some attributes | ||
$this-> | $this-> | ||
$this-> | $this-> | ||
+ | |||
+ | // instantiate new PicaRecord() | ||
$this-> | $this-> | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function convOutput($array, | function convOutput($array, | ||
+ | // check if $array not empty, otherwise just return | ||
if (empty($array)) return ""; | if (empty($array)) return ""; | ||
+ | |||
+ | // check if $subfield is given, otherwise just return category | ||
if (!empty($subfield)) { | if (!empty($subfield)) { | ||
if (empty($array[$category][$subfield])) return ""; | if (empty($array[$category][$subfield])) return ""; | ||
- | | + | |
} else { | } else { | ||
if (empty($array[$category])) return ""; | if (empty($array[$category])) return ""; | ||
- | | + | |
} | } | ||
- | | + | |
+ | // return result | ||
+ | | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function convOutputNice($array_nice, | function convOutputNice($array_nice, | ||
+ | // check if $array_nice not empty, otherwise just return | ||
if (empty($array_nice)) return ""; | if (empty($array_nice)) return ""; | ||
+ | // check if $array_nice[$key] not empty, otherwise just return | ||
if (empty($array_nice[$key])) return ""; | if (empty($array_nice[$key])) return ""; | ||
+ | |||
+ | // build result | ||
$res = $array_text[$key].$prefix.$array_nice[$key].$suffix; | $res = $array_text[$key].$prefix.$array_nice[$key].$suffix; | ||
- | | + | |
+ | // return result | ||
+ | | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getArray() { | function getArray() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // build result | ||
$res = $this-> | $res = $this-> | ||
$res = $this-> | $res = $this-> | ||
- | return $res; | ||
- | } | ||
- | |||
- | /** public -- return array with speaking keys */ | ||
- | function getArrayNice($array_raw) { | ||
- | if (empty($array_raw)) return ""; | ||
- | $record = $array_raw; | ||
- | |||
- | global $filter_nice; | ||
- | |||
- | //Type | ||
- | $res[' | ||
- | //Author | + | // |
- | $res[' | + | |
- | //Editor | + | |
- | $res[' | + | |
- | + | ||
- | //Title | + | |
- | $res[' | + | |
- | + | ||
- | //Series | + | |
- | $res[' | + | |
- | + | ||
- | //Address, especially city | + | |
- | $res[' | + | |
- | // | + | |
- | $res[' | + | |
- | //Edition | + | |
- | $res[' | + | |
- | //Year | + | |
- | $res[' | + | |
- | + | ||
- | //ISBNs | + | |
- | $res[' | + | |
- | $res[' | + | |
- | + | ||
- | //PPN | + | |
- | $res[' | + | |
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | //used by bibsonomy | + | * public |
+ | | ||
+ | | ||
+ | * Used by Bibsonomy.php | ||
+ | | ||
function getBibsonomy() { | function getBibsonomy() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | // get BibTeX-Record and URL-encode it | ||
$res = $this-> | $res = $this-> | ||
$res = urlencode($res); | $res = urlencode($res); | ||
+ | /* | ||
+ | | ||
+ | | ||
+ | **/ | ||
global $bibsonomy_url; | global $bibsonomy_url; | ||
$res = $bibsonomy_url.$res; | $res = $bibsonomy_url.$res; | ||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by unAPI.php and Picappn-> | ||
+ | | ||
function getBibTex() { | function getBibTex() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // get pica data as array | ||
$record_raw = $this-> | $record_raw = $this-> | ||
- | $record_nice = $this-> | + | |
- | $keys_nice = $this-> | + | |
+ | // get keys name from array | ||
+ | $keys_nice = $record_nice[' | ||
+ | // declare $res | ||
+ | $res = "" | ||
- | //make sure there is only one ISBN | + | // make sure there is only one ISBN, prefer isbn13 to isbn10 |
if (!empty($record_nice[' | if (!empty($record_nice[' | ||
- | if (substr($record_nice[' | + | |
- | //Type | + | |
+ | | ||
+ | **/ | ||
+ | | ||
+ | // type: book | ||
$res = "@book {"; | $res = "@book {"; | ||
- | //create identifier | + | // create identifier |
$res .= $this-> | $res .= $this-> | ||
$res .= $this-> | $res .= $this-> | ||
- | //Author | + | // set the field which are fetched: author |
$i = array(' | $i = array(' | ||
- | ' | + | ' |
+ | // fetch them from array, format and output them | ||
foreach ($i as $j) { | foreach ($i as $j) { | ||
$res .= $this-> | $res .= $this-> | ||
} | } | ||
- | //Call Number | + | // get call number, format and output it |
+ | $res .= $this-> | ||
+ | } elseif (preg_match('/ | ||
+ | // type: journal | ||
+ | $res = "@misc {"; | ||
+ | |||
+ | // create identifier | ||
+ | $res .= $this-> | ||
+ | $res .= $this-> | ||
+ | |||
+ | // set the field which are fetched: title et al. | ||
+ | $i = array(' | ||
+ | |||
+ | // fetch them from array, format and output them | ||
+ | foreach ($i as $j) { | ||
+ | $res .= $this-> | ||
+ | } | ||
+ | |||
+ | // get call number, format and output it | ||
$res .= $this-> | $res .= $this-> | ||
} | } | ||
- | | + | |
+ | // stripping et al. | ||
+ | if (isset($res)) { | ||
+ | // check if last characters of $res are ", | ||
+ | $res = rtrim($res, ", | ||
+ | // trailing element | ||
+ | | ||
+ | } | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** private | + | /* |
+ | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
+ | function getCsv() { | ||
+ | // check if $this->ppn is not the preset value else return emptily | ||
+ | if ($this->ppn == 0) return ""; | ||
+ | |||
+ | // get pica data as array | ||
+ | $record_raw = $this-> | ||
+ | // transform raw to nice array | ||
+ | $record_nice = $this-> | ||
+ | // declare $res | ||
+ | $res = ''; | ||
+ | |||
+ | // set categories to used for CSV | ||
+ | $i = array(' | ||
+ | ' | ||
+ | |||
+ | // fetch them from array, format and output them | ||
+ | foreach ($i as $j) { | ||
+ | $res .= '"' | ||
+ | } | ||
+ | |||
+ | // stripping et al. | ||
+ | if (isset($res)) { | ||
+ | // check if last characters of $res are ", | ||
+ | $res = rtrim($res, " | ||
+ | } | ||
+ | |||
+ | // return result | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getData($ppn) { | function getData($ppn) { | ||
- | //check whether curl-Module is available, if not available use fallback | + | // get global $use_curl as switch for the following conditional |
- | if (function_exists(' | + | global $use_curl; |
+ | |||
+ | // | ||
+ | if (function_exists(' | ||
$ch = curl_init(" | $ch = curl_init(" | ||
curl_setopt($ch, | curl_setopt($ch, | ||
Line 633: | Line 1091: | ||
$res = file_get_contents(" | $res = file_get_contents(" | ||
} | } | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getDublinCore() { | function getDublinCore() { | ||
+ | // retrieve data | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // format data | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getDublinCoreRDF() { | function getDublinCoreRDF() { | ||
+ | // retrieve data | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // put it to some XML structure | ||
$res = $this-> | $res = $this-> | ||
+ | // check if $this-> | ||
if (empty($res)) return ""; | if (empty($res)) return ""; | ||
+ | // format | ||
$res = "<? | $res = "<? | ||
$res .= "< | $res .= "< | ||
Line 676: | Line 1156: | ||
$res .= "</ | $res .= "</ | ||
$res .= "</ | $res .= "</ | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by unAPI.php | ||
+ | | ||
function getJson() { | function getJson() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | // get PICA record as array | ||
$res = $this-> | $res = $this-> | ||
- | //(PHP 5 >= 5.2.0, PECL json >= 1.2.0) | + | // |
$res = json_encode($res); | $res = json_encode($res); | ||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | function | + | * public |
- | //Type | + | |
- | $res[' | + | |
+ | | ||
+ | **/ | ||
+ | function | ||
+ | // check if $this-> | ||
+ | | ||
- | //Author | + | // get pica data as array |
- | $res[' | + | $record_raw |
- | //Editor | + | // transform raw to nice array |
- | $res['editor' | + | $record_nice = $this-> |
+ | // get keys' name from array | ||
+ | $keys_nice = $record_nice['_openurlkev']; | ||
+ | // declare $res | ||
+ | $res = "" | ||
- | //Title | + | // get global, user-defineable variable $rfr_id_hostname |
- | $res[' | + | |
- | //Series | + | // set immutable context objects for OpenURL |
- | $res['series' | + | // version of the ContextObject |
+ | $res .= 'ctx_ver=Z39.88-2004'; | ||
+ | // referrer identifier | ||
+ | $res .= '& | ||
- | //Address, especially city | + | // make sure there is only one ISBN, prefer isbn13 to isbn10 |
- | $res['address' | + | |
- | // | + | |
- | | + | |
- | //Edition | + | |
- | $res[' | + | |
- | //Year | + | |
- | $res[' | + | |
- | //ISBNs | + | // check type and choose right OpenURL-type |
- | $res['isbn10' | + | |
- | $res['isbn13'] = ' | + | // make $keys_nice['title'] more standard compliant |
+ | $keys_nice['title'] = 'rft.btitle'; | ||
- | | + | |
- | $res['ppn' | + | $res .= '& |
- | | + | $res .= '& |
- | } | + | |
- | | + | |
- | function getKeysText() { | + | $i = array('author', 'editor', ' |
- | // | + | ' |
- | | + | |
- | | + | |
- | $res[' | + | |
- | //Editor | + | $record_nice[$j] = urlencode($record_nice[$j]); |
- | | + | $res .= $this-> |
+ | } | ||
+ | | ||
+ | // type: journal/ | ||
+ | $res .= '& | ||
+ | $res .= '& | ||
- | | + | |
- | $res[' | + | $i = array(' |
- | | + | |
- | $res[' | + | |
+ | $record_nice[$j] = urlencode($record_nice[$j]); | ||
+ | $res .= $this-> | ||
+ | } | ||
+ | } | ||
- | //Address, especially city | + | // strip trailing "& |
- | $res[' | + | |
- | | + | $res = rtrim($res, "& |
- | | + | |
- | // | + | |
- | | + | |
- | //Year | + | |
- | | + | |
- | + | ||
- | //ISBNs | + | |
- | $res[' | + | |
- | | + | |
- | //PPN | + | // |
- | $res[' | + | |
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getPicaPlus() { | function getPicaPlus() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // retrieve record | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // format | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // set prefix | ||
$head = "<? | $head = "<? | ||
$head .= "< | $head .= "< | ||
+ | |||
+ | // set suffix | ||
$tail = "</ | $tail = "</ | ||
+ | |||
+ | // return result | ||
return $head.$res.$tail; | return $head.$res.$tail; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getPlain() { | function getPlain() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // retrieve record | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // put to some XML structure | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
- | //used by unapi | + | * public |
+ | | ||
+ | | ||
+ | * Used by unAPI.php | ||
+ | | ||
function getText() { | function getText() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // get pica data as array | ||
$record_raw = $this-> | $record_raw = $this-> | ||
- | $record_nice = $this-> | + | |
- | $keys_nice = $this-> | + | |
+ | // get keys' names from array | ||
+ | $keys_nice = $record_nice[' | ||
+ | // declare $res | ||
$res = ""; | $res = ""; | ||
- | if (substr($record_nice[' | + | |
- | //Type | + | |
- | $res .= "Art: | + | // type: book |
+ | $res .= $keys_nice[' | ||
- | //Author | + | // set the field which are fetched: author et al. |
- | $res .= $this-> | + | $i = array(' |
- | // | + | ' |
- | $res .= $this-> | + | ' |
- | //Title | + | // fetch them from array, format and output them |
- | $res .= $this-> | + | |
+ | | ||
+ | } | ||
- | //Series | + | // call number |
- | $res .= $this->convOutputNice($record_nice, | + | |
+ | $j = 0; | ||
+ | while ( $i <= 99 ) { | ||
+ | if (($i <= 9) && ($j == 0)) { | ||
+ | $j = " | ||
+ | } elseif (($i > 9) && ($j == 0)) { | ||
+ | $j = $i; | ||
+ | } | ||
+ | | ||
+ | $i++; | ||
+ | if ($i <= 9 ) { | ||
+ | $j = " | ||
+ | } else { | ||
+ | $j = $i; | ||
+ | } | ||
+ | if (empty($record_raw[" | ||
+ | } | ||
+ | } elseif (preg_match('/ | ||
+ | // type: journal | ||
+ | $res .= $keys_nice[' | ||
- | //Address, especially city | + | // set the field which are fetched: title et al. |
- | $res .= $this-> | + | $i = array(' |
- | // | + | ' |
- | $res .= $this-> | + | |
- | //Edition | + | |
- | $res .= $this-> | + | |
- | // | + | |
- | $res .= $this-> | + | |
- | //ISBNs | + | // fetch them from array, format and output them |
- | | + | |
- | $res .= $this-> | + | $res .= $this-> |
+ | } | ||
- | //Call Number | + | // call number |
$i = 1; | $i = 1; | ||
$j = 0; | $j = 0; | ||
Line 833: | Line 1383: | ||
if (empty($record_raw[" | if (empty($record_raw[" | ||
} | } | ||
- | |||
- | $res .= $this-> | ||
} | } | ||
+ | |||
+ | // return result | ||
return $res; | return $res; | ||
} | } | ||
- | /** public | + | /* |
+ | * public | ||
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function getXmlData() { | function getXmlData() { | ||
+ | // check if $this-> | ||
if ($this-> | if ($this-> | ||
+ | |||
+ | // retrieve record | ||
$res = $this-> | $res = $this-> | ||
- | | + | |
+ | // put it to some XML structure | ||
+ | | ||
+ | |||
+ | // define prefix | ||
$head = "<? | $head = "<? | ||
//$head .= "< | //$head .= "< | ||
Line 851: | Line 1413: | ||
//$head .= "< | //$head .= "< | ||
$head .= "< | $head .= "< | ||
+ | |||
+ | // define suffix | ||
$tail = "</ | $tail = "</ | ||
+ | |||
+ | // return result | ||
return $head.$res.$tail; | return $head.$res.$tail; | ||
} | } | ||
- | //public | + | /* |
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function setOpac($opac) { | function setOpac($opac) { | ||
$this-> | $this-> | ||
} | } | ||
- | //public | + | /* |
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function setPpn($ppn) { | function setPpn($ppn) { | ||
- | $this-> | + | |
- | $this-> | + | global $pattern_ppn; |
+ | |||
+ | /* | ||
+ | | ||
+ | | ||
+ | **/ | ||
+ | if (preg_match($pattern_ppn, | ||
+ | | ||
+ | $this-> | ||
+ | } else { | ||
+ | // for debugging only | ||
+ | //echo foo; | ||
+ | } | ||
$this-> | $this-> | ||
} | } | ||
+ | } | ||
- | } //end class Picappn | + | /* |
+ | | ||
+ | **/ | ||
- | /* Return result or 404 */ | + | /* |
+ | | ||
+ | | ||
+ | | ||
+ | **/ | ||
function final_result($res, | function final_result($res, | ||
+ | /* if $res is not empty, return it, otherwise act accordingly to unAPI | ||
+ | | ||
+ | **/ | ||
if (!empty($res)) { | if (!empty($res)) { | ||
+ | // send header | ||
header(" | header(" | ||
+ | // return result | ||
echo $res; | echo $res; | ||
} else { | } else { | ||
Line 878: | Line 1476: | ||
} | } | ||
} | } | ||
+ | |||
+ | /* | ||
+ | | ||
+ | **/ | ||
?> | ?> | ||
</ | </ | ||
+ | Former name of this file was [[PicaRecord.php]] |