comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:6f6e07baad80
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
42 function digitalobjects_getBibFormattedDC($bibdata){
43 $bd = drupal_json_encode($bibdata);
44
45 $base = variable_get('digitalobjects_bibdata_path');
46 #$path="http://localhost:18080/metadata/getDCMappedDataJSON";
47 $path = $base ."/getDCMappedData";
48 $options = array(
49
50 'method' => 'POST',
51 'data' => 'bibdata=' . $bd
52 );
53 $request = drupal_http_request($path, $options);
54 #return drupal_json_decode($request->data);
55
56 return drupal_json_decode($request->data);
57
58 }
59
60
61 function digitalobjects_getBibFormattedLabel($bibdata){
62 $bd = drupal_json_encode($bibdata);
63
64 $base = variable_get('digitalobjects_bibdata_path');
65 #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
66 $path = $base ."/getBibFormattedLabelJSON";
67 $options = array(
68
69 'method' => 'POST',
70 'data' => 'bibdata=' . $bd
71 );
72 $request = drupal_http_request($path, $options);
73 return drupal_json_decode($request->data);
74
75 }
76
77
78
79 function digitalobjects_getBibMappedData($bibdata){
80 $bd = drupal_json_encode($bibdata);
81
82 $base = variable_get('digitalobjects_bibdata_path');
83 #$path="http://localhost:18080/metadata/getBibFormattedMetaDataJSON";
84 $path = $base ."/getBibMappedDataJSON";
85
86 $options = array(
87
88 'method' => 'POST',
89 'data' => 'bibdata=' . $bd
90 );
91 $request = drupal_http_request($path, $options);
92 return drupal_json_decode($request->data);
93
94 }
95 #here.metadata.getBibFormattedMetaData(bibdata=docinfo.get('bib', None))
96
97
98
99 function digitalobjects_readMetadata($objid_full,$format="long"){
100
101 //objid_full can have the structure ID/Pagenumber
102
103
104 $objid_parts = explode("/",$objid_full);
105
106 $objid=$objid_parts[0];
107
108
109 if (isset($objid_parts[1])){
110 $pn=$objid_parts[1];
111 $pn_set=true;
112 } else {
113 $pn="1";
114 $pn_set=false;
115 }
116
117
118
119 $md = digitalobject_getMetadata($objid);
120
121 switch($format){
122 case "long":
123 $bib = isset($md['bib']) ?digitalobjects_getBibFormattedMetaData($md['bib']): null;
124 break;
125
126 case "short":
127 $bib = isset($md['bib']) ?digitalobjects_getBibFormattedLabel($md['bib']): null;
128
129 break;
130
131 case "DC":
132 $bibArray = isset($md['bib']) ?digitalobjects_getBibFormattedDC($md['bib']): null;
133
134
135
136 if (count($bibArray) == 0) {
137 $bibArray = array (
138 "creator" => $md['creator'],
139 "title" => $md['title'],
140 "date" => $md['date']
141 );
142 }
143
144
145 $bib = '<metadata xmlns:DC="http://purl.org/dc/terms/" xlink:href="http://md.mpiwg-berlin.mpg.de/purls/indexMeta/'. $objid . '">';
146
147 foreach ($bibArray as $key => $value){
148 $bib = $bib . "<DC:" . $key .">" . $value . "</DC:" . $key . ">";
149 }
150 $bib = $bib . '</metadata>';
151
152
153
154
155 } // close switch
156
157
158 if ($bib == null) {
159 $bibdata = array (
160 "Author" => $md['creator'],
161 "Title" => $md['title'],
162 "Date" => $md['date']
163 );
164 $bib="";
165 /*foreach ($bibdata as $key => $content){
166 $bib = $bib . '<tr><td class="type">' . $key . '</td>
167 <td class="content">' . $content . '</td></tr>';
168 }
169 */
170 foreach ($bibdata as $key => $content){
171 $bib = $bib . '<span class="type">' . $key . ':</span>
172 <span class="content">' . $content . ' </span>';
173 }
174 }
175
176
177
178 $access_type = isset($md['accessType']) ? $md['accessType'] : 'mpiwg';
179
180 if ($pn_set){
181 $titlepage=$pn; // im parameter war die Seitenzahl gesetzt.
182 } else
183 {
184 $titlepage = isset($md['titlePage']) ? $md['titlePage'] : 1;
185 }
186
187
188 $data = array(
189 "thumburl" => create_thumburl_from_dri($objid,$titlepage=$titlepage),
190 "viewerurl" => create_url_from_dri($objid,$access_type = $access_type,$titlepage=$titlepage),
191 "md" => $md,
192 "bibdata" => $bib,
193 "access_type" => $access_type,
194 );
195
196
197 return $data;
198 }
199
200
201 function create_library_path($id){
202 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=";
203 }
204
205 function create_url_from_dri($dri,$access_type = "closed",$pn="1"){
206
207 if ($access_type=="free"){
208 return "http://echo.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
209 }
210 else
211 return "http://libcoll.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
212 }
213
214 function create_thumburl_from_dri($dri,$titlepage=1){
215 return "http://md.mpiwg-berlin.mpg.de/purls/image/".$dri."?pn=" . $titlepage;
216 }