comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:015d06b10d37
1 <?php
2
3 /* function reads the metadata from index meta and gives it back to the
4 * template.
5 */
6
7 #http://localhost:18080/ECHOdocuView/getDocinfo?mode=imagepath&url=http://md.mpiwg-berlin.mpg.de/indexMeta/MPIWG:WEBVEZ22
8 function digitalobject_getMetadata($objid){
9
10 $base = variable_get('digitalobjects_docuviewer_path');
11 #$path="http://localhost:18080/ECHOdocuView/getDocinfoJSON?mode=texttool&url=http://md.mpiwg-berlin.mpg.de/indexMeta/" . $objid;
12 $path = $base . "/getDocinfoJSON?mode=texttool&url=http://md.mpiwg-berlin.mpg.de/indexMeta/" . $objid;
13 $request = drupal_http_request($path);
14 #TODO give out a status message reports if servers is not available
15
16 if (isset($request->data)){
17 return drupal_json_decode($request->data);
18 }
19 else {
20 return null;
21 }
22
23 }
24
25 function digitalobjects_getBibFormattedMetaData($bibdata){
26 $bd = drupal_json_encode($bibdata);
27
28 $base = variable_get('digitalobjects_bibdata_path');
29 #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
30 $path = $base ."/getBibFormattedMetaDataJSON";
31 $options = array(
32
33 'method' => 'POST',
34 'data' => 'bibdata=' . $bd
35 );
36 $request = drupal_http_request($path, $options);
37 return drupal_json_decode($request->data);
38
39 }
40
41 function digitalobjects_getBibFormattedLabel($bibdata){
42 $bd = drupal_json_encode($bibdata);
43
44 $base = variable_get('digitalobjects_bibdata_path');
45 #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
46 $path = $base ."/getBibFormattedLabelJSON";
47 $options = array(
48
49 'method' => 'POST',
50 'data' => 'bibdata=' . $bd
51 );
52 $request = drupal_http_request($path, $options);
53 return drupal_json_decode($request->data);
54
55 }
56
57
58
59 function digitalobjects_getBibMappedData($bibdata){
60 $bd = drupal_json_encode($bibdata);
61
62 $base = variable_get('digitalobjects_bibdata_path');
63 #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
64 $path = $base ."/getBibMappedDataJSON";
65
66 $options = array(
67
68 'method' => 'POST',
69 'data' => 'bibdata=' . $bd
70 );
71 $request = drupal_http_request($path, $options);
72 return drupal_json_decode($request->data);
73
74 }
75 #here.metadata.getBibFormattedMetaData(bibdata=docinfo.get('bib', None))
76
77
78
79 function digitalobjects_readMetadata($objid,$format="long"){
80
81 $md = digitalobject_getMetadata($objid);
82
83 switch($format){
84 case "long":
85 $bib = isset($md['bib']) ?digitalobjects_getBibFormattedMetaData($md['bib']): null;
86 break;
87
88 case "short":
89 $bib = isset($md['bib']) ?digitalobjects_getBibFormattedLabel($md['bib']): null;
90 }
91 if ($bib == null) {
92 $bibdata = array (
93 "Author" => $md['creator'],
94 "Title" => $md['title'],
95 "Date" => $md['date']
96 );
97 $bib="";
98 foreach ($bibdata as $key => $content){
99 $bib = $bib . '<tr><td class="type">' . $key . '</td>
100 <td class="content">' . $content . '</td></tr>';
101 }
102
103 }
104
105 $access_type = isset($md['accessType']) ? $md['accessType'] : 'mpiwg';
106 $titlepage = isset($md['titlePage']) ? $md['titlePage'] : 1;
107 $data = array(
108 "thumburl" => create_thumburl_from_dri($objid,$titlepage=$titlepage),
109 "viewerurl" => create_url_from_dri($objid,$access_type = $access_type),
110 "md" => $md,
111 "bibdata" => $bib,
112 "access_type" => $access_type,
113 );
114
115 return $data;
116 }
117
118
119 function create_url_from_dri($dri,$access_type = "closed"){
120
121 if ($access_type=="free"){
122 return "http://echo.mpiwg-berlin.mpg.de/".$dri;
123 }
124 else
125 return "http://libcoll.mpiwg-berlin.mpg.de/".$dri;
126 }
127
128 function create_thumburl_from_dri($dri,$titlepage=1){
129 return "http://md.mpiwg-berlin.mpg.de/purls/image/".$dri."?pn=" . $titlepage;
130 }