Mercurial > hg > MPIWG-drupal-modules
diff sites/all/modules/custom/digitalobjects/digitalobject_reader.php @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sites/all/modules/custom/digitalobjects/digitalobject_reader.php Wed Jul 31 13:49:13 2013 +0200 @@ -0,0 +1,130 @@ +<?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_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,$format="long"){ + + $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; + } + 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>'; + } + + } + + $access_type = isset($md['accessType']) ? $md['accessType'] : 'mpiwg'; + $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), + "md" => $md, + "bibdata" => $bib, + "access_type" => $access_type, + ); + + return $data; +} + + +function create_url_from_dri($dri,$access_type = "closed"){ + + if ($access_type=="free"){ + return "http://echo.mpiwg-berlin.mpg.de/".$dri; + } + else + return "http://libcoll.mpiwg-berlin.mpg.de/".$dri; +} + +function create_thumburl_from_dri($dri,$titlepage=1){ + return "http://md.mpiwg-berlin.mpg.de/purls/image/".$dri."?pn=" . $titlepage; +}