-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflvc_custom_display.module
189 lines (164 loc) · 5.75 KB
/
flvc_custom_display.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
<?php
/**
* @file
* A block that displays collection information when the user performs a blank search
*/
require_once 'includes/theme_helper.inc';
/**
* Implements hook_help.
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function flvc_custom_display_help($path, $arg) {
switch ($path) {
case "admin/help#flvc_custom_display":
return '<p>' . t("Displays collection information related to an empty search") . '</p>';
break;
}
}
/**
* Implements hook_block_info().
*/
function flvc_custom_display_block_info() {
$blocks['flvc_custom_display'] = array(
'info' => t('Collection Information in Search'), //The name that will appear in the block list.
'cache' => DRUPAL_CACHE_PER_ROLE, //Default
);
return $blocks;
}
/**
* Get Collection Object function.
*
* Get the collection objectId from the URL and retrive the object from the Fedora repository
*
* @return
* The collection object
*/
function flvc_custom_display_get_collection_information(){
global $base_url;
$banner = '';
$exists = false;
$desc_text = false;
$collection_id = NULL;
$collection = array();
$collection['name'] = 'Not a Collection';
$collection['base_url'] = $base_url;
if (isset($_GET['collection']))
{
$collection_id = $_GET['collection'];
$collection['id'] = $collection_id;
}
if ($collection_id)
{
// load object and get the collection name
$collection_object = islandora_object_load($collection_id);
$collection['name'] = $collection_object->label;
//create DC datastream URL
$collection['dc_url'] = $base_url . '/islandora/object/' . $collection_id . '/datastream/DC/';
//retrieve the DC databsteam
//$dc = file_get_contents($collection['dc_url']);
$dc = $collection_object['DC']->content;
//convert DC into an object
$collection['dc_object'] = DublinCore::importFromXMLString($dc);
//if the Dublin Core exists, retrieve the collection name
if($collection['dc_object'])
{
$dc_object_array = $collection['dc_object']->asArray();
}
//Try to retrieve the related links datastream
if (isset($collection_object['RELATED-LINKS']))
{
$collection['related_links_html'] = create_related_links_html($collection_object);
}
//Try to retrieve the description text datastream
if (isset($collection_object['DESC-TEXT']))
{
$desc_text = $collection_object['DESC-TEXT']->content;
}
if ($desc_text)
{
$collection['description_text'] = $desc_text;
}
else
{
$collection['description_text'] = ' ';
}
//create BANNER datastream URL
$collection['banner_url'] = $base_url . '/islandora/object/' . $collection_id . '/datastream/BANNER/view';
//Check if the BANNER datastream exists
$datastream_headers = @get_headers($collection['banner_url']);
if(strpos($datastream_headers[0], '200') === false) {
$collection['banner_exists'] = false;
}
else {
$collection['banner_exists'] = true;
}
}
return $collection;
}
/**
* Implements hook_block_view().
*
* Prepares the contents of the block.
*/
function flvc_custom_display_block_view($delta = '') {
switch($delta){
case 'flvc_custom_display':
if(user_access('access content')){
//Use custom function to retrieve collection information.
$collection_info = flvc_custom_display_get_collection_information();
if ($collection_info) { //Found collection, send to theme.
$search_form =
'<div id="local-search-container">
<h2 class="local-collection-search-title">Search this Collection</h2>
<form id="local-collection-search-form" accept-charset="UTF-8" onsubmit="return makeURL(\'local-collection-search-form\');" method="get" action="#">
<div class="form-item">
<input class="search-input-text" type="text" maxlength="128" name="islandora_simple_search_query" />
<input type="submit" name="submit" value="search" class="form-submit" />
</div>
<input type="hidden" name="islandora_simple_collection" value="' . $collection_info['id'] . '">
<input type="hidden" name="base_url" value="' . $collection_info['base_url'] . '">
</form>
</div>';
if($collection_info['banner_exists'])
{
$formatted_banner = theme('image', array('path' => $collection_info['banner_url']));
$formatted_banner = '<p>' . $formatted_banner . '</p>';
}
else
{
$formatted_banner = t($collection_info['name']);
}
if(isset($collection_info['related_links_html']))
{
$formatted_related_links = $collection_info['related_links_html'];
$formatted_description = '<p class="related-links-present">' . t($collection_info['description_text']) . '</p>';
}
else
{
$formatted_related_links = '';
$formatted_description = '<p>' . t($collection_info['description_text']) . '</p>';
}
if($collection_info['banner_exists'])
{
$block['content'] = $formatted_banner . $formatted_related_links . $search_form . $formatted_description;
}
else
{
$block['subject'] = $formatted_banner;
$block['content'] = $formatted_related_links . $search_form . $formatted_description;
}
}
else {
//No Collection Info
$block['content'] = t('Unable to retrieve collection information');
}
}
return $block;
}
}