Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
buechereielektrik:unapi:unapi.inc.php [2010-01-13 21:12] – Added comments. Added further mappings in getArrayNice. rosenkebuechereielektrik:unapi:unapi.inc.php [2010-03-03 17:13] strols
Line 9: Line 9:
   - Picappn   - Picappn
  *  *
- *  The functions follow+ *  These functions follow
   - final_result   - final_result
  *  *
Line 19: Line 19:
  *  *
   Copyright 2008 2009 Goetz Hatop <hatop@ub.uni-marburg.de>.   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   Copyright 2009 2010 Stephan Rosenke <rosenke@ulb.tu-darmstadt.de> or
-  <r01-551@r0s.de>.+  <r01-551@r0s.de>. See also <http://r0s.de/unapi>.
  */  */
  
Line 46: Line 46:
   Version   Version
  *  *
-  0.5+  0.7
  */  */
  
Line 52: Line 52:
   Changelog   Changelog
  *  *
-  20100113: Added comments. Added further mappings in getArrayNice. + *  20100303: Added check of $use_curl as additional switch for de- 
-  20100112: Added further mappings in getArrayNice.+ * activating curl. 
 +  20100219: Added function "getCsv()" to class "Picappn"
 + * Renamend keys "RVK" to "rvk" and "DDC" to "ddc"
 +  20100131: Added (e)Journals to "getBibTex()", "getOpenUrlKev()" and 
 + * "getText()" in class "Picappn"
 +  20100127: Added link in copyright. 
 +  20100126: Transfered "getArrayNice()" from class "Picappn" to 
 + * "PicaRecord". Removed dead code. Added comments. 
 +  20100125: Added comments. 
 + * Renamed "decodePica_array()" to "decodePicaArray()" in class 
 + * "PicaRecord"
 + *  20100113: Added comments. Added further mappings in "getArrayNice()"
 +  20100112: Added further mappings in "getArrayNice()".
  * Extended types for monographies.  * Extended types for monographies.
-  20100111: Added function getOpenUrlKev() to class "Picappn"+  20100111: Added function "getOpenUrlKev()to class "Picappn"
- * Removed functions "getKeysText" and "getKeysBibTex" from class + * Removed functions "getKeysText()" and "getKeysBibTex()" from 
- * "Picappn".+ * class "Picappn".
   20100110: Added input sanitising for $ppn.   20100110: Added input sanitising for $ppn.
   20100109: Some style improvements, added comments.   20100109: Some style improvements, added comments.
   20091220: Check whether curl-Module is available, if not use   20091220: Check whether curl-Module is available, if not use
- * file_get_contents().+ * "file_get_contents()".
  * Some minor bugfixes.  * Some minor bugfixes.
-  20091215: Added function "getJson" to class "Picappn"+  20091215: Added function "getJson()" to class "Picappn"
- * Made ISBN in getBibTex() unique. + * Made ISBN in "getBibTex()unique. 
- * Filtered some characters in getArrayNice(). + * Filtered some characters in "getArrayNice()"
-  20091214: Added function "convOutputNice", "getArrayNice", "getBibsonomy", +  20091214: Added function "convOutputNice()", "getArrayNice()", 
- * "getKeysText" and "getKeysBibTex" to class "Picappn".+              "getBibsonomy()", getKeysText()" and "getKeysBibTex()" to class 
 +              "Picappn".
  * Handled empty records for dc and rdf.  * Handled empty records for dc and rdf.
-  20091213: Added function "convOutput" to class "Picappn".+  20091213: Added function "convOutput()" to class "Picappn".
  * Defined text-format.  * Defined text-format.
  * Defined bibtex-format.  * Defined bibtex-format.
-  20091211: Added function "final_result".+  20091211: Added function "final_result()".
   20091210: Put class "Picappn" to PicaRecord.php.   20091210: Put class "Picappn" to PicaRecord.php.
  * Ordered functions alphabetically.  * Ordered functions alphabetically.
- * Added functions "getArray", "getPlain" and  "getText" to class + * Added functions "getArray()", "getPlain()" and  "getText()" to 
- * "Picappn"+              class "Picappn"
- * Added functions "decodePicaArray", "getArray" and "getPlain" to + * Added functions "decodePicaArray()", "getArray()" and 
- * class "PicaRecord".+ * "getPlain()" to class "PicaRecord".
   20091210: Started with Goetz Hatop's version of 2009-12-08.   20091210: Started with Goetz Hatop's version of 2009-12-08.
  */  */
Line 93: Line 106:
  */  */
  
-//  URL-prefix for XML-interface +//  URL-prefix for XML interface 
-$opac_url = 'http://pica1l.lhb.tu-darmstadt.de/DB=LHBDA/XML=1.0/PPN?PPN=';+$opac_url = 'http://example.com/DB=1/XML=1.0/PPN?PPN=';
  
-//  URL-prefix for Bibsonomy's BibTeX-import+//  URL-prefix for Bibsonomy's BibTeX import
 $bibsonomy_url = 'http://www.bibsonomy.org/BibtexHandler?requTask=upload&selection='; $bibsonomy_url = 'http://www.bibsonomy.org/BibtexHandler?requTask=upload&selection=';
  
Line 112: Line 125:
  
 /* /*
- * + ******************************************************************************
-  DO NOT MESS BEHIND THIS LINE +  DO NOT MESS BEHIND THIS LINE                                               * 
- *+ *******************************************************************************
  */  */
  
 /* /*
   class PicaRecord   class PicaRecord
-  represents a bibliographic data record from oclc/pica LBS +  represents a bibliographic data record from OCLC/PICA LBS, puts record to a 
 +  XML structure or an array  
 **/ **/
 class PicaRecord { class PicaRecord {
-  // 15 dublin core elements http://dublincore.org/documents/dces/+  //  15 dublin core elements http://dublincore.org/documents/dces/
   var $contributor, $coverage, $creator, $date, $description, $format;   var $contributor, $coverage, $creator, $date, $description, $format;
   var $identifier, $language, $publisher, $related, $rights, $source;   var $identifier, $language, $publisher, $related, $rights, $source;
   var $subject, $title, $type;   var $subject, $title, $type;
-  // 1 for me+  //  1 for me
   var $signatur;   var $signatur;
  
-  / set some default values+  /
 +    constructor 
 +    class PicaRecord 
 +    PHP5 or later should use '__construct()' 
 +  **/
   function PicaRecord() {   function PicaRecord() {
      //  default values      //  default values
Line 139: Line 157:
   /*   /*
     private     private
-    make pica data behave well+   *  class PicaRecord 
 +   *  make PICA data behave well and convert them to a XML structure 
 +    Used by PicaRecord->getXmlData
   **/   **/
   function decodePica($str) {   function decodePica($str) {
Line 164: Line 184:
              break;              break;
  
-          case 226: //pica two byte char accent like "é";+          case 226: //PICA two byte char accent like "é";
              $ch = substr($str,++$i,1); // read one char ahead              $ch = substr($str,++$i,1); // read one char ahead
              $res .= $this->getCode2($ch);              $res .= $this->getCode2($ch);
Line 176: Line 196:
     }     }
     $res .= "</".$tag.">";     $res .= "</".$tag.">";
 +
 +    //  return result
     return $res;     return $res;
   }   }
Line 181: Line 203:
   /*   /*
     private     private
-    make pica data behave well and put them to an array+   *  class PicaRecord 
 +   *  make PICA data behave well and put them to an array 
 +    Used by PicaRecord->getArray
   **/   **/
-  function decodePica_array($str) {+  function decodePicaArray($str) {
     $tag = "";     $tag = "";
     $res = "";     $res = "";
Line 196: Line 220:
           case 30: //information separator two, another field to follow           case 30: //information separator two, another field to follow
              break;              break;
-          case 226: //pica two byte char accent like "é";+          case 226: //PICA two byte char accent like "é";
              $ch = substr($str,++$i,1); // read one char ahead              $ch = substr($str,++$i,1); // read one char ahead
              $res[$tag] .= $this->getCode2($ch);              $res[$tag] .= $this->getCode2($ch);
Line 205: Line 229:
         } //switch         } //switch
     }     }
 +
 +    //  return result
     return $res;     return $res;
   }   }
