-
Notifications
You must be signed in to change notification settings - Fork 3
/
ADRBasicViewer.inc
324 lines (301 loc) · 11.3 KB
/
ADRBasicViewer.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
// $Id$
/**
* @file
*
*/
class ADRBasicViewer {
protected $pid;
protected $dsid;
protected $item;
protected $mimeType;
static protected $allowedMimeTypes = array(
'application/rdf+xml',
'text/xml',
'text/html',
'video/x-flv',
'audio/mpeg',
'audio/x-mpeg',
'video/mpeg',
'video/mp4',
'application/x-shockwave-flash',
'image/jpeg',
'image/jp2',
'image/tiff',
'image/png',
);
public static function hasViewer($pid, $dsid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$matches = array();
$dsid_without_extension = preg_replace('/\.[^.]+$/', '', $dsid);
$find_similar_dsids = function($dsid) use ($dsid_without_extension, &$matches) {
$local_dsid_without_extension = preg_replace('/\.[^.]+$/', '', $dsid);
if ($local_dsid_without_extension == $dsid_without_extension) {
$matches[] = $subject;
}
};
$item = new Fedora_Item($pid);
array_walk($item->datastreams, $find_similar_dsids);
foreach ($matches as $match) {
$mime_type = $item->datastreams[$match]['MIMEType'];
if (self::allowedMimeType($mime_type)) {
return TRUE;
}
}
return FALSE;
}
public static function allowedMimeType($mime_type) {
return array_search($mime_type, self::$allowedMimeTypes) !== FALSE;
}
public static function includeRequiredJSForViewers($pid) {
self::includeJSForFlash($pid);
self::includeJSForFlexPaper($pid);
self::includeJSForFlowPlayer($pid);
self::includeJSForPrettyPrint();
}
private static function includeJSForFlowPlayer($pid) {
$path = drupal_get_path('module', 'adr_basic_viewer');
$base_path = base_path();
$full_path = $base_path . $path;
drupal_add_js("$path/flowplayer/flowplayer-3.2.6.min.js");
$js = <<<EOT
function loadFlowPlayerAduio(dsid) {
flowplayer("playerFlow", "$full_path/flowplayer/flowplayer-3.2.7.swf");
}
function loadFlowPlayer(dsid) {
flowplayer("playerFlow", "$full_path/flowplayer/flowplayer-3.2.7.swf", {
plugins: {
controls: {
fullscreen: false,
autoHide: false
}
},
clip: {
autoPlay: false,
scaling: 'orig',
}
});
}
EOT;
drupal_add_js($js, 'inline');
}
private static function includeJSForFlash($pid) {
$path = drupal_get_path('module', 'Fedora_Repository');
$base_path = base_path();
$full_path = $base_path . $path;
drupal_add_js("$path/js/swfobject.js");
$js = <<<EOT
function loadFLVPlayer(dsid) {
var basePath = window.location.protocol + '//' + window.location.hostname;
var pid = window.location.pathname.split('/')[3];
var s1 = new SWFObject( '$full_path/flash/flvplayer.swf', 'single', '320', '240', '7');
s1.addParam('allowfullscreen', 'TRUE');
s1.addVariable('file', '{$base_path}fedora/repository/$pid/' + dsid);
s1.write('playerFLV');
}
EOT;
drupal_add_js($js, 'inline');
}
private static function includeJSForFlexPaper($pid) {
global $base_url;
drupal_add_js("sites/all/libraries/flexpaper/js/flexpaper_flash.js");
drupal_add_js("sites/all/libraries/swfobject/swfobject.js");
$js = <<<EOT
function loadFlexPlayer(dsid) {
var swfURL = '$base_url/fedora/repository/{$pid}/' + dsid;
var swfVersionStr = "10.0.0";
var xiSwfUrlStr = "/sites/all/libraries/flexpaper/js/swfobject/expressInstall.swf";
var flashvars = {
SwfFile : escape(swfURL),
Scale : 0.6,
ZoomTransition : "easeOut",
ZoomTime : 0.5,
ZoomInterval : 0.1,
FitPageOnLoad : true,
FitWidthOnLoad : false,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
PrintToolsVisible : true,
ViewModeToolsVisible : true,
ZoomToolsVisible : true,
FullScreenVisible : true,
NavToolsVisible : true,
CursorToolsVisible : true,
SearchToolsVisible : true,
localeChain: "en_US",
scaleMode: "exactFit"
};
var params = {}
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = { wmode: "transparent" };
attributes.id = "FlexPaperViewer";
attributes.name = "FlexPaperViewer";
swfobject.embedSWF(
"$base_url/sites/all/libraries/flexpaper/FlexPaperViewer.swf", "playerFlexPaper",
"100%", "857", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
swfobject.createCSS("#playerFlexPaper", "display:block;text-align:left;");
}
EOT;
drupal_add_js($js, 'inline'); //"915", "835"
}
private static function includeJSForPrettyPrint() {
$path = drupal_get_path('module', 'adr_basic_viewer');
drupal_add_js("$path/pretty-print/prettify.js");
drupal_add_css("$path/pretty-print/prettify.css");
}
public function __construct($pid, $dsid = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$this->item = new Fedora_Item($pid);
$this->pid = $pid;
$this->dsid = $dsid;
$this->mimeType = $this->item->datastreams[$this->dsid]['MIMEType'];
}
private function getTextHtmlViewer() {
$content_url = variable_get('fedora_base_url', '') . '/objects/' . $this->pid . '/datastreams/' . $this->dsid . '/content';
$datastream = $this->item->get_datastream($this->dsid);
if ($datastream->controlGroup == 'R') {
$content_url = $this->item->get_datastream_dissemination($this->dsid);
}
return '<iframe src="' . $content_url . '" frameborder="0" style="width: 100%; height: 880px">Error: unable to load viewer</iframe>';
}
/**
*
* @return string
*/
private function getTextXmlViewer() {
$filename = drupal_get_path('module', 'adr_basic_viewer') . '/xsl/PrettyPrint.xsl';
$xsl = new DOMDocument();
$xsl->load($filename);
$doc = new DOMDocument();
$output = '';
// Need to test if the datastream is a redirect stream. If it is then the returned dissemination
// is a URL to the actual data. If it is not a redirect stream then the data returned will be
// the actual displayable data.
$datastream = $this->item->get_datastream($this->dsid);
$datastream_dissemination = $this->item->get_datastream_dissemination($this->dsid);
if ($datastream->controlGroup == 'R') {
$datastream_dissemination = do_curl($datastream_dissemination);
}
$doc->loadXML($datastream_dissemination);
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$content = $proc->transformToXml($doc);
$content = htmlentities($content);
foreach (preg_split("/(\r?\n)/", $content) as $line) {
$output .= $line . '<br/>';
}
return "<code class='prettyprint xml' style='overflow: scroll; position: relative;'>$output</code>";
}
/**
*
* @return string
*/
private function getDjatokaViewer() {
global $base_url;
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$img_url = variable_get('fedora_base_url', '') . '/objects/' . $this->pid . '/datastreams/' . $this->dsid . '/content';
$img_size = getimagesize($img_url);
$img_height = $img_size[1];
$img_width = $img_size[0];
// Display the original content in an image tag as IIV returns null identifiers for files under a certain dimension
if ($img_height < 100 && $img_width < 100) {
$object = new Fedora_Item($this->pid);
$rels = $object->get_datastream_dissemination('RELS-INT');
$xml = new SimpleXMLElement($rels);
$result = $xml->xpath('//coal:hasJP2/..');
$file_name = substr($this->dsid, 0, strrpos($this->dsid, '.'));
foreach($result as $test) {
preg_match('/rdf:Description rdf:about="info:fedora\/'.$this->pid.'\/(.*)"/', $test->asXML(), $match);
$match_name = substr($match[1], 0, strrpos($match[1], '.'));
if ($file_name == $match_name) {
break;
}
}
$original_ds = $match[1];
$original_url = variable_get('fedora_base_url', '') . '/objects/' . $this->pid . '/datastreams/' . $original_ds . '/content';
return '<img src="' . $original_url . '"/>';
}
else {
$viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer?dsid=' . $this->dsid;
return '<iframe src="' . $viewer_url . '" frameborder="0" style="width: 100%; height: 835px;" scrolling="no">Errors: unable to load viewer</iframe>';
}
}
/**
*
* @return string
*/
private function getVideoViewer() {
global $base_url;
$file_url = $base_url . '/fedora/repository/' . $this->pid . "/{$this->dsid}";
return "<a href='$file_url' style='display:block;width:640px;height:480px;margin-left:auto;margin-right:auto;' id='playerFlow'/>";
}
private function getFlashImageViewer($imageList=null) {
global $base_url;
$path = drupal_get_path('module', 'Fedora_Repository');
$fullPath = base_path() . $path;
$swfURL = $base_url . base_path() . '/fedora/repository/' . $this->pid . '/WEB/web.jpg';
$swfURL = 'image0=' . $swfURL . '&title0=IMAGE0';
if (!empty($imageList)) {
$swfURL = "";
$counter = 0;
foreach ($imageList as $image) {
$swfURL .= 'image' . $counter . '=' . $base_url . base_path() . 'fedora/repository/' . $this->pid . '/' . $image . '&title' . $counter . '=IMAGE' . $counter++ . '&';
}
$swfURL = substr($swfURL, 0, strlen($swfURL) - 1);
}
$content = "";
$content = '<div id="flashpictureviewer">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="540" height="300" style="margin-left: auto; margin-right: auto;display:block;">
<param name="movie" value="/sites/all/libraries/flash_image_viewer.swf" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<param name="FlashVars" value="' . $swfURL . '" / >
<embed src="/sites/all/libraries/flash_image_viewer.swf"
FlashVars="' . $swfURL . '"
quality="high"
type="application/x-shockwave-flash"
WMODE="transparent"
width="640"
height="480"
allowFullScreen="true"
allowScriptAccess="always"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object></div>';
return $content;
}
/**
*
* @return string
*/
public function getViewer() {
switch ($this->mimeType) {
case 'application/rdf+xml':
case 'text/xml':
return $this->getTextXmlViewer();
case 'text/html':
return $this->getTextHtmlViewer();
case 'video/x-flv':
return "<div id='playerFLV' style='margin-left:auto; margin-right: auto;'></div>";
case 'audio/mpeg':
case 'audio/x-mpeg':
case 'video/mpeg':
case 'video/mp4':
return $this->getVideoViewer();
case 'application/x-shockwave-flash':
return '<div id="playerFlexPaper"></div>';
case 'image/jpeg':
case 'image/jp2':
case 'image/tiff':
case 'image/png':
return $this->getDjatokaViewer();
default:
return '<div>There is no viewer for the selected file type... or no file is selected.</div>';
}
}
}