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:picarecord.php [2009-12-14 14:35] – Handled empty records for dc and rdf strolsbuechereielektrik:unapi:picarecord.php [2009-12-26 14:44] rosenke
Line 1: Line 1:
-<code>+<code php PicaRecord.php>
 <?php <?php
  
Line 27: Line 27:
 /*  Changelog /*  Changelog
  *  *
 +  20091220: Check whether curl-Module is available, if not use
 +              file_get_contents().
 +              Some minor bugfixes.
 +  20091215:   Added function "getJson" to class "Picappn".
 +              Made ISBN in getBibTex() unique.
 +              Filtered some characters in getArrayNice().
   20091214:   Added function "convOutputNice", "getArrayNice", "getBibsonomy",   20091214:   Added function "convOutputNice", "getArrayNice", "getBibsonomy",
               "getKeysText" and "getKeysBibTex" to class "Picappn".               "getKeysText" and "getKeysBibTex" to class "Picappn".
Line 49: Line 55:
  
 $bibsonomy_url = "http://www.bibsonomy.org/BibtexHandler?requTask=upload&selection="; $bibsonomy_url = "http://www.bibsonomy.org/BibtexHandler?requTask=upload&selection=";
 +
 +$filter_nice = array(
 + '{' => '',
 + '}' => ''
 + );
  
 /** represents a bibliographic data record from oclc/pica LBS  /** represents a bibliographic data record from oclc/pica LBS 
Line 116: Line 127:
              $ch = substr($str,++$i,1); //new tag ahead              $ch = substr($str,++$i,1); //new tag ahead
              $tag = $this->getTagName($ch);              $tag = $this->getTagName($ch);
 +             $res[$tag] = "";
              break;              break;
- 
           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 .= $this->getCode2($ch);+             $res[$tag] .= $this->getCode2($ch);
              break;              break;
- 
           default:           default:
              $res[$tag] .= $this->getCode($ch);              $res[$tag] .= $this->getCode($ch);
              break;              break;
         } //switch         } //switch
- 
     }     }
     return $res;     return $res;
Line 377: Line 385:
             break;             break;
      }      }
-     return $res;+     //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 406: Line 415:
   /** public -- parse dublin core data */   /** public -- parse dublin core data */
   //  experimental, does not work   //  experimental, does not work
 +  /*
   function readRDF_DC($str) {   function readRDF_DC($str) {
      $doc = new DomDocument();      $doc = new DomDocument();
Line 427: Line 437:
      return $res;      return $res;
   }   }
 +  */
  
   /** private -- read tag content from string */   /** private -- read tag content from string */
Line 525: Line 536:
     if (empty($array_raw)) return "";     if (empty($array_raw)) return "";
     $record = $array_raw;     $record = $array_raw;
 +
 +    global $filter_nice;
  
     //Type     //Type
-    $res['type'] = $record['002@']['x0'];+    $res['type'] = strtr($record['002@']['x0'], $filter_nice);
  
     //Author     //Author
-    $res['author'] = $record['028A']['x8'];+    $res['author'] = strtr($record['028A']['x8'], $filter_nice);
     //Editor     //Editor
-    $res['editor'] = $record['028C']['x8'];+    $res['editor'] = strtr($record['028C']['x8'], $filter_nice);
  
     //Title     //Title
-    $res['title'] = $record['021A']['a'];+    $res['title'] = strtr($record['021A']['a'], $filter_nice);
  
     //Series     //Series
-    $res['series'] = $record['036F']['x8']." ".$record['036F']['l'];+    $res['series'] = strtr($record['036F']['x8'], $filter_nice)." ".strtr($record['036F']['l'], $filter_nice);
  
     //Address, especially city     //Address, especially city
-    $res['address'] = $record['033A']['p'];+    $res['address'] = strtr($record['033A']['p'], $filter_nice);
     //Publisher     //Publisher
-    $res['publisher'] = $record['033A']['n'];+    $res['publisher'] = strtr($record['033A']['n'], $filter_nice);
     //Edition     //Edition
-    $res['edition'] = $record['032@']['a'];+    $res['edition'] = strtr($record['032@']['a'], $filter_nice);
     //Year     //Year
-    $res['year'] = $record['011@']['a'];+    $res['year'] = strtr($record['011@']['a'], $filter_nice);
  
     //ISBNs     //ISBNs
-    $res['isbn10'] = $record['004A']['x0']; +    $res['isbn10'] = strtr($record['004A']['x0'], $filter_nice)
-    $res['isbn13'] = $record['004A']['A'];+    $res['isbn13'] = strtr($record['004A']['A'], $filter_nice);
  
     //PPN     //PPN
-    $res['ppn'] = $record['003@']['x0'];+    $res['ppn'] = strtr($record['003@']['x0'], $filter_nice);
     return $res;     return $res;
   }   }
