diff digitalobject_reader.php~ @ 0:6f6e07baad80 default tip

initial
author Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
date Tue, 02 Jun 2015 08:57:48 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/digitalobject_reader.php~	Tue Jun 02 08:57:48 2015 +0200
@@ -0,0 +1,215 @@
+<?php
+
+/* function reads the metadata from index meta and gives it back to the
+ * template.
+ */
+
+#http://localhost:18080/ECHOdocuView/getDocinfo?mode=imagepath&url=http://md.mpiwg-berlin.mpg.de/indexMeta/MPIWG:WEBVEZ22
+function digitalobject_getMetadata($objid){
+
+  $base = variable_get('digitalobjects_docuviewer_path');
+  #$path="http://localhost:18080/ECHOdocuView/getDocinfoJSON?mode=texttool&url=http://md.mpiwg-berlin.mpg.de/indexMeta/" . $objid;
+  $path = $base . "/getDocinfoJSON?mode=texttool&url=http://md.mpiwg-berlin.mpg.de/indexMeta/" . $objid;
+  $request = drupal_http_request($path);
+  #TODO give out a status message  reports if servers is not available
+
+  if (isset($request->data)){
+    return drupal_json_decode($request->data);
+  }
+  else {
+    return null;
+  }
+
+}
+
+function digitalobjects_getBibFormattedMetaData($bibdata){
+  $bd = drupal_json_encode($bibdata);
+
+  $base = variable_get('digitalobjects_bibdata_path');
+  #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
+  $path = $base ."/getBibFormattedMetaDataJSON";
+  $options = array(
+
+      'method' => 'POST',
+      'data' => 'bibdata=' . $bd
+  );
+  $request = drupal_http_request($path,  $options);
+  return drupal_json_decode($request->data);
+
+}
+
+
+function digitalobjects_getBibFormattedDC($bibdata){
+  $bd = drupal_json_encode($bibdata);
+
+  $base = variable_get('digitalobjects_bibdata_path');
+  #$path="http://localhost:18080/metadata/getDCMappedDataJSON";
+  $path = $base ."/getDCMappedData";
+  $options = array(
+
+      'method' => 'POST',
+      'data' => 'bibdata=' . $bd
+  );
+  $request = drupal_http_request($path,  $options);
+  #return drupal_json_decode($request->data);
+
+  return  drupal_json_decode($request->data);
+
+}
+
+
+function digitalobjects_getBibFormattedLabel($bibdata){
+  $bd = drupal_json_encode($bibdata);
+
+  $base = variable_get('digitalobjects_bibdata_path');
+  #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
+  $path = $base ."/getBibFormattedLabelJSON";
+  $options = array(
+
+      'method' => 'POST',
+      'data' => 'bibdata=' . $bd
+  );
+  $request = drupal_http_request($path,  $options);
+  return drupal_json_decode($request->data);
+
+}
+
+
+
+function digitalobjects_getBibMappedData($bibdata){
+  $bd = drupal_json_encode($bibdata);
+
+  $base = variable_get('digitalobjects_bibdata_path');
+  #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
+  $path = $base ."/getBibMappedDataJSON";
+
+  $options = array(
+
+      'method' => 'POST',
+      'data' => 'bibdata=' . $bd
+  );
+  $request = drupal_http_request($path,  $options);
+  return drupal_json_decode($request->data);
+
+}
+#here.metadata.getBibFormattedMetaData(bibdata=docinfo.get('bib', None))
+
+
+
+function digitalobjects_readMetadata($objid_full,$format="long"){
+
+  //objid_full can have the structure ID/Pagenumber
+
+
+  $objid_parts = explode("/",$objid_full);
+
+  $objid=$objid_parts[0];
+
+
+  if (isset($objid_parts[1])){
+    $pn=$objid_parts[1];
+    $pn_set=true;
+  } else {
+    $pn="1";
+    $pn_set=false;
+  }
+
+
+
+  $md = digitalobject_getMetadata($objid);
+
+  switch($format){
+    case "long":
+      $bib = isset($md['bib']) ?digitalobjects_getBibFormattedMetaData($md['bib']): null;
+    break;
+
+    case "short":
+      $bib = isset($md['bib']) ?digitalobjects_getBibFormattedLabel($md['bib']): null;
+
+    break;
+
+    case "DC":
+      $bibArray = isset($md['bib']) ?digitalobjects_getBibFormattedDC($md['bib']): null;
+
+
+
+      if (count($bibArray) == 0) {
+        $bibArray = array (
+            "creator" => $md['creator'],
+            "title" => $md['title'],
+            "date" => $md['date']
+        );
+      }
+
+      $bib = '<metadata xmlns:DC="http://purl.org/dc/terms/">';
+
+      foreach ($bibArray as $key => $value){
+        $bib = $bib . "<DC:" . $key .">" . $value . "</DC:" . $key . ">";
+      }
+      $bib = $bib . '</metadata>';
+
+
+
+
+    } // close switch
+
+
+    if ($bib == null) {
+      $bibdata = array (
+          "Author" => $md['creator'],
+          "Title" => $md['title'],
+          "Date" => $md['date']
+      );
+      $bib="";
+      /*foreach ($bibdata as $key => $content){
+        $bib = $bib . '<tr><td class="type">' . $key . '</td>
+                  <td class="content">' . $content . '</td></tr>';
+      }
+  */
+      foreach ($bibdata as $key => $content){
+       $bib = $bib . '<span class="type">' . $key . ':</span>
+      <span class="content">' . $content . ' </span>';
+      }
+    }
+
+
+
+  $access_type = isset($md['accessType']) ? $md['accessType'] : 'mpiwg';
+
+  if ($pn_set){
+    $titlepage=$pn; // im parameter war die Seitenzahl gesetzt.
+  } else
+  {
+  $titlepage = isset($md['titlePage']) ? $md['titlePage'] : 1;
+  }
+
+
+  $data =  array(
+      "thumburl" => create_thumburl_from_dri($objid,$titlepage=$titlepage),
+      "viewerurl" => create_url_from_dri($objid,$access_type = $access_type,$titlepage=$titlepage),
+      "md" => $md,
+      "bibdata" => $bib,
+      "access_type" => $access_type,
+  );
+
+
+  return $data;
+}
+
+
+function create_library_path($id){
+  return "http://141.14.236.36/fmi/xsl/katalog/browserecord.xsl?-db=katalog&-lay=fullrecord&-encoding=UTF-8&-grammar=fmresultset&-max=1&Biblio::ID=" . $id . "&-find=";
+}
+
+function create_url_from_dri($dri,$access_type = "closed",$pn="1"){
+
+  if ($access_type=="free"){
+    return "http://echo.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
+  }
+  else
+    return "http://libcoll.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
+}
+
+function create_thumburl_from_dri($dri,$titlepage=1){
+  return "http://md.mpiwg-berlin.mpg.de/purls/image/".$dri."?pn=" . $titlepage;
+}