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 $bib = '<metadata xmlns:DC="http://purl.org/dc/terms/">';
145
146 foreach ($bibArray as $key => $value){
147 $bib = $bib . "<DC:" . $key .">" . $value . "</DC:" . $key . ">";
148 }
149 $bib = $bib . '</metadata>';
150
151
152
153
154 } // close switch
155
156
157 if ($bib == null) {
158 $bibdata = array (
159 "Author" => $md['creator'],
160 "Title" => $md['title'],
161 "Date" => $md['date']
162 );
163 $bib="";
164 /*foreach ($bibdata as $key => $content){
165 $bib = $bib . '<tr><td class="type">' . $key . '</td>
166 <td class="content">' . $content . '</td></tr>';
167 }
168 */
169 foreach ($bibdata as $key => $content){
170 $bib = $bib . '<span class="type">' . $key . ':</span>
171 <span class="content">' . $content . ' </span>';
172 }
173 }
174
175
176
177 $access_type = isset($md['accessType']) ? $md['accessType'] : 'mpiwg';
178
179 if ($pn_set){
180 $titlepage=$pn; // im parameter war die Seitenzahl gesetzt.
181 } else
182 {
183 $titlepage = isset($md['titlePage']) ? $md['titlePage'] : 1;
184 }
185
186
187 $data = array(
188 "thumburl" => create_thumburl_from_dri($objid,$titlepage=$titlepage),
189 "viewerurl" => create_url_from_dri($objid,$access_type = $access_type,$titlepage=$titlepage),
190 "md" => $md,
191 "bibdata" => $bib,
192 "access_type" => $access_type,
193 );
194
195
196 return $data;
197 }
198
199
200 function create_library_path($id){
201 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=";
202 }
203
204 function create_url_from_dri($dri,$access_type = "closed",$pn="1"){
205
206 if ($access_type=="free"){
207 return "http://echo.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
208 }
209 else
210 return "http://libcoll.mpiwg-berlin.mpg.de/".$dri . "?pn=" . $pn;
211 }
212
213 function create_thumburl_from_dri($dri,$titlepage=1){
214 return "http://md.mpiwg-berlin.mpg.de/purls/image/".$dri."?pn=" . $titlepage;
215 }