-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathislandora_embed.module
205 lines (194 loc) · 6.14 KB
/
islandora_embed.module
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
<?php
/**
* @file
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Implements hook_menu().
*
* @return string
*/
function islandora_embed_menu() {
$items = array();
$items['embed_service/uuid'] = array(
'title' => 'Islandora Embed',
'description' => "Interpret the embedding request and send back JSON objects",
'page callback' => 'uuid_embed_object',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['islandora/embed/object/%islandora_object'] = array(
'title' => 'Islandora Embed',
'description' => "Send back JSON objects in response to oembed requests",
'page callback' => 'islandora_embed_object',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['islandora/embed/object_UI/%islandora_object'] = array(
'title' => 'Islandora Embed',
'description' => "Send back JSON objects in response to oembed requests",
'page callback' => 'islandora_embed_object_UI',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['embed/uuid/%'] = array(
'title' => 'Uuid Embed',
'description' => "Send back JSON objects in response to oembed requests",
'page callback' => 'uuid_embed_object_interpret',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
/**
* Redirects Oembed requests to appropriate content model module.
*/
function islandora_embed() {
$parameters = drupal_get_query_parameters($query = NULL);
if (isset($parameters['url']) && $parameters['url'] != "") {
$url = $parameters['url'];
unset($parameters['url']);
drupal_goto($url, array('query' => $parameters));
}
exit();
}
/**
*
*/
function uuid_embed_object_interpret(){
global $base_url;
$path = current_path();
$parameters_string = $_SERVER['QUERY_STRING'];
$url = $base_url . "/embed_service/uuid/?url=" . $base_url . "/" . $path."?".$parameters_string;
drupal_goto($url);
// print $url;
}
/**
* Generate the response based on the Oembed requests.
*
* @global type $base_url
* @param AbstractFedoraObject $object
* The object.
*
* @return JSON object
* JSON object containing data for being processed by the Oembed module
* to generate embedded display.
*/
function islandora_embed_object(AbstractFedoraObject $object) {
global $base_url;
module_load_include('inc', 'islandora_embed', 'includes/response_generator');
$fedoraObjExt = new FedoraObjectExtended($object->id, $object->repository);
if (isset($_GET['maxwidth'])) {
$maxwidth = $_GET['maxwidth'];
}
elseif (isset($_GET['width'])) {
$maxwidth = $_GET['width'];
}
if (isset($_GET['maxheight'])) {
$maxheight = $_GET['maxheight'];
}
elseif (isset($_GET['height'])) {
$maxheight = $_GET['height'];
}
$resGenerator = new RespsonseGenerator($fedoraObjExt, $base_url, $maxheight, $maxwidth, $maxheight, $maxwidth);
$resGenerator->getJSONResponse();
}
/**
* Redirects the requests directly to the display of content model without returning JSON objects.
*
* @global type $base_url
* @param AbstractFedoraObject $object
* The object.
*/
function islandora_embed_object_UI(AbstractFedoraObject $object) {
global $base_url;
module_load_include('inc', 'islandora_embed', 'includes/response_generator');
module_load_include('inc', 'islandora', 'islandora.module');
$fedoraObjExt = new FedoraObjectExtended($object->id, $object->repository);
if (isset($_GET['maxwidth'])) {
$maxwidth = $_GET['maxwidth'];
}
elseif (isset($_GET['width'])) {
$maxwidth = $_GET['width'];
}
if (isset($_GET['maxheight'])) {
$maxheight = $_GET['maxheight'];
}
elseif (isset($_GET['height'])) {
$maxheight = $_GET['height'];
}
$resGenerator = new RespsonseGenerator($fedoraObjExt, $base_url, $maxheight, $maxwidth);
$resGenerator->getEmbeddedObjUI();
}
/**
* Interpret and the request and get the URL pattern
* '/islandora/embed/object/islandora%3Auuid?height=h&width=w' and redirect the request to the interpreted URL
*/
function uuid_embed_object() {
$parameters = array();
$parameters_string = $_SERVER['QUERY_STRING'];
parse_str($parameters_string, $parameters);
$url = urldecode($parameters['url']);
if(!empty($parameters['maxheight']) || !empty($parameters['height'])){
$height = !empty($parameters['maxheight']) ? $parameters['maxheight'] : $parameters['height'];
}
if(!empty($parameters['maxwidth']) || !empty($parameters['width'])){
$width = !empty($parameters['maxwidth']) ? $parameters['maxwidth'] : $parameters['width'];
}
$query_string = "";
if(!empty($height) || !empty($width)){
$query_string = "?";
if(!empty($height)){
$query_string .= "height=".$height;
}
if(!empty($width)){
if(!empty($height)){
$query_string .= "&";
}
$query_string .= "width=".$width;
}
}
$url = $url.$query_string;
if (isset($url) && $url != "") {
$translated_url = getTranslatedUrl($url);
drupal_goto($translated_url);
}
exit();
}
/**
* Translate the url pattern from '/embed/uuid/uuid' to '/islandora/embed/object/islandora%3Auuid'
*/
function getTranslatedUrl($url) {
module_load_include('inc', 'islandora_embed', 'includes/utilities');
try{
$url_arr = explode("/embed/uuid/",$url);
$uuid = $url_arr[count($url_arr)-1];
$uuid_arr = explode("?", $uuid);
$path = 'uuid/'.$uuid_arr[0];
$prefix = _get_pid_prefix($path);
$pid_prefix = urlencode($prefix.":");
$translatedUrl = $url_arr[0]."/islandora/embed/object/".$pid_prefix.$uuid;
return $translatedUrl;
}
catch(Exception $ex){
echo "The uuid cannot be translated!\n";
echo $exc->getTraceAsString();
}
}
/**
* Implements hook_theme().
*/
function islandora_embed_theme(){
return array(
'islandora_internet_archive_bookreader_book_info' => array(
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-embed',
'variables' => array('object' => NULL),
),
);
}