Line 562: Line 575:
   function getBibsonomy() {   function getBibsonomy() {
     if ($this->ppn == 0) return "";     if ($this->ppn == 0) return "";
-    $record_raw = $this->getArray($this->ppn); 
-    $record_nice = $this->getArrayNice($record_raw); 
-    $keys_nice = $this->getKeysBibTex(); 
- 
-    if (substr($record_nice['type'], 0, 2) == "Aa") { 
-      //Type 
-      $res .= "@book {"; 
- 
-      //create identifier 
-      $res .= $this->convOutput($record_raw,"","",'003@','x0',""); 
-      $res .= $this->convOutput($record_raw,"","",'011@','a',",\n"); 
- 
-      //Author et al. 
-      $i = array('author', 'editor', 'title', 'series', 'address', 'publisher', 
-        'edition', 'year', 'isbn10', 'isbn13'); 
-      foreach ($i as $j) { 
-        $res .= $this->convOutputNice($record_nice,$keys_nice,$j," = {","},\n"); 
-      } 
- 
-      //Call Number 
-      $res .= $this->convOutput($record_raw,"  note"," = {","209A/01",'a',"}"); 
-    } 
-    $res .= "\n}"; 
  
 +    $res = $this->getBibTex();
     $res = urlencode($res);     $res = urlencode($res);
  
Line 601: Line 592:
     $record_nice = $this->getArrayNice($record_raw);     $record_nice = $this->getArrayNice($record_raw);
     $keys_nice = $this->getKeysBibTex();     $keys_nice = $this->getKeysBibTex();
 +
 +    //make sure there is only one ISBN
 +    if (!empty($record_nice['isbn13'])) unset($record_nice['isbn10']);
  
     if (substr($record_nice['type'], 0, 2) == "Aa") {     if (substr($record_nice['type'], 0, 2) == "Aa") {
       //Type       //Type
-      $res .= "@book {";+      $res = "@book {";
  
       //create identifier       //create identifier
Line 613: Line 607:
       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',       $i = array('author', 'editor', 'title', 'series', 'address', 'publisher',
         'edition', 'year', 'isbn10', 'isbn13');         'edition', 'year', 'isbn10', 'isbn13');
 +
       foreach ($i as $j) {       foreach ($i as $j) {
         $res .= $this->convOutputNice($record_nice,$keys_nice,$j," = {","},\n");         $res .= $this->convOutputNice($record_nice,$keys_nice,$j," = {","},\n");
Line 626: 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("$this->url"); +    //check whether curl-Module is available, if not available use fallback 
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); +    if (function_exists('curl_init')) { 
-    curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id() );  +      $ch = curl_init("$this->url"); 
-    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );  +      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
-    curl_setopt($ch, CURLOPT_HEADER, 0); +      curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id() );  
-    $res = curl_exec($ch); +      //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );  
-    curl_close($ch);+      curl_setopt($ch, CURLOPT_HEADER, 0); 
 +      $res = curl_exec($ch); 
 +      curl_close($ch); 
 +    } else { 
 +      $res = file_get_contents("$this->url"); 
 +    }
     return $res;     return $res;
   }   }
Line 658: Line 658:
              xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";              xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
     $res .= "<rdf:Description rdf:about=\""     $res .= "<rdf:Description rdf:about=\""
-            .$this->myself."?ppn=$ppn&amp;format=rdf"."\">\n";+            .$this->myself."?ppn=".$this->ppn."&amp;format=rdf"."\">\n";
     $res .= "<dc:contributor>".$this->prec->contributor."</dc:contributor>\n";     $res .= "<dc:contributor>".$this->prec->contributor."</dc:contributor>\n";
     $res .= "<dc:coverage>".$this->prec->coverage."</dc:coverage>\n";     $res .= "<dc:coverage>".$this->prec->coverage."</dc:coverage>\n";
Line 676: Line 676:
     $res .= "</rdf:Description>\n";     $res .= "</rdf:Description>\n";
     $res .= "</rdf:RDF>\n";     $res .= "</rdf:RDF>\n";
 +    return $res;
 +  }
 +
 +  /** public -- return JSON record from pica data */
 +  //used by unapi
 +  function getJson() {
 +    if ($this->ppn == 0) return "";
 +
 +    $res = $this->getArray();
 +    //(PHP 5 >= 5.2.0, PECL json >= 1.2.0)
 +    $res = json_encode($res);
 +
     return $res;     return $res;
   }   }
Line 773: Line 785:
     $record_nice = $this->getArrayNice($record_raw);     $record_nice = $this->getArrayNice($record_raw);
     $keys_nice = $this->getKeysText();     $keys_nice = $this->getKeysText();
 +    $res = "";
  
     if (substr($record_nice['type'], 0, 2) == "Aa") {     if (substr($record_nice['type'], 0, 2) == "Aa") {
buechereielektrik/unapi/picarecord.php.txt · Last modified: 2010-01-10 22:28 by rosenke
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0