Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
buechereielektrik:unapi:picarecord.php [2009-12-10 19:42] – nun aber: PicaRecord.php strols | buechereielektrik:unapi:picarecord.php [2009-12-26 14:44] – rosenke | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | + | < |
<?php | <?php | ||
Line 26: | Line 26: | ||
/* Changelog | /* Changelog | ||
- | | + | * |
- | | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
| | ||
| | ||
Line 37: | Line 50: | ||
$opac_url = " | $opac_url = " | ||
- | //$opac_url = " | + | //$opac_url = " |
+ | //$opac_url = " | ||
+ | //$opac_url = " | ||
+ | |||
+ | $bibsonomy_url = " | ||
+ | |||
+ | $filter_nice = array( | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
/** represents a bibliographic data record from oclc/pica LBS | /** represents a bibliographic data record from oclc/pica LBS | ||
Line 105: | Line 127: | ||
$ch = substr($str, | $ch = substr($str, | ||
$tag = $this-> | $tag = $this-> | ||
+ | | ||
| | ||
- | |||
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, | ||
- | $res .= $this-> | + | $res[$tag] |
| | ||
- | |||
default: | default: | ||
| | ||
| | ||
} //switch | } //switch | ||
- | |||
} | } | ||
return $res; | return $res; | ||
Line 195: | Line 214: | ||
function getDublinCore($str) { | function getDublinCore($str) { | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | if (empty($res)) return ""; | ||
$res = "<? | $res = "<? | ||
Line 364: | Line 385: | ||
break; | break; | ||
} | } | ||
- | | + | //return $res; |
} | } | ||
/** public -- parse dublin core data */ | /** public -- parse dublin core data */ | ||
//client functionality | //client functionality | ||
+ | // comment out if using PHP4 | ||
function readDublinCore($str) { | function readDublinCore($str) { | ||
$doc = new DomDocument(); | $doc = new DomDocument(); | ||
Line 393: | Line 415: | ||
/** public -- parse dublin core data */ | /** public -- parse dublin core data */ | ||
// experimental, | // experimental, | ||
+ | /* | ||
function readRDF_DC($str) { | function readRDF_DC($str) { | ||
$doc = new DomDocument(); | $doc = new DomDocument(); | ||
Line 414: | Line 437: | ||
| | ||
} | } | ||
+ | */ | ||
/** private -- read tag content from string */ | /** private -- read tag content from string */ | ||
Line 477: | Line 501: | ||
$this-> | $this-> | ||
$this-> | $this-> | ||
+ | } | ||
+ | |||
+ | /** public -- convert for output using raw array data*/ | ||
+ | function convOutput($array, | ||
+ | if (empty($array)) return ""; | ||
+ | if (!empty($subfield)) { | ||
+ | if (empty($array[$category][$subfield])) return ""; | ||
+ | $res = $text.$separator.$array[$category][$subfield].$suffix; | ||
+ | } else { | ||
+ | if (empty($array[$category])) return ""; | ||
+ | $res = $text.$separator.$array[$category].$suffix; | ||
+ | } | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- convert for output using nice array data*/ | ||
+ | function convOutputNice($array_nice, | ||
+ | if (empty($array_nice)) return ""; | ||
+ | if (empty($array_nice[$key])) return ""; | ||
+ | $res = $array_text[$key].$prefix.$array_nice[$key].$suffix; | ||
+ | return $res; | ||
} | } | ||
Line 484: | Line 529: | ||
$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[' | ||
+ | //Publisher | ||
+ | $res[' | ||
+ | //Edition | ||
+ | $res[' | ||
+ | //Year | ||
+ | $res[' | ||
+ | |||
+ | //ISBNs | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | //PPN | ||
+ | $res[' | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- return BibTex record from pica data */ | ||
+ | //used by bibsonomy | ||
+ | function getBibsonomy() { | ||
+ | if ($this-> | ||
+ | |||
+ | $res = $this-> | ||
+ | $res = urlencode($res); | ||
+ | |||
+ | global $bibsonomy_url; | ||
+ | $res = $bibsonomy_url.$res; | ||
+ | |||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- return BibTex record from pica data */ | ||
+ | //used by unapi | ||
+ | function getBibTex() { | ||
+ | if ($this-> | ||
+ | $record_raw = $this-> | ||
+ | $record_nice = $this-> | ||
+ | $keys_nice = $this-> | ||
+ | |||
+ | //make sure there is only one ISBN | ||
+ | if (!empty($record_nice[' | ||
+ | |||
+ | if (substr($record_nice[' | ||
+ | //Type | ||
+ | $res = "@book {"; | ||
+ | |||
+ | //create identifier | ||
+ | $res .= $this-> | ||
+ | $res .= $this-> | ||
+ | |||
+ | //Author et al. | ||
+ | $i = array(' | ||
+ | ' | ||
+ | |||
+ | foreach ($i as $j) { | ||
+ | $res .= $this-> | ||
+ | } | ||
+ | |||
+ | //Call Number | ||
+ | $res .= $this-> | ||
+ | } | ||
+ | $res .= " | ||
return $res; | return $res; | ||
} | } | ||
Line 489: | Line 621: | ||
/** private -- get data via pica xml interface */ | /** private -- get data via pica xml interface */ | ||
function getData($ppn) { | function getData($ppn) { | ||
- | $ch = curl_init(" | + | |
- | curl_setopt($ch, | + | if (function_exists(' |
- | curl_setopt($ch, | + | |
- | // | + | curl_setopt($ch, |
- | curl_setopt($ch, | + | curl_setopt($ch, |
- | $res = curl_exec($ch); | + | // |
- | curl_close($ch); | + | curl_setopt($ch, |
+ | $res = curl_exec($ch); | ||
+ | curl_close($ch); | ||
+ | } else { | ||
+ | $res = file_get_contents(" | ||
+ | } | ||
return $res; | return $res; | ||
} | } | ||
Line 510: | Line 647: | ||
$res = $this-> | $res = $this-> | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | if (empty($res)) return ""; | ||
$res = "<? | $res = "<? | ||
Line 519: | Line 658: | ||
| | ||
$res .= "< | $res .= "< | ||
- | .$this-> | + | .$this-> |
$res .= "< | $res .= "< | ||
$res .= "< | $res .= "< | ||
Line 540: | Line 679: | ||
} | } | ||
- | /** public -- return | + | /** public -- return |
- | function | + | //used by unapi |
+ | function | ||
if ($this-> | if ($this-> | ||
- | | + | |
- | $res = $this->prec-> | + | |
- | $head = "<? | + | //(PHP 5 >= 5.2.0, PECL json >= 1.2.0) |
- | //$head .= "< | + | $res = json_encode($res); |
- | //$head .= "< | + | |
- | //$head .= "< | + | return $res; |
- | //$head .= "< | + | } |
- | //$head .= "< | + | |
- | $head .= "< | + | /** public |
- | $tail = "</record> | + | function getKeysBibTex() { |
- | | + | //Type |
+ | | ||
+ | |||
+ | //Author | ||
+ | $res[' | ||
+ | //Editor | ||
+ | $res[' | ||
+ | |||
+ | //Title | ||
+ | | ||
+ | |||
+ | //Series | ||
+ | | ||
+ | |||
+ | //Address, especially city | ||
+ | $res[' | ||
+ | // | ||
+ | | ||
+ | //Edition | ||
+ | | ||
+ | //Year | ||
+ | | ||
+ | |||
+ | //ISBNs | ||
+ | | ||
+ | $res[' | ||
+ | |||
+ | //PPN | ||
+ | | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public | ||
+ | function getKeysText() { | ||
+ | //Type | ||
+ | $res[' | ||
+ | |||
+ | //Author | ||
+ | | ||
+ | //Editor | ||
+ | $res[' | ||
+ | |||
+ | //Title | ||
+ | | ||
+ | |||
+ | //Series | ||
+ | | ||
+ | |||
+ | //Address, especially city | ||
+ | $res[' | ||
+ | // | ||
+ | $res[' | ||
+ | //Edition | ||
+ | | ||
+ | //Year | ||
+ | $res[' | ||
+ | |||
+ | | ||
+ | $res[' | ||
+ | $res[' | ||
+ | |||
+ | //PPN | ||
+ | | ||
+ | return | ||
} | } | ||
Line 579: | Line 782: | ||
function getText() { | function getText() { | ||
if ($this-> | if ($this-> | ||
- | $record | + | $record_raw |
- | $res .= "PPN:\t".$record['003@' | + | |
+ | $keys_nice = $this-> | ||
+ | $res = ""; | ||
+ | |||
+ | if (substr($record_nice[' | ||
+ | //Type | ||
+ | | ||
+ | |||
+ | //Author | ||
+ | $res .= $this-> | ||
+ | //Editor | ||
+ | $res .= $this-> | ||
+ | |||
+ | //Title | ||
+ | $res .= $this-> | ||
+ | |||
+ | //Series | ||
+ | $res .= $this-> | ||
+ | |||
+ | //Address, especially city | ||
+ | $res .= $this-> | ||
+ | // | ||
+ | $res .= $this-> | ||
+ | //Edition | ||
+ | $res .= $this-> | ||
+ | //Year | ||
+ | $res .= $this-> | ||
+ | |||
+ | //ISBNs | ||
+ | $res .= $this-> | ||
+ | $res .= $this-> | ||
+ | |||
+ | //Call Number | ||
+ | $i = 1; | ||
+ | $j = 0; | ||
+ | while ( $i <= 99 ) { | ||
+ | if (($i <= 9) && ($j == 0)) { | ||
+ | $j = " | ||
+ | } elseif (($i > 9) && ($j == 0)) { | ||
+ | $j = $i; | ||
+ | } | ||
+ | $res .= $this-> | ||
+ | $i++; | ||
+ | if ($i <= 9 ) { | ||
+ | $j = " | ||
+ | } else { | ||
+ | $j = $i; | ||
+ | } | ||
+ | if (empty($record_raw[" | ||
+ | } | ||
+ | |||
+ | $res .= $this-> | ||
+ | } | ||
return $res; | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- return xml formated pica record */ | ||
+ | function getXmlData() { | ||
+ | if ($this-> | ||
+ | $res = $this-> | ||
+ | $res = $this-> | ||
+ | $head = "<? | ||
+ | //$head .= "< | ||
+ | //$head .= "< | ||
+ | //$head .= "< | ||
+ | //$head .= "< | ||
+ | //$head .= "< | ||
+ | $head .= "< | ||
+ | $tail = "</ | ||
+ | return $head.$res.$tail; | ||
} | } | ||
Line 597: | Line 868: | ||
} //end class Picappn | } //end class Picappn | ||
+ | |||
+ | /* Return result or 404 */ | ||
+ | function final_result($res, | ||
+ | if (!empty($res)) { | ||
+ | header(" | ||
+ | echo $res; | ||
+ | } else { | ||
+ | header(' | ||
+ | } | ||
+ | } | ||
?> | ?> | ||
</ | </ |