-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdsudora.module
166 lines (152 loc) · 4.99 KB
/
sdsudora.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
<?php
/**
* @file
* Main SDSUdora module file.
* @author Diego Pino Navarro
*/
// Permissions.
define('SDSUDORA_ADMIN', 'Administer sdsudora');
/**
* Implements hook_menu().
*/
function sdsudora_menu() {
return array(
'admin/islandora/tools/sdsudora' => array(
'title' => 'SDSUdora settings',
'description' => 'Configure SDSUdora-the-explorer.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array('sdsudora_admin_form'),
'file' => 'includes/admin.form.inc',
'access arguments' => array(SDSUDORA_ADMIN),
),
);
}
/**
* Implements hook_permission().
*/
function sdsudora_permission() {
return array(
SDSUDORA_ADMIN => array(
'title' => t('Administer SDSUdora'),
'description' => t('Administer settings for the SDSUdora module.'),
),
);
}
/**
* Alters breadcrumbs used on Solr search results and within Islandora views.
*
* @param array $breadcrumbs
* Breadcrumbs array to be altered by reference. Each element is markup.
* @param string $context
* Where the alter is originating from for distinguishing.
* @param AbstractObject $object
* (Optional) AbstractObject representing object providing breadcrumb path.
*/
function sdsudora_islandora_breadcrumbs_alter(array &$breadcrumbs, $context, AbstractObject $object = NULL) {
if ($context == 'islandora') {
// Copy to be able to remove values.
$breadcrumbstmp = $breadcrumbs;
$values = variable_get('sdsudora_settings', array());
$numvalues = count($values);
if ($numvalues) {
$i = 0;
$root = variable_get('islandora_repository_pid', 'islandora:root');
// Number of values will be always even.
$iterations = (int) round($numvalues / 2);
for ($i = 0; $i < $iterations; $i++) {
$unescapedpid = $values['sdsudora_settings_o_' . $i];
$pid = str_replace(":", "%3A", $values['sdsudora_settings_o_' . $i]);
foreach ($breadcrumbstmp as $key => $item) {
if ((strpos($item, "islandora/object/{$pid}") !== FALSE) ||
(strpos($item, 'a href="/islandora"') !== FALSE && $unescapedpid == $root)) {
$replacementpath = trim($values['sdsudora_settings_d_' . $i], "/");
$path = drupal_lookup_path('source', $replacementpath);
if ($path) {
$uri = drupal_get_path_alias($replacementpath);
$preferred_link = menu_link_get_preferred($path);
$item = menu_get_item($path);
if ($preferred_link) {
$title = $preferred_link['title'];
}
else {
$title = $item['title'];
}
$breadcrumbs[$key] = l($title, $item['href']);
}
}
}
$i++;
}
}
}
}
/**
* Implements hook_preprocess_islandora_solr_metadata_description().
*
* Adds formatter function to all *_dt and *_mdt fields.
*/
function sdsudora_preprocess_islandora_solr_metadata_display(array &$variables) {
foreach ($variables['solr_fields'] as $fieldname => $fields) {
if ((substr($fieldname, -3) === '_dt') || (substr($fieldname, -4) === '_mdt')) {
if (!isset($fields['formatter']) || empty($fields['formatter'])) {
$variables['solr_fields'][$fieldname]['formatter'] = '_sdsu_format_date';
}
}
}
}
/**
* Formats a Solr Date into Natural language removing time and zone.
*/
function _sdsu_format_date($value) {
if (empty($value)) {
return $value;
}
return date('Y-m-d', strtotime($value));
}
/**
* Implements hook_js_alter().
*
* Replaces Islandora Solr Search Facet JS with our own.
*
* @author dpino@metro.org
*/
function sdsudora_js_alter(&$javascript) {
$index = 'sites/all/modules/islandora_solr_search/js/islandora_solr_facets.js';
if (isset($javascript[$index])) {
$javascript[$index]['data'] = drupal_get_path('module', 'sdsudora') . '/js/islandora_solr_facets.js';
}
}
/**
* Implements hook_islandora_newspaper_get_issues_alter().
*
* Permit other modules to modify the issues list prior to being returned from
* islandora_newspaper_get_issues. This is primarily intended to be able
* to change sorting so that "prev" and "next" links make sense.
*
* @param array &$issues
* The list of issues about to be returned. Each one is an associative array
* with the following indexes:
* 'pid' string
* 'label' string
* 'sequence' string
* 'issued' dateTime object
* @param \AbstractFedoraObject $newspaper
* The newspaper object whose issues are being fetched.
*/
function sdsudora_islandora_newspaper_get_issues_alter(&$issues, $newspaper) {
function date_compare($a, $b)
{
$time1Object = $a['issued'];
$time2Object = $b['issued'];
$t1 = $time1Object->getTimestamp();
$t2 = $time2Object->getTimestamp();
$order = $t1 - $t2;
if ($order == 0) {
// Try with the sequence for Objects with the same date
$order = (int) $a['sequence'] - (int) $b['sequence'];
}
return $order;
}
usort($issues, 'date_compare');
}