Line 210: Line 236:
   /*   /*
     public     public
-    transform raw pica data to array+   *  class PicaRecord 
 +   *  transform raw PICA data to array 
 +    Used by Picappn->getArray
   **/   **/
   function getArray($str) {   function getArray($str) {
-     // pica record separator is ascii record separator +    //  PICA record separator is ascii record separator 
-     $lines = explode(chr(30), $str); +    $lines = explode(chr(30), $str); 
-     $res = ""; +    $res = ""; 
-     foreach ($lines as $line) { +    foreach ($lines as $line) { 
-       $in1 = ltrim($line); +      $in1 = ltrim($line); 
-       $ch1 = substr($in1,1,1); +      $ch1 = substr($in1,1,1); 
-       //first char between 0-9 +      //  first char between 0-9 
-       if (ord($ch1) >47 && ord($ch1)<58) { +      if (ord($ch1) >47 && ord($ch1)<58) { 
-          $pos = strpos($in1, ' '); +         $pos = strpos($in1, ' '); 
-          $key = substr($in1,0,$pos); +         $key = substr($in1,0,$pos); 
-          $val = substr($in1,$pos+1); +         $val = substr($in1,$pos+1); 
-          $val = $this->decodePica_array($val); +         $val = $this->decodePicaArray($val); 
-          $pica_array[$key] = $val; +         $pica_array[$key] = $val; 
-       } else { +      } else { 
-         //not valid +        //  not valid 
-       +      
-     +    
-     $res = $pica_array; +    $res = $pica_array; 
-     return $res;+ 
 +    //  return result 
 +    return $res; 
 +  } 
 + 
 +  /* 
 +    public 
 +    class PicaRecord 
 +    return bibliographic data in array with speaking keys 
 +    Used by Picappn->{getBibTex,getCsv,getOpenUrlKev,getText} 
 +  **/ 
 +  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['type'] = strtr($record['002@']['x0'], $filter_nice); 
 +    $res['_bibtex']['type'] = ''; 
 +    $res['_openurlkev']['type'] = 'rft.genre'; 
 +    $res['_text']['type'] = 'Art'; 
 +    //  type w/o kind of record 
 +    $res['twokr'] = substr($res['type'], 0, 2); 
 +    $res['_bibtex']['twokr'] = ''; 
 +    $res['_openurlkev']['twokr'] = ''; 
 +    $res['_text']['twokr'] = ''; 
 + 
 +    //  author 
 +    $res['author'] = strtr($record['028A']['x8'], $filter_nice); 
 +    $res['author'] = rtrim($res['author']); 
 +    $res['_bibtex']['author'] = '  author'; 
 +    $res['_openurlkev']['author'] = 'rft.au'; 
 +    $res['_text']['author'] = 'Autor'; 
 +    //  editor 
 +    $res['editor'] = strtr($record['028C']['x8'], $filter_nice); 
 +    $res['editor'] = rtrim($res['editor']); 
 +    $res['_bibtex']['editor'] = '  editor'; 
 +    $res['_openurlkev']['editor'] = 'rft.au'; 
 +    $res['_text']['editor'] = 'Herausgeber'; 
 + 
 +    //  title 
 +    $res['title'] = strtr($record['021A']['a'], $filter_nice); 
 +    $res['_bibtex']['title'] = '  title'; 
 +    $res['_openurlkev']['title'] = 'rft.title'; 
 +    $res['_text']['title'] = 'Titel'; 
 + 
 +    //  series 
 +    if ((!empty($record['036F']['x8'])) || (!empty($record['036F']['l']))) { 
 +      $res['series'] = strtr($record['036F']['x8'], $filter_nice)." ". 
 +       strtr($record['036F']['l'], $filter_nice); 
 +    } 
 +    $res['_bibtex']['series'] = '  series'; 
 +    $res['_openurlkev']['series'] = 'rft.series'; 
 +    $res['_text']['series'] = 'Schriftenreihe'; 
 + 
 +    //  address, especially city 
 +    $res['address'] = strtr($record['033A']['p'], $filter_nice); 
 +    $res['_bibtex']['address'] = '  address'; 
 +    $res['_openurlkev']['address'] = 'rft.place'; 
 +    $res['_text']['address'] = 'Ort'; 
 +    //  publisher 
 +    $res['publisher'] = strtr($record['033A']['n'], $filter_nice); 
 +    $res['_bibtex']['publisher'] = '  publisher'; 
 +    $res['_openurlkev']['publisher'] = 'rft.pub'; 
 +    $res['_text']['publisher'] = 'Verlag'; 
 + 
 +    //  edition 
 +    $res['edition'] = strtr($record['032@']['a'], $filter_nice); 
 +    $res['_bibtex']['edition'] = '  edition'; 
 +    $res['_openurlkev']['edition'] = 'rft.edition'; 
 +    $res['_text']['edition'] = 'Auflage'; 
 +    //  year 
 +    $res['year'] = strtr($record['011@']['a'], $filter_nice); 
 +    $res['_bibtex']['year'] = '  year'; 
 +    $res['_openurlkev']['year'] = 'rft.date'; 
 +    $res['_text']['year'] = 'Jahr'; 
 +    //  Erscheinungsverlauf 
 +    $res['everlauf'] = strtr($record['031@']['a'], $filter_nice); 
 +    $res['_bibtex']['everlauf'] = ''; 
 +    $res['_openurlkev']['everlauf'] = ''; 
 +    $res['_text']['everlauf'] = 'Erscheinungsverlauf'; 
 + 
 +    //  pages 
 +    $res['pages'] = strtr($record['034D']['a'], $filter_nice); 
 +    $res['_bibtex']['pages'] = ''; 
 +    $res['_openurlkev']['pages'] = 'rft.pages'; 
 +    $res['_text']['pages'] = 'Umfang'; 
 + 
 +    //  ISBNs 
 +    $res['isbn10'] = strtr($record['004A']['x0'], $filter_nice); 
 +    $res['_bibtex']['isbn10'] = '  isbn'; 
 +    $res['_openurlkev']['isbn10'] = 'rft.isbn'; 
 +    $res['_text']['isbn10'] = 'ISBN-10'; 
 +    $res['isbn13'] = strtr($record['004A']['A'], $filter_nice); 
 +    $res['_bibtex']['isbn13'] = '  isbn'; 
 +    $res['_openurlkev']['isbn13'] = 'rft.isbn'; 
 +    $res['_text']['isbn13'] = 'ISBN-13'; 
 + 
 +    //  ISSN 
 +    $res['issn'] = strtr($record['005A']['x0'], $filter_nice); 
 +    $res['_bibtex']['issn'] = '  issn'; 
 +    $res['_openurlkev']['issn'] = 'rft.issn'; 
 +    $res['_text']['issn'] = 'ISSN'; 
 + 
 +    //  DNB Number 
 +    $res['dnb_no'] = strtr($record['006G']['x0'], $filter_nice); 
 +    $res['_bibtex']['dnb_no'] = ''; 
 +    $res['_openurlkev']['dnb_no'] = ''; 
 +    $res['_text']['dnb_no'] = 'DNB-Nummer'; 
 + 
 +    //  OCLC Number 
 +    $res['oclc_no'] = strtr($record['003O']['x0'], $filter_nice); 
 +    $res['_bibtex']['oclc_no'] = ''; 
 +    $res['_openurlkev']['oclc_no'] = ''; 
 +    $res['_text']['oclc_no'] = 'OCLC-Nummer'; 
 + 
 +    //  Foreign Data Identification Number 
 +    $res['fdin'] = strtr($record['007I']['x0'], $filter_nice); 
 +    $res['_bibtex']['fdin'] = ''; 
 +    $res['_openurlkev']['fdin'] = ''; 
 +    $res['_text']['fdin'] = 'Fremddaten-Identifikationsnummer'; 
 + 
 +    //  ZDB identification number 
 +    $res['zdb_id'] = strtr($record['007A']['x0'], $filter_nice); 
 +    $res['_bibtex']['zdb_id'] = ''; 
 +    $res['_openurlkev']['zdb_id'] = ''; 
 +    $res['_text']['zdb_id'] = 'ZDB-ID'; 
 + 
 +    //  PPN 
 +    $res['ppn'] = strtr($record['003@']['x0'], $filter_nice); 
 +    $res['_bibtex']['ppn'] = '  note'; 
 +    $res['_openurlkev']['ppn'] = ''; 
 +    $res['_text']['ppn'] = 'PPN'; 
 + 
 +    //  Link 
 +    $res['link'] = strtr($record['009Q']['u'], $filter_nice); 
 +    $res['_bibtex']['link'] = 'URL'; 
 +    $res['_openurlkev']['link'] = ''; 
 +    $res['_text']['link'] = 'Link'; 
 + 
 +    //  Table of Contents 
 +    $res['toc'] = strtr($record['009P']['u'], $filter_nice); 
 +    $res['_bibtex']['toc'] = ''; 
 +    $res['_openurlkev']['toc'] = ''; 
 +    $res['_text']['toc'] = 'Inhaltsverzeichnis'; 
 + 
 +    //  DDC 
 +    $res['ddc'] = strtr($record['045B']['a'], $filter_nice); 
 +    $res['_bibtex']['ddc'] = ''; 
 +    $res['_openurlkev']['ddc'] = ''; 
 +    $res['_text']['ddc'] = 'DDC'; 
 + 
 +    //  RVK 
 +    $res['rvk'] = strtr($record['045Z']['a'], $filter_nice); 
 +    $res['_bibtex']['rvk'] = 'keywords'; 
 +    $res['_openurlkev']['rvk'] = ''; 
 +    $res['_text']['rvk'] = 'rvk'; 
 + 
 +    //  EZB link 
 +    $res['ezb_link'] = strtr($record['209S/01']['u'], $filter_nice); 
 +    $res['_bibtex']['ezb_link'] = '  url'; 
 +    $res['_openurlkev']['ezb_link'] = ''; 
 +    $res['_text']['ezb_link'] = 'EZB-Link'; 
 + 
 +    //  return result 
 +    return $res;
   }   }
  
   /*   /*
     private     private
-    recode pica charset+   *  class PicaRecord 
 +   *  recode PICA charset 
 +    Used by PicaRecord->{decodePica,decodePicaArray}
   **/   **/
   function getCode($ch) {   function getCode($ch) {
Line 248: Line 447:
        // case 62: return "]";        // case 62: return "]";
        case 62: return "&gt;";        case 62: return "&gt;";
-       case 64: return ""; // @ pica no sort sign+       case 64: return ""; // @ PICA no sort sign
        case 209: return "ä";        case 209: return "ä";
        case 210: return "ö";        case 210: return "ö";
Line 265: Line 464:
  
   /*   /*
-   * private +    private 
-   * not complete set of double byte pica characters started with +    class PicaRecord 
-   * an accent sign+   *  not complete set of double byte PICA characters started with 
 +    an accent sign 
 +    Used by PicaRecord->{decodePica,decodePicaArray}
   **/   **/
   function getCode2($ch) {   function getCode2($ch) {
Line 286: Line 487:
   /*   /*
     public     public
-    return simple dublin core record from pica data +   *  class PicaRecord 
-    Used by unAPI.php+   *  return simple Dublin Core record from PICA data 
 +    Used by Picappn->getDublinCore
   **/   **/
   function getDublinCore($str) {   function getDublinCore($str) {
Line 312: Line 514:
     $res .= "<type>".$this->type."</type>\n";     $res .= "<type>".$this->type."</type>\n";
     $res .="</record>\n";     $res .="</record>\n";
 +
 +    //  return result
     return $res;     return $res;
   }   }
Line 317: Line 521:
   /*   /*
     public     public
-    transform raw pica plus to a more readable diagnostic format +   *  class PicaRecord 
-    Used by unAPI.php+   *  transform raw PICA plus to a more readable diagnostic format 
 +    Used by Picappn->getPicaPlus
   **/   **/
   function getPicaPlus($str) {   function getPicaPlus($str) {
     $res = $this->transcribe_pica_utf8($str);     $res = $this->transcribe_pica_utf8($str);
     $res = $this->transcribe_pica_rec($res);     $res = $this->transcribe_pica_rec($res);
 +
 +    //  return result
     return $res;     return $res;
   }   }
Line 328: Line 535:
   /*   /*
     private     private
-    rename numeric tags not allowed in xml+   *  class PicaRecord 
 +   *  rename numeric tags not allowed in XML 
 +    Used by PicaRecord->{decodePica,decodePicaArray}
   **/   **/
   function getTagName($ch) {   function getTagName($ch) {
Line 340: Line 549:
   /*   /*
     public     public
-    transform raw pica data to valid xml +   *  class PicaRecord 
-    Used by unAPI.php+   *  transform raw PICA data to valid XML 
 +    Used by PicaRecord->getDublinCore, 
 +    Picappn->{getDublinCoreRDF,getPlain,getXmlData}
   **/   **/
   function getXmlData($str) {   function getXmlData($str) {
-     // pica record separator is ascii record separator +    //  PICA record separator is ascii record separator 
-     $lines = explode(chr(30), $str); +    $lines = explode(chr(30), $str); 
-     $res = ""; + 
-     foreach ($lines as $line) { +    //  define $res 
-       $in1 = ltrim($line); +    $res = ""; 
-       $ch1 = substr($in1,1,1); + 
-       //first char between 0-9 +    //  check each element of array 
-       if (ord($ch1) >47 && ord($ch1)<58) { +    foreach ($lines as $line) { 
-          $pos = strpos($in1, ' '); +      $in1 = ltrim($line); 
-          $key = substr($in1,0,$pos); +      $ch1 = substr($in1,1,1); 
-          $val = substr($in1,$pos+1); +      //  first char between 0-9 
-          $val = $this->decodePica($val); +      if (ord($ch1) >47 && ord($ch1)<58) { 
-          //$res .= "[$key] [$val]\n"; +         $pos = strpos($in1, ' '); 
-          $res .= "<field tag=\"$key\">$val</field>\n"; +         $key = substr($in1,0,$pos); 
-          //side effect to scan dublin core elements +         $val = substr($in1,$pos+1); 
-          $this->readData($key,$val); +         $val = $this->decodePica($val); 
-       } else { +         //$res .= "[$key] [$val]\n"; 
-         //not valid +         $res .= "<field tag=\"$key\">$val</field>\n"; 
-       +         //side effect to scan dublin core elements 
-     +         $this->readData($key,$val); 
-     return $res;+      } else { 
 +        //not valid 
 +      
 +    
 + 
 +    //  return result 
 +    return $res;
   }   }
  
   /*   /*
     private     private
-    read dublin core elements+   *  class PicaRecord 
 +   *  read Dublin Core elements 
 +    Used by PicaRecord->{getXmlData,readXmlData}
   **/   **/
   function readData($key, $val) {   function readData($key, $val) {
Line 432: Line 651:
             break;             break;
        case '036D': //nicht dokumentiert: Sammelband Gesamtausgabe        case '036D': //nicht dokumentiert: Sammelband Gesamtausgabe
-            //source : A related resource from which the described is derived.+            //  source : A related resource from which the described is derived.
             $this->source = $this->readTag($val, "x8")." ";             $this->source = $this->readTag($val, "x8")." ";
-            //$this->source .= $this->readTag($val, "l"); 
             break;             break;
        case '045B': //DDC        case '045B': //DDC
Line 468: Line 686:
             break;             break;
        case '016A': //Materialspezifische Codes für elektronische Ressourcen        case '016A': //Materialspezifische Codes für elektronische Ressourcen
-            //type The nature or genre of the resource.+            //  type The nature or genre of the resource.
             $this->type = $this->readTag($val, "a");             $this->type = $this->readTag($val, "a");
             break;             break;
Line 479: Line 697:
   /*   /*
     public     public
 +    class PicaRecord
     parse dublin core data     parse dublin core data
     Used by unClient.php     Used by unClient.php
Line 484: Line 703:
   **/   **/
   function readDublinCore($str) {   function readDublinCore($str) {
-     $doc = new DomDocument(); +    $doc = new DomDocument(); 
-     $doc -> loadXML($str); +    $doc -> loadXML($str); 
-     $xp = new DomXPath($doc); +    $xp = new DomXPath($doc); 
-     $this->contributor = $xp->query("/record/contributor")->item(0)->nodeValue; +    $this->contributor = $xp->query("/record/contributor")->item(0)->nodeValue; 
-     $this->coverage = $xp->query("/record/coverage")->item(0)->nodeValue; +    $this->coverage = $xp->query("/record/coverage")->item(0)->nodeValue; 
-     $this->creator = $xp->query("/record/creator")->item(0)->nodeValue; +    $this->creator = $xp->query("/record/creator")->item(0)->nodeValue; 
-     $this->date = $xp->query("/record/date")->item(0)->nodeValue; +    $this->date = $xp->query("/record/date")->item(0)->nodeValue; 
-     $this->description = $xp->query("/record/description")->item(0)->nodeValue; +    $this->description = $xp->query("/record/description")->item(0)->nodeValue; 
-     $this->format = $xp->query("/record/format")->item(0)->nodeValue; +    $this->format = $xp->query("/record/format")->item(0)->nodeValue; 
-     $this->identifier = $xp->query("/record/identifier")->item(0)->nodeValue; +    $this->identifier = $xp->query("/record/identifier")->item(0)->nodeValue; 
-     $this->language = $xp->query("/record/language")->item(0)->nodeValue; +    $this->language = $xp->query("/record/language")->item(0)->nodeValue; 
-     $this->publisher = $xp->query("/record/publisher")->item(0)->nodeValue; +    $this->publisher = $xp->query("/record/publisher")->item(0)->nodeValue; 
-     $this->related = $xp->query("/record/related")->item(0)->nodeValue; +    $this->related = $xp->query("/record/related")->item(0)->nodeValue; 
-     $this->rights = $xp->query("/record/rights")->item(0)->nodeValue; +    $this->rights = $xp->query("/record/rights")->item(0)->nodeValue; 
-     $this->source = $xp->query("/record/source")->item(0)->nodeValue; +    $this->source = $xp->query("/record/source")->item(0)->nodeValue; 
-     $this->subject = $xp->query("/record/subject")->item(0)->nodeValue; +    $this->subject = $xp->query("/record/subject")->item(0)->nodeValue; 
-     $this->title = $xp->query("/record/title")->item(0)->nodeValue; +    $this->title = $xp->query("/record/title")->item(0)->nodeValue; 
-     $this->type = $xp->query("/record/type")->item(0)->nodeValue; +    $this->type = $xp->query("/record/type")->item(0)->nodeValue; 
-     return $res;+ 
 +    //  return result 
 +    return $res;
   }   }
  
   /*   /*
     public     public
 +    class PicaRecord
     parse dublin core data     parse dublin core data
     experimental, does not work, so commented out     experimental, does not work, so commented out
 +    Used by n/a
   **/   **/
   /*   /*
   function readRDF_DC($str) {   function readRDF_DC($str) {
-     $doc = new DomDocument(); +    $doc = new DomDocument(); 
-     $doc -> loadXML($str); +    $doc -> loadXML($str); 
-     $xp = new DomXPath($doc); +    $xp = new DomXPath($doc); 
-     $this->contributor = $xp->query("/rdf/dc:contributor")->item(0)->nodeValue; +    $this->contributor = $xp->query("/rdf/dc:contributor")->item(0)->nodeValue; 
-     $this->coverage = $xp->query("/rdf/dc:coverage")->item(0)->nodeValue; +    $this->coverage = $xp->query("/rdf/dc:coverage")->item(0)->nodeValue; 
-     $this->creator = $xp->query("/rdf/dc:creator")->item(0)->nodeValue; +    $this->creator = $xp->query("/rdf/dc:creator")->item(0)->nodeValue; 
-     $this->date = $xp->query("/rdf/dc:date")->item(0)->nodeValue; +    $this->date = $xp->query("/rdf/dc:date")->item(0)->nodeValue; 
-     $this->description = $xp->query("/rdf/dc:description")->item(0)->nodeValue; +    $this->description = $xp->query("/rdf/dc:description")->item(0)->nodeValue; 
-     $this->format = $xp->query("/rdf/dc:format")->item(0)->nodeValue; +    $this->format = $xp->query("/rdf/dc:format")->item(0)->nodeValue; 
-     $this->identifier = $xp->query("/rdf/dc:identifier")->item(0)->nodeValue; +    $this->identifier = $xp->query("/rdf/dc:identifier")->item(0)->nodeValue; 
-     $this->language = $xp->query("/rdf/dc:language")->item(0)->nodeValue; +    $this->language = $xp->query("/rdf/dc:language")->item(0)->nodeValue; 
-     $this->publisher = $xp->query("/rdf/dc:publisher")->item(0)->nodeValue; +    $this->publisher = $xp->query("/rdf/dc:publisher")->item(0)->nodeValue; 
-     $this->related = $xp->query("/rdf/dc:related")->item(0)->nodeValue; +    $this->related = $xp->query("/rdf/dc:related")->item(0)->nodeValue; 
-     $this->rights = $xp->query("/rdf/dc:rights")->item(0)->nodeValue; +    $this->rights = $xp->query("/rdf/dc:rights")->item(0)->nodeValue; 
-     $this->source = $xp->query("/rdf/dc:source")->item(0)->nodeValue; +    $this->source = $xp->query("/rdf/dc:source")->item(0)->nodeValue; 
-     $this->subject = $xp->query("/rdf/dc:subject")->item(0)->nodeValue; +    $this->subject = $xp->query("/rdf/dc:subject")->item(0)->nodeValue; 
-     $this->title = $xp->query("/rdf/dc:title")->item(0)->nodeValue; +    $this->title = $xp->query("/rdf/dc:title")->item(0)->nodeValue; 
-     $this->type = $xp->query("/rdf/dc:type")->item(0)->nodeValue; +    $this->type = $xp->query("/rdf/dc:type")->item(0)->nodeValue; 
-     return $res;+ 
 +    //  return result 
 +    return $res;
   }   }
   */   */
Line 536: Line 761:
   /*   /*
     private     private
 +    class PicaRecord
     read tag content from string     read tag content from string
 +    Used by PicaRecord->readData
   **/   **/
   function readTag($val, $tag) {   function readTag($val, $tag) {
Line 547: Line 774:
   /*   /*
     public     public
 +    class PicaRecord
     read XML data     read XML data
     used by unClient.php     used by unClient.php
Line 570: Line 798:
  
   /*   /*
-   * private +    private 
-   * transcribe separators to diagnostic format+    class PicaRecord 
 +   *  transcribe separators to diagnostic format 
 +    Used by PicaRecord->getPicaPlus
   **/   **/
   function transcribe_pica_rec($str) {   function transcribe_pica_rec($str) {
Line 580: Line 810:
  
   /*   /*
-   * private +    private 
-   pica charset handling (we want utf8)+    class PicaRecord 
 +    PICA charset handling (we want utf8) 
 +    Used by PicaRecord->getPicaPlus
   **/   **/
   function transcribe_pica_utf8($str) {   function transcribe_pica_utf8($str) {
Line 592: Line 824:
  
 /* /*
- * end class PicaRecord+  end class PicaRecord
 **/ **/
  
 /* /*
   class Picappn   class Picappn
-  get a pica record via pica xml web interface and return it+  get a PICA record via PICA XML web interface, format and return it
 +  Supported formats: 
 +  - Array: Picappn->getArray 
 +  - Bibsonomy: Picappn->getBibsonomy 
 +  - BibTex: Picappn->getBibTex 
 +  - CSV: Picappn->getCsv 
 +  - Dublin Core: Picappn->getDublinCore 
 +  - RDF: Picappn->getDublinCoreRDF 
 +  - JSON: Picappn->getJson 
 +  - OpenURL KEV: Picappn->getOpenUrlKev 
 +  - PICA Plus: Picappn->getPicaPlus 
 +  - Plain: Picappn->getPlain 
 +  - Text: Picappn->getText 
 +  - XML: Picappn->getXmlData
 **/ **/
 class Picappn { class Picappn {
Line 609: Line 854:
   var $prec;   var $prec;
  
-  / constructor +  /
 +    constructor 
 +    class Picappn 
 +    PHP5 or later should use '__construct()' 
 +  **/
   function Picappn() {   function Picappn() {
     //  get global user-defineable $opac_url     //  get global user-defineable $opac_url
     global $opac_url;     global $opac_url;
 +
     //  preset some attributes     //  preset some attributes
     $this->opac = $opac_url;     $this->opac = $opac_url;
     $this->ppn = 0;     $this->ppn = 0;
 +
     //  instantiate new PicaRecord()     //  instantiate new PicaRecord()
     $this->prec = new PicaRecord();     $this->prec = new PicaRecord();
Line 622: Line 873:
   /*   /*
     public     public
 +    class Picappn
     convert for output using raw array data     convert for output using raw array data
-    Used by+    Used by Picappn->{getBibTex,getText}
   **/   **/
   function convOutput($array,$text,$separator,$category,$subfield,$suffix) {   function convOutput($array,$text,$separator,$category,$subfield,$suffix) {
 +    //  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 "";
Line 634: Line 889:
         $res = $text.$separator.$array[$category].$suffix;         $res = $text.$separator.$array[$category].$suffix;
     }     }
 +
 +    //  return result
     return $res;     return $res;
   }   }
Line 639: Line 896:
   /*   /*
     public     public
 +    class Picappn
     convert for output using nice array data     convert for output using nice array data
 +    Used by Picappn->{getBibTex,getOpenUrlKev,getText}
   **/   **/
   function convOutputNice($array_nice,$array_text,$key,$prefix,$suffix) {   function convOutputNice($array_nice,$array_text,$key,$prefix,$suffix) {
 +    //  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 $res; + 
 +    //  return result 
 +    return $res;
   }   }
  
   /*   /*
     public     public
 +    class Picappn
     return record as Array     return record as Array
 +    Used by Picappn->{getBibTex,getCsv,getJson,getOpenUrlKev,getText}
   **/   **/
   function getArray() {   function getArray() {
 +    //  check if $this->ppn is not the preset value else return emptily
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
 +
 +    //  build result
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
     $res = $this->prec->getArray($res);     $res = $this->prec->getArray($res);
-    return $res; 
-  } 
- 
-  /* 
-    public 
-    return bibliographic data in array with speaking keys 
-    Used by getBibtex(), getOpenUrlKev() and getText() 
-  **/ 
-  function getArrayNice($array_raw) { 
-    if (empty($array_raw)) return ""; 
-    $record = $array_raw; 
- 
-    //  get global, user-defineable variable $filter_nice 
-    global $filter_nice; 
- 
-    //  type 
-    $res['type'] = strtr($record['002@']['x0'], $filter_nice); 
-    $res['_bibtex']['type'] = ''; 
-    $res['_openurlkev']['type'] = 'rft.genre'; 
-    $res['_text']['type'] = 'Art'; 
-    //  type w/o kind of record 
-    $res['twokr'] = substr($res['type'], 0, 2); 
-    $res['_bibtex']['twokr'] = ''; 
-    $res['_openurlkev']['twokr'] = ''; 
-    $res['_text']['twokr'] = ''; 
- 
-    //  author 
-    $res['author'] = strtr($record['028A']['x8'], $filter_nice); 
-    $res['author'] = rtrim($res['author']); 
-    $res['_bibtex']['author'] = '  author'; 
-    $res['_openurlkev']['author'] = 'rft.au'; 
-    $res['_text']['author'] = 'Autor'; 
-    //  editor 
-    $res['editor'] = strtr($record['028C']['x8'], $filter_nice); 
-    $res['editor'] = rtrim($res['editor']); 
-    $res['_bibtex']['editor'] = '  editor'; 
-    $res['_openurlkev']['editor'] = 'rft.au'; 
-    $res['_text']['editor'] = 'Herausgeber'; 
- 
-    //  title 
-    $res['title'] = strtr($record['021A']['a'], $filter_nice); 
-    $res['_bibtex']['title'] = '  title'; 
-    $res['_openurlkev']['title'] = 'rft.title'; 
-    $res['_text']['title'] = 'Titel'; 
- 
-    //  series 
-    if ((!empty($record['036F']['x8'])) || (!empty($record['036F']['l']))) { 
-      $res['series'] = strtr($record['036F']['x8'], $filter_nice)." ". 
-       strtr($record['036F']['l'], $filter_nice); 
-    } 
-    $res['_bibtex']['series'] = '  series'; 
-    $res['_openurlkev']['series'] = 'rft.series'; 
-    $res['_text']['series'] = 'Schriftenreihe'; 
- 
-    //  address, especially city 
-    $res['address'] = strtr($record['033A']['p'], $filter_nice); 
-    $res['_bibtex']['address'] = '  address'; 
-    $res['_openurlkev']['address'] = 'rft.place'; 
-    $res['_text']['address'] = 'Ort'; 
-    //  publisher 
-    $res['publisher'] = strtr($record['033A']['n'], $filter_nice); 
-    $res['_bibtex']['publisher'] = '  publisher'; 
-    $res['_openurlkev']['publisher'] = 'rft.pub'; 
-    $res['_text']['publisher'] = 'Verlag'; 
-    //  edition 
-    $res['edition'] = strtr($record['032@']['a'], $filter_nice); 
-    $res['_bibtex']['edition'] = '  edition'; 
-    $res['_openurlkev']['edition'] = 'rft.edition'; 
-    $res['_text']['edition'] = 'Auflage'; 
-    //  year 
-    $res['year'] = strtr($record['011@']['a'], $filter_nice); 
-    $res['_bibtex']['year'] = '  year'; 
-    $res['_openurlkev']['year'] = 'rft.date'; 
-    $res['_text']['year'] = 'Jahr'; 
- 
-    //  pages 
-    $res['pages'] = strtr($record['034D']['a'], $filter_nice); 
-    $res['_bibtex']['pages'] = ''; 
-    $res['_openurlkev']['pages'] = 'rft.pages'; 
-    $res['_text']['pages'] = 'Umfang'; 
- 
-    //  ISBNs 
-    $res['isbn10'] = strtr($record['004A']['x0'], $filter_nice); 
-    $res['_bibtex']['isbn10'] = '  isbn'; 
-    $res['_openurlkev']['isbn10'] = 'rft.isbn'; 
-    $res['_text']['isbn10'] = 'ISBN-10'; 
-    $res['isbn13'] = strtr($record['004A']['A'], $filter_nice); 
-    $res['_bibtex']['isbn13'] = '  isbn'; 
-    $res['_openurlkev']['isbn13'] = 'rft.isbn'; 
-    $res['_text']['isbn13'] = 'ISBN-13'; 
- 
-    //  DNB Number 
-    $res['dnb_no'] = strtr($record['006G']['x0'], $filter_nice); 
-    $res['_bibtex']['dnb_no'] = ''; 
-    $res['_openurlkev']['dnb_no'] = ''; 
-    $res['_text']['dnb_no'] = 'DNB-Nummer'; 
- 
-    //  OCLC Number 
-    $res['oclc_no'] = strtr($record['003O']['x0'], $filter_nice); 
-    $res['_bibtex']['oclc_no'] = ''; 
-    $res['_openurlkev']['oclc_no'] = ''; 
-    $res['_text']['oclc_no'] = 'OCLC-Nummer'; 
- 
-    //  Foreign Data Identification Number 
-    $res['fdin'] = strtr($record['007I']['x0'], $filter_nice); 
-    $res['_bibtex']['fdin'] = ''; 
-    $res['_openurlkev']['fdin'] = ''; 
-    $res['_text']['fdin'] = 'Fremddaten-Identifikationsnummer'; 
- 
-    //  PPN 
-    $res['ppn'] = strtr($record['003@']['x0'], $filter_nice); 
-    $res['_bibtex']['ppn'] = '  note'; 
-    $res['_openurlkev']['ppn'] = ''; 
-    $res['_text']['ppn'] = 'PPN'; 
- 
-    //  Link 
-    $res['link'] = strtr($record['009Q']['u'], $filter_nice); 
-    $res['_bibtex']['link'] = 'URL'; 
-    $res['_openurlkev']['link'] = ''; 
-    $res['_text']['link'] = 'Link'; 
- 
-    //  Table of Contents 
-    $res['toc'] = strtr($record['009P']['u'], $filter_nice); 
-    $res['_bibtex']['toc'] = ''; 
-    $res['_openurlkev']['toc'] = ''; 
-    $res['_text']['toc'] = 'Inhaltsverzeichnis'; 
- 
-    //  DDC 
-    $res['DDC'] = strtr($record['045B']['a'], $filter_nice); 
-    $res['_bibtex']['DDC'] = ''; 
-    $res['_openurlkev']['DDC'] = ''; 
-    $res['_text']['DDC'] = 'DDC'; 
- 
-    //  RVK 
-    $res['RVK'] = strtr($record['045Z']['a'], $filter_nice); 
-    $res['_bibtex']['RVK'] = 'keywords'; 
-    $res['_openurlkev']['RVK'] = ''; 
-    $res['_text']['RVK'] = 'RVK'; 
  
     //  return result     //  return result
Line 801: Line 933:
   /*   /*
     public     public
-    return BibTeX record prefixed with $bibsonomy_url from pica data.+   *  class Picappn 
 +   *  return BibTeX record prefixed with $bibsonomy_url from PICA data.
     Used by Bibsonomy.php     Used by Bibsonomy.php
   **/   **/
Line 824: Line 957:
  
   /*   /*
-   * public +    public 
-   * Return BibTex record from pica data +    class Picappn 
-   * Used by unAPI.php and Bibsonomy.php+   *  Return BibTex record from pica data 
 +    Used by unAPI.php and Picappn->getBibsonomy
   **/   **/
   function getBibTex() {   function getBibTex() {
Line 835: Line 969:
     $record_raw = $this->getArray($this->ppn);     $record_raw = $this->getArray($this->ppn);
     //  transform raw to nice array     //  transform raw to nice array
-    $record_nice = $this->getArrayNice($record_raw);+    $record_nice = $this->prec->getArrayNice($record_raw);
     //  get keys name from array     //  get keys name from array
     $keys_nice = $record_nice['_bibtex'];     $keys_nice = $record_nice['_bibtex'];
Line 844: Line 978:
     if (!empty($record_nice['isbn13'])) unset($record_nice['isbn10']);     if (!empty($record_nice['isbn13'])) unset($record_nice['isbn10']);
  
-    / check type and choose right BibTeX-type+    /
 +      check type and choose right BibTeX-type 
 +      "book" works quite well, "journal" not so 
 +    **/
     if (preg_match('/^[AO][aeEfF]$/',$record_nice['twokr'])) {     if (preg_match('/^[AO][aeEfF]$/',$record_nice['twokr'])) {
-      //  type+      //  type: book
       $res = "@book {";       $res = "@book {";
  
Line 856: Line 993:
       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',
         'edition', 'year', 'isbn10', 'isbn13', 'link');         'edition', 'year', 'isbn10', 'isbn13', 'link');
 +
 +      //  fetch them from array, format and output them
 +      foreach ($i as $j) {
 +        $res .= $this->convOutputNice($record_nice,$keys_nice,$j," = {","},\n");
 +      }
 +
 +      //  get call number, format and output it
 +      $res .= $this->convOutput($record_raw,"  note"," = {","209A/01",'a',"}");
 +    } elseif (preg_match('/^[AO]b$/',$record_nice['twokr'])) {
 +      //  type: journal
 +      $res = "@misc {";
 +
 +      //  create identifier
 +      $res .= $this->convOutput($record_raw,"","",'003@','x0',"");
 +      $res .= $this->convOutput($record_raw,"","",'011@','a',",\n");
 +
 +      //  set the field which are fetched: title et al.
 +      $i = array('title', 'address', 'publisher', 'issn', 'ezb_link');
  
       //  fetch them from array, format and output them       //  fetch them from array, format and output them
Line 866: Line 1021:
     }     }
  
-    //  trailing element+    //  stripping et al.
     if (isset($res)) {     if (isset($res)) {
 +      //  check if last characters of $res are ",\n" and trim them
 +      $res = rtrim($res, ",\n");
 +      //  trailing element
       $res .= "\n}";       $res .= "\n}";
     }     }
Line 875: Line 1033:
   }   }
  
-  /** private -- get data via pica xml interface */+  /* 
 +    public 
 +    class Picappn 
 +    Return CSV record from pica data 
 +    Used by unAPI.php 
 +  **/ 
 +  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->getArray($this->ppn); 
 +    //  transform raw to nice array 
 +    $record_nice = $this->prec->getArrayNice($record_raw); 
 +    //  declare $res 
 +    $res = ''; 
 + 
 +    //  set categories to used for CSV 
 +    $i = array('ppn', 'author', 'editor', 'title', 'address', 'year', 'isbn10', 
 +     'isbn13', 'issn', 'dnb_no', 'oclc_no', 'fdin', 'zdb_id', 'rvk'); 
 + 
 +    //  fetch them from array, format and output them 
 +    foreach ($i as $j) { 
 +      $res .= '"'.$record_nice["$j"].'"|';  
 +    } 
 + 
 +    //  stripping et al. 
 +    if (isset($res)) { 
 +      //  check if last characters of $res are ",\n" and trim them 
 +      $res = rtrim($res, "|"); 
 +    } 
 + 
 +    //  return result 
 +    return $res; 
 +  } 
 + 
 +  /* 
 +    private 
 +    class Picappn 
 +   *  get data via PICA XML interface 
 +    Used by Picappn->{getArray,getDublinCore,getDublinCoreRDF,getPicaPlus,getPlain,getXmlData} 
 +  **/
   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('curl_init')) {+    global $use_curl; 
 + 
 +    //  check whether curl-Module is available, if not available use fallback 
 +    if (function_exists('curl_init'&& $use_curl != 'no') {
       $ch = curl_init("$this->url");       $ch = curl_init("$this->url");
       curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);       curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
Line 889: Line 1091:
       $res = file_get_contents("$this->url");       $res = file_get_contents("$this->url");
     }     }
 +
 +    // return result
     return $res;     return $res;
   }   }
  
-  /** public -- return simple dublin core record data from pica record */+  /* 
 +    public 
 +    class Picappn 
 +   *  return simple dublin core record data from pica record 
 +    Used by unAPI.php 
 +  **/
   function getDublinCore() {   function getDublinCore() {
 +    //  retrieve data
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
 +
 +    //  format data
     $res = $this->prec->getDublinCore($res);     $res = $this->prec->getDublinCore($res);
 +
 +    //  return result
     return $res;     return $res;
   }   }
  
-  /** public -- return dublin core rdf data from pica record */+  /* 
 +    public 
 +    class Picappn 
 +   *  return dublin core rdf data from pica record 
 +    Used by unAPI.php 
 +  **/
   function getDublinCoreRDF() {   function getDublinCoreRDF() {
 +    //  retrieve data
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
 +
 +    //  put it to some XML structure
     $res = $this->prec->getXmlData($res); //parses dublin core     $res = $this->prec->getXmlData($res); //parses dublin core
  
 +    //  check if $this->ppn is not the preset value else return emptily
     if (empty($res)) return "";     if (empty($res)) return "";
  
 +    //  format
     $res  = "<?xml version=\"1.0\"?>\n";     $res  = "<?xml version=\"1.0\"?>\n";
     $res .= "<!DOCTYPE rdf:RDF PUBLIC ";     $res .= "<!DOCTYPE rdf:RDF PUBLIC ";
Line 932: Line 1156:
     $res .= "</rdf:Description>\n";     $res .= "</rdf:Description>\n";
     $res .= "</rdf:RDF>\n";     $res .= "</rdf:RDF>\n";
 +
 +    //  return result
     return $res;     return $res;
   }   }
  
-  /** public -- return JSON record from pica data */ +  /* 
-  //used by unapi+    public 
 +    class Picappn 
 +   *  return JSON record from pica data 
 +    Used by unAPI.php 
 +  **/
   function getJson() {   function getJson() {
 +    //  check if $this->ppn is not the preset value else return emptily
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
  
 +    //  get PICA record as array
     $res = $this->getArray();     $res = $this->getArray();
-    //(PHP 5 >= 5.2.0, PECL json >= 1.2.0)+    //  encode array as JSON, requirements: 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 +    public 
-   * return OpenURL KEV record from pica data +    class Picappn 
-   * Used by unAPI.php and Coins.php+   *  return OpenURL KEV record from pica data 
 +    Used by unAPI.php and Coins.php
   **/   **/
   function getOpenUrlKev() {   function getOpenUrlKev() {
Line 959: Line 1193:
     $record_raw = $this->getArray($this->ppn);     $record_raw = $this->getArray($this->ppn);
     //  transform raw to nice array     //  transform raw to nice array
-    $record_nice = $this->getArrayNice($record_raw);+    $record_nice = $this->prec->getArrayNice($record_raw);
     //  get keys' name from array     //  get keys' name from array
     $keys_nice = $record_nice['_openurlkev'];     $keys_nice = $record_nice['_openurlkev'];
Line 982: Line 1216:
       $keys_nice['title'] = 'rft.btitle';       $keys_nice['title'] = 'rft.btitle';
  
-      //  type+      //  type: book
       $res .= '&amp;rft_val_fmt='.urlencode('info:ofi/fmt:kev:mtx:book');       $res .= '&amp;rft_val_fmt='.urlencode('info:ofi/fmt:kev:mtx:book');
       $res .= '&amp;rft.genre=book&amp;';       $res .= '&amp;rft.genre=book&amp;';
Line 989: Line 1223:
       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',
         'edition', 'year', 'isbn10', 'isbn13', 'pages');         'edition', 'year', 'isbn10', 'isbn13', 'pages');
 +
 +      //  fetch them from array, format, url-encode and output them
 +      foreach ($i as $j) {
 +        $record_nice[$j] = urlencode($record_nice[$j]);
 +        $res .= $this->convOutputNice($record_nice,$keys_nice,$j,"=","&amp;");
 +      }
 +    } elseif (preg_match('/^[AO]b$/',$record_nice['twokr'])) {
 +      //  type: journal/article
 +      $res .= '&amp;rft_val_fmt='.urlencode('info:ofi/fmt:kev:mtx:journal');
 +      $res .= '&amp;rft.genre=article&amp;';
 +
 +      //  set the field which are fetched: author et al.
 +      $i = array('title', 'address', 'publisher', 'issn');
  
       //  fetch them from array, format, url-encode and output them       //  fetch them from array, format, url-encode and output them
Line 999: Line 1246:
     //  strip trailing "&amp;" if necessary     //  strip trailing "&amp;" if necessary
     if (isset($res)) {     if (isset($res)) {
-      $length = strlen($res); +      $res = rtrim($res, "&amp;");
-      $last strrpos($res,"&amp;"); +
-      if ( $length == $last+5 ) { +
-        $res = substr($res,0,-5); +
-      }+
     }     }
  
Line 1010: Line 1253:
   }   }
  
-  /** public -- return formated pica plus record */+  /*  
 +    public 
 +    class Picappn 
 +   *  return formatted PICA Plus record 
 +    Used by unAPI.php 
 +  **/
   function getPicaPlus() {   function getPicaPlus() {
 +    //  check if $this->ppn is not the preset value else return emptily
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
 +
 +    //  retrieve record
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
 +
 +    //  format
     $res = $this->prec->getPicaPlus($res);     $res = $this->prec->getPicaPlus($res);
 +
 +    //  set prefix
     $head = "<?xml version='1.0' encoding='UTF-8'?>\n";     $head = "<?xml version='1.0' encoding='UTF-8'?>\n";
     $head .= "<record url=\"$this->url\">\n";     $head .= "<record url=\"$this->url\">\n";
 +
 +    //  set suffix
     $tail = "</record>\n";     $tail = "</record>\n";
 +
 +    //  return result
     return $head.$res.$tail;     return $head.$res.$tail;
   }   }
  
-  /** public -- return formated plain record */+  /* 
 +    public 
 +    class Picappn 
 +   *  return formatted plain (not well formed XML) record 
 +    Used by unAPI.php 
 +  **/
   function getPlain() {   function getPlain() {
 +    //  check if $this->ppn is not the preset value else return emptily
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
 +
 +    //  retrieve record
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
 +
 +    //  put to some XML structure
     $res = $this->prec->getXmlData($res);     $res = $this->prec->getXmlData($res);
 +
 +    //  return result
     return $res;     return $res;
   }   }
  
   /*   /*
-   * public +    public 
-   * Return simple text record from pica data +    class Picappn 
-   * Used by unAPI.php+   *  Return simple text record from pica data 
 +    Used by unAPI.php
   **/   **/
   function getText() {   function getText() {
Line 1041: Line 1313:
     $record_raw = $this->getArray($this->ppn);     $record_raw = $this->getArray($this->ppn);
     //  transform raw to nice array     //  transform raw to nice array
-    $record_nice = $this->getArrayNice($record_raw);+    $record_nice = $this->prec->getArrayNice($record_raw);
     //  get keys' names from array     //  get keys' names from array
     $keys_nice = $record_nice['_text'];     $keys_nice = $record_nice['_text'];
Line 1049: Line 1321:
     //  check type and choose right type     //  check type and choose right type
     if (preg_match('/^[AO][aeEfF]$/',$record_nice['twokr'])) {     if (preg_match('/^[AO][aeEfF]$/',$record_nice['twokr'])) {
-      //  type+      //  type: book
       $res .= $keys_nice['type'].":\t\tMonographie\n";       $res .= $keys_nice['type'].":\t\tMonographie\n";
  
       //  set the field which are fetched: author et al.       //  set the field which are fetched: author et al.
       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',
-        'edition', 'year', 'isbn10', 'isbn13', 'pages', 'RVK', 'DDC', 'link',+        'edition', 'year', 'isbn10', 'isbn13', 'pages', 'rvk', 'ddc', 'link',
         'toc', 'ppn', 'dnb_no', 'oclc_no', 'fdin');         'toc', 'ppn', 'dnb_no', 'oclc_no', 'fdin');
 +
 +      //  fetch them from array, format and output them
 +      foreach ($i as $j) {
 +        $res .= $this->convOutputNice($record_nice,$keys_nice,$j,":\t\t","\n");
 +      }
 +
 +      //  call number
 +      $i = 1;
 +      $j = 0;
 +      while ( $i <= 99 ) {
 +        if (($i <= 9) && ($j == 0)) {
 +          $j = "0".$i;
 +        } elseif (($i > 9) && ($j == 0)) {
 +          $j = $i;
 +        }
 +        $res .= $this->convOutput($record_raw,"Signatur",":\t","209A/$j",'a',"\n");
 +        $i++;
 +        if ($i <= 9 ) {
 +          $j = "0".$i;
 +        } else {
 +          $j = $i;
 +        }
 +        if (empty($record_raw["209A/$j"]['a'])) break;
 +      }
 +    } elseif (preg_match('/^[AO]b$/',$record_nice['twokr'])) {
 +      //  type: journal
 +      $res .= $keys_nice['type'].":\t\tZeitschrift\n";
 +
 +      //  set the field which are fetched: title et al.
 +      $i = array('title', 'address', 'publisher', 'issn', 'everlauf', 'rvk',
 +        'zdb_id', 'ppn', 'ezb_link');
  
       //  fetch them from array, format and output them       //  fetch them from array, format and output them
Line 1081: Line 1384:
       }       }
     }     }
 +
 +    //  return result
     return $res;     return $res;
   }   }
  
-  /** public -- return xml formated pica record */+  /* 
 +    public 
 +    class Picappn 
 +   *  return XML formatted PICA record 
 +    Used by unAPI.php 
 +  **/
   function getXmlData() {   function getXmlData() {
 +    //  check if $this->ppn is not the preset value else return emptily
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
 +
 +    //  retrieve record
     $res = $this->getData($this->ppn);     $res = $this->getData($this->ppn);
-    $res = $this->prec->getXmlData($res); + 
 +    //  put it to some XML structure 
 +    $res = $this->prec->getXmlData($res); 
 + 
 +    //  define prefix
     $head = "<?xml version='1.0' ?>\n";     $head = "<?xml version='1.0' ?>\n";
     //$head .= "<record>\n";     //$head .= "<record>\n";
Line 1096: Line 1413:
     //$head .= "<record url=\"".$this->opac.$this->ppn."\">\n";     //$head .= "<record url=\"".$this->opac.$this->ppn."\">\n";
     $head .= "<record url=\"".htmlentities($this->url)."\">\n";     $head .= "<record url=\"".htmlentities($this->url)."\">\n";
 +
 +    //  define suffix
     $tail = "</record>\n";     $tail = "</record>\n";
 +
 +    //  return result
     return $head.$res.$tail;     return $head.$res.$tail;
   }   }
  
-  / public+  / public 
 +    class Picappn 
 +    set attribute Picappn->opac 
 +    Used by n/a 
 +  **/
   function setOpac($opac) {   function setOpac($opac) {
     $this->opac = $opac;     $this->opac = $opac;
   }   }
  
-  / public -- set ppn, the unapi identifier+  / public 
 +    class Picappn 
 +   *  set PPN, the unAPI identifier 
 +    Used by Bibsonomy.php, Coins.php and unAPI.php 
 +  **/
   function setPpn($ppn) {   function setPpn($ppn) {
     //  get global, user-defineable $pattern_ppn     //  get global, user-defineable $pattern_ppn
Line 1112: Line 1441:
     /*       /*  
       for input sanitising - check if $ppn can be matched against a regex       for input sanitising - check if $ppn can be matched against a regex
-      which defines allowed input +      which defines allowed input, if correct set some attributes 
-     */+    **/
     if (preg_match($pattern_ppn,$ppn)) {     if (preg_match($pattern_ppn,$ppn)) {
       $this->ppn = $ppn;       $this->ppn = $ppn;
Line 1135: Line 1464:
 **/ **/
 function final_result($res, $content_type) { function final_result($res, $content_type) {
 +  /*  if $res is not empty, return it, otherwise act accordingly to unAPI
 +    specification
 +  **/
   if (!empty($res)) {   if (!empty($res)) {
 +    //  send header
     header("Content-type: $content_type");     header("Content-type: $content_type");
 +    //  return result
     echo $res;     echo $res;
   } else {   } else {
Line 1144: Line 1478:
  
 /* /*
- * end function final_result+  end function final_result
 **/ **/
  
buechereielektrik/unapi/unapi.inc.php.txt · Last modified: 2011-01-20 17:12 by strols
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0