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-13 22:22] – format bibtex, text; function convOutput strols | buechereielektrik:unapi:picarecord.php [2009-12-26 14:44] – rosenke | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | + | < |
<?php | <?php | ||
Line 27: | Line 27: | ||
/* Changelog | /* Changelog | ||
* | * | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
| | ||
| | ||
Line 44: | Line 53: | ||
//$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 111: | 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 201: | Line 214: | ||
function getDublinCore($str) { | function getDublinCore($str) { | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | if (empty($res)) return ""; | ||
$res = "<? | $res = "<? | ||
Line 370: | 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 399: | 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 420: | Line 437: | ||
| | ||
} | } | ||
+ | */ | ||
/** private -- read tag content from string */ | /** private -- read tag content from string */ | ||
Line 485: | Line 503: | ||
} | } | ||
- | /** public -- convert for output */ | + | /** public -- convert for output |
function convOutput($array, | function convOutput($array, | ||
if (empty($array)) return ""; | if (empty($array)) return ""; | ||
Line 495: | Line 513: | ||
$res = $text.$separator.$array[$category].$suffix; | $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; | return $res; | ||
} | } | ||
Line 503: | 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; | return $res; | ||
} | } | ||
/** public -- return BibTex record from pica data */ | /** public -- return BibTex record from pica data */ | ||
- | //used by unapi | + | //used by bibsonomy |
- | function | + | function |
if ($this-> | if ($this-> | ||
- | $record = $this-> | ||
- | if (substr($record[' | ||
- | //Type | ||
- | $res .= "@book {"; | ||
- | //create identifier | + | |
- | | + | $res = urlencode($res); |
- | $res .= $this-> | + | |
- | //Author | + | global |
- | | + | $res = $bibsonomy_url.$res; |
- | // | + | |
- | | + | |
- | //Title | + | return |
- | | + | } |
- | | + | |
- | $res .= $this->convOutput($record," | + | // |
+ | function getBibTex() { | ||
+ | if ($this-> | ||
+ | $record_raw | ||
+ | $record_nice | ||
+ | $keys_nice = $this-> | ||
- | | + | |
- | $res .= $this-> | + | |
- | // | + | |
- | $res .= $this-> | + | |
- | //Edition | + | |
- | $res .= $this-> | + | |
- | //Year | + | |
- | $res .= $this-> | + | |
- | //ISBNs | + | if (substr($record_nice['type'], 0, 2) == "Aa" |
- | $res .= $this-> | + | // |
- | $res .= $this-> | + | |
- | | + | |
- | $i = 0; | + | $res .= $this-> |
- | while ( $i <= 99 ) { | + | $res .= $this-> |
- | if ($i <= 9 ) { | + | |
- | $j = "0".$i; | + | //Author et al. |
- | } else { | + | |
- | $j = $i; | + | ' |
- | } | + | |
- | | + | foreach ($i as $j) { |
- | $i++; | + | |
- | } | + | |
} | } | ||
+ | |||
+ | //Call Number | ||
+ | $res .= $this-> | ||
+ | } | ||
+ | $res .= " | ||
return $res; | return $res; | ||
} | } | ||
Line 560: | 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 581: | Line 647: | ||
$res = $this-> | $res = $this-> | ||
$res = $this-> | $res = $this-> | ||
+ | |||
+ | if (empty($res)) return ""; | ||
$res = "<? | $res = "<? | ||
Line 590: | Line 658: | ||
| | ||
$res .= "< | $res .= "< | ||
- | .$this-> | + | .$this-> |
$res .= "< | $res .= "< | ||
$res .= "< | $res .= "< | ||
Line 608: | Line 676: | ||
$res .= "</ | $res .= "</ | ||
$res .= "</ | $res .= "</ | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- return JSON record from pica data */ | ||
+ | //used by unapi | ||
+ | function getJson() { | ||
+ | if ($this-> | ||
+ | |||
+ | $res = $this-> | ||
+ | //(PHP 5 >= 5.2.0, PECL json >= 1.2.0) | ||
+ | $res = json_encode($res); | ||
+ | |||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | /** public -- return array with key names for BibTex*/ | ||
+ | function getKeysBibTex() { | ||
+ | //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 array with key names for text*/ | ||
+ | function getKeysText() { | ||
+ | //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; | return $res; | ||
} | } | ||
Line 634: | Line 782: | ||
function getText() { | function getText() { | ||
if ($this-> | if ($this-> | ||
- | | + | |
- | if (substr($record[' | + | |
- | //Type | + | $keys_nice |
- | $res .= "Art: | + | $res = ""; |
- | //Author | + | if (substr($record_nice['type'], 0, 2) == "Aa" |
- | $res .= $this-> | + | //Type |
- | //Editor | + | $res .= "Art:\t\tMonographie\n"; |
- | $res .= $this-> | + | |
- | | + | |
- | $res .= $this->convOutput($record,"Titel",": | + | $res .= $this->convOutputNice($record_nice, |
+ | //Editor | ||
+ | $res .= $this-> | ||
- | | + | |
- | $res .= $this->convOutput($record,"Schriftenreihe",": | + | $res .= $this->convOutputNice($record_nice, |
- | | + | |
- | $res .= $this->convOutput($record," | + | $res .= $this->convOutputNice($record_nice,$keys_nice,"series",": |
- | // | + | |
- | $res .= $this-> | + | |
- | //Edition | + | |
- | $res .= $this-> | + | |
- | //Year | + | |
- | $res .= $this-> | + | |
- | | + | |
- | $res .= $this->convOutput($record,"ISBN-10",": | + | $res .= $this->convOutputNice($record_nice, |
- | $res .= $this->convOutput($record,"ISBN-13",": | + | // |
+ | $res .= $this-> | ||
+ | // | ||
+ | | ||
+ | //Year | ||
+ | $res .= $this-> | ||
- | | + | |
- | $i = 0; | + | $res .= $this-> |
- | while ( $i <= 99 ) { | + | $res .= $this->convOutputNice($record_nice, |
- | if ($i <= 9 ) { | + | |
- | $j = "0".$i; | + | |
- | } else { | + | |
- | $j = $i; | + | |
- | } | + | |
- | | + | |
- | $i++; | + | |
- | } | + | |
- | | + | //Call Number |
+ | $i = 1; | ||
+ | $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[" | ||
} | } | ||
+ | |||
+ | $res .= $this-> | ||
+ | } | ||
return $res; | return $res; | ||
} | } |