-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom.php
143 lines (122 loc) · 4.77 KB
/
custom.php
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
<?php
require_once dirname(__FILE__) . '/functions.php';
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Description'),
'filter_contribution_description'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Title'),
'filter_contribution_title'
);
add_filter(
array('ElementForm', 'Item', 'Item Type Metadata', 'Text'),
'filter_contribution_text'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Date'),
'filter_contribution_date'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Spatial Coverage'),
'filter_contribution_coverage'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Contributor'),
'filter_contribution_contributor'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Abstract'),
'filter_contribution_abstract'
);
add_filter(
array('ElementForm', 'Item', 'Dublin Core', 'Creator'),
'filter_contribution_creator'
);
add_filter(
array('Display','Item','Dublin Core', 'Creator'),
'filter_for_anonymity'
);
add_filter(
array('Display','Item','Dublin Core', 'Contributor'),
'filter_for_anonymity'
);
add_filter(
'item_citation',
'filter_item_citation'
);
//Retaining sort or search order when paging through items
function custom_paging()
{
//Starts a conditional statement that determines a search has been run
if (isset($_SERVER['QUERY_STRING'])) {
// Sets the current item ID to the variable $current
$current = metadata('item', 'id');
//Break the query into an array
parse_str($_SERVER['QUERY_STRING'], $queryarray);
//Items don't need the page level
unset($queryarray['page']);
$itemIds = array();
$list = array();
if (isset($queryarray['query'])) {
//We only want to browse previous and next for Items
$queryarray['record_types'] = array('Item');
//Get an array of the texts from the query.
$textlist = get_db()->getTable('SearchText')->findBy($queryarray);
//Loop through the texts ans populate the ids and records.
foreach ($textlist as $value) {
$itemIds[] = $value->record_id;
$record = get_record_by_id($value['record_type'], $value['record_id']);
$list[] = $record;
}
}
elseif (isset($queryarray['advanced'])) {
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
//Get an array of the items from the query.
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
$list[] = $value;
}
}
//Browsing all items in general
else
{
if (!array_key_exists('sort_field', $queryarray))
{
$queryarray['sort_field'] = 'added';
$queryarray['sort_dir'] = 'd';
}
$list = get_db()->getTable('Item')->findBy($queryarray);
foreach ($list as $value) {
$itemIds[] = $value->id;
}
}
//Update the query string without the page and with the sort_fields
$updatedquery = http_build_query($queryarray);
$updatedquery = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $updatedquery);
// Find where we currently are in the result set
$key = array_search($current, $itemIds);
// If we aren't at the beginning, print a Previous link
if ($key > 0) {
$previousItem = $list[$key - 1];
$previousUrl = record_url($previousItem, 'show') . '?' . $updatedquery;
$text = __('← Previous Item');
echo '<li id="previous-item" class="previous"><a href="' . html_escape($previousUrl) . '">' . $text . '</a></li>';
}
// If we aren't at the end, print a Next link
if ($key >= 0 && $key < (count($list) - 1)) {
$nextItem = $list[$key + 1];
$nextUrl = record_url($nextItem, 'show') . '?' . $updatedquery;
$text = __("Next Item →");
echo '<li id="next-item" class="next"><a href="' . html_escape($nextUrl) . '">' . $text . '</a></li>';
}
} else {
// If a search was not run, then the normal next/previous navigation is displayed.
echo '<li id="previous-item" class="previous">'.link_to_previous_item_show().'</li>';
echo '<li id="next-item" class="next">'.link_to_next_item_show().'</li>';
}